Skip to content
API Documentation
BastionGuard™
BastionGuard-secure.cpp File Reference

Go to the source code of this file.

Functions

static std::string to_lower (std::string s)
static void load_payments_list_only (const std::string &path, std::vector< std::string > &out)
static bool matches_payment_domain (const std::string &host_norm, const std::vector< std::string > &list_norm)

Function Documentation

◆ load_payments_list_only()

void load_payments_list_only ( const std::string & path,
std::vector< std::string > & out )
static

Definition at line 159 of file BastionGuard-secure.cpp.

159 {
160 if (!fs::exists(path)) {
161 std::cerr << _("[BastionGuard-secure] ⚠ payments.json non trovato: ") << path << "\n";
162 return;
163 }
164
165 std::ifstream f(path, std::ios::binary);
166 if (!f.is_open()) {
167 std::cerr << _("[BastionGuard-secure] ⚠ Impossibile aprire: ") << path << "\n";
168 return;
169 }
170
171 json j;
172 try {
173 f >> j;
174 } catch (const std::exception& e) {
175 std::cerr << Glib::ustring::compose(
176 _("[BastionGuard-secure] ❌ Errore parsing JSON (%1): %2"),
177 path,
178 e.what()
179 ) << "\n";
180 return;
181 }
182
183 if (!j.is_object()) {
184 std::cerr << _(
185 "[BastionGuard-secure] ⚠ payments.json deve essere un oggetto con chiave \"list\"."
186 ) << "\n";
187
188 return;
189 }
190
191 if (!j.contains("list") || !j["list"].is_array()) {
192 std::cerr << _("[BastionGuard-secure] ⚠ payments.json: chiave \"list\" mancante o non array.\n");
193 return;
194 }
195
196 for (const auto& v : j["list"]) {
197 if (!v.is_string()) continue;
198 auto cd = SecureList::clean_domain(v.get<std::string>());
199 if (!cd.empty()) out.push_back(cd);
200 }
201
202 std::cerr << _("[BastionGuard-secure] ✅ Caricati ") << out.size()
203 << _(" domini da payments.json (list)\n");
204}
nlohmann::json json
Definition Backend.cpp:2908
#define _(s)
static std::string clean_domain(const std::string &d)

References _, SecureList::clean_domain(), and load_payments_list_only().

Referenced by load_payments_list_only(), and SecureList::payments_cache_only().

◆ matches_payment_domain()

bool matches_payment_domain ( const std::string & host_norm,
const std::vector< std::string > & list_norm )
static

Definition at line 219 of file BastionGuard-secure.cpp.

220 {
221 for (const auto& d : list_norm) {
222 if (d.empty()) continue;
223 if (host_norm == d) return true;
224 if (SecureList::ends_with(host_norm, "." + d)) return true;
225 }
226 return false;
227}
static bool ends_with(const std::string &s, const std::string &suffix)

References SecureList::ends_with(), and matches_payment_domain().

Referenced by SecureList::is_payment_domain(), and matches_payment_domain().

◆ to_lower()

std::string to_lower ( std::string s)
static

Definition at line 44 of file BastionGuard-secure.cpp.

44 {
45 std::transform(s.begin(), s.end(), s.begin(),
46 [](unsigned char c){ return std::tolower(c); });
47 return s;
48}

References to_lower().

Referenced by SecureList::clean_domain().