diff options
author | Maximilian Wuttke <mwuttke97@posteo.de> | 2021-03-10 17:26:38 +0100 |
---|---|---|
committer | Maximilian Wuttke <mwuttke97@posteo.de> | 2021-03-11 17:11:22 +0100 |
commit | e217ed0b798706fd11d19f1ffc0bdbbb95d55f53 (patch) | |
tree | e28734730ffce8996bfb6d4be95e7a08790491cc /src/tools | |
parent | 96580f917b5c0a061e7bf41714cf48c8e89cd5f8 (diff) | |
download | profani-tty-e217ed0b798706fd11d19f1ffc0bdbbb95d55f53.tar.gz |
Update to the newest version of XEP 0363 (HTTP Upload)
Main changes: 1. Attributes instead of tags 2. Read the optional <header> tags and send them in the HTTP PUT header: * Authorization * Cookie * Expires Co-authored-by: Martin Dosch <martin@mdosch.de>
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/http_upload.c | 27 | ||||
-rw-r--r-- | src/tools/http_upload.h | 5 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/tools/http_upload.c b/src/tools/http_upload.c index fcdd582a..ff72e1b9 100644 --- a/src/tools/http_upload.c +++ b/src/tools/http_upload.c @@ -166,6 +166,10 @@ http_file_put(void* userdata) char* err = NULL; char* content_type_header; + // Optional headers + char* auth_header = NULL; + char* cookie_header = NULL; + char* expires_header = NULL; CURL* curl; CURLcode res; @@ -196,6 +200,21 @@ http_file_put(void* userdata) } headers = curl_slist_append(headers, content_type_header); headers = curl_slist_append(headers, "Expect:"); + + // Optional headers + if (upload->authorization) { + asprintf(&auth_header, "Authorization: %s", upload->authorization); + headers = curl_slist_append(headers, auth_header); + } + if (upload->cookie) { + asprintf(&cookie_header, "Cookie: %s", upload->cookie); + headers = curl_slist_append(headers, cookie_header); + } + if (upload->expires) { + asprintf(&expires_header, "Expires: %s", upload->expires); + headers = curl_slist_append(headers, expires_header); + } + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); #if LIBCURL_VERSION_NUM >= 0x072000 @@ -225,6 +244,7 @@ http_file_put(void* userdata) curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)(upload->filesize)); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); + if ((res = curl_easy_perform(curl)) != CURLE_OK) { err = strdup(curl_easy_strerror(res)); } else { @@ -252,11 +272,15 @@ http_file_put(void* userdata) curl_easy_cleanup(curl); curl_global_cleanup(); curl_slist_free_all(headers); + if (fh) { fclose(fh); } free(content_type_header); free(output.buffer); + free(auth_header); + free(cookie_header); + free(expires_header); pthread_mutex_lock(&lock); g_free(cert_path); @@ -334,6 +358,9 @@ http_file_put(void* userdata) free(upload->put_url); free(upload->alt_scheme); free(upload->alt_fragment); + free(upload->authorization); + free(upload->cookie); + free(upload->expires); free(upload); return NULL; diff --git a/src/tools/http_upload.h b/src/tools/http_upload.h index 4e95d4d8..06145a43 100644 --- a/src/tools/http_upload.h +++ b/src/tools/http_upload.h @@ -59,6 +59,11 @@ typedef struct http_upload_t ProfWin* window; pthread_t worker; int cancel; + // Additional headers + // (NULL if they shouldn't be send in the PUT) + char* authorization; + char* cookie; + char* expires; } HTTPUpload; void* http_file_put(void* userdata); |