]> source.dussan.org Git - rspamd.git/commitdiff
Fix diff normalization.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 3 Dec 2012 12:30:09 +0000 (16:30 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 3 Dec 2012 12:30:09 +0000 (16:30 +0400)
Fix redirector call in surbl module.

src/diff.c
src/plugins/surbl.c
src/plugins/surbl.h

index 3173b5f19d0fe57797843215d6b582bd31eee2ec..354cfeda9c41d658dda1e9b46a0d39febb2966f5 100644 (file)
@@ -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);
        }
index 18b8441ea8b21bcbb9c1c26eab1dde0b72379e70..ba2df2dd87a9b26680cd8de26ab5d3984158a1d7 100644 (file)
@@ -820,6 +820,7 @@ free_redirector_session (void *ud)
        struct redirector_param        *param = (struct redirector_param *)ud;
 
        event_del (&param->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 (&param->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;
index 49b79ea8f6d11d4832c2c7a9bfa4113daafc4673..950e55bcb8a3315136e28b5e3ea162312e120705 100644 (file)
@@ -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;