summaryrefslogtreecommitdiffstats
path: root/server/core.c
diff options
context:
space:
mode:
authorEric Covener <covener@apache.org>2016-11-15 04:50:42 +0100
committerEric Covener <covener@apache.org>2016-11-15 04:50:42 +0100
commita3992a341127dcc371af45531f532d01547392bb (patch)
tree9eb4956cb40d75db73d0d1975c79666ce4caaa42 /server/core.c
parentreorganize mod_socache_redis so it compiles w/o apr-redis (diff)
downloadapache2-a3992a341127dcc371af45531f532d01547392bb.tar.xz
apache2-a3992a341127dcc371af45531f532d01547392bb.zip
add an <IfFile> config section like <IfDefine>
It allows a non httpd config file to be used as a marker directly in httpd.conf without hiding logic in a script in front of apachectl to do test -f and pass extra -D's. This is something we've had in IBM's httpd distro for a little bit and hadn't remembered to share. I've seen some questions/config files come up in a few places lately that would benefit from this as an option. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1769718 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--server/core.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/server/core.c b/server/core.c
index ff203daf31..f802769649 100644
--- a/server/core.c
+++ b/server/core.c
@@ -2851,6 +2851,49 @@ static const char *start_ifdefine(cmd_parms *cmd, void *dummy, const char *arg)
}
}
+static const char *start_iffile(cmd_parms *cmd, void *dummy, const char *arg)
+{
+ apr_finfo_t sb;
+ const char *endp;
+ int file_exists = 0;
+ int not = 0;
+ const char *relative;
+
+ endp = ap_strrchr_c(arg, '>');
+ if (endp == NULL) {
+ return unclosed_directive(cmd);
+ }
+
+ arg = apr_pstrndup(cmd->temp_pool, arg, endp - arg);
+
+ if (arg[0] == '!') {
+ not = 1;
+ arg++;
+ }
+
+ if (!arg[0]) {
+ return missing_container_arg(cmd);
+ }
+
+ relative = ap_server_root_relative(cmd->temp_pool, arg);
+ file_exists = (apr_stat(&sb, relative, 0, cmd->pool) == APR_SUCCESS);
+
+ if ((!not && file_exists) || (not && !file_exists)) {
+ ap_directive_t *parent = NULL;
+ ap_directive_t *current = NULL;
+ const char *retval;
+
+ retval = ap_build_cont_config(cmd->pool, cmd->temp_pool, cmd,
+ &current, &parent, "<IfFile");
+ *(ap_directive_t **)dummy = current;
+ return retval;
+ }
+ else {
+ *(ap_directive_t **)dummy = NULL;
+ return ap_soak_end_container(cmd, "<IfFile");
+ }
+}
+
/* httpd.conf commands... beginning with the <VirtualHost> business */
static const char *virtualhost_section(cmd_parms *cmd, void *dummy,
@@ -4464,6 +4507,8 @@ AP_INIT_TAKE1("<IfModule", start_ifmod, NULL, EXEC_ON_READ | OR_ALL,
"Container for directives based on existence of specified modules"),
AP_INIT_TAKE1("<IfDefine", start_ifdefine, NULL, EXEC_ON_READ | OR_ALL,
"Container for directives based on existence of command line defines"),
+AP_INIT_TAKE1("<IfFile", start_iffile, NULL, EXEC_ON_READ | OR_ALL,
+ "Container for directives based on existence of files on disk"),
AP_INIT_RAW_ARGS("<DirectoryMatch", dirsection, (void*)1, RSRC_CONF,
"Container for directives affecting resources located in the "
"specified directories"),