mod_firewall: Don't use util.cache unless it's needed, and add explanatory error if it is not available
--- a/mod_firewall/definitions.lib.lua Fri Mar 18 09:51:01 2016 +0000
+++ b/mod_firewall/definitions.lib.lua Fri Mar 18 09:57:09 2016 +0000
@@ -33,14 +33,13 @@
local burst = tonumber(line:match("%(%s*burst%s+([%d.]+)%s*%)")) or 1;
local max_throttles = tonumber(line:match("%(%s*entries%s+([%d]+)%s*%)")) or multirate_cache_size;
- local cache = new_cache(max_throttles, evict_only_unthrottled);
-
return {
single = function ()
return new_throttle(rate*burst, burst);
end;
multi = function ()
+ local cache = new_cache(max_throttles, evict_only_unthrottled);
return {
poll_on = function (_, key, amount)
assert(key, "no key");
--- a/mod_firewall/mod_firewall.lua Fri Mar 18 09:51:01 2016 +0000
+++ b/mod_firewall/mod_firewall.lua Fri Mar 18 09:57:09 2016 +0000
@@ -117,6 +117,7 @@
};
multithrottle = {
global_code = function (throttle)
+ assert(pcall(require, "util.cache"), "Using LIMIT with 'on' requires Prosody 0.10 or higher");
assert(idsafe(throttle), "Invalid rate limit name: "..throttle);
assert(active_definitions.RATE[throttle], "Unknown rate limit: "..throttle);
return ("local multi_throttle_%s = rates.%s:multi();"):format(throttle, throttle);