Преглед на файлове

* Add versions to lua API

* Provide compatibility for lua plugins for old versions of rspamd
tags/0.3.7
Vsevolod Stakhov преди 13 години
родител
ревизия
29c3237009

+ 2
- 0
src/lua/lua_common.h Целия файл

@@ -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);

+ 9
- 0
src/lua/lua_config.c Целия файл

@@ -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)
{

+ 17
- 5
src/plugins/lua/forged_recipients.lua Целия файл

@@ -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

+ 5
- 1
src/plugins/lua/maillist.lua Целия файл

@@ -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

+ 16
- 4
src/plugins/lua/multimap.lua Целия файл

@@ -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

+ 11
- 5
src/plugins/lua/once_received.lua Целия файл

@@ -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

+ 6
- 2
src/plugins/lua/phishing.lua Целия файл

@@ -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

+ 9
- 3
src/plugins/lua/received_rbl.lua Целия файл

@@ -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

+ 8
- 4
src/plugins/lua/whitelist.lua Целия файл

@@ -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')

Loading…
Отказ
Запис