Mercurial > prosody-modules
comparison 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 |
| parents | d773a51af9b1 |
| children | 8a3f3f485675 |
comparison
equal
deleted
inserted
replaced
| 960:d773a51af9b1 | 961:f0108ec2b016 |
|---|---|
| 1 local action_handlers = {}; | 1 local action_handlers = {}; |
| 2 | |
| 3 | |
| 4 -- Run code through this to allow strings to contain code. e.g.: LOG=Received: $(stanza:top_tag()) | |
| 5 local function meta(s, extra) | |
| 6 return (s:gsub("$(%b())", [["..%1.."]]) | |
| 7 :gsub("$(%b<>)", [["..stanza:find("%1").."]]) | |
| 8 :gsub("$$(%a+)", extra or {})); | |
| 9 end | |
| 2 | 10 |
| 3 -- Takes an XML string and returns a code string that builds that stanza | 11 -- Takes an XML string and returns a code string that builds that stanza |
| 4 -- using st.stanza() | 12 -- using st.stanza() |
| 5 local function compile_xml(data) | 13 local function compile_xml(data) |
| 6 local code = {}; | 14 local code = {}; |
| 150 end | 158 end |
| 151 | 159 |
| 152 function action_handlers.LOG(string) | 160 function action_handlers.LOG(string) |
| 153 local level = string:match("^%[(%a+)%]") or "info"; | 161 local level = string:match("^%[(%a+)%]") or "info"; |
| 154 string = string:gsub("^%[%a+%] ?", ""); | 162 string = string:gsub("^%[%a+%] ?", ""); |
| 155 return (("log(%q, %q)"):format(level, string) | 163 return meta(("log(%q, %q)"):format(level, string)); |
| 156 :gsub("$top", [["..stanza:top_tag().."]]) | |
| 157 :gsub("$stanza", [["..stanza.."]]) | |
| 158 :gsub("$(%b())", [["..%1.."]])); | |
| 159 end | 164 end |
| 160 | 165 |
| 161 function action_handlers.RULEDEP(dep) | 166 function action_handlers.RULEDEP(dep) |
| 162 return "", { dep }; | 167 return "", { dep }; |
| 163 end | 168 end |
