]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Add handling of regexp maps
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 24 Nov 2016 12:14:39 +0000 (12:14 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 24 Nov 2016 12:14:39 +0000 (12:14 +0000)
src/lua/global_functions.lua

index 64f4f6b72ef89f88f927c7af1b6765af0973aa81..d3b84b4ea18bf1f62bc6270bf71fc6bb86071386 100644 (file)
@@ -436,17 +436,45 @@ function rspamd_map_add(mname, optname, mtype, description)
           setmetatable(ret, ret_mt)
           return ret
         end
+      elseif mtype == 'regexp' then
+        local data = {}
+        local rspamd_regexp = require "rspamd_regexp"
+        for _,elt in ipairs(opt) do
+          if type(elt) == 'string' then
+            local re = rspamd_regexp:create_cached(elt)
+
+            if re then
+              table.insert(data, re)
+            else
+              local logger = require "rspamd_logger"
+              logger.errx(rspamd_config, "cannot create regexp from '%s'", elt)
+            end
+          end
+        end
+
+        ret.__data = data
+        ret.get_key = function(t, k)
+          for _,re in ipairs(t.__data) do
+            if re:match(k) then return true end
+          end
+
+          return nil
+        end
       else
         local data = {}
         for _,elt in ipairs(opt) do
           if type(elt) == 'string' then
-            data[elt] = '1'
+            data[elt] = true
           end
         end
 
         ret.__data = data
         ret.get_key = function(t, k)
-          return t.__data[k]
+          if k ~= '__data' then
+            return t.__data[k]
+          end
+
+          return nil
         end
       end
     else