commit 664d8ca99f681d6f222ec754f3f1d2943b78df7c
parent efaa0a6226f7be70f3d7c71f5c4394f2d2306993
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Fri, 20 May 2022 13:06:57 +0300
MHD_str_unquote(): added new internal function
Diffstat:
2 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
@@ -1375,3 +1375,28 @@ MHD_bin_to_hex (const void *bin,
hex[i * 2] = 0;
return i;
}
+
+
+size_t
+MHD_str_unquote (const char *quoted,
+ size_t quoted_len,
+ char *result)
+{
+ size_t r;
+ size_t w;
+
+ r = 0;
+ w = 0;
+
+ while (quoted_len > r)
+ {
+ if ('\\' == quoted[r])
+ {
+ ++r;
+ if (quoted_len == r)
+ return 0; /* Last backslash is not followed by char to unescape */
+ }
+ result[w++] = quoted[r++];
+ }
+ return w;
+}
diff --git a/src/microhttpd/mhd_str.h b/src/microhttpd/mhd_str.h
@@ -471,4 +471,23 @@ MHD_bin_to_hex (const void *bin,
size_t size,
char *hex);
+/**
+ * Convert string from quoted to unquoted form as specified by
+ * RFC7230#section-3.2.6 and RFC7694#quoted.strings.
+ *
+ * @param quoted the quoted string, must NOT include leading and closing
+ * DQUOTE chars, does not need to be zero-terminated
+ * @param size the size in chars of the @a quited string
+ * @param[out] result the pointer to the buffer to put the result, must
+ * be at least @a size character long. The result is NOT
+ * zero-terminated.
+ * @return The number of characters written to the output buffer,
+ * zero if last backslash is not followed by any character (or
+ * @a size is zero).
+ */
+size_t
+MHD_str_unquote (const char *quoted,
+ size_t quoted_len,
+ char *result);
+
#endif /* MHD_STR_H */