summaryrefslogtreecommitdiffstats
path: root/src/libstat/stat_config.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-01-23 16:26:55 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-01-23 16:26:55 +0000
commit82612bf153debaff5a11e5542caca454e921eeaf (patch)
treeda3a5c9e7fcb90855543af1d36b0d437c88a960e /src/libstat/stat_config.c
parent2b1f046085b35e685fad03a88c827eee1f483093 (diff)
downloadrspamd-82612bf153debaff5a11e5542caca454e921eeaf.tar.gz
rspamd-82612bf153debaff5a11e5542caca454e921eeaf.zip
Refactor structures names.
Diffstat (limited to 'src/libstat/stat_config.c')
-rw-r--r--src/libstat/stat_config.c81
1 files changed, 76 insertions, 5 deletions
diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c
index a539f3c80..cd25ad0c5 100644
--- a/src/libstat/stat_config.c
+++ b/src/libstat/stat_config.c
@@ -28,11 +28,10 @@
#include "main.h"
#include "cfg_rcl.h"
#include "stat_internal.h"
-#include "backends/mmaped_file.h"
static struct rspamd_stat_ctx *stat_ctx = NULL;
-static struct classifier classifiers[] = {
+static struct rspamd_stat_classifier stat_classifiers[] = {
{
.name = "bayes",
.init_func = bayes_init,
@@ -41,11 +40,11 @@ static struct classifier classifiers[] = {
}
};
-static struct tokenizer tokenizers[] = {
- {"osb-text", osb_tokenize_text, rspamd_tokenizer_get_word},
+static struct rspamd_stat_tokenizer stat_tokenizers[] = {
+ {"osb-text", osb_tokenize_text},
};
-struct rspamd_stat_backend statfile_backends[] = {
+struct rspamd_stat_backend stat_backends[] = {
{
.name = RSPAMD_DEFAULT_BACKEND,
.init = rspamd_mmaped_file_init,
@@ -56,5 +55,77 @@ struct rspamd_stat_backend statfile_backends[] = {
void
rspamd_stat_init (struct rspamd_config *cfg)
{
+ guint i;
+ if (stat_ctx == NULL) {
+ stat_ctx = g_slice_alloc0 (sizeof (*stat_ctx));
+ }
+
+ stat_ctx->backends = stat_backends;
+ stat_ctx->backends_count = G_N_ELEMENTS (stat_backends);
+ stat_ctx->classifiers = stat_classifiers;
+ stat_ctx->classifiers_count = G_N_ELEMENTS (stat_classifiers);
+ stat_ctx->tokenizers = stat_tokenizers;
+ stat_ctx->tokenizers_count = G_N_ELEMENTS (stat_tokenizers);
+
+ /* Init backends */
+ for (i = 0; i < stat_ctx->backends_count; i ++) {
+ stat_ctx->backends[i].ctx = stat_ctx->backends[i].init (stat_ctx, cfg);
+ }
+}
+
+struct rspamd_stat_ctx *
+rspamd_stat_get_ctx (void)
+{
+ return stat_ctx;
+}
+
+struct rspamd_stat_classifier *
+rspamd_stat_get_classifier (const gchar *name)
+{
+ guint i;
+
+ for (i = 0; i < stat_ctx->classifiers_count; i ++) {
+ if (strcmp (name, stat_ctx->classifiers[i].name) == 0) {
+ return &stat_ctx->classifiers[i];
+ }
+ }
+
+ return NULL;
+}
+
+struct rspamd_stat_backend *
+rspamd_stat_get_backend (const gchar *name)
+{
+ guint i;
+
+ if (name == NULL || name[0] == '\0') {
+ name = RSPAMD_DEFAULT_BACKEND;
+ }
+
+ for (i = 0; i < stat_ctx->backends_count; i ++) {
+ if (strcmp (name, stat_ctx->backends[i].name) == 0) {
+ return &stat_ctx->backends[i];
+ }
+ }
+
+ return NULL;
+}
+
+struct rspamd_stat_tokenizer *
+rspamd_stat_get_tokenizer (const gchar *name)
+{
+ guint i;
+
+ if (name == NULL || name[0] == '\0') {
+ name = RSPAMD_DEFAULT_TOKENIZER;
+ }
+
+ for (i = 0; i < stat_ctx->tokenizers_count; i ++) {
+ if (strcmp (name, stat_ctx->tokenizers[i].name) == 0) {
+ return &stat_ctx->tokenizers[i];
+ }
+ }
+
+ return NULL;
}