64 lines
1.5 KiB
C++
64 lines
1.5 KiB
C++
|
// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||
|
// 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>();
|
||
|
}
|
||
|
|
||
|
std::string Config::getPassword() const {
|
||
|
return root["password"].as<std::string>();
|
||
|
}
|
||
|
|
||
|
std::string Config::getResource() const {
|
||
|
return root["resource"].as<std::string>("bot");
|
||
|
}
|
||
|
|
||
|
std::string Config::getFullJID() const {
|
||
|
return getBareJID() + "/" + getResource();
|
||
|
}
|
||
|
|
||
|
gloox::LogLevel Config::getLogLevel() const {
|
||
|
std::string level = root["logLevel"].as<std::string>("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<std::string>("optional");
|
||
|
|
||
|
if (level == "disabled")
|
||
|
return gloox::TLSDisabled;
|
||
|
else if (level == "required")
|
||
|
return gloox::TLSRequired;
|
||
|
else
|
||
|
return gloox::TLSOptional;
|
||
|
}
|
||
|
|
||
|
|
||
|
std::set<std::string> Config::getOwners() const {
|
||
|
std::set<std::string> result;
|
||
|
YAML::Node owners = root["resource"];
|
||
|
if (!owners.IsSequence())
|
||
|
return result;
|
||
|
|
||
|
for (const YAML::Node& node : owners)
|
||
|
result.insert(node.as<std::string>());
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
bool Config::isValid() const {
|
||
|
return !getBareJID().empty() && !getPassword().empty();
|
||
|
}
|