#include "config.h" | #include "config.h" | ||||
#include "ucl.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_task; | ||||
struct rspamd_stat_ctx; | struct rspamd_stat_ctx; | ||||
struct rspamd_stat_cache { | struct rspamd_stat_cache { | ||||
const char *name; | const char *name; | ||||
gpointer (*init)(struct rspamd_stat_ctx *ctx, struct rspamd_config *cfg); | 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 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_ */ | #endif /* LEARN_CACHE_H_ */ |
return ret; | 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) | gboolean is_spam, gpointer c) | ||||
{ | { | ||||
struct rspamd_stat_sqlite3_ctx *ctx = (struct rspamd_stat_sqlite3_ctx *)c; | struct rspamd_stat_sqlite3_ctx *ctx = (struct rspamd_stat_sqlite3_ctx *)c; |
{"osb-text", osb_tokenize_text}, | {"osb-text", osb_tokenize_text}, | ||||
}; | }; | ||||
struct rspamd_stat_backend stat_backends[] = { | |||||
static struct rspamd_stat_backend stat_backends[] = { | |||||
{ | { | ||||
.name = RSPAMD_DEFAULT_BACKEND, | .name = RSPAMD_DEFAULT_BACKEND, | ||||
.init = rspamd_mmaped_file_init, | .init = rspamd_mmaped_file_init, | ||||
} | } | ||||
}; | }; | ||||
static struct rspamd_stat_cache stat_caches[] = { | |||||
{ | |||||
.name = RSPAMD_DEFAULT_CACHE, | |||||
.init = rspamd_stat_cache_sqlite3_init, | |||||
.process = rspamd_stat_cache_sqlite3_process | |||||
} | |||||
}; | |||||
void | void | ||||
rspamd_stat_init (struct rspamd_config *cfg) | rspamd_stat_init (struct rspamd_config *cfg) | ||||
stat_ctx->classifiers_count = G_N_ELEMENTS (stat_classifiers); | stat_ctx->classifiers_count = G_N_ELEMENTS (stat_classifiers); | ||||
stat_ctx->tokenizers = stat_tokenizers; | stat_ctx->tokenizers = stat_tokenizers; | ||||
stat_ctx->tokenizers_count = G_N_ELEMENTS (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 */ | /* Init backends */ | ||||
for (i = 0; i < stat_ctx->backends_count; i ++) { | for (i = 0; i < stat_ctx->backends_count; i ++) { | ||||
stat_ctx->backends[i].ctx = stat_ctx->backends[i].init (stat_ctx, cfg); | stat_ctx->backends[i].ctx = stat_ctx->backends[i].init (stat_ctx, cfg); | ||||
msg_debug ("added backend %s", stat_ctx->backends[i].name); | 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 * | struct rspamd_stat_ctx * |
#include "classifiers/classifiers.h" | #include "classifiers/classifiers.h" | ||||
#include "tokenizers/tokenizers.h" | #include "tokenizers/tokenizers.h" | ||||
#include "backends/backends.h" | #include "backends/backends.h" | ||||
#include "learn_cache/learn_cache.h" | |||||
struct rspamd_tokenizer_runtime { | struct rspamd_tokenizer_runtime { | ||||
GTree *tokens; | GTree *tokens; | ||||
guint tokenizers_count; | guint tokenizers_count; | ||||
struct rspamd_stat_backend *backends; | struct rspamd_stat_backend *backends; | ||||
guint backends_count; | guint backends_count; | ||||
struct rspamd_stat_cache *caches; | |||||
guint caches_count; | |||||
guint statfiles; | 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_ctx * rspamd_stat_get_ctx (void); | ||||
struct rspamd_stat_classifier * rspamd_stat_get_classifier (const gchar *name); | struct rspamd_stat_classifier * rspamd_stat_get_classifier (const gchar *name); | ||||
struct rspamd_stat_backend * rspamd_stat_get_backend (const gchar *name); | struct rspamd_stat_backend * rspamd_stat_get_backend (const gchar *name); |