diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-08-25 20:15:29 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-08-25 20:15:29 +0400 |
commit | 59822ebf58a3bf9f0a3bb97150206013be3b43d7 (patch) | |
tree | d08236df32ec8742c3ca2b6097de0977aa893ace /src | |
parent | 671bbfa9cc85a625df33d6384a3179ce076765b9 (diff) | |
download | rspamd-59822ebf58a3bf9f0a3bb97150206013be3b43d7.tar.gz rspamd-59822ebf58a3bf9f0a3bb97150206013be3b43d7.zip |
* Add ability to extract filename and size of images from lua
Diffstat (limited to 'src')
-rw-r--r-- | src/images.c | 1 | ||||
-rw-r--r-- | src/images.h | 1 | ||||
-rw-r--r-- | src/lua/lua_task.c | 34 | ||||
-rw-r--r-- | src/message.c | 1 | ||||
-rw-r--r-- | src/message.h | 1 |
5 files changed, 38 insertions, 0 deletions
diff --git a/src/images.c b/src/images.c index 00c9599c0..d071c38e7 100644 --- a/src/images.c +++ b/src/images.c @@ -226,6 +226,7 @@ process_image (struct worker_task *task, struct mime_part *part) image_type_str (img->type), img->width, img->height, task->message_id); + img->filename = part->filename; task->images = g_list_prepend (task->images, img); } } diff --git a/src/images.h b/src/images.h index 2a79e4edd..f7616a680 100644 --- a/src/images.h +++ b/src/images.h @@ -17,6 +17,7 @@ struct rspamd_image { GByteArray *data; guint32 width; guint32 height; + const char *filename; }; void process_images (struct worker_task *task); diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index b18cfc21f..cb9433d5e 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -109,11 +109,15 @@ static const struct luaL_reg textpartlib_m[] = { LUA_FUNCTION_DEF (image, get_width); LUA_FUNCTION_DEF (image, get_height); LUA_FUNCTION_DEF (image, get_type); +LUA_FUNCTION_DEF (image, get_filename); +LUA_FUNCTION_DEF (image, get_size); static const struct luaL_reg imagelib_m[] = { LUA_INTERFACE_DEF (image, get_width), LUA_INTERFACE_DEF (image, get_height), LUA_INTERFACE_DEF (image, get_type), + LUA_INTERFACE_DEF (image, get_filename), + LUA_INTERFACE_DEF (image, get_size), {"__tostring", lua_class_tostring}, {NULL, NULL} }; @@ -885,6 +889,36 @@ lua_image_get_type (lua_State *L) return 1; } +static int +lua_image_get_size (lua_State *L) +{ + struct rspamd_image *img = lua_check_image (L); + + if (img != NULL) { + lua_pushinteger (L, img->data->len); + } + else { + lua_pushnil (L); + } + + return 1; +} + +static int +lua_image_get_filename (lua_State *L) +{ + struct rspamd_image *img = lua_check_image (L); + + if (img != NULL && img->filename != NULL) { + lua_pushstring (L, img->filename); + } + else { + lua_pushnil (L); + } + + return 1; +} + /* Init part */ int luaopen_task (lua_State * L) diff --git a/src/message.c b/src/message.c index ad730d360..2491ddfc0 100644 --- a/src/message.c +++ b/src/message.c @@ -709,6 +709,7 @@ mime_foreach_callback (GMimeObject * part, gpointer user_data) mime_part->type = type; mime_part->content = part_content; mime_part->parent = task->parser_parent_part; + mime_part->filename = g_mime_part_get_filename (GMIME_PART (part)); /* Extract checksums for some types */ if (g_mime_content_type_is_type (type, "image", "*") && part_content->len > 0) { mime_part->checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5, part_content->data, part_content->len); diff --git a/src/message.h b/src/message.h index 3bdb0285d..4b51064ab 100644 --- a/src/message.h +++ b/src/message.h @@ -17,6 +17,7 @@ struct mime_part { GByteArray *content; GMimeObject *parent; gchar *checksum; + const char *filename; }; struct mime_text_part { |