diff mod_firewall/conditions.lib.lua @ 2519:d4bc434a60a4

mod_firewall: Update functions that use meta() to allow functions with deps inside expressions
author Matthew Wild <mwild1@gmail.com>
date Sun, 19 Feb 2017 21:08:30 +0000
parents bd69ffe071e6
children c6fd8975704b
line wrap: on
line diff
--- a/mod_firewall/conditions.lib.lua	Sun Feb 19 21:06:57 2017 +0000
+++ b/mod_firewall/conditions.lib.lua	Sun Feb 19 21:08:30 2017 +0000
@@ -124,17 +124,18 @@
 		if not(query:match("#$") or query:match("@[^/]+")) then
 			error("Stanza path does not return a string (append # for text content or @name for value of named attribute)", 0);
 		end
+		local meta_deps = {};
 		local quoted_value = ("%q"):format(value);
 		if match_type:find("$", 1, true) then
 			match_type = match_type:gsub("%$", "");
-			quoted_value = meta(quoted_value);
+			quoted_value = meta(quoted_value, meta_deps);
 		end
 		if match_type == "~" then -- Lua pattern match
-			return ("(stanza:find(%q) or ''):match(%s)"):format(query, quoted_value);
+			return ("(stanza:find(%q) or ''):match(%s)"):format(query, quoted_value), meta_deps;
 		elseif match_type == "/" then -- find literal substring
-			return ("(stanza:find(%q) or ''):find(%s, 1, true)"):format(query, quoted_value);
+			return ("(stanza:find(%q) or ''):find(%s, 1, true)"):format(query, quoted_value), meta_deps;
 		elseif match_type == "" then -- exact match
-			return ("stanza:find(%q) == %s"):format(query, quoted_value);
+			return ("stanza:find(%q) == %s"):format(query, quoted_value), meta_deps;
 		else
 			error("Unrecognised comparison '"..match_type.."='", 0);
 		end
@@ -220,6 +221,7 @@
 
 function condition_handlers.LIMIT(spec)
 	local name, param = spec:match("^(%w+) on (.+)$");
+	local meta_deps = {};
 
 	if not name then
 		name = spec:match("^%w+$");
@@ -227,13 +229,13 @@
 			error("Unable to parse LIMIT specification");
 		end
 	else
-		param = meta(("%q"):format(param));
+		param = meta(("%q"):format(param), meta_deps);
 	end
 
 	if not param then
-		return ("not global_throttle_%s:poll(1)"):format(name), { "globalthrottle:"..name };
+		return ("not global_throttle_%s:poll(1)"):format(name), { "globalthrottle:"..name, unpack(meta_deps) };
 	end
-	return ("not multi_throttle_%s:poll_on(%s, 1)"):format(name, param), { "multithrottle:"..name };	
+	return ("not multi_throttle_%s:poll_on(%s, 1)"):format(name, param), { "multithrottle:"..name, unpack(meta_deps) };	
 end
 
 function condition_handlers.ORIGIN_MARKED(name_and_time)