Comparison

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
comparison
equal deleted inserted replaced
964:04e85eb3dfef 965:d4e24fb289c0
70 group_contains = { 70 group_contains = {
71 global_code = [[local group_contains = module:depends("groups").group_contains]]; 71 global_code = [[local group_contains = module:depends("groups").group_contains]];
72 }; 72 };
73 is_admin = { global_code = [[local is_admin = require "core.usermanager".is_admin]]}; 73 is_admin = { global_code = [[local is_admin = require "core.usermanager".is_admin]]};
74 core_post_stanza = { global_code = [[local core_post_stanza = prosody.core_post_stanza]] }; 74 core_post_stanza = { global_code = [[local core_post_stanza = prosody.core_post_stanza]] };
75 zone = { global_code = function (zone)
76 assert(zone:match("^%a[%w_]*$"), "Invalid zone name: "..zone);
77 return ("local zone_%s = zones[%q] or {};"):format(zone, zone);
78 end };
75 }; 79 };
76 80
77 local function include_dep(dep, code) 81 local function include_dep(dep, code)
82 local dep, dep_param = dep:match("^([^:]+):?(.*)$");
78 local dep_info = available_deps[dep]; 83 local dep_info = available_deps[dep];
79 if not dep_info then 84 if not dep_info then
80 module:log("error", "Dependency not found: %s", dep); 85 module:log("error", "Dependency not found: %s", dep);
81 return; 86 return;
82 end 87 end
89 code.included_deps[dep] = false; -- Pending flag (used to detect circular references) 94 code.included_deps[dep] = false; -- Pending flag (used to detect circular references)
90 for _, dep_dep in ipairs(dep_info.depends or {}) do 95 for _, dep_dep in ipairs(dep_info.depends or {}) do
91 include_dep(dep_dep, code); 96 include_dep(dep_dep, code);
92 end 97 end
93 if dep_info.global_code then 98 if dep_info.global_code then
94 table.insert(code.global_header, dep_info.global_code); 99 if dep_param ~= "" then
100 table.insert(code.global_header, dep_info.global_code(dep_param));
101 else
102 table.insert(code.global_header, dep_info.global_code);
103 end
95 end 104 end
96 if dep_info.local_code then 105 if dep_info.local_code then
97 table.insert(code, "\n\t-- "..dep.."\n\t"..dep_info.local_code.."\n\n\t"); 106 if dep_param ~= "" then
107 table.insert(code, "\n\t-- "..dep.."\n\t"..dep_info.local_code(dep_param).."\n\n\t");
108 else
109 table.insert(code, "\n\t-- "..dep.."\n\t"..dep_info.local_code.."\n\n\t");
110 end
98 end 111 end
99 code.included_deps[dep] = true; 112 code.included_deps[dep] = true;
100 end 113 end
101 114
102 local condition_handlers = module:require("conditions"); 115 local condition_handlers = module:require("conditions");