From 0ec9bd6fdc4e536c832fc2393435ed9134e874d5 Mon Sep 17 00:00:00 2001 From: Stefan Fritsch Date: Thu, 30 Dec 2010 11:59:02 +0000 Subject: [PATCH] Add -T operator to allow easy evaluation of on/off, 1/0, ... variables git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1053865 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/expr.html.en | 10 +++++++--- docs/manual/expr.xml | 8 ++++++-- server/util_expr_eval.c | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/docs/manual/expr.html.en b/docs/manual/expr.html.en index af94f551d2..919c109fae 100644 --- a/docs/manual/expr.html.en +++ b/docs/manual/expr.html.en @@ -307,10 +307,14 @@ listfunction ::= listfuncname "(" word ")" - + - - + + + +
NameDescription
-nString is not empty
True if string is not empty
-zString is empty
-RTrue if string is empty
-TFalse if string is empty, "0", "off", + "false", or "no" (case insensitive). + True otherwise.
-R Same as "%{REMOTE_ADDR} -ipmatch ...", but more efficient
diff --git a/docs/manual/expr.xml b/docs/manual/expr.xml index 6aed34d180..e3096d7f52 100644 --- a/docs/manual/expr.xml +++ b/docs/manual/expr.xml @@ -323,9 +323,13 @@ listfunction ::= listfuncname "(" word ")" NameDescription -n - String is not empty + True if string is not empty -z - String is empty + True if string is empty + -T + False if string is empty, "0", "off", + "false", or "no" (case insensitive). + True otherwise. -R Same as "%{REMOTE_ADDR} -ipmatch ...", but more efficient diff --git a/server/util_expr_eval.c b/server/util_expr_eval.c index 9d7f3a89f9..ba0df24060 100644 --- a/server/util_expr_eval.c +++ b/server/util_expr_eval.c @@ -1161,6 +1161,27 @@ static int op_R(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg1) return apr_ipsubnet_test(subnet, ctx->c->remote_addr); } +static int op_T(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg) +{ + switch (arg[0]) { + case '\0': + return FALSE; + case 'o': + case 'O': + return strcasecmp(arg, "off") == 0 ? FALSE : TRUE; + case 'n': + case 'N': + return strcasecmp(arg, "no") == 0 ? FALSE : TRUE; + case 'f': + case 'F': + return strcasecmp(arg, "false") == 0 ? FALSE : TRUE; + case '0': + return arg[1] == '\0' ? FALSE : TRUE; + default: + return TRUE; + } +} + static int op_fnmatch(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg1, const char *arg2) { @@ -1220,6 +1241,7 @@ static const struct expr_provider_single unary_op_providers[] = { { op_nz, "n", NULL }, { op_nz, "z", NULL }, { op_R, "R", subnet_parse_arg }, + { op_T, "T", NULL }, { NULL, NULL, NULL } }; -- 2.40.0