MHD_str_unquote(): added new internal function

This commit is contained in:
Evgeny Grin (Karlson2k)
2022-05-20 13:12:21 +03:00
parent efaa0a6226
commit 664d8ca99f
2 changed files with 44 additions and 0 deletions
+25
View File
@@ -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;
}
+19
View File
@@ -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 */