// SPDX-FileCopyrightText: 2024 Yury Gubich // SPDX-License-Identifier: GPL-3.0-or-later #include "config.h" Config::Config(const std::string& path): root(YAML::LoadFile(path)) {} std::string Config::getBareJID() const { return root["jid"].as(); } std::string Config::getPassword() const { return root["password"].as(); } std::string Config::getResource() const { return root["resource"].as("bot"); } std::string Config::getFullJID() const { return getBareJID() + "/" + getResource(); } gloox::LogLevel Config::getLogLevel() const { std::string level = root["logLevel"].as("warning"); if (level == "debug") return gloox::LogLevelDebug; else if (level == "error") return gloox::LogLevelError; else return gloox::LogLevelWarning; } gloox::TLSPolicy Config::getTLSPolicy() const { std::string level = root["tls"].as("optional"); if (level == "disabled") return gloox::TLSDisabled; else if (level == "required") return gloox::TLSRequired; else return gloox::TLSOptional; } std::set Config::getOwners() const { std::set result; YAML::Node owners = root["resource"]; if (!owners.IsSequence()) return result; for (const YAML::Node& node : owners) result.insert(node.as()); return result; } bool Config::isValid() const { return !getBareJID().empty() && !getPassword().empty(); }