]> source.dussan.org Git - rspamd.git/commitdiff
[Rework] Remove dedicated images list
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 4 Jul 2016 15:14:53 +0000 (16:14 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 4 Jul 2016 15:14:53 +0000 (16:14 +0100)
src/libmime/images.c
src/libmime/images.h
src/libmime/message.c
src/libserver/task.c
src/libserver/task.h
src/libstat/stat_process.c
src/lua/lua_task.c
src/plugins/fuzzy_check.c

index 008522a7be11afa24c4a1c792f93d47c93793fcb..5a556ce9c068763f438b8e36ef1708e493d8f814 100644 (file)
@@ -15,7 +15,7 @@
  */
 #include "config.h"
 #include "images.h"
-#include "rspamd.h"
+#include "task.h"
 #include "message.h"
 #include "html.h"
 
@@ -37,8 +37,8 @@ rspamd_images_process (struct rspamd_task *task)
 
        for (i = 0; i < task->parts->len; i ++) {
                part = g_ptr_array_index (task->parts, i);
-               if (g_mime_content_type_is_type (part->type, "image",
-                       "*") && part->content->len > 0) {
+               if (g_mime_content_type_is_type (part->type, "image", "*") &&
+                               part->content->len > 0) {
                        process_image (task, part);
                }
        }
@@ -226,7 +226,8 @@ process_image (struct rspamd_task *task, struct rspamd_mime_part *part)
                        img->width, img->height,
                        task->message_id);
                img->filename = part->filename;
-               task->images = g_list_prepend (task->images, img);
+               part->flags |= RSPAMD_MIME_PART_IMAGE;
+               part->specific_data = img;
 
                /* Check Content-Id */
                rh = g_hash_table_lookup (part->raw_headers, "Content-Id");
index 6d64ea5d13acdcddddf2a4a67d02924066a744bc..aa63d92e2cc237d9ea77c8cc2d8a8ab42e32f0ca 100644 (file)
@@ -2,9 +2,9 @@
 #define IMAGES_H_
 
 #include "config.h"
-#include "rspamd.h"
 
 struct html_image;
+struct rspamd_task;
 
 enum rspamd_image_type {
        IMAGE_TYPE_PNG = 0,
index 67624f6b23c3b75b69668e3e81bcc9b3839406bf..de2d337d445f25e4273bad2a89489c0b76b6d237 100644 (file)
@@ -969,6 +969,9 @@ process_text_part (struct rspamd_task *task,
                return;
        }
 
+       mime_part->flags |= RSPAMD_MIME_PART_TEXT;
+       mime_part->specific_data = text_part;
+
        if (rspamd_check_gtube (task, text_part)) {
                struct metric_result *mres;
 
index c53f04242f4d8054ab3102bb58ad328cab20da5a..1bf086cce6244312bac8512d8a3baaf6319c0b5d 100644 (file)
@@ -213,10 +213,6 @@ rspamd_task_free (struct rspamd_task *task)
                        rspamd_email_address_unref (task->from_envelope);
                }
 
-               if (task->images) {
-                       g_list_free (task->images);
-               }
-
                if (task->messages) {
                        g_list_free (task->messages);
                }
index 8b0fdb999f64d569dca7a603745b2d8ec9bdf9e3..f34c2ce1028145a22986598be80487b82f2f2831 100644 (file)
@@ -146,7 +146,6 @@ struct rspamd_task {
        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                                                                     */
index 081f1825bd9db98fc9d460da0297cbc6ade43e01..cca676288c183bc2bc93aae1fe05238b82108e0d 100644 (file)
@@ -78,36 +78,36 @@ rspamd_stat_tokenize_parts_metadata (struct rspamd_stat_ctx *st_ctx,
        ar = g_array_sized_new (FALSE, FALSE, sizeof (elt), 4);
 
        /* Insert images */
-       cur = g_list_first (task->images);
+       for (i = 0; i < task->parts->len; i ++) {
+               part = g_ptr_array_index (task->parts, i);
 
-       while (cur) {
-               img = cur->data;
+               if (part->flags & RSPAMD_MIME_PART_IMAGE) {
+                       img = part->specific_data;
 
-               /* If an image has a linked HTML part, then we push its details to the stat */
-               if (img->html_image) {
-                       elt.begin = (gchar *)"image";
-                       elt.len = 5;
-                       g_array_append_val (ar, elt);
-                       elt.begin = (gchar *)&img->html_image->height;
-                       elt.len = sizeof (img->html_image->height);
-                       g_array_append_val (ar, elt);
-                       elt.begin = (gchar *)&img->html_image->width;
-                       elt.len = sizeof (img->html_image->width);
-                       g_array_append_val (ar, elt);
-                       elt.begin = (gchar *)&img->type;
-                       elt.len = sizeof (img->type);
-                       g_array_append_val (ar, elt);
-
-                       if (img->filename) {
-                               elt.begin = (gchar *)img->filename;
-                               elt.len = strlen (elt.begin);
+                       /* If an image has a linked HTML part, then we push its details to the stat */
+                       if (img->html_image) {
+                               elt.begin = (gchar *)"image";
+                               elt.len = 5;
+                               g_array_append_val (ar, elt);
+                               elt.begin = (gchar *)&img->html_image->height;
+                               elt.len = sizeof (img->html_image->height);
+                               g_array_append_val (ar, elt);
+                               elt.begin = (gchar *)&img->html_image->width;
+                               elt.len = sizeof (img->html_image->width);
+                               g_array_append_val (ar, elt);
+                               elt.begin = (gchar *)&img->type;
+                               elt.len = sizeof (img->type);
                                g_array_append_val (ar, elt);
-                       }
 
-                       msg_debug_task ("added stat tokens for image '%s'", img->html_image->src);
-               }
+                               if (img->filename) {
+                                       elt.begin = (gchar *)img->filename;
+                                       elt.len = strlen (elt.begin);
+                                       g_array_append_val (ar, elt);
+                               }
 
-               cur = g_list_next (cur);
+                               msg_debug_task ("added stat tokens for image '%s'", img->html_image->src);
+                       }
+               }
        }
 
        /* Process mime parts */
index b46fd26718e2dbfb19c4d156eaf629f2217afc91..f00c0ba526da4f0638395b91513243d991b5cb6d 100644 (file)
@@ -2111,28 +2111,23 @@ static gint
 lua_task_get_images (lua_State *L)
 {
        struct rspamd_task *task = lua_check_task (L, 1);
-       gint i = 1;
-       GList *cur;
+       guint nelt = 0, i;
+       struct rspamd_mime_part *part;
        struct rspamd_image **pimg;
 
        if (task) {
-               cur = task->images;
+               lua_newtable (L);
 
-               if (cur) {
-                       lua_newtable (L);
+               for (i = 0; i < task->parts->len; i ++) {
+                       part = g_ptr_array_index (task->parts, i);
 
-                       while (cur) {
+                       if (part->flags & RSPAMD_MIME_PART_IMAGE) {
                                pimg = lua_newuserdata (L, sizeof (struct rspamd_image *));
                                rspamd_lua_setclass (L, "rspamd{image}", -1);
-                               *pimg = cur->data;
-                               lua_rawseti (L, -2, i++);
-                               cur = g_list_next (cur);
+                               *pimg = part->specific_data;
+                               lua_rawseti (L, -2, ++nelt);
                        }
                }
-               else {
-                       /* Return nil if there are no images to preserve compatibility */
-                       lua_pushnil (L);
-               }
        }
        else {
                return luaL_error (L, "invalid arguments");
index 9d05f9026963e46795230a9ef175fd7dfc2eb60a..3d35c21063678348074e517fe40f6720dc75e15b 100644 (file)
@@ -2042,32 +2042,28 @@ fuzzy_generate_commands (struct rspamd_task *task, struct fuzzy_rule *rule,
                }
        }
 
-       /* Process images */
-       GList *cur;
+       /* Process other parts and images */
+       for (i = 0; i < task->parts->len; i ++) {
+               mime_part = g_ptr_array_index (task->parts, i);
 
-       cur = task->images;
-       while (cur) {
-               image = cur->data;
-               if (image->data->len > 0) {
-                       if (fuzzy_module_ctx->min_height <= 0 || image->height >=
-                               fuzzy_module_ctx->min_height) {
-                               if (fuzzy_module_ctx->min_width <= 0 || image->width >=
-                                       fuzzy_module_ctx->min_width) {
-                                       io = fuzzy_cmd_from_data_part (rule, c, flag, value,
-                                                       task->task_pool,
-                                                       image->data->data, image->data->len);
-                                       if (io) {
-                                               g_ptr_array_add (res, io);
+               if (mime_part->flags & RSPAMD_MIME_PART_IMAGE) {
+                       image = mime_part->specific_data;
+
+                       if (image->data->len > 0) {
+                               if (fuzzy_module_ctx->min_height <= 0 || image->height >=
+                                               fuzzy_module_ctx->min_height) {
+                                       if (fuzzy_module_ctx->min_width <= 0 || image->width >=
+                                                       fuzzy_module_ctx->min_width) {
+                                               io = fuzzy_cmd_from_data_part (rule, c, flag, value,
+                                                               task->task_pool,
+                                                               image->data->data, image->data->len);
+                                               if (io) {
+                                                       g_ptr_array_add (res, io);
+                                               }
                                        }
                                }
                        }
                }
-               cur = g_list_next (cur);
-       }
-
-       /* Process other parts */
-       for (i = 0; i < task->parts->len; i ++) {
-               mime_part = g_ptr_array_index (task->parts, i);
 
                if (mime_part->content->len > 0 &&
                        fuzzy_check_content_type (rule, mime_part->type)) {