]> granicus.if.org Git - apache/commitdiff
cleanup the add_cookie function a bit.
authorAndré Malo <nd@apache.org>
Sun, 3 Aug 2003 19:04:54 +0000 (19:04 +0000)
committerAndré Malo <nd@apache.org>
Sun, 3 Aug 2003 19:04:54 +0000 (19:04 +0000)
- the if(s) check is superfluid. s is guaranteed to be non-NULL
  (except for out of memory)
- strtok as late as possible to save some cycles.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@100892 13f79535-47bb-0310-9956-ffa450edef68

modules/mappers/mod_rewrite.c

index e25a711205019e80b35c80c6b36f19feeeb3b369..f40492d9b2da4c7986cbd953dc068d67c9857b7d 100644 (file)
@@ -2133,6 +2133,8 @@ static void do_expand_env(request_rec *r, data_item *env,
 
 /*
  * perform all the expansions on the cookies
+ *
+ * TODO: use cached time similar to how logging does it
  */
 static void add_cookie(request_rec *r, char *s)
 {
@@ -2145,57 +2147,49 @@ static void add_cookie(request_rec *r, char *s)
     char *tok_cntx;
     char *cookie;
 
-    if (s) {
-        var = apr_strtok(s, ":", &tok_cntx);
-        val = apr_strtok(NULL, ":", &tok_cntx);
-        domain = apr_strtok(NULL, ":", &tok_cntx);
-        /** the line below won't hit the token ever **/
-        expires = apr_strtok(NULL, ":", &tok_cntx);
-        if (expires) {
-            path = apr_strtok(NULL,":", &tok_cntx);
+    var = apr_strtok(s, ":", &tok_cntx);
+    val = apr_strtok(NULL, ":", &tok_cntx);
+    domain = apr_strtok(NULL, ":", &tok_cntx);
+
+    if (var && val && domain) {
+        request_rec *rmain = r;
+        char *notename;
+        void *data;
+
+        while (rmain->main) {
+            rmain = rmain->main;
+        }
+
+        notename = apr_pstrcat(rmain->pool, var, "_rewrite", NULL);
+        apr_pool_userdata_get(&data, notename, rmain->pool);
+        if (!data) {
+            expires = apr_strtok(NULL, ":", &tok_cntx);
+            path = expires ? apr_strtok(NULL, ":", &tok_cntx) : NULL;
+
+            cookie = apr_pstrcat(rmain->pool,
+                                 var, "=", val,
+                                 "; path=", (path)? path : "/",
+                                 "; domain=", domain,
+                                 (expires)? "; expires=" : NULL,
+                                 (expires)?
+                                 ap_ht_time(r->pool,
+                                            r->request_time +
+                                            apr_time_from_sec((60 *
+                                                               atol(expires))),
+                                            "%a, %d-%b-%Y %T GMT", 1)
+                                          : NULL,
+                                 NULL);
+
+            apr_table_add(rmain->err_headers_out, "Set-Cookie", cookie);
+            apr_pool_userdata_set("set", notename, NULL, rmain->pool);
+            rewritelog(rmain, 5, "setting cookie '%s'", cookie);
         }
         else {
-            path = NULL;
-        }
-
-        if (var && val && domain) {
-            /* FIX: use cached time similar to how logging does it */
-            request_rec *rmain = r;
-            char *notename;
-            void *data;
-            while (rmain->main) {
-                rmain = rmain->main;
-            }
-
-            notename = apr_pstrcat(rmain->pool, var, "_rewrite", NULL);
-            apr_pool_userdata_get(&data, notename, rmain->pool);
-            if (data == NULL) {
-                cookie = apr_pstrcat(rmain->pool,
-                                     var, "=", val,
-                                     "; path=", (path)? path : "/",
-                                     "; domain=", domain,
-                                     (expires)? "; expires=" : NULL,
-                                     (expires)?
-                                     ap_ht_time(r->pool,
-                                                r->request_time +
-                                                apr_time_from_sec((60 *
-                                                               atol(expires))),
-                                                "%a, %d-%b-%Y %T GMT", 1)
-                                              : NULL,
-                                     NULL);
-                /*
-                 * XXX: should we add it to err_headers_out as well ?
-                 * if we do we need to be careful that only ONE gets sent out
-                 */
-                apr_table_add(rmain->err_headers_out, "Set-Cookie", cookie);
-                apr_pool_userdata_set("set", notename, NULL, rmain->pool);
-                rewritelog(rmain, 5, "setting cookie '%s'", cookie);
-            }
-            else {
-                rewritelog(rmain, 5, "skipping already set cookie '%s'", var);
-            }
+            rewritelog(rmain, 5, "skipping already set cookie '%s'", var);
         }
     }
+
+    return;
 }
 
 static void do_expand_cookie(request_rec *r, data_item *cookie,