diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-30 13:21:08 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-30 13:21:08 +0100 |
commit | 121f9e8b5434b0d8367b124a39ac73dc8b40c454 (patch) | |
tree | 309e0e88f9eeded422e3bf7e7eee431dbcc49de5 | |
parent | dad973b08ce91f4d1219ac3c17692128d92ec579 (diff) | |
download | rspamd-121f9e8b5434b0d8367b124a39ac73dc8b40c454.tar.gz rspamd-121f9e8b5434b0d8367b124a39ac73dc8b40c454.zip |
[Minor] Remove deprecated lua functions
-rw-r--r-- | src/lua/lua_common.c | 155 | ||||
-rw-r--r-- | src/lua/lua_common.h | 8 |
2 files changed, 0 insertions, 163 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index fc65a67df..803daa2f9 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -341,161 +341,6 @@ rspamd_init_lua_filters (struct rspamd_config *cfg) return TRUE; } -/* Callback functions */ - -gint -rspamd_lua_call_filter (const gchar *function, struct rspamd_task *task) -{ - gint result = 0; - struct rspamd_task **ptask; - lua_State *L = task->cfg->lua_state; - - lua_getglobal (L, function); - ptask = lua_newuserdata (L, sizeof (struct rspamd_task *)); - rspamd_lua_setclass (L, "rspamd{task}", -1); - *ptask = task; - - if (lua_pcall (L, 1, 1, 0) != 0) { - msg_info_task ("call to %s failed", function); - } - - /* retrieve result */ - if (!lua_isnumber (L, -1)) { - msg_info_task ("function %s must return a number", function); - } - else { - result = lua_tonumber (L, -1); - } - - lua_pop (L, 1); /* pop returned value */ - - return result; -} - -gint -rspamd_lua_call_chain_filter (const gchar *function, - struct rspamd_task *task, - gint *marks, - guint number) -{ - gint result; - guint i; - lua_State *L = task->cfg->lua_state; - - lua_getglobal (L, function); - - for (i = 0; i < number; i++) { - lua_pushnumber (L, marks[i]); - } - if (lua_pcall (L, number, 1, 0) != 0) { - msg_info_task ("call to %s failed", function); - } - - /* retrieve result */ - if (!lua_isnumber (L, -1)) { - msg_info_task ("function %s must return a number", function); - } - result = lua_tonumber (L, -1); - lua_pop (L, 1); /* pop returned value */ - - return result; -} - - -/* - * LUA custom consolidation function - */ -struct consolidation_callback_data { - struct rspamd_task *task; - double score; - const gchar *func; -}; - -static void -lua_consolidation_callback (gpointer key, gpointer value, gpointer arg) -{ - double res; - struct symbol *s = (struct symbol *)value; - struct consolidation_callback_data *data = - (struct consolidation_callback_data *)arg; - lua_State *L; - struct rspamd_task *task; - - L = data->task->cfg->lua_state; - task = data->task; - - lua_getglobal (L, data->func); - - lua_pushstring (L, (const gchar *)key); - lua_pushnumber (L, s->score); - if (lua_pcall (L, 2, 1, 0) != 0) { - msg_info_task ("call to %s failed", data->func); - } - - /* retrieve result */ - if (!lua_isnumber (L, -1)) { - msg_info_task ("function %s must return a number", data->func); - } - res = lua_tonumber (L, -1); - lua_pop (L, 1); /* pop returned value */ - data->score += res; -} - -double -rspamd_lua_consolidation_func (struct rspamd_task *task, - const gchar *metric_name, - const gchar *function_name) -{ - struct metric_result *metric_res; - double res = 0.; - struct consolidation_callback_data data = { task, 0, function_name }; - - if (function_name == NULL) { - return 0; - } - - metric_res = g_hash_table_lookup (task->results, metric_name); - if (metric_res == NULL) { - return res; - } - - g_hash_table_foreach (metric_res->symbols, lua_consolidation_callback, - &data); - - return data.score; -} - -double -rspamd_lua_normalize (struct rspamd_config *cfg, long double score, void *params) -{ - GList *p = params; - long double res = score; - lua_State *L = cfg->lua_state; - - /* Call specified function and put input score on stack */ - if (!p->data) { - msg_info_config ("bad function name while calling normalizer"); - return score; - } - - lua_getglobal (L, p->data); - lua_pushnumber (L, score); - - if (lua_pcall (L, 1, 1, 0) != 0) { - msg_info_config ("call to %s failed", p->data); - } - - /* retrieve result */ - if (!lua_isnumber (L, -1)) { - msg_info_config ("function %s must return a number", p->data); - } - res = lua_tonumber (L, -1); - lua_pop (L, 1); - - return res; -} - - void rspamd_lua_dumpstack (lua_State *L) { diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index a7348c210..c20d833ca 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -256,14 +256,6 @@ void luaopen_fann (lua_State *L); void luaopen_sqlite3 (lua_State *L); void luaopen_cryptobox (lua_State *L); -gint rspamd_lua_call_filter (const gchar *function, struct rspamd_task *task); -gint rspamd_lua_call_chain_filter (const gchar *function, - struct rspamd_task *task, - gint *marks, - guint number); -double rspamd_lua_consolidation_func (struct rspamd_task *task, - const gchar *metric_name, - const gchar *function_name); void rspamd_lua_call_post_filters (struct rspamd_task *task); void rspamd_lua_call_pre_filters (struct rspamd_task *task); void rspamd_lua_dostring (const gchar *line); |