Software /
code /
prosody-modules
Diff
mod_firewall/actions.lib.lua @ 961:f0108ec2b016
mod_firewall/actions: Break out logic into a separate reusable function
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 05 Apr 2013 18:50:52 +0100 |
parent | 960:d773a51af9b1 |
child | 1303:8a3f3f485675 |
line wrap: on
line diff
--- a/mod_firewall/actions.lib.lua Fri Apr 05 18:08:16 2013 +0100 +++ b/mod_firewall/actions.lib.lua Fri Apr 05 18:50:52 2013 +0100 @@ -1,5 +1,13 @@ local action_handlers = {}; + +-- Run code through this to allow strings to contain code. e.g.: LOG=Received: $(stanza:top_tag()) +local function meta(s, extra) + return (s:gsub("$(%b())", [["..%1.."]]) + :gsub("$(%b<>)", [["..stanza:find("%1").."]]) + :gsub("$$(%a+)", extra or {})); +end + -- Takes an XML string and returns a code string that builds that stanza -- using st.stanza() local function compile_xml(data) @@ -152,10 +160,7 @@ function action_handlers.LOG(string) local level = string:match("^%[(%a+)%]") or "info"; string = string:gsub("^%[%a+%] ?", ""); - return (("log(%q, %q)"):format(level, string) - :gsub("$top", [["..stanza:top_tag().."]]) - :gsub("$stanza", [["..stanza.."]]) - :gsub("$(%b())", [["..%1.."]])); + return meta(("log(%q, %q)"):format(level, string)); end function action_handlers.RULEDEP(dep)