diff options
m--------- | interface | 0 | ||||
-rw-r--r-- | src/libserver/fuzzy_backend.c | 7 | ||||
-rw-r--r-- | src/libstat/backends/sqlite3_backend.c | 29 | ||||
-rw-r--r-- | src/plugins/lua/emails.lua | 22 |
4 files changed, 31 insertions, 27 deletions
diff --git a/interface b/interface -Subproject 6d4d9aa8af7fb462f93093f20d110e967506c24 +Subproject c2d48265ca8246b9bad1af6045f9ebfabbb00d2 diff --git a/src/libserver/fuzzy_backend.c b/src/libserver/fuzzy_backend.c index c59fa6133..0cf2f8cfa 100644 --- a/src/libserver/fuzzy_backend.c +++ b/src/libserver/fuzzy_backend.c @@ -377,6 +377,8 @@ rspamd_fuzzy_backend_open_db (const gchar *path, GError **err) { struct rspamd_fuzzy_backend *bk; sqlite3 *sqlite; + static const char sqlite_wal[] = "PRAGMA journal_mode=WAL;", + fallback_journal[] = "PRAGMA journal_mode=OFF;"; int rc; if ((rc = sqlite3_open_v2 (path, &sqlite, @@ -402,6 +404,11 @@ rspamd_fuzzy_backend_open_db (const gchar *path, GError **err) prepared_stmts[RSPAMD_FUZZY_BACKEND_COUNT].stmt, 0); } + if (sqlite3_exec (sqlite, sqlite_wal, NULL, NULL, NULL) != SQLITE_OK) { + msg_warn ("WAL mode is not supported, locking issues might occur"); + sqlite3_exec (sqlite, fallback_journal, NULL, NULL, NULL); + } + rspamd_fuzzy_backend_run_simple (RSPAMD_FUZZY_BACKEND_TRANSACTION_START, bk, NULL); diff --git a/src/libstat/backends/sqlite3_backend.c b/src/libstat/backends/sqlite3_backend.c index f2b5a226c..13d82b7a3 100644 --- a/src/libstat/backends/sqlite3_backend.c +++ b/src/libstat/backends/sqlite3_backend.c @@ -49,8 +49,8 @@ struct rspamd_stat_sqlite3_rt { struct rspamd_stat_sqlite3_ctx *ctx; struct rspamd_task *task; struct rspamd_stat_sqlite3_db *db; - const gchar *user; - const gchar *language; + gint64 user_id; + gint64 lang_id; }; static const char *create_tables_sql = @@ -67,8 +67,8 @@ static const char *create_tables_sql = ");" "CREATE TABLE tokens(" "token INTEGER NOT NULL," - "user INTEGER REFERENCES users(id) ON DELETE CASCADE," - "language INTEGER REFERENCES languages(id) ON DELETE CASCADE," + "user INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE," + "language INTEGER NOT NULL REFERENCES languages(id) ON DELETE CASCADE," "value INTEGER," "CONSTRAINT tid UNIQUE (token, user, language) ON CONFLICT REPLACE" ");" @@ -130,15 +130,16 @@ static struct rspamd_sqlite3_prstmt { .sql = "SELECT value FROM tokens " "LEFT JOIN languages ON tokens.language=languages.id " "LEFT JOIN users ON tokens.user=users.id " - "WHERE token=?1 AND users.name=?2 AND languages.name=?3;", + "WHERE token=?1 AND (users.id=?2 OR users.id=0) " + "AND (languages.id=?3 OR languages.id=0);", .stmt = NULL, - .args = "ITT", + .args = "III", .result = SQLITE_ROW, .ret = "I" }, { .idx = RSPAMD_STAT_BACKEND_SET_TOKEN, - .sql = "INSERT OR REPLACE INTO tokens(token, user, language, value)" + .sql = "INSERT OR REPLACE INTO tokens (token, user, language, value) " "VALUES (?1, ?2, ?3, ?4);", .stmt = NULL, .args = "IIII", @@ -234,7 +235,7 @@ rspamd_sqlite3_run_prstmt (struct rspamd_stat_sqlite3_db *db, int idx, ...) va_start (ap, idx); nargs = 1; - for (i = 0, rowid = 1; argtypes[i] != '\0'; i ++, rowid ++) { + for (i = 0, rowid = 1; argtypes[i] != '\0'; i ++) { switch (argtypes[i]) { case 'T': @@ -332,9 +333,15 @@ rspamd_sqlite3_opendb (const gchar *path, const ucl_object_t *opts, if ((rc = sqlite3_open_v2 (path, &sqlite, flags, NULL)) != SQLITE_OK) { +#if SQLITE_VERSION_NUMBER >= 3008000 g_set_error (err, rspamd_sqlite3_quark (), rc, "cannot open sqlite db %s: %s", path, sqlite3_errstr (rc)); +#else + g_set_error (err, rspamd_sqlite3_quark (), + rc, "cannot open sqlite db %s: %d", + path, rc); +#endif return NULL; } @@ -492,7 +499,7 @@ rspamd_sqlite3_runtime (struct rspamd_task *task, bk = g_hash_table_lookup (ctx->files, stcf); if (bk) { - rt = rspamd_mempool_alloc (task->task_pool, sizeof (*rt)); + rt = rspamd_mempool_alloc0 (task->task_pool, sizeof (*rt)); rt->ctx = ctx; rt->db = bk; rt->task = task; @@ -528,7 +535,7 @@ rspamd_sqlite3_process_token (struct rspamd_task *task, struct token_node_s *tok /* TODO: language and user support */ if (rspamd_sqlite3_run_prstmt (bk, RSPAMD_STAT_BACKEND_GET_TOKEN, - idx, SQLITE3_DEFAULT, SQLITE3_DEFAULT, &iv) == SQLITE_OK) { + idx, rt->user_id, rt->lang_id, &iv) == SQLITE_OK) { res->value = iv; } else { @@ -571,7 +578,7 @@ rspamd_sqlite3_learn_token (struct rspamd_task *task, struct token_node_s *tok, memcpy (&idx, tok->data, sizeof (idx)); if (rspamd_sqlite3_run_prstmt (bk, RSPAMD_STAT_BACKEND_SET_TOKEN, - idx, 0, 0, iv) == SQLITE_OK) { + idx, rt->user_id, rt->lang_id, iv) == SQLITE_OK) { return FALSE; } diff --git a/src/plugins/lua/emails.lua b/src/plugins/lua/emails.lua index 7df5262d0..36776a089 100644 --- a/src/plugins/lua/emails.lua +++ b/src/plugins/lua/emails.lua @@ -37,8 +37,8 @@ local function check_email_rule(task, rule, addr) local function emails_dns_cb(resolver, to_resolve, results, err) task:inc_dns_req() if results then - logger.info(string.format('<%s> email: [%s] resolved for symbol: %s', - task:get_message_id(), to_resolve, rule['symbol'])) + logger.infox('<%1> email: [%2] resolved for symbol: %3', + task:get_message_id(), to_resolve, rule['symbol']) task:insert_result(rule['symbol'], 1) end end @@ -56,15 +56,15 @@ local function check_email_rule(task, rule, addr) local key = addr:get_host() if rule['map']:get_key(key) then task:insert_result(rule['symbol'], 1) - logger.info(string.format('<%s> email: \'%s\' is found in list: %s', - task:get_message_id(), key, rule['symbol'])) + logger.infox('<%1> email: \'%2\' is found in list: %3', + task:get_message_id(), key, rule['symbol']) end else local key = string.format('%s@%s', addr:get_user(), addr:get_host()) if rule['map']:get_key(key) then task:insert_result(rule['symbol'], 1) - logger.info(string.format('<%s> email: \'%s\' is found in list: %s', - task:get_message_id(), key, rule['symbol'])) + logger.infox('<%1> email: \'%2\' is found in list: %3', + task:get_message_id(), key, rule['symbol']) end end end @@ -87,16 +87,6 @@ local function check_emails(task) end end - --- Registration -if type(rspamd_config.get_api_version) ~= 'nil' then - if rspamd_config:get_api_version() >= 2 then - rspamd_config:register_module_option('emails', 'rule', 'string') - else - logger.err('Invalid rspamd version for this plugin') - end -end - local opts = rspamd_config:get_all_opt('emails', 'rule') if opts and type(opts) == 'table' then for k,v in pairs(opts) do |