joes 2003/05/06 12:34:19
Modified: env libapreq_cgi.c
src apreq_parsers.c apreq_parsers.h apreq_tables.c
Log:
Let caller pass apr_hook_t to apreq_parser (instead of a raw hook function.).
Use platform int for table checksum instead of an APR type. Fix pointer bug
in apr_toupper call in libapreq_cgi.c.
Revision Changes Path
1.4 +1 -1 httpd-apreq-2/env/libapreq_cgi.c
Index: libapreq_cgi.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/env/libapreq_cgi.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- libapreq_cgi.c 6 May 2003 02:11:35 -0000 1.3
+++ libapreq_cgi.c 6 May 2003 19:34:19 -0000 1.4
@@ -97,7 +97,7 @@
if (*k == '-')
*k = '_';
else
- *k = apr_toupper(k);
+ *k = apr_toupper(*k);
}
1.23 +5 -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.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- apreq_parsers.c 6 May 2003 02:11:36 -0000 1.22
+++ apreq_parsers.c 6 May 2003 19:34:19 -0000 1.23
@@ -81,7 +81,7 @@
apreq_hook_t *hook)
{
apreq_parser_t *p = apr_palloc(pool, APREQ_CTX_MAXSIZE + sizeof *p);
- p->type = apr_pstrdup(pool,type);
+ p->name = apr_pstrdup(pool,type);
p->parser = parser;
p->hook = hook;
@@ -116,24 +116,19 @@
return APR_SUCCESS;
}
-APREQ_DECLARE(apreq_parser_t *)apreq_parser(void *env,
- APREQ_DECLARE_HOOK(*hook))
+APREQ_DECLARE(apreq_parser_t *)apreq_parser(void *env, apreq_hook_t *hook)
{
apr_pool_t *pool = apreq_env_pool(env);
- apreq_hook_t *h = NULL;
const char *type = apreq_env_content_type(env);
if (type == NULL)
return NULL;
- if (hook)
- h = apreq_make_hook(pool,hook,NULL,NULL);
-
if (!strncasecmp(type, APREQ_URL_ENCTYPE,strlen(APREQ_URL_ENCTYPE)))
- return apreq_make_parser(pool, type, apreq_parse_urlencoded, h);
+ return apreq_make_parser(pool, type, apreq_parse_urlencoded, hook);
else if (!strncasecmp(type,APREQ_MFD_ENCTYPE,strlen(APREQ_MFD_ENCTYPE)))
- return apreq_make_parser(pool, type, apreq_parse_multipart, h);
+ return apreq_make_parser(pool, type, apreq_parse_multipart, hook);
else
return NULL;
@@ -777,7 +772,7 @@
ctx = apr_pcalloc(pool, sizeof *ctx);
- ct = strchr(parser->type, ';');
+ ct = strchr(parser->name, ';');
if (ct == NULL) {
return APR_EINIT;
}
1.10 +2 -9 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- apreq_parsers.h 6 May 2003 02:11:36 -0000 1.9
+++ apreq_parsers.h 6 May 2003 19:34:19 -0000 1.10
@@ -48,18 +48,12 @@
struct apreq_parser_t {
APREQ_DECLARE_PARSER (*parser);
- const char *type;
+ const char *name;
apreq_hook_t *hook;
void *ctx;
};
-#define apreq_value_to_parser(ptr) apreq_attr_to_type(apreq_parser_t,v,ptr)
-#define apreq_ctx_to_parser(ptr) apreq_value_to_parser(apreq_strtoval(ptr))
-
-#define apreq_parser_enctype(p) ((p)->v.name)
-#define apreq_parser_ctx(p) ((p)->v.data)
-
APREQ_DECLARE_PARSER(apreq_parse_headers);
APREQ_DECLARE_PARSER(apreq_parse_urlencoded);
APREQ_DECLARE_PARSER(apreq_parse_multipart);
@@ -83,8 +77,7 @@
APREQ_DECLARE(apr_status_t) apreq_merge_parsers(apr_pool_t *p,
const apr_array_header_t *a);
-APREQ_DECLARE(apreq_parser_t *)apreq_parser(void *env,
- APREQ_DECLARE_HOOK(*hook));
+APREQ_DECLARE(apreq_parser_t *)apreq_parser(void *env, apreq_hook_t *hook);
#ifdef __cplusplus
}
1.30 +9 -11 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.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- apreq_tables.c 6 May 2003 02:11:36 -0000 1.29
+++ apreq_tables.c 6 May 2003 19:34:19 -0000 1.30
@@ -69,17 +69,15 @@
#include "apr_signal.h"
/********************* table_entry structure ********************/
-#define CS_TYPE apr_uint32_t
-#define CS_BYTES 4
-#define OFFSET ((CS_BYTES-1) * 8)
+#define CS_OFFSET (8 * (sizeof(unsigned int) - 1))
/* private struct */
typedef struct apreq_table_entry_t {
const apreq_value_t *val;
const char *key; /* = val->name : saves a ptr deref */
- CS_TYPE checksum;
+ unsigned int checksum;
enum { RED, BLACK } color;
int tree[4]; /* LEFT RIGHT UP NEXT */
} apreq_table_entry_t;
@@ -107,13 +105,13 @@
#define COMPUTE_KEY_CHECKSUM(k, checksum) \
{ \
- CS_TYPE c = (CS_TYPE)*(k); \
+ unsigned int c = (unsigned int)*(k); \
int j = 0; \
(checksum) = c; \
- while (++j < CS_BYTES) { \
+ while (++j < sizeof(c)) { \
(checksum) <<= 8; \
if (c) { \
- c = (CS_TYPE)*++(k); \
+ c = (unsigned int)*++(k); \
checksum |= c; \
} \
} \
@@ -156,7 +154,7 @@
/* NEVER KILL AN ENTRY THAT'S STILL WITHIN THE FOREST */
#define IN_FOREST(t,idx) ( !DEAD(idx) && ( (idx)[o].tree[UP] >= 0 || \
- (idx) == t->root[TABLE_HASH((idx)[o].checksum>>OFFSET)] )
)
+ (idx) == t->root[TABLE_HASH((idx)[o].checksum>>CS_OFFSET)] ) )
/* MUST ensure n's parent exists (>=0) before using LR(n) */
#define LR(n) ( ( (n)[o].tree[UP][o].tree[LEFT] == (n) ) ? LEFT : RIGHT )
@@ -220,7 +218,7 @@
const char *key)
{
int idx = *elt;
- CS_TYPE csum;
+ unsigned int csum;
COMPUTE_KEY_CHECKSUM(key, csum);
@@ -273,7 +271,7 @@
* http://www.cs.uiowa.edu/~hzhang/c44/lec14.PDF
*/
- const CS_TYPE csum = elt->checksum;
+ const unsigned int csum = elt->checksum;
const char *const key = elt->key;
while (1) {
@@ -898,7 +896,7 @@
t->ghosts += s->ghosts;
for (idx = n; idx < t->a.nelts; ++idx) {
- const unsigned char hash = TABLE_HASH(idx[o].checksum>>OFFSET);
+ const unsigned char hash = TABLE_HASH(idx[o].checksum>>CS_OFFSET);
if (DEAD(idx))
continue;