joes 2003/04/11 18:45:30
Modified: src apreq.c apreq.h apreq_cookie.c apreq_cookie.h
apreq_env.h apreq_params.c apreq_params.h
apreq_parsers.c apreq_parsers.h apreq_tables.c
Log:
core API (parser, env) cleanup.
Revision Changes Path
1.9 +56 -0 httpd-apreq-2/src/apreq.c
Index: apreq.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- apreq.c 11 Apr 2003 02:48:01 -0000 1.8
+++ apreq.c 12 Apr 2003 01:45:30 -0000 1.9
@@ -1,5 +1,61 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
#include "apreq.h"
#include "apr_time.h"
+#include "apr_strings.h"
+#include "apr_lib.h"
#define MIN(a,b) ( (a) < (b) ? (a) : (b) )
#define MAX(a,b) ( (a) > (b) ? (a) : (b) )
1.9 +5 -16 httpd-apreq-2/src/apreq.h
Index: apreq.h
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- apreq.h 11 Apr 2003 02:48:01 -0000 1.8
+++ apreq.h 12 Apr 2003 01:45:30 -0000 1.9
@@ -6,9 +6,6 @@
#endif
#include "apr_tables.h"
-#include "apr_lib.h"
-#include "apr_pools.h"
-#include "apr_strings.h"
#include <stddef.h>
@@ -21,22 +18,12 @@
#define APREQ_XML_ENCTYPE "application/xml"
#define APREQ_XML_ENCTYPE_LENGTH 15
-/* 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 {
const char *name;
- apr_size_t size;
apr_status_t status;
+ apr_size_t size;
char data[1];
} apreq_value_t;
@@ -65,12 +52,13 @@
typedef enum { AS_IS, ENCODE, DECODE, QUOTE } apreq_join_t;
+
APREQ_DECLARE(const char *) apreq_join(apr_pool_t *p,
const char *sep,
const apr_array_header_t *arr,
apreq_join_t mode);
-/* XXX: should we drop this and replace it with apreq_index ? */
+
typedef enum {FULL, PARTIAL} apreq_match_t;
char *apreq_memmem(char* hay, apr_size_t haylen,
@@ -104,13 +92,14 @@
* either as an ::NSCOOKIE or ::HTTP date */
typedef enum {HTTP, NSCOOKIE} apreq_expires_t;
+
APREQ_DECLARE(char *) apreq_expires(apr_pool_t *p, const char *time_str,
const apreq_expires_t type);
/* file sizes (KMG) to bytes */
apr_int64_t apreq_atoi64(const char *s);
-/* "duration" strings (YMDhms) to seconds */
+/* "time" strings (YMDhms) to seconds */
long apreq_atol(const char *s);
#ifdef __cplusplus
1.9 +36 -26 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- apreq_cookie.c 26 Jan 2003 02:39:08 -0000 1.8
+++ apreq_cookie.c 12 Apr 2003 01:45:30 -0000 1.9
@@ -58,6 +58,9 @@
#include "apreq_cookie.h"
#include "apreq_env.h"
+#include "apr_strings.h"
+#include "apr_lib.h"
+
APREQ_DECLARE(int) (apreq_jar_items)(apreq_jar_t *jar)
{
@@ -80,7 +83,7 @@
const char *time_str)
{
if ( c->version == NETSCAPE )
- c->time.expires = apreq_expires(apreq_env_pool(c->ctx),
+ c->time.expires = apreq_expires(apreq_env_pool(c->env),
time_str,
NSCOOKIE);
else
@@ -118,6 +121,8 @@
char *attr,
char *val)
{
+ dAPREQ_LOG;
+
if ( attr[0] == '-' || attr[0] == '$' )
++attr;
@@ -135,7 +140,7 @@
return APR_SUCCESS;
}
else {
- apreq_warn(c->ctx, APR_BADARG,
+ apreq_log(APREQ_WARN APR_BADARG, c->env,
"Bad Version number (no digits found).");
return APR_BADARG;
}
@@ -176,7 +181,7 @@
};
- apreq_warn(c->ctx, APR_ENOTIMPL,
+ apreq_log(APREQ_WARN APR_ENOTIMPL, c->env,
"unknown cookie attribute: `%s' => `%s'",
attr, val);
@@ -192,7 +197,7 @@
apreq_cookie_t *c = apr_palloc(p, vlen + sizeof *c);
apreq_value_t *v = &c->v;
- c->ctx = ctx;
+ c->env = ctx;
v->size = vlen;
v->name = apr_pstrmemdup(p, name, nlen);
memcpy(v->data, value, vlen);
@@ -289,6 +294,8 @@
const char *name, *value;
apr_size_t nlen, vlen;
+ dAPREQ_LOG;
+
/* initialize jar */
if (data == NULL) {
@@ -316,10 +323,7 @@
origin = data;
-#ifdef DEBUG
- apreq_debug(ctx, 0, "parsing cookie data: %s", data);
-#endif
-
+ apreq_log(APREQ_DEBUG 0, ctx, "parsing cookie data: %s", data);
/* parse data */
@@ -357,14 +361,16 @@
case '$':
if (c == NULL) {
- apreq_error(ctx, APR_BADCH, "Saw attribute, "
- "execting NAME=VALUE cookie pair: %s", data);
+ apreq_log(APREQ_ERROR APR_BADCH, ctx,
+ "Saw attribute, expecting NAME=VALUE cookie pair: %s",
+ data);
return j;
}
else if (version == NETSCAPE) {
c->v.status = APR_EMISMATCH;
- apreq_error(ctx, c->v.status, "Saw attribute in a "
- "Netscape Cookie header: %s", data);
+ apreq_log(APREQ_ERROR c->v.status, ctx,
+ "Saw attribute in a Netscape Cookie header: %s",
+ data);
return j;
}
@@ -375,7 +381,7 @@
apr_pstrmemdup(p,value, vlen));
else {
c->v.status = status;
- apreq_warn(ctx, c->v.status,
+ apreq_log(APREQ_WARN c->v.status, ctx,
"Ignoring bad attribute pair: %s", data);
}
break;
@@ -389,8 +395,8 @@
apreq_add_cookie(j, c);
}
else {
- apreq_warn(ctx, status, "Skipping bad NAME=VALUE pair: %s",
- data);
+ apreq_log(APREQ_WARN status, ctx,
+ "Skipping bad NAME=VALUE pair: %s", data);
}
}
}
@@ -479,40 +485,44 @@
APREQ_DECLARE(apr_status_t) apreq_bake_cookie(const apreq_cookie_t *c)
{
- char *s = apreq_cookie_as_string(apreq_env_pool(c->ctx),c);
+ char *s = apreq_cookie_as_string(apreq_env_pool(c->env),c);
+ dAPREQ_LOG;
if (s == NULL) {
- apreq_error(c->ctx, APR_ENAMETOOLONG, "Serialized cookie "
- "exceeds APREQ_COOKIE_LENGTH = %d",
+ apreq_log(APREQ_ERROR APR_ENAMETOOLONG, c->env,
+ "Serialized cookie exceeds APREQ_COOKIE_LENGTH = %d",
APREQ_COOKIE_LENGTH);
return APR_ENAMETOOLONG;
}
- return apreq_env_set_cookie(c->ctx, s);
+ return apreq_env_set_cookie(c->env, s);
}
APREQ_DECLARE(apr_status_t) apreq_bake2_cookie(const apreq_cookie_t *c)
{
- char *s = apreq_cookie_as_string(apreq_env_pool(c->ctx),c);
+ char *s = apreq_cookie_as_string(apreq_env_pool(c->env),c);
+ dAPREQ_LOG;
if ( s == NULL ) {
- apreq_error(c->ctx, APR_ENAMETOOLONG, "Serialized cookie "
- "exceeds APREQ_COOKIE_LENGTH = %d",
+ apreq_log(APREQ_ERROR APR_ENAMETOOLONG, c->env,
+ "Serialized cookie exceeds APREQ_COOKIE_LENGTH = %d",
APREQ_COOKIE_LENGTH);
return APR_ENAMETOOLONG;
}
else if ( c->version == NETSCAPE ) {
- apreq_error(c->ctx, APR_EMISMATCH, "Cannot bake2 "
- "a Netscape cookie: %s", s);
+ apreq_log(APREQ_ERROR APR_EMISMATCH, c->env,
+ "Cannot bake2 a Netscape cookie: %s", s);
return APR_EMISMATCH;
}
- return apreq_env_set_cookie2(c->ctx, s);
+ return apreq_env_set_cookie2(c->env, s);
}
-
+/* The functions below belong somewhere else, since they
+ generally make use of "common conventions" for cookie values.
+ (whereas the cookie specs regard values as opaque) */
#ifdef NEEDS_A_NEW_HOME
1.8 +2 -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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- apreq_cookie.h 26 Jan 2003 02:39:08 -0000 1.7
+++ apreq_cookie.h 12 Apr 2003 01:45:30 -0000 1.8
@@ -32,7 +32,7 @@
const char *expires;
} time;
- void *ctx;
+ void *env;
apreq_value_t v; /* "raw" value (extended struct) */
@@ -88,7 +88,7 @@
* data with the result of apreq_env_cookie(ctx), parse that,
* and store the resulting jar back within the environment.
* This Orcish maneuver is designed to mimimize parsing work,
- * since generating the cookie jar is fairly expensive.
+ * since generating the cookie jar is relatively expensive.
*
*/
1.7 +74 -49 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- apreq_env.h 11 Apr 2003 02:48:01 -0000 1.6
+++ apreq_env.h 12 Apr 2003 01:45:30 -0000 1.7
@@ -6,76 +6,101 @@
#endif
#include "apreq.h"
-/* ctx ~ request_rec */
+#include "apr_buckets.h"
+
+#ifdef HAVE_SYSLOG
+#include <syslog.h>
+
+#ifndef LOG_PRIMASK
+#define LOG_PRIMASK 7
+#endif
+
+#define APREQ_LOG_EMERG LOG_EMERG /* system is unusable */
+#define APREQ_LOG_ALERT LOG_ALERT /* action must be taken
immediately */
+#define APREQ_LOG_CRIT LOG_CRIT /* critical conditions */
+#define APREQ_LOG_ERR LOG_ERR /* error conditions */
+#define APREQ_LOG_WARNING LOG_WARNING /* warning conditions */
+#define APREQ_LOG_NOTICE LOG_NOTICE /* normal but significant
condition */
+#define APREQ_LOG_INFO LOG_INFO /* informational */
+#define APREQ_LOG_DEBUG LOG_DEBUG /* debug-level messages */
+
+#define APREQ_LOG_LEVELMASK LOG_PRIMASK /* mask off the level value */
+
+#else
+
+#define APREQ_LOG_EMERG 0 /* system is unusable */
+#define APREQ_LOG_ALERT 1 /* action must be taken immediately */
+#define APREQ_LOG_CRIT 2 /* critical conditions */
+#define APREQ_LOG_ERR 3 /* error conditions */
+#define APREQ_LOG_WARNING 4 /* warning conditions */
+#define APREQ_LOG_NOTICE 5 /* normal but significant condition */
+#define APREQ_LOG_INFO 6 /* informational */
+#define APREQ_LOG_DEBUG 7 /* debug-level messages */
+
+#define APREQ_LOG_LEVELMASK 7 /* mask off the level value */
+
+#endif
+
+#define APREQ_LOG_MARK __FILE__ , __LINE__
+
+#define APREQ_DEBUG APREQ_LOG_MARK, APREQ_LOG_DEBUG,
+#define APREQ_WARN APREQ_LOG_MARK, APREQ_LOG_WARNING,
+#define APREQ_ERROR APREQ_LOG_MARK, APREQ_LOG_ERR,
+
+#define dAPREQ_LOG APREQ_LOG(*apreq_log) = APREQ_ENV.log
+
+typedef struct apreq_cfg_t {
+ apr_off_t max_len;
+ char *temp_dir;
+ int disable_uploads;
+} apreq_cfg_t;
+
+#define APREQ_LOG(f) void (f)(const char *file, int line, int level, \
+ apr_status_t status, void *ctx, const char *fmt, ...)
extern const struct apreq_env {
- const char *name;
- apr_pool_t *(*pool)(void *ctx);
+ const char *name;
+ apr_pool_t *(*pool)(void *ctx);
/* header access */
- const char *(*in)(void *ctx, char *name);
- apr_status_t(*out)(void *ctx, const char *name, char *value);
+ const char *(*in)(void *ctx, const char *name);
+ apr_status_t (*out)(void *ctx, const char *name, char *value);
- /* cached objects */
- void *(*jar)(void *ctx, void *j);
- void *(*request)(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);
+ /* raw (unparsed) query_string access */
+ const char *(*args)(void *ctx);
- /* XXX: the brass tacks */
- apr_status_t (*parse)(void *ctx);
+ /* (get/set) cached core objects */
+ void *(*jar)(void *ctx, void *j);
+ void *(*request)(void *ctx, void *r);
- void (*log)(const char *file, int line, int level,
- apr_status_t status, void *ctx, const char *fmt, ...);
-} APREQ_ENV;
+ /* environment configuration */
+ apreq_cfg_t *(*config)(void *ctx);
+ /* the brass tacks */
+ apr_status_t (*get_brigade)(void *ctx, apr_bucket_brigade **bb);
+ /* core logging function */
+ APREQ_LOG (*log);
-#define apreq_env_add_parser(c,p) APREQ_ENV.add_parser(c,p)
+} APREQ_ENV;
-APREQ_DECLARE(void) apreq_log(const char *file, int line, int level,
- apr_status_t status, void *ctx, const char
*fmt, ...);
+#define apreq_env_name() APREQ_ENV.name
+#define apreq_env_pool(c) APREQ_ENV.pool(c)
-APREQ_DECLARE(void *) apreq_env_request(void *ctx, void *r);
-APREQ_DECLARE(char *) apreq_env_args(void *ctx);
-APREQ_DECLARE(apr_status_t) apreq_env_parse(void *req);
+#define apreq_env_jar(c,j) APREQ_ENV.jar(c,j)
+#define apreq_env_request(c,r) APREQ_ENV.request(c,r)
-APREQ_DECLARE(void *) apreq_env_jar(void *ctx, void *j);
+#define apreq_env_config(c) APREQ_ENV.config(c)
-#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_content_type(c) APREQ_ENV.in(c, "Content-Type");
#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 apreq_env_args(c) APREQ_ENV.args(c)
-#define AP_LOG_MARK __FILE__,__LINE__
+#define apreq_env_get_brigade(c,bb) APREQ_ENV.get_brigade(c,bb)
-#define AP_LOG_EMERG 0 /* system is unusable */
-#define AP_LOG_ALERT 1 /* action must be taken immediately */
-#define AP_LOG_CRIT 2 /* critical conditions */
-#define AP_LOG_ERR 3 /* error conditions */
-#define AP_LOG_WARNING 4 /* warning conditions */
-#define AP_LOG_NOTICE 5 /* normal but significant condition */
-#define AP_LOG_INFO 6 /* informational */
-#define AP_LOG_DEBUG 7 /* debug-level messages */
-
-
-#define APREQ_LOG_DEBUG(r) AP_LOG_MARK, AP_LOG_DEBUG,0,(r)
-#define APREQ_LOG_ERROR(r) AP_LOG_MARK, AP_LOG_ERR,0,(r)
-#define APREQ_LOG_WARN(r) AP_LOG_MARK, AP_LOG_WARNING,0,(r)
-
-APREQ_DECLARE(void) apreq_debug(void *ctx, apr_status_t status,
- const char *fmt, ...);
-APREQ_DECLARE(void) apreq_warn(void *ctx, apr_status_t status,
- const char *fmt, ...);
-APREQ_DECLARE(void) apreq_error(void *ctx, apr_status_t status,
- const char *fmt, ...);
#ifdef __cplusplus
}
1.7 +30 -29 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- apreq_params.c 11 Apr 2003 04:24:01 -0000 1.6
+++ apreq_params.c 12 Apr 2003 01:45:30 -0000 1.7
@@ -58,6 +58,7 @@
#include "apreq_params.h"
#include "apreq_env.h"
+#include "apr_strings.h"
#define p2v(param) ( (param) ? &(param)->v : NULL )
#define UPGRADE(s) apreq_value_to_param(apreq_char_to_value(s))
@@ -92,19 +93,36 @@
{
apreq_request_t *req, *old_req = apreq_env_request(ctx, NULL);
- char *query_string;
- apr_pool_t *p;
+ const char *query_string, *ct;
+ apr_pool_t *p;
+
+ dAPREQ_LOG;
if (old_req != NULL)
return old_req;
p = apreq_env_pool(ctx);
- req = apr_palloc(p, sizeof *req);
+ req = apr_palloc(p, sizeof(apreq_table_t *) + sizeof *req);
+
+ *(apreq_table_t **)&req->v.data = apreq_make_table(p, APREQ_NELTS);
+ req->v.size = sizeof(apreq_table_t *);
+ req->v.status = APR_EINIT;
+ req->env = ctx;
+ req->args = apreq_make_table(p, APREQ_NELTS);
+ req->body = NULL;
+
+ ct = apreq_env_content_type(ctx);
+
+ if (ct == NULL)
+ req->v.name = NULL;
+ else {
+ char *enctype = apr_pstrdup(req->pool, ct);
+ char *semicolon = strchr(enctype, ';');
+ if (semicolon)
+ *semicolon = 0;
- req->status = APR_EINIT;
- req->ctx = ctx;
- req->args = apreq_make_table(p, APREQ_NELTS);
- req->body = NULL;
+ req->v.name = enctype;
+ }
/* XXX get/set race condition here wrt apreq_env_request.
* apreq_env_request probably needs a write lock ???
@@ -112,37 +130,20 @@
old_req = apreq_env_request(ctx, req);
- if (old_req != NULL)
+ if (old_req != NULL) {
+ apreq_env_request(ctx, old_req); /* reset old_req */
return old_req;
+ }
-#ifdef DEBUG
- apreq.debug(ctx, 0, "making new request");
-#endif
+ apreq_log(APREQ_DEBUG req->v.status, ctx, "making new request");
/* 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 :
+ req->v.status = (query_string == NULL) ? APR_SUCCESS :
apreq_split_params(p, req->args, query_string, strlen(query_string));
return req;
-}
-
-
-APREQ_DECLARE(apr_status_t) apreq_parse(apreq_request_t *req)
-{
- if (req->body == NULL) {
- if (req->status == APR_SUCCESS) {
- req->body = apreq_table_make(req->pool, APREQ_NELTS);
- return apreq_env_parse(req);
- }
- else
- return req->status;
- }
- else if (req->status == APR_EAGAIN || req->status == APR_INCOMPLETE)
- return apreq_env_parse(req);
- else
- return req->status;
}
1.6 +3 -3 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- apreq_params.h 11 Apr 2003 02:48:01 -0000 1.5
+++ apreq_params.h 12 Apr 2003 01:45:30 -0000 1.6
@@ -98,9 +98,10 @@
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;
+ void *env;
+ apreq_value_t v;
} apreq_request_t;
/**
@@ -110,7 +111,6 @@
APREQ_DECLARE(apreq_request_t *)apreq_request(void *ctx);
-APREQ_DECLARE(apr_status_t)apreq_parse(apreq_request_t *req);
/**
* Returns the first parameter value for the requested key,
1.5 +55 -6 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- apreq_parsers.c 11 Apr 2003 16:10:03 -0000 1.4
+++ apreq_parsers.c 12 Apr 2003 01:45:30 -0000 1.5
@@ -58,6 +58,8 @@
#include "apreq_parsers.h"
#include "apreq_env.h"
+#include "apr_lib.h"
+#include "apr_strings.h"
#ifndef MAX
#define MAX(A,B) ( (A) > (B) ? (A) : (B) )
@@ -70,6 +72,7 @@
#define CRLF "\015\012"
#endif
+
APREQ_DECLARE(apreq_parser_t *) apreq_make_parser(apr_pool_t *pool,
const char *enctype,
APREQ_PARSER(*parser),
@@ -97,10 +100,54 @@
{
apreq_parser_t *p = apreq_make_parser(req->pool, enctype,
parser, hook, out);
- return apreq_env_add_parser(req->ctx, &p->v);
+ if (req->body == NULL)
+ return apreq_table_add((apreq_table_t *)req->v.data, &p->v);
+ else
+ return APR_EGENERAL;
+}
+
+
+APREQ_DECLARE(apr_status_t) apreq_parse(apreq_request_t *req)
+{
+
+ if (req->v.name == NULL)
+ return req->v.status;
+
+ if (req->body == NULL && req->v.status == APR_SUCCESS) {
+ const char *q = apreq_table_get((apreq_table_t *)req->v.data,
+ req->v.name);
+ if (q == NULL)
+ return req->v.status = APR_NOTFOUND;
+
+ req->body = apreq_table_make(req->pool, APREQ_NELTS);
+
+ *(apreq_parser_t **)req->v.data =
+ apreq_value_to_parser(apreq_strtoval(q));
+
+ req->v.size = sizeof(apreq_parser_t *);
+ req->v.status = APR_INCOMPLETE;
+ }
+
+ if (req->v.status == APR_INCOMPLETE && req->body != NULL) {
+ apreq_parser_t *p;
+ apr_bucket_brigade *bb;
+ apr_status_t s;
+ p = (apreq_parser_t *)req->v.data;
+
+ s = apreq_env_get_brigade(req->env, &bb);
+ if (s != APR_SUCCESS)
+ return s;
+
+ req->v.status = p->parser(req->pool, bb, p);
+ }
+
+ return req->v.status;
}
+
+/******************** application/x-www-form-urlencoded ********************/
+
static apr_status_t split_urlword(apr_pool_t *pool, apreq_table_t *t,
apr_bucket_brigade *bb,
const apr_size_t nlen,
@@ -111,7 +158,7 @@
const apr_size_t glen = 1;
apreq_value_t *v = ¶m->v;
- param->bb = NULL; /* XXX: could use to retain original encoded data */
+ param->bb = NULL;
param->info = NULL;
param->charset = UTF_8;
param->language = NULL;
@@ -223,9 +270,6 @@
parse_url_brigade:
- /* parse the brigade for CRLF_CRLF-terminated header block,
- * each time starting from the front of the brigade.
- */
parser->v.status = URL_NAME;
for (e = APR_BRIGADE_FIRST(bb), nlen = vlen = 0;
@@ -551,6 +595,9 @@
return APR_INCOMPLETE;
}
+
+/********************* multipart/form-data *********************/
+
struct mfd_ctx {
void *hook_data;
apreq_table_t *t;
@@ -626,6 +673,7 @@
return APR_INCOMPLETE;
}
+
static apr_status_t getval(const char **line, const char *name,
const char **val, apr_size_t *vlen)
{
@@ -671,6 +719,7 @@
return APR_SUCCESS;
}
+
static const char crlf[] = CRLF;
APREQ_DECLARE(apr_status_t) apreq_parse_multipart(apr_pool_t *pool,
@@ -690,7 +739,7 @@
#define MFD_ERROR -1
if (parser->v.size == 0) {
- const char *bdry, *ct = apreq_env_content_type(req->ctx);
+ const char *bdry, *ct = apreq_env_content_type(req->env);
apr_size_t blen;
apr_status_t s;
1.5 +2 -0 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- apreq_parsers.h 11 Apr 2003 16:10:03 -0000 1.4
+++ apreq_parsers.h 12 Apr 2003 01:45:30 -0000 1.5
@@ -70,6 +70,8 @@
APREQ_DECLARE(apr_status_t) apreq_merge_parsers(apr_pool_t *p,
const apr_array_header_t *a);
+APREQ_DECLARE(apr_status_t)apreq_parse(apreq_request_t *req);
+
#ifdef __cplusplus
}
1.10 +0 -10 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- apreq_tables.c 11 Apr 2003 02:48:01 -0000 1.9
+++ apreq_tables.c 12 Apr 2003 01:45:30 -0000 1.10
@@ -52,16 +52,6 @@
* <http://www.apache.org/>.
*/
-/*
- * Resource allocation code... the code here is responsible for making
- * sure that nothing leaks.
- *
- * rst --- 4/95 --- 6/95
- */
-
-/*
-#include "apr_private.h"
-*/
#include "apr_general.h"
#include "apr_pools.h"
#include "apreq_tables.h"