aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorcebka@lenovo-laptop <cebka@lenovo-laptop>2010-03-16 16:32:12 +0300
committercebka@lenovo-laptop <cebka@lenovo-laptop>2010-03-16 16:32:12 +0300
commitbbd6839d50209d80fafe13fe3fab9b5bcf74bcbe (patch)
tree77413bd80760e455a4b58f46d91502fd0e8bf361 /src
parentd41fec74be04d13bd07adffe796c66cc52d8c4b7 (diff)
downloadrspamd-bbd6839d50209d80fafe13fe3fab9b5bcf74bcbe.tar.gz
rspamd-bbd6839d50209d80fafe13fe3fab9b5bcf74bcbe.zip
* Add normalizer for fuzzy hashes
* Fix fuzzy add and fuzzy del
Diffstat (limited to 'src')
-rw-r--r--src/controller.c2
-rw-r--r--src/plugins/fuzzy_check.c37
2 files changed, 36 insertions, 3 deletions
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;
}