Software /
code /
prosody-modules
Changeset
2519:d4bc434a60a4
mod_firewall: Update functions that use meta() to allow functions with deps inside expressions
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 19 Feb 2017 21:08:30 +0000 |
parents | 2518:0e1054c19f9d |
children | 2520:c6fd8975704b |
files | mod_firewall/actions.lib.lua mod_firewall/conditions.lib.lua |
diffstat | 2 files changed, 12 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_firewall/actions.lib.lua Sun Feb 19 21:06:57 2017 +0000 +++ b/mod_firewall/actions.lib.lua Sun Feb 19 21:08:30 2017 +0000 @@ -158,7 +158,9 @@ function action_handlers.LOG(string) local level = string:match("^%[(%a+)%]") or "info"; string = string:gsub("^%[%a+%] ?", ""); - return meta(("(session.log or log)(%q, %q);"):format(level, string)); + local meta_deps = {}; + local code = meta(("(session.log or log)(%q, %q);"):format(level, string), meta_deps); + return code, meta_deps; end function action_handlers.RULEDEP(dep)
--- a/mod_firewall/conditions.lib.lua Sun Feb 19 21:06:57 2017 +0000 +++ b/mod_firewall/conditions.lib.lua Sun Feb 19 21:08:30 2017 +0000 @@ -124,17 +124,18 @@ if not(query:match("#$") or query:match("@[^/]+")) then error("Stanza path does not return a string (append # for text content or @name for value of named attribute)", 0); end + local meta_deps = {}; local quoted_value = ("%q"):format(value); if match_type:find("$", 1, true) then match_type = match_type:gsub("%$", ""); - quoted_value = meta(quoted_value); + quoted_value = meta(quoted_value, meta_deps); end if match_type == "~" then -- Lua pattern match - return ("(stanza:find(%q) or ''):match(%s)"):format(query, quoted_value); + return ("(stanza:find(%q) or ''):match(%s)"):format(query, quoted_value), meta_deps; elseif match_type == "/" then -- find literal substring - return ("(stanza:find(%q) or ''):find(%s, 1, true)"):format(query, quoted_value); + return ("(stanza:find(%q) or ''):find(%s, 1, true)"):format(query, quoted_value), meta_deps; elseif match_type == "" then -- exact match - return ("stanza:find(%q) == %s"):format(query, quoted_value); + return ("stanza:find(%q) == %s"):format(query, quoted_value), meta_deps; else error("Unrecognised comparison '"..match_type.."='", 0); end @@ -220,6 +221,7 @@ function condition_handlers.LIMIT(spec) local name, param = spec:match("^(%w+) on (.+)$"); + local meta_deps = {}; if not name then name = spec:match("^%w+$"); @@ -227,13 +229,13 @@ error("Unable to parse LIMIT specification"); end else - param = meta(("%q"):format(param)); + param = meta(("%q"):format(param), meta_deps); end if not param then - return ("not global_throttle_%s:poll(1)"):format(name), { "globalthrottle:"..name }; + return ("not global_throttle_%s:poll(1)"):format(name), { "globalthrottle:"..name, unpack(meta_deps) }; end - return ("not multi_throttle_%s:poll_on(%s, 1)"):format(name, param), { "multithrottle:"..name }; + return ("not multi_throttle_%s:poll_on(%s, 1)"):format(name, param), { "multithrottle:"..name, unpack(meta_deps) }; end function condition_handlers.ORIGIN_MARKED(name_and_time)