]> source.dussan.org Git - rspamd.git/commitdiff
[Rework] Html: Another steps to get rid of gnode
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 7 Jun 2021 16:00:42 +0000 (17:00 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 7 Jun 2021 16:30:09 +0000 (17:30 +0100)
src/libserver/html/html.cxx
src/libserver/html/html_tag.hxx

index a459ee0c6044ab3f10bed0056c14cb30d55da850..f041f45b704e401914285f7ed85870a5db47d6cb 100644 (file)
@@ -182,16 +182,19 @@ html_process_tag(rspamd_mempool_t *pool,
                                                return true;
                                        }
                                }
-                       }
 
-                       if (hc->total_tags < rspamd::html::max_tags) {
-                               parent->children.push_back(tag);
+                               if (hc->total_tags < rspamd::html::max_tags) {
+                                       parent->children.push_back(tag);
 
-                               if ((tag->flags & FL_CLOSED) == 0) {
-                                       tags_stack.push_back(tag);
-                               }
+                                       if ((tag->flags & FL_CLOSED) == 0) {
+                                               tags_stack.push_back(tag);
+                                       }
 
-                               hc->total_tags++;
+                                       hc->total_tags++;
+                               }
+                       }
+                       else {
+                               hc->root_tag = tag;
                        }
 
                        if (tag->flags & (CM_HEAD | CM_UNKNOWN | FL_IGNORE)) {
@@ -1526,26 +1529,6 @@ html_process_block_tag(rspamd_mempool_t *pool, struct html_tag *tag,
        tag->block = bl;
 }
 
-static auto
-html_propagate_lengths(GNode *node, gpointer _unused) -> gboolean
-{
-       GNode *child;
-       struct html_tag *tag = static_cast<html_tag *>(node->data), *cld_tag;
-
-       if (tag) {
-               child = node->children;
-
-               /* Summarize content length from children */
-               while (child) {
-                       cld_tag = static_cast<html_tag *>(child->data);
-                       tag->content_length += cld_tag->content_length;
-                       child = child->next;
-               }
-       }
-
-       return FALSE;
-}
-
 static auto
 html_propagate_style(struct html_content *hc,
                                                        struct html_tag *tag,
@@ -2260,10 +2243,13 @@ html_process_part_full (rspamd_mempool_t *pool,
                }
        }
 
-       if (hc->html_tags) {
-               g_node_traverse (hc->html_tags, G_POST_ORDER, G_TRAVERSE_ALL, -1,
-                               html_propagate_lengths, NULL);
-       }
+       hc->traverse_tags([](const html_tag *tag) -> bool {
+               /* Summarize content length from children */
+               for (const auto *cld_tag : tag->children) {
+                       tag->content_length += cld_tag->content_length;
+               }
+               return true;
+       }, html_content::traverse_type::POST_ORDER);
 
        return hc;
 }
index d75cfcf6dd59120093e114518218dc308132b183..4aba9af41b512adc0a611fbe66fcbd1a6e61d232 100644 (file)
@@ -45,7 +45,7 @@ using html_tag_extra_t = std::variant<std::monostate, struct rspamd_url *, struc
 struct html_tag {
        gint id = -1;
        gint flags = 0;
-       guint content_length = 0;
+       mutable guint content_length = 0; /* Allow content length propagation */
        goffset content_offset = 0;
 
        std::string_view name;