Commit a9f3ddf4 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

https: improve header field list iteration

parent eeab18ae
......@@ -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;
......
......@@ -165,13 +165,6 @@ const char *vlc_http_msg_get_path(const struct vlc_http_msg *m);
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.
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment