diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-05 15:45:57 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-05 15:45:57 +0000 |
commit | ca2e07394ed795183be1a798fee1b1c7dd4d01f2 (patch) | |
tree | f233cb0f78f4d740aee0eca66f186be3944d4297 /src/libstat/learn_cache | |
parent | 603f3664584a2942b718a16a2c303212fdc4871a (diff) | |
download | rspamd-ca2e07394ed795183be1a798fee1b1c7dd4d01f2.tar.gz rspamd-ca2e07394ed795183be1a798fee1b1c7dd4d01f2.zip |
Another fix to the whole libstat architecture
Diffstat (limited to 'src/libstat/learn_cache')
-rw-r--r-- | src/libstat/learn_cache/learn_cache.h | 6 | ||||
-rw-r--r-- | src/libstat/learn_cache/sqlite3_cache.c | 78 |
2 files changed, 33 insertions, 51 deletions
diff --git a/src/libstat/learn_cache/learn_cache.h b/src/libstat/learn_cache/learn_cache.h index 273e906f5..84851649f 100644 --- a/src/libstat/learn_cache/learn_cache.h +++ b/src/libstat/learn_cache/learn_cache.h @@ -36,7 +36,8 @@ struct rspamd_config; struct rspamd_stat_cache { 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, const ucl_object_t *cf); gint (*process)(struct rspamd_task *task, gboolean is_spam, gpointer ctx); @@ -45,7 +46,8 @@ struct rspamd_stat_cache { }; gpointer rspamd_stat_cache_sqlite3_init(struct rspamd_stat_ctx *ctx, - struct rspamd_config *cfg); + struct rspamd_config *cfg, + const ucl_object_t *cf); gint rspamd_stat_cache_sqlite3_process ( struct rspamd_task *task, gboolean is_spam, gpointer c); diff --git a/src/libstat/learn_cache/sqlite3_cache.c b/src/libstat/learn_cache/sqlite3_cache.c index cf4ab615a..f5ef89ceb 100644 --- a/src/libstat/learn_cache/sqlite3_cache.c +++ b/src/libstat/learn_cache/sqlite3_cache.c @@ -121,71 +121,51 @@ struct rspamd_stat_sqlite3_ctx { gpointer rspamd_stat_cache_sqlite3_init(struct rspamd_stat_ctx *ctx, - struct rspamd_config *cfg) + struct rspamd_config *cfg, + const ucl_object_t *cf) { struct rspamd_stat_sqlite3_ctx *new = NULL; - struct rspamd_classifier_config *clf; - const ucl_object_t *obj, *elt; - GList *cur; + const ucl_object_t *elt; gchar dbpath[PATH_MAX]; + const gchar *path; sqlite3 *sqlite; - gboolean has_sqlite_cache = FALSE; GError *err = NULL; - rspamd_snprintf (dbpath, sizeof (dbpath), SQLITE_CACHE_PATH); - cur = cfg->classifiers; - while (cur) { - clf = cur->data; + if (cf) { + elt = ucl_object_find_key (cf, "path"); - obj = ucl_object_find_key (clf->opts, "cache"); - - /* Sqlite3 cache is the default learn cache method */ - if (obj == NULL) { - has_sqlite_cache = TRUE; - break; + if (elt != NULL) { + path = ucl_object_tostring (elt); + } + else { + path = SQLITE_CACHE_PATH; } - 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) { + rspamd_snprintf (dbpath, sizeof (dbpath), "%s", path); - 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)); - } - } - } + sqlite = rspamd_sqlite3_open_or_create (cfg->cfg_pool, + dbpath, create_tables_sql, &err); - cur = g_list_next (cur); + if (sqlite == NULL) { + msg_err ("cannot open sqlite3 cache: %e", err); + g_error_free (err); + err = NULL; } + else { + new = g_slice_alloc (sizeof (*new)); + new->db = sqlite; + new->prstmt = rspamd_sqlite3_init_prstmt (sqlite, prepared_stmts, + RSPAMD_STAT_CACHE_MAX, &err); - if (has_sqlite_cache) { - sqlite = rspamd_sqlite3_open_or_create (cfg->cfg_pool, - dbpath, create_tables_sql, &err); - - if (sqlite == NULL) { - msg_err_config ("cannot open sqlite3 cache: %e", err); + if (new->prstmt == NULL) { + msg_err ("cannot open sqlite3 cache: %e", err); g_error_free (err); err = NULL; - } - else { - new = g_slice_alloc (sizeof (*new)); - new->db = sqlite; - new->prstmt = rspamd_sqlite3_init_prstmt (sqlite, prepared_stmts, - RSPAMD_STAT_CACHE_MAX, &err); - - if (new->prstmt == NULL) { - msg_err_config ("cannot open sqlite3 cache: %e", err); - g_error_free (err); - err = NULL; - sqlite3_close (sqlite); - g_slice_free1 (sizeof (*new), new); - new = NULL; - } + sqlite3_close (sqlite); + g_slice_free1 (sizeof (*new), new); + new = NULL; } } |