Skip to content
API Documentation
BastionGuard™
bsc::ui_util Namespace Reference

Namespaces

namespace  anonymous_namespace{AppResolver.cpp}
namespace  anonymous_namespace{GeoResolver.cpp}
namespace  anonymous_namespace{ProxyDetect.cpp}

Classes

struct  GeoEntry
class  GeoResolver
struct  ProxyEndpoint

Functions

AppMetadata resolve_app_metadata (const std::string &app_comm, const std::string &app_path, const std::vector< std::string > &app_args)
std::string best_app_display_name (const std::string &app_comm, const std::string &app_path, const std::vector< std::string > &app_args)
std::string best_app_icon_name (const std::string &app_comm, const std::string &app_path, const std::vector< std::string > &app_args)
bool is_safe_local_address (const std::string &address)
bool is_safe_local_connection (const std::string &dst_ip, const std::string &src_ip)
std::string safe_local_process_label ()
std::string safe_local_process_icon_name ()
std::string best_connection_display_name (const std::string &app_comm, const std::string &app_path, const std::vector< std::string > &app_args, const std::string &dst_ip, const std::string &src_ip)
std::string best_connection_icon_name (const std::string &app_comm, const std::string &app_path, const std::vector< std::string > &app_args, const std::string &dst_ip, const std::string &src_ip)
const std::vector< ProxyEndpoint > & detected_proxies ()
bool matches_configured_proxy (const std::string &host, std::uint16_t port)

Function Documentation

◆ best_app_display_name()

std::string bsc::ui_util::best_app_display_name ( const std::string & app_comm,
const std::string & app_path,
const std::vector< std::string > & app_args )

Definition at line 367 of file AppResolver.cpp.

369 {
370 return resolve_app_metadata(app_comm, app_path, app_args).display_name;
371}
AppMetadata resolve_app_metadata(const std::string &app_comm, const std::string &app_path, const std::vector< std::string > &app_args)

References best_app_display_name(), bsc::ui_util::AppMetadata::display_name, and resolve_app_metadata().

Referenced by best_app_display_name(), and best_connection_display_name().

◆ best_app_icon_name()

std::string bsc::ui_util::best_app_icon_name ( const std::string & app_comm,
const std::string & app_path,
const std::vector< std::string > & app_args )

Definition at line 373 of file AppResolver.cpp.

375 {
376 auto icon = resolve_app_metadata(app_comm, app_path, app_args).icon_name;
377 return icon.empty() ? kGenericIcon : icon;
378}

References best_app_icon_name(), bsc::ui_util::AppMetadata::icon_name, and resolve_app_metadata().

Referenced by best_app_icon_name(), best_connection_icon_name(), and ConnectionsPage::resolveIconName().

◆ best_connection_display_name()

std::string bsc::ui_util::best_connection_display_name ( const std::string & app_comm,
const std::string & app_path,
const std::vector< std::string > & app_args,
const std::string & dst_ip,
const std::string & src_ip )

Definition at line 410 of file AppResolver.cpp.

414 {
415 const auto display = best_app_display_name(app_comm, app_path, app_args);
416 if (is_unknown_display_name(display)
417 && !has_reliable_process_identity(app_comm, app_path, app_args)
418 && is_safe_local_connection(dst_ip, src_ip)) {
419 return kSafeLocalProcessLabel;
420 }
421 return display;
422}
std::string best_app_display_name(const std::string &app_comm, const std::string &app_path, const std::vector< std::string > &app_args)
bool is_safe_local_connection(const std::string &dst_ip, const std::string &src_ip)

References best_app_display_name(), best_connection_display_name(), and is_safe_local_connection().

Referenced by best_connection_display_name(), AlertDialog::buildUI(), display_app_name(), AppsPage::displayNameFor(), anonymous_namespace{MainWindow.cpp}::displayNameForStatus(), NetworkPage::noteConnection(), and ConnectionsPage::onNewConnection().

◆ best_connection_icon_name()

std::string bsc::ui_util::best_connection_icon_name ( const std::string & app_comm,
const std::string & app_path,
const std::vector< std::string > & app_args,
const std::string & dst_ip,
const std::string & src_ip )

Definition at line 424 of file AppResolver.cpp.

428 {
429 if (!has_reliable_process_identity(app_comm, app_path, app_args)
430 && is_safe_local_connection(dst_ip, src_ip)) {
431 return kSafeLocalProcessIcon;
432 }
433 return best_app_icon_name(app_comm, app_path, app_args);
434}
std::string best_app_icon_name(const std::string &app_comm, const std::string &app_path, const std::vector< std::string > &app_args)

