From 5f10853e90014ea9929a976f647f2a2d32a2c129 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Wed, 30 Jan 2013 18:50:31 -0800 Subject: Skip "user@" when finding hostname in url --- src/netops.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/netops.c') diff --git a/src/netops.c b/src/netops.c index 59e6bda1e..5623ca9bf 100644 --- a/src/netops.c +++ b/src/netops.c @@ -580,10 +580,12 @@ int gitno_select_in(gitno_buffer *buf, long int sec, long int usec) int gitno_extract_host_and_port(char **host, char **port, const char *url, const char *default_port) { - char *colon, *slash, *delim; + char *colon, *slash, *at, *delim; + const char *start; colon = strchr(url, ':'); slash = strchr(url, '/'); + at = strchr(url, '@'); if (slash == NULL) { giterr_set(GITERR_NET, "Malformed URL: missing /"); @@ -598,7 +600,9 @@ int gitno_extract_host_and_port(char **host, char **port, const char *url, const GITERR_CHECK_ALLOC(*port); delim = colon == NULL ? slash : colon; - *host = git__strndup(url, delim - url); + start = at == NULL && at < slash ? url : at+1; + + *host = git__strndup(start, delim - start); GITERR_CHECK_ALLOC(*host); return 0; -- cgit v1.2.1 From 2234b2b03153c03fc6d502dd61ae55e659be4b8b Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Wed, 30 Jan 2013 19:03:58 -0800 Subject: Stash username from url (but don't use it yet) --- src/netops.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/netops.c') diff --git a/src/netops.c b/src/netops.c index 5623ca9bf..12738141f 100644 --- a/src/netops.c +++ b/src/netops.c @@ -578,7 +578,7 @@ int gitno_select_in(gitno_buffer *buf, long int sec, long int usec) return select((int)buf->socket->socket + 1, &fds, NULL, NULL, &tv); } -int gitno_extract_host_and_port(char **host, char **port, const char *url, const char *default_port) +int gitno_extract_host_and_port(char **host, char **port, char **username, const char *url, const char *default_port) { char *colon, *slash, *at, *delim; const char *start; @@ -600,7 +600,12 @@ int gitno_extract_host_and_port(char **host, char **port, const char *url, const GITERR_CHECK_ALLOC(*port); delim = colon == NULL ? slash : colon; - start = at == NULL && at < slash ? url : at+1; + + start = url; + if (at && at < slash) { + start = at+1; + *username = git__strndup(url, at - url); + } *host = git__strndup(start, delim - start); GITERR_CHECK_ALLOC(*host); -- cgit v1.2.1 From cf7038a65cb080a2946202fe6cbbe52aefae1fd4 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Thu, 31 Jan 2013 14:04:21 -0800 Subject: Enhance url parsing to include passwords --- src/netops.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src/netops.c') diff --git a/src/netops.c b/src/netops.c index 12738141f..fd788bc1d 100644 --- a/src/netops.c +++ b/src/netops.c @@ -578,11 +578,22 @@ int gitno_select_in(gitno_buffer *buf, long int sec, long int usec) return select((int)buf->socket->socket + 1, &fds, NULL, NULL, &tv); } -int gitno_extract_host_and_port(char **host, char **port, char **username, const char *url, const char *default_port) +int gitno_extract_url_parts( + char **host, + char **port, + char **username, + char **password, + const char *url, + const char *default_port) { - char *colon, *slash, *at, *delim; + char *colon, *slash, *at, *end; const char *start; + /* + * + * ==> [user[:pass]@]hostname.tld[:port]/resource + */ + colon = strchr(url, ':'); slash = strchr(url, '/'); at = strchr(url, '@'); @@ -592,6 +603,19 @@ int gitno_extract_host_and_port(char **host, char **port, char **username, const return -1; } + start = url; + if (at && at < slash) { + start = at+1; + *username = git__strndup(url, at - url); + } + + if (colon && colon < at) { + git__free(*username); + *username = git__strndup(url, colon-url); + *password = git__strndup(colon+1, at-colon-1); + colon = strchr(at, ':'); + } + if (colon == NULL) { *port = git__strdup(default_port); } else { @@ -599,15 +623,9 @@ int gitno_extract_host_and_port(char **host, char **port, char **username, const } GITERR_CHECK_ALLOC(*port); - delim = colon == NULL ? slash : colon; - - start = url; - if (at && at < slash) { - start = at+1; - *username = git__strndup(url, at - url); - } + end = colon == NULL ? slash : colon; - *host = git__strndup(start, delim - start); + *host = git__strndup(start, end - start); GITERR_CHECK_ALLOC(*host); return 0; -- cgit v1.2.1 From c4beee768135f70b91b2c0bfa1dbc99a58c1f311 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Fri, 1 Feb 2013 10:00:55 -0800 Subject: Introduce git__substrdup --- src/netops.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/netops.c') diff --git a/src/netops.c b/src/netops.c index fd788bc1d..cc94d0350 100644 --- a/src/netops.c +++ b/src/netops.c @@ -606,26 +606,26 @@ int gitno_extract_url_parts( start = url; if (at && at < slash) { start = at+1; - *username = git__strndup(url, at - url); + *username = git__substrdup(url, at - url); } if (colon && colon < at) { git__free(*username); - *username = git__strndup(url, colon-url); - *password = git__strndup(colon+1, at-colon-1); + *username = git__substrdup(url, colon-url); + *password = git__substrdup(colon+1, at-colon-1); colon = strchr(at, ':'); } if (colon == NULL) { *port = git__strdup(default_port); } else { - *port = git__strndup(colon + 1, slash - colon - 1); + *port = git__substrdup(colon + 1, slash - colon - 1); } GITERR_CHECK_ALLOC(*port); end = colon == NULL ? slash : colon; - *host = git__strndup(start, end - start); + *host = git__substrdup(start, end - start); GITERR_CHECK_ALLOC(*host); return 0; -- cgit v1.2.1