From: stbenz Date: Fri, 22 May 2015 18:38:35 +0000 (+0200) Subject: http: fix Accept-Encoding parsing X-Git-Tag: v4.2.1~2490 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef5b43a344e9fbef4db63383fd93693ce876b284;p=thirdparty%2Ftvheadend.git http: fix Accept-Encoding parsing --- diff --git a/src/http.c b/src/http.c index 8d27b22c4..4575e1f0c 100644 --- a/src/http.c +++ b/src/http.c @@ -1,6 +1,6 @@ /* * tvheadend, HTTP interface - * Copyright (C) 2007 Andreas Öman + * Copyright (C) 2007 Andreas Öman * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -319,24 +319,30 @@ int http_encoding_valid(http_connection_t *hc, const char *encoding) { const char *accept; - size_t l = strlen(encoding); - size_t i; + char *tokbuf, *tok, *saveptr, *q, *s; accept = http_arg_get(&hc->hc_args, "accept-encoding"); if (!accept) return 0; - while (*accept) { - for (i = 0; i < l; i++) - if (tolower(accept[i]) != encoding[i]) - break; - if (i < l) - continue; - accept += l; - while (*accept == ' ') - accept++; - if (*accept == ',' || *accept == '\0') + tokbuf = tvh_strdupa(accept); + tok = strtok_r(tokbuf, ",", &saveptr); + while (tok) { + while (*tok == ' ') + tok++; + // check for semicolon + if ((q = strchr(tok, ';')) != NULL) { + *q = '\0'; + q++; + while (*q == ' ') + q++; + } + if ((s = strchr(tok, ' ')) != NULL) + *s = '\0'; + // check for matching encoding with q > 0 + if ((!strcasecmp(tok, encoding) || !strcmp(tok, "*")) && (q == NULL || strncmp(q, "q=0.000", strlen(q)))) return 1; + tok = strtok_r(NULL, ",", &saveptr); } return 0; }