commit bd1ed8f: [Minor] Use traverse over all tags

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Jun 11 16:42:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-06-11 16:36:31 +0100
URL: https://github.com/rspamd/rspamd/commit/bd1ed8fa07d22dd048fc38a191ed34f77d8618de

[Minor] Use traverse over all tags

---
 src/libserver/html/html.cxx |  2 +-
 src/libserver/html/html.hxx | 14 +++++++++++++-
 src/lua/lua_html.cxx        |  2 +-
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx
index 1cbc1f105..e727639aa 100644
--- a/src/libserver/html/html.cxx
+++ b/src/libserver/html/html.cxx
@@ -1643,7 +1643,7 @@ html_process_input(rspamd_mempool_t *pool,
 		}
 	}
 
-	hc->traverse_tags([](const html_tag *tag) -> bool {
+	hc->traverse_block_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;
diff --git a/src/libserver/html/html.hxx b/src/libserver/html/html.hxx
index c75d84ea4..3fd778ade 100644
--- a/src/libserver/html/html.hxx
+++ b/src/libserver/html/html.hxx
@@ -63,7 +63,7 @@ struct html_content {
 		PRE_ORDER,
 		POST_ORDER
 	};
-	auto traverse_tags(fu2::function<bool(const html_tag *)> &&func,
+	auto traverse_block_tags(fu2::function<bool(const html_tag *)> &&func,
 					traverse_type how = traverse_type::PRE_ORDER) const -> bool {
 
 		if (root_tag == nullptr) {
@@ -103,6 +103,18 @@ struct html_content {
 		}
 	}
 
+	auto traverse_all_tags(fu2::function<bool(const html_tag *)> &&func) const -> bool {
+		for (const auto &tag : all_tags) {
+			if (!(tag->flags & (FL_CLOSING|FL_XML))) {
+				if (!func(tag.get())) {
+					return false;
+				}
+			}
+		}
+
+		return true;
+	}
+
 private:
 	~html_content() = default;
 };
diff --git a/src/lua/lua_html.cxx b/src/lua/lua_html.cxx
index 058ef401f..7e17f835f 100644
--- a/src/lua/lua_html.cxx
+++ b/src/lua/lua_html.cxx
@@ -431,7 +431,7 @@ lua_html_foreach_tag (lua_State *L)
 	}
 
 	if (hc && (any || !tags.empty()) && lua_isfunction (L, 3)) {
-		hc->traverse_tags([&](const rspamd::html::html_tag *tag) -> bool {
+		hc->traverse_all_tags([&](const rspamd::html::html_tag *tag) -> bool {
 			if (tag && (any || tags.contains(tag->id))) {
 				lua_pushvalue(L, 3);
 


More information about the Commits mailing list