httpd-apreq-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r155672 - in httpd/apreq/branches/multi-env-unstable: acinclude.m4 configure.ac module/Makefile.am module/apache/ module/apache/Makefile.am module/apache/apreq_module_apache.h module/apache/apreq_private_apache.h module/apache/command.c module/apache/handle.c module/apache2/Makefile.am
Date Mon, 28 Feb 2005 06:51:08 GMT
Author: joes
Date: Sun Feb 27 22:51:05 2005
New Revision: 155672

URL: http://svn.apache.org/viewcvs?view=rev&rev=155672
Log:
Add basic layout for experimental apache 1.3.x module.

Added:
    httpd/apreq/branches/multi-env-unstable/module/apache/   (with props)
    httpd/apreq/branches/multi-env-unstable/module/apache/Makefile.am
    httpd/apreq/branches/multi-env-unstable/module/apache/apreq_module_apache.h
    httpd/apreq/branches/multi-env-unstable/module/apache/apreq_private_apache.h
    httpd/apreq/branches/multi-env-unstable/module/apache/command.c
    httpd/apreq/branches/multi-env-unstable/module/apache/handle.c
Modified:
    httpd/apreq/branches/multi-env-unstable/acinclude.m4
    httpd/apreq/branches/multi-env-unstable/configure.ac
    httpd/apreq/branches/multi-env-unstable/module/Makefile.am
    httpd/apreq/branches/multi-env-unstable/module/apache2/Makefile.am

Modified: httpd/apreq/branches/multi-env-unstable/acinclude.m4
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/acinclude.m4?view=diff&r1=155671&r2=155672
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/acinclude.m4 (original)
+++ httpd/apreq/branches/multi-env-unstable/acinclude.m4 Sun Feb 27 22:51:05 2005
@@ -24,6 +24,9 @@
         AC_ARG_WITH(apu-config,
                 AC_HELP_STRING([  --with-apu-config],[path to apu-*-config script]),
                 [APU_CONFIG=$withval],[APU_CONFIG=""])
+        AC_ARG_WITH(apache1-apxs,
+                AC_HELP_STRING([--with-apache1-apxs],[path to apxs]),
+                [APACHE1_APXS=$withval],[APACHE1_APXS=""])
 
         prereq_check="$PERL build/version_check.pl"
 
@@ -131,6 +134,7 @@
         AM_CONDITIONAL(BUILD_HTTPD, test -n "$APACHE2_SRC")
         AM_CONDITIONAL(BUILD_APR, test "x$APR_CONFIG" = x`$APR_CONFIG --srcdir`/apr-config)
         AM_CONDITIONAL(BUILD_APU, test "x$APU_CONFIG" = x`$APU_CONFIG --srcdir`/apu-config)
+        AM_CONDITIONAL(HAVE_APACHE1, test -n "$APACHE1_APXS")
 
         dnl Reset the default installation prefix to be the same as apu's
         ac_default_prefix=`$APU_CONFIG --prefix`
@@ -157,32 +161,19 @@
         fi
 
         if test "x$USE_MAINTAINER_MODE" != "xno"; then
-            CPPFLAGS="$CPPFLAGS -Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
-Werror"
-            if test "$GCC" = "yes"; then
-                CPPFLAGS="$CPPFLAGS -Wwrite-strings -Wcast-qual -Wfloat-equal -Wshadow -Wpointer-arith
-Wbad-function-cast -Wsign-compare -Waggregate-return -Wmissing-noreturn -Wmissing-format-attribute
-Wpacked -Wredundant-decls -Wnested-externs -Wdisabled-optimization -Wno-long-long -Wendif-labels
-Wcast-align -Wpacked"
+            APR_ADDTO([CFLAGS],[
+                      -Werror -Wall -Wmissing-prototypes -Wstrict-prototypes
+                      -Wmissing-declarations -Wwrite-strings -Wcast-qual
+                      -Wfloat-equal -Wshadow -Wpointer-arith
+                      -Wbad-function-cast -Wsign-compare -Waggregate-return
+                      -Wmissing-noreturn -Wmissing-format-attribute -Wpacked
+                      -Wredundant-decls -Wnested-externs -Wdisabled-optimization
+                      -Wno-long-long -Wendif-labels -Wcast-align -Wpacked
+                      ])
                 # -Wdeclaration-after-statement is only supported on gcc 3.4+
