]> granicus.if.org Git - apache/commitdiff
Simplify code by using apr_strtok
authorStefan Fritsch <sf@apache.org>
Mon, 9 Nov 2009 09:59:53 +0000 (09:59 +0000)
committerStefan Fritsch <sf@apache.org>
Mon, 9 Nov 2009 09:59:53 +0000 (09:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@834006 13f79535-47bb-0310-9956-ffa450edef68

modules/loggers/mod_log_config.c

index ee0afd5b892ff18437c3b308022a31965b6457d4..29836196fb95d223cd6a2a076d7931d6b11ef6d5 100644 (file)
@@ -496,7 +496,7 @@ static const char *log_env_var(request_rec *r, char *a)
 
 static const char *log_cookie(request_rec *r, char *a)
 {
-    const char *cookies;
+    const char *cookies_entry;
 
     /*
      * This supports Netscape version 0 cookies while being tolerant to
@@ -508,31 +508,20 @@ static const char *log_cookie(request_rec *r, char *a)
      * - commas to separate cookies
      */
 
-    if ((cookies = apr_table_get(r->headers_in, "Cookie"))) {
-        const char *cookie;
-        const char *cookie_end;
-        const char *cp;
-        int a_len = strlen(a);
-        /*
-         * Loop over semicolon-separated cookies.
-         */
-        for (cookie = cookies; *cookie != '\0'; cookie = cookie_end + strspn(cookie_end, "; \t")) {
-            /* Loop invariant: "cookie" always points to start of cookie name */
-
-            /* Set cookie_end to ';' that ends this cookie, or '\0' at EOS */
-            cookie_end = cookie + strcspn(cookie, ";");
-
-            cp = cookie + a_len;
-            if (cp >= cookie_end)
-                continue;
-            cp += strspn(cp, " \t");
-            if (*cp == '=' && !strncasecmp(cookie, a, a_len)) {
-                char *cookie_value;
-                cp++;  /* Move past '=' */
-                cp += strspn(cp, " \t");  /* Move past WS */
-                cookie_value = apr_pstrmemdup(r->pool, cp, cookie_end - cp);
-                return ap_escape_logitem(r->pool, cookie_value);
-             }
+    if ((cookies_entry = apr_table_get(r->headers_in, "Cookie"))) {
+        char *cookie, *last1, *last2;
+        char *cookies = apr_pstrdup(r->pool, cookies_entry);
+
+        while ((cookie = apr_strtok(cookies, ";", &last1))) {
+            char *name = apr_strtok(cookie, "=", &last2);
+            char *value;
+            apr_collapse_spaces(name, name);
+
+            if (!strcasecmp(name, a) && (value = apr_strtok(NULL, "=", &last2))) {
+                value += strspn(value, " \t");  /* Move past WS */
+                return ap_escape_logitem(r->pool, value);
+            }
+            cookies = NULL;
         }
     }
     return NULL;