summaryrefslogtreecommitdiffstats
path: root/src/libstat/learn_cache
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-01-10 22:34:19 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-01-10 22:34:19 +0000
commitd0a92eca7e992d1c1b544c24d09acf0019babaa3 (patch)
treeaf5d420ce0da1265062be66a32148b608612a8c0 /src/libstat/learn_cache
parent5a4566af6e715e15ea8dce6776cdc7b9bd03b5bf (diff)
downloadrspamd-d0a92eca7e992d1c1b544c24d09acf0019babaa3.tar.gz
rspamd-d0a92eca7e992d1c1b544c24d09acf0019babaa3.zip
Rework caches API
Diffstat (limited to 'src/libstat/learn_cache')
-rw-r--r--src/libstat/learn_cache/learn_cache.h42
-rw-r--r--src/libstat/learn_cache/sqlite3_cache.c3
2 files changed, 35 insertions, 10 deletions
diff --git a/src/libstat/learn_cache/learn_cache.h b/src/libstat/learn_cache/learn_cache.h
index 84851649f..05c332076 100644
--- a/src/libstat/learn_cache/learn_cache.h
+++ b/src/libstat/learn_cache/learn_cache.h
@@ -33,24 +33,48 @@
struct rspamd_task;
struct rspamd_stat_ctx;
struct rspamd_config;
+struct rspamd_statfile;
struct rspamd_stat_cache {
const char *name;
gpointer (*init)(struct rspamd_stat_ctx *ctx,
- struct rspamd_config *cfg, const ucl_object_t *cf);
- gint (*process)(struct rspamd_task *task,
+ struct rspamd_config *cfg,
+ struct rspamd_statfile *st,
+ const ucl_object_t *cf);
+ gpointer (*runtime)(struct rspamd_task *task,
+ gpointer ctx);
+ gint (*check)(struct rspamd_task *task,
+ gboolean is_spam,
+ gpointer runtime,
+ gpointer ctx);
+ gint (*learn)(struct rspamd_task *task,
gboolean is_spam,
+ gpointer runtime,
gpointer ctx);
void (*close) (gpointer ctx);
gpointer ctx;
};
-gpointer rspamd_stat_cache_sqlite3_init(struct rspamd_stat_ctx *ctx,
- struct rspamd_config *cfg,
- const ucl_object_t *cf);
-gint rspamd_stat_cache_sqlite3_process (
- struct rspamd_task *task,
- gboolean is_spam, gpointer c);
-void rspamd_stat_cache_sqlite3_close (gpointer c);
+#define RSPAMD_STAT_CACHE_DEF(name) \
+ gpointer rspamd_stat_cache_##name##_init (struct rspamd_stat_ctx *ctx, \
+ struct rspamd_config *cfg, \
+ struct rspamd_statfile *st, \
+ const ucl_object_t *cf); \
+ gpointer rspamd_stat_cache_##name##_runtime (struct rspamd_task *task, \
+ gpointer ctx); \
+ gboolean rspamd_stat_cache_##name##_check (struct rspamd_task *task, \
+ gboolean is_spam, \
+ gpointer runtime, \
+ gpointer ctx); \
+ gboolean rspamd_stat_cache_##name##_learn (struct rspamd_task *task, \
+ gboolean is_spam, \
+ gpointer runtime, \
+ gpointer ctx); \
+ void rspamd_stat_cache_##name##_close (gpointer ctx)
+
+RSPAMD_STAT_CACHE_DEF(sqlite3);
+#ifdef WITH_HIREDIS
+RSPAMD_STAT_CACHE_DEF(redis);
+#endif
#endif /* LEARN_CACHE_H_ */
diff --git a/src/libstat/learn_cache/sqlite3_cache.c b/src/libstat/learn_cache/sqlite3_cache.c
index 299c1ebd9..02a6a81ab 100644
--- a/src/libstat/learn_cache/sqlite3_cache.c
+++ b/src/libstat/learn_cache/sqlite3_cache.c
@@ -120,8 +120,9 @@ struct rspamd_stat_sqlite3_ctx {
};
gpointer
-rspamd_stat_cache_sqlite3_init(struct rspamd_stat_ctx *ctx,
+rspamd_stat_cache_sqlite3_init (struct rspamd_stat_ctx *ctx,
struct rspamd_config *cfg,
+ struct rspamd_statfile *st,
const ucl_object_t *cf)
{
struct rspamd_stat_sqlite3_ctx *new = NULL;