From: Vsevolod Stakhov Date: Fri, 13 Feb 2015 16:57:06 +0000 (+0000) Subject: Configure learn caches. X-Git-Tag: 0.9.0~712 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fdff2c694ba91d9e96300b1020d577cfbe8fbd3b;p=rspamd.git Configure learn caches. --- diff --git a/src/libstat/learn_cache/learn_cache.h b/src/libstat/learn_cache/learn_cache.h index bd01d1be1..51b2a9dbd 100644 --- a/src/libstat/learn_cache/learn_cache.h +++ b/src/libstat/learn_cache/learn_cache.h @@ -28,11 +28,7 @@ #include "config.h" #include "ucl.h" -typedef enum rspamd_learn_cache_result { - RSPAMD_LEARN_OK = 0, - RSPAMD_LEARN_UNLEARN, - RSPAMD_LEARN_INGORE -} rspamd_learn_t; +#define RSPAMD_DEFAULT_CACHE "sqlite3" struct rspamd_task; struct rspamd_stat_ctx; @@ -41,9 +37,16 @@ struct rspamd_config; struct rspamd_stat_cache { const char *name; gpointer (*init)(struct rspamd_stat_ctx *ctx, struct rspamd_config *cfg); - rspamd_learn_t (*process)(struct rspamd_task *task, gboolean is_spam, + gint (*process)(struct rspamd_task *task, + gboolean is_spam, gpointer ctx); gpointer ctx; }; +gpointer rspamd_stat_cache_sqlite3_init(struct rspamd_stat_ctx *ctx, + struct rspamd_config *cfg); +gint rspamd_stat_cache_sqlite3_process ( + struct rspamd_task *task, + gboolean is_spam, gpointer c); + #endif /* LEARN_CACHE_H_ */ diff --git a/src/libstat/learn_cache/sqlite3_cache.c b/src/libstat/learn_cache/sqlite3_cache.c index ef6f005b3..0bde829f7 100644 --- a/src/libstat/learn_cache/sqlite3_cache.c +++ b/src/libstat/learn_cache/sqlite3_cache.c @@ -167,8 +167,8 @@ rspamd_stat_cache_sqlite3_check (const guchar *h, gsize len, gboolean is_spam, return ret; } -rspamd_learn_t -rspamd_stat_cache_sqlite3_process(struct rspamd_task *task, +gint +rspamd_stat_cache_sqlite3_process (struct rspamd_task *task, gboolean is_spam, gpointer c) { struct rspamd_stat_sqlite3_ctx *ctx = (struct rspamd_stat_sqlite3_ctx *)c; diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index 53eff3ecb..574d25fd3 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -44,7 +44,7 @@ static struct rspamd_stat_tokenizer stat_tokenizers[] = { {"osb-text", osb_tokenize_text}, }; -struct rspamd_stat_backend stat_backends[] = { +static struct rspamd_stat_backend stat_backends[] = { { .name = RSPAMD_DEFAULT_BACKEND, .init = rspamd_mmaped_file_init, @@ -57,6 +57,13 @@ struct rspamd_stat_backend stat_backends[] = { } }; +static struct rspamd_stat_cache stat_caches[] = { + { + .name = RSPAMD_DEFAULT_CACHE, + .init = rspamd_stat_cache_sqlite3_init, + .process = rspamd_stat_cache_sqlite3_process + } +}; void rspamd_stat_init (struct rspamd_config *cfg) @@ -73,12 +80,20 @@ rspamd_stat_init (struct rspamd_config *cfg) stat_ctx->classifiers_count = G_N_ELEMENTS (stat_classifiers); stat_ctx->tokenizers = stat_tokenizers; stat_ctx->tokenizers_count = G_N_ELEMENTS (stat_tokenizers); + stat_ctx->caches = stat_caches; + stat_ctx->caches_count = G_N_ELEMENTS (stat_caches); /* Init backends */ for (i = 0; i < stat_ctx->backends_count; i ++) { stat_ctx->backends[i].ctx = stat_ctx->backends[i].init (stat_ctx, cfg); msg_debug ("added backend %s", stat_ctx->backends[i].name); } + + /* Init caches */ + for (i = 0; i < stat_ctx->caches_count; i ++) { + stat_ctx->caches[i].ctx = stat_ctx->caches[i].init (stat_ctx, cfg); + msg_debug ("added cache %s", stat_ctx->caches[i].name); + } } struct rspamd_stat_ctx * diff --git a/src/libstat/stat_internal.h b/src/libstat/stat_internal.h index a4bcf3362..29bd937fb 100644 --- a/src/libstat/stat_internal.h +++ b/src/libstat/stat_internal.h @@ -28,6 +28,7 @@ #include "classifiers/classifiers.h" #include "tokenizers/tokenizers.h" #include "backends/backends.h" +#include "learn_cache/learn_cache.h" struct rspamd_tokenizer_runtime { GTree *tokens; @@ -79,10 +80,18 @@ struct rspamd_stat_ctx { guint tokenizers_count; struct rspamd_stat_backend *backends; guint backends_count; + struct rspamd_stat_cache *caches; + guint caches_count; guint statfiles; }; +typedef enum rspamd_learn_cache_result { + RSPAMD_LEARN_OK = 0, + RSPAMD_LEARN_UNLEARN, + RSPAMD_LEARN_INGORE +} rspamd_learn_t; + struct rspamd_stat_ctx * rspamd_stat_get_ctx (void); struct rspamd_stat_classifier * rspamd_stat_get_classifier (const gchar *name); struct rspamd_stat_backend * rspamd_stat_get_backend (const gchar *name);