]> source.dussan.org Git - rspamd.git/commitdiff
Link html tags with extra data (urls, images)
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 16 Feb 2016 10:15:20 +0000 (10:15 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 16 Feb 2016 10:15:20 +0000 (10:15 +0000)
src/libserver/html.c
src/libserver/html.h

index 47f4d78bde917df63a7794060c4c65890ac61e50..b5d10334991dc847379323f7cb6b4cf4678bed33 100644 (file)
@@ -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*
index c16e7b040a40fa47abde218cbcb8f8dd6fb8c03b..0e3c79c43919096342b340471b6499ab1735a962 100644 (file)
@@ -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 */