From b31d6f23ed0af0c9046f5de85bfb15e906bb4888 Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Tue, 24 Jan 2017 19:33:28 +0200 Subject: [PATCH] [Minor] Rework ratelimit module changes --- src/plugins/lua/ratelimit.lua | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua index 6791395de..c532e4379 100644 --- a/src/plugins/lua/ratelimit.lua +++ b/src/plugins/lua/ratelimit.lua @@ -539,7 +539,7 @@ local function parse_string_limit(lim) local t = lpeg.match(grammar.limit, lim) if t and t[1] and t[2] and t[2] ~= 0 then - return t[1] / t[2] + return t[1] / t[2], t[1] end rspamd_logger.errx(rspamd_config, 'bad limit: %s', lim) @@ -560,14 +560,11 @@ if opts then -- new way of setting limits fun.each(function(t, lim) if type(lim) == 'table' then - if type(lim[2]) == 'number' then - settings[t] = lim - elseif type(lim[2]) == 'string' then - settings[t] = lim - local plim = parse_string_limit(lim[2]) - if plim then - settings[t][2] = plim - end + settings[t] = lim + elseif type(lim) == 'string' then + local plim, size = parse_string_limit(lim) + if plim then + settings[t] = {size, plim, 1} end end end, opts['rates']) @@ -586,6 +583,7 @@ if opts then end, fun.filter(function(_, lim) return type(lim) == 'string' or (type(lim) == 'table' and type(lim[1]) == 'number' and lim[1] > 0) + or (type(lim) == 'table' and (lim[3])) end, settings))) rspamd_logger.infox(rspamd_config, 'enabled rate buckets: %s', enabled_limits) -- 2.39.5