-            fi
         fi
 
-        if test "x$CPPFLAGS" = "x"; then
-           echo "  setting CPPFLAGS to \"`$APR_CONFIG --cppflags`\""
-           CPPFLAGS="`$APR_CONFIG --cppflags`"
-        else
-           apr_addto_bugger="`$APR_CONFIG --cppflags`"
-           for i in $apr_addto_bugger; do
-             apr_addto_duplicate="0"
-             for j in $CPPFLAGS; do
-               if test "x$i" = "x$j"; then
-                 apr_addto_duplicate="1"
-                 break
-               fi
-             done
-             if test $apr_addto_duplicate = "0"; then
-               echo "  adding \"$i\" to CPPFLAGS"
-               CPPFLAGS="$CPPFLAGS $i"
-             fi
-           done
-        fi
+        APR_ADDTO([CPPFLAGS], "`$APR_CONFIG --cppflags`")
 
         get_version="$abs_srcdir/build/get-version.sh"
         version_hdr="$abs_srcdir/include/apreq_version.h"
@@ -221,6 +212,8 @@
         AC_SUBST(APACHE2_INCLUDES)
         AC_SUBST(APACHE2_HTTPD)
 
+        AC_SUBST(APACHE1_APXS)
+
         AC_SUBST(APU_CONFIG)
         AC_SUBST(APR_CONFIG)
         AC_SUBST(APR_INCLUDES)
@@ -284,4 +277,31 @@
 
   echo [$]0 [$]ac_configure_args '"[$]@"' >> $1
   chmod +x $1
+])dnl
+
+dnl
+dnl APR_ADDTO(variable, value)
+dnl
+dnl  Add value to variable
+dnl
+AC_DEFUN([APR_ADDTO],[
+  if test "x$$1" = "x"; then
+    echo "  setting $1 to \"$2\""
+    $1="$2"
+  else
+    apr_addto_bugger="$2"
+    for i in $apr_addto_bugger; do
+      apr_addto_duplicate="0"
+      for j in $$1; do
+        if test "x$i" = "x$j"; then
+          apr_addto_duplicate="1"
+          break
+        fi
+      done
+      if test $apr_addto_duplicate = "0"; then
+        echo "  adding \"$i\" to $1"
+        $1="$$1 $i"
+      fi
+    done
+  fi
 ])dnl

Modified: httpd/apreq/branches/multi-env-unstable/configure.ac
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/configure.ac?view=diff&r1=155671&r2=155672
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/configure.ac (original)
+++ httpd/apreq/branches/multi-env-unstable/configure.ac Sun Feb 27 22:51:05 2005
@@ -32,7 +32,7 @@
 dnl Checks for library functions.
 
 AC_APREQ
-AC_CONFIG_FILES([Makefile library/Makefile library/t/Makefile module/Makefile module/apache2/Makefile
glue/Makefile])
+AC_CONFIG_FILES([Makefile library/Makefile library/t/Makefile module/Makefile module/apache2/Makefile
module/apache/Makefile glue/Makefile])
 AC_CONFIG_FILES([build/doxygen.conf include/groups.dox])
 AC_CONFIG_FILES([apreq2-config], [chmod +x apreq2-config])
 AC_OUTPUT

Modified: httpd/apreq/branches/multi-env-unstable/module/Makefile.am
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/module/Makefile.am?view=diff&r1=155671&r2=155672
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/module/Makefile.am (original)
+++ httpd/apreq/branches/multi-env-unstable/module/Makefile.am Sun Feb 27 22:51:05 2005
@@ -1,5 +1,5 @@
 INCLUDES = -I../src @APACHE2_INCLUDES@ @APR_INCLUDES@ @APU_INCLUDES@
-SUBDIRS = apache2
+SUBDIRS = apache2 apache
 LIBS = ../library/lib@APREQ_LIBNAME@.la @APR_LTLIBS@ @APU_LTLIBS@
 LDFLAGS = @APR_LDFLAGS@ @APU_LDFLAGS@
 TEST_CONFIG_SCRIPT = package Apache::TestMM; filter_args(); generate_script("t/TEST")

Propchange: httpd/apreq/branches/multi-env-unstable/module/apache/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Feb 27 22:51:05 2005
@@ -0,0 +1,4 @@
+.deps
+.libs
+Makefile.in
+Makefile

