commit 1a37de9601862a2875629cc6698b17cda4ca534c
parent 7eef6dd3e45975012afcc03ba30dfb951984910f
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Mon, 6 Jun 2022 15:53:21 +0300
MHD_str_equal_caseless_quoted_bin_n(): added new internal function
Diffstat:
2 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
@@ -1418,6 +1418,36 @@ MHD_str_equal_quoted_bin_n (const char *quoted,
}
+bool
+MHD_str_equal_caseless_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 (! charsequalcaseless (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
@@ -502,6 +502,32 @@ MHD_str_equal_quoted_bin_n (const char *quoted,
size_t unquoted_len);
/**
+ * Check two strings for equality, "unquoting" the first string from quoted
+ * form as specified by RFC7230#section-3.2.6 and RFC7694#quoted.strings and
+ * ignoring case of US-ASCII letters.
+ *
+ * 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 caseless equal after unquoting of the
+ * first string.
+ */
+bool
+MHD_str_equal_caseless_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.
*