]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
http: fix Accept-Encoding parsing
authorstbenz <benz.st@gmail.com>
Fri, 22 May 2015 18:38:35 +0000 (20:38 +0200)
committerJaroslav Kysela <perex@perex.cz>
Fri, 22 May 2015 19:28:08 +0000 (21:28 +0200)
src/http.c

index 8d27b22c42a4d4215556afff58490648f0205db3..4575e1f0c2c9a34103356d9711bcd4148a1d3978 100644 (file)
@@ -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;
 }