aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/fuzzy_check.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-23 18:58:12 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-23 18:58:12 +0100
commitf2daba8fdb6045ed4be8a5458b8450a73363e725 (patch)
treec290379c294ae9a27a7ffe3f7ef6b03f006c94fb /src/plugins/fuzzy_check.c
parent9f8183fbb7bdbb38c0c5e9d7c2a2419fd0c2f074 (diff)
downloadrspamd-f2daba8fdb6045ed4be8a5458b8450a73363e725.tar.gz
rspamd-f2daba8fdb6045ed4be8a5458b8450a73363e725.zip
[Fix] More fixes to multi-flag fuzzy storage
Diffstat (limited to 'src/plugins/fuzzy_check.c')
-rw-r--r--src/plugins/fuzzy_check.c126
1 files changed, 73 insertions, 53 deletions
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index c11ab40bf..721f1257a 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -1397,6 +1397,66 @@ fuzzy_process_reply (guchar **pos, gint *r, GPtrArray *req,
return NULL;
}
+static void
+fuzzy_insert_result (struct fuzzy_client_session *session,
+ const struct rspamd_fuzzy_reply *rep,
+ struct rspamd_fuzzy_cmd *cmd, guint flag)
+{
+ const gchar *symbol;
+ struct fuzzy_mapping *map;
+ struct rspamd_task *task = session->task;
+ double nval;
+ guchar buf[2048];
+
+ /* Get mapping by flag */
+ if ((map =
+ g_hash_table_lookup (session->rule->mappings,
+ GINT_TO_POINTER (rep->flag))) == NULL) {
+ /* Default symbol and default weight */
+ symbol = session->rule->symbol;
+
+ }
+ else {
+ /* Get symbol and weight from map */
+ symbol = map->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
+ */
+
+ nval = fuzzy_normalize (rep->value,
+ session->rule->max_score);
+ nval *= rep->prob;
+ msg_info_task (
+ "found fuzzy hash %*xs with weight: "
+ "%.2f, in list: %s:%d%s",
+ rspamd_fuzzy_hash_len, cmd->digest,
+ nval,
+ symbol,
+ rep->flag,
+ map == NULL ? "(unknown)" : "");
+ if (map != NULL || !session->rule->skip_unknown) {
+ rspamd_snprintf (buf,
+ sizeof (buf),
+ "%d:%*xs:%.2f",
+ rep->flag,
+ rspamd_fuzzy_hash_len, cmd->digest,
+ rep->prob,
+ nval);
+ rspamd_task_insert_result_single (session->task,
+ symbol,
+ nval,
+ g_list_prepend (NULL,
+ rspamd_mempool_strdup (
+ session->task->task_pool,
+ buf)));
+ }
+}
+
/* Fuzzy check callback */
static void
fuzzy_check_io_callback (gint fd, short what, void *arg)
@@ -1404,14 +1464,12 @@ fuzzy_check_io_callback (gint fd, short what, void *arg)
struct fuzzy_client_session *session = arg;
const struct rspamd_fuzzy_reply *rep;
struct rspamd_task *task;
- struct fuzzy_mapping *map;
guchar buf[2048], *p;
- const gchar *symbol;
struct fuzzy_cmd_io *io;
struct rspamd_fuzzy_cmd *cmd = NULL;
guint i;
gint r;
- double nval;
+
enum {
return_error = 0,
return_want_more,
@@ -1434,68 +1492,30 @@ fuzzy_check_io_callback (gint fd, short what, void *arg)
while ((rep = fuzzy_process_reply (&p, &r,
session->commands, session->rule, &cmd)) != NULL) {
- /* Get mapping by flag */
- if ((map =
- g_hash_table_lookup (session->rule->mappings,
- GINT_TO_POINTER (rep->flag))) == NULL) {
- /* Default symbol and default weight */
- symbol = session->rule->symbol;
-
- }
- else {
- /* Get symbol and weight from map */
- symbol = map->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 %*xs with weight: "
- "%.2f, in list: %s:%d%s",
- rspamd_fuzzy_hash_len, cmd->digest,
- nval,
- symbol,
- rep->flag,
- map == NULL ? "(unknown)" : "");
- if (map != NULL || !session->rule->skip_unknown) {
- rspamd_snprintf (buf,
- sizeof (buf),
- "%d:%*xs:%.2f",
- rep->flag,
- rspamd_fuzzy_hash_len, cmd->digest,
- rep->prob,
- nval);
- rspamd_task_insert_result_single (session->task,
- symbol,
- nval,
- g_list_prepend (NULL,
- rspamd_mempool_strdup (
- session->task->task_pool,
- buf)));
+ 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);
}
}
else if (rep->value == 403) {
msg_info_task (
- "fuzzy check error for %s(%d): forbidden",
- symbol,
+ "fuzzy check error for %d: forbidden",
rep->flag);
}
else if (rep->value != 0) {
msg_info_task (
- "fuzzy check error for %s(%d): unknown error (%d)",
- symbol,
+ "fuzzy check error for %d: unknown error (%d)",
rep->flag,
rep->value);
}
- /* Not found */
ret = return_finished;
}