mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-23 05:38:41 +00:00
transport-git: Encapsulation ist gut
This commit is contained in:
parent
657ce4b5b6
commit
10063aeb41
@ -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)
|
|||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user