Line data Source code
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 "account_config.h"
18 : #include "account_const.h"
19 : #include "account_schema.h"
20 : #include "string_utils.h"
21 : #include "fileutils.h"
22 : #include "config/account_config_utils.h"
23 :
24 : #include <fmt/compile.h>
25 : #include <fmt/ranges.h>
26 :
27 : namespace jami {
28 :
29 : constexpr const char* RINGTONE_PATH_KEY = "ringtonePath";
30 : constexpr const char* RINGTONE_ENABLED_KEY = "ringtoneEnabled";
31 : constexpr const char* VIDEO_ENABLED_KEY = "videoEnabled";
32 : constexpr const char* DISPLAY_NAME_KEY = "displayName";
33 : constexpr const char* ALIAS_KEY = "alias";
34 : constexpr const char* TYPE_KEY = "type";
35 : constexpr const char* AUTHENTICATION_USERNAME_KEY = "authenticationUsername";
36 : constexpr const char* USERNAME_KEY = "username";
37 : constexpr const char* PASSWORD_KEY = "password";
38 : constexpr const char* HOSTNAME_KEY = "hostname";
39 : constexpr const char* ACCOUNT_ENABLE_KEY = "enable";
40 : constexpr const char* ACCOUNT_AUTOANSWER_KEY = "autoAnswer";
41 : constexpr const char* DENY_SECOND_CALL_KEY = "denySecondCall";
42 : constexpr const char* ACCOUNT_READRECEIPT_KEY = "sendReadReceipt";
43 : constexpr const char* ACCOUNT_COMPOSING_KEY = "sendComposing";
44 : constexpr const char* ACCOUNT_ISRENDEZVOUS_KEY = "rendezVous";
45 : constexpr const char* ACCOUNT_ACTIVE_CALL_LIMIT_KEY = "activeCallLimit";
46 : constexpr const char* MAILBOX_KEY = "mailbox";
47 : constexpr const char* USER_AGENT_KEY = "useragent";
48 : constexpr const char* HAS_CUSTOM_USER_AGENT_KEY = "hasCustomUserAgent";
49 : constexpr const char* UPNP_ENABLED_KEY = "upnpEnabled";
50 : constexpr const char* ACTIVE_CODEC_KEY = "activeCodecs";
51 : constexpr const char* DEFAULT_MODERATORS_KEY = "defaultModerators";
52 : constexpr const char* LOCAL_MODERATORS_ENABLED_KEY = "localModeratorsEnabled";
53 : constexpr const char* ALL_MODERATORS_ENABLED_KEY = "allModeratorsEnabled";
54 : constexpr const char* PROXY_PUSH_TOKEN_KEY = "proxyPushToken";
55 : constexpr const char* PROXY_PUSH_PLATFORM_KEY = "proxyPushPlatform";
56 : constexpr const char* PROXY_PUSH_TOPIC_KEY = "proxyPushiOSTopic";
57 : constexpr const char* UI_CUSTOMIZATION = "uiCustomization";
58 :
59 : using yaml_utils::parseValueOptional;
60 :
61 : void
62 2288 : AccountConfig::serializeDiff(YAML::Emitter& out, const AccountConfig& DEFAULT_CONFIG) const
63 : {
64 2288 : SERIALIZE_CONFIG(ACCOUNT_ENABLE_KEY, enabled);
65 2288 : SERIALIZE_CONFIG(TYPE_KEY, type);
66 2288 : SERIALIZE_CONFIG(ALIAS_KEY, alias);
67 2288 : SERIALIZE_CONFIG(HOSTNAME_KEY, hostname);
68 2288 : SERIALIZE_CONFIG(USERNAME_KEY, username);
69 2288 : SERIALIZE_CONFIG(MAILBOX_KEY, mailbox);
70 : out << YAML::Key << ACTIVE_CODEC_KEY << YAML::Value
71 9152 : << fmt::format(FMT_COMPILE("{}"), fmt::join(activeCodecs, "/"));
72 2288 : SERIALIZE_CONFIG(ACCOUNT_AUTOANSWER_KEY, autoAnswerEnabled);
73 2288 : SERIALIZE_CONFIG(DENY_SECOND_CALL_KEY, denySecondCallEnabled);
74 2288 : SERIALIZE_CONFIG(ACCOUNT_READRECEIPT_KEY, sendReadReceipt);
75 2288 : SERIALIZE_CONFIG(ACCOUNT_COMPOSING_KEY, sendComposing);
76 2288 : SERIALIZE_CONFIG(ACCOUNT_ISRENDEZVOUS_KEY, isRendezVous);
77 2288 : SERIALIZE_CONFIG(ACCOUNT_ACTIVE_CALL_LIMIT_KEY, activeCallLimit);
78 2288 : SERIALIZE_CONFIG(RINGTONE_ENABLED_KEY, ringtoneEnabled);
79 2288 : SERIALIZE_CONFIG(RINGTONE_PATH_KEY, ringtonePath);
80 2288 : SERIALIZE_CONFIG(USER_AGENT_KEY, customUserAgent);
81 2288 : SERIALIZE_CONFIG(DISPLAY_NAME_KEY, displayName);
82 2288 : SERIALIZE_CONFIG(UPNP_ENABLED_KEY, upnpEnabled);
83 : out << YAML::Key << DEFAULT_MODERATORS_KEY << YAML::Value
84 9152 : << fmt::format(FMT_COMPILE("{}"), fmt::join(defaultModerators, "/"));
85 2288 : SERIALIZE_CONFIG(LOCAL_MODERATORS_ENABLED_KEY, localModeratorsEnabled);
86 2288 : SERIALIZE_CONFIG(ALL_MODERATORS_ENABLED_KEY, allModeratorsEnabled);
87 2288 : SERIALIZE_CONFIG(PROXY_PUSH_TOKEN_KEY, deviceKey);
88 2288 : SERIALIZE_CONFIG(PROXY_PUSH_PLATFORM_KEY, platform);
89 2288 : SERIALIZE_CONFIG(PROXY_PUSH_TOPIC_KEY, notificationTopic);
90 2288 : SERIALIZE_CONFIG(VIDEO_ENABLED_KEY, videoEnabled);
91 2288 : SERIALIZE_CONFIG(UI_CUSTOMIZATION, uiCustomization);
92 2288 : }
93 :
94 : void
95 0 : AccountConfig::unserialize(const YAML::Node& node)
96 : {
97 0 : parseValueOptional(node, ALIAS_KEY, alias);
98 : // parseValueOptional(node, TYPE_KEY, type);
99 0 : parseValueOptional(node, ACCOUNT_ENABLE_KEY, enabled);
100 0 : parseValueOptional(node, HOSTNAME_KEY, hostname);
101 0 : parseValueOptional(node, ACCOUNT_AUTOANSWER_KEY, autoAnswerEnabled);
102 0 : parseValueOptional(node, DENY_SECOND_CALL_KEY, denySecondCallEnabled);
103 0 : parseValueOptional(node, ACCOUNT_READRECEIPT_KEY, sendReadReceipt);
104 0 : parseValueOptional(node, ACCOUNT_COMPOSING_KEY, sendComposing);
105 0 : parseValueOptional(node, ACCOUNT_ISRENDEZVOUS_KEY, isRendezVous);
106 0 : parseValueOptional(node, ACCOUNT_ACTIVE_CALL_LIMIT_KEY, activeCallLimit);
107 0 : parseValueOptional(node, MAILBOX_KEY, mailbox);
108 :
109 0 : std::string codecs;
110 0 : if (parseValueOptional(node, ACTIVE_CODEC_KEY, codecs))
111 0 : activeCodecs = split_string_to_unsigned(codecs, '/');
112 :
113 0 : parseValueOptional(node, DISPLAY_NAME_KEY, displayName);
114 :
115 0 : parseValueOptional(node, USER_AGENT_KEY, customUserAgent);
116 0 : parseValueOptional(node, RINGTONE_PATH_KEY, ringtonePath);
117 0 : parseValueOptional(node, RINGTONE_ENABLED_KEY, ringtoneEnabled);
118 0 : parseValueOptional(node, VIDEO_ENABLED_KEY, videoEnabled);
119 :
120 0 : parseValueOptional(node, UPNP_ENABLED_KEY, upnpEnabled);
121 :
122 0 : std::string defMod;
123 0 : parseValueOptional(node, DEFAULT_MODERATORS_KEY, defMod);
124 0 : defaultModerators = string_split_set(defMod);
125 0 : parseValueOptional(node, LOCAL_MODERATORS_ENABLED_KEY, localModeratorsEnabled);
126 0 : parseValueOptional(node, ALL_MODERATORS_ENABLED_KEY, allModeratorsEnabled);
127 0 : parseValueOptional(node, PROXY_PUSH_TOKEN_KEY, deviceKey);
128 0 : parseValueOptional(node, PROXY_PUSH_PLATFORM_KEY, platform);
129 0 : parseValueOptional(node, PROXY_PUSH_TOPIC_KEY, notificationTopic);
130 0 : parseValueOptional(node, UI_CUSTOMIZATION, uiCustomization);
131 0 : }
132 :
133 : std::map<std::string, std::string>
134 629 : AccountConfig::toMap() const
135 : {
136 629 : return {{Conf::CONFIG_ACCOUNT_ALIAS, alias},
137 629 : {Conf::CONFIG_ACCOUNT_DISPLAYNAME, displayName},
138 629 : {Conf::CONFIG_ACCOUNT_ENABLE, enabled ? TRUE_STR : FALSE_STR},
139 629 : {Conf::CONFIG_ACCOUNT_TYPE, type},
140 629 : {Conf::CONFIG_ACCOUNT_USERNAME, username},
141 629 : {Conf::CONFIG_ACCOUNT_HOSTNAME, hostname},
142 629 : {Conf::CONFIG_ACCOUNT_MAILBOX, mailbox},
143 629 : {Conf::CONFIG_ACCOUNT_USERAGENT, customUserAgent},
144 629 : {Conf::CONFIG_ACCOUNT_AUTOANSWER, autoAnswerEnabled ? TRUE_STR : FALSE_STR},
145 629 : {Conf::CONFIG_ACCOUNT_DENY_SECOND_CALL, denySecondCallEnabled ? TRUE_STR : FALSE_STR},
146 629 : {Conf::CONFIG_ACCOUNT_SENDREADRECEIPT, sendReadReceipt ? TRUE_STR : FALSE_STR},
147 629 : {Conf::CONFIG_ACCOUNT_SENDCOMPOSING, sendComposing ? TRUE_STR : FALSE_STR},
148 629 : {Conf::CONFIG_ACCOUNT_ISRENDEZVOUS, isRendezVous ? TRUE_STR : FALSE_STR},
149 1258 : {libjami::Account::ConfProperties::ACTIVE_CALL_LIMIT, std::to_string(activeCallLimit)},
150 629 : {Conf::CONFIG_RINGTONE_ENABLED, ringtoneEnabled ? TRUE_STR : FALSE_STR},
151 629 : {Conf::CONFIG_RINGTONE_PATH, ringtonePath},
152 629 : {Conf::CONFIG_VIDEO_ENABLED, videoEnabled ? TRUE_STR : FALSE_STR},
153 629 : {Conf::CONFIG_UPNP_ENABLED, upnpEnabled ? TRUE_STR : FALSE_STR},
154 1258 : {Conf::CONFIG_DEFAULT_MODERATORS, string_join(defaultModerators)},
155 629 : {Conf::CONFIG_LOCAL_MODERATORS_ENABLED, localModeratorsEnabled ? TRUE_STR : FALSE_STR},
156 629 : {Conf::CONFIG_ALL_MODERATORS_ENABLED, allModeratorsEnabled ? TRUE_STR : FALSE_STR},
157 23273 : {Conf::CONFIG_ACCOUNT_UICUSTOMIZATION, uiCustomization}};
158 : }
159 :
160 : void
161 1301 : AccountConfig::fromMap(const std::map<std::string, std::string>& details)
162 : {
163 1301 : parseString(details, Conf::CONFIG_ACCOUNT_ALIAS, alias);
164 1301 : parseString(details, Conf::CONFIG_ACCOUNT_DISPLAYNAME, displayName);
165 1301 : parseBool(details, Conf::CONFIG_ACCOUNT_ENABLE, enabled);
166 1301 : parseBool(details, Conf::CONFIG_VIDEO_ENABLED, videoEnabled);
167 1301 : parseString(details, Conf::CONFIG_ACCOUNT_HOSTNAME, hostname);
168 1301 : parseString(details, Conf::CONFIG_ACCOUNT_MAILBOX, mailbox);
169 1301 : parseBool(details, Conf::CONFIG_ACCOUNT_AUTOANSWER, autoAnswerEnabled);
170 1301 : parseBool(details, Conf::CONFIG_ACCOUNT_DENY_SECOND_CALL, denySecondCallEnabled);
171 1301 : parseBool(details, Conf::CONFIG_ACCOUNT_SENDREADRECEIPT, sendReadReceipt);
172 1301 : parseBool(details, Conf::CONFIG_ACCOUNT_SENDCOMPOSING, sendComposing);
173 1301 : parseBool(details, Conf::CONFIG_ACCOUNT_ISRENDEZVOUS, isRendezVous);
174 1301 : parseInt(details, libjami::Account::ConfProperties::ACTIVE_CALL_LIMIT, activeCallLimit);
175 1301 : parseBool(details, Conf::CONFIG_RINGTONE_ENABLED, ringtoneEnabled);
176 1301 : parseString(details, Conf::CONFIG_RINGTONE_PATH, ringtonePath);
177 1301 : parseString(details, Conf::CONFIG_ACCOUNT_USERAGENT, customUserAgent);
178 1301 : parseBool(details, Conf::CONFIG_UPNP_ENABLED, upnpEnabled);
179 1301 : std::string defMod;
180 1301 : parseString(details, Conf::CONFIG_DEFAULT_MODERATORS, defMod);
181 1301 : defaultModerators = string_split_set(defMod);
182 1301 : parseBool(details, Conf::CONFIG_LOCAL_MODERATORS_ENABLED, localModeratorsEnabled);
183 1301 : parseBool(details, Conf::CONFIG_ALL_MODERATORS_ENABLED, allModeratorsEnabled);
184 :
185 1301 : parseString(details, libjami::Account::ConfProperties::PROXY_PUSH_TOKEN, deviceKey);
186 1301 : parseString(details, PROXY_PUSH_PLATFORM_KEY, platform);
187 1301 : parseString(details, PROXY_PUSH_TOPIC_KEY, notificationTopic);
188 :
189 1301 : parseString(details, Conf::CONFIG_ACCOUNT_UICUSTOMIZATION, uiCustomization);
190 1301 : }
191 :
192 : void
193 3903 : parsePath(const std::map<std::string, std::string>& details,
194 : const char* key,
195 : std::string& s,
196 : const std::filesystem::path& base)
197 : {
198 3903 : auto it = details.find(key);
199 3903 : if (it != details.end())
200 1978 : s = fileutils::getFullPath(base, it->second).string();
201 3903 : }
202 :
203 : } // namespace jami
|