[vlc-commits] http: helper to extra quoted string token value
Rémi Denis-Courmont
git at videolan.org
Tue Aug 30 20:54:41 CEST 2016
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Aug 30 21:30:50 2016 +0300| [3a9cf31cc188b23cf3955771c2361d49ad16ae32] | committer: Rémi Denis-Courmont
http: helper to extra quoted string token value
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3a9cf31cc188b23cf3955771c2361d49ad16ae32
---
modules/access/http/message.c | 51 ++++++++++++++++++++++++++++++++++++++++---
1 file changed, 48 insertions(+), 3 deletions(-)
diff --git a/modules/access/http/message.c b/modules/access/http/message.c
index b3874be..6efda5e 100644
--- a/modules/access/http/message.c
+++ b/modules/access/http/message.c
@@ -619,10 +619,8 @@ const char *vlc_http_next_token(const char *value)
return value + strspn(value, "\t ,");
}
-const char *vlc_http_msg_get_token(const struct vlc_http_msg *msg,
- const char *field, const char *token)
+static const char *vlc_http_get_token(const char *value, const char *token)
{
- const char *value = vlc_http_msg_get_header(msg, field);
const size_t length = strlen(token);
while (value != NULL)
@@ -637,6 +635,53 @@ const char *vlc_http_msg_get_token(const struct vlc_http_msg *msg,
return NULL;
}
+static char *vlc_http_get_token_value(const char *value, const char *token)
+{
+ value = vlc_http_get_token(value, token);
+ if (value == NULL)
+ return NULL;
+
+ value += vlc_http_token_length(value);
+ value += strspn(value, " \t"); /* BWS */
+
+ if (*value != '=')
+ return NULL;
+
+ value++;
+ value += strspn(value, " \t"); /* BWS */
+
+ size_t len = vlc_http_quoted_length(value);
+ if (len == 0)
+ return NULL;
+
+ assert(len >= 2);
+ value++;
+ len -= 2;
+
+ char *out = malloc(len + 1), *p;
+ if (unlikely(out == NULL))
+ return NULL;
+
+ for (p = out; len > 0; len--)
+ {
+ char c = *(value++);
+ if (c == '\\') /* Quoted pair */
+ {
+ c = *(value++);
+ len--;
+ }
+ *(p++) = c;
+ }
+ *p = '\0';
+ return out;
+}
+
+const char *vlc_http_msg_get_token(const struct vlc_http_msg *msg,
+ const char *field, const char *token)
+{
+ return vlc_http_get_token(vlc_http_msg_get_header(msg, field), token);
+}
+
static size_t vlc_http_comment_length(const char *str)
{ /* IETF RFC7230 §3.2.6 */
if (*str != '(')
More information about the vlc-commits
mailing list