libmicrohttpd

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

commit 83d7386c4705340df2e099c5248d1bc800dd01aa
parent 667be90ded9bbc84c51c47c1917a7852bc76ce93
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Mon,  6 Jun 2022 14:23:35 +0300

MHD_str_equal_quoted_bin_n(): added new internal function

Diffstat:
Msrc/microhttpd/mhd_str.c | 30++++++++++++++++++++++++++++++
Msrc/microhttpd/mhd_str.h | 25+++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c @@ -1387,6 +1387,36 @@ MHD_bin_to_hex (const void *bin, } +bool +MHD_str_equal_quoted_bin_n (const char *quoted, + size_t quoted_len, + const char *unquoted, + size_t unquoted_len) +{ + size_t i; + size_t j; + if (unquoted_len < quoted_len / 2) + return false; + + j = 0; + for (i = 0; quoted_len > i && unquoted_len > j; ++i, ++j) + { + if ('\\' == quoted[i]) + { + i++; /* Advance to the next character */ + if (quoted_len == i) + return false; /* No character after escaping backslash */ + } + if (quoted[i] != unquoted[j]) + return false; /* Different characters */ + } + if ((quoted_len != i) || (unquoted_len != j)) + return false; /* The strings have different length */ + + return true; +} + + size_t MHD_str_unquote (const char *quoted, size_t quoted_len, diff --git a/src/microhttpd/mhd_str.h b/src/microhttpd/mhd_str.h @@ -476,6 +476,31 @@ MHD_bin_to_hex (const void *bin, char *hex); /** + * Check two strings for equality, "unquoting" the first string from quoted + * form as specified by RFC7230#section-3.2.6 and RFC7694#quoted.strings. + * + * Null-termination for input stings is not required, binary zeros compared + * like other characters. + * + * @param quoted the quoted string to compare, must NOT include leading and + * closing DQUOTE chars, does not need to be zero-terminated + * @param quoted_len the length in chars of the @a quoted string + * @param unquoted the unquoted string to compare, does not need to be + * zero-terminated + * @param unquoted_len the length in chars of the @a unquoted string + * @return zero if quoted form is broken (no character after the last escaping + * backslash), zero if strings are not equal after unquoting of the + * first string, + * non-zero if two strings are equal after unquoting of the + * first string. + */ +bool +MHD_str_equal_quoted_bin_n (const char *quoted, + size_t quoted_len, + const char *unquoted, + size_t unquoted_len); + +/** * Convert string from quoted to unquoted form as specified by * RFC7230#section-3.2.6 and RFC7694#quoted.strings. *