summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNigel Metheringham <nigel@exim.org>2009-10-14 14:48:40 +0000
committerNigel Metheringham <nigel@exim.org>2009-10-14 14:48:40 +0000
commitf3766eb5a200d0deb99dc3f096ced249727940cd (patch)
treec2cd6bc893834396868c3c821bd1e4faf6747ad5 /src
parent36f12725ebda2bfd6ed4fe98b0eeaf1ce01f2604 (diff)
bool: condition support. fixes: #167
Diffstat (limited to 'src')
-rw-r--r--src/src/acl.c5
-rw-r--r--src/src/expand.c51
2 files changed, 54 insertions, 2 deletions
diff --git a/src/src/acl.c b/src/src/acl.c
index a3e79b13d..04b7fe5f5 100644
--- a/src/src/acl.c
+++ b/src/src/acl.c
@@ -1,4 +1,4 @@
-/* $Cambridge: exim/src/src/acl.c,v 1.83 2009/06/10 07:34:04 tom Exp $ */
+/* $Cambridge: exim/src/src/acl.c,v 1.84 2009/10/14 14:48:41 nm4 Exp $ */
/*************************************************
* Exim - an Internet mail transport agent *
@@ -2540,6 +2540,9 @@ for (; cb != NULL; cb = cb->next)
#endif
case ACLC_CONDITION:
+ /* The true/false parsing here should be kept in sync with that used in
+ expand.c when dealing with ECOND_BOOL so that we don't have too many
+ different definitions of what can be a boolean. */
if (Ustrspn(arg, "0123456789") == Ustrlen(arg)) /* Digits, or empty */
rc = (Uatoi(arg) == 0)? FAIL : OK;
else
diff --git a/src/src/expand.c b/src/src/expand.c
index 943ec76ec..b52901c32 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -1,4 +1,4 @@
-/* $Cambridge: exim/src/src/expand.c,v 1.100 2009/08/31 21:14:50 tom Exp $ */
+/* $Cambridge: exim/src/src/expand.c,v 1.101 2009/10/14 14:48:41 nm4 Exp $ */
/*************************************************
* Exim - an Internet mail transport agent *
@@ -242,6 +242,7 @@ static uschar *cond_table[] = {
US">",
US">=",
US"and",
+ US"bool",
US"crypteq",
US"def",
US"eq",
@@ -283,6 +284,7 @@ enum {
ECOND_NUM_G,
ECOND_NUM_GE,
ECOND_AND,
+ ECOND_BOOL,
ECOND_CRYPTEQ,
ECOND_DEF,
ECOND_STR_EQ,
@@ -2408,6 +2410,53 @@ switch(cond_type)
}
+ /* The bool{} expansion condition maps a string to boolean.
+ The values supported should match those supported by the ACL condition
+ (acl.c, ACLC_CONDITION) so that we keep to a minimum the different ideas
+ of true/false. Note that Router "condition" rules have a different
+ interpretation, where general data can be used and only a few values
+ map to FALSE.
+ Note that readconf.c boolean matching, for boolean configuration options,
+ only matches true/yes/false/no. */
+ case ECOND_BOOL:
+ {
+ uschar *sub_arg[1];
+ uschar *t;
+ size_t len;
+ BOOL boolvalue = FALSE;
+ while (isspace(*s)) s++;
+ if (*s != '{') goto COND_FAILED_CURLY_START;
+ switch(read_subs(sub_arg, 1, 1, &s, yield == NULL, FALSE, US"bool"))
+ {
+ case 1: expand_string_message = US"too few arguments or bracketing "
+ "error for bool";
+ /*FALLTHROUGH*/
+ case 2:
+ case 3: return NULL;
+ }
+ t = sub_arg[0];
+ while (isspace(*t)) t++;
+ len = Ustrlen(t);
+ DEBUG(D_expand)
+ debug_printf("considering bool: %s\n", len ? t : US"<empty>");
+ if (len == 0)
+ boolvalue = FALSE;
+ else if (Ustrspn(t, "0123456789") == len)
+ boolvalue = (Uatoi(t) == 0) ? FALSE : TRUE;
+ else if (strcmpic(t, US"true") == 0 || strcmpic(t, US"yes") == 0)
+ boolvalue = TRUE;
+ else if (strcmpic(t, US"false") == 0 || strcmpic(t, US"no") == 0)
+ boolvalue = FALSE;
+ else
+ {
+ expand_string_message = string_sprintf("unrecognised boolean "
+ "value \"%s\"", t);
+ return NULL;
+ }
+ if (yield != NULL) *yield = (boolvalue != 0);
+ return s;
+ }
+
/* Unknown condition */
default: