From: Vsevolod Stakhov Date: Mon, 5 Jul 2010 12:57:55 +0000 (+0400) Subject: * Fix stupid error with surbl module reconfig (another one, blame me) X-Git-Tag: 0.3.1~65 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bae637bec8e9c23668cbacbb9f5a1bd829cae487;p=rspamd.git * Fix stupid error with surbl module reconfig (another one, blame me) * Do not show duplicate urls in url header --- diff --git a/src/main.c b/src/main.c index e75b46899..da8b87e64 100644 --- a/src/main.c +++ b/src/main.c @@ -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); diff --git a/src/map.c b/src/map.c index b864c6a42..12b833ae0 100644 --- 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; +} + diff --git a/src/map.h b/src/map.h index c9093d68c..fe3a2b36b 100644 --- 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); diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index ee8622f12..8c9d2ccb0 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -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); } diff --git a/src/protocol.c b/src/protocol.c index 276b63a9e..98d68bf12 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -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); }