From: TimePath Date: Tue, 29 Mar 2016 07:24:31 +0000 (+1100) Subject: HTTP PUT/DELETE X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b1757dce70f4de393ac555c5ef79bf94597af657;p=xonotic%2Fdarkplaces.git HTTP PUT/DELETE --- diff --git a/libcurl.c b/libcurl.c index 2f001d5b..b2d4f677 100644 --- a/libcurl.c +++ b/libcurl.c @@ -46,6 +46,7 @@ CURLMcode; #define CURL_GLOBAL_WIN32 2 #define CURLOPTTYPE_LONG 0 #define CURLOPTTYPE_OBJECTPOINT 10000 +#define CURLOPTTYPE_STRINGPOINT 10000 #define CURLOPTTYPE_FUNCTIONPOINT 20000 #define CURLOPTTYPE_OFF_T 30000 #define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type + number @@ -62,6 +63,7 @@ typedef enum CINIT(LOW_SPEED_TIME, LONG, 20), CINIT(RESUME_FROM, LONG, 21), CINIT(HTTPHEADER, OBJECTPOINT, 23), + CINIT(CUSTOMREQUEST, STRINGPOINT, 36), CINIT(POST, LONG, 47), /* HTTP POST method */ CINIT(FOLLOWLOCATION, LONG, 52), /* use Location: Luke! */ CINIT(POSTFIELDSIZE, LONG, 60), @@ -223,6 +225,7 @@ typedef struct downloadinfo_s size_t postbufsize; const char *post_content_type; const char *extraheaders; + const char *verb; } downloadinfo; static downloadinfo *downloads = NULL; @@ -509,7 +512,7 @@ CURL_DOWNLOAD_FAILED or CURL_DOWNLOAD_ABORTED) and in the second case the error code from libcurl, or 0, if another error has occurred. ==================== */ -static qboolean Curl_Begin(const char *URL, const char *extraheaders, double maxspeed, const char *name, int loadtype, qboolean forthismap, const char *post_content_type, const unsigned char *postbuf, size_t postbufsize, unsigned char *buf, size_t bufsize, curl_callback_t callback, void *cbdata); +static qboolean Curl_Begin(const char *URL, const char *verb, const char *extraheaders, double maxspeed, const char *name, int loadtype, qboolean forthismap, const char *post_content_type, const unsigned char *postbuf, size_t postbufsize, unsigned char *buf, size_t bufsize, curl_callback_t callback, void *cbdata); static void Curl_EndDownload(downloadinfo *di, CurlStatus status, CURLcode error, const char *content_type_) { char content_type[64]; @@ -573,7 +576,7 @@ static void Curl_EndDownload(downloadinfo *di, CurlStatus status, CURLcode error FS_Close(di->stream); \ if(di->startpos && !di->callback) \ { \ - Curl_Begin(di->url, di->extraheaders, di->maxspeed, di->filename, di->loadtype, di->forthismap, di->post_content_type, di->postbuf, di->postbufsize, NULL, 0, NULL, NULL); \ + Curl_Begin(di->url, di->verb, di->extraheaders, di->maxspeed, di->filename, di->loadtype, di->forthismap, di->post_content_type, di->postbuf, di->postbufsize, NULL, 0, NULL, NULL); \ di->forthismap = false; \ } \ } \ @@ -756,6 +759,8 @@ static void CheckPendingDownloads(void) if(di->post_content_type) { qcurl_easy_setopt(di->curle, CURLOPT_POST, 1); + if(di->verb) + qcurl_easy_setopt(di->curle, CURLOPT_CUSTOMREQUEST, di->verb); qcurl_easy_setopt(di->curle, CURLOPT_POSTFIELDS, di->postbuf); qcurl_easy_setopt(di->curle, CURLOPT_POSTFIELDSIZE, di->postbufsize); di->slist = qcurl_slist_append(di->slist, va(vabuf, sizeof(vabuf), "Content-Type: %s", di->post_content_type)); @@ -875,7 +880,7 @@ Starts a download of a given URL to the file name portion of this URL (or name if given) in the "dlcache/" folder. ==================== */ -static qboolean Curl_Begin(const char *URL, const char *extraheaders, double maxspeed, const char *name, int loadtype, qboolean forthismap, const char *post_content_type, const unsigned char *postbuf, size_t postbufsize, unsigned char *buf, size_t bufsize, curl_callback_t callback, void *cbdata) +static qboolean Curl_Begin(const char *URL, const char *verb, const char *extraheaders, double maxspeed, const char *name, int loadtype, qboolean forthismap, const char *post_content_type, const unsigned char *postbuf, size_t postbufsize, unsigned char *buf, size_t bufsize, curl_callback_t callback, void *cbdata) { if(buf) if(loadtype != LOADTYPE_NONE) @@ -1067,6 +1072,7 @@ static qboolean Curl_Begin(const char *URL, const char *extraheaders, double max di->bytes_received_curl = 0; di->bytes_sent_curl = 0; di->extraheaders = extraheaders; + di->verb = verb; di->next = downloads; di->prev = NULL; if(di->next) @@ -1106,15 +1112,15 @@ static qboolean Curl_Begin(const char *URL, const char *extraheaders, double max qboolean Curl_Begin_ToFile(const char *URL, double maxspeed, const char *name, int loadtype, qboolean forthismap) { - return Curl_Begin(URL, NULL, maxspeed, name, loadtype, forthismap, NULL, NULL, 0, NULL, 0, NULL, NULL); + return Curl_Begin(URL, NULL, NULL, maxspeed, name, loadtype, forthismap, NULL, NULL, 0, NULL, 0, NULL, NULL); } qboolean Curl_Begin_ToMemory(const char *URL, double maxspeed, unsigned char *buf, size_t bufsize, curl_callback_t callback, void *cbdata) { - return Curl_Begin(URL, NULL, maxspeed, NULL, false, false, NULL, NULL, 0, buf, bufsize, callback, cbdata); + return Curl_Begin(URL, NULL, NULL, maxspeed, NULL, false, false, NULL, NULL, 0, buf, bufsize, callback, cbdata); } -qboolean Curl_Begin_ToMemory_POST(const char *URL, const char *extraheaders, double maxspeed, const char *post_content_type, const unsigned char *postbuf, size_t postbufsize, unsigned char *buf, size_t bufsize, curl_callback_t callback, void *cbdata) +qboolean Curl_Begin_ToMemory_POST(const char *URL, const char *verb, const char *extraheaders, double maxspeed, const char *post_content_type, const unsigned char *postbuf, size_t postbufsize, unsigned char *buf, size_t bufsize, curl_callback_t callback, void *cbdata) { - return Curl_Begin(URL, extraheaders, maxspeed, NULL, false, false, post_content_type, postbuf, postbufsize, buf, bufsize, callback, cbdata); + return Curl_Begin(URL, verb, extraheaders, maxspeed, NULL, false, false, post_content_type, postbuf, postbufsize, buf, bufsize, callback, cbdata); } /* diff --git a/libcurl.h b/libcurl.h index 15bf019b..df1717d5 100644 --- a/libcurl.h +++ b/libcurl.h @@ -14,7 +14,7 @@ qboolean Curl_Running(void); qboolean Curl_Begin_ToFile(const char *URL, double maxspeed, const char *name, int loadtype, qboolean forthismap); qboolean Curl_Begin_ToMemory(const char *URL, double maxspeed, unsigned char *buf, size_t bufsize, curl_callback_t callback, void *cbdata); -qboolean Curl_Begin_ToMemory_POST(const char *URL, const char *extraheaders, double maxspeed, const char *post_content_type, const unsigned char *postbuf, size_t postbufsize, unsigned char *buf, size_t bufsize, curl_callback_t callback, void *cbdata); +qboolean Curl_Begin_ToMemory_POST(const char *URL, const char *verb, const char *extraheaders, double maxspeed, const char *post_content_type, const unsigned char *postbuf, size_t postbufsize, unsigned char *buf, size_t bufsize, curl_callback_t callback, void *cbdata); void Curl_Cancel_ToMemory(curl_callback_t callback, void* cbdata); void Curl_Init(void); diff --git a/prvm_cmds.c b/prvm_cmds.c index e2b023e2..f02e2adf 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -6202,6 +6202,7 @@ void VM_uri_get (prvm_prog_t *prog) uri_to_prog_t *handle; const char *posttype = NULL; const char *postseparator = NULL; + const char *verb = NULL; int poststringbuffer = -1; int postkeyid = -1; const char *query_string = NULL; @@ -6217,7 +6218,16 @@ void VM_uri_get (prvm_prog_t *prog) if(prog->argc >= 3) posttype = PRVM_G_STRING(OFS_PARM2); if(prog->argc >= 4) - postseparator = PRVM_G_STRING(OFS_PARM3); + { + const char *s = PRVM_G_STRING(OFS_PARM3); + postseparator = ""; + if(strcmp(s, "PUT") == 0) + verb = "PUT"; + else if(strcmp(s, "DELETE") == 0) + verb = "DELETE"; + else + postseparator = PRVM_G_STRING(OFS_PARM3); + } if(prog->argc >= 5) poststringbuffer = PRVM_G_FLOAT(OFS_PARM4); if(prog->argc >= 6) @@ -6309,7 +6319,7 @@ void VM_uri_get (prvm_prog_t *prog) } out1: strlcpy(handle->posttype, posttype, sizeof(handle->posttype)); - ret = Curl_Begin_ToMemory_POST(url, handle->sigdata, 0, handle->posttype, handle->postdata, handle->postlen, (unsigned char *) handle->buffer, sizeof(handle->buffer), uri_to_string_callback, handle); + ret = Curl_Begin_ToMemory_POST(url, verb, handle->sigdata, 0, handle->posttype, handle->postdata, handle->postlen, (unsigned char *) handle->buffer, sizeof(handle->buffer), uri_to_string_callback, handle); } else { @@ -6340,7 +6350,7 @@ out1: out2: handle->postdata = NULL; handle->postlen = 0; - ret = Curl_Begin_ToMemory_POST(url, handle->sigdata, 0, NULL, NULL, 0, (unsigned char *) handle->buffer, sizeof(handle->buffer), uri_to_string_callback, handle); + ret = Curl_Begin_ToMemory_POST(url, NULL, handle->sigdata, 0, NULL, NULL, 0, (unsigned char *) handle->buffer, sizeof(handle->buffer), uri_to_string_callback, handle); } if(ret) {