From: Vsevolod Stakhov Date: Sat, 20 Dec 2014 14:33:53 +0000 (+0000) Subject: Implement basic add and deletion. X-Git-Tag: 0.8.0~55 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e35c53bd0ed4d672392508e01230bbf0203102b4;p=rspamd.git Implement basic add and deletion. --- diff --git a/src/fuzzy_storage.h b/src/fuzzy_storage.h index 31921013f..5c659a7b9 100644 --- a/src/fuzzy_storage.h +++ b/src/fuzzy_storage.h @@ -26,6 +26,7 @@ struct rspamd_fuzzy_cmd { guint8 cmd; guint8 shingles_count; guint8 flag; + gint32 value; gchar digest[64]; }; diff --git a/src/libserver/fuzzy_backend.c b/src/libserver/fuzzy_backend.c index 0b78b2ac0..9556e0447 100644 --- a/src/libserver/fuzzy_backend.c +++ b/src/libserver/fuzzy_backend.c @@ -68,6 +68,7 @@ enum rspamd_fuzzy_statement_idx { RSPAMD_FUZZY_BACKEND_TRANSACTION_COMMIT, RSPAMD_FUZZY_BACKEND_TRANSACTION_ROLLBACK, RSPAMD_FUZZY_BACKEND_INSERT, + RSPAMD_FUZZY_BACKEND_UPDATE, RSPAMD_FUZZY_BACKEND_INSERT_SHINGLE, RSPAMD_FUZZY_BACKEND_CHECK, RSPAMD_FUZZY_BACKEND_CHECK_SHINGLE, @@ -111,6 +112,14 @@ static struct rspamd_fuzzy_stmts { .stmt = NULL, .result = SQLITE_DONE }, + { + .idx = RSPAMD_FUZZY_BACKEND_UPDATE, + .sql = "UPDATE digests SET value = value + ?1 WHERE " + "digest==?2 AND flag==?3;", + .args = "IDI", + .stmt = NULL, + .result = SQLITE_DONE + }, { .idx = RSPAMD_FUZZY_BACKEND_INSERT_SHINGLE, .sql = "INSERT INTO shingles(value, number, digest_id) " @@ -512,7 +521,26 @@ gboolean rspamd_fuzzy_backend_add (struct rspamd_fuzzy_backend *backend, const struct rspamd_fuzzy_cmd *cmd) { + int rc; + rc = rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_CHECK, + cmd->digest, cmd->flag); + + if (rc == SQLITE_OK) { + /* We need to increase weight */ + rc = rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_UPDATE, + (gint64)cmd->value, cmd->digest, (gint)cmd->flag); + } + else { + rc = rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_INSERT, + (gint)cmd->flag, cmd->digest, (gint64)cmd->value, (gint64)time (NULL)); + + if (cmd->shingles_count > 0) { + /* Add corresponding shingles */ + } + } + + return (rc == SQLITE_OK); } @@ -520,7 +548,12 @@ gboolean rspamd_fuzzy_backend_del (struct rspamd_fuzzy_backend *backend, const struct rspamd_fuzzy_cmd *cmd) { + int rc; + + rc = rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_DELETE, + cmd->digest, cmd->flag); + return (rc == SQLITE_OK); } gboolean