]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
minicurl: fix missing CURLOPT_XFERINFOFUNCTION on old curl versions 12297/head
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Wed, 7 Dec 2022 14:26:15 +0000 (15:26 +0100)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Thu, 8 Dec 2022 10:50:30 +0000 (11:50 +0100)
pdns/minicurl.cc
pdns/minicurl.hh

index 02b5204562fc7f98fa7113c72a7526aab7d29333..948f3f488aed8e478568ee02981e1f536ea725d5 100644 (file)
@@ -65,6 +65,7 @@ size_t MiniCurl::write_callback(char *ptr, size_t size, size_t nmemb, void *user
   return 0;
 }
 
+#if defined(LIBCURL_VERSION_NUM) && LIBCURL_VERSION_NUM >= 0x072000 // 7.32.0
 size_t MiniCurl::progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
 {
   if (clientp != nullptr) {
@@ -75,6 +76,18 @@ size_t MiniCurl::progress_callback(void *clientp, curl_off_t dltotal, curl_off_t
   }
   return 0;
 }
+#else
+size_t MiniCurl::progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
+{
+  if (clientp != nullptr) {
+    MiniCurl* us = static_cast<MiniCurl*>(clientp);
+    if (us->d_byteslimit > 0 && dlnow > static_cast<double>(us->d_byteslimit)) {
+      return static_cast<size_t>(dlnow);
+    }
+  }
+  return 0;
+}
+#endif
 
 static string extractHostFromURL(const std::string& url)
 {
@@ -131,8 +144,13 @@ void MiniCurl::setupURL(const std::string& str, const ComboAddress* rem, const C
   if (d_byteslimit > 0) {
     /* enable progress meter */
     curl_easy_setopt(d_curl, CURLOPT_NOPROGRESS, 0L);
+#if defined(LIBCURL_VERSION_NUM) && LIBCURL_VERSION_NUM >= 0x072000 // 7.32.0
     curl_easy_setopt(d_curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
     curl_easy_setopt(d_curl, CURLOPT_XFERINFODATA, this);
+#else
+    curl_easy_setopt(d_curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
+    curl_easy_setopt(d_curl, CURLOPT_PROGRESSDATA, this);
+#endif
   }
 
   curl_easy_setopt(d_curl, CURLOPT_TIMEOUT, static_cast<long>(timeout));
index c5bbf3316e3590844f7bf9f282a54953102442d0..52447a886a53c55dfb1de22dac658b2d8930890c 100644 (file)
@@ -43,7 +43,11 @@ public:
 private:
   CURL *d_curl;
   static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata);
+#if defined(LIBCURL_VERSION_NUM) && LIBCURL_VERSION_NUM >= 0x072000 // 7.32.0
   static size_t progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow);
+#else
+  static size_t progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
+#endif
   std::string d_data;
   size_t d_byteslimit;
   struct curl_slist* d_header_list = nullptr;