if (sel_id != -1) {
/* We have some id selected here */
rep.prob = (float)max_cnt / (float)RSPAMD_SHINGLE_SIZE;
- msg_debug_fuzzy_backend ("found fuzzy hash with probability %.2f", rep.prob);
- rc = rspamd_fuzzy_backend_run_stmt (backend, FALSE,
- RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID, sel_id);
- if (rc == SQLITE_OK) {
- digest = sqlite3_column_text (
- prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt, 0);
- timestamp = sqlite3_column_int64 (
- prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt, 2);
- if (time (NULL) - timestamp > expire) {
- /* Expire element */
- msg_debug_fuzzy_backend ("requested hash has been expired");
- }
- else {
- rep.value = sqlite3_column_int64 (
- prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt, 1);
- rep.flag = sqlite3_column_int (
- prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt, 3);
+
+ if (rep.prob > 0.5) {
+ msg_debug_fuzzy_backend (
+ "found fuzzy hash with probability %.2f",
+ rep.prob);
+ rc = rspamd_fuzzy_backend_run_stmt (backend, FALSE,
+ RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID, sel_id);
+ if (rc == SQLITE_OK) {
+ digest = sqlite3_column_text (
+ prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt,
+ 0);
+ timestamp = sqlite3_column_int64 (
+ prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt,
+ 2);
+ if (time (NULL) - timestamp > expire) {
+ /* Expire element */
+ msg_debug_fuzzy_backend (
+ "requested hash has been expired");
+ }
+ else {
+ rep.value = sqlite3_column_int64 (
+ prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt,
+ 1);
+ rep.flag = sqlite3_column_int (
+ prepared_stmts[RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID].stmt,
+ 3);
+ }
}
}
+ else {
+ /* Otherwise we assume that as error */
+ rep.value = 0;
+ }
rspamd_fuzzy_backend_cleanup_stmt (backend,
RSPAMD_FUZZY_BACKEND_GET_DIGEST_BY_ID);
symbol = map->symbol;
}
- if (rep->value == 0) {
- if (rep->prob > 0.5) {
- nval = fuzzy_normalize (rep->value,
- session->rule->max_score);
- nval *= rep->prob;
- msg_info_task (
- "found fuzzy hash with weight: "
- "%.2f, in list: %s:%d%s",
- nval,
- symbol,
+
+ /*
+ * Hash is assumed to be found if probability is more than 0.5
+ * In that case `value` means number of matches
+ * Otherwise `value` means error code
+ */
+ if (rep->prob > 0.5) {
+ nval = fuzzy_normalize (rep->value,
+ session->rule->max_score);
+ nval *= rep->prob;
+ msg_info_task (
+ "found fuzzy hash with weight: "
+ "%.2f, in list: %s:%d%s",
+ nval,
+ symbol,
+ rep->flag,
+ map == NULL ? "(unknown)" : "");
+ if (map != NULL || !session->rule->skip_unknown) {
+ rspamd_snprintf (buf,
+ sizeof (buf),
+ "%d: %.2f / %.2f",
rep->flag,
- map == NULL ? "(unknown)" : "");
- if (map != NULL || !session->rule->skip_unknown) {
- rspamd_snprintf (buf,
- sizeof (buf),
- "%d: %.2f / %.2f",
- rep->flag,
- rep->prob,
- nval);
- rspamd_task_insert_result_single (session->task,
- symbol,
- nval,
- g_list_prepend (NULL,
- rspamd_mempool_strdup (
- session->task->task_pool,
- buf)));
- }
+ rep->prob,
+ nval);
+ rspamd_task_insert_result_single (session->task,
+ symbol,
+ nval,
+ g_list_prepend (NULL,
+ rspamd_mempool_strdup (
+ session->task->task_pool,
+ buf)));
}
}
else if (rep->value == 403) {