You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-cvs@httpd.apache.org by jo...@apache.org on 2005/01/26 00:36:04 UTC

svn commit: r126444 - in httpd/apreq/branches/multi-env-unstable: . env env/c-modules/apreq_access_test env/c-modules/apreq_big_request_test env/c-modules/apreq_cookie_test env/c-modules/apreq_output_filter_test env/c-modules/apreq_redirect_test env/c-modules/apreq_request_test env/t src t

Author: joes
Date: Tue Jan 25 15:36:01 2005
New Revision: 126444

URL: http://svn.apache.org/viewcvs?view=rev&rev=126444
Log:

Introduce apreq_env_handle_t to replace the void *env usage.
Also added apreq_env_custom for making private handles, and new 
apreq_env_apache2.h to let mod_apreq export apreq_env_make_apache2.

This patch represents part one of 

        http://marc.theaimsgroup.com/?l=apreq-dev&m=110667661730797&w=2

I added a few additional notes to STATUS and CHANGES.

Submitted by: Max Kellermann
Reviewed by: joes

Added:
   httpd/apreq/branches/multi-env-unstable/env/apreq_env_apache2.h
   httpd/apreq/branches/multi-env-unstable/src/apreq_env_custom.c
Modified:
   httpd/apreq/branches/multi-env-unstable/CHANGES
   httpd/apreq/branches/multi-env-unstable/STATUS
   httpd/apreq/branches/multi-env-unstable/env/Makefile.am
   httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_access_test/mod_apreq_access_test.c
   httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_big_request_test/mod_apreq_big_request_test.c
   httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_cookie_test/mod_apreq_cookie_test.c
   httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_output_filter_test/mod_apreq_output_filter_test.c
   httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_redirect_test/mod_apreq_redirect_test.c
   httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_request_test/mod_apreq_request_test.c
   httpd/apreq/branches/multi-env-unstable/env/mod_apreq.c
   httpd/apreq/branches/multi-env-unstable/env/t/TEST.PL
   httpd/apreq/branches/multi-env-unstable/env/test_cgi.c
   httpd/apreq/branches/multi-env-unstable/src/Makefile.am
   httpd/apreq/branches/multi-env-unstable/src/apreq.c
   httpd/apreq/branches/multi-env-unstable/src/apreq.h
   httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.c
   httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.h
   httpd/apreq/branches/multi-env-unstable/src/apreq_env.c
   httpd/apreq/branches/multi-env-unstable/src/apreq_env.h
   httpd/apreq/branches/multi-env-unstable/src/apreq_env_cgi.c
   httpd/apreq/branches/multi-env-unstable/src/apreq_params.c
   httpd/apreq/branches/multi-env-unstable/src/apreq_params.h
   httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.c
   httpd/apreq/branches/multi-env-unstable/t/cookie.c
   httpd/apreq/branches/multi-env-unstable/t/params.c
   httpd/apreq/branches/multi-env-unstable/t/parsers.c
   httpd/apreq/branches/multi-env-unstable/t/testall.c

Modified: httpd/apreq/branches/multi-env-unstable/CHANGES
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/CHANGES?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/CHANGES&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/CHANGES&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/CHANGES	(original)
+++ httpd/apreq/branches/multi-env-unstable/CHANGES	Tue Jan 25 15:36:01 2005
@@ -4,6 +4,10 @@
 
 @section v2_05 Changes with libapreq2-2.05
 
+- C API [Max Kellermann]
+  Introduce apreq_env_handle_t to replace the void *env usage.
+  Also added apreq_env_custom for making private handles, and new 
+  apreq_env_apache2.h to let mod_apreq export apreq_env_make_apache2.
 
 - C API [Max Kellermann]
   Rename apreq_env_t to apreq_env_module_t, to prepare for

Modified: httpd/apreq/branches/multi-env-unstable/STATUS
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/STATUS?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/STATUS&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/STATUS&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/STATUS	(original)
+++ httpd/apreq/branches/multi-env-unstable/STATUS	Tue Jan 25 15:36:01 2005
@@ -20,6 +20,8 @@
 RELEASE SHOWSTOPPERS:
 
      - The api docs and perl glue are currently broken.
+     - Need to fix the memory leak regression in apreq_env_custom and 
+       apreq_env_cgi (created bucket allocators need to be explicitly destroyed).
 
 
 CURRENT VOTES:

Modified: httpd/apreq/branches/multi-env-unstable/env/Makefile.am
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/env/Makefile.am?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/env/Makefile.am&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/env/Makefile.am&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/env/Makefile.am	(original)
+++ httpd/apreq/branches/multi-env-unstable/env/Makefile.am	Tue Jan 25 15:36:01 2005
@@ -3,6 +3,8 @@
 LDFLAGS = @APR_LDFLAGS@ @APU_LDFLAGS@
 TEST_CONFIG_SCRIPT = package Apache::TestMM; filter_args(); generate_script("t/TEST")
 EXTRA_DIST = t c-modules
+pkgincludedir = $(includedir)/@APREQ_LIBNAME@
+pkginclude_HEADERS = apreq_env_apache2.h
 mod_apreq_la_LDFLAGS = -export-dynamic -module -avoid-version -rpath `@APACHE2_APXS@ -q LIBEXECDIR`
 
 check_PROGRAMS = test_cgi

Added: httpd/apreq/branches/multi-env-unstable/env/apreq_env_apache2.h
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/env/apreq_env_apache2.h?view=auto&rev=126444
==============================================================================
--- (empty file)
+++ httpd/apreq/branches/multi-env-unstable/env/apreq_env_apache2.h	Tue Jan 25 15:36:01 2005
@@ -0,0 +1,37 @@
+/*
+**  Copyright 2003-2004  The Apache Software Foundation
+**
+**  Licensed under the Apache License, Version 2.0 (the "License");
+**  you may not use this file except in compliance with the License.
+**  You may obtain a copy of the License at
+**
+**      http://www.apache.org/licenses/LICENSE-2.0
+**
+**  Unless required by applicable law or agreed to in writing, software
+**  distributed under the License is distributed on an "AS IS" BASIS,
+**  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+**  See the License for the specific language governing permissions and
+**  limitations under the License.
+*/
+
+#ifndef APREQ_APACHE2_H
+#define APREQ_APACHE2_H
+
+#include "apreq.h"
+#include <httpd.h>
+
+#ifdef  __cplusplus
+ extern "C" {
+#endif
+
+/**
+ * Create an apreq handle which communicates with an Apache 2
+ * request_rec.
+ */
+APREQ_DECLARE(apreq_env_handle_t*) apreq_env_make_apache2(request_rec *r);
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif

Modified: httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_access_test/mod_apreq_access_test.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_access_test/mod_apreq_access_test.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_access_test/mod_apreq_access_test.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_access_test/mod_apreq_access_test.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_access_test/mod_apreq_access_test.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_access_test/mod_apreq_access_test.c	Tue Jan 25 15:36:01 2005
@@ -32,6 +32,7 @@
 #include "apache_httpd_test.h"
 #include "apreq_params.h"
 #include "apreq_env.h"
+#include "apreq_env_apache2.h"
 #include "httpd.h"
 #include "apr_strings.h"
 
@@ -65,6 +66,7 @@
 
 static int apreq_access_checker(request_rec *r)
 {
+    apreq_env_handle_t *handle;
     apreq_request_t *req;
     apreq_param_t *param;
     struct access_test_cfg *cfg = (struct access_test_cfg *)
@@ -73,15 +75,16 @@
     if (!cfg || !cfg->param)
         return DECLINED;
 
-    req = apreq_request(r, NULL);
+    handle = apreq_env_make_apache2(r);
+    req = apreq_request(handle, NULL);
     param = apreq_param(req, cfg->param);
     if (param) {
-        apreq_log(APREQ_DEBUG 0, r, "%s => %s", cfg->param, param->v.data);
+        apreq_log(APREQ_DEBUG 0, handle, "%s => %s", cfg->param, param->v.data);
         return OK;
     }
     else {
         if (req->body)
-            apreq_log(APREQ_DEBUG HTTP_FORBIDDEN, r, "%s not found in %d elts",
+            apreq_log(APREQ_DEBUG HTTP_FORBIDDEN, handle, "%s not found in %d elts",
                       cfg->param, apr_table_elts(req->body)->nelts);
         return HTTP_FORBIDDEN;
     }

Modified: httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_big_request_test/mod_apreq_big_request_test.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_big_request_test/mod_apreq_big_request_test.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_big_request_test/mod_apreq_big_request_test.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_big_request_test/mod_apreq_big_request_test.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_big_request_test/mod_apreq_big_request_test.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_big_request_test/mod_apreq_big_request_test.c	Tue Jan 25 15:36:01 2005
@@ -29,6 +29,7 @@
 #include "apache_httpd_test.h"
 #include "apreq_params.h"
 #include "apreq_env.h"
+#include "apreq_env_apache2.h"
 #include "httpd.h"
 
 static int dump_table(void *count, const char *key, const char *value)
@@ -40,6 +41,7 @@
 
 static int apreq_big_request_test_handler(request_rec *r)
 {
+    apreq_env_handle_t *env;
     apreq_request_t *req;
     apr_table_t *params;
     int count = 0;
@@ -47,8 +49,10 @@
     if (strcmp(r->handler, "apreq_big_request_test") != 0)
         return DECLINED;
 
-    apreq_log(APREQ_DEBUG 0, r, "initializing request");
-    req = apreq_request(r, NULL);
+    env = apreq_env_make_apache2(r);
+
+    apreq_log(APREQ_DEBUG 0, env, "initializing request");
+    req = apreq_request(env, NULL);
     params = apreq_params(r->pool, req);
     apr_table_do(dump_table, &count, params, NULL);
     ap_set_content_type(r, "text/plain");

Modified: httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_cookie_test/mod_apreq_cookie_test.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_cookie_test/mod_apreq_cookie_test.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_cookie_test/mod_apreq_cookie_test.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_cookie_test/mod_apreq_cookie_test.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_cookie_test/mod_apreq_cookie_test.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_cookie_test/mod_apreq_cookie_test.c	Tue Jan 25 15:36:01 2005
@@ -29,10 +29,13 @@
 #include "apache_httpd_test.h"
 #include "apreq_params.h"
 #include "apreq_env.h"
+#include "apreq_cookie.h"
+#include "apreq_env_apache2.h"
 #include "httpd.h"
 
 static int apreq_cookie_test_handler(request_rec *r)
 {
+    apreq_env_handle_t *env;
     apreq_request_t *req;
     apr_status_t s;
     const apreq_jar_t *jar;
@@ -45,21 +48,23 @@
     if (strcmp(r->handler, "apreq_cookie_test") != 0)
         return DECLINED;
 
-    apreq_log(APREQ_DEBUG 0, r, "initializing request");
-    req = apreq_request(r, NULL);
+    env = apreq_env_make_apache2(r);
+
+    apreq_log(APREQ_DEBUG 0, env, "initializing request");
+    req = apreq_request(env, NULL);
     test = apreq_param(req, "test");
     key = apreq_param(req, "key");
 
-    apreq_log(APREQ_DEBUG 0, r, "initializing cookie");
-    jar = apreq_jar(r, NULL);
-    cookie = apreq_cookie(jar, key->v.data);    
+    apreq_log(APREQ_DEBUG 0, env, "initializing cookie");
+    jar = apreq_jar(env, NULL);
+    cookie = apreq_cookie(jar, key->v.data);
     ap_set_content_type(r, "text/plain");
 
     if (strcmp(test->v.data, "bake") == 0) {
-        s = apreq_cookie_bake(cookie, r);
+        s = apreq_cookie_bake(cookie, env);
     }
     else if (strcmp(test->v.data, "bake2") == 0) {
-        s = apreq_cookie_bake2(cookie, r);
+        s = apreq_cookie_bake2(cookie, env);
     }
     else {
         size = strlen(cookie->v.data);

Modified: httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_output_filter_test/mod_apreq_output_filter_test.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_output_filter_test/mod_apreq_output_filter_test.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_output_filter_test/mod_apreq_output_filter_test.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_output_filter_test/mod_apreq_output_filter_test.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_output_filter_test/mod_apreq_output_filter_test.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_output_filter_test/mod_apreq_output_filter_test.c	Tue Jan 25 15:36:01 2005
@@ -27,16 +27,19 @@
 #include "apache_httpd_test.h"
 #include "apreq_params.h"
 #include "apreq_env.h"
+#include "apreq_env_apache2.h"
 #include "httpd.h"
 #include "util_filter.h"
 
 static const char filter_name[] =  "APREQ_OUTPUT_FILTER";
-module AP_MODULE_DECLARE_DATA apreq_output_filter_test_module;
+extern module AP_MODULE_DECLARE_DATA apreq_output_filter_test_module;
 
 static apr_status_t apreq_output_filter_test_init(ap_filter_t *f)
 {
+    apreq_env_handle_t *handle;
     apreq_request_t *req;
-    req = apreq_request(f->r, NULL);
+    handle = apreq_env_make_apache2(f->r);
+    req = apreq_request(handle, NULL);
     return APR_SUCCESS;
 }
 
@@ -47,8 +50,10 @@
 
 static int dump_table(void *data, const char *key, const char *value)
 {
+    apreq_env_handle_t *env;
     struct ctx_t *ctx = (struct ctx_t *)data;
-    apreq_log(APREQ_DEBUG 0, ctx->r, "%s => %s", key, value);
+    env = apreq_env_make_apache2(ctx->r);
+    apreq_log(APREQ_DEBUG 0, env, "%s => %s", key, value);
     apr_brigade_printf(ctx->bb,NULL,NULL,"\t%s => %s\n", key, value);
     return 1;
 }
@@ -56,6 +61,7 @@
 static apr_status_t apreq_output_filter_test(ap_filter_t *f, apr_bucket_brigade *bb)
 {
     request_rec *r = f->r;
+    apreq_env_handle_t *env;
     apreq_request_t *req;
     apr_bucket_brigade *eos;
     struct ctx_t ctx = {r, bb};
@@ -65,8 +71,9 @@
 
     eos = apr_brigade_split(bb, APR_BRIGADE_LAST(bb));
 
-    req = apreq_request(r, NULL);
-    apreq_log(APREQ_DEBUG 0, r, "appending parsed data");
+    env = apreq_env_make_apache2(r);
+    req = apreq_request(env, NULL);
+    apreq_log(APREQ_DEBUG 0, env, "appending parsed data");
     apr_brigade_puts(bb, NULL, NULL, "\n--APREQ OUTPUT FILTER--\nARGS:\n");
     apr_table_do(dump_table, &ctx, req->args, NULL);
 
@@ -80,6 +87,7 @@
 
 static void register_hooks (apr_pool_t *p)
 {
+    (void)p;
     ap_register_output_filter(filter_name, apreq_output_filter_test, 
                               apreq_output_filter_test_init,
                               AP_FTYPE_CONTENT_SET);

Modified: httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_redirect_test/mod_apreq_redirect_test.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_redirect_test/mod_apreq_redirect_test.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_redirect_test/mod_apreq_redirect_test.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_redirect_test/mod_apreq_redirect_test.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_redirect_test/mod_apreq_redirect_test.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_redirect_test/mod_apreq_redirect_test.c	Tue Jan 25 15:36:01 2005
@@ -30,22 +30,26 @@
 #include "apache_httpd_test.h"
 #include "apreq_params.h"
 #include "apreq_env.h"
+#include "apreq_env_apache2.h"
 #include "httpd.h"
 
 static int apreq_redirect_test_handler(request_rec *r)
 {
+    apreq_env_handle_t *env;
     apreq_request_t *req;
     const apreq_param_t *loc;
 
     if (strcmp(r->handler, "apreq_redirect_test") != 0)
         return DECLINED;
 
-    req = apreq_request(r, NULL);
-    apreq_log(APREQ_DEBUG 0, r, "looking for new location");
+    env = apreq_env_make_apache2(r);
+
+    req = apreq_request(env, NULL);
+    apreq_log(APREQ_DEBUG 0, env, "looking for new location");
     loc = apreq_param(req, "location");
     if (!loc)
         return DECLINED;
-    apreq_log(APREQ_DEBUG 0,r, "redirecting to %s", loc->v.data);
+    apreq_log(APREQ_DEBUG 0, env, "redirecting to %s", loc->v.data);
     ap_internal_redirect(loc->v.data, r);
     return OK;
 }

Modified: httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_request_test/mod_apreq_request_test.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_request_test/mod_apreq_request_test.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_request_test/mod_apreq_request_test.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_request_test/mod_apreq_request_test.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_request_test/mod_apreq_request_test.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/env/c-modules/apreq_request_test/mod_apreq_request_test.c	Tue Jan 25 15:36:01 2005
@@ -30,18 +30,22 @@
 #include "apache_httpd_test.h"
 #include "apreq_params.h"
 #include "apreq_env.h"
+#include "apreq_env_apache2.h"
 #include "httpd.h"
 
 static int dump_table(void *ctx, const char *key, const char *value)
 {
     request_rec *r = ctx;
-    apreq_log(APREQ_DEBUG 0, r, "%s => %s", key, value);
+    apreq_env_handle_t *env;
+    env = apreq_env_make_apache2(r);
+    apreq_log(APREQ_DEBUG 0, env, "%s => %s", key, value);
     ap_rprintf(r, "\t%s => %s\n", key, value);
     return 1;
 }
 
 static int apreq_request_test_handler(request_rec *r)
 {
+    apreq_env_handle_t *env;
     apr_bucket_brigade *bb;
     apreq_request_t *req;
     apr_status_t s;
@@ -49,11 +53,13 @@
     if (strcmp(r->handler, "apreq_request_test") != 0)
         return DECLINED;
 
-    apreq_log(APREQ_DEBUG 0, r, "initializing request");
-    req = apreq_request(r, NULL);
+    env = apreq_env_make_apache2(r);
+
+    apreq_log(APREQ_DEBUG 0, env, "initializing request");
+    req = apreq_request(env, NULL);
     bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
 
-    apreq_log(APREQ_DEBUG 0, r, "start parsing body");    
+    apreq_log(APREQ_DEBUG 0, env, "start parsing body");
     while ((s =ap_get_brigade(r->input_filters, bb, AP_MODE_READBYTES,
                               APR_BLOCK_READ, HUGE_STRING_LEN)) == APR_SUCCESS)
     {
@@ -63,7 +69,7 @@
         apr_brigade_cleanup(bb);
 
     }
-    apreq_log(APREQ_DEBUG s, r, "finished parsing body");
+    apreq_log(APREQ_DEBUG s, env, "finished parsing body");
 
     ap_set_content_type(r, "text/plain");
     ap_rputs("ARGS:\n",r);

Modified: httpd/apreq/branches/multi-env-unstable/env/mod_apreq.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/env/mod_apreq.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/env/mod_apreq.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/env/mod_apreq.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/env/mod_apreq.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/env/mod_apreq.c	Tue Jan 25 15:36:01 2005
@@ -27,8 +27,11 @@
 #include "apreq_env.h"
 #include "apreq_params.h"
 #include "apreq_cookie.h"
+#include "apreq_env_apache2.h"
 
-#define dR  request_rec *r = (request_rec *)env
+#define dR      struct env_config *c = (struct env_config*)env;\
+    request_rec *r = c->r;\
+    (void)r;
 
 struct dir_config {
     const char         *temp_dir;
@@ -59,6 +62,8 @@
 
 /* The "warehouse", stored in r->request_config */
 struct env_config {
+    apreq_env_handle_t  env;
+    request_rec        *r;
     apreq_jar_t        *jar;    /* Active jar for the current request_rec */
     apreq_request_t    *req;    /* Active request for current request_rec */
     ap_filter_t        *f;      /* Active apreq filter for this request_rec */
@@ -78,7 +83,6 @@
 };
 
 static const char filter_name[] = "APREQ";
-extern module AP_MODULE_DECLARE_DATA apreq_module;
 
 /**
  * @defgroup mod_apreq Apache 2.X Filter Module
@@ -172,8 +176,8 @@
 #define APREQ_MODULE_MAGIC_NUMBER       20050105
 
 static void apache2_log(const char *file, int line, int level, 
-                        apr_status_t status, void *env, const char *fmt,
-                        va_list vp)
+                        apr_status_t status, apreq_env_handle_t *env,
+                        const char *fmt, va_list vp)
 {
     dR;
     ap_log_rerror(file, line, level, status, r, 
@@ -181,25 +185,25 @@
 }
 
 
-static const char *apache2_query_string(void *env)
+static const char *apache2_query_string(apreq_env_handle_t *env)
 {
     dR;
     return r->args;
 }
 
-static apr_pool_t *apache2_pool(void *env)
+static apr_pool_t *apache2_pool(apreq_env_handle_t *env)
 {
     dR;
     return r->pool;
 }
 
-static apr_bucket_alloc_t *apache2_bucket_alloc(void *env)
+static apr_bucket_alloc_t *apache2_bucket_alloc(apreq_env_handle_t *env)
 {
     dR;
     return r->connection->bucket_alloc;
 }
 
-static const char *apache2_header_in(void *env, const char *name)
+static const char *apache2_header_in(apreq_env_handle_t *env, const char *name)
 {
     dR;
     return apr_table_get(r->headers_in, name);
@@ -210,8 +214,8 @@
  * @bug Sending a Set-Cookie header on a 304
  * requires err_headers_out table.
  */
-static apr_status_t apache2_header_out(void *env, const char *name, 
-                                       char *value)
+static apr_status_t apache2_header_out(apreq_env_handle_t *env,
+                                       const char *name, char *value)
 {
     dR;
     apr_table_add(r->err_headers_out, name, value);
@@ -219,34 +223,9 @@
 }
 
 
-APR_INLINE
-static struct env_config *get_cfg(request_rec *r)
-{
-    struct env_config *cfg = 
-        ap_get_module_config(r->request_config, &apreq_module);
-    if (cfg == NULL) {
-        struct dir_config *d = ap_get_module_config(r->per_dir_config, 
-                                                    &apreq_module);
-        cfg = apr_pcalloc(r->pool, sizeof *cfg);
-        ap_set_module_config(r->request_config, &apreq_module, cfg);
-
-        if (d) {
-            cfg->temp_dir    = d->temp_dir;
-            cfg->max_body    = d->max_body;
-            cfg->max_brigade = d->max_brigade;
-        } 
-        else {
-            cfg->max_body    = -1;
-            cfg->max_brigade = APREQ_MAX_BRIGADE_LEN;
-        }
-    }
-    return cfg;
-}
-
-static apreq_jar_t *apache2_jar(void *env, apreq_jar_t *jar)
+static apreq_jar_t *apache2_jar(apreq_env_handle_t *env, apreq_jar_t *jar)
 {
     dR;
-    struct env_config *c = get_cfg(r);
     if (jar != NULL) {
         apreq_jar_t *old = c->jar;
         c->jar = jar;
@@ -267,9 +246,10 @@
     }
 }
 
-static ap_filter_t *get_apreq_filter(request_rec *r)
+static ap_filter_t *get_apreq_filter(apreq_env_handle_t *env)
 {
-    struct env_config *cfg = get_cfg(r);
+    struct env_config *cfg = (struct env_config*)env;
+    request_rec *r = cfg->r;
 
     if (cfg->f != NULL)
        return cfg->f;
@@ -284,14 +264,13 @@
     return cfg->f;
 }
 
-static apreq_request_t *apache2_request(void *env, 
+static apreq_request_t *apache2_request(apreq_env_handle_t *env,
                                         apreq_request_t *req)
 {
     dR;
-    struct env_config *c = get_cfg(r);
 
     if (c->f == NULL)
-        get_apreq_filter(r);
+        get_apreq_filter(env);
 
     if (req != NULL) {
         apreq_request_t *old = c->req;
@@ -306,7 +285,8 @@
 static void apreq_filter_make_context(ap_filter_t *f)
 {
     request_rec *r = f->r;
-    struct env_config *cfg = get_cfg(r);
+    apreq_env_handle_t *env = apreq_env_make_apache2(r);
+    struct env_config *cfg = (struct env_config*)env;
     apreq_request_t *req = cfg->req;
     struct filter_ctx *ctx;
     apr_bucket_alloc_t *alloc;
@@ -324,7 +304,7 @@
         case APR_INCOMPLETE:
             break;
         default:
-            apreq_log(APREQ_DEBUG ctx->status, r, 
+            apreq_log(APREQ_DEBUG ctx->status, env, 
                       "cannot steal context: bad filter status");
             goto make_new_context;
         }
@@ -335,18 +315,18 @@
 
             if (req != NULL) {
                 if (req->parser != NULL) {
-                    apreq_log(APREQ_DEBUG ctx->status, r, 
+                    apreq_log(APREQ_DEBUG ctx->status, env,
                               "cannot steal context: new parser detected");
                     goto make_new_context;
                 }
             }
             else {
-                req = apreq_request(r, NULL);
+                req = apache2_request(env, NULL);
             }
 
             /* steal the parser output */
-            apreq_log(APREQ_DEBUG 0, r, "stealing parser output");
-            old_req = apreq_request(ctx->r, NULL);
+            apreq_log(APREQ_DEBUG 0, env, "stealing parser output");
+            old_req = apache2_request(apreq_env_make_apache2(ctx->r), NULL);
             req->parser = old_req->parser;
             req->body = old_req->body;
             req->body_status = old_req->body_status;
@@ -354,7 +334,7 @@
         }
 
         /* steal the filter context */
-        apreq_log(APREQ_DEBUG 0, r, "stealing filter context");
+        apreq_log(APREQ_DEBUG 0, env, "stealing filter context");
         f->ctx = f->next->ctx;
         r->proto_input_filters = f;
         ap_remove_input_filter(f->next);
@@ -388,18 +368,18 @@
             apr_int64_t content_length = apr_strtoi64(cl,&dummy,0);
 
             if (dummy == NULL || *dummy != 0) {
-                apreq_log(APREQ_ERROR APR_EGENERAL, r, 
+                apreq_log(APREQ_ERROR APR_EGENERAL, env,
                       "Invalid Content-Length header (%s)", cl);
                 ctx->status = APR_EGENERAL;
-                apreq_request(r, NULL)->body_status = APR_EGENERAL;
+                apache2_request(env, NULL)->body_status = APR_EGENERAL;
             }
             else if (content_length > (apr_int64_t)cfg->max_body) {
-                apreq_log(APREQ_ERROR APR_EGENERAL, r,
+                apreq_log(APREQ_ERROR APR_EGENERAL, env,
                           "Content-Length header (%s) exceeds configured "
                           "max_body limit (%" APR_OFF_T_FMT ")", 
                           cl, cfg->max_body);
                 ctx->status = APR_EGENERAL;
-                apreq_request(r, NULL)->body_status = APR_EGENERAL;
+                apache2_request(env, NULL)->body_status = APR_EGENERAL;
             }
         }
     }
@@ -409,12 +389,11 @@
  * Reads data directly into the parser.
  */
 
-static apr_status_t apache2_read(void *env, 
+static apr_status_t apache2_read(apreq_env_handle_t *env,
                                  apr_read_type_e block,
                                  apr_off_t bytes)
 {
-    dR;
-    ap_filter_t *f = get_apreq_filter(r); /*ensures correct filter for prefetch */
+    ap_filter_t *f = get_apreq_filter(env); /*ensures correct filter for prefetch */
     struct filter_ctx *ctx;
     apr_status_t s;
 
@@ -424,7 +403,7 @@
     if (ctx->status != APR_INCOMPLETE || bytes == 0)
         return ctx->status;
 
-    apreq_log(APREQ_DEBUG 0, r, "prefetching %" APR_OFF_T_FMT " bytes", bytes);
+    apreq_log(APREQ_DEBUG 0, env, "prefetching %" APR_OFF_T_FMT " bytes", bytes);
     s = ap_get_brigade(f, NULL, AP_MODE_READBYTES, block, bytes);
     if (s != APR_SUCCESS)
         return s;
@@ -432,10 +411,9 @@
 }
 
 
-static const char *apache2_temp_dir(void *env, const char *path)
+static const char *apache2_temp_dir(apreq_env_handle_t *env, const char *path)
 {
     dR;
-    struct env_config *c = get_cfg(r);
 
     if (path != NULL) {
         const char *rv = c->temp_dir;
@@ -451,10 +429,9 @@
 }
 
 
-static apr_off_t apache2_max_body(void *env, apr_off_t bytes)
+static apr_off_t apache2_max_body(apreq_env_handle_t *env, apr_off_t bytes)
 {
     dR;
-    struct env_config *c = get_cfg(r);
 
     if (bytes >= 0) {
         apr_off_t rv = c->max_body;
@@ -465,10 +442,10 @@
 }
 
 
-static apr_ssize_t apache2_max_brigade(void *env, apr_ssize_t bytes)
+static apr_ssize_t apache2_max_brigade(apreq_env_handle_t *env,
+                                       apr_ssize_t bytes)
 {
-    dR;
-    struct env_config *c = get_cfg(r);
+    struct env_config *c = (struct env_config*)env;
 
     if (bytes >= 0) {
         apr_ssize_t rv = c->max_brigade;
@@ -503,7 +480,8 @@
 static apr_status_t apreq_filter_init(ap_filter_t *f)
 {
     request_rec *r = f->r;
-    struct env_config *cfg = get_cfg(r);
+    apreq_env_handle_t *env = apreq_env_make_apache2(r);
+    struct env_config *cfg = (struct env_config*)env;
     ap_filter_t *in;
 
     if (f != r->proto_input_filters) {
@@ -516,14 +494,14 @@
         {
             if (f == in) {
                 if (strcasecmp(r->input_filters->frec->name, filter_name) == 0) {
-                    apreq_log(APREQ_DEBUG 0, r, 
+                    apreq_log(APREQ_DEBUG 0, env,
                               "removing intermediate apreq filter");
                     if (cfg->f == f)
                         cfg->f = r->input_filters;
                     ap_remove_input_filter(f);
                 }
                 else {
-                    apreq_log(APREQ_DEBUG 0, r, 
+                    apreq_log(APREQ_DEBUG 0, env,
                               "relocating intermediate apreq filter");
                     apreq_filter_relocate(f);
                     cfg->f = f;
@@ -537,7 +515,7 @@
      * if it is, we must deregister it now.
      */
     if (cfg->f == f) {
-        apreq_log(APREQ_DEBUG 0, r, "disabling stale protocol filter");
+        apreq_log(APREQ_DEBUG 0, env, "disabling stale protocol filter");
         cfg->f = NULL;
     }
     return APR_SUCCESS;
@@ -551,8 +529,8 @@
 {
     request_rec *r = f->r;
     struct filter_ctx *ctx;
+    apreq_env_handle_t *env;
     struct env_config *cfg;
-    apreq_request_t *req;
     apr_status_t rv;
 
     switch (mode) {
@@ -566,8 +544,8 @@
         return APR_ENOTIMPL;
     }
 
-    cfg = get_cfg(r);
-    req = cfg->req;
+    env = apreq_env_make_apache2(r);
+    cfg = (struct env_config*)env;
 
     if (f->ctx == NULL)
         apreq_filter_make_context(f);
@@ -586,7 +564,7 @@
                 rv = ap_get_brigade(f->next, bb, mode, block, readbytes);
             
                 if (rv != APR_SUCCESS) {
-                    apreq_log(APREQ_ERROR rv, r, "ap_get_brigade failed");
+                    apreq_log(APREQ_ERROR rv, env, "ap_get_brigade failed");
                     return rv;
                 }
 
@@ -596,8 +574,8 @@
 
                 if (cfg->max_body >= 0 && ctx->bytes_read > cfg->max_body) {
                     ctx->status = APR_EGENERAL;
-                    apreq_request(r, NULL)->body_status = APR_EGENERAL;
-                    apreq_log(APREQ_ERROR ctx->status, r, "Bytes read (" APR_OFF_T_FMT
+                    apache2_request(env, NULL)->body_status = APR_EGENERAL;
+                    apreq_log(APREQ_ERROR ctx->status, env, "Bytes read (" APR_OFF_T_FMT
                               ") exceeds configured max_body limit (" APR_OFF_T_FMT ")",
                               ctx->bytes_read, cfg->max_body);
                 }
@@ -613,7 +591,7 @@
                 apr_bucket *e;
                 rv = apr_brigade_partition(bb, readbytes, &e);
                 if (rv != APR_SUCCESS && rv != APR_INCOMPLETE) {
-                    apreq_log(APREQ_ERROR rv, r, "partition failed");
+                    apreq_log(APREQ_ERROR rv, env, "partition failed");
                     return rv;
                 }
                 if (APR_BUCKET_IS_EOS(e))
@@ -628,7 +606,7 @@
                 ap_filter_t *next = f->next;
 
                 if (cfg->f != f) {
-                    apreq_log(APREQ_DEBUG ctx->status, r,
+                    apreq_log(APREQ_DEBUG ctx->status, env,
                               "removing inactive filter (%d)",
                               r->input_filters == f);
 
@@ -657,7 +635,7 @@
 
             rv = ap_get_brigade(f->next, bb, mode, block, readbytes);
             if (rv != APR_SUCCESS) {
-                apreq_log(APREQ_ERROR rv, r, "ap_get_brigade failed");
+                apreq_log(APREQ_ERROR rv, env, "ap_get_brigade failed");
                 return rv;
             }
             APREQ_BRIGADE_SETASIDE(bb, r->pool);
@@ -666,9 +644,9 @@
             apr_brigade_length(bb, 1, &len);
             total_read += len;
 
-            rv = apreq_brigade_concat(r, ctx->spool, bb);
+            rv = apreq_brigade_concat(env, ctx->spool, bb);
             if (rv != APR_SUCCESS && rv != APR_EOF) {
-                apreq_log(APREQ_ERROR rv, r,
+                apreq_log(APREQ_ERROR rv, env,
                           "apreq_brigade_concat failed; APREQ_TempDir problem?");
                 return rv;
             }
@@ -678,8 +656,8 @@
 
         if (cfg->max_body >= 0 && ctx->bytes_read > cfg->max_body) {
             ctx->status = APR_EGENERAL;
-            apreq_request(r, NULL)->body_status = APR_EGENERAL;
-            apreq_log(APREQ_ERROR ctx->status, r, "Bytes read (%" APR_OFF_T_FMT
+            apache2_request(env, NULL)->body_status = APR_EGENERAL;
+            apreq_log(APREQ_ERROR ctx->status, env, "Bytes read (%" APR_OFF_T_FMT
                       ") exceeds configured max_body limit (%" APR_OFF_T_FMT ")",
                       ctx->bytes_read, cfg->max_body);
         }
@@ -703,8 +681,7 @@
         return APR_SUCCESS;
 
     if (ctx->status == APR_INCOMPLETE) {
-        if (req == NULL)
-            req = apreq_request(r, NULL);
+        apreq_request_t *req = apache2_request(env, NULL);
 
         ctx->status = apreq_parse_request(req, ctx->bb);
         apr_brigade_cleanup(ctx->bb);
@@ -718,8 +695,6 @@
 
 static void register_hooks (apr_pool_t *p)
 {
-    const apreq_env_module_t *old_env;
-    old_env = apreq_env_module(&apache2_module);
     ap_register_input_filter(filter_name, apreq_filter, apreq_filter_init,
                              AP_FTYPE_PROTOCOL-1);
 }
@@ -798,3 +773,32 @@
 	apreq_cmds,
 	register_hooks,
 };
+
+APREQ_DECLARE(apreq_env_handle_t*) apreq_env_make_apache2(request_rec *r) {
+    struct env_config *cfg =
+        ap_get_module_config(r->request_config, &apreq_module);
+    struct dir_config *d;
+
+    if (cfg != NULL)
+        return &cfg->env;
+
+    d = ap_get_module_config(r->per_dir_config,
+                             &apreq_module);
+    cfg = apr_pcalloc(r->pool, sizeof *cfg);
+    ap_set_module_config(r->request_config, &apreq_module, cfg);
+
+    cfg->env.module = &apache2_module;
+    cfg->r = r;
+
+    if (d == NULL) {
+        cfg->max_body    = -1;
+        cfg->max_brigade = APREQ_MAX_BRIGADE_LEN;
+    } else {
+        apreq_log(APREQ_DEBUG 0, &cfg->env, "copying temp_dir %s", d->temp_dir);
+        cfg->temp_dir    = d->temp_dir;
+        cfg->max_body    = d->max_body;
+        cfg->max_brigade = d->max_brigade;
+    }
+
+    return &cfg->env;
+}

Modified: httpd/apreq/branches/multi-env-unstable/env/t/TEST.PL
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/env/t/TEST.PL?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/env/t/TEST.PL&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/env/t/TEST.PL&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/env/t/TEST.PL	(original)
+++ httpd/apreq/branches/multi-env-unstable/env/t/TEST.PL	Tue Jan 25 15:36:01 2005
@@ -73,7 +73,7 @@
 all: $lib
 
 $lib: $name.c
-        \$(APXS) -I../../../src $libs -llibhttpd $dversion -p -I$self->{cmodules_dir} -c $name.c
+        \$(APXS) -I../.. -I../../../src $libs -llibhttpd $dversion -p -I$self->{cmodules_dir} -c $name.c
 
 clean:
 	-erase @goners vc60.pdb 
@@ -85,7 +85,7 @@
 all: $lib
 
 $lib: $name.c
-	\$(APXS) -L../../../src -I../../../src -lapreq2 $dversion -I$self->{cmodules_dir} -c $name.c
+	\$(APXS) -L../../../src -I../.. -I../../../src -lapreq2 $dversion -I$self->{cmodules_dir} -c $name.c
 
 clean:
 	-rm -rf $name.o $name.lo $name.slo $name.la .libs

Modified: httpd/apreq/branches/multi-env-unstable/env/test_cgi.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/env/test_cgi.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/env/test_cgi.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/env/test_cgi.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/env/test_cgi.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/env/test_cgi.c	Tue Jan 25 15:36:01 2005
@@ -35,6 +35,7 @@
 int main(int argc, char const * const * argv)
 {
     apr_pool_t *pool;
+    apreq_env_handle_t *env;
     apreq_request_t *req;
     const apreq_param_t *foo, *bar, *test, *key;
     apr_file_t *out;
@@ -50,12 +51,14 @@
         exit(-1);
     }
 
+    env = apreq_env_make_cgi(pool);
+
     apr_file_open_stdout(&out, pool);
 
-    apreq_log(APREQ_DEBUG 0, pool, "%s", "Creating apreq_request");
-    req = apreq_request(pool, NULL);
+    apreq_log(APREQ_DEBUG 0, env, "%s", "Creating apreq_request");
+    req = apreq_request(env, NULL);
 
-    apreq_log(APREQ_DEBUG 0, pool, "%s", "Fetching the parameters");
+    apreq_log(APREQ_DEBUG 0, env, "%s", "Fetching the parameters");
 
     foo = apreq_param(req, "foo");
     bar = apreq_param(req, "bar");
@@ -68,33 +71,33 @@
 
         if (foo) {
             apr_file_printf(out, "\t%s => %s\n", "foo", foo->v.data);
-            apreq_log(APREQ_DEBUG 0, pool, "%s => %s", "foo", foo->v.data);
+            apreq_log(APREQ_DEBUG 0, env, "%s => %s", "foo", foo->v.data);
         }
         if (bar) {
             apr_file_printf(out, "\t%s => %s\n", "bar", bar->v.data);
-            apreq_log(APREQ_DEBUG 0, pool, "%s => %s", "bar", bar->v.data);
+            apreq_log(APREQ_DEBUG 0, env, "%s => %s", "bar", bar->v.data);
         }
     }
     
     else if (test && key) {
-        const apreq_jar_t *jar = apreq_jar(pool, NULL);
+        const apreq_jar_t *jar = apreq_jar(env, NULL);
         apreq_cookie_t *cookie;
         char *dest;
 
-        apreq_log(APREQ_DEBUG 0, pool, "Fetching Cookie %s", key->v.data);
+        apreq_log(APREQ_DEBUG 0, env, "Fetching Cookie %s", key->v.data);
         cookie = apreq_cookie(jar, key->v.data);
 
         if (cookie == NULL) {
-            apreq_log(APREQ_DEBUG APR_EGENERAL, pool, 
+            apreq_log(APREQ_DEBUG APR_EGENERAL, env,
                       "No cookie for %s found!", key->v.data);
             exit(-1);
         }
 
         if (strcmp(test->v.data, "bake") == 0) {
-            apreq_cookie_bake(cookie, pool);
+            apreq_cookie_bake(cookie, env);
         }
         else if (strcmp(test->v.data, "bake2") == 0) {
-            apreq_cookie_bake2(cookie, pool);
+            apreq_cookie_bake2(cookie, env);
         }
 
         apr_file_printf(out, "%s", "Content-Type: text/plain\n\n");
@@ -102,7 +105,7 @@
         if (apreq_decode(dest, cookie->v.data, cookie->v.size) >= 0)
             apr_file_printf(out, "%s", dest);
         else {
-            apreq_log(APREQ_ERROR APR_EGENERAL, pool, 
+            apreq_log(APREQ_ERROR APR_EGENERAL, env,
                       "Bad cookie encoding: %s", 
                       cookie->v.data);
             exit(-1);
@@ -114,10 +117,10 @@
         int count = 0;
         apr_file_printf(out, "%s", "Content-Type: text/plain\n\n");
 
-        apreq_log(APREQ_DEBUG 0, pool, "Fetching all parameters");
+        apreq_log(APREQ_DEBUG 0, env, "Fetching all parameters");
 
         if (params == NULL) {
-            apreq_log(APREQ_ERROR APR_EGENERAL, pool, "No parameters found!");
+            apreq_log(APREQ_ERROR APR_EGENERAL, env, "No parameters found!");
             exit(-1);
         }
         apr_table_do(dump_table, &count, params, NULL);

Modified: httpd/apreq/branches/multi-env-unstable/src/Makefile.am
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/Makefile.am?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/src/Makefile.am&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/src/Makefile.am&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/Makefile.am	(original)
+++ httpd/apreq/branches/multi-env-unstable/src/Makefile.am	Tue Jan 25 15:36:01 2005
@@ -5,7 +5,7 @@
 BUILT_SOURCES= @APR_LA@ @APU_LA@
 lib_LTLIBRARIES = libapreq2.la
 libapreq2_la_SOURCES = apreq.c apreq_version.c apreq_cookie.c \
-                       apreq_env_cgi.c \
+                       apreq_env_custom.c apreq_env_cgi.c \
                        apreq_params.c apreq_parsers.c apreq_env.c
 pkginclude_HEADERS = apreq.h apreq_version.h apreq_cookie.h \
                   apreq_params.h  apreq_env.h

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/src/apreq.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/src/apreq.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq.c	Tue Jan 25 15:36:01 2005
@@ -75,7 +75,7 @@
     return v;
 }
 
-APREQ_DECLARE(const char *)apreq_enctype(void *env)
+APREQ_DECLARE(const char *)apreq_enctype(apreq_env_handle_t *env)
 {
     char *enctype;
     const char *ct = apreq_env_content_type(env);

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq.h
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq.h?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/src/apreq.h&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/src/apreq.h&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq.h	(original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq.h	Tue Jan 25 15:36:01 2005
@@ -147,10 +147,19 @@
                                    const apr_array_header_t *arr);
 
 /**
+ * An apreq environment, associated with an env module. The structure
+ * may have variable size, because the module may append its own data
+ * structures after it.
+ */
+typedef struct apreq_env_handle_t {
+    const struct apreq_env_module_t *module;
+} apreq_env_handle_t;
+
+/**
  * Fetches the enctype from the environment.
  * @param env Environment.
  */
-APREQ_DECLARE(const char *)apreq_enctype(void *env);
+APREQ_DECLARE(const char *)apreq_enctype(apreq_env_handle_t *env);
 
 /** @enum apreq_join_t Join type */
 typedef enum { 

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.c	Tue Jan 25 15:36:01 2005
@@ -67,7 +67,7 @@
                                       1 -> not found, keep going. */
 }
 
-APREQ_DECLARE(apreq_cookie_version_t) apreq_ua_cookie_version(void *env)
+APREQ_DECLARE(apreq_cookie_version_t) apreq_ua_cookie_version(apreq_env_handle_t *env)
 {
     if (apreq_env_cookie2(env) == NULL) {
         apreq_jar_t *j = apreq_jar(env, NULL);
@@ -282,7 +282,8 @@
 }
 
 
-APREQ_DECLARE(apreq_jar_t *) apreq_jar(void *env, const char *hdr)
+APREQ_DECLARE(apreq_jar_t *) apreq_jar(apreq_env_handle_t *env,
+                                       const char *hdr)
 {
     apr_pool_t *p = apreq_env_pool(env);
 
@@ -543,7 +544,7 @@
 }
 
 APREQ_DECLARE(apr_status_t) apreq_cookie_bake(const apreq_cookie_t *c,
-                                              void *env)
+                                              apreq_env_handle_t *env)
 {
     char s[APREQ_COOKIE_MAX_LENGTH];
     int len = apreq_cookie_serialize(c, s, APREQ_COOKIE_MAX_LENGTH);
@@ -557,7 +558,7 @@
 }
 
 APREQ_DECLARE(apr_status_t) apreq_cookie_bake2(const apreq_cookie_t *c,
-                                               void *env)
+                                               apreq_env_handle_t *env)
 {
     char s[APREQ_COOKIE_MAX_LENGTH];
     if ( c->version != NETSCAPE ) {

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.h
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.h?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.h&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.h&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.h	(original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_cookie.h	Tue Jan 25 15:36:01 2005
@@ -43,7 +43,7 @@
 /** @brief This is the container class for libapreq cookies. */
 typedef struct apreq_jar_t {
     apr_table_t   *cookies;   /**< cookie table */
-    void          *env;       /**< environment */
+    apreq_env_handle_t *env;  /**< env handle */
     apr_status_t  status;     /**< status of "Cookie" header parse */
 } apreq_jar_t;
 
@@ -132,7 +132,7 @@
  */
 
 
-APREQ_DECLARE(apreq_jar_t *) apreq_jar(void *env, const char *hdr);
+APREQ_DECLARE(apreq_jar_t *) apreq_jar(apreq_env_handle_t *env, const char *hdr);
 
 /**
  * Returns a new cookie, made from the argument list.
@@ -214,7 +214,7 @@
  * @param env Environment.
  */
 APREQ_DECLARE(apr_status_t) apreq_cookie_bake(const apreq_cookie_t *c,
-                                              void *env);
+                                              apreq_env_handle_t *env);
 
 /**
  * Add the cookie to the outgoing "Set-Cookie2" headers.
@@ -223,7 +223,7 @@
  * @param env Environment.
  */
 APREQ_DECLARE(apr_status_t) apreq_cookie_bake2(const apreq_cookie_t *c,
-                                               void *env);
+                                               apreq_env_handle_t *env);
 
 /**
  * Looks for the presence of a "Cookie2" header to determine whether
@@ -232,7 +232,7 @@
  * @return APREQ_COOKIE_VERSION_RFC if rfc2965 is supported, 
  *         APREQ_COOKIE_VERSION_NETSCAPE otherwise.
  */
-APREQ_DECLARE(apreq_cookie_version_t) apreq_ua_cookie_version(void *env);
+APREQ_DECLARE(apreq_cookie_version_t) apreq_ua_cookie_version(apreq_env_handle_t *env);
 
 #ifdef __cplusplus
  }

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_env.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_env.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/src/apreq_env.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/src/apreq_env.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_env.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_env.c	Tue Jan 25 15:36:01 2005
@@ -22,96 +22,84 @@
 #include "apr_file_io.h"
 
 
-extern const apreq_env_module_t cgi_module;
-static const apreq_env_module_t *apreq_env = &cgi_module;
-
-extern void apreq_parser_initialize(void);
-
-
-APREQ_DECLARE(const apreq_env_module_t *) apreq_env_module(const apreq_env_module_t *mod)
-{
-    apreq_parser_initialize();
-    if (mod != NULL) {
-        const apreq_env_module_t *old_mod = apreq_env;
-        apreq_env = mod;
-        return old_mod;
-    }
-    return apreq_env;
-}
-
-
 APREQ_DECLARE_NONSTD(void) apreq_log(const char *file, int line,
                                      int level, apr_status_t status,
-                                     void *env, const char *fmt, ...)
+                                     apreq_env_handle_t *env,
+                                     const char *fmt, ...)
 {
     va_list vp;
     va_start(vp, fmt);
-    apreq_env->log(file,line,level,status,env,fmt,vp);
+    env->module->log(file,line,level,status,env,fmt,vp);
     va_end(vp);
 }
 
-APREQ_DECLARE(apr_pool_t *) apreq_env_pool(void *env)
+APREQ_DECLARE(apr_pool_t *) apreq_env_pool(apreq_env_handle_t *env)
 {
-    return apreq_env->pool(env);
+    return env->module->pool(env);
 }
 
-APREQ_DECLARE(apr_bucket_alloc_t *) apreq_env_bucket_alloc(void *env)
+APREQ_DECLARE(apr_bucket_alloc_t *) apreq_env_bucket_alloc(apreq_env_handle_t *env)
 {
-    return apreq_env->bucket_alloc(env);
+    return env->module->bucket_alloc(env);
 }
 
-APREQ_DECLARE(apreq_jar_t *) apreq_env_jar(void *env, apreq_jar_t *jar)
+APREQ_DECLARE(apreq_jar_t *) apreq_env_jar(apreq_env_handle_t *env,
+                                           apreq_jar_t *jar)
 {
-    return apreq_env->jar(env,jar);
+    return env->module->jar(env,jar);
 }
 
-APREQ_DECLARE(apreq_request_t *) apreq_env_request(void *env,
+APREQ_DECLARE(apreq_request_t *) apreq_env_request(apreq_env_handle_t *env,
                                                    apreq_request_t *req)
 {
-    return apreq_env->request(env,req);
+    return env->module->request(env,req);
 }
 
-APREQ_DECLARE(const char *) apreq_env_query_string(void *env)
+APREQ_DECLARE(const char *) apreq_env_query_string(apreq_env_handle_t *env)
 {
-    return apreq_env->query_string(env);
+    return env->module->query_string(env);
 }
 
-APREQ_DECLARE(const char *) apreq_env_header_in(void *env, const char *name)
+APREQ_DECLARE(const char *) apreq_env_header_in(apreq_env_handle_t *env,
+                                                const char *name)
 {
-    return apreq_env->header_in(env, name);
+    return env->module->header_in(env, name);
 }
 
-APREQ_DECLARE(apr_status_t)apreq_env_header_out(void *env, 
+APREQ_DECLARE(apr_status_t)apreq_env_header_out(apreq_env_handle_t *env,
                                                 const char *name,
                                                 char *val)
 {
-    return apreq_env->header_out(env,name,val);
+    return env->module->header_out(env,name,val);
 }
 
-APREQ_DECLARE(apr_status_t) apreq_env_read(void *env,
+APREQ_DECLARE(apr_status_t) apreq_env_read(apreq_env_handle_t *env,
                                            apr_read_type_e block,
                                            apr_off_t bytes)
 {
-    return apreq_env->read(env,block,bytes);
+    return env->module->read(env,block,bytes);
 }
 
-APREQ_DECLARE(const char *) apreq_env_temp_dir(void *env, const char *path)
+APREQ_DECLARE(const char *) apreq_env_temp_dir(apreq_env_handle_t *env,
+                                               const char *path)
 {
     if (path != NULL)
         /* ensure path is a valid pointer during the entire request */
         path = apr_pstrdup(apreq_env_pool(env),path);
 
-    return apreq_env->temp_dir(env,path);
+    return env->module->temp_dir(env,path);
 }
 
-APREQ_DECLARE(apr_off_t) apreq_env_max_body(void *env, apr_off_t bytes)
+APREQ_DECLARE(apr_off_t) apreq_env_max_body(apreq_env_handle_t *env,
+                                            apr_off_t bytes)
 {
-    return apreq_env->max_body(env,bytes);
+    return env->module->max_body(env,bytes);
 }
 
-APREQ_DECLARE(apr_ssize_t) apreq_env_max_brigade(void *env, apr_ssize_t bytes)
+APREQ_DECLARE(apr_ssize_t) apreq_env_max_brigade(apreq_env_handle_t *env,
+                                                 apr_ssize_t bytes)
 {
-    return apreq_env->max_brigade(env,bytes);
+    return env->module->max_brigade(env,bytes);
 }
 
 /** @} */

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_env.h
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_env.h?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/src/apreq_env.h&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/src/apreq_env.h&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_env.h	(original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_env.h	Tue Jan 25 15:36:01 2005
@@ -83,14 +83,16 @@
 
 APREQ_DECLARE_NONSTD(void) apreq_log(const char *file, int line,
                                      int level, apr_status_t status,
-                                     void *env, const char *fmt, ...);
+                                     apreq_env_handle_t *env,
+                                     const char *fmt, ...);
+
 /**
  * Pool associated with the environment.
  * @param env The current environment
  * @return The associated pool.
  */
 
-APREQ_DECLARE(apr_pool_t *) apreq_env_pool(void *env);
+APREQ_DECLARE(apr_pool_t *) apreq_env_pool(apreq_env_handle_t *env);
 
 /**
  * Bucket allocator associated with the environment.
@@ -98,7 +100,7 @@
  * @return The associated bucket allocator.
  */
 
-APREQ_DECLARE(apr_bucket_alloc_t *) apreq_env_bucket_alloc(void *env);
+APREQ_DECLARE(apr_bucket_alloc_t *) apreq_env_bucket_alloc(apreq_env_handle_t *env);
 
 /**
  * Get/set the jar currently associated to the environment.
@@ -108,7 +110,8 @@
  * jar == NULL gets the current jar, which will remain associated
  * after the call.
  */
-APREQ_DECLARE(apreq_jar_t *) apreq_env_jar(void *env, apreq_jar_t *jar);
+APREQ_DECLARE(apreq_jar_t *) apreq_env_jar(apreq_env_handle_t *env,
+                                           apreq_jar_t *jar);
 
 /**
  * Get/set the request currently associated to the environment.
@@ -118,7 +121,7 @@
  * req == NULL gets the current request, which will remain associated
  * after the call.
  */
-APREQ_DECLARE(apreq_request_t *) apreq_env_request(void *env,
+APREQ_DECLARE(apreq_request_t *) apreq_env_request(apreq_env_handle_t *env,
                                                    apreq_request_t *req);
 
 /**
@@ -126,7 +129,7 @@
  * @param env The current environment.
  * @return The query string.
  */
-APREQ_DECLARE(const char *) apreq_env_query_string(void *env);
+APREQ_DECLARE(const char *) apreq_env_query_string(apreq_env_handle_t *env);
 
 /**
  * Fetch the header value (joined by ", " if there are multiple headers)
@@ -135,7 +138,8 @@
  * @param name The header name.
  * @return The value of the header, NULL if not found.
  */
-APREQ_DECLARE(const char *) apreq_env_header_in(void *env, const char *name);
+APREQ_DECLARE(const char *) apreq_env_header_in(apreq_env_handle_t *env,
+                                                const char *name);
 
 
 /**
@@ -167,7 +171,7 @@
  * @param val Value of the outgoing header.
  * @return APR_SUCCESS on success, error code otherwise.
  */
-APREQ_DECLARE(apr_status_t)apreq_env_header_out(void *env, 
+APREQ_DECLARE(apr_status_t)apreq_env_header_out(apreq_env_handle_t *env, 
                                                 const char *name,
                                                 char *val);
 
@@ -196,7 +200,7 @@
  *         APR_SUCCESS if everything was read & parsed successfully,
  *         error code otherwise.
  */
-APREQ_DECLARE(apr_status_t) apreq_env_read(void *env,
+APREQ_DECLARE(apr_status_t) apreq_env_read(apreq_env_handle_t *env,
                                            apr_read_type_e block,
                                            apr_off_t bytes);
 
@@ -208,7 +212,8 @@
  * path==NULL fetches the current directory without resetting it to NULL.
  */
 
-APREQ_DECLARE(const char *) apreq_env_temp_dir(void *env, const char *path);
+APREQ_DECLARE(const char *) apreq_env_temp_dir(apreq_env_handle_t *env,
+                                               const char *path);
 
 /**
  * Get/set the current max_body setting.  This is the maximum
@@ -220,7 +225,8 @@
  *
  */
 
-APREQ_DECLARE(apr_off_t) apreq_env_max_body(void *env, apr_off_t bytes);
+APREQ_DECLARE(apr_off_t) apreq_env_max_body(apreq_env_handle_t *env,
+                                            apr_off_t bytes);
 
 /**
  * Get/set the current max_brigade setting.  This is the maximum
@@ -232,7 +238,8 @@
  * bytes == -1 fetches the current max_brigade setting without modifying it.
  *
  */
-APREQ_DECLARE(apr_ssize_t) apreq_env_max_brigade(void *env, apr_ssize_t bytes);
+APREQ_DECLARE(apr_ssize_t) apreq_env_max_brigade(apreq_env_handle_t *env,
+                                                 apr_ssize_t bytes);
 
 /**
  * This must be fully defined for libapreq2 to operate properly 
@@ -244,18 +251,19 @@
 typedef struct apreq_env_module_t {
     const char *name;
     apr_uint32_t magic_number;
-    void (*log)(const char *,int,int,apr_status_t,void *,const char *,va_list);
-    apr_pool_t *(*pool)(void *);
-    apr_bucket_alloc_t *(*bucket_alloc)(void *);
-    apreq_jar_t *(*jar)(void *,apreq_jar_t *);
-    apreq_request_t *(*request)(void *,apreq_request_t *);
-    const char *(*query_string)(void *);
-    const char *(*header_in)(void *,const char *);
-    apr_status_t (*header_out)(void *, const char *,char *);
-    apr_status_t (*read)(void *,apr_read_type_e,apr_off_t);
-    const char *(*temp_dir)(void *, const char *);
-    apr_off_t (*max_body)(void *,apr_off_t);
-    apr_ssize_t (*max_brigade)(void *, apr_ssize_t);
+    void (*log)(const char *,int,int,apr_status_t,apreq_env_handle_t *,
+                const char *,va_list);
+    apr_pool_t *(*pool)(apreq_env_handle_t *);
+    apr_bucket_alloc_t *(*bucket_alloc)(apreq_env_handle_t *);
+    apreq_jar_t *(*jar)(apreq_env_handle_t *,apreq_jar_t *);
+    apreq_request_t *(*request)(apreq_env_handle_t *,apreq_request_t *);
+    const char *(*query_string)(apreq_env_handle_t *);
+    const char *(*header_in)(apreq_env_handle_t *,const char *);
+    apr_status_t (*header_out)(apreq_env_handle_t *, const char *,char *);
+    apr_status_t (*read)(apreq_env_handle_t *,apr_read_type_e,apr_off_t);
+    const char *(*temp_dir)(apreq_env_handle_t *, const char *);
+    apr_off_t (*max_body)(apreq_env_handle_t *,apr_off_t);
+    apr_ssize_t (*max_brigade)(apreq_env_handle_t *, apr_ssize_t);
 } apreq_env_module_t;
 
 /**
@@ -272,25 +280,29 @@
   pre##_request, pre##_query_string, pre##_header_in, pre##_header_out,     \
   pre##_read, pre##_temp_dir, pre##_max_body, pre##_max_brigade }
 
-
-/**
- * Get/set function for the active environment stucture. Usually this
- * is called only once per process, to define the correct environment.
- * @param mod  The new active environment.
- * @return The previous active environment.  Note: a call using
- * mod == NULL fetches the current environment module without modifying it.
- */
-APREQ_DECLARE(const apreq_env_module_t *) apreq_env_module(const apreq_env_module_t *mod);
-
 /**
- * The current environment's name.
+ * Create an apreq handle which is suitable for a CGI program. It
+ * reads input from stdin and writes output to stdout.
  */
-#define apreq_env_name (apreq_env_module(NULL)->name)
+APREQ_DECLARE(apreq_env_handle_t*) apreq_env_make_cgi(apr_pool_t *pool);
 
 /**
- * The current environment's magic (ie. version) number.
- */
-#define apreq_env_magic_number (apreq_env_module(NULL)->magic_number)
+ * Create a custom apreq handle which knows only some static
+ * values. Useful if you want to test the parser code or if you have
+ * got data from a custom source (neither Apache 2 nor CGI).
+ * @param pool the APR pool
+ * @param query_string the query string
+ * @param cookie value of the request "Cookie" header
+ * @param cookie2 value of the request "Cookie2" header
+ * @param content_type content type of the request body
+ * @param in a bucket brigade containing the request body
+ */
+APREQ_DECLARE(apreq_env_handle_t*) apreq_env_make_custom(apr_pool_t *pool,
+                                                         const char *query_string,
+                                                         const char *cookie,
+                                                         const char *cookie2,
+                                                         const char *content_type,
+                                                         apr_bucket_brigade *in);
 
 #ifdef __cplusplus
  }

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_env_cgi.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_env_cgi.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/src/apreq_env_cgi.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/src/apreq_env_cgi.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_env_cgi.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_env_cgi.c	Tue Jan 25 15:36:01 2005
@@ -20,9 +20,8 @@
 #include "apr_lib.h"
 #include "apr_env.h"
 
-#define dP apr_pool_t *p = (apr_pool_t *)env
-
-extern void apreq_parser_initialize(void);
+#define dP struct cgi_env *cgi_env = (struct cgi_env*)env; \
+    apr_pool_t *p = cgi_env->pool
 
 static struct {
     apreq_request_t    *req;
@@ -35,12 +34,17 @@
     apr_off_t           bytes_read;
 } ctx = {NULL, NULL, APR_SUCCESS, NULL, -1, APREQ_MAX_BRIGADE_LEN, NULL, 0};
 
+struct cgi_env {
+    struct apreq_env_handle_t env;
+    apr_pool_t *pool;
+};
+
 #define CRLF "\015\012"
 
 #define APREQ_ENV_STATUS(rc_run, k) do {                                \
          apr_status_t rc = rc_run;                                      \
          if (rc != APR_SUCCESS) {                                       \
-             apreq_log(APREQ_DEBUG APR_EGENERAL, p,                     \
+             apreq_log(APREQ_DEBUG APR_EGENERAL, env,                   \
                        "Lookup of %s failed: status=%d", k, rc);        \
          }                                                              \
      } while (0)
@@ -48,17 +52,21 @@
 #define APREQ_MODULE_NAME         "CGI"
 #define APREQ_MODULE_MAGIC_NUMBER 20041130
 
-static apr_pool_t *cgi_pool(void *env)
+static apr_pool_t *cgi_pool(apreq_env_handle_t *env)
 {
-    return (apr_pool_t *)env;
+    struct cgi_env *cgi_env = (struct cgi_env*)env;
+
+    return cgi_env->pool;
 }
 
-static apr_bucket_alloc_t *cgi_bucket_alloc(void *env)
+static apr_bucket_alloc_t *cgi_bucket_alloc(apreq_env_handle_t *env)
 {
-    return apr_bucket_alloc_create((apr_pool_t *)env);
+    struct cgi_env *cgi_env = (struct cgi_env*)env;
+
+    return apr_bucket_alloc_create(cgi_env->pool);
 }
 
-static const char *cgi_query_string(void *env)
+static const char *cgi_query_string(apreq_env_handle_t *env)
 {
     dP;
     char *value = NULL, qs[] = "QUERY_STRING";
@@ -66,7 +74,7 @@
     return value;
 }
 
-static const char *cgi_header_in(void *env,
+static const char *cgi_header_in(apreq_env_handle_t *env,
                                  const char *name)
 {
     dP;
@@ -90,21 +98,21 @@
     return value;
 }
 
-static apr_status_t cgi_header_out(void *env, const char *name,
+static apr_status_t cgi_header_out(apreq_env_handle_t *env, const char *name,
                                    char *value)
 {
     dP;
     apr_file_t *out;
     int bytes;
     apr_status_t s = apr_file_open_stdout(&out, p);
-    apreq_log(APREQ_DEBUG s, p, "Setting header: %s => %s", name, value);
+    apreq_log(APREQ_DEBUG s, env, "Setting header: %s => %s", name, value);
     bytes = apr_file_printf(out, "%s: %s" CRLF, name, value);
     apr_file_flush(out);
     return bytes > 0 ? APR_SUCCESS : APR_EGENERAL;
 }
 
 
-static apreq_jar_t *cgi_jar(void *env, apreq_jar_t *jar)
+static apreq_jar_t *cgi_jar(apreq_env_handle_t *env, apreq_jar_t *jar)
 {
     (void)env;
 
@@ -117,12 +125,11 @@
     return ctx.jar;
 }
 
-static apreq_request_t *cgi_request(void *env,
+static apreq_request_t *cgi_request(apreq_env_handle_t *env,
                                     apreq_request_t *req)
 {
     (void)env;
 
-    apreq_parser_initialize();
     if (req != NULL) {
         apreq_request_t *old_req = ctx.req;
         ctx.req = req;
@@ -151,8 +158,8 @@
 
 
 static void cgi_log(const char *file, int line, int level,
-                    apr_status_t status, void *env, const char *fmt,
-                    va_list vp)
+                    apr_status_t status, apreq_env_handle_t *env,
+                    const char *fmt, va_list vp)
 {
     dP;
     char buf[256];
@@ -196,7 +203,7 @@
 
 }
 
-static apr_status_t cgi_read(void *env,
+static apr_status_t cgi_read(apreq_env_handle_t *env,
                              apr_read_type_e block,
                              apr_off_t bytes)
 {
@@ -297,7 +304,7 @@
 }
 
 
-static const char *cgi_temp_dir(void *env, const char *path)
+static const char *cgi_temp_dir(apreq_env_handle_t *env, const char *path)
 {
     if (path != NULL) {
         dP;
@@ -315,7 +322,7 @@
 }
 
 
-static apr_off_t cgi_max_body(void *env, apr_off_t bytes)
+static apr_off_t cgi_max_body(apreq_env_handle_t *env, apr_off_t bytes)
 {
     (void)env;
 
@@ -328,7 +335,7 @@
 }
 
 
-static apr_ssize_t cgi_max_brigade(void *env, apr_ssize_t bytes)
+static apr_ssize_t cgi_max_brigade(apreq_env_handle_t *env, apr_ssize_t bytes)
 {
     (void)env;
 
@@ -342,3 +349,13 @@
 
 APREQ_ENV_MODULE(cgi, APREQ_MODULE_NAME,
                  APREQ_MODULE_MAGIC_NUMBER);
+
+APREQ_DECLARE(apreq_env_handle_t*) apreq_env_make_cgi(apr_pool_t *pool) {
+    struct cgi_env *handle;
+
+    handle = apr_pcalloc(pool, sizeof(*handle));
+    handle->env.module = &cgi_module;
+    handle->pool = pool;
+
+    return &handle->env;
+}

Added: httpd/apreq/branches/multi-env-unstable/src/apreq_env_custom.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_env_custom.c?view=auto&rev=126444
==============================================================================
--- (empty file)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_env_custom.c	Tue Jan 25 15:36:01 2005
@@ -0,0 +1,254 @@
+/*
+**  Copyright 2003-2004  The Apache Software Foundation
+**
+**  Licensed under the Apache License, Version 2.0 (the "License");
+**  you may not use this file except in compliance with the License.
+**  You may obtain a copy of the License at
+**
+**      http://www.apache.org/licenses/LICENSE-2.0
+**
+**  Unless required by applicable law or agreed to in writing, software
+**  distributed under the License is distributed on an "AS IS" BASIS,
+**  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+**  See the License for the specific language governing permissions and
+**  limitations under the License.
+*/
+
+#include <apr_strings.h>
+
+#include "apreq.h"
+#include "apreq_env.h"
+
+struct custom_handle {
+    struct apreq_env_handle_t env;
+    apr_pool_t *pool;
+    const char *query_string;
+    apreq_request_t *request;
+    const char *content_type;
+    const char *cookie_string, *cookie2_string;
+    apreq_jar_t *jar;
+    const char *temp_dir;
+    apr_off_t max_body;
+    apr_ssize_t max_brigade;
+
+    /* body state */
+    apr_status_t status;
+    apr_off_t bytes_read;
+    apr_bucket_brigade *in;
+};
+
+static apr_pool_t *custom_pool(apreq_env_handle_t *env) {
+    struct custom_handle *handle = (struct custom_handle*)env;
+
+    return handle->pool;
+}
+
+static apr_bucket_alloc_t *custom_bucket_alloc(apreq_env_handle_t *env)
+{
+    struct custom_handle *handle = (struct custom_handle*)env;
+
+    return apr_bucket_alloc_create(handle->pool);
+}
+
+static const char *custom_query_string(apreq_env_handle_t *env)
+{
+    struct custom_handle *handle = (struct custom_handle*)env;
+
+    return handle->query_string;
+}
+
+static const char *custom_header_in(apreq_env_handle_t *env,
+                                    const char *name)
+{
+    struct custom_handle *handle = (struct custom_handle*)env;
+
+    if (strcasecmp(name, "Content-Type") == 0)
+        return handle->content_type;
+    else if (strcasecmp(name, "Cookie") == 0)
+        return handle->cookie_string;
+    else if (strcasecmp(name, "Cookie2") == 0)
+        return handle->cookie2_string;
+    else
+        return NULL;
+}
+
+static apr_status_t custom_header_out(apreq_env_handle_t *env, const char *name,
+                                      char *value)
+{
+    (void)env;
+    (void)name;
+    (void)value;
+
+    return APR_SUCCESS;
+}
+
+static apreq_jar_t *custom_jar(apreq_env_handle_t *env, apreq_jar_t *jar)
+{
+    struct custom_handle *handle = (struct custom_handle*)env;
+    apreq_jar_t *value = handle->jar;
+
+    if (jar != NULL)
+        handle->jar = jar;
+
+    return value;
+}
+
+static apreq_request_t *custom_request(apreq_env_handle_t *env,
+                                       apreq_request_t *req)
+{
+    struct custom_handle *handle = (struct custom_handle*)env;
+    apreq_request_t *value = handle->request;
+
+    if (req != NULL)
+        handle->request = req;
+
+    return value;
+}
+
+static void custom_log(const char *file, int line, int level,
+                       apr_status_t status, apreq_env_handle_t *env,
+                       const char *fmt, va_list vp)
+{
+    (void)file;
+    (void)line;
+    (void)level;
+    (void)status;
+    (void)env;
+    (void)fmt;
+    (void)vp;
+}
+
+static apr_status_t custom_read(apreq_env_handle_t *env,
+                                apr_read_type_e block,
+                                apr_off_t bytes)
+{
+    struct custom_handle *handle = (struct custom_handle*)env;
+    apr_bucket *e;
+
+    (void)block;
+
+    if (handle->status != APR_INCOMPLETE)
+        return handle->status;
+
+    handle->status = apr_brigade_partition(handle->in, bytes, &e);
+    switch (handle->status) {
+        apr_bucket_brigade *bb;
+        apr_off_t len;
+        apreq_request_t *req;
+
+    case APR_SUCCESS:
+        bb = apr_brigade_split(handle->in, e);
+        req = apreq_request(env, NULL);
+        if (handle->max_body >= 0 &&
+            handle->bytes_read + bytes > handle->max_body) {
+            apreq_log(APREQ_ERROR APR_EGENERAL, env,
+                      "Bytes read (%" APR_OFF_T_FMT
+                      ") exceeds configured limit (%" APR_OFF_T_FMT ")",
+                      handle->bytes_read, handle->max_body);
+            req->body_status = APR_EGENERAL;
+            return handle->status = APR_EGENERAL;
+        }
+        handle->bytes_read += bytes;
+        handle->status = apreq_parse_request(req, handle->in);
+        apr_brigade_cleanup(handle->in);
+        APR_BRIGADE_CONCAT(handle->in, bb);
+        break;
+
+    case APR_INCOMPLETE:
+        bb = apr_brigade_split(handle->in, e);
+        handle->status = apr_brigade_length(handle->in,1,&len);
+        if (handle->status != APR_SUCCESS)
+            return handle->status;
+        req = apreq_request(env, NULL);
+        if (handle->max_body >= 0 &&
+            handle->bytes_read + len > handle->max_body) {
+            apreq_log(APREQ_ERROR APR_EGENERAL, env,
+                      "Bytes read (%" APR_OFF_T_FMT
+                      ") exceeds configured limit (%" APR_OFF_T_FMT ")",
+                      handle->bytes_read, handle->max_body);
+            req->body_status = APR_EGENERAL;
+            return handle->status = APR_EGENERAL;
+        }
+        handle->bytes_read += len;
+        handle->status = apreq_parse_request(req, handle->in);
+        apr_brigade_cleanup(handle->in);
+        APR_BRIGADE_CONCAT(handle->in, bb);
+        break;
+    }
+
+    return handle->status;
+}
+
+static const char *custom_temp_dir(apreq_env_handle_t *env, const char *path)
+{
+    struct custom_handle *handle = (struct custom_handle*)env;
+    const char *value = handle->temp_dir;
+
+    if (path != NULL)
+        handle->temp_dir = apr_pstrdup(handle->pool, path);
+
+    if (handle->temp_dir == NULL) {
+        apr_status_t status;
+
+        status = apr_temp_dir_get(&value, handle->pool);
+        if (status != APR_SUCCESS)
+            value = NULL;
+
+        handle->temp_dir = value;
+    }
+
+    return value;
+}
+
+static apr_off_t custom_max_body(apreq_env_handle_t *env, apr_off_t bytes)
+{
+    struct custom_handle *handle = (struct custom_handle*)env;
+    apr_off_t value = handle->max_body;
+
+    if (bytes >= 0)
+        handle->max_body = bytes;
+
+    return value;
+}
+
+static apr_ssize_t custom_max_brigade(apreq_env_handle_t *env, apr_ssize_t bytes)
+{
+    struct custom_handle *handle = (struct custom_handle*)env;
+    apr_off_t value = handle->max_brigade;
+
+    if (bytes >= 0)
+        handle->max_brigade = bytes;
+
+    return value;
+}
+
+static APREQ_ENV_MODULE(custom, "Custom", 20050110);
+
+APREQ_DECLARE(apreq_env_handle_t*) apreq_env_make_custom(apr_pool_t *pool,
+                                                         const char *query_string,
+                                                         const char *cookie,
+                                                         const char *cookie2,
+                                                         const char *content_type,
+                                                         apr_bucket_brigade *in) {
+    struct custom_handle *handle;
+
+    handle = apr_pcalloc(pool, sizeof(*handle));
+    handle->env.module = &custom_module;
+    handle->pool = pool;
+    handle->max_body = -1;
+    handle->max_brigade = -1;
+
+    if (query_string != NULL)
+        handle->query_string = apr_pstrdup(pool, query_string);
+    if (content_type != NULL)
+        handle->content_type = apr_pstrdup(pool, content_type);
+    if (cookie != NULL)
+        handle->cookie_string = apr_pstrdup(pool, cookie);
+    if (cookie2 != NULL)
+        handle->cookie2_string = apr_pstrdup(pool, cookie2);
+
+    handle->in = in;
+    handle->status = handle->in == NULL ? APR_ENOTIMPL : APR_INCOMPLETE;
+
+    return &handle->env;
+}

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_params.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_params.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/src/apreq_params.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/src/apreq_params.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_params.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_params.c	Tue Jan 25 15:36:01 2005
@@ -47,7 +47,8 @@
 }
 
 
-APREQ_DECLARE(apreq_request_t *) apreq_request(void *env, const char *qs)
+APREQ_DECLARE(apreq_request_t *) apreq_request(apreq_env_handle_t *env,
+                                               const char *qs)
 {
     apreq_request_t *req;
     apr_pool_t *p;

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_params.h
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_params.h?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/src/apreq_params.h&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/src/apreq_params.h&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_params.h	(original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_params.h	Tue Jan 25 15:36:01 2005
@@ -60,7 +60,7 @@
     apr_table_t        *args;         /**< parsed query-string */
     apr_table_t        *body;         /**< parsed post data */
     apreq_parser_t     *parser;       /**< active parser for this request */
-    void               *env;          /**< request environment */
+    apreq_env_handle_t *env;          /**< request environment */
     apr_status_t        args_status;  /**< status of query-string parse */
     apr_status_t        body_status;  /**< status of post data parse */
 } apreq_request_t;
@@ -82,7 +82,8 @@
  * the apreq_env_read function.
  */
 
-APREQ_DECLARE(apreq_request_t *)apreq_request(void *env, const char *qs);
+APREQ_DECLARE(apreq_request_t *)apreq_request(apreq_env_handle_t *env,
+                                              const char *qs);
 
 
 /**
@@ -219,13 +220,13 @@
 
 /** Parser arguments. */
 #define APREQ_PARSER_ARGS  apreq_parser_t *parser,     \
-                           void *env,                  \
+                           apreq_env_handle_t *env,        \
                            apr_table_t *t,             \
                            apr_bucket_brigade *bb
 
 /** Hook arguments */
 #define APREQ_HOOK_ARGS    apreq_hook_t *hook,         \
-                           void *env,                  \
+                           apreq_env_handle_t *env,        \
                            apreq_param_t *param,       \
                            apr_bucket_brigade *bb
 
@@ -298,7 +299,7 @@
  * @param in Brigade to append.
  * @return APR_SUCCESS on success, error code otherwise.
  */
-APREQ_DECLARE(apr_status_t) apreq_brigade_concat(void *env,
+APREQ_DECLARE(apr_status_t) apreq_brigade_concat(apreq_env_handle_t *env,
                                                  apr_bucket_brigade *out, 
                                                  apr_bucket_brigade *in);
 
@@ -398,7 +399,7 @@
  * @return The parser; NULL if the environment's
  * Content-Type is unrecognized.
  */
-APREQ_DECLARE(apreq_parser_t *)apreq_parser(void *env,
+APREQ_DECLARE(apreq_parser_t *)apreq_parser(apreq_env_handle_t *env,
                                             apreq_hook_t *hook);
 
 

Modified: httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/src/apreq_parsers.c	Tue Jan 25 15:36:01 2005
@@ -22,8 +22,6 @@
 #include "apr_xml.h"
 #include "apr_hash.h"
 
-void apreq_parser_initialize(void);
-
 #ifndef MAX
 #define MAX(A,B)  ( (A) > (B) ? (A) : (B) )
 #endif
@@ -89,7 +87,7 @@
 static apr_hash_t *default_parsers;
 static apr_pool_t *default_parser_pool;
 
-void apreq_parser_initialize(void)
+static void apreq_parser_initialize(void)
 {
     if (default_parsers != NULL)
         return;
@@ -116,14 +114,16 @@
 
 }
 
-APREQ_DECLARE(apreq_parser_t *)apreq_parser(void *env, apreq_hook_t *hook)
+APREQ_DECLARE(apreq_parser_t *)apreq_parser(apreq_env_handle_t *env, apreq_hook_t *hook)
 {
     apreq_parser_function_t *f;
     apr_pool_t *pool = apreq_env_pool(env);
     const char *type = apreq_env_content_type(env);
     apr_ssize_t tlen;
 
-    if (type == NULL || default_parsers == NULL)
+    apreq_parser_initialize();
+
+    if (type == NULL)
         return NULL;
 
     tlen = 0;
@@ -775,7 +775,7 @@
 
 #define MAX_FILE_BUCKET_LENGTH ((apr_off_t) 1 << (6 * sizeof(apr_size_t)))
 
-APREQ_DECLARE(apr_status_t) apreq_brigade_concat(void *env,
+APREQ_DECLARE(apr_status_t) apreq_brigade_concat(apreq_env_handle_t *env,
                                                  apr_bucket_brigade *out, 
                                                  apr_bucket_brigade *in)
 {
@@ -841,7 +841,7 @@
     return s;
 }
 
-static struct mfd_ctx *create_multipart_context(void *env,
+static struct mfd_ctx *create_multipart_context(apreq_env_handle_t *env,
                                                 char *enctype)
 {
     apr_status_t s;

Modified: httpd/apreq/branches/multi-env-unstable/t/cookie.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/cookie.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/t/cookie.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/t/cookie.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/cookie.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/t/cookie.c	Tue Jan 25 15:36:01 2005
@@ -24,7 +24,8 @@
 
 static void jar_make(CuTest *tc)
 {
-    j = apreq_jar(p,"a=1; foo=bar; fl=left; fr=right;bad; ns=foo=1&bar=2,"
+    j = apreq_jar(apreq_env_make_custom(p, NULL, NULL, NULL, NULL, NULL),
+                  "a=1; foo=bar; fl=left; fr=right;bad; ns=foo=1&bar=2,"
                   "frl=right-left; flr=left-right; fll=left-left; good_one=1;bad");
     CuAssertPtrNotNull(tc, j);
 }
@@ -114,9 +115,9 @@
     apreq_cookie_version_t v;
     char version[] = "$Version=\"1\"";
 
-    v = apreq_ua_cookie_version(NULL);
+    v = apreq_ua_cookie_version(apreq_env_make_custom(p, NULL, NULL, NULL, NULL, NULL));
     CuAssertIntEquals(tc, APREQ_COOKIE_VERSION_NETSCAPE, v);
-    v = apreq_ua_cookie_version(version);
+    v = apreq_ua_cookie_version(apreq_env_make_custom(p, NULL, NULL, version, NULL, NULL));
     CuAssertIntEquals(tc, APREQ_COOKIE_VERSION_RFC, v);
 
 }

Modified: httpd/apreq/branches/multi-env-unstable/t/params.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/params.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/t/params.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/t/params.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/params.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/t/params.c	Tue Jan 25 15:36:01 2005
@@ -24,7 +24,7 @@
 
 static void request_make(CuTest *tc)
 {
-    r = apreq_request(NULL,"a=1;quux=foo+bar&a=2&plus=%2B;uplus=%U002b;okie=dokie;novalue1;novalue2=");
+    r = apreq_request(apreq_env_make_custom(p, NULL, NULL, NULL, NULL, NULL), "a=1;quux=foo+bar&a=2&plus=%2B;uplus=%U002b;okie=dokie;novalue1;novalue2=");
     CuAssertPtrNotNull(tc, r);
     CuAssertIntEquals(tc,8, apr_table_elts(r->args)->nelts);
 }

Modified: httpd/apreq/branches/multi-env-unstable/t/parsers.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/parsers.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/t/parsers.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/t/parsers.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/parsers.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/t/parsers.c	Tue Jan 25 15:36:01 2005
@@ -106,23 +106,25 @@
     apreq_request_t *req;
     apreq_parser_t *parser;
 
-    req = apreq_request("application/x-www-form-urlencoded", "");
+    req = apreq_request(apreq_env_make_custom(p, NULL, NULL, NULL, "application/x-www-form-urlencoded", NULL), NULL);
     CuAssertPtrNotNull(tc, req);
     CuAssertStrEquals(tc, APREQ_URL_ENCTYPE, apreq_enctype(req->env));
     parser = apreq_parser(req->env, NULL);
     CuAssertPtrNotNull(tc, parser);
     CuAssertStrEquals(tc, APREQ_URL_ENCTYPE, parser->enctype);
 
-    req = apreq_request(APREQ_MFD_ENCTYPE
-                        "; charset=\"iso-8859-1\"; boundary=\"AaB03x\"" ,"");
+    req = apreq_request(apreq_env_make_custom(p, NULL, NULL, NULL, APREQ_MFD_ENCTYPE
+                                              "; charset=\"iso-8859-1\"; boundary=\"AaB03x\"",
+                                              NULL), NULL);
     CuAssertPtrNotNull(tc, req);
     parser = apreq_parser(req->env, NULL);
     CuAssertPtrNotNull(tc, parser);
     CuAssertStrNEquals(tc, APREQ_MFD_ENCTYPE, parser->enctype, 
                        strlen(APREQ_MFD_ENCTYPE));
 
-    req = apreq_request("multipart/related; boundary=f93dcbA3; "
-        "type=application/xml; start=\"<98...@example.com>\"","");
+    req = apreq_request(apreq_env_make_custom(p, NULL, NULL, NULL, "multipart/related; boundary=f93dcbA3; "
+                                              "type=application/xml; start=\"<98...@example.com>\"",
+                                              NULL), NULL);
     CuAssertPtrNotNull(tc, req);
     parser = apreq_parser(req->env, NULL);
     CuAssertPtrNotNull(tc, parser);
@@ -134,22 +136,27 @@
 static void parse_urlencoded(CuTest *tc)
 {
     const char *val;
-    apreq_request_t *req = apreq_request(APREQ_URL_ENCTYPE,"");
+    apreq_env_handle_t *env;
+    apreq_request_t *req;
     apr_status_t rv;
     const char *enctype;
     apr_bucket_brigade *bb;
+
+    bb = apr_brigade_create(p, apr_bucket_alloc_create(p));
+
+    env = apreq_env_make_custom(p, NULL, NULL, NULL, APREQ_URL_ENCTYPE, bb);
+    req = apreq_request(env, NULL);
+
     CuAssertPtrNotNull(tc, req);
 
     enctype = apreq_enctype(req->env);
     CuAssertStrEquals(tc, APREQ_URL_ENCTYPE, enctype);
 
-    bb = apr_brigade_create(p, apr_bucket_alloc_create(p));
-
     APR_BRIGADE_INSERT_HEAD(bb,
         apr_bucket_immortal_create(url_data,strlen(url_data), 
                                    bb->bucket_alloc));
 
-    rv = apreq_parse_request(req,bb);
+    rv = apreq_env_read(env, APR_BLOCK_READ, 65536);
     CuAssertIntEquals(tc, APR_INCOMPLETE, rv);
 
     APR_BRIGADE_INSERT_HEAD(bb,
@@ -158,10 +165,10 @@
     APR_BRIGADE_INSERT_TAIL(bb,
            apr_bucket_eos_create(bb->bucket_alloc));
 
-    rv = apreq_parse_request(req,bb);
-
+    rv = apreq_env_read(env, APR_BLOCK_READ, 65536);
     CuAssertIntEquals(tc, APR_SUCCESS, rv);
 
+    CuAssertPtrNotNull(tc, req->body);
     val = apr_table_get(req->body,"alpha");
 
     CuAssertStrEquals(tc, "one", val);
@@ -179,21 +186,15 @@
     apr_bucket_alloc_t *ba;
 
     for (j = 0; j <= strlen(form_data); ++j) {
-        const char *enctype;
         apr_bucket_brigade *bb;
-        apreq_request_t *req = apreq_request(APREQ_MFD_ENCTYPE
-                         "; charset=\"iso-8859-1\"; boundary=\"AaB03x\"" ,"");
-
-        CuAssertPtrNotNull(tc, req);
-        CuAssertStrEquals(tc, req->env, apreq_env_content_type(req->env));
-
-        enctype = apreq_enctype(req->env);
-        CuAssertStrEquals(tc, APREQ_MFD_ENCTYPE, enctype);
 
         ba = apr_bucket_alloc_create(p);
         bb = apr_brigade_create(p, ba);
 
         for (i = 0; i <= strlen(form_data); ++i) {
+            apreq_env_handle_t *env;
+            apreq_request_t *req;
+            apr_bucket_brigade *vb;
             const char *val;
             char *val2;
             apr_size_t len;
@@ -207,6 +208,13 @@
             APR_BRIGADE_INSERT_HEAD(bb, e);
             APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_eos_create(bb->bucket_alloc));
 
+            env = apreq_env_make_custom(p, NULL, NULL, NULL,
+                                        APREQ_MFD_ENCTYPE "; charset=\"iso-8859-1\"; boundary=\"AaB03x\"",
+                                        bb);
+            req = apreq_request(env, NULL);
+            CuAssertPtrNotNull(tc, req);
+            CuAssertStrEquals(tc, APREQ_MFD_ENCTYPE, apreq_enctype(req->env));
+
             /* Split e into three buckets */
             apr_bucket_split(e, j);
             f = APR_BUCKET_NEXT(e);
@@ -219,9 +227,10 @@
             req->body = NULL;
             req->parser = NULL;
             req->body_status = APR_EINIT;
-            rv = apreq_parse_request(req,bb);
+            rv = apreq_env_read(env, APR_BLOCK_READ, 65536);
             CuAssertIntEquals(tc, (j < strlen(form_data)) ? APR_INCOMPLETE : APR_SUCCESS, rv);
-            rv = apreq_parse_request(req, tail);
+            APR_BRIGADE_CONCAT(bb, tail);
+            rv = apreq_env_read(env, APR_BLOCK_READ, 65536);
             CuAssertIntEquals(tc, APR_SUCCESS, rv);
             CuAssertPtrNotNull(tc, req->body);
             CuAssertIntEquals(tc, 2, apr_table_elts(req->body)->nelts);
@@ -236,12 +245,13 @@
             val = apr_table_get(req->body, "pics");
             CuAssertStrEquals(tc, "file1.txt", val);
             t = apreq_value_to_param(apreq_strtoval(val))->info;
-            bb = apreq_value_to_param(apreq_strtoval(val))->bb;
-            apr_brigade_pflatten(bb, &val2, &len, p);
+            vb = apreq_value_to_param(apreq_strtoval(val))->bb;
+            apr_brigade_pflatten(vb, &val2, &len, p);
             CuAssertIntEquals(tc,strlen("... contents of file1.txt ..." CRLF), len);
             CuAssertStrNEquals(tc,"... contents of file1.txt ..." CRLF, val2, len);
             val = apr_table_get(t, "content-type");
             CuAssertStrEquals(tc, "text/plain", val);
+            apr_brigade_cleanup(vb);
             apr_brigade_cleanup(bb);
         }
         apr_bucket_alloc_destroy(ba);
@@ -254,8 +264,9 @@
     const char *val;
     apr_table_t *t;
     apr_status_t rv;
-    apreq_request_t *req = apreq_request(APREQ_MFD_ENCTYPE
-                         "; charset=\"iso-8859-1\"; boundary=\"AaB03x\"" ,"");
+    apreq_request_t *req = apreq_request(apreq_env_make_custom(p, NULL, NULL, NULL, APREQ_MFD_ENCTYPE
+                                                               "; charset=\"iso-8859-1\"; boundary=\"AaB03x\"",
+                                                               NULL), NULL);
     apr_bucket_brigade *bb = apr_brigade_create(p, 
                                    apr_bucket_alloc_create(p));
     apr_bucket *e = apr_bucket_immortal_create(form_data,
@@ -263,7 +274,8 @@
                                                    bb->bucket_alloc);
 
     CuAssertPtrNotNull(tc, req);
-    CuAssertStrEquals(tc, req->env, apreq_env_content_type(req->env));
+    CuAssertStrEquals(tc, APREQ_MFD_ENCTYPE
+                      "; charset=\"iso-8859-1\"; boundary=\"AaB03x\"", apreq_env_content_type(req->env));
 
     APR_BRIGADE_INSERT_HEAD(bb, e);
     APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_eos_create(bb->bucket_alloc));
@@ -293,8 +305,8 @@
     apr_size_t vlen;
     apr_status_t rv;
     apreq_param_t *dummy;
-    apreq_request_t *req = apreq_request(APREQ_XML_ENCTYPE, "");
-    apr_bucket_brigade *bb = apr_brigade_create(p, 
+    apreq_request_t *req = apreq_request(apreq_env_make_custom(p, NULL, NULL, NULL, APREQ_XML_ENCTYPE, NULL), NULL);
+    apr_bucket_brigade *bb = apr_brigade_create(p,
                                    apr_bucket_alloc_create(p));
     apr_bucket *e = apr_bucket_immortal_create(xml_data,
                                                    strlen(xml_data),
@@ -321,7 +333,7 @@
 {
     apr_status_t rv;
     apreq_param_t *dummy;
-    apreq_request_t *req = apreq_request(APREQ_XML_ENCTYPE, "");
+    apreq_request_t *req = apreq_request(apreq_env_make_custom(p, NULL, NULL, NULL, APREQ_XML_ENCTYPE, NULL), NULL);
     apr_bucket_brigade *bb = apr_brigade_create(p,
                                    apr_bucket_alloc_create(p));
     apr_bucket *e = apr_bucket_immortal_create(xml_data,
@@ -361,7 +373,7 @@
     apr_xml_doc *doc;
     apreq_hook_t *xml_hook;
     apreq_param_t *param;
-    apreq_request_t *req = apreq_request(ct, "");
+    apreq_request_t *req = apreq_request(apreq_env_make_custom(p, NULL, NULL, NULL, ct, NULL), NULL);
     apr_bucket_brigade *bb = apr_brigade_create(p, 
                                    apr_bucket_alloc_create(p));
     apr_bucket *e = apr_bucket_immortal_create(rel_data,
@@ -426,8 +438,9 @@
     apreq_param_t *param;
     const apr_array_header_t *arr;
     array_elt *elt;
-    apreq_request_t *req = apreq_request(APREQ_MFD_ENCTYPE
-                     "; charset=\"iso-8859-1\"; boundary=\"AaB03x\"" ,"");
+    apreq_request_t *req = apreq_request(apreq_env_make_custom(p, NULL, NULL, NULL, APREQ_MFD_ENCTYPE
+                                                               "; charset=\"iso-8859-1\"; boundary=\"AaB03x\"", NULL),
+                                         NULL);
     apr_bucket_brigade *bb = apr_brigade_create(p, 
                                    apr_bucket_alloc_create(p));
     apr_bucket *e = apr_bucket_immortal_create(mix_data,

Modified: httpd/apreq/branches/multi-env-unstable/t/testall.c
Url: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/testall.c?view=diff&rev=126444&p1=httpd/apreq/branches/multi-env-unstable/t/testall.c&r1=126443&p2=httpd/apreq/branches/multi-env-unstable/t/testall.c&r2=126444
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/testall.c	(original)
+++ httpd/apreq/branches/multi-env-unstable/t/testall.c	Tue Jan 25 15:36:01 2005
@@ -60,114 +60,6 @@
 
 apr_table_t *table;
 
-static apr_pool_t *test_pool(void *env)
-{
-    return p;
-}
-
-static apr_status_t bucket_alloc_cleanup(void *data)
-{
-    apr_bucket_alloc_t *ba = data;
-    apr_bucket_alloc_destroy(ba);
-    return APR_SUCCESS;
-}
-
-static apr_bucket_alloc_t *test_bucket_alloc(void *env)
-{
-    apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
-    apr_pool_cleanup_register(p, ba, bucket_alloc_cleanup, NULL);
-    return ba;
-}
-
-static const char *test_header_in(void *env, const char *name)
-{
-    return env;
-}
-
-static apr_status_t test_header_out(void *env, 
-                                    const char *name, 
-                                    char *value)
-{    
-    return printf("%s: %s" CRLF, name, value) > 0 ? APR_SUCCESS : APR_EGENERAL;
-}
-
-static const char *test_query_string(void *env)
-{
-    return env;
-}
-
-static apreq_jar_t *test_jar(void *env, apreq_jar_t *jar)
-{
-    return NULL;
-}
-
-static apreq_request_t *test_request(void *env, apreq_request_t *req)
-{
-    return NULL;
-}
-
-static void test_log(const char *file, int line, int level, 
-                     apr_status_t status, void *env, const char *fmt,
-                     va_list vp)
-{
-    char buf[256];
-    if (level < APREQ_LOG_ERR)
-        fprintf(stderr, "[%s(%d)]%s (%s)\n", file, line, apr_strerror(status,buf,255), apr_pvsprintf(p,fmt,vp));
-}
-
-static apr_status_t test_read(void *env, apr_read_type_e block, 
-                              apr_off_t bytes)
-{
-    return APR_ENOTIMPL;
-}
-
-static const char *test_temp_dir(void *env, const char *path)
-{
-    static const char *temp_dir;
-    if (path != NULL) {
-        const char *rv = temp_dir;
-        temp_dir = apr_pstrdup(p, path);
-        return rv;
-    }
-    if (temp_dir == NULL) {
-        if (apr_temp_dir_get(&temp_dir, p) != APR_SUCCESS)
-            temp_dir = NULL;
-    }
-
-    return temp_dir;
-}
-
-
-static apr_off_t test_max_body(void *env, apr_off_t bytes)
-{
-    static apr_off_t max_body = -1;
-    if (bytes >= 0) {
-        apr_off_t rv = max_body;
-        max_body = bytes;
-        return rv;
-    }
-    return max_body;
-}
-
-
-static apr_ssize_t test_max_brigade(void *env, apr_ssize_t bytes)
-{
-    static apr_ssize_t max_brigade = -1;
-
-    if (bytes >= 0) {
-        apr_ssize_t rv = max_brigade;
-        max_brigade = bytes;
-        return rv;
-    }
-    return max_brigade;
-}
-
-
-
-static APREQ_ENV_MODULE(test, APREQ_MODULE_NAME,
-                       APREQ_MODULE_MAGIC_NUMBER);
-
-
 int main(int argc, char *argv[])
 {
     CuSuiteList *alltests = NULL;
@@ -177,7 +69,6 @@
 
     apr_initialize();
     atexit(apr_terminate);
-    apreq_env_module(&test_module);
 
     CuInit(argc, argv);