aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
parent5a4566af6e715e15ea8dce6776cdc7b9bd03b5bf (diff)
downloadrspamd-d0a92eca7e992d1c1b544c24d09acf0019babaa3.tar.gz
rspamd-d0a92eca7e992d1c1b544c24d09acf0019babaa3.zip
Rework caches API
Diffstat (limited to 'src')
-rw-r--r--src/libstat/learn_cache/learn_cache.h42
-rw-r--r--src/libstat/learn_cache/sqlite3_cache.c3
-rw-r--r--src/libstat/stat_config.c19
3 files changed, 48 insertions, 16 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;
diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c
index 1c6989508..d8b980aec 100644
--- a/src/libstat/stat_config.c
+++ b/src/libstat/stat_config.c
@@ -77,13 +77,20 @@ static struct rspamd_stat_backend stat_backends[] = {
#endif
};
-static struct rspamd_stat_cache stat_caches[] = {
- {
- .name = RSPAMD_DEFAULT_CACHE,
- .init = rspamd_stat_cache_sqlite3_init,
- .process = rspamd_stat_cache_sqlite3_process,
- .close = rspamd_stat_cache_sqlite3_close
+#define RSPAMD_STAT_CACHE_ELT(nam, eltn) { \
+ .name = #nam, \
+ .init = rspamd_stat_cache_##eltn##_init, \
+ .runtime = rspamd_stat_cache_##eltn##_runtime, \
+ .check = rspamd_stat_cache_##eltn##_check, \
+ .learn = rspamd_stat_cache_##eltn##_learn, \
+ .close = rspamd_stat_cache_##eltn##_close \
}
+
+static struct rspamd_stat_cache stat_caches[] = {
+ RSPAMD_STAT_CACHE_ELT(sqlite3, sqlite3),
+#ifdef WITH_HIREDIS
+ RSPAMD_STAT_CACHE_ELT(redis, redis),
+#endif
};
void