Skip to content
API Documentation
BastionGuard™
PhishingPage.hpp
Go to the documentation of this file.
1/*
2 * BastionGuard™
3 * Copyright (C) 2025–2026 Calogero Scarnà
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 *
17 * BastionGuard™ is a trademark of Calogero Scarnà.
18 * The BastionGuard™ name and branding are not licensed under the GPL.
19 */
20
21#pragma once
22#include <regex>
23#include <gtkmm.h>
24#include <atomic>
25#include <optional>
26#include "PhishingCheckCard.hpp"
27#include "../LifetimeGuard.hpp"
28
29class PhishingPage : public Gtk::Box {
30public:
32 virtual ~PhishingPage();
33
34private:
35 struct ParsedResult {
36 Glib::ustring classification;
37 Glib::ustring severity;
38 Glib::ustring normalized_host;
39 Glib::ustring evaluation_chain;
40 Glib::ustring matched_indicator;
41 Glib::ustring live_probe_status;
42 Glib::ustring live_probe_text;
43 Glib::ustring report_text;
44 };
45
46 void on_analyze_requested(const Glib::ustring& url);
47
48 static std::string url_encode(const std::string& s);
49 static std::string fetch_url_body(const std::string& url);
50 static std::string html_entity_decode(std::string s);
51 static std::string strip_tags(const std::string& s);
52 static std::string trim_copy(const std::string& s);
53 static std::optional<std::string> extract_first(
54 const std::string& text,
55 const std::regex& re,
56 int group = 1);
57 static std::vector<std::string> extract_all_li_after_label(
58 const std::string& html,
59 const std::string& label);
60 static ParsedResult parse_result_html(const std::string& html);
61
62 Gtk::Label lbl_title_;
64 Gtk::ScrolledWindow scroller_;
65 Gtk::TextView txt_output_;
66 Gtk::Label lbl_status_;
67
68 std::atomic<bool> destroyed_{false};
69
70 // Protegge i lambda async (thread detach + signal_idle) dall'accedere a
71 // `this` dopo che la pagina è stata distrutta. destroyed_ da solo non
72 // basta: una volta che il distruttore ritorna, leggere this->destroyed_
73 // dal thread/idle è già use-after-free. Con l'alive flag (shared_ptr) la
74 // memoria del flag resta valida e il lambda fa early-return in sicurezza.
76};
static ParsedResult parse_result_html(const std::string &html)
PhishingCheckCard phishing_card_
static std::string fetch_url_body(const std::string &url)
static std::string trim_copy(const std::string &s)
static std::string strip_tags(const std::string &s)
Gtk::TextView txt_output_
static std::string url_encode(const std::string &s)
static std::string html_entity_decode(std::string s)
std::atomic< bool > destroyed_
Gtk::Label lbl_status_
void on_analyze_requested(const Glib::ustring &url)
BastionGuard::AliveFlag alive_
Gtk::Label lbl_title_
static std::vector< std::string > extract_all_li_after_label(const std::string &html, const std::string &label)
Gtk::ScrolledWindow scroller_
static std::optional< std::string > extract_first(const std::string &text, const std::regex &re, int group=1)
std::shared_ptr< std::atomic< bool > > AliveFlag
AliveFlag make_alive_flag()