]> source.dussan.org Git - rspamd.git/commitdiff
Implement basic add and deletion.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 20 Dec 2014 14:33:53 +0000 (14:33 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 20 Dec 2014 14:33:53 +0000 (14:33 +0000)
src/fuzzy_storage.h
src/libserver/fuzzy_backend.c

index 31921013fa459ac86e86d91be00471db7035f0c4..5c659a7b9928ae2a9775f7875b33fa98a397bfa7 100644 (file)
@@ -26,6 +26,7 @@ struct rspamd_fuzzy_cmd {
        guint8 cmd;
        guint8 shingles_count;
        guint8 flag;
+       gint32 value;
        gchar digest[64];
 };
 
index 0b78b2ac05e6f04ced236712e6921d925281d6be..9556e044763afa34563f3af889417847b9bac32e 100644 (file)
@@ -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