httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cove...@apache.org
Subject svn commit: r1769718 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/core.xml server/core.c
Date Tue, 15 Nov 2016 03:50:42 GMT
Author: covener
Date: Tue Nov 15 03:50:42 2016
New Revision: 1769718

URL: http://svn.apache.org/viewvc?rev=1769718&view=rev
Log:
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.


Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/docs/manual/mod/core.xml
    httpd/httpd/trunk/server/core.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1769718&r1=1769717&r2=1769718&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Tue Nov 15 03:50:42 2016
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.0
 
+  *) core: Add <IfFile> configuration section to allow any file on disk to be
+     used as a conditional.  [Edward Lu, Eric Covener]
+
   *) event: Avoid listener periodic wake ups by using the pollset wake-ability
      when available.  PR 57399.  [Yann Ylavic, Luca Toscano]
 

Modified: httpd/httpd/trunk/docs/manual/mod/core.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/core.xml?rev=1769718&r1=1769717&r2=1769718&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/core.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/core.xml Tue Nov 15 03:50:42 2016
@@ -2241,6 +2241,43 @@ if a test is true at startup</descriptio
 </directivesynopsis>
 
 <directivesynopsis type="section">
+<name>IfFile</name>
+<description>Encloses directives that will be processed only
+if file exists at startup</description>
+<syntax>&lt;IfFile [!]<var>parameter-name</var>&gt; ...
+    &lt;/IfFile&gt;</syntax>
+<contextlist><context>server config</context><context>virtual host</context>
+<context>directory</context><context>.htaccess</context>
+</contextlist>
+
+<usage>
+    <p>The <code>&lt;IfFile <var>filename</var>&gt;...&lt;/IfFile&gt;
+    </code> section is used to mark directives that are conditional on
+    the existence of a file on disk. The directives within an
+    <directive type="section">IfFile</directive> section are only
+    processed if the <var>filename</var> exists. If <var> filename</var>
+    doesn't exist, everything between the start and end markers is
+    ignored. <var>filename</var> can be an absolute path or a path
+    relative to the server root.</p>
+
+    <p>The <var>filename</var> in the <directive type="section">IfFile
+    </directive> section directive can take the same forms as the
+    <var>test</var> variable in the <directive type="section">IfDefine
+    </directive> section, i.e. the test can be negated if the <code>
+    !</code> character is placed directly before <var>filename</var>.
+    </p>
+   
+    <p>If a relative <var>filename</var> is supplied, the check is
+    <directive>ServerRoot</directive> relative.  In the  case where
+    this directive occurs before the <directive>ServerRoot</directive>,
+    the path will be checked relative to the compiled-in server root or
+    the server root passed in on the command line via the <code>-d</code>
+    parameter.</p>
+    
+</usage>
+</directivesynopsis>
+
+<directivesynopsis type="section">
 <name>IfModule</name>
 <description>Encloses directives that are processed conditional on the
 presence or absence of a specific module</description>

Modified: httpd/httpd/trunk/server/core.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/core.c?rev=1769718&r1=1769717&r2=1769718&view=diff
==============================================================================
--- httpd/httpd/trunk/server/core.c (original)
+++ httpd/httpd/trunk/server/core.c Tue Nov 15 03:50:42 2016
@@ -2851,6 +2851,49 @@ static const char *start_ifdefine(cmd_pa
     }
 }
 
+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,
   "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"),



Mime
View raw message