From: Vsevolod Stakhov Date: Tue, 16 Feb 2016 10:15:20 +0000 (+0000) Subject: Link html tags with extra data (urls, images) X-Git-Tag: 1.2.0~227 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0784bf958e7657c68b06c98682d093d957e92bc0;p=rspamd.git Link html tags with extra data (urls, images) --- diff --git a/src/libserver/html.c b/src/libserver/html.c index 47f4d78bd..b5d103349 100644 --- a/src/libserver/html.c +++ b/src/libserver/html.c @@ -1339,6 +1339,7 @@ rspamd_html_process_url_tag (rspamd_mempool_t *pool, struct html_tag *tag) { struct html_tag_component *comp; GList *cur; + struct rspamd_url *url; cur = tag->params->head; @@ -1346,7 +1347,13 @@ rspamd_html_process_url_tag (rspamd_mempool_t *pool, struct html_tag *tag) comp = cur->data; if (comp->type == RSPAMD_HTML_COMPONENT_HREF && comp->len > 0) { - return rspamd_html_process_url (pool, comp->start, comp->len, comp); + url = rspamd_html_process_url (pool, comp->start, comp->len, comp); + + if (url && tag->extra == NULL) { + tag->extra = url; + } + + return url; } cur = g_list_next (cur); @@ -1404,6 +1411,7 @@ rspamd_html_process_img_tag (rspamd_mempool_t *pool, struct html_tag *tag, cur = tag->params->head; img = rspamd_mempool_alloc0 (pool, sizeof (*img)); + img->tag = tag; while (cur) { comp = cur->data; @@ -1443,6 +1451,7 @@ rspamd_html_process_img_tag (rspamd_mempool_t *pool, struct html_tag *tag, } g_ptr_array_add (hc->images, img); + tag->extra = img; } /* Keep sorted by name */ @@ -1645,6 +1654,7 @@ rspamd_html_process_block_tag (rspamd_mempool_t *pool, struct html_tag *tag, } g_ptr_array_add (hc->blocks, bl); + tag->extra = bl; } GByteArray* diff --git a/src/libserver/html.h b/src/libserver/html.h index c16e7b040..0e3c79c43 100644 --- a/src/libserver/html.h +++ b/src/libserver/html.h @@ -36,8 +36,8 @@ enum html_component_type { struct html_tag_component { enum html_component_type type; - const guchar *start; guint len; + const guchar *start; }; struct html_image { @@ -45,6 +45,7 @@ struct html_image { guint width; guint flags; gchar *src; + struct html_tag *tag; }; struct html_color { @@ -78,9 +79,10 @@ struct html_block { struct html_tag { gint id; + gint flags; struct html_tag_component name; GQueue *params; - gint flags; + gpointer extra; /** Additional data associated with tag (e.g. image) */ }; /* Forwarded declaration */