From: Vsevolod Stakhov Date: Mon, 3 Dec 2012 12:30:09 +0000 (+0400) Subject: Fix diff normalization. X-Git-Tag: 0.5.4~46 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e981e52b3a4e74fc365150a9e8cac43bc10c2969;p=rspamd.git Fix diff normalization. Fix redirector call in surbl module. --- diff --git a/src/diff.c b/src/diff.c index 3173b5f19..354cfeda9 100644 --- a/src/diff.c +++ b/src/diff.c @@ -411,7 +411,7 @@ compare_diff_distance_normalized (f_str_t *s1, f_str_t *s2) t = b1; /* The first string */ - while (r1 > 0 && h - b1 < (gint)sizeof (b1)) { + while (r1 > 0 && t - b1 < (gint)sizeof (b1)) { if (!g_ascii_isspace (*h)) { *t++ = g_ascii_tolower (*h); } @@ -421,12 +421,12 @@ compare_diff_distance_normalized (f_str_t *s1, f_str_t *s2) } t1.begin = b1; - t1.len = h - b1; + t1.len = t - b1; /* The second string */ h = p2; t = b2; - while (r2 > 0 && h - b2 < (gint)sizeof (b2)) { + while (r2 > 0 && t - b2 < (gint)sizeof (b2)) { if (!g_ascii_isspace (*h)) { *t++ = g_ascii_tolower (*h); } @@ -436,7 +436,7 @@ compare_diff_distance_normalized (f_str_t *s1, f_str_t *s2) } t2.begin = b2; - t2.len = h - b2; + t2.len = t - b2; cur_diff += compare_diff_distance_unnormalized (&t1, &t2); } diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 18b8441ea..ba2df2dd8 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -820,6 +820,7 @@ free_redirector_session (void *ud) struct redirector_param *param = (struct redirector_param *)ud; event_del (¶m->ev); + g_string_free (param->buf, TRUE); close (param->sock); } @@ -828,10 +829,11 @@ redirector_callback (gint fd, short what, void *arg) { struct redirector_param *param = (struct redirector_param *)arg; struct worker_task *task = param->task; - gchar url_buf[1024]; + gchar url_buf[512]; gint r; struct timeval *timeout; gchar *p, *c; + gboolean found = FALSE; switch (param->state) { case STATE_CONNECT: @@ -872,20 +874,22 @@ redirector_callback (gint fd, short what, void *arg) return; } - url_buf[r - 1] = '\0'; + g_string_append_len (param->buf, url_buf, r); - if ((p = strstr (url_buf, "Uri: ")) != NULL) { + if ((p = strstr (param->buf->str, "Uri: ")) != NULL) { p += sizeof ("Uri: ") - 1; c = p; - while (p++ < url_buf + sizeof (url_buf) - 1) { + while (p++ < param->buf->str + param->buf->len - 1) { if (*p == '\r' || *p == '\n') { *p = '\0'; + found = TRUE; break; } } - if (*p == '\0') { + if (found) { debug_task ("<%s> got reply from redirector: '%s' -> '%s'", param->task->message_id, struri (param->url), c); parse_uri (param->url, memory_pool_strdup (param->task->task_pool, c), param->task->task_pool); + make_surbl_requests (param->url, param->task, param->suffix, FALSE); } } upstream_ok (¶m->redirector->up, param->task->tv.tv_sec); @@ -934,6 +938,7 @@ register_redirector_call (struct uri *url, struct worker_task *task, param->sock = s; param->suffix = suffix; param->redirector = selected; + param->buf = g_string_sized_new (1024); timeout = memory_pool_alloc (task->task_pool, sizeof (struct timeval)); timeout->tv_sec = surbl_module_ctx->connect_timeout / 1000; timeout->tv_usec = (surbl_module_ctx->connect_timeout - timeout->tv_sec * 1000) * 1000; diff --git a/src/plugins/surbl.h b/src/plugins/surbl.h index 49b79ea8f..950e55bcb 100644 --- a/src/plugins/surbl.h +++ b/src/plugins/surbl.h @@ -68,8 +68,9 @@ struct redirector_param { struct redirector_upstream *redirector; enum { STATE_CONNECT, - STATE_READ, + STATE_READ } state; + GString *buf; struct event ev; gint sock; GTree *tree;