aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-01-23 15:36:31 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-01-23 15:36:31 +0000
commit8ebc43f86166fd121d9634349dfca873cb92278c (patch)
tree33a8c5843dbd3426fb16c0fd591d3f5343c764df
parent8a05515078bc8fd3d642778fcae0d005a38ec7b0 (diff)
downloadrspamd-8ebc43f86166fd121d9634349dfca873cb92278c.tar.gz
rspamd-8ebc43f86166fd121d9634349dfca873cb92278c.zip
Rework classifiers configuration and naming.
Now it is possible to register multiple classifiers with the same type.
-rw-r--r--src/libserver/cfg_file.h5
-rw-r--r--src/libserver/cfg_rcl.c115
-rw-r--r--src/libserver/cfg_utils.c3
-rw-r--r--src/lua/lua_classifier.c3
-rw-r--r--src/lua/lua_config.c3
-rw-r--r--src/lua/lua_task.c2
6 files changed, 62 insertions, 69 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index 7338b9068..23e785443 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -148,11 +148,12 @@ struct rspamd_classifier_config {
GList *statfiles; /**< statfiles list */
GHashTable *labels; /**< statfiles with labels */
gchar *metric; /**< metric of this classifier */
- struct classifier *classifier; /**< classifier interface */
- struct tokenizer *tokenizer; /**< tokenizer used for classifier */
+ gchar *classifier; /**< classifier interface */
+ gchar *tokenizer; /**< tokenizer used for classifier */
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 */
+ gchar *name; /**< unique name of classifier */
};
struct rspamd_worker_bind_conf {
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index 97481e6b2..60ec7f641 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -28,8 +28,6 @@
#include "cfg_file.h"
#include "lua/lua_common.h"
#include "expressions.h"
-#include "classifiers.h"
-#include "tokenizers.h"
struct rspamd_rcl_default_handler_data {
@@ -933,70 +931,44 @@ rspamd_rcl_classifier_handler (struct rspamd_config *cfg,
const ucl_object_t *val, *cur;
ucl_object_iter_t it = NULL;
const gchar *key, *type;
- struct rspamd_classifier_config *ccf, *found = NULL;
+ struct rspamd_classifier_config *ccf;
gboolean res = TRUE;
struct rspamd_rcl_section *stat_section;
- GList *cur_cl;
- val = ucl_object_find_key (obj, "type");
- if (val == NULL || !ucl_object_tostring_safe (val, &type)) {
- g_set_error (err,
- CFG_RCL_ERROR,
- EINVAL,
- "classifier should have type defined");
- return FALSE;
- }
+ ccf = rspamd_config_new_classifier (cfg, NULL);
- cur_cl = cfg->classifiers;
- while (cur_cl != NULL) {
- ccf = cur_cl->data;
- if (g_ascii_strcasecmp (ccf->classifier->name, type) == 0) {
- found = ccf;
- break;
+ if (rspamd_rcl_section_parse_defaults (section, cfg, obj, ccf, err)) {
+
+ HASH_FIND_STR (section->subsections, "statfile", stat_section);
+
+ if (ccf->classifier == NULL) {
+ ccf->classifier = "bayes";
}
- cur_cl = g_list_next (cur_cl);
- }
- if (found == NULL) {
- ccf = rspamd_config_new_classifier (cfg, NULL);
- ccf->classifier = rspamd_stat_get_classifier (type);
- }
- else {
- ccf = found;
- }
-
- HASH_FIND_STR (section->subsections, "statfile", stat_section);
-
- while ((val = ucl_iterate_object (obj, &it, true)) != NULL && res) {
- key = ucl_object_key (val);
- if (key != NULL) {
- if (g_ascii_strcasecmp (key, "statfile") == 0) {
- LL_FOREACH (val, cur)
- {
- res = rspamd_rcl_statfile_handler (cfg,
- cur,
- ccf,
- stat_section,
- err);
- if (!res) {
- return FALSE;
+ if (ccf->name == NULL) {
+ ccf->name = ccf->classifier;
+ }
+
+ while ((val = ucl_iterate_object (obj, &it, true)) != NULL && res) {
+ key = ucl_object_key (val);
+ if (key != NULL) {
+ if (g_ascii_strcasecmp (key, "statfile") == 0) {
+ LL_FOREACH (val, cur) {
+ res = rspamd_rcl_statfile_handler (cfg,
+ cur,
+ ccf,
+ stat_section,
+ err);
+ if (!res) {
+ return FALSE;
+ }
}
}
}
- else if (g_ascii_strcasecmp (key,
- "type") == 0 && val->type == UCL_STRING) {
- continue;
- }
- else if (g_ascii_strcasecmp (key,
- "tokenizer") == 0 && val->type == UCL_STRING) {
- ccf->tokenizer = rspamd_stat_get_tokenizer (ucl_object_tostring (val));
- }
}
}
- if (found == NULL) {
- cfg->classifiers = g_list_prepend (cfg->classifiers, ccf);
- }
+ cfg->classifiers = g_list_prepend (cfg->classifiers, ccf);
return res;
@@ -1368,12 +1340,37 @@ rspamd_rcl_config_init (void)
UCL_OBJECT,
FALSE,
TRUE);
+ rspamd_rcl_add_default_handler (sub,
+ "name",
+ rspamd_rcl_parse_struct_string,
+ G_STRUCT_OFFSET (struct rspamd_classifier_config, name),
+ 0);
+ rspamd_rcl_add_default_handler (sub,
+ "classifier",
+ rspamd_rcl_parse_struct_string,
+ G_STRUCT_OFFSET (struct rspamd_classifier_config, classifier),
+ 0);
+ /* type is an alias for classifier now */
+ rspamd_rcl_add_default_handler (sub,
+ "type",
+ rspamd_rcl_parse_struct_string,
+ G_STRUCT_OFFSET (struct rspamd_classifier_config, classifier),
+ 0);
+ rspamd_rcl_add_default_handler (sub,
+ "tokenizer",
+ rspamd_rcl_parse_struct_string,
+ G_STRUCT_OFFSET (struct rspamd_classifier_config, tokenizer),
+ 0);
+
+ /*
+ * Statfile defaults
+ */
ssub = rspamd_rcl_add_section (&sub->subsections,
- "statfile",
- rspamd_rcl_statfile_handler,
- UCL_OBJECT,
- TRUE,
- TRUE);
+ "statfile",
+ rspamd_rcl_statfile_handler,
+ UCL_OBJECT,
+ TRUE,
+ TRUE);
rspamd_rcl_add_default_handler (ssub,
"symbol",
rspamd_rcl_parse_struct_string,
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 3a0186c89..fef983758 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -29,7 +29,6 @@
#include "main.h"
#include "uthash_strcase.h"
#include "filter.h"
-#include "classifiers.h"
#include "lua/lua_common.h"
#include "kvstorage_config.h"
#include "map.h"
@@ -681,7 +680,7 @@ rspamd_config_find_classifier (struct rspamd_config *cfg, const gchar *name)
while (cur) {
cf = cur->data;
- if (g_ascii_strcasecmp (cf->classifier->name, name) == 0) {
+ if (g_ascii_strcasecmp (cf->name, name) == 0) {
return cf;
}
diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c
index 7adc473ba..c338fb294 100644
--- a/src/lua/lua_classifier.c
+++ b/src/lua/lua_classifier.c
@@ -25,7 +25,6 @@
#include "lua_common.h"
#include "cfg_file.h"
-#include "classifiers.h"
/* Classifier methods */
LUA_FUNCTION_DEF (classifier, register_pre_callback);
@@ -147,7 +146,7 @@ rspamd_lua_call_cls_pre_callbacks (struct rspamd_classifier_config *ccf,
/* Check function from global table 'classifiers' */
lua_getglobal (L, "classifiers");
if (lua_istable (L, -1)) {
- lua_pushstring (L, ccf->classifier->name);
+ lua_pushstring (L, ccf->name);
lua_gettable (L, -2);
/* Function is now on top */
if (lua_isfunction (L, -1)) {
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index c1eec7655..8e166ac32 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -29,7 +29,6 @@
#include "message.h"
#include "radix.h"
#include "trie.h"
-#include "classifiers.h"
/***
* This module is used to configure rspamd and is normally available as global
@@ -450,7 +449,7 @@ lua_config_get_classifier (lua_State * L)
cur = g_list_first (cfg->classifiers);
while (cur) {
clc = cur->data;
- if (g_ascii_strcasecmp (clc->classifier->name, name) == 0) {
+ if (g_ascii_strcasecmp (clc->name, name) == 0) {
pclc = &clc;
break;
}
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 86b19827f..98aba7f15 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -32,8 +32,6 @@
#include "util.h"
#include "images.h"
#include "cfg_file.h"
-#include "tokenizers.h"
-#include "classifiers.h"
#include "diff.h"
/***