Skip to content
API Documentation
BastionGuard™
SettingsStore.cpp File Reference

Go to the source code of this file.

Functions

static std::string config_dir_path ()
static std::vector< std::string > split_dotted (const std::string &dotted_key)
static std::string normalize_domain (std::string s)
static void extract_domains_from_payments_json (const nlohmann::json &j, std::vector< std::string > &out)

Function Documentation

◆ config_dir_path()

std::string config_dir_path ( )
static

Definition at line 37 of file SettingsStore.cpp.

37 {
38 return Glib::get_home_dir() + "/.config/BastionGuard";
39}

References config_dir_path().

Referenced by config_dir_path(), SettingsStore::settings_file_path(), and SettingsStore::write_to_disk_locked().

◆ extract_domains_from_payments_json()

void extract_domains_from_payments_json ( const nlohmann::json & j,
std::vector< std::string > & out )
static

Definition at line 462 of file SettingsStore.cpp.

462 {
463 if (j.is_object()) {
464 if (j.contains("list") && j["list"].is_array()) {
465 for (const auto& v : j["list"]) {
466 if (v.is_string()) out.push_back(normalize_domain(v.get<std::string>()));
467 }
468 } else if (j.contains("domains") && j["domains"].is_array()) {
469 for (const auto& v : j["domains"]) {
470 if (v.is_string()) out.push_back(normalize_domain(v.get<std::string>()));
471 }
472 }
473 } else if (j.is_array()) {
474 for (const auto& v : j) {
475 if (v.is_string()) out.push_back(normalize_domain(v.get<std::string>()));
476 }
477 }
478}
static std::string normalize_domain(std::string s)

References extract_domains_from_payments_json(), and normalize_domain().

Referenced by extract_domains_from_payments_json(), and SettingsStore::get_payment_domains().

◆ normalize_domain()

std::string normalize_domain ( std::string s)
static

Definition at line 361 of file SettingsStore.cpp.

361 {
362 s.erase(0, s.find_first_not_of(" \t\r\n"));
363 s.erase(s.find_last_not_of(" \t\r\n") + 1);
364 std::transform(s.begin(), s.end(), s.begin(),
365 [](unsigned char c){ return (char)std::tolower(c); });
366 if (!s.empty() && s[0] == '.') s.erase(0, 1);
367 if (s.rfind("www.", 0) == 0) s.erase(0, 4);
368 auto p = s.find(':');
369 if (p != std::string::npos) s.erase(p);
370
371 return s;
372}

References normalize_domain().

Referenced by extract_domains_from_payments_json(), SettingsStore::get_payment_domains(), normalize_domain(), and SettingsStore::save_payment_domains_user().

◆ split_dotted()

std::vector< std::string > split_dotted ( const std::string & dotted_key)
static

Definition at line 145 of file SettingsStore.cpp.

145 {
146 std::vector<std::string> parts;
147 std::string cur;
148 for (char c : dotted_key) {
149 if (c == '.') {
150 if (!cur.empty()) parts.push_back(cur);
151 cur.clear();
152 } else {
153 cur.push_back(c);
154 }
155 }
156 if (!cur.empty()) parts.push_back(cur);
157 return parts;
158}

References split_dotted().

Referenced by SettingsStore::get_node_locked(), SettingsStore::get_or_create_node_locked(), SettingsStore::set_bool(), SettingsStore::set_int(), SettingsStore::set_string(), and split_dotted().