libmicrohttpd

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

commit ad7652a28c4308c24457fb98cc24dbce3c869201
parent e93439da71e027cafe5b2788a997cbfc85d193c8
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Mon,  8 May 2017 19:22:34 +0300

Added internal function for finding token in response headers MHD_check_response_header_token_ci()

Diffstat:
Msrc/microhttpd/internal.h | 34++++++++++++++++++++++++++++++++++
Msrc/microhttpd/response.c | 34++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -1888,4 +1888,38 @@ MHD_parse_arguments_ (struct MHD_Connection *connection, unsigned int *num_headers); +/** + * Check whether response header contains particular @a token. + * + * Token could be surrounded by spaces and tabs and delimited by comma. + * Case-insensitive match used for header names and tokens. + * @param response the response to query + * @param key header name + * @param token the token to find + * @param token_len the length of token, not including optional + * terminating null-character. + * @return true if token is found in specified header, + * false otherwise + */ +bool +MHD_check_response_header_token_ci (const struct MHD_Response *response, + const char *key, + const char *token, + size_t token_len); + +/** + * Check whether response header contains particular static @a tkn. + * + * Token could be surrounded by spaces and tabs and delimited by comma. + * Case-insensitive match used for header names and tokens. + * @param r the response to query + * @param k header name + * @param tkn the static string of token to find + * @return true if token is found in specified header, + * false otherwise + */ +#define MHD_check_response_header_s_token_ci(r,k,tkn) \ + MHD_check_response_header_token_ci((r),(k),(tkn),MHD_STATICSTR_LEN_(tkn)) + + #endif diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c @@ -248,6 +248,40 @@ MHD_get_response_header (struct MHD_Response *response, return NULL; } +/** + * Check whether response header contains particular token. + * + * Token could be surrounded by spaces and tabs and delimited by comma. + * Case-insensitive match used for header names and tokens. + * @param response the response to query + * @param key header name + * @param token the token to find + * @param token_len the length of token, not including optional + * terminating null-character. + * @return true if token is found in specified header, + * false otherwise + */ +bool +MHD_check_response_header_token_ci (const struct MHD_Response *response, + const char *key, + const char *token, + size_t token_len) +{ + struct MHD_HTTP_Header *pos; + + if (NULL == key || 0 == key[0] || NULL == token || 0 == token[0]) + return false; + + for (pos = response->first_header; NULL != pos; pos = pos->next) + { + if ( (pos->kind == MHD_HEADER_KIND) && + MHD_str_equal_caseless_ (pos->header, key) && + MHD_str_has_token_caseless_ (pos->value, token, token_len) ) + return true; + } + return false; +} + /** * Create a response object. The response object can be extended with