Skip to content
Snippets Groups Projects
Commit 6c90ba38 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

config: only save non-default values

Change-Id: I099d185f1a68470274012d3a597ff0b4a9f589d5
parent 1360c775
No related branches found
Tags
No related merge requests found
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
#include "account_config.h" #include "account_config.h"
#include "account_const.h" #include "account_const.h"
#include "account_schema.h" #include "account_schema.h"
#include "config/yamlparser.h"
#include "string_utils.h" #include "string_utils.h"
#include "fileutils.h" #include "fileutils.h"
#include "config/account_config_utils.h"
#include <fmt/compile.h> #include <fmt/compile.h>
...@@ -54,30 +54,30 @@ constexpr const char* PROXY_PUSH_TOPIC_KEY = "proxyPushiOSTopic"; ...@@ -54,30 +54,30 @@ constexpr const char* PROXY_PUSH_TOPIC_KEY = "proxyPushiOSTopic";
using yaml_utils::parseValueOptional; using yaml_utils::parseValueOptional;
void void
AccountConfig::serialize(YAML::Emitter& out) const AccountConfig::serializeDiff(YAML::Emitter& out, const AccountConfig& DEFAULT_CONFIG) const
{ {
out << YAML::Key << ACCOUNT_ENABLE_KEY << YAML::Value << enabled; SERIALIZE_CONFIG(ACCOUNT_ENABLE_KEY, enabled);
out << YAML::Key << TYPE_KEY << YAML::Value << type; SERIALIZE_CONFIG(TYPE_KEY, type);
out << YAML::Key << ALIAS_KEY << YAML::Value << alias; SERIALIZE_CONFIG(ALIAS_KEY, alias);
out << YAML::Key << HOSTNAME_KEY << YAML::Value << hostname; SERIALIZE_CONFIG(HOSTNAME_KEY, hostname);
out << YAML::Key << USERNAME_KEY << YAML::Value << username; SERIALIZE_CONFIG(USERNAME_KEY, username);
SERIALIZE_CONFIG(MAILBOX_KEY, mailbox);
out << YAML::Key << ACTIVE_CODEC_KEY << YAML::Value << fmt::format(FMT_COMPILE("{}"), fmt::join(activeCodecs, "/"sv)); out << YAML::Key << ACTIVE_CODEC_KEY << YAML::Value << fmt::format(FMT_COMPILE("{}"), fmt::join(activeCodecs, "/"sv));
out << YAML::Key << MAILBOX_KEY << YAML::Value << mailbox; SERIALIZE_CONFIG(ACCOUNT_AUTOANSWER_KEY, autoAnswerEnabled);
out << YAML::Key << ACCOUNT_AUTOANSWER_KEY << YAML::Value << autoAnswerEnabled; SERIALIZE_CONFIG(ACCOUNT_READRECEIPT_KEY, sendReadReceipt);
out << YAML::Key << ACCOUNT_READRECEIPT_KEY << YAML::Value << sendReadReceipt; SERIALIZE_CONFIG(ACCOUNT_ISRENDEZVOUS_KEY, isRendezVous);
out << YAML::Key << ACCOUNT_ISRENDEZVOUS_KEY << YAML::Value << isRendezVous; SERIALIZE_CONFIG(ACCOUNT_ACTIVE_CALL_LIMIT_KEY, activeCallLimit);
out << YAML::Key << ACCOUNT_ACTIVE_CALL_LIMIT_KEY << YAML::Value << activeCallLimit; SERIALIZE_CONFIG(RINGTONE_ENABLED_KEY, ringtoneEnabled);
out << YAML::Key << RINGTONE_ENABLED_KEY << YAML::Value << ringtoneEnabled; SERIALIZE_CONFIG(RINGTONE_PATH_KEY, ringtonePath);
out << YAML::Key << RINGTONE_PATH_KEY << YAML::Value << ringtonePath; SERIALIZE_CONFIG(USER_AGENT_KEY, customUserAgent);
out << YAML::Key << USER_AGENT_KEY << YAML::Value << customUserAgent; SERIALIZE_CONFIG(DISPLAY_NAME_KEY, displayName);
out << YAML::Key << DISPLAY_NAME_KEY << YAML::Value << displayName; SERIALIZE_CONFIG(UPNP_ENABLED_KEY, upnpEnabled);
out << YAML::Key << UPNP_ENABLED_KEY << YAML::Value << upnpEnabled; SERIALIZE_CONFIG(DEFAULT_MODERATORS_KEY, defaultModerators);
out << YAML::Key << DEFAULT_MODERATORS_KEY << YAML::Value << defaultModerators; SERIALIZE_CONFIG(LOCAL_MODERATORS_ENABLED_KEY, localModeratorsEnabled);
out << YAML::Key << LOCAL_MODERATORS_ENABLED_KEY << YAML::Value << localModeratorsEnabled; SERIALIZE_CONFIG(ALL_MODERATORS_ENABLED_KEY, allModeratorsEnabled);
out << YAML::Key << ALL_MODERATORS_ENABLED_KEY << YAML::Value << allModeratorsEnabled; SERIALIZE_CONFIG(PROXY_PUSH_TOKEN_KEY, deviceKey);
out << YAML::Key << PROXY_PUSH_TOKEN_KEY << YAML::Value << deviceKey; SERIALIZE_CONFIG(PROXY_PUSH_TOPIC_KEY, notificationTopic);
out << YAML::Key << PROXY_PUSH_TOPIC_KEY << YAML::Value << notificationTopic; SERIALIZE_CONFIG(VIDEO_ENABLED_KEY, videoEnabled);
out << YAML::Key << VIDEO_ENABLED_KEY << YAML::Value << videoEnabled;
} }
void void
......
...@@ -30,7 +30,9 @@ constexpr const char* const DEFAULT_RINGTONE_PATH = "default.opus"; ...@@ -30,7 +30,9 @@ constexpr const char* const DEFAULT_RINGTONE_PATH = "default.opus";
struct AccountConfig: public Serializable { struct AccountConfig: public Serializable {
AccountConfig(const std::string& type_, const std::string& id_, const std::string& path_ = {}): type(type_), id(id_), path(path_) {} AccountConfig(const std::string& type_, const std::string& id_, const std::string& path_ = {}): type(type_), id(id_), path(path_) {}
virtual void serialize(YAML::Emitter& out) const; void serializeDiff(YAML::Emitter& out, const AccountConfig& def) const;
virtual void serialize(YAML::Emitter& out) const = 0;
virtual void unserialize(const YAML::Node& node); virtual void unserialize(const YAML::Node& node);
virtual std::map<std::string, std::string> toMap() const; virtual std::map<std::string, std::string> toMap() const;
......
/*
* Copyright (C) 2004-2022 Savoir-faire Linux Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "yamlparser.h"
template<typename T>
inline void serializeValue(YAML::Emitter& out, const char* key, const T& value, const T& def) {
if (value != def)
out << YAML::Key << key << YAML::Value << value;
}
#define SERIALIZE_CONFIG(key, name) serializeValue(out, key, name, DEFAULT_CONFIG.name)
#define SERIALIZE_PATH(key, name) serializeValue(out, key, fileutils::getCleanPath(path, name), DEFAULT_CONFIG.name)
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#include "account_const.h" #include "account_const.h"
#include "account_schema.h" #include "account_schema.h"
#include "configkeys.h" #include "configkeys.h"
#include "config/yamlparser.h"
#include "fileutils.h" #include "fileutils.h"
#include "config/account_config_utils.h"
namespace jami { namespace jami {
...@@ -31,53 +31,43 @@ const char* const TLS_PASSWORD_KEY = "password"; ...@@ -31,53 +31,43 @@ const char* const TLS_PASSWORD_KEY = "password";
const char* const PRIVATE_KEY_KEY = "privateKey"; const char* const PRIVATE_KEY_KEY = "privateKey";
} // namespace Conf } // namespace Conf
static const JamiAccountConfig DEFAULT_CONFIG {};
void void
JamiAccountConfig::serialize(YAML::Emitter& out) const JamiAccountConfig::serialize(YAML::Emitter& out) const
{ {
out << YAML::BeginMap; out << YAML::BeginMap;
SipAccountBaseConfig::serialize(out); SipAccountBaseConfig::serializeDiff(out, DEFAULT_CONFIG);
out << YAML::Key << Conf::DHT_PORT_KEY << YAML::Value << dhtPort; SERIALIZE_CONFIG(Conf::DHT_PORT_KEY, dhtPort);
out << YAML::Key << Conf::DHT_PUBLIC_IN_CALLS << YAML::Value << allowPublicIncoming; SERIALIZE_CONFIG(Conf::DHT_PUBLIC_IN_CALLS, allowPublicIncoming);
out << YAML::Key << Conf::DHT_ALLOW_PEERS_FROM_HISTORY << YAML::Value << allowPeersFromHistory; SERIALIZE_CONFIG(Conf::DHT_ALLOW_PEERS_FROM_HISTORY, allowPeersFromHistory);
out << YAML::Key << Conf::DHT_ALLOW_PEERS_FROM_CONTACT << YAML::Value << allowPeersFromContact; SERIALIZE_CONFIG(Conf::DHT_ALLOW_PEERS_FROM_CONTACT, allowPeersFromContact);
out << YAML::Key << Conf::DHT_ALLOW_PEERS_FROM_TRUSTED << YAML::Value << allowPeersFromTrusted; SERIALIZE_CONFIG(Conf::DHT_ALLOW_PEERS_FROM_TRUSTED, allowPeersFromTrusted);
out << YAML::Key << libjami::Account::ConfProperties::DHT_PEER_DISCOVERY << YAML::Value SERIALIZE_CONFIG(libjami::Account::ConfProperties::DHT_PEER_DISCOVERY, dhtPeerDiscovery);
<< dhtPeerDiscovery; SERIALIZE_CONFIG(libjami::Account::ConfProperties::ACCOUNT_PEER_DISCOVERY, accountPeerDiscovery);
out << YAML::Key << libjami::Account::ConfProperties::ACCOUNT_PEER_DISCOVERY << YAML::Value SERIALIZE_CONFIG(libjami::Account::ConfProperties::ACCOUNT_PUBLISH, accountPublish);
<< accountPeerDiscovery; SERIALIZE_CONFIG(Conf::PROXY_ENABLED_KEY, proxyEnabled);
out << YAML::Key << libjami::Account::ConfProperties::ACCOUNT_PUBLISH << YAML::Value SERIALIZE_CONFIG(Conf::PROXY_SERVER_KEY, proxyServer);
<< accountPublish; SERIALIZE_CONFIG(libjami::Account::ConfProperties::DHT_PROXY_LIST_URL, proxyListUrl);
SERIALIZE_CONFIG(libjami::Account::ConfProperties::RingNS::URI, nameServer);
out << YAML::Key << Conf::PROXY_ENABLED_KEY << YAML::Value << proxyEnabled; SERIALIZE_CONFIG(libjami::Account::VolatileProperties::REGISTERED_NAME, registeredName);
out << YAML::Key << Conf::PROXY_SERVER_KEY << YAML::Value << proxyServer; SERIALIZE_PATH(libjami::Account::ConfProperties::ARCHIVE_PATH, archivePath);
out << YAML::Key << libjami::Account::ConfProperties::DHT_PROXY_LIST_URL << YAML::Value SERIALIZE_CONFIG(libjami::Account::ConfProperties::ARCHIVE_HAS_PASSWORD, archiveHasPassword);
<< proxyListUrl; SERIALIZE_CONFIG(libjami::Account::ConfProperties::DEVICE_NAME, deviceName);
SERIALIZE_CONFIG(libjami::Account::ConfProperties::MANAGER_URI, managerUri);
#if HAVE_RINGNS SERIALIZE_CONFIG(libjami::Account::ConfProperties::MANAGER_USERNAME, managerUsername);
out << YAML::Key << libjami::Account::ConfProperties::RingNS::URI << YAML::Value << nameServer;
if (not registeredName.empty())
out << YAML::Key << libjami::Account::VolatileProperties::REGISTERED_NAME << YAML::Value
<< registeredName;
#endif
out << YAML::Key << libjami::Account::ConfProperties::ARCHIVE_PATH << YAML::Value << fileutils::getCleanPath(path, archivePath);
out << YAML::Key << libjami::Account::ConfProperties::ARCHIVE_HAS_PASSWORD << YAML::Value
<< archiveHasPassword;
out << YAML::Key << Conf::RING_ACCOUNT_RECEIPT << YAML::Value << receipt; out << YAML::Key << Conf::RING_ACCOUNT_RECEIPT << YAML::Value << receipt;
if (receiptSignature.size() > 0) if (receiptSignature.size() > 0)
out << YAML::Key << Conf::RING_ACCOUNT_RECEIPT_SIG << YAML::Value out << YAML::Key << Conf::RING_ACCOUNT_RECEIPT_SIG << YAML::Value
<< YAML::Binary(receiptSignature.data(), receiptSignature.size()); << YAML::Binary(receiptSignature.data(), receiptSignature.size());
out << YAML::Key << libjami::Account::ConfProperties::DEVICE_NAME << YAML::Value << deviceName;
out << YAML::Key << libjami::Account::ConfProperties::MANAGER_URI << YAML::Value << managerUri;
out << YAML::Key << libjami::Account::ConfProperties::MANAGER_USERNAME << YAML::Value
<< managerUsername;
// tls submap // tls submap
out << YAML::Key << Conf::TLS_KEY << YAML::Value << YAML::BeginMap; out << YAML::Key << Conf::TLS_KEY << YAML::Value << YAML::BeginMap;
out << YAML::Key << Conf::CALIST_KEY << YAML::Value << fileutils::getCleanPath(path, tlsCaListFile); SERIALIZE_PATH(Conf::CALIST_KEY, tlsCaListFile);
out << YAML::Key << Conf::CERTIFICATE_KEY << YAML::Value << fileutils::getCleanPath(path, tlsCertificateFile);; SERIALIZE_PATH(Conf::CERTIFICATE_KEY, tlsCertificateFile);
out << YAML::Key << Conf::TLS_PASSWORD_KEY << YAML::Value << tlsPassword; SERIALIZE_CONFIG(Conf::TLS_PASSWORD_KEY, tlsPassword);
out << YAML::Key << Conf::PRIVATE_KEY_KEY << YAML::Value << fileutils::getCleanPath(path, tlsPrivateKeyFile);; SERIALIZE_PATH(Conf::PRIVATE_KEY_KEY, tlsPrivateKeyFile);
out << YAML::EndMap; out << YAML::EndMap;
out << YAML::EndMap; out << YAML::EndMap;
...@@ -87,7 +77,6 @@ void ...@@ -87,7 +77,6 @@ void
JamiAccountConfig::unserialize(const YAML::Node& node) JamiAccountConfig::unserialize(const YAML::Node& node)
{ {
using yaml_utils::parseValueOptional; using yaml_utils::parseValueOptional;
using yaml_utils::parsePath;
using yaml_utils::parsePathOptional; using yaml_utils::parsePathOptional;
SipAccountBaseConfig::unserialize(node); SipAccountBaseConfig::unserialize(node);
......
...@@ -70,6 +70,7 @@ constexpr const char* KEY_EXCHANGE_KEY = "keyExchange"; ...@@ -70,6 +70,7 @@ constexpr const char* KEY_EXCHANGE_KEY = "keyExchange";
constexpr const char* RTP_FALLBACK_KEY = "rtpFallback"; constexpr const char* RTP_FALLBACK_KEY = "rtpFallback";
} // namespace Conf } // namespace Conf
static const SipAccountConfig DEFAULT_CONFIG {};
static constexpr unsigned MIN_REGISTRATION_TIME = 60; // seconds static constexpr unsigned MIN_REGISTRATION_TIME = 60; // seconds
using yaml_utils::parseValueOptional; using yaml_utils::parseValueOptional;
...@@ -90,7 +91,7 @@ SipAccountConfig::serialize(YAML::Emitter& out) const ...@@ -90,7 +91,7 @@ SipAccountConfig::serialize(YAML::Emitter& out) const
{ {
out << YAML::BeginMap; out << YAML::BeginMap;
out << YAML::Key << Conf::ID_KEY << YAML::Value << id; out << YAML::Key << Conf::ID_KEY << YAML::Value << id;
SipAccountBaseConfig::serialize(out); SipAccountBaseConfig::serializeDiff(out, DEFAULT_CONFIG);
out << YAML::Key << Conf::BIND_ADDRESS_KEY << YAML::Value << bindAddress; out << YAML::Key << Conf::BIND_ADDRESS_KEY << YAML::Value << bindAddress;
out << YAML::Key << Conf::PORT_KEY << YAML::Value << localPort; out << YAML::Key << Conf::PORT_KEY << YAML::Value << localPort;
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "sipaccountbase_config.h" #include "sipaccountbase_config.h"
#include "account_const.h" #include "account_const.h"
#include "account_schema.h" #include "account_schema.h"
#include "config/yamlparser.h" #include "config/account_config_utils.h"
namespace jami { namespace jami {
...@@ -75,33 +75,24 @@ addRangeToDetails(std::map<std::string, std::string>& a, ...@@ -75,33 +75,24 @@ addRangeToDetails(std::map<std::string, std::string>& a,
} }
void void
SipAccountBaseConfig::serialize(YAML::Emitter& out) const SipAccountBaseConfig::serializeDiff(YAML::Emitter& out, const SipAccountBaseConfig& DEFAULT_CONFIG) const
{ {
AccountConfig::serialize(out); AccountConfig::serializeDiff(out, DEFAULT_CONFIG);
out << YAML::Key << Conf::AUDIO_PORT_MAX_KEY << YAML::Value << audioPortRange.second; SERIALIZE_CONFIG(Conf::DTMF_TYPE_KEY, dtmfType);
out << YAML::Key << Conf::AUDIO_PORT_MIN_KEY << YAML::Value << audioPortRange.first; SERIALIZE_CONFIG(Conf::INTERFACE_KEY, interface);
out << YAML::Key << Conf::DTMF_TYPE_KEY << YAML::Value << dtmfType; SERIALIZE_CONFIG(Conf::PUBLISH_ADDR_KEY, publishedIp);
out << YAML::Key << Conf::INTERFACE_KEY << YAML::Value << interface; SERIALIZE_CONFIG(Conf::SAME_AS_LOCAL_KEY, publishedSameasLocal);
out << YAML::Key << Conf::PUBLISH_ADDR_KEY << YAML::Value << publishedIp; SERIALIZE_CONFIG(Conf::AUDIO_PORT_MAX_KEY, audioPortRange.second);
//out << YAML::Key << Conf::PUBLISH_PORT_KEY << YAML::Value << publishedPort; SERIALIZE_CONFIG(Conf::AUDIO_PORT_MAX_KEY, audioPortRange.first);
out << YAML::Key << Conf::SAME_AS_LOCAL_KEY << YAML::Value << publishedSameasLocal; SERIALIZE_CONFIG(Conf::VIDEO_PORT_MAX_KEY, videoPortRange.second);
SERIALIZE_CONFIG(Conf::VIDEO_PORT_MIN_KEY, videoPortRange.first);
out << YAML::Key << Conf::VIDEO_PORT_MAX_KEY << YAML::Value << videoPortRange.second; SERIALIZE_CONFIG(Conf::TURN_ENABLED_KEY, turnEnabled);
out << YAML::Key << Conf::VIDEO_PORT_MIN_KEY << YAML::Value << videoPortRange.first; SERIALIZE_CONFIG(Conf::TURN_SERVER_KEY, turnServer);
SERIALIZE_CONFIG(Conf::TURN_SERVER_UNAME_KEY, turnServerUserName);
out << YAML::Key << Conf::TURN_ENABLED_KEY << YAML::Value << turnEnabled; SERIALIZE_CONFIG(Conf::TURN_SERVER_PWD_KEY, turnServerPwd);
out << YAML::Key << Conf::TURN_SERVER_KEY << YAML::Value << turnServer; SERIALIZE_CONFIG(Conf::TURN_SERVER_REALM_KEY, turnServerRealm);
out << YAML::Key << Conf::TURN_SERVER_UNAME_KEY << YAML::Value << turnServerUserName;
out << YAML::Key << Conf::TURN_SERVER_PWD_KEY << YAML::Value << turnServerPwd;
out << YAML::Key << Conf::TURN_SERVER_REALM_KEY << YAML::Value << turnServerRealm;
/*out << YAML::Key << Conf::CALIST_KEY << YAML::Value << tlsCaListFile;
out << YAML::Key << Conf::CERTIFICATE_KEY << YAML::Value << tlsCertificateFile;
out << YAML::Key << Conf::TLS_PASSWORD_KEY << YAML::Value << tlsPassword;
out << YAML::Key << Conf::PRIVATE_KEY_KEY << YAML::Value << tlsPrivateKeyFile;*/
} }
void void
SipAccountBaseConfig::unserialize(const YAML::Node& node) SipAccountBaseConfig::unserialize(const YAML::Node& node)
{ {
......
...@@ -26,7 +26,7 @@ constexpr static unsigned HALF_MAX_PORT {MAX_PORT / 2}; ...@@ -26,7 +26,7 @@ constexpr static unsigned HALF_MAX_PORT {MAX_PORT / 2};
struct SipAccountBaseConfig: public AccountConfig { struct SipAccountBaseConfig: public AccountConfig {
SipAccountBaseConfig(const std::string& type, const std::string& id, const std::string& path): AccountConfig(type, id, path) {} SipAccountBaseConfig(const std::string& type, const std::string& id, const std::string& path): AccountConfig(type, id, path) {}
void serialize(YAML::Emitter& out) const override; void serializeDiff(YAML::Emitter& out, const SipAccountBaseConfig& def) const;
void unserialize(const YAML::Node& node) override; void unserialize(const YAML::Node& node) override;
std::map<std::string, std::string> toMap() const override; std::map<std::string, std::string> toMap() const override;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment