]> granicus.if.org Git - apache/commitdiff
First order simplification; Add IncludeOptional for introducing
authorWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 7 Apr 2010 04:51:46 +0000 (04:51 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 7 Apr 2010 04:51:46 +0000 (04:51 +0000)
wildcard pattern matches or specific includes which may be omitted.
Refactors ap_process_resource_config() to deal efficiently with
a single file, and renames the new _ex() flavor per list discussion
to  ap_process_fnmatch_configs() for wildcard processing.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@931435 13f79535-47bb-0310-9956-ffa450edef68

include/ap_mmn.h
include/http_config.h
server/config.c
server/core.c

index e12140bc3775f4e1d2d0160bf38ec3ab162e9326..c4e08b7d475f064a6517efe98c52d959ee4dfb35 100644 (file)
  * 20100208.0 (2.3.6-dev)  ap_socache_provider_t API changes to store and iterate
  * 20100208.1 (2.3.6-dev)  Added forward member to proxy_conn_rec
  * 20100208.2 (2.3.7-dev)  Added ap_log_command_line().
- * 20100223.1 (2.3.7-dev)  LDAP client_certs per-server moved to per-dir
- *
+ * 20100208.3 (2.3.7-dev)  LDAP client_certs per-server moved to per-dir
+ * 20100208.4 (2.3.7-dev)  Added ap_process_fnmatch_configs().
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
 
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
-#define MODULE_MAGIC_NUMBER_MAJOR 20100223
+#define MODULE_MAGIC_NUMBER_MAJOR 20100208
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 1                     /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 4                     /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a
index dd78e04cb7a7e7b25a76d37dace00c1844de89e0..33a3e54a62c3f0234253203b89a260f43fc0595e 100644 (file)
@@ -65,12 +65,6 @@ enum cmd_how {
     TAKE_ARGV                  /**< an argc and argv are passed */
 };
 
-enum strict_how {
-    AP_OPTIONAL, /* directory and file wildcards succeed on no-match */
-    AP_MIXED, /* directory wildcards fail, file wildcards succeed on no match */
-    AP_STRICT /* directory and file wildcards fail on no-match */
-};
-
 /**
  * This structure is passed to a command which is being invoked,
  * to carry a large variety of miscellaneous data which is all of
@@ -907,34 +901,35 @@ AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p,
                                                    server_rec **ps);
 
 /**
- * Process the config file for Apache
+ * Process a config file for Apache
  * @param s The server rec to use for the command parms
  * @param fname The name of the config file
  * @param conftree The root node of the created config tree
  * @param p Pool for general allocation
  * @param ptemp Pool for temporary allocation
- * @param strict Whether a no-match wildcard should be fatal
  */
-AP_DECLARE(const char *) ap_process_resource_config_ex(server_rec *s,
-                                                       const char *fname,
-                                                       ap_directive_t **conftree,
-                                                       apr_pool_t *p,
-                                                       apr_pool_t *ptemp,
-                                                       enum strict_how strict);
+AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
+                                                    const char *fname,
+                                                    ap_directive_t **conftree,
+                                                    apr_pool_t *p,
+                                                    apr_pool_t *ptemp);
 
 /**
- * Process the config file for Apache
+ * Process all matching files as Apache configs
  * @param s The server rec to use for the command parms
- * @param fname The name of the config file
+ * @param fname The filename pattern of the config file
  * @param conftree The root node of the created config tree
  * @param p Pool for general allocation
  * @param ptemp Pool for temporary allocation
+ * @param optional Whether a no-match wildcard is allowed
+ * @see apr_fnmatch for pattern handling
  */
-AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
+AP_DECLARE(const char *) ap_process_fnmatch_configs(server_rec *s,
                                                     const char *fname,
                                                     ap_directive_t **conftree,
                                                     apr_pool_t *p,
-                                                    apr_pool_t *ptemp);
+                                                    apr_pool_t *ptemp,
+                                                    int optional);
 
 /**
  * Process all directives in the config tree
index 54a58b61a2140909bd0abf7194939ce3c0c8e83b..9d468f07fbf734f42915f4ba874dd1941f2c7d52 100644 (file)
@@ -1553,16 +1553,52 @@ static int fname_alphasort(const void *fn1, const void *fn2)
     return strcmp(f1->fname,f2->fname);
 }
 
+AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
+                                                    const char *fname,
+                                                    ap_directive_t **conftree,
+                                                    apr_pool_t *p,
+                                                    apr_pool_t *ptemp)
+{
+    ap_configfile_t *cfp;
+    cmd_parms parms;
+    apr_status_t rv;
+    const char *error;
+
+    parms = default_parms;
+    parms.pool = p;
+    parms.temp_pool = ptemp;
+    parms.server = s;
+    parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
+    parms.override_opts = OPT_ALL | OPT_SYM_OWNER | OPT_MULTI;
+
+    rv = ap_pcfg_openfile(&cfp, p, fname);
+    if (rv != APR_SUCCESS) {
+        char errmsg[120];
+        return apr_psprintf(p, "Could not open configuration file %s: %s",
+                            fname, apr_strerror(rv, errmsg, sizeof errmsg));
+    }
+
+    parms.config_file = cfp;
+    error = ap_build_config(&parms, p, ptemp, conftree);
+    ap_cfg_closefile(cfp);
+
+    if (error) {
+        return apr_psprintf(p, "Syntax error on line %d of %s: %s",
+                            parms.err_directive->line_num,
+                            parms.err_directive->filename, error);
+    }
+
+    return NULL;
+}
+
 static const char *process_resource_config_nofnmatch(server_rec *s,
                                                      const char *fname,
                                                      ap_directive_t **conftree,
                                                      apr_pool_t *p,
                                                      apr_pool_t *ptemp,
                                                      unsigned depth,
-                                                     enum strict_how strict)
+                                                     int optional)
 {
-    cmd_parms parms;
-    ap_configfile_t *cfp;
     const char *error;
     apr_status_t rv;
 
@@ -1616,7 +1652,7 @@ static const char *process_resource_config_nofnmatch(server_rec *s,
                 fnew = &((fnames *) candidates->elts)[current];
                 error = process_resource_config_nofnmatch(s, fnew->fname,
                                                           conftree, p, ptemp,
-                                                          depth, strict);
+                                                          depth, optional);
                 if (error) {
                     return error;
                 }
@@ -1626,32 +1662,7 @@ static const char *process_resource_config_nofnmatch(server_rec *s,
         return NULL;
     }
 
-    /* GCC's initialization extensions are soooo nice here... */
-    parms = default_parms;
-    parms.pool = p;
-    parms.temp_pool = ptemp;
-    parms.server = s;
-    parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
-    parms.override_opts = OPT_ALL | OPT_SYM_OWNER | OPT_MULTI;
-
-    rv = ap_pcfg_openfile(&cfp, p, fname);
-    if (rv != APR_SUCCESS) {
-        char errmsg[120];
-        return apr_psprintf(p, "Could not open configuration file %s: %s",
-                            fname, apr_strerror(rv, errmsg, sizeof errmsg));
-    }
-
-    parms.config_file = cfp;
-    error = ap_build_config(&parms, p, ptemp, conftree);
-    ap_cfg_closefile(cfp);
-
-    if (error) {
-        return apr_psprintf(p, "Syntax error on line %d of %s: %s",
-                            parms.err_directive->line_num,
-                            parms.err_directive->filename, error);
-    }
-
-    return NULL;
+    return ap_process_resource_config(s, fname, conftree, p, ptemp);
 }
 
 static const char *process_resource_config_fnmatch(server_rec *s,
@@ -1661,7 +1672,7 @@ static const char *process_resource_config_fnmatch(server_rec *s,
                                                    apr_pool_t *p,
                                                    apr_pool_t *ptemp,
                                                    unsigned depth,
-                                                   enum strict_how strict)
+                                                   int optional)
 {
     const char *rest;
     apr_status_t rv;
@@ -1684,12 +1695,12 @@ static const char *process_resource_config_fnmatch(server_rec *s,
         if (!rest) {
             return process_resource_config_nofnmatch(s, path,
                                                      conftree, p,
-                                                     ptemp, 0, strict);
+                                                     ptemp, 0, optional);
         }
         else {
             return process_resource_config_fnmatch(s, path, rest,
                                                    conftree, p,
-                                                   ptemp, 0, strict);
+                                                   ptemp, 0, optional);
         }
     }
 
@@ -1740,12 +1751,12 @@ static const char *process_resource_config_fnmatch(server_rec *s,
             if (!rest) {
                 error = process_resource_config_nofnmatch(s, fnew->fname,
                                                           conftree, p,
-                                                          ptemp, 0, strict);
+                                                          ptemp, 0, optional);
             }
             else {
                 error = process_resource_config_fnmatch(s, fnew->fname, rest,
                                                         conftree, p,
-                                                        ptemp, 0, strict);
+                                                        ptemp, 0, optional);
             }
             if (error) {
                 return error;
@@ -1754,33 +1765,21 @@ static const char *process_resource_config_fnmatch(server_rec *s,
     }
     else {
 
-        /* Support for the three states of strictness:
-         *
-         * AP_OPTIONAL - directory and file wildcards succeed on no-match, we don't
-         * need to do anything here for this case.
-         * AP_MIXED - directory wildcards fail on no match, file wildcards succeed
-         * on no match. Use rest to tell between the two.
-         * AP_STRICT - both directory and file wildcards fail on no-match.
-         */
-        if (AP_STRICT == strict) {
-            return apr_psprintf(p, "No matches for the wildcard '%s' in '%s' with "
-                    "strict wildcard matching, failing", fname, path);
-        }
-        else if (AP_MIXED == strict && rest) {
+        if (!optional) {
             return apr_psprintf(p, "No matches for the wildcard '%s' in '%s', failing "
-                    "(use Include optional if required)", fname, path);
+                                   "(use IncludeOptional if required)", fname, path);
         }
     }
 
     return NULL;
 }
 
-AP_DECLARE(const char *) ap_process_resource_config_ex(server_rec *s,
-                                                       const char *fname,
-                                                       ap_directive_t **conftree,
-                                                       apr_pool_t *p,
-                                                       apr_pool_t *ptemp,
-                                                       enum strict_how strict)
+AP_DECLARE(const char *) ap_process_fnmatch_configs(server_rec *s,
+                                                    const char *fname,
+                                                    ap_directive_t **conftree,
+                                                    apr_pool_t *p,
+                                                    apr_pool_t *ptemp,
+                                                    int optional)
 {
     /* XXX: lstat() won't work on the wildcard pattern...
      */
@@ -1796,8 +1795,7 @@ AP_DECLARE(const char *) ap_process_resource_config_ex(server_rec *s,
     }
 
     if (!apr_fnmatch_test(fname)) {
-        return process_resource_config_nofnmatch(s, fname, conftree, p, ptemp,
-                                                 0, strict);
+        return ap_process_resource_config(s, fname, conftree, p, ptemp);
     }
     else {
         apr_status_t status;
@@ -1816,22 +1814,13 @@ AP_DECLARE(const char *) ap_process_resource_config_ex(server_rec *s,
 
         /* walk the filepath */
         return process_resource_config_fnmatch(s, rootpath, filepath, conftree, p, ptemp,
-                                                 0, strict);
+                                               0, optional);
 
     }
 
     return NULL;
 }
 
-AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
-                                                    const char *fname,
-                                                    ap_directive_t **conftree,
-                                                    apr_pool_t *p,
-                                                    apr_pool_t *ptemp)
-{
-    return ap_process_resource_config_ex(s, fname, conftree, p, ptemp, AP_MIXED);
-}
-
 AP_DECLARE(int) ap_process_config_tree(server_rec *s,
                                        ap_directive_t *conftree,
                                        apr_pool_t *p,
index 921bf23c5ee22930eb48c75923d6ae93da98dec4..47ae6ad53dea1341b2a44c4512d9c7155cbd34bc 100644 (file)
@@ -2567,33 +2567,14 @@ static const char *set_use_canonical_phys_port(cmd_parms *cmd, void *d_,
 }
 
 static const char *include_config (cmd_parms *cmd, void *dummy,
-                                   const char *arg1, const char *arg2)
+                                   const char *name)
 {
     ap_directive_t *conftree = NULL;
-    const char *name;
-    enum strict_how strict;
     const char *conffile, *error;
     unsigned *recursion;
+    int optional = (int)cmd->cmd->cmd_data;
     void *data;
 
-    if (arg2) {
-        name = arg2;
-        if (!strcmp(arg1, "optional")) {
-            strict = AP_OPTIONAL;
-        }
-        else if (!strcmp(arg1, "strict")) {
-            strict = AP_STRICT;
-        }
-        else {
-            return apr_pstrcat(cmd->pool, "Invalid Include modifier '",
-                               arg1, "', should be 'optional' or 'strict'", NULL);
-        }
-    }
-    else {
-        name = arg1;
-        strict = AP_MIXED;
-    }
-
     apr_pool_userdata_get(&data, "ap_include_sentinel", cmd->pool);
     if (data) {
         recursion = data;
@@ -2606,8 +2587,8 @@ static const char *include_config (cmd_parms *cmd, void *dummy,
 
     if (++*recursion > AP_MAX_INCLUDE_DEPTH) {
         *recursion = 0;
-        return apr_psprintf(cmd->pool, "Exceeded maximum include depth of %u. "
-                            "You have probably a recursion somewhere.",
+        return apr_psprintf(cmd->pool, "Exceeded maximum include depth of %u, "
+                            "There appears to be a recursion.",
                             AP_MAX_INCLUDE_DEPTH);
     }
 
@@ -2618,8 +2599,9 @@ static const char *include_config (cmd_parms *cmd, void *dummy,
                            name, NULL);
     }
 
-    error = ap_process_resource_config_ex(cmd->server, conffile,
-                                       &conftree, cmd->pool, cmd->temp_pool, strict);
+    error = ap_process_fnmatch_configs(cmd->server, conffile, &conftree, 
+                                       cmd->pool, cmd->temp_pool, 
+                                       optional);
     if (error) {
         *recursion = 0;
         return error;
@@ -3321,10 +3303,14 @@ AP_INIT_TAKE1("UseCanonicalPhysicalPort", set_use_canonical_phys_port, NULL,
   "Whether to use the physical Port when constructing URLs"),
 /* TODO: RlimitFoo should all be part of mod_cgi, not in the core */
 /* TODO: ListenBacklog in MPM */
-AP_INIT_TAKE12("Include", include_config, NULL,
+AP_INIT_TAKE1("Include", include_config, NULL,
+  (RSRC_CONF | ACCESS_CONF | EXEC_ON_READ),
+  "Name(s) of the config file(s) to be included; fails if the wildcard does "
+  "not match at least one file"),
+AP_INIT_TAKE1("IncludeOptional", include_config, (void*)1,
   (RSRC_CONF | ACCESS_CONF | EXEC_ON_READ),
-  "Name of the config file to be included, ignore file wildcards with no "
-  "matching files, fail directory wildcards with no matching directories"),
+  "Name or pattern of the config file(s) to be included; ignored if the file "
+  "does not exist or the pattern does not match any files"),
 AP_INIT_TAKE1("LogLevel", set_loglevel, NULL, RSRC_CONF,
   "Level of verbosity in error logging"),
 AP_INIT_TAKE1("NameVirtualHost", ap_set_name_virtual_host, NULL, RSRC_CONF,