Commit c1e8ff96 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

yaml: add parseValueOptional

Change-Id: I011791cd9cb4ecc06e5962b6bac269b4558dde17
parent f40eb59a
......@@ -20,6 +20,7 @@
#pragma once
#include "logger.h"
#include <yaml-cpp/yaml.h>
namespace jami { namespace yaml_utils {
......@@ -32,6 +33,19 @@ void parseValue(const YAML::Node &node, const char *key, T &value)
value = node[key].as<T>(value);
}
template <typename T>
bool parseValueOptional(const YAML::Node &node, const char *key, T &value)
{
try {
parseValue(node, key, value);
return true;
} catch (const std::exception& e) {
JAMI_DBG("Can't read yaml field: %s", key);
}
return false;
}
void parsePath(const YAML::Node &node, const char *key, std::string& path, const std::string& base);
std::vector<std::map<std::string, std::string>>
......
......@@ -681,6 +681,7 @@ void RingAccount::unserialize(const YAML::Node &node)
std::lock_guard<std::mutex> lock(configurationMutex_);
using yaml_utils::parseValue;
using yaml_utils::parseValueOptional;
using yaml_utils::parsePath;
SIPAccountBase::unserialize(node);
......@@ -700,17 +701,9 @@ void RingAccount::unserialize(const YAML::Node &node)
parseValue(node, Conf::PROXY_SERVER_KEY, proxyServer_);
parseValue(node, Conf::PROXY_PUSH_TOKEN_KEY, deviceKey_);
try {
parseValue(node, DRing::Account::ConfProperties::RING_DEVICE_NAME, ringDeviceName_);
} catch (const std::exception& e) {
JAMI_WARN("can't read device name: %s", e.what());
}
parseValueOptional(node, DRing::Account::ConfProperties::RING_DEVICE_NAME, ringDeviceName_);
if (registeredName_.empty()) {
try {
parseValue(node, DRing::Account::VolatileProperties::REGISTERED_NAME, registeredName_);
} catch (const std::exception& e) {
JAMI_WARN("can't read registered name: %s", e.what());
}
parseValueOptional(node, DRing::Account::VolatileProperties::REGISTERED_NAME, registeredName_);
}
try {
......@@ -734,11 +727,7 @@ void RingAccount::unserialize(const YAML::Node &node)
dhtPortUsed_ = dhtPort_;
#if HAVE_RINGNS
try {
parseValue(node, DRing::Account::ConfProperties::RingNS::URI, nameServer_);
} catch (const std::exception& e) {
JAMI_WARN("can't read name server: %s", e.what());
}
parseValueOptional(node, DRing::Account::ConfProperties::RingNS::URI, nameServer_);
nameDir_ = NameDirectory::instance(nameServer_);
#endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment