From bbd6839d50209d80fafe13fe3fab9b5bcf74bcbe Mon Sep 17 00:00:00 2001 From: "cebka@lenovo-laptop" Date: Tue, 16 Mar 2010 16:32:12 +0300 Subject: [PATCH] * Add normalizer for fuzzy hashes * Fix fuzzy add and fuzzy del --- rspamc.pl.in | 1 - src/controller.c | 2 +- src/plugins/fuzzy_check.c | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/rspamc.pl.in b/rspamc.pl.in index 979c4a02e..1cf6dd45a 100755 --- a/rspamc.pl.in +++ b/rspamc.pl.in @@ -241,7 +241,6 @@ if (defined ($args{s})) { } if (defined ($args{h})) { $cfg{'hosts'} = [ $args{h} ]; - $do_parse_config = 0; } if (defined ($args{P})) { $cfg{'password'} = $args{P}; diff --git a/src/controller.c b/src/controller.c index 3bafeaa05..69b5608e7 100644 --- a/src/controller.c +++ b/src/controller.c @@ -862,7 +862,7 @@ controller_read_socket (f_str_t * in, void *arg) if (session->other_handler) { session->other_handler (session, in); } - session->state = STATE_REPLY; + rspamd_dispatcher_pause (session->dispatcher); break; case STATE_WAIT: rspamd_dispatcher_pause (session->dispatcher); diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 0b5c43a57..aad7f3b11 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -59,6 +59,7 @@ struct fuzzy_ctx { struct storage_server *servers; int servers_num; memory_pool_t *fuzzy_pool; + double max_score; }; struct fuzzy_client_session { @@ -148,6 +149,27 @@ parse_servers_string (char *str) } +static double +fuzzy_normalize (int32_t in) +{ + double ms = fuzzy_module_ctx->max_score, ams = fabs (ms), ain = fabs (in); + + if (ams > 0.001) { + if (ain < ams / 2.) { + return in; + } + else if (ain < ams * 2.) { + ain = ain / 3. + ams / 3.; + return in > 0 ? ain : -(ain); + } + else { + return in > 0 ? ms : -(ms); + } + } + + return (double)in; +} + int fuzzy_check_module_init (struct config_file *cfg, struct module_ctx **ctx) { @@ -185,6 +207,14 @@ fuzzy_check_module_config (struct config_file *cfg) else { fuzzy_module_ctx->symbol = DEFAULT_SYMBOL; } + if ((value = get_module_opt (cfg, "fuzzy_check", "max_score")) != NULL) { + fuzzy_module_ctx->max_score = strtod (value, NULL); + g_free (value); + } + else { + fuzzy_module_ctx->max_score = 0.; + } + if ((value = get_module_opt (cfg, "fuzzy_check", "servers")) != NULL) { parse_servers_string (value); } @@ -242,6 +272,7 @@ fuzzy_io_callback (int fd, short what, void *arg) struct fuzzy_cmd cmd; char buf[62], *err_str; int value; + double nval; if (what == EV_WRITE) { /* Send command to storage */ @@ -266,8 +297,10 @@ fuzzy_io_callback (int fd, short what, void *arg) /* Now try to get value */ value = strtol (buf + 3, &err_str, 10); *err_str = '\0'; - insert_result (session->task, fuzzy_module_ctx->metric, fuzzy_module_ctx->symbol, value, g_list_prepend (NULL, - memory_pool_strdup (session->task->task_pool, buf + 3))); + nval = fuzzy_normalize (value); + snprintf (buf, sizeof (buf), "%d / %.2f", value, nval); + insert_result (session->task, fuzzy_module_ctx->metric, fuzzy_module_ctx->symbol, nval, g_list_prepend (NULL, + memory_pool_strdup (session->task->task_pool, buf))); } goto ok; } -- 2.39.5