auto url = html_process_url(pool, href_value);
- if (url && tag->extra == nullptr) {
+ if (url && std::holds_alternative<std::monostate>(tag->extra)) {
tag->extra = url.value();
}
}
g_ptr_array_add(hc->blocks, bl);
- tag->extra = bl;
+ tag->block = bl;
}
static auto
html_propagate_style(struct html_content *hc,
struct html_tag *tag,
struct html_block *bl,
- GQueue *blocks) -> void
+ std::vector<struct html_block *> &blocks) -> void
{
struct html_block *bl_parent;
gboolean push_block = FALSE;
/* Propagate from the parent if needed */
- bl_parent = static_cast<html_block *>(g_queue_peek_tail(blocks));
+ bl_parent = blocks.back();
if (bl_parent) {
if (!bl->background_color.valid) {
}
if (push_block && !(tag->flags & FL_CLOSED)) {
- g_queue_push_tail(blocks, bl);
+ blocks.push_back(bl);
}
}
struct rspamd_url *url = NULL;
gint len, href_offset = -1;
struct html_tag *cur_tag = NULL, *content_tag = NULL;
- GQueue *styles_blocks;
+ std::vector<struct html_block *> styles_blocks;
struct tag_content_parser_state content_parser_env;
tags_vector *all_tags;
hc->bgcolor.valid = TRUE;
dest = g_byte_array_sized_new (in->len / 3 * 2);
- styles_blocks = g_queue_new ();
+ styles_blocks.reserve(32);
p = in->data;
c = p;
if (prev_tag->id == Tag_A &&
!(prev_tag->flags & (FL_CLOSING)) &&
- prev_tag->extra) {
- prev_url = static_cast<rspamd_url *>(prev_tag->extra);
+ std::holds_alternative<rspamd_url *>(prev_tag->extra)) {
+ prev_url = std::get<rspamd_url *>(prev_tag->extra);
std::string_view disp_part{
reinterpret_cast<const gchar *>(dest->data + href_offset),
if (cur_tag->flags & FL_CLOSING) {
/* Just remove block element from the queue if any */
- if (styles_blocks->length > 0) {
- g_queue_pop_tail (styles_blocks);
+ if (!styles_blocks.empty()) {
+ styles_blocks.pop_back();
}
}
else {
html_process_block_tag(pool, cur_tag, hc);
- bl = static_cast<html_block *>(cur_tag->extra);
+ bl = cur_tag->block;
if (bl) {
html_propagate_style(hc, cur_tag,
html_propagate_lengths, NULL);
}
- g_queue_free (styles_blocks);
hc->parsed = dest;
return dest;
#include <utility>
#include <string_view>
+#include <variant>
#include <contrib/robin-hood/robin_hood.h>
namespace rspamd::html {
RSPAMD_HTML_COMPONENT_ALT,
};
+using html_tag_extra_t = std::variant<std::monostate, struct rspamd_url *, struct html_image *>;
+
struct html_tag {
gint id;
gint flags;
std::string_view name;
robin_hood::unordered_flat_map<html_component_type, std::string_view> parameters;
- gpointer extra; /* TODO: convert to variant */
+ html_tag_extra_t extra;
+ struct html_block *block; /* TODO: temporary, must be handled by css */
GNode *parent;
};