aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-12-20 14:33:53 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-12-20 14:33:53 +0000
commite35c53bd0ed4d672392508e01230bbf0203102b4 (patch)
tree5501bfb44bf796c99d450a1b8eba50803d7353e5
parenteda0029062ca38641a59674987873811742f08f8 (diff)
downloadrspamd-e35c53bd0ed4d672392508e01230bbf0203102b4.tar.gz
rspamd-e35c53bd0ed4d672392508e01230bbf0203102b4.zip
Implement basic add and deletion.
-rw-r--r--src/fuzzy_storage.h1
-rw-r--r--src/libserver/fuzzy_backend.c33
2 files changed, 34 insertions, 0 deletions
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,
@@ -112,6 +113,14 @@ static struct rspamd_fuzzy_stmts {
.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) "
"VALUES (?1, ?2, ?3);",
@@ -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