Kaynağa Gözat

test_digestauth{,_sha256,_with_aguments}: moved back to Digest Auth APIv2

Fixed compiler warnings
Evgeny Grin (Karlson2k) 3 yıl önce
ebeveyn
işleme
5da848a157

+ 11 - 11
src/testcurl/test_digestauth.c

@@ -265,7 +265,7 @@ ahc_echo (void *cls,
   const char *password = "testpass";
   const char *realm = "[email protected]";
   enum MHD_Result ret;
-  enum MHD_DigestAuthResult ret_e;
+  int ret_i;
   static int already_called_marker;
   (void) cls; (void) url;                         /* Unused. Silent compiler warning. */
   (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */
@@ -297,14 +297,14 @@ ahc_echo (void *cls,
     MHD_destroy_response (response);
     return ret;
   }
-  ret_e = MHD_digest_auth_check3 (connection,
+  ret_i = MHD_digest_auth_check2 (connection,
                                   realm,
                                   username,
                                   password,
                                   300,
                                   MHD_DIGEST_ALG_MD5);
   MHD_free (username);
-  if (ret_e != MHD_DAUTH_OK)
+  if (ret_i != MHD_YES)
   {
     response = MHD_create_response_from_buffer_static (strlen (DENIED),
                                                        DENIED);
@@ -314,7 +314,7 @@ ahc_echo (void *cls,
                                          realm,
                                          MY_OPAQUE,
                                          response,
-                                         (MHD_DAUTH_NONCE_STALE == ret_e) ?
+                                         (MHD_INVALID_NONCE == ret_i) ?
                                          MHD_YES : MHD_NO,
                                          MHD_DIGEST_ALG_MD5);
     if (MHD_YES != ret)
@@ -337,7 +337,7 @@ ahc_echo (void *cls,
 
 
 static CURL *
-setupCURL (void *cbc, int port)
+setupCURL (void *cbc, uint16_t port)
 {
   CURL *c;
   char url[512];
@@ -348,7 +348,7 @@ setupCURL (void *cbc, int port)
     /* 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);
+                    "http://127.0.0.1:%d%s", (int) port, MHD_URI_BASE_PATH);
     if ((0 >= res) || ((sizeof(url) / sizeof(url[0])) <= (size_t) res))
       externalErrorExitDesc ("Cannot form request URL");
   }
@@ -387,15 +387,15 @@ setupCURL (void *cbc, int port)
 }
 
 
-static int
-testDigestAuth ()
+static unsigned int
+testDigestAuth (void)
 {
   CURL *c;
   struct MHD_Daemon *d;
   struct CBC cbc;
   char buf[2048];
   char rnd[8];
-  int port;
+  uint16_t port;
 #ifndef WINDOWS
   int fd;
   size_t len;
@@ -446,7 +446,7 @@ testDigestAuth ()
 #endif
   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
                         port, NULL, NULL,
-                        &ahc_echo, PAGE,
+                        &ahc_echo, NULL,
                         MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd,
                         MHD_OPTION_NONCE_NC_SIZE, 300,
                         MHD_OPTION_END);
@@ -461,7 +461,7 @@ testDigestAuth ()
     if ( (NULL == dinfo) ||
          (0 == dinfo->port) )
       mhdErrorExitDesc ("MHD_get_daemon_info() failed");
-    port = (int) dinfo->port;
+    port = dinfo->port;
   }
   c = setupCURL (&cbc, port);
 

+ 10 - 10
src/testcurl/test_digestauth_sha256.c

@@ -94,7 +94,7 @@ ahc_echo (void *cls,
   const char *password = "testpass";
   const char *realm = "[email protected]";
   enum MHD_Result ret;
-  enum MHD_DigestAuthResult ret_e;
+  int ret_i;
   static int already_called_marker;
   (void) cls; (void) url;                         /* Unused. Silent compiler warning. */
   (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */
@@ -122,14 +122,14 @@ ahc_echo (void *cls,
     MHD_destroy_response (response);
     return ret;
   }
-  ret_e = MHD_digest_auth_check3 (connection,
+  ret_i = MHD_digest_auth_check2 (connection,
                                   realm,
                                   username,
                                   password,
                                   300,
                                   MHD_DIGEST_ALG_SHA256);
   MHD_free (username);
-  if (ret_e != MHD_DAUTH_OK)
+  if (ret_i != MHD_YES)
   {
     response = MHD_create_response_from_buffer_static (strlen (DENIED),
                                                        DENIED);
@@ -139,7 +139,7 @@ ahc_echo (void *cls,
                                          realm,
                                          MY_OPAQUE,
                                          response,
-                                         (MHD_DAUTH_NONCE_STALE == ret_e) ?
+                                         (MHD_INVALID_NONCE == ret_i) ?
                                          MHD_YES : MHD_NO,
                                          MHD_DIGEST_ALG_SHA256);
     MHD_destroy_response (response);
@@ -155,8 +155,8 @@ ahc_echo (void *cls,
 }
 
 
-static int
-testDigestAuth ()
+static unsigned int
+testDigestAuth (void)
 {
   CURL *c;
   CURLcode errornum;
@@ -164,7 +164,7 @@ testDigestAuth ()
   struct CBC cbc;
   char buf[2048];
   char rnd[8];
-  int port;
+  uint16_t port;
   char url[128];
 #ifndef WINDOWS
   int fd;
@@ -239,7 +239,7 @@ testDigestAuth ()
 #endif
   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
                         port, NULL, NULL,
-                        &ahc_echo, PAGE,
+                        &ahc_echo, NULL,
                         MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd,
                         MHD_OPTION_NONCE_NC_SIZE, 300,
                         MHD_OPTION_END);
@@ -257,12 +257,12 @@ testDigestAuth ()
       MHD_stop_daemon (d);
       return 32;
     }
-    port = (int) dinfo->port;
+    port = dinfo->port;
   }
   snprintf (url,
             sizeof (url),
             "http://127.0.0.1:%d/bar%%20foo?key=value",
-            port);
+            (int) port);
   c = curl_easy_init ();
   curl_easy_setopt (c, CURLOPT_URL, url);
   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);

+ 16 - 12
src/testcurl/test_digestauth_with_arguments.c

@@ -87,7 +87,7 @@ ahc_echo (void *cls,
   const char *password = "testpass";
   const char *realm = "[email protected]";
   enum MHD_Result ret;
-  enum MHD_DigestAuthResult ret_e;
+  int ret_i;
   static int already_called_marker;
   (void) cls; (void) url;                         /* Unused. Silent compiler warning. */
   (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */
@@ -114,24 +114,28 @@ ahc_echo (void *cls,
     MHD_destroy_response (response);
     return ret;
   }
-  ret_e = MHD_digest_auth_check3 (connection, realm,
+  ret_i = MHD_digest_auth_check2 (connection,
+                                  realm,
                                   username,
                                   password,
                                   300,
                                   MHD_DIGEST_ALG_MD5);
   MHD_free (username);
-  if (ret_e != MHD_DAUTH_OK)
+  if (ret_i != MHD_YES)
   {
     response = MHD_create_response_from_buffer_static (strlen (DENIED),
                                                        DENIED);
     if (NULL == response)
-      return MHD_NO;
-    ret = MHD_queue_auth_fail_response2 (connection, realm,
+      fprintf (stderr, "MHD_create_response_from_buffer() failed.\n");
+    ret = MHD_queue_auth_fail_response2 (connection,
+                                         realm,
                                          MY_OPAQUE,
                                          response,
-                                         (ret_e == MHD_DAUTH_NONCE_STALE) ?
+                                         (MHD_INVALID_NONCE == ret_i) ?
                                          MHD_YES : MHD_NO,
                                          MHD_DIGEST_ALG_MD5);
+    if (MHD_YES != ret)
+      fprintf (stderr, "MHD_queue_auth_fail_response2() failed.\n");
     MHD_destroy_response (response);
     return ret;
   }
@@ -143,8 +147,8 @@ ahc_echo (void *cls,
 }
 
 
-static int
-testDigestAuth ()
+static unsigned int
+testDigestAuth (void)
 {
   CURL *c;
   CURLcode errornum;
@@ -152,7 +156,7 @@ testDigestAuth ()
   struct CBC cbc;
   char buf[2048];
   char rnd[8];
-  int port;
+  uint16_t port;
   char url[128];
 #ifndef WINDOWS
   int fd;
@@ -216,7 +220,7 @@ testDigestAuth ()
   }
 #endif
   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
-                        port, NULL, NULL, &ahc_echo, PAGE,
+                        port, NULL, NULL, &ahc_echo, NULL,
                         MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd,
                         MHD_OPTION_NONCE_NC_SIZE, 300,
                         MHD_OPTION_END);
@@ -230,13 +234,13 @@ testDigestAuth ()
     {
       MHD_stop_daemon (d); return 32;
     }
-    port = (int) dinfo->port;
+    port = dinfo->port;
   }
   snprintf (url,
             sizeof (url),
             "http://127.0.0.1:%d/bar%%20foo?"
             "key=value&more=even%%20more&empty&=no_key&&same=one&&same=two",
-            port);
+            (int) port);
   c = curl_easy_init ();
   curl_easy_setopt (c, CURLOPT_URL, url);
   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);