Hi,

Attached is a patch which implements ap_document_root(r) as a hook.
This way modules can set document_root on the fly. (think vhost_alias)
AND get the right DOCUMENT_ROOT env. variable (as set by
ap_add_common_vars(r)).

The patch also changes ap_core_translate to use ap_document_root(r)
instead of conf->ap_document_root.  This way, modules that just need
to point to a different docroot won't have to implement a translate
hook by appending r->uri til r->filename, but just rely on
ap_document_root.

Comments ?

/Jakob
Index: server/core.c
===================================================================
--- server/core.c	(revision 530676)
+++ server/core.c	(working copy)
@@ -69,12 +69,16 @@
 
 APR_HOOK_STRUCT(
     APR_HOOK_LINK(get_mgmt_items)
+    APR_HOOK_LINK(document_root)
 )
 
 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(const char *,document_root,
+			    (request_rec *r), (r), NULL)
+
 /* 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.
@@ -682,7 +686,7 @@
                : DEFAULT_CONTENT_TYPE;
 }
 
-AP_DECLARE(const char *) ap_document_root(request_rec *r) /* Don't use this! */
+AP_DECLARE(const char *) ap_core_document_root(request_rec *r)
 {
     core_server_config *conf;
 
@@ -3390,7 +3394,7 @@
         while (*path == '/') {
             ++path;
         }
-        if ((rv = apr_filepath_merge(&r->filename, conf->ap_document_root, path,
+        if ((rv = apr_filepath_merge(&r->filename, ap_document_root(r), path,
                                      APR_FILEPATH_TRUENAME
                                    | APR_FILEPATH_SECUREROOT, r->pool))
                     != APR_SUCCESS) {
@@ -3413,7 +3417,7 @@
         while (*path == '/') {
             ++path;
         }
-        if ((rv = apr_filepath_merge(&r->filename, conf->ap_document_root, path,
+        if ((rv = apr_filepath_merge(&r->filename, ap_document_root(r), path,
                                      APR_FILEPATH_TRUENAME
                                    | APR_FILEPATH_SECUREROOT, r->pool))
                     != APR_SUCCESS) {
@@ -3863,6 +3867,7 @@
     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_document_root(ap_core_document_root, NULL, NULL, APR_HOOK_REALLY_LAST);
 
     /* register the core's insert_filter hook and register core-provided
      * filters
Index: include/http_core.h
===================================================================
--- include/http_core.h	(revision 530676)
+++ include/http_core.h	(working copy)
@@ -148,11 +148,10 @@
 /**
  * Retrieve the document root for this server
  * @param r The current request
- * @warning Don't use this!  If your request went through a Userdir, or 
- * something like that, it'll screw you.  But it's back-compatible...
  * @return The document root
  */
-AP_DECLARE(const char *) ap_document_root(request_rec *r);
+AP_DECLARE(const char *) ap_core_document_root(request_rec *r);
+#define ap_document_root(r) ap_run_document_root(r)
 
 /**
  * Lookup the remote client's DNS name or IP address
@@ -629,6 +628,14 @@
 AP_DECLARE_HOOK(int, get_mgmt_items,
                 (apr_pool_t *p, const char * val, apr_hash_t *ht))
 
+/**
+ * This hook allows modules to return customized documentroot
+ * @param r the current request
+ * @ingroup hooks
+ */
+AP_DECLARE_HOOK(const char*,document_root,(request_rec *r))
+
+
 /* ---------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------

Reply via email to