Ring Daemon 16.0.0
Loading...
Searching...
No Matches
jamiaccount_config.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#include "jamiaccount_config.h"
18#include "account_const.h"
19#include "account_schema.h"
20#include "configkeys.h"
21#include "fileutils.h"
23
24namespace jami {
25
26namespace Conf {
27constexpr const char* const TLS_KEY = "tls";
28constexpr const char* CERTIFICATE_KEY = "certificate";
29constexpr const char* CALIST_KEY = "calist";
30const char* const TLS_PASSWORD_KEY = "password";
31const char* const PRIVATE_KEY_KEY = "privateKey";
32} // namespace Conf
33
35
36void
37JamiAccountConfig::serialize(YAML::Emitter& out) const
38{
39 out << YAML::BeginMap;
61
62 out << YAML::Key << Conf::RING_ACCOUNT_RECEIPT << YAML::Value << receipt;
63 if (receiptSignature.size() > 0)
64 out << YAML::Key << Conf::RING_ACCOUNT_RECEIPT_SIG << YAML::Value
65 << YAML::Binary(receiptSignature.data(), receiptSignature.size());
66
67 // tls submap
68 out << YAML::Key << Conf::TLS_KEY << YAML::Value << YAML::BeginMap;
73 out << YAML::EndMap;
74
75 out << YAML::EndMap;
76}
77
78void
79JamiAccountConfig::unserialize(const YAML::Node& node)
80{
84
85 // get tls submap
86 try {
87 const auto& tlsMap = node[Conf::TLS_KEY];
89 parsePathOptional(tlsMap, Conf::CALIST_KEY, tlsCaListFile, path);
90 parseValueOptional(tlsMap, Conf::TLS_PASSWORD_KEY, tlsPassword);
92 } catch (...) {
93 }
94 parseValueOptional(node, Conf::DHT_PORT_KEY, dhtPort);
98
99 parseValueOptional(node, Conf::PROXY_ENABLED_KEY, proxyEnabled);
100 parseValueOptional(node, Conf::PROXY_SERVER_KEY, proxyServer);
103
107 parseValueOptional(node,
110
112 parseValueOptional(node,
115
116 try {
117 parseValueOptional(node, Conf::RING_ACCOUNT_RECEIPT, receipt);
118 auto receipt_sig = node[Conf::RING_ACCOUNT_RECEIPT_SIG].as<YAML::Binary>();
119 receiptSignature = {receipt_sig.data(), receipt_sig.data() + receipt_sig.size()};
120 } catch (const std::exception& e) {
121 JAMI_WARN("Unable to read receipt: %s", e.what());
122 }
123
125 parseValueOptional(node,
131 parseValueOptional(node, Conf::DHT_PUBLIC_IN_CALLS, allowPublicIncoming);
132}
133
134std::map<std::string, std::string>
136{
137 std::map<std::string, std::string> a = SipAccountBaseConfig::toMap();
138 a.emplace(Conf::CONFIG_DHT_PORT, std::to_string(dhtPort));
148 if (not archivePath.empty() or not managerUri.empty())
151
173#if HAVE_RINGNS
175#endif
176 return a;
177}
178
179void
180JamiAccountConfig::fromMap(const std::map<std::string, std::string>& details)
181{
183 // TLS
188
189 if (hostname.empty())
208
212 // parseString(details, libjami::Account::ConfProperties::USERNAME, username);
213
221 std::transform(credentials.archive_pin.begin(),
223 credentials.archive_pin.begin(),
224 ::toupper);
228
235 if (not managerUri.empty() and managerUri.rfind("http", 0) != 0) {
236 managerUri = "https://" + managerUri;
237 }
238
239#if HAVE_RINGNS
241#endif
242}
243
244} // namespace jami
#define SERIALIZE_PATH(key, name)
#define SERIALIZE_CONFIG(key, name)
Account specific keys/constants that must be shared in daemon and clients.
#define JAMI_WARN(...)
Definition logger.h:217
constexpr const char *const DHT_PUBLIC_IN_CALLS
Definition configkeys.h:26
constexpr const char * CALIST_KEY
const char *const TLS_PASSWORD_KEY
constexpr const char *const RING_ACCOUNT_RECEIPT
Definition configkeys.h:36
constexpr const char *const PROXY_ENABLED_KEY
Definition configkeys.h:42
constexpr const char *const DHT_ALLOW_PEERS_FROM_TRUSTED
Definition configkeys.h:29
static const char *const CONFIG_TLS_CERTIFICATE_FILE
constexpr const char *const TLS_KEY
static const char *const CONFIG_DHT_PUBLIC_IN_CALLS
static const char *const CONFIG_TLS_PASSWORD
static const char *const CONFIG_TLS_PRIVATE_KEY_FILE
constexpr const char *const DHT_ALLOW_PEERS_FROM_CONTACT
Definition configkeys.h:28
const char *const PRIVATE_KEY_KEY
constexpr const char *const PROXY_SERVER_KEY
Definition configkeys.h:43
constexpr const char * CERTIFICATE_KEY
constexpr const char *const RING_ACCOUNT_RECEIPT_SIG
Definition configkeys.h:37
static const char *const CONFIG_DHT_PORT
constexpr const char *const DHT_PORT_KEY
Definition configkeys.h:22
static const char *const CONFIG_TLS_CA_LIST_FILE
constexpr const char *const DHT_ALLOW_PEERS_FROM_HISTORY
Definition configkeys.h:27
std::filesystem::path getFullPath(const std::filesystem::path &base, const std::filesystem::path &path)
If path is relative, it is appended to base.
void parsePathOptional(const YAML::Node &node, const char *key, std::string &path, const std::filesystem::path &base)
bool parseValueOptional(const YAML::Node &node, const char *key, T &value)
Definition yamlparser.h:38
void parseBool(const std::map< std::string, std::string > &details, const char *key, bool &s)
static constexpr const char TRUE_STR[]
void emitSignal(Args... args)
Definition ring_signal.h:64
void parseInt(const std::map< std::string, std::string > &details, const char *key, T &s)
static constexpr const char *const DHT_DEFAULT_BOOTSTRAP
static constexpr const char FALSE_STR[]
void parseString(const std::map< std::string, std::string > &details, const char *key, std::string &s)
void parsePath(const std::map< std::string, std::string > &details, const char *key, std::string &s, const std::filesystem::path &base)
static const JamiAccountConfig DEFAULT_CONFIG
static constexpr const char PUBLIC_IN_CALLS[]
static constexpr const char SUPPORT_SUBSCRIBE[]
static constexpr const char URI[]
static constexpr const char ACCOUNT_PEER_DISCOVERY[]
static constexpr const char ALLOW_CERT_FROM_TRUSTED[]
static constexpr const char ARCHIVE_HAS_PASSWORD[]
static constexpr const char DHT_PEER_DISCOVERY[]
static constexpr const char ALLOW_CERT_FROM_CONTACT[]
static constexpr const char DHT_PROXY_LIST_URL[]
static constexpr const char UI_CUSTOMIZATION[]
static constexpr const char PROXY_SERVER[]
static constexpr const char DEVICE_NAME[]
static constexpr const char ARCHIVE_PASSWORD[]
static constexpr const char ARCHIVE_PATH[]
static constexpr const char MANAGER_URI[]
static constexpr const char ALLOW_CERT_FROM_HISTORY[]
static constexpr const char PROXY_ENABLED[]
static constexpr const char BOOTSTRAP_LIST_URL[]
static constexpr const char PROXY_LIST_ENABLED[]
static constexpr const char ACCOUNT_PUBLISH[]
static constexpr const char MANAGER_USERNAME[]
static constexpr const char ARCHIVE_PIN[]
static constexpr const char ARCHIVE_PASSWORD_SCHEME[]
static constexpr const char ARCHIVE_URL[]
static constexpr const char REGISTERED_NAME[]
std::string hostname
SIP hostname (SIP account) or DHT bootstrap nodes (Jami account)
std::string uiCustomization
information about the customization of ui
const std::filesystem::path path
Path where the configuration file is stored.
std::map< std::string, std::string > toMap() const override
void serialize(YAML::Emitter &out) const override
std::vector< uint8_t > receiptSignature
void unserialize(const YAML::Node &node) override
void fromMap(const std::map< std::string, std::string > &) override
struct jami::JamiAccountConfig::Credentials credentials
void fromMap(const std::map< std::string, std::string > &) override
void serializeDiff(YAML::Emitter &out, const SipAccountBaseConfig &def) const
void unserialize(const YAML::Node &node) override
std::map< std::string, std::string > toMap() const override