diff options
author | Vicent Martà <tanoku@gmail.com> | 2011-09-22 10:17:43 -0700 |
---|---|---|
committer | Vicent Martà <tanoku@gmail.com> | 2011-09-22 10:17:43 -0700 |
commit | 8114ee4c950d035388f1191081fbe77d9a9f3017 (patch) | |
tree | a1cfd43c33d8c8d56bf23d91f24bd5bb9840f24e /src/netops.c | |
parent | e1b86444676b70154bf8ab450d429bdef57a8276 (diff) | |
parent | 4ee8418a0877d1c2f48459bb266342b127fc7d87 (diff) | |
download | libgit2-8114ee4c950d035388f1191081fbe77d9a9f3017.tar.gz |
Merge pull request #405 from carlosmn/http-ls
Implement ls-remote over HTTP
Diffstat (limited to 'src/netops.c')
-rw-r--r-- | src/netops.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/netops.c b/src/netops.c index a237fae73..187397ec6 100644 --- a/src/netops.c +++ b/src/netops.c @@ -27,7 +27,7 @@ void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, int fd) memset(buf, 0x0, sizeof(gitno_buffer)); memset(data, 0x0, len); buf->data = data; - buf->len = len - 1; + buf->len = len; buf->offset = 0; buf->fd = fd; } @@ -84,6 +84,7 @@ int gitno_connect(const char *host, const char *port) ret = getaddrinfo(host, port, &hints, &info); if (ret != 0) { error = GIT_EOSERR; + info = NULL; goto cleanup; } @@ -121,7 +122,7 @@ int gitno_send(int s, const char *msg, size_t len, int flags) while (off < len) { ret = send(s, msg + off, len - off, flags); if (ret < 0) - return GIT_EOSERR; + return git__throw(GIT_EOSERR, "Error sending data: %s", strerror(errno)); off += ret; } @@ -143,3 +144,33 @@ int gitno_select_in(gitno_buffer *buf, long int sec, long int usec) /* The select(2) interface is silly */ return select(buf->fd + 1, &fds, NULL, NULL, &tv); } + +int gitno_extract_host_and_port(char **host, char **port, const char *url, const char *default_port) +{ + char *colon, *slash, *delim; + int error = GIT_SUCCESS; + + colon = strchr(url, ':'); + slash = strchr(url, '/'); + + if (slash == NULL) + return git__throw(GIT_EOBJCORRUPTED, "Malformed URL: missing /"); + + if (colon == NULL) { + *port = git__strdup(default_port); + } else { + *port = git__strndup(colon + 1, slash - colon - 1); + } + if (*port == NULL) + return GIT_ENOMEM;; + + + delim = colon == NULL ? slash : colon; + *host = git__strndup(url, delim - url); + if (*host == NULL) { + free(*port); + error = GIT_ENOMEM; + } + + return error; +} |