aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-23 16:07:00 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-23 16:07:00 +0100
commit0e09a5486513847905fb059185a7c5a32f50ead9 (patch)
treecc812dadbb38b3b264a106807a166f9c3bdcacd4
parent8dc67975d826c02e2757ff8e3e758b1839edb044 (diff)
downloadrspamd-0e09a5486513847905fb059185a7c5a32f50ead9.tar.gz
rspamd-0e09a5486513847905fb059185a7c5a32f50ead9.zip
[Revert] Revert flags changes in fuzzy check
-rw-r--r--src/fuzzy_storage.c18
-rw-r--r--src/libserver/fuzzy_backend.c73
-rw-r--r--src/plugins/fuzzy_check.c19
3 files changed, 12 insertions, 98 deletions
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c
index 31cde97a1..ece171135 100644
--- a/src/fuzzy_storage.c
+++ b/src/fuzzy_storage.c
@@ -686,24 +686,6 @@ rspamd_fuzzy_process_command (struct fuzzy_session *session)
reply:
result.tag = cmd->tag;
- if (session->epoch < RSPAMD_FUZZY_EPOCH11) {
- /* We need to convert flags to legacy format */
- guint32 flag = 0;
-
- /* We select the least significant flag if multiple flags are set */
- for (flag = 0; flag < 32; flag ++) {
- if (result.flag & (1U << flag)) {
- break;
- }
- }
-
- if (flag == (1U << 31)) {
- flag = 0;
- }
-
- result.flag = flag + 1;
- }
-
memcpy (&session->reply.rep, &result, sizeof (result));
rspamd_fuzzy_update_stats (session->ctx,
diff --git a/src/libserver/fuzzy_backend.c b/src/libserver/fuzzy_backend.c
index 5a22377bb..a45d7c6a7 100644
--- a/src/libserver/fuzzy_backend.c
+++ b/src/libserver/fuzzy_backend.c
@@ -32,7 +32,6 @@ struct rspamd_fuzzy_backend {
static const gdouble sql_sleep_time = 0.1;
static const guint max_retries = 10;
-static const guint32 flags_mask = (1U << 31);
#define msg_err_fuzzy_backend(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
backend->pool->tag.tagname, backend->pool->tag.uid, \
@@ -527,10 +526,6 @@ rspamd_fuzzy_backend_check (struct rspamd_fuzzy_backend *backend,
rep.prob = 1.0;
rep.flag = sqlite3_column_int (
prepared_stmts[RSPAMD_FUZZY_BACKEND_CHECK].stmt, 2);
-
- if (!(rep.flag & flags_mask) && rep.flag > 0) {
- rep.flag = (1U << (rep.flag - 1)) | flags_mask;
- }
}
}
else if (cmd->shingles_count > 0) {
@@ -614,10 +609,6 @@ rspamd_fuzzy_backend_check (struct rspamd_fuzzy_backend *backend,
rep.flag = sqlite3_column_int (
prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt,
3);
-
- if (!(rep.flag & flags_mask) && rep.flag > 0) {
- rep.flag = (1U << (rep.flag - 1)) | flags_mask;
- }
}
}
}
@@ -672,11 +663,6 @@ rspamd_fuzzy_backend_add (struct rspamd_fuzzy_backend *backend,
return FALSE;
}
- if (cmd->flag > 31 || cmd->flag == 0) {
- msg_err_fuzzy_backend ("flag more than 31 is no longer supported");
- return FALSE;
- }
-
rc = rspamd_fuzzy_backend_run_stmt (backend, FALSE,
RSPAMD_FUZZY_BACKEND_CHECK,
cmd->digest);
@@ -688,7 +674,7 @@ rspamd_fuzzy_backend_add (struct rspamd_fuzzy_backend *backend,
2);
rspamd_fuzzy_backend_cleanup_stmt (backend, RSPAMD_FUZZY_BACKEND_CHECK);
- if (flag & (1U << (cmd->flag - 1))) {
+ if (flag == cmd->flag) {
/* We need to increase weight */
rc = rspamd_fuzzy_backend_run_stmt (backend, TRUE,
RSPAMD_FUZZY_BACKEND_UPDATE,
@@ -703,26 +689,11 @@ rspamd_fuzzy_backend_add (struct rspamd_fuzzy_backend *backend,
}
else {
/* We need to relearn actually */
- if (flag & flags_mask) {
- /* This is already new format */
- flag |= (1U << (cmd->flag - 1));
- }
- else {
- /* Convert to the new format */
- if (flag > 31 || flag == 0) {
- msg_warn_fuzzy_backend ("storage had flag more than 31, remove "
- "it");
- flag = cmd->flag | flags_mask;
- }
- else {
- flag = (1U << (flag - 1)) | (1U << (cmd->flag - 1)) | flags_mask;
- }
- }
rc = rspamd_fuzzy_backend_run_stmt (backend, TRUE,
RSPAMD_FUZZY_BACKEND_UPDATE_FLAG,
(gint64) cmd->value,
- (gint64) flag,
+ (gint64) cmd->flag,
cmd->digest);
if (rc != SQLITE_OK) {
@@ -737,7 +708,7 @@ rspamd_fuzzy_backend_add (struct rspamd_fuzzy_backend *backend,
rspamd_fuzzy_backend_cleanup_stmt (backend, RSPAMD_FUZZY_BACKEND_CHECK);
rc = rspamd_fuzzy_backend_run_stmt (backend, FALSE,
RSPAMD_FUZZY_BACKEND_INSERT,
- (gint) (1U << (cmd->flag - 1)),
+ (gint) cmd->flag,
cmd->digest,
(gint64) cmd->value);
@@ -847,36 +818,14 @@ rspamd_fuzzy_backend_del (struct rspamd_fuzzy_backend *backend,
2);
rspamd_fuzzy_backend_cleanup_stmt (backend, RSPAMD_FUZZY_BACKEND_CHECK);
- if (!(flag & flags_mask)) {
- flag = (1U << (flag - 1)) | flags_mask;
- }
-
- if (flag & (1U << (cmd->flag - 1))) {
- flag &= ~(1U << (cmd->flag - 1));
-
- if (flag == 0) {
- /* It is the last flag, so delete hash completely */
- rc = rspamd_fuzzy_backend_run_stmt (backend, TRUE,
- RSPAMD_FUZZY_BACKEND_DELETE,
- cmd->digest);
- }
- else {
- /* We need to delete specific flag */
- rc = rspamd_fuzzy_backend_run_stmt (backend, TRUE,
- RSPAMD_FUZZY_BACKEND_UPDATE_FLAG,
- (gint64) cmd->value,
- (gint64) flag,
- cmd->digest);
- if (rc != SQLITE_OK) {
- msg_warn_fuzzy_backend ("cannot update hash to %d -> "
- "%*xs: %s", (gint) cmd->flag,
- (gint) sizeof (cmd->digest), cmd->digest,
- sqlite3_errmsg (backend->db));
- }
- }
- }
- else {
- /* The hash has a wrong flag, ignoring */
+ rc = rspamd_fuzzy_backend_run_stmt (backend, TRUE,
+ RSPAMD_FUZZY_BACKEND_DELETE,
+ cmd->digest);
+ if (rc != SQLITE_OK) {
+ msg_warn_fuzzy_backend ("cannot update hash to %d -> "
+ "%*xs: %s", (gint) cmd->flag,
+ (gint) sizeof (cmd->digest), cmd->digest,
+ sqlite3_errmsg (backend->db));
}
}
else {
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index a4abf3c9f..a1cf01806 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -198,12 +198,6 @@ parse_flags (struct fuzzy_rule *rule,
if (elt != NULL) {
map->fuzzy_flag = ucl_obj_toint (elt);
- if (map->fuzzy_flag > 31) {
- msg_err_config ("flags more than 31 are no longer "
- "supported by rspamd");
- return;
- }
-
elt = ucl_object_lookup (val, "max_score");
if (elt != NULL) {
@@ -1525,7 +1519,6 @@ fuzzy_check_try_read (struct fuzzy_client_session *session)
struct rspamd_task *task;
const struct rspamd_fuzzy_reply *rep;
struct rspamd_fuzzy_cmd *cmd = NULL;
- guint i;
gint r, ret;
guchar buf[2048], *p;
@@ -1547,17 +1540,7 @@ fuzzy_check_try_read (struct fuzzy_client_session *session)
while ((rep = fuzzy_process_reply (&p, &r,
session->commands, session->rule, &cmd)) != NULL) {
if (rep->prob > 0.5) {
- if (rep->flag & (1U << 31)) {
- /* Multi-flag */
- for (i = 0; i < 31; i ++) {
- if ((1U << i) & rep->flag) {
- fuzzy_insert_result (session, rep, cmd, i + 1);
- }
- }
- }
- else {
- fuzzy_insert_result (session, rep, cmd, rep->flag);
- }
+ fuzzy_insert_result (session, rep, cmd, rep->flag);
}
else if (rep->value == 403) {
msg_info_task (