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);
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),
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}
};
}
/*** 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)
{
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')
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
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
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
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
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
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
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')
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
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
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')
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
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')