From 43ba45ce62100bc1dbc9b04b5d869f59026783f5 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Wed, 6 May 2020 19:55:17 +0100 Subject: [PATCH] Numeric variable returns --- doc/doc-docbook/spec.xfpt | 6 +++++- doc/doc-txt/NewStuff | 5 +++++ src/src/match.c | 34 +++++++++++++++++----------------- test/confs/0624 | 3 ++- test/log/0624 | 18 ++++++++++++------ test/scripts/0000-Basic/0624 | 2 +- test/stdout/0002 | 4 ++-- 7 files changed, 44 insertions(+), 28 deletions(-) diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt index 33e07db0a..c55dff0af 100644 --- a/doc/doc-docbook/spec.xfpt +++ b/doc/doc-docbook/spec.xfpt @@ -8545,7 +8545,7 @@ In today's Internet, the use of domain literals is controversial; see the &%allow_domain_literals%& main option. .new -The value for a match will be the &`@[]`& string. +The value for a match will be the string &`@[]`&. .wen @@ -8616,6 +8616,8 @@ list item such as &`*key.ex`& matches &'donkey.ex'& as well as .new The value for a match will be the list element string (starting with the asterisk). +Additionally, &$0$& will be set to the matched string +and &$1$& to the variable portion which the asterisk matched. .wen .next @@ -8637,6 +8639,8 @@ expression by expansion, of course). .new The value for a match will be the list element string (starting with the circumflex). +Additionally, &$0$& will be set to the string matching the regular expression, +and &$1$& (onwards) to any submatches identified by parentheses. .wen diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff index 493244ff1..cf142afb6 100644 --- a/doc/doc-txt/NewStuff +++ b/doc/doc-txt/NewStuff @@ -63,6 +63,11 @@ Version 4.94 19. bounce_message_file and warn_message_file are now expanded before use. +20. $domain_data and $localpart_data are now set by all list-match successes. + Previously only list items that performed lookups did so. + Also, matching list items that are tail-match or RE-match now set the + numeric variables $0 (etc) in the same way os other RE matches. + Version 4.93 diff --git a/src/src/match.c b/src/src/match.c index f9b539d10..65d44198e 100644 --- a/src/src/match.c +++ b/src/src/match.c @@ -106,7 +106,7 @@ void *handle; error = error; /* Keep clever compilers from complaining */ -if (valueptr != NULL) *valueptr = NULL; /* For non-lookup matches */ +if (valueptr) *valueptr = NULL; /* For regular expressions, use cb->origsubject rather than cb->subject so that it works if the pattern uses (?-i) to turn off case-independence, overriding @@ -136,7 +136,6 @@ if (pattern[0] == '^') : !regex_match_and_setup(re, s, 0, expand_setup) ) return FAIL; - /* assume the above wrote $0, $n... TODO: CHECK THAT !! */ if (valueptr) *valueptr = pattern; /* "value" gets the RE */ return OK; } @@ -158,7 +157,7 @@ if (pattern[0] == '*') { expand_nstring[++expand_setup] = s; /* write a $n, the matched subject variable-part */ expand_nlength[expand_setup] = slen - patlen; - expand_nmax = expand_setup; + expand_nmax = expand_setup; /* commit also $0, the matched subject */ } if (valueptr) *valueptr = pattern - 1; /* "value" gets the (original) pattern */ return OK; @@ -185,7 +184,7 @@ if (cb->at_is_special && pattern[0] == '@') if (Ustrncmp(ip->address, s+1, slen - 2) == 0 && ip->address[slen - 2] == 0) { -/* I see no reason not to return $0, the matchd IP. if (expand_setup >= 0) expand_nmax = expand_setup; */ + if (expand_setup >= 0) expand_nmax = expand_setup; /* commit $0, the IP addr */ if (valueptr) *valueptr = pattern; /* "value" gets the pattern */ return OK; } @@ -238,11 +237,11 @@ if (cb->at_is_special && pattern[0] == '@') return DEFER; } - if (rc != HOST_FOUND_LOCAL || secy) - if (prim || !removed) return FAIL; + if ((rc != HOST_FOUND_LOCAL || secy) && (prim || !removed)) + return FAIL; -/* again, $0 getting the subject, the matched IP. if (expand_setup >= 0) expand_nmax = expand_setup; */ - if (valueptr) *valueptr = pattern; /* "vaulue" gets the patterm */ + if (expand_setup >= 0) expand_nmax = expand_setup; /* commit $0, the matched subject */ + if (valueptr) *valueptr = pattern; /* "value" gets the patterm */ return OK; /*** The above line used to be the following line, but this is incorrect, @@ -268,10 +267,6 @@ if ((semicolon = Ustrchr(pattern, ';')) == NULL) if (expand_setup >= 0) expand_nmax = expand_setup; /* Original code! $0 gets the matched subject */ if (valueptr) *valueptr = pattern; /* "value" gets the pattern */ return OK; - -/* -XXX looks like $0 may be usable -*/ } /* Otherwise we have a lookup item. The lookup type, including partial, etc. is @@ -355,7 +350,7 @@ match_check_string(const uschar *s, const uschar *pattern, int expand_setup, { check_string_block cb; cb.origsubject = s; -cb.subject = caseless? string_copylc(s) : string_copy(s); +cb.subject = caseless ? string_copylc(s) : string_copy(s); cb.expand_setup = expand_setup; cb.use_partial = use_partial; cb.caseless = caseless; @@ -966,12 +961,17 @@ match_isinlist(const uschar *s, const uschar **listptr, int sep, unsigned int *local_cache_bits = cache_bits; check_string_block cb; cb.origsubject = s; -cb.subject = caseless? string_copylc(s) : string_copy(s); -cb.expand_setup = (sep > UCHAR_MAX)? 0 : -1; +cb.subject = caseless ? string_copylc(s) : string_copy(s); +cb.at_is_special = FALSE; +switch (type & ~MCL_NOEXPAND) + { + case MCL_DOMAIN: cb.at_is_special = TRUE; /*FALLTHROUGH*/ + case MCL_LOCALPART: cb.expand_setup = 0; break; + default: cb.expand_setup = sep > UCHAR_MAX ? 0 : -1; break; + } cb.use_partial = TRUE; cb.caseless = caseless; -cb.at_is_special = (type == MCL_DOMAIN || type == MCL_DOMAIN + MCL_NOEXPAND); -if (valueptr != NULL) *valueptr = NULL; +if (valueptr) *valueptr = NULL; return match_check_list(listptr, sep, anchorptr, &local_cache_bits, check_string, &cb, type, s, valueptr); } diff --git a/test/confs/0624 b/test/confs/0624 index d6f00b345..c8178d22b 100644 --- a/test/confs/0624 +++ b/test/confs/0624 @@ -18,6 +18,7 @@ begin acl chk_rcpt: accept domains = OPT logwrite = domain $domain - logwrite = value $domain_data + logwrite = value $domain_data + logwrite = \$0 '$0' \$1 '$1' # End diff --git a/test/log/0624 b/test/log/0624 index 3622b9f42..bbfa98dfe 100644 --- a/test/log/0624 +++ b/test/log/0624 @@ -1,13 +1,19 @@ 1999-03-02 09:44:33 U=CALLER F= rejected RCPT 1999-03-02 09:44:33 domain plainstring.ex -1999-03-02 09:44:33 value plainstring.ex +1999-03-02 09:44:33 value plainstring.ex +1999-03-02 09:44:33 $0 'plainstring.ex' $1 '' 1999-03-02 09:44:33 domain headtail.ex -1999-03-02 09:44:33 value *tail.ex +1999-03-02 09:44:33 value *tail.ex +1999-03-02 09:44:33 $0 'headtail.ex' $1 'head' 1999-03-02 09:44:33 domain headregextail.ex -1999-03-02 09:44:33 value ^.*regex +1999-03-02 09:44:33 value ^.*r(e.)ex +1999-03-02 09:44:33 $0 'headregextail.ex' $1 'eg' 1999-03-02 09:44:33 domain primaryhostname.ex -1999-03-02 09:44:33 value primaryhostname.ex +1999-03-02 09:44:33 value primaryhostname.ex +1999-03-02 09:44:33 $0 'primaryhostname.ex' $1 '' 1999-03-02 09:44:33 domain [127.0.0.1] -1999-03-02 09:44:33 value @[] +1999-03-02 09:44:33 value @[] +1999-03-02 09:44:33 $0 '[127.0.0.1]' $1 '' 1999-03-02 09:44:33 domain mx46.test.ex -1999-03-02 09:44:33 value @mx_any/ignore=1.1.1.1 +1999-03-02 09:44:33 value @mx_any/ignore=1.1.1.1 +1999-03-02 09:44:33 $0 '46.test.ex' $1 '' diff --git a/test/scripts/0000-Basic/0624 b/test/scripts/0000-Basic/0624 index d4e5acbbc..3715b125f 100644 --- a/test/scripts/0000-Basic/0624 +++ b/test/scripts/0000-Basic/0624 @@ -21,7 +21,7 @@ RCPT TO: QUIT **** # -exim -bs '-DOPT=notthis : ^.*regex : nothiseither' +exim -bs '-DOPT=notthis : ^.*r(e.)ex : nothiseither' HELO test MAIL FROM: RCPT TO: diff --git a/test/stdout/0002 b/test/stdout/0002 index 4345a0969..ea918aebb 100644 --- a/test/stdout/0002 +++ b/test/stdout/0002 @@ -443,9 +443,9 @@ newline tab\134backslash ~tilde\177DEL\200\201. > match_domain: yes > match_domain: no > -> >x@zz.aa.bb< [] >x@zz.aa.bb< +> >x@zz.aa.bb< [zz] >x@zz.aa.bb< > -> >x@xxxabc< [] >x@xxxabc< +> >x@xxxabc< [abc] >x@xxxabc< > > match_address: yes > match_address: yes -- 2.30.2