Comparison

mod_firewall/mod_firewall.lua @ 2543:3c16f0a8d66c

mod_firewall: Do patterns properly, instead of cheating
author Matthew Wild <mwild1@gmail.com>
date Tue, 21 Feb 2017 22:41:08 +0000
parent 2539:1510b66a43fc
child 2544:223eea31588d
comparison
equal deleted inserted replaced
2542:cca9de97526b 2543:3c16f0a8d66c
207 local_code = function (search_name) 207 local_code = function (search_name)
208 local search_path = assert(active_definitions.SEARCH[search_name], "Undefined search path: "..search_name); 208 local search_path = assert(active_definitions.SEARCH[search_name], "Undefined search path: "..search_name);
209 return ("local search_%s = tostring(stanza:find(%q) or \"\")"):format(search_name, search_path); 209 return ("local search_%s = tostring(stanza:find(%q) or \"\")"):format(search_name, search_path);
210 end; 210 end;
211 }; 211 };
212 pattern = {
213 local_code = function (pattern_name)
214 local pattern = assert(active_definitions.PATTERN[pattern_name], "Undefined pattern: "..pattern_name);
215 return ("local pattern_%s = %q"):format(pattern_name, pattern);
216 end;
217 };
212 tokens = { 218 tokens = {
213 local_code = function (search_and_pattern) 219 local_code = function (search_and_pattern)
214 local search_name, pattern_name = search_and_pattern:match("^([^%-]+)_(.+)$"); 220 local search_name, pattern_name = search_and_pattern:match("^([^%-]+)_(.+)$");
215 local code = ([[local tokens_%s_%s = {}; 221 local code = ([[local tokens_%s_%s = {};
216 if search_%s then 222 if search_%s then
217 for s in search_%s:gmatch(patterns.%s) do 223 for s in search_%s:gmatch(pattern_%s) do
218 tokens_%s_%s[s] = true; 224 tokens_%s_%s[s] = true;
219 end 225 end
220 end 226 end
221 ]]):format(search_name, pattern_name, search_name, search_name, pattern_name, search_name, pattern_name); 227 ]]):format(search_name, pattern_name, search_name, search_name, pattern_name, search_name, pattern_name);
222 return code, { "search:"..search_name }; 228 return code, { "search:"..search_name, "pattern:"..pattern_name };
223 end; 229 end;
224 }; 230 };
225 scan_list = { 231 scan_list = {
226 global_code = [[local function scan_list(list, items) for item in pairs(items) do if list:contains(item) then return true; end end end]]; 232 global_code = [[local function scan_list(list, items) for item in pairs(items) do if list:contains(item) then return true; end end end]];
227 } 233 }