diff mod_firewall/conditions.lib.lua @ 965:d4e24fb289c0

mod_firewall: Improve zone handling, make it more efficient, and support dynamic dependencies in the compiler. ENTERING and LEAVING conditions now work at expected (not matching stanzas flowing within a zone).
author Matthew Wild <mwild1@gmail.com>
date Fri, 05 Apr 2013 19:21:46 +0100
parents 04e85eb3dfef
children f3b0ddeebd9d
line wrap: on
line diff
--- a/mod_firewall/conditions.lib.lua	Fri Apr 05 19:20:05 2013 +0100
+++ b/mod_firewall/conditions.lib.lua	Fri Apr 05 19:21:46 2013 +0100
@@ -61,21 +61,24 @@
 function condition_handlers.TYPE(type)
 	return compile_comparison_list("(type or (name == 'message' and 'chat') or (name == 'presence' and 'available'))", type), { "type", "name" };
 end
+
+local function zone_check(zone, which)
+	local which_not = which == "from" and "to" or "from";
+	return ("(zone_%s[%s_host] or zone_%s[%s] or zone_%s[bare_%s]) "
+		.."and not(zone_%s[%s_host] or zone_%s[%s] or zone_%s[%s])"
+		)
+		:format(zone, which, zone, which, zone, which,
+		zone, which_not, zone, which_not, zone, which_not), {
+			"split_to", "split_from", "bare_to", "bare_from", "zone:"..zone
+		};
 end
 
 function condition_handlers.ENTERING(zone)
-	return ("(zones[%q] and (zones[%q][to_host] or "
-		.."zones[%q][to] or "
-		.."zones[%q][bare_to]))"
-		)
-		:format(zone, zone, zone, zone), { "split_to", "bare_to" };
+	return zone_check(zone, "to");
 end
 
 function condition_handlers.LEAVING(zone)
-	return ("zones[%q] and (zones[%q][from_host] or "
-		.."(zones[%q][from] or "
-		.."zones[%q][bare_from]))")
-		:format(zone, zone, zone, zone), { "split_from", "bare_from" };
+	return zone_check(zone, "from");
 end
 
 function condition_handlers.PAYLOAD(payload_ns)