Line data Source code
1 : /*
2 : * Copyright (C) 2004-2024 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 "sipaccountbase_config.h"
18 : #include "account_const.h"
19 : #include "account_schema.h"
20 : #include "config/account_config_utils.h"
21 :
22 : namespace jami {
23 :
24 : namespace Conf {
25 : // SIP specific configuration keys
26 : const char* const BIND_ADDRESS_KEY = "bindAddress";
27 : const char* const INTERFACE_KEY = "interface";
28 : const char* const PORT_KEY = "port";
29 : const char* const PUBLISH_ADDR_KEY = "publishAddr";
30 : const char* const PUBLISH_PORT_KEY = "publishPort";
31 : const char* const SAME_AS_LOCAL_KEY = "sameasLocal";
32 : const char* const DTMF_TYPE_KEY = "dtmfType";
33 : const char* const SERVICE_ROUTE_KEY = "serviceRoute";
34 : const char* const ALLOW_IP_AUTO_REWRITE = "allowIPAutoRewrite";
35 : const char* const PRESENCE_ENABLED_KEY = "presenceEnabled";
36 : const char* const PRESENCE_PUBLISH_SUPPORTED_KEY = "presencePublishSupported";
37 : const char* const PRESENCE_SUBSCRIBE_SUPPORTED_KEY = "presenceSubscribeSupported";
38 : const char* const PRESENCE_STATUS_KEY = "presenceStatus";
39 : const char* const PRESENCE_NOTE_KEY = "presenceNote";
40 : const char* const STUN_ENABLED_KEY = "stunEnabled";
41 : const char* const STUN_SERVER_KEY = "stunServer";
42 : const char* const TURN_ENABLED_KEY = "turnEnabled";
43 : const char* const TURN_SERVER_KEY = "turnServer";
44 : const char* const TURN_SERVER_UNAME_KEY = "turnServerUserName";
45 : const char* const TURN_SERVER_PWD_KEY = "turnServerPassword";
46 : const char* const TURN_SERVER_REALM_KEY = "turnServerRealm";
47 : const char* const CRED_KEY = "credential";
48 : const char* const AUDIO_PORT_MIN_KEY = "audioPortMin";
49 : const char* const AUDIO_PORT_MAX_KEY = "audioPortMax";
50 : const char* const VIDEO_PORT_MIN_KEY = "videoPortMin";
51 : const char* const VIDEO_PORT_MAX_KEY = "videoPortMax";
52 : } // namespace Conf
53 :
54 : using yaml_utils::parseValueOptional;
55 :
56 : static void
57 0 : unserializeRange(const YAML::Node& node,
58 : const char* minKey,
59 : const char* maxKey,
60 : std::pair<uint16_t, uint16_t>& range)
61 : {
62 0 : int tmpMin = yaml_utils::parseValueOptional(node, minKey, tmpMin);
63 0 : int tmpMax = yaml_utils::parseValueOptional(node, maxKey, tmpMax);
64 0 : updateRange(tmpMin, tmpMax, range);
65 0 : }
66 :
67 : static void
68 1380 : addRangeToDetails(std::map<std::string, std::string>& a,
69 : const char* minKey,
70 : const char* maxKey,
71 : const std::pair<uint16_t, uint16_t>& range)
72 : {
73 1380 : a.emplace(minKey, std::to_string(range.first));
74 1380 : a.emplace(maxKey, std::to_string(range.second));
75 1380 : }
76 :
77 : void
78 2803 : SipAccountBaseConfig::serializeDiff(YAML::Emitter& out, const SipAccountBaseConfig& DEFAULT_CONFIG) const
79 : {
80 2803 : AccountConfig::serializeDiff(out, DEFAULT_CONFIG);
81 2803 : SERIALIZE_CONFIG(Conf::DTMF_TYPE_KEY, dtmfType);
82 2803 : SERIALIZE_CONFIG(Conf::INTERFACE_KEY, interface);
83 2803 : SERIALIZE_CONFIG(Conf::PUBLISH_ADDR_KEY, publishedIp);
84 2803 : SERIALIZE_CONFIG(Conf::SAME_AS_LOCAL_KEY, publishedSameasLocal);
85 2803 : SERIALIZE_CONFIG(Conf::AUDIO_PORT_MAX_KEY, audioPortRange.second);
86 2803 : SERIALIZE_CONFIG(Conf::AUDIO_PORT_MAX_KEY, audioPortRange.first);
87 2803 : SERIALIZE_CONFIG(Conf::VIDEO_PORT_MAX_KEY, videoPortRange.second);
88 2803 : SERIALIZE_CONFIG(Conf::VIDEO_PORT_MIN_KEY, videoPortRange.first);
89 2803 : SERIALIZE_CONFIG(Conf::TURN_ENABLED_KEY, turnEnabled);
90 2803 : SERIALIZE_CONFIG(Conf::TURN_SERVER_KEY, turnServer);
91 2803 : SERIALIZE_CONFIG(Conf::TURN_SERVER_UNAME_KEY, turnServerUserName);
92 2803 : SERIALIZE_CONFIG(Conf::TURN_SERVER_PWD_KEY, turnServerPwd);
93 2803 : SERIALIZE_CONFIG(Conf::TURN_SERVER_REALM_KEY, turnServerRealm);
94 2803 : }
95 :
96 : void
97 0 : SipAccountBaseConfig::unserialize(const YAML::Node& node)
98 : {
99 0 : AccountConfig::unserialize(node);
100 0 : parseValueOptional(node, Conf::INTERFACE_KEY, interface);
101 0 : parseValueOptional(node, Conf::SAME_AS_LOCAL_KEY, publishedSameasLocal);
102 0 : parseValueOptional(node, Conf::PUBLISH_ADDR_KEY, publishedIp);
103 0 : parseValueOptional(node, Conf::DTMF_TYPE_KEY, dtmfType);
104 0 : unserializeRange(node, Conf::AUDIO_PORT_MIN_KEY, Conf::AUDIO_PORT_MAX_KEY, audioPortRange);
105 0 : unserializeRange(node, Conf::VIDEO_PORT_MIN_KEY, Conf::VIDEO_PORT_MAX_KEY, videoPortRange);
106 :
107 : // ICE - STUN/TURN
108 : //parseValueOptional(node, Conf::STUN_ENABLED_KEY, stunEnabled);
109 : //parseValueOptional(node, Conf::STUN_SERVER_KEY, stunServer);
110 0 : parseValueOptional(node, Conf::TURN_ENABLED_KEY, turnEnabled);
111 0 : parseValueOptional(node, Conf::TURN_SERVER_KEY, turnServer);
112 0 : parseValueOptional(node, Conf::TURN_SERVER_UNAME_KEY, turnServerUserName);
113 0 : parseValueOptional(node, Conf::TURN_SERVER_PWD_KEY, turnServerPwd);
114 0 : parseValueOptional(node, Conf::TURN_SERVER_REALM_KEY, turnServerRealm);
115 0 : }
116 :
117 : std::map<std::string, std::string>
118 690 : SipAccountBaseConfig::toMap() const
119 : {
120 690 : auto a = AccountConfig::toMap();
121 :
122 690 : addRangeToDetails(a,
123 : Conf::CONFIG_ACCOUNT_AUDIO_PORT_MIN,
124 : Conf::CONFIG_ACCOUNT_AUDIO_PORT_MAX,
125 690 : audioPortRange);
126 690 : addRangeToDetails(a,
127 : Conf::CONFIG_ACCOUNT_VIDEO_PORT_MIN,
128 : Conf::CONFIG_ACCOUNT_VIDEO_PORT_MAX,
129 690 : videoPortRange);
130 :
131 690 : a.emplace(Conf::CONFIG_ACCOUNT_DTMF_TYPE, dtmfType);
132 690 : a.emplace(Conf::CONFIG_LOCAL_INTERFACE, interface);
133 690 : a.emplace(Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal ? TRUE_STR : FALSE_STR);
134 690 : a.emplace(Conf::CONFIG_PUBLISHED_ADDRESS, publishedIp);
135 :
136 690 : a.emplace(Conf::CONFIG_TURN_ENABLE, turnEnabled ? TRUE_STR : FALSE_STR);
137 690 : a.emplace(Conf::CONFIG_TURN_SERVER, turnServer);
138 690 : a.emplace(Conf::CONFIG_TURN_SERVER_UNAME, turnServerUserName);
139 690 : a.emplace(Conf::CONFIG_TURN_SERVER_PWD, turnServerPwd);
140 690 : a.emplace(Conf::CONFIG_TURN_SERVER_REALM, turnServerRealm);
141 690 : return a;
142 0 : }
143 :
144 : void
145 1606 : SipAccountBaseConfig::fromMap(const std::map<std::string, std::string>& details)
146 : {
147 1606 : AccountConfig::fromMap(details);
148 :
149 : // general sip settings
150 1606 : parseString(details, Conf::CONFIG_LOCAL_INTERFACE, interface);
151 1606 : parseBool(details, Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal);
152 1606 : parseString(details, Conf::CONFIG_PUBLISHED_ADDRESS, publishedIp);
153 1606 : parseString(details, Conf::CONFIG_ACCOUNT_DTMF_TYPE, dtmfType);
154 :
155 1606 : int tmpMin = -1;
156 1606 : parseInt(details, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MIN, tmpMin);
157 1606 : int tmpMax = -1;
158 1606 : parseInt(details, Conf::CONFIG_ACCOUNT_AUDIO_PORT_MAX, tmpMax);
159 1606 : updateRange(tmpMin, tmpMax, audioPortRange);
160 1606 : tmpMin = -1;
161 1606 : parseInt(details, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MIN, tmpMin);
162 1606 : tmpMax = -1;
163 1606 : parseInt(details, Conf::CONFIG_ACCOUNT_VIDEO_PORT_MAX, tmpMax);
164 1606 : updateRange(tmpMin, tmpMax, videoPortRange);
165 :
166 : // ICE - STUN
167 : //parseBool(details, Conf::CONFIG_STUN_ENABLE, stunEnabled);
168 : //parseString(details, Conf::CONFIG_STUN_SERVER, stunServer);
169 :
170 : // ICE - TURN
171 1606 : parseBool(details, Conf::CONFIG_TURN_ENABLE, turnEnabled);
172 1606 : parseString(details, Conf::CONFIG_TURN_SERVER, turnServer);
173 1606 : parseString(details, Conf::CONFIG_TURN_SERVER_UNAME, turnServerUserName);
174 1606 : parseString(details, Conf::CONFIG_TURN_SERVER_PWD, turnServerPwd);
175 1606 : parseString(details, Conf::CONFIG_TURN_SERVER_REALM, turnServerRealm);
176 1606 : }
177 :
178 : }
|