You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-cvs@httpd.apache.org by jo...@apache.org on 2003/04/18 22:15:51 UTC

cvs commit: httpd-apreq-2/src apreq.h apreq_cookie.h apreq_params.h apreq_parsers.c apreq_parsers.h apreq_tables.c apreq_tables.h

joes        2003/04/18 13:15:50

  Modified:    src      apreq.h apreq_cookie.h apreq_params.h
                        apreq_parsers.c apreq_parsers.h apreq_tables.c
                        apreq_tables.h
  Log:
  Polish table iterator API.
  
  Revision  Changes    Path
  1.12      +4 -4      httpd-apreq-2/src/apreq.h
  
  Index: apreq.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq.h,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- apreq.h	15 Apr 2003 21:47:23 -0000	1.11
  +++ apreq.h	18 Apr 2003 20:15:50 -0000	1.12
  @@ -1,16 +1,16 @@
   #ifndef APREQ_H
   #define APREQ_H
   
  +#include "apr_tables.h" 
  +#include <stddef.h>
  +
   #ifdef  __cplusplus
    extern "C" {
   #endif 
   
  -#include "apr_tables.h" 
  -
  -#include <stddef.h>
   
   #define APREQ_DECLARE(d)                d
  -
  +#define APREQ_DECLARE_NONSTD(d)         d
   #define APREQ_URL_ENCTYPE               "application/x-www-form-urlencoded"
   #define APREQ_MFD_ENCTYPE               "multipart/form-data"
   #define APREQ_XML_ENCTYPE               "application/xml"
  
  
  
  1.9       +1 -2      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- apreq_cookie.h	12 Apr 2003 01:45:30 -0000	1.8
  +++ apreq_cookie.h	18 Apr 2003 20:15:50 -0000	1.9
  @@ -1,12 +1,11 @@
   #ifndef APREQ_COOKIE_H
   #define APREQ_COOKIE_H
   
  +#include "apreq_tables.h"
   
   #ifdef  __cplusplus
   extern "C" {
   #endif 
  -
  -#include "apreq_tables.h"
   
   typedef struct apreq_table_t apreq_jar_t;
   
  
  
  
  1.9       +3 -2      httpd-apreq-2/src/apreq_params.h
  
  Index: apreq_params.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_params.h,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- apreq_params.h	15 Apr 2003 09:36:11 -0000	1.8
  +++ apreq_params.h	18 Apr 2003 20:15:50 -0000	1.9
  @@ -59,12 +59,13 @@
   #ifndef APREQ_PARAM_H
   #define APREQ_PARAM_H
   
  +#include "apreq_tables.h"
  +#include "apr_buckets.h"
  +
   #ifdef __cplusplus
   extern "C" {
   #endif /* __cplusplus */
   
  -#include "apreq_tables.h"
  -#include "apr_buckets.h"
   
   /***************************************************
    * API: apreq_params.c
  
  
  
  1.15      +7 -10     httpd-apreq-2/src/apreq_parsers.c
  
  Index: apreq_parsers.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_parsers.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- apreq_parsers.c	17 Apr 2003 21:23:13 -0000	1.14
  +++ apreq_parsers.c	18 Apr 2003 20:15:50 -0000	1.15
  @@ -909,22 +909,22 @@
   
   
           }
  -        break;
  +        break;  /* not reached */
   
       case MFD_UPLOAD:
           {
               apr_bucket *eos;
               apr_status_t s = split_on_bdry(pool, ctx->bb, bb, ctx->bdry);
               apreq_param_t *param;
  -            const apreq_value_t *v;
  -            int dummy;
  +            apreq_table_iter_t ti;
  +
  +            ti.t = req->body;
  +            apreq_table_last(&ti);
  +            param = apreq_value_to_param(ti.v);
   
               switch (s) {
   
               case APR_INCOMPLETE:
  -                apreq_table_last(req->body, &v, &dummy);
  -                param = apreq_value_to_param(v);
  -
                   if (parser->hook)
                       return parser->hook(pool, param->bb, ctx->bb, parser);
                   else {
  @@ -933,9 +933,6 @@
                   }
   
               case APR_SUCCESS:
  -                apreq_table_last(req->body, &v, &dummy);
  -                param = apreq_value_to_param(v);
  -
                   eos = apr_bucket_eos_create(ctx->bb->bucket_alloc);
                   APR_BRIGADE_INSERT_TAIL(ctx->bb, eos);
   
  @@ -955,7 +952,7 @@
               }
   
           }
  -        break;
  +        break;  /* not reached */
   
       case MFD_ERROR:
           return APR_EGENERAL;
  
  
  
  1.8       +2 -3      httpd-apreq-2/src/apreq_parsers.h
  
  Index: apreq_parsers.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_parsers.h,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- apreq_parsers.h	15 Apr 2003 09:36:11 -0000	1.7
  +++ apreq_parsers.h	18 Apr 2003 20:15:50 -0000	1.8
  @@ -1,13 +1,12 @@
   #ifndef APREQ_PARSERS_H
   #define APREQ_PARSERS_H
   
  +#include "apreq_params.h"
  +#include "apr_buckets.h"
   
   #ifdef  __cplusplus
   extern "C" {
   #endif 
  -
  -#include "apreq_params.h"
  -#include "apr_buckets.h"
   
   /* parsers: single copy paradigm */
   
  
  
  
  1.11      +45 -69    httpd-apreq-2/src/apreq_tables.c
  
  Index: apreq_tables.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_tables.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- apreq_tables.c	12 Apr 2003 01:45:30 -0000	1.10
  +++ apreq_tables.c	18 Apr 2003 20:15:50 -0000	1.11
  @@ -146,7 +146,8 @@
   
   #define DEAD(idx)     ( (idx)[o].key == NULL )
   #define KILL(t,idx) do { (idx)[o].key = NULL; \
  -                         (t)->ghosts++; } while (0)
  +                         if (idx ==(t)->a.nelts-1) (t)->a.nelts--; \
  +                         else                      (t)->ghosts++; } while (0)
   #define RESURRECT(t,idx) do { (idx)[o].key = (idx)[o].val->name; \
                                 (t)->ghosts--; } while (0)
   
  @@ -767,11 +768,8 @@
       if (t->ghosts < t->a.nelts) {
           apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
   
  -        /* first eliminate trailing ghosts */
  -        while (DEAD(t->a.nelts - 1)) {
  -            t->a.nelts--;
  -            t->ghosts--;
  -        }
  +        /* trailing ghosts cannot occur; IOW t->a.nelts-1 is 
  +           always alive */
   
           /* bury any remaining ghosts */
           if (t->ghosts) {
  @@ -812,8 +810,8 @@
       return v2c(idx[o].val);
   }
   
  -APREQ_DECLARE(const char *) apreq_table_get_cached(apreq_table_t *t,
  -                                                   const char *key)
  +APREQ_DECLARE(const char *) apreq_table_cache(apreq_table_t *t,
  +                                              const char *key)
   {
       int *root = &t->root[TABLE_HASH(key)];
       int idx = *root;
  @@ -1151,99 +1149,77 @@
   
   /********************* iterators ********************/
   
  -APREQ_DECLARE(apr_status_t) apreq_table_fetch(const apreq_table_t *t,
  -                                              const apreq_value_t **val,
  -                                              int *off)
  +APREQ_DECLARE(apr_status_t) APR_INLINE apreq_table_fetch(apreq_table_iter_t *ti, int idx)
   {
  -    int idx = *off;
  +    const apreq_table_t *t = ti->t;
       apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
   
       if (idx < 0 || idx >= t->a.nelts - t->ghosts) {
  -        *val = NULL;
  +        ti->v = NULL;
  +        ti->i = -1;
           return APR_EGENERAL;
       }
   
  -    if (t->ghosts) {   /* count ghosts: O(N) */
  -        int n;
  -
  -        for (n=0; n <= idx; ++n)
  -            if ( DEAD(n) )
  -                ++idx;
  -
  -        *off = idx;
  +    if (t->ghosts) {
  +        if (idx == t->a.nelts - t->ghosts - 1)
  +            ti->i = t->a.nelts - 1;
  +        else
  +            for (ti->i = 0; ti->i <= idx; ti->i++)
  +                if ( DEAD(ti->i) )
  +                    ++idx;
       }
  +    else
  +        ti->i = idx;
   
  -    *val = idx[o].val;
  +    ti->v = idx[o].val;
   
       return APR_SUCCESS;
   }
   
  -APREQ_DECLARE(apr_status_t) apreq_table_first(const apreq_table_t *t,
  -                                              const apreq_value_t **val,
  -                                              int *off)
  -{
  -    *off = -1;
  -    return apreq_table_next(t,val,off);
  -}
  -
  -APREQ_DECLARE(apr_status_t) apreq_table_next(const apreq_table_t *t,
  -                                             const apreq_value_t **val,
  -                                             int *off)
  +APREQ_DECLARE(apr_status_t) APR_INLINE apreq_table_next(apreq_table_iter_t *ti)
   {
  -    int idx = *off;
  +    const apreq_table_t *t = ti->t;
       apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
   
  -    if (idx < -1 || idx >= t->a.nelts) {
  -        *val = NULL;
  +    if (ti->i < 0 || ti->i >= t->a.nelts) {
  +        ti->v = NULL;
  +        ti->i = -1;
           return APR_EGENERAL;
       }
   
  -    do { 
  -        if (++idx == t->a.nelts) {
  -            *off = idx;
  -            *val = NULL;
  -            return APR_EGENERAL;
  -        }
  -    } while ( DEAD(idx) );
  +    if (ti->i == t->a.nelts - 1) {
  +        ti->v = NULL;
  +        ti->i = -1;
  +        return APR_SUCCESS;
  +    }
  +
  +    while (DEAD(++ti->i))
  +        ;       /* skip dead elements */
   
  -    *off = idx;
  -    *val = idx[o].val;
  +    ti->v = ti->i[o].val;
       return APR_SUCCESS;
   }
   
  -APREQ_DECLARE(apr_status_t) apreq_table_last(const apreq_table_t *t, 
  -                                             const apreq_value_t **val, 
  -                                             int *off)
  -{
  -    *off = t->a.nelts;
  -    return apreq_table_prev(t,val,off);
  -}
   
  -APREQ_DECLARE(apr_status_t) apreq_table_prev(const apreq_table_t *t, 
  -                                             const apreq_value_t **val,
  -                                             int *off)
  +APREQ_DECLARE(apr_status_t) APR_INLINE apreq_table_prev(apreq_table_iter_t *ti)
   {
  -    int idx = *off;
  +    const apreq_table_t *t = ti->t;
       apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
   
  -    if (idx <= 0 || idx > t->a.nelts) {
  -        *val = NULL;
  +    if (ti->i < 0 || ti->i >= t->a.nelts) {
  +        ti->v = NULL;
  +        ti->i = -1;
           return APR_EGENERAL;
       }
   
  -    do { 
  -        if (--idx == -1) {
  -            *off = idx;
  -            *val = NULL;
  -            return APR_EGENERAL;
  -        }
  -    } while ( DEAD(idx) );
  +    while (--ti->i >= 0 && DEAD(ti->i))
  +        ; /* skip dead elements */
   
  -    *off = idx;
  -    *val = idx[o].val;
  +    ti->v = (ti->i == -1) ? NULL : ti->i[o].val;
       return APR_SUCCESS;
   }
   
  +
   /* And now for something completely abstract ...
   
    * For each key value given as a vararg:
  @@ -1287,8 +1263,8 @@
    *
    * So to make mod_file_cache easier to maintain, it's a good thing
    */
  -APREQ_DECLARE(int) apreq_table_do(apreq_table_do_callback_fn_t *comp,
  -                                  void *rec, const apreq_table_t *t, ...)
  +APREQ_DECLARE_NONSTD(int) apreq_table_do(apreq_table_do_callback_fn_t *comp,
  +                                         void *rec, const apreq_table_t *t, ...)
   {
       int rv;
   
  
  
  
  1.9       +17 -63    httpd-apreq-2/src/apreq_tables.h
  
  Index: apreq_tables.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_tables.h,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- apreq_tables.h	11 Apr 2003 04:24:02 -0000	1.8
  +++ apreq_tables.h	18 Apr 2003 20:15:50 -0000	1.9
  @@ -232,8 +232,8 @@
    * function may deactivate the tree-balancing algorithm if
    * necessary.
    */
  -APREQ_DECLARE(const char *) apreq_table_get_cached(apreq_table_t *t,
  -                                                   const char *key);
  +APREQ_DECLARE(const char *) apreq_table_cache(apreq_table_t *t,
  +                                              const char *key);
   
   /**
    * Return the (unique) values in an (apreq_value_t *) array,
  @@ -353,64 +353,18 @@
   
   /** Iterator API */
   
  -/**
  - * Fetch a table entry using a specific index.
  - * @param t   Table.
  - * @param val Location of resulting value.
  - * @param off Index of desired value. Upon success, off will be updated
  - *            to reflect the actual offset of the value sought.  Any
  - *            difference reflects the presence of earlier ghosts in 
  - *            the table.
  - */
  -APREQ_DECLARE(apr_status_t) apreq_table_fetch(const apreq_table_t *t,
  -                                              const apreq_value_t **val,
  -                                              int *off);
  -
  -/**
  - * Locate the first value in the table.
  - * @param t   Table.
  - * @param val Location of resulting value.
  - * @param off Index of first value.  The offset will count
  - *            the number of ghosts before the first value.
  - */
  -APREQ_DECLARE(apr_status_t) apreq_table_first(const apreq_table_t *t,
  -                                              const apreq_value_t **val,
  -                                              int *off);
  -
  -/**
  - * Locate the next value in the table.
  - * @param t   Table.
  - * @param val Location of resulting value.
  - * @param off (Internal) Index of next value.  On success, the offset
  - *            will be 1 + the number of ghosts between the current offset
  - *            and the new one.
  - */
  -APREQ_DECLARE(apr_status_t) apreq_table_next(const apreq_table_t *t,
  -                                             const apreq_value_t **val,
  -                                             int *off);
  -/**
  - * Locate the last value in the table.
  - * @param t   Table.
  - * @param val Location of the final value.
  - * @param off (Internal) Index of last value.  The offset will be one
  - *            less than the number of entries (including ghosts)
  - *            occupying the table.
  - */
  -APREQ_DECLARE(apr_status_t) apreq_table_last(const apreq_table_t *t, 
  -                                             const apreq_value_t **val, 
  -                                             int *off);
  -
  -/**
  - * Locate the previous value in the table.
  - * @param t   Table.
  - * @param val Location of previous value.
  - * @param off (Internal) Index of previous value.  On success, the 
  - *            offset will be 1 + the number of ghosts between the 
  - *            current offset and the new one.
  - */
  -APREQ_DECLARE(apr_status_t) apreq_table_prev(const apreq_table_t *t, 
  -                                             const apreq_value_t **val,
  -                                             int *off);
  +typedef struct apreq_table_iter_t {
  +    const apreq_table_t *t;
  +    const apreq_value_t *v;
  +    int                  i;
  +} apreq_table_iter_t;
  +
  +APREQ_DECLARE(apr_status_t) APR_INLINE apreq_table_fetch(apreq_table_iter_t *ti, int idx);
  +#define apreq_table_first(ti) apreq_table_fetch(ti,0)
  +#define apreq_table_last(ti) apreq_table_fetch(ti,apreq_table_nelts((ti)->t)-1)
  +
  +APREQ_DECLARE(apr_status_t) APR_INLINE apreq_table_next(apreq_table_iter_t *ti);
  +APREQ_DECLARE(apr_status_t) APR_INLINE apreq_table_prev(apreq_table_iter_t *ti);
   
   /**
    * Declaration prototype for the iterator callback function of apr_table_do()
  @@ -441,9 +395,9 @@
    *            iterations returned non-zero
    * @see apreq_table_do_callback_fn_t
    */
  -APREQ_DECLARE(int) apreq_table_do(apreq_table_do_callback_fn_t *comp,
  -                                  void *ctx,
  -                                  const apreq_table_t *t, ...);
  +APREQ_DECLARE_NONSTD(int) apreq_table_do(apreq_table_do_callback_fn_t *comp,
  +                                         void *ctx,
  +                                         const apreq_table_t *t, ...);
   
   /** 
    * Iterate over a table running the provided function once for every