Comparison

mod_firewall/conditions.lib.lua @ 962:93ffa3ffc66f

mod_firewall/conditions: Support Lua patterns in JID matching, and make <*>@example.com NOT match example.com
author Matthew Wild <mwild1@gmail.com>
date Fri, 05 Apr 2013 19:17:33 +0100
parent 954:bec5b6e2eab8
child 963:c7fca2c9e24f
comparison
equal deleted inserted replaced
961:f0108ec2b016 962:93ffa3ffc66f
22 local function compile_jid_match_part(part, match) 22 local function compile_jid_match_part(part, match)
23 if not match then 23 if not match then
24 return part.." == nil" 24 return part.." == nil"
25 end 25 end
26 local pattern = match:match("<(.*)>"); 26 local pattern = match:match("<(.*)>");
27 -- TODO: Support Lua pattern matching (main issue syntax... << >>?)
28 if pattern then 27 if pattern then
29 if pattern ~= "*" then 28 if pattern == "*" then
30 return ("%s:match(%q)"):format(part, pattern:gsub(".", wildcard_equivs)); 29 return part;
31 end 30 end
31 if pattern:match("^<.*>$") then
32 pattern = pattern:match("^<(.*)>$");
33 else
34 pattern = pattern:gsub("%p", "%%%0"):gsub("%%(%p)", wildcard_equivs);
35 end
36 return ("%s:match(%q)"):format(part, "^"..pattern.."$");
32 else 37 else
33 return ("%s == %q"):format(part, match); 38 return ("%s == %q"):format(part, match);
34 end 39 end
35 end 40 end
36 41