X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=http-push.c;h=2d9441ec60222be6806eddbd5e515b2233a4f06d;hb=8c278abcbe35b23e9f93e99daf2144336fad1849;hp=40524a8593a96e83fa4e32c429034490112d1033;hpb=b3ca4e4ebba6915ea534c4b82cfc5d6f10b4c283;p=git.git diff --git a/http-push.c b/http-push.c index 40524a85..2d9441ec 100644 --- a/http-push.c +++ b/http-push.c @@ -186,6 +186,7 @@ static void process_response(void *callback_data) finish_request(request); } +#ifdef USE_CURL_MULTI static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb, void *data) { @@ -349,6 +350,41 @@ static void start_fetch_loose(struct transfer_request *request) } } +static void start_mkcol(struct transfer_request *request) +{ + char *hex = sha1_to_hex(request->obj->sha1); + struct active_request_slot *slot; + char *posn; + + request->url = xmalloc(strlen(remote->url) + 13); + strcpy(request->url, remote->url); + posn = request->url + strlen(remote->url); + strcpy(posn, "objects/"); + posn += 8; + memcpy(posn, hex, 2); + posn += 2; + strcpy(posn, "/"); + + slot = get_active_slot(); + slot->callback_func = process_response; + slot->callback_data = request; + curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1); /* undo PUT setup */ + curl_easy_setopt(slot->curl, CURLOPT_URL, request->url); + curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, request->errorstr); + curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_MKCOL); + curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null); + + if (start_active_slot(slot)) { + request->slot = slot; + request->state = RUN_MKCOL; + } else { + request->state = ABORTED; + free(request->url); + request->url = NULL; + } +} +#endif + static void start_fetch_packed(struct transfer_request *request) { char *url; @@ -438,40 +474,6 @@ static void start_fetch_packed(struct transfer_request *request) } } -static void start_mkcol(struct transfer_request *request) -{ - char *hex = sha1_to_hex(request->obj->sha1); - struct active_request_slot *slot; - char *posn; - - request->url = xmalloc(strlen(remote->url) + 13); - strcpy(request->url, remote->url); - posn = request->url + strlen(remote->url); - strcpy(posn, "objects/"); - posn += 8; - memcpy(posn, hex, 2); - posn += 2; - strcpy(posn, "/"); - - slot = get_active_slot(); - slot->callback_func = process_response; - slot->callback_data = request; - curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1); /* undo PUT setup */ - curl_easy_setopt(slot->curl, CURLOPT_URL, request->url); - curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, request->errorstr); - curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_MKCOL); - curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null); - - if (start_active_slot(slot)) { - request->slot = slot; - request->state = RUN_MKCOL; - } else { - request->state = ABORTED; - free(request->url); - request->url = NULL; - } -} - static void start_put(struct transfer_request *request) { char *hex = sha1_to_hex(request->obj->sha1); @@ -1267,8 +1269,8 @@ xml_cdata(void *userData, const XML_Char *s, int len) struct xml_ctx *ctx = (struct xml_ctx *)userData; if (ctx->cdata) free(ctx->cdata); - ctx->cdata = xcalloc(len+1, 1); - strncpy(ctx->cdata, s, len); + ctx->cdata = xmalloc(len + 1); + safe_strncpy(ctx->cdata, s, len + 1); } static struct remote_lock *lock_remote(char *path, long timeout) @@ -1470,7 +1472,7 @@ static void process_ls_object(struct remote_ls_ctx *ls) return; path += 8; obj_hex = xmalloc(strlen(path)); - strncpy(obj_hex, path, 2); + safe_strncpy(obj_hex, path, 3); strcpy(obj_hex + 2, path + 3); one_remote_object(obj_hex); free(obj_hex); @@ -2158,8 +2160,8 @@ static void fetch_symref(char *path, char **symref, unsigned char *sha1) /* If it's a symref, set the refname; otherwise try for a sha1 */ if (!strncmp((char *)buffer.buffer, "ref: ", 5)) { - *symref = xcalloc(buffer.posn - 5, 1); - strncpy(*symref, (char *)buffer.buffer + 5, buffer.posn - 6); + *symref = xmalloc(buffer.posn - 5); + safe_strncpy(*symref, (char *)buffer.buffer + 5, buffer.posn - 5); } else { get_sha1_hex(buffer.buffer, sha1); }