[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 03/10: MHD_str_equal_quoted_bin_n(): added new internal
From: |
gnunet |
Subject: |
[libmicrohttpd] 03/10: MHD_str_equal_quoted_bin_n(): added new internal function |
Date: |
Mon, 06 Jun 2022 18:41:29 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit 83d7386c4705340df2e099c5248d1bc800dd01aa
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Mon Jun 6 14:23:35 2022 +0300
MHD_str_equal_quoted_bin_n(): added new internal function
---
src/microhttpd/mhd_str.c | 30 ++++++++++++++++++++++++++++++
src/microhttpd/mhd_str.h | 25 +++++++++++++++++++++++++
2 files changed, 55 insertions(+)
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index 7a337574..7fdb6f13 100644
--- 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
index 6abebf3d..ecad5422 100644
--- a/src/microhttpd/mhd_str.h
+++ b/src/microhttpd/mhd_str.h
@@ -475,6 +475,31 @@ MHD_bin_to_hex (const void *bin,
size_t size,
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.
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] branch master updated (56c4b4ae -> 8d5ebaec), gnunet, 2022/06/06
- [libmicrohttpd] 01/10: test_auth_parse: minor formatting imrpovement, gnunet, 2022/06/06
- [libmicrohttpd] 02/10: mhd_str: fixed doxy again, gnunet, 2022/06/06
- [libmicrohttpd] 03/10: MHD_str_equal_quoted_bin_n(): added new internal function,
gnunet <=
- [libmicrohttpd] 04/10: test_str_quote: added new test, gnunet, 2022/06/06
- [libmicrohttpd] 06/10: MHD_str_equal_caseless_quoted_bin_n(): added new internal function, gnunet, 2022/06/06
- [libmicrohttpd] 09/10: digestauth: avoid repetitive calculations of some strings' length, gnunet, 2022/06/06
- [libmicrohttpd] 08/10: Simplified Digest Auth code by using the new string processing functions, gnunet, 2022/06/06
- [libmicrohttpd] 05/10: Excluded build on the new string functions when they are unused, gnunet, 2022/06/06
- [libmicrohttpd] 10/10: gen_auth: simplified value assignment, gnunet, 2022/06/06
- [libmicrohttpd] 07/10: test_str_quote: added testing of the new function, gnunet, 2022/06/06