diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-02-18 12:56:43 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-02-18 12:56:43 +0000 |
commit | fbf727498eefbe38d6d439b1b315f290e58aa051 (patch) | |
tree | c24acc4fdcbc17774f9d4ef4b23501108adc747c /src/libstat/learn_cache | |
parent | 29a06a80f432749fd707aecfb1612da5e4af76aa (diff) | |
download | rspamd-fbf727498eefbe38d6d439b1b315f290e58aa051.tar.gz rspamd-fbf727498eefbe38d6d439b1b315f290e58aa051.zip |
Allow sqlite3 cache customization.
Diffstat (limited to 'src/libstat/learn_cache')
-rw-r--r-- | src/libstat/learn_cache/learn_cache.h | 2 | ||||
-rw-r--r-- | src/libstat/learn_cache/sqlite3_cache.c | 35 |
2 files changed, 33 insertions, 4 deletions
diff --git a/src/libstat/learn_cache/learn_cache.h b/src/libstat/learn_cache/learn_cache.h index 51b2a9dbd..273e906f5 100644 --- a/src/libstat/learn_cache/learn_cache.h +++ b/src/libstat/learn_cache/learn_cache.h @@ -40,6 +40,7 @@ struct rspamd_stat_cache { gint (*process)(struct rspamd_task *task, gboolean is_spam, gpointer ctx); + void (*close) (gpointer ctx); gpointer ctx; }; @@ -48,5 +49,6 @@ gpointer rspamd_stat_cache_sqlite3_init(struct rspamd_stat_ctx *ctx, gint rspamd_stat_cache_sqlite3_process ( struct rspamd_task *task, gboolean is_spam, gpointer c); +void rspamd_stat_cache_sqlite3_close (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 8d8922542..d8c904d90 100644 --- a/src/libstat/learn_cache/sqlite3_cache.c +++ b/src/libstat/learn_cache/sqlite3_cache.c @@ -53,12 +53,14 @@ rspamd_stat_cache_sqlite3_init(struct rspamd_stat_ctx *ctx, { struct rspamd_stat_sqlite3_ctx *new = NULL; struct rspamd_classifier_config *clf; - const ucl_object_t *obj; + const ucl_object_t *obj, *elt; GList *cur; + gchar dbpath[PATH_MAX]; sqlite3 *sqlite; gboolean has_sqlite_cache = FALSE; gint rc; + rspamd_snprintf (dbpath, sizeof (dbpath), SQLITE_CACHE_PATH); cur = cfg->classifiers; while (cur) { @@ -67,17 +69,30 @@ rspamd_stat_cache_sqlite3_init(struct rspamd_stat_ctx *ctx, obj = ucl_object_find_key (clf->opts, "cache"); /* Sqlite3 cache is the default learn cache method */ - if (obj == NULL || g_ascii_strcasecmp (ucl_object_tostring (obj), - "sqlite3") == 0) { + if (obj == NULL) { has_sqlite_cache = TRUE; break; } + else if (ucl_object_type (obj) == UCL_OBJECT) { + elt = ucl_object_find_key (obj, "name"); + + if (ucl_object_type (elt) == UCL_STRING && + g_ascii_strcasecmp (ucl_object_tostring (elt), "sqlite3") == 0) { + + has_sqlite_cache = TRUE; + elt = ucl_object_find_key (obj, "path"); + if (elt != NULL && ucl_object_type (elt) == UCL_STRING) { + rspamd_snprintf (dbpath, sizeof (dbpath), "%s", + ucl_object_tostring (elt)); + } + } + } cur = g_list_next (cur); } if (has_sqlite_cache) { - if ((rc = sqlite3_open_v2 (SQLITE_CACHE_PATH, &sqlite, + if ((rc = sqlite3_open_v2 (dbpath, &sqlite, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_NOMUTEX, NULL)) != SQLITE_OK) { msg_err ("Cannot open sqlite db %s: %s", SQLITE_CACHE_PATH, @@ -202,3 +217,15 @@ rspamd_stat_cache_sqlite3_process (struct rspamd_task *task, return RSPAMD_LEARN_OK; } + +void +rspamd_stat_cache_sqlite3_close (gpointer c) +{ + struct rspamd_stat_sqlite3_ctx *ctx = (struct rspamd_stat_sqlite3_ctx *)c; + + if (ctx != NULL) { + sqlite3_close (ctx->db); + g_slice_free1 (sizeof (*ctx), ctx); + } + +} |