From: Vsevolod Stakhov Date: Mon, 4 Jul 2016 15:14:53 +0000 (+0100) Subject: [Rework] Remove dedicated images list X-Git-Tag: 1.3.0~182 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=759fa05d26aeb86fa9005ce39d222c65c45ef787;p=rspamd.git [Rework] Remove dedicated images list --- diff --git a/src/libmime/images.c b/src/libmime/images.c index 008522a7b..5a556ce9c 100644 --- a/src/libmime/images.c +++ b/src/libmime/images.c @@ -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"); diff --git a/src/libmime/images.h b/src/libmime/images.h index 6d64ea5d1..aa63d92e2 100644 --- a/src/libmime/images.h +++ b/src/libmime/images.h @@ -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, diff --git a/src/libmime/message.c b/src/libmime/message.c index 67624f6b2..de2d337d4 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -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; diff --git a/src/libserver/task.c b/src/libserver/task.c index c53f04242..1bf086cce 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -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); } diff --git a/src/libserver/task.h b/src/libserver/task.h index 8b0fdb999..f34c2ce10 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -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 */ diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index 081f1825b..cca676288 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -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 */ diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index b46fd2671..f00c0ba52 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -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"); diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 9d05f9026..3d35c2106 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -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)) {