]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix adding maps from config in Lua
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 11 Jan 2017 12:08:48 +0000 (12:08 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 11 Jan 2017 12:08:48 +0000 (12:08 +0000)
src/lua/global_functions.lua

index e89a5da6442ce932e4827291935ed72644b87deb..750516190e9be8b145d5bfe09e175ba701b98c26 100644 (file)
@@ -429,59 +429,74 @@ function rspamd_map_add(mname, optname, mtype, description)
     -- it might be plain map or map of plain elements
     if opt[1] then
       if mtype == 'radix' then
-        local map = rspamd_config:radix_from_config(mname, optname)
 
+        if string.find(opt[1], '^%d') then
+          local map = rspamd_config:radix_from_config(mname, optname)
+
+          if map then
+            ret.__data = map
+            setmetatable(ret, ret_mt)
+            return ret
+          end
+        else
+          -- Plain table
+          local map = rspamd_config:add_map{
+            type = mtype,
+            description = description,
+            url = opt,
+          }
+          if map then
+            ret.__data = map
+            setmetatable(ret, ret_mt)
+            return ret
+          end
+        end
+      elseif mtype == 'regexp' then
+        -- Plain table
+        local map = rspamd_config:add_map{
+          type = mtype,
+          description = description,
+          url = opt,
+        }
         if map then
           ret.__data = map
           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
-              logger.errx(rspamd_config, "cannot create regexp from '%s'", elt)
-            end
+      else
+        if string.find(opt[1], '^/%a') or string.find(opt[1], '^http') then
+          -- Plain table
+          local map = rspamd_config:add_map{
+            type = mtype,
+            description = description,
+            url = opt,
+          }
+          if map then
+            ret.__data = map
+            setmetatable(ret, ret_mt)
+            return ret
           end
-        end
-
-        if #data > 0 then
-          ret.__data = data
-          ret.get_key = function(t, k)
-            for _,re in ipairs(t.__data) do
-              if re:match(k) then return true end
+        else
+          local data = {}
+          local nelts = 0
+          for _,elt in ipairs(opt) do
+            if type(elt) == 'string' then
+              data[elt] = true
+              nelts = nelts + 1
             end
-
-            return nil
-          end
-          return ret
-        end
-      else
-        local data = {}
-        local nelts = 0
-        for _,elt in ipairs(opt) do
-          if type(elt) == 'string' then
-            data[elt] = true
-            nelts = nelts + 1
           end
-        end
 
-        if nelts > 0 then
-          ret.__data = data
-          ret.get_key = function(t, k)
-            if k ~= '__data' then
-              return t.__data[k]
-            end
+          if nelts > 0 then
+            ret.__data = data
+            ret.get_key = function(t, k)
+              if k ~= '__data' then
+                return t.__data[k]
+              end
 
-            return nil
+              return nil
+            end
+            return ret
           end
-          return ret
         end
       end
     else