Renamed one new basic auth function, improved doxy

This commit is contained in:
Evgeny Grin (Karlson2k)
2023-10-06 14:12:31 +03:00
parent 596cc4b1cb
commit ce38b0fa79
6 changed files with 68 additions and 65 deletions
+8 -8
View File
@@ -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
{
+4 -4
View File
@@ -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;
}
+4 -4
View File
@@ -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
{
+40 -37
View File
@@ -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;
@@ -5830,6 +5834,38 @@ struct MHD_BasicAuthInfo
_MHD_EXTERN struct MHD_BasicAuthInfo *
MHD_basic_auth_get_username_password3 (struct MHD_Connection *connection);
/**
* Queues a response to request basic authentication from the client.
*
* The given response object is expected to include the payload for
* the response; the "WWW-Authenticate" header will be added and the
* response queued with the 'UNAUTHORIZED' status code.
*
* See RFC 7617#section-2 for details.
*
* 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_required_response3() function. The response could
* be destroyed right after call of this function.
*
* @param connection the MHD connection structure
* @param realm the realm presented to the client
* @param prefer_utf8 if not set to #MHD_NO, parameter'charset="UTF-8"' will
* be added, indicating for client that UTF-8 encoding
* is preferred
* @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 0x00097704
* @ingroup authentication
*/
_MHD_EXTERN enum MHD_Result
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
*
@@ -5845,39 +5881,6 @@ 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
* the response; the "WWW-Authenticate" header will be added and the
* response queued with the 'UNAUTHORIZED' status code.
*
* See RFC 7617#section-2 for details.
*
* 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
* be destroyed right after call of this function.
*
* @param connection the MHD connection structure
* @param realm the realm presented to the client
* @param prefer_utf8 if not set to #MHD_NO, parameter'charset="UTF-8"' will
* be added, indicating for client that UTF-8 encoding
* is preferred
* @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
* @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);
/**
* Queues a response to request basic authentication from the client
* The given response object is expected to include the payload for
@@ -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
+9 -9
View File
@@ -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);
}
+3 -3
View File
@@ -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