Mercurial > prosody-modules
comparison mod_firewall/mod_firewall.lua @ 2125:edf5cf3c474b
mod_firewall: Move meta() function to main module, and make it a global so libs can use it
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 17 Mar 2016 21:29:07 +0000 |
| parents | 89363766202c |
| children | b0d711cd3da5 |
comparison
equal
deleted
inserted
replaced
| 2124:89363766202c | 2125:edf5cf3c474b |
|---|---|
| 39 | 39 |
| 40 -- Returns the input if it is safe to be used as a variable name, otherwise nil | 40 -- Returns the input if it is safe to be used as a variable name, otherwise nil |
| 41 function idsafe(name) | 41 function idsafe(name) |
| 42 return name:match("^%a[%w_]*$") | 42 return name:match("^%a[%w_]*$") |
| 43 end | 43 end |
| 44 | |
| 45 -- Run quoted (%q) strings through this to allow them to contain code. e.g.: LOG=Received: $(stanza:top_tag()) | |
| 46 function meta(s, extra) | |
| 47 return (s:gsub("$(%b())", [["..tostring(%1).."]]) | |
| 48 :gsub("$(%b<>)", function (expr) | |
| 49 expr = expr:sub(2,-2); | |
| 50 if expr:match("^@") then | |
| 51 return "\"..stanza.attr["..(%q):format(expr:sub(2)).."]..\""; | |
| 52 end | |
| 53 return "\"..stanza:find("..("%q"):format(expr:sub(2, -2))..")..\""; | |
| 54 end) | |
| 55 :gsub("$$(%a+)", extra or {}) | |
| 56 :gsub([[^""%.%.]], "") | |
| 57 :gsub([[%.%.""$]], "")); | |
| 58 end | |
| 59 | |
| 44 | 60 |
| 45 -- Dependency locations: | 61 -- Dependency locations: |
| 46 -- <type lib> | 62 -- <type lib> |
| 47 -- <type global> | 63 -- <type global> |
| 48 -- function handler() | 64 -- function handler() |
