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, \
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) {
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;
- }
}
}
}
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);
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,
}
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) {
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);
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 {
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) {
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;
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 (