Diff

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
parent 2124:89363766202c
child 2126:b0d711cd3da5
line wrap: on
line diff
--- a/mod_firewall/mod_firewall.lua	Thu Mar 17 21:27:24 2016 +0000
+++ b/mod_firewall/mod_firewall.lua	Thu Mar 17 21:29:07 2016 +0000
@@ -42,6 +42,22 @@
 	return name:match("^%a[%w_]*$")
 end
 
+-- Run quoted (%q) strings through this to allow them to contain code. e.g.: LOG=Received: $(stanza:top_tag())
+function meta(s, extra)
+	return (s:gsub("$(%b())", [["..tostring(%1).."]])
+		:gsub("$(%b<>)", function (expr)
+			expr = expr:sub(2,-2);
+			if expr:match("^@") then
+				return "\"..stanza.attr["..(%q):format(expr:sub(2)).."]..\"";
+			end
+			return "\"..stanza:find("..("%q"):format(expr:sub(2, -2))..")..\"";
+		end)
+		:gsub("$$(%a+)", extra or {})
+		:gsub([[^""%.%.]], "")
+		:gsub([[%.%.""$]], ""));
+end
+
+
 -- Dependency locations:
 -- <type lib>
 -- <type global>