diff --git a/common/kicad_curl/kicad_curl_easy.cpp b/common/kicad_curl/kicad_curl_easy.cpp index f114e202b0..3e3d683e8d 100644 --- a/common/kicad_curl/kicad_curl_easy.cpp +++ b/common/kicad_curl/kicad_curl_easy.cpp @@ -59,9 +59,9 @@ static size_t write_callback( void* contents, size_t size, size_t nmemb, void* u { size_t realsize = size * nmemb; - std::string* p = (std::string*) userp; + std::string* p = static_cast( userp ); - p->append( (const char*) contents, realsize ); + p->append( static_cast( contents ), realsize ); return realsize; } @@ -73,7 +73,7 @@ static size_t stream_write_callback( void* contents, size_t size, size_t nmemb, std::ostream* p = (std::ostream*) userp; - p->write( (const char*) contents, realsize ); + p->write( static_cast( contents ), realsize ); return realsize; } @@ -82,7 +82,7 @@ static size_t stream_write_callback( void* contents, size_t size, size_t nmemb, static int xferinfo( void* p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow ) { - CURL_PROGRESS* progress = (CURL_PROGRESS*) p; + CURL_PROGRESS* progress = static_cast( p ); curl_off_t curtime = 0; curl_easy_getinfo( progress->curl->GetCurl(), CURLINFO_TOTAL_TIME, &curtime ); @@ -97,6 +97,13 @@ static int xferinfo( void* p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t u } +static int progressinfo( void* p, double dltotal, double dlnow, double ultotal, double ulnow ) +{ + return xferinfo( p, static_cast( dltotal ), static_cast( dlnow ), + static_cast( ultotal ), static_cast( ulnow ) ); +} + + KICAD_CURL_EASY::KICAD_CURL_EASY() : m_headers( nullptr ) { // Call KICAD_CURL::Init() from in here every time, but only the first time @@ -178,13 +185,13 @@ void KICAD_CURL_EASY::SetHeader( const std::string& aName, const std::string& aV template int KICAD_CURL_EASY::setOption( int aOption, T aArg ) { - return curl_easy_setopt( m_CURL, (CURLoption) aOption, aArg ); + return curl_easy_setopt( m_CURL, static_cast( aOption ), aArg ); } const std::string KICAD_CURL_EASY::GetErrorText( int aCode ) { - return curl_easy_strerror( (CURLcode) aCode ); + return curl_easy_strerror( static_cast( aCode ) ); } @@ -254,9 +261,15 @@ std::string KICAD_CURL_EASY::Escape( const std::string& aUrl ) bool KICAD_CURL_EASY::SetTransferCallback( const TRANSFER_CALLBACK& aCallback, size_t aInterval ) { - progress = std::make_unique( this, aCallback, (curl_off_t) aInterval ); + progress = std::make_unique( this, aCallback, + static_cast( aInterval ) ); +#ifdef CURLOPT_XFERINFOFUNCTION setOption( CURLOPT_XFERINFOFUNCTION, xferinfo ); setOption( CURLOPT_XFERINFODATA, progress.get() ); +#else + setOption( CURLOPT_PROGRESSFUNCTION, progressinfo ); + setOption( CURLOPT_PROGRESSDATA, progress.get() ); +#endif setOption( CURLOPT_NOPROGRESS, 0L ); return true; } @@ -265,15 +278,21 @@ bool KICAD_CURL_EASY::SetTransferCallback( const TRANSFER_CALLBACK& aCallback, s bool KICAD_CURL_EASY::SetOutputStream( const std::ostream* aOutput ) { curl_easy_setopt( m_CURL, CURLOPT_WRITEFUNCTION, stream_write_callback ); - curl_easy_setopt( m_CURL, CURLOPT_WRITEDATA, (void*) aOutput ); + curl_easy_setopt( m_CURL, CURLOPT_WRITEDATA, reinterpret_cast( aOutput ) ); return true; } int KICAD_CURL_EASY::GetTransferTotal( uint64_t& aDownloadedBytes ) const { +#ifdef CURLINFO_SIZE_DOWNLOAD_T curl_off_t dl; int result = curl_easy_getinfo( m_CURL, CURLINFO_SIZE_DOWNLOAD_T, &dl ); - aDownloadedBytes = (uint64_t) dl; + aDownloadedBytes = static_cast( dl ); +#else + double dl; + int result = curl_easy_getinfo( m_CURL, CURLINFO_SIZE_DOWNLOAD, &dl ); + aDownloadedBytes = static_cast( dl ); +#endif return result; }