httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n.@apache.org
Subject cvs commit: httpd-2.0/modules/mappers mod_rewrite.c
Date Sun, 03 Aug 2003 19:04:54 GMT
nd          2003/08/03 12:04:54

  Modified:    modules/mappers mod_rewrite.c
  Log:
  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.
  
  Revision  Changes    Path
  1.212     +40 -46    httpd-2.0/modules/mappers/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_rewrite.c,v
  retrieving revision 1.211
  retrieving revision 1.212
  diff -u -r1.211 -r1.212
  --- mod_rewrite.c	3 Aug 2003 18:38:14 -0000	1.211
  +++ mod_rewrite.c	3 Aug 2003 19:04:54 -0000	1.212
  @@ -2133,6 +2133,8 @@
   
   /*
    * 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 @@
       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);
  -        }
  -        else {
  -            path = NULL;
  +    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;
           }
   
  -        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 *
  +        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);
  -                /*
  -                 * 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);
  -            }
  +                                            "%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 {
  +            rewritelog(rmain, 5, "skipping already set cookie '%s'", var);
           }
       }
  +
  +    return;
   }
   
   static void do_expand_cookie(request_rec *r, data_item *cookie,
  
  
  

Mime
View raw message