Comparison

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
parent 964:04e85eb3dfef
child 968:f3b0ddeebd9d
comparison
equal deleted inserted replaced
964:04e85eb3dfef 965:d4e24fb289c0
59 end 59 end
60 60
61 function condition_handlers.TYPE(type) 61 function condition_handlers.TYPE(type)
62 return compile_comparison_list("(type or (name == 'message' and 'chat') or (name == 'presence' and 'available'))", type), { "type", "name" }; 62 return compile_comparison_list("(type or (name == 'message' and 'chat') or (name == 'presence' and 'available'))", type), { "type", "name" };
63 end 63 end
64
65 local function zone_check(zone, which)
66 local which_not = which == "from" and "to" or "from";
67 return ("(zone_%s[%s_host] or zone_%s[%s] or zone_%s[bare_%s]) "
68 .."and not(zone_%s[%s_host] or zone_%s[%s] or zone_%s[%s])"
69 )
70 :format(zone, which, zone, which, zone, which,
71 zone, which_not, zone, which_not, zone, which_not), {
72 "split_to", "split_from", "bare_to", "bare_from", "zone:"..zone
73 };
64 end 74 end
65 75
66 function condition_handlers.ENTERING(zone) 76 function condition_handlers.ENTERING(zone)
67 return ("(zones[%q] and (zones[%q][to_host] or " 77 return zone_check(zone, "to");
68 .."zones[%q][to] or "
69 .."zones[%q][bare_to]))"
70 )
71 :format(zone, zone, zone, zone), { "split_to", "bare_to" };
72 end 78 end
73 79
74 function condition_handlers.LEAVING(zone) 80 function condition_handlers.LEAVING(zone)
75 return ("zones[%q] and (zones[%q][from_host] or " 81 return zone_check(zone, "from");
76 .."(zones[%q][from] or "
77 .."zones[%q][bare_from]))")
78 :format(zone, zone, zone, zone), { "split_from", "bare_from" };
79 end 82 end
80 83
81 function condition_handlers.PAYLOAD(payload_ns) 84 function condition_handlers.PAYLOAD(payload_ns)
82 return ("stanza:get_child(nil, %q)"):format(payload_ns); 85 return ("stanza:get_child(nil, %q)"):format(payload_ns);
83 end 86 end