libmicrohttpd

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

commit ce38b0fa79f0f0fc537163d39c1db0d76d616eb0
parent 596cc4b1cbe9c0db6cf3bfe1f2910d3883ac8ae8
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Fri,  6 Oct 2023 14:11:55 +0300

Renamed one new basic auth function, improved doxy

Diffstat:
Mdoc/examples/basicauthentication.c | 16++++++++--------
Mdoc/examples/tlsauthentication.c | 8++++----
Msrc/examples/authorization_example.c | 8++++----
Msrc/include/microhttpd.h | 53++++++++++++++++++++++++++++-------------------------
Msrc/microhttpd/basicauth.c | 18+++++++++---------
Msrc/testcurl/test_basicauth.c | 6+++---
6 files changed, 56 insertions(+), 53 deletions(-)

diff --git a/doc/examples/basicauthentication.c b/doc/examples/basicauthentication.c @@ -45,10 +45,10 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, static const char *page = "<html><body>Authorization required</body></html>"; response = MHD_create_response_from_buffer_static (strlen (page), page); - ret = MHD_queue_basic_auth_fail_response3 (connection, - "admins", - MHD_YES, - response); + ret = MHD_queue_basic_auth_required_response3 (connection, + "admins", + MHD_YES, + response); } else if ((strlen ("root") != auth_info->username_len) || (0 != memcmp (auth_info->username, "root", @@ -63,10 +63,10 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, static const char *page = "<html><body>Wrong username or password</body></html>"; response = MHD_create_response_from_buffer_static (strlen (page), page); - ret = MHD_queue_basic_auth_fail_response3 (connection, - "admins", - MHD_YES, - response); + ret = MHD_queue_basic_auth_required_response3 (connection, + "admins", + MHD_YES, + response); } else { diff --git a/doc/examples/tlsauthentication.c b/doc/examples/tlsauthentication.c @@ -89,10 +89,10 @@ ask_for_authentication (struct MHD_Connection *connection, const char *realm) if (! response) return MHD_NO; - ret = MHD_queue_basic_auth_fail_response3 (connection, - realm, - MHD_YES, - response); + ret = MHD_queue_basic_auth_required_response3 (connection, + realm, + MHD_YES, + response); MHD_destroy_response (response); return ret; } diff --git a/src/examples/authorization_example.c b/src/examples/authorization_example.c @@ -87,10 +87,10 @@ ahc_echo (void *cls, response = MHD_create_response_from_buffer_static (strlen (DENIED), (const void *) DENIED); - ret = MHD_queue_basic_auth_fail_response3 (connection, - "TestRealm", - MHD_NO, - response); + ret = MHD_queue_basic_auth_required_response3 (connection, + "TestRealm", + MHD_NO, + response); } else { diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -96,7 +96,7 @@ extern "C" * they are parsed as decimal numbers. * Example: 0x01093001 = 1.9.30-1. */ -#define MHD_VERSION 0x00097703 +#define MHD_VERSION 0x00097704 /* If generic headers don't work on your platform, include headers which define 'va_list', 'size_t', 'ssize_t', 'intptr_t', 'off_t', @@ -5794,7 +5794,9 @@ MHD_queue_auth_fail_response (struct MHD_Connection *connection, struct MHD_BasicAuthInfo { /** - * The username, cannot be NULL + * The username, cannot be NULL. + * The buffer pointed by the @a username becomes invalid when the pointer + * to the structure is freed by #MHD_free(). */ char *username; @@ -5804,7 +5806,9 @@ struct MHD_BasicAuthInfo size_t username_len; /** - * The password, may be NULL if password is not encoded by the client + * The password, may be NULL if password is not encoded by the client. + * The buffer pointed by the @a password becomes invalid when the pointer + * to the structure is freed by #MHD_free(). */ char *password; @@ -5831,21 +5835,6 @@ _MHD_EXTERN struct MHD_BasicAuthInfo * MHD_basic_auth_get_username_password3 (struct MHD_Connection *connection); /** - * Get the username and password from the basic authorization header sent by the client - * - * @param connection The MHD connection structure - * @param[out] password a pointer for the password, free using #MHD_free(). - * @return NULL if no username could be found, a pointer - * to the username if found, free using #MHD_free(). - * @deprecated use #MHD_basic_auth_get_username_password3() - * @ingroup authentication - */ -_MHD_EXTERN char * -MHD_basic_auth_get_username_password (struct MHD_Connection *connection, - char **password); - - -/** * Queues a response to request basic authentication from the client. * * The given response object is expected to include the payload for @@ -5857,7 +5846,7 @@ MHD_basic_auth_get_username_password (struct MHD_Connection *connection, * The @a response is modified by this function. The modified response object * can be used to respond subsequent requests by #MHD_queue_response() * function with status code #MHD_HTTP_UNAUTHORIZED and must not be used again - * with MHD_queue_basic_auth_fail_response3() function. The response could + * with MHD_queue_basic_auth_required_response3() function. The response could * be destroyed right after call of this function. * * @param connection the MHD connection structure @@ -5868,14 +5857,28 @@ MHD_basic_auth_get_username_password (struct MHD_Connection *connection, * @param response the response object to modify and queue; the NULL * is tolerated * @return #MHD_YES on success, #MHD_NO otherwise - * @note Available since #MHD_VERSION 0x00097701 + * @note Available since #MHD_VERSION 0x00097704 * @ingroup authentication */ _MHD_EXTERN enum MHD_Result -MHD_queue_basic_auth_fail_response3 (struct MHD_Connection *connection, - const char *realm, - int prefer_utf8, - struct MHD_Response *response); +MHD_queue_basic_auth_required_response3 (struct MHD_Connection *connection, + const char *realm, + int prefer_utf8, + struct MHD_Response *response); + +/** + * Get the username and password from the basic authorization header sent by the client + * + * @param connection The MHD connection structure + * @param[out] password a pointer for the password, free using #MHD_free(). + * @return NULL if no username could be found, a pointer + * to the username if found, free using #MHD_free(). + * @deprecated use #MHD_basic_auth_get_username_password3() + * @ingroup authentication + */ +_MHD_EXTERN char * +MHD_basic_auth_get_username_password (struct MHD_Connection *connection, + char **password); /** @@ -5888,7 +5891,7 @@ MHD_queue_basic_auth_fail_response3 (struct MHD_Connection *connection, * @param realm the realm presented to the client * @param response response object to modify and queue; the NULL is tolerated * @return #MHD_YES on success, #MHD_NO otherwise - * @deprecated use MHD_queue_basic_auth_fail_response3() + * @deprecated use MHD_queue_basic_auth_required_response3() * @ingroup authentication */ _MHD_EXTERN enum MHD_Result diff --git a/src/microhttpd/basicauth.c b/src/microhttpd/basicauth.c @@ -205,7 +205,7 @@ MHD_basic_auth_get_username_password (struct MHD_Connection *connection, * The @a response is modified by this function. The modified response object * can be used to respond subsequent requests by #MHD_queue_response() * function with status code #MHD_HTTP_UNAUTHORIZED and must not be used again - * with MHD_queue_basic_auth_fail_response3() function. The response could + * with MHD_queue_basic_auth_required_response3() function. The response could * be destroyed right after call of this function. * * @param connection the MHD connection structure @@ -216,14 +216,14 @@ MHD_basic_auth_get_username_password (struct MHD_Connection *connection, * @param response the response object to modify and queue; the NULL * is tolerated * @return #MHD_YES on success, #MHD_NO otherwise - * @note Available since #MHD_VERSION 0x00097701 + * @note Available since #MHD_VERSION 0x00097704 * @ingroup authentication */ _MHD_EXTERN enum MHD_Result -MHD_queue_basic_auth_fail_response3 (struct MHD_Connection *connection, - const char *realm, - int prefer_utf8, - struct MHD_Response *response) +MHD_queue_basic_auth_required_response3 (struct MHD_Connection *connection, + const char *realm, + int prefer_utf8, + struct MHD_Response *response) { static const char prefix[] = "Basic realm=\""; static const char suff_charset[] = "\", charset=\"UTF-8\""; @@ -306,7 +306,7 @@ MHD_queue_basic_auth_fail_response3 (struct MHD_Connection *connection, * @param realm the realm presented to the client * @param response response object to modify and queue; the NULL is tolerated * @return #MHD_YES on success, #MHD_NO otherwise - * @deprecated use MHD_queue_basic_auth_fail_response3() + * @deprecated use MHD_queue_basic_auth_required_response3() * @ingroup authentication */ _MHD_EXTERN enum MHD_Result @@ -314,8 +314,8 @@ MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection, const char *realm, struct MHD_Response *response) { - return MHD_queue_basic_auth_fail_response3 (connection, realm, MHD_NO, - response); + return MHD_queue_basic_auth_required_response3 (connection, realm, MHD_NO, + response); } diff --git a/src/testcurl/test_basicauth.c b/src/testcurl/test_basicauth.c @@ -366,10 +366,10 @@ ahc_echo (void *cls, (const void *) DENIED); if (NULL == response) mhdErrorExitDesc ("Response creation failed"); - ret = MHD_queue_basic_auth_fail_response3 (connection, REALM, MHD_YES, - response); + ret = MHD_queue_basic_auth_required_response3 (connection, REALM, MHD_YES, + response); if (MHD_YES != ret) - mhdErrorExitDesc ("'MHD_queue_basic_auth_fail_response3()' failed"); + mhdErrorExitDesc ("'MHD_queue_basic_auth_required_response3()' failed"); } } else