From: Vsevolod Stakhov Date: Mon, 7 Jun 2021 16:00:42 +0000 (+0100) Subject: [Rework] Html: Another steps to get rid of gnode X-Git-Tag: 3.0~339 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2930802de7f8b64959617ea3b0948078eb3adc9b;p=rspamd.git [Rework] Html: Another steps to get rid of gnode --- diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx index a459ee0c6..f041f45b7 100644 --- a/src/libserver/html/html.cxx +++ b/src/libserver/html/html.cxx @@ -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(node->data), *cld_tag; - - if (tag) { - child = node->children; - - /* Summarize content length from children */ - while (child) { - cld_tag = static_cast(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; } diff --git a/src/libserver/html/html_tag.hxx b/src/libserver/html/html_tag.hxx index d75cfcf6d..4aba9af41 100644 --- a/src/libserver/html/html_tag.hxx +++ b/src/libserver/html/html_tag.hxx @@ -45,7 +45,7 @@ using html_tag_extra_t = std::variant