]> source.dussan.org Git - rspamd.git/commitdiff
* Fix stupid error with surbl module reconfig (another one, blame me)
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 5 Jul 2010 12:57:55 +0000 (16:57 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 5 Jul 2010 12:57:55 +0000 (16:57 +0400)
* Do not show duplicate urls in url header

src/main.c
src/map.c
src/map.h
src/plugins/surbl.c
src/protocol.c

index e75b468999b74033995886101f5508f69a155c1a..da8b87e64fea37be45f9aebdadbaba6729de0a21 100644 (file)
@@ -28,6 +28,7 @@
 #include "util.h"
 #include "lmtp.h"
 #include "smtp.h"
+#include "map.h"
 #include "fuzzy_storage.h"
 #include "cfg_xml.h"
 
@@ -951,6 +952,7 @@ main (int argc, char **argv, char **env)
 
                        msg_info ("rspamd " RVERSION " is restarting");
                        g_hash_table_foreach (rspamd->workers, kill_old_workers, NULL);
+                       remove_all_maps ();
                        reread_config (rspamd);
                        spawn_workers (rspamd);
 
index b864c6a42bd80d876d8a1b01e31c7459b8643bf6..12b833ae0a053a4eba01b2b4db5b69c6b83cae51 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -831,3 +831,22 @@ start_map_watch (void)
                cur = g_list_next (cur);
        }
 }
+
+void 
+remove_all_maps (void)
+{
+       GList                          *cur = maps;
+       struct rspamd_map              *map;
+
+       /* First of all do synced read of data */
+       while (cur) {
+               map = cur->data;
+               event_del (&map->ev);
+               cur = g_list_next (cur);
+       }
+       g_list_free (maps);
+       maps = NULL;
+       memory_pool_delete (map_pool);
+       map_pool = NULL;
+}
+
index c9093d68ce67555508f7f4dc765029767053dd5d..fe3a2b36bc62267cdc7362aa0c26cc97ba87bf32 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -50,6 +50,7 @@ struct rspamd_map {
 
 gboolean add_map (const char *map_line, map_cb_t read_callback, map_fin_cb_t fin_callback, void **user_data);
 void start_map_watch (void);
+void remove_all_maps (void);
 
 typedef void                    (*insert_func) (gpointer st, gconstpointer key, gpointer value);
 
index ee8622f126f8b733b57f42a602a330db79b1def7..8c9d2ccb08f07eaae84d7e102f27f907b1ddbe6a 100644 (file)
@@ -100,7 +100,7 @@ static u_char *
 read_exceptions_list (memory_pool_t * pool, u_char * chunk, size_t len, struct map_cb_data *data)
 {
        if (data->cur_data == NULL) {
-               data->cur_data = memory_pool_alloc (pool, sizeof (GHashTable *) * MAX_LEVELS);
+               data->cur_data = memory_pool_alloc0 (pool, sizeof (GHashTable *) * MAX_LEVELS);
        }
        return abstract_parse_list (pool, chunk, len, data, (insert_func) exception_insert);
 }
index 276b63a9eaa1560397e8e1543ae4e7b9755fb7bc..98d68bf129934dace92f009ce05cf21c6a8ced15 100644 (file)
@@ -439,6 +439,19 @@ write_hashes_to_log (struct worker_task *task, char *logbuf, int offset, int siz
        }
 }
 
+static gint
+compare_url_func (gconstpointer a, gconstpointer b)
+{
+       const struct uri               *u1 = a, *u2 = b;
+
+       if (u1->hostlen != u2->hostlen) {
+               return u1->hostlen - u2->hostlen;
+       }
+       else {
+               return memcmp (u1->host, u2->host, u1->hostlen);
+       }
+}
+
 static gboolean
 show_url_header (struct worker_task *task)
 {
@@ -447,8 +460,10 @@ show_url_header (struct worker_task *task)
        struct uri                     *url;
        GList                          *cur;
        f_str_t                         host;
+       GTree                          *url_tree;
 
        r = rspamd_snprintf (outbuf, sizeof (outbuf), "Urls: ");
+       url_tree = g_tree_new (compare_url_func);
        cur = task->urls;
        while (cur) {
                url = cur->data;
@@ -456,37 +471,40 @@ show_url_header (struct worker_task *task)
             /* Write this url to log as well */
             msg_info ("url found: <%s>, score: [%.2f / %.2f]", struri (url), default_score, default_required_score);
         }
-               host.begin = url->host;
-               host.len = url->hostlen;
-               /* Skip long hosts to avoid protocol coollisions */
-               if (host.len > OUTBUFSIZ) {
-                       cur = g_list_next (cur);
-                       continue;
-               }
-               /* Do header folding */
-               if (host.len + r >= OUTBUFSIZ - 3) {
-                       outbuf[r++] = '\r';
-                       outbuf[r++] = '\n';
-                       outbuf[r] = ' ';
-                       if (! rspamd_dispatcher_write (task->dispatcher, outbuf, r, TRUE, FALSE)) {
-                               return FALSE;
+               if (g_tree_lookup (url_tree, url) == NULL) {
+                       g_tree_insert (url_tree, url, url);
+                       host.begin = url->host;
+                       host.len = url->hostlen;
+                       /* Skip long hosts to avoid protocol coollisions */
+                       if (host.len > OUTBUFSIZ) {
+                               cur = g_list_next (cur);
+                               continue;
+                       }
+                       /* Do header folding */
+                       if (host.len + r >= OUTBUFSIZ - 3) {
+                               outbuf[r++] = '\r';
+                               outbuf[r++] = '\n';
+                               outbuf[r] = ' ';
+                               if (! rspamd_dispatcher_write (task->dispatcher, outbuf, r, TRUE, FALSE)) {
+                                       return FALSE;
+                               }
+                               r = 0;
+                       }
+                       /* Write url host to buf */
+                       if (g_list_next (cur) != NULL) {
+                               c = *(host.begin + host.len);
+                               *(host.begin + host.len) = '\0';
+                               debug_task ("write url: %s", host.begin);
+                               r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "%s, ", host.begin);
+                               *(host.begin + host.len) = c;
+                       }
+                       else {
+                               c = *(host.begin + host.len);
+                               *(host.begin + host.len) = '\0';
+                               debug_task ("write url: %s", host.begin);
+                               r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "%s" CRLF, host.begin);
+                               *(host.begin + host.len) = c;
                        }
-                       r = 0;
-               }
-               /* Write url host to buf */
-               if (g_list_next (cur) != NULL) {
-                       c = *(host.begin + host.len);
-                       *(host.begin + host.len) = '\0';
-                       debug_task ("write url: %s", host.begin);
-                       r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "%s, ", host.begin);
-                       *(host.begin + host.len) = c;
-               }
-               else {
-                       c = *(host.begin + host.len);
-                       *(host.begin + host.len) = '\0';
-                       debug_task ("write url: %s", host.begin);
-                       r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "%s" CRLF, host.begin);
-                       *(host.begin + host.len) = c;
                }
                cur = g_list_next (cur);
        }