Software /
code /
prosody-modules
Diff
mod_firewall/mod_firewall.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 | 960:d773a51af9b1 |
child | 966:a65df6e97d94 |
line wrap: on
line diff
--- a/mod_firewall/mod_firewall.lua Fri Apr 05 19:20:05 2013 +0100 +++ b/mod_firewall/mod_firewall.lua Fri Apr 05 19:21:46 2013 +0100 @@ -72,9 +72,14 @@ }; is_admin = { global_code = [[local is_admin = require "core.usermanager".is_admin]]}; core_post_stanza = { global_code = [[local core_post_stanza = prosody.core_post_stanza]] }; + zone = { global_code = function (zone) + assert(zone:match("^%a[%w_]*$"), "Invalid zone name: "..zone); + return ("local zone_%s = zones[%q] or {};"):format(zone, zone); + end }; }; local function include_dep(dep, code) + local dep, dep_param = dep:match("^([^:]+):?(.*)$"); local dep_info = available_deps[dep]; if not dep_info then module:log("error", "Dependency not found: %s", dep); @@ -91,10 +96,18 @@ include_dep(dep_dep, code); end if dep_info.global_code then - table.insert(code.global_header, dep_info.global_code); + if dep_param ~= "" then + table.insert(code.global_header, dep_info.global_code(dep_param)); + else + table.insert(code.global_header, dep_info.global_code); + end end if dep_info.local_code then - table.insert(code, "\n\t-- "..dep.."\n\t"..dep_info.local_code.."\n\n\t"); + if dep_param ~= "" then + table.insert(code, "\n\t-- "..dep.."\n\t"..dep_info.local_code(dep_param).."\n\n\t"); + else + table.insert(code, "\n\t-- "..dep.."\n\t"..dep_info.local_code.."\n\n\t"); + end end code.included_deps[dep] = true; end