diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2012-12-03 16:30:09 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2012-12-03 16:30:09 +0400 |
commit | e981e52b3a4e74fc365150a9e8cac43bc10c2969 (patch) | |
tree | 43de51f9e0a621fa016d03ab4a5c8ac81f90a7e5 /src | |
parent | 71defe8523b86a0c0ac898f5512f70ab74df15c7 (diff) | |
download | rspamd-e981e52b3a4e74fc365150a9e8cac43bc10c2969.tar.gz rspamd-e981e52b3a4e74fc365150a9e8cac43bc10c2969.zip |
Fix diff normalization.
Fix redirector call in surbl module.
Diffstat (limited to 'src')
-rw-r--r-- | src/diff.c | 8 | ||||
-rw-r--r-- | src/plugins/surbl.c | 15 | ||||
-rw-r--r-- | src/plugins/surbl.h | 3 |
3 files changed, 16 insertions, 10 deletions
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; |