]> granicus.if.org Git - apache/blobdiff - server/config.c
event: child_main() never returns, so remove some dead code after
[apache] / server / config.c
index 1de993011919f7e0c8bfedbf2925a8b5a474db32..31def823c3eed71f987fdd2af4e522cd084f50c4 100644 (file)
@@ -1,59 +1,17 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
  *
- * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
- * reserved.
+ *     http://www.apache.org/licenses/LICENSE-2.0
  *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- *    if any, must include the following acknowledgment:
- *       "This product includes software developed by the
- *        Apache Software Foundation (http://www.apache.org/)."
- *    Alternately, this acknowledgment may appear in the software itself,
- *    if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- *    not be used to endorse or promote products derived from this
- *    software without prior written permission. For written
- *    permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- *    nor may "Apache" appear in their name, without prior written
- *    permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- * Portions of this software are based upon public domain software
- * originally written at the National Center for Supercomputing Applications,
- * University of Illinois, Urbana-Champaign.
+ * 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 "apr_portable.h"
 #include "apr_file_io.h"
+#include "apr_fnmatch.h"
 
 #define APR_WANT_STDIO
 #define APR_WANT_STRFUNC
 #include "apr_want.h"
 
-#define CORE_PRIVATE
-
 #include "ap_config.h"
 #include "httpd.h"
 #include "http_config.h"
 #include "http_protocol.h"
 #include "http_core.h"
-#include "http_log.h"          /* for errors in parse_htaccess */
-#include "http_request.h"      /* for default_handler (see invoke_handler) */
+#include "http_log.h"      /* for errors in parse_htaccess */
+#include "http_request.h"  /* for default_handler (see invoke_handler) */
 #include "http_main.h"
 #include "http_vhost.h"
 #include "util_cfgtree.h"
-#include "mpm.h"
+#include "mpm_common.h"
 
+#define APLOG_UNSET   (APLOG_NO_MODULE - 1)
+APLOG_USE_MODULE(core);
 
 AP_DECLARE_DATA const char *ap_server_argv0 = NULL;
-
 AP_DECLARE_DATA const char *ap_server_root = NULL;
+AP_DECLARE_DATA server_rec *ap_server_conf = NULL;
+AP_DECLARE_DATA apr_pool_t *ap_pglobal = NULL;
 
 AP_DECLARE_DATA apr_array_header_t *ap_server_pre_read_config = NULL;
 AP_DECLARE_DATA apr_array_header_t *ap_server_post_read_config = NULL;
@@ -108,12 +68,14 @@ AP_DECLARE_DATA ap_directive_t *ap_conftree = NULL;
 APR_HOOK_STRUCT(
            APR_HOOK_LINK(header_parser)
            APR_HOOK_LINK(pre_config)
+           APR_HOOK_LINK(check_config)
            APR_HOOK_LINK(post_config)
            APR_HOOK_LINK(open_logs)
            APR_HOOK_LINK(child_init)
            APR_HOOK_LINK(handler)
            APR_HOOK_LINK(quick_handler)
            APR_HOOK_LINK(optional_fn_retrieve)
+           APR_HOOK_LINK(test_config)
 )
 
 AP_IMPLEMENT_HOOK_RUN_ALL(int, header_parser,
@@ -124,6 +86,15 @@ AP_IMPLEMENT_HOOK_RUN_ALL(int, pre_config,
                            apr_pool_t *ptemp),
                           (pconf, plog, ptemp), OK, DECLINED)
 
+AP_IMPLEMENT_HOOK_RUN_ALL(int, check_config,
+                          (apr_pool_t *pconf, apr_pool_t *plog,
+                           apr_pool_t *ptemp, server_rec *s),
+                          (pconf, plog, ptemp, s), OK, DECLINED)
+
+AP_IMPLEMENT_HOOK_VOID(test_config,
+                       (apr_pool_t *pconf, server_rec *s),
+                       (pconf, s))
+
 AP_IMPLEMENT_HOOK_RUN_ALL(int, post_config,
                           (apr_pool_t *pconf, apr_pool_t *plog,
                            apr_pool_t *ptemp, server_rec *s),
@@ -144,7 +115,7 @@ AP_DECLARE(int) ap_hook_post_config(ap_HOOK_post_config_t *pf,
     ap_LINK_post_config_t *pHook;
 
     if (!_hooks.link_post_config) {
-        _hooks.link_post_config = apr_array_make(apr_global_hook_pool, 1,
+        _hooks.link_post_config = apr_array_make(apr_hook_global_pool, 1,
                                                  sizeof(ap_LINK_post_config_t));
         apr_hook_sort_register("post_config", &_hooks.link_post_config);
     }
@@ -154,10 +125,10 @@ AP_DECLARE(int) ap_hook_post_config(ap_HOOK_post_config_t *pf,
     pHook->aszPredecessors = aszPre;
     pHook->aszSuccessors = aszSucc;
     pHook->nOrder = nOrder;
-    pHook->szName = apr_current_hooking_module;
+    pHook->szName = apr_hook_debug_current;
 
-    if (apr_debug_module_hooks)
-        apr_show_hook("post_config", aszPre, aszSucc);
+    if (apr_hook_debug_enabled)
+        apr_hook_debug_show("post_config", aszPre, aszSucc);
 }
 
 AP_DECLARE(apr_array_header_t *) ap_hook_get_post_config(void) {
@@ -215,13 +186,43 @@ static int total_modules = 0;
  */
 static int dynamic_modules = 0;
 
+/* The maximum possible value for total_modules, i.e. number of static
+ * modules plus DYNAMIC_MODULE_LIMIT.
+ */
+static int max_modules = 0;
+
+/* The number of elements we need to alloc for config vectors. Before loading
+ * of dynamic modules, we must be liberal and set this to max_modules. After
+ * loading of dynamic modules, we can trim it down to total_modules. On
+ * restart, reset to max_modules.
+ */
+static int conf_vector_length = 0;
+
 AP_DECLARE_DATA module *ap_top_module = NULL;
 AP_DECLARE_DATA module **ap_loaded_modules=NULL;
 
+static apr_hash_t *ap_config_hash = NULL;
+
+/* a list of the module symbol names with the trailing "_module"removed */
+static char **ap_module_short_names = NULL;
+
 typedef int (*handler_func)(request_rec *);
 typedef void *(*dir_maker_func)(apr_pool_t *, char *);
 typedef void *(*merger_func)(apr_pool_t *, void *, void *);
 
+/* A list of the merge_dir_config functions of all loaded modules, sorted
+ * by module_index.
+ * Using this list in ap_merge_per_dir_configs() is faster than following
+ * the module->next linked list because of better memory locality (resulting
+ * in better cache usage).
+ */
+static merger_func *merger_func_cache;
+
+/* maximum nesting level for config directories */
+#ifndef AP_MAX_INCLUDE_DIR_DEPTH
+#define AP_MAX_INCLUDE_DIR_DEPTH (128)
+#endif
+
 /* Dealing with config vectors.  These are associated with per-directory,
  * per-server, and per-request configuration, and have a void* pointer for
  * each modules.  The nature of the structure pointed to is private to the
@@ -235,15 +236,13 @@ typedef void *(*merger_func)(apr_pool_t *, void *, void *);
 
 static ap_conf_vector_t *create_empty_config(apr_pool_t *p)
 {
-    void *conf_vector = apr_pcalloc(p, sizeof(void *) *
-                                    (total_modules + DYNAMIC_MODULE_LIMIT));
+    void *conf_vector = apr_pcalloc(p, sizeof(void *) * conf_vector_length);
     return conf_vector;
 }
 
 static ap_conf_vector_t *create_default_per_dir_config(apr_pool_t *p)
 {
-    void **conf_vector = apr_pcalloc(p, sizeof(void *) *
-                                     (total_modules + DYNAMIC_MODULE_LIMIT));
+    void **conf_vector = apr_pcalloc(p, sizeof(void *) * conf_vector_length);
     module *modp;
 
     for (modp = ap_top_module; modp; modp = modp->next) {
@@ -260,19 +259,17 @@ AP_CORE_DECLARE(ap_conf_vector_t *) ap_merge_per_dir_configs(apr_pool_t *p,
                                            ap_conf_vector_t *base,
                                            ap_conf_vector_t *new_conf)
 {
-    void **conf_vector = apr_palloc(p, sizeof(void *) * total_modules);
+    void **conf_vector = apr_palloc(p, sizeof(void *) * conf_vector_length);
     void **base_vector = (void **)base;
     void **new_vector = (void **)new_conf;
-    module *modp;
-
-    for (modp = ap_top_module; modp; modp = modp->next) {
-        int i = modp->module_index;
+    int i;
 
+    for (i = 0; i < total_modules; i++) {
         if (!new_vector[i]) {
             conf_vector[i] = base_vector[i];
         }
         else {
-            merger_func df = modp->merge_dir_config;
+            const merger_func df = merger_func_cache[i];
             if (df && base_vector[i]) {
                 conf_vector[i] = (*df)(p, base_vector[i], new_vector[i]);
             }
@@ -286,8 +283,7 @@ AP_CORE_DECLARE(ap_conf_vector_t *) ap_merge_per_dir_configs(apr_pool_t *p,
 
 static ap_conf_vector_t *create_server_config(apr_pool_t *p, server_rec *s)
 {
-    void **conf_vector = apr_pcalloc(p, sizeof(void *) *
-                                     (total_modules + DYNAMIC_MODULE_LIMIT));
+    void **conf_vector = apr_pcalloc(p, sizeof(void *) * conf_vector_length);
     module *modp;
 
     for (modp = ap_top_module; modp; modp = modp->next) {
@@ -335,26 +331,37 @@ AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_per_dir_config(apr_pool_t *p)
     return create_empty_config(p);
 }
 
-static int ap_invoke_filter_init(ap_filter_t *filters)
+/* Invoke the filter_init_func for all filters with FILTERS where f->r
+ * matches R.  Restricting to a matching R avoids re-running init
+ * functions for filters configured for r->main where r is a
+ * subrequest.  */
+static int invoke_filter_init(request_rec *r, ap_filter_t *filters)
 {
     while (filters) {
-        if (filters->frec->filter_init_func) {
+        if (filters->frec->filter_init_func && filters->r == r) {
             int result = filters->frec->filter_init_func(filters);
             if (result != OK) {
                 return result;
             }
         }
         filters = filters->next;
-    } 
+    }
     return OK;
 }
 
+/*
+ * TODO: Move this to an appropriate include file and possibly prefix it
+ * with AP_.
+ */
+#define DEFAULT_HANDLER_NAME ""
+
 AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r)
 {
     const char *handler;
     const char *p;
     int result;
     const char *old_handler = r->handler;
+    const char *ignore;
 
     /*
      * The new insert_filter stage makes the most sense here.  We only use
@@ -370,28 +377,33 @@ AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r)
      * run their init function to let them do any magic before we could
      * start generating data.
      */
-    result = ap_invoke_filter_init(r->input_filters);
+    result = invoke_filter_init(r, r->input_filters);
     if (result != OK) {
         return result;
     }
-    result = ap_invoke_filter_init(r->output_filters);
+    result = invoke_filter_init(r, r->output_filters);
     if (result != OK) {
         return result;
     }
 
     if (!r->handler) {
-        handler = r->content_type ? r->content_type : ap_default_type(r);
-        if ((p=ap_strchr_c(handler, ';')) != NULL) {
-            char *new_handler = (char *)apr_pmemdup(r->pool, handler,
-                                                    p - handler + 1);
-            char *p2 = new_handler + (p - handler);
-            handler = new_handler;
-
-            /* MIME type arguments */
-            while (p2 > handler && p2[-1] == ' ')
-                --p2; /* strip trailing spaces */
-
-            *p2='\0';
+        if (r->content_type) {
+            handler = r->content_type;
+            if ((p=ap_strchr_c(handler, ';')) != NULL) {
+                char *new_handler = (char *)apr_pmemdup(r->pool, handler,
+                                                        p - handler + 1);
+                char *p2 = new_handler + (p - handler);
+                handler = new_handler;
+
+                /* exclude media type arguments */
+                while (p2 > handler && p2[-1] == ' ')
+                    --p2; /* strip trailing spaces */
+
+                *p2='\0';
+            }
+        }
+        else {
+            handler = DEFAULT_HANDLER_NAME;
         }
 
         r->handler = handler;
@@ -405,6 +417,23 @@ AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r)
         ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
             "handler \"%s\" not found for: %s", r->handler, r->filename);
     }
+    if ((result != OK) && (result != DONE) && (result != DECLINED) && (result != SUSPENDED)
+        && (result != AP_FILTER_ERROR) /* ap_die() knows about this specifically */
+        && !ap_is_HTTP_VALID_RESPONSE(result)) {
+        /* If a module is deliberately returning something else
+         * (request_rec in non-HTTP or proprietary extension?)
+         * let it set a note to allow it explicitly.
+         * Otherwise, a return code that is neither reserved nor HTTP
+         * is a bug, as in PR#31759.
+         */
+        ignore = apr_table_get(r->notes, "HTTP_IGNORE_RANGE");
+        if (!ignore) {
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+                          "Handler for %s returned invalid result code %d",
+                          r->handler, result);
+            result = HTTP_INTERNAL_SERVER_ERROR;
+        }
+    }
 
     return result == DECLINED ? HTTP_INTERNAL_SERVER_ERROR : result;
 }
@@ -431,30 +460,85 @@ AP_DECLARE(void) ap_register_hooks(module *m, apr_pool_t *p)
     if (m->register_hooks) {
         if (getenv("SHOW_HOOKS")) {
             printf("Registering hooks for %s\n", m->name);
-            apr_debug_module_hooks = 1;
+            apr_hook_debug_enabled = 1;
         }
 
-        apr_current_hooking_module = m->name;
+        apr_hook_debug_current = m->name;
         m->register_hooks(p);
     }
 }
 
+static void ap_add_module_commands(module *m, apr_pool_t *p);
+
+typedef struct ap_mod_list_struct ap_mod_list;
+struct ap_mod_list_struct {
+    struct ap_mod_list_struct *next;
+    module *m;
+    const command_rec *cmd;
+};
+
+static void rebuild_conf_hash(apr_pool_t *p, int add_prelinked)
+{
+    module **m;
+
+    ap_config_hash = apr_hash_make(p);
+
+    apr_pool_cleanup_register(p, &ap_config_hash, ap_pool_cleanup_set_null,
+                              apr_pool_cleanup_null);
+    if (add_prelinked) {
+        for (m = ap_prelinked_modules; *m != NULL; m++) {
+            ap_add_module_commands(*m, p);
+        }
+    }
+}
+
+static void ap_add_module_commands(module *m, apr_pool_t *p)
+{
+    apr_pool_t *tpool;
+    ap_mod_list *mln;
+    const command_rec *cmd;
+    char *dir;
+
+    cmd = m->cmds;
+
+    if (ap_config_hash == NULL) {
+        rebuild_conf_hash(p, 0);
+    }
+
+    tpool = apr_hash_pool_get(ap_config_hash);
+
+    while (cmd && cmd->name) {
+        mln = apr_palloc(tpool, sizeof(ap_mod_list));
+        mln->cmd = cmd;
+        mln->m = m;
+        dir = apr_pstrdup(tpool, cmd->name);
+
+        ap_str_tolower(dir);
+
+        mln->next = apr_hash_get(ap_config_hash, dir, APR_HASH_KEY_STRING);
+        apr_hash_set(ap_config_hash, dir, APR_HASH_KEY_STRING, mln);
+        ++cmd;
+    }
+}
+
+
 /* One-time setup for precompiled modules --- NOT to be done on restart */
 
-AP_DECLARE(void) ap_add_module(module *m, apr_pool_t *p)
+AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p,
+                                       const char *sym_name)
 {
-    /* This could be called from an AddModule httpd.conf command,
+    ap_module_symbol_t *sym = ap_prelinked_module_symbols;
+
+    /* This could be called from a LoadModule httpd.conf command,
      * after the file has been linked and the module structure within it
      * teased out...
      */
 
     if (m->version != MODULE_MAGIC_NUMBER_MAJOR) {
-        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
-                     "%s: module \"%s\" is not compatible with this "
-                     "version of Apache.", ap_server_argv0, m->name);
-        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
-                     "Please contact the vendor for the correct version.");
-        exit(1);
+        return apr_psprintf(p, "Module \"%s\" is not compatible with this "
+                            "version of Apache (found %d, need %d). Please "
+                            "contact the vendor for the correct version.",
+                            m->name, m->version, MODULE_MAGIC_NUMBER_MAJOR);
     }
 
     if (m->next == NULL) {
@@ -467,16 +551,36 @@ AP_DECLARE(void) ap_add_module(module *m, apr_pool_t *p)
         dynamic_modules++;
 
         if (dynamic_modules > DYNAMIC_MODULE_LIMIT) {
-            ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
-                         "%s: module \"%s\" could not be loaded, because"
-                         " the dynamic", ap_server_argv0, m->name);
-            ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
-                         "module limit was reached. Please increase "
-                         "DYNAMIC_MODULE_LIMIT and recompile.");
-            exit(1);
+            return apr_psprintf(p, "Module \"%s\" could not be loaded, "
+                                "because the dynamic module limit was "
+                                "reached. Please increase "
+                                "DYNAMIC_MODULE_LIMIT and recompile.", m->name);
+        }
+
+    }
+    else if (!sym_name) {
+        while (sym->modp != NULL) {
+            if (sym->modp == m) {
+                sym_name = sym->name;
+                break;
+            }
+            sym++;
         }
     }
 
+    if (sym_name) {
+        int len = strlen(sym_name);
+        int slen = strlen("_module");
+        if (len > slen && !strcmp(sym_name + len - slen, "_module")) {
+            len -= slen;
+        }
+
+        ap_module_short_names[m->module_index] = strdup(sym_name);
+        ap_module_short_names[m->module_index][len] = '\0';
+        merger_func_cache[m->module_index] = m->merge_dir_config;
+    }
+
+
     /* Some C compilers put a complete path into __FILE__, but we want
      * only the filename (e.g. mod_includes.c). So check for path
      * components (Unix and DOS), and remove them.
@@ -501,10 +605,13 @@ AP_DECLARE(void) ap_add_module(module *m, apr_pool_t *p)
     }
 #endif /*_OSD_POSIX*/
 
+    ap_add_module_commands(m, p);
     /*  FIXME: is this the right place to call this?
      *  It doesn't appear to be
      */
     ap_register_hooks(m, p);
+
+    return NULL;
 }
 
 /*
@@ -546,20 +653,29 @@ AP_DECLARE(void) ap_remove_module(module *m)
         modp->next = modp->next->next;
     }
 
+    free(ap_module_short_names[m->module_index]);
+    ap_module_short_names[m->module_index] = NULL;
+    merger_func_cache[m->module_index] = NULL;
+
     m->module_index = -1; /* simulate being unloaded, should
                            * be unnecessary */
     dynamic_modules--;
     total_modules--;
 }
 
-AP_DECLARE(void) ap_add_loaded_module(module *mod, apr_pool_t *p)
+AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p,
+                                              const char *short_name)
 {
     module **m;
+    const char *error;
 
     /*
      *  Add module pointer to top of chained module list
      */
-    ap_add_module(mod, p);
+    error = ap_add_module(mod, p, short_name);
+    if (error) {
+        return error;
+    }
 
     /*
      *  And module pointer to list of loaded modules
@@ -573,6 +689,8 @@ AP_DECLARE(void) ap_add_loaded_module(module *mod, apr_pool_t *p)
         ;
     *m++ = mod;
     *m = NULL;
+
+    return NULL;
 }
 
 AP_DECLARE(void) ap_remove_loaded_module(module *mod)
@@ -605,12 +723,15 @@ AP_DECLARE(void) ap_remove_loaded_module(module *mod)
     *m = NULL;
 }
 
-AP_DECLARE(void) ap_setup_prelinked_modules(process_rec *process)
+AP_DECLARE(const char *) ap_setup_prelinked_modules(process_rec *process)
 {
     module **m;
     module **m2;
+    const char *error;
 
-    apr_global_hook_pool=process->pconf;
+    apr_hook_global_pool=process->pconf;
+
+    rebuild_conf_hash(process->pconf, 0);
 
     /*
      *  Initialise total_modules variable and module indices
@@ -619,16 +740,23 @@ AP_DECLARE(void) ap_setup_prelinked_modules(process_rec *process)
     for (m = ap_preloaded_modules; *m != NULL; m++)
         (*m)->module_index = total_modules++;
 
+    max_modules = total_modules + DYNAMIC_MODULE_LIMIT + 1;
+    conf_vector_length = max_modules;
+
     /*
-     *  Initialise list of loaded modules
+     *  Initialise list of loaded modules and short names
      */
     ap_loaded_modules = (module **)apr_palloc(process->pool,
-        sizeof(module *) * (total_modules + DYNAMIC_MODULE_LIMIT + 1));
+        sizeof(module *) * conf_vector_length);
+    if (!ap_module_short_names)
+        ap_module_short_names = calloc(sizeof(char *), conf_vector_length);
 
-    if (ap_loaded_modules == NULL) {
-        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
-                     "Ouch!  Out of memory in ap_setup_prelinked_modules()!");
-    }
+    if (!merger_func_cache)
+        merger_func_cache = calloc(sizeof(merger_func), conf_vector_length);
+
+    if (ap_loaded_modules == NULL || ap_module_short_names == NULL
+        || merger_func_cache == NULL)
+        return "Ouch! Out of memory in ap_setup_prelinked_modules()!";
 
     for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; )
         *m2++ = *m++;
@@ -638,10 +766,16 @@ AP_DECLARE(void) ap_setup_prelinked_modules(process_rec *process)
     /*
      *   Initialize chain of linked (=activate) modules
      */
-    for (m = ap_prelinked_modules; *m != NULL; m++)
-        ap_add_module(*m, process->pconf);
+    for (m = ap_prelinked_modules; *m != NULL; m++) {
+        error = ap_add_module(*m, process->pconf, NULL);
+        if (error) {
+            return error;
+        }
+    }
+
+    apr_hook_sort_all();
 
-    apr_sort_hooks();
+    return NULL;
 }
 
 AP_DECLARE(const char *) ap_find_module_name(module *m)
@@ -649,6 +783,13 @@ AP_DECLARE(const char *) ap_find_module_name(module *m)
     return m->name;
 }
 
+AP_DECLARE(const char *) ap_find_module_short_name(int module_index)
+{
+        if (module_index < 0 || module_index >= conf_vector_length)
+                return NULL;
+        return ap_module_short_names[module_index];
+}
+
 AP_DECLARE(module *) ap_find_linked_module(const char *name)
 {
     module *modp;
@@ -661,26 +802,6 @@ AP_DECLARE(module *) ap_find_linked_module(const char *name)
     return NULL;
 }
 
-/* Add a named module.  Returns 1 if module found, 0 otherwise.  */
-AP_DECLARE(int) ap_add_named_module(const char *name, apr_pool_t *p)
-{
-    module *modp;
-    int i = 0;
-
-    for (modp = ap_loaded_modules[i]; modp; modp = ap_loaded_modules[++i]) {
-        if (strcmp(modp->name, name) == 0) {
-            /* Only add modules that are not already enabled.  */
-            if (modp->next == NULL) {
-                ap_add_module(modp, p);
-            }
-
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
 /*****************************************************************
  *
  * Resource, access, and .htaccess config files now parsed by a common
@@ -690,11 +811,13 @@ AP_DECLARE(int) ap_add_named_module(const char *name, apr_pool_t *p)
  * invoking the function...
  */
 
+#define AP_MAX_ARGC 64
+
 static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
                               void *mconfig, const char *args)
 {
     char *w, *w2, *w3;
-    const char *errmsg;
+    const char *errmsg = NULL;
 
     if ((parms->override & cmd->req_override) == 0)
         return apr_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
@@ -709,6 +832,23 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
 #endif
         return cmd->AP_RAW_ARGS(parms, mconfig, args);
 
+    case TAKE_ARGV:
+        {
+            char *argv[AP_MAX_ARGC];
+            int argc = 0;
+
+            do {
+                w = ap_getword_conf(parms->pool, &args);
+                if (*w == '\0' && *args == '\0') {
+                    break;
+                }
+                argv[argc] = w;
+                argc++;
+            } while (argc < AP_MAX_ARGC && *args != '\0');
+
+            return cmd->AP_TAKE_ARGV(parms, mconfig, argc, argv);
+        }
+
     case NO_ARGS:
         if (*args != 0)
             return apr_pstrcat(parms->pool, cmd->name, " takes no arguments",
@@ -794,11 +934,14 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
 
     case ITERATE:
         while (*(w = ap_getword_conf(parms->pool, &args)) != '\0') {
-            if ((errmsg = cmd->AP_TAKE1(parms, mconfig, w)))
+
+            errmsg = cmd->AP_TAKE1(parms, mconfig, w);
+
+            if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0)
                 return errmsg;
         }
 
-        return NULL;
+        return errmsg;
 
     case ITERATE2:
         w = ap_getword_conf(parms->pool, &args);
@@ -809,11 +952,14 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
                                cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
 
         while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0') {
-            if ((errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2)))
+
+            errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2);
+
+            if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0)
                 return errmsg;
         }
 
-        return NULL;
+        return errmsg;
 
     case FLAG:
         w = ap_getword_conf(parms->pool, &args);
@@ -923,6 +1069,9 @@ static const char *ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool,
         if (*lastc == '>') {
             *lastc = '\0' ;
         }
+        if (cmd_name[0] == '<' && *args == '\0') {
+            args = ">";
+        }
     }
 
     newdir = apr_pcalloc(p, sizeof(ap_directive_t));
@@ -1016,12 +1165,18 @@ AP_DECLARE(const char *) ap_build_cont_config(apr_pool_t *p,
                                               ap_directive_t **curr_parent,
                                               char *orig_directive)
 {
-    char l[MAX_STRING_LEN];
+    char *l;
     char *bracket;
     const char *retval;
     ap_directive_t *sub_tree = NULL;
 
-    bracket = apr_pstrcat(p, orig_directive + 1, ">", NULL);
+    /* Since this function can be called recursively, allocate
+     * the temporary 8k string buffer from the temp_pool rather
+     * than the stack to avoid over-running a fixed length stack.
+     */
+    l = apr_palloc(temp_pool, MAX_STRING_LEN);
+
+    bracket = apr_pstrcat(temp_pool, orig_directive + 1, ">", NULL);
     while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
         if (!memcmp(l, "</", 2)
             && (strcasecmp(l + 2, bracket) == 0)
@@ -1033,11 +1188,11 @@ AP_DECLARE(const char *) ap_build_cont_config(apr_pool_t *p,
         if (retval != NULL)
             return retval;
 
-        if (sub_tree == NULL && curr_parent != NULL) {
+        if (sub_tree == NULL) {
             sub_tree = *curr_parent;
         }
 
-        if (sub_tree == NULL && current != NULL) {
+        if (sub_tree == NULL) {
             sub_tree = *current;
         }
     }
@@ -1050,54 +1205,53 @@ static const char *ap_walk_config_sub(const ap_directive_t *current,
                                       cmd_parms *parms,
                                       ap_conf_vector_t *section_vector)
 {
-    module *mod = ap_top_module;
+    const command_rec *cmd;
+    ap_mod_list *ml;
+    char *dir = apr_pstrdup(parms->pool, current->directive);
 
-    while (1) {
-        const command_rec *cmd;
+    ap_str_tolower(dir);
 
-        if (!(cmd = ap_find_command_in_modules(current->directive, &mod))) {
-            parms->err_directive = current;
-            return apr_pstrcat(parms->pool, "Invalid command '",
-                               current->directive,
-                               "', perhaps mis-spelled or defined by a module "
-                               "not included in the server configuration",
-                               NULL);
-        }
-        else {
-            void *dir_config = ap_set_config_vectors(parms->server,
-                                                     section_vector,
-                                                     parms->path,
-                                                     mod,
-                                                     parms->pool);
-            const char *retval;
-
-            /* Once was enough? */
-            if (cmd->req_override & EXEC_ON_READ) {
-                return NULL;
-            }
+    ml = apr_hash_get(ap_config_hash, dir, APR_HASH_KEY_STRING);
 
-            retval = invoke_cmd(cmd, parms, dir_config, current->args);
-            if (retval == NULL) {
-                return NULL;
-            }
+    if (ml == NULL) {
+        parms->err_directive = current;
+        return apr_pstrcat(parms->pool, "Invalid command '",
+                           current->directive,
+                           "', perhaps misspelled or defined by a module "
+                           "not included in the server configuration",
+                           NULL);
+    }
 
-            if (strcmp(retval, DECLINE_CMD) != 0) {
-                /* If the directive in error has already been set, don't
-                 * replace it.  Otherwise, an error inside a container 
-                 * will be reported as occuring on the first line of the
-                 * container.
-                 */
-                if (!parms->err_directive) {
-                    parms->err_directive = current;
-                }
+    for ( ; ml != NULL; ml = ml->next) {
+        void *dir_config = ap_set_config_vectors(parms->server,
+                                                 section_vector,
+                                                 parms->path,
+                                                 ml->m,
+                                                 parms->pool);
+        const char *retval;
+        cmd = ml->cmd;
 
-                return retval;
-            }
+        /* Once was enough? */
+        if (cmd->req_override & EXEC_ON_READ) {
+            continue;
+        }
 
-            mod = mod->next; /* Next time around, skip this one */
+        retval = invoke_cmd(cmd, parms, dir_config, current->args);
+
+        if (retval != NULL && strcmp(retval, DECLINE_CMD) != 0) {
+            /* If the directive in error has already been set, don't
+             * replace it.  Otherwise, an error inside a container
+             * will be reported as occuring on the first line of the
+             * container.
+             */
+            if (!parms->err_directive) {
+                parms->err_directive = current;
+            }
+            return retval;
         }
     }
-    /* NOTREACHED */
+
+    return NULL;
 }
 
 AP_DECLARE(const char *) ap_walk_config(ap_directive_t *current,
@@ -1133,13 +1287,30 @@ AP_DECLARE(const char *) ap_build_config(cmd_parms *parms,
 {
     ap_directive_t *current = *conftree;
     ap_directive_t *curr_parent = NULL;
-    char l[MAX_STRING_LEN];
+    char *l = apr_palloc (temp_pool, MAX_STRING_LEN);
     const char *errmsg;
+    ap_directive_t **last_ptr = NULL;
 
     if (current != NULL) {
+        /* If we have to traverse the whole tree again for every included
+         * config file, the required time grows as O(n^2) with the number of
+         * files. This can be a significant delay for large configurations.
+         * Therefore we cache a pointer to the last node.
+         */
+        last_ptr = &(current->last);
+
+        if(last_ptr && *last_ptr) {
+            current = *last_ptr;
+        }
+
         while (current->next) {
             current = current->next;
         }
+
+        if(last_ptr) {
+            /* update cached pointer to last node */
+            *last_ptr = current;
+        }
     }
 
     while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
@@ -1167,7 +1338,9 @@ AP_DECLARE(const char *) ap_build_config(cmd_parms *parms,
                                   curr_parent->filename,
                                   curr_parent->line_num,
                                   curr_parent->directive);
-                                  curr_parent = curr_parent->parent;
+
+            parms->err_directive = curr_parent;
+            curr_parent = curr_parent->parent;
         }
 
         return errmsg;
@@ -1234,6 +1407,18 @@ AP_DECLARE_NONSTD(const char *) ap_set_flag_slot(cmd_parms *cmd,
     return NULL;
 }
 
+AP_DECLARE_NONSTD(const char *) ap_set_flag_slot_char(cmd_parms *cmd,
+                                                      void *struct_ptr_v, int arg)
+{
+    int offset = (int)(long)cmd->info;
+    char *struct_ptr = (char *)struct_ptr_v;
+
+    *(struct_ptr + offset) = arg ? 1 : 0;
+
+    return NULL;
+}
+
+
 AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, void *struct_ptr,
                                                  const char *arg)
 {
@@ -1263,22 +1448,50 @@ AP_DECLARE_NONSTD(const char *) ap_set_deprecated(cmd_parms *cmd,
     return cmd->cmd->errmsg;
 }
 
+AP_DECLARE(void) ap_reset_module_loglevels(struct ap_logconf *l, int val)
+{
+    if (l->module_levels)
+        memset(l->module_levels, val, conf_vector_length);
+}
+
+AP_DECLARE(void) ap_set_module_loglevel(apr_pool_t *pool, struct ap_logconf *l,
+                                        int index, int level)
+{
+    if (!l->module_levels) {
+        l->module_levels = apr_palloc(pool, conf_vector_length);
+        if (l->level == APLOG_UNSET) {
+                ap_reset_module_loglevels(l, APLOG_UNSET);
+        }
+        else {
+                ap_reset_module_loglevels(l, APLOG_NO_MODULE);
+        }
+    }
+
+    l->module_levels[index] = level;
+}
+
 /*****************************************************************
  *
  * Reading whole config files...
  */
 
 static cmd_parms default_parms =
-{NULL, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
+{NULL, 0, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
 
 AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *file)
 {
-    char *newpath;
-    if (apr_filepath_merge(&newpath, ap_server_root, file,
-                           APR_FILEPATH_TRUENAME, p) == APR_SUCCESS)
+    char *newpath = NULL;
+    apr_status_t rv;
+    rv = apr_filepath_merge(&newpath, ap_server_root, file,
+                            APR_FILEPATH_TRUENAME, p);
+    if (newpath && (rv == APR_SUCCESS || APR_STATUS_IS_EPATHWILD(rv)
+                                      || APR_STATUS_IS_ENOENT(rv)
+                                      || APR_STATUS_IS_ENOTDIR(rv))) {
         return newpath;
-    else
+    }
+    else {
         return NULL;
+    }
 }
 
 AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive)
@@ -1294,7 +1507,7 @@ AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive)
         args = ap_resolve_env(cmd->temp_pool, l);
 #endif
 
-        cmd_name = ap_getword_conf(cmd->pool, &args);
+        cmd_name = ap_getword_conf(cmd->temp_pool, &args);
         if (cmd_name[0] == '<') {
             if (cmd_name[1] == '/') {
                 cmd_name[strlen(cmd_name) - 1] = '\0';
@@ -1310,6 +1523,10 @@ AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive)
             else {
                 const char *msg;
 
+                if (*args == '\0' && cmd_name[strlen(cmd_name) - 1] == '>') {
+                    cmd_name[strlen(cmd_name) - 1] = '\0';
+                }
+
                 if ((msg = ap_soak_end_container(cmd, cmd_name)) != NULL) {
                     return msg;
                 }
@@ -1328,19 +1545,34 @@ static const char *execute_now(char *cmd_line, const char *args,
                                ap_directive_t **sub_tree,
                                ap_directive_t *parent)
 {
-    module *mod = ap_top_module;
     const command_rec *cmd;
+    ap_mod_list *ml;
+    char *dir = apr_pstrdup(parms->temp_pool, cmd_line);
+
+    ap_str_tolower(dir);
 
-    if (!(cmd = ap_find_command_in_modules(cmd_line, &mod))) {
+    ml = apr_hash_get(ap_config_hash, dir, APR_HASH_KEY_STRING);
+
+    if (ml == NULL) {
         return apr_pstrcat(parms->pool, "Invalid command '",
                            cmd_line,
-                           "', perhaps mis-spelled or defined by a module "
+                           "', perhaps misspelled or defined by a module "
                            "not included in the server configuration",
                            NULL);
     }
-    else {
-        return invoke_cmd(cmd, parms, sub_tree, args);
+
+    for ( ; ml != NULL; ml = ml->next) {
+        const char *retval;
+        cmd = ml->cmd;
+
+        retval = invoke_cmd(cmd, parms, sub_tree, args);
+
+        if (retval != NULL) {
+            return retval;
+        }
     }
+
+    return NULL;
 }
 
 /* This structure and the following functions are needed for the
@@ -1387,9 +1619,11 @@ static int arr_elts_close(void *param)
     return 0;
 }
 
-static void process_command_config(server_rec *s, apr_array_header_t *arr,
-                                   ap_directive_t **conftree, apr_pool_t *p,
-                                   apr_pool_t *ptemp)
+static const char *process_command_config(server_rec *s,
+                                          apr_array_header_t *arr,
+                                          ap_directive_t **conftree,
+                                          apr_pool_t *p,
+                                          apr_pool_t *ptemp)
 {
     const char *errmsg;
     cmd_parms parms;
@@ -1398,29 +1632,34 @@ static void process_command_config(server_rec *s, apr_array_header_t *arr,
     arr_parms.curr_idx = 0;
     arr_parms.array = arr;
 
+    if (ap_config_hash == NULL) {
+        rebuild_conf_hash(s->process->pconf, 1);
+    }
+
     parms = default_parms;
     parms.pool = p;
     parms.temp_pool = ptemp;
     parms.server = s;
     parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
+    parms.override_opts = OPT_ALL | OPT_SYM_OWNER | OPT_MULTI;
 
     parms.config_file = ap_pcfg_open_custom(p, "-c/-C directives",
                                             &arr_parms, NULL,
                                             arr_elts_getstr, arr_elts_close);
 
     errmsg = ap_build_config(&parms, p, ptemp, conftree);
+    ap_cfg_closefile(parms.config_file);
+
     if (errmsg) {
-        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
-                     "Syntax error in -C/-c directive:" APR_EOL_STR "%s",
-                     errmsg);
-        exit(1);
+        return apr_pstrcat(p, "Syntax error in -C/-c directive: ", errmsg,
+                           NULL);
     }
 
-    ap_cfg_closefile(parms.config_file);
+    return NULL;
 }
 
 typedef struct {
-    char *fname;
+    const char *fname;
 } fnames;
 
 static int fname_alphasort(const void *fn1, const void *fn2)
@@ -1431,60 +1670,89 @@ static int fname_alphasort(const void *fn1, const void *fn2)
     return strcmp(f1->fname,f2->fname);
 }
 
-AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname,
-                                            ap_directive_t **conftree,
-                                            apr_pool_t *p,
-                                            apr_pool_t *ptemp)
+AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
+                                                    const char *fname,
+                                                    ap_directive_t **conftree,
+                                                    apr_pool_t *p,
+                                                    apr_pool_t *ptemp)
 {
-    cmd_parms parms;
-    apr_finfo_t finfo;
-    const char *errmsg;
     ap_configfile_t *cfp;
+    cmd_parms parms;
+    apr_status_t rv;
+    const char *error;
 
-    /* don't require conf/httpd.conf if we have a -C or -c switch */
-    if ((ap_server_pre_read_config->nelts
-        || ap_server_post_read_config->nelts)
-        && !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) {
-        if (apr_lstat(&finfo, fname, APR_FINFO_TYPE, p) != APR_SUCCESS)
-            return;
+    parms = default_parms;
+    parms.pool = p;
+    parms.temp_pool = ptemp;
+    parms.server = s;
+    parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
+    parms.override_opts = OPT_ALL | OPT_SYM_OWNER | OPT_MULTI;
+
+    rv = ap_pcfg_openfile(&cfp, p, fname);
+    if (rv != APR_SUCCESS) {
+        char errmsg[120];
+        return apr_psprintf(p, "Could not open configuration file %s: %s",
+                            fname, apr_strerror(rv, errmsg, sizeof errmsg));
     }
 
-    /*
-     * here we want to check if the candidate file is really a
-     * directory, and most definitely NOT a symlink (to prevent
-     * horrible loops).  If so, let's recurse and toss it back
-     * into the function.
-     */
-    if (ap_is_rdirectory(ptemp, fname)) {
+    parms.config_file = cfp;
+    error = ap_build_config(&parms, p, ptemp, conftree);
+    ap_cfg_closefile(cfp);
+
+    if (error) {
+        return apr_psprintf(p, "Syntax error on line %d of %s: %s",
+                            parms.err_directive->line_num,
+                            parms.err_directive->filename, error);
+    }
+
+    return NULL;
+}
+
+static const char *process_resource_config_nofnmatch(server_rec *s,
+                                                     const char *fname,
+                                                     ap_directive_t **conftree,
+                                                     apr_pool_t *p,
+                                                     apr_pool_t *ptemp,
+                                                     unsigned depth,
+                                                     int optional)
+{
+    const char *error;
+    apr_status_t rv;
+
+    if (ap_is_directory(ptemp, fname)) {
         apr_dir_t *dirp;
         apr_finfo_t dirent;
         int current;
         apr_array_header_t *candidates = NULL;
         fnames *fnew;
-        apr_status_t rv;
-        char errmsg[120];
+        char *path = apr_pstrdup(ptemp, fname);
+
+        if (++depth > AP_MAX_INCLUDE_DIR_DEPTH) {
+            return apr_psprintf(p, "Directory %s exceeds the maximum include "
+                                "directory nesting level of %u. You have "
+                                "probably a recursion somewhere.", path,
+                                AP_MAX_INCLUDE_DIR_DEPTH);
+        }
 
         /*
          * first course of business is to grok all the directory
          * entries here and store 'em away. Recall we need full pathnames
          * for this.
          */
-        fprintf(stderr, "Processing config directory: %s\n", fname);
-        rv = apr_dir_open(&dirp, fname, p);
+        rv = apr_dir_open(&dirp, path, ptemp);
         if (rv != APR_SUCCESS) {
-            fprintf(stderr, "%s: could not open config directory %s: %s\n",
-                    ap_server_argv0, fname,
-                    apr_strerror(rv, errmsg, sizeof errmsg));
-            exit(1);
+            char errmsg[120];
+            return apr_psprintf(p, "Could not open config directory %s: %s",
+                                path, apr_strerror(rv, errmsg, sizeof errmsg));
         }
 
-        candidates = apr_array_make(p, 1, sizeof(fnames));
+        candidates = apr_array_make(ptemp, 1, sizeof(fnames));
         while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) {
             /* strip out '.' and '..' */
             if (strcmp(dirent.name, ".")
                 && strcmp(dirent.name, "..")) {
                 fnew = (fnames *) apr_array_push(candidates);
-                fnew->fname = ap_make_full_path(p, fname, dirent.name);
+                fnew->fname = ap_make_full_path(ptemp, path, dirent.name);
             }
         }
 
@@ -1499,49 +1767,181 @@ AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname,
              */
             for (current = 0; current < candidates->nelts; ++current) {
                 fnew = &((fnames *) candidates->elts)[current];
-                fprintf(stderr, " Processing config file: %s\n", fnew->fname);
-                ap_process_resource_config(s, fnew->fname, conftree, p, ptemp);
+                error = process_resource_config_nofnmatch(s, fnew->fname,
+                                                          conftree, p, ptemp,
+                                                          depth, optional);
+                if (error) {
+                    return error;
+                }
             }
         }
 
-        return;
+        return NULL;
     }
 
-    /* GCC's initialization extensions are soooo nice here... */
+    return ap_process_resource_config(s, fname, conftree, p, ptemp);
+}
 
-    parms = default_parms;
-    parms.pool = p;
-    parms.temp_pool = ptemp;
-    parms.server = s;
-    parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
+static const char *process_resource_config_fnmatch(server_rec *s,
+                                                   const char *path,
+                                                   const char *fname,
+                                                   ap_directive_t **conftree,
+                                                   apr_pool_t *p,
+                                                   apr_pool_t *ptemp,
+                                                   unsigned depth,
+                                                   int optional)
+{
+    const char *rest;
+    apr_status_t rv;
+    apr_dir_t *dirp;
+    apr_finfo_t dirent;
+    apr_array_header_t *candidates = NULL;
+    fnames *fnew;
+    int current;
+
+    /* find the first part of the filename */
+    rest = ap_strchr_c(fname, '/');
+    if (rest) {
+        fname = apr_pstrndup(ptemp, fname, rest - fname);
+        rest++;
+    }
 
-    if (ap_pcfg_openfile(&cfp, p, fname) != APR_SUCCESS) {
-        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
-                     "%s: could not open document config file %s",
-                     ap_server_argv0, fname);
-        exit(1);
+    /* optimisation - if the filename isn't a wildcard, process it directly */
+    if (!apr_fnmatch_test(fname)) {
+        path = ap_make_full_path(ptemp, path, fname);
+        if (!rest) {
+            return process_resource_config_nofnmatch(s, path,
+                                                     conftree, p,
+                                                     ptemp, 0, optional);
+        }
+        else {
+            return process_resource_config_fnmatch(s, path, rest,
+                                                   conftree, p,
+                                                   ptemp, 0, optional);
+        }
     }
 
-    parms.config_file = cfp;
+    /*
+     * first course of business is to grok all the directory
+     * entries here and store 'em away. Recall we need full pathnames
+     * for this.
+     */
+    rv = apr_dir_open(&dirp, path, ptemp);
+    if (rv != APR_SUCCESS) {
+        char errmsg[120];
+        return apr_psprintf(p, "Could not open config directory %s: %s",
+                            path, apr_strerror(rv, errmsg, sizeof errmsg));
+    }
 
-    errmsg = ap_build_config(&parms, p, ptemp, conftree);
+    candidates = apr_array_make(ptemp, 1, sizeof(fnames));
+    while (apr_dir_read(&dirent, APR_FINFO_DIRENT | APR_FINFO_TYPE, dirp) == APR_SUCCESS) {
+        /* strip out '.' and '..' */
+        if (strcmp(dirent.name, ".")
+            && strcmp(dirent.name, "..")
+            && (apr_fnmatch(fname, dirent.name,
+                            APR_FNM_PERIOD) == APR_SUCCESS)) {
+            const char *full_path = ap_make_full_path(ptemp, path, dirent.name);
+            /* If matching internal to path, and we happen to match something
+             * other than a directory, skip it
+             */
+            if (rest && (rv == APR_SUCCESS) && (dirent.filetype != APR_DIR)) {
+                continue;
+            }
+            fnew = (fnames *) apr_array_push(candidates);
+            fnew->fname = full_path;
+        }
+    }
 
-    if (errmsg != NULL) {
-        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
-                     "Syntax error on line %d of %s:",
-                     parms.err_directive->line_num,
-                     parms.err_directive->filename);
-        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
-                     "%s", errmsg);
-        exit(1);
+    apr_dir_close(dirp);
+    if (candidates->nelts != 0) {
+        const char *error;
+
+        qsort((void *) candidates->elts, candidates->nelts,
+              sizeof(fnames), fname_alphasort);
+
+        /*
+         * Now recurse these... we handle errors and subdirectories
+         * via the recursion, which is nice
+         */
+        for (current = 0; current < candidates->nelts; ++current) {
+            fnew = &((fnames *) candidates->elts)[current];
+            if (!rest) {
+                error = process_resource_config_nofnmatch(s, fnew->fname,
+                                                          conftree, p,
+                                                          ptemp, 0, optional);
+            }
+            else {
+                error = process_resource_config_fnmatch(s, fnew->fname, rest,
+                                                        conftree, p,
+                                                        ptemp, 0, optional);
+            }
+            if (error) {
+                return error;
+            }
+        }
     }
+    else {
 
-    ap_cfg_closefile(cfp);
+        if (!optional) {
+            return apr_psprintf(p, "No matches for the wildcard '%s' in '%s', failing "
+                                   "(use IncludeOptional if required)", fname, path);
+        }
+    }
+
+    return NULL;
+}
+
+AP_DECLARE(const char *) ap_process_fnmatch_configs(server_rec *s,
+                                                    const char *fname,
+                                                    ap_directive_t **conftree,
+                                                    apr_pool_t *p,
+                                                    apr_pool_t *ptemp,
+                                                    int optional)
+{
+    /* XXX: lstat() won't work on the wildcard pattern...
+     */
+
+    /* don't require conf/httpd.conf if we have a -C or -c switch */
+    if ((ap_server_pre_read_config->nelts
+        || ap_server_post_read_config->nelts)
+        && !(strcmp(fname, ap_server_root_relative(ptemp, SERVER_CONFIG_FILE)))) {
+        apr_finfo_t finfo;
+
+        if (apr_stat(&finfo, fname, APR_FINFO_LINK | APR_FINFO_TYPE, ptemp) != APR_SUCCESS)
+            return NULL;
+    }
+
+    if (!apr_fnmatch_test(fname)) {
+        return ap_process_resource_config(s, fname, conftree, p, ptemp);
+    }
+    else {
+        apr_status_t status;
+        const char *rootpath, *filepath = fname;
+
+        /* locate the start of the directories proper */
+        status = apr_filepath_root(&rootpath, &filepath, APR_FILEPATH_TRUENAME, ptemp);
+
+        /* we allow APR_SUCCESS and APR_EINCOMPLETE */
+        if (APR_ERELATIVE == status) {
+            return apr_pstrcat(p, "Include must have an absolute path, ", fname, NULL);
+        }
+        else if (APR_EBADPATH == status) {
+            return apr_pstrcat(p, "Include has a bad path, ", fname, NULL);
+        }
+
+        /* walk the filepath */
+        return process_resource_config_fnmatch(s, rootpath, filepath, conftree, p, ptemp,
+                                               0, optional);
+
+    }
+
+    return NULL;
 }
 
-AP_DECLARE(void) ap_process_config_tree(server_rec *s,
-                                        ap_directive_t *conftree,
-                                        apr_pool_t *p, apr_pool_t *ptemp)
+AP_DECLARE(int) ap_process_config_tree(server_rec *s,
+                                       ap_directive_t *conftree,
+                                       apr_pool_t *p,
+                                       apr_pool_t *ptemp)
 {
     const char *errmsg;
     cmd_parms parms;
@@ -1551,6 +1951,7 @@ AP_DECLARE(void) ap_process_config_tree(server_rec *s,
     parms.temp_pool = ptemp;
     parms.server = s;
     parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
+    parms.override_opts = OPT_ALL | OPT_SYM_OWNER | OPT_MULTI;
     parms.limited = -1;
 
     errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults);
@@ -1561,12 +1962,15 @@ AP_DECLARE(void) ap_process_config_tree(server_rec *s,
                      parms.err_directive->filename);
         ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p,
                      "%s", errmsg);
-        exit(1);
+        return HTTP_INTERNAL_SERVER_ERROR;
     }
+
+    return OK;
 }
 
 AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result,
                                        request_rec *r, int override,
+                                       int override_opts,
                                        const char *d, const char *access_name)
 {
     ap_configfile_t *f = NULL;
@@ -1587,6 +1991,7 @@ AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result,
 
     parms = default_parms;
     parms.override = override;
+    parms.override_opts = override_opts;
     parms.pool = r->pool;
     parms.temp_pool = r->pool;
     parms.server = r->server;
@@ -1629,8 +2034,9 @@ AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result,
                 && !APR_STATUS_IS_ENOTDIR(status)) {
                 ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r,
                               "%s pcfg_openfile: unable to check htaccess file, "
-                              "ensure it is readable",
-                              filename);
+                              "ensure it is readable and that '%s' " 
+                              "is executable",
+                              filename, d);
                 apr_table_setn(r->notes, "error-notes",
                                "Server unable to read htaccess file, denying "
                                "access to be safe");
@@ -1643,6 +2049,7 @@ AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result,
     new = apr_palloc(r->pool, sizeof(struct htaccess_result));
     new->dir = parms.path;
     new->override = override;
+    new->override_opts = override_opts;
     new->htaccess = dc;
 
     /* add to head of list */
@@ -1663,13 +2070,15 @@ AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p,
     s->process = main_server->process;
     s->server_admin = NULL;
     s->server_hostname = NULL;
+    s->server_scheme = NULL;
     s->error_fname = NULL;
     s->timeout = 0;
     s->keep_alive_timeout = 0;
     s->keep_alive = -1;
     s->keep_alive_max = -1;
     s->error_log = main_server->error_log;
-    s->loglevel = main_server->loglevel;
+    s->log.level = APLOG_UNSET;
+    s->log.module_levels = NULL;
     /* useful default, otherwise we get a port of 0 on redirects */
     s->port = main_server->port;
     s->next = NULL;
@@ -1690,10 +2099,52 @@ AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p,
     return ap_parse_vhost_addrs(p, hostname, s);
 }
 
+AP_DECLARE(struct ap_logconf *) ap_new_log_config(apr_pool_t *p,
+                                                  const struct ap_logconf *old)
+{
+    struct ap_logconf *l = apr_pcalloc(p, sizeof(struct ap_logconf));
+    if (old) {
+        l->level = old->level;
+        if (old->module_levels) {
+            l->module_levels =
+                apr_pmemdup(p, old->module_levels, conf_vector_length);
+        }
+    }
+    else {
+        l->level = APLOG_UNSET;
+    }
+    return l;
+}
+
+AP_DECLARE(void) ap_merge_log_config(const struct ap_logconf *old_conf,
+                                     struct ap_logconf *new_conf)
+{
+    if (new_conf->level != APLOG_UNSET) {
+        /* Setting the main loglevel resets all per-module log levels.
+         * I.e. if new->level has been set, we must ignore old->module_levels.
+         */
+        return;
+    }
+
+    new_conf->level = old_conf->level;
+    if (new_conf->module_levels == NULL) {
+        new_conf->module_levels = old_conf->module_levels;
+    }
+    else if (old_conf->module_levels != NULL) {
+        int i;
+        for (i = 0; i < conf_vector_length; i++) {
+            if (new_conf->module_levels[i] == APLOG_UNSET)
+                new_conf->module_levels[i] = old_conf->module_levels[i];
+        }
+    }
+}
 
 AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, server_rec *main_server)
 {
     server_rec *virt;
+    core_dir_config *dconf = ap_get_module_config(main_server->lookup_defaults,
+                                                  &core_module);
+    dconf->log = &main_server->log;
 
     for (virt = main_server->next; virt; virt = virt->next) {
         merge_server_configs(p, main_server->module_config,
@@ -1718,6 +2169,11 @@ AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, server_rec *main_server)
         if (virt->keep_alive_max == -1)
             virt->keep_alive_max = main_server->keep_alive_max;
 
+        ap_merge_log_config(&main_server->log, &virt->log);
+
+        dconf = ap_get_module_config(virt->lookup_defaults, &core_module);
+        dconf->log = &virt->log;
+
         /* XXX: this is really something that should be dealt with by a
          * post-config api phase
          */
@@ -1748,8 +2204,10 @@ static server_rec *init_server_config(process_rec *process, apr_pool_t *p)
     s->port = 0;
     s->server_admin = DEFAULT_ADMIN;
     s->server_hostname = NULL;
+    s->server_scheme = NULL;
     s->error_fname = DEFAULT_ERRORLOG;
-    s->loglevel = DEFAULT_LOGLEVEL;
+    s->log.level = DEFAULT_LOGLEVEL;
+    s->log.module_levels = NULL;
     s->limit_req_line = DEFAULT_LIMIT_REQUEST_LINE;
     s->limit_req_fieldsize = DEFAULT_LIMIT_REQUEST_FIELDSIZE;
     s->limit_req_fields = DEFAULT_LIMIT_REQUEST_FIELDS;
@@ -1763,7 +2221,12 @@ static server_rec *init_server_config(process_rec *process, apr_pool_t *p)
     /* NOT virtual host; don't match any real network interface */
     rv = apr_sockaddr_info_get(&s->addrs->host_addr,
                                NULL, APR_INET, 0, 0, p);
-    ap_assert(rv == APR_SUCCESS); /* otherwise: bug or no storage */
+    if (rv != APR_SUCCESS) {
+        /* should we test here for rv being an EAIERR? */
+        ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, rv, NULL,
+                     "initialisation: bug or getaddrinfo fail");
+        return NULL;
+    }
 
     s->addrs->host_port = 0; /* matches any port */
     s->addrs->virthost = ""; /* must be non-NULL */
@@ -1776,19 +2239,33 @@ static server_rec *init_server_config(process_rec *process, apr_pool_t *p)
 }
 
 
+static apr_status_t reset_conf_vector_length(void *dummy)
+{
+    conf_vector_length = max_modules;
+    return APR_SUCCESS;
+}
+
 AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
                                        const char *filename,
                                        ap_directive_t **conftree)
 {
-    const char *confname;
+    const char *confname, *error;
     apr_pool_t *p = process->pconf;
     server_rec *s = init_server_config(process, p);
+    if (s == NULL) {
+        return s;
+    }
 
     init_config_globals(p);
 
     /* All server-wide config files now have the SAME syntax... */
-    process_command_config(s, ap_server_pre_read_config, conftree,
-                           p, ptemp);
+    error = process_command_config(s, ap_server_pre_read_config, conftree,
+                                   p, ptemp);
+    if (error) {
+        ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, "%s: %s",
+                     ap_server_argv0, error);
+        return NULL;
+    }
 
     /* process_command_config may change the ServerRoot so
      * compute this config file name afterwards.
@@ -1799,13 +2276,39 @@ AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
         ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT,
                      APR_EBADPATH, NULL, "Invalid config file path %s",
                      filename);
-        exit(1);
+        return NULL;
     }
 
-    ap_process_resource_config(s, confname, conftree, p, ptemp);
+    error = ap_process_resource_config(s, confname, conftree, p, ptemp);
+    if (error) {
+        ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL,
+                     "%s: %s", ap_server_argv0, error);
+        return NULL;
+    }
 
-    process_command_config(s, ap_server_post_read_config, conftree,
-                           p, ptemp);
+    error = ap_check_mpm();
+    if (error) {
+        ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL,
+                     "%s: Configuration error: %s", ap_server_argv0, error);
+        return NULL;
+    }
+
+    /*
+     * We have loaded the dynamic modules. From now on we know exactly how
+     * long the config vectors need to be.
+     */
+    conf_vector_length = total_modules;
+    apr_pool_cleanup_register(p, NULL, reset_conf_vector_length,
+                              apr_pool_cleanup_null);
+
+    error = process_command_config(s, ap_server_post_read_config, conftree,
+                                   p, ptemp);
+
+    if (error) {
+        ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, "%s: %s",
+                     ap_server_argv0, error);
+        return NULL;
+    }
 
     return s;
 }
@@ -1952,7 +2455,19 @@ AP_DECLARE(void) ap_show_modules(void)
         printf("  %s\n", ap_loaded_modules[n]->name);
 }
 
-AP_DECLARE(const char *) ap_show_mpm(void)
+AP_DECLARE(void *) ap_retained_data_get(const char *key)
 {
-    return MPM_NAME;
+    void *retained;
+
+    apr_pool_userdata_get((void *)&retained, key, ap_pglobal);
+    return retained;
+}
+
+AP_DECLARE(void *) ap_retained_data_create(const char *key, apr_size_t size)
+{
+    void *retained;
+
+    retained = apr_pcalloc(ap_pglobal, size);
+    apr_pool_userdata_set((const void *)retained, key, apr_pool_cleanup_null, ap_pglobal);
+    return retained;
 }