Mercurial > prosody-modules
comparison mod_firewall/mod_firewall.lua @ 2368:7e1d8c46d788
mod_firewall: Support for default values in stanza paths
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 15 Nov 2016 21:02:04 +0000 |
| parents | 3ebd3cb4d7d2 |
| children | d630fa0d4dba |
comparison
equal
deleted
inserted
replaced
| 2367:3ebd3cb4d7d2 | 2368:7e1d8c46d788 |
|---|---|
| 45 -- Run quoted (%q) strings through this to allow them to contain code. e.g.: LOG=Received: $(stanza:top_tag()) | 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) | 46 function meta(s, extra) |
| 47 return (s:gsub("$(%b())", [["..tostring(%1).."]]) | 47 return (s:gsub("$(%b())", [["..tostring(%1).."]]) |
| 48 :gsub("$(%b<>)", function (expr) | 48 :gsub("$(%b<>)", function (expr) |
| 49 expr = expr:sub(2,-2); | 49 expr = expr:sub(2,-2); |
| 50 local default = expr:match("||([^|]+)$"); | |
| 51 if default then | |
| 52 expr = expr:sub(1, -(#default+2)); | |
| 53 else | |
| 54 default = "<undefined>"; | |
| 55 end | |
| 50 if expr:match("^@") then | 56 if expr:match("^@") then |
| 51 return "\"..stanza.attr["..("%q"):format(expr:sub(2)).."]..\""; | 57 return "\"..(stanza.attr["..("%q"):format(expr:sub(2)).."] or "..("%q"):format(default)..")..\""; |
| 52 end | 58 end |
| 53 return "\"..stanza:find("..("%q"):format(expr:sub(2, -2))..")..\""; | 59 return "\"..(stanza:find("..("%q"):format(expr:sub(2, -2))..") or "..("%q"):format(default)..")..\""; |
| 54 end) | 60 end) |
| 55 :gsub("$$(%a+)", extra or {}) | 61 :gsub("$$(%a+)", extra or {}) |
| 56 :gsub([[^""%.%.]], "") | 62 :gsub([[^""%.%.]], "") |
| 57 :gsub([[%.%.""$]], "")); | 63 :gsub([[%.%.""$]], "")); |
| 58 end | 64 end |
