Commit 10063aeb by Vicent Marti

transport-git: Encapsulation ist gut

parent 657ce4b5
...@@ -36,13 +36,12 @@ typedef struct { ...@@ -36,13 +36,12 @@ typedef struct {
* *
* For example: 0035git-upload-pack /libgit2/libgit2\0host=github.com\0 * For example: 0035git-upload-pack /libgit2/libgit2\0host=github.com\0
*/ */
static int gen_proto(char **out, int *outlen, const char *cmd, const char *url) static int gen_proto(git_buf *request, const char *cmd, const char *url)
{ {
char *delim, *repo; char *delim, *repo;
char default_command[] = "git-upload-pack"; char default_command[] = "git-upload-pack";
char host[] = "host="; char host[] = "host=";
int len; int len;
git_buf buf = GIT_BUF_INIT;
delim = strchr(url, '/'); delim = strchr(url, '/');
if (delim == NULL) if (delim == NULL)
...@@ -59,31 +58,27 @@ static int gen_proto(char **out, int *outlen, const char *cmd, const char *url) ...@@ -59,31 +58,27 @@ static int gen_proto(char **out, int *outlen, const char *cmd, const char *url)
len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 1 + 1; len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 1 + 1;
git_buf_grow(&buf, len); git_buf_grow(request, len);
git_buf_printf(request, "%04x%s %s%c%s", len, cmd, repo, 0, host);
git_buf_put(request, url, delim - url);
git_buf_putc(request, '\0');
git_buf_printf(&buf, "%04x%s %s%c%s", len, cmd, repo, 0, host); return git_buf_oom(request);
git_buf_put(&buf, url, delim - url);
git_buf_putc(&buf, '\0');
*outlen = len;
*out = buf.ptr;
return GIT_SUCCESS;
} }
static int send_request(GIT_SOCKET s, const char *cmd, const char *url) static int send_request(GIT_SOCKET s, const char *cmd, const char *url)
{ {
int error, len; int error;
char *msg = NULL; git_buf request = GIT_BUF_INIT;
error = gen_proto(&msg, &len, cmd, url); error = gen_proto(&request, cmd, url);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
goto cleanup; goto cleanup;
error = gitno_send(s, msg, len, 0); error = gitno_send(s, request.ptr, request.size, 0);
cleanup: cleanup:
free(msg); git_buf_free(&request);
return error; return error;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment