httpd-apreq-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject cvs commit: httpd-apreq-2/t cookie.c
Date Mon, 21 Apr 2003 19:40:12 GMT
joes        2003/04/21 12:40:11

  Modified:    src      apreq_cookie.c apreq_cookie.h
               t        cookie.c
  Log:
  Make cookie API more like the param API.
  
  Revision  Changes    Path
  1.11      +34 -33    httpd-apreq-2/src/apreq_cookie.c
  
  Index: apreq_cookie.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_cookie.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- apreq_cookie.c	21 Apr 2003 18:45:57 -0000	1.10
  +++ apreq_cookie.c	21 Apr 2003 19:40:11 -0000	1.11
  @@ -79,13 +79,12 @@
       return apreq_add_cookie(jar,c);
   }
   
  -APREQ_DECLARE(void) apreq_cookie_expires(apreq_cookie_t *c, 
  +APREQ_DECLARE(void) apreq_cookie_expires(apr_pool_t *p,
  +                                         apreq_cookie_t *c, 
                                            const char *time_str)
   {
       if ( c->version == NETSCAPE )
  -        c->time.expires = apreq_expires(apreq_env_pool(c->env), 
  -                                        time_str,
  -                                        NSCOOKIE);
  +        c->time.expires = apreq_expires(p, time_str, NSCOOKIE);
       else
           c->time.max_age = apreq_atol(time_str);
   }
  @@ -107,7 +106,7 @@
           if (j == NULL || apreq_jar_nelts(j) == 0) 
               return APREQ_COOKIE_VERSION;
   
  -        else if (apreq_table_do(has_rfc_cookie, NULL, j) == 1)
  +        else if (apreq_table_do(has_rfc_cookie, NULL, j->cookies) == 1)
               return NETSCAPE;
   
           else
  @@ -117,9 +116,10 @@
           return RFC;
   }
   
  -APREQ_DECLARE(apr_status_t) apreq_cookie_attr(apreq_cookie_t *c, 
  -                                              char *attr,
  -                                              char *val)
  +static apr_status_t apreq_cookie_attr(apr_pool_t *p,
  +                                      apreq_cookie_t *c, 
  +                                      char *attr,
  +                                      char *val)
   {
       dAPREQ_LOG;
   
  @@ -140,13 +140,11 @@
               return APR_SUCCESS;
           }
           else {
  -            apreq_log(APREQ_WARN APR_BADARG, c->env, 
  -                       "Bad Version number (no digits found).");
               return APR_BADARG;
           }
   
       case 'e': case 'm': /* expires, max-age */
  -        apreq_cookie_expires(c, val);
  +        apreq_cookie_expires(p, c, val);
           return APR_SUCCESS;
   
       case 'd':
  @@ -181,23 +179,17 @@
   
       };
   
  -    apreq_log(APREQ_WARN APR_ENOTIMPL, c->env,
  -               "unknown cookie attribute: `%s' => `%s'", 
  -               attr, val);
  -
       return APR_ENOTIMPL;
   }
   
  -APREQ_DECLARE(apreq_cookie_t *) apreq_make_cookie(void *ctx, 
  +APREQ_DECLARE(apreq_cookie_t *) apreq_make_cookie(apr_pool_t *p, 
                                     const apreq_cookie_version_t version,
                                     const char *name, const apr_size_t nlen,
                                     const char *value, const apr_size_t vlen)
   {
  -    apr_pool_t *p = apreq_env_pool(ctx);
       apreq_cookie_t *c = apr_palloc(p, vlen + sizeof *c);
       apreq_value_t *v = &c->v;
   
  -    c->env = ctx;
       v->size = vlen;
       v->name = apr_pstrmemdup(p, name, nlen);
       memcpy(v->data, value, vlen);
  @@ -305,9 +297,13 @@
           j = apreq_env_jar(ctx, NULL);
           if ( j != NULL )
               return j;
  -        
  +
  +        j = apr_palloc(p, sizeof *j);
  +        j->pool = p;
  +        j->env = ctx;
  +        j->cookies = apreq_table_make(p, APREQ_NELTS);
  +
           data = apreq_env_cookie(ctx);
  -        j = apreq_table_make(apreq_env_pool(ctx), APREQ_NELTS);
   
           /* XXX: potential race condition here 
              between env_jar fetch and env_jar set.  */
  @@ -318,7 +314,10 @@
               return j;
       }
       else {
  -        j = apreq_table_make(p, APREQ_NELTS);
  +        j = apr_palloc(p, sizeof *j);
  +        j->pool = p;
  +        j->env = ctx;
  +        j->cookies = apreq_table_make(p, APREQ_NELTS);
       }
   
       origin = data;
  @@ -377,8 +376,8 @@
               status = get_pair(&data, &name, &nlen, &value, &vlen);
   
               if (status == APR_SUCCESS)
  -                apreq_cookie_attr(c, apr_pstrmemdup(p, name, nlen),
  -                                     apr_pstrmemdup(p,value, vlen));    
  +                apreq_cookie_attr(p, c, apr_pstrmemdup(p, name, nlen),
  +                                        apr_pstrmemdup(p,value, vlen));    
               else {
                   c->v.status = status;
                   apreq_log(APREQ_WARN c->v.status, ctx,
  @@ -390,7 +389,7 @@
               status = get_pair(&data, &name, &nlen, &value, &vlen);
   
               if (status == APR_SUCCESS) {
  -                c = apreq_make_cookie(ctx, version, name, nlen, 
  +                c = apreq_make_cookie(p, version, name, nlen, 
                                         value, vlen);
                   apreq_log(APREQ_DEBUG status, ctx, 
                             "adding cookie: %s => %s", c->v.name, c->v.data);
  @@ -485,39 +484,41 @@
           return NULL;
   }
   
  -APREQ_DECLARE(apr_status_t) apreq_bake_cookie(const apreq_cookie_t *c)
  +APREQ_DECLARE(apr_status_t) apreq_bake_cookie(const apreq_cookie_t *c,
  +                                              void *ctx)
   {
  -    char *s = apreq_cookie_as_string(apreq_env_pool(c->env),c);
  +    char *s = apreq_cookie_as_string(apreq_env_pool(ctx),c);
       dAPREQ_LOG;
   
       if (s == NULL) {
  -        apreq_log(APREQ_ERROR APR_ENAMETOOLONG, c->env, 
  +        apreq_log(APREQ_ERROR APR_ENAMETOOLONG, ctx, 
                     "Serialized cookie exceeds APREQ_COOKIE_LENGTH = %d", 
                       APREQ_COOKIE_LENGTH);
           return APR_ENAMETOOLONG;
       }
   
  -    return apreq_env_set_cookie(c->env, s);
  +    return apreq_env_set_cookie(ctx, s);
   }
   
  -APREQ_DECLARE(apr_status_t) apreq_bake2_cookie(const apreq_cookie_t *c)
  +APREQ_DECLARE(apr_status_t) apreq_bake2_cookie(const apreq_cookie_t *c,
  +                                               void *ctx)
   {
  -    char *s = apreq_cookie_as_string(apreq_env_pool(c->env),c);
  +    char *s = apreq_cookie_as_string(apreq_env_pool(ctx),c);
       dAPREQ_LOG;
   
       if ( s == NULL ) {
  -        apreq_log(APREQ_ERROR APR_ENAMETOOLONG, c->env,
  +        apreq_log(APREQ_ERROR APR_ENAMETOOLONG, ctx,
                     "Serialized cookie exceeds APREQ_COOKIE_LENGTH = %d", 
                       APREQ_COOKIE_LENGTH);
           return APR_ENAMETOOLONG;
       }
       else if ( c->version == NETSCAPE ) {
  -        apreq_log(APREQ_ERROR APR_EMISMATCH, c->env,
  +        apreq_log(APREQ_ERROR APR_EMISMATCH, ctx,
                     "Cannot bake2 a Netscape cookie: %s", s);
           return APR_EMISMATCH;
       }
   
  -    return apreq_env_set_cookie2(c->env, s);
  +    return apreq_env_set_cookie2(ctx, s);
   }
   
   
  
  
  
  1.10      +15 -15    httpd-apreq-2/src/apreq_cookie.h
  
  Index: apreq_cookie.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_cookie.h,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- apreq_cookie.h	18 Apr 2003 20:15:50 -0000	1.9
  +++ apreq_cookie.h	21 Apr 2003 19:40:11 -0000	1.10
  @@ -7,7 +7,11 @@
   extern "C" {
   #endif 
   
  -typedef struct apreq_table_t apreq_jar_t;
  +typedef struct apreq_jar_t {
  +    apreq_table_t *cookies;
  +    apr_pool_t    *pool;
  +    void          *env;
  +} apreq_jar_t;
   
   typedef enum { NETSCAPE, RFC } apreq_cookie_version_t;
   
  @@ -31,8 +35,6 @@
           const char *expires; 
       } time;
   
  -    void           *env;
  -
       apreq_value_t   v;           /* "raw" value (extended struct) */
   
   } apreq_cookie_t;
  @@ -52,8 +54,8 @@
    */
   
   int apreq_jar_items(apreq_jar_t *jar);
  -#define apreq_jar_items(j) apreq_table_nelts(j)
  -#define apreq_jar_nelts(j) apreq_table_nelts(j)
  +#define apreq_jar_items(j) apreq_table_nelts(j->cookies)
  +#define apreq_jar_nelts(j) apreq_table_nelts(j->cookies)
   
   /**
    * Fetches a cookie from the jar
  @@ -64,7 +66,7 @@
   
   apreq_cookie_t *apreq_cookie(const apreq_jar_t *jar, const char *name);
   #define apreq_cookie(j,k) apreq_value_to_cookie(apreq_char_to_value( \
  -                              apreq_table_get(j,k)))
  +                              apreq_table_get((j)->cookies,k)))
   
   /**
    * Adds a cookie by pushing it to the bottom of the jar.
  @@ -74,7 +76,7 @@
    */
   
   apr_status_t apreq_add_cookie(apreq_jar_t *jar, const apreq_cookie_t *c);
  -#define apreq_add_cookie(jar,c)  apreq_table_add(jar, &(c)->v)
  +#define apreq_add_cookie(jar,c)  apreq_table_add(jar->cookies, &(c)->v)
   
   /**
    * Parse the incoming "Cookie:" headers into a cookie jar.
  @@ -109,15 +111,11 @@
    * @param value The cookie's value.
    * @param vlen  Length of value.
    */
  -APREQ_DECLARE(apreq_cookie_t *) apreq_make_cookie(void *ctx, 
  +APREQ_DECLARE(apreq_cookie_t *) apreq_make_cookie(apr_pool_t *p, 
                                     const apreq_cookie_version_t version,
                                     const char *name, const apr_size_t nlen, 
                                     const char *value, const apr_size_t vlen);
   
  -
  -APREQ_DECLARE(apr_status_t) apreq_cookie_attr(apreq_cookie_t *c, 
  -                                              char *attr, char *val);
  -
   /**
    * Returns a string that represents the cookie as it would appear 
    * in a valid "Set-Cookie*" header.
  @@ -152,7 +150,7 @@
    * replace with this value instead.  The time_str should be in a format
    * that apreq_atod() can understand, namely /[+-]?\d+\s*[YMDhms]/.
    */
  -APREQ_DECLARE(void) apreq_cookie_expires(apreq_cookie_t *c, 
  +APREQ_DECLARE(void) apreq_cookie_expires(apr_pool_t *p, apreq_cookie_t *c, 
                                            const char *time_str);
   
   /**
  @@ -160,7 +158,8 @@
    *
    * @param c The cookie.
    */
  -APREQ_DECLARE(apr_status_t) apreq_bake_cookie(const apreq_cookie_t *c);
  +APREQ_DECLARE(apr_status_t) apreq_bake_cookie(const apreq_cookie_t *c, 
  +                                              void *ctx);
   
   /* XXX: how about baking whole cookie jars, too ??? */
   
  @@ -169,7 +168,8 @@
    *
    * @param c The cookie.
    */
  -APREQ_DECLARE(apr_status_t) apreq_bake2_cookie(const apreq_cookie_t *c);
  +APREQ_DECLARE(apr_status_t) apreq_bake2_cookie(const apreq_cookie_t *c,
  +                                               void *ctx);
   
   APREQ_DECLARE(apreq_cookie_version_t) apreq_ua_cookie_version(void *ctx);
   
  
  
  
  1.2       +12 -12    httpd-apreq-2/t/cookie.c
  
  Index: cookie.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/cookie.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- cookie.c	21 Apr 2003 18:45:57 -0000	1.1
  +++ cookie.c	21 Apr 2003 19:40:11 -0000	1.2
  @@ -71,22 +71,22 @@
   {
       const char *val;
   
  -    val = apreq_table_get(j,"a");
  +    val = apreq_table_get(j->cookies,"a");
       CuAssertStrEquals(tc,"1",val);
  -    val = apreq_table_get(j,"b");
  +    val = apreq_table_get(j->cookies,"b");
       CuAssertStrEquals(tc,"2",val);
   
  -    val = apreq_table_get(j,"foo");
  +    val = apreq_table_get(j->cookies,"foo");
       CuAssertStrEquals(tc,"bar",val);
  -    val = apreq_table_get(j,"fl");
  +    val = apreq_table_get(j->cookies,"fl");
       CuAssertStrEquals(tc,"left",val);
  -    val = apreq_table_get(j,"fr");
  +    val = apreq_table_get(j->cookies,"fr");
       CuAssertStrEquals(tc,"right",val);
  -    val = apreq_table_get(j,"frl");
  +    val = apreq_table_get(j->cookies,"frl");
       CuAssertStrEquals(tc,"right-left",val);
  -    val = apreq_table_get(j,"flr");
  +    val = apreq_table_get(j->cookies,"flr");
       CuAssertStrEquals(tc,"left-right",val);
  -    val = apreq_table_get(j,"fll");
  +    val = apreq_table_get(j->cookies,"fll");
       CuAssertStrEquals(tc,"left-left",val);
   }
   
  @@ -110,17 +110,16 @@
       CuAssertStrEquals(tc, "foo=bar; path=/quux; domain=example.com",
                         apreq_cookie_as_string(p,c));
   
  -    apreq_cookie_expires(c, "+1y");
  +    apreq_cookie_expires(p, c, "+1y");
       CuAssertStrEquals(tc,apr_pstrcat(p,
                            "foo=bar; path=/quux; domain=example.com; expires=", 
                            expires, NULL), apreq_cookie_as_string(p,c));
  -
   }
   
   
   static void rfc_cookie(CuTest *tc)
   {
  -    apreq_cookie_t *c = apreq_make_cookie(NULL,RFC,"rfc",3,"out",3);
  +    apreq_cookie_t *c = apreq_make_cookie(p,RFC,"rfc",3,"out",3);
       apreq_cookie_version_t version = RFC;
       long expires = apreq_atol("+3m");
   
  @@ -137,7 +136,8 @@
                 "rfc=out; Version=1; path=/quux; domain=example.com",
                         apreq_cookie_as_string(p,c));
   
  -    apreq_cookie_expires(c, "+3m");
  +
  +    apreq_cookie_expires(p, c, "+3m");
       CuAssertStrEquals(tc,apr_psprintf(p,
            "rfc=out; Version=1; path=/quux; domain=example.com; max-age=%ld", 
                  expires), apreq_cookie_as_string(p,c));
  
  
  

Mime
View raw message