]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Combine selectors and use the proper table field in ratelimit
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 19 Aug 2018 10:55:35 +0000 (11:55 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 19 Aug 2018 10:55:35 +0000 (11:55 +0100)
src/plugins/lua/ratelimit.lua

index d9c0f164ef0d67f29910ec1b328766cdce557632..8c0c48387977ee9adcc3f6dd201e89179674b042 100644 (file)
@@ -432,25 +432,37 @@ end
 
 local function limit_to_prefixes(task, k, v, prefixes)
   local n = 0
-  for _,bucket in ipairs(v.bucket) do
-    local prefix
+  for _,bucket in ipairs(v.buckets) do
     if v.selector then
-      prefix = lua_selectors.process_selectors(task, v.selector)
+      local selectors = lua_selectors.process_selectors(task, v.selector)
+      if selectors then
+        local combined = lua_selectors.combine_selectors(task, selectors, ':')
+        if type(combined) == 'string' then
+          prefixes[combined] = make_prefix(combined, k, bucket)
+          n = n + 1
+        else
+          fun.each(function(p)
+            prefixes[p] = make_prefix(p, k, bucket)
+            n = n + 1
+          end, combined)
+        end
+      end
     else
-      prefix = gen_rate_key(task, k, bucket)
-    end
-
-    if prefix then
-      if type(prefix) == 'string' then
-        prefixes[prefix] = make_prefix(prefix, k, bucket)
-        n = n + 1
-      else
-        fun.each(function(p)
-          prefixes[p] = make_prefix(p, k, bucket)
+      local prefix = gen_rate_key(task, k, bucket)
+      if prefix then
+        if type(prefix) == 'string' then
+          prefixes[prefix] = make_prefix(prefix, k, bucket)
           n = n + 1
-        end, prefix)
+        else
+          fun.each(function(p)
+            prefixes[p] = make_prefix(p, k, bucket)
+            n = n + 1
+          end, prefix)
+        end
       end
     end
+
+
   end
 
   return n