summaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-13 17:46:50 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-13 17:46:50 +0100
commitd2a938d398d31fae55e709a4e219b5acfa5c7622 (patch)
tree616ee4dacde622e13ee26f4437febf9e5eae4661 /src/libserver
parent444c70ff896dcd07f1569e394b528cf1f61dec54 (diff)
downloadrspamd-d2a938d398d31fae55e709a4e219b5acfa5c7622.tar.gz
rspamd-d2a938d398d31fae55e709a4e219b5acfa5c7622.zip
Rework parts and task structure:
- Now text_parts, parts and received are arrays - Pre-allocate arrays with some reasonable defaults - Use arrays instead of lists in plugins and checks - Remove unused fields from task structure - Rework mime_foreach callback function - Remove deprecated scan_milliseconds field
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/protocol.c15
-rw-r--r--src/libserver/roll_history.c2
-rw-r--r--src/libserver/task.c51
-rw-r--r--src/libserver/task.h108
4 files changed, 88 insertions, 88 deletions
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index 761b04a30..a4d78427f 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -642,15 +642,14 @@ rspamd_protocol_handle_request (struct rspamd_task *task,
static void
write_hashes_to_log (struct rspamd_task *task, GString *logbuf)
{
- GList *cur;
struct mime_text_part *text_part;
+ guint i;
- cur = task->text_parts;
+ for (i = 0; i < task->text_parts->len; i ++) {
+ text_part = g_ptr_array_index (task->text_parts, i);
- while (cur) {
- text_part = cur->data;
if (text_part->fuzzy) {
- if (cur->next != NULL) {
+ if (i != task->text_parts->len - 1) {
rspamd_printf_gstring (logbuf,
" part: %Xd,",
text_part->fuzzy->h);
@@ -660,7 +659,6 @@ write_hashes_to_log (struct rspamd_task *task, GString *logbuf)
text_part->fuzzy->h);
}
}
- cur = g_list_next (cur);
}
}
@@ -923,10 +921,9 @@ rspamd_metric_result_ucl (struct rspamd_task *task,
rspamd_printf_gstring (logbuf, "]), len: %z, time: %s, dns req: %d,",
task->msg.len,
- calculate_check_time (task->time_real,
+ rspamd_log_check_time (task->time_real,
task->time_virtual,
- task->cfg->clock_res,
- &task->scan_milliseconds),
+ task->cfg->clock_res),
task->dns_requests);
}
diff --git a/src/libserver/roll_history.c b/src/libserver/roll_history.c
index c494ce74c..9effcfc3a 100644
--- a/src/libserver/roll_history.c
+++ b/src/libserver/roll_history.c
@@ -154,7 +154,7 @@ rspamd_roll_history_update (struct roll_history *history,
}
}
- row->scan_time = task->scan_milliseconds;
+ row->scan_time = rspamd_get_ticks () - task->time_real;
row->len = task->msg.len;
row->completed = TRUE;
}
diff --git a/src/libserver/task.c b/src/libserver/task.c
index 236f2918b..8dd682a1e 100644
--- a/src/libserver/task.c
+++ b/src/libserver/task.c
@@ -94,6 +94,16 @@ rspamd_task_new (struct rspamd_worker *worker)
rspamd_mempool_add_destructor (new_task->task_pool,
(rspamd_mempool_destruct_t) g_hash_table_unref,
new_task->urls);
+ new_task->parts = g_ptr_array_sized_new (4);
+ rspamd_mempool_add_destructor (new_task->task_pool,
+ rspamd_ptr_array_free_hard, new_task->parts);
+ new_task->text_parts = g_ptr_array_sized_new (2);
+ rspamd_mempool_add_destructor (new_task->task_pool,
+ rspamd_ptr_array_free_hard, new_task->text_parts);
+ new_task->received = g_ptr_array_sized_new (8);
+ rspamd_mempool_add_destructor (new_task->task_pool,
+ rspamd_ptr_array_free_hard, new_task->received);
+
new_task->sock = -1;
new_task->flags |= (RSPAMD_TASK_FLAG_MIME|RSPAMD_TASK_FLAG_JSON);
new_task->pre_result.action = METRIC_ACTION_NOACTION;
@@ -159,57 +169,56 @@ rspamd_task_restore (void *arg)
void
rspamd_task_free (struct rspamd_task *task, gboolean is_soft)
{
- GList *part;
struct mime_part *p;
struct mime_text_part *tp;
+ guint i;
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;
+
+ for (i = 0; i < task->parts->len; i ++) {
+ p = g_ptr_array_index (task->parts, i);
g_byte_array_free (p->content, TRUE);
- g_list_free_1 (part);
}
- if (task->text_parts) {
- part = task->text_parts;
- while (part) {
- tp = (struct mime_text_part *)part->data;
- if (tp->words) {
- g_array_free (tp->words, TRUE);
- }
- if (tp->normalized_words) {
- g_array_free (tp->normalized_words, TRUE);
- }
- part = g_list_next (part);
- }
- g_list_free (task->text_parts);
+ for (i = 0; i < task->text_parts->len; i ++) {
+ tp = g_ptr_array_index (task->text_parts, i);
+ if (tp->words) {
+ g_array_free (tp->words, TRUE);
+ }
+ if (tp->normalized_words) {
+ g_array_free (tp->normalized_words, TRUE);
+ }
}
+
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);
}
+
if (task->settings != NULL) {
ucl_object_unref (task->settings);
}
+
if (task->client_addr) {
rspamd_inet_address_destroy (task->client_addr);
}
+
if (task->from_addr) {
rspamd_inet_address_destroy (task->from_addr);
}
+
if (task->err) {
g_error_free (task->err);
}
diff --git a/src/libserver/task.h b/src/libserver/task.h
index 79aa19fb5..e6894bea9 100644
--- a/src/libserver/task.h
+++ b/src/libserver/task.h
@@ -107,78 +107,72 @@ struct custom_command {
* Worker task structure
*/
struct rspamd_task {
- struct rspamd_worker *worker; /**< pointer to worker object */
- struct custom_command *custom_cmd; /**< custom command if any */
- guint processed_stages; /**< bits of stages that are processed */
- enum rspamd_command cmd; /**< command */
- gint sock; /**< socket descriptor */
- guint flags; /**< Bit flags */
- guint message_len; /**< Message length */
-
- gchar *helo; /**< helo header value */
- gchar *queue_id; /**< queue id if specified */
- const gchar *message_id; /**< message id */
-
- rspamd_inet_addr_t *from_addr; /**< from addr for a task */
- rspamd_inet_addr_t *client_addr; /**< address of connected socket */
- gchar *deliver_to; /**< address to deliver */
- gchar *user; /**< user to deliver */
- gchar *subject; /**< subject (for non-mime) */
- gchar *hostname; /**< hostname reported by MTA */
- GHashTable *request_headers; /**< HTTP headers in a request */
- GHashTable *reply_headers; /**< Custom reply headers */
+ struct rspamd_worker *worker; /**< pointer to worker object */
+ struct custom_command *custom_cmd; /**< custom command if any */
+ guint processed_stages; /**< bits of stages that are processed */
+ enum rspamd_command cmd; /**< command */
+ gint sock; /**< socket descriptor */
+ guint flags; /**< Bit flags */
+ guint message_len; /**< Message length */
+ guint32 dns_requests; /**< number of DNS requests per this task */
+ gchar *helo; /**< helo header value */
+ gchar *queue_id; /**< queue id if specified */
+ const gchar *message_id; /**< message id */
+ rspamd_inet_addr_t *from_addr; /**< from addr for a task */
+ rspamd_inet_addr_t *client_addr; /**< address of connected socket */
+ gchar *deliver_to; /**< address to deliver */
+ gchar *user; /**< user to deliver */
+ gchar *subject; /**< subject (for non-mime) */
+ gchar *hostname; /**< hostname reported by MTA */
+ GHashTable *request_headers; /**< HTTP headers in a request */
+ GHashTable *reply_headers; /**< Custom reply headers */
struct {
const gchar *start;
gsize len;
- } msg; /**< message buffer */
- struct rspamd_http_connection *http_conn; /**< HTTP server connection */
- struct rspamd_async_session * s; /**< async session object */
- gint parts_count; /**< mime parts count */
- GMimeMessage *message; /**< message, parsed with GMime */
- GMimeObject *parser_parent_part; /**< current parent part */
- GList *parts; /**< list of parsed parts */
- GList *text_parts; /**< list of text parts */
- rspamd_fstring_t raw_headers_content; /**< list of raw headers */
- GList *received; /**< list of received headers */
- GHashTable *urls; /**< list of parsed urls */
- GHashTable *emails; /**< list of parsed emails */
- GList *images; /**< list of images */
- GHashTable *raw_headers; /**< list of raw headers */
- GHashTable *results; /**< hash table of metric_result indexed by
- * metric's name */
- GHashTable *tokens; /**< hash table of tokens indexed by tokenizer
- * pointer */
-
- InternetAddressList *rcpt_mime; /**< list of all recipients */
- InternetAddressList *rcpt_envelope; /**< list of all recipients */
+ } msg; /**< message buffer */
+ struct rspamd_http_connection *http_conn; /**< HTTP server connection */
+ struct rspamd_async_session * s; /**< async session object */
+ GMimeMessage *message; /**< message, parsed with GMime */
+ GPtrArray *parts; /**< list of parsed parts */
+ GPtrArray *text_parts; /**< list of text parts */
+ rspamd_fstring_t raw_headers_content; /**< list of raw headers */
+ GPtrArray *received; /**< list of received headers */
+ GHashTable *urls; /**< list of parsed urls */
+ GHashTable *emails; /**< list of parsed emails */
+ GList *images; /**< list of images */
+ GHashTable *raw_headers; /**< list of raw headers */
+ GHashTable *results; /**< hash table of metric_result indexed by
+ * metric's name */
+ GHashTable *tokens; /**< hash table of tokens indexed by tokenizer
+ * pointer */
+ InternetAddressList *rcpt_mime; /**< list of all recipients */
+ InternetAddressList *rcpt_envelope; /**< list of all recipients */
InternetAddressList *from_mime;
InternetAddressList *from_envelope;
- GList *messages; /**< list of messages that would be reported */
- GHashTable *re_cache; /**< cache for matched or not matched regexps */
- struct rspamd_config *cfg; /**< pointer to config object */
+ GList *messages; /**< list of messages that would be reported */
+ GHashTable *re_cache; /**< cache for matched or not matched regexps */
+ struct rspamd_config *cfg; /**< pointer to config object */
GError *err;
- rspamd_mempool_t *task_pool; /**< memory pool for task */
+ rspamd_mempool_t *task_pool; /**< memory pool for task */
double time_real;
double time_virtual;
struct timeval tv;
- guint32 scan_milliseconds; /**< how much milliseconds passed */
- gboolean (*fin_callback)(struct rspamd_task *task, void *arg); /**< calback for filters finalizing */
- void *fin_arg; /**< argument for fin callback */
-
- guint32 dns_requests; /**< number of DNS requests per this task */
+ gboolean (*fin_callback)(struct rspamd_task *task, void *arg);
+ /**< calback for filters finalizing */
+ void *fin_arg; /**< argument for fin callback */
- struct rspamd_dns_resolver *resolver; /**< DNS resolver */
- struct event_base *ev_base; /**< Event base */
+ struct rspamd_dns_resolver *resolver; /**< DNS resolver */
+ struct event_base *ev_base; /**< Event base */
- gpointer checkpoint; /**< Opaque checkpoint data */
+ gpointer checkpoint; /**< Opaque checkpoint data */
struct {
- enum rspamd_metric_action action; /**< Action of pre filters */
- gchar *str; /**< String describing action */
- } pre_result; /**< Result of pre-filters */
+ enum rspamd_metric_action action; /**< Action of pre filters */
+ gchar *str; /**< String describing action */
+ } pre_result; /**< Result of pre-filters */
- ucl_object_t *settings; /**< Settings applied to task */
+ ucl_object_t *settings; /**< Settings applied to task */
};
/**