]> granicus.if.org Git - apache/blobdiff - server/config.c
avoid duplication of APR_HOOK_LINK invocations
[apache] / server / config.c
index 733d9c285fa9514b16940b70eb6c8183995d2738..e48d37016f6a2344fa500b0570e719f1efc56c9e 100644 (file)
@@ -80,7 +80,7 @@ APR_HOOK_STRUCT(
            APR_HOOK_LINK(quick_handler)
            APR_HOOK_LINK(optional_fn_retrieve)
            APR_HOOK_LINK(test_config)
-           APR_HOOK_LINK(pre_htaccess)
+           APR_HOOK_LINK(open_htaccess)
 )
 
 AP_IMPLEMENT_HOOK_RUN_ALL(int, header_parser,
@@ -172,8 +172,11 @@ AP_IMPLEMENT_HOOK_RUN_FIRST(int, handler, (request_rec *r),
 AP_IMPLEMENT_HOOK_RUN_FIRST(int, quick_handler, (request_rec *r, int lookup),
                             (r, lookup), DECLINED)
 
-AP_IMPLEMENT_HOOK_RUN_FIRST(int, pre_htaccess, (request_rec *r, const char *filename),
-                            (r, filename), DECLINED)
+AP_IMPLEMENT_HOOK_RUN_FIRST(apr_status_t, open_htaccess,
+                            (request_rec *r, const char *dir_name, const char *access_name,
+                             ap_configfile_t **conffile, const char **full_name),
+                            (r, dir_name, access_name, conffile, full_name),
+                            AP_DECLINED)
 
 /* hooks with no args are implemented last, after disabling APR hook probes */
 #if defined(APR_HOOK_PROBES_ENABLED)
@@ -373,12 +376,6 @@ static int invoke_filter_init(request_rec *r, ap_filter_t *filters)
     return OK;
 }
 
-/*
- * TODO: Move this to an appropriate include file and possibly prefix it
- * with AP_.
- */
-#define DEFAULT_HANDLER_NAME ""
-
 AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r)
 {
     const char *handler;
@@ -427,7 +424,7 @@ AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r)
             }
         }
         else {
-            handler = DEFAULT_HANDLER_NAME;
+            handler = AP_DEFAULT_HANDLER_NAME;
         }
 
         r->handler = handler;
@@ -1802,9 +1799,8 @@ AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
 
     rv = ap_pcfg_openfile(&cfp, p, fname);
     if (rv != APR_SUCCESS) {
-        char errmsg[120];
-        return apr_psprintf(p, "Could not open configuration file %s: %s",
-                            fname, apr_strerror(rv, errmsg, sizeof errmsg));
+        return apr_psprintf(p, "Could not open configuration file %s: %pm",
+                            fname, &rv);
     }
 
     parms.config_file = cfp;
@@ -1859,9 +1855,8 @@ static const char *process_resource_config_nofnmatch(server_rec *s,
          */
         rv = apr_dir_open(&dirp, path, ptemp);
         if (rv != APR_SUCCESS) {
-            char errmsg[120];
-            return apr_psprintf(p, "Could not open config directory %s: %s",
-                                path, apr_strerror(rv, errmsg, sizeof errmsg));
+            return apr_psprintf(p, "Could not open config directory %s: %pm",
+                                path, &rv);
         }
 
         candidates = apr_array_make(ptemp, 1, sizeof(fnames));
@@ -1946,9 +1941,8 @@ static const char *process_resource_config_fnmatch(server_rec *s,
      */
     rv = apr_dir_open(&dirp, path, ptemp);
     if (rv != APR_SUCCESS) {
-        char errmsg[120];
-        return apr_psprintf(p, "Could not open config directory %s: %s",
-                            path, apr_strerror(rv, errmsg, sizeof errmsg));
+        return apr_psprintf(p, "Could not open config directory %s: %pm",
+                            path, &rv);
     }
 
     candidates = apr_array_make(ptemp, 1, sizeof(fnames));
@@ -2083,19 +2077,27 @@ AP_DECLARE(int) ap_process_config_tree(server_rec *s,
     return OK;
 }
 
+apr_status_t ap_open_htaccess(request_rec *r, const char *dir_name,
+                              const char *access_name,
+                              ap_configfile_t **conffile,
+                              const char **full_name)
+{
+    *full_name = ap_make_full_path(r->pool, dir_name, access_name);
+    return ap_pcfg_openfile(conffile, r->pool, *full_name);
+}
+
 AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result,
                                        request_rec *r, int override,
                                        int override_opts, apr_table_t *override_list,
-                                       const char *d, const char *access_name)
+                                       const char *d, const char *access_names)
 {
     ap_configfile_t *f = NULL;
     cmd_parms parms;
-    char *filename = NULL;
+    const char *filename;
     const struct htaccess_result *cache;
     struct htaccess_result *new;
     ap_conf_vector_t *dc = NULL;
     apr_status_t status;
-    int rc;
 
     /* firstly, search cache */
     for (cache = r->htaccess; cache != NULL; cache = cache->next) {
@@ -2115,19 +2117,11 @@ AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result,
     parms.path = apr_pstrdup(r->pool, d);
 
     /* loop through the access names and find the first one */
-    while (access_name[0]) {
-        /* AFAICT; there is no use of the actual 'filename' against
-         * any canonicalization, so we will simply take the given
-         * name, ignoring case sensitivity and aliases
-         */
-        filename = ap_make_full_path(r->pool, d,
-                                     ap_getword_conf(r->pool, &access_name));
-        rc = ap_run_pre_htaccess(r, filename);
-        if (rc != DECLINED && rc != OK) {
-            return rc;
-        }
-        status = ap_pcfg_openfile(&f, r->pool, filename);
+    while (access_names[0]) {
+        const char *access_name = ap_getword_conf(r->pool, &access_names);
 
+        filename = NULL;
+        status = ap_run_open_htaccess(r, d, access_name, &f, &filename);
         if (status == APR_SUCCESS) {
             const char *errmsg;
             ap_directive_t *temptree = NULL;