diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-02-24 18:51:13 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-02-24 18:51:13 +0300 |
commit | 121efbcddf8ec41eea91aa80574dab3730bf8976 (patch) | |
tree | 2d39b5895526d63c7994aa81575c2db15a46cee1 /src/worker.c | |
parent | 7eb9b642db888b26a97b06394695e55173c45895 (diff) | |
download | rspamd-121efbcddf8ec41eea91aa80574dab3730bf8976.tar.gz rspamd-121efbcddf8ec41eea91aa80574dab3730bf8976.zip |
* Rewrite URL storage system
Diffstat (limited to 'src/worker.c')
-rw-r--r-- | src/worker.c | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/src/worker.c b/src/worker.c index 1d6ec05fb..0ac952b79 100644 --- a/src/worker.c +++ b/src/worker.c @@ -261,12 +261,6 @@ free_task (struct worker_task *task, gboolean is_soft) if (task->text_parts) { g_list_free (task->text_parts); } - if (task->urls) { - g_list_free (task->urls); - } - if (task->emails) { - g_list_free (task->emails); - } if (task->images) { g_list_free (task->images); } @@ -460,6 +454,52 @@ err_socket (GError * err, void *arg) } } +/* Compare two emails for building emails tree */ +static gint +compare_email_func (gconstpointer a, gconstpointer b) +{ + const struct uri *u1 = a, *u2 = b; + gint r; + + if (u1->hostlen != u2->hostlen) { + return u1->hostlen - u2->hostlen; + } + else { + if ((r = g_ascii_strncasecmp (u1->host, u2->host, u1->hostlen)) == 0){ + if (u1->userlen != u2->userlen) { + return u1->userlen - u2->userlen; + } + else { + return g_ascii_strncasecmp (u1->user, u2->user, u1->userlen); + } + } + else { + return r; + } + } + + return 0; +} + +static gint +compare_url_func (gconstpointer a, gconstpointer b) +{ + const struct uri *u1 = a, *u2 = b; + int r; + + if (u1->hostlen != u2->hostlen) { + return u1->hostlen - u2->hostlen; + } + else { + r = g_ascii_strncasecmp (u1->host, u2->host, u1->hostlen); + } + + return r; +} + +/* + * Create new task + */ struct worker_task * construct_task (struct rspamd_worker *worker) { @@ -499,6 +539,14 @@ construct_task (struct rspamd_worker *worker) memory_pool_add_destructor (new_task->task_pool, (pool_destruct_func) g_hash_table_destroy, new_task->re_cache); + new_task->emails = g_tree_new (compare_email_func); + memory_pool_add_destructor (new_task->task_pool, + (pool_destruct_func) g_tree_destroy, + new_task->emails); + new_task->urls = g_tree_new (compare_url_func); + memory_pool_add_destructor (new_task->task_pool, + (pool_destruct_func) g_tree_destroy, + new_task->urls); new_task->s = new_async_session (new_task->task_pool, free_task_hard, new_task); new_task->sock = -1; |