static void rspamd_process_file (const gchar *fname) { struct rspamd_task *task; GIOChannel *f; GError *err = NULL; GString *buf; struct received_header rh; gdouble t1, t2; f = g_io_channel_new_file (fname, "r", &err); if (!f) { rspamd_fprintf (stderr, "cannot open %s: %e\n", fname, err); g_error_free (err); return; } g_io_channel_set_encoding (f, NULL, NULL); buf = g_string_sized_new (8192); task = g_malloc0 (sizeof (*task)); task->task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "test"); while (g_io_channel_read_line_string (f, buf, NULL, &err) == G_IO_STATUS_NORMAL) { while (buf->len > 0 && g_ascii_isspace (buf->str[buf->len - 1])) { buf->len --; } t1 = rspamd_get_virtual_ticks (); rspamd_smtp_recieved_parse (task, buf->str, buf->len, &rh); t2 = rspamd_get_virtual_ticks (); total_time += t2 - t1; total_parsed ++; if (rh.addr) { total_real_ip ++; } if (rh.real_hostname) { total_real_host ++; } if (rh.type != RSPAMD_RECEIVED_UNKNOWN) { total_known_proto ++; } if (rh.by_hostname || rh.timestamp > 0) { total_valid ++; } if (rh.timestamp != 0) { total_known_ts ++; } } if (err) { rspamd_fprintf (stderr, "cannot read %s: %e\n", fname, err); g_error_free (err); } g_io_channel_unref (f); g_string_free (buf, TRUE); rspamd_mempool_delete (task->task_pool); g_free (task); }
/* * 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; if (worker) { new_task->cfg = worker->srv->cfg; if (new_task->cfg->check_all_filters) { new_task->flags |= RSPAMD_TASK_FLAG_PASS_ALL; } } gettimeofday (&new_task->tv, NULL); new_task->time_real = rspamd_get_ticks (); new_task->time_virtual = rspamd_get_virtual_ticks (); new_task->task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "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_unref, 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_unref, new_task->re_cache); new_task->raw_headers = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); new_task->request_headers = g_hash_table_new_full (rspamd_gstring_icase_hash, rspamd_gstring_icase_equal, rspamd_gstring_free_hard, rspamd_gstring_free_hard); rspamd_mempool_add_destructor (new_task->task_pool, (rspamd_mempool_destruct_t) g_hash_table_unref, new_task->request_headers); new_task->reply_headers = g_hash_table_new_full (rspamd_gstring_icase_hash, rspamd_gstring_icase_equal, rspamd_gstring_free_hard, rspamd_gstring_free_hard); rspamd_mempool_add_destructor (new_task->task_pool, (rspamd_mempool_destruct_t) g_hash_table_unref, new_task->reply_headers); rspamd_mempool_add_destructor (new_task->task_pool, (rspamd_mempool_destruct_t) g_hash_table_unref, new_task->raw_headers); new_task->emails = g_hash_table_new (rspamd_url_hash, rspamd_emails_cmp); rspamd_mempool_add_destructor (new_task->task_pool, (rspamd_mempool_destruct_t) g_hash_table_unref, new_task->emails); new_task->urls = g_hash_table_new (rspamd_url_hash, rspamd_urls_cmp); 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; new_task->message_id = new_task->queue_id = "undef"; return new_task; }