]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
http: fix http_get_header_value() - digest auth
authorJaroslav Kysela <perex@perex.cz>
Thu, 8 Feb 2018 17:13:19 +0000 (18:13 +0100)
committerJaroslav Kysela <perex@perex.cz>
Thu, 8 Feb 2018 17:13:27 +0000 (18:13 +0100)
src/http.c

index 1573e4e2ac8d2b2377ea5c7b7644beeaed55af01..96053ee16f540a6037c46cdc5c00942ee1906b75 100644 (file)
@@ -476,31 +476,33 @@ http_encoding_valid(http_connection_t *hc, const char *encoding)
 static char *
 http_get_header_value(const char *hdr, const char *name)
 {
-  char *tokbuf, *tok, *saveptr = NULL, *q, *s;
-
-  tokbuf = tvh_strdupa(hdr);
-  tok = strtok_r(tokbuf, ",", &saveptr);
-  while (tok) {
-    while (*tok == ' ')
-      tok++;
-    if ((q = strchr(tok, '=')) == NULL)
-      goto next;
-    *q = '\0';
-    if (strcasecmp(tok, name))
-      goto next;
-    s = q + 1;
+  char *s, *start, *val;
+  s = tvh_strdupa(hdr);
+  while (*s) {
+    while (*s && *s <= ' ') s++;
+    start = s;
+    while (*s && *s != '=') s++;
+    if (*s == '=') {
+      *s = '\0';
+      s++;
+    }
+    while (*s && *s <= ' ') s++;
     if (*s == '"') {
-      q = strchr(++s, '"');
-      if (q)
-        *q = '\0';
+      val = ++s;
+      while (*s && *s != '"') s++;
+      if (*s == '"') {
+        *s = '\0';
+        s++;
+      }
+      while (*s && (*s <= ' ' || *s == ',')) s++;
     } else {
-      q = strchr(s, ' ');
-      if (q)
-        *q = '\0';
+      val = s;
+      while (*s && *s != ',') s++;
+      *s = '\0';
+      s++;
     }
-    return strdup(s);
-next:
-    tok = strtok_r(NULL, ",", &saveptr);
+    if (*start && strcmp(name, start) == 0)
+      return strdup(val);
   }
   return NULL;
 }