libmicrohttpd

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

commit cc5032b85365e567f02650f13ea6ad9a5bb5fef7
parent 7e4885da25b58455452cd6dbcd167f761e3ff38e
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Fri,  3 May 2019 16:48:57 +0300

Added MHD_lookup_connection_value_n().

Diffstat:
Msrc/include/microhttpd.h | 31++++++++++++++++++++++++++++++-
Msrc/microhttpd/connection.c | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 106 insertions(+), 11 deletions(-)

diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -128,7 +128,7 @@ typedef intptr_t ssize_t; * Current version of the library. * 0x01093001 = 1.9.30-1. */ -#define MHD_VERSION 0x00096303 +#define MHD_VERSION 0x00096304 /** * MHD-internal return code for "YES". @@ -2620,6 +2620,35 @@ MHD_lookup_connection_value (struct MHD_Connection *connection, /** + * Get a particular header value. If multiple + * values match the kind, return any one of them. + * @note Since MHD_VERSION 0x00096304 + * + * @param connection connection to get values from + * @param kind what kind of value are we looking for + * @param key the header to look for, NULL to lookup 'trailing' value without a key + * @param key_size the length of @a key in bytes + * @param[out] value_ptr the pointer to variable, which will be set to found value, + * will not be updated if key not found, + * could be NULL to just check for presence of @a key + * @param[out] value_size_ptr the pointer variable, which will set to found value, + * will not be updated if key not found, + * could be NULL + * @param key_size the length of @a key in bytes + * @return #MHD_YES if key is found, + * #MHD_NO otherwise. + * @ingroup request + */ +_MHD_EXTERN int +MHD_lookup_connection_value_n (struct MHD_Connection *connection, + enum MHD_ValueKind kind, + const char *key, + size_t key_size, + const char **value, + size_t *value_size); + + +/** * Queue a response to be transmitted to the client (as soon as * possible but after #MHD_AccessHandlerCallback returns). * diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -838,19 +838,85 @@ MHD_lookup_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key) { + const char *value; + + value = NULL; + MHD_lookup_connection_value_n (connection, + kind, + key, + (NULL == key) ? 0 : strlen(key), + &value, + NULL); + return value; +} + + +/** + * Get a particular header value. If multiple + * values match the kind, return any one of them. + * @note Since MHD_VERSION 0x00096304 + * + * @param connection connection to get values from + * @param kind what kind of value are we looking for + * @param key the header to look for, NULL to lookup 'trailing' value without a key + * @param key_size the length of @a key in bytes + * @param[out] value_ptr the pointer to variable, which will be set to found value, + * will not be updated if key not found, + * could be NULL to just check for presence of @a key + * @param[out] value_size_ptr the pointer variable, which will set to found value, + * will not be updated if key not found, + * could be NULL + * @param key_size the length of @a key in bytes + * @return #MHD_YES if key is found, + * #MHD_NO otherwise. + * @ingroup request + */ +_MHD_EXTERN int +MHD_lookup_connection_value_n (struct MHD_Connection *connection, + enum MHD_ValueKind kind, + const char *key, + size_t key_size, + const char **value_ptr, + size_t *value_size_ptr) +{ struct MHD_HTTP_Header *pos; if (NULL == connection) - return NULL; - for (pos = connection->headers_received; NULL != pos; pos = pos->next) - if ((0 != (pos->kind & kind)) && - ( (key == pos->header) || - ( (NULL != pos->header) && - (NULL != key) && - (MHD_str_equal_caseless_(key, - pos->header))))) - return pos->value; - return NULL; + return MHD_NO; + + if (NULL == key) + { + for (pos = connection->headers_received; NULL != pos; pos = pos->next) + { + if ( (kind == pos->kind) && + (NULL == pos->header) ) + break; + } + } + else + { + for (pos = connection->headers_received; NULL != pos; pos = pos->next) + { + if ( (kind == pos->kind) && + (key_size == pos->header_size) && + ( (key == pos->header) || + (MHD_str_equal_caseless_bin_n_ (key, + pos->header, + key_size) ) ) ) + break; + } + } + + if (NULL == pos) + return MHD_NO; + + if (NULL != value_ptr) + *value_ptr = pos->value; + + if (NULL != value_size_ptr) + *value_size_ptr = pos->value_size; + + return MHD_YES; }