summaryrefslogtreecommitdiff
path: root/src/netops.c
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2013-01-31 14:04:21 -0800
committerBen Straub <bs@github.com>2013-01-31 14:04:21 -0800
commitcf7038a65cb080a2946202fe6cbbe52aefae1fd4 (patch)
tree379e3be397c781f7af8e06d89f4fb024bd8c05db /src/netops.c
parent7602cb7c0ea0d69efd30640af234be20393bf57c (diff)
downloadlibgit2-cf7038a65cb080a2946202fe6cbbe52aefae1fd4.tar.gz
Enhance url parsing to include passwords
Diffstat (limited to 'src/netops.c')
-rw-r--r--src/netops.c38
1 files changed, 28 insertions, 10 deletions
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;