libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 5da848a157202cc8ebfc0dbdc39ec4529160d36e
parent 50828ba77d316daf88acda15ec22f05d75a2d273
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Mon, 25 Jul 2022 10:01:00 +0300

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

Fixed compiler warnings

Diffstat:
Msrc/testcurl/test_digestauth.c | 22+++++++++++-----------
Msrc/testcurl/test_digestauth_sha256.c | 20++++++++++----------
Msrc/testcurl/test_digestauth_with_arguments.c | 28++++++++++++++++------------
3 files changed, 37 insertions(+), 33 deletions(-)

diff --git a/src/testcurl/test_digestauth.c b/src/testcurl/test_digestauth.c @@ -265,7 +265,7 @@ ahc_echo (void *cls, const char *password = "testpass"; const char *realm = "test@example.com"; 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); diff --git a/src/testcurl/test_digestauth_sha256.c b/src/testcurl/test_digestauth_sha256.c @@ -94,7 +94,7 @@ ahc_echo (void *cls, const char *password = "testpass"; const char *realm = "test@example.com"; 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); diff --git a/src/testcurl/test_digestauth_with_arguments.c b/src/testcurl/test_digestauth_with_arguments.c @@ -87,7 +87,7 @@ ahc_echo (void *cls, const char *password = "testpass"; const char *realm = "test@example.com"; 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);