@@ -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_ */ |
@@ -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; |
@@ -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 * |
@@ -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); |