vhost.m4: Refactor virtual host routing some more.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 6 Mar 2014 01:54:33 +0000 (01:54 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 6 Mar 2014 02:04:05 +0000 (02:04 +0000)
Move the does-this-key-exist condition out of the `VHOST' macro and
into `VHOST_FILTER'.  Alas, this means we must repeat the logic for
the `virtual_route' router.  But we can take the opportunity to elide
the unnecessary existence checks for the domain keys we just tested in
the router conditions.

Also, switch the arguments to `VHOST_FILTER' around.  I think they
make more sense like this.

vhost.m4

index 3643dce..4ac677b 100644 (file)
--- a/vhost.m4
+++ b/vhost.m4
 m4_define(<:VHOST:>,
        <:domains = ${if exists{CONF_sysconf_dir/domains.conf} \
                         {partial0-lsearch; CONF_sysconf_dir/domains.conf} \
-                        {}}
-       condition = DOMKV($1):>)
+                        {}}:>)
 m4_define(<:VHOST_FILTER:>,
        <:FILTER_BASE
-       VHOST(<:$1:>)
+       VHOST
+       condition = DOMKV($2, {true}{false})
        router_home_directory = DOMKV(home, {$value} fail)
        more = ${if bool{DOMKV(final, {$value}{true})} {false} {true}}
-       $2 = ${expand:DOMKV($1, {$value} fail)}:>)
+       $1 = ${expand:DOMKV($2)}:>)
 m4_define(<:VHOST_USER:>,
        <:user = DOMKV(owner, {$value}{CONF_filter_user})
        errors_to = DOMKV(errors_to, {$value} fail):>)
@@ -45,8 +45,9 @@ SECTION(routers, route)m4_dnl
 virtual_route:
        driver = manualroute
        self = fail
-       VHOST(route)
-       route_data = DOMKV(route, {$value} fail)
+       VHOST
+       condition = DOMKV(route, {true}{false})
+       route_data = DOMKV(route)
        same_domain_copy_routing = true
        transport = smtp
        no_more
@@ -56,10 +57,10 @@ SECTION(routers, virtual)m4_dnl
 ## be done in two passes, so that we can identify the correct user's spam
 ## threshold during address verification.
 FILTER_ROUTER(virtual_data,
-       <:VHOST_FILTER(redirect, data):>,, <:
+       <:VHOST_FILTER(data, redirect):>,, <:
        VHOST_USER:>)
 FILTER_ROUTER(virtual_file,
-       <:VHOST_FILTER(filter, file):>,, <:
+       <:VHOST_FILTER(file, filter):>,, <:
        VHOST_USER:>)
 
 DIVERT(null)