From 774f43485cb65b6ec013d913a6fe3783dbcde422 Mon Sep 17 00:00:00 2001
From: Nick Kew
Date: Thu, 3 Apr 2008 10:23:12 +0000
Subject: [PATCH] HTTPD Core: Implement sections for conditional (runtime)
configuration. N.B. This is a first pass, and has a way to go!
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@644253 13f79535-47bb-0310-9956-ffa450edef68
---
docs/manual/mod/core.xml | 33 +++++++++++++++++++-
include/ap_mmn.h | 4 ++-
include/http_core.h | 2 ++
server/core.c | 67 ++++++++++++++++++++++++++++++++++++++++
server/request.c | 23 +++++++++-----
5 files changed, 120 insertions(+), 9 deletions(-)
diff --git a/docs/manual/mod/core.xml b/docs/manual/mod/core.xml
index 8dfe877d0d..a9c79eb0b8 100644
--- a/docs/manual/mod/core.xml
+++ b/docs/manual/mod/core.xml
@@ -1303,6 +1303,36 @@ MIME content-type
+
+If
+Contains directives that apply only if a condition is
+satisfied by a request at runtime
+<If expression> ... </If>
+server configvirtual host
+directory.htaccess
+
+All
+
+
+ The If directive
+ evaluates an expression at runtime, and applies the enclosed
+ directives if and only if the expression evaluates to true.
+ For example:
+
+
+ <If "$req{Host} = ''">
+
+
+ would match HTTP/1.0 requests without a Host: header.
+
+
+How <Directory>, <Location>,
+ <Files> sections work for an explanation of how these
+ different sections are combined when a request is received.
+ If has the same precedence
+ and usage as Files
+
+
IfDefine
Encloses directives that will be processed only
@@ -1633,7 +1663,8 @@ methods
LOCK
, and UNLOCK
. The method name is
case-sensitive. If GET
is used it will also
restrict HEAD
requests. The TRACE
method
- cannot be limited.
+ cannot be limited (see TraceEnable).
A LimitExcept section should always be
diff --git a/include/ap_mmn.h b/include/ap_mmn.h
index 52f324063f..45ccbe0fe6 100644
--- a/include/ap_mmn.h
+++ b/include/ap_mmn.h
@@ -151,6 +151,8 @@
* 20071108.9 (2.3.0-dev) Add chroot support to unixd_config
* 20071108.10(2.3.0-dev) Introduce new ap_expr API
* 20071108.11(2.3.0-dev) Revise/Expand new ap_expr API
+ * 20071108.12(2.3.0-dev) Remove ap_expr_clone from the API (same day it was added)
+ * 20000403.0 (2.3.0-dev) Add condition field to core dir config
*/
#define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
@@ -158,7 +160,7 @@
#ifndef MODULE_MAGIC_NUMBER_MAJOR
#define MODULE_MAGIC_NUMBER_MAJOR 20071108
#endif
-#define MODULE_MAGIC_NUMBER_MINOR 11 /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 0 /* 0...n */
/**
* Determine if the server's current MODULE_MAGIC_NUMBER is at least a
diff --git a/include/http_core.h b/include/http_core.h
index 31b14895ee..0b537e253d 100644
--- a/include/http_core.h
+++ b/include/http_core.h
@@ -30,6 +30,7 @@
#include "apr_hash.h"
#include "apr_optional.h"
#include "util_filter.h"
+#include "ap_expr.h"
#if APR_HAVE_STRUCT_RLIMIT
#include
@@ -541,6 +542,7 @@ typedef struct {
#define USE_CANONICAL_PHYS_PORT_UNSET (2)
unsigned use_canonical_phys_port : 2;
+ ap_parse_node_t *condition; /* Conditionally merge sections */
} core_dir_config;
/* Per-server core configuration */
diff --git a/server/core.c b/server/core.c
index 02734ef7e4..cfa9fc4ad6 100644
--- a/server/core.c
+++ b/server/core.c
@@ -1995,6 +1995,71 @@ static const char *filesection(cmd_parms *cmd, void *mconfig, const char *arg)
return NULL;
}
+static const char *ifsection(cmd_parms *cmd, void *mconfig, const char *arg)
+{
+ const char *errmsg;
+ const char *endp = ap_strrchr_c(arg, '>');
+ int old_overrides = cmd->override;
+ char *old_path = cmd->path;
+ core_dir_config *conf;
+ ap_regex_t *r = NULL;
+ const command_rec *thiscmd = cmd->cmd;
+ core_dir_config *c = mconfig;
+ ap_conf_vector_t *new_file_conf = ap_create_per_dir_config(cmd->pool);
+ const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT|NOT_IN_LOCATION);
+ const char *condition;
+ int expr_err = 0;
+
+ if (err != NULL) {
+ return err;
+ }
+
+ if (endp == NULL) {
+ return unclosed_directive(cmd);
+ }
+
+ arg = apr_pstrndup(cmd->pool, arg, endp - arg);
+
+ if (!arg[0]) {
+ return missing_container_arg(cmd);
+ }
+
+ //cmd->path = "*";
+ condition = ap_getword_conf(cmd->pool, &arg);
+ /* Only if not an .htaccess file */
+ if (!old_path) {
+ cmd->override = OR_ALL|ACCESS_CONF;
+ }
+
+ /* initialize our config and fetch it */
+ conf = ap_set_config_vectors(cmd->server, new_file_conf, cmd->path,
+ &core_module, cmd->pool);
+
+ conf->condition = ap_expr_parse(cmd->pool, condition, &expr_err);
+ if (expr_err) {
+ return "Cannot parse condition clause";
+ }
+
+ errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_file_conf);
+ if (errmsg != NULL)
+ return errmsg;
+
+ conf->d = cmd->path;
+ conf->d_is_fnmatch = 0;
+ conf->r = NULL;
+
+ ap_add_file_conf(c, new_file_conf);
+
+ if (*arg != '\0') {
+ return apr_pstrcat(cmd->pool, "Multiple ", thiscmd->name,
+ "> arguments not supported.", NULL);
+ }
+
+ cmd->path = old_path;
+ cmd->override = old_overrides;
+
+ return NULL;
+}
static const char *start_ifmod(cmd_parms *cmd, void *mconfig, const char *arg)
{
@@ -3209,6 +3274,8 @@ AP_INIT_TAKE1("AcceptPathInfo", set_accept_path_info, NULL, OR_FILEINFO,
"Set to on or off for PATH_INFO to be accepted by handlers, or default for the per-handler preference"),
AP_INIT_TAKE1("Define", set_define, NULL, RSRC_CONF,
"Define the existance of a variable. Same as passing -D to the command line."),
+AP_INIT_RAW_ARGS("r
- ? ap_regexec(entry_core->r, cache->cached , 0, NULL, 0)
- : (entry_core->d_is_fnmatch
- ? apr_fnmatch(entry_core->d, cache->cached, APR_FNM_PATHNAME)
- : strcmp(entry_core->d, cache->cached))) {
- continue;
+ if (entry_core->condition) {
+ if (!ap_expr_eval(r, entry_core->condition, &err, NULL,
+ ap_expr_string, NULL)) {
+ continue;
+ }
+ }
+ else {
+ if (entry_core->r
+ ? ap_regexec(entry_core->r, cache->cached , 0, NULL, 0)
+ : (entry_core->d_is_fnmatch
+ ? apr_fnmatch(entry_core->d, cache->cached, APR_FNM_PATHNAME)
+ : strcmp(entry_core->d, cache->cached))) {
+ continue;
+ }
}
/* If we merged this same section last time, reuse it
--
2.40.0