Mercurial > prosody-modules
changeset 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 | 2fb11d34087e |
files | mod_firewall/mod_firewall.lua |
diffstat | 1 files changed, 8 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_firewall/mod_firewall.lua Tue Nov 15 15:01:14 2016 +0000 +++ b/mod_firewall/mod_firewall.lua Tue Nov 15 21:02:04 2016 +0000 @@ -47,10 +47,16 @@ return (s:gsub("$(%b())", [["..tostring(%1).."]]) :gsub("$(%b<>)", function (expr) expr = expr:sub(2,-2); + local default = expr:match("||([^|]+)$"); + if default then + expr = expr:sub(1, -(#default+2)); + else + default = "<undefined>"; + end if expr:match("^@") then - return "\"..stanza.attr["..("%q"):format(expr:sub(2)).."]..\""; + return "\"..(stanza.attr["..("%q"):format(expr:sub(2)).."] or "..("%q"):format(default)..")..\""; end - return "\"..stanza:find("..("%q"):format(expr:sub(2, -2))..")..\""; + return "\"..(stanza:find("..("%q"):format(expr:sub(2, -2))..") or "..("%q"):format(default)..")..\""; end) :gsub("$$(%a+)", extra or {}) :gsub([[^""%.%.]], "")