]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Fix task functions to work without rspamd_config
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 9 May 2016 12:35:37 +0000 (13:35 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 9 May 2016 12:35:37 +0000 (13:35 +0100)
src/libmime/message.c
src/libserver/cfg_utils.c
src/libserver/task.c
src/libserver/url.c

index 9c27bf5f5a58d3040877ae6f5638086d1ebd6204..6c4004f6183d34f418e88df462d632fdbfaaef41 100644 (file)
@@ -770,7 +770,7 @@ convert_text_to_utf (struct rspamd_task *task,
        gchar *res_str, *ocharset;
        GByteArray *result_array;
 
-       if (task->cfg->raw_mode) {
+       if (task->cfg && task->cfg->raw_mode) {
                SET_PART_RAW (text_part);
                return part_content;
        }
@@ -1177,7 +1177,7 @@ process_text_part (struct rspamd_task *task,
        cd = g_mime_part_get_content_disposition (GMIME_PART (mime_part->mime));
        if (cd &&
                g_ascii_strcasecmp (cd,
-               "attachment") == 0 && !task->cfg->check_text_attachements) {
+               "attachment") == 0 && (task->cfg && !task->cfg->check_text_attachements)) {
                debug_task ("skip attachments for checking as text parts");
                return;
        }
@@ -1186,7 +1186,7 @@ process_text_part (struct rspamd_task *task,
        if (cd &&
                g_ascii_strcasecmp (cd,
                GMIME_DISPOSITION_ATTACHMENT) == 0 &&
-               !task->cfg->check_text_attachements) {
+               (task->cfg && !task->cfg->check_text_attachements)) {
                debug_task ("skip attachments for checking as text parts");
                return;
        }
@@ -1552,7 +1552,7 @@ rspamd_message_from_data (struct rspamd_task *task, GByteArray *data,
                ct = g_mime_content_type_new_from_string (ct_cpy);
                g_free (ct_cpy);
        }
-       else if (task->cfg->libs_ctx) {
+       else if (task->cfg && task->cfg->libs_ctx) {
                /* Try to predict it by content (slow) */
                mb = magic_buffer (task->cfg->libs_ctx->libmagic,
                                data->data,
@@ -1662,7 +1662,7 @@ rspamd_message_parse (struct rspamd_task *task)
                message = g_mime_parser_construct_message (parser);
 
                if (message == NULL) {
-                       if (!task->cfg->allow_raw_input) {
+                       if (task->cfg && (!task->cfg->allow_raw_input)) {
                                msg_err_task ("cannot construct mime from stream");
                                g_set_error (&task->err,
                                                rspamd_message_quark (),
@@ -1757,7 +1757,7 @@ rspamd_message_parse (struct rspamd_task *task)
                if (i == 0) {
                        gboolean need_recv_correction = FALSE;
 
-                       if (recv->real_ip == NULL || task->cfg->ignore_received) {
+                       if (recv->real_ip == NULL || (task->cfg && task->cfg->ignore_received)) {
                                need_recv_correction = TRUE;
                        }
                        else if (!(task->flags & RSPAMD_TASK_FLAG_NO_IP) && task->from_addr) {
@@ -1799,7 +1799,7 @@ rspamd_message_parse (struct rspamd_task *task)
 
        /* Extract data from received header if we were not given IP */
        if (task->received->len > 0 && (task->flags & RSPAMD_TASK_FLAG_NO_IP) &&
-                       !task->cfg->ignore_received) {
+                       (task->cfg && !task->cfg->ignore_received)) {
                recv = g_ptr_array_index (task->received, 0);
                if (recv->real_ip) {
                        if (!rspamd_parse_inet_address (&task->from_addr,
index fb3783866ab8d8397259171c040ec3cceea8d04e..8cc54c792656726724b52ab744be537de98c9219 100644 (file)
@@ -658,7 +658,7 @@ rspamd_config_post_load (struct rspamd_config *cfg, gboolean validate_cache)
                                G_DIR_SEPARATOR, "effective_tld_names.dat");
 
                if (access (fpath->str, R_OK)) {
-                       msg_warn_config ("url_tld option is not specified but %s is available,"
+                       msg_info_config ("url_tld option is not specified but %s is available,"
                                        " therefore this file is assumed as TLD file for URL"
                                        " extraction", fpath->str);
                        cfg->tld_file = rspamd_mempool_strdup (cfg->cfg_pool, fpath->str);
index c76209cae7c0624c6cf3792cf378947560971edf..3d6387b52708dbe0550901ae7420f74dac4c74d4 100644 (file)
@@ -40,15 +40,18 @@ rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg)
 {
        struct rspamd_task *new_task;
 
-       g_assert (cfg != NULL);
-
        new_task = g_slice_alloc0 (sizeof (struct rspamd_task));
        new_task->worker = worker;
-       new_task->cfg = cfg;
-       REF_RETAIN (cfg);
 
-       if (cfg->check_all_filters) {
-               new_task->flags |= RSPAMD_TASK_FLAG_PASS_ALL;
+       if (cfg) {
+               new_task->cfg = cfg;
+               REF_RETAIN (cfg);
+
+               if (cfg->check_all_filters) {
+                       new_task->flags |= RSPAMD_TASK_FLAG_PASS_ALL;
+               }
+
+               new_task->re_rt = rspamd_re_cache_runtime_new (cfg->re_cache);
        }
 
        gettimeofday (&new_task->tv, NULL);
@@ -61,7 +64,7 @@ rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg)
        rspamd_mempool_add_destructor (new_task->task_pool,
                (rspamd_mempool_destruct_t) g_hash_table_unref,
                new_task->results);
-       new_task->re_rt = rspamd_re_cache_runtime_new (cfg->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_ftok_icase_hash,
@@ -246,8 +249,10 @@ rspamd_task_free (struct rspamd_task *task)
                        close (task->sock);
                }
 
-               rspamd_re_cache_runtime_destroy (task->re_rt);
-               REF_RELEASE (task->cfg);
+               if (task->cfg) {
+                       rspamd_re_cache_runtime_destroy (task->re_rt);
+                       REF_RELEASE (task->cfg);
+               }
 
                rspamd_mempool_delete (task->task_pool);
                g_slice_free1 (sizeof (struct rspamd_task), task);
index fb725ed18520672151e74812956bb3c793693b8b..fe70585beae6d0cd915b2442408e199d96a70774 100644 (file)
@@ -445,7 +445,7 @@ rspamd_url_init (const gchar *tld_file)
                        rspamd_url_parse_tld_file (tld_file, url_scanner);
                }
                else {
-                       msg_warn (
+                       msg_info (
                                        "tld extension file is not specified, url matching is limited");
                }