[vlc-commits] https: improve header field list iteration
Rémi Denis-Courmont
git at videolan.org
Tue Dec 22 23:34:13 CET 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Dec 23 00:33:21 2015 +0200| [a9f3ddf463773c92e3c2541114317d66d6fbfdd3] | committer: Rémi Denis-Courmont
https: improve header field list iteration
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a9f3ddf463773c92e3c2541114317d66d6fbfdd3
---
modules/access/http/message.c | 48 +++++++++++++++++++++++++++++------------
modules/access/http/message.h | 7 ------
2 files changed, 34 insertions(+), 21 deletions(-)
diff --git a/modules/access/http/message.c b/modules/access/http/message.c
index d6ba97d..5de60d4 100644
--- a/modules/access/http/message.c
+++ b/modules/access/http/message.c
@@ -552,23 +552,46 @@ static size_t vlc_http_token_length(const char *str)
return i;
}
-static bool vlc_http_is_token(const char *str)
+static size_t vlc_http_quoted_length(const char *str)
{
- size_t len = vlc_http_token_length(str);
- return len > 0 && str[len] == '\0';
+ size_t i = 0;
+ unsigned char c;
+
+ if (str[i++] != '"')
+ return 0;
+
+ do
+ {
+ c = str[i++];
+
+ if (c == '\0')
+ return 0;
+
+ if (c == '\\') /* Quoted pair */
+ {
+ unsigned char q = str[i++];
+ if (q < 32 && q != '\t')
+ return 0;
+ }
+ }
+ while (c != '"');
+
+ return i;
}
-const char *vlc_http_first_token(const char *value)
+static bool vlc_http_is_token(const char *str)
{
- return value + strspn(value, "\t ");
+ size_t len = vlc_http_token_length(str);
+ return len > 0 && str[len] == '\0';
}
const char *vlc_http_next_token(const char *value)
-{
- value = strchr(value, ',');
- if (value == NULL)
+{ /* We handle either token or token = token / quoted-string */
+ value += strcspn(value, ",\"");
+ if (!*value)
return NULL;
+ value += vlc_http_quoted_length(value);
return value + strspn(value, "\t ,");
}
@@ -576,18 +599,15 @@ const char *vlc_http_msg_get_token(const struct vlc_http_msg *msg,
const char *field, const char *token)
{
const char *value = vlc_http_msg_get_header(msg, field);
- if (value == NULL)
- return NULL;
-
const size_t length = strlen(token);
- for (value = vlc_http_first_token(value);
- value != NULL;
- value = vlc_http_next_token(value))
+ while (value != NULL)
{
if (vlc_http_token_length(value) == length
&& !strncasecmp(token, value, length))
return value;
+
+ value = vlc_http_next_token(value);
}
return NULL;
diff --git a/modules/access/http/message.h b/modules/access/http/message.h
index 6e19a91..ebfc8aa 100644
--- a/modules/access/http/message.h
+++ b/modules/access/http/message.h
@@ -166,13 +166,6 @@ const char *vlc_http_msg_get_token(const struct vlc_http_msg *,
const char *field, const char *token);
/**
- * Finds first token.
- *
- * Finds the first token in a HTTP field value.
- */
-const char *vlc_http_first_token(const char *);
-
-/**
* Finds next token.
*
* Finds the following token in a HTTP field value.
More information about the vlc-commits
mailing list