summaryrefslogtreecommitdiffstats
path: root/src/lua/lua_config.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-12-16 20:06:29 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-12-16 20:06:29 +0300
commit1b1bcd6966f47a2568acee011dd4b9f18195d765 (patch)
tree219073936a703bd001699bc0ca4c70014068c26c /src/lua/lua_config.c
parentb7046a0e6667e9c840b83acaf08f9ac117508eaa (diff)
downloadrspamd-1b1bcd6966f47a2568acee011dd4b9f18195d765.tar.gz
rspamd-1b1bcd6966f47a2568acee011dd4b9f18195d765.zip
* Implement pre and post classify callbacks for checking specific statfiles for this task
TODO: - add properties to get all parameters of input task - add properties to statfile object - add some normalization function for calling from classify process - document changes
Diffstat (limited to 'src/lua/lua_config.c')
-rw-r--r--src/lua/lua_config.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 377d72be5..fa23134a9 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -27,6 +27,7 @@
#include "../expressions.h"
#include "../map.h"
#include "../radix.h"
+#include "../classifiers/classifiers.h"
/* Config file methods */
LUA_FUNCTION_DEF (config, get_module_opt);
@@ -35,6 +36,7 @@ LUA_FUNCTION_DEF (config, get_all_opt);
LUA_FUNCTION_DEF (config, register_function);
LUA_FUNCTION_DEF (config, add_radix_map);
LUA_FUNCTION_DEF (config, add_hash_map);
+LUA_FUNCTION_DEF (config, get_classifier);
static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, get_module_opt),
@@ -43,6 +45,7 @@ static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, register_function),
LUA_INTERFACE_DEF (config, add_radix_map),
LUA_INTERFACE_DEF (config, add_hash_map),
+ LUA_INTERFACE_DEF (config, get_classifier),
{"__tostring", lua_class_tostring},
{NULL, NULL}
};
@@ -236,6 +239,39 @@ lua_config_get_metric (lua_State * L)
}
+static int
+lua_config_get_classifier (lua_State * L)
+{
+ struct config_file *cfg = lua_check_config (L);
+ struct classifier_config *clc = NULL, **pclc = NULL;
+ const char *name;
+ GList *cur;
+
+ if (cfg) {
+ name = luaL_checkstring (L, 2);
+
+ cur = g_list_first (cfg->classifiers);
+ while (cur) {
+ clc = cur->data;
+ if (g_ascii_strcasecmp (clc->classifier->name, name) == 0) {
+ pclc = &clc;
+ break;
+ }
+ cur = g_list_next (cur);
+ }
+ if (pclc) {
+ pclc = lua_newuserdata (L, sizeof (struct classifier_config *));
+ lua_setclass (L, "rspamd{classifier}", -1);
+ *pclc = clc;
+ return 1;
+ }
+ }
+
+ lua_pushnil (L);
+ return 1;
+
+}
+
struct lua_callback_data {
const char *name;
lua_State *L;