From ad5bf825b7f33bc10311673991f0cc888e69c0b1 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 21 Apr 2014 15:57:39 +0100 Subject: [PATCH] Refactor task functions. --- src/controller.c | 22 +++--- src/events.h | 1 + src/lmtp.c | 2 +- src/lua/lua_task.c | 6 +- src/main.h | 22 ------ src/plugins/fuzzy_check.c | 8 +-- src/smtp.c | 2 +- src/smtp_utils.c | 2 +- src/task.c | 136 ++++++++++++++++++++++++++++++++++++++ src/task.h | 22 ++++++ src/webui.c | 26 ++++---- src/worker.c | 6 +- src/worker_util.c | 136 +------------------------------------- 13 files changed, 198 insertions(+), 193 deletions(-) diff --git a/src/controller.c b/src/controller.c index f8b49d236..0c2a8b25f 100644 --- a/src/controller.c +++ b/src/controller.c @@ -1394,7 +1394,7 @@ controller_read_socket (f_str_t * in, void *arg) break; case STATE_LEARN: session->learn_buf = in; - task = construct_task (session->worker); + task = rspamd_task_new (session->worker); task->msg = g_string_new_len (in->begin, in->len); task->ev_base = session->ev_base; @@ -1402,7 +1402,7 @@ controller_read_socket (f_str_t * in, void *arg) r = process_message (task); if (r == -1) { msg_warn ("processing of message failed"); - free_task (task, FALSE); + rspamd_task_free (task, FALSE); session->state = STATE_REPLY; if (session->restful) { r = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 500 Cannot process message" CRLF CRLF); @@ -1417,7 +1417,7 @@ controller_read_socket (f_str_t * in, void *arg) } if (!learn_task (session->learn_symbol, task, &err)) { - free_task (task, FALSE); + rspamd_task_free (task, FALSE); if (err) { if (session->restful) { i = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 500 Learn classifier error: %s" CRLF CRLF, err->message); @@ -1443,7 +1443,7 @@ controller_read_socket (f_str_t * in, void *arg) return TRUE; } - free_task (task, FALSE); + rspamd_task_free (task, FALSE); if (session->restful) { i = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 200 Learn OK" CRLF CRLF); } @@ -1457,7 +1457,7 @@ controller_read_socket (f_str_t * in, void *arg) break; case STATE_LEARN_SPAM_PRE: session->learn_buf = in; - task = construct_task (session->worker); + task = rspamd_task_new (session->worker); task->msg = g_string_new_len (in->begin, in->len); @@ -1487,7 +1487,7 @@ controller_read_socket (f_str_t * in, void *arg) return FALSE; } /* Set up async session */ - task->s = new_async_session (task->task_pool, fin_learn_task, restore_learn_task, free_task_hard, task); + task->s = new_async_session (task->task_pool, fin_learn_task, restore_learn_task, rspamd_task_free_hard, task); session->learn_task = task; session->state = STATE_LEARN_SPAM; rspamd_dispatcher_pause (session->dispatcher); @@ -1516,7 +1516,7 @@ controller_read_socket (f_str_t * in, void *arg) break; case STATE_WEIGHTS: session->learn_buf = in; - task = construct_task (session->worker); + task = rspamd_task_new (session->worker); task->msg = g_string_new_len (in->begin, in->len); task->ev_base = session->ev_base; @@ -1524,7 +1524,7 @@ controller_read_socket (f_str_t * in, void *arg) r = process_message (task); if (r == -1) { msg_warn ("processing of message failed"); - free_task (task, FALSE); + rspamd_task_free (task, FALSE); session->state = STATE_REPLY; r = rspamd_snprintf (out_buf, sizeof (out_buf), "cannot process message" CRLF END); if (!session->restful) { @@ -1553,7 +1553,7 @@ controller_read_socket (f_str_t * in, void *arg) if (!session->learn_classifier->tokenizer->tokenize_func (session->learn_classifier->tokenizer, session->session_pool, &c, &tokens, FALSE, part->is_utf, part->urls_offset)) { i = rspamd_snprintf (out_buf, sizeof (out_buf), "weights failed, tokenizer error" CRLF END); - free_task (task, FALSE); + rspamd_task_free (task, FALSE); if (!session->restful) { if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) { return FALSE; @@ -1573,7 +1573,7 @@ controller_read_socket (f_str_t * in, void *arg) /* Handle messages without text */ if (tokens == NULL) { i = rspamd_snprintf (out_buf, sizeof (out_buf), "weights failed, no tokens can be extracted (no text data)" CRLF END); - free_task (task, FALSE); + rspamd_task_free (task, FALSE); if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) { return FALSE; } @@ -1607,7 +1607,7 @@ controller_read_socket (f_str_t * in, void *arg) } } - free_task (task, FALSE); + rspamd_task_free (task, FALSE); session->state = STATE_REPLY; break; diff --git a/src/events.h b/src/events.h index 072a243da..6728288eb 100644 --- a/src/events.h +++ b/src/events.h @@ -2,6 +2,7 @@ #define RSPAMD_EVENTS_H #include "config.h" +#include "mem_pool.h" struct rspamd_async_event; diff --git a/src/lmtp.c b/src/lmtp.c index c79c46376..946f8ca8b 100644 --- a/src/lmtp.c +++ b/src/lmtp.c @@ -255,7 +255,7 @@ accept_socket (gint fd, short what, void *arg) lmtp = g_malloc (sizeof (struct rspamd_lmtp_proto)); - new_task = construct_task (worker); + new_task = rspamd_task_new (worker); if (su.ss.ss_family == AF_UNIX) { msg_info ("accepted connection from unix socket"); diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 4ef56b3d4..3d58e6a65 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -267,7 +267,7 @@ lua_task_create_empty (lua_State *L) { struct rspamd_task **ptask, *task; - task = construct_task (NULL); + task = rspamd_task_new (NULL); ptask = lua_newuserdata (L, sizeof (gpointer)); lua_setclass (L, "rspamd{task}", -1); *ptask = task; @@ -283,7 +283,7 @@ lua_task_create_from_buffer (lua_State *L) data = luaL_checklstring (L, 1, &len); if (data) { - task = construct_task (NULL); + task = rspamd_task_new (NULL); ptask = lua_newuserdata (L, sizeof (gpointer)); lua_setclass (L, "rspamd{task}", -1); *ptask = task; @@ -328,7 +328,7 @@ lua_task_destroy (lua_State *L) struct rspamd_task *task = lua_check_task (L); if (task != NULL) { - free_task (task, FALSE); + rspamd_task_free (task, FALSE); } return 0; diff --git a/src/main.h b/src/main.h index 3ec26434c..17d693cae 100644 --- a/src/main.h +++ b/src/main.h @@ -197,28 +197,6 @@ extern struct rspamd_main *rspamd_main; /* Worker task manipulations */ -/** - * Construct new task for worker - */ -struct rspamd_task* construct_task (struct rspamd_worker *worker); -/** - * Destroy task object and remove its IO dispatcher if it exists - */ -void free_task (struct rspamd_task *task, gboolean is_soft); -void free_task_hard (gpointer ud); -void free_task_soft (gpointer ud); - -/** - * Called if session was restored inside fin callback - */ -void rspamd_restore_task (void *arg); - -/** - * Called if all filters are processed - * @return TRUE if session should be terminated - */ -gboolean rspamd_fin_task (void *arg); - /** * Set counter for a symbol */ diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index a6c1ed0f2..4f7a4c3d7 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -982,7 +982,7 @@ fuzzy_process_rule (struct controller_session *session, struct fuzzy_rule *rule, return processed; err: - free_task (task, FALSE); + rspamd_task_free (task, FALSE); return -1; } @@ -1006,7 +1006,7 @@ fuzzy_process_handler (struct controller_session *session, f_str_t * in) } /* Prepare task */ - task = construct_task (session->worker); + task = rspamd_task_new (session->worker); session->other_data = task; session->state = STATE_WAIT; @@ -1018,7 +1018,7 @@ fuzzy_process_handler (struct controller_session *session, f_str_t * in) r = process_message (task); if (r == -1) { msg_warn ("processing of message failed"); - free_task (task, FALSE); + rspamd_task_free (task, FALSE); session->state = STATE_REPLY; if (session->restful) { r = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 500 Cannot process message" CRLF CRLF); @@ -1059,7 +1059,7 @@ fuzzy_process_handler (struct controller_session *session, f_str_t * in) cur = g_list_next (cur); } - rspamd_mempool_add_destructor (session->session_pool, (rspamd_mempool_destruct_t)free_task_soft, task); + rspamd_mempool_add_destructor (session->session_pool, (rspamd_mempool_destruct_t)rspamd_task_free_soft, task); if (res == -1) { session->state = STATE_REPLY; diff --git a/src/smtp.c b/src/smtp.c index 32e9826b0..2d36c0549 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -306,7 +306,7 @@ process_smtp_data (struct smtp_session *session) /* Now mmap temp file if it is small enough */ session->temp_size = st.st_size; if (session->ctx->max_size == 0 || st.st_size < (off_t)session->ctx->max_size) { - session->task = construct_task (session->worker); + session->task = rspamd_task_new (session->worker); session->task->resolver = session->resolver; session->task->fin_callback = smtp_write_socket; session->task->fin_arg = session; diff --git a/src/smtp_utils.c b/src/smtp_utils.c index 15551aa41..5178de9dd 100644 --- a/src/smtp_utils.c +++ b/src/smtp_utils.c @@ -35,7 +35,7 @@ free_smtp_session (gpointer arg) if (session) { if (session->task) { - free_task (session->task, FALSE); + rspamd_task_free (session->task, FALSE); if (session->task->msg->str) { munmap (session->task->msg->str, session->task->msg->len); } diff --git a/src/task.c b/src/task.c index 126ddcd1b..f389793dd 100644 --- a/src/task.c +++ b/src/task.c @@ -21,3 +21,139 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "task.h" +#include "main.h" +#include "filter.h" +#include "message.h" + +/* + * Destructor for recipients list in a task + */ +static void +rcpt_destruct (void *pointer) +{ + struct rspamd_task *task = (struct rspamd_task *) pointer; + + if (task->rcpt) { + g_list_free (task->rcpt); + } +} + +/* + * Create new task + */ +struct rspamd_task * +rspamd_task_new (struct rspamd_worker *worker) +{ + struct rspamd_task *new_task; + + new_task = g_slice_alloc0 (sizeof (struct rspamd_task)); + + new_task->worker = worker; + new_task->state = READ_MESSAGE; + if (worker) { + new_task->cfg = worker->srv->cfg; + } +#ifdef HAVE_CLOCK_GETTIME +# ifdef HAVE_CLOCK_PROCESS_CPUTIME_ID + clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &new_task->ts); +# elif defined(HAVE_CLOCK_VIRTUAL) + clock_gettime (CLOCK_VIRTUAL, &new_task->ts); +# else + clock_gettime (CLOCK_REALTIME, &new_task->ts); +# endif +#endif + if (gettimeofday (&new_task->tv, NULL) == -1) { + msg_warn ("gettimeofday failed: %s", strerror (errno)); + } + + new_task->task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); + + /* Add destructor for recipients list (it would be better to use anonymous function here */ + rspamd_mempool_add_destructor (new_task->task_pool, + (rspamd_mempool_destruct_t) rcpt_destruct, new_task); + new_task->results = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); + rspamd_mempool_add_destructor (new_task->task_pool, + (rspamd_mempool_destruct_t) g_hash_table_destroy, + new_task->results); + new_task->re_cache = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); + rspamd_mempool_add_destructor (new_task->task_pool, + (rspamd_mempool_destruct_t) g_hash_table_destroy, + new_task->re_cache); + new_task->raw_headers = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); + rspamd_mempool_add_destructor (new_task->task_pool, + (rspamd_mempool_destruct_t) g_hash_table_destroy, + new_task->raw_headers); + new_task->emails = g_tree_new (compare_email_func); + rspamd_mempool_add_destructor (new_task->task_pool, + (rspamd_mempool_destruct_t) g_tree_destroy, + new_task->emails); + new_task->urls = g_tree_new (compare_url_func); + rspamd_mempool_add_destructor (new_task->task_pool, + (rspamd_mempool_destruct_t) g_tree_destroy, + new_task->urls); + new_task->sock = -1; + new_task->is_mime = TRUE; + new_task->pre_result.action = METRIC_ACTION_NOACTION; + + new_task->message_id = new_task->queue_id = "undef"; + + return new_task; +} + + +/* + * Free all structures of worker_task + */ +void +rspamd_task_free (struct rspamd_task *task, gboolean is_soft) +{ + GList *part; + struct mime_part *p; + + if (task) { + debug_task ("free pointer %p", task); + while ((part = g_list_first (task->parts))) { + task->parts = g_list_remove_link (task->parts, part); + p = (struct mime_part *) part->data; + g_byte_array_free (p->content, TRUE); + g_list_free_1 (part); + } + if (task->text_parts) { + g_list_free (task->text_parts); + } + if (task->images) { + g_list_free (task->images); + } + if (task->messages) { + g_list_free (task->messages); + } + if (task->received) { + g_list_free (task->received); + } + if (task->http_conn != NULL) { + rspamd_http_connection_unref (task->http_conn); + } + if (task->sock != -1) { + close (task->sock); + } + rspamd_mempool_delete (task->task_pool); + g_slice_free1 (sizeof (struct rspamd_task), task); + } +} + +void +rspamd_task_free_hard (gpointer ud) +{ + struct rspamd_task *task = ud; + + rspamd_task_free (task, FALSE); +} + +void +rspamd_task_free_soft (gpointer ud) +{ + struct rspamd_task *task = ud; + + rspamd_task_free (task, FALSE); +} diff --git a/src/task.h b/src/task.h index 2a543f5e7..f8f7c89e3 100644 --- a/src/task.h +++ b/src/task.h @@ -140,4 +140,26 @@ struct rspamd_task { } pre_result; /**< Result of pre-filters */ }; +/** + * Construct new task for worker + */ +struct rspamd_task* rspamd_task_new (struct rspamd_worker *worker); +/** + * Destroy task object and remove its IO dispatcher if it exists + */ +void rspamd_task_free (struct rspamd_task *task, gboolean is_soft); +void rspamd_task_free_hard (gpointer ud); +void rspamd_task_free_soft (gpointer ud); + +/** + * Called if session was restored inside fin callback + */ +void rspamd_task_restore (void *arg); + +/** + * Called if all filters are processed + * @return TRUE if session should be terminated + */ +gboolean rspamd_task_fin (void *arg); + #endif /* TASK_H_ */ diff --git a/src/webui.c b/src/webui.c index 6c438135f..7f6fe7868 100644 --- a/src/webui.c +++ b/src/webui.c @@ -336,7 +336,7 @@ rspamd_webui_scan_task_free (gpointer arg) if (!evb) { msg_err ("cannot allocate evbuffer for reply"); evhttp_send_reply (cbdata->req, HTTP_INTERNAL, "500 insufficient memory", NULL); - free_task_hard (cbdata->task); + rspamd_task_free_hard (cbdata->task); return; } cbdata->out = evb; @@ -367,7 +367,7 @@ rspamd_webui_scan_task_free (gpointer arg) evhttp_send_reply (cbdata->req, HTTP_OK, "OK", evb); evbuffer_free (evb); - free_task_hard (cbdata->task); + rspamd_task_free_hard (cbdata->task); } /* If task is not processed, just do nothing */ return; @@ -444,7 +444,7 @@ rspamd_webui_prepare_scan (struct evhttp_request *req, struct rspamd_webui_worke } /* Prepare task */ - task = construct_task (ctx->worker); + task = rspamd_task_new (ctx->worker); if (task == NULL) { g_set_error (err, g_quark_from_static_string ("webui"), 500, "task cannot be created"); return NULL; @@ -464,7 +464,7 @@ rspamd_webui_prepare_scan (struct evhttp_request *req, struct rspamd_webui_worke if (process_message (task) == -1) { msg_warn ("processing of message failed"); g_set_error (err, g_quark_from_static_string ("webui"), 500, "message cannot be processed"); - free_task_hard (task); + rspamd_task_free_hard (task); return NULL; } @@ -473,7 +473,7 @@ rspamd_webui_prepare_scan (struct evhttp_request *req, struct rspamd_webui_worke if (process_filters (task) == -1) { msg_warn ("filtering of message failed"); g_set_error (err, g_quark_from_static_string ("webui"), 500, "message cannot be filtered"); - free_task_hard (task); + rspamd_task_free_hard (task); return NULL; } @@ -506,7 +506,7 @@ rspamd_webui_learn_task_free (gpointer arg) if (!evb) { msg_err ("cannot allocate evbuffer for reply"); evhttp_send_reply (cbdata->req, HTTP_INTERNAL, "500 insufficient memory", NULL); - free_task_hard (cbdata->task); + rspamd_task_free_hard (cbdata->task); return; } @@ -518,7 +518,7 @@ rspamd_webui_learn_task_free (gpointer arg) evhttp_send_reply (cbdata->req, HTTP_INTERNAL + err->code, err->message, evb); evbuffer_free (evb); g_error_free (err); - free_task_hard (cbdata->task); + rspamd_task_free_hard (cbdata->task); return; } /* Successful learn */ @@ -528,7 +528,7 @@ rspamd_webui_learn_task_free (gpointer arg) evhttp_send_reply (cbdata->req, HTTP_OK, "OK", evb); evbuffer_free (evb); - free_task_hard (cbdata->task); + rspamd_task_free_hard (cbdata->task); } /* If task is not processed, just do nothing */ return; @@ -609,7 +609,7 @@ rspamd_webui_prepare_learn (struct evhttp_request *req, struct rspamd_webui_work return NULL; } /* Prepare task */ - task = construct_task (ctx->worker); + task = rspamd_task_new (ctx->worker); if (task == NULL) { g_set_error (err, g_quark_from_static_string ("webui"), 500, "task cannot be created"); return NULL; @@ -631,7 +631,7 @@ rspamd_webui_prepare_learn (struct evhttp_request *req, struct rspamd_webui_work if (process_message (task) == -1) { msg_warn ("processing of message failed"); g_set_error (err, g_quark_from_static_string ("webui"), 500, "message cannot be processed"); - free_task_hard (task); + rspamd_task_free_hard (task); return NULL; } @@ -640,7 +640,7 @@ rspamd_webui_prepare_learn (struct evhttp_request *req, struct rspamd_webui_work if (process_filters (task) == -1) { msg_warn ("filtering of message failed"); g_set_error (err, g_quark_from_static_string ("webui"), 500, "message cannot be filtered"); - free_task_hard (task); + rspamd_task_free_hard (task); return NULL; } @@ -1271,7 +1271,7 @@ rspamd_webui_handle_learn_common (struct rspamd_http_connection_entry *conn_ent, return 0; } - task = construct_task (session->ctx->worker); + task = rspamd_task_new (session->ctx->worker); task->ev_base = session->ctx->ev_base; task->msg = msg->body; @@ -1279,7 +1279,7 @@ rspamd_webui_handle_learn_common (struct rspamd_http_connection_entry *conn_ent, task->ev_base = ctx->ev_base; task->s = new_async_session (session->pool, rspamd_webui_learn_fin_task, NULL, - free_task_hard, task); + rspamd_task_free_hard, task); task->s->wanna_die = TRUE; task->fin_arg = conn_ent; diff --git a/src/worker.c b/src/worker.c index 8efb5a19e..94ec74451 100644 --- a/src/worker.c +++ b/src/worker.c @@ -320,7 +320,7 @@ accept_socket (gint fd, short what, void *arg) return; } - new_task = construct_task (worker); + new_task = rspamd_task_new (worker); msg_info ("accepted connection from %s port %d", rspamd_inet_address_to_string (&addr), @@ -342,8 +342,8 @@ accept_socket (gint fd, short what, void *arg) rspamd_mempool_add_destructor (new_task->task_pool, (rspamd_mempool_destruct_t)reduce_tasks_count, &ctx->tasks); /* Set up async session */ - new_task->s = new_async_session (new_task->task_pool, rspamd_fin_task, - rspamd_restore_task, free_task_hard, new_task); + new_task->s = new_async_session (new_task->task_pool, rspamd_task_fin, + rspamd_task_restore, rspamd_task_free_hard, new_task); new_task->classify_pool = ctx->classify_pool; diff --git a/src/worker_util.c b/src/worker_util.c index ee51e77b6..d029f5dc4 100644 --- a/src/worker_util.c +++ b/src/worker_util.c @@ -28,81 +28,6 @@ extern struct rspamd_main *rspamd_main; -/* - * Destructor for recipients list in a task - */ -static void -rcpt_destruct (void *pointer) -{ - struct rspamd_task *task = (struct rspamd_task *) pointer; - - if (task->rcpt) { - g_list_free (task->rcpt); - } -} - -/* - * Create new task - */ -struct rspamd_task * -construct_task (struct rspamd_worker *worker) -{ - struct rspamd_task *new_task; - - new_task = g_slice_alloc0 (sizeof (struct rspamd_task)); - - new_task->worker = worker; - new_task->state = READ_MESSAGE; - if (worker) { - new_task->cfg = worker->srv->cfg; - } -#ifdef HAVE_CLOCK_GETTIME -# ifdef HAVE_CLOCK_PROCESS_CPUTIME_ID - clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &new_task->ts); -# elif defined(HAVE_CLOCK_VIRTUAL) - clock_gettime (CLOCK_VIRTUAL, &new_task->ts); -# else - clock_gettime (CLOCK_REALTIME, &new_task->ts); -# endif -#endif - if (gettimeofday (&new_task->tv, NULL) == -1) { - msg_warn ("gettimeofday failed: %s", strerror (errno)); - } - - new_task->task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); - - /* Add destructor for recipients list (it would be better to use anonymous function here */ - rspamd_mempool_add_destructor (new_task->task_pool, - (rspamd_mempool_destruct_t) rcpt_destruct, new_task); - new_task->results = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); - rspamd_mempool_add_destructor (new_task->task_pool, - (rspamd_mempool_destruct_t) g_hash_table_destroy, - new_task->results); - new_task->re_cache = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); - rspamd_mempool_add_destructor (new_task->task_pool, - (rspamd_mempool_destruct_t) g_hash_table_destroy, - new_task->re_cache); - new_task->raw_headers = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); - rspamd_mempool_add_destructor (new_task->task_pool, - (rspamd_mempool_destruct_t) g_hash_table_destroy, - new_task->raw_headers); - new_task->emails = g_tree_new (compare_email_func); - rspamd_mempool_add_destructor (new_task->task_pool, - (rspamd_mempool_destruct_t) g_tree_destroy, - new_task->emails); - new_task->urls = g_tree_new (compare_url_func); - rspamd_mempool_add_destructor (new_task->task_pool, - (rspamd_mempool_destruct_t) g_tree_destroy, - new_task->urls); - new_task->sock = -1; - new_task->is_mime = TRUE; - new_task->pre_result.action = METRIC_ACTION_NOACTION; - - new_task->message_id = new_task->queue_id = "undef"; - - return new_task; -} - /** * Return worker's control structure by its type * @param type @@ -124,63 +49,6 @@ get_worker_by_type (GQuark type) return NULL; } - -/* - * Free all structures of worker_task - */ -void -free_task (struct rspamd_task *task, gboolean is_soft) -{ - GList *part; - struct mime_part *p; - - if (task) { - debug_task ("free pointer %p", task); - while ((part = g_list_first (task->parts))) { - task->parts = g_list_remove_link (task->parts, part); - p = (struct mime_part *) part->data; - g_byte_array_free (p->content, TRUE); - g_list_free_1 (part); - } - if (task->text_parts) { - g_list_free (task->text_parts); - } - if (task->images) { - g_list_free (task->images); - } - if (task->messages) { - g_list_free (task->messages); - } - if (task->received) { - g_list_free (task->received); - } - if (task->http_conn != NULL) { - rspamd_http_connection_unref (task->http_conn); - } - if (task->sock != -1) { - close (task->sock); - } - rspamd_mempool_delete (task->task_pool); - g_slice_free1 (sizeof (struct rspamd_task), task); - } -} - -void -free_task_hard (gpointer ud) -{ - struct rspamd_task *task = ud; - - free_task (task, FALSE); -} - -void -free_task_soft (gpointer ud) -{ - struct rspamd_task *task = ud; - - free_task (task, FALSE); -} - double set_counter (const gchar *name, guint32 value) { @@ -278,7 +146,7 @@ worker_stop_accept (struct rspamd_worker *worker) * @return TRUE if session should be terminated */ gboolean -rspamd_fin_task (void *arg) +rspamd_task_fin (void *arg) { struct rspamd_task *task = (struct rspamd_task *) arg; gint r; @@ -375,7 +243,7 @@ rspamd_fin_task (void *arg) * Called if session was restored inside fin callback */ void -rspamd_restore_task (void *arg) +rspamd_task_restore (void *arg) { struct rspamd_task *task = (struct rspamd_task *) arg; -- 2.39.5