From 943734997a929e3d952be693ff7b202a9314680b Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 19 Mar 2015 16:19:09 +0000 Subject: [PATCH] Remove expressions pollutions from parts of rspamd. --- src/libmime/CMakeLists.txt | 2 +- src/libserver/cfg_rcl.c | 1 - src/lua/lua_cfg_file.c | 1 - src/lua/lua_common.c | 1 - src/lua/lua_config.c | 107 ------------------------------------- src/lua/lua_regexp.c | 1 - 6 files changed, 1 insertion(+), 112 deletions(-) diff --git a/src/libmime/CMakeLists.txt b/src/libmime/CMakeLists.txt index 36de02c820..bb678d2f94 100644 --- a/src/libmime/CMakeLists.txt +++ b/src/libmime/CMakeLists.txt @@ -1,6 +1,6 @@ # Librspamd mime SET(LIBRSPAMDMIMESRC - ${CMAKE_CURRENT_SOURCE_DIR}/expressions.c + ${CMAKE_CURRENT_SOURCE_DIR}/mime_expressions.c ${CMAKE_CURRENT_SOURCE_DIR}/filter.c ${CMAKE_CURRENT_SOURCE_DIR}/images.c ${CMAKE_CURRENT_SOURCE_DIR}/message.c diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index 21dff7dd17..5071b390f0 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -27,7 +27,6 @@ #include "utlist.h" #include "cfg_file.h" #include "lua/lua_common.h" -#include "expressions.h" struct rspamd_rcl_default_handler_data { diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c index c29b4b2b14..9ad3331325 100644 --- a/src/lua/lua_cfg_file.c +++ b/src/lua/lua_cfg_file.c @@ -23,7 +23,6 @@ */ #include "lua_common.h" -#include "expressions.h" #include "symbols_cache.h" #ifdef HAVE_SYS_UTSNAME_H #include diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 63d34e4e6b..d970325d14 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -23,7 +23,6 @@ */ #include "lua_common.h" -#include "expressions.h" /* Lua module init function */ #define MODULE_INIT_FUNC "module_init" diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 5116fff93d..178b3f098f 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -24,7 +24,6 @@ #include "lua_common.h" -#include "expressions.h" #include "map.h" #include "message.h" #include "radix.h" @@ -69,27 +68,6 @@ LUA_FUNCTION_DEF (config, get_all_opt); * @return {mempool} [memory pool](mempool.md) object */ LUA_FUNCTION_DEF (config, get_mempool); -/*** - * @method rspamd_config:register_function(name, callback) - * Registers new rspamd function that could be used in symbols expressions - * @param {string} name name of function - * @param {function} callback callback to be called - * @example - -local function lua_header_exists(task, hname) - if task:get_raw_header(hname) then - return true - end - - return false -end - -rspamd_config:register_function('lua_header_exists', lua_header_exists) - --- Further in configuration it would be possible to define symbols like: --- HAS_CONTENT_TYPE = 'lua_header_exists(Content-Type)' - */ -LUA_FUNCTION_DEF (config, register_function); /*** * @method rspamd_config:add_radix_map(mapline[, description]) * Creates new dynamic map of IP/mask addresses. @@ -314,7 +292,6 @@ static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, get_module_opt), LUA_INTERFACE_DEF (config, get_mempool), LUA_INTERFACE_DEF (config, get_all_opt), - LUA_INTERFACE_DEF (config, register_function), LUA_INTERFACE_DEF (config, add_radix_map), LUA_INTERFACE_DEF (config, radix_from_config), LUA_INTERFACE_DEF (config, add_hash_map), @@ -532,90 +509,6 @@ lua_destroy_cfg_symbol (gpointer ud) } } -static gboolean -lua_config_function_callback (struct rspamd_task *task, - GList *args, - void *user_data) -{ - struct lua_callback_data *cd = user_data; - struct rspamd_task **ptask; - gint i = 1; - struct expression_argument *arg; - GList *cur; - gboolean res = FALSE; - - if (cd->cb_is_ref) { - lua_rawgeti (cd->L, LUA_REGISTRYINDEX, cd->callback.ref); - } - else { - lua_getglobal (cd->L, cd->callback.name); - } - ptask = lua_newuserdata (cd->L, sizeof (struct rspamd_task *)); - rspamd_lua_setclass (cd->L, "rspamd{task}", -1); - *ptask = task; - /* Now push all arguments */ - cur = args; - while (cur) { - arg = get_function_arg (cur->data, task, TRUE); - lua_pushstring (cd->L, (const gchar *)arg->data); - cur = g_list_next (cur); - i++; - } - - if (lua_pcall (cd->L, i, 1, 0) != 0) { - msg_info ("error processing symbol %s: call to %s failed: %s", - cd->symbol, - cd->cb_is_ref ? "local function" : - cd->callback.name, - lua_tostring (cd->L, -1)); - } - else { - if (lua_isboolean (cd->L, 1)) { - res = lua_toboolean (cd->L, 1); - } - lua_pop (cd->L, 1); - } - - return res; -} - -static gint -lua_config_register_function (lua_State *L) -{ - struct rspamd_config *cfg = lua_check_config (L); - gchar *name; - struct lua_callback_data *cd; - - if (cfg) { - name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); - cd = - rspamd_mempool_alloc (cfg->cfg_pool, - sizeof (struct lua_callback_data)); - - if (lua_type (L, 3) == LUA_TSTRING) { - cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, - luaL_checkstring (L, 3)); - cd->cb_is_ref = FALSE; - } - else { - lua_pushvalue (L, 3); - /* Get a reference */ - cd->callback.ref = luaL_ref (L, LUA_REGISTRYINDEX); - cd->cb_is_ref = TRUE; - } - if (name) { - cd->L = L; - cd->symbol = name; - register_expression_function (name, lua_config_function_callback, - cd); - } - rspamd_mempool_add_destructor (cfg->cfg_pool, - (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, - cd); - } - return 1; -} - static gint lua_config_register_module_option (lua_State *L) { diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c index 6fa0de7727..58073b3bc3 100644 --- a/src/lua/lua_regexp.c +++ b/src/lua/lua_regexp.c @@ -22,7 +22,6 @@ */ #include "lua_common.h" -#include "expressions.h" #include "regexp.h" /*** -- 2.47.3