References best_app_icon_name(), best_connection_icon_name(), and is_safe_local_connection().

Referenced by best_connection_icon_name(), and AlertDialog::buildUI().

◆ detected_proxies()

const std::vector< ProxyEndpoint > & bsc::ui_util::detected_proxies ( )

Restituisce la lista dei proxy rilevati. Lista vuota se nessun proxy. Thread-safe, idempotente, risultato cache-ato.

Definition at line 156 of file ProxyDetect.cpp.

156 {
157 static std::once_flag once;
158 static std::vector<ProxyEndpoint> cache;
159 std::call_once(once, []() {
160 collect_env_proxies(cache);
161 collect_file_proxies("/etc/environment", cache);
162 if (const char* home = std::getenv("HOME")) {
163 collect_file_proxies(fs::path(home) / ".profile", cache);
164 collect_file_proxies(fs::path(home) / ".bashrc", cache);
165 }
166 dedup(cache);
167 });
168 return cache;
169}

References detected_proxies().

Referenced by detected_proxies(), and matches_configured_proxy().

◆ is_safe_local_address()

bool bsc::ui_util::is_safe_local_address ( const std::string & address)

Definition at line 380 of file AppResolver.cpp.

380 {
381 const auto s = normalized_address(address);
382 if (s.empty()) return false;
383
384 if (s == "localhost" || s == "localhost.localdomain" || s == "ip6-localhost") return true;
385 if (s == "::1" || s == "0:0:0:0:0:0:0:1") return true;
386
387 // Endpoint unspecified che indicano binding/traffico locale, non Internet.
388 if (s == "0.0.0.0" || s == "::" || s == "0:0:0:0:0:0:0:0") return true;
389
390 // IPv4 loopback 127.0.0.0/8 e IPv4-mapped IPv6 loopback.
391 if (s.rfind("127.", 0) == 0) return true;
392 if (s.rfind("::ffff:127.", 0) == 0) return true;
393 if (s.rfind("0:0:0:0:0:ffff:127.", 0) == 0) return true;
394
395 return false;
396}

References is_safe_local_address().

Referenced by is_safe_local_address(), and is_safe_local_connection().

◆ is_safe_local_connection()

bool bsc::ui_util::is_safe_local_connection ( const std::string & dst_ip,
const std::string & src_ip )

◆ matches_configured_proxy()

bool bsc::ui_util::matches_configured_proxy ( const std::string & host,
std::uint16_t port )

Ritorna true se (host, port) matcha uno dei proxy rilevati. host puo' essere hostname o IP; il confronto e' case-insensitive e risolve anche localhost/127.0.0.1/::1 come equivalenti.

Definition at line 171 of file ProxyDetect.cpp.

171 {
172 for (const auto& p : detected_proxies()) {
173 if (p.port == port && host_equals(host, p.host)) return true;
174 }
175 return false;
176}
const std::vector< ProxyEndpoint > & detected_proxies()

References detected_proxies(), and matches_configured_proxy().

Referenced by AlertDialog::buildUI(), and matches_configured_proxy().

◆ resolve_app_metadata()

AppMetadata bsc::ui_util::resolve_app_metadata ( const std::string & app_comm,
const std::string & app_path,
const std::vector< std::string > & app_args )

Definition at line 351 of file AppResolver.cpp.

353 {
354 std::lock_guard lock(g_index_mutex);
355 build_index_locked();
356
357 std::vector<std::string> candidates;
358 add_candidate(candidates, app_path);
359 if (!app_args.empty()) add_candidate(candidates, app_args.front());
360 add_candidate(candidates, app_comm);
361
362 if (auto found = lookup_exact_or_alias(candidates)) return *found;
363 if (auto found = lookup_prefix(candidates)) return *found;
364 return fallback_metadata(app_comm, app_path, app_args);
365}

References resolve_app_metadata().

Referenced by best_app_display_name(), best_app_icon_name(), and resolve_app_metadata().

◆ safe_local_process_icon_name()

std::string bsc::ui_util::safe_local_process_icon_name ( )

Definition at line 406 of file AppResolver.cpp.

406 {
407 return kSafeLocalProcessIcon;
408}

References safe_local_process_icon_name().

Referenced by ConnectionsPage::resolveIconName(), and safe_local_process_icon_name().

◆ safe_local_process_label()

std::string bsc::ui_util::safe_local_process_label ( )

Definition at line 402 of file AppResolver.cpp.

402 {
403 return kSafeLocalProcessLabel;
404}

References safe_local_process_label().

Referenced by ConnectionsPage::resolveIconName(), and safe_local_process_label().