gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] 02/03: test_digestauth: added workaround for bug in old


From: gnunet
Subject: [libmicrohttpd] 02/03: test_digestauth: added workaround for bug in old libcurl
Date: Sun, 30 Jan 2022 15:13:00 +0100

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 1a1e9a591e1bdede4c76a8110e04aec548584c0a
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Sun Jan 30 15:45:12 2022 +0300

    test_digestauth: added workaround for bug in old libcurl
---
 src/testcurl/test_digestauth.c | 43 +++++++++++++++++++++++++++++++++---------
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/src/testcurl/test_digestauth.c b/src/testcurl/test_digestauth.c
index 09272a09..73242590 100644
--- a/src/testcurl/test_digestauth.c
+++ b/src/testcurl/test_digestauth.c
@@ -46,6 +46,14 @@
 #include <wincrypt.h>
 #endif
 
+#ifndef CURL_VERSION_BITS
+#define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|(z))
+#endif /* ! CURL_VERSION_BITS */
+#ifndef CURL_AT_LEAST_VERSION
+#define CURL_AT_LEAST_VERSION(x,y,z) \
+  (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z))
+#endif /* ! CURL_AT_LEAST_VERSION */
+
 #ifndef _MHD_INSTRMACRO
 /* Quoted macro parameter */
 #define _MHD_INSTRMACRO(a) #a
@@ -336,27 +344,44 @@ static CURL *
 setupCURL (void *cbc, int port)
 {
   CURL *c;
+  char url[512];
+
+  if (1)
+  {
+    int res;
+    /* A workaround for some old libcurl versions, which ignore the specified
+     * port by CURLOPT_PORT when digest authorisation is used. */
+    res = snprintf (url, (sizeof(url) / sizeof(url[0])),
+                    "http://127.0.0.1:%d%s";, port, MHD_URI_BASE_PATH);
+    if ((0 >= res) || ((sizeof(url) / sizeof(url[0])) <= (size_t) res))
+      externalErrorExitDesc ("Cannot form request URL");
+  }
 
   c = curl_easy_init ();
   if (NULL == c)
     libcurlErrorExitDesc ("curl_easy_init() failed");
 
   if ((CURLE_OK != curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L)) ||
-      (CURLE_OK != curl_easy_setopt (c, CURLOPT_URL,
-                                     "http://127.0.0.1"; MHD_URI_BASE_PATH)) ||
-      (CURLE_OK != curl_easy_setopt (c, CURLOPT_PORT, (long) port)) ||
+      (CURLE_OK != curl_easy_setopt (c, CURLOPT_ERRORBUFFER,
+                                     libcurl_errbuf)) ||
       (CURLE_OK != curl_easy_setopt (c, CURLOPT_WRITEFUNCTION,
                                      &copyBuffer)) ||
       (CURLE_OK != curl_easy_setopt (c, CURLOPT_WRITEDATA, cbc)) ||
       (CURLE_OK != curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT,
-                                     (long) TIMEOUTS_VAL)) ||
+                                     ((long) TIMEOUTS_VAL))) ||
       (CURLE_OK != curl_easy_setopt (c, CURLOPT_TIMEOUT,
-                                     (long) TIMEOUTS_VAL)) ||
-      (CURLE_OK != curl_easy_setopt (c, CURLOPT_ERRORBUFFER,
-                                     libcurl_errbuf)) ||
-      (CURLE_OK != curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L)) ||
+                                     ((long) TIMEOUTS_VAL))) ||
       (CURLE_OK != curl_easy_setopt (c, CURLOPT_HTTP_VERSION,
-                                     CURL_HTTP_VERSION_1_1)))
+                                     CURL_HTTP_VERSION_1_1)) ||
+      (CURLE_OK != curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L)) ||
+#if CURL_AT_LEAST_VERSION (7, 19, 4)
+      (CURLE_OK != curl_easy_setopt (c, CURLOPT_PROTOCOLS, CURLPROTO_HTTP)) ||
+#endif /* CURL_AT_LEAST_VERSION (7, 19, 4) */
+#if CURL_AT_LEAST_VERSION (7, 45, 0)
+      (CURLE_OK != curl_easy_setopt (c, CURLOPT_DEFAULT_PROTOCOL, "http")) ||
+#endif /* CURL_AT_LEAST_VERSION (7, 45, 0) */
+      (CURLE_OK != curl_easy_setopt (c, CURLOPT_PORT, ((long) port))) ||
+      (CURLE_OK != curl_easy_setopt (c, CURLOPT_URL, url)))
     libcurlErrorExitDesc ("curl_easy_setopt() failed");
   if ((CURLE_OK != curl_easy_setopt (c, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST)) ||
       (CURLE_OK != curl_easy_setopt (c, CURLOPT_USERPWD,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]