aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_str.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_str.c')
-rw-r--r--src/microhttpd/mhd_str.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index c5e9813c..bb10d26f 100644
--- a/src/microhttpd/mhd_str.c
+++ b/src/microhttpd/mhd_str.c
@@ -365,6 +365,64 @@ MHD_str_equal_caseless_n_ (const char * const str1,
365 return !0; 365 return !0;
366} 366}
367 367
368
369/**
370 * Check whether @a str has case-insensitive @a token.
371 * Token could be surrounded by spaces and tabs and delimited by comma.
372 * Match succeed if substring between start, end (of string) or comma
373 * contains only case-insensitive token and optional spaces and tabs.
374 * @warning token must not contain null-charters except optional
375 * terminating null-character.
376 * @param str the string to check
377 * @param token the token to find
378 * @param token_len length of token, not including optional terminating
379 * null-character.
380 * @return non-zero if two strings are equal, zero otherwise.
381 */
382bool
383MHD_str_has_token_caseless_ (const char * str,
384 const char * const token,
385 size_t token_len)
386{
387 if (0 == token_len)
388 return false;
389
390 while (0 != *str)
391 {
392 size_t i;
393 /* Skip all whitespaces and empty tokens. */
394 while (' ' == *str || '\t' == *str || ',' == *str) str++;
395
396 /* Check for token match. */
397 i = 0;
398 while (1)
399 {
400 const char sc = *(str++);
401 const char tc = token[i++];
402
403 if (0 == sc)
404 return false;
405 if ( (sc != tc) &&
406 (toasciilower (sc) != toasciilower (tc)) )
407 break;
408 if (i >= token_len)
409 {
410 /* Check whether substring match token fully or
411 * has additional unmatched chars at tail. */
412 while (' ' == *str || '\t' == *str) str++;
413 /* End of (sub)string? */
414 if (0 == *str || ',' == *str)
415 return true;
416 /* Unmatched chars at end of substring. */
417 break;
418 }
419 }
420 /* Find next substring. */
421 while (0 != *str && ',' != *str) str++;
422 }
423 return false;
424}
425
368#ifndef MHD_FAVOR_SMALL_CODE 426#ifndef MHD_FAVOR_SMALL_CODE
369/* Use individual function for each case */ 427/* Use individual function for each case */
370 428