diff options
author | jak1 <jak1@themanaworld.org> | 2023-04-07 03:04:54 +0200 |
---|---|---|
committer | jak1 <jak1@themanaworld.org> | 2023-04-07 03:04:54 +0200 |
commit | f683acc05a4edf5ae95a72d3ecffc7ed7c6b248f (patch) | |
tree | f8293378ef2f6fc8cf553ecbb0c27ac98d415886 /src | |
parent | 5858b44f42c76e698a4806f874f8cbaa1c64abaf (diff) | |
download | plus-f683acc05a4edf5ae95a72d3ecffc7ed7c6b248f.tar.gz plus-f683acc05a4edf5ae95a72d3ecffc7ed7c6b248f.tar.bz2 plus-f683acc05a4edf5ae95a72d3ecffc7ed7c6b248f.tar.xz plus-f683acc05a4edf5ae95a72d3ecffc7ed7c6b248f.zip |
fixed curl deprecation
Diffstat (limited to 'src')
-rw-r--r-- | src/net/download.cpp | 53 | ||||
-rw-r--r-- | src/net/download.h | 7 |
2 files changed, 49 insertions, 11 deletions
diff --git a/src/net/download.cpp b/src/net/download.cpp index a8ee03f77..0c0008d0e 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -70,7 +70,11 @@ Download::Download(void *const ptr, mThread(nullptr), mCurl(nullptr), mHeaders(nullptr), +#if LIBCURL_VERSION_NUM < 0x073800 mFormPost(nullptr), +#else + mMime(nullptr), +#endif // LIBCURL_VERSION_NUM < 0x073800 mError(static_cast<char*>(calloc(CURL_ERROR_SIZE + 1, 1))), mIgnoreError(ignoreError), mUpload(isUpload), @@ -99,11 +103,20 @@ Download::Download(void *const ptr, Download::~Download() { +#if LIBCURL_VERSION_NUM < 0x073800 if (mFormPost != nullptr) { curl_formfree(mFormPost); mFormPost = nullptr; } +#else + if (mMime != nullptr) + { + curl_mime_free(mMime); + mMime = nullptr; + } +#endif // LIBCURL_VERSION_NUM < 0x073800 + if (mHeaders != nullptr) { @@ -256,7 +269,7 @@ int Download::downloadThread(void *ptr) if (d->mUpload) { outFilename = d->mFileName; - prepareForm(&d->mFormPost, outFilename); + prepareForm(d, outFilename); } else { @@ -297,7 +310,11 @@ int Download::downloadThread(void *ptr) { logger->log_r("Uploading: %s", d->mUrl.c_str()); curl_easy_setopt(d->mCurl, CURLOPT_URL, d->mUrl.c_str()); +#if LIBCURL_VERSION_NUM < 0x073800 curl_easy_setopt(d->mCurl, CURLOPT_HTTPPOST, d->mFormPost); +#else + curl_easy_setopt(d->mCurl, CURLOPT_MIMEPOST, d->mMime); +#endif // LIBCURL_VERSION_NUM < 0x073800 curl_easy_setopt(d->mCurl, CURLOPT_WRITEFUNCTION, &Download::writeFunction); mUploadResponse.clear(); @@ -336,12 +353,18 @@ int Download::downloadThread(void *ptr) curl_easy_setopt(d->mCurl, CURLOPT_ERRORBUFFER, d->mError); curl_easy_setopt(d->mCurl, CURLOPT_URL, d->mUrl.c_str()); curl_easy_setopt(d->mCurl, CURLOPT_NOPROGRESS, 0); +#if LIBCURL_VERSION_NUM < 0x072000 curl_easy_setopt(d->mCurl, CURLOPT_PROGRESSFUNCTION, - &downloadProgress); + &downloadProgress); +#else + curl_easy_setopt(d->mCurl, CURLOPT_XFERINFOFUNCTION, + &downloadProgress); + +#endif // LIBCURL_VERSION_NUM < 0x072000 curl_easy_setopt(d->mCurl, CURLOPT_PROGRESSDATA, ptr); #if LIBCURL_VERSION_NUM >= 0x070a00 curl_easy_setopt(d->mCurl, CURLOPT_NOSIGNAL, 1); -#endif // LIBCURL_VERSION_NUM >= 0x070a00 +#endif // LIBCURL_VERSION_NUM >= 0x070a00 curl_easy_setopt(d->mCurl, CURLOPT_CONNECTTIMEOUT, 30); curl_easy_setopt(d->mCurl, CURLOPT_TIMEOUT, 1800); addHeaders(d->mCurl); @@ -578,12 +601,18 @@ void Download::secureCurl(CURL *const curl) void Download::secureCurl(CURL *const curl A_UNUSED) #endif // LIBCURL_VERSION_NUM >= 0x070f01 { -#if LIBCURL_VERSION_NUM >= 0x071304 +#if LIBCURL_VERSION_NUM >= 0x071304 && LIBCURL_VERSION_NUM <= 0x075500 curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); -#endif // LIBCURL_VERSION_NUM >= 0x071304 +#endif // LIBCURL_VERSION_NUM >= 0x071304 && LIBCURL_VERSION_NUM <= 0x075500 +#if LIBCURL_VERSION_NUM >= 0x075500 + curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, + "http,https"); + curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS_STR, + "http,https"); +#endif // LIBCURL_VERSION_NUM >= 0x075500 #if LIBCURL_VERSION_NUM >= 0x071500 curl_easy_setopt(curl, CURLOPT_WILDCARDMATCH, 0); #endif // LIBCURL_VERSION_NUM >= 0x071500 @@ -622,10 +651,8 @@ void Download::addCommonFlags(CURL *const curl) #endif // LIBCURL_VERSION_NUM >= 0x072D00 } -void Download::prepareForm(curl_httppost **form, const std::string &fileName) +void Download::prepareForm(Download *const d, const std::string &fileName) { - curl_httppost *lastPtr = nullptr; - std::ifstream file; file.open(fileName.c_str(), std::ios::in); if (!file.is_open()) @@ -638,10 +665,18 @@ void Download::prepareForm(curl_httppost **form, const std::string &fileName) delete [] line; - curl_formadd(form, &lastPtr, +#if LIBCURL_VERSION_NUM < 0x073800 + curl_httppost *lastPtr = nullptr; + curl_formadd(&d->mFormPost, &lastPtr, CURLFORM_COPYNAME, "f:1", CURLFORM_COPYCONTENTS, str.str().c_str(), CURLFORM_END); +#else + curl_mimepart *part = curl_mime_addpart(d->mMime); + curl_mime_init(d->mCurl); + curl_mime_name(part, "f:1"); + curl_mime_data(part, str.str().c_str(), str.str().length()); +#endif } size_t Download::writeFunction(void *ptr, diff --git a/src/net/download.h b/src/net/download.h index 75dcf9b4b..c838943b7 100644 --- a/src/net/download.h +++ b/src/net/download.h @@ -95,8 +95,7 @@ class Download final static size_t writeFunction(void *ptr, size_t size, size_t nmemb, void *stream); - static void prepareForm(curl_httppost **form, - const std::string &fileName); + static void prepareForm(Download *const d, const std::string &fileName); static unsigned long fadler32(FILE *const file) A_WARN_UNUSED; @@ -135,7 +134,11 @@ class Download final SDL_Thread *mThread; CURL *mCurl; curl_slist *mHeaders; +#if LIBCURL_VERSION_NUM < 0x073800 curl_httppost *mFormPost; +#else + curl_mime *mMime; +#endif char *mError; bool mIgnoreError; bool mUpload; |