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,
.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) "
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);
}
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