From 2a219b342e8e2ff2354ac6dd96e73c3242899d93 Mon Sep 17 00:00:00 2001 From: GetAway Date: Thu, 12 Jan 2023 21:08:40 +0100 Subject: [PATCH] fix for newer libcurl --- src/gui/lua/lua_curl.cpp | 12 ++++++++++-- src/gui/lua/lua_curl.h | 2 +- src/system/helpers.cpp | 4 ++++ src/system/httptool.cpp | 21 ++++++++++++++++++--- src/system/httptool.h | 6 +++++- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/gui/lua/lua_curl.cpp b/src/gui/lua/lua_curl.cpp index 88f01cc9a..cb9d49fea 100644 --- a/src/gui/lua/lua_curl.cpp +++ b/src/gui/lua/lua_curl.cpp @@ -98,7 +98,11 @@ int CLuaInstCurl::CurlProgressFunc(void *p, curl_off_t dltotal, curl_off_t dlnow double dlSpeed; long responseCode = 0; +#if CURL_AT_LEAST_VERSION( 7,55,0 ) + curl_easy_getinfo(_pgd->curl, CURLINFO_SPEED_DOWNLOAD_T, &dlSpeed); +#else curl_easy_getinfo(_pgd->curl, CURLINFO_SPEED_DOWNLOAD, &dlSpeed); +#endif curl_easy_getinfo(_pgd->curl, CURLINFO_RESPONSE_CODE, &responseCode); uint32_t MUL = 0x7FFF; @@ -124,7 +128,7 @@ int CLuaInstCurl::CurlProgressFunc(void *p, curl_off_t dltotal, curl_off_t dlnow return 0; } -#if LIBCURL_VERSION_NUM < 0x072000 +#if !CURL_AT_LEAST_VERSION( 7,32,0 ) int CLuaInstCurl::CurlProgressFunc_old(void *p, double dltotal, double dlnow, double ultotal, double ulnow) { return CurlProgressFunc(p, (curl_off_t)dltotal, (curl_off_t)dlnow, (curl_off_t)ultotal, (curl_off_t)ulnow); @@ -324,7 +328,7 @@ Example: if (!silent) { pgd.curl = curl_handle; pgd.last_dlnow = -1; -#if LIBCURL_VERSION_NUM >= 0x072000 +#if CURL_AT_LEAST_VERSION( 7,32,0 ) curl_easy_setopt(curl_handle, CURLOPT_XFERINFOFUNCTION, CLuaInstCurl::CurlProgressFunc); curl_easy_setopt(curl_handle, CURLOPT_XFERINFODATA, &pgd); #else @@ -349,7 +353,11 @@ Example: if (!silent) { double dsize, dtime; char *dredirect=NULL, *deffektive=NULL; +#if CURL_AT_LEAST_VERSION( 7,55,0 ) + curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD_T, &dsize); +#else curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD, &dsize); +#endif curl_easy_getinfo(curl_handle, CURLINFO_TOTAL_TIME, &dtime); CURLcode res1 = curl_easy_getinfo(curl_handle, CURLINFO_EFFECTIVE_URL, &deffektive); CURLcode res2 = curl_easy_getinfo(curl_handle, CURLINFO_REDIRECT_URL, &dredirect); diff --git a/src/gui/lua/lua_curl.h b/src/gui/lua/lua_curl.h index f3a077856..abb22f365 100644 --- a/src/gui/lua/lua_curl.h +++ b/src/gui/lua/lua_curl.h @@ -53,7 +53,7 @@ class CLuaInstCurl static CLuaCurl *CurlCheckData(lua_State *L, int n); static int CurlNew(lua_State *L); static size_t CurlWriteToString(void *ptr, size_t size, size_t nmemb, void *data); -#if LIBCURL_VERSION_NUM < 0x072000 +#if !CURL_AT_LEAST_VERSION( 7,32,0 ) static int CurlProgressFunc_old(void *p, double dltotal, double dlnow, double ultotal, double ulnow); #endif static int CurlProgressFunc(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow); diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index f1bbf0f43..12fa6b4a6 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -1866,7 +1866,11 @@ bool downloadUrl(std::string url, std::string file, std::string userAgent, unsig CURLcode httpres = curl_easy_perform(curl_handle); double dsize; +#if CURL_AT_LEAST_VERSION( 7,55,0 ) + curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD_T, &dsize); +#else curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD, &dsize); +#endif curl_easy_cleanup(curl_handle); fclose(fp); diff --git a/src/system/httptool.cpp b/src/system/httptool.cpp index 429f590d1..1f39b5f08 100644 --- a/src/system/httptool.cpp +++ b/src/system/httptool.cpp @@ -51,7 +51,7 @@ size_t CHTTPTool::CurlWriteToString(void *ptr, size_t size, size_t nmemb, void * return size*nmemb; } -int CHTTPTool::show_progress( void *clientp, double dltotal, double dlnow, double /*ultotal*/, double /*ulnow*/ ) +int CHTTPTool::show_progress(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t /*ultotal*/, curl_off_t /*ulnow*/) { CHTTPTool* hTool = ((CHTTPTool*)clientp); if(hTool->statusViewer) @@ -66,6 +66,13 @@ int CHTTPTool::show_progress( void *clientp, double dltotal, double dlnow, doubl } return 0; } +#if !CURL_AT_LEAST_VERSION( 7,32,0 ) +int CHTTPTool::show_progress_old(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) +{ + return show_progress(clientp, (curl_off_t)dltotal, (curl_off_t)dlnow, (curl_off_t)ultotal , (curl_off_t)ulnow); +} +#endif + //#define DEBUG bool CHTTPTool::downloadFile(const std::string & URL, const char * const downloadTarget, int globalProgressEnd, int connecttimeout/*=10000*/, int timeout/*=1800*/) { @@ -94,7 +101,11 @@ printf("url is %s\n", URL.c_str()); curl_easy_setopt(curl, CURLOPT_URL, URL.c_str() ); curl_easy_setopt(curl, CURLOPT_FILE, headerfile); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); - curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, show_progress); +#if CURL_AT_LEAST_VERSION( 7,32,0 ) + curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, show_progress); +#else + curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, show_progress_old); +#endif curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str()); @@ -159,7 +170,11 @@ printf("url is %s\n", URL.c_str()); curl_easy_setopt(curl, CURLOPT_URL, URL.c_str() ); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &CHTTPTool::CurlWriteToString); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&retString); - curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, show_progress); +#if CURL_AT_LEAST_VERSION( 7,32,0 ) + curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, show_progress); +#else + curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, show_progress_old); +#endif curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str()); diff --git a/src/system/httptool.h b/src/system/httptool.h index 845cc3bf6..fa0efa060 100644 --- a/src/system/httptool.h +++ b/src/system/httptool.h @@ -34,6 +34,7 @@ #define __httptool__ #include +#include #include @@ -45,7 +46,10 @@ class CHTTPTool int iGlobalProgressBegin; CProgressWindow* statusViewer; - static int show_progress( void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); +#if !CURL_AT_LEAST_VERSION( 7,32,0 ) + static int show_progress_old(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); +#endif + static int show_progress(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow); static size_t CurlWriteToString(void *ptr, size_t size, size_t nmemb, void *data); public: