fix for newer libcurl

This commit is contained in:
GetAway
2023-01-12 21:08:40 +01:00
parent 0f0c3eb5ff
commit 2a219b342e
5 changed files with 38 additions and 7 deletions

View File

@@ -98,7 +98,11 @@ int CLuaInstCurl::CurlProgressFunc(void *p, curl_off_t dltotal, curl_off_t dlnow
double dlSpeed; double dlSpeed;
long responseCode = 0; 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); curl_easy_getinfo(_pgd->curl, CURLINFO_SPEED_DOWNLOAD, &dlSpeed);
#endif
curl_easy_getinfo(_pgd->curl, CURLINFO_RESPONSE_CODE, &responseCode); curl_easy_getinfo(_pgd->curl, CURLINFO_RESPONSE_CODE, &responseCode);
uint32_t MUL = 0x7FFF; uint32_t MUL = 0x7FFF;
@@ -124,7 +128,7 @@ int CLuaInstCurl::CurlProgressFunc(void *p, curl_off_t dltotal, curl_off_t dlnow
return 0; 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) 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); 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) { if (!silent) {
pgd.curl = curl_handle; pgd.curl = curl_handle;
pgd.last_dlnow = -1; 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_XFERINFOFUNCTION, CLuaInstCurl::CurlProgressFunc);
curl_easy_setopt(curl_handle, CURLOPT_XFERINFODATA, &pgd); curl_easy_setopt(curl_handle, CURLOPT_XFERINFODATA, &pgd);
#else #else
@@ -349,7 +353,11 @@ Example:
if (!silent) { if (!silent) {
double dsize, dtime; double dsize, dtime;
char *dredirect=NULL, *deffektive=NULL; 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); curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD, &dsize);
#endif
curl_easy_getinfo(curl_handle, CURLINFO_TOTAL_TIME, &dtime); curl_easy_getinfo(curl_handle, CURLINFO_TOTAL_TIME, &dtime);
CURLcode res1 = curl_easy_getinfo(curl_handle, CURLINFO_EFFECTIVE_URL, &deffektive); CURLcode res1 = curl_easy_getinfo(curl_handle, CURLINFO_EFFECTIVE_URL, &deffektive);
CURLcode res2 = curl_easy_getinfo(curl_handle, CURLINFO_REDIRECT_URL, &dredirect); CURLcode res2 = curl_easy_getinfo(curl_handle, CURLINFO_REDIRECT_URL, &dredirect);

View File

@@ -53,7 +53,7 @@ class CLuaInstCurl
static CLuaCurl *CurlCheckData(lua_State *L, int n); static CLuaCurl *CurlCheckData(lua_State *L, int n);
static int CurlNew(lua_State *L); static int CurlNew(lua_State *L);
static size_t CurlWriteToString(void *ptr, size_t size, size_t nmemb, void *data); 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); static int CurlProgressFunc_old(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
#endif #endif
static int CurlProgressFunc(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow); static int CurlProgressFunc(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow);

View File

@@ -1866,7 +1866,11 @@ bool downloadUrl(std::string url, std::string file, std::string userAgent, unsig
CURLcode httpres = curl_easy_perform(curl_handle); CURLcode httpres = curl_easy_perform(curl_handle);
double dsize; 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); curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD, &dsize);
#endif
curl_easy_cleanup(curl_handle); curl_easy_cleanup(curl_handle);
fclose(fp); fclose(fp);

View File

@@ -51,7 +51,7 @@ size_t CHTTPTool::CurlWriteToString(void *ptr, size_t size, size_t nmemb, void *
return size*nmemb; 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); CHTTPTool* hTool = ((CHTTPTool*)clientp);
if(hTool->statusViewer) if(hTool->statusViewer)
@@ -66,6 +66,13 @@ int CHTTPTool::show_progress( void *clientp, double dltotal, double dlnow, doubl
} }
return 0; 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 //#define DEBUG
bool CHTTPTool::downloadFile(const std::string & URL, const char * const downloadTarget, int globalProgressEnd, int connecttimeout/*=10000*/, int timeout/*=1800*/) 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_URL, URL.c_str() );
curl_easy_setopt(curl, CURLOPT_FILE, headerfile); curl_easy_setopt(curl, CURLOPT_FILE, headerfile);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); 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_PROGRESSDATA, this);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str()); 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_URL, URL.c_str() );
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &CHTTPTool::CurlWriteToString); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &CHTTPTool::CurlWriteToString);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&retString); 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_PROGRESSDATA, this);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str()); curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str());

View File

@@ -34,6 +34,7 @@
#define __httptool__ #define __httptool__
#include <gui/widget/progresswindow.h> #include <gui/widget/progresswindow.h>
#include <curl/curl.h>
#include <string> #include <string>
@@ -45,7 +46,10 @@ class CHTTPTool
int iGlobalProgressBegin; int iGlobalProgressBegin;
CProgressWindow* statusViewer; 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); static size_t CurlWriteToString(void *ptr, size_t size, size_t nmemb, void *data);
public: public: