From cdef5507e20992b5fe08e3655620e6690d887dc7 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 12 Aug 2015 15:34:58 +0100 Subject: Add configured `per_user` and `per_language` knobs for sqlite3. --- src/libstat/backends/sqlite3_backend.c | 40 ++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'src/libstat/backends/sqlite3_backend.c') diff --git a/src/libstat/backends/sqlite3_backend.c b/src/libstat/backends/sqlite3_backend.c index b87e05bde..836fe18d5 100644 --- a/src/libstat/backends/sqlite3_backend.c +++ b/src/libstat/backends/sqlite3_backend.c @@ -38,12 +38,12 @@ struct rspamd_stat_sqlite3_db { gchar *fname; GArray *prstmt; gboolean in_transaction; + gboolean enable_users; + gboolean enable_languages; }; struct rspamd_stat_sqlite3_ctx { GHashTable *files; - gboolean enable_users; - gboolean enable_languages; }; struct rspamd_stat_sqlite3_rt { @@ -443,7 +443,7 @@ rspamd_sqlite3_init (struct rspamd_stat_ctx *ctx, struct rspamd_classifier_config *clf; struct rspamd_statfile_config *stf; GList *cur, *curst; - const ucl_object_t *filenameo; + const ucl_object_t *filenameo, *lang_enabled, *users_enabled; const gchar *filename; struct rspamd_stat_sqlite3_db *bk; GError *err = NULL; @@ -489,6 +489,24 @@ rspamd_sqlite3_init (struct rspamd_stat_ctx *ctx, err = NULL; } + users_enabled = ucl_object_find_any_key (clf->opts, "per_user", + "users_enabled", NULL); + if (users_enabled != NULL) { + bk->enable_users = ucl_object_toboolean (users_enabled); + } + else { + bk->enable_users = FALSE; + } + + lang_enabled = ucl_object_find_any_key (clf->opts, + "per_language", "languages_enabled", NULL); + if (lang_enabled != NULL) { + bk->enable_languages = ucl_object_toboolean (lang_enabled); + } + else { + bk->enable_languages = FALSE; + } + ctx->statfiles ++; curst = curst->next; @@ -583,22 +601,30 @@ rspamd_sqlite3_process_token (struct rspamd_task *task, struct token_node_s *tok } if (rt->user_id == -1) { - rt->user_id = rspamd_sqlite3_get_user (bk, task, FALSE); + if (bk->enable_users) { + rt->user_id = rspamd_sqlite3_get_user (bk, task, FALSE); + } + else { + rt->user_id = 0; + } } if (rt->lang_id == -1) { - rt->lang_id = rspamd_sqlite3_get_language (bk, task, FALSE); + if (bk->enable_languages) { + rt->lang_id = rspamd_sqlite3_get_language (bk, task, FALSE); + } + else { + rt->lang_id = 0; + } } memcpy (&idx, tok->data, sizeof (idx)); - /* TODO: language and user support */ if (rspamd_sqlite3_run_prstmt (bk->sqlite, bk->prstmt, RSPAMD_STAT_BACKEND_GET_TOKEN, idx, rt->user_id, rt->lang_id, &iv) == SQLITE_OK) { res->value = iv; - /* TODO: purge empty values */ if (iv == 0) { return FALSE; } -- cgit v1.2.3