Added: httpd/apreq/branches/multi-env-unstable/module/apache/Makefile.am
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/module/apache/Makefile.am?view=auto&rev=155672
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/module/apache/Makefile.am (added)
+++ httpd/apreq/branches/multi-env-unstable/module/apache/Makefile.am Sun Feb 27 22:51:05
2005
@@ -0,0 +1,23 @@
+if MAINTAINER_MODE
+APACHE1_INCLUDES = -isystem `@APACHE1_APXS@ -q INCLUDEDIR`
+else
+APACHE1_INCLUDES = -I `@APACHE1_APXS@ -q INCLUDEDIR`
+endif
+
+INCLUDES = $(APACHE1_INCLUDES) @APR_INCLUDES@ @APU_INCLUDES@
+LIBS = ../../library/lib@APREQ_LIBNAME@.la @APR_LTLIBS@ @APU_LTLIBS@
+LDFLAGS = @APR_LDFLAGS@ @APU_LDFLAGS@
+TEST_CONFIG_SCRIPT = package Apache::TestMM; filter_args(); generate_script("t/TEST")
+pkgincludedir = $(includedir)/@APREQ_LIBNAME@
+pkginclude_HEADERS = apreq_module_apache.h
+mod_apreq2_la_LDFLAGS = -export-dynamic -module -avoid-version -rpath `@APACHE1_APXS@ -q
LIBEXECDIR`
+
+if HAVE_APACHE1
+
+noinst_LTLIBRARIES = mod_apreq2.la
+mod_apreq2_la_SOURCES = apreq_private_apache.h handle.c command.c
+
+install-exec-local: mod_apreq2.la
+	$(LIBTOOL) --mode=install cp mod_apreq2.la `@APACHE1_APXS@ -q LIBEXECDIR`
+
+endif
\ No newline at end of file

Added: httpd/apreq/branches/multi-env-unstable/module/apache/apreq_module_apache.h
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/module/apache/apreq_module_apache.h?view=auto&rev=155672
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/module/apache/apreq_module_apache.h (added)
+++ httpd/apreq/branches/multi-env-unstable/module/apache/apreq_module_apache.h Sun Feb 27
22:51:05 2005
@@ -0,0 +1,43 @@
+/*
+**  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_APACHE_H
+#define APREQ_APACHE_H
+
+#include "apreq_module.h"
+#include <httpd.h>
+
+#ifdef  __cplusplus
+ extern "C" {
+#endif
+
+/**
+ * Create an apreq handle which communicates with an Apache 1.3.x
+ * request_rec.
+ */
+APREQ_DECLARE(apreq_handle_t*) apreq_handle_apache(request_rec *r);
+
+
+APREQ_DECLARE(apr_pool_t *) apreq_handle_apache_pool(apreq_handle_t *req);
+
+APREQ_DECLARE(apr_bucket_alloc_t *)
+    apreq_handle_apache_bucket_alloc(apreq_handle_t *req);
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif

Added: httpd/apreq/branches/multi-env-unstable/module/apache/apreq_private_apache.h
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/module/apache/apreq_private_apache.h?view=auto&rev=155672
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/module/apache/apreq_private_apache.h (added)
+++ httpd/apreq/branches/multi-env-unstable/module/apache/apreq_private_apache.h Sun Feb 27
22:51:05 2005
@@ -0,0 +1,11 @@
+#define CORE_PRIVATE
+#include "http_config.h"
+#undef CORE_PRIVATE
+
+extern module MODULE_VAR_EXPORT apreq_module;
+
+struct dir_config {
+    const char         *temp_dir;
+    apr_uint64_t        read_limit;
+    apr_size_t          brigade_limit;
+};

Added: httpd/apreq/branches/multi-env-unstable/module/apache/command.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/module/apache/command.c?view=auto&rev=155672
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/module/apache/command.c (added)
+++ httpd/apreq/branches/multi-env-unstable/module/apache/command.c Sun Feb 27 22:51:05 2005
@@ -0,0 +1,185 @@
+/*
+**  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_util.h"
+#include "apreq_module_apache.h"
+
+#include "httpd.h"
+#include "http_log.h"
+#include "http_request.h"
+
+#include "apreq_private_apache.h"
+
+/**
+ * <h2>Server Configuration Directives</h2>
+ *
+ * <TABLE class="qref"><CAPTION>Per-directory commands for mod_apreq</CAPTION>
+ * <TR><TH>Directive</TH><TH>Context</TH><TH>Default</TH><TH>Description</TH></TR>
+ * <TR class="odd"><TD>APREQ_ReadLimit</TD><TD>directory</TD><TD>-1
(Unlimited)</TD><TD>
+ * Maximum number of bytes mod_apreq will send off to libapreq for parsing.  
+ * mod_apreq will log this event and remove itself from the filter chain.
+ * The APR_EGENERAL error will be reported to libapreq2 users via the return 
+ * value of apreq_env_read().
+ * </TD></TR>
+ * <TR><TD>APREQ_BrigadeLimit</TD><TD>directory</TD><TD>
#APREQ_MAX_BRIGADE_LEN </TD><TD>
+ * Maximum number of bytes apreq will allow to accumulate
+ * within a brigade.  Excess data will be spooled to a
+ * file bucket appended to the brigade.
+ * </TD></TR>
+ * <TR class="odd"><TD>APREQ_TempDir</TD><TD>directory</TD><TD>NULL</TD><TD>
+ * Sets the location of the temporary directory apreq will use to spool
+ * overflow brigade data (based on the APREQ_BrigadeLimit setting).
+ * If left unset, libapreq2 will select a platform-specific location via apr_temp_dir_get().
+ * </TD></TR>
+ * </TABLE>
+ *
+ * <h2>Implementation Details</h2>
+ * <pre>
+ * XXX apreq as a normal input filter
+ * XXX apreq as a "virtual" content handler.
+ * XXX apreq as a transparent "tee".
+ * XXX apreq parser registration in post_config
+ * </pre>
+ * @{
+ */
+
+
+static void *apreq_create_dir_config(pool *p, char *d)
+{
+    /* d == OR_ALL */
+    struct dir_config *dc = ap_palloc(p, sizeof *dc);
+    dc->temp_dir      = NULL;
+    dc->read_limit    = (apr_uint64_t)-1;
+    dc->brigade_limit = APREQ_DEFAULT_BRIGADE_LIMIT;
+    return dc;
+}
+
+static void *apreq_merge_dir_config(pool *p, void *a_, void *b_)
+{
+    struct dir_config *a = a_, *b = b_, *c = ap_palloc(p, sizeof *c);
+
+    c->temp_dir      = (b->temp_dir != NULL)            /* overrides ok */
+                      ? b->temp_dir : a->temp_dir;
+
+    c->brigade_limit = (b->brigade_limit == (apr_size_t)-1) /* overrides ok */
+                      ? a->brigade_limit : b->brigade_limit;
+
+    c->read_limit    = (b->read_limit < a->read_limit)  /* why min? */
+                      ? b->read_limit : a->read_limit;
+
+    return c;
+}
+
+static const char *apreq_set_temp_dir(cmd_parms *cmd, void *data,
+                                      const char *arg)
+{
+    struct dir_config *conf = data;
+    const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
+
+    if (err != NULL)
+        return err;
+
+    conf->temp_dir = arg;
+    return NULL;
+}
+
+static const char *apreq_set_read_limit(cmd_parms *cmd, void *data,
+                                        const char *arg)
+{
+    struct dir_config *conf = data;
+    const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
+
+    if (err != NULL)
+        return err;
+
+    conf->read_limit = apreq_atoi64f(arg);
+    return NULL;
+}
+
+static const char *apreq_set_brigade_limit(cmd_parms *cmd, void *data,
+                                           const char *arg)
+{
+    struct dir_config *conf = data;
+    const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
+
+    if (err != NULL)
+        return err;
+
+    conf->brigade_limit = apreq_atoi64f(arg);
+    return NULL;
+}
+
+
+static const command_rec apreq_cmds[] =
+{
+    { "APREQ_TempDir", apreq_set_temp_dir, NULL, OR_ALL, TAKE1,
+      "Default location of temporary directory" },
+    { "APREQ_ReadLimit", apreq_set_read_limit, NULL, OR_ALL, TAKE1,
+      "Maximum amount of data that will be fed into a parser." },
+    { "APREQ_BrigadeLimit", apreq_set_brigade_limit, NULL, OR_ALL, TAKE1,
+      "Maximum in-memory bytes a brigade may use." },
+    { NULL }
+};
+
+static void apreq_cleanup(void *data)
+{
+    apr_pool_t *p = data;
+    apr_pool_destroy(p);
+    apr_terminate();
+}
+
+static void apreq_init (server_rec *s, pool *sp)
+{
+    /* APR_HOOK_FIRST because we want other modules to be able to
+       register parsers in their post_config hook */
+
+    apr_pool_t *p;
+    apr_initialize();
+    apr_pool_create(&p, NULL);
+    apreq_initialize(p);
+    ap_register_cleanup(sp, p, apreq_cleanup, apreq_cleanup);
+}
+
+
+
+/** @} */
+
+
+module MODULE_VAR_EXPORT apreq_module =
+{
+    STANDARD_MODULE_STUFF,
+    apreq_init,                /* module initializer                 */
+    apreq_create_dir_config,   /* per-directory config creator       */
+    apreq_merge_dir_config,    /* dir config merger                  */
+    NULL,                      /* server config creator              */
+    NULL,                      /* server config merger               */
+    apreq_cmds,                /* command table                      */
+    NULL,                      /* [9]  content handlers              */
+    NULL,                      /* [2]  URI-to-filename translation   */
+    NULL,                      /* [5]  check/validate user_id        */
+    NULL,                      /* [6]  check user_id is valid *here* */
+    NULL,                      /* [4]  check access by host address  */
+    NULL,                      /* [7]  MIME type checker/setter      */
+    NULL,                      /* [8]  fixups                        */
+    NULL,                      /* [10] logger                        */
+    NULL,                      /* [3]  header parser                 */
+    NULL,                      /* process initialization             */
+    NULL,                      /* process exit/cleanup               */
+    NULL                       /* [1]  post read_request handling    */
+};
+

Added: httpd/apreq/branches/multi-env-unstable/module/apache/handle.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/module/apache/handle.c?view=auto&rev=155672
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/module/apache/handle.c (added)
+++ httpd/apreq/branches/multi-env-unstable/module/apache/handle.c Sun Feb 27 22:51:05 2005
@@ -0,0 +1,526 @@
+/*
+**  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_module_apache.h"
+
+#include "http_main.h"
+#include "http_log.h"
+#include "http_protocol.h"
+#include "http_request.h"
+
+#include "apreq_private_apache.h"
+
+/* This is basically the cgi_handle struct with a request_rec */
+
+struct apache_handle {
+    struct apreq_handle_t        handle;
+    request_rec                 *r;
+    apr_pool_t                  *pool;
+    apr_bucket_alloc_t          *bucket_alloc;
+
+    apr_table_t                 *jar, *args, *body;
+    apr_status_t                 jar_status,
+                                 args_status,
+                                 body_status;
+
+    apreq_parser_t              *parser;
+    apreq_hook_t                *hook_queue;
+
+    const char                  *temp_dir;
+    apr_size_t                   brigade_limit;
+    apr_uint64_t                 read_limit;
+    apr_uint64_t                 bytes_read;
+    apr_bucket_brigade          *in;
+
+};
+
+static const char *apache_header_in(apreq_handle_t *env, const char *name)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    return ap_table_get(req->r->headers_in, name);
+}
+
+static apr_status_t apache_header_out(apreq_handle_t *env,
+                                       const char *name, char *value)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    ap_table_add(req->r->err_headers_out, name, value);
+    return APR_SUCCESS;
+}
+
+
+static apr_status_t ba_cleanup(void *data)
+{
+    apr_bucket_alloc_t *ba = data;
+    apr_bucket_alloc_destroy(ba);
+    return APR_SUCCESS;
+}
+
+
+static void init_body(apreq_handle_t *env)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    const char *cl_header = apache_header_in(env, "Content-Length");
+    apr_bucket_alloc_t *ba = req->bucket_alloc;
+    request_rec *r = req->r;
+
+    req->body  = apr_table_make(req->pool, APREQ_DEFAULT_NELTS);
+    apr_pool_cleanup_register(req->pool, ba, ba_cleanup, ba_cleanup);
+
+    if (cl_header != NULL) {
+        char *dummy;
+        apr_int64_t content_length = apr_strtoi64(cl_header, &dummy, 0);
+
+        if (dummy == NULL || *dummy != 0) {
+            req->body_status = APREQ_ERROR_BADHEADER;
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
+                          "Invalid Content-Length header (%s)", cl_header);
+            return;
+        }
+        else if ((apr_uint64_t)content_length > req->read_limit) {
+            req->body_status = APREQ_ERROR_OVERLIMIT;
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
+                          "Content-Length header (%s) exceeds configured "
+                          "max_body limit (%" APR_UINT64_T_FMT ")", 
+                          cl_header, req->read_limit);
+            return;
+        }
+    }
+
+    if (req->parser == NULL) {
+        const char *ct_header = apache_header_in(env, "Content-Type");
+
+        if (ct_header != NULL) {
+            apreq_parser_function_t pf = apreq_parser(ct_header);
+
+            if (pf != NULL) {
+                req->parser = apreq_parser_make(req->pool,
+                                                ba,
+                                                ct_header, 
+                                                pf,
+                                                req->brigade_limit,
+                                                req->temp_dir,
+                                                req->hook_queue,
+                                                NULL);
+            }
+            else {
+                req->body_status = APREQ_ERROR_NOPARSER;
+                return;
+            }
+        }
+        else {
+            req->body_status = APREQ_ERROR_NOHEADER;
+            return;
+        }
+    }
+    else {
+        if (req->parser->brigade_limit > req->brigade_limit)
+            req->parser->brigade_limit = req->brigade_limit;
+        if (req->temp_dir != NULL)
+            req->parser->temp_dir = req->temp_dir;
+        if (req->hook_queue != NULL)
+            apreq_parser_add_hook(req->parser, req->hook_queue);
+    }
+
+    req->hook_queue = NULL;
+    req->in         = apr_brigade_create(req->pool, ba);
+    req->body_status = APR_INCOMPLETE;
+
+}
+
+static apr_status_t apache_read(apreq_handle_t *env,
+                                apr_off_t bytes)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    request_rec *r = req->r;
+    apr_bucket *e;
+    long got = 0;
+    char buf[HUGE_STRING_LEN];
+    char tc[] = "[apreq] apache_read";
+    int want = sizeof buf;
+
+    if (req->body_status == APR_EINIT)
+        init_body(env);
+
+    if (req->body_status != APR_INCOMPLETE)
+        return req->body_status;
+
+    /* XXX want a loop here, instead of reducing bytes */
+
+    if (bytes > HUGE_STRING_LEN)
+        want = HUGE_STRING_LEN;
+    else
+        want = bytes;
+
+
+    ap_hard_timeout(tc, r);
+    got = ap_get_client_block(r, buf, want);
+    ap_kill_timeout(r);
+
+    if (got > 0) {
+        e = apr_bucket_transient_create(buf, got, req->bucket_alloc);
+        req->bytes_read += got;
+    }
+    else
+        e = apr_bucket_eos_create(req->bucket_alloc);
+
+    APR_BRIGADE_INSERT_TAIL(req->in, e);
+
+
+    if (req->bytes_read <= req->read_limit) {
+        req->body_status = apreq_parser_run(req->parser, req->body, req->in);
+        apr_brigade_cleanup(req->in);
+    }
+    else {
+        req->body_status = APREQ_ERROR_OVERLIMIT;
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, req->r,
+                      "Bytes read (%" APR_UINT64_T_FMT
+                      ") exceeds configured limit (%" APR_UINT64_T_FMT ")",
+                      req->bytes_read, req->read_limit);
+    }
+
+    return req->body_status;
+}
+
+
+
+
+
+
+static apr_status_t apache_jar(apreq_handle_t *env, const apr_table_t **t)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    request_rec *r = req->r;
+
+    if (req->jar_status == APR_EINIT) {
+        const char *cookies = ap_table_get(r->headers_in, "Cookie");
+        if (cookies != NULL) {
+            req->jar = apr_table_make(req->pool, APREQ_DEFAULT_NELTS);
+            req->jar_status = 
+                apreq_parse_cookie_header(req->pool, req->jar, cookies);
+        }
+        else
+            req->jar_status = APREQ_ERROR_NODATA;
+    }
+
+    *t = req->jar;
+    return req->jar_status;
+}
+
+static apr_status_t apache_args(apreq_handle_t *env, const apr_table_t **t)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    request_rec *r = req->r;
+
+    if (req->args_status == APR_EINIT) {
+        if (r->args != NULL) {
+            req->args = apr_table_make(req->pool, APREQ_DEFAULT_NELTS);
+            req->args_status = 
+                apreq_parse_query_string(req->pool, req->args, r->args);
+        }
+        else
+            req->args_status = APREQ_ERROR_NODATA;
+    }
+
+    *t = req->args;
+    return req->args_status;
+}
+
+
+
+
+static apreq_cookie_t *apache_jar_get(apreq_handle_t *env, const char *name)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    const apr_table_t *t;
+    const char *val;
+
+    if (req->jar_status == APR_EINIT)
+        apache_jar(env, &t);
+    else
+        t = req->jar;
+
+    if (t == NULL)
+        return NULL;
+
+    val = apr_table_get(t, name);
+    if (val == NULL)
+        return NULL;
+
+    return apreq_value_to_cookie(val);
+}
+
+static apreq_param_t *apache_args_get(apreq_handle_t *env, const char *name)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    const apr_table_t *t;
+    const char *val;
+
+    if (req->args_status == APR_EINIT)
+        apache_args(env, &t);
+    else
+        t = req->args;
+
+    if (t == NULL)
+        return NULL;
+
+    val = apr_table_get(t, name);
+    if (val == NULL)
+        return NULL;
+
+    return apreq_value_to_param(val);
+}
+
+
+static apr_status_t apache_body(apreq_handle_t *env, const apr_table_t **t)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+
+    switch (req->body_status) {
+
+    case APR_EINIT:
+        init_body(env);
+        if (req->body_status != APR_INCOMPLETE)
+            break;
+
+    case APR_INCOMPLETE:
+        while (apache_read(env, APREQ_DEFAULT_READ_BLOCK_SIZE) == APR_INCOMPLETE)
+            ;   /*loop*/
+    }
+
+    *t = req->body;
+    return req->body_status;
+}
+
+static apreq_param_t *apache_body_get(apreq_handle_t *env, const char *name)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    const char *val;
+
+    switch (req->body_status) {
+
+    case APR_EINIT:
+
+        init_body(env);
+        if (req->body_status != APR_INCOMPLETE)
+            return NULL;
+        apache_read(env, APREQ_DEFAULT_READ_BLOCK_SIZE);
+
+    case APR_INCOMPLETE:
+
+        val = apr_table_get(req->body, name);
+        if (val != NULL)
+            return apreq_value_to_param(val);
+
+        do {
+            /* riff on Duff's device */
+            apache_read(env, APREQ_DEFAULT_READ_BLOCK_SIZE);
+
+    default:
+
+            val = apr_table_get(req->body, name);
+            if (val != NULL)
+                return apreq_value_to_param(val);
+
+        } while (req->body_status == APR_INCOMPLETE);
+
+    }
+
+    return NULL;
+}
+
+static
+apr_status_t apache_parser_get(apreq_handle_t *env, 
+                                  const apreq_parser_t **parser)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    *parser = req->parser;
+    return APR_SUCCESS;
+}
+
+static
+apr_status_t apache_parser_set(apreq_handle_t *env, 
+                                apreq_parser_t *parser)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+
+    if (req->parser == NULL) {
+
+        if (req->hook_queue != NULL) {
+            apr_status_t s = apreq_parser_add_hook(parser, req->hook_queue);
+            if (s != APR_SUCCESS)
+                return s;
+        }
+        if (req->temp_dir != NULL) {
+            req->temp_dir = req->temp_dir;
+        }
+        if (req->brigade_limit < req->brigade_limit) {
+            req->brigade_limit = req->brigade_limit;
+        }
+
+        req->hook_queue = NULL;
+        req->parser = parser;
+        return APR_SUCCESS;
+    }
+    else
+        return APREQ_ERROR_MISMATCH;
+}
+
+static
+apr_status_t apache_hook_add(apreq_handle_t *env,
+                              apreq_hook_t *hook)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+
+    if (req->parser != NULL) {
+        return apreq_parser_add_hook(req->parser, hook);
+    }
+    else if (req->hook_queue != NULL) {
+        apreq_hook_t *h = req->hook_queue;
+        while (h->next != NULL)
+            h = h->next;
+        h->next = hook;
+    }
+    else {
+        req->hook_queue = hook;
+    }
+    return APR_SUCCESS;
+
+}
+
+static
+apr_status_t apache_brigade_limit_set(apreq_handle_t *env,
+                                       apr_size_t bytes)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    apr_size_t *limit = (req->parser == NULL) 
+                      ? &req->brigade_limit 
+                      : &req->parser->brigade_limit;
+
+    if (*limit > bytes) {
+        *limit = bytes;
+        return APR_SUCCESS;
+    }
+
+    return APREQ_ERROR_MISMATCH;
+}
+
+static
+apr_status_t apache_brigade_limit_get(apreq_handle_t *env,
+                                       apr_size_t *bytes)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    *bytes = (req->parser == NULL) 
+           ?  req->brigade_limit 
+           :  req->parser->brigade_limit;
+
+    return APR_SUCCESS;
+}
+
+static
+apr_status_t apache_read_limit_set(apreq_handle_t *env,
+                                    apr_uint64_t bytes)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    if (req->read_limit > bytes && req->bytes_read < bytes) {
+        req->read_limit = bytes;
+        return APR_SUCCESS;
+    }
+
+    return APREQ_ERROR_MISMATCH;
+}
+
+static
+apr_status_t apache_read_limit_get(apreq_handle_t *env,
+                                    apr_uint64_t *bytes)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+    *bytes = req->read_limit;
+    return APR_SUCCESS;
+}
+
+static
+apr_status_t apache_temp_dir_set(apreq_handle_t *env,
+                                  const char *path)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+
+    const char **curpath = (req->parser == NULL) 
+                         ? &req->temp_dir
+                         : &req->parser->temp_dir;
+
+    if (*curpath == NULL) {
+        *curpath = apr_pstrdup(req->pool, path);
+        return APR_SUCCESS;
+    }
+
+    return APREQ_ERROR_NOTEMPTY;
+}
+
+static
+apr_status_t apache_temp_dir_get(apreq_handle_t *env,
+                                  const char **path)
+{
+    struct apache_handle *req = (struct apache_handle *)env;
+
+    *path = req->parser ? req->parser->temp_dir : req->temp_dir;
+    return APR_SUCCESS;
+}
+
+static APREQ_MODULE(apache, 20050227);
+
+static void apreq_cleanup(void *data)
+{
+    struct apache_handle *req = data;
+    apr_pool_destroy(req->pool);
+}
+
+
+APREQ_DECLARE(apreq_handle_t *) apreq_handle_apache(request_rec *r)
+{
+    struct apache_handle *req =
+        ap_get_module_config(r->request_config, &apreq_module);
+    struct dir_config *d =
+        ap_get_module_config(r->per_dir_config, &apreq_module);
+
+    if (req != NULL)
+        return &req->handle;
+
+    apr_pool_create(&req->pool, NULL);
+    req = apr_pcalloc(req->pool, sizeof *req);
+    req->bucket_alloc = apr_bucket_alloc_create(req->pool);
+
+    req->handle.module = &apache_module;
+    req->r = r;
+
+    req->args_status = req->jar_status = req->body_status = APR_EINIT;
+    ap_register_cleanup(r->pool, req, apreq_cleanup, apreq_cleanup);
+
+    if (d == NULL) {
+        req->read_limit    = (apr_uint64_t)-1;
+        req->brigade_limit = APREQ_DEFAULT_BRIGADE_LIMIT;
+    }
+    else {
+        req->temp_dir      = d->temp_dir;
+        req->read_limit    = d->read_limit;
+        req->brigade_limit = d->brigade_limit;
+    }
+
+    ap_set_module_config(r->request_config, &apreq_module, req);
+
+    return &req->handle;
+}

Modified: httpd/apreq/branches/multi-env-unstable/module/apache2/Makefile.am
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/module/apache2/Makefile.am?view=diff&r1=155671&r2=155672
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/module/apache2/Makefile.am (original)
+++ httpd/apreq/branches/multi-env-unstable/module/apache2/Makefile.am Sun Feb 27 22:51:05
2005
@@ -30,6 +30,6 @@
 mod_apreq2_la_SOURCES = apreq_private_apache2.h handle.c filter.c
 
 install-exec-local: mod_apreq.la
-	@APACHE2_APXS@ -i -a -n apreq2 mod_apreq2.la
+	@APACHE2_APXS@ -i -a -n apreq mod_apreq2.la
 
 endif



Mime
View raw message