joes 2003/04/25 11:11:16
Modified: . STATUS
src apreq_tables.c apreq_tables.h
t tables.c
Log:
Update keys/values table API.
Revision Changes Path
1.5 +2 -6 httpd-apreq-2/STATUS
Index: STATUS
===================================================================
RCS file: /home/cvs/httpd-apreq-2/STATUS,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- STATUS 19 Apr 2003 17:49:44 -0000 1.4
+++ STATUS 25 Apr 2003 18:11:15 -0000 1.5
@@ -34,9 +34,6 @@
2. `Prefetching' filter reads are unimplemented.
- 3. Filter should activate `as necessary', and inject itself only
- once into the input filter chain.
-
CURRENT VOTES:
@@ -44,8 +41,7 @@
TODO:
- * more core unit tests in t/.
- tables.c needs tests for "balanced" tables
+ * more Apache::Test tests in glue/perl/t.
* Populate the glue/ directory (perl, tcl, etc.).
1.21 +16 -15 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.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- apreq_tables.c 23 Apr 2003 06:48:57 -0000 1.20
+++ apreq_tables.c 25 Apr 2003 18:11:15 -0000 1.21
@@ -775,46 +775,47 @@
}
-APREQ_DECLARE(apr_array_header_t *) apreq_table_keys(apr_pool_t *p,
- const apreq_table_t *t)
+APREQ_DECLARE(apr_status_t) apreq_table_keys(const apreq_table_t *t,
+ apr_array_header_t *keys)
{
int idx;
apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
- apr_array_header_t *a = apr_array_make(p,t->a.nelts - t->ghosts,
- sizeof(char *));
+ if (t->a.nelts == 0)
+ return APR_NOTFOUND;
for (idx = 0; idx < t->a.nelts; ++idx)
if (IN_FOREST(t,idx))
- *(const char **)apr_array_push(a) = idx[o].key;
+ *(const char **)apr_array_push(keys) = idx[o].key;
- return a;
+ return APR_SUCCESS;
}
-APREQ_DECLARE(apr_array_header_t *) apreq_table_values(apr_pool_t *p,
- const apreq_table_t
*t,
- const char *key)
+APREQ_DECLARE(apr_status_t) apreq_table_values(const apreq_table_t *t,
+ const char *key,
+ apr_array_header_t *values)
{
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_NELTS :
- t->a.nelts - t->ghosts,
- sizeof(apreq_value_t *));
+ if (t->a.nelts == 0)
+ return APR_NOTFOUND;
if (key == NULL) { /* fetch all values */
for (idx = 0; idx < t->a.nelts; ++idx)
if (IN_FOREST(t,idx))
- *(const apreq_value_t **)apr_array_push(a) = idx[o].val;
+ *(const apreq_value_t **)apr_array_push(values) = idx[o].val;
}
else {
idx = t->root[TABLE_HASH(key)];
if ( idx>=0 && search(o,&idx,key) == 0 )
for ( ; idx>=0; idx = idx[o].tree[NEXT] )
- *(const apreq_value_t **)apr_array_push(a) = idx[o].val;
+ *(const apreq_value_t **)apr_array_push(values) = idx[o].val;
+ else
+ return APR_NOTFOUND;
}
- return a;
+ return APR_SUCCESS;
}
1.13 +6 -5 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- apreq_tables.h 21 Apr 2003 16:09:09 -0000 1.12
+++ apreq_tables.h 25 Apr 2003 18:11:15 -0000 1.13
@@ -245,8 +245,9 @@
* @param p Pool used to allocate the resulting array struct.
*/
-APREQ_DECLARE(apr_array_header_t *) apreq_table_keys(apr_pool_t *p,
- const apreq_table_t *t);
+APREQ_DECLARE(apr_status_t) apreq_table_keys(const apreq_table_t *t,
+ apr_array_header_t *keys);
+
/**
* Return the (unique) values in an (apreq_value_t *) array,
* preserving their original order.
@@ -256,9 +257,9 @@
* only the first value of a multivalued entry is used.
*/
-APREQ_DECLARE(apr_array_header_t *) apreq_table_values(apr_pool_t *p,
- const apreq_table_t
*t,
- const char *key);
+APREQ_DECLARE(apr_status_t) apreq_table_values(const apreq_table_t *t,
+ const char *key,
+ apr_array_header_t *values);
/**
* Add an apreq_value_t to the table. If another value already exists
* with the same name, this will replace the old value.
1.8 +61 -1 httpd-apreq-2/t/tables.c
Index: tables.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/t/tables.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- tables.c 23 Apr 2003 06:48:57 -0000 1.7
+++ tables.c 25 Apr 2003 18:11:15 -0000 1.8
@@ -267,7 +267,6 @@
}
-
static void table_overlay(CuTest *tc)
{
const char *val;
@@ -307,6 +306,65 @@
CuAssertStrEquals(tc, "7",val);
}
+static void table_keys(CuTest *tc)
+{
+ const char *k;
+ apr_array_header_t *a = apr_array_make(p,1, sizeof k);
+ apr_status_t s = apreq_table_keys(t1,a);
+ CuAssertIntEquals(tc, APR_SUCCESS, s);
+ CuAssertIntEquals(tc, 7, a->nelts);
+ k = ((const char **)a->elts)[0];
+ CuAssertStrEquals(tc, "a", k);
+ k = ((const char **)a->elts)[1];
+ CuAssertStrEquals(tc, "g", k);
+ k = ((const char **)a->elts)[2];
+ CuAssertStrEquals(tc, "b", k);
+ k = ((const char **)a->elts)[3];
+ CuAssertStrEquals(tc, "c", k);
+ k = ((const char **)a->elts)[4];
+ CuAssertStrEquals(tc, "d", k);
+ k = ((const char **)a->elts)[5];
+ CuAssertStrEquals(tc, "e", k);
+ k = ((const char **)a->elts)[6];
+ CuAssertStrEquals(tc, "f", k);
+}
+
+static void table_values(CuTest *tc)
+{
+ const apreq_value_t *v;
+ apr_array_header_t *a = apr_array_make(p,1,sizeof v);
+ apr_status_t s = apreq_table_values(t1,"a",a);
+ CuAssertIntEquals(tc, APR_SUCCESS, s);
+ CuAssertIntEquals(tc, 2, a->nelts);
+ v = ((const apreq_value_t **)a->elts)[0];
+ CuAssertStrEquals(tc, "a", v->name);
+ CuAssertStrEquals(tc, "0", v->data);
+ v = ((const apreq_value_t **)a->elts)[1];
+ CuAssertStrEquals(tc, "a", v->name);
+ CuAssertStrEquals(tc, "1", v->data);
+
+ a->nelts = 0;
+ s = apreq_table_values(t1,"b",a);
+ CuAssertIntEquals(tc, APR_SUCCESS, s);
+ CuAssertIntEquals(tc, 3, a->nelts);
+ v = ((const apreq_value_t **)a->elts)[0];
+ CuAssertStrEquals(tc, "b", v->name);
+ CuAssertStrEquals(tc, "2", v->data);
+ v = ((const apreq_value_t **)a->elts)[1];
+ CuAssertStrEquals(tc, "b", v->name);
+ CuAssertStrEquals(tc, "2.0", v->data);
+ v = ((const apreq_value_t **)a->elts)[2];
+ CuAssertStrEquals(tc, "b", v->name);
+ CuAssertStrEquals(tc, "2.", v->data);
+
+ a->nelts = 0;
+ s = apreq_table_values(t1,NULL,a);
+ CuAssertIntEquals(tc, APR_SUCCESS, s);
+ CuAssertIntEquals(tc, 7, a->nelts);
+
+}
+
+
CuSuite *testtable(void)
{
CuSuite *suite = CuSuiteNew("Table");
@@ -322,6 +380,8 @@
SUITE_ADD_TEST(suite, table_overlap);
SUITE_ADD_TEST(suite, table_elts);
SUITE_ADD_TEST(suite, table_overlay);
+ SUITE_ADD_TEST(suite, table_keys);
+ SUITE_ADD_TEST(suite, table_values);
return suite;
}