gnunet-svn
[Top][All Lists]
Advanced

[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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]