diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-05-09 21:37:44 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-05-09 22:20:43 +0300 |
commit | 17d1176f26fb679602b990e8194bf21a1c92d005 (patch) | |
tree | 96edb87190e5628b84e6ac973ff76cd5275775d8 | |
parent | 22ab1e90ed94ede591198380ac8ad32d71458982 (diff) | |
download | libmicrohttpd-17d1176f26fb679602b990e8194bf21a1c92d005.tar.gz libmicrohttpd-17d1176f26fb679602b990e8194bf21a1c92d005.zip |
Added internal function for finding token in request headers
-rw-r--r-- | src/microhttpd/connection.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 8c91f468..6c7d5226 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -468,6 +468,57 @@ MHD_lookup_connection_value (struct MHD_Connection *connection, | |||
468 | 468 | ||
469 | 469 | ||
470 | /** | 470 | /** |
471 | * Check whether request header contains particular token. | ||
472 | * | ||
473 | * Token could be surrounded by spaces and tabs and delimited by comma. | ||
474 | * Case-insensitive match used for header names and tokens. | ||
475 | * @param connection the connection to get values from | ||
476 | * @param header the header name | ||
477 | * @param token the token to find | ||
478 | * @param token_len the length of token, not including optional | ||
479 | * terminating null-character. | ||
480 | * @return true if token is found in specified header, | ||
481 | * false otherwise | ||
482 | */ | ||
483 | static bool | ||
484 | MHD_lookup_header_token_ci (const struct MHD_Connection *connection, | ||
485 | const char *header, | ||
486 | const char *token, | ||
487 | size_t token_len) | ||
488 | { | ||
489 | struct MHD_HTTP_Header *pos; | ||
490 | |||
491 | if (NULL == connection || NULL == header || 0 == header[0] || NULL == token || 0 == token[0]) | ||
492 | return false; | ||
493 | for (pos = connection->headers_received; NULL != pos; pos = pos->next) | ||
494 | { | ||
495 | if ((0 != (pos->kind & MHD_HEADER_KIND)) && | ||
496 | ( (header == pos->header) || | ||
497 | (MHD_str_equal_caseless_(header, | ||
498 | pos->header)) ) && | ||
499 | (MHD_str_has_token_caseless_ (pos->value, token, token_len))) | ||
500 | return true; | ||
501 | } | ||
502 | return false; | ||
503 | } | ||
504 | |||
505 | |||
506 | /** | ||
507 | * Check whether request header contains particular static @a tkn. | ||
508 | * | ||
509 | * Token could be surrounded by spaces and tabs and delimited by comma. | ||
510 | * Case-insensitive match used for header names and tokens. | ||
511 | * @param c the connection to get values from | ||
512 | * @param h the header name | ||
513 | * @param tkn the static string of token to find | ||
514 | * @return true if token is found in specified header, | ||
515 | * false otherwise | ||
516 | */ | ||
517 | #define MHD_lookup_header_s_token_ci(c,h,tkn) \ | ||
518 | MHD_lookup_header_token_ci((c),(h),(tkn),MHD_STATICSTR_LEN_(tkn)) | ||
519 | |||
520 | |||
521 | /** | ||
471 | * Do we (still) need to send a 100 continue | 522 | * Do we (still) need to send a 100 continue |
472 | * message for this connection? | 523 | * message for this connection? |
473 | * | 524 | * |