From adaa0e2c25fb6cf60aa9e3c4088915733d073022 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Thu, 22 Sep 2016 19:29:49 +0100 Subject: [PATCH] Routing: for efficiency, avoid complexifying the "condition" string until the second is read from config --- src/src/readconf.c | 22 ++++++++++------------ src/src/route.c | 2 +- test/stderr/0364 | 6 +++--- test/stderr/0377 | 20 ++++++++++---------- test/stderr/0378 | 4 ++-- test/stderr/0499 | 2 +- 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/src/readconf.c b/src/src/readconf.c index 0a06559f4..3e82b7119 100644 --- a/src/src/readconf.c +++ b/src/src/readconf.c @@ -1462,7 +1462,6 @@ int intbase = 0; uschar *inttype = US""; uschar *sptr; uschar *s = buffer; -uschar *saved_condition, *strtemp; uschar **str_target; uschar name[64]; uschar name2[64]; @@ -1597,19 +1596,18 @@ switch (type) control block and flags word. */ case opt_stringptr: - if (data_block == NULL) - str_target = (uschar **)(ol->value); - else - str_target = (uschar **)((uschar *)data_block + (long int)(ol->value)); + str_target = data_block ? USS (US data_block + (long int)(ol->value)) + : USS (ol->value); if (ol->type & opt_rep_con) { + uschar * saved_condition; /* We already have a condition, we're conducting a crude hack to let multiple condition rules be chained together, despite storing them in text form. */ - saved_condition = *str_target; - strtemp = string_sprintf("${if and{{bool_lax{%s}}{bool_lax{%s}}}}", - saved_condition, sptr); - *str_target = string_copy_malloc(strtemp); + *str_target = string_copy_malloc( (saved_condition = *str_target) + ? string_sprintf("${if and{{bool_lax{%s}}{bool_lax{%s}}}}", + saved_condition, sptr) + : sptr); /* TODO(pdp): there is a memory leak here and just below when we set 3 or more conditions; I still don't understand the store mechanism enough to know @@ -1645,10 +1643,10 @@ switch (type) break; case opt_rewrite: - if (data_block == NULL) - *((uschar **)(ol->value)) = sptr; + if (data_block) + *USS (US data_block + (long int)(ol->value)) = sptr; else - *((uschar **)((uschar *)data_block + (long int)(ol->value))) = sptr; + *USS (ol->value) = sptr; freesptr = FALSE; if (type == opt_rewrite) { diff --git a/src/src/route.c b/src/src/route.c index 57dfc09e6..cd44389db 100644 --- a/src/src/route.c +++ b/src/src/route.c @@ -979,7 +979,7 @@ if ((rc = check_files(r->require_files, perror)) != OK) if (r->condition) { - DEBUG(D_route) debug_printf("checking \"condition\"\n"); + DEBUG(D_route) debug_printf("checking \"condition\" \"%.80s\"...\n", r->condition); if (!expand_check_condition(r->condition, r->name, US"router")) { if (search_find_defer) diff --git a/test/stderr/0364 b/test/stderr/0364 index f648839f1..d6a49bbf6 100644 --- a/test/stderr/0364 +++ b/test/stderr/0364 @@ -81,7 +81,7 @@ r2 router declined for solik@otherhost.test.ex --------> r3 router <-------- local_part=solik domain=otherhost.test.ex checking domains -checking "condition" +checking "condition" "${if eq{$address_data}{}{no}{yes}}"... processing address_data calling r3 router rda_interpret (string): $local_part@$original_domain.sub.test.ex @@ -107,7 +107,7 @@ r2 router declined for solik@otherhost.sub.test.ex --------> r3 router <-------- local_part=solik domain=otherhost.sub.test.ex checking domains -checking "condition" +checking "condition" "${if eq{$address_data}{}{no}{yes}}"... r3 router skipped: condition failure --------> r4 router <-------- local_part=solik domain=otherhost.sub.test.ex @@ -184,7 +184,7 @@ r2 router declined for xxx@testsub.test.ex --------> r3 router <-------- local_part=xxx domain=testsub.test.ex checking domains -checking "condition" +checking "condition" "${if eq{$address_data}{}{no}{yes}}"... processing address_data calling r3 router rda_interpret (string): $local_part@$original_domain.sub.test.ex diff --git a/test/stderr/0377 b/test/stderr/0377 index ca3949890..848ee3367 100644 --- a/test/stderr/0377 +++ b/test/stderr/0377 @@ -63,7 +63,7 @@ bbbb_0 router skipped: local_parts mismatch --------> cccc_2nd_time router <-------- local_part=cccc domain=myhost.test.ex checking local_parts -checking "condition" +checking "condition" "${if first_delivery{no}{yes}}"... cccc_2nd_time router skipped: condition failure --------> cccc_redirect router <-------- local_part=cccc domain=myhost.test.ex @@ -101,7 +101,7 @@ seen_aaaa router skipped: local_parts mismatch --------> bbbb router <-------- local_part=bbbb domain=myhost.test.ex checking local_parts -checking "condition" +checking "condition" "${if first_delivery{yes}{no}}"... calling bbbb router rda_interpret (string): bbbb@$domain, defer_bbbb@$domain expanded: bbbb@myhost.test.ex, defer_bbbb@myhost.test.ex @@ -127,7 +127,7 @@ defer router skipped: local_parts mismatch --------> unseen_aaaa router <-------- local_part=aaaa domain=myhost.test.ex checking local_parts -checking "condition" +checking "condition" "${if first_delivery{yes}{no}}"... calling unseen_aaaa router rda_interpret (string): defer_aaaa@$domain expanded: defer_aaaa@myhost.test.ex @@ -207,7 +207,7 @@ bbbb_0 router skipped: local_parts mismatch --------> cccc_2nd_time router <-------- local_part=cccc domain=myhost.test.ex checking local_parts -checking "condition" +checking "condition" "${if first_delivery{no}{yes}}"... cccc_2nd_time router skipped: condition failure --------> cccc_redirect router <-------- cccc_redirect router skipped: previously routed cccc@myhost.test.ex @@ -376,7 +376,7 @@ bbbb_0 router skipped: local_parts mismatch --------> cccc_2nd_time router <-------- local_part=cccc domain=myhost.test.ex checking local_parts -checking "condition" +checking "condition" "${if first_delivery{no}{yes}}"... calling cccc_2nd_time router rda_interpret (string): $local_part@$domain expanded: cccc@myhost.test.ex @@ -406,7 +406,7 @@ seen_aaaa router skipped: local_parts mismatch --------> bbbb router <-------- local_part=bbbb domain=myhost.test.ex checking local_parts -checking "condition" +checking "condition" "${if first_delivery{yes}{no}}"... bbbb router skipped: condition failure --------> bbbb_0 router <-------- local_part=bbbb domain=myhost.test.ex @@ -431,7 +431,7 @@ defer router skipped: local_parts mismatch --------> unseen_aaaa router <-------- local_part=aaaa domain=myhost.test.ex checking local_parts -checking "condition" +checking "condition" "${if first_delivery{yes}{no}}"... unseen_aaaa router skipped: condition failure --------> seen_aaaa router <-------- local_part=aaaa domain=myhost.test.ex @@ -627,7 +627,7 @@ bbbb_0 router skipped: local_parts mismatch --------> cccc_2nd_time router <-------- local_part=cccc domain=myhost.test.ex checking local_parts -checking "condition" +checking "condition" "${if first_delivery{no}{yes}}"... calling cccc_2nd_time router rda_interpret (string): $local_part@$domain expanded: cccc@myhost.test.ex @@ -657,7 +657,7 @@ seen_aaaa router skipped: local_parts mismatch --------> bbbb router <-------- local_part=bbbb domain=myhost.test.ex checking local_parts -checking "condition" +checking "condition" "${if first_delivery{yes}{no}}"... bbbb router skipped: condition failure --------> bbbb_0 router <-------- local_part=bbbb domain=myhost.test.ex @@ -682,7 +682,7 @@ defer router skipped: local_parts mismatch --------> unseen_aaaa router <-------- local_part=aaaa domain=myhost.test.ex checking local_parts -checking "condition" +checking "condition" "${if first_delivery{yes}{no}}"... unseen_aaaa router skipped: condition failure --------> seen_aaaa router <-------- local_part=aaaa domain=myhost.test.ex diff --git a/test/stderr/0378 b/test/stderr/0378 index bb7b4a40a..d82f049a7 100644 --- a/test/stderr/0378 +++ b/test/stderr/0378 @@ -35,7 +35,7 @@ defer router skipped: local_parts mismatch --------> aaaa_2nd_time router <-------- local_part=aaaa domain=myhost.test.ex checking local_parts -checking "condition" +checking "condition" "${if first_delivery{no}{yes}}"... aaaa_2nd_time router skipped: condition failure --------> aaaa router <-------- local_part=aaaa domain=myhost.test.ex @@ -212,7 +212,7 @@ defer router skipped: local_parts mismatch --------> aaaa_2nd_time router <-------- local_part=aaaa domain=myhost.test.ex checking local_parts -checking "condition" +checking "condition" "${if first_delivery{no}{yes}}"... calling aaaa_2nd_time router rda_interpret (string): aaaa@$domain expanded: aaaa@myhost.test.ex diff --git a/test/stderr/0499 b/test/stderr/0499 index 4592f6469..2ecd699aa 100644 --- a/test/stderr/0499 +++ b/test/stderr/0499 @@ -25,7 +25,7 @@ host_find_bydns yield = HOST_FOUND_LOCAL (3); returned hosts: eximtesthost.test.ex ip4.ip4.ip4.ip4 MX=5 mxt1.test.ex in "@mx_any"? yes (matched "@mx_any") mxt1.test.ex in "+anymx"? yes (matched "+anymx") -checking "condition" +checking "condition" "${if match_domain{$domain}{+anymx}{yes}}"... DNS lookup of mxt1.test.ex (MX) using fakens DNS lookup of mxt1.test.ex (MX) succeeded DNS lookup of eximtesthost.test.ex (A) using fakens -- 2.30.2