]> source.dussan.org Git - rspamd.git/commitdiff
* Add versions to lua API
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 22 Dec 2010 15:08:14 +0000 (18:08 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 22 Dec 2010 15:08:14 +0000 (18:08 +0300)
* Provide compatibility for lua plugins for old versions of rspamd

src/lua/lua_common.h
src/lua/lua_config.c
src/plugins/lua/forged_recipients.lua
src/plugins/lua/maillist.lua
src/plugins/lua/multimap.lua
src/plugins/lua/once_received.lua
src/plugins/lua/phishing.lua
src/plugins/lua/received_rbl.lua
src/plugins/lua/whitelist.lua

index 82305631692489fd6e2b3b3cb87ccaabed0d1622..3e0fbed88595f350105ee4323e3b767196a8383c 100644 (file)
@@ -16,6 +16,8 @@
 
 extern const luaL_reg null_reg[];
 
+#define RSPAMD_LUA_API_VERSION 1
+
 /* Common utility functions */
 void lua_newclass (lua_State *L, const gchar *classname, const struct luaL_reg *func);
 void lua_setclass (lua_State *L, const gchar *classname, gint objidx);
index e05545355f6810963b7c71890f539c0d3d81c959..b77c97bfc25eb555d7b12bdfbbc7cfd338104a40 100644 (file)
@@ -44,6 +44,7 @@ LUA_FUNCTION_DEF (config, register_virtual_symbol);
 LUA_FUNCTION_DEF (config, register_callback_symbol);
 LUA_FUNCTION_DEF (config, register_post_filter);
 LUA_FUNCTION_DEF (config, register_module_option);
+LUA_FUNCTION_DEF (config, get_api_version);
 
 static const struct luaL_reg    configlib_m[] = {
        LUA_INTERFACE_DEF (config, get_module_opt),
@@ -57,6 +58,7 @@ static const struct luaL_reg    configlib_m[] = {
        LUA_INTERFACE_DEF (config, register_callback_symbol),
        LUA_INTERFACE_DEF (config, register_module_option),
        LUA_INTERFACE_DEF (config, register_post_filter),
+       LUA_INTERFACE_DEF (config, get_api_version),
        {"__tostring", lua_class_tostring},
        {NULL, NULL}
 };
@@ -128,6 +130,13 @@ lua_check_trie (lua_State * L)
 }
 
 /*** Config functions ***/
+static gint
+lua_config_get_api_version (lua_State *L)
+{
+       lua_pushinteger (L, RSPAMD_LUA_API_VERSION);
+       return 1;
+}
+
 static gint
 lua_config_get_module_opt (lua_State * L)
 {
index d759960d3e23d4f24ae799564012a239555608f7..6b6ec298bd98a026381b83eb7a110021014e6799 100644 (file)
@@ -64,8 +64,12 @@ function check_forged_headers(task)
 end
 
 -- Registration
-rspamd_config:register_module_option('forged_recipients', 'symbol_rcpt', 'string')
-rspamd_config:register_module_option('forged_recipients', 'symbol_sender', 'string')
+if type(rspamd_config.get_api_version) ~= 'nil' then
+       if rspamd_config:get_api_version() >= 1 then
+               rspamd_config:register_module_option('forged_recipients', 'symbol_rcpt', 'string')
+               rspamd_config:register_module_option('forged_recipients', 'symbol_sender', 'string')
+       end
+end
 
 -- Configuration
 local opts =  rspamd_config:get_all_opt('forged_recipients')
@@ -73,13 +77,21 @@ if opts then
        if opts['symbol_rcpt'] or opts['symbol_sender'] then
                if opts['symbol_rcpt'] then
                        symbol_rcpt = opts['symbol_rcpt']
-                       rspamd_config:register_virtual_symbol(symbol_rcpt, 1.0, 'check_forged_headers')
+                       if type(rspamd_config.get_api_version) ~= 'nil' then
+                               rspamd_config:register_virtual_symbol(symbol_rcpt, 1.0, 'check_forged_headers')
+                       end
                end
                if opts['symbol_sender'] then
                        symbol_sender = opts['symbol_sender']
-                       rspamd_config:register_virtual_symbol(symbol_sender, 1.0)
+                       if type(rspamd_config.get_api_version) ~= 'nil' then
+                               rspamd_config:register_virtual_symbol(symbol_sender, 1.0)
+                       end
+               end
+               if type(rspamd_config.get_api_version) ~= 'nil' then
+                       rspamd_config:register_callback_symbol('FORGED_RECIPIENTS', 1.0, 'check_forged_headers')
+               else
+                       rspamd_config:register_symbol('FORGED_RECIPIENTS', 1.0, 'check_forged_headers')
                end
-               rspamd_config:register_callback_symbol('FORGED_RECIPIENTS', 1.0, 'check_forged_headers')
                
        end
 end
index 16be1764fadc8c26af582fed4038b41bca1e9f42..c7a4751eb2fbe73b3f61ea760e001d95d6ab42ac 100644 (file)
@@ -163,7 +163,11 @@ function check_maillist(task)
        end
 end
 -- Registration
-rspamd_config:register_module_option('maillist', 'symbol', 'string')
+if type(rspamd_config.get_api_version) ~= 'nil' then
+       if rspamd_config:get_api_version() >= 1 then
+               rspamd_config:register_module_option('maillist', 'symbol', 'string')
+       end
+end
 -- Configuration
 local opts =  rspamd_config:get_all_opt('maillist')
 if opts then
index 97f122c48ca72fbfb37a92ca9b3ddec50d607f68..6986c8c7214d3506591a5eb6e7cbcaa82c8f02c4 100644 (file)
@@ -130,7 +130,11 @@ function add_rule(params)
 end
 
 -- Registration
-rspamd_config:register_module_option('multimap', 'rule', 'string')
+if type(rspamd_config.get_api_version) ~= 'nil' then
+       if rspamd_config:get_api_version() >= 1 then
+               rspamd_config:register_module_option('multimap', 'rule', 'string')
+       end
+end
 
 local opts =  rspamd_config:get_all_opt('multimap')
 if opts then
@@ -143,7 +147,9 @@ if opts then
                                if not rule then
                                        rspamd_logger:err('cannot add rule: "'..value..'"')
                                else
-                                       rspamd_config:register_virtual_symbol(rule['symbol'], 1.0)
+                                       if type(rspamd_config.get_api_version) ~= 'nil' then
+                                               rspamd_config:register_virtual_symbol(rule['symbol'], 1.0)
+                                       end
                                end
                        end
                elseif type(strrules) == 'string' then
@@ -152,7 +158,9 @@ if opts then
                        if not rule then
                                rspamd_logger:err('cannot add rule: "'..strrules..'"')
                        else
-                               rspamd_config:register_virtual_symbol(rule['symbol'], 1.0)
+                               if type(rspamd_config.get_api_version) ~= 'nil' then
+                                       rspamd_config:register_virtual_symbol(rule['symbol'], 1.0)
+                               end
                        end
                end
        end
@@ -160,5 +168,9 @@ end
 
 if table.maxn(rules) > 0 then
        -- add fake symbol to check all maps inside a single callback
-       rspamd_config:register_callback_symbol('MULTIMAP', 1.0, 'check_multimap')
+       if type(rspamd_config.get_api_version) ~= 'nil' then
+               rspamd_config:register_callback_symbol('MULTIMAP', 1.0, 'check_multimap')
+       else
+               rspamd_config:register_symbol('MULTIMAP', 1.0, 'check_multimap')
+       end
 end
index 97df71da3247310a79fcc89ee2f2c530cb2723d2..a7b2a26559ace368ddf6fad14d39c2bb4c1cc77d 100644 (file)
@@ -45,10 +45,14 @@ function check_quantity_received (task)
 end
 
 -- Registration
-rspamd_config:register_module_option('once_received', 'symbol', 'string')
-rspamd_config:register_module_option('once_received', 'symbol_strict', 'string')
-rspamd_config:register_module_option('once_received', 'bad_host', 'string')
-rspamd_config:register_module_option('once_received', 'good_host', 'string')
+if type(rspamd_config.get_api_version) ~= 'nil' then
+       if rspamd_config:get_api_version() >= 1 then
+               rspamd_config:register_module_option('once_received', 'symbol', 'string')
+               rspamd_config:register_module_option('once_received', 'symbol_strict', 'string')
+               rspamd_config:register_module_option('once_received', 'bad_host', 'string')
+               rspamd_config:register_module_option('once_received', 'good_host', 'string')
+       end
+end
 
 -- Configuration
 local opts =  rspamd_config:get_all_opt('once_received')
@@ -59,7 +63,9 @@ if opts then
            for n,v in pairs(opts) do
                        if n == 'symbol_strict' then
                                symbol_strict = v
-                               rspamd_config:register_virtual_symbol(symbol_strict, 1.0)
+                               if type(rspamd_config.get_api_version) ~= 'nil' then
+                                       rspamd_config:register_virtual_symbol(symbol_strict, 1.0)
+                               end
                        elseif n == 'bad_host' then
                            bad_hosts = v
                        elseif n == 'good_host' then
index af5c91e15499fa9ed955f1908bf5e59e376aa91a..11568875057f1dbcd43add0f3c4f8deb78b9b42a 100644 (file)
@@ -28,8 +28,12 @@ function phishing_cb (task)
 end
 
 -- Registration
-rspamd_config:register_module_option('phishing', 'symbol', 'string')
-rspamd_config:register_module_option('phishing', 'domains', 'map')
+if type(rspamd_config.get_api_version) ~= 'nil' then
+       if rspamd_config:get_api_version() >= 1 then
+               rspamd_config:register_module_option('phishing', 'symbol', 'string')
+               rspamd_config:register_module_option('phishing', 'domains', 'map')
+       end
+end
 
 local opts = rspamd_config:get_all_opt('phishing')
 if opts then
index 162add51ef4d3b8c404c30a4e3999d9ace3a51a5..653b092ad993774a9d92b807a346eebe8adbcdd7 100644 (file)
@@ -56,8 +56,12 @@ function received_cb (task)
 end
 
 -- Registration
-rspamd_config:register_module_option('received_rbl', 'symbol', 'string')
-rspamd_config:register_module_option('received_rbl', 'rbl', 'string')
+if type(rspamd_config.get_api_version) ~= 'nil' then
+       if rspamd_config:get_api_version() >= 1 then
+               rspamd_config:register_module_option('received_rbl', 'symbol', 'string')
+               rspamd_config:register_module_option('received_rbl', 'rbl', 'string')
+       end
+end
 
 -- Configuration
 local opts =  rspamd_config:get_all_opt('received_rbl')
@@ -71,7 +75,9 @@ if opts then
         for _,rbl in ipairs(rbls) do
                local s, _ = string.find(rbl, ':')
                        if s then
-                               rspamd_config:register_virtual_symbol(string.sub(rbl, s + 1, -1), 1)
+                               if type(rspamd_config.get_api_version) ~= 'nil' then
+                                       rspamd_config:register_virtual_symbol(string.sub(rbl, s + 1, -1), 1)
+                               end
                        end
                end
         -- Register symbol's callback
index 1899809fef66383ccbf29f79093521718e7b14fe..0f4c41f852660c78420cf5636dc5eddeadd5ae9c 100644 (file)
@@ -33,10 +33,14 @@ function check_whitelist (task)
 end
 
 -- Registration
-rspamd_config:register_module_option('whitelist', 'symbol_ip', 'string')
-rspamd_config:register_module_option('whitelist', 'symbol_from', 'string')
-rspamd_config:register_module_option('whitelist', 'ip_whitelist', 'map')
-rspamd_config:register_module_option('whitelist', 'from_whitelist', 'map')
+if type(rspamd_config.get_api_version) ~= 'nil' then
+       if rspamd_config:get_api_version() >= 1 then
+               rspamd_config:register_module_option('whitelist', 'symbol_ip', 'string')
+               rspamd_config:register_module_option('whitelist', 'symbol_from', 'string')
+               rspamd_config:register_module_option('whitelist', 'ip_whitelist', 'map')
+               rspamd_config:register_module_option('whitelist', 'from_whitelist', 'map')
+       end
+end
 
 -- Configuration
 local opts =  rspamd_config:get_all_opt('whitelist')