joes 2003/01/19 17:54:44
Modified: src apreq.c apreq.h apreq_tables.c apreq_tables.h
Log:
Clean up table API.
Revision Changes Path
1.2 +16 -36 httpd-apreq-2/src/apreq.c
Index: apreq.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- apreq.c 17 Jan 2003 23:24:52 -0000 1.1
+++ apreq.c 20 Jan 2003 01:54:43 -0000 1.2
@@ -1,17 +1,18 @@
#include "apreq.h"
#include "apr_time.h"
-#include "apr_file_info.h"
#define MIN(a,b) ( (a) < (b) ? (a) : (b) )
#define MAX(a,b) ( (a) > (b) ? (a) : (b) )
-apreq_value_t *apreq_value_make(apr_pool_t *p, const char *str,
- const apr_ssize_t size)
+apreq_value_t *apreq_value_make(apr_pool_t *p, const char *n,
+ const char *d, const apr_ssize_t s)
{
- apreq_value_t *v = apr_palloc(p, size + sizeof *v);
- memcpy(v->data,str,size);
- v->size = size;
- v->data[size] = 0;
+ apreq_value_t *v = apr_palloc(p, s + sizeof *v);
+ memcpy(v->data, d, s);
+ v->flags = 0;
+ v->name = n;
+ v->size = s;
+ v->data[s] = 0;
return v;
}
@@ -69,8 +70,9 @@
memcpy(rv->data, a[j]->data, a[j]->size);
rv->size += a[j]->size;
}
-
- rv->data[rv->size] = 0; /* nul-terminate rv->data */
+ rv->flags = 0; /* XXX */
+ rv->name = a[0]->name;
+ rv->data[rv->size] = 0; /* nul-terminate rv->data */
return rv;
}
@@ -163,6 +165,7 @@
returns NULL if not found, or a pointer to the start of the first match.
*/
+/* XXX: should we drop this and replace it with apreq_index ? */
char *apreq_memmem(char* hay, apr_off_t hlen,
const char* ndl, apr_off_t nlen, int part)
{
@@ -185,12 +188,12 @@
return hay;
}
-apr_off_t apreq_index(char* hay, apr_off_t hlen,
- const char* ndl, apr_off_t nlen, int part)
+apr_off_t apreq_index(const char* hay, apr_off_t hlen,
+ const char* ndl, apr_off_t nlen, int part)
{
apr_off_t len = hlen;
- char *end = hay + hlen;
- char *begin = hay;
+ const char *end = hay + hlen;
+ const char *begin = hay;
while ( (hay = memchr(hay, ndl[0], len)) ) {
len = end - hay;
@@ -296,29 +299,6 @@
*d = 0;
return esc;
}
-
-/*
-
-char *apreq_script_name(request_rec *r)
-{
- char *tmp;
-
- if(r->path_info && *r->path_info) {
- int pi_start = ap_find_path_info(r->uri,r->path_info);
- tmp = apr_pstrndup(r->pool,r->uri,pi_start);
- }
- else {
- tmp = r->uri;
- }
-
- return tmp;
-}
-char *(apreq_script_path)(request_rec *r)
-{
- return apreq_script_path(r);
-}
-
-*/
static char *apreq_array_pstrcat(apr_pool_t *p,
const apr_array_header_t *arr,
1.2 +22 -22 httpd-apreq-2/src/apreq.h
Index: apreq.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- apreq.h 17 Jan 2003 23:24:52 -0000 1.1
+++ apreq.h 20 Jan 2003 01:54:43 -0000 1.2
@@ -17,8 +17,8 @@
#define APREQ_URL_LENGTH 33
#define APREQ_MFD_ENCTYPE "multipart/form-data"
#define APREQ_MFD_ENCTYPE_LENGTH 19
-#define APREQ_XML_ENCTYPE "text/xml"
-#define APREQ_XML_ENCTYPE_LENGTH 8
+#define APREQ_XML_ENCTYPE "application/xml"
+#define APREQ_XML_ENCTYPE_LENGTH 15
#define APREQ_EXPIRES_HTTP 1
#define APREQ_EXPIRES_NSCOOKIE 2
@@ -39,17 +39,21 @@
#define APREQ_QUOTE 3
/* status codes */
-#define APREQ_OK 0
-#define APREQ_CONTINUE 100
-#define APREQ_ERROR 500
+#define APREQ_OK 0
+#define APREQ_CONTINUE 100
+#define APREQ_ERROR 500
+
typedef struct apreq_value_t {
+ const char *name;
apr_ssize_t size;
- unsigned char flags; /* ??? */
+ unsigned flags;
char data[1];
} apreq_value_t;
-
+typedef apreq_value_t *(apreq_value_make_t)(apr_pool_t *p, const char *name,
+ const char *data,
+ const apr_ssize_t size);
typedef apreq_value_t *(apreq_value_merge_t)(apr_pool_t *p,
const apr_array_header_t *a);
typedef apreq_value_t *(apreq_value_copy_t)(apr_pool_t *p,
@@ -58,8 +62,11 @@
#define apreq_attr_to_type(T,A,P) ( (T*) ((char*)(P)-offsetof(T,A)) )
#define apreq_char_to_value(ptr) apreq_attr_to_type(apreq_value_t, data,
ptr)
-apreq_value_t *apreq_value_make(apr_pool_t *p, const char *str,
- const apr_ssize_t size);
+#define apreq_strtoval(ptr) apreq_char_to_value(ptr)
+#define apreq_strlen(ptr) (apreq_strtoval(ptr)->size)
+
+apreq_value_t *apreq_value_make(apr_pool_t *p, const char *name,
+ const char *data, const apr_ssize_t size);
apreq_value_t *apreq_value_copy(apr_pool_t *p, const apreq_value_t *val);
apreq_value_t *apreq_value_merge(apr_pool_t *p, const apr_array_header_t
*arr);
@@ -69,11 +76,12 @@
const char *sep,
int mode);
-char *apreq_memmem(char* h, apr_off_t hlen,
- const char* n, apr_off_t nlen, int part);
+/* XXX: should we drop this and replace it with apreq_index ? */
+char *apreq_memmem(char* hay, apr_off_t haylen,
+ const char* ndl, apr_off_t ndllen, int part);
-apr_off_t apreq_index(char* h, apr_off_t hlen,
- const char* n, apr_off_t nlen, int part);
+apr_off_t apreq_index(const char* hay, apr_off_t haylen,
+ const char* ndl, apr_off_t ndllen, int part);
/* url-escapes non-alphanumeric characters */
char *apreq_escape(apr_pool_t *p, char *s);
@@ -88,16 +96,8 @@
/* "duration" strings (YMDhms) to seconds */
apr_int64_t apreq_atod(const char *s);
-/* r->uri, omitting path info */
-
-
-/*
-char *apreq_script_name(void *r);
-char *(apreq_script_path)(void *r);
-#define apreq_script_path(r)
ap_make_dirstr_parent(r->pool,apreq_script_name(r))
-*/
#ifdef __cplusplus
}
#endif
-#endif
+#endif /* APREQ_H */
1.2 +105 -217 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- apreq_tables.c 17 Jan 2003 23:24:52 -0000 1.1
+++ apreq_tables.c 20 Jan 2003 01:54:43 -0000 1.2
@@ -76,7 +76,7 @@
#if APR_HAVE_STRINGS_H
#include <strings.h>
#endif
-
+#include "apr_signal.h"
@@ -85,11 +85,11 @@
/* private struct */
typedef struct apreq_table_entry_t {
- const char *key;
- apreq_value_t *val;
+ const char *key; /* = val->name : saves a ptr deref */
+ const apreq_value_t *val;
- enum { RED, BLACK } color;
- int tree[4]; /* LEFT RIGHT PARENT NEXT */
+ enum { RED, BLACK } color;
+ int tree[4]; /* LEFT RIGHT PARENT NEXT */
} apreq_table_entry_t;
/* LEFT & RIGHT must satisfy !LEFT==RIGHT , !RIGHT==LEFT */
@@ -110,6 +110,10 @@
/* this one is strcasecmp compatible */
#define TABLE_HASH(key) (TABLE_INDEX_MASK & *(unsigned char *)(key))
+
+/* XXX: apreq_tables need to be signal( thread? )safe; currently
+ these LOCK* macros indicate some unsafe locations in the code. */
+
/* coarse locking (maybe API worthy) */
#define LOCK_TABLE(t)
#define UNLOCK_TABLE(t)
@@ -120,26 +124,28 @@
#define UNLOCK_TREE(t,n)
#define TREE_IS_LOCKED(t,n)
+
/* This may someday become public, but has hash+tree harmony embedded. */
typedef int (apreq_table_cmp_t)(const char *, const char *);
-#define TF_LOCK 1
-#define TF_BALANCE 8
-#define TF_PROMOTE 16
+#define TF_MERGE 1
+#define TF_BALANCE 2
+#define TF_LOCK 4
struct apreq_table_t {
- apr_array_header_t a;
- int ghosts;
+ apr_array_header_t a;
+ int ghosts;
apreq_table_cmp_t *cmp;
- apreq_value_merge_t *merge;
+
apreq_value_copy_t *copy;
+ apreq_value_merge_t *merge;
- int root[TABLE_HASH_SIZE];
- unsigned long locks;
+ int root[TABLE_HASH_SIZE];
+ unsigned long locks; /* XXX ??? */
- unsigned char flags;
+ unsigned char flags;
#ifdef MAKE_TABLE_PROFILE
int creator; /* XXX Is this the right type ??? */
@@ -150,13 +156,13 @@
/***************************** tree macros ****************************/
-/* NEVER KILL AN ENTRY THAT'S STILL WITHIN THE FOREST */
-#define KILL_ENTRY(t,idx) do { (idx)[o].tree[PARENT] = idx; \
+#define DEAD(idx) ( (idx)[o].key == NULL )
+#define KILL_ENTRY(t,idx) do { (idx)[o].key = NULL; \
(t)->ghosts++; } while (0)
-#define IS_DEAD(idx) ( idx[o].tree[PARENT] == idx )
-#define IN_FOREST(t,idx) ( (idx[o].tree[PARENT] >= 0 && ! IS_DEAD(idx))\
- || idx == (t)->root[TABLE_HASH(idx[o].key)] )
+/* NEVER KILL AN ENTRY THAT'S STILL WITHIN THE FOREST */
+#define IN_FOREST(t,idx) ( (idx)[o].tree[PARENT] >= 0 || \
+ (idx) == t->root[TABLE_HASH((idx)[o].key)] )
/********************* (internal) tree operations ********************/
@@ -480,6 +486,8 @@
static void *apr_array_push_noclear(apr_array_header_t *arr)
{
+ /* XXX: this function is not reentrant */
+
if (arr->nelts == arr->nalloc) {
int new_size = (arr->nalloc <= 0) ? 1 : arr->nalloc * 2;
char *new_data;
@@ -512,17 +520,12 @@
/********************* table ctors ********************/
-static apreq_value_t *collapse(apr_pool_t *p,
+static apreq_value_t *collapse(apr_pool_t *p,
const apr_array_header_t *arr)
{
apreq_value_t **a = (apreq_value_t **)arr->elts;
-
- if (arr->nelts == 0)
- return NULL;
- else
- return a[arr->nelts - 1];
-}
-
+ return (arr->nelts == 0) ? NULL : a[arr->nelts - 1];
+}
APREQ_DECLARE(apreq_table_t *) apreq_table_make(apr_pool_t *p, int nelts)
{
@@ -536,9 +539,9 @@
/* XXX: is memset(*,-1,*) portable ??? */
memset(t->root, -1, TABLE_HASH_SIZE * sizeof(int));
- t->cmp = &strcasecmp;
- t->merge = &apreq_value_merge;
- t->copy = &apreq_value_copy;
+ t->cmp = strcasecmp;
+ t->merge = apreq_value_merge;
+ t->copy = apreq_value_copy;
t->flags = 0;
t->ghosts = 0;
return t;
@@ -570,24 +573,26 @@
return new;
}
-APREQ_DECLARE(apr_table_t *)apreq_table_export(apreq_table_t *t, apr_pool_t
*p)
+APREQ_DECLARE(apr_table_t *)apreq_table_export(const apreq_table_t *t,
+ apr_pool_t *p)
{
int idx;
apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
apr_table_t *s = apr_table_make(p, t->a.nelts);
for (idx = 0; idx < t->a.nelts; ++idx) {
- if (! IS_DEAD(idx))
- apr_table_addn(s, apr_pstrdup(p,idx[o].key),
- t->copy(p,idx[o].val)->data);
+ if (! DEAD(idx)) {
+ const apreq_value_t *v = idx[o].val;
+ apr_table_addn(s, v->name, v->data);
+ }
}
return s;
}
APREQ_DECLARE(apreq_table_t *)apreq_table_import(apr_pool_t *p,
- apr_table_t *s,
- unsigned f)
+ const apr_table_t *s,
+ const unsigned f)
{
apreq_table_t *t = apreq_table_make(p,APREQ_DEFAULT_NELTS);
const apr_array_header_t *a = apr_table_elts(s);
@@ -596,11 +601,12 @@
t->flags = f;
- for ( ; e < end; e++)
- apreq_table_addv(t, apr_pstrdup(p,e->key),
- e->val ? apreq_value_make(p, e->val,
strlen(e->val))
- : NULL);
-
+ for ( ; e < end; e++) {
+ apreq_value_t *v = e->val ?
+ apreq_value_make(p,e->key,e->val,strlen(e->val)) :
+ NULL;
+ apreq_table_add(t, v);
+ }
return t;
}
@@ -614,6 +620,7 @@
{
memset(t->root,-1,TABLE_HASH_SIZE * sizeof(int));
t->a.nelts = 0;
+ t->ghosts = 0;
}
APREQ_DECLARE(int) apreq_table_nelts(const apreq_table_t *t)
@@ -623,7 +630,7 @@
APREQ_DECLARE(int) apreq_is_empty_table(const apreq_table_t *t)
{
- return t != NULL && t->a.nelts > t->ghosts;
+ return t->a.nelts > t->ghosts;
}
@@ -643,13 +650,6 @@
return t->merge;
}
-APREQ_DECLARE(void) apreq_table_cache_lookups(apreq_table_t *t, const int on)
-{
- if (on)
- t->flags |= TF_PROMOTE;
- else
- t->flags &= ~TF_PROMOTE;
-}
APREQ_DECLARE(void) apreq_table_balance(apreq_table_t *t, const int on)
{
@@ -664,7 +664,6 @@
insert(t->cmp, o, &t->root[TABLE_HASH(idx[o].key)], -1, &idx[o],
TF_BALANCE | TREE_PUSH);
- t->flags &= ~TF_PROMOTE;
t->flags |= TF_BALANCE;
}
else {
@@ -672,9 +671,9 @@
}
}
-APREQ_DECLARE(void) apreq_table_normalize(apreq_table_t *t)
+APREQ_DECLARE(apr_status_t) apreq_table_normalize(apreq_table_t *t)
{
- if (t->merge) {
+ if (t->flags & TF_MERGE) {
int idx;
apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
apr_array_header_t *a = apr_array_make(t->a.pool,
APREQ_DEFAULT_NELTS,
@@ -689,10 +688,10 @@
idx[o].tree[NEXT] = -1;
a->nelts = 0;
- *(apreq_value_t **)apr_array_push(a) = idx[o].val;
+ *(const apreq_value_t **)apr_array_push(a) = idx[o].val;
for ( ; j >= 0; j = j[o].tree[NEXT]) {
- *(apreq_value_t **)apr_array_push(a) = j[o].val;
+ *(const apreq_value_t **)apr_array_push(a) = j[o].val;
KILL_ENTRY(t,j);
}
@@ -701,7 +700,10 @@
UNLOCK_TABLE(t);
}
}
+ return APR_SUCCESS;
}
+ else
+ return APR_EGENERAL;
}
static int bury_table_entries(apreq_table_t *t, apr_array_header_t *q)
@@ -762,7 +764,7 @@
apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
/* first eliminate trailing ghosts */
- while (IS_DEAD(t->a.nelts - 1)) {
+ while (DEAD(t->a.nelts - 1)) {
t->a.nelts--;
t->ghosts--;
}
@@ -774,7 +776,7 @@
t->ghosts + 1,
sizeof(int));
for (idx = 0; idx < t->a.nelts; ++idx)
- if (IS_DEAD(idx))
+ if (DEAD(idx))
*(int *)apr_array_push(a) = idx;
rv = bury_table_entries(t,a);
@@ -794,8 +796,20 @@
-APREQ_DECLARE(const char *) apreq_table_get(apreq_table_t *t,
- const char *key)
+APREQ_DECLARE(const char *) apreq_table_get(const apreq_table_t *t,
+ const char *key)
+{
+ int idx = t->root[TABLE_HASH(key)];
+ apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
+
+ if ( idx < 0 || search(t->cmp,o,&idx,key) )
+ return NULL;
+
+ return v2c(idx[o].val);
+}
+
+APREQ_DECLARE(const char *) apreq_table_get_cached(apreq_table_t *t,
+ const char *key)
{
int *root = &t->root[TABLE_HASH(key)];
int idx = *root;
@@ -804,8 +818,8 @@
if ( idx < 0 || search(t->cmp,o,&idx,key) )
return NULL;
- if (t->flags & TF_PROMOTE && idx != *root) {
- /* modifies tree, which is why t isn't declared as const */
+ if (idx != *root) {
+ t->flags &= ~TF_BALANCE;
PROMOTE(o,root,idx);
}
return v2c(idx[o].val);
@@ -826,33 +840,26 @@
return a;
}
-APREQ_DECLARE(apr_array_header_t *) apreq_table_values(apreq_table_t *t,
- const char *key,
- apr_pool_t *p)
+APREQ_DECLARE(apr_array_header_t *) apreq_table_values(const apreq_table_t
*t,
+ apr_pool_t *p,
+ const char *key)
{
- int i;
+ int idx;
apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
apr_array_header_t *a = apr_array_make(p, key ? APREQ_DEFAULT_NELTS :
t->a.nelts - t->ghosts,
sizeof(apreq_value_t *));
if (key == NULL) { /* fetch all values */
- for (i = 0; i < t->a.nelts; ++i)
- if (IN_FOREST(t,i))
- *(apreq_value_t **)apr_array_push(a) = i[o].val;
+ for (idx = 0; idx < t->a.nelts; ++idx)
+ if (IN_FOREST(t,idx))
+ *(const apreq_value_t **)apr_array_push(a) = idx[o].val;
}
else {
- i = t->root[TABLE_HASH(key)];
- if ( i>=0 && search(t->cmp,o,&i,key) == 0 )
- for ( ; i>=0; i = i[o].tree[NEXT] )
- *(apreq_value_t **)apr_array_push(a) = i[o].val;
-
- if (t->flags & TF_PROMOTE && i != t->root[TABLE_HASH(key)]) {
- /* modifies tree, so t cannot be declared const */
- int *root = &t->root[TABLE_HASH(key)];
- PROMOTE(o,root,i);
- }
-
+ idx = t->root[TABLE_HASH(key)];
+ if ( idx>=0 && search(t->cmp,o,&idx,key) == 0 )
+ for ( ; idx>=0; idx = idx[o].tree[NEXT] )
+ *(const apreq_value_t **)apr_array_push(a) = idx[o].val;
}
return a;
@@ -863,42 +870,9 @@
/********************* table_set* & table_unset ********************/
-
-APREQ_DECLARE(void) apreq_table_set(apreq_table_t *t, const char *key,
- const char *val)
-{
- if (key && val)
- apreq_table_setb(t, key, strlen(key), val, strlen(val));
- else if (key != NULL)
- apreq_table_setb(t, key, strlen(key), val, 0);
-}
-
-APREQ_DECLARE(void) apreq_table_setb(apreq_table_t *t,
- const char *key, int klen,
- const char *val, int vlen)
-{
- apreq_value_t *k, *v;
- apr_pool_t *p = t->a.pool;
-
- if (key == NULL)
- return;
-
- k = apreq_value_make(p, key, klen);
- v = (val == NULL) ? NULL : apreq_value_make(p, val, vlen);
- apreq_table_setv(t, k->data, v);
-}
-
-APREQ_DECLARE(void) apreq_table_setn(apreq_table_t *t,
- const char *key,
- const char *val)
-{
- apreq_table_setv(t,key,apreq_char_to_value(val));
-}
-
-APREQ_DECLARE(void) apreq_table_setv(apreq_table_t *t,
- const char *key,
- apreq_value_t *val)
+APREQ_DECLARE(void) apreq_table_set(apreq_table_t *t, const apreq_value_t
*val)
{
+ const char *key = val->name;
int idx = t->root[TABLE_HASH(key)];
apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
@@ -956,79 +930,41 @@
/********************* table_merge* *********************/
-
-
APREQ_DECLARE(void) apreq_table_merge(apreq_table_t *t,
- const char *key,
- const char *val)
-{
- if (key && val)
- apreq_table_mergeb(t, key, strlen(key), val, strlen(val));
- else if (key != NULL)
- apreq_table_mergeb(t, key, strlen(key), val, 0);
-}
-
-APREQ_DECLARE(void) apreq_table_mergeb(apreq_table_t *t,
- const char *key, int klen,
- const char *val, int vlen)
-{
- apreq_value_t *k, *v;
- apr_pool_t *p = t->a.pool;
-
- if (key == NULL)
- return;
-
- k = apreq_value_make(p, key, klen);
- v = (val == NULL) ? NULL : apreq_value_make(p, val, vlen);
- apreq_table_mergev(t, k->data, v);
-}
-
-
-APREQ_DECLARE(void) apreq_table_mergen(apreq_table_t *t,
- const char *key,
- const char *val)
-{
- apreq_table_mergev(t,key,apreq_char_to_value(val));
-}
-
-APREQ_DECLARE(void) apreq_table_mergev(apreq_table_t *t,
- const char *key,
- apreq_value_t *val)
+ const apreq_value_t *val)
{
+ const char *key = val->name;
int idx = t->root[TABLE_HASH(key)];
apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
#ifdef POOL_DEBUG
{
- if (!apr_pool_is_ancestor(apr_pool_find(key), t->a.pool)) {
- fprintf(stderr, "table_set: key not in ancestor pool of t\n");
- abort();
- }
if (!apr_pool_is_ancestor(apr_pool_find(val), t->a.pool)) {
- fprintf(stderr, "table_set: key not in ancestor pool of t\n");
+ /* XXX */
+ fprintf(stderr, "apreq_table_merge: val not in ancestor pool of
t\n");
abort();
}
}
#endif
- if (t->merge && idx >= 0 && search(t->cmp,o,&idx,key) == 0) {
+ if (t->merge && idx >= 0 && search(t->cmp,o,&idx,val->name) == 0) {
int n;
apr_array_header_t *arr = apr_array_make(t->a.pool,
APREQ_DEFAULT_NELTS,
sizeof(apreq_value_t *));
if (idx[o].val)
- *(apreq_value_t **)apr_array_push(arr) = idx[o].val;
+ *(const apreq_value_t **)apr_array_push(arr) = idx[o].val;
for (n = idx[o].tree[NEXT]; n >= 0; n = n[o].tree[NEXT]) {
KILL_ENTRY(t,n);
if (n[o].val)
- *(apreq_value_t **)apr_array_push(arr) = n[o].val;
+ *(const apreq_value_t **)apr_array_push(arr) = n[o].val;
}
if (val)
- *(apreq_value_t **)apr_array_push(arr) = val;
+ *(const apreq_value_t **)apr_array_push(arr) = val;
if (arr->nelts > 1)
idx[o].val = t->merge(t->a.pool, arr);
@@ -1036,7 +972,7 @@
else { /* not found */
apreq_table_entry_t *e = table_push(t);
- e->key = key;
+ e->key = val->name;
e->val = val;
e->tree[NEXT] = -1;
insert(t->cmp,o,&t->root[TABLE_HASH(key)],idx,e,TREE_PUSH);
@@ -1044,47 +980,12 @@
}
-
/********************* table_add* *********************/
-
-
APREQ_DECLARE(void) apreq_table_add(apreq_table_t *t,
- const char *key,
- const char *val)
-{
- if (key && val)
- apreq_table_addb(t, key, strlen(key), val, strlen(val));
- else if (key != NULL)
- apreq_table_addb(t, key, strlen(key), val, 0);
-}
-
-APREQ_DECLARE(void) apreq_table_addb(apreq_table_t *t,
- const char *key, int klen,
- const char *val, int vlen)
-{
- apreq_value_t *k, *v;
- apr_pool_t *p = t->a.pool;
-
- if (key == NULL)
- return;
-
- k = apreq_value_make(p, key, klen);
- v = (val == NULL) ? NULL : apreq_value_make(p, val, vlen);
- apreq_table_addv(t, k->data, v);
-}
-
-APREQ_DECLARE(void) apreq_table_addn(apreq_table_t *t,
- const char *key,
- const char *val)
-{
- apreq_table_addv(t, key, apreq_char_to_value(val));
-}
-
-APREQ_DECLARE(void) apreq_table_addv(apreq_table_t *t,
- const char *key,
- apreq_value_t *val)
+ const apreq_value_t *val)
{
+ const char *key = val->name;
apreq_table_entry_t *elt = table_push(t);
int *root = &t->root[TABLE_HASH(key)];
apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
@@ -1102,7 +1003,7 @@
}
#endif
- elt->key = key;
+ elt->key = val->name;
elt->val = val;
elt->tree[NEXT] = -1;
insert(t->cmp, o, root, *root, elt,TREE_PUSH);
@@ -1249,7 +1150,6 @@
/********************* iterators ********************/
APREQ_DECLARE(apr_status_t) apreq_table_fetch(const apreq_table_t *t,
- const char **key,
const apreq_value_t **val,
int *off)
{
@@ -1257,7 +1157,6 @@
apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
if (idx < 0 || idx >= t->a.nelts - t->ghosts) {
- *key = NULL;
*val = NULL;
return APR_EGENERAL;
}
@@ -1266,29 +1165,26 @@
int n;
for (n=0; n <= idx; ++n)
- if ( IS_DEAD(n) )
+ if ( DEAD(n) )
++idx;
*off = idx;
}
- *key = idx[o].key;
*val = idx[o].val;
return APR_SUCCESS;
}
APREQ_DECLARE(apr_status_t) apreq_table_first(const apreq_table_t *t,
- const char **key,
const apreq_value_t **val,
int *off)
{
*off = -1;
- return apreq_table_next(t,key,val,off);
+ return apreq_table_next(t,val,off);
}
APREQ_DECLARE(apr_status_t) apreq_table_next(const apreq_table_t *t,
- const char **key,
const apreq_value_t **val,
int *off)
{
@@ -1296,7 +1192,6 @@
apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
if (idx < -1 || idx >= t->a.nelts) {
- *key = NULL;
*val = NULL;
return APR_EGENERAL;
}
@@ -1304,29 +1199,25 @@
do {
if (++idx == t->a.nelts) {
*off = idx;
- *key = NULL;
*val = NULL;
return APR_EGENERAL;
}
- } while ( IS_DEAD(idx) );
+ } while ( DEAD(idx) );
*off = idx;
- *key = idx[o].key;
*val = idx[o].val;
return APR_SUCCESS;
}
APREQ_DECLARE(apr_status_t) apreq_table_last(const apreq_table_t *t,
- const char **key,
const apreq_value_t **val,
int *off)
{
*off = t->a.nelts;
- return apreq_table_prev(t,key,val,off);
+ return apreq_table_prev(t,val,off);
}
APREQ_DECLARE(apr_status_t) apreq_table_prev(const apreq_table_t *t,
- const char **key,
const apreq_value_t **val,
int *off)
{
@@ -1334,7 +1225,6 @@
apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
if (idx <= 0 || idx > t->a.nelts) {
- *key = NULL;
*val = NULL;
return APR_EGENERAL;
}
@@ -1342,14 +1232,12 @@
do {
if (--idx == -1) {
*off = idx;
- *key = NULL;
*val = NULL;
return APR_EGENERAL;
}
- } while ( IS_DEAD(idx) );
+ } while ( DEAD(idx) );
*off = idx;
- *key = idx[o].key;
*val = idx[o].val;
return APR_SUCCESS;
}
@@ -1461,7 +1349,7 @@
else { /* Scan the entire table */
for (idx = 0; rv && (idx < t->a.nelts); ++idx)
/* if (idx[o].key) */
- if (! IS_DEAD(idx) )
+ if (! DEAD(idx) )
rv = (*comp) (rec, idx[o].key, v2c(idx[o].val));
}
if (rv == 0) {
1.2 +23 -86 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- apreq_tables.h 17 Jan 2003 23:24:52 -0000 1.1
+++ apreq_tables.h 20 Jan 2003 01:54:43 -0000 1.2
@@ -105,11 +105,12 @@
const apreq_table_t *t);
-APREQ_DECLARE(apr_table_t *)apreq_table_export(apreq_table_t *t,
- apr_pool_t *p);
+APREQ_DECLARE(apr_table_t *)apreq_table_export(const apreq_table_t *t,
+ apr_pool_t *p);
+
APREQ_DECLARE(apreq_table_t *)apreq_table_import(apr_pool_t *p,
- apr_table_t *s,
- unsigned f);
+ const apr_table_t *s,
+ const unsigned f);
/**
@@ -130,7 +131,7 @@
const int on);
APREQ_DECLARE(void) apreq_table_balance(apreq_table_t *t, const int on);
-APREQ_DECLARE(void) apreq_table_normalize(apreq_table_t *t);
+APREQ_DECLARE(apr_status_t) apreq_table_normalize(apreq_table_t *t);
APREQ_DECLARE(int) apreq_table_ghosts(apreq_table_t *t);
APREQ_DECLARE(int) apreq_table_exorcise(apreq_table_t *t);
@@ -143,17 +144,18 @@
* @param key The key to search for
* @return The value associated with the key
*/
-APREQ_DECLARE(const char*) apreq_table_get(apreq_table_t *t,
+APREQ_DECLARE(const char*) apreq_table_get(const apreq_table_t *t,
const char *key);
+APREQ_DECLARE(const char *) apreq_table_get_cached(apreq_table_t *t,
+ const char *key);
-APREQ_DECLARE(apr_array_header_t *) apreq_table_keys(const
- apreq_table_t *t,
+APREQ_DECLARE(apr_array_header_t *) apreq_table_keys(const apreq_table_t *t,
apr_pool_t *p);
-APREQ_DECLARE(apr_array_header_t *) apreq_table_values(apreq_table_t *t,
- const char *key,
- apr_pool_t *p);
+APREQ_DECLARE(apr_array_header_t *) apreq_table_values(const apreq_table_t
*t,
+ apr_pool_t *p,
+ const char *key);
/**
@@ -165,28 +167,7 @@
* @remark When adding data, this function makes a copy of both the key and
the
* value.
*/
-APREQ_DECLARE(void) apreq_table_set(apreq_table_t *t, const char *key,
- const char *val);
-
-APREQ_DECLARE(void) apreq_table_setb(apreq_table_t *t, const char *key,
- int klen, const char *val, int vlen);
-
-/**
- * Add a key/value pair to a table, if another element already exists with
the
- * same key, this will over-write the old data.
- * @param t The table to add the data to.
- * @param key The key to use
- * @param val The value to add
- * @warning When adding data, this function does not make a copy of the key
or
- * the value, so care should be taken to ensure that the values
will
- * not change after they have been added..
- */
-APREQ_DECLARE(void) apreq_table_setn(apreq_table_t *t, const char *key,
- const char *val);
-
-APREQ_DECLARE(void) apreq_table_setv(apreq_table_t *t, const char *key,
- apreq_value_t *val);
-
+APREQ_DECLARE(void) apreq_table_set(apreq_table_t *t, const apreq_value_t
*v);
/**
* Remove data from the table
@@ -204,27 +185,8 @@
* @remark If the key is not found, then this function acts like
apr_table_add
*/
-APREQ_DECLARE(void) apreq_table_merge(apreq_table_t *t, const char *key,
- const char *val);
-
-APREQ_DECLARE(void) apreq_table_mergeb(apreq_table_t *t,
- const char *key, int klen,
- const char *val, int vlen);
-
-/**
- * Add data to a table by merging the value with data that has already been
- * stored
- * @param t The table to search for the data
- * @param key The key to merge data for
- * @param val The data to add
- * @remark If the key is not found, then this function acts like
apr_table_addn
- */
-APREQ_DECLARE(void) apreq_table_mergen(apreq_table_t *t, const char *key,
- const char *val);
-
-APREQ_DECLARE(void) apreq_table_mergev(apreq_table_t *t,
- const char *key,
- apreq_value_t *val);
+APREQ_DECLARE(void) apreq_table_merge(apreq_table_t *t,
+ const apreq_value_t *v);
/**
* Add data to a table, regardless of whether there is another element with
the
@@ -235,29 +197,8 @@
* @remark When adding data, this function makes a copy of both the key and
the
* value.
*/
-APREQ_DECLARE(void) apreq_table_add(apreq_table_t *t,
- const char *key, const char *val);
-APREQ_DECLARE(void) apreq_table_addb(apreq_table_t *t,
- const char *key, int klen,
- const char *val, int vlen);
-
-/**
- * Add data to a table, regardless of whether there is another element with
the
- * same key.
- * @param t The table to add to
- * @param key The key to use
- * @param val The value to add.
- * @remark When adding data, this function does not make a copy of the key
or the
- * value, so care should be taken to ensure that the values will not
- * change after they have been added..
- */
-APREQ_DECLARE(void) apreq_table_addn(apreq_table_t *t, const char *key,
- const char *val);
-APREQ_DECLARE(void) apreq_table_addv(apreq_table_t *t,
- const char *key,
- apreq_value_t *val);
+APREQ_DECLARE(void) apreq_table_add(apreq_table_t *t, const apreq_value_t
*v);
-APREQ_DECLARE(void) apreq_table_cat(apreq_table_t *t, const apreq_table_t
*s);
/**
* Merge two tables into one new table
* @param p The pool to use for the new table
@@ -265,10 +206,13 @@
* @param under The table to add at the end of the new table
* @return A new table containing all of the data from the two passed in
*/
+
APREQ_DECLARE(apreq_table_t *) apreq_table_overlay(apr_pool_t *p,
const apreq_table_t *over,
const apreq_table_t
*under);
+APREQ_DECLARE(void) apreq_table_cat(apreq_table_t *t, const apreq_table_t
*s);
+
/**
* For each element in table b, either use setn or mergen to add the data
* to table a. Which method is used is determined by the flags passed in.
@@ -310,32 +254,25 @@
const apreq_table_t *b,
const unsigned flags);
-
-
-/* iterator API */
+/** Iterator API */
APREQ_DECLARE(apr_status_t) apreq_table_fetch(const apreq_table_t *t,
- const char **key,
const apreq_value_t **val,
int *off);
-
APREQ_DECLARE(apr_status_t) apreq_table_first(const apreq_table_t *t,
- const char **key,
const apreq_value_t **val,
int *off);
APREQ_DECLARE(apr_status_t) apreq_table_next(const apreq_table_t *t,
- const char **key,
const apreq_value_t **val,
int *off);
APREQ_DECLARE(apr_status_t) apreq_table_last(const apreq_table_t *t,
- const char **key,
const apreq_value_t **val,
int *off);
APREQ_DECLARE(apr_status_t) apreq_table_prev(const apreq_table_t *t,
- const char **key,
const apreq_value_t **val,
int *off);
+
/**
* Declaration prototype for the iterator callback function of apr_table_do()
* and apr_table_vdo().
@@ -346,7 +283,7 @@
* To export the callback function for apr_table_[v]do() it must be declared
* in the _NONSTD convention.
*/
-typedef int (apreq_table_do_callback_fn_t)(void *rec, const char *key,
+typedef int (apreq_table_do_callback_fn_t)(void *ctx, const char *key,
const char *val);
/**