summaryrefslogtreecommitdiff
path: root/src/netops.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-02-04 14:49:28 -0800
committerRussell Belfer <rb@github.com>2013-02-04 14:49:28 -0800
commitde81aee3907e3737ad87e88e14b702f4b3bf12a6 (patch)
treee3c8c35378bf5c4c5f922b39d3dc168d1657097e /src/netops.c
parent3261a3e980b00cf19b971c078d09bc0660ce1f81 (diff)
parent630146bd1b71cbb450f1fe658048ca8e25479105 (diff)
downloadlibgit2-de81aee3907e3737ad87e88e14b702f4b3bf12a6.tar.gz
Merge pull request #1298 from ben/user-at
Handle "user@" prefix for credentials partially included in URLs
Diffstat (limited to 'src/netops.c')
-rw-r--r--src/netops.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/netops.c b/src/netops.c
index fd83a1cc3..69179dd1c 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -577,27 +577,54 @@ 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_url_parts(
+ char **host,
+ char **port,
+ char **username,
+ char **password,
+ const char *url,
+ const char *default_port)
{
- char *colon, *slash, *delim;
+ char *colon, *slash, *at, *end;
+ const char *start;
+
+ /*
+ *
+ * ==> [user[:pass]@]hostname.tld[:port]/resource
+ */
colon = strchr(url, ':');
slash = strchr(url, '/');
+ at = strchr(url, '@');
if (slash == NULL) {
giterr_set(GITERR_NET, "Malformed URL: missing /");
return -1;
}
+ start = url;
+ if (at && at < slash) {
+ start = at+1;
+ *username = git__substrdup(url, at - url);
+ }
+
+ if (colon && colon < at) {
+ git__free(*username);
+ *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);
- delim = colon == NULL ? slash : colon;
- *host = git__strndup(url, delim - url);
+ end = colon == NULL ? slash : colon;
+
+ *host = git__substrdup(start, end - start);
GITERR_CHECK_ALLOC(*host);
return 0;