Debian Codegraph @

Xpjproject/pjsip/include/pjsua2/account.hpp

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 #ifndef __PJSUA2_ACCOUNT_HPP__
19 #define __PJSUA2_ACCOUNT_HPP__
20
21 /**
22 * @file pjsua2/account.hpp
23 * @brief PJSUA2 Account operations
24 */
25 #include <pjsua-lib/pjsua.h>
26 #include <pjsua2/persistent.hpp>
27 #include <pjsua2/presence.hpp>
28 #include <pjsua2/siptypes.hpp>
29
30 /** PJSUA2 API is inside pj namespace */
31 namespace pj
32 {
33
34 /**
35 * @defgroup PJSUA2_ACC Account
36 * @ingroup PJSUA2_Ref
37 * @{
38 */
39
40 using std::string;
41
42 /**
43 * Account registration config. This will be specified in AccountConfig.
44 */
45 struct AccountRegConfig : public PersistentObject
46 {
47 /**
48 * This is the URL to be put in the request URI for the registration,
49 * and will look something like "sip:serviceprovider".
50 *
51 * This field should be specified if registration is desired. If the
52 * value is empty, no account registration will be performed.
53 */
54 string registrarUri;
55
56 /**
57 * Specify whether the account should register as soon as it is
58 * added to the UA. Application can set this to PJ_FALSE and control
59 * the registration manually with pjsua_acc_set_registration().
60 *
61 * Default: True
62 */
63 bool registerOnAdd;
64
65 /**
66 * Specify whether account modification with Account::modify() should
67 * automatically update registration if necessary, for example if
68 * account credentials change.
69 *
70 * Disable this when immediate registration is not desirable, such as
71 * during IP address change.
72 *
73 * Default: false.
74 */
75 bool disableRegOnModify;
76
77 /**
78 * The optional custom SIP headers to be put in the registration
79 * request.
80 */
81 SipHeaderVector headers;
82
83 /**
84 * Additional parameters that will be appended in the Contact header
85 * of the registration requests. This will be appended after
86 * \a AccountSipConfig.contactParams;
87 *
88 * The parameters should be preceeded by semicolon, and all strings must
89 * be properly escaped. Example:
90 * ";my-param=X;another-param=Hi%20there"
91 */
92 string contactParams;
93
94 /**
95 * Additional parameters that will be appended in the Contact URI
96 * of the registration requests. This will be appended after
97 * \a AccountSipConfig.contactUriParams;
98 *
99 * The parameters should be preceeded by semicolon, and all strings must
100 * be properly escaped. Example:
101 * ";my-param=X;another-param=Hi%20there"
102 */
103 string contactUriParams;
104
105 /**
106 * Optional interval for registration, in seconds. If the value is zero,
107 * default interval will be used (PJSUA_REG_INTERVAL, 300 seconds).
108 */
109 unsigned timeoutSec;
110
111 /**
112 * Specify interval of auto registration retry upon registration failure
113 * (including caused by transport problem), in second. Set to 0 to
114 * disable auto re-registration. Note that if the registration retry
115 * occurs because of transport failure, the first retry will be done
116 * after \a firstRetryIntervalSec seconds instead. Also note that
117 * the interval will be randomized slightly by some seconds (specified
118 * in \a reg_retry_random_interval) to avoid all clients re-registering
119 * at the same time.
120 *
121 * See also \a firstRetryIntervalSec and \a randomRetryIntervalSec
122 * settings.
123 *
124 * Default: PJSUA_REG_RETRY_INTERVAL
125 */
126 unsigned retryIntervalSec;
127
128 /**
129 * This specifies the interval for the first registration retry. The
130 * registration retry is explained in \a retryIntervalSec. Note that
131 * the value here will also be randomized by some seconds (specified
132 * in \a reg_retry_random_interval) to avoid all clients re-registering
133 * at the same time.
134 *
135 * See also \a retryIntervalSec and \a randomRetryIntervalSec settings.
136 *
137 * Default: 0
138 */
139 unsigned firstRetryIntervalSec;
140
141 /**
142 * This specifies maximum randomized value to be added/substracted
143 * to/from the registration retry interval specified in \a
144 * reg_retry_interval and \a reg_first_retry_interval, in second.
145 * This is useful to avoid all clients re-registering at the same time.
146 * For example, if the registration retry interval is set to 100 seconds
147 * and this is set to 10 seconds, the actual registration retry interval
148 * will be in the range of 90 to 110 seconds.
149 *
150 * See also \a retryIntervalSec and \a firstRetryIntervalSec settings.
151 *
152 * Default: 10
153 */
154 unsigned randomRetryIntervalSec;
155
156 /**
157 * Specify the number of seconds to refresh the client registration
158 * before the registration expires.
159 *
160 * Default: PJSIP_REGISTER_CLIENT_DELAY_BEFORE_REFRESH, 5 seconds
161 */
162 unsigned delayBeforeRefreshSec;
163
164 /**
165 * Specify whether calls of the configured account should be dropped
166 * after registration failure and an attempt of re-registration has
167 * also failed.
168 *
169 * Default: FALSE (disabled)
170 */
171 bool dropCallsOnFail;
172
173 /**
174 * Specify the maximum time to wait for unregistration requests to
175 * complete during library shutdown sequence.
176 *
177 * Default: PJSUA_UNREG_TIMEOUT
178 */
179 unsigned unregWaitMsec;
180
181 /**
182 * Specify how the registration uses the outbound and account proxy
183 * settings. This controls if and what Route headers will appear in
184 * the REGISTER request of this account. The value is bitmask combination
185 * of PJSUA_REG_USE_OUTBOUND_PROXY and PJSUA_REG_USE_ACC_PROXY bits.
186 * If the value is set to 0, the REGISTER request will not use any proxy
187 * (i.e. it will not have any Route headers).
188 *
189 * Default: 3 (PJSUA_REG_USE_OUTBOUND_PROXY | PJSUA_REG_USE_ACC_PROXY)
190 */
191 unsigned proxyUse;
192
193 public:
194 /**
195 * Read this object from a container node.
196 *
197 * @param node Container to read values from.
198 */
199 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
200
201 /**
202 * Write this object to a container node.
203 *
204 * @param node Container to write values to.
205 */
206 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
207
208 };
209
210 /** Array of SIP credentials */
211 typedef std::vector<AuthCredInfo> AuthCredInfoVector;
212
213 /**
214 * Various SIP settings for the account. This will be specified in
215 * AccountConfig.
216 */
217 struct AccountSipConfig : public PersistentObject
218 {
219 /**
220 * Array of credentials. If registration is desired, normally there should
221 * be at least one credential specified, to successfully authenticate
222 * against the service provider. More credentials can be specified, for
223 * example when the requests are expected to be challenged by the
224 * proxies in the route set.
225 */
226 AuthCredInfoVector authCreds;
227
228 /**
229 * Array of proxy servers to visit for outgoing requests. Each of the
230 * entry is translated into one Route URI.
231 */
232 StringVector proxies;
233
234 /**
235 * Optional URI to be put as Contact for this account. It is recommended
236 * that this field is left empty, so that the value will be calculated
237 * automatically based on the transport address.
238 */
239 string contactForced;
240
241 /**
242 * Additional parameters that will be appended in the Contact header
243 * for this account. This will affect the Contact header in all SIP
244 * messages sent on behalf of this account, including but not limited to
245 * REGISTER, INVITE, and SUBCRIBE requests or responses.
246 *
247 * The parameters should be preceeded by semicolon, and all strings must
248 * be properly escaped. Example:
249 * ";my-param=X;another-param=Hi%20there"
250 */
251 string contactParams;
252
253 /**
254 * Additional URI parameters that will be appended in the Contact URI
255 * for this account. This will affect the Contact URI in all SIP
256 * messages sent on behalf of this account, including but not limited to
257 * REGISTER, INVITE, and SUBCRIBE requests or responses.
258 *
259 * The parameters should be preceeded by semicolon, and all strings must
260 * be properly escaped. Example:
261 * ";my-param=X;another-param=Hi%20there"
262 */
263 string contactUriParams;
264
265
266 /**
267 * If this flag is set, the authentication client framework will
268 * send an empty Authorization header in each initial request.
269 * Default is no.
270 */
271 bool authInitialEmpty;
272
273 /**
274 * Specify the algorithm to use when empty Authorization header
275 * is to be sent for each initial request (see above)
276 */
277 string authInitialAlgorithm;
278
279 /**
280 * Optionally bind this account to specific transport. This normally is
281 * not a good idea, as account should be able to send requests using
282 * any available transports according to the destination. But some
283 * application may want to have explicit control over the transport to
284 * use, so in that case it can set this field.
285 *
286 * Default: -1 (PJSUA_INVALID_ID)
287 *
288 * @see Account::setTransport()
289 */
290 TransportId transportId;
291
292 /**
293 * Specify whether IPv6 should be used for SIP signalling.
294 *
295 * Default: PJSUA_IPV6_ENABLED_NO_PREFERENCE
296 * (IP version used will be based on the address resolution
297 * returned by OS/resolver)
298 */
299 pjsua_ipv6_use ipv6Use;
300
301 /**
302 * Use a shared authorization session within this account.
303 * This will use the accounts credentials on outgoing requests,
304 * so that less 401/407 Responses will be returned.
305 *
306 * Needs PJSIP_AUTH_AUTO_SEND_NEXT and PJSIP_AUTH_HEADER_CACHING
307 * enabled to work properly, and also will grow usage of the used pool for
308 * the cached headers.
309 *
310 * Default is disabled/false.
311 */
312 bool useSharedAuth;
313
314 /**
315 * Configure automatic SIP-MESSAGE processing behavior for this account.
316 * When set to true, incoming SIP MESSAGE requests will be responded to
317 * immediately with a 200 OK response (legacy behavior). When set to false,
318 * incoming SIP MESSAGE requests will create UAS transactions allowing for
319 * deferred responses, cf. Account::sendResponse() and DeferredResponse.
320 *
321 * Default: true (automatic response for backward compatibility)
322 */
323 bool autoRespondSipMessage;
324
325 public:
326 /**
327 * Read this object from a container node.
328 *
329 * @param node Container to read values from.
330 */
331 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
332
333 /**
334 * Write this object to a container node.
335 *
336 * @param node Container to write values to.
337 */
338 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
339 };
340
341 /**
342 * Account's call settings. This will be specified in AccountConfig.
343 */
344 struct AccountCallConfig : public PersistentObject
345 {
346 /**
347 * Specify how to offer call hold to remote peer. Please see the
348 * documentation on pjsua_call_hold_type for more info.
349 *
350 * Default: PJSUA_CALL_HOLD_TYPE_DEFAULT
351 */
352 pjsua_call_hold_type holdType;
353
354 /**
355 * Specify how support for reliable provisional response (100rel/
356 * PRACK) should be used for all sessions in this account. See the
357 * documentation of pjsua_100rel_use enumeration for more info.
358 *
359 * Default: PJSUA_100REL_NOT_USED
360 */
361 pjsua_100rel_use prackUse;
362
363 /**
364 * Specify the usage of Session Timers for all sessions. See the
365 * pjsua_sip_timer_use for possible values.
366 *
367 * Default: PJSUA_SIP_TIMER_OPTIONAL
368 */
369 pjsua_sip_timer_use timerUse;
370
371 /**
372 * Specify the usage of SIPREC INVITE request. See the
373 * pjsua_sip_siprec_use for possible values.
374 *
375 * Default: PJSUA_SIP_SIPREC_INACTIVE
376 */
377 pjsua_sip_siprec_use siprecUse;
378
379 /**
380 * Specify minimum Session Timer expiration period, in seconds.
381 * Must not be lower than 90. Default is 90.
382 */
383 unsigned timerMinSESec;
384
385 /**
386 * Specify Session Timer expiration period, in seconds.
387 * Must not be lower than timerMinSE. Default is 1800.
388 */
389 unsigned timerSessExpiresSec;
390
391 public:
392 /**
393 * Default constructor
394 */
395 AccountCallConfig() : holdType(PJSUA_CALL_HOLD_TYPE_DEFAULT),
396 prackUse(PJSUA_100REL_NOT_USED),
397 timerUse(PJSUA_SIP_TIMER_OPTIONAL),
398 siprecUse(PJSUA_SIP_SIPREC_INACTIVE),
399 timerMinSESec(90),
400 timerSessExpiresSec(PJSIP_SESS_TIMER_DEF_SE)
401 {}
402
403 /**
404 * Read this object from a container node.
405 *
406 * @param node Container to read values from.
407 */
408 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
409
410 /**
411 * Write this object to a container node.
412 *
413 * @param node Container to write values to.
414 */
415 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
416 };
417
418 /**
419 * Account presence config. This will be specified in AccountConfig.
420 */
421 struct AccountPresConfig : public PersistentObject
422 {
423 /**
424 * The optional custom SIP headers to be put in the presence
425 * subscription request.
426 */
427 SipHeaderVector headers;
428
429 /**
430 * If this flag is set, the presence information of this account will
431 * be PUBLISH-ed to the server where the account belongs.
432 *
433 * Default: PJ_FALSE
434 */
435 bool publishEnabled;
436
437 /**
438 * Specify whether the client publication session should queue the
439 * PUBLISH request should there be another PUBLISH transaction still
440 * pending. If this is set to false, the client will return error
441 * on the PUBLISH request if there is another PUBLISH transaction still
442 * in progress.
443 *
444 * Default: PJSIP_PUBLISHC_QUEUE_REQUEST (TRUE)
445 */
446 bool publishQueue;
447
448 /**
449 * Maximum time to wait for unpublication transaction(s) to complete
450 * during shutdown process, before sending unregistration. The library
451 * tries to wait for the unpublication (un-PUBLISH) to complete before
452 * sending REGISTER request to unregister the account, during library
453 * shutdown process. If the value is set too short, it is possible that
454 * the unregistration is sent before unpublication completes, causing
455 * unpublication request to fail.
456 *
457 * Value is in milliseconds.
458 *
459 * Default: PJSUA_UNPUBLISH_MAX_WAIT_TIME_MSEC (2000)
460 */
461 unsigned publishShutdownWaitMsec;
462
463 /**
464 * Optional PIDF tuple ID for outgoing PUBLISH and NOTIFY. If this value
465 * is not specified, a random string will be used.
466 */
467 string pidfTupleId;
468
469 public:
470 /**
471 * Read this object from a container node.
472 *
473 * @param node Container to read values from.
474 */
475 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
476
477 /**
478 * Write this object to a container node.
479 *
480 * @param node Container to write values to.
481 */
482 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
483 };
484
485 /**
486 * Account MWI (Message Waiting Indication) settings. This will be specified
487 * in AccountConfig.
488 */
489 struct AccountMwiConfig : public PersistentObject
490 {
491 /**
492 * Subscribe to message waiting indication events (RFC 3842).
493 *
494 * See also UaConfig.mwiUnsolicitedEnabled setting.
495 *
496 * Default: FALSE
497 */
498 bool enabled;
499
500 /**
501 * Specify the default expiration time (in seconds) for Message
502 * Waiting Indication (RFC 3842) event subscription. This must not
503 * be zero.
504 *
505 * Default: PJSIP_MWI_DEFAULT_EXPIRES (3600)
506 */
507 unsigned expirationSec;
508
509 public:
510 /**
511 * Read this object from a container node.
512 *
513 * @param node Container to read values from.
514 */
515 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
516
517 /**
518 * Write this object to a container node.
519 *
520 * @param node Container to write values to.
521 */
522 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
523 };
524
525 /**
526 * Account's NAT (Network Address Translation) settings. This will be
527 * specified in AccountConfig.
528 */
529 struct AccountNatConfig : public PersistentObject
530 {
531 /**
532 * Control the use of STUN for the SIP signaling.
533 *
534 * Default: PJSUA_STUN_USE_DEFAULT
535 */
536 pjsua_stun_use sipStunUse;
537
538 /**
539 * Control the use of STUN for the media transports.
540 *
541 * Default: PJSUA_STUN_USE_DEFAULT
542 */
543 pjsua_stun_use mediaStunUse;
544
545 /**
546 * Control the use of UPnP for the SIP signaling.
547 *
548 * Default: PJSUA_UPNP_USE_DEFAULT
549 */
550 pjsua_upnp_use sipUpnpUse;
551
552 /**
553 * Control the use of UPnP for the media transports.
554 *
555 * Default: PJSUA_UPNP_USE_DEFAULT
556 */
557 pjsua_upnp_use mediaUpnpUse;
558
559 /**
560 * Specify NAT64 options.
561 *
562 * Default: PJSUA_NAT64_DISABLED
563 */
564 pjsua_nat64_opt nat64Opt;
565
566 /**
567 * Enable ICE for the media transport.
568 *
569 * Default: False
570 */
571 bool iceEnabled;
572
573 /**
574 * Set trickle ICE mode for ICE media transport.
575 *
576 * Default: PJ_ICE_SESS_TRICKLE_DISABLED
577 */
578 pj_ice_sess_trickle iceTrickle;
579
580 /**
581 * Set the maximum number of ICE host candidates.
582 *
583 * Default: -1 (maximum not set)
584 */
585 int iceMaxHostCands;
586
587 /**
588 * Optional configuration to manually specify host candidates.
589 * Each candidate will use the same port as the automatic/base host
590 * candidate. The number of entries in this array must be equal or less
591 * than \a iceMaxHostCands.
592 */
593 SocketAddressVector iceManualHost;
594
595 /**
596 * Specify whether to use aggressive nomination.
597 *
598 * Default: True
599 */
600 bool iceAggressiveNomination;
601
602 /**
603 * For controlling agent if it uses regular nomination, specify the delay
604 * to perform nominated check (connectivity check with USE-CANDIDATE
605 * attribute) after all components have a valid pair.
606 *
607 * Default value is PJ_ICE_NOMINATED_CHECK_DELAY.
608 */
609 unsigned iceNominatedCheckDelayMsec;
610
611 /**
612 * For a controlled agent, specify how long it wants to wait (in
613 * milliseconds) for the controlling agent to complete sending
614 * connectivity check with nominated flag set to true for all components
615 * after the controlled agent has found that all connectivity checks in
616 * its checklist have been completed and there is at least one successful
617 * (but not nominated) check for every component.
618 *
619 * Default value for this option is
620 * ICE_CONTROLLED_AGENT_WAIT_NOMINATION_TIMEOUT. Specify -1 to disable
621 * this timer.
622 */
623 int iceWaitNominationTimeoutMsec;
624
625 /**
626 * Specify whether to check the source address of the incoming messages.
627 * The source address will be compared to the remote candidate which has
628 * a completed connectivity check or received a connectivity check.
629 *
630 * Default value is PJ_ICE_SESS_CHECK_SRC_ADDR.
631 */
632 unsigned iceCheckSrcAddr;
633
634 /**
635 * Disable RTCP component.
636 *
637 * Default: False
638 */
639 bool iceNoRtcp;
640
641 /**
642 * Always send re-INVITE/UPDATE after ICE negotiation regardless of whether
643 * the default ICE transport address is changed or not. When this is set
644 * to False, re-INVITE/UPDATE will be sent only when the default ICE
645 * transport address is changed.
646 *
647 * Default: yes
648 */
649 bool iceAlwaysUpdate;
650
651 /**
652 * Enable TURN candidate in ICE.
653 */
654 bool turnEnabled;
655
656 /**
657 * Specify TURN domain name or host name, in in "DOMAIN:PORT" or
658 * "HOST:PORT" format.
659 */
660 string turnServer;
661
662 /**
663 * Specify the connection type to be used to the TURN server. Valid
664 * values are PJ_TURN_TP_UDP or PJ_TURN_TP_TCP.
665 *
666 * Default: PJ_TURN_TP_UDP
667 */
668 pj_turn_tp_type turnConnType;
669
670 /**
671 * Specify the username to authenticate with the TURN server.
672 */
673 string turnUserName;
674
675 /**
676 * Specify the type of password. Currently this must be zero to
677 * indicate plain-text password will be used in the password.
678 */
679 int turnPasswordType;
680
681 /**
682 * Specify the password to authenticate with the TURN server.
683 */
684 string turnPassword;
685
686 /**
687 * This option is used to update the transport address and the Contact
688 * header of REGISTER request. When this option is enabled, the library
689 * will keep track of the public IP address from the response of REGISTER
690 * request. Once it detects that the address has changed, it will
691 * unregister current Contact, update the Contact with transport address
692 * learned from Via header, and register a new Contact to the registrar.
693 * This will also update the public name of UDP transport if STUN is
694 * configured.
695 *
696 * Possible values:
697 * * 0 (disabled).
698 * * 1 (enabled). Update except if both Contact and server's IP address
699 * are public but response contains private IP.
700 * * 2 (enabled). Update without exception.
701 *
702 * See also contactRewriteMethod field.
703 *
704 * Default: 1
705 */
706 int contactRewriteUse;
707
708 /**
709 * Specify how Contact update will be done with the registration, if
710 * \a contactRewriteEnabled is enabled. The value is bitmask combination of
711 * \a pjsua_contact_rewrite_method. See also pjsua_contact_rewrite_method.
712 *
713 * Value PJSUA_CONTACT_REWRITE_UNREGISTER(1) is the legacy behavior.
714 *
715 * Default value: PJSUA_CONTACT_REWRITE_METHOD
716 * (PJSUA_CONTACT_REWRITE_NO_UNREG | PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE)
717 */
718 int contactRewriteMethod;
719
720 /**
721 * Specify if source TCP port should be used as the initial Contact
722 * address if TCP/TLS transport is used. Note that this feature will
723 * be automatically turned off when nameserver is configured because
724 * it may yield different destination address due to DNS SRV resolution.
725 * Also some platforms are unable to report the local address of the
726 * TCP socket when it is still connecting. In these cases, this
727 * feature will also be turned off.
728 *
729 * Default: 1 (PJ_TRUE / yes).
730 */
731 int contactUseSrcPort;
732
733 /**
734 * This option is used to overwrite the "sent-by" field of the Via header
735 * for outgoing messages with the same interface address as the one in
736 * the REGISTER request, as long as the request uses the same transport
737 * instance as the previous REGISTER request.
738 *
739 * Default: 1 (PJ_TRUE / yes)
740 */
741 int viaRewriteUse;
742
743 /**
744 * This option controls whether the IP address in SDP should be replaced
745 * with the IP address found in Via header of the REGISTER response, ONLY
746 * when STUN and ICE are not used. If the value is FALSE (the original
747 * behavior), then the local IP address will be used. If TRUE, and when
748 * STUN and ICE are disabled, then the IP address found in registration
749 * response will be used.
750 *
751 * Default: PJ_FALSE (no)
752 */
753 int sdpNatRewriteUse;
754
755 /**
756 * Control the use of SIP outbound feature. SIP outbound is described in
757 * RFC 5626 to enable proxies or registrar to send inbound requests back
758 * to UA using the same connection initiated by the UA for its
759 * registration. This feature is highly useful in NAT-ed deployemtns,
760 * hence it is enabled by default.
761 *
762 * Note: currently SIP outbound can only be used with TCP and TLS
763 * transports. If UDP is used for the registration, the SIP outbound
764 * feature will be silently ignored for the account.
765 *
766 * Default: 1 (PJ_TRUE / yes)
767 */
768 int sipOutboundUse;
769
770 /**
771 * Specify SIP outbound (RFC 5626) instance ID to be used by this
772 * account. If empty, an instance ID will be generated based on
773 * the hostname of this agent. If application specifies this parameter, the
774 * value will look like "<urn:uuid:00000000-0000-1000-8000-AABBCCDDEEFF>"
775 * without the double-quotes.
776 *
777 * Default: empty
778 */
779 string sipOutboundInstanceId;
780
781 /**
782 * Specify SIP outbound (RFC 5626) registration ID. The default value
783 * is empty, which would cause the library to automatically generate
784 * a suitable value.
785 *
786 * Default: empty
787 */
788 string sipOutboundRegId;
789
790 /**
791 * Set the interval for periodic keep-alive transmission for this account.
792 * If this value is zero, keep-alive will be disabled for this account.
793 * The keep-alive transmission will be sent to the registrar's address,
794 * after successful registration.
795 *
796 * Default: 15 (seconds)
797 */
798 unsigned udpKaIntervalSec;
799
800 /**
801 * Specify the data to be transmitted as keep-alive packets.
802 *
803 * Default: CR-LF
804 */
805 string udpKaData;
806
807 public:
808 /**
809 * Default constructor
810 */
811 AccountNatConfig() : sipStunUse(PJSUA_STUN_USE_DEFAULT),
812 mediaStunUse(PJSUA_STUN_USE_DEFAULT),
813 sipUpnpUse(PJSUA_UPNP_USE_DEFAULT),
814 mediaUpnpUse(PJSUA_UPNP_USE_DEFAULT),
815 nat64Opt(PJSUA_NAT64_DISABLED),
816 iceEnabled(false),
817 iceTrickle(PJ_ICE_SESS_TRICKLE_DISABLED),
818 iceMaxHostCands(-1),
819 iceAggressiveNomination(true),
820 iceNominatedCheckDelayMsec(PJ_ICE_NOMINATED_CHECK_DELAY),
821 iceWaitNominationTimeoutMsec(ICE_CONTROLLED_AGENT_WAIT_NOMINATION_TIMEOUT),
822 iceCheckSrcAddr(PJ_ICE_SESS_CHECK_SRC_ADDR),
823 iceNoRtcp(false),
824 iceAlwaysUpdate(true),
825 turnEnabled(false),
826 turnConnType(PJ_TURN_TP_UDP),
827 turnPasswordType(0),
828 contactRewriteUse(PJ_TRUE),
829 contactRewriteMethod(PJSUA_CONTACT_REWRITE_METHOD),
830 contactUseSrcPort(PJ_TRUE),
831 viaRewriteUse(PJ_TRUE),
832 sdpNatRewriteUse(PJ_FALSE),
833 sipOutboundUse(PJ_TRUE),
834 udpKaIntervalSec(15),
835 udpKaData("\r\n")
836 {}
837
838 /**
839 * Read this object from a container node.
840 *
841 * @param node Container to read values from.
842 */
843 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
844
845 /**
846 * Write this object to a container node.
847 *
848 * @param node Container to write values to.
849 */
850 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
851 };
852
853 /**
854 * This structure contains parameters for Account::sendRequest()
855 */
856 struct SendRequestParam
857 {
858 /**
859 * Token or arbitrary user data ownd by the application,
860 * which will be passed back in callback Account::onSendRequest().
861 */
862 Token userData;
863
864 /**
865 * SIP method of the request.
866 */
867 string method;
868
869 /**
870 * Message body and/or list of headers etc. to be included in
871 * the outgoing request.
872 */
873 SipTxOption txOption;
874
875 public:
876 /**
877 * Default constructor initializes with zero/empty values.
878 */
879 SendRequestParam();
880 };
881
882 /**
883 * SRTP crypto.
884 */
885 struct SrtpCrypto
886 {
887 /**
888 * Optional key. If empty, a random key will be autogenerated.
889 */
890 string key;
891
892 /**
893 * Crypto name.
894 */
895 string name;
896
897 /**
898 * Flags, bitmask from #pjmedia_srtp_crypto_option
899 */
900 unsigned flags;
901
902 public:
903 /**
904 * Convert from pjsip
905 */
906 void fromPj(const pjmedia_srtp_crypto &prm);
907
908 /**
909 * Convert to pjsip
910 */
911 pjmedia_srtp_crypto toPj() const;
912 };
913
914 /** Array of SRTP cryptos. */
915 typedef std::vector<SrtpCrypto> SrtpCryptoVector;
916
917 /**
918 * SRTP settings.
919 */
920 struct SrtpOpt : public PersistentObject
921 {
922 /**
923 * Specify SRTP cryptos. If empty, all crypto will be enabled.
924 * Available crypto can be enumerated using Endpoint::srtpCryptoEnum().
925 *
926 * Default: empty.
927 */
928 SrtpCryptoVector cryptos;
929
930 /**
931 * Specify SRTP keying methods, valid keying method is defined in
932 * pjmedia_srtp_keying_method. If empty, all keying methods will be
933 * enabled with priority order: SDES, DTLS-SRTP.
934 *
935 * Default: empty.
936 */
937 IntVector keyings;
938
939 public:
940 /**
941 * Default constructor initializes with default values.
942 */
943 SrtpOpt();
944
945 /**
946 * Convert from pjsip
947 */
948 void fromPj(const pjsua_srtp_opt &prm);
949
950 /**
951 * Convert to pjsip
952 */
953 pjsua_srtp_opt toPj() const;
954
955 public:
956 /**
957 * Read this object from a container node.
958 *
959 * @param node Container to read values from.
960 */
961 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
962
963 /**
964 * Write this object to a container node.
965 *
966 * @param node Container to write values to.
967 */
968 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
969 };
970
971 /**
972 * RTCP Feedback capability.
973 */
974 struct RtcpFbCap
975 {
976 /**
977 * Specify the codecs to which the capability is applicable. Codec ID is
978 * using the same format as in pjmedia_codec_mgr_find_codecs_by_id() and
979 * pjmedia_vid_codec_mgr_find_codecs_by_id(), e.g: "L16/8000/1", "PCMU",
980 * "H264". This can also be an asterisk ("*") to represent all codecs.
981 */
982 string codecId;
983
984 /**
985 * Specify the RTCP Feedback type.
986 */
987 pjmedia_rtcp_fb_type type;
988
989 /**
990 * Specify the type name if RTCP Feedback type is PJMEDIA_RTCP_FB_OTHER.
991 */
992 string typeName;
993
994 /**
995 * Specify the RTCP Feedback parameters.
996 */
997 string param;
998
999 public:
1000 /**
1001 * Constructor.
1002 */
1003 RtcpFbCap() : type(PJMEDIA_RTCP_FB_OTHER)
1004 {}
1005
1006 /**
1007 * Convert from pjsip
1008 */
1009 void fromPj(const pjmedia_rtcp_fb_cap &prm);
1010
1011 /**
1012 * Convert to pjsip
1013 */
1014 pjmedia_rtcp_fb_cap toPj() const;
1015 };
1016
1017 /** Array of RTCP Feedback capabilities. */
1018 typedef std::vector<RtcpFbCap> RtcpFbCapVector;
1019
1020
1021 /**
1022 * RTCP Feedback settings.
1023 */
1024 struct RtcpFbConfig : public PersistentObject
1025 {
1026 /**
1027 * Specify whether transport protocol in SDP media description uses
1028 * RTP/AVP instead of RTP/AVPF. Note that the standard mandates to signal
1029 * AVPF profile, but it may cause SDP negotiation failure when negotiating
1030 * with endpoints that does not support RTCP Feedback (including older
1031 * version of PJSIP).
1032 *
1033 * Default: false.
1034 */
1035 bool dontUseAvpf;
1036
1037 /**
1038 * RTCP Feedback capabilities.
1039 */
1040 RtcpFbCapVector caps;
1041
1042 public:
1043 /**
1044 * Constructor.
1045 */
1046 RtcpFbConfig();
1047
1048 /**
1049 * Convert from pjsip
1050 */
1051 void fromPj(const pjmedia_rtcp_fb_setting &prm);
1052
1053 /**
1054 * Convert to pjsip
1055 */
1056 pjmedia_rtcp_fb_setting toPj() const;
1057
1058 public:
1059 /**
1060 * Read this object from a container node.
1061 *
1062 * @param node Container to read values from.
1063 */
1064 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
1065
1066 /**
1067 * Write this object to a container node.
1068 *
1069 * @param node Container to write values to.
1070 */
1071 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
1072 };
1073
1074 /**
1075 * Account media config (applicable for audio, video, and text). This will be
1076 * specified in AccountConfig.
1077 */
1078 struct AccountMediaConfig : public PersistentObject
1079 {
1080 /**
1081 * Media transport (RTP) configuration.
1082 *
1083 * For \a port and \a portRange settings, RTCP port is selected as
1084 * RTP port+1.
1085 * Example: \a port=5000, \a portRange=4
1086 * - Available ports: 5000, 5002, 5004 (Media/RTP transport)
1087 * 5001, 5003, 5005 (Media/RTCP transport)
1088 */
1089 TransportConfig transportConfig;
1090
1091 /**
1092 * If remote sends SDP answer containing more than one format or codec in
1093 * the media line, send re-INVITE or UPDATE with just one codec to lock
1094 * which codec to use.
1095 *
1096 * Default: True (Yes).
1097 */
1098 bool lockCodecEnabled;
1099
1100 /**
1101 * Specify whether stream keep-alive and NAT hole punching with
1102 * non-codec-VAD mechanism (see PJMEDIA_STREAM_ENABLE_KA) is enabled
1103 * for this account.
1104 *
1105 * Default: False
1106 */
1107 bool streamKaEnabled;
1108
1109 /**
1110 * Specify whether secure media transport should be used for this account.
1111 * Valid values are PJMEDIA_SRTP_DISABLED, PJMEDIA_SRTP_OPTIONAL, and
1112 * PJMEDIA_SRTP_MANDATORY.
1113 *
1114 * Default: PJSUA_DEFAULT_USE_SRTP
1115 */
1116 pjmedia_srtp_use srtpUse;
1117
1118 /**
1119 * Specify whether SRTP requires secure signaling to be used. This option
1120 * is only used when \a use_srtp option above is non-zero.
1121 *
1122 * Valid values are:
1123 * 0: SRTP does not require secure signaling
1124 * 1: SRTP requires secure transport such as TLS
1125 * 2: SRTP requires secure end-to-end transport (SIPS)
1126 *
1127 * Default: PJSUA_DEFAULT_SRTP_SECURE_SIGNALING
1128 */
1129 int srtpSecureSignaling;
1130
1131 /**
1132 * Specify SRTP settings, like cryptos and keying methods.
1133 */
1134 SrtpOpt srtpOpt;
1135
1136 /**
1137 * Specify whether IPv6 should be used on media.
1138 *
1139 * Default: PJSUA_IPV6_ENABLED_PREFER_IPV4
1140 * (Dual stack media, capable to use IPv4/IPv6.
1141 * Outgoing offer will prefer to use IPv4)
1142 */
1143 pjsua_ipv6_use ipv6Use;
1144
1145 /**
1146 * Enable RTP and RTCP multiplexing.
1147 * Default: false
1148 */
1149 bool rtcpMuxEnabled;
1150
1151 /**
1152 * RTCP Feedback settings.
1153 */
1154 RtcpFbConfig rtcpFbConfig;
1155
1156 /**
1157 * Enable RTCP Extended Report (RTCP XR).
1158 *
1159 * Default: PJMEDIA_STREAM_ENABLE_XR
1160 */
1161 bool rtcpXrEnabled;
1162
1163 /**
1164 * Use loopback media transport. This may be useful if application
1165 * doesn't want PJSUA2 to create real media transports/sockets, such as
1166 * when using third party media.
1167 *
1168 * Default: false
1169 */
1170 bool useLoopMedTp;
1171
1172 /**
1173 * Enable local loopback when useLoopMedTp is set to TRUE.
1174 * If enabled, packets sent to the transport will be sent back to
1175 * the streams attached to the transport.
1176 *
1177 * Default: false
1178 */
1179 bool enableLoopback;
1180
1181 public:
1182 /**
1183 * Default constructor
1184 */
1185 AccountMediaConfig()
1186 : lockCodecEnabled(true),
1187 streamKaEnabled(false),
1188 srtpUse(PJSUA_DEFAULT_USE_SRTP),
1189 srtpSecureSignaling(PJSUA_DEFAULT_SRTP_SECURE_SIGNALING),
1190 ipv6Use(PJSUA_IPV6_ENABLED_PREFER_IPV4),
1191 rtcpMuxEnabled(false),
1192 rtcpXrEnabled(PJMEDIA_STREAM_ENABLE_XR),
1193 useLoopMedTp(false),
1194 enableLoopback(false)
1195 {}
1196
1197 /**
1198 * Read this object from a container node.
1199 *
1200 * @param node Container to read values from.
1201 */
1202 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
1203
1204 /**
1205 * Write this object to a container node.
1206 *
1207 * @param node Container to write values to.
1208 */
1209 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
1210 };
1211
1212 /**
1213 * Account video config. This will be specified in AccountConfig.
1214 */
1215 struct AccountVideoConfig : public PersistentObject
1216 {
1217 /**
1218 * Specify whether incoming video should be shown to screen by default.
1219 * This applies to incoming call (INVITE), incoming re-INVITE, and
1220 * incoming UPDATE requests.
1221 *
1222 * Regardless of this setting, application can detect incoming video
1223 * by implementing \a on_call_media_state() callback and enumerating
1224 * the media stream(s) with pjsua_call_get_info(). Once incoming
1225 * video is recognised, application may retrieve the window associated
1226 * with the incoming video and show or hide it with
1227 * pjsua_vid_win_set_show().
1228 *
1229 * Default: False
1230 */
1231 bool autoShowIncoming;
1232
1233 /**
1234 * Specify whether outgoing video should be activated by default when
1235 * making outgoing calls and/or when incoming video is detected. This
1236 * applies to incoming and outgoing calls, incoming re-INVITE, and
1237 * incoming UPDATE. If the setting is non-zero, outgoing video
1238 * transmission will be started as soon as response to these requests
1239 * is sent (or received).
1240 *
1241 * Regardless of the value of this setting, application can start and
1242 * stop outgoing video transmission with pjsua_call_set_vid_strm().
1243 *
1244 * Default: False
1245 */
1246 bool autoTransmitOutgoing;
1247
1248 /**
1249 * Specify video window's flags. The value is a bitmask combination of
1250 * pjmedia_vid_dev_wnd_flag.
1251 *
1252 * Default: 0
1253 */
1254 unsigned windowFlags;
1255
1256 /**
1257 * Specify the default capture device to be used by this account. If
1258 * vidOutAutoTransmit is enabled, this device will be used for
1259 * capturing video.
1260 *
1261 * Default: PJMEDIA_VID_DEFAULT_CAPTURE_DEV
1262 */
1263 pjmedia_vid_dev_index defaultCaptureDevice;
1264
1265 /**
1266 * Specify the default rendering device to be used by this account.
1267 *
1268 * Default: PJMEDIA_VID_DEFAULT_RENDER_DEV
1269 */
1270 pjmedia_vid_dev_index defaultRenderDevice;
1271
1272 /**
1273 * Rate control method.
1274 *
1275 * Default: PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING.
1276 */
1277 pjmedia_vid_stream_rc_method rateControlMethod;
1278
1279 /**
1280 * Upstream/outgoing bandwidth. If this is set to zero, the video stream
1281 * will use codec maximum bitrate setting.
1282 *
1283 * Default: 0 (follow codec maximum bitrate).
1284 */
1285 unsigned rateControlBandwidth;
1286
1287 /**
1288 * The number of keyframe to be sent after the stream is created.
1289 *
1290 * Default: PJMEDIA_VID_STREAM_START_KEYFRAME_CNT
1291 */
1292 unsigned startKeyframeCount;
1293
1294 /**
1295 * The keyframe sending interval after the stream is created.
1296 *
1297 * Default: PJMEDIA_VID_STREAM_START_KEYFRAME_INTERVAL_MSEC
1298 */
1299 unsigned startKeyframeInterval;
1300
1301
1302 public:
1303 /**
1304 * Default constructor
1305 */
1306 AccountVideoConfig()
1307 : autoShowIncoming(false),
1308 autoTransmitOutgoing(false),
1309 windowFlags(0),
1310 defaultCaptureDevice(PJMEDIA_VID_DEFAULT_CAPTURE_DEV),
1311 defaultRenderDevice(PJMEDIA_VID_DEFAULT_RENDER_DEV),
1312 rateControlMethod(PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING),
1313 rateControlBandwidth(0),
1314 startKeyframeCount(PJMEDIA_VID_STREAM_START_KEYFRAME_CNT),
1315 startKeyframeInterval(PJMEDIA_VID_STREAM_START_KEYFRAME_INTERVAL_MSEC)
1316 {}
1317
1318 /**
1319 * Read this object from a container node.
1320 *
1321 * @param node Container to read values from.
1322 */
1323 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
1324
1325 /**
1326 * Write this object to a container node.
1327 *
1328 * @param node Container to write values to.
1329 */
1330 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
1331 };
1332
1333 /**
1334 * Account text config. This will be specified in AccountConfig.
1335 */
1336 struct AccountTextConfig : public PersistentObject
1337 {
1338 /**
1339 * Specifies text stream redundancy level, as specified in RFC 4103
1340 * and 2198. When redundancy is enabled, each packet transmission
1341 * will contain the current text data as well as a number of the
1342 * previously transmitted text data to provide levels of redundancy.
1343 * This mechanism offers protection against loss of data at the cost
1344 * of additional bandwidth required.
1345 *
1346 * Value is integer indicating redundancy levels, i.e. the number
1347 * of previous text data to be included with the current packet.
1348 * (0 means disabled/no redundancy).
1349 * A value of 1 provides an adequate protection against an average
1350 * packet loss of up to 50%, while 2 can potentially protect
1351 * against 66.7%.
1352 * The maximum value is determined by PJMEDIA_TXT_STREAM_MAX_RED_LEVELS.
1353 *
1354 * Note that the redundancy level actually used is subject to remote
1355 * capability and we will opt to use the lower redundancy value based
1356 * on the result of SDP negotiation.
1357 *
1358 * Default: PJSUA_TXT_DEFAULT_REDUNDANCY_LEVEL (2), as per the
1359 * recommendation of RFC 4103.
1360 */
1361 int redundancyLevel;
1362
1363 public:
1364 /**
1365 * Default constructor
1366 */
1367 AccountTextConfig()
1368 : redundancyLevel(PJSUA_TXT_DEFAULT_REDUNDANCY_LEVEL)
1369 {}
1370
1371 /**
1372 * Read this object from a container node.
1373 *
1374 * @param node Container to read values from.
1375 */
1376 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
1377
1378 /**
1379 * Write this object to a container node.
1380 *
1381 * @param node Container to write values to.
1382 */
1383 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
1384 };
1385
1386 /**
1387 * Account config specific to IP address change.
1388 */
1389 typedef struct AccountIpChangeConfig
1390 {
1391 /**
1392 * Shutdown the transport used for account registration. If this is set to
1393 * PJ_TRUE, the transport will be shutdown altough it's used by multiple
1394 * account. Shutdown transport will be followed by re-Registration if
1395 * AccountConfig.natConfig.contactRewriteUse is enabled.
1396 *
1397 * Default: true
1398 */
1399 bool shutdownTp;
1400
1401 /**
1402 * Hangup active calls associated with the acount. If this is set to true,
1403 * then the calls will be hang up.
1404 *
1405 * Default: false
1406 */
1407 bool hangupCalls;
1408
1409 /**
1410 * Specify the call flags used in the re-INVITE when \a hangupCalls is set
1411 * to false. If this is set to 0, no re-INVITE will be sent. The
1412 * re-INVITE will be sent after re-Registration is finished.
1413 *
1414 * Default: PJSUA_CALL_REINIT_MEDIA | PJSUA_CALL_UPDATE_CONTACT |
1415 * PJSUA_CALL_UPDATE_VIA
1416 */
1417 unsigned reinviteFlags;
1418
1419 /**
1420 * For refreshing the call, use SIP UPDATE, instead of re-INVITE, if
1421 * remote supports it (by publishing it in Allow header). If remote
1422 * does not support UPDATE method or somehow the UPDATE attempt fails,
1423 * it will fallback to using re-INVITE. The \a reinviteFlags will be
1424 * used regardless whether it is re-INVITE or UPDATE that is sent.
1425 *
1426 * Default: PJ_FALSE (using re-INVITE).
1427 */
1428 unsigned reinvUseUpdate;
1429
1430 public:
1431 /**
1432 * Virtual destructor
1433 */
1434 virtual ~AccountIpChangeConfig()
1435 {}
1436
1437 /**
1438 * Read this object from a container node.
1439 *
1440 * @param node Container to read values from.
1441 */
1442 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
1443
1444 /**
1445 * Write this object to a container node.
1446 *
1447 * @param node Container to write values to.
1448 */
1449 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
1450
1451 } AccountIpChangeConfig;
1452
1453 /**
1454 * Account configuration.
1455 */
1456 struct AccountConfig : public PersistentObject
1457 {
1458 /**
1459 * Account priority, which is used to control the order of matching
1460 * incoming/outgoing requests. The higher the number means the higher
1461 * the priority is, and the account will be matched first.
1462 */
1463 int priority;
1464
1465 /**
1466 * The Address of Record or AOR, that is full SIP URL that identifies the
1467 * account. The value can take name address or URL format, and will look
1468 * something like "sip:account@serviceprovider".
1469 *
1470 * This field is mandatory.
1471 */
1472 string idUri;
1473
1474 /**
1475 * Registration settings.
1476 */
1477 AccountRegConfig regConfig;
1478
1479 /**
1480 * SIP settings.
1481 */
1482 AccountSipConfig sipConfig;
1483
1484 /**
1485 * Call settings.
1486 */
1487 AccountCallConfig callConfig;
1488
1489 /**
1490 * Presence settings.
1491 */
1492 AccountPresConfig presConfig;
1493
1494 /**
1495 * MWI (Message Waiting Indication) settings.
1496 */
1497 AccountMwiConfig mwiConfig;
1498
1499 /**
1500 * NAT settings.
1501 */
1502 AccountNatConfig natConfig;
1503
1504 /**
1505 * Media settings (applicable for audio, video, and text).
1506 */
1507 AccountMediaConfig mediaConfig;
1508
1509 /**
1510 * Video settings.
1511 */
1512 AccountVideoConfig videoConfig;
1513
1514 /**
1515 * Text settings.
1516 */
1517 AccountTextConfig textConfig;
1518
1519 /**
1520 * IP Change settings.
1521 */
1522 AccountIpChangeConfig ipChangeConfig;
1523
1524 public:
1525 /**
1526 * Default constructor will initialize with default values.
1527 */
1528 AccountConfig();
1529
1530 /**
1531 * This will return a temporary pjsua_acc_config instance, which contents
1532 * are only valid as long as this AccountConfig structure remains valid
1533 * AND no modifications are done to it AND no further toPj() function call
1534 * is made. Any call to toPj() function will invalidate the content of
1535 * temporary pjsua_acc_config that was returned by the previous call.
1536 */
1537 void toPj(pjsua_acc_config &cfg) const;
1538
1539 /**
1540 * Initialize from pjsip.
1541 */
1542 void fromPj(const pjsua_acc_config &prm, const pjsua_media_config *mcfg);
1543
1544 /**
1545 * Read this object from a container node.
1546 *
1547 * @param node Container to read values from.
1548 */
1549 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
1550
1551 /**
1552 * Write this object to a container node.
1553 *
1554 * @param node Container to write values to.
1555 */
1556 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
1557 };
1558
1559
1560 /**
1561 * Account information. Application can query the account information
1562 * by calling Account::getInfo().
1563 */
1564 struct AccountInfo
1565 {
1566 /**
1567 * The account ID.
1568 */
1569 pjsua_acc_id id;
1570
1571 /**
1572 * Flag to indicate whether this is the default account.
1573 */
1574 bool isDefault;
1575
1576 /**
1577 * Account URI
1578 */
1579 string uri;
1580
1581 /**
1582 * Flag to tell whether this account has registration setting
1583 * (reg_uri is not empty).
1584 */
1585 bool regIsConfigured;
1586
1587 /**
1588 * Flag to tell whether this account is currently registered
1589 * (has active registration session).
1590 */
1591 bool regIsActive;
1592
1593 /**
1594 * An up to date expiration interval for account registration session.
1595 */
1596 unsigned regExpiresSec;
1597
1598 /**
1599 * Last registration status code. If status code is zero, the account
1600 * is currently not registered. Any other value indicates the SIP
1601 * status code of the registration.
1602 */
1603 pjsip_status_code regStatus;
1604
1605 /**
1606 * String describing the registration status.
1607 */
1608 string regStatusText;
1609
1610 /**
1611 * Last registration error code. When the status field contains a SIP
1612 * status code that indicates a registration failure, last registration
1613 * error code contains the error code that causes the failure. In any
1614 * other case, its value is zero.
1615 */
1616 pj_status_t regLastErr;
1617
1618 /**
1619 * Presence online status for this account.
1620 */
1621 bool onlineStatus;
1622
1623 /**
1624 * Presence online status text.
1625 */
1626 string onlineStatusText;
1627
1628 public:
1629 /**
1630 * Default constructor
1631 */
1632 AccountInfo() : id(PJSUA_INVALID_ID),
1633 isDefault(false),
1634 regIsConfigured(false),
1635 regIsActive(false),
1636 regExpiresSec(0),
1637 regStatus(PJSIP_SC_NULL),
1638 regLastErr(-1),
1639 onlineStatus(false)
1640 {}
1641
1642 /** Import from pjsip data */
1643 void fromPj(const pjsua_acc_info &pai);
1644 };
1645
1646 /**
1647 * This structure contains parameters for onIncomingCall() account callback.
1648 */
1649 struct OnIncomingCallParam
1650 {
1651 /**
1652 * The library call ID allocated for the new call.
1653 */
1654 int callId;
1655
1656 /**
1657 * The incoming INVITE request.
1658 */
1659 SipRxData rdata;
1660 };
1661
1662 /**
1663 * This structure contains parameters for onRegStarted() account callback.
1664 */
1665 struct OnRegStartedParam
1666 {
1667 /**
1668 * True for registration and False for unregistration.
1669 */
1670 bool renew;
1671 };
1672
1673 /**
1674 * This structure contains parameters for onRegState() account callback.
1675 */
1676 struct OnRegStateParam
1677 {
1678 /**
1679 * Registration operation status.
1680 */
1681 pj_status_t status;
1682
1683 /**
1684 * SIP status code received.
1685 */
1686 pjsip_status_code code;
1687
1688 /**
1689 * SIP reason phrase received.
1690 */
1691 string reason;
1692
1693 /**
1694 * The incoming message.
1695 */
1696 SipRxData rdata;
1697
1698 /**
1699 * Next expiration interval.
1700 */
1701 unsigned expiration;
1702 };
1703
1704 /**
1705 * This structure contains parameters for onIncomingSubscribe() callback.
1706 */
1707 struct OnIncomingSubscribeParam
1708 {
1709 /**
1710 * Server presence subscription instance. If application delays
1711 * the acceptance of the request, it will need to specify this object
1712 * when calling Account::presNotify().
1713 */
1714 void *srvPres;
1715
1716 /**
1717 * Sender URI.
1718 */
1719 string fromUri;
1720
1721 /**
1722 * The incoming message.
1723 */
1724 SipRxData rdata;
1725
1726 /**
1727 * The status code to respond to the request. The default value is 200.
1728 * Application may set this to other final status code to accept or
1729 * reject the request.
1730 */
1731 pjsip_status_code code;
1732
1733 /**
1734 * The reason phrase to respond to the request.
1735 */
1736 string reason;
1737
1738 /**
1739 * Additional data to be sent with the response, if any.
1740 */
1741 SipTxOption txOption;
1742 };
1743
1744 /**
1745 * Parameters for onInstantMessage() account callback.
1746 */
1747 struct OnInstantMessageParam
1748 {
1749 /**
1750 * Sender From URI.
1751 */
1752 string fromUri;
1753
1754 /**
1755 * To URI of the request.
1756 */
1757 string toUri;
1758
1759 /**
1760 * Contact URI of the sender.
1761 */
1762 string contactUri;
1763
1764 /**
1765 * MIME type of the message body.
1766 */
1767 string contentType;
1768
1769 /**
1770 * The message body.
1771 */
1772 string msgBody;
1773
1774 /**
1775 * The whole message.
1776 */
1777 SipRxData rdata;
1778 };
1779
1780 /**
1781 * Parameters for onInstantMessageStatus() account callback.
1782 */
1783 struct OnInstantMessageStatusParam
1784 {
1785 /**
1786 * Token or a user data that was associated with the pager
1787 * transmission.
1788 */
1789 Token userData;
1790
1791 /**
1792 * Destination URI.
1793 */
1794 string toUri;
1795
1796 /**
1797 * The message body.
1798 */
1799 string msgBody;
1800
1801 /**
1802 * The SIP status code of the transaction.
1803 */
1804 pjsip_status_code code;
1805
1806 /**
1807 * The reason phrase of the transaction.
1808 */
1809 string reason;
1810
1811 /**
1812 * The incoming response that causes this callback to be called.
1813 * If the transaction fails because of time out or transport error,
1814 * the content will be empty.
1815 */
1816 SipRxData rdata;
1817 };
1818
1819 /**
1820 * Parameters for onTypingIndication() account callback.
1821 */
1822 struct OnTypingIndicationParam
1823 {
1824 /**
1825 * Sender/From URI.
1826 */
1827 string fromUri;
1828
1829 /**
1830 * To URI.
1831 */
1832 string toUri;
1833
1834 /**
1835 * The Contact URI.
1836 */
1837 string contactUri;
1838
1839 /**
1840 * Boolean to indicate if sender is typing.
1841 */
1842 bool isTyping;
1843
1844 /**
1845 * The whole message buffer.
1846 */
1847 SipRxData rdata;
1848 };
1849
1850 /**
1851 * Parameters for onMwiInfo() account callback.
1852 */
1853 struct OnMwiInfoParam
1854 {
1855 /**
1856 * MWI subscription state.
1857 */
1858 pjsip_evsub_state state;
1859
1860 /**
1861 * The whole message buffer.
1862 */
1863 SipRxData rdata;
1864 };
1865
1866 /**
1867 * This structure contains parameters for Account::onSendRequest() callback.
1868 */
1869 struct OnSendRequestParam
1870 {
1871 /**
1872 * Token or arbitrary user data owned by the application,
1873 * which was passed to Endpoint::sendRquest() function.
1874 */
1875 Token userData;
1876
1877 /**
1878 * Transaction event that caused the state change.
1879 */
1880 SipEvent e;
1881 };
1882
1883
1884 /**
1885 * Represents a pending authentication challenge.
1886 * Call respond() to resend with authentication, or abandon() to give up.
1887 * If neither is called before the callback returns, the library handles
1888 * authentication automatically using configured credentials (sync path).
1889 *
1890 * For async use, call defer() during the callback to obtain a heap-allocated
1891 * AuthChallenge that can be used later. The caller owns the returned object.
1892 *
1893 * Each AuthChallenge is single-use: once consumed by respond(), abandon(),
1894 * or defer(), further calls return PJ_EINVALIDOP (defer() throws Error).
1895 *
1896 * Thread safety: on a deferred object, respond() and abandon() must be called
1897 * from a pjlib-registered thread. The non-deferred object must only be used
1898 * during the onAuthChallenge() callback.
1899 *
1900 * GC note (Python/Java): The destructor calls pjsip APIs which require a
1901 * pjlib-registered thread. Since garbage collectors may run destructor/
1902 * Release() on an unregistered finalizer thread, you MUST explicitly call
1903 * respond(), abandon(), or delete/Release() on the deferred object from a
1904 * pjlib-registered thread. Do NOT let the GC collect it implicitly.
1905 * See https://docs.pjsip.org/en/latest/pjsua2/general_concept.html#problems-with-garbage-collection
1906 */
1907 class AuthChallenge
1908 {
1909 public:
1910 AuthChallenge();
1911
1912 /**
1913 * Destructor. If this is a deferred challenge that was never consumed
1914 * by respond() or abandon(), destruction will auto-abandon the pending
1915 * authentication and release associated resources.
1916 */
1917 ~AuthChallenge();
1918
1919 /**
1920 * Defer the challenge for asynchronous handling. Creates a new
1921 * heap-allocated AuthChallenge that can be used after the callback
1922 * returns. The caller owns the returned object and must eventually
1923 * call respond() or abandon() on it (or simply delete it, which
1924 * auto-abandons).
1925 *
1926 * Must be called during the onAuthChallenge() callback. After this
1927 * call, the original AuthChallenge becomes invalid.
1928 *
1929 * @return New heap-allocated AuthChallenge (caller owns).
1930 */
1931 AuthChallenge* defer() PJSUA2_THROW(Error);
1932
1933 /**
1934 * Respond to the authentication challenge by building and sending
1935 * an authenticated request. Uses credentials currently configured
1936 * on the auth session.
1937 *
1938 * @return PJ_SUCCESS on success, or PJ_EINVALIDOP if already
1939 * consumed by a prior respond()/abandon()/defer() call.
1940 */
1941 pj_status_t respond();
1942
1943 /**
1944 * Respond with provided credentials. Sets them on the account-level
1945 * shared auth session before building the authenticated request.
1946 * Note that this permanently replaces the account's credentials,
1947 * affecting all subsequent authentication for the account.
1948 *
1949 * @param creds Credentials to set on the auth session.
1950 * @return PJ_SUCCESS on success.
1951 */
1952 pj_status_t respond(const AuthCredInfoVector &creds);
1953
1954 /**
1955 * Abandon the authentication challenge. The pending request will
1956 * not be resent.
1957 *
1958 * @return PJ_SUCCESS on success, or PJ_EINVALIDOP if already
1959 * consumed by a prior respond()/abandon()/defer() call.
1960 */
1961 pj_status_t abandon();
1962
1963 /**
1964 * Check whether this challenge object is still valid (not yet
1965 * consumed by respond() or abandon(), and the associated account
1966 * is still active).
1967 *
1968 * Note: this is an advisory check without synchronization.
1969 * The result may be stale if another thread concurrently
1970 * deletes the account.
1971 *
1972 * @return true if valid.
1973 */
1974 bool isValid() const;
1975
1976 private:
1977 friend class Endpoint;
1978
1979 AuthChallenge(const AuthChallenge&);
1980 AuthChallenge& operator=(const AuthChallenge&);
1981
1982 pjsua_on_auth_challenge_param *param_;
1983 bool deferred_;
1984 bool consumed_;
1985 pjsip_rx_data *cloned_rdata_;
1986 pjsip_auth_clt_sess *auth_sess_;
1987 void *token_;
1988 pjsip_tx_data *tdata_;
1989 pjsua_acc_id acc_id_;
1990 };
1991
1992 /**
1993 * Parameters for Account::onAuthChallenge() callback.
1994 */
1995 struct OnAuthChallengeParam
1996 {
1997 /** Account ID associated with the challenged request. */
1998 pjsua_acc_id accId;
1999
2000 /** Call ID, or PJSUA_INVALID_ID for non-call requests. */
2001 pjsua_call_id callId;
2002
2003 /** The 401/407 response containing the challenge. */
2004 SipRxData rdata;
2005
2006 /** The authentication challenge. Call respond() or abandon(). */
2007 AuthChallenge challenge;
2008 };
2009
2010
2011 /**
2012 * Parameters for presNotify() account method.
2013 */
2014 struct PresNotifyParam
2015 {
2016 /**
2017 * Server presence subscription instance.
2018 */
2019 void *srvPres;
2020
2021 /**
2022 * Server presence subscription state to set.
2023 */
2024 pjsip_evsub_state state;
2025
2026 /**
2027 * Optionally specify the state string name, if state is not "active",
2028 * "pending", or "terminated".
2029 */
2030 string stateStr;
2031
2032 /**
2033 * If the new state is PJSIP_EVSUB_STATE_TERMINATED, optionally specify
2034 * the termination reason.
2035 */
2036 string reason;
2037
2038 /**
2039 * If the new state is PJSIP_EVSUB_STATE_TERMINATED, this specifies
2040 * whether the NOTIFY request should contain message body containing
2041 * account's presence information.
2042 */
2043 bool withBody;
2044
2045 /**
2046 * Optional list of headers to be sent with the NOTIFY request.
2047 */
2048 SipTxOption txOption;
2049 };
2050
2051
2052 /**
2053 * Wrapper class for Buddy matching algo.
2054 *
2055 * Default algo is a simple substring lookup of search-token in the
2056 * Buddy URIs, with case sensitive. Application can implement its own
2057 * matching algo by overriding this class and specifying its instance
2058 * in Account::findBuddy().
2059 */
2060 class FindBuddyMatch
2061 {
2062 public:
2063 /**
2064 * Default algo implementation.
2065 */
2066 virtual bool match(const string &token, const Buddy &buddy)
2067 {
2068 BuddyInfo bi = buddy.getInfo();
2069 return bi.uri.find(token) != string::npos;
2070 }
2071
2072 /**
2073 * Destructor.
2074 */
2075 virtual ~FindBuddyMatch() {}
2076 };
2077
2078 /**
2079 * This class is used to store the received parsed SIP MESSAGE request and
2080 * its transaction for use in sendResponse().
2081 */
2082 class DeferredResponse
2083 {
2084 friend class Account;
2085 public:
2086 /**
2087 * Constructor that clones the rx_data and keeps a non-owning pointer
2088 * to the transaction.
2089 * @param param The instant message parameters from the callback.
2090 */
2091 explicit
2092 DeferredResponse(const OnInstantMessageParam& param) PJSUA2_THROW(Error);
2093
2094 /**
2095 * Constructs an empty object. Must be assigned to before use.
2096 */
2097 DeferredResponse();
2098
2099 /**
2100 * Copies the deferred response object by cloning the rx_data.
2101 */
2102 DeferredResponse(const DeferredResponse& deferredResponse)
2103 PJSUA2_THROW(Error);
2104
2105 /**
2106 * Copies the deferred response object by cloning the rx_data.
2107 */
2108 DeferredResponse& operator=(const DeferredResponse& deferredResponse)
2109 PJSUA2_THROW(Error);
2110
2111 /* SWIG 4.x doesn't reliably match rvalue-reference signatures in
2112 * %ignore, and the target languages (Java/C#/Python) have no concept
2113 * of move semantics anyway. Hide the move ctor/assignment from SWIG.
2114 */
2115 #ifndef SWIG
2116 /**
2117 * Moves the deferred response object.
2118 */
2119 DeferredResponse(DeferredResponse&& deferredResponse) noexcept;
2120
2121 /**
2122 * Moves the deferred response object.
2123 */
2124 DeferredResponse& operator=(DeferredResponse&& deferredResponse) noexcept;
2125 #endif
2126
2127 /**
2128 * Destructor that frees possible cloned rx_data.
2129 */
2130 virtual ~DeferredResponse();
2131
2132 private:
2133 /**
2134 * Non-owning pointer to the registered transaction.
2135 */
2136 pjsip_transaction* transaction;
2137
2138 /**
2139 * Owning pointer to the cloned rx_data.
2140 */
2141 pjsip_rx_data* data = nullptr;
2142 };
2143
2144 /**
2145 * Parameters for Account::sendResponse().
2146 */
2147 struct SendResponseParam
2148 {
2149 /**
2150 * Deferred response object, which is valid until the response is sent.
2151 */
2152 DeferredResponse deferredResponse;
2153
2154 /**
2155 * Status code of the response.
2156 */
2157 int code;
2158
2159 /**
2160 * Optional reason phrase of the response.
2161 */
2162 string reason;
2163 };
2164
2165 /**
2166 * Parameters for Account::shutdown2().
2167 */
2168 struct AccountShutdownParam
2169 {
2170 /**
2171 * If true, the account will always be deleted even when there are
2172 * active calls using it (a warning will be logged). If false, the
2173 * function will throw an Error with PJ_EBUSY when active calls exist.
2174 *
2175 * Default: false
2176 */
2177 bool force;
2178
2179 /** Default constructor */
2180 AccountShutdownParam() : force(false) {}
2181 };
2182
2183 /**
2184 * Account.
2185 */
2186 class Account
2187 {
2188 public:
2189 /**
2190 * Constructor.
2191 */
2192 Account();
2193
2194 /**
2195 * Destructor. This will call shutdown() to always delete the
2196 * corresponding account in the PJSUA-LIB, even if there are active
2197 * calls. This ensures no resource leak occurs.
2198 *
2199 * If application implements a derived class, the derived class should
2200 * call shutdown() in the beginning stage in its destructor, or
2201 * alternatively application should call shutdown() before deleting
2202 * the derived class instance. This is to avoid race condition between
2203 * the derived class destructor and Account callbacks.
2204 */
2205 virtual ~Account();
2206
2207 /**
2208 * Create the account.
2209 *
2210 * If application implements a derived class, the derived class should
2211 * call shutdown() in the beginning stage in its destructor, or
2212 * alternatively application should call shutdown() before deleting
2213 * the derived class instance. This is to avoid race condition between
2214 * the derived class destructor and Account callbacks.
2215 *
2216 * @param cfg The account config.
2217 * @param make_default Make this the default account.
2218 */
2219 void create(const AccountConfig &cfg,
2220 bool make_default=false) PJSUA2_THROW(Error);
2221
2222 /**
2223 * Shutdown the account. This will always delete the account
2224 * (force=true), initiating unregistration if needed, and deleting the
2225 * corresponding account in the PJSUA-LIB. Active calls will not
2226 * prevent deletion; a warning will be logged if any exist.
2227 *
2228 * This method does not throw an exception. Any error will be logged
2229 * internally. For safer behavior that checks for active calls, use
2230 * shutdown2() instead.
2231 *
2232 * Note that application must delete all Buddy instances belong to this
2233 * account before shutting down the account.
2234 *
2235 * If application implements a derived class, the derived class should
2236 * call this method in the beginning stage in its destructor, or
2237 * alternatively application should call this method before deleting
2238 * the derived class instance. This is to avoid race condition between
2239 * the derived class destructor and Account callbacks.
2240 */
2241 void shutdown();
2242
2243 /**
2244 * Shutdown the account, with additional options. This will initiate
2245 * unregistration if needed, and delete the corresponding account in
2246 * the PJSUA-LIB.
2247 *
2248 * Unlike shutdown(), this method throws an Error exception on failure.
2249 * By default (force=false), if there are active calls still using this
2250 * account, it will throw an Error with PJ_EBUSY status. Set force=true
2251 * to always delete the account regardless.
2252 *
2253 * @param prm Shutdown parameters.
2254 */
2255 void shutdown2(const AccountShutdownParam &prm) PJSUA2_THROW(Error);
2256
2257 /**
2258 * Modify the account to use the specified account configuration.
2259 * Depending on the changes, this may cause unregistration or
2260 * reregistration on the account.
2261 *
2262 * @param cfg New account config to be applied to the
2263 * account.
2264 */
2265 void modify(const AccountConfig &cfg) PJSUA2_THROW(Error);
2266
2267 /**
2268 * Check if this account is still valid.
2269 *
2270 * @return True if it is.
2271 */
2272 bool isValid() const;
2273
2274 /**
2275 * Set this as default account to be used when incoming and outgoing
2276 * requests don't match any accounts.
2277 */
2278 void setDefault() PJSUA2_THROW(Error);
2279
2280 /**
2281 * Check if this account is the default account. Default account will be
2282 * used for incoming and outgoing requests that don't match any other
2283 * accounts.
2284 *
2285 * @return True if this is the default account.
2286 */
2287 bool isDefault() const;
2288
2289 /**
2290 * Get PJSUA-LIB account ID or index associated with this account.
2291 *
2292 * @return Integer greater than or equal to zero.
2293 */
2294 int getId() const;
2295
2296 /**
2297 * Get the Account class for the specified account Id.
2298 *
2299 * @param acc_id The account ID to lookup
2300 *
2301 * @return The Account instance or NULL if not found.
2302 */
2303 static Account *lookup(int acc_id);
2304
2305 /**
2306 * Get account info.
2307 *
2308 * @return Account info.
2309 */
2310 AccountInfo getInfo() const PJSUA2_THROW(Error);
2311
2312 /**
2313 * Send arbitrary requests using the account. Application should only use
2314 * this function to create auxiliary requests outside dialog, such as
2315 * OPTIONS, and use the call or presence API to create dialog related
2316 * requests.
2317 *
2318 * @param prm.method SIP method of the request.
2319 * @param prm.txOption Optional message body and/or list of headers to be
2320 * included in outgoing request.
2321 */
2322 void sendRequest(const pj::SendRequestParam& prm) PJSUA2_THROW(Error);
2323
2324 /**
2325 * Send response for incoming request that was deferred earlier
2326 * using DeferredResponse object.
2327 *
2328 * @param prm The response's parameters.
2329 * @param prm.deferredResponse The deferred response object
2330 * identifying the incoming request to
2331 * respond to.
2332 * @param prm.code The status code of the response.
2333 * @param prm.reason Optional reason phrase of the response.
2334 */
2335 void sendResponse(const pj::SendResponseParam& prm) PJSUA2_THROW(Error);
2336
2337 /**
2338 * Update registration or perform unregistration. Application normally
2339 * only needs to call this function if it wants to manually update the
2340 * registration or to unregister from the server.
2341 *
2342 * @param renew If False, this will start unregistration
2343 * process.
2344 */
2345 void setRegistration(bool renew) PJSUA2_THROW(Error);
2346
2347 /**
2348 * Set or modify account's presence online status to be advertised to
2349 * remote/presence subscribers. This would trigger the sending of
2350 * outgoing NOTIFY request if there are server side presence subscription
2351 * for this account, and/or outgoing PUBLISH if presence publication is
2352 * enabled for this account.
2353 *
2354 * @param pres_st Presence online status.
2355 */
2356 void setOnlineStatus(const PresenceStatus &pres_st) PJSUA2_THROW(Error);
2357
2358 /**
2359 * Lock/bind this account to a specific transport/listener. Normally
2360 * application shouldn't need to do this, as transports will be selected
2361 * automatically by the library according to the destination.
2362 *
2363 * When account is locked/bound to a specific transport, all outgoing
2364 * requests from this account will use the specified transport (this
2365 * includes SIP registration, dialog (call and event subscription), and
2366 * out-of-dialog requests such as MESSAGE).
2367 *
2368 * Note that transport id may be specified in AccountConfig too.
2369 *
2370 * @param tp_id The transport ID.
2371 */
2372 void setTransport(TransportId tp_id) PJSUA2_THROW(Error);
2373
2374 /**
2375 * Send NOTIFY to inform account presence status or to terminate server
2376 * side presence subscription. If application wants to reject the incoming
2377 * request, it should set the param \a PresNotifyParam.state to
2378 * PJSIP_EVSUB_STATE_TERMINATED.
2379 *
2380 * @param prm The sending NOTIFY parameter.
2381 */
2382 void presNotify(const PresNotifyParam &prm) PJSUA2_THROW(Error);
2383
2384 #if !DEPRECATED_FOR_TICKET_2232
2385 /**
2386 * Warning: deprecated, use enumBuddies2() instead. This function is not
2387 * safe in multithreaded environment.
2388 *
2389 * Enumerate all buddies of the account.
2390 *
2391 * @return The buddy list.
2392 */
2393 const BuddyVector& enumBuddies() const PJSUA2_THROW(Error);
2394 #endif
2395
2396 /**
2397 * Enumerate all buddies of the account.
2398 *
2399 * @return The buddy list.
2400 */
2401 BuddyVector2 enumBuddies2() const PJSUA2_THROW(Error);
2402
2403 #if !DEPRECATED_FOR_TICKET_2232
2404 /**
2405 * Warning: deprecated, use findBuddy2 instead. This function is not
2406 * safe in multithreaded environment.
2407 *
2408 * Find a buddy in the buddy list with the specified URI.
2409 *
2410 * Exception: if buddy is not found, PJ_ENOTFOUND will be thrown.
2411 *
2412 * @param uri The buddy URI.
2413 * @param buddy_match The buddy match algo.
2414 *
2415 * @return The pointer to buddy.
2416 */
2417 Buddy* findBuddy(string uri, FindBuddyMatch *buddy_match = NULL) const
2418 PJSUA2_THROW(Error);
2419 #endif
2420
2421 /**
2422 * Find a buddy in the buddy list with the specified URI.
2423 *
2424 * Exception: if buddy is not found, PJ_ENOTFOUND will be thrown.
2425 *
2426 * @param uri The buddy URI.
2427 *
2428 * @return The pointer to buddy.
2429 */
2430 Buddy findBuddy2(string uri) const PJSUA2_THROW(Error);
2431
2432 public:
2433 /*
2434 * Callbacks
2435 */
2436 /**
2437 * Notify application on incoming call.
2438 *
2439 * @param prm Callback parameter.
2440 */
2441 virtual void onIncomingCall(OnIncomingCallParam &prm)
2442 { PJ_UNUSED_ARG(prm); }
2443
2444 /**
2445 * Notify application when registration or unregistration has been
2446 * initiated. Note that this only notifies the initial registration
2447 * and unregistration. Once registration session is active, subsequent
2448 * refresh will not cause this callback to be called.
2449 *
2450 * @param prm Callback parameter.
2451 */
2452 virtual void onRegStarted(OnRegStartedParam &prm)
2453 { PJ_UNUSED_ARG(prm); }
2454
2455 /**
2456 * Notify application when registration status has changed.
2457 * Application may then query the account info to get the
2458 * registration details.
2459 *
2460 * @param prm Callback parameter.
2461 */
2462 virtual void onRegState(OnRegStateParam &prm)
2463 { PJ_UNUSED_ARG(prm); }
2464
2465 /**
2466 * Notification when incoming SUBSCRIBE request is received. Application
2467 * may use this callback to authorize the incoming subscribe request
2468 * (e.g. ask user permission if the request should be granted).
2469 *
2470 * If this callback is not implemented, all incoming presence subscription
2471 * requests will be accepted.
2472 *
2473 * If this callback is implemented, application has several choices on
2474 * what to do with the incoming request:
2475 * - it may reject the request immediately by specifying non-200 class
2476 * final response in the IncomingSubscribeParam.code parameter.
2477 * - it may immediately accept the request by specifying 200 as the
2478 * IncomingSubscribeParam.code parameter. This is the default value if
2479 * application doesn't set any value to the IncomingSubscribeParam.code
2480 * parameter. In this case, the library will automatically send NOTIFY
2481 * request upon returning from this callback.
2482 * - it may delay the processing of the request, for example to request
2483 * user permission whether to accept or reject the request. In this
2484 * case, the application MUST set the IncomingSubscribeParam.code
2485 * argument to 202, then IMMEDIATELY calls presNotify() with
2486 * state PJSIP_EVSUB_STATE_PENDING and later calls presNotify()
2487 * again to accept or reject the subscription request.
2488 *
2489 * Any IncomingSubscribeParam.code other than 200 and 202 will be treated
2490 * as 200.
2491 *
2492 * Application MUST return from this callback immediately (e.g. it must
2493 * not block in this callback while waiting for user confirmation).
2494 *
2495 * @param prm Callback parameter.
2496 */
2497 virtual void onIncomingSubscribe(OnIncomingSubscribeParam &prm)
2498 { PJ_UNUSED_ARG(prm); }
2499
2500 /**
2501 * Notify application on incoming instant message or pager (i.e. MESSAGE
2502 * request) that was received outside call context.
2503 *
2504 * @param prm Callback parameter.
2505 */
2506 virtual void onInstantMessage(OnInstantMessageParam &prm)
2507 { PJ_UNUSED_ARG(prm); }
2508
2509 /**
2510 * Notify application about the delivery status of outgoing pager/instant
2511 * message (i.e. MESSAGE) request.
2512 *
2513 * @param prm Callback parameter.
2514 */
2515 virtual void onInstantMessageStatus(OnInstantMessageStatusParam &prm)
2516 { PJ_UNUSED_ARG(prm); }
2517
2518 /**
2519 * Notify application when a transaction started by Account::sendRequest()
2520 * has been completed,i.e. when a response has been received.
2521 *
2522 * @param prm Callback parameter.
2523 */
2524 virtual void onSendRequest(OnSendRequestParam &prm)
2525 { PJ_UNUSED_ARG(prm); }
2526
2527 /**
2528 * Notify application about typing indication.
2529 *
2530 * @param prm Callback parameter.
2531 */
2532 virtual void onTypingIndication(OnTypingIndicationParam &prm)
2533 { PJ_UNUSED_ARG(prm); }
2534
2535 /**
2536 * Notification about MWI (Message Waiting Indication) status change.
2537 * This callback can be called upon the status change of the
2538 * SUBSCRIBE request (for example, 202/Accepted to SUBSCRIBE is received)
2539 * or when a NOTIFY reqeust is received.
2540 *
2541 * @param prm Callback parameter.
2542 */
2543 virtual void onMwiInfo(OnMwiInfoParam &prm)
2544 { PJ_UNUSED_ARG(prm); }
2545
2546 /**
2547 * Called when a 401/407 challenge is received. Override to handle
2548 * authentication challenges. Three usage patterns are supported:
2549 *
2550 * - Synchronous: call prm.challenge.respond() or
2551 * prm.challenge.respond(creds) directly within this callback.
2552 * - Asynchronous: call prm.challenge.defer() to obtain a
2553 * heap-allocated AuthChallenge, then call respond() or abandon()
2554 * on it later from any context. The caller owns the returned object.
2555 * - Default: if neither respond(), abandon(), nor defer() is called,
2556 * the library handles authentication automatically using configured
2557 * credentials.
2558 *
2559 * @param prm Callback parameter.
2560 *
2561 * @see AuthChallenge
2562 * @see OnAuthChallengeParam
2563 */
2564 virtual void onAuthChallenge(OnAuthChallengeParam &prm)
2565 { PJ_UNUSED_ARG(prm); }
2566
2567 private:
2568 friend class Endpoint;
2569 friend class Buddy;
2570
2571 /**
2572 * An internal function to add a Buddy to Account buddy list.
2573 * This method is used by Buddy::create().
2574 */
2575 void addBuddy(Buddy *buddy);
2576
2577 /**
2578 * An internal function to remove a Buddy from Account buddy list.
2579 * This method is used by Buddy::~Buddy().
2580 */
2581 void removeBuddy(Buddy *buddy);
2582
2583 private:
2584 pjsua_acc_id id;
2585 string tmpReason; // for saving response's reason
2586 #if !DEPRECATED_FOR_TICKET_2232
2587 BuddyVector buddyList;
2588 #endif
2589 };
2590
2591 /**
2592 * @} // PJSUA2_ACC
2593 */
2594
2595 } // namespace pj
2596
2597 #endif /* __PJSUA2_ACCOUNT_HPP__ */
2598