mirror of
https://git.gnunet.org/libmicrohttpd.git
synced 2026-09-25 04:09:31 +03:00
MHD_str_unquote(): added new internal function
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user