diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-10-06 18:59:25 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-10-06 18:59:25 +0100 |
commit | 37ad53dee0c78deaaef3cf15212a081c8b460bed (patch) | |
tree | dbb465f4a3e1d156ca8b7c34d3fc44b3960908b1 | |
parent | 1dfa09dd11af4aad772935508cb0d234484c7d86 (diff) | |
download | rspamd-37ad53dee0c78deaaef3cf15212a081c8b460bed.tar.gz rspamd-37ad53dee0c78deaaef3cf15212a081c8b460bed.zip |
[Rework] Remove legacy code never used for classifiers
-rw-r--r-- | src/libserver/cfg_file.h | 2 | ||||
-rw-r--r-- | src/libserver/cfg_rcl.c | 4 | ||||
-rw-r--r-- | src/lua/lua_classifier.c | 191 | ||||
-rw-r--r-- | src/lua/lua_common.h | 11 |
4 files changed, 2 insertions, 206 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 2f671135e..d10ce235d 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -156,8 +156,6 @@ struct rspamd_classifier_config { struct rspamd_tokenizer_config *tokenizer; /**< tokenizer used for classifier */ const gchar *backend; /**< name of statfile's backend */ ucl_object_t *opts; /**< other options */ - GList *pre_callbacks; /**< list of callbacks that are called before classification */ - GList *post_callbacks; /**< list of callbacks that are called after classification */ GList *learn_conditions; /**< list of learn condition callbacks */ gchar *name; /**< unique name of classifier */ guint32 min_tokens; /**< minimal number of tokens to process classifier */ diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index 8ada11f88..b770e14ad 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -874,10 +874,10 @@ rspamd_rcl_set_lua_globals (struct rspamd_config *cfg, lua_State *L, lua_setglobal (L, "composites"); } - lua_getglobal (L, "classifiers"); + lua_getglobal (L, "rspamd_classifiers"); if (lua_isnil (L, -1)) { lua_newtable (L); - lua_setglobal (L, "classifiers"); + lua_setglobal (L, "rspamd_classifiers"); } lua_getglobal (L, "rspamd_version"); diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c index aaf3888df..488a9d477 100644 --- a/src/lua/lua_classifier.c +++ b/src/lua/lua_classifier.c @@ -17,21 +17,16 @@ #include "cfg_file.h" /* Classifier methods */ -LUA_FUNCTION_DEF (classifier, register_pre_callback); -LUA_FUNCTION_DEF (classifier, register_post_callback); LUA_FUNCTION_DEF (classifier, get_statfiles); LUA_FUNCTION_DEF (classifier, get_statfile_by_label); static const struct luaL_reg classifierlib_m[] = { - LUA_INTERFACE_DEF (classifier, register_pre_callback), - LUA_INTERFACE_DEF (classifier, register_post_callback), LUA_INTERFACE_DEF (classifier, get_statfiles), LUA_INTERFACE_DEF (classifier, get_statfile_by_label), {"__tostring", rspamd_lua_class_tostring}, {NULL, NULL} }; - LUA_FUNCTION_DEF (statfile, get_symbol); LUA_FUNCTION_DEF (statfile, get_label); LUA_FUNCTION_DEF (statfile, is_spam); @@ -46,11 +41,6 @@ static const struct luaL_reg statfilelib_m[] = { {NULL, NULL} }; -struct classifier_callback_data { - lua_State *L; - const gchar *name; -}; - static struct rspamd_statfile_config * lua_check_statfile (lua_State * L); /* Classifier implementation */ @@ -64,187 +54,6 @@ lua_check_classifier (lua_State * L) return ud ? *((struct rspamd_classifier_config **)ud) : NULL; } -static GList * -call_classifier_pre_callback (struct rspamd_classifier_config *ccf, - struct rspamd_task *task, - lua_State *L, - gboolean is_learn, - gboolean is_spam) -{ - struct rspamd_classifier_config **pccf; - struct rspamd_task **ptask; - struct rspamd_statfile_config **pst; - GList *res = NULL; - - pccf = lua_newuserdata (L, sizeof (struct rspamd_classifier_config *)); - rspamd_lua_setclass (L, "rspamd{classifier}", -1); - *pccf = ccf; - - ptask = lua_newuserdata (L, sizeof (struct rspamd_task *)); - rspamd_lua_setclass (L, "rspamd{task}", -1); - *ptask = task; - - lua_pushboolean (L, is_learn); - lua_pushboolean (L, is_spam); - - if (lua_pcall (L, 4, 1, 0) != 0) { - msg_warn_task ("error running pre classifier callback %s", - lua_tostring (L, -1)); - lua_pop (L, 1); - } - else { - if (lua_istable (L, -1)) { - lua_pushnil (L); - while (lua_next (L, -2)) { - pst = rspamd_lua_check_udata (L, -1, "rspamd{statfile}"); - if (pst) { - res = g_list_prepend (res, *pst); - } - lua_pop (L, 1); - } - } - lua_pop (L, 1); - } - - return res; -} - -/* Return list of statfiles that should be checked for this message */ -GList * -rspamd_lua_call_cls_pre_callbacks (struct rspamd_classifier_config *ccf, - struct rspamd_task *task, - gboolean is_learn, - gboolean is_spam, - lua_State *L) -{ - GList *res = NULL, *cur; - struct classifier_callback_data *cd; - - - /* Go throught all callbacks and call them, appending results to list */ - cur = g_list_first (ccf->pre_callbacks); - while (cur) { - cd = cur->data; - lua_getglobal (L, cd->name); - - res = - g_list_concat (res, - call_classifier_pre_callback (ccf, task, L, is_learn, is_spam)); - - cur = g_list_next (cur); - } - - if (res == NULL) { - /* Check function from global table 'classifiers' */ - lua_getglobal (L, "classifiers"); - if (lua_istable (L, -1)) { - lua_pushstring (L, ccf->name); - lua_gettable (L, -2); - /* Function is now on top */ - if (lua_isfunction (L, -1)) { - res = call_classifier_pre_callback (ccf, - task, - L, - is_learn, - is_spam); - } - lua_pop (L, 1); - } - lua_pop (L, 1); - } - - return res; -} - -/* Return result mark for statfile */ -double -rspamd_lua_call_cls_post_callbacks (struct rspamd_classifier_config *ccf, - struct rspamd_task *task, - double in, - lua_State *L) -{ - struct classifier_callback_data *cd; - struct rspamd_classifier_config **pccf; - struct rspamd_task **ptask; - double out = in; - GList *cur; - - /* Go throught all callbacks and call them, appending results to list */ - cur = g_list_first (ccf->pre_callbacks); - while (cur) { - cd = cur->data; - lua_getglobal (L, cd->name); - - pccf = lua_newuserdata (L, sizeof (struct rspamd_classifier_config *)); - rspamd_lua_setclass (L, "rspamd{classifier}", -1); - *pccf = ccf; - - ptask = lua_newuserdata (L, sizeof (struct rspamd_task *)); - rspamd_lua_setclass (L, "rspamd{task}", -1); - *ptask = task; - - lua_pushnumber (L, out); - - if (lua_pcall (L, 3, 1, 0) != 0) { - msg_warn_task ("error running function %s: %s", cd->name, - lua_tostring (L, -1)); - lua_pop (L, 1); - } - else { - if (lua_isnumber (L, 1)) { - out = lua_tonumber (L, 1); - } - lua_pop (L, 1); - } - - cur = g_list_next (cur); - } - - return out; - -} - -static gint -lua_classifier_register_pre_callback (lua_State *L) -{ - struct rspamd_classifier_config *ccf = lua_check_classifier (L); - struct classifier_callback_data *cd; - const gchar *name; - - if (ccf) { - name = luaL_checkstring (L, 2); - if (name) { - cd = g_malloc (sizeof (struct classifier_callback_data)); - cd->name = g_strdup (name); - cd->L = L; - ccf->pre_callbacks = g_list_prepend (ccf->pre_callbacks, cd); - } - } - - return 0; - -} - -static gint -lua_classifier_register_post_callback (lua_State *L) -{ - struct rspamd_classifier_config *ccf = lua_check_classifier (L); - struct classifier_callback_data *cd; - const gchar *name; - - if (ccf) { - name = luaL_checkstring (L, 2); - if (name) { - cd = g_malloc (sizeof (struct classifier_callback_data)); - cd->name = g_strdup (name); - cd->L = L; - ccf->pre_callbacks = g_list_prepend (ccf->pre_callbacks, cd); - } - } - - return 0; -} - /* Return table of statfiles indexed by name */ static gint lua_classifier_get_statfiles (lua_State *L) diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 249ca9b90..6fdff5990 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -258,17 +258,6 @@ void luaopen_cryptobox (lua_State *L); void rspamd_lua_dostring (const gchar *line); -/* Classify functions */ -GList * rspamd_lua_call_cls_pre_callbacks (struct rspamd_classifier_config *ccf, - struct rspamd_task *task, - gboolean is_learn, - gboolean is_spam, - lua_State *L); -double rspamd_lua_call_cls_post_callbacks (struct rspamd_classifier_config *ccf, - struct rspamd_task *task, - double in, - lua_State *L); - double rspamd_lua_normalize (struct rspamd_config *cfg, long double score, void *params); |