comparison mod_firewall/mod_firewall.lua @ 2528:44a71584521d

mod_firewall: Add SEARCH, PATTERN definitions and SCAN condition to check tokenized stanza:find() against a list
author Matthew Wild <mwild1@gmail.com>
date Mon, 20 Feb 2017 09:31:30 +0000
parents 5ff7eb601d60
children 9aed7f4e9f07
comparison
equal deleted inserted replaced
2527:5ff7eb601d60 2528:44a71584521d
197 assert(idsafe(list), "Invalid list name: "..list); 197 assert(idsafe(list), "Invalid list name: "..list);
198 assert(active_definitions.LIST[list], "Unknown list: "..list); 198 assert(active_definitions.LIST[list], "Unknown list: "..list);
199 return ("local list_%s = lists[%q];"):format(list, list); 199 return ("local list_%s = lists[%q];"):format(list, list);
200 end 200 end
201 }; 201 };
202 search = {
203 local_code = function (search_name)
204 local search_path = assert(active_definitions.SEARCH[search_name], "Undefined search path: "..search_name);
205 return ("local search_%s = tostring(stanza:find(%q) or \"\")"):format(search_name, search_path);
206 end;
207 };
208 tokens = {
209 local_code = function (search_and_pattern)
210 local search_name, pattern_name = search_and_pattern:match("^([^%-]+)_(.+)$");
211 local code = ([[local tokens_%s_%s = {};
212 if search_%s then
213 for s in search_%s:gmatch(patterns.%s) do
214 tokens_%s_%s[s] = true;
215 end
216 end
217 ]]):format(search_name, pattern_name, search_name, search_name, pattern_name, search_name, pattern_name);
218 return code, { "search:"..search_name };
219 end;
220 };
221 scan_list = {
222 global_code = [[local function scan_list(list, items) for item in pairs(items) do if list:contains(item) then return true; end end]];
223 }
202 }; 224 };
203 225
204 local function include_dep(dependency, code) 226 local function include_dep(dependency, code)
205 local dep, dep_param = dependency:match("^([^:]+):?(.*)$"); 227 local dep, dep_param = dependency:match("^([^:]+):?(.*)$");
206 local dep_info = available_deps[dep]; 228 local dep_info = available_deps[dep];