aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-06-07 17:00:42 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-06-07 17:30:09 +0100
commit2930802de7f8b64959617ea3b0948078eb3adc9b (patch)
treee181382b679b3d9ba5b8bff562260c16b17f7a8b
parent5b703a46b4b06dcdc2d1910940cd3ea105ab7e39 (diff)
downloadrspamd-2930802de7f8b64959617ea3b0948078eb3adc9b.tar.gz
rspamd-2930802de7f8b64959617ea3b0948078eb3adc9b.zip
[Rework] Html: Another steps to get rid of gnode
-rw-r--r--src/libserver/html/html.cxx48
-rw-r--r--src/libserver/html/html_tag.hxx2
2 files changed, 18 insertions, 32 deletions
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)) {
@@ -1527,26 +1530,6 @@ html_process_block_tag(rspamd_mempool_t *pool, struct html_tag *tag,
}
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,
struct html_block *bl,
@@ -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<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;