From 2e62dad3d91280032b2130f02553c968d306edf5 Mon Sep 17 00:00:00 2001
From: Alexander Chernyakhovsky <achernya@mit.edu>
Date: Fri, 3 May 2013 22:43:28 -0400
Subject: [PATCH 4/4] Export method to fixup a single virtual host

Apache normally provides ap_fixup_virtual_hosts, which merges the
configuration from the main server into each virtual host.  Refactor
this code to allow merging the configuration into a single virtual
host, and export this method for use in mod_vhost_ldap.

Additionally, call the newly created method in the loop in
ap_fixup_virtual_hosts.
---
 include/http_config.h |    9 ++++++++
 server/config.c       |   58 +++++++++++++++++++++++++++----------------------
 2 files changed, 41 insertions(+), 26 deletions(-)

diff --git a/include/http_config.h b/include/http_config.h
index 7ee3760..e3657ea 100644
--- a/include/http_config.h
+++ b/include/http_config.h
@@ -1012,6 +1012,15 @@ AP_DECLARE(void) ap_register_hooks(module *m, apr_pool_t *p);
  */
 AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p,
                                         server_rec *main_server);
+/**
+ * Setup all virtual hosts
+ * @param p The pool to allocate from
+ * @param main_server The head of the server_rec list
+ * @param virt The individual virtual host to fix
+ */
+AP_DECLARE(void) ap_fixup_virtual_host(apr_pool_t *p,
+				       server_rec *main_server,
+				       server_rec *virt);
 
 /**
  * Reserve some modules slots for modules loaded by other means than
diff --git a/server/config.c b/server/config.c
index bc0804a..488954d 100644
--- a/server/config.c
+++ b/server/config.c
@@ -2246,46 +2246,52 @@ AP_DECLARE(void) ap_merge_log_config(const struct ap_logconf *old_conf,
     }
 }
 
-AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, server_rec *main_server)
+AP_DECLARE(void) ap_fixup_virtual_host(apr_pool_t *p, server_rec *main_server,
+				       server_rec *virt)
 {
-    server_rec *virt;
     core_dir_config *dconf =
         ap_get_core_module_config(main_server->lookup_defaults);
     dconf->log = &main_server->log;
 
-    for (virt = main_server->next; virt; virt = virt->next) {
-        merge_server_configs(p, main_server->module_config,
-                             virt->module_config);
+    merge_server_configs(p, main_server->module_config,
+			 virt->module_config);
 
-        virt->lookup_defaults =
-            ap_merge_per_dir_configs(p, main_server->lookup_defaults,
-                                     virt->lookup_defaults);
+    virt->lookup_defaults =
+	ap_merge_per_dir_configs(p, main_server->lookup_defaults,
+				 virt->lookup_defaults);
 
-        if (virt->server_admin == NULL)
-            virt->server_admin = main_server->server_admin;
+    if (virt->server_admin == NULL)
+	virt->server_admin = main_server->server_admin;
 
-        if (virt->timeout == 0)
-            virt->timeout = main_server->timeout;
+    if (virt->timeout == 0)
+	virt->timeout = main_server->timeout;
 
-        if (virt->keep_alive_timeout == 0)
-            virt->keep_alive_timeout = main_server->keep_alive_timeout;
+    if (virt->keep_alive_timeout == 0)
+	virt->keep_alive_timeout = main_server->keep_alive_timeout;
 
-        if (virt->keep_alive == -1)
-            virt->keep_alive = main_server->keep_alive;
+    if (virt->keep_alive == -1)
+	virt->keep_alive = main_server->keep_alive;
 
-        if (virt->keep_alive_max == -1)
-            virt->keep_alive_max = main_server->keep_alive_max;
+    if (virt->keep_alive_max == -1)
+	virt->keep_alive_max = main_server->keep_alive_max;
 
-        ap_merge_log_config(&main_server->log, &virt->log);
+    ap_merge_log_config(&main_server->log, &virt->log);
 
-        dconf = ap_get_core_module_config(virt->lookup_defaults);
-        dconf->log = &virt->log;
+    dconf = ap_get_core_module_config(virt->lookup_defaults);
+    dconf->log = &virt->log;
 
-        /* XXX: this is really something that should be dealt with by a
-         * post-config api phase
-         */
-        ap_core_reorder_directories(p, virt);
-    }
+    /* XXX: this is really something that should be dealt with by a
+     * post-config api phase
+     */
+    ap_core_reorder_directories(p, virt);
+}
+
+AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, server_rec *main_server)
+{
+    server_rec *virt;
+    
+    for (virt = main_server->next; virt; virt = virt->next)
+        ap_fixup_virtual_host(p, main_server, virt);
 
     ap_core_reorder_directories(p, main_server);
 }
-- 
1.7.9.6 (Apple Git-31.1)

