joes 2003/01/25 18:39:08
Modified: src apreq_cookie.h apreq_cookie.c apreq_env.h
apreq_tables.c apreq_tables.h apreq.h apreq.c
apreq_params.h apreq_params.c
Log:
apreq_env cleanups, etc.
Revision Changes Path
1.7 +4 -3 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- apreq_cookie.h 24 Jan 2003 23:33:44 -0000 1.6
+++ apreq_cookie.h 26 Jan 2003 02:39:08 -0000 1.7
@@ -1,12 +1,13 @@
#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;
typedef enum { NETSCAPE, RFC } apreq_cookie_version_t;
@@ -125,8 +126,8 @@
* @param c The cookie.
* @param p The pool.
*/
-APREQ_DECLARE(const char*) apreq_cookie_as_string(apr_pool_t *p,
- const apreq_cookie_t *c);
+APREQ_DECLARE(char*) apreq_cookie_as_string(apr_pool_t *p,
+ const apreq_cookie_t *c);
/**
* Same functionality as apreq_cookie_as_string. Stores the string
1.8 +7 -7 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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- apreq_cookie.c 24 Jan 2003 23:33:44 -0000 1.7
+++ apreq_cookie.c 26 Jan 2003 02:39:08 -0000 1.8
@@ -300,7 +300,7 @@
return j;
data = apreq_env_cookie(ctx);
- j = apreq_table_make(apreq_env_pool(ctx), APREQ_DEFAULT_NELTS);
+ j = apreq_table_make(apreq_env_pool(ctx), APREQ_NELTS);
/* XXX: potential race condition here
between env_jar fetch and env_jar set. */
@@ -311,7 +311,7 @@
return j;
}
else {
- j = apreq_table_make(p, APREQ_DEFAULT_NELTS);
+ j = apreq_table_make(p, APREQ_NELTS);
}
origin = data;
@@ -464,8 +464,8 @@
}
-APREQ_DECLARE(const char*) apreq_cookie_as_string(apr_pool_t *p,
- const apreq_cookie_t *c)
+APREQ_DECLARE(char*) apreq_cookie_as_string(apr_pool_t *p,
+ const apreq_cookie_t *c)
{
char s[APREQ_COOKIE_LENGTH];
@@ -479,7 +479,7 @@
APREQ_DECLARE(apr_status_t) apreq_bake_cookie(const apreq_cookie_t *c)
{
- const char *s = apreq_cookie_as_string(apreq_env_pool(c->ctx),c);
+ char *s = apreq_cookie_as_string(apreq_env_pool(c->ctx),c);
if (s == NULL) {
apreq_error(c->ctx, APR_ENAMETOOLONG, "Serialized cookie "
@@ -493,7 +493,7 @@
APREQ_DECLARE(apr_status_t) apreq_bake2_cookie(const apreq_cookie_t *c)
{
- const char *s = apreq_cookie_as_string(apreq_env_pool(c->ctx),c);
+ char *s = apreq_cookie_as_string(apreq_env_pool(c->ctx),c);
if ( s == NULL ) {
apreq_error(c->ctx, APR_ENAMETOOLONG, "Serialized cookie "
@@ -546,7 +546,7 @@
if (len <= 0) /* key size must be > 0 */
return NULL;
- a = apr_array_make(p, APREQ_DEFAULT_NELTS, sizeof(apreq_value_t));
+ a = apr_array_make(p, APREQ_NELTS, sizeof(apreq_value_t));
v = (apreq_value_t *)apr_array_push(a);
v->data = word;
v->size = len;
1.5 +26 -34 httpd-apreq-2/src/apreq_env.h
Index: apreq_env.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_env.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- apreq_env.h 24 Jan 2003 04:29:09 -0000 1.4
+++ apreq_env.h 26 Jan 2003 02:39:08 -0000 1.5
@@ -8,40 +8,33 @@
#include "apreq.h"
/* ctx ~ request_rec */
-struct apreq_request_env {
- void *(*request)(void *ctx);
-
- apr_status_t (*setup)(void *ctx,
- void *parser,
- void *cfg);
+extern const struct apreq_env {
+ const char *name;
+ apr_pool_t *(*pool)(void *ctx);
- apr_status_t (*parse)(void *req);
-};
+ /* header access */
+ const char *(*in)(void *ctx, char *name);
+ apr_status_t(*out)(void *ctx, const char *name, char *value);
-struct apreq_cookie_env {
+ /* cached objects */
void *(*jar)(void *ctx, void *j);
+ void *(*request)(void *ctx);
- const char *(*in)(void *ctx);
- const char *(*in2)(void *ctx);
+ /* request confuration */
+ apr_status_t (*configure)(void *ctx, apreq_cfg_t *cfg);
+ apr_status_t (*add_parser)(void *ctx, apreq_value_t *parser);
- apr_status_t (*out)(void *ctx, const char *c);
- apr_status_t (*out2)(void *ctx, const char *c);
-};
-
-extern const struct apreq_env {
- const char *name;
- struct apreq_request_env r;
- struct apreq_cookie_env c;
-
- /* uri components (cookies need to know the host/domain and path) */
- const char *(*uri)(void *ctx);
- const char *(*uri_path)(void *ctx);
+ /* XXX: the brass tacks */
+ apr_status_t (*parse)(void *ctx);
- apr_pool_t *(*pool)(void *ctx);
void (*log)(const char *file, int line, int level,
apr_status_t status, void *ctx, const char *fmt, ...);
} APREQ_ENV;
+
+
+#define apreq_env_add_parser(c,p) APREQ_ENV.add_parser(c,p)
+
APREQ_DECLARE(void) apreq_log(const char *file, int line, int level,
apr_status_t status, void *ctx, const char
*fmt, ...);
@@ -50,16 +43,15 @@
APREQ_DECLARE(apr_status_t) apreq_env_parse(void *req);
APREQ_DECLARE(void *) apreq_env_jar(void *ctx, void *j);
-APREQ_DECLARE(const char *) apreq_env_cookie(void *ctx);
-APREQ_DECLARE(const char *) apreq_env_cookie2(void *ctx);
-APREQ_DECLARE(apr_status_t) apreq_env_set_cookie(void *ctx, const char *s);
-APREQ_DECLARE(apr_status_t) apreq_env_set_cookie2(void *ctx, const char *s);
-
-#define apreq_env_pool(r) APREQ_ENV.pool(r)
-#define apreq_env_cookie(r) APREQ_ENV.c.in(r)
-#define apreq_env_cookie2(r) APREQ_ENV.c.in2(r)
-#define apreq_env_set_cookie(r,s) APREQ_ENV.c.out(r,s)
-#define apreq_env_set_cookie2(r,s) APREQ_ENV.c.out2(r,s)
+
+#define apreq_env_name APREQ_ENV.name
+#define apreq_env_jar(c,j) APREQ_ENV.jar(c,j)
+#define apreq_env_request(c,r) APREQ_ENV.jar(c,r)
+#define apreq_env_pool(c) APREQ_ENV.pool(c)
+#define apreq_env_cookie(c) APREQ_ENV.in(c, "Cookie")
+#define apreq_env_cookie2(c) APREQ_ENV.in(c, "Cookie2")
+#define apreq_env_set_cookie(c,s) APREQ_ENV.out(c,"Set-Cookie",s)
+#define apreq_env_set_cookie2(c,s) APREQ_ENV.out(c,"Set-Cookie2",s)
#define AP_LOG_MARK __FILE__,__LINE__
1.8 +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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- apreq_tables.c 24 Jan 2003 19:15:07 -0000 1.7
+++ apreq_tables.c 26 Jan 2003 02:39:08 -0000 1.8
@@ -78,8 +78,6 @@
#endif
#include "apr_signal.h"
-
-
/********************* table_entry structure ********************/
/* private struct */
@@ -542,8 +540,8 @@
memset(t->root, -1, TABLE_HASH_SIZE * sizeof(int));
t->cmp = strcasecmp;
- t->merge = apreq_value_merge;
- t->copy = apreq_value_copy;
+ t->merge = apreq_merge_values;
+ t->copy = apreq_copy_value;
t->flags = 0;
t->ghosts = 0;
return t;
@@ -596,7 +594,7 @@
const apr_table_t *s,
const unsigned f)
{
- apreq_table_t *t = apreq_table_make(p,APREQ_DEFAULT_NELTS);
+ apreq_table_t *t = apreq_table_make(p,APREQ_NELTS);
const apr_array_header_t *a = apr_table_elts(s);
const apr_table_entry_t *e = (const apr_table_entry_t *)a->elts;
const apr_table_entry_t *end = e + a->nelts;
@@ -605,7 +603,7 @@
for ( ; e < end; e++) {
apreq_value_t *v = e->val ?
- apreq_value_make(p,e->key,e->val,strlen(e->val)) :
+ apreq_make_value(p,e->key,e->val,strlen(e->val)) :
NULL;
apreq_table_add(t, v);
}
@@ -677,9 +675,9 @@
apr_status_t status = APR_SUCCESS;
int idx;
apreq_table_entry_t *o = (apreq_table_entry_t *)t->a.elts;
- apreq_value_t *a[APREQ_DEFAULT_NELTS];
+ apreq_value_t *a[APREQ_NELTS];
apr_array_header_t arr = { t->a.pool, sizeof(apreq_value_t *), 0,
- APREQ_DEFAULT_NELTS, (char *)a };
+ APREQ_NELTS, (char *)a };
for (idx = 0; idx < t->a.nelts; ++idx) {
int j = idx[o].tree[NEXT];
@@ -847,7 +845,7 @@
{
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 :
+ apr_array_header_t *a = apr_array_make(p, key ? APREQ_NELTS :
t->a.nelts - t->ghosts,
sizeof(apreq_value_t *));
@@ -935,9 +933,9 @@
if (idx >= 0 && search(t->cmp,o,&idx,val->name) == 0) {
int n;
- apreq_value_t *a[APREQ_DEFAULT_NELTS];
+ apreq_value_t *a[APREQ_NELTS];
apr_array_header_t arr = { t->a.pool, sizeof(apreq_value_t *), 0,
- APREQ_DEFAULT_NELTS, (char *)a };
+ APREQ_NELTS, (char *)a };
*(const apreq_value_t **)apr_array_push(&arr) = idx[o].val;
1.7 +1 -0 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- apreq_tables.h 24 Jan 2003 19:15:07 -0000 1.6
+++ apreq_tables.h 26 Jan 2003 02:39:08 -0000 1.7
@@ -465,6 +465,7 @@
const apreq_table_t *t, va_list);
+
/** @} */
#ifdef __cplusplus
}
1.7 +30 -26 httpd-apreq-2/src/apreq.h
Index: apreq.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- apreq.h 24 Jan 2003 19:15:07 -0000 1.6
+++ apreq.h 26 Jan 2003 02:39:08 -0000 1.7
@@ -14,7 +14,6 @@
#define APREQ_DECLARE(d) d
-/* default enctypes */
#define APREQ_URL_ENCTYPE "application/x-www-form-urlencoded"
#define APREQ_URL_LENGTH 33
#define APREQ_MFD_ENCTYPE "multipart/form-data"
@@ -22,23 +21,16 @@
#define APREQ_XML_ENCTYPE "application/xml"
#define APREQ_XML_ENCTYPE_LENGTH 15
-#define APREQ_EXPIRES_HTTP 0
-#define APREQ_EXPIRES_COOKIE 1
-
-#define APREQ_DEFAULT_POST_MAX -1 /* XXX: unsafe default ??? */
-#define APREQ_DEFAULT_NELTS 8
-
-/* string match modes:
- * full match: full needle must be found
- * partial match: allow for partial matches at the end of haystack
- */
-#define APREQ_MATCH_FULL 0
-#define APREQ_MATCH_PART 1
-
-/* status codes */
-#define APREQ_OK 0
-#define APREQ_CONTINUE 100
-#define APREQ_ERROR 500
+/* defaults */
+#define APREQ_NELTS 8
+#define APREQ_BUFFER_SIZE 8192
+#define APREQ_BODY_SIZE (APREQ_BUFFER_SIZE * 1024)
+
+typedef struct apreq_cfg_t {
+ apr_off_t max_len;
+ char *temp_dir;
+ int run_hooks;
+} apreq_cfg_t;
typedef struct apreq_value_t {
@@ -59,10 +51,17 @@
#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_size_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);
+APREQ_DECLARE(apreq_value_t *) apreq_make_value(apr_pool_t *p,
+ const char *name,
+ const char *data,
+ const apr_size_t size);
+
+APREQ_DECLARE(apreq_value_t *) apreq_copy_value(apr_pool_t *p,
+ const apreq_value_t *val);
+
+APREQ_DECLARE(apreq_value_t *) apreq_merge_values(apr_pool_t *p,
+ const apr_array_header_t *arr);
+
typedef enum { AS_IS, ENCODE, DECODE, QUOTE } apreq_join_t;
APREQ_DECLARE(const char *) apreq_join(apr_pool_t *p,
@@ -71,11 +70,15 @@
apreq_join_t mode);
/* 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);
+typedef enum {FULL, PARTIAL} apreq_match_t;
-apr_off_t apreq_index(const char* hay, apr_off_t haylen,
- const char* ndl, apr_off_t ndllen, int part);
+char *apreq_memmem(char* hay, apr_size_t haylen,
+ const char* ndl, apr_size_t ndllen,
+ const apreq_match_t type);
+
+apr_ssize_t apreq_index(const char* hay, apr_size_t haylen,
+ const char* ndl, apr_size_t ndllen,
+ const apreq_match_t type);
/* url-escapes non-alphanumeric characters */
apr_size_t apreq_quote(char *dest, const char *src, const apr_size_t slen);
@@ -114,3 +117,4 @@
#endif
#endif /* APREQ_H */
+
1.6 +28 -20 httpd-apreq-2/src/apreq.c
Index: apreq.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- apreq.c 24 Jan 2003 19:15:07 -0000 1.5
+++ apreq.c 26 Jan 2003 02:39:08 -0000 1.6
@@ -4,8 +4,10 @@
#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 *name,
- const char *d, apr_size_t size)
+APREQ_DECLARE(apreq_value_t *)apreq_make_value(apr_pool_t *p,
+ const char *name,
+ const char *d,
+ apr_size_t size)
{
apreq_value_t *v = apr_palloc(p, size + sizeof *v);
if (d == NULL || v == NULL)
@@ -20,8 +22,8 @@
return v;
}
-apreq_value_t *apreq_value_copy(apr_pool_t *p,
- const apreq_value_t *val)
+APREQ_DECLARE(apreq_value_t *)apreq_copy_value(apr_pool_t *p,
+ const apreq_value_t *val)
{
apreq_value_t *v;
if (val == NULL)
@@ -37,8 +39,8 @@
return v;
}
-apreq_value_t *apreq_value_merge(apr_pool_t *p,
- const apr_array_header_t *arr)
+APREQ_DECLARE(apreq_value_t *)apreq_merge_values(apr_pool_t *p,
+ const apr_array_header_t *arr)
{
apreq_value_t *a = *(apreq_value_t **)(arr->elts);
apreq_value_t *v = apreq_char_to_value( apreq_join(p, ", ", arr, AS_IS)
);
@@ -52,7 +54,7 @@
{
apr_time_t when;
apr_time_exp_t tms;
- char sep = (type == APREQ_EXPIRES_HTTP) ? ' ' : '-';
+ char sep = (type == HTTP) ? ' ' : '-';
if (time_str == NULL) {
return NULL;
@@ -75,7 +77,8 @@
/* used for specifying file & byte sizes */
-APREQ_DECLARE(apr_int64_t) apreq_atoi64(const char *s) {
+APREQ_DECLARE(apr_int64_t) apreq_atoi64(const char *s)
+{
apr_int64_t n = 0;
char *p;
if (s == NULL)
@@ -138,10 +141,11 @@
*/
/* 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)
+APREQ_DECLARE(char *) apreq_memmem(char* hay, apr_size_t hlen,
+ const char* ndl, apr_size_t nlen,
+ const apreq_match_t type)
{
- apr_off_t len = hlen;
+ apr_size_t len = hlen;
char *end = hay + hlen;
while ( (hay = memchr(hay, ndl[0], len)) ) {
@@ -149,7 +153,7 @@
/* done if matches up to capacity of buffer */
if ( memcmp(hay, ndl, MIN(nlen, len)) == 0 ) {
- if (part == 0 && len < nlen)
+ if (type == FULL && len < nlen)
hay = NULL; /* insufficient room for match */
break;
}
@@ -160,10 +164,11 @@
return hay;
}
-apr_off_t apreq_index(const char* hay, apr_off_t hlen,
- const char* ndl, apr_off_t nlen, int part)
+APREQ_DECLARE(apr_ssize_t ) apreq_index(const char* hay, apr_size_t hlen,
+ const char* ndl, apr_size_t nlen,
+ const apreq_match_t type)
{
- apr_off_t len = hlen;
+ apr_size_t len = hlen;
const char *end = hay + hlen;
const char *begin = hay;
@@ -172,7 +177,7 @@
/* done if matches up to capacity of buffer */
if ( memcmp(hay, ndl, MIN(nlen, len)) == 0 ) {
- if (part == 0 && len < nlen)
+ if (type == FULL && len < nlen)
hay = NULL; /* insufficient room for match */
break;
}
@@ -204,7 +209,8 @@
return (digit);
}
-apr_ssize_t apreq_decode(char *d, const char *s, const apr_size_t slen)
+APREQ_DECLARE(apr_ssize_t) apreq_decode(char *d, const char *s,
+ const apr_size_t slen)
{
register int badesc = 0;
char *start = d;
@@ -270,8 +276,8 @@
}
-apr_size_t apreq_encode(char *dest, const char *src,
- const apr_size_t slen)
+APREQ_DECLARE(apr_size_t) apreq_encode(char *dest, const char *src,
+ const apr_size_t slen)
{
char *d = dest;
const unsigned char *s = (const unsigned char *)src;
@@ -299,7 +305,8 @@
return d - dest;
}
-apr_size_t apreq_quote(char *dest, const char *src, const apr_size_t slen)
+APREQ_DECLARE(apr_size_t) apreq_quote(char *dest, const char *src,
+ const apr_size_t slen)
{
char *d = dest;
const char *s = src;
@@ -468,3 +475,4 @@
rv->size = apreq_encode(rv->data, src, slen);
return rv->data;
}
+
1.4 +1 -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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- apreq_params.h 24 Jan 2003 23:33:44 -0000 1.3
+++ apreq_params.h 26 Jan 2003 02:39:08 -0000 1.4
@@ -88,11 +88,10 @@
-/* XXX this might be better as an ADT */
typedef struct apreq_request_t {
apreq_table_t *args; /* query_string params */
apreq_table_t *body;
-
+ apr_pool_t *pool;
void *ctx;
apr_status_t status;
} apreq_request_t;
1.4 +3 -2 httpd-apreq-2/src/apreq_params.c
Index: apreq_params.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_params.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- apreq_params.c 24 Jan 2003 23:33:44 -0000 1.3
+++ apreq_params.c 26 Jan 2003 02:39:08 -0000 1.4
@@ -78,7 +78,7 @@
req->status = APR_EINIT;
req->ctx = ctx;
- req->args = apreq_table_make(p, APREQ_DEFAULT_NELTS);
+ req->args = apreq_table_make(p, APREQ_NELTS);
req->body = NULL;
/* XXX get/set race condition here wrt apreq_env_request.
@@ -95,7 +95,7 @@
#endif
/* XXX need to install copy/merge callbacks for apreq_param_t */
-
+ req->pool = p;
query_string = apreq_env_args(ctx);
req->status = (query_string == NULL) ? APR_SUCCESS :
apreq_split_params(p, req->args, query_string, strlen(query_string));
@@ -242,4 +242,5 @@
return v->data;
}
+