FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
git2cpp/src/wasm/subtransport.cpp at main · QuantStack/git2cpp · GitHub
QuantStack
git2cpp
Repository navigation
Code
Issues
6
(6)
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
git2cpp
/
src
/
wasm
/
subtransport.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
103 lines (82 loc) · 2.66 KB
Breadcrumbs
git2cpp
/
src
/
wasm
/
subtransport.cpp
Copy path
File metadata and controls
103 lines (82 loc) · 2.66 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#
ifdef
EMSCRIPTEN
#
include
"
subtransport.hpp
"
#
include
<
iostream
>
#
include
<
regex
>
#
include
<
sstream
>
#
include
<
git2/sys/credential.h
>
#
include
<
git2/sys/remote.h
>
#
include
"
libgit2_internals.hpp
"
#
include
"
stream.hpp
"
#
include
"
utils.hpp
"
//
C functions.
static
int
wasm_http_action
(
git_smart_subtransport_stream** out,
git_smart_subtransport* s,
const
char
* url,
git_smart_service_t
action
)
{
//
An action is a single http/https request that is handled by a single wasm_http_stream.
GIT_ASSERT_ARG
(out);
GIT_ASSERT_ARG
(s);
GIT_ASSERT_ARG
(url);
wasm_http_subtransport* subtransport =
reinterpret_cast
<wasm_http_subtransport*>(s);
wasm_http_stream* stream =
nullptr
;
*out =
nullptr
;
auto
service =
select_service
(action);
if
(!service.
has_value
())
{
git_error_set
(
0
,
"
invalid http/https action
"
);
return
-
1
;
}
if
(subtransport->
m_base_url
.
empty
())
{
//
Store base URL without trailing slashes.
subtransport->
m_base_url
=
std::regex_replace
(url,
std::regex
(
"
\\
s+$
"
),
"
"
);
}
stream =
new
wasm_http_stream
(subtransport, service.
value
());
stream->
m_parent
.
subtransport
= &subtransport->
m_parent
;
if
(stream->
m_service
.
m_method
==
GIT_HTTP_METHOD_GET
)
{
stream->
m_parent
.
read
= wasm_http_stream_read;
}
else
{
stream->
m_parent
.
write
= wasm_http_stream_write;
stream->
m_parent
.
read
= wasm_http_stream_read_response;
}
stream->
m_parent
.
free
= wasm_http_stream_free;
*out = (git_smart_subtransport_stream*) stream;
return
0
;
}
static
int
wasm_http_close
(git_smart_subtransport* s)
{
return
0
;
}
static
void
wasm_http_free
(git_smart_subtransport* s)
{
wasm_http_subtransport* subtransport =
reinterpret_cast
<wasm_http_subtransport*>(s);
wasm_http_close
(s);
if
(subtransport->
m_credential
!=
nullptr
)
{
subtransport->
m_credential
->
free
(subtransport->
m_credential
);
}
delete
subtransport;
}
int
create_wasm_http_subtransport
(git_smart_subtransport** out, git_transport* owner,
void
* param)
{
GIT_ASSERT_ARG
(out);
GIT_ASSERT_ARG
(owner);
wasm_http_subtransport* subtransport =
new
wasm_http_subtransport
();
GIT_ASSERT_WITH_RETVAL
(subtransport, -
1
);
subtransport->
m_parent
.
action
= wasm_http_action;
subtransport->
m_parent
.
close
= wasm_http_close;
subtransport->
m_parent
.
free
= wasm_http_free;
subtransport->
m_owner
= owner;
subtransport->
m_base_url
=
"
"
;
subtransport->
m_credential
=
nullptr
;
subtransport->
m_request_timeout_ms
=
get_request_timeout_ms
();
*out = &subtransport->
m_parent
;
return
0
;
}
#
endif
//
EMSCRIPTEN
Back
|
FazBrowse Home
|
New Git URL