From c44343712df6dc75b1fbb857433faacfcd1bde75 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 5 Dec 2020 13:38:39 -0800 Subject: [PATCH] Add support for older versions of libcurl (e.g. those found on RHEL7) that do not have support for the newer CURLOPT_XFERINFODATA / CURLOPT_XFERINFOFUNCTION options. --- src/plugins/httpdatastream/HttpDataStream.cpp | 29 ++++++++++++++++--- src/plugins/httpdatastream/HttpDataStream.h | 4 +++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/plugins/httpdatastream/HttpDataStream.cpp b/src/plugins/httpdatastream/HttpDataStream.cpp index 09e826609..df3a1e035 100755 --- a/src/plugins/httpdatastream/HttpDataStream.cpp +++ b/src/plugins/httpdatastream/HttpDataStream.cpp @@ -327,12 +327,20 @@ bool HttpDataStream::Open(const char *rawUri, OpenFlags flags) { curl_easy_setopt(this->curlEasy, CURLOPT_FAILONERROR, 1); curl_easy_setopt(this->curlEasy, CURLOPT_USERAGENT, "musikcube HttpDataStream"); curl_easy_setopt(this->curlEasy, CURLOPT_NOPROGRESS, 0); + curl_easy_setopt(this->curlEasy, CURLOPT_WRITEHEADER, this); - curl_easy_setopt(this->curlEasy, CURLOPT_WRITEDATA, this); - curl_easy_setopt(this->curlEasy, CURLOPT_XFERINFODATA, this); - curl_easy_setopt(this->curlEasy, CURLOPT_WRITEFUNCTION, &HttpDataStream::CurlWriteCallback); curl_easy_setopt(this->curlEasy, CURLOPT_HEADERFUNCTION, &HttpDataStream::CurlReadHeaderCallback); + + curl_easy_setopt(this->curlEasy, CURLOPT_WRITEDATA, this); + curl_easy_setopt(this->curlEasy, CURLOPT_WRITEFUNCTION, &HttpDataStream::CurlWriteCallback); + +#if LIBCURL_VERSION_NUM < 0x072000 + curl_easy_setopt(this->curlEasy, CURLOPT_PROGRESSDATA, this); + curl_easy_setopt(this->curlEasy, CURLOPT_PROGRESSFUNCTION, &HttpDataStream::LegacyCurlTransferCallback); +#else + curl_easy_setopt(this->curlEasy, CURLOPT_XFERINFODATA, this); curl_easy_setopt(this->curlEasy, CURLOPT_XFERINFOFUNCTION, &HttpDataStream::CurlTransferCallback); +#endif const int connectionTimeout = prefs->GetInt(kConnectionTimeoutSecondsKey.c_str(), kDefaultConnectionTimeoutSeconds); const int readTimeout = prefs->GetInt(kReadTimeoutSecondsKey.c_str(), kDefaultReadTimeoutSeconds); @@ -578,4 +586,17 @@ int HttpDataStream::CurlTransferCallback( return -1; /* kill the stream */ } return 0; /* ok! */ -} \ No newline at end of file +} + +#if LIBCURL_VERSION_NUM < 0x072000 +int HttpDataStream::LegacyCurlTransferCallback( + void *ptr, double downTotal, double downNow, double upTotal, double upNow) +{ + return CurlTransferCallback( + ptr, + (curl_off_t) downTotal, + (curl_off_t) downNow, + (curl_off_t) upTotal, + (curl_off_t) upNow); +} +#endif \ No newline at end of file diff --git a/src/plugins/httpdatastream/HttpDataStream.h b/src/plugins/httpdatastream/HttpDataStream.h index 179947e9b..5bae5e65c 100755 --- a/src/plugins/httpdatastream/HttpDataStream.h +++ b/src/plugins/httpdatastream/HttpDataStream.h @@ -91,6 +91,10 @@ class HttpDataStream : public IDataStream { static size_t CurlReadHeaderCallback(char *buffer, size_t size, size_t nitems, void *userdata); static int CurlTransferCallback(void *ptr, curl_off_t downTotal, curl_off_t downNow, curl_off_t upTotal, curl_off_t upNow); + #if LIBCURL_VERSION_NUM < 0x072000 + static int LegacyCurlTransferCallback(void *ptr, double downTotal, double downNow, double upTotal, double upNow); + #endif + std::string originalUri, httpUri, type; size_t length; std::string filename;