mirror of
https://git.proxmox.com/git/libgit2
synced 2026-01-03 03:18:56 +00:00
Stash username from url (but don't use it yet)
This commit is contained in:
parent
5f10853e90
commit
2234b2b031
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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, '/');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user