Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
f30d91ce
Commit
f30d91ce
authored
Sep 26, 2013
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor URL handling to use library call
parent
8988688c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
68 deletions
+27
-68
src/transports/winhttp.c
+27
-68
No files found.
src/transports/winhttp.c
View file @
f30d91ce
...
...
@@ -420,70 +420,6 @@ static void free_connection_data(winhttp_subtransport *t)
}
}
static
int
set_connection_data_from_url
(
winhttp_subtransport
*
t
,
const
char
*
url
,
const
char
*
service_suffix
)
{
int
error
=
0
;
const
char
*
default_port
=
NULL
;
char
*
original_host
=
NULL
;
const
char
*
original_url
=
url
;
if
(
!
git__prefixcmp
(
url
,
prefix_http
))
{
url
+=
strlen
(
prefix_http
);
default_port
=
"80"
;
if
(
t
->
use_ssl
)
{
giterr_set
(
GITERR_NET
,
"Redirect from HTTPS to HTTP not allowed"
);
return
-
1
;
}
}
if
(
!
git__prefixcmp
(
url
,
prefix_https
))
{
url
+=
strlen
(
prefix_https
);
default_port
=
"443"
;
t
->
use_ssl
=
1
;
}
if
(
!
default_port
)
{
giterr_set
(
GITERR_NET
,
"Unrecognized URL prefix"
);
return
-
1
;
}
/* preserve original host name for checking */
original_host
=
t
->
host
;
t
->
host
=
NULL
;
free_connection_data
(
t
);
error
=
gitno_extract_url_parts
(
&
t
->
host
,
&
t
->
port
,
&
t
->
user_from_url
,
&
t
->
pass_from_url
,
url
,
default_port
);
if
(
!
error
)
{
const
char
*
path
=
strchr
(
url
,
'/'
);
size_t
pathlen
=
strlen
(
path
);
size_t
suffixlen
=
service_suffix
?
strlen
(
service_suffix
)
:
0
;
if
(
suffixlen
&&
!
memcmp
(
path
+
pathlen
-
suffixlen
,
service_suffix
,
suffixlen
))
t
->
path
=
git__strndup
(
path
,
pathlen
-
suffixlen
);
else
t
->
path
=
git__strdup
(
path
);
/* Allow '/'-led urls, or a change of protocol */
if
(
original_host
!=
NULL
)
{
if
(
strcmp
(
original_host
,
t
->
host
)
&&
original_url
[
0
]
!=
'/'
)
{
giterr_set
(
GITERR_NET
,
"Cross host redirect not allowed"
);
error
=
-
1
;
}
git__free
(
original_host
);
}
}
return
error
;
}
static
int
winhttp_connect
(
winhttp_subtransport
*
t
,
const
char
*
url
)
...
...
@@ -699,7 +635,18 @@ replay:
if
(
!
git__prefixcmp_icase
(
location8
,
prefix_https
))
{
/* Upgrade to secure connection; disconnect and start over */
set_connection_data_from_url
(
t
,
location8
,
s
->
service_url
);
gitno_connection_data
data
=
{
0
};
if
(
gitno_connection_data_from_url
(
&
data
,
location8
,
s
->
service_url
,
t
->
host
,
t
->
use_ssl
)
<
0
)
{
gitno_connection_data_free_ptrs
(
&
data
);
return
-
1
;
}
free_connection_data
(
t
);
t
->
host
=
data
.
host
;
t
->
port
=
data
.
port
;
t
->
path
=
data
.
path
;
t
->
user_from_url
=
data
.
user
;
t
->
pass_from_url
=
data
.
pass
;
t
->
use_ssl
=
data
.
use_ssl
;
winhttp_connect
(
t
,
location8
);
}
...
...
@@ -1101,10 +1048,22 @@ static int winhttp_action(
winhttp_stream
*
s
;
int
ret
=
-
1
;
if
(
!
t
->
connection
&&
(
set_connection_data_from_url
(
t
,
url
,
NULL
)
<
0
||
winhttp_connect
(
t
,
url
)
<
0
))
if
(
!
t
->
connection
)
{
gitno_connection_data
data
=
{
0
};
if
(
gitno_connection_data_from_url
(
&
data
,
url
,
NULL
,
NULL
,
false
)
<
0
)
{
gitno_connection_data_free_ptrs
(
&
data
);
return
-
1
;
}
free_connection_data
(
t
);
t
->
host
=
data
.
host
;
t
->
port
=
data
.
port
;
t
->
path
=
data
.
path
;
t
->
user_from_url
=
data
.
user
;
t
->
pass_from_url
=
data
.
pass
;
t
->
use_ssl
=
data
.
use_ssl
;
if
(
winhttp_connect
(
t
,
url
)
<
0
)
return
-
1
;
}
if
(
winhttp_stream_alloc
(
t
,
&
s
)
<
0
)
return
-
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment