Debian Codegraph @

Xpjproject/pjsip/src/pjsua2/account.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
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 2 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, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #include <pjsua2/account.hpp>
19 #include <pjsua2/endpoint.hpp>
20 #include <pjsua2/presence.hpp>
21 #include <pj/ctype.h>
22 #include "util.hpp"
23
24 using namespace pj;
25 using namespace std;
26
27 #define THIS_FILE "account.cpp"
28
29 ///////////////////////////////////////////////////////////////////////////////
30 // DeferredResponse implementation
31
32 DeferredResponse::DeferredResponse(const OnInstantMessageParam& param)
33 : transaction{pjsip_rdata_get_tsx(static_cast<pjsip_rx_data*>(param.rdata.pjRxData))}
34 {
35 auto status = pjsip_rx_data_clone(static_cast<pjsip_rx_data*>(param.rdata.pjRxData),
36 0, &data);
37 if (status != PJ_SUCCESS) {
38 throw Error(status, "DeferredResponse","Unable to clone rx_data",
39 std::string{}, 0);
40 }
41 }
42
43 DeferredResponse::DeferredResponse() : transaction{nullptr}
44 {
45 }
46
47 DeferredResponse::DeferredResponse(const DeferredResponse& deferredResponse)
48 {
49 transaction = deferredResponse.transaction;
50 auto status = pjsip_rx_data_clone(deferredResponse.data, 0, &data);
51 if (status != PJ_SUCCESS) {
52 throw Error(status, "DeferredResponse","Unable to clone rx_data",
53 std::string{}, 0);
54 }
55 }
56
57 DeferredResponse& DeferredResponse::operator=(const DeferredResponse& deferredResponse)
58 {
59 if (this != &deferredResponse) {
60 transaction = deferredResponse.transaction;
61 if(data) {
62 pjsip_rx_data_free_cloned(data);
63 }
64 auto status = pjsip_rx_data_clone(deferredResponse.data, 0, &data);
65 if (status != PJ_SUCCESS) {
66 throw Error(status, "DeferredResponse","Unable to clone rx_data",
67 std::string{}, 0);
68 }
69 }
70 return *this;
71 }
72
73 DeferredResponse::DeferredResponse(DeferredResponse&& deferredResponse) noexcept
74 : transaction{deferredResponse.transaction}, data{deferredResponse.data}
75 {
76 deferredResponse.data = nullptr;
77 deferredResponse.transaction = nullptr;
78 }
79
80 DeferredResponse& DeferredResponse::operator=(DeferredResponse&& deferredResponse)
81 noexcept
82 {
83 if (this != &deferredResponse) {
84 transaction = deferredResponse.transaction;
85 data = deferredResponse.data;
86 deferredResponse.data = nullptr;
87 deferredResponse.transaction = nullptr;
88 }
89 return *this;
90 }
91
92 DeferredResponse::~DeferredResponse()
93 {
94 if(data) {
95 pjsip_rx_data_free_cloned(data);
96 }
97 }
98
99 ///////////////////////////////////////////////////////////////////////////////
100
101 void RtcpFbCap::fromPj(const pjmedia_rtcp_fb_cap &prm)
102 {
103 this->codecId = pj2Str(prm.codec_id);
104 this->type = prm.type;
105 this->typeName = pj2Str(prm.type_name);
106 this->param = pj2Str(prm.param);
107 }
108
109 pjmedia_rtcp_fb_cap RtcpFbCap::toPj() const
110 {
111 pjmedia_rtcp_fb_cap cap;
112
113 pj_bzero(&cap, sizeof(cap));
114 cap.codec_id = str2Pj(this->codecId);
115 cap.type = this->type;
116 cap.type_name = str2Pj(this->typeName);
117 cap.param = str2Pj(this->param);
118
119 return cap;
120 }
121
122 ///////////////////////////////////////////////////////////////////////////////
123
124 RtcpFbConfig::RtcpFbConfig()
125 {
126 pjmedia_rtcp_fb_setting setting;
127 pjmedia_rtcp_fb_setting_default(&setting);
128 fromPj(setting);
129 }
130
131 void RtcpFbConfig::fromPj(const pjmedia_rtcp_fb_setting &prm)
132 {
133 this->dontUseAvpf = PJ2BOOL(prm.dont_use_avpf);
134 this->caps.clear();
135 for (unsigned i = 0; i < prm.cap_count; ++i) {
136 RtcpFbCap cap;
137 cap.fromPj(prm.caps[i]);
138 this->caps.push_back(PJSUA2_MOVE(cap));
139 }
140 }
141
142 pjmedia_rtcp_fb_setting RtcpFbConfig::toPj() const
143 {
144 pjmedia_rtcp_fb_setting setting;
145
146 pj_bzero(&setting, sizeof(setting));
147 setting.dont_use_avpf = this->dontUseAvpf;
148 setting.cap_count = (unsigned)this->caps.size();
149 for (unsigned i = 0; i < setting.cap_count; ++i) {
150 setting.caps[i] = this->caps[i].toPj();
151 }
152
153 return setting;
154 }
155
156 void RtcpFbConfig::readObject(const ContainerNode &node) PJSUA2_THROW(Error)
157 {
158 ContainerNode this_node = node.readContainer("RtcpFbConfig");
159 NODE_READ_BOOL (this_node, dontUseAvpf);
160
161 ContainerNode cap_node = this_node.readArray("caps");
162 this->caps.clear();
163 while (cap_node.hasUnread()) {
164 RtcpFbCap cap;
165 NODE_READ_STRING (cap_node, cap.codecId);
166 NODE_READ_NUM_T (cap_node, pjmedia_rtcp_fb_type, cap.type);
167 NODE_READ_STRING (cap_node, cap.typeName);
168 NODE_READ_STRING (cap_node, cap.param);
169 this->caps.push_back(PJSUA2_MOVE(cap));
170 }
171 }
172
173 void RtcpFbConfig::writeObject(ContainerNode &node) const PJSUA2_THROW(Error)
174 {
175 ContainerNode this_node = node.writeNewContainer("RtcpFbConfig");
176 NODE_WRITE_BOOL (this_node, dontUseAvpf);
177
178 ContainerNode cap_node = this_node.writeNewArray("caps");
179 for (unsigned i=0; i<this->caps.size(); ++i) {
180 NODE_WRITE_STRING (cap_node, this->caps[i].codecId);
181 NODE_WRITE_NUM_T (cap_node, pjmedia_rtcp_fb_type,
182 this->caps[i].type);
183 NODE_WRITE_STRING (cap_node, this->caps[i].typeName);
184 NODE_WRITE_STRING (cap_node, this->caps[i].param);
185 }
186 }
187
188 ///////////////////////////////////////////////////////////////////////////////
189
190 SendRequestParam::SendRequestParam()
191 : userData(NULL), method("")
192 {
193 }
194
195 ///////////////////////////////////////////////////////////////////////////////
196
197 void SrtpCrypto::fromPj(const pjmedia_srtp_crypto &prm)
198 {
199 this->key = pj2Str(prm.key);
200 this->name = pj2Str(prm.name);
201 this->flags = prm.flags;
202 }
203
204 pjmedia_srtp_crypto SrtpCrypto::toPj() const
205 {
206 pjmedia_srtp_crypto crypto;
207
208 crypto.key = str2Pj(this->key);
209 crypto.name = str2Pj(this->name);
210 crypto.flags = this->flags;
211
212 return crypto;
213 }
214
215 ///////////////////////////////////////////////////////////////////////////////
216
217 SrtpOpt::SrtpOpt()
218 {
219 pjsua_srtp_opt opt;
220 pjsua_srtp_opt_default(&opt);
221 fromPj(opt);
222 }
223
224 void SrtpOpt::fromPj(const pjsua_srtp_opt &prm)
225 {
226 this->cryptos.clear();
227 for (unsigned i = 0; i < prm.crypto_count; ++i) {
228 SrtpCrypto crypto;
229 crypto.fromPj(prm.crypto[i]);
230 this->cryptos.push_back(PJSUA2_MOVE(crypto));
231 }
232
233 this->keyings.clear();
234 for (unsigned i = 0; i < prm.keying_count; ++i) {
235 this->keyings.push_back(prm.keying[i]);
236 }
237 }
238
239 pjsua_srtp_opt SrtpOpt::toPj() const
240 {
241 pjsua_srtp_opt opt;
242
243 pj_bzero(&opt, sizeof(opt));
244
245 opt.crypto_count = (unsigned)this->cryptos.size();
246 for (unsigned i = 0; i < opt.crypto_count; ++i) {
247 opt.crypto[i] = this->cryptos[i].toPj();
248 }
249
250 opt.keying_count = (unsigned)this->keyings.size();
251 for (unsigned i = 0; i < opt.keying_count; ++i) {
252 opt.keying[i] = (pjmedia_srtp_keying_method)this->keyings[i];
253 }
254
255 return opt;
256 }
257
258 void SrtpOpt::readObject(const ContainerNode &node) PJSUA2_THROW(Error)
259 {
260 ContainerNode this_node = node.readContainer("SrtpOpt");
261
262 ContainerNode crypto_node = this_node.readArray("cryptos");
263 this->cryptos.clear();
264 while (crypto_node.hasUnread()) {
265 SrtpCrypto crypto;
266 NODE_READ_STRING (crypto_node, crypto.key);
267 NODE_READ_STRING (crypto_node, crypto.name);
268 NODE_READ_UNSIGNED (crypto_node, crypto.flags);
269 this->cryptos.push_back(PJSUA2_MOVE(crypto));
270 }
271
272 ContainerNode keying_node = this_node.readArray("keyings");
273 this->keyings.clear();
274 while (keying_node.hasUnread()) {
275 unsigned keying;
276 NODE_READ_UNSIGNED (keying_node, keying);
277 this->keyings.push_back(keying);
278 }
279 }
280
281 void SrtpOpt::writeObject(ContainerNode &node) const PJSUA2_THROW(Error)
282 {
283 ContainerNode this_node = node.writeNewContainer("SrtpOpt");
284
285 ContainerNode crypto_node = this_node.writeNewArray("cryptos");
286 for (unsigned i=0; i<this->cryptos.size(); ++i) {
287 NODE_WRITE_STRING (crypto_node, this->cryptos[i].key);
288 NODE_WRITE_STRING (crypto_node, this->cryptos[i].name);
289 NODE_WRITE_UNSIGNED (crypto_node, this->cryptos[i].flags);
290 }
291
292 ContainerNode keying_node = this_node.writeNewArray("keyings");
293 for (unsigned i=0; i<this->keyings.size(); ++i) {
294 NODE_WRITE_UNSIGNED (keying_node, this->keyings[i]);
295 }
296 }
297
298 ///////////////////////////////////////////////////////////////////////////////
299
300 void AccountRegConfig::readObject(const ContainerNode &node)
301 PJSUA2_THROW(Error)
302 {
303 ContainerNode this_node = node.readContainer("AccountRegConfig");
304
305 NODE_READ_STRING (this_node, registrarUri);
306 NODE_READ_BOOL (this_node, registerOnAdd);
307 NODE_READ_UNSIGNED (this_node, timeoutSec);
308 NODE_READ_UNSIGNED (this_node, retryIntervalSec);
309 NODE_READ_UNSIGNED (this_node, firstRetryIntervalSec);
310 NODE_READ_UNSIGNED (this_node, randomRetryIntervalSec);
311 NODE_READ_UNSIGNED (this_node, delayBeforeRefreshSec);
312 NODE_READ_BOOL (this_node, dropCallsOnFail);
313 NODE_READ_UNSIGNED (this_node, unregWaitMsec);
314 NODE_READ_UNSIGNED (this_node, proxyUse);
315 NODE_READ_STRING (this_node, contactParams);
316
317 readSipHeaders(this_node, "headers", headers);
318 }
319
320 void AccountRegConfig::writeObject(ContainerNode &node) const
321 PJSUA2_THROW(Error)
322 {
323 ContainerNode this_node = node.writeNewContainer("AccountRegConfig");
324
325 NODE_WRITE_STRING (this_node, registrarUri);
326 NODE_WRITE_BOOL (this_node, registerOnAdd);
327 NODE_WRITE_UNSIGNED (this_node, timeoutSec);
328 NODE_WRITE_UNSIGNED (this_node, retryIntervalSec);
329 NODE_WRITE_UNSIGNED (this_node, firstRetryIntervalSec);
330 NODE_WRITE_UNSIGNED (this_node, randomRetryIntervalSec);
331 NODE_WRITE_UNSIGNED (this_node, delayBeforeRefreshSec);
332 NODE_WRITE_BOOL (this_node, dropCallsOnFail);
333 NODE_WRITE_UNSIGNED (this_node, unregWaitMsec);
334 NODE_WRITE_UNSIGNED (this_node, proxyUse);
335 NODE_WRITE_STRING (this_node, contactParams);
336
337 writeSipHeaders(this_node, "headers", headers);
338 }
339
340 ///////////////////////////////////////////////////////////////////////////////
341
342 void AccountSipConfig::readObject(const ContainerNode &node)
343 PJSUA2_THROW(Error)
344 {
345 ContainerNode this_node = node.readContainer("AccountSipConfig");
346
347 NODE_READ_STRINGV (this_node, proxies);
348 NODE_READ_STRING (this_node, contactForced);
349 NODE_READ_STRING (this_node, contactParams);
350 NODE_READ_STRING (this_node, contactUriParams);
351 NODE_READ_BOOL (this_node, authInitialEmpty);
352 NODE_READ_STRING (this_node, authInitialAlgorithm);
353 NODE_READ_INT (this_node, transportId);
354 NODE_READ_BOOL (this_node, useSharedAuth);
355 NODE_READ_BOOL (this_node, autoRespondSipMessage);
356
357 ContainerNode creds_node = this_node.readArray("authCreds");
358 authCreds.resize(0);
359 while (creds_node.hasUnread()) {
360 AuthCredInfo cred;
361 cred.readObject(creds_node);
362 authCreds.push_back(PJSUA2_MOVE(cred));
363 }
364 }
365
366 void AccountSipConfig::writeObject(ContainerNode &node) const
367 PJSUA2_THROW(Error)
368 {
369 ContainerNode this_node = node.writeNewContainer("AccountSipConfig");
370
371 NODE_WRITE_STRINGV (this_node, proxies);
372 NODE_WRITE_STRING (this_node, contactForced);
373 NODE_WRITE_STRING (this_node, contactParams);
374 NODE_WRITE_STRING (this_node, contactUriParams);
375 NODE_WRITE_BOOL (this_node, authInitialEmpty);
376 NODE_WRITE_STRING (this_node, authInitialAlgorithm);
377 NODE_WRITE_INT (this_node, transportId);
378 NODE_WRITE_BOOL (this_node, useSharedAuth);
379 NODE_WRITE_BOOL (this_node, autoRespondSipMessage);
380
381 ContainerNode creds_node = this_node.writeNewArray("authCreds");
382 for (unsigned i=0; i<authCreds.size(); ++i) {
383 authCreds[i].writeObject(creds_node);
384 }
385 }
386
387 ///////////////////////////////////////////////////////////////////////////////
388
389 void AccountCallConfig::readObject(const ContainerNode &node)
390 PJSUA2_THROW(Error)
391 {
392 ContainerNode this_node = node.readContainer("AccountCallConfig");
393
394 NODE_READ_NUM_T ( this_node, pjsua_call_hold_type, holdType);
395 NODE_READ_NUM_T ( this_node, pjsua_100rel_use, prackUse);
396 NODE_READ_NUM_T ( this_node, pjsua_sip_timer_use, timerUse);
397 NODE_READ_NUM_T ( this_node, pjsua_sip_siprec_use, siprecUse);
398 NODE_READ_UNSIGNED( this_node, timerMinSESec);
399 NODE_READ_UNSIGNED( this_node, timerSessExpiresSec);
400 }
401
402 void AccountCallConfig::writeObject(ContainerNode &node) const
403 PJSUA2_THROW(Error)
404 {
405 ContainerNode this_node = node.writeNewContainer("AccountCallConfig");
406
407 NODE_WRITE_NUM_T ( this_node, pjsua_call_hold_type, holdType);
408 NODE_WRITE_NUM_T ( this_node, pjsua_100rel_use, prackUse);
409 NODE_WRITE_NUM_T ( this_node, pjsua_sip_timer_use, timerUse);
410 NODE_WRITE_NUM_T ( this_node, pjsua_sip_siprec_use, siprecUse);
411 NODE_WRITE_UNSIGNED( this_node, timerMinSESec);
412 NODE_WRITE_UNSIGNED( this_node, timerSessExpiresSec);
413 }
414
415 ///////////////////////////////////////////////////////////////////////////////
416
417 void AccountPresConfig::readObject(const ContainerNode &node)
418 PJSUA2_THROW(Error)
419 {
420 ContainerNode this_node = node.readContainer("AccountPresConfig");
421
422 NODE_READ_BOOL ( this_node, publishEnabled);
423 NODE_READ_BOOL ( this_node, publishQueue);
424 NODE_READ_UNSIGNED( this_node, publishShutdownWaitMsec);
425 NODE_READ_STRING ( this_node, pidfTupleId);
426
427 readSipHeaders(this_node, "headers", headers);
428 }
429
430 void AccountPresConfig::writeObject(ContainerNode &node) const
431 PJSUA2_THROW(Error)
432 {
433 ContainerNode this_node = node.writeNewContainer("AccountPresConfig");
434
435 NODE_WRITE_BOOL ( this_node, publishEnabled);
436 NODE_WRITE_BOOL ( this_node, publishQueue);
437 NODE_WRITE_UNSIGNED( this_node, publishShutdownWaitMsec);
438 NODE_WRITE_STRING ( this_node, pidfTupleId);
439
440 writeSipHeaders(this_node, "headers", headers);
441 }
442
443 ///////////////////////////////////////////////////////////////////////////////
444
445 void AccountMwiConfig::readObject(const ContainerNode &node)
446 PJSUA2_THROW(Error)
447 {
448 ContainerNode this_node = node.readContainer("AccountMwiConfig");
449
450 NODE_READ_BOOL ( this_node, enabled);
451 NODE_READ_UNSIGNED( this_node, expirationSec);
452 }
453
454 void AccountMwiConfig::writeObject(ContainerNode &node) const
455 PJSUA2_THROW(Error)
456 {
457 ContainerNode this_node = node.writeNewContainer("AccountMwiConfig");
458
459 NODE_WRITE_BOOL ( this_node, enabled);
460 NODE_WRITE_UNSIGNED( this_node, expirationSec);
461 }
462
463 ///////////////////////////////////////////////////////////////////////////////
464
465 void AccountNatConfig::readObject(const ContainerNode &node)
466 PJSUA2_THROW(Error)
467 {
468 ContainerNode this_node = node.readContainer("AccountNatConfig");
469
470 NODE_READ_NUM_T ( this_node, pjsua_stun_use, sipStunUse);
471 NODE_READ_NUM_T ( this_node, pjsua_stun_use, mediaStunUse);
472 NODE_READ_NUM_T ( this_node, pjsua_upnp_use, sipUpnpUse);
473 NODE_READ_NUM_T ( this_node, pjsua_upnp_use, mediaUpnpUse);
474 NODE_READ_NUM_T ( this_node, pjsua_nat64_opt, nat64Opt);
475 NODE_READ_BOOL ( this_node, iceEnabled);
476 NODE_READ_NUM_T ( this_node, pj_ice_sess_trickle, iceTrickle);
477 NODE_READ_INT ( this_node, iceMaxHostCands);
478 NODE_READ_BOOL ( this_node, iceAggressiveNomination);
479 NODE_READ_UNSIGNED( this_node, iceNominatedCheckDelayMsec);
480 NODE_READ_INT ( this_node, iceWaitNominationTimeoutMsec);
481 NODE_READ_INT ( this_node, iceCheckSrcAddr);
482 NODE_READ_BOOL ( this_node, iceNoRtcp);
483 NODE_READ_BOOL ( this_node, iceAlwaysUpdate);
484 NODE_READ_BOOL ( this_node, turnEnabled);
485 NODE_READ_STRING ( this_node, turnServer);
486 NODE_READ_NUM_T ( this_node, pj_turn_tp_type, turnConnType);
487 NODE_READ_STRING ( this_node, turnUserName);
488 NODE_READ_INT ( this_node, turnPasswordType);
489 NODE_READ_STRING ( this_node, turnPassword);
490 NODE_READ_INT ( this_node, contactRewriteUse);
491 NODE_READ_INT ( this_node, contactRewriteMethod);
492 NODE_READ_INT ( this_node, viaRewriteUse);
493 NODE_READ_INT ( this_node, sdpNatRewriteUse);
494 NODE_READ_INT ( this_node, sipOutboundUse);
495 NODE_READ_STRING ( this_node, sipOutboundInstanceId);
496 NODE_READ_STRING ( this_node, sipOutboundRegId);
497 NODE_READ_UNSIGNED( this_node, udpKaIntervalSec);
498 NODE_READ_STRING ( this_node, udpKaData);
499 NODE_READ_INT ( this_node, contactUseSrcPort);
500 NODE_READ_STRINGV ( this_node, iceManualHost);
501 }
502
503 void AccountNatConfig::writeObject(ContainerNode &node) const
504 PJSUA2_THROW(Error)
505 {
506 ContainerNode this_node = node.writeNewContainer("AccountNatConfig");
507
508 NODE_WRITE_NUM_T ( this_node, pjsua_stun_use, sipStunUse);
509 NODE_WRITE_NUM_T ( this_node, pjsua_stun_use, mediaStunUse);
510 NODE_WRITE_NUM_T ( this_node, pjsua_upnp_use, sipUpnpUse);
511 NODE_WRITE_NUM_T ( this_node, pjsua_upnp_use, mediaUpnpUse);
512 NODE_WRITE_NUM_T ( this_node, pjsua_nat64_opt, nat64Opt);
513 NODE_WRITE_BOOL ( this_node, iceEnabled);
514 NODE_WRITE_NUM_T ( this_node, pj_ice_sess_trickle, iceTrickle);
515 NODE_WRITE_INT ( this_node, iceMaxHostCands);
516 NODE_WRITE_BOOL ( this_node, iceAggressiveNomination);
517 NODE_WRITE_UNSIGNED( this_node, iceNominatedCheckDelayMsec);
518 NODE_WRITE_INT ( this_node, iceWaitNominationTimeoutMsec);
519 NODE_WRITE_INT ( this_node, iceCheckSrcAddr);
520 NODE_WRITE_BOOL ( this_node, iceNoRtcp);
521 NODE_WRITE_BOOL ( this_node, iceAlwaysUpdate);
522 NODE_WRITE_BOOL ( this_node, turnEnabled);
523 NODE_WRITE_STRING ( this_node, turnServer);
524 NODE_WRITE_NUM_T ( this_node, pj_turn_tp_type, turnConnType);
525 NODE_WRITE_STRING ( this_node, turnUserName);
526 NODE_WRITE_INT ( this_node, turnPasswordType);
527 NODE_WRITE_STRING ( this_node, turnPassword);
528 NODE_WRITE_INT ( this_node, contactRewriteUse);
529 NODE_WRITE_INT ( this_node, contactRewriteMethod);
530 NODE_WRITE_INT ( this_node, viaRewriteUse);
531 NODE_WRITE_INT ( this_node, sdpNatRewriteUse);
532 NODE_WRITE_INT ( this_node, sipOutboundUse);
533 NODE_WRITE_STRING ( this_node, sipOutboundInstanceId);
534 NODE_WRITE_STRING ( this_node, sipOutboundRegId);
535 NODE_WRITE_UNSIGNED( this_node, udpKaIntervalSec);
536 NODE_WRITE_STRING ( this_node, udpKaData);
537 NODE_WRITE_INT ( this_node, contactUseSrcPort);
538 NODE_WRITE_STRINGV (this_node, iceManualHost);
539 }
540
541 ///////////////////////////////////////////////////////////////////////////////
542
543 void AccountMediaConfig::readObject(const ContainerNode &node)
544 PJSUA2_THROW(Error)
545 {
546 ContainerNode this_node = node.readContainer("AccountMediaConfig");
547
548 NODE_READ_BOOL ( this_node, lockCodecEnabled);
549 NODE_READ_BOOL ( this_node, streamKaEnabled);
550 NODE_READ_NUM_T ( this_node, pjmedia_srtp_use, srtpUse);
551 NODE_READ_INT ( this_node, srtpSecureSignaling);
552 NODE_READ_OBJ ( this_node, srtpOpt);
553 NODE_READ_NUM_T ( this_node, pjsua_ipv6_use, ipv6Use);
554 NODE_READ_OBJ ( this_node, transportConfig);
555 NODE_READ_BOOL ( this_node, rtcpMuxEnabled);
556 NODE_READ_BOOL ( this_node, useLoopMedTp);
557 NODE_READ_BOOL ( this_node, enableLoopback);
558 NODE_READ_BOOL ( this_node, rtcpXrEnabled);
559 }
560
561 void AccountMediaConfig::writeObject(ContainerNode &node) const
562 PJSUA2_THROW(Error)
563 {
564 ContainerNode this_node = node.writeNewContainer("AccountMediaConfig");
565
566 NODE_WRITE_BOOL ( this_node, lockCodecEnabled);
567 NODE_WRITE_BOOL ( this_node, streamKaEnabled);
568 NODE_WRITE_NUM_T ( this_node, pjmedia_srtp_use, srtpUse);
569 NODE_WRITE_INT ( this_node, srtpSecureSignaling);
570 NODE_WRITE_OBJ ( this_node, srtpOpt);
571 NODE_WRITE_NUM_T ( this_node, pjsua_ipv6_use, ipv6Use);
572 NODE_WRITE_OBJ ( this_node, transportConfig);
573 NODE_WRITE_BOOL ( this_node, rtcpMuxEnabled);
574 NODE_WRITE_BOOL ( this_node, useLoopMedTp);
575 NODE_WRITE_BOOL ( this_node, enableLoopback);
576 NODE_WRITE_BOOL ( this_node, rtcpXrEnabled);
577 }
578
579 ///////////////////////////////////////////////////////////////////////////////
580
581 void AccountVideoConfig::readObject(const ContainerNode &node)
582 PJSUA2_THROW(Error)
583 {
584 ContainerNode this_node = node.readContainer("AccountVideoConfig");
585
586 NODE_READ_BOOL ( this_node, autoShowIncoming);
587 NODE_READ_BOOL ( this_node, autoTransmitOutgoing);
588 NODE_READ_UNSIGNED( this_node, windowFlags);
589 NODE_READ_NUM_T ( this_node, pjmedia_vid_dev_index,
590 defaultCaptureDevice);
591 NODE_READ_NUM_T ( this_node, pjmedia_vid_dev_index,
592 defaultRenderDevice);
593 NODE_READ_NUM_T ( this_node, pjmedia_vid_stream_rc_method,
594 rateControlMethod);
595 NODE_READ_UNSIGNED( this_node, rateControlBandwidth);
596 NODE_READ_UNSIGNED( this_node, startKeyframeCount);
597 NODE_READ_UNSIGNED( this_node, startKeyframeInterval);
598 }
599
600 void AccountVideoConfig::writeObject(ContainerNode &node) const
601 PJSUA2_THROW(Error)
602 {
603 ContainerNode this_node = node.writeNewContainer("AccountVideoConfig");
604
605 NODE_WRITE_BOOL ( this_node, autoShowIncoming);
606 NODE_WRITE_BOOL ( this_node, autoTransmitOutgoing);
607 NODE_WRITE_UNSIGNED( this_node, windowFlags);
608 NODE_WRITE_NUM_T ( this_node, pjmedia_vid_dev_index,
609 defaultCaptureDevice);
610 NODE_WRITE_NUM_T ( this_node, pjmedia_vid_dev_index,
611 defaultRenderDevice);
612 NODE_WRITE_NUM_T ( this_node, pjmedia_vid_stream_rc_method,
613 rateControlMethod);
614 NODE_WRITE_UNSIGNED( this_node, rateControlBandwidth);
615 NODE_WRITE_UNSIGNED( this_node, startKeyframeCount);
616 NODE_WRITE_UNSIGNED( this_node, startKeyframeInterval);
617 }
618 ///////////////////////////////////////////////////////////////////////////////
619
620 void AccountTextConfig::readObject(const ContainerNode &node)
621 PJSUA2_THROW(Error)
622 {
623 ContainerNode this_node = node.readContainer("AccountTextConfig");
624
625 NODE_READ_INT ( this_node, redundancyLevel);
626 }
627
628 void AccountTextConfig::writeObject(ContainerNode &node) const
629 PJSUA2_THROW(Error)
630 {
631 ContainerNode this_node = node.writeNewContainer("AccountTextConfig");
632
633 NODE_WRITE_INT ( this_node, redundancyLevel);
634 }
635 ///////////////////////////////////////////////////////////////////////////////
636
637 void AccountIpChangeConfig::readObject(const ContainerNode &node)
638 PJSUA2_THROW(Error)
639 {
640 ContainerNode this_node = node.readContainer("AccountIpChangeConfig");
641
642 NODE_READ_BOOL ( this_node, shutdownTp);
643 NODE_READ_BOOL ( this_node, hangupCalls);
644 NODE_READ_UNSIGNED( this_node, reinviteFlags);
645 }
646
647 void AccountIpChangeConfig::writeObject(ContainerNode &node) const
648 PJSUA2_THROW(Error)
649 {
650 ContainerNode this_node = node.writeNewContainer("AccountIpChangeConfig");
651
652 NODE_WRITE_BOOL ( this_node, shutdownTp);
653 NODE_WRITE_BOOL ( this_node, hangupCalls);
654 NODE_WRITE_UNSIGNED( this_node, reinviteFlags);
655 }
656
657 ///////////////////////////////////////////////////////////////////////////////
658
659 AccountConfig::AccountConfig()
660 {
661 pjsua_acc_config acc_cfg;
662 pjsua_acc_config_default(&acc_cfg);
663 pjsua_media_config med_cfg;
664 pjsua_media_config_default(&med_cfg);
665 fromPj(acc_cfg, &med_cfg);
666 }
667
668 /* Convert to pjsip. */
669 void AccountConfig::toPj(pjsua_acc_config &ret) const
670 {
671 unsigned i;
672
673 pjsua_acc_config_default(&ret);
674
675 // Global
676 ret.priority = priority;
677 ret.id = str2Pj(idUri);
678
679 // AccountRegConfig
680 ret.reg_uri = str2Pj(regConfig.registrarUri);
681 ret.register_on_acc_add = regConfig.registerOnAdd;
682 ret.disable_reg_on_modify = regConfig.disableRegOnModify;
683 ret.reg_timeout = regConfig.timeoutSec;
684 ret.reg_retry_interval = regConfig.retryIntervalSec;
685 ret.reg_first_retry_interval= regConfig.firstRetryIntervalSec;
686 ret.reg_retry_random_interval= regConfig.randomRetryIntervalSec;
687 ret.reg_delay_before_refresh= regConfig.delayBeforeRefreshSec;
688 ret.drop_calls_on_reg_fail = regConfig.dropCallsOnFail;
689 ret.unreg_timeout = regConfig.unregWaitMsec;
690 ret.reg_use_proxy = regConfig.proxyUse;
691 ret.reg_contact_params = str2Pj(regConfig.contactParams);
692 ret.reg_contact_uri_params = str2Pj(regConfig.contactUriParams);
693 for (i=0; i<regConfig.headers.size(); ++i) {
694 pj_list_push_back(&ret.reg_hdr_list, &regConfig.headers[i].toPj());
695 }
696
697 // AccountSipConfig
698 ret.cred_count = 0;
699 if (sipConfig.authCreds.size() > PJ_ARRAY_SIZE(ret.cred_info))
700 PJSUA2_RAISE_ERROR(PJ_ETOOMANY);
701 for (i=0; i<sipConfig.authCreds.size(); ++i) {
702 const AuthCredInfo &src = sipConfig.authCreds[i];
703 pjsip_cred_info *dst = &ret.cred_info[i];
704
705 dst->realm = str2Pj(src.realm);
706 dst->scheme = str2Pj(src.scheme);
707 dst->username = str2Pj(src.username);
708 dst->data_type = src.dataType;
709 dst->data = str2Pj(src.data);
710 dst->ext.aka.k = str2Pj(src.akaK);
711 dst->ext.aka.op = str2Pj(src.akaOp);
712 dst->ext.aka.amf= str2Pj(src.akaAmf);
713
714 ret.cred_count++;
715 }
716 ret.proxy_cnt = 0;
717 if (sipConfig.proxies.size() > PJ_ARRAY_SIZE(ret.proxy))
718 PJSUA2_RAISE_ERROR(PJ_ETOOMANY);
719 for (i=0; i<sipConfig.proxies.size(); ++i) {
720 ret.proxy[ret.proxy_cnt++] = str2Pj(sipConfig.proxies[i]);
721 }
722 ret.force_contact = str2Pj(sipConfig.contactForced);
723 ret.contact_params = str2Pj(sipConfig.contactParams);
724 ret.contact_uri_params = str2Pj(sipConfig.contactUriParams);
725 ret.auth_pref.initial_auth = sipConfig.authInitialEmpty;
726 ret.auth_pref.algorithm = str2Pj(sipConfig.authInitialAlgorithm);
727 ret.transport_id = sipConfig.transportId;
728 ret.ipv6_sip_use = sipConfig.ipv6Use;
729 ret.use_shared_auth = sipConfig.useSharedAuth;
730 ret.auto_repond_sip_message = sipConfig.autoRespondSipMessage;
731
732 // AccountCallConfig
733 ret.call_hold_type = callConfig.holdType;
734 ret.require_100rel = callConfig.prackUse;
735 ret.use_timer = callConfig.timerUse;
736 ret.use_siprec = callConfig.siprecUse;
737 ret.timer_setting.min_se = callConfig.timerMinSESec;
738 ret.timer_setting.sess_expires = callConfig.timerSessExpiresSec;
739
740 // AccountPresConfig
741 for (i=0; i<presConfig.headers.size(); ++i) {
742 pj_list_push_back(&ret.sub_hdr_list, &presConfig.headers[i].toPj());
743 }
744 ret.publish_enabled = presConfig.publishEnabled;
745 ret.publish_opt.queue_request= presConfig.publishQueue;
746 ret.unpublish_max_wait_time_msec = presConfig.publishShutdownWaitMsec;
747 ret.pidf_tuple_id = str2Pj(presConfig.pidfTupleId);
748
749 // AccountMwiConfig
750 ret.mwi_enabled = mwiConfig.enabled;
751 ret.mwi_expires = mwiConfig.expirationSec;
752
753 // AccountNatConfig
754 ret.sip_stun_use = natConfig.sipStunUse;
755 ret.media_stun_use = natConfig.mediaStunUse;
756 ret.sip_upnp_use = natConfig.sipUpnpUse;
757 ret.media_upnp_use = natConfig.mediaUpnpUse;
758 ret.nat64_opt = natConfig.nat64Opt;
759 ret.ice_cfg_use = PJSUA_ICE_CONFIG_USE_CUSTOM;
760 ret.ice_cfg.enable_ice = natConfig.iceEnabled;
761 ret.ice_cfg.ice_opt.trickle = natConfig.iceTrickle;
762 ret.ice_cfg.ice_max_host_cands = natConfig.iceMaxHostCands;
763 ret.ice_cfg.ice_manual_host_cnt = 0;
764 if (natConfig.iceManualHost.size() >
765 PJ_ARRAY_SIZE(ret.ice_cfg.ice_manual_host))
766 {
767 PJSUA2_RAISE_ERROR(PJ_ETOOMANY);
768 }
769 for (i=0; i<natConfig.iceManualHost.size(); ++i) {
770 pj_str_t tmp = pj_str(const_cast<char*>
771 (natConfig.iceManualHost[i].c_str()));
772 pj_sockaddr* addr =
773 &ret.ice_cfg.ice_manual_host[ret.ice_cfg.ice_manual_host_cnt];
774 if (pj_sockaddr_set_str_addr(pj_AF_INET(), addr, &tmp)==PJ_SUCCESS ||
775 pj_sockaddr_set_str_addr(pj_AF_INET6(), addr, &tmp)==PJ_SUCCESS)
776 {
777 ret.ice_cfg.ice_manual_host_cnt++;
778 } else {
779 PJSUA2_RAISE_ERROR(PJ_EINVAL);
780 }
781 }
782 ret.ice_cfg.ice_opt.aggressive = natConfig.iceAggressiveNomination;
783 ret.ice_cfg.ice_opt.nominated_check_delay =
784 natConfig.iceNominatedCheckDelayMsec;
785 ret.ice_cfg.ice_opt.controlled_agent_want_nom_timeout =
786 natConfig.iceWaitNominationTimeoutMsec;
787 ret.ice_cfg.ice_opt.check_src_addr = natConfig.iceCheckSrcAddr;
788 ret.ice_cfg.ice_no_rtcp = natConfig.iceNoRtcp;
789 ret.ice_cfg.ice_always_update = natConfig.iceAlwaysUpdate;
790
791 ret.turn_cfg_use = PJSUA_TURN_CONFIG_USE_CUSTOM;
792 ret.turn_cfg.enable_turn = natConfig.turnEnabled;
793 ret.turn_cfg.turn_server = str2Pj(natConfig.turnServer);
794 ret.turn_cfg.turn_conn_type = natConfig.turnConnType;
795 ret.turn_cfg.turn_auth_cred.type = PJ_STUN_AUTH_CRED_STATIC;
796 ret.turn_cfg.turn_auth_cred.data.static_cred.username =
797 str2Pj(natConfig.turnUserName);
798 ret.turn_cfg.turn_auth_cred.data.static_cred.data_type =
799 (pj_stun_passwd_type)natConfig.turnPasswordType;
800 ret.turn_cfg.turn_auth_cred.data.static_cred.data =
801 str2Pj(natConfig.turnPassword);
802 ret.turn_cfg.turn_auth_cred.data.static_cred.realm = pj_str((char*)"");
803 ret.turn_cfg.turn_auth_cred.data.static_cred.nonce = pj_str((char*)"");
804
805 ret.allow_contact_rewrite = natConfig.contactRewriteUse;
806 ret.contact_rewrite_method = natConfig.contactRewriteMethod;
807 ret.contact_use_src_port = natConfig.contactUseSrcPort;
808 ret.allow_via_rewrite = natConfig.viaRewriteUse;
809 ret.allow_sdp_nat_rewrite = natConfig.sdpNatRewriteUse;
810 ret.use_rfc5626 = natConfig.sipOutboundUse;
811 ret.rfc5626_instance_id = str2Pj(natConfig.sipOutboundInstanceId);
812 ret.rfc5626_reg_id = str2Pj(natConfig.sipOutboundRegId);
813 ret.ka_interval = natConfig.udpKaIntervalSec;
814 ret.ka_data = str2Pj(natConfig.udpKaData);
815
816 // AccountMediaConfig
817 ret.rtp_cfg = mediaConfig.transportConfig.toPj();
818 ret.lock_codec = mediaConfig.lockCodecEnabled;
819 #if defined(PJMEDIA_STREAM_ENABLE_KA) && (PJMEDIA_STREAM_ENABLE_KA != 0)
820 ret.use_stream_ka = mediaConfig.streamKaEnabled;
821 #endif
822 ret.use_srtp = mediaConfig.srtpUse;
823 ret.srtp_secure_signaling = mediaConfig.srtpSecureSignaling;
824 ret.srtp_opt = mediaConfig.srtpOpt.toPj();
825 ret.ipv6_media_use = mediaConfig.ipv6Use;
826 ret.enable_rtcp_mux = mediaConfig.rtcpMuxEnabled;
827 ret.rtcp_fb_cfg = mediaConfig.rtcpFbConfig.toPj();
828 ret.use_loop_med_tp = mediaConfig.useLoopMedTp;
829 ret.enable_loopback = mediaConfig.enableLoopback;
830 ret.enable_rtcp_xr = mediaConfig.rtcpXrEnabled;
831
832 // AccountVideoConfig
833 ret.vid_in_auto_show = videoConfig.autoShowIncoming;
834 ret.vid_out_auto_transmit = videoConfig.autoTransmitOutgoing;
835 ret.vid_wnd_flags = videoConfig.windowFlags;
836 ret.vid_cap_dev = videoConfig.defaultCaptureDevice;
837 ret.vid_rend_dev = videoConfig.defaultRenderDevice;
838 ret.vid_stream_rc_cfg.method= videoConfig.rateControlMethod;
839 ret.vid_stream_rc_cfg.bandwidth = videoConfig.rateControlBandwidth;
840 ret.vid_stream_sk_cfg.count = videoConfig.startKeyframeCount;
841 ret.vid_stream_sk_cfg.interval = videoConfig.startKeyframeInterval;
842
843 // AccountTextConfig
844 ret.txt_red_level = textConfig.redundancyLevel;
845
846 // AccountIpChangeConfig
847 ret.ip_change_cfg.shutdown_tp = ipChangeConfig.shutdownTp;
848 ret.ip_change_cfg.hangup_calls = ipChangeConfig.hangupCalls;
849 ret.ip_change_cfg.reinvite_flags = ipChangeConfig.reinviteFlags;
850 ret.ip_change_cfg.reinv_use_update = ipChangeConfig.reinvUseUpdate;
851 }
852
853 /* Initialize from pjsip. */
854 void AccountConfig::fromPj(const pjsua_acc_config &prm,
855 const pjsua_media_config *mcfg)
856 {
857 pjsua_media_config default_mcfg;
858 const pjsip_hdr *hdr;
859 unsigned i;
860
861 // Global
862 priority = prm.priority;
863 idUri = pj2Str(prm.id);
864
865 // AccountRegConfig
866 regConfig.registrarUri = pj2Str(prm.reg_uri);
867 regConfig.registerOnAdd = (prm.register_on_acc_add != 0);
868 regConfig.disableRegOnModify= (prm.disable_reg_on_modify != 0);
869 regConfig.timeoutSec = prm.reg_timeout;
870 regConfig.retryIntervalSec = prm.reg_retry_interval;
871 regConfig.firstRetryIntervalSec = prm.reg_first_retry_interval;
872 regConfig.randomRetryIntervalSec = prm.reg_retry_random_interval;
873 regConfig.delayBeforeRefreshSec = prm.reg_delay_before_refresh;
874 regConfig.dropCallsOnFail = PJ2BOOL(prm.drop_calls_on_reg_fail);
875 regConfig.unregWaitMsec = prm.unreg_timeout;
876 regConfig.proxyUse = prm.reg_use_proxy;
877 regConfig.contactParams = pj2Str(prm.reg_contact_params);
878 regConfig.contactUriParams = pj2Str(prm.reg_contact_uri_params);
879 regConfig.headers.clear();
880 hdr = prm.reg_hdr_list.next;
881 while (hdr != &prm.reg_hdr_list) {
882 SipHeader new_hdr;
883 new_hdr.fromPj(hdr);
884
885 regConfig.headers.push_back(PJSUA2_MOVE(new_hdr));
886
887 hdr = hdr->next;
888 }
889
890 // AccountSipConfig
891 sipConfig.authCreds.clear();
892 for (i=0; i<prm.cred_count; ++i) {
893 AuthCredInfo cred;
894 const pjsip_cred_info &src = prm.cred_info[i];
895
896 cred.realm = pj2Str(src.realm);
897 cred.scheme = pj2Str(src.scheme);
898 cred.username = pj2Str(src.username);
899 cred.dataType = src.data_type;
900 cred.data = pj2Str(src.data);
901 cred.akaK = pj2Str(src.ext.aka.k);
902 cred.akaOp = pj2Str(src.ext.aka.op);
903 cred.akaAmf = pj2Str(src.ext.aka.amf);
904
905 sipConfig.authCreds.push_back(PJSUA2_MOVE(cred));
906 }
907 sipConfig.proxies.clear();
908 for (i=0; i<prm.proxy_cnt; ++i) {
909 sipConfig.proxies.push_back(pj2Str(prm.proxy[i]));
910 }
911 sipConfig.contactForced = pj2Str(prm.force_contact);
912 sipConfig.contactParams = pj2Str(prm.contact_params);
913 sipConfig.contactUriParams = pj2Str(prm.contact_uri_params);
914 sipConfig.authInitialEmpty = PJ2BOOL(prm.auth_pref.initial_auth);
915 sipConfig.authInitialAlgorithm = pj2Str(prm.auth_pref.algorithm);
916 sipConfig.transportId = prm.transport_id;
917 sipConfig.ipv6Use = prm.ipv6_sip_use;
918 sipConfig.useSharedAuth = PJ2BOOL(prm.use_shared_auth);
919 sipConfig.autoRespondSipMessage = PJ2BOOL(prm.auto_repond_sip_message);
920
921 // AccountCallConfig
922 callConfig.holdType = prm.call_hold_type;
923 callConfig.prackUse = prm.require_100rel;
924 callConfig.timerUse = prm.use_timer;
925 callConfig.siprecUse = prm.use_siprec;
926 callConfig.timerMinSESec = prm.timer_setting.min_se;
927 callConfig.timerSessExpiresSec = prm.timer_setting.sess_expires;
928
929 // AccountPresConfig
930 presConfig.headers.clear();
931 hdr = prm.sub_hdr_list.next;
932 while (hdr != &prm.sub_hdr_list) {
933 SipHeader new_hdr;
934 new_hdr.fromPj(hdr);
935 presConfig.headers.push_back(PJSUA2_MOVE(new_hdr));
936 hdr = hdr->next;
937 }
938 presConfig.publishEnabled = PJ2BOOL(prm.publish_enabled);
939 presConfig.publishQueue = PJ2BOOL(prm.publish_opt.queue_request);
940 presConfig.publishShutdownWaitMsec = prm.unpublish_max_wait_time_msec;
941 presConfig.pidfTupleId = pj2Str(prm.pidf_tuple_id);
942
943 // AccountMwiConfig
944 mwiConfig.enabled = PJ2BOOL(prm.mwi_enabled);
945 mwiConfig.expirationSec = prm.mwi_expires;
946
947 // AccountNatConfig
948 natConfig.sipStunUse = prm.sip_stun_use;
949 natConfig.mediaStunUse = prm.media_stun_use;
950 natConfig.sipUpnpUse = prm.sip_upnp_use;
951 natConfig.mediaUpnpUse = prm.media_upnp_use;
952 natConfig.nat64Opt = prm.nat64_opt;
953 if (prm.ice_cfg_use == PJSUA_ICE_CONFIG_USE_CUSTOM) {
954 natConfig.iceEnabled = PJ2BOOL(prm.ice_cfg.enable_ice);
955 natConfig.iceTrickle = prm.ice_cfg.ice_opt.trickle;
956 natConfig.iceMaxHostCands = prm.ice_cfg.ice_max_host_cands;
957 natConfig.iceManualHost.clear();
958 for (i=0; i<prm.ice_cfg.ice_manual_host_cnt; ++i) {
959 char buf[PJ_INET6_ADDRSTRLEN];
960 const pj_sockaddr *addr = &prm.ice_cfg.ice_manual_host[i];
961 if (pj_sockaddr_print(addr, buf, sizeof(buf), 0) != NULL) {
962 natConfig.iceManualHost.push_back(std::string(buf));
963 }
964 }
965 natConfig.iceAggressiveNomination =
966 PJ2BOOL(prm.ice_cfg.ice_opt.aggressive);
967 natConfig.iceNominatedCheckDelayMsec =
968 prm.ice_cfg.ice_opt.nominated_check_delay;
969 natConfig.iceWaitNominationTimeoutMsec =
970 prm.ice_cfg.ice_opt.controlled_agent_want_nom_timeout;
971 natConfig.iceCheckSrcAddr = prm.ice_cfg.ice_opt.check_src_addr;
972 natConfig.iceNoRtcp = PJ2BOOL(prm.ice_cfg.ice_no_rtcp);
973 natConfig.iceAlwaysUpdate = PJ2BOOL(prm.ice_cfg.ice_always_update);
974 } else {
975 if (!mcfg) {
976 pjsua_media_config_default(&default_mcfg);
977 mcfg = &default_mcfg;
978 }
979 natConfig.iceEnabled = PJ2BOOL(mcfg->enable_ice);
980 natConfig.iceMaxHostCands= mcfg->ice_max_host_cands;
981 natConfig.iceAggressiveNomination = PJ2BOOL(mcfg->ice_opt.aggressive);
982 natConfig.iceNominatedCheckDelayMsec =
983 mcfg->ice_opt.nominated_check_delay;
984 natConfig.iceWaitNominationTimeoutMsec =
985 mcfg->ice_opt.controlled_agent_want_nom_timeout;
986 natConfig.iceCheckSrcAddr = mcfg->ice_opt.check_src_addr;
987 natConfig.iceNoRtcp = PJ2BOOL(mcfg->ice_no_rtcp);
988 natConfig.iceAlwaysUpdate = PJ2BOOL(mcfg->ice_always_update);
989 }
990
991 if (prm.turn_cfg_use == PJSUA_TURN_CONFIG_USE_CUSTOM) {
992 natConfig.turnEnabled = PJ2BOOL(prm.turn_cfg.enable_turn);
993 natConfig.turnServer = pj2Str(prm.turn_cfg.turn_server);
994 natConfig.turnConnType = prm.turn_cfg.turn_conn_type;
995 natConfig.turnUserName =
996 pj2Str(prm.turn_cfg.turn_auth_cred.data.static_cred.username);
997 natConfig.turnPasswordType =
998 prm.turn_cfg.turn_auth_cred.data.static_cred.data_type;
999 natConfig.turnPassword =
1000 pj2Str(prm.turn_cfg.turn_auth_cred.data.static_cred.data);
1001 } else {
1002 if (!mcfg) {
1003 pjsua_media_config_default(&default_mcfg);
1004 mcfg = &default_mcfg;
1005 }
1006 natConfig.turnEnabled = PJ2BOOL(mcfg->enable_turn);
1007 natConfig.turnServer = pj2Str(mcfg->turn_server);
1008 natConfig.turnConnType = mcfg->turn_conn_type;
1009 natConfig.turnUserName =
1010 pj2Str(mcfg->turn_auth_cred.data.static_cred.username);
1011 natConfig.turnPasswordType =
1012 mcfg->turn_auth_cred.data.static_cred.data_type;
1013 natConfig.turnPassword =
1014 pj2Str(mcfg->turn_auth_cred.data.static_cred.data);
1015 }
1016 natConfig.contactRewriteUse = prm.allow_contact_rewrite;
1017 natConfig.contactRewriteMethod = prm.contact_rewrite_method;
1018 natConfig.contactUseSrcPort = prm.contact_use_src_port;
1019 natConfig.viaRewriteUse = prm.allow_via_rewrite;
1020 natConfig.sdpNatRewriteUse = prm.allow_sdp_nat_rewrite;
1021 natConfig.sipOutboundUse = prm.use_rfc5626;
1022 natConfig.sipOutboundInstanceId = pj2Str(prm.rfc5626_instance_id);
1023 natConfig.sipOutboundRegId = pj2Str(prm.rfc5626_reg_id);
1024 natConfig.udpKaIntervalSec = prm.ka_interval;
1025 natConfig.udpKaData = pj2Str(prm.ka_data);
1026
1027 // AccountMediaConfig
1028 mediaConfig.transportConfig.fromPj(prm.rtp_cfg);
1029 mediaConfig.lockCodecEnabled= PJ2BOOL(prm.lock_codec);
1030 #if defined(PJMEDIA_STREAM_ENABLE_KA) && (PJMEDIA_STREAM_ENABLE_KA != 0)
1031 mediaConfig.streamKaEnabled = PJ2BOOL(prm.use_stream_ka);
1032 #else
1033 mediaConfig.streamKaEnabled = false;
1034 #endif
1035 mediaConfig.srtpUse = prm.use_srtp;
1036 mediaConfig.srtpSecureSignaling = prm.srtp_secure_signaling;
1037 mediaConfig.srtpOpt.fromPj(prm.srtp_opt);
1038 mediaConfig.ipv6Use = prm.ipv6_media_use;
1039 mediaConfig.rtcpMuxEnabled = PJ2BOOL(prm.enable_rtcp_mux);
1040 mediaConfig.rtcpFbConfig.fromPj(prm.rtcp_fb_cfg);
1041 mediaConfig.useLoopMedTp = PJ2BOOL(prm.use_loop_med_tp);
1042 mediaConfig.enableLoopback = PJ2BOOL(prm.enable_loopback);
1043 mediaConfig.rtcpXrEnabled = PJ2BOOL(prm.enable_rtcp_xr);
1044
1045 // AccountVideoConfig
1046 videoConfig.autoShowIncoming = PJ2BOOL(prm.vid_in_auto_show);
1047 videoConfig.autoTransmitOutgoing = PJ2BOOL(prm.vid_out_auto_transmit);
1048 videoConfig.windowFlags = prm.vid_wnd_flags;
1049 videoConfig.defaultCaptureDevice = prm.vid_cap_dev;
1050 videoConfig.defaultRenderDevice = prm.vid_rend_dev;
1051 videoConfig.rateControlMethod = prm.vid_stream_rc_cfg.method;
1052 videoConfig.rateControlBandwidth = prm.vid_stream_rc_cfg.bandwidth;
1053 videoConfig.startKeyframeCount = prm.vid_stream_sk_cfg.count;
1054 videoConfig.startKeyframeInterval = prm.vid_stream_sk_cfg.interval;
1055
1056 // AccountTextConfig
1057 textConfig.redundancyLevel = prm.txt_red_level;
1058
1059 // AccountIpChangeConfig
1060 ipChangeConfig.shutdownTp = PJ2BOOL(prm.ip_change_cfg.shutdown_tp);
1061 ipChangeConfig.hangupCalls = PJ2BOOL(prm.ip_change_cfg.hangup_calls);
1062 ipChangeConfig.reinviteFlags = prm.ip_change_cfg.reinvite_flags;
1063 ipChangeConfig.reinvUseUpdate = prm.ip_change_cfg.reinv_use_update;
1064 }
1065
1066 void AccountConfig::readObject(const ContainerNode &node) PJSUA2_THROW(Error)
1067 {
1068 ContainerNode this_node = node.readContainer("AccountConfig");
1069
1070 NODE_READ_INT ( this_node, priority);
1071 NODE_READ_STRING ( this_node, idUri);
1072 NODE_READ_OBJ ( this_node, regConfig);
1073 NODE_READ_OBJ ( this_node, sipConfig);
1074 NODE_READ_OBJ ( this_node, callConfig);
1075 NODE_READ_OBJ ( this_node, presConfig);
1076 NODE_READ_OBJ ( this_node, mwiConfig);
1077 NODE_READ_OBJ ( this_node, natConfig);
1078 NODE_READ_OBJ ( this_node, mediaConfig);
1079 NODE_READ_OBJ ( this_node, videoConfig);
1080 }
1081
1082 void AccountConfig::writeObject(ContainerNode &node) const PJSUA2_THROW(Error)
1083 {
1084 ContainerNode this_node = node.writeNewContainer("AccountConfig");
1085
1086 NODE_WRITE_INT ( this_node, priority);
1087 NODE_WRITE_STRING ( this_node, idUri);
1088 NODE_WRITE_OBJ ( this_node, regConfig);
1089 NODE_WRITE_OBJ ( this_node, sipConfig);
1090 NODE_WRITE_OBJ ( this_node, callConfig);
1091 NODE_WRITE_OBJ ( this_node, presConfig);
1092 NODE_WRITE_OBJ ( this_node, mwiConfig);
1093 NODE_WRITE_OBJ ( this_node, natConfig);
1094 NODE_WRITE_OBJ ( this_node, mediaConfig);
1095 NODE_WRITE_OBJ ( this_node, videoConfig);
1096 }
1097
1098
1099 ///////////////////////////////////////////////////////////////////////////////
1100
1101 void AccountInfo::fromPj(const pjsua_acc_info &pai)
1102 {
1103 id = pai.id;
1104 isDefault = pai.is_default != 0;
1105 uri = pj2Str(pai.acc_uri);
1106 regIsConfigured = pai.has_registration != 0;
1107 regIsActive = pai.has_registration && pai.expires > 0 &&
1108 pai.expires != PJSIP_EXPIRES_NOT_SPECIFIED &&
1109 (pai.status / 100 == 2);
1110 regExpiresSec = pai.expires;
1111 regStatus = pai.status;
1112 regStatusText = pj2Str(pai.status_text);
1113 regLastErr = pai.reg_last_err;
1114 onlineStatus = pai.online_status != 0;
1115 onlineStatusText = pj2Str(pai.online_status_text);
1116 }
1117
1118 ///////////////////////////////////////////////////////////////////////////////
1119
1120 Account::Account()
1121 : id(PJSUA_INVALID_ID)
1122 {
1123 }
1124
1125 Account::~Account()
1126 {
1127 /* Always delete the C-layer account to prevent resource leaks. */
1128 shutdown();
1129 }
1130
1131 void Account::create(const AccountConfig &acc_cfg,
1132 bool make_default) PJSUA2_THROW(Error)
1133 {
1134 pjsua_acc_config pj_acc_cfg;
1135
1136 acc_cfg.toPj(pj_acc_cfg);
1137
1138 for (unsigned i = 0; i < pj_acc_cfg.cred_count; ++i) {
1139 pjsip_cred_info *dst = &pj_acc_cfg.cred_info[i];
1140 dst->ext.aka.cb = (pjsip_cred_cb)
1141 &Endpoint::on_auth_create_aka_response_callback;
1142 }
1143 pj_acc_cfg.user_data = (void*)this;
1144 PJSUA2_CHECK_EXPR( pjsua_acc_add(&pj_acc_cfg, make_default, &id) );
1145 }
1146
1147 void Account::shutdown()
1148 {
1149 try {
1150 AccountShutdownParam prm;
1151 prm.force = true;
1152 shutdown2(prm);
1153 } catch (Error &err) {
1154 PJ_PERROR(1, (THIS_FILE, err.status,
1155 "Failed to delete account %d", id));
1156 }
1157 }
1158
1159 void Account::shutdown2(const AccountShutdownParam &prm) PJSUA2_THROW(Error)
1160 {
1161 if (isValid() && pjsua_get_state() < PJSUA_STATE_CLOSING) {
1162 #if !DEPRECATED_FOR_TICKET_2232
1163 // Cleanup buddies in the buddy list
1164 while(buddyList.size() > 0) {
1165 Buddy *b = buddyList[0];
1166 delete b; /* this will remove itself from the list */
1167 }
1168 #endif
1169
1170 pjsua_acc_del_param del_prm;
1171 pjsua_acc_del_param_default(&del_prm);
1172 del_prm.force = prm.force? PJ_TRUE : PJ_FALSE;
1173 PJSUA2_CHECK_EXPR(pjsua_acc_del2(id, &del_prm));
1174 }
1175 }
1176
1177 void Account::modify(const AccountConfig &acc_cfg) PJSUA2_THROW(Error)
1178 {
1179 pjsua_acc_config pj_acc_cfg;
1180
1181 acc_cfg.toPj(pj_acc_cfg);
1182 pj_acc_cfg.user_data = (void*)this;
1183 PJSUA2_CHECK_EXPR( pjsua_acc_modify(id, &pj_acc_cfg) );
1184 }
1185
1186 bool Account::isValid() const
1187 {
1188 return pjsua_acc_is_valid(id) != 0;
1189 }
1190
1191 void Account::setDefault() PJSUA2_THROW(Error)
1192 {
1193 PJSUA2_CHECK_EXPR( pjsua_acc_set_default(id) );
1194 }
1195
1196 bool Account::isDefault() const
1197 {
1198 return pjsua_acc_get_default() == id;
1199 }
1200
1201 int Account::getId() const
1202 {
1203 return id;
1204 }
1205
1206 Account *Account::lookup(int acc_id)
1207 {
1208 if (!pjsua_acc_is_valid(acc_id))
1209 return NULL;
1210 return (Account*)pjsua_acc_get_user_data(acc_id);
1211 }
1212
1213 AccountInfo Account::getInfo() const PJSUA2_THROW(Error)
1214 {
1215 pjsua_acc_info pj_ai;
1216 AccountInfo ai;
1217
1218 PJSUA2_CHECK_EXPR( pjsua_acc_get_info(id, &pj_ai) );
1219 ai.fromPj(pj_ai);
1220 return ai;
1221 }
1222
1223 void Account::sendRequest(const pj::SendRequestParam& prm) PJSUA2_THROW(Error)
1224 {
1225 pj_str_t method = str2Pj(prm.method);
1226 pj_str_t dest_uri = str2Pj(prm.txOption.targetUri);
1227 pjsua_msg_data msg_data;
1228 prm.txOption.toPj(msg_data);
1229
1230 PJSUA2_CHECK_EXPR(pjsua_acc_send_request(id, &dest_uri, &method, NULL,
1231 prm.userData, &msg_data));
1232 }
1233
1234 void Account::sendResponse(const pj::SendResponseParam& prm) PJSUA2_THROW(Error)
1235 {
1236 const auto reason = str2Pj(prm.reason);
1237 PJSUA2_CHECK_EXPR(pjsua_acc_send_response(id, prm.deferredResponse.data,
1238 prm.deferredResponse.transaction,
1239 static_cast<pj_status_t>(prm.code),
1240 &reason, nullptr));
1241 }
1242
1243 void Account::setRegistration(bool renew) PJSUA2_THROW(Error)
1244 {
1245 PJSUA2_CHECK_EXPR( pjsua_acc_set_registration(id, renew) );
1246 }
1247
1248 void
1249 Account::setOnlineStatus(const PresenceStatus &pres_st) PJSUA2_THROW(Error)
1250 {
1251 pjrpid_element pj_rpid;
1252
1253 pj_bzero(&pj_rpid, sizeof(pj_rpid));
1254 pj_rpid.type = PJRPID_ELEMENT_TYPE_PERSON;
1255 pj_rpid.activity = pres_st.activity;
1256 pj_rpid.id = str2Pj(pres_st.rpidId);
1257 pj_rpid.note = str2Pj(pres_st.note);
1258
1259 PJSUA2_CHECK_EXPR( pjsua_acc_set_online_status2(
1260 id, pres_st.status == PJSUA_BUDDY_STATUS_ONLINE,
1261 &pj_rpid) );
1262 }
1263
1264 void Account::setTransport(TransportId tp_id) PJSUA2_THROW(Error)
1265 {
1266 PJSUA2_CHECK_EXPR( pjsua_acc_set_transport(id, tp_id) );
1267 }
1268
1269 void Account::presNotify(const PresNotifyParam &prm) PJSUA2_THROW(Error)
1270 {
1271 pj_str_t pj_state_str = str2Pj(prm.stateStr);
1272 pj_str_t pj_reason = str2Pj(prm.reason);
1273 pjsua_msg_data msg_data;
1274 prm.txOption.toPj(msg_data);
1275
1276 PJSUA2_CHECK_EXPR( pjsua_pres_notify(id, (pjsua_srv_pres*)prm.srvPres,
1277 prm.state, &pj_state_str,
1278 &pj_reason, prm.withBody,
1279 &msg_data) );
1280 }
1281
1282 #if !DEPRECATED_FOR_TICKET_2232
1283 const BuddyVector& Account::enumBuddies() const PJSUA2_THROW(Error)
1284 {
1285 return buddyList;
1286 }
1287 #endif
1288
1289 BuddyVector2 Account::enumBuddies2() const PJSUA2_THROW(Error)
1290 {
1291 BuddyVector2 bv2;
1292 pjsua_buddy_id ids[PJSUA_MAX_BUDDIES];
1293 unsigned i, count = PJSUA_MAX_BUDDIES;
1294
1295 PJSUA2_CHECK_EXPR( pjsua_enum_buddies(ids, &count) );
1296 for (i = 0; i < count; ++i) {
1297 pjsua_buddy_info pbi;
1298
1299 pjsua_buddy_get_info(ids[i], &pbi);
1300 if (id == pbi.acc_id) {
1301 bv2.push_back(Buddy(ids[i]));
1302 }
1303 }
1304
1305 return bv2;
1306 }
1307
1308 #if !DEPRECATED_FOR_TICKET_2232
1309 Buddy* Account::findBuddy(string uri, FindBuddyMatch *buddy_match) const
1310 PJSUA2_THROW(Error)
1311 {
1312 if (!buddy_match) {
1313 static FindBuddyMatch def_bm;
1314 buddy_match = &def_bm;
1315 }
1316
1317 for (unsigned i = 0; i < buddyList.size(); i++) {
1318 if (buddy_match->match(uri, *buddyList[i]))
1319 return buddyList[i];
1320 }
1321 PJSUA2_RAISE_ERROR(PJ_ENOTFOUND);
1322 }
1323 #endif
1324
1325 Buddy Account::findBuddy2(string uri) const PJSUA2_THROW(Error)
1326 {
1327 pj_str_t pj_uri;
1328 pjsua_buddy_id bud_id;
1329 pjsua_buddy_info pbi;
1330
1331 pj_strset2(&pj_uri, (char*)uri.c_str());
1332
1333 bud_id = pjsua_buddy_find(&pj_uri);
1334 if (bud_id == PJSUA_INVALID_ID) {
1335 PJSUA2_RAISE_ERROR(PJ_ENOTFOUND);
1336 }
1337
1338 pjsua_buddy_get_info(bud_id, &pbi);
1339 if (id != pbi.acc_id) {
1340 PJSUA2_RAISE_ERROR(PJ_ENOTFOUND);
1341 }
1342
1343 Buddy buddy(bud_id);
1344 return buddy;
1345 }
1346
1347 void Account::addBuddy(Buddy *buddy)
1348 {
1349 #if !DEPRECATED_FOR_TICKET_2232
1350 pj_assert(buddy);
1351
1352 buddyList.push_back(buddy);
1353 #else
1354 PJ_UNUSED_ARG(buddy);
1355 #endif
1356 }
1357
1358 void Account::removeBuddy(Buddy *buddy)
1359 {
1360 #if !DEPRECATED_FOR_TICKET_2232
1361 pj_assert(buddy);
1362
1363 BuddyVector::iterator it;
1364 for (it = buddyList.begin(); it != buddyList.end(); it++) {
1365 if (*it == buddy) {
1366 buddyList.erase(it);
1367 return;
1368 }
1369 }
1370
1371 pj_assert(!"Bug! Buddy to be removed is not in the buddy list!");
1372 #else
1373 PJ_UNUSED_ARG(buddy);
1374 #endif
1375 }