]> granicus.if.org Git - apache/blobdiff - server/core.c
Fixed unused "ap_listen_rec *lr;" in prefork_run().
[apache] / server / core.c
index b2cdfe0e3527f5b0830f0793e0c7053dbea6d67b..5032bc796bf684402ce80a18442dbce4d7547d34 100644 (file)
@@ -20,7 +20,7 @@
 #include "apr_fnmatch.h"
 #include "apr_hash.h"
 #include "apr_thread_proc.h"    /* for RLIMIT stuff */
-#include "apr_hooks.h"
+#include "apr_random.h"
 
 #define APR_WANT_IOVEC
 #define APR_WANT_STRFUNC
@@ -48,6 +48,7 @@
 #include "mod_core.h"
 #include "mod_proxy.h"
 #include "ap_listen.h"
+#include "ap_provider.h"
 
 #include "mod_so.h" /* for ap_find_loaded_module_symbol */
 
@@ -64,7 +65,7 @@
 
 /* LimitXMLRequestBody handling */
 #define AP_LIMIT_UNSET                  ((long) -1)
-#define AP_DEFAULT_LIMIT_XML_BODY       ((size_t)1000000)
+#define AP_DEFAULT_LIMIT_XML_BODY       ((apr_size_t)1000000)
 
 #define AP_MIN_SENDFILE_BYTES           (256)
 
 #endif
 
 /* valid in core-conf, but not in runtime r->used_path_info */
-#define AP_ACCEPT_PATHINFO_UNSET 3 
+#define AP_ACCEPT_PATHINFO_UNSET 3
+
+#define AP_CONTENT_MD5_OFF   0
+#define AP_CONTENT_MD5_ON    1
+#define AP_CONTENT_MD5_UNSET 2
 
 APR_HOOK_STRUCT(
     APR_HOOK_LINK(get_mgmt_items)
+    APR_HOOK_LINK(insert_network_bucket)
 )
 
 AP_IMPLEMENT_HOOK_RUN_ALL(int, get_mgmt_items,
                           (apr_pool_t *p, const char *val, apr_hash_t *ht),
                           (p, val, ht), OK, DECLINED)
 
+AP_IMPLEMENT_HOOK_RUN_FIRST(apr_status_t, insert_network_bucket,
+                            (conn_rec *c, apr_bucket_brigade *bb,
+                             apr_socket_t *socket),
+                            (c, bb, socket), AP_DECLINED)
+
 /* Server core module... This module provides support for really basic
  * server operations, including options and commands which control the
  * operation of other modules.  Consider this the bureaucracy module.
@@ -95,6 +106,10 @@ AP_IMPLEMENT_HOOK_RUN_ALL(int, get_mgmt_items,
  * the http_conf_globals.
  */
 
+/* we know core's module_index is 0 */
+#undef APLOG_MODULE_INDEX
+#define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
+
 /* Handles for core filters */
 AP_DECLARE_DATA ap_filter_rec_t *ap_subreq_core_filter_handle;
 AP_DECLARE_DATA ap_filter_rec_t *ap_core_output_filter_handle;
@@ -112,7 +127,12 @@ static apr_table_t *server_config_defined_vars = NULL;
 
 AP_DECLARE_DATA int ap_main_state = AP_SQ_MS_INITIAL_STARTUP;
 AP_DECLARE_DATA int ap_run_mode = AP_SQ_RM_UNKNOWN;
-AP_DECLARE_DATA int ap_config_generation = 1;
+AP_DECLARE_DATA int ap_config_generation = 0;
+
+typedef struct {
+    apr_ipsubnet_t *subnet;
+    struct ap_logconf log;
+} conn_log_config;
 
 static void *create_core_dir_config(apr_pool_t *a, char *dir)
 {
@@ -127,7 +147,7 @@ static void *create_core_dir_config(apr_pool_t *a, char *dir)
     conf->override = OR_UNSET|OR_NONE;
     conf->override_opts = OPT_UNSET | OPT_ALL | OPT_SYM_OWNER | OPT_MULTI;
 
-    conf->content_md5 = 2;
+    conf->content_md5 = AP_CONTENT_MD5_UNSET;
     conf->accept_path_info = AP_ACCEPT_PATHINFO_UNSET;
 
     conf->use_canonical_name = USE_CANONICAL_NAME_UNSET;
@@ -172,6 +192,10 @@ static void *create_core_dir_config(apr_pool_t *a, char *dir)
     conf->allow_encoded_slashes = 0;
     conf->decode_encoded_slashes = 0;
 
+    conf->max_ranges = AP_MAXRANGES_UNSET;
+    conf->max_overlaps = AP_MAXRANGES_UNSET;
+    conf->max_reversals = AP_MAXRANGES_UNSET;
+
     return (void *)conf;
 }
 
@@ -191,6 +215,7 @@ static void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
     conf->d_is_fnmatch = new->d_is_fnmatch;
     conf->d_components = new->d_components;
     conf->r = new->r;
+    conf->refs = new->refs;
     conf->condition = new->condition;
 
     if (new->opts & OPT_UNSET) {
@@ -229,6 +254,10 @@ static void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
         conf->override_opts = new->override_opts;
     }
 
+    if (new->override_list != NULL) {
+        conf->override_list = new->override_list;
+    }
+
     if (conf->response_code_strings == NULL) {
         conf->response_code_strings = new->response_code_strings;
     }
@@ -252,11 +281,11 @@ static void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
         conf->hostname_lookups = new->hostname_lookups;
     }
 
-    if ((new->content_md5 & 2) == 0) {
+    if (new->content_md5 != AP_CONTENT_MD5_UNSET) {
         conf->content_md5 = new->content_md5;
     }
 
-    if (new->accept_path_info != 3) {
+    if (new->accept_path_info != AP_ACCEPT_PATHINFO_UNSET) {
         conf->accept_path_info = new->accept_path_info;
     }
 
@@ -292,8 +321,6 @@ static void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
 
     if (new->limit_xml_body != AP_LIMIT_UNSET)
         conf->limit_xml_body = new->limit_xml_body;
-    else
-        conf->limit_xml_body = base->limit_xml_body;
 
     if (!conf->sec_file) {
         conf->sec_file = new->sec_file;
@@ -373,8 +400,12 @@ static void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
         conf->enable_sendfile = new->enable_sendfile;
     }
 
-    conf->allow_encoded_slashes = new->allow_encoded_slashes;
-    conf->decode_encoded_slashes = new->decode_encoded_slashes;
+    if (new->allow_encoded_slashes_set) {
+        conf->allow_encoded_slashes = new->allow_encoded_slashes;
+    }
+    if (new->decode_encoded_slashes_set) {
+        conf->decode_encoded_slashes = new->decode_encoded_slashes;
+    }
 
     if (new->log) {
         if (!conf->log) {
@@ -386,6 +417,10 @@ static void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
         }
     }
 
+    conf->max_ranges = new->max_ranges != AP_MAXRANGES_UNSET ? new->max_ranges : base->max_ranges;
+    conf->max_overlaps = new->max_overlaps != AP_MAXRANGES_UNSET ? new->max_overlaps : base->max_overlaps;
+    conf->max_reversals = new->max_reversals != AP_MAXRANGES_UNSET ? new->max_reversals : base->max_reversals;
+
     return (void*)conf;
 }
 
@@ -478,6 +513,18 @@ static void *merge_core_server_configs(apr_pool_t *p, void *basev, void *virtv)
     if (virt->trace_enable != AP_TRACE_UNSET)
         conf->trace_enable = virt->trace_enable;
 
+    if (virt->http09_enable != AP_HTTP09_UNSET)
+        conf->http09_enable = virt->http09_enable;
+
+    if (virt->http_conformance != AP_HTTP_CONFORMANCE_UNSET)
+        conf->http_conformance = virt->http_conformance;
+
+    if (virt->http_cl_head_zero != AP_HTTP_CL_HEAD_ZERO_UNSET)
+        conf->http_cl_head_zero = virt->http_cl_head_zero;
+
+    if (virt->http_expect_strict != AP_HTTP_EXPECT_STRICT_UNSET)
+        conf->http_expect_strict = virt->http_expect_strict;
+
     /* no action for virt->accf_map, not allowed per-vhost */
 
     if (virt->protocol)
@@ -495,6 +542,17 @@ static void *merge_core_server_configs(apr_pool_t *p, void *basev, void *virtv)
     if (virt->error_log_req)
         conf->error_log_req = virt->error_log_req;
 
+    if (virt->conn_log_level) {
+        if (!conf->conn_log_level) {
+            conf->conn_log_level = virt->conn_log_level;
+        }
+        else {
+            /* apr_array_append actually creates a new array */
+            conf->conn_log_level = apr_array_append(p, conf->conn_log_level,
+                                                    virt->conn_log_level);
+        }
+    }
+
     return conf;
 }
 
@@ -504,8 +562,7 @@ static void *merge_core_server_configs(apr_pool_t *p, void *basev, void *virtv)
 
 AP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec *s, void *dir_config)
 {
-    core_server_config *sconf = ap_get_module_config(s->module_config,
-                                                     &core_module);
+    core_server_config *sconf = ap_get_core_module_config(s->module_config);
     void **new_space = (void **)apr_array_push(sconf->sec_dir);
 
     *new_space = dir_config;
@@ -513,8 +570,7 @@ AP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec *s, void *dir_config)
 
 AP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec *s, void *url_config)
 {
-    core_server_config *sconf = ap_get_module_config(s->module_config,
-                                                     &core_module);
+    core_server_config *sconf = ap_get_core_module_config(s->module_config);
     void **new_space = (void **)apr_array_push(sconf->sec_url);
 
     *new_space = url_config;
@@ -532,16 +588,35 @@ AP_CORE_DECLARE(void) ap_add_file_conf(apr_pool_t *p, core_dir_config *conf,
     *new_space = url_config;
 }
 
-AP_CORE_DECLARE(void) ap_add_if_conf(apr_pool_t *p, core_dir_config *conf,
-                                     void *url_config)
+AP_CORE_DECLARE(const char *) ap_add_if_conf(apr_pool_t *p,
+                                             core_dir_config *conf,
+                                             void *if_config)
 {
     void **new_space;
+    core_dir_config *new = ap_get_module_config(if_config, &core_module);
 
-    if (!conf->sec_if)
+    if (!conf->sec_if) {
         conf->sec_if = apr_array_make(p, 2, sizeof(ap_conf_vector_t *));
+    }
+    if (new->condition_ifelse & AP_CONDITION_ELSE) {
+        int have_if = 0;
+        if (conf->sec_if->nelts > 0) {
+            core_dir_config *last;
+            ap_conf_vector_t *lastelt = APR_ARRAY_IDX(conf->sec_if,
+                                                      conf->sec_if->nelts - 1,
+                                                      ap_conf_vector_t *);
+            last = ap_get_module_config(lastelt, &core_module);
+            if (last->condition_ifelse & AP_CONDITION_IF)
+                have_if = 1;
+        }
+        if (!have_if)
+            return "<Else> or <ElseIf> section without previous <If> or "
+                   "<ElseIf> section in same scope";
+    }
 
     new_space = (void **)apr_array_push(conf->sec_if);
-    *new_space = url_config;
+    *new_space = if_config;
+    return NULL;
 }
 
 
@@ -562,8 +637,8 @@ static int reorder_sorter(const void *va, const void *vb)
     core_dir_config *core_a;
     core_dir_config *core_b;
 
-    core_a = ap_get_module_config(a->elt, &core_module);
-    core_b = ap_get_module_config(b->elt, &core_module);
+    core_a = ap_get_core_module_config(a->elt);
+    core_b = ap_get_core_module_config(b->elt);
 
     /* a regex always sorts after a non-regex
      */
@@ -599,7 +674,7 @@ void ap_core_reorder_directories(apr_pool_t *p, server_rec *s)
     int i;
     apr_pool_t *tmp;
 
-    sconf = ap_get_module_config(s->module_config, &core_module);
+    sconf = ap_get_core_module_config(s->module_config);
     sec_dir = sconf->sec_dir;
     nelts = sec_dir->nelts;
     elts = (ap_conf_vector_t **)sec_dir->elts;
@@ -642,7 +717,7 @@ void ap_core_reorder_directories(apr_pool_t *p, server_rec *s)
 AP_DECLARE(int) ap_allow_options(request_rec *r)
 {
     core_dir_config *conf =
-      (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);
+      (core_dir_config *)ap_get_core_module_config(r->per_dir_config);
 
     return conf->opts;
 }
@@ -650,8 +725,7 @@ AP_DECLARE(int) ap_allow_options(request_rec *r)
 AP_DECLARE(int) ap_allow_overrides(request_rec *r)
 {
     core_dir_config *conf;
-    conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
-                                                   &core_module);
+    conf = (core_dir_config *)ap_get_core_module_config(r->per_dir_config);
 
     return conf->override;
 }
@@ -700,12 +774,46 @@ AP_DECLARE(int) ap_satisfies(request_rec *r)
 
 AP_DECLARE(const char *) ap_document_root(request_rec *r) /* Don't use this! */
 {
-    core_server_config *conf;
+    core_server_config *sconf;
+    core_request_config *rconf = ap_get_core_module_config(r->request_config);
+    if (rconf->document_root)
+        return rconf->document_root;
+    sconf = ap_get_core_module_config(r->server->module_config);
+    return sconf->ap_document_root;
+}
 
-    conf = (core_server_config *)ap_get_module_config(r->server->module_config,
-                                                      &core_module);
+AP_DECLARE(const char *) ap_context_prefix(request_rec *r)
+{
+    core_request_config *conf = ap_get_core_module_config(r->request_config);
+    if (conf->context_prefix)
+        return conf->context_prefix;
+    else
+        return "";
+}
 
-    return conf->ap_document_root;
+AP_DECLARE(const char *) ap_context_document_root(request_rec *r)
+{
+    core_request_config *conf = ap_get_core_module_config(r->request_config);
+    if (conf->context_document_root)
+        return conf->context_document_root;
+    else
+        return ap_document_root(r);
+}
+
+AP_DECLARE(void) ap_set_document_root(request_rec *r, const char *document_root)
+{
+    core_request_config *conf = ap_get_core_module_config(r->request_config);
+    conf->document_root = document_root;
+}
+
+AP_DECLARE(void) ap_set_context_info(request_rec *r, const char *context_prefix,
+                                     const char *context_document_root)
+{
+    core_request_config *conf = ap_get_core_module_config(r->request_config);
+    if (context_prefix)
+        conf->context_prefix = context_prefix;
+    if (context_document_root)
+        conf->context_document_root = context_document_root;
 }
 
 /* Should probably just get rid of this... the only code that cares is
@@ -716,19 +824,16 @@ AP_DECLARE(const char *) ap_document_root(request_rec *r) /* Don't use this! */
 char *ap_response_code_string(request_rec *r, int error_index)
 {
     core_dir_config *dirconf;
-    core_request_config *reqconf;
+    core_request_config *reqconf = ap_get_core_module_config(r->request_config);
 
     /* check for string registered via ap_custom_response() first */
-    reqconf = (core_request_config *)ap_get_module_config(r->request_config,
-                                                          &core_module);
     if (reqconf->response_code_strings != NULL &&
         reqconf->response_code_strings[error_index] != NULL) {
         return reqconf->response_code_strings[error_index];
     }
 
     /* check for string specified via ErrorDocument */
-    dirconf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
-                                                      &core_module);
+    dirconf = ap_get_core_module_config(r->per_dir_config);
 
     if (dirconf->response_code_strings == NULL) {
         return NULL;
@@ -762,7 +867,7 @@ static APR_INLINE void do_double_reverse (conn_rec *conn)
     rv = apr_sockaddr_info_get(&sa, conn->remote_host, APR_UNSPEC, 0, 0, conn->pool);
     if (rv == APR_SUCCESS) {
         while (sa) {
-            if (apr_sockaddr_equal(sa, conn->remote_addr)) {
+            if (apr_sockaddr_equal(sa, conn->client_addr)) {
                 conn->double_reverse = 1;
                 return;
             }
@@ -787,9 +892,8 @@ AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config,
 
     /* If we haven't checked the host name, and we want to */
     if (dir_config) {
-        hostname_lookups =
-            ((core_dir_config *)ap_get_module_config(dir_config, &core_module))
-            ->hostname_lookups;
+        hostname_lookups = ((core_dir_config *)ap_get_core_module_config(dir_config))
+                           ->hostname_lookups;
 
         if (hostname_lookups == HOSTNAME_LOOKUP_UNSET) {
             hostname_lookups = HOSTNAME_LOOKUP_OFF;
@@ -805,7 +909,7 @@ AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config,
         && (type == REMOTE_DOUBLE_REV
         || hostname_lookups != HOSTNAME_LOOKUP_OFF)) {
 
-        if (apr_getnameinfo(&conn->remote_host, conn->remote_addr, 0)
+        if (apr_getnameinfo(&conn->remote_host, conn->client_addr, 0)
             == APR_SUCCESS) {
             ap_str_tolower(conn->remote_host);
 
@@ -844,7 +948,7 @@ AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config,
         }
         else {
             *str_is_ip = 1;
-            return conn->remote_ip;
+            return conn->client_ip;
         }
     }
 }
@@ -884,8 +988,7 @@ AP_DECLARE(const char *) ap_get_server_name(request_rec *r)
     core_dir_config *d;
     const char *retval;
 
-    d = (core_dir_config *)ap_get_module_config(r->per_dir_config,
-                                                &core_module);
+    d = (core_dir_config *)ap_get_core_module_config(r->per_dir_config);
 
     switch (d->use_canonical_name) {
         case USE_CANONICAL_NAME_ON:
@@ -908,7 +1011,7 @@ AP_DECLARE(const char *) ap_get_server_name(request_rec *r)
             retval = r->hostname ? r->hostname : r->server->server_hostname;
             break;
         default:
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00109)
                          "ap_get_server_name: Invalid UCN Option somehow");
             retval = "localhost";
             break;
@@ -927,7 +1030,7 @@ AP_DECLARE(const char *) ap_get_server_name_for_url(request_rec *r)
 
 #if APR_HAVE_IPV6
     if (ap_strchr_c(plain_server_name, ':')) { /* IPv6 literal? */
-        return apr_psprintf(r->pool, "[%s]", plain_server_name);
+        return apr_pstrcat(r->pool, "[", plain_server_name, "]", NULL);
     }
 #endif
     return plain_server_name;
@@ -937,7 +1040,7 @@ AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r)
 {
     apr_port_t port;
     core_dir_config *d =
-      (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);
+      (core_dir_config *)ap_get_core_module_config(r->per_dir_config);
 
     switch (d->use_canonical_name) {
         case USE_CANONICAL_NAME_OFF:
@@ -971,7 +1074,7 @@ AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r)
                        ap_default_port(r);
             break;
         default:
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00110)
                          "ap_get_server_port: Invalid UCN Option somehow");
             port = ap_default_port(r);
             break;
@@ -996,7 +1099,7 @@ AP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri,
 AP_DECLARE(apr_off_t) ap_get_limit_req_body(const request_rec *r)
 {
     core_dir_config *d =
-      (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);
+      (core_dir_config *)ap_get_core_module_config(r->per_dir_config);
 
     if (d->limit_req_body == AP_LIMIT_REQ_BODY_UNSET) {
         return AP_DEFAULT_LIMIT_REQ_BODY;
@@ -1048,6 +1151,11 @@ AP_DECLARE(const char *) ap_check_cmd_context(cmd_parms *cmd,
                            "section", NULL);
     }
 
+    if ((forbidden & NOT_IN_HTACCESS) && (cmd->pool == cmd->temp_pool)) {
+         return apr_pstrcat(cmd->pool, cmd->cmd->name, gt,
+                            " cannot occur within htaccess files", NULL);
+    }
+
     if ((forbidden & NOT_IN_DIR_LOC_FILE) == NOT_IN_DIR_LOC_FILE) {
         if (cmd->path != NULL) {
             return apr_pstrcat(cmd->pool, cmd->cmd->name, gt,
@@ -1070,7 +1178,10 @@ AP_DECLARE(const char *) ap_check_cmd_context(cmd_parms *cmd,
                 || (found = find_parent(cmd->directive, "<LocationMatch"))))
         || ((forbidden & NOT_IN_FILES)
             && ((found = find_parent(cmd->directive, "<Files"))
-                || (found = find_parent(cmd->directive, "<FilesMatch"))))) {
+                || (found = find_parent(cmd->directive, "<FilesMatch"))
+                || (found = find_parent(cmd->directive, "<If"))
+                || (found = find_parent(cmd->directive, "<ElseIf"))
+                || (found = find_parent(cmd->directive, "<Else"))))) {
         return apr_pstrcat(cmd->pool, cmd->cmd->name, gt,
                            " cannot occur within ", found->directive,
                            "> section", NULL);
@@ -1083,7 +1194,7 @@ static const char *set_access_name(cmd_parms *cmd, void *dummy,
                                    const char *arg)
 {
     void *sconf = cmd->server->module_config;
-    core_server_config *conf = ap_get_module_config(sconf, &core_module);
+    core_server_config *conf = ap_get_core_module_config(sconf);
 
     const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE);
     if (err != NULL) {
@@ -1148,7 +1259,7 @@ AP_DECLARE(const char *) ap_resolve_env(apr_pool_t *p, const char * word)
                 }
                 else {
                     if (ap_strchr(name, ':') == 0)
-                        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
+                        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, APLOGNO(00111)
                                      "Config variable ${%s} is not defined",
                                      name);
                     current->string = s;
@@ -1212,6 +1323,9 @@ static void init_config_defines(apr_pool_t *pconf)
 static const char *set_define(cmd_parms *cmd, void *dummy,
                               const char *name, const char *value)
 {
+    const char *err = ap_check_cmd_context(cmd, NOT_IN_HTACCESS);
+    if (err)
+        return err;
     if (ap_strchr_c(name, ':') != NULL)
         return "Variable name must not contain ':'";
 
@@ -1235,6 +1349,9 @@ static const char *unset_define(cmd_parms *cmd, void *dummy,
 {
     int i;
     char **defines;
+    const char *err = ap_check_cmd_context(cmd, NOT_IN_HTACCESS);
+    if (err)
+        return err;
     if (ap_strchr_c(name, ':') != NULL)
         return "Variable name must not contain ':'";
 
@@ -1256,30 +1373,56 @@ static const char *unset_define(cmd_parms *cmd, void *dummy,
     return NULL;
 }
 
-static const char *generate_error(cmd_parms *cmd, void *dummy,
-                                  const char *arg)
+static const char *generate_message(cmd_parms *cmd, void *dummy,
+                                    const char *arg)
 {
+    /* cast with 64-bit warning avoidance */
+    int level = (cmd->info==(void*)APLOG_ERR)? APLOG_ERR: APLOG_WARNING;
+    char * msg;
+
+    /* get position information from wherever we can? */
+    ap_configfile_t * cf = cmd->config_file;
+    ap_directive_t const * ed1 = cmd->directive;
+    ap_directive_t const * ed2 = cmd->err_directive;
+
+    /* expect an argument */
     if (!arg || !*arg) {
-        return "The Error directive was used with no message.";
+        return "The Error or Warning directive was used with no message.";
     }
 
-    if (*arg == '"' || *arg == '\'') { /* strip off quotes */
+    /* set message, strip off quotes if necessary */
+    msg = (char *)arg;
+    if (*arg == '"' || *arg == '\'') {
         apr_size_t len = strlen(arg);
         char last = *(arg + len - 1);
 
         if (*arg == last) {
-            return apr_pstrndup(cmd->pool, arg + 1, len - 2);
+            msg = apr_pstrndup(cmd->pool, arg + 1, len - 2);
         }
     }
 
-    return arg;
+    /* generate error or warning with a configuration file position.
+     * the log is displayed on the terminal as no log file is opened yet.
+     */
+    ap_log_error(APLOG_MARK, APLOG_NOERRNO|level, 0, NULL,
+                "%s on line %d of %s", msg,
+                cf? cf->line_number:
+                  ed1? ed1->line_num:
+                    ed2? ed2->line_num: -1,
+                cf? cf->name:
+                  ed1? ed1->filename:
+                    ed2? ed2->filename: "<UNKNOWN>");
+
+    /* message displayed above, return will stop configuration processing */
+    return level==APLOG_ERR?
+        "Configuration processing stopped by Error directive": NULL;
 }
 
 #ifdef GPROF
 static const char *set_gprof_dir(cmd_parms *cmd, void *dummy, const char *arg)
 {
     void *sconf = cmd->server->module_config;
-    core_server_config *conf = ap_get_module_config(sconf, &core_module);
+    core_server_config *conf = ap_get_core_module_config(sconf);
 
     const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE);
     if (err != NULL) {
@@ -1315,7 +1458,7 @@ static const char *set_document_root(cmd_parms *cmd, void *dummy,
                                      const char *arg)
 {
     void *sconf = cmd->server->module_config;
-    core_server_config *conf = ap_get_module_config(sconf, &core_module);
+    core_server_config *conf = ap_get_core_module_config(sconf);
 
     const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE);
     if (err != NULL) {
@@ -1340,13 +1483,15 @@ static const char *set_document_root(cmd_parms *cmd, void *dummy,
         || !ap_is_directory(cmd->pool, arg)) {
         if (cmd->server->is_virtual) {
             ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0,
-                          cmd->pool,
+                          cmd->pool, APLOGNO(00112)
                           "Warning: DocumentRoot [%s] does not exist",
                           arg);
             conf->ap_document_root = arg;
         }
         else {
-            return "DocumentRoot must be a directory";
+            return apr_psprintf(cmd->pool, 
+                                "DocumentRoot '%s' is not a directory, or is not readable",
+                                arg);
         }
     }
     return NULL;
@@ -1355,8 +1500,7 @@ static const char *set_document_root(cmd_parms *cmd, void *dummy,
 AP_DECLARE(void) ap_custom_response(request_rec *r, int status,
                                     const char *string)
 {
-    core_request_config *conf =
-        ap_get_module_config(r->request_config, &core_module);
+    core_request_config *conf = ap_get_core_module_config(r->request_config);
     int idx;
 
     if (conf->response_code_strings == NULL) {
@@ -1406,9 +1550,9 @@ static const char *set_error_document(cmd_parms *cmd, void *conf_,
     /* The entry should be ignored if it is a full URL for a 401 error */
 
     if (error_number == 401 && what == REMOTE_PATH) {
-        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, cmd->server,
-                     "cannot use a full URL in a 401 ErrorDocument "
-                     "directive --- ignoring!");
+        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, cmd->server, APLOGNO(00113)
+                     "%s:%d cannot use a full URL in a 401 ErrorDocument "
+                     "directive --- ignoring!", cmd->directive->filename, cmd->directive->line_num);
     }
     else { /* Store it... */
         if (conf->response_code_strings == NULL) {
@@ -1418,7 +1562,7 @@ static const char *set_error_document(cmd_parms *cmd, void *conf_,
                             RESPONSE_CODES);
         }
 
-        if (strcmp(msg, "default") == 0) {
+        if (strcasecmp(msg, "default") == 0) {
             /* special case: ErrorDocument 404 default restores the
              * canned server error response
              */
@@ -1430,7 +1574,7 @@ static const char *set_error_document(cmd_parms *cmd, void *conf_,
              * a msg and a (local) path.
              */
             conf->response_code_strings[index_number] = (what == MSG) ?
-                    apr_pstrcat(cmd->pool, "\"",msg,NULL) :
+                    apr_pstrcat(cmd->pool, "\"", msg, NULL) :
                     apr_pstrdup(cmd->pool, msg);
         }
     }
@@ -1504,13 +1648,16 @@ static const char *set_override(cmd_parms *cmd, void *d_, const char *l)
     core_dir_config *d = d_;
     char *w;
     char *k, *v;
+    const char *err;
 
     /* Throw a warning if we're in <Location> or <Files> */
     if (ap_check_cmd_context(cmd, NOT_IN_LOCATION | NOT_IN_FILES)) {
-        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server,
+        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00114)
                      "Useless use of AllowOverride in line %d of %s.",
                      cmd->directive->line_num, cmd->directive->filename);
     }
+    if ((err = ap_check_cmd_context(cmd, NOT_IN_HTACCESS)) != NULL)
+        return err;
 
     d->override = OR_NONE;
     while (l[0]) {
@@ -1530,7 +1677,7 @@ static const char *set_override(cmd_parms *cmd, void *d_, const char *l)
             if (v)
                 set_allow_opts(cmd, &(d->override_opts), v);
             else
-                d->override_opts = OPT_SYM_LINKS;
+                d->override_opts = OPT_ALL;
         }
         else if (!strcasecmp(w, "FileInfo")) {
             d->override |= OR_FILEINFO;
@@ -1541,6 +1688,17 @@ static const char *set_override(cmd_parms *cmd, void *d_, const char *l)
         else if (!strcasecmp(w, "Indexes")) {
             d->override |= OR_INDEXES;
         }
+        else if (!strcasecmp(w, "Nonfatal")) {
+            if (!strcasecmp(v, "Override")) {
+                d->override |= NONFATAL_OVERRIDE;
+            }
+            else if (!strcasecmp(v, "Unknown")) {
+                d->override |= NONFATAL_UNKNOWN;
+            }
+            else if (!strcasecmp(v, "All")) {
+                d->override |= NONFATAL_ALL;
+            }
+        }
         else if (!strcasecmp(w, "None")) {
             d->override = OR_NONE;
         }
@@ -1557,6 +1715,60 @@ static const char *set_override(cmd_parms *cmd, void *d_, const char *l)
     return NULL;
 }
 
+static const char *set_override_list(cmd_parms *cmd, void *d_, int argc, char *const argv[])
+{
+    core_dir_config *d = d_;
+    int i;
+    const char *err;
+
+    /* Throw a warning if we're in <Location> or <Files> */
+    if (ap_check_cmd_context(cmd, NOT_IN_LOCATION | NOT_IN_FILES)) {
+        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00115)
+                     "Useless use of AllowOverrideList at %s:%d",
+                     cmd->directive->filename, cmd->directive->line_num);
+    }
+    if ((err = ap_check_cmd_context(cmd, NOT_IN_HTACCESS)) != NULL)
+        return err;
+
+    d->override_list = apr_table_make(cmd->pool, argc);
+
+    for (i=0;i<argc;i++){
+        if (!strcasecmp(argv[i], "None")) {
+            if (argc != 1) {
+                return "'None' not allowed with other directives in "
+                       "AllowOverrideList";
+            }
+            return NULL;
+        }
+        else {
+            const command_rec *result = NULL;
+            module *mod = ap_top_module;
+            result = ap_find_command_in_modules(argv[i], &mod);
+            if (result == NULL) {
+                ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server,
+                             APLOGNO(00116) "Discarding unrecognized "
+                             "directive `%s' in AllowOverrideList at %s:%d",
+                             argv[i], cmd->directive->filename,
+                             cmd->directive->line_num);
+                continue;
+            }
+            else if ((result->req_override & (OR_ALL|ACCESS_CONF)) == 0) {
+                ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server,
+                             APLOGNO(02304) "Discarding directive `%s' not "
+                             "allowed in AllowOverrideList at %s:%d",
+                             argv[i], cmd->directive->filename,
+                             cmd->directive->line_num);
+                continue;
+            }
+            else {
+                apr_table_set(d->override_list, argv[i], "1");
+            }
+        }
+    }
+
+    return NULL;
+}
+
 static const char *set_options(cmd_parms *cmd, void *d_, const char *l)
 {
     core_dir_config *d = d_;
@@ -1660,7 +1872,7 @@ static const char *set_default_type(cmd_parms *cmd, void *d_,
                                    const char *arg)
 {
     if ((strcasecmp(arg, "off") != 0) && (strcasecmp(arg, "none") != 0)) {
-        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server,
+        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00117)
               "Ignoring deprecated use of DefaultType in line %d of %s.",
                      cmd->directive->line_num, cmd->directive->filename);
     }
@@ -2009,6 +2221,11 @@ static const char *dirsection(cmd_parms *cmd, void *mconfig, const char *arg)
     conf->d = cmd->path;
     conf->d_is_fnmatch = (apr_fnmatch_test(conf->d) != 0);
 
+    if (r) {
+        conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *));
+        ap_regname(r, conf->refs, AP_REG_MATCH, 1);
+    }
+
     /* Make this explicit - the "/" root has 0 elements, that is, we
      * will always merge it, and it will always sort and merge first.
      * All others are sorted and tested by the number of slashes.
@@ -2085,6 +2302,11 @@ static const char *urlsection(cmd_parms *cmd, void *mconfig, const char *arg)
     conf->d_is_fnmatch = apr_fnmatch_test(conf->d) != 0;
     conf->r = r;
 
+    if (r) {
+        conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *));
+        ap_regname(r, conf->refs, AP_REG_MATCH, 1);
+    }
+
     ap_add_per_url_conf(cmd->server, new_url_conf);
 
     if (*arg != '\0') {
@@ -2167,6 +2389,11 @@ static const char *filesection(cmd_parms *cmd, void *mconfig, const char *arg)
     conf->d_is_fnmatch = apr_fnmatch_test(conf->d) != 0;
     conf->r = r;
 
+    if (r) {
+        conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *));
+        ap_regname(r, conf->refs, AP_REG_MATCH, 1);
+    }
+
     ap_add_file_conf(cmd->pool, (core_dir_config *)mconfig, new_file_conf);
 
     if (*arg != '\0') {
@@ -2179,6 +2406,11 @@ static const char *filesection(cmd_parms *cmd, void *mconfig, const char *arg)
 
     return NULL;
 }
+
+#define COND_IF      ((void *)1)
+#define COND_ELSE    ((void *)2)
+#define COND_ELSEIF  ((void *)3)
+
 static const char *ifsection(cmd_parms *cmd, void *mconfig, const char *arg)
 {
     const char *errmsg;
@@ -2187,7 +2419,7 @@ static const char *ifsection(cmd_parms *cmd, void *mconfig, const char *arg)
     char *old_path = cmd->path;
     core_dir_config *conf;
     const command_rec *thiscmd = cmd->cmd;
-    ap_conf_vector_t *new_file_conf = ap_create_per_dir_config(cmd->pool);
+    ap_conf_vector_t *new_if_conf = ap_create_per_dir_config(cmd->pool);
     const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
     const char *condition;
     const char *expr_err;
@@ -2202,27 +2434,44 @@ static const char *ifsection(cmd_parms *cmd, void *mconfig, const char *arg)
 
     arg = apr_pstrndup(cmd->temp_pool, arg, endp - arg);
 
-    if (!arg[0]) {
-        return missing_container_arg(cmd);
-    }
-
-    condition = ap_getword_conf(cmd->pool, &arg);
+    /*
+     * Set a dummy value so that other directives notice that they are inside
+     * a config section.
+     */
+    cmd->path = "*If";
     /* Only if not an .htaccess file */
     if (!old_path) {
         cmd->override = OR_ALL|ACCESS_CONF;
     }
 
     /* initialize our config and fetch it */
-    conf = ap_set_config_vectors(cmd->server, new_file_conf, cmd->path,
+    conf = ap_set_config_vectors(cmd->server, new_if_conf, cmd->path,
                                  &core_module, cmd->pool);
 
-    conf->condition = ap_expr_parse_cmd(cmd, condition, &expr_err, NULL);
-    if (expr_err) {
-        return apr_psprintf(cmd->pool, "Cannot parse condition clause: %s", expr_err);
+    if (cmd->cmd->cmd_data == COND_IF)
+        conf->condition_ifelse = AP_CONDITION_IF;
+    else if (cmd->cmd->cmd_data == COND_ELSEIF)
+        conf->condition_ifelse = AP_CONDITION_ELSEIF;
+    else if (cmd->cmd->cmd_data == COND_ELSE)
+        conf->condition_ifelse = AP_CONDITION_ELSE;
+    else
+        ap_assert(0);
+
+    if (conf->condition_ifelse == AP_CONDITION_ELSE) {
+        if (arg[0])
+            return "<Else> does not take an argument";
+    }
+    else {
+        if (!arg[0])
+            return missing_container_arg(cmd);
+        condition = ap_getword_conf(cmd->pool, &arg);
+        conf->condition = ap_expr_parse_cmd(cmd, condition, 0, &expr_err, NULL);
+        if (expr_err)
+            return apr_psprintf(cmd->pool, "Cannot parse condition clause: %s",
+                                expr_err);
     }
-    conf->condition->module_index = APLOG_MODULE_INDEX;
 
-    errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_file_conf);
+    errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_if_conf);
     if (errmsg != NULL)
         return errmsg;
 
@@ -2230,7 +2479,9 @@ static const char *ifsection(cmd_parms *cmd, void *mconfig, const char *arg)
     conf->d_is_fnmatch = 0;
     conf->r = NULL;
 
-    ap_add_if_conf(cmd->pool, (core_dir_config *)mconfig, new_file_conf);
+    errmsg = ap_add_if_conf(cmd->pool, (core_dir_config *)mconfig, new_if_conf);
+    if (errmsg != NULL)
+        return errmsg;
 
     if (*arg != '\0') {
         return apr_pstrcat(cmd->pool, "Multiple ", thiscmd->name,
@@ -2463,8 +2714,8 @@ static const char *set_accf_map(cmd_parms *cmd, void *dummy,
                                 const char *iproto, const char* iaccf)
 {
     const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
-    core_server_config *conf = ap_get_module_config(cmd->server->module_config,
-                                                    &core_module);
+    core_server_config *conf =
+        ap_get_core_module_config(cmd->server->module_config);
     char* proto;
     char* accf;
     if (err != NULL) {
@@ -2482,15 +2733,13 @@ static const char *set_accf_map(cmd_parms *cmd, void *dummy,
 
 AP_DECLARE(const char*) ap_get_server_protocol(server_rec* s)
 {
-    core_server_config *conf = ap_get_module_config(s->module_config,
-                                                    &core_module);
+    core_server_config *conf = ap_get_core_module_config(s->module_config);
     return conf->protocol;
 }
 
 AP_DECLARE(void) ap_set_server_protocol(server_rec* s, const char* proto)
 {
-    core_server_config *conf = ap_get_module_config(s->module_config,
-                                                    &core_module);
+    core_server_config *conf = ap_get_core_module_config(s->module_config);
     conf->protocol = proto;
 }
 
@@ -2498,8 +2747,8 @@ static const char *set_protocol(cmd_parms *cmd, void *dummy,
                                 const char *arg)
 {
     const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE);
-    core_server_config *conf = ap_get_module_config(cmd->server->module_config,
-                                                    &core_module);
+    core_server_config *conf =
+        ap_get_core_module_config(cmd->server->module_config);
     char* proto;
 
     if (err != NULL) {
@@ -2625,6 +2874,24 @@ static const char *set_server_root(cmd_parms *cmd, void *dummy,
     return NULL;
 }
 
+static const char *set_runtime_dir(cmd_parms *cmd, void *dummy, const char *arg)
+{
+    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+
+    if (err != NULL) {
+        return err;
+    }
+
+    if ((apr_filepath_merge((char**)&ap_runtime_dir, NULL,
+                            ap_server_root_relative(cmd->pool, arg),
+                            APR_FILEPATH_TRUENAME, cmd->pool) != APR_SUCCESS)
+        || !ap_is_directory(cmd->temp_pool, ap_runtime_dir)) {
+        return "DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot";
+    }
+
+    return NULL;
+}
+
 static const char *set_timeout(cmd_parms *cmd, void *dummy, const char *arg)
 {
     const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE);
@@ -2655,6 +2922,10 @@ static const char *set_allow2f(cmd_parms *cmd, void *d_, const char *arg)
                            cmd->cmd->name, " must be On, Off, or NoDecode",
                            NULL);
     }
+
+    d->allow_encoded_slashes_set = 1;
+    d->decode_encoded_slashes_set = 1;
+
     return NULL;
 }
 
@@ -2697,7 +2968,7 @@ static const char *set_content_md5(cmd_parms *cmd, void *d_, int arg)
 {
     core_dir_config *d = d_;
 
-    d->content_md5 = arg != 0;
+    d->content_md5 = arg ? AP_CONTENT_MD5_ON : AP_CONTENT_MD5_OFF;
     return NULL;
 }
 
@@ -2793,8 +3064,8 @@ static const char *include_config (cmd_parms *cmd, void *dummy,
                            name, NULL);
     }
 
-    error = ap_process_fnmatch_configs(cmd->server, conffile, &conftree, 
-                                       cmd->pool, cmd->temp_pool, 
+    error = ap_process_fnmatch_configs(cmd->server, conffile, &conftree,
+                                       cmd->pool, cmd->temp_pool,
                                        optional);
     if (error) {
         *recursion = 0;
@@ -2811,38 +3082,14 @@ static const char *include_config (cmd_parms *cmd, void *dummy,
     return NULL;
 }
 
-static const char *set_loglevel(cmd_parms *cmd, void *config_, const char *arg_)
+static const char *update_loglevel(cmd_parms *cmd, struct ap_logconf *log,
+                                   const char *arg)
 {
-    char *level_str;
-    int level;
+    const char *level_str, *err;
     module *module;
-    char *arg = apr_pstrdup(cmd->temp_pool, arg_);
-    struct ap_logconf *log;
-    const char *err;
-
-    /* XXX: what check is necessary here? */
-#if 0
-    const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE);
-    if (err != NULL) {
-        return err;
-    }
-#endif
-
-    if (cmd->path) {
-        core_dir_config *dconf = config_;
-        if (!dconf->log) {
-            dconf->log = ap_new_log_config(cmd->pool, NULL);
-        }
-        log = dconf->log;
-    }
-    else {
-        log = &cmd->server->log;
-    }
-
-    if (arg == NULL)
-        return "LogLevel requires level keyword or module loglevel specifier";
+    int level;
 
-    level_str = ap_strrchr(arg, ':');
+    level_str = ap_strrchr_c(arg, ':');
 
     if (level_str == NULL) {
         err = ap_parse_log_level(arg, &log->level);
@@ -2850,11 +3097,12 @@ static const char *set_loglevel(cmd_parms *cmd, void *config_, const char *arg_)
             return err;
         ap_reset_module_loglevels(log, APLOG_NO_MODULE);
         ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, cmd->server,
-                     "Setting LogLevel for all modules to %s", arg);
+                     "Setting %s for all modules to %s", cmd->cmd->name, arg);
         return NULL;
     }
 
-    *level_str++ = '\0';
+    arg = apr_pstrmemdup(cmd->temp_pool, arg, level_str - arg);
+    level_str++;
     if (!*level_str) {
         return apr_psprintf(cmd->temp_pool, "Module specifier '%s' must be "
                             "followed by a log level keyword", arg);
@@ -2877,9 +3125,64 @@ static const char *set_loglevel(cmd_parms *cmd, void *config_, const char *arg_)
 
     ap_set_module_loglevel(cmd->pool, log, module->module_index, level);
     ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, cmd->server,
-                 "Setting LogLevel for module %s to %s", module->name,
-                 level_str);
+                 "Setting %s for module %s to %s", cmd->cmd->name,
+                 module->name, level_str);
+
+    return NULL;
+}
+
+static const char *set_loglevel(cmd_parms *cmd, void *config_, const char *arg)
+{
+    struct ap_logconf *log;
+
+    if (cmd->path) {
+        core_dir_config *dconf = config_;
+        if (!dconf->log) {
+            dconf->log = ap_new_log_config(cmd->pool, NULL);
+        }
+        log = dconf->log;
+    }
+    else {
+        log = &cmd->server->log;
+    }
+
+    if (arg == NULL)
+        return "LogLevel requires level keyword or module loglevel specifier";
+
+    return update_loglevel(cmd, log, arg);
+}
 
+static const char *set_loglevel_override(cmd_parms *cmd, void *d_, int argc,
+                                         char *const argv[])
+{
+    core_server_config *sconf;
+    conn_log_config *entry;
+    int ret, i;
+    const char *addr, *mask, *err;
+
+    if (argc < 2)
+        return "LogLevelOverride requires at least two arguments";
+
+    entry = apr_pcalloc(cmd->pool, sizeof(conn_log_config));
+    sconf = ap_get_core_module_config(cmd->server->module_config);
+    if (!sconf->conn_log_level)
+        sconf->conn_log_level = apr_array_make(cmd->pool, 4, sizeof(entry));
+    APR_ARRAY_PUSH(sconf->conn_log_level, conn_log_config *) = entry;
+
+    addr = argv[0];
+    mask = ap_strchr_c(addr, '/');
+    if (mask) {
+        addr = apr_pstrmemdup(cmd->temp_pool, addr, mask - addr);
+        mask++;
+    }
+    ret = apr_ipsubnet_create(&entry->subnet, addr, mask, cmd->pool);
+    if (ret != APR_SUCCESS)
+        return "parsing of subnet/netmask failed";
+
+    for (i = 1; i < argc; i++) {
+        if ((err = update_loglevel(cmd, &entry->log, argv[i])) != NULL)
+            return err;
+    }
     return NULL;
 }
 
@@ -2888,8 +3191,7 @@ AP_DECLARE(const char *) ap_psignature(const char *prefix, request_rec *r)
     char sport[20];
     core_dir_config *conf;
 
-    conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
-                                                   &core_module);
+    conf = (core_dir_config *)ap_get_core_module_config(r->per_dir_config);
     if ((conf->server_signature == srv_sig_off)
             || (conf->server_signature == srv_sig_unset)) {
         return "";
@@ -2934,7 +3236,7 @@ enum server_token_type {
     SrvTk_MINIMAL,       /* eg: Apache/2.0.41 */
     SrvTk_OS,            /* eg: Apache/2.0.41 (UNIX) */
     SrvTk_FULL,          /* eg: Apache/2.0.41 (UNIX) PHP/4.2.2 FooBar/1.2b */
-    SrvTk_PRODUCT_ONLY  /* eg: Apache */
+    SrvTk_PRODUCT_ONLY   /* eg: Apache */
 };
 static enum server_token_type ap_server_tokens = SrvTk_FULL;
 
@@ -3025,7 +3327,7 @@ static void set_banner(apr_pool_t *pconf)
 }
 
 static const char *set_serv_tokens(cmd_parms *cmd, void *dummy,
-                                   const char *arg1, const char *arg2)
+                                   const char *arg)
 {
     const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
 
@@ -3033,24 +3335,27 @@ static const char *set_serv_tokens(cmd_parms *cmd, void *dummy,
         return err;
     }
 
-    if (!strcasecmp(arg1, "OS")) {
+    if (!strcasecmp(arg, "OS")) {
         ap_server_tokens = SrvTk_OS;
     }
-    else if (!strcasecmp(arg1, "Min") || !strcasecmp(arg1, "Minimal")) {
+    else if (!strcasecmp(arg, "Min") || !strcasecmp(arg, "Minimal")) {
         ap_server_tokens = SrvTk_MINIMAL;
     }
-    else if (!strcasecmp(arg1, "Major")) {
+    else if (!strcasecmp(arg, "Major")) {
         ap_server_tokens = SrvTk_MAJOR;
     }
-    else if (!strcasecmp(arg1, "Minor") ) {
+    else if (!strcasecmp(arg, "Minor") ) {
         ap_server_tokens = SrvTk_MINOR;
     }
-    else if (!strcasecmp(arg1, "Prod") || !strcasecmp(arg1, "ProductOnly")) {
+    else if (!strcasecmp(arg, "Prod") || !strcasecmp(arg, "ProductOnly")) {
         ap_server_tokens = SrvTk_PRODUCT_ONLY;
     }
-    else {
+    else if (!strcasecmp(arg, "Full")) {
         ap_server_tokens = SrvTk_FULL;
     }
+    else {
+        return "ServerTokens takes 1 argument: 'Prod(uctOnly)', 'Major', 'Minor', 'Min(imal)', 'OS', or 'Full'";
+    }
 
     return NULL;
 }
@@ -3145,22 +3450,100 @@ static const char *set_limit_xml_req_body(cmd_parms *cmd, void *conf_,
     return NULL;
 }
 
-AP_DECLARE(size_t) ap_get_limit_xml_body(const request_rec *r)
+static const char *set_max_ranges(cmd_parms *cmd, void *conf_, const char *arg)
+{
+    core_dir_config *conf = conf_;
+    int val = 0;
+
+    if (!strcasecmp(arg, "none")) {
+        val = AP_MAXRANGES_NORANGES;
+    }
+    else if (!strcasecmp(arg, "default")) {
+        val = AP_MAXRANGES_DEFAULT;
+    }
+    else if (!strcasecmp(arg, "unlimited")) {
+        val = AP_MAXRANGES_UNLIMITED;
+    }
+    else {
+        val = atoi(arg);
+        if (val <= 0)
+            return "MaxRanges requires 'none', 'default', 'unlimited' or "
+                   "a positive integer";
+    }
+
+    conf->max_ranges = val;
+
+    return NULL;
+}
+
+static const char *set_max_overlaps(cmd_parms *cmd, void *conf_, const char *arg)
+{
+    core_dir_config *conf = conf_;
+    int val = 0;
+
+    if (!strcasecmp(arg, "none")) {
+        val = AP_MAXRANGES_NORANGES;
+    }
+    else if (!strcasecmp(arg, "default")) {
+        val = AP_MAXRANGES_DEFAULT;
+    }
+    else if (!strcasecmp(arg, "unlimited")) {
+        val = AP_MAXRANGES_UNLIMITED;
+    }
+    else {
+        val = atoi(arg);
+        if (val <= 0)
+            return "MaxRangeOverlaps requires 'none', 'default', 'unlimited' or "
+            "a positive integer";
+    }
+
+    conf->max_overlaps = val;
+
+    return NULL;
+}
+
+static const char *set_max_reversals(cmd_parms *cmd, void *conf_, const char *arg)
+{
+    core_dir_config *conf = conf_;
+    int val = 0;
+
+    if (!strcasecmp(arg, "none")) {
+        val = AP_MAXRANGES_NORANGES;
+    }
+    else if (!strcasecmp(arg, "default")) {
+        val = AP_MAXRANGES_DEFAULT;
+    }
+    else if (!strcasecmp(arg, "unlimited")) {
+        val = AP_MAXRANGES_UNLIMITED;
+    }
+    else {
+        val = atoi(arg);
+        if (val <= 0)
+            return "MaxRangeReversals requires 'none', 'default', 'unlimited' or "
+            "a positive integer";
+    }
+
+    conf->max_reversals = val;
+
+    return NULL;
+}
+
+AP_DECLARE(apr_size_t) ap_get_limit_xml_body(const request_rec *r)
 {
     core_dir_config *conf;
 
-    conf = ap_get_module_config(r->per_dir_config, &core_module);
+    conf = ap_get_core_module_config(r->per_dir_config);
     if (conf->limit_xml_body == AP_LIMIT_UNSET)
         return AP_DEFAULT_LIMIT_XML_BODY;
 
-    return (size_t)conf->limit_xml_body;
+    return (apr_size_t)conf->limit_xml_body;
 }
 
 #if !defined (RLIMIT_CPU) || !(defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)) || !defined (RLIMIT_NPROC)
 static const char *no_set_limit(cmd_parms *cmd, void *conf_,
                                 const char *arg, const char *arg2)
 {
-    ap_log_error(APLOG_MARK, APLOG_ERR, 0, cmd->server,
+    ap_log_error(APLOG_MARK, APLOG_ERR, 0, cmd->server, APLOGNO(00118)
                 "%s not supported on this platform", cmd->cmd->name);
 
     return NULL;
@@ -3210,15 +3593,15 @@ static const char *set_limit_nproc(cmd_parms *cmd, void *conf_,
 static const char *set_recursion_limit(cmd_parms *cmd, void *dummy,
                                        const char *arg1, const char *arg2)
 {
-    core_server_config *conf = ap_get_module_config(cmd->server->module_config,
-                                                    &core_module);
+    core_server_config *conf =
+        ap_get_core_module_config(cmd->server->module_config);
     int limit = atoi(arg1);
 
     if (limit <= 0) {
         return "The recursion limit must be greater than zero.";
     }
     if (limit < 4) {
-        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server,
+        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00119)
                      "Limiting internal redirects to very low numbers may "
                      "cause normal requests to fail.");
     }
@@ -3232,7 +3615,7 @@ static const char *set_recursion_limit(cmd_parms *cmd, void *dummy,
             return "The recursion limit must be greater than zero.";
         }
         if (limit < 4) {
-            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server,
+            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00120)
                          "Limiting the subrequest depth to a very low level may"
                          " cause normal requests to fail.");
         }
@@ -3247,20 +3630,20 @@ static void log_backtrace(const request_rec *r)
 {
     const request_rec *top = r;
 
-    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
+    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00121)
                   "r->uri = %s", r->uri ? r->uri : "(unexpectedly NULL)");
 
     while (top && (top->prev || top->main)) {
         if (top->prev) {
             top = top->prev;
-            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
+            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00122)
                           "redirected from r->uri = %s",
                           top->uri ? top->uri : "(unexpectedly NULL)");
         }
 
         if (!top->prev && top->main) {
             top = top->main;
-            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
+            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00123)
                           "subrequested from r->uri = %s",
                           top->uri ? top->uri : "(unexpectedly NULL)");
         }
@@ -3272,8 +3655,8 @@ static void log_backtrace(const request_rec *r)
  */
 AP_DECLARE(int) ap_is_recursion_limit_exceeded(const request_rec *r)
 {
-    core_server_config *conf = ap_get_module_config(r->server->module_config,
-                                                    &core_module);
+    core_server_config *conf =
+        ap_get_core_module_config(r->server->module_config);
     const request_rec *top = r;
     int redirects = 0, subreqs = 0;
     int rlimit = conf->redirect_limit
@@ -3288,7 +3671,7 @@ AP_DECLARE(int) ap_is_recursion_limit_exceeded(const request_rec *r)
         if (top->prev) {
             if (++redirects >= rlimit) {
                 /* uuh, too much. */
-                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00124)
                               "Request exceeded the limit of %d internal "
                               "redirects due to probable configuration error. "
                               "Use 'LimitInternalRecursion' to increase the "
@@ -3308,7 +3691,7 @@ AP_DECLARE(int) ap_is_recursion_limit_exceeded(const request_rec *r)
         if (!top->prev && top->main) {
             if (++subreqs >= slimit) {
                 /* uuh, too much. */
-                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00125)
                               "Request exceeded the limit of %d subrequest "
                               "nesting levels due to probable configuration "
                               "error. Use 'LimitInternalRecursion' to increase "
@@ -3333,8 +3716,8 @@ AP_DECLARE(int) ap_is_recursion_limit_exceeded(const request_rec *r)
 static const char *set_trace_enable(cmd_parms *cmd, void *dummy,
                                     const char *arg1)
 {
-    core_server_config *conf = ap_get_module_config(cmd->server->module_config,
-                                                    &core_module);
+    core_server_config *conf =
+        ap_get_core_module_config(cmd->server->module_config);
 
     if (strcasecmp(arg1, "on") == 0) {
         conf->trace_enable = AP_TRACE_ENABLE;
@@ -3352,6 +3735,77 @@ static const char *set_trace_enable(cmd_parms *cmd, void *dummy,
     return NULL;
 }
 
+static const char *set_http_protocol(cmd_parms *cmd, void *dummy,
+                                     const char *arg)
+{
+    core_server_config *conf =
+        ap_get_core_module_config(cmd->server->module_config);
+
+    if (strncmp(arg, "min=", 4) == 0) {
+        arg += 4;
+        if (strcmp(arg, "0.9") == 0)
+            conf->http09_enable = AP_HTTP09_ENABLE;
+        else if (strcmp(arg, "1.0") == 0)
+            conf->http09_enable = AP_HTTP09_DISABLE;
+        else
+            return "HttpProtocol 'min' must be one of '0.9' and '1.0'";
+        return NULL;
+    }
+
+    if (strcmp(arg, "strict") == 0)
+        conf->http_conformance = AP_HTTP_CONFORMANCE_STRICT;
+    else if (strcmp(arg, "strict,log-only") == 0)
+        conf->http_conformance = AP_HTTP_CONFORMANCE_STRICT|
+                                 AP_HTTP_CONFORMANCE_LOGONLY;
+    else if (strcmp(arg, "liberal") == 0)
+        conf->http_conformance = AP_HTTP_CONFORMANCE_LIBERAL;
+    else
+        return "HttpProtocol accepts 'min=0.9', 'min=1.0', 'liberal', "
+               "'strict', 'strict,log-only'";
+
+    if ((conf->http_conformance & AP_HTTP_CONFORMANCE_STRICT) &&
+        (conf->http_conformance & AP_HTTP_CONFORMANCE_LIBERAL)) {
+        return "HttpProtocol 'strict' and 'liberal' are mutually exclusive";
+    }
+
+    return NULL;
+}
+
+static const char *set_http_method(cmd_parms *cmd, void *conf, const char *arg)
+{
+    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+    if (err != NULL)
+        return err;
+    ap_method_register(cmd->pool, arg);
+    return NULL;
+}
+
+static const char *set_cl_head_zero(cmd_parms *cmd, void *dummy, int arg)
+{
+    core_server_config *conf =
+        ap_get_core_module_config(cmd->server->module_config);
+
+    if (arg) {
+        conf->http_cl_head_zero = AP_HTTP_CL_HEAD_ZERO_ENABLE;
+    } else {
+        conf->http_cl_head_zero = AP_HTTP_CL_HEAD_ZERO_DISABLE;
+    }
+    return NULL;
+}
+
+static const char *set_expect_strict(cmd_parms *cmd, void *dummy, int arg)
+{
+    core_server_config *conf =
+        ap_get_core_module_config(cmd->server->module_config);
+
+    if (arg) {
+        conf->http_expect_strict = AP_HTTP_EXPECT_STRICT_ENABLE;
+    } else {
+        conf->http_expect_strict = AP_HTTP_EXPECT_STRICT_DISABLE;
+    }
+    return NULL;
+}
+
 static apr_hash_t *errorlog_hash;
 
 static int log_constant_item(const ap_errorlog_info *info, const char *arg,
@@ -3531,12 +3985,12 @@ static apr_array_header_t *parse_errorlog_string(apr_pool_t *p,
             *err = "The '+' flag cannot be used in the main error log format";
             return NULL;
         }
-       if (!is_main_fmt && item->min_loglevel) {
+        if (!is_main_fmt && item->min_loglevel) {
             *err = "The loglevel cannot be used as a condition in "
-                  "once-per-request or once-per-connection formats";
+                   "once-per-request or once-per-connection formats";
             return NULL;
         }
-       if (item->min_loglevel > APLOG_TRACE8) {
+        if (item->min_loglevel > APLOG_TRACE8) {
             *err = "The specified loglevel modifier is out of range";
             return NULL;
         }
@@ -3550,12 +4004,61 @@ static apr_array_header_t *parse_errorlog_string(apr_pool_t *p,
     return a;
 }
 
+static const char *set_errorlog(cmd_parms *cmd, void *dummy, const char *arg1,
+                                const char *arg2)
+{
+    ap_errorlog_provider *provider;
+    const char *err;
+    cmd->server->errorlog_provider = NULL;
+
+    if (!arg2) {
+        /* Stay backward compatible and check for "syslog" */
+        if (strncmp("syslog", arg1, 6) == 0) {
+            arg2 = arg1 + 7; /* skip the ':' if any */
+            arg1 = "syslog";
+        }
+        else {
+            /* Admin can define only "ErrorLog provider" and we should 
+             * still handle that using the defined provider, but with empty
+             * error_fname. */
+            provider = ap_lookup_provider(AP_ERRORLOG_PROVIDER_GROUP, arg1,
+                                          AP_ERRORLOG_PROVIDER_VERSION);
+            if (provider) {
+                arg2 = "";
+            }
+            else {
+                return set_server_string_slot(cmd, dummy, arg1);
+            }
+        }
+    }
+
+    if (strcmp("file", arg1) == 0) {
+        return set_server_string_slot(cmd, dummy, arg2);
+    }
+
+    provider = ap_lookup_provider(AP_ERRORLOG_PROVIDER_GROUP, arg1,
+                                    AP_ERRORLOG_PROVIDER_VERSION);
+    if (!provider) {
+        return apr_psprintf(cmd->pool,
+                            "Unknown ErrorLog provider: %s",
+                            arg1);
+    }
+
+    err = provider->parse_errorlog_arg(cmd, arg2);
+    if (err) {
+        return err;
+    }
+
+    cmd->server->errorlog_provider = provider;
+    return set_server_string_slot(cmd, dummy, arg2);
+}
+
 static const char *set_errorlog_format(cmd_parms *cmd, void *dummy,
                                        const char *arg1, const char *arg2)
 {
     const char *err_string = NULL;
-    core_server_config *conf = ap_get_module_config(cmd->server->module_config,
-                                                    &core_module);
+    core_server_config *conf =
+        ap_get_core_module_config(cmd->server->module_config);
 
     if (!arg2) {
         conf->error_log_format = parse_errorlog_string(cmd->pool, arg1,
@@ -3654,9 +4157,15 @@ AP_INIT_TAKE12("Define", set_define, NULL, EXEC_ON_READ|ACCESS_CONF|RSRC_CONF,
               "Define a variable, optionally to a value.  Same as passing -D to the command line."),
 AP_INIT_TAKE1("UnDefine", unset_define, NULL, EXEC_ON_READ|ACCESS_CONF|RSRC_CONF,
               "Undefine the existence of a variable. Undo a Define."),
-AP_INIT_RAW_ARGS("Error", generate_error, NULL, OR_ALL,
-                 "Generate error message from within configuration"),
-AP_INIT_RAW_ARGS("<If", ifsection, NULL, OR_ALL,
+AP_INIT_RAW_ARGS("Error", generate_message, (void*) APLOG_ERR, OR_ALL,
+                 "Generate error message from within configuration."),
+AP_INIT_RAW_ARGS("Warning", generate_message, (void*) APLOG_WARNING, OR_ALL,
+                 "Generate warning message from within configuration."),
+AP_INIT_RAW_ARGS("<If", ifsection, COND_IF, OR_ALL,
+  "Container for directives to be conditionally applied"),
+AP_INIT_RAW_ARGS("<ElseIf", ifsection, COND_ELSEIF, OR_ALL,
+  "Container for directives to be conditionally applied"),
+AP_INIT_RAW_ARGS("<Else", ifsection, COND_ELSE, OR_ALL,
   "Container for directives to be conditionally applied"),
 
 /* Old resource config file commands */
@@ -3670,6 +4179,9 @@ AP_INIT_TAKE2("ErrorDocument", set_error_document, NULL, OR_FILEINFO,
 AP_INIT_RAW_ARGS("AllowOverride", set_override, NULL, ACCESS_CONF,
   "Controls what groups of directives can be configured by per-directory "
   "config files"),
+AP_INIT_TAKE_ARGV("AllowOverrideList", set_override_list, NULL, ACCESS_CONF,
+  "Controls what individual directives can be configured by per-directory "
+  "config files"),
 AP_INIT_RAW_ARGS("Options", set_options, NULL, OR_OPTIONS,
   "Set a number of attributes for a given directory"),
 AP_INIT_TAKE1("DefaultType", set_default_type, NULL, OR_FILEINFO,
@@ -3702,7 +4214,9 @@ AP_INIT_TAKE1("ServerSignature", set_signature_flag, NULL, OR_ALL,
   "En-/disable server signature (on|off|email)"),
 AP_INIT_TAKE1("ServerRoot", set_server_root, NULL, RSRC_CONF | EXEC_ON_READ,
   "Common directory of server-related files (logs, confs, etc.)"),
-AP_INIT_TAKE1("ErrorLog", set_server_string_slot,
+AP_INIT_TAKE1("DefaultRuntimeDir", set_runtime_dir, NULL, RSRC_CONF | EXEC_ON_READ,
+  "Common directory for run-time files (shared memory, locks, etc.)"),
+AP_INIT_TAKE12("ErrorLog", set_errorlog,
   (void *)APR_OFFSETOF(server_rec, error_fname), RSRC_CONF,
   "The filename of the error log"),
 AP_INIT_TAKE12("ErrorLogFormat", set_errorlog_format, NULL, RSRC_CONF,
@@ -3733,11 +4247,13 @@ AP_INIT_TAKE1("IncludeOptional", include_config, (void*)1,
   "does not exist or the pattern does not match any files"),
 AP_INIT_ITERATE("LogLevel", set_loglevel, NULL, RSRC_CONF|ACCESS_CONF,
   "Level of verbosity in error logging"),
+AP_INIT_TAKE_ARGV("LogLevelOverride", set_loglevel_override, NULL, RSRC_CONF,
+  "Override LogLevel for clients with certain IPs"),
 AP_INIT_TAKE1("NameVirtualHost", ap_set_name_virtual_host, NULL, RSRC_CONF,
   "A numeric IP address:port, or the name of a host"),
-AP_INIT_TAKE12("ServerTokens", set_serv_tokens, NULL, RSRC_CONF,
+AP_INIT_TAKE1("ServerTokens", set_serv_tokens, NULL, RSRC_CONF,
   "Determine tokens displayed in the Server: header - Min(imal), "
-  "Major, Minor, Prod, OS or Full"),
+  "Major, Minor, Prod(uctOnly), OS, or Full"),
 AP_INIT_TAKE1("LimitRequestLine", set_limit_req_line, NULL, RSRC_CONF,
   "Limit on maximum size of an HTTP request line"),
 AP_INIT_TAKE1("LimitRequestFieldsize", set_limit_req_fieldsize, NULL,
@@ -3754,6 +4270,15 @@ AP_INIT_TAKE1("LimitXMLRequestBody", set_limit_xml_req_body, NULL, OR_ALL,
 AP_INIT_RAW_ARGS("Mutex", ap_set_mutex, NULL, RSRC_CONF,
                  "mutex (or \"default\") and mechanism"),
 
+AP_INIT_TAKE1("MaxRanges", set_max_ranges, NULL, RSRC_CONF|ACCESS_CONF,
+              "Maximum number of Ranges in a request before returning the entire "
+              "resource, or 0 for unlimited"),
+AP_INIT_TAKE1("MaxRangeOverlaps", set_max_overlaps, NULL, RSRC_CONF|ACCESS_CONF,
+              "Maximum number of overlaps in Ranges in a request before returning the entire "
+              "resource, or 0 for unlimited"),
+AP_INIT_TAKE1("MaxRangeReversals", set_max_reversals, NULL, RSRC_CONF|ACCESS_CONF,
+              "Maximum number of reversals in Ranges in a request before returning the entire "
+              "resource, or 0 for unlimited"),
 /* System Resource Controls */
 #ifdef RLIMIT_CPU
 AP_INIT_TAKE12("RLimitCPU", set_limit_cpu,
@@ -3824,7 +4349,7 @@ AP_INIT_TAKE1("MaxConnectionsPerChild", ap_mpm_set_max_requests, NULL, RSRC_CONF
 AP_INIT_TAKE1("CoreDumpDirectory", ap_mpm_set_coredumpdir, NULL, RSRC_CONF,
               "The location of the directory Apache changes to before dumping core"),
 AP_INIT_TAKE1("MaxMemFree", ap_mpm_set_max_mem_free, NULL, RSRC_CONF,
-              "Maximum number of 1k blocks a particular childs allocator may hold."),
+              "Maximum number of 1k blocks a particular child's allocator may hold."),
 AP_INIT_TAKE1("ThreadStackSize", ap_mpm_set_thread_stacksize, NULL, RSRC_CONF,
               "Size in bytes of stack used by threads handling client connections"),
 #if AP_ENABLE_EXCEPTION_HOOK
@@ -3833,6 +4358,15 @@ AP_INIT_TAKE1("EnableExceptionHook", ap_mpm_set_exception_hook, NULL, RSRC_CONF,
 #endif
 AP_INIT_TAKE1("TraceEnable", set_trace_enable, NULL, RSRC_CONF,
               "'on' (default), 'off' or 'extended' to trace request body content"),
+AP_INIT_ITERATE("HttpProtocol", set_http_protocol, NULL, RSRC_CONF,
+              "'min=0.9' (default) or 'min=1.0' to allow/deny HTTP/0.9; "
+              "'liberal', 'strict', 'strict,log-only'"),
+AP_INIT_ITERATE("RegisterHttpMethod", set_http_method, NULL, RSRC_CONF,
+                "Registers non-standard HTTP methods"),
+AP_INIT_FLAG("HttpContentLengthHeadZero", set_cl_head_zero, NULL, OR_OPTIONS,
+  "whether to permit Content-Length of 0 responses to HEAD requests"),
+AP_INIT_FLAG("HttpExpectStrict", set_expect_strict, NULL, OR_OPTIONS,
+  "whether to return a 417 if a client doesn't send 100-Continue"),
 { NULL }
 };
 
@@ -3843,9 +4377,8 @@ AP_INIT_TAKE1("TraceEnable", set_trace_enable, NULL, RSRC_CONF,
 
 AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r)
 {
-    void *sconf = r->server->module_config;
-    core_server_config *conf = ap_get_module_config(sconf, &core_module);
     apr_status_t rv;
+    char *path;
 
     /* XXX this seems too specific, this should probably become
      * some general-case test
@@ -3854,7 +4387,7 @@ AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r)
         return HTTP_FORBIDDEN;
     }
     if (!r->uri || ((r->uri[0] != '/') && strcmp(r->uri, "*"))) {
-        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00126)
                      "Invalid URI in request %s", r->the_request);
         return HTTP_BAD_REQUEST;
     }
@@ -3865,46 +4398,31 @@ AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r)
             || r->uri[r->server->pathlen] == '/'
             || r->uri[r->server->pathlen] == '\0'))
     {
-        /* skip all leading /'s (e.g. http://localhost///foo)
-         * so we are looking at only the relative path.
-         */
-        char *path = r->uri + r->server->pathlen;
-        while (*path == '/') {
-            ++path;
-        }
-        if ((rv = apr_filepath_merge(&r->filename, conf->ap_document_root, path,
-                                     APR_FILEPATH_TRUENAME
-                                   | APR_FILEPATH_SECUREROOT, r->pool))
-                    != APR_SUCCESS) {
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
-                         "Cannot map %s to file", r->the_request);
-            return HTTP_FORBIDDEN;
-        }
-        r->canonical_filename = r->filename;
+        path = r->uri + r->server->pathlen;
     }
     else {
-        /*
-         * Make sure that we do not mess up the translation by adding two
-         * /'s in a row.  This happens under windows when the document
-         * root ends with a /
-         */
-        /* skip all leading /'s (e.g. http://localhost///foo)
-         * so we are looking at only the relative path.
-         */
-        char *path = r->uri;
-        while (*path == '/') {
-            ++path;
-        }
-        if ((rv = apr_filepath_merge(&r->filename, conf->ap_document_root, path,
-                                     APR_FILEPATH_TRUENAME
-                                   | APR_FILEPATH_SECUREROOT, r->pool))
-                    != APR_SUCCESS) {
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
-                         "Cannot map %s to file", r->the_request);
-            return HTTP_FORBIDDEN;
-        }
-        r->canonical_filename = r->filename;
+        path = r->uri;
     }
+    /*
+     * Make sure that we do not mess up the translation by adding two
+     * /'s in a row.  This happens under windows when the document
+     * root ends with a /
+     */
+    /* skip all leading /'s (e.g. http://localhost///foo)
+     * so we are looking at only the relative path.
+     */
+    while (*path == '/') {
+        ++path;
+    }
+    if ((rv = apr_filepath_merge(&r->filename, ap_document_root(r), path,
+                                 APR_FILEPATH_TRUENAME
+                               | APR_FILEPATH_SECUREROOT, r->pool))
+                != APR_SUCCESS) {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00127)
+                     "Cannot map %s to file", r->the_request);
+        return HTTP_FORBIDDEN;
+    }
+    r->canonical_filename = r->filename;
 
     return OK;
 }
@@ -3935,8 +4453,7 @@ static int do_nothing(request_rec *r) { return OK; }
 static int core_override_type(request_rec *r)
 {
     core_dir_config *conf =
-        (core_dir_config *)ap_get_module_config(r->per_dir_config,
-                                                &core_module);
+        (core_dir_config *)ap_get_core_module_config(r->per_dir_config);
 
     /* Check for overrides with ForceType / SetHandler
      */
@@ -3952,9 +4469,9 @@ static int core_override_type(request_rec *r)
      * beginning of the fixup phase (here!), so modules should override the user's
      * discretion in their own module fixup phase.  It is tristate, if
      * the user doesn't specify, the result is AP_REQ_DEFAULT_PATH_INFO.
-     * (which the module may interpret to its own customary behavior.)  
+     * (which the module may interpret to its own customary behavior.)
      * It won't be touched if the value is no longer AP_ACCEPT_PATHINFO_UNSET,
-     * so any module changing the value prior to the fixup phase 
+     * so any module changing the value prior to the fixup phase
      * OVERRIDES the user's choice.
      */
     if ((r->used_path_info == AP_REQ_DEFAULT_PATH_INFO)
@@ -3984,9 +4501,8 @@ static int default_handler(request_rec *r)
      */
     int bld_content_md5;
 
-    d = (core_dir_config *)ap_get_module_config(r->per_dir_config,
-                                                &core_module);
-    bld_content_md5 = (d->content_md5 & 1)
+    d = (core_dir_config *)ap_get_core_module_config(r->per_dir_config);
+    bld_content_md5 = (d->content_md5 == AP_CONTENT_MD5_ON)
                       && r->output_filters->frec->ftype != AP_FTYPE_RESOURCE;
 
     ap_allow_standard_methods(r, MERGE_ALLOW, M_GET, M_OPTIONS, M_POST, -1);
@@ -4002,8 +4518,9 @@ static int default_handler(request_rec *r)
 
     if (r->method_number == M_GET || r->method_number == M_POST) {
         if (r->finfo.filetype == APR_NOFILE) {
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
-                          "File does not exist: %s", r->filename);
+            ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00128)
+                          "File does not exist: %s",
+                          apr_pstrcat(r->pool, r->filename, r->path_info, NULL));
             return HTTP_NOT_FOUND;
         }
 
@@ -4011,7 +4528,7 @@ static int default_handler(request_rec *r)
          * raw I/O on a dir.
          */
         if (r->finfo.filetype == APR_DIR) {
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+            ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00129)
                           "Attempt to serve directory: %s", r->filename);
             return HTTP_NOT_FOUND;
         }
@@ -4020,7 +4537,7 @@ static int default_handler(request_rec *r)
             r->path_info && *r->path_info)
         {
             /* default to reject */
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+            ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00130)
                           "File does not exist: %s",
                           apr_pstrcat(r->pool, r->filename, r->path_info, NULL));
             return HTTP_NOT_FOUND;
@@ -4037,10 +4554,10 @@ static int default_handler(request_rec *r)
         if (r->method_number != M_GET) {
             core_request_config *req_cfg;
 
-            req_cfg = ap_get_module_config(r->request_config, &core_module);
+            req_cfg = ap_get_core_module_config(r->request_config);
             if (!req_cfg->deliver_script) {
                 /* The flag hasn't been set for this request. Punt. */
-                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00131)
                               "This resource does not accept the %s method.",
                               r->method);
                 return HTTP_METHOD_NOT_ALLOWED;
@@ -4053,7 +4570,7 @@ static int default_handler(request_rec *r)
                             | AP_SENDFILE_ENABLED(d->enable_sendfile)
 #endif
                                     , 0, r->pool)) != APR_SUCCESS) {
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r,
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00132)
                           "file permissions deny server access: %s", r->filename);
             return HTTP_FORBIDDEN;
         }
@@ -4061,7 +4578,7 @@ static int default_handler(request_rec *r)
         ap_update_mtime(r, r->finfo.mtime);
         ap_set_last_modified(r);
         ap_set_etag(r);
-        apr_table_setn(r->headers_out, "Accept-Ranges", "bytes");
+        ap_set_accept_ranges(r);
         ap_set_content_length(r, r->finfo.size);
         if (bld_content_md5) {
             apr_table_setn(r->headers_out, "Content-MD5",
@@ -4095,7 +4612,7 @@ static int default_handler(request_rec *r)
         }
         else {
             /* no way to know what type of error occurred */
-            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r,
+            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00133)
                           "default_handler: ap_pass_brigade returned %i",
                           status);
             return HTTP_INTERNAL_SERVER_ERROR;
@@ -4108,12 +4625,12 @@ static int default_handler(request_rec *r)
              * always allocated at least MIN_LINE_ALLOC (80) bytes.
              */
             if (r->the_request
-                && r->the_request[0] == 0x16                                
+                && r->the_request[0] == 0x16
                 && (r->the_request[1] == 0x2 || r->the_request[1] == 0x3)) {
-                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00134)
                               "Invalid method in request %s - possible attempt to establish SSL connection on non-SSL port", r->the_request);
             } else {
-                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00135)
                               "Invalid method in request %s", r->the_request);
             }
             return HTTP_NOT_IMPLEMENTED;
@@ -4142,6 +4659,45 @@ AP_DECLARE(int) ap_sys_privileges_handlers(int inc)
     return sys_privileges;
 }
 
+static int check_errorlog_dir(apr_pool_t *p, server_rec *s)
+{
+    if (!s->error_fname || s->error_fname[0] == '|'
+        || s->errorlog_provider != NULL) {
+        return APR_SUCCESS;
+    }
+    else {
+        char *abs = ap_server_root_relative(p, s->error_fname);
+        char *dir = ap_make_dirstr_parent(p, abs);
+        apr_finfo_t finfo;
+        apr_status_t rv = apr_stat(&finfo, dir, APR_FINFO_TYPE, p);
+        if (rv == APR_SUCCESS && finfo.filetype != APR_DIR)
+            rv = APR_ENOTDIR;
+        if (rv != APR_SUCCESS) {
+            const char *desc = "main error log";
+            if (s->defn_name)
+                desc = apr_psprintf(p, "error log of vhost defined at %s:%d",
+                                    s->defn_name, s->defn_line_number);
+            ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_EMERG, rv,
+                          ap_server_conf, APLOGNO(02291)
+                         "Cannot access directory '%s' for %s", dir, desc);
+            return !OK;
+        }
+    }
+    return OK;
+}
+
+static int core_check_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
+{
+    int rv = OK;
+    while (s) {
+        if (check_errorlog_dir(ptemp, s) != OK)
+            rv = !OK;
+        s = s->next;
+    }
+    return rv;
+}
+
+
 static int core_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
 {
     ap_mutex_init(pconf);
@@ -4153,7 +4709,7 @@ static int core_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptem
 
     mpm_common_pre_config(pconf);
 
-    return APR_SUCCESS;
+    return OK;
 }
 
 static int core_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
@@ -4169,20 +4725,21 @@ static int core_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *pte
     ap_setup_make_content_type(pconf);
     ap_setup_auth_internal(ptemp);
     if (!sys_privileges) {
-        ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL,
+        ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL, APLOGNO(00136)
                      "Server MUST relinquish startup privileges before "
                      "accepting connections.  Please ensure mod_unixd "
                      "or other system security module is loaded.");
         return !OK;
     }
+    apr_pool_cleanup_register(pconf, NULL, ap_mpm_end_gen_helper,
+                              apr_pool_cleanup_null);
     return OK;
 }
 
 static void core_insert_filter(request_rec *r)
 {
     core_dir_config *conf = (core_dir_config *)
-                            ap_get_module_config(r->per_dir_config,
-                                                 &core_module);
+                            ap_get_core_module_config(r->per_dir_config);
     const char *filter, *filters = conf->output_filters;
 
     if (filters) {
@@ -4223,7 +4780,7 @@ AP_DECLARE(void **) ap_get_request_note(request_rec *r, apr_size_t note_num)
     }
 
     req_cfg = (core_request_config *)
-        ap_get_module_config(r->request_config, &core_module);
+        ap_get_core_module_config(r->request_config);
 
     if (!req_cfg) {
         return NULL;
@@ -4232,6 +4789,11 @@ AP_DECLARE(void **) ap_get_request_note(request_rec *r, apr_size_t note_num)
     return &(req_cfg->notes[note_num]);
 }
 
+AP_DECLARE(apr_socket_t *) ap_get_conn_socket(conn_rec *c)
+{
+    return ap_get_core_module_config(c->conn_config);
+}
+
 static int core_create_req(request_rec *r)
 {
     /* Alloc the config struct and the array of request notes in
@@ -4248,14 +4810,14 @@ static int core_create_req(request_rec *r)
 
     if (r->main) {
         core_request_config *main_req_cfg = (core_request_config *)
-            ap_get_module_config(r->main->request_config, &core_module);
+            ap_get_core_module_config(r->main->request_config);
         req_cfg->bb = main_req_cfg->bb;
     }
     else {
         req_cfg->bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
     }
 
-    ap_set_module_config(r->request_config, &core_module, req_cfg);
+    ap_set_core_module_config(r->request_config, req_cfg);
 
     return OK;
 }
@@ -4265,12 +4827,14 @@ static int core_create_proxy_req(request_rec *r, request_rec *pr)
     return core_create_req(pr);
 }
 
-static conn_rec *core_create_conn(apr_pool_t *ptrans, server_rec *server,
+static conn_rec *core_create_conn(apr_pool_t *ptrans, server_rec *s,
                                   apr_socket_t *csd, long id, void *sbh,
                                   apr_bucket_alloc_t *alloc)
 {
     apr_status_t rv;
+    apr_pool_t *pool;
     conn_rec *c = (conn_rec *) apr_pcalloc(ptrans, sizeof(conn_rec));
+    core_server_config *sconf = ap_get_core_module_config(s->module_config);
 
     c->sbh = sbh;
     (void)ap_update_child_status(c->sbh, SERVER_BUSY_READ, (request_rec *)NULL);
@@ -4278,42 +4842,58 @@ static conn_rec *core_create_conn(apr_pool_t *ptrans, server_rec *server,
     /* Got a connection structure, so initialize what fields we can
      * (the rest are zeroed out by pcalloc).
      */
-    c->conn_config = ap_create_conn_config(ptrans);
-    c->notes = apr_table_make(ptrans, 5);
+    apr_pool_create(&pool, ptrans);
+    apr_pool_tag(pool, "master_conn");
+    c->pool = pool;
+
+    c->conn_config = ap_create_conn_config(c->pool);
+    c->notes = apr_table_make(c->pool, 5);
+    c->slaves = apr_array_make(c->pool, 20, sizeof(conn_slave_rec *));
+
 
-    c->pool = ptrans;
     if ((rv = apr_socket_addr_get(&c->local_addr, APR_LOCAL, csd))
         != APR_SUCCESS) {
-        ap_log_error(APLOG_MARK, APLOG_INFO, rv, server,
+        ap_log_error(APLOG_MARK, APLOG_INFO, rv, s, APLOGNO(00137)
                      "apr_socket_addr_get(APR_LOCAL)");
         apr_socket_close(csd);
         return NULL;
     }
 
     apr_sockaddr_ip_get(&c->local_ip, c->local_addr);
-    if ((rv = apr_socket_addr_get(&c->remote_addr, APR_REMOTE, csd))
+    if ((rv = apr_socket_addr_get(&c->client_addr, APR_REMOTE, csd))
         != APR_SUCCESS) {
-        ap_log_error(APLOG_MARK, APLOG_INFO, rv, server,
+        ap_log_error(APLOG_MARK, APLOG_INFO, rv, s, APLOGNO(00138)
                      "apr_socket_addr_get(APR_REMOTE)");
         apr_socket_close(csd);
         return NULL;
     }
 
-    apr_sockaddr_ip_get(&c->remote_ip, c->remote_addr);
-    c->base_server = server;
+    apr_sockaddr_ip_get(&c->client_ip, c->client_addr);
+    c->base_server = s;
 
     c->id = id;
     c->bucket_alloc = alloc;
 
-    c->cs = (conn_state_t *)apr_pcalloc(ptrans, sizeof(conn_state_t));
-    APR_RING_INIT(&(c->cs->timeout_list), conn_state_t, timeout_list);
-    c->cs->expiration_time = 0;
-    c->cs->state = CONN_STATE_CHECK_REQUEST_LINE_READABLE;
-    c->cs->c = c;
-    c->cs->p = ptrans;
-    c->cs->bucket_alloc = alloc;
     c->clogging_input_filters = 0;
 
+    if (sconf->conn_log_level) {
+        int i;
+        conn_log_config *conf;
+        const struct ap_logconf *log = NULL;
+        struct ap_logconf *merged;
+
+        for (i = 0; i < sconf->conn_log_level->nelts; i++) {
+            conf = APR_ARRAY_IDX(sconf->conn_log_level, i, conn_log_config *);
+            if (apr_ipsubnet_test(conf->subnet, c->client_addr))
+                log = &conf->log;
+        }
+        if (log) {
+            merged = ap_new_log_config(c->pool, log);
+            ap_merge_log_config(&s->log, merged);
+            c->log = merged;
+        }
+    }
+
     return c;
 }
 
@@ -4334,7 +4914,7 @@ static int core_pre_connection(conn_rec *c, void *csd)
         /* expected cause is that the client disconnected already,
          * hence the debug level
          */
-        ap_log_cerror(APLOG_MARK, APLOG_DEBUG, rv, c,
+        ap_log_cerror(APLOG_MARK, APLOG_DEBUG, rv, c, APLOGNO(00139)
                       "apr_socket_opt_set(APR_TCP_NODELAY)");
     }
 
@@ -4347,7 +4927,7 @@ static int core_pre_connection(conn_rec *c, void *csd)
     rv = apr_socket_timeout_set(csd, c->base_server->timeout);
     if (rv != APR_SUCCESS) {
         /* expected cause is that the client disconnected already */
-        ap_log_cerror(APLOG_MARK, APLOG_DEBUG, rv, c,
+        ap_log_cerror(APLOG_MARK, APLOG_DEBUG, rv, c, APLOGNO(00140)
                       "apr_socket_timeout_set");
     }
 
@@ -4356,12 +4936,36 @@ static int core_pre_connection(conn_rec *c, void *csd)
     net->out_ctx = NULL;
     net->client_socket = csd;
 
-    ap_set_module_config(net->c->conn_config, &core_module, csd);
-    ap_add_input_filter_handle(ap_core_input_filter_handle, net, NULL, net->c);
-    ap_add_output_filter_handle(ap_core_output_filter_handle, net, NULL, net->c);
+    ap_set_core_module_config(net->c->conn_config, csd);
+    /* only the master connection talks to the network */
+    if (c->master == NULL) {
+        ap_add_input_filter_handle(ap_core_input_filter_handle, net, NULL,
+                                   net->c);
+        ap_add_output_filter_handle(ap_core_output_filter_handle, net, NULL,
+                                    net->c);
+    }
     return DONE;
 }
 
+AP_CORE_DECLARE(conn_rec *) ap_create_slave_connection(conn_rec *c)
+{
+    apr_pool_t *pool;
+    conn_slave_rec *new;
+    conn_rec *sc = (conn_rec *) apr_palloc(c->pool, sizeof(conn_rec));
+
+    apr_pool_create(&pool, c->pool);
+    apr_pool_tag(pool, "slave_conn");
+    memcpy(sc, c, sizeof(conn_rec));
+    sc->slaves = NULL;
+    sc->master = c;
+    sc->input_filters = NULL;
+    sc->output_filters = NULL;
+    sc->pool = pool;
+    new = apr_array_push(c->slaves);
+    new->c = sc;
+    return sc;
+}
+
 AP_DECLARE(int) ap_state_query(int query)
 {
     switch (query) {
@@ -4376,15 +4980,179 @@ AP_DECLARE(int) ap_state_query(int query)
     }
 }
 
+static apr_random_t *rng = NULL;
+#if APR_HAS_THREADS
+static apr_thread_mutex_t *rng_mutex = NULL;
+#endif
+
+static void core_child_init(apr_pool_t *pchild, server_rec *s)
+{
+    apr_proc_t proc;
+#if APR_HAS_THREADS
+    int threaded_mpm;
+    if (ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm) == APR_SUCCESS
+        && threaded_mpm)
+    {
+        apr_thread_mutex_create(&rng_mutex, APR_THREAD_MUTEX_DEFAULT, pchild);
+    }
+#endif
+    /* The MPMs use plain fork() and not apr_proc_fork(), so we have to call
+     * apr_random_after_fork() manually in the child
+     */
+    proc.pid = getpid();
+    apr_random_after_fork(&proc);
+}
+
+AP_CORE_DECLARE(void) ap_random_parent_after_fork(void)
+{
+    /*
+     * To ensure that the RNG state in the parent changes after the fork, we
+     * pull some data from the RNG and discard it. This ensures that the RNG
+     * states in the children are different even after the pid wraps around.
+     * As we only use apr_random for insecure random bytes, pulling 2 bytes
+     * should be enough.
+     * XXX: APR should probably have some dedicated API to do this, but it
+     * XXX: currently doesn't.
+     */
+    apr_uint16_t data;
+    apr_random_insecure_bytes(rng, &data, sizeof(data));
+}
+
+AP_CORE_DECLARE(void) ap_init_rng(apr_pool_t *p)
+{
+    unsigned char seed[8];
+    apr_status_t rv;
+    rng = apr_random_standard_new(p);
+    do {
+        rv = apr_generate_random_bytes(seed, sizeof(seed));
+        if (rv != APR_SUCCESS)
+            goto error;
+        apr_random_add_entropy(rng, seed, sizeof(seed));
+        rv = apr_random_insecure_ready(rng);
+    } while (rv == APR_ENOTENOUGHENTROPY);
+    if (rv == APR_SUCCESS)
+        return;
+error:
+    ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, APLOGNO(00141)
+                 "Could not initialize random number generator");
+    exit(1);
+}
+
+AP_DECLARE(void) ap_random_insecure_bytes(void *buf, apr_size_t size)
+{
+#if APR_HAS_THREADS
+    if (rng_mutex)
+        apr_thread_mutex_lock(rng_mutex);
+#endif
+    /* apr_random_insecure_bytes can only fail with APR_ENOTENOUGHENTROPY,
+     * and we have ruled that out during initialization. Therefore we don't
+     * need to check the return code.
+     */
+    apr_random_insecure_bytes(rng, buf, size);
+#if APR_HAS_THREADS
+    if (rng_mutex)
+        apr_thread_mutex_unlock(rng_mutex);
+#endif
+}
+
+/*
+ * Finding a random number in a range.
+ *      n' = a + n(b-a+1)/(M+1)
+ * where:
+ *      n' = random number in range
+ *      a  = low end of range
+ *      b  = high end of range
+ *      n  = random number of 0..M
+ *      M  = maxint
+ * Algorithm 'borrowed' from PHP's rand() function.
+ */
+#define RAND_RANGE(__n, __min, __max, __tmax) \
+(__n) = (__min) + (long) ((double) ((__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0)))
+AP_DECLARE(apr_uint32_t) ap_random_pick(apr_uint32_t min, apr_uint32_t max)
+{
+    apr_uint32_t number;
+#if (!__GNUC__ || __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || \
+     !__sparc__ || APR_SIZEOF_VOIDP != 8)
+    /* This triggers a gcc bug on sparc/64bit with gcc < 4.8, PR 52900 */
+    if (max < 16384) {
+        apr_uint16_t num16;
+        ap_random_insecure_bytes(&num16, sizeof(num16));
+        RAND_RANGE(num16, min, max, APR_UINT16_MAX);
+        number = num16;
+    }
+    else
+#endif
+    {
+        ap_random_insecure_bytes(&number, sizeof(number));
+        RAND_RANGE(number, min, max, APR_UINT32_MAX);
+    }
+    return number;
+}
+
+static apr_status_t core_insert_network_bucket(conn_rec *c,
+                                               apr_bucket_brigade *bb,
+                                               apr_socket_t *socket)
+{
+    apr_bucket *e = apr_bucket_socket_create(socket, c->bucket_alloc);
+    APR_BRIGADE_INSERT_TAIL(bb, e);
+    return APR_SUCCESS;
+}
+
+static apr_status_t core_dirwalk_stat(apr_finfo_t *finfo, request_rec *r,
+                                      apr_int32_t wanted) 
+{
+    return apr_stat(finfo, r->filename, wanted, r->pool);
+}
+
+static void core_dump_config(apr_pool_t *p, server_rec *s)
+{
+    core_server_config *sconf = ap_get_core_module_config(s->module_config);
+    apr_file_t *out = NULL;
+    const char *tmp;
+    const char **defines;
+    int i;
+    if (!ap_exists_config_define("DUMP_RUN_CFG"))
+        return;
+
+    apr_file_open_stdout(&out, p);
+    apr_file_printf(out, "ServerRoot: \"%s\"\n", ap_server_root);
+    tmp = ap_server_root_relative(p, sconf->ap_document_root);
+    apr_file_printf(out, "Main DocumentRoot: \"%s\"\n", tmp);
+    if (s->error_fname[0] != '|' && s->errorlog_provider == NULL)
+        tmp = ap_server_root_relative(p, s->error_fname);
+    else
+        tmp = s->error_fname;
+    apr_file_printf(out, "Main ErrorLog: \"%s\"\n", tmp);
+    if (ap_scoreboard_fname) {
+        tmp = ap_runtime_dir_relative(p, ap_scoreboard_fname);
+        apr_file_printf(out, "ScoreBoardFile: \"%s\"\n", tmp);
+    }
+    ap_dump_mutexes(p, s, out);
+    ap_mpm_dump_pidfile(p, out);
+
+    defines = (const char **)ap_server_config_defines->elts;
+    for (i = 0; i < ap_server_config_defines->nelts; i++) {
+        const char *name = defines[i];
+        const char *val = NULL;
+        if (server_config_defined_vars)
+           val = apr_table_get(server_config_defined_vars, name);
+        if (val)
+            apr_file_printf(out, "Define: %s=%s\n", name, val);
+        else
+            apr_file_printf(out, "Define: %s\n", name);
+    }
+}
+
 static void register_hooks(apr_pool_t *p)
 {
     errorlog_hash = apr_hash_make(p);
     ap_register_log_hooks(p);
+    ap_register_config_hooks(p);
     ap_expr_init(p);
 
     /* create_connection and pre_connection should always be hooked
      * APR_HOOK_REALLY_LAST by core to give other modules the opportunity
-     * to install alternate network transports and stop other functions 
+     * to install alternate network transports and stop other functions
      * from being run.
      */
     ap_hook_create_connection(core_create_conn, NULL, NULL,
@@ -4394,9 +5162,12 @@ static void register_hooks(apr_pool_t *p)
 
     ap_hook_pre_config(core_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
     ap_hook_post_config(core_post_config,NULL,NULL,APR_HOOK_REALLY_FIRST);
+    ap_hook_check_config(core_check_config,NULL,NULL,APR_HOOK_FIRST);
+    ap_hook_test_config(core_dump_config,NULL,NULL,APR_HOOK_FIRST);
     ap_hook_translate_name(ap_core_translate,NULL,NULL,APR_HOOK_REALLY_LAST);
     ap_hook_map_to_storage(core_map_to_storage,NULL,NULL,APR_HOOK_REALLY_LAST);
     ap_hook_open_logs(ap_open_logs,NULL,NULL,APR_HOOK_REALLY_FIRST);
+    ap_hook_child_init(core_child_init,NULL,NULL,APR_HOOK_REALLY_FIRST);
     ap_hook_child_init(ap_logs_child_init,NULL,NULL,APR_HOOK_MIDDLE);
     ap_hook_handler(default_handler,NULL,NULL,APR_HOOK_REALLY_LAST);
     /* FIXME: I suspect we can eliminate the need for these do_nothings - Ben */
@@ -4406,7 +5177,12 @@ static void register_hooks(apr_pool_t *p)
     APR_OPTIONAL_HOOK(proxy, create_req, core_create_proxy_req, NULL, NULL,
                       APR_HOOK_MIDDLE);
     ap_hook_pre_mpm(ap_create_scoreboard, NULL, NULL, APR_HOOK_MIDDLE);
-
+    ap_hook_child_status(ap_core_child_status, NULL, NULL, APR_HOOK_MIDDLE);
+    ap_hook_insert_network_bucket(core_insert_network_bucket, NULL, NULL,
+                                  APR_HOOK_REALLY_LAST);
+    ap_hook_dirwalk_stat(core_dirwalk_stat, NULL, NULL, APR_HOOK_REALLY_LAST);
+    ap_hook_open_htaccess(ap_open_htaccess, NULL, NULL, APR_HOOK_REALLY_LAST);
+    
     /* register the core's insert_filter hook and register core-provided
      * filters
      */