]> source.dussan.org Git - rspamd.git/commitdiff
[Revert] Revert flags changes in fuzzy check
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 23 Jun 2016 15:07:00 +0000 (16:07 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 23 Jun 2016 15:07:00 +0000 (16:07 +0100)
src/fuzzy_storage.c
src/libserver/fuzzy_backend.c
src/plugins/fuzzy_check.c

index 31cde97a1c1d69a51e2abc00e7af1fd926c00955..ece17113578e77cf5713d9abfa394f3286e277eb 100644 (file)
@@ -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,
index 5a22377bbe488d5a484465b002ed716d07acc721..a45d7c6a735a89b457315411f5cfb89c47bc6710 100644 (file)
@@ -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 {
index a4abf3c9fcd48bc2c17aec98d731dedcec1c917f..a1cf018068eff33fb179da85122f7ef804bb8470 100644 (file)
@@ -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 (