diff options
| author | Ben Straub <bs@github.com> | 2013-01-30 19:03:58 -0800 |
|---|---|---|
| committer | Ben Straub <bs@github.com> | 2013-01-30 19:03:58 -0800 |
| commit | 2234b2b03153c03fc6d502dd61ae55e659be4b8b (patch) | |
| tree | f3ebc65392fa5c94c3c11c809688454f51f64c48 | |
| parent | 5f10853e90014ea9929a976f647f2a2d32a2c129 (diff) | |
| download | libgit2-2234b2b03153c03fc6d502dd61ae55e659be4b8b.tar.gz | |
Stash username from url (but don't use it yet)
| -rw-r--r-- | src/netops.c | 9 | ||||
| -rw-r--r-- | src/netops.h | 2 | ||||
| -rw-r--r-- | src/transports/git.c | 10 | ||||
| -rw-r--r-- | src/transports/http.c | 3 | ||||
| -rw-r--r-- | src/transports/winhttp.c | 2 |
5 files changed, 17 insertions, 9 deletions
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); diff --git a/src/netops.h b/src/netops.h index f8ff42c40..bb2624abe 100644 --- a/src/netops.h +++ b/src/netops.h @@ -66,6 +66,6 @@ int gitno_send(gitno_socket *socket, const char *msg, size_t len, int flags); int gitno_close(gitno_socket *s); 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); +int gitno_extract_host_and_port(char **host, char **port, char **username, const char *url, const char *default_port); #endif diff --git a/src/transports/git.c b/src/transports/git.c index ba6dbfea9..5c816e127 100644 --- a/src/transports/git.c +++ b/src/transports/git.c @@ -179,7 +179,7 @@ static int _git_uploadpack_ls( const char *url, git_smart_subtransport_stream **stream) { - char *host, *port; + char *host, *port, *user; git_stream *s; *stream = NULL; @@ -192,7 +192,7 @@ static int _git_uploadpack_ls( s = (git_stream *)*stream; - if (gitno_extract_host_and_port(&host, &port, url, GIT_DEFAULT_PORT) < 0) + if (gitno_extract_host_and_port(&host, &port, &user, url, GIT_DEFAULT_PORT) < 0) goto on_error; if (gitno_connect(&s->socket, host, port, 0) < 0) @@ -201,6 +201,7 @@ static int _git_uploadpack_ls( t->current_stream = s; git__free(host); git__free(port); + git__free(user); return 0; on_error: @@ -233,7 +234,7 @@ static int _git_receivepack_ls( const char *url, git_smart_subtransport_stream **stream) { - char *host, *port; + char *host, *port, *user; git_stream *s; *stream = NULL; @@ -246,7 +247,7 @@ static int _git_receivepack_ls( s = (git_stream *)*stream; - if (gitno_extract_host_and_port(&host, &port, url, GIT_DEFAULT_PORT) < 0) + if (gitno_extract_host_and_port(&host, &port, &user, url, GIT_DEFAULT_PORT) < 0) goto on_error; if (gitno_connect(&s->socket, host, port, 0) < 0) @@ -255,6 +256,7 @@ static int _git_receivepack_ls( t->current_stream = s; git__free(host); git__free(port); + git__free(user); return 0; on_error: diff --git a/src/transports/http.c b/src/transports/http.c index 96a9c3942..e5bb1071f 100644 --- a/src/transports/http.c +++ b/src/transports/http.c @@ -60,6 +60,7 @@ typedef struct { const char *path; char *host; char *port; + char *user_from_url; git_cred *cred; http_authmechanism_t auth_mechanism; unsigned connected : 1, @@ -742,7 +743,7 @@ static int http_action( if (!default_port) return -1; - if ((ret = gitno_extract_host_and_port(&t->host, &t->port, + if ((ret = gitno_extract_host_and_port(&t->host, &t->port, &t->user_from_url, url, default_port)) < 0) return ret; diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c index 808f6afaa..544e52f4d 100644 --- a/src/transports/winhttp.c +++ b/src/transports/winhttp.c @@ -788,7 +788,7 @@ static int winhttp_connect( t->use_ssl = 1; } - if ((ret = gitno_extract_host_and_port(&t->host, &t->port, url, default_port)) < 0) + if ((ret = gitno_extract_host_and_port(&t->host, &t->port, &t->parent.user_from_url, url, default_port)) < 0) return ret; t->path = strchr(url, '/'); |
