From b209affe9890ccf078c9110fc3ea072ee6859c17 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Malo?= Date: Sun, 3 Aug 2003 19:04:54 +0000 Subject: [PATCH] cleanup the add_cookie function a bit. - 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 | 88 ++++++++++++++++------------------- 1 file changed, 41 insertions(+), 47 deletions(-) diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index e25a711205..f40492d9b2 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -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, -- 2.40.0