account.hpp 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135
  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. * @file pjsua2/account.hpp
  22. * @brief PJSUA2 Account operations
  23. */
  24. #include <pjsua-lib/pjsua.h>
  25. #include <pjsua2/persistent.hpp>
  26. #include <pjsua2/presence.hpp>
  27. #include <pjsua2/siptypes.hpp>
  28. /** PJSUA2 API is inside pj namespace */
  29. namespace pj
  30. {
  31. /**
  32. * @defgroup PJSUA2_ACC Account
  33. * @ingroup PJSUA2_Ref
  34. * @{
  35. */
  36. using std::string;
  37. /**
  38. * Account registration config. This will be specified in AccountConfig.
  39. */
  40. struct AccountRegConfig : public PersistentObject
  41. {
  42. /**
  43. * This is the URL to be put in the request URI for the registration,
  44. * and will look something like "sip:serviceprovider".
  45. *
  46. * This field should be specified if registration is desired. If the
  47. * value is empty, no account registration will be performed.
  48. */
  49. string registrarUri;
  50. /**
  51. * Specify whether the account should register as soon as it is
  52. * added to the UA. Application can set this to PJ_FALSE and control
  53. * the registration manually with pjsua_acc_set_registration().
  54. *
  55. * Default: True
  56. */
  57. bool registerOnAdd;
  58. /**
  59. * Specify whether account modification with Account::modify() should
  60. * automatically update registration if necessary, for example if
  61. * account credentials change.
  62. *
  63. * Disable this when immediate registration is not desirable, such as
  64. * during IP address change.
  65. *
  66. * Default: false.
  67. */
  68. bool disableRegOnModify;
  69. /**
  70. * The optional custom SIP headers to be put in the registration
  71. * request.
  72. */
  73. SipHeaderVector headers;
  74. /**
  75. * Additional parameters that will be appended in the Contact header
  76. * of the registration requests. This will be appended after
  77. * \a AccountSipConfig.contactParams;
  78. *
  79. * The parameters should be preceeded by semicolon, and all strings must
  80. * be properly escaped. Example:
  81. * ";my-param=X;another-param=Hi%20there"
  82. */
  83. string contactParams;
  84. /**
  85. * Additional parameters that will be appended in the Contact URI
  86. * of the registration requests. This will be appended after
  87. * \a AccountSipConfig.contactUriParams;
  88. *
  89. * The parameters should be preceeded by semicolon, and all strings must
  90. * be properly escaped. Example:
  91. * ";my-param=X;another-param=Hi%20there"
  92. */
  93. string contactUriParams;
  94. /**
  95. * Optional interval for registration, in seconds. If the value is zero,
  96. * default interval will be used (PJSUA_REG_INTERVAL, 300 seconds).
  97. */
  98. unsigned timeoutSec;
  99. /**
  100. * Specify interval of auto registration retry upon registration failure
  101. * (including caused by transport problem), in second. Set to 0 to
  102. * disable auto re-registration. Note that if the registration retry
  103. * occurs because of transport failure, the first retry will be done
  104. * after \a firstRetryIntervalSec seconds instead. Also note that
  105. * the interval will be randomized slightly by some seconds (specified
  106. * in \a reg_retry_random_interval) to avoid all clients re-registering
  107. * at the same time.
  108. *
  109. * See also \a firstRetryIntervalSec and \a randomRetryIntervalSec
  110. * settings.
  111. *
  112. * Default: PJSUA_REG_RETRY_INTERVAL
  113. */
  114. unsigned retryIntervalSec;
  115. /**
  116. * This specifies the interval for the first registration retry. The
  117. * registration retry is explained in \a retryIntervalSec. Note that
  118. * the value here will also be randomized by some seconds (specified
  119. * in \a reg_retry_random_interval) to avoid all clients re-registering
  120. * at the same time.
  121. *
  122. * See also \a retryIntervalSec and \a randomRetryIntervalSec settings.
  123. *
  124. * Default: 0
  125. */
  126. unsigned firstRetryIntervalSec;
  127. /**
  128. * This specifies maximum randomized value to be added/substracted
  129. * to/from the registration retry interval specified in \a
  130. * reg_retry_interval and \a reg_first_retry_interval, in second.
  131. * This is useful to avoid all clients re-registering at the same time.
  132. * For example, if the registration retry interval is set to 100 seconds
  133. * and this is set to 10 seconds, the actual registration retry interval
  134. * will be in the range of 90 to 110 seconds.
  135. *
  136. * See also \a retryIntervalSec and \a firstRetryIntervalSec settings.
  137. *
  138. * Default: 10
  139. */
  140. unsigned randomRetryIntervalSec;
  141. /**
  142. * Specify the number of seconds to refresh the client registration
  143. * before the registration expires.
  144. *
  145. * Default: PJSIP_REGISTER_CLIENT_DELAY_BEFORE_REFRESH, 5 seconds
  146. */
  147. unsigned delayBeforeRefreshSec;
  148. /**
  149. * Specify whether calls of the configured account should be dropped
  150. * after registration failure and an attempt of re-registration has
  151. * also failed.
  152. *
  153. * Default: FALSE (disabled)
  154. */
  155. bool dropCallsOnFail;
  156. /**
  157. * Specify the maximum time to wait for unregistration requests to
  158. * complete during library shutdown sequence.
  159. *
  160. * Default: PJSUA_UNREG_TIMEOUT
  161. */
  162. unsigned unregWaitMsec;
  163. /**
  164. * Specify how the registration uses the outbound and account proxy
  165. * settings. This controls if and what Route headers will appear in
  166. * the REGISTER request of this account. The value is bitmask combination
  167. * of PJSUA_REG_USE_OUTBOUND_PROXY and PJSUA_REG_USE_ACC_PROXY bits.
  168. * If the value is set to 0, the REGISTER request will not use any proxy
  169. * (i.e. it will not have any Route headers).
  170. *
  171. * Default: 3 (PJSUA_REG_USE_OUTBOUND_PROXY | PJSUA_REG_USE_ACC_PROXY)
  172. */
  173. unsigned proxyUse;
  174. public:
  175. /**
  176. * Read this object from a container node.
  177. *
  178. * @param node Container to read values from.
  179. */
  180. virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
  181. /**
  182. * Write this object to a container node.
  183. *
  184. * @param node Container to write values to.
  185. */
  186. virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
  187. };
  188. /** Array of SIP credentials */
  189. typedef std::vector<AuthCredInfo> AuthCredInfoVector;
  190. /**
  191. * Various SIP settings for the account. This will be specified in
  192. * AccountConfig.
  193. */
  194. struct AccountSipConfig : public PersistentObject
  195. {
  196. /**
  197. * Array of credentials. If registration is desired, normally there should
  198. * be at least one credential specified, to successfully authenticate
  199. * against the service provider. More credentials can be specified, for
  200. * example when the requests are expected to be challenged by the
  201. * proxies in the route set.
  202. */
  203. AuthCredInfoVector authCreds;
  204. /**
  205. * Array of proxy servers to visit for outgoing requests. Each of the
  206. * entry is translated into one Route URI.
  207. */
  208. StringVector proxies;
  209. /**
  210. * Optional URI to be put as Contact for this account. It is recommended
  211. * that this field is left empty, so that the value will be calculated
  212. * automatically based on the transport address.
  213. */
  214. string contactForced;
  215. /**
  216. * Additional parameters that will be appended in the Contact header
  217. * for this account. This will affect the Contact header in all SIP
  218. * messages sent on behalf of this account, including but not limited to
  219. * REGISTER, INVITE, and SUBCRIBE requests or responses.
  220. *
  221. * The parameters should be preceeded by semicolon, and all strings must
  222. * be properly escaped. Example:
  223. * ";my-param=X;another-param=Hi%20there"
  224. */
  225. string contactParams;
  226. /**
  227. * Additional URI parameters that will be appended in the Contact URI
  228. * for this account. This will affect the Contact URI in all SIP
  229. * messages sent on behalf of this account, including but not limited to
  230. * REGISTER, INVITE, and SUBCRIBE requests or responses.
  231. *
  232. * The parameters should be preceeded by semicolon, and all strings must
  233. * be properly escaped. Example:
  234. * ";my-param=X;another-param=Hi%20there"
  235. */
  236. string contactUriParams;
  237. /**
  238. * If this flag is set, the authentication client framework will
  239. * send an empty Authorization header in each initial request.
  240. * Default is no.
  241. */
  242. bool authInitialEmpty;
  243. /**
  244. * Specify the algorithm to use when empty Authorization header
  245. * is to be sent for each initial request (see above)
  246. */
  247. string authInitialAlgorithm;
  248. /**
  249. * Optionally bind this account to specific transport. This normally is
  250. * not a good idea, as account should be able to send requests using
  251. * any available transports according to the destination. But some
  252. * application may want to have explicit control over the transport to
  253. * use, so in that case it can set this field.
  254. *
  255. * Default: -1 (PJSUA_INVALID_ID)
  256. *
  257. * @see Account::setTransport()
  258. */
  259. TransportId transportId;
  260. /**
  261. * Specify whether IPv6 should be used for SIP signalling.
  262. *
  263. * Default: PJSUA_IPV6_ENABLED_NO_PREFERENCE
  264. * (IP version used will be based on the address resolution
  265. * returned by OS/resolver)
  266. */
  267. pjsua_ipv6_use ipv6Use;
  268. public:
  269. /**
  270. * Read this object from a container node.
  271. *
  272. * @param node Container to read values from.
  273. */
  274. virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
  275. /**
  276. * Write this object to a container node.
  277. *
  278. * @param node Container to write values to.
  279. */
  280. virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
  281. };
  282. /**
  283. * Account's call settings. This will be specified in AccountConfig.
  284. */
  285. struct AccountCallConfig : public PersistentObject
  286. {
  287. /**
  288. * Specify how to offer call hold to remote peer. Please see the
  289. * documentation on pjsua_call_hold_type for more info.
  290. *
  291. * Default: PJSUA_CALL_HOLD_TYPE_DEFAULT
  292. */
  293. pjsua_call_hold_type holdType;
  294. /**
  295. * Specify how support for reliable provisional response (100rel/
  296. * PRACK) should be used for all sessions in this account. See the
  297. * documentation of pjsua_100rel_use enumeration for more info.
  298. *
  299. * Default: PJSUA_100REL_NOT_USED
  300. */
  301. pjsua_100rel_use prackUse;
  302. /**
  303. * Specify the usage of Session Timers for all sessions. See the
  304. * pjsua_sip_timer_use for possible values.
  305. *
  306. * Default: PJSUA_SIP_TIMER_OPTIONAL
  307. */
  308. pjsua_sip_timer_use timerUse;
  309. /**
  310. * Specify minimum Session Timer expiration period, in seconds.
  311. * Must not be lower than 90. Default is 90.
  312. */
  313. unsigned timerMinSESec;
  314. /**
  315. * Specify Session Timer expiration period, in seconds.
  316. * Must not be lower than timerMinSE. Default is 1800.
  317. */
  318. unsigned timerSessExpiresSec;
  319. public:
  320. /**
  321. * Default constructor
  322. */
  323. AccountCallConfig() : holdType(PJSUA_CALL_HOLD_TYPE_DEFAULT),
  324. prackUse(PJSUA_100REL_NOT_USED),
  325. timerUse(PJSUA_SIP_TIMER_OPTIONAL),
  326. timerMinSESec(90),
  327. timerSessExpiresSec(PJSIP_SESS_TIMER_DEF_SE)
  328. {}
  329. /**
  330. * Read this object from a container node.
  331. *
  332. * @param node Container to read values from.
  333. */
  334. virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
  335. /**
  336. * Write this object to a container node.
  337. *
  338. * @param node Container to write values to.
  339. */
  340. virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
  341. };
  342. /**
  343. * Account presence config. This will be specified in AccountConfig.
  344. */
  345. struct AccountPresConfig : public PersistentObject
  346. {
  347. /**
  348. * The optional custom SIP headers to be put in the presence
  349. * subscription request.
  350. */
  351. SipHeaderVector headers;
  352. /**
  353. * If this flag is set, the presence information of this account will
  354. * be PUBLISH-ed to the server where the account belongs.
  355. *
  356. * Default: PJ_FALSE
  357. */
  358. bool publishEnabled;
  359. /**
  360. * Specify whether the client publication session should queue the
  361. * PUBLISH request should there be another PUBLISH transaction still
  362. * pending. If this is set to false, the client will return error
  363. * on the PUBLISH request if there is another PUBLISH transaction still
  364. * in progress.
  365. *
  366. * Default: PJSIP_PUBLISHC_QUEUE_REQUEST (TRUE)
  367. */
  368. bool publishQueue;
  369. /**
  370. * Maximum time to wait for unpublication transaction(s) to complete
  371. * during shutdown process, before sending unregistration. The library
  372. * tries to wait for the unpublication (un-PUBLISH) to complete before
  373. * sending REGISTER request to unregister the account, during library
  374. * shutdown process. If the value is set too short, it is possible that
  375. * the unregistration is sent before unpublication completes, causing
  376. * unpublication request to fail.
  377. *
  378. * Value is in milliseconds.
  379. *
  380. * Default: PJSUA_UNPUBLISH_MAX_WAIT_TIME_MSEC (2000)
  381. */
  382. unsigned publishShutdownWaitMsec;
  383. /**
  384. * Optional PIDF tuple ID for outgoing PUBLISH and NOTIFY. If this value
  385. * is not specified, a random string will be used.
  386. */
  387. string pidfTupleId;
  388. public:
  389. /**
  390. * Read this object from a container node.
  391. *
  392. * @param node Container to read values from.
  393. */
  394. virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
  395. /**
  396. * Write this object to a container node.
  397. *
  398. * @param node Container to write values to.
  399. */
  400. virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
  401. };
  402. /**
  403. * Account MWI (Message Waiting Indication) settings. This will be specified
  404. * in AccountConfig.
  405. */
  406. struct AccountMwiConfig : public PersistentObject
  407. {
  408. /**
  409. * Subscribe to message waiting indication events (RFC 3842).
  410. *
  411. * See also UaConfig.mwiUnsolicitedEnabled setting.
  412. *
  413. * Default: FALSE
  414. */
  415. bool enabled;
  416. /**
  417. * Specify the default expiration time (in seconds) for Message
  418. * Waiting Indication (RFC 3842) event subscription. This must not
  419. * be zero.
  420. *
  421. * Default: PJSIP_MWI_DEFAULT_EXPIRES (3600)
  422. */
  423. unsigned expirationSec;
  424. public:
  425. /**
  426. * Read this object from a container node.
  427. *
  428. * @param node Container to read values from.
  429. */
  430. virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
  431. /**
  432. * Write this object to a container node.
  433. *
  434. * @param node Container to write values to.
  435. */
  436. virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
  437. };
  438. /**
  439. * Account's NAT (Network Address Translation) settings. This will be
  440. * specified in AccountConfig.
  441. */
  442. struct AccountNatConfig : public PersistentObject
  443. {
  444. /**
  445. * Control the use of STUN for the SIP signaling.
  446. *
  447. * Default: PJSUA_STUN_USE_DEFAULT
  448. */
  449. pjsua_stun_use sipStunUse;
  450. /**
  451. * Control the use of STUN for the media transports.
  452. *
  453. * Default: PJSUA_STUN_USE_DEFAULT
  454. */
  455. pjsua_stun_use mediaStunUse;
  456. /**
  457. * Control the use of UPnP for the SIP signaling.
  458. *
  459. * Default: PJSUA_UPNP_USE_DEFAULT
  460. */
  461. pjsua_upnp_use sipUpnpUse;
  462. /**
  463. * Control the use of UPnP for the media transports.
  464. *
  465. * Default: PJSUA_UPNP_USE_DEFAULT
  466. */
  467. pjsua_upnp_use mediaUpnpUse;
  468. /**
  469. * Specify NAT64 options.
  470. *
  471. * Default: PJSUA_NAT64_DISABLED
  472. */
  473. pjsua_nat64_opt nat64Opt;
  474. /**
  475. * Enable ICE for the media transport.
  476. *
  477. * Default: False
  478. */
  479. bool iceEnabled;
  480. /**
  481. * Set trickle ICE mode for ICE media transport.
  482. *
  483. * Default: PJ_ICE_SESS_TRICKLE_DISABLED
  484. */
  485. pj_ice_sess_trickle iceTrickle;
  486. /**
  487. * Set the maximum number of ICE host candidates.
  488. *
  489. * Default: -1 (maximum not set)
  490. */
  491. int iceMaxHostCands;
  492. /**
  493. * Specify whether to use aggressive nomination.
  494. *
  495. * Default: True
  496. */
  497. bool iceAggressiveNomination;
  498. /**
  499. * For controlling agent if it uses regular nomination, specify the delay
  500. * to perform nominated check (connectivity check with USE-CANDIDATE
  501. * attribute) after all components have a valid pair.
  502. *
  503. * Default value is PJ_ICE_NOMINATED_CHECK_DELAY.
  504. */
  505. unsigned iceNominatedCheckDelayMsec;
  506. /**
  507. * For a controlled agent, specify how long it wants to wait (in
  508. * milliseconds) for the controlling agent to complete sending
  509. * connectivity check with nominated flag set to true for all components
  510. * after the controlled agent has found that all connectivity checks in
  511. * its checklist have been completed and there is at least one successful
  512. * (but not nominated) check for every component.
  513. *
  514. * Default value for this option is
  515. * ICE_CONTROLLED_AGENT_WAIT_NOMINATION_TIMEOUT. Specify -1 to disable
  516. * this timer.
  517. */
  518. int iceWaitNominationTimeoutMsec;
  519. /**
  520. * Disable RTCP component.
  521. *
  522. * Default: False
  523. */
  524. bool iceNoRtcp;
  525. /**
  526. * Always send re-INVITE/UPDATE after ICE negotiation regardless of whether
  527. * the default ICE transport address is changed or not. When this is set
  528. * to False, re-INVITE/UPDATE will be sent only when the default ICE
  529. * transport address is changed.
  530. *
  531. * Default: yes
  532. */
  533. bool iceAlwaysUpdate;
  534. /**
  535. * Enable TURN candidate in ICE.
  536. */
  537. bool turnEnabled;
  538. /**
  539. * Specify TURN domain name or host name, in in "DOMAIN:PORT" or
  540. * "HOST:PORT" format.
  541. */
  542. string turnServer;
  543. /**
  544. * Specify the connection type to be used to the TURN server. Valid
  545. * values are PJ_TURN_TP_UDP or PJ_TURN_TP_TCP.
  546. *
  547. * Default: PJ_TURN_TP_UDP
  548. */
  549. pj_turn_tp_type turnConnType;
  550. /**
  551. * Specify the username to authenticate with the TURN server.
  552. */
  553. string turnUserName;
  554. /**
  555. * Specify the type of password. Currently this must be zero to
  556. * indicate plain-text password will be used in the password.
  557. */
  558. int turnPasswordType;
  559. /**
  560. * Specify the password to authenticate with the TURN server.
  561. */
  562. string turnPassword;
  563. /**
  564. * This option is used to update the transport address and the Contact
  565. * header of REGISTER request. When this option is enabled, the library
  566. * will keep track of the public IP address from the response of REGISTER
  567. * request. Once it detects that the address has changed, it will
  568. * unregister current Contact, update the Contact with transport address
  569. * learned from Via header, and register a new Contact to the registrar.
  570. * This will also update the public name of UDP transport if STUN is
  571. * configured.
  572. *
  573. * Possible values:
  574. * * 0 (disabled).
  575. * * 1 (enabled). Update except if both Contact and server's IP address
  576. * are public but response contains private IP.
  577. * * 2 (enabled). Update without exception.
  578. *
  579. * See also contactRewriteMethod field.
  580. *
  581. * Default: 1
  582. */
  583. int contactRewriteUse;
  584. /**
  585. * Specify how Contact update will be done with the registration, if
  586. * \a contactRewriteEnabled is enabled. The value is bitmask combination of
  587. * \a pjsua_contact_rewrite_method. See also pjsua_contact_rewrite_method.
  588. *
  589. * Value PJSUA_CONTACT_REWRITE_UNREGISTER(1) is the legacy behavior.
  590. *
  591. * Default value: PJSUA_CONTACT_REWRITE_METHOD
  592. * (PJSUA_CONTACT_REWRITE_NO_UNREG | PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE)
  593. */
  594. int contactRewriteMethod;
  595. /**
  596. * Specify if source TCP port should be used as the initial Contact
  597. * address if TCP/TLS transport is used. Note that this feature will
  598. * be automatically turned off when nameserver is configured because
  599. * it may yield different destination address due to DNS SRV resolution.
  600. * Also some platforms are unable to report the local address of the
  601. * TCP socket when it is still connecting. In these cases, this
  602. * feature will also be turned off.
  603. *
  604. * Default: 1 (PJ_TRUE / yes).
  605. */
  606. int contactUseSrcPort;
  607. /**
  608. * This option is used to overwrite the "sent-by" field of the Via header
  609. * for outgoing messages with the same interface address as the one in
  610. * the REGISTER request, as long as the request uses the same transport
  611. * instance as the previous REGISTER request.
  612. *
  613. * Default: 1 (PJ_TRUE / yes)
  614. */
  615. int viaRewriteUse;
  616. /**
  617. * This option controls whether the IP address in SDP should be replaced
  618. * with the IP address found in Via header of the REGISTER response, ONLY
  619. * when STUN and ICE are not used. If the value is FALSE (the original
  620. * behavior), then the local IP address will be used. If TRUE, and when
  621. * STUN and ICE are disabled, then the IP address found in registration
  622. * response will be used.
  623. *
  624. * Default: PJ_FALSE (no)
  625. */
  626. int sdpNatRewriteUse;
  627. /**
  628. * Control the use of SIP outbound feature. SIP outbound is described in
  629. * RFC 5626 to enable proxies or registrar to send inbound requests back
  630. * to UA using the same connection initiated by the UA for its
  631. * registration. This feature is highly useful in NAT-ed deployemtns,
  632. * hence it is enabled by default.
  633. *
  634. * Note: currently SIP outbound can only be used with TCP and TLS
  635. * transports. If UDP is used for the registration, the SIP outbound
  636. * feature will be silently ignored for the account.
  637. *
  638. * Default: 1 (PJ_TRUE / yes)
  639. */
  640. int sipOutboundUse;
  641. /**
  642. * Specify SIP outbound (RFC 5626) instance ID to be used by this
  643. * account. If empty, an instance ID will be generated based on
  644. * the hostname of this agent. If application specifies this parameter, the
  645. * value will look like "<urn:uuid:00000000-0000-1000-8000-AABBCCDDEEFF>"
  646. * without the double-quotes.
  647. *
  648. * Default: empty
  649. */
  650. string sipOutboundInstanceId;
  651. /**
  652. * Specify SIP outbound (RFC 5626) registration ID. The default value
  653. * is empty, which would cause the library to automatically generate
  654. * a suitable value.
  655. *
  656. * Default: empty
  657. */
  658. string sipOutboundRegId;
  659. /**
  660. * Set the interval for periodic keep-alive transmission for this account.
  661. * If this value is zero, keep-alive will be disabled for this account.
  662. * The keep-alive transmission will be sent to the registrar's address,
  663. * after successful registration.
  664. *
  665. * Default: 15 (seconds)
  666. */
  667. unsigned udpKaIntervalSec;
  668. /**
  669. * Specify the data to be transmitted as keep-alive packets.
  670. *
  671. * Default: CR-LF
  672. */
  673. string udpKaData;
  674. public:
  675. /**
  676. * Default constructor
  677. */
  678. AccountNatConfig() : sipStunUse(PJSUA_STUN_USE_DEFAULT),
  679. mediaStunUse(PJSUA_STUN_USE_DEFAULT),
  680. sipUpnpUse(PJSUA_UPNP_USE_DEFAULT),
  681. mediaUpnpUse(PJSUA_UPNP_USE_DEFAULT),
  682. nat64Opt(PJSUA_NAT64_DISABLED),
  683. iceEnabled(false),
  684. iceTrickle(PJ_ICE_SESS_TRICKLE_DISABLED),
  685. iceMaxHostCands(-1),
  686. iceAggressiveNomination(true),
  687. iceNominatedCheckDelayMsec(PJ_ICE_NOMINATED_CHECK_DELAY),
  688. iceWaitNominationTimeoutMsec(ICE_CONTROLLED_AGENT_WAIT_NOMINATION_TIMEOUT),
  689. iceNoRtcp(false),
  690. iceAlwaysUpdate(true),
  691. turnEnabled(false),
  692. turnConnType(PJ_TURN_TP_UDP),
  693. turnPasswordType(0),
  694. contactRewriteUse(PJ_TRUE),
  695. contactRewriteMethod(PJSUA_CONTACT_REWRITE_METHOD),
  696. contactUseSrcPort(PJ_TRUE),
  697. viaRewriteUse(PJ_TRUE),
  698. sdpNatRewriteUse(PJ_FALSE),
  699. sipOutboundUse(PJ_TRUE),
  700. udpKaIntervalSec(15),
  701. udpKaData("\r\n")
  702. {}
  703. /**
  704. * Read this object from a container node.
  705. *
  706. * @param node Container to read values from.
  707. */
  708. virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
  709. /**
  710. * Write this object to a container node.
  711. *
  712. * @param node Container to write values to.
  713. */
  714. virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
  715. };
  716. /**
  717. * SRTP crypto.
  718. */
  719. struct SrtpCrypto
  720. {
  721. /**
  722. * Optional key. If empty, a random key will be autogenerated.
  723. */
  724. string key;
  725. /**
  726. * Crypto name.
  727. */
  728. string name;
  729. /**
  730. * Flags, bitmask from #pjmedia_srtp_crypto_option
  731. */
  732. unsigned flags;
  733. public:
  734. /**
  735. * Convert from pjsip
  736. */
  737. void fromPj(const pjmedia_srtp_crypto &prm);
  738. /**
  739. * Convert to pjsip
  740. */
  741. pjmedia_srtp_crypto toPj() const;
  742. };
  743. /** Array of SRTP cryptos. */
  744. typedef std::vector<SrtpCrypto> SrtpCryptoVector;
  745. /**
  746. * SRTP settings.
  747. */
  748. struct SrtpOpt : public PersistentObject
  749. {
  750. /**
  751. * Specify SRTP cryptos. If empty, all crypto will be enabled.
  752. * Available crypto can be enumerated using Endpoint::srtpCryptoEnum().
  753. *
  754. * Default: empty.
  755. */
  756. SrtpCryptoVector cryptos;
  757. /**
  758. * Specify SRTP keying methods, valid keying method is defined in
  759. * pjmedia_srtp_keying_method. If empty, all keying methods will be
  760. * enabled with priority order: SDES, DTLS-SRTP.
  761. *
  762. * Default: empty.
  763. */
  764. IntVector keyings;
  765. public:
  766. /**
  767. * Default constructor initializes with default values.
  768. */
  769. SrtpOpt();
  770. /**
  771. * Convert from pjsip
  772. */
  773. void fromPj(const pjsua_srtp_opt &prm);
  774. /**
  775. * Convert to pjsip
  776. */
  777. pjsua_srtp_opt toPj() const;
  778. public:
  779. /**
  780. * Read this object from a container node.
  781. *
  782. * @param node Container to read values from.
  783. */
  784. virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
  785. /**
  786. * Write this object to a container node.
  787. *
  788. * @param node Container to write values to.
  789. */
  790. virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
  791. };
  792. /**
  793. * RTCP Feedback capability.
  794. */
  795. struct RtcpFbCap
  796. {
  797. /**
  798. * Specify the codecs to which the capability is applicable. Codec ID is
  799. * using the same format as in pjmedia_codec_mgr_find_codecs_by_id() and
  800. * pjmedia_vid_codec_mgr_find_codecs_by_id(), e.g: "L16/8000/1", "PCMU",
  801. * "H264". This can also be an asterisk ("*") to represent all codecs.
  802. */
  803. string codecId;
  804. /**
  805. * Specify the RTCP Feedback type.
  806. */
  807. pjmedia_rtcp_fb_type type;
  808. /**
  809. * Specify the type name if RTCP Feedback type is PJMEDIA_RTCP_FB_OTHER.
  810. */
  811. string typeName;
  812. /**
  813. * Specify the RTCP Feedback parameters.
  814. */
  815. string param;
  816. public:
  817. /**
  818. * Constructor.
  819. */
  820. RtcpFbCap() : type(PJMEDIA_RTCP_FB_OTHER)
  821. {}
  822. /**
  823. * Convert from pjsip
  824. */
  825. void fromPj(const pjmedia_rtcp_fb_cap &prm);
  826. /**
  827. * Convert to pjsip
  828. */
  829. pjmedia_rtcp_fb_cap toPj() const;
  830. };
  831. /** Array of RTCP Feedback capabilities. */
  832. typedef std::vector<RtcpFbCap> RtcpFbCapVector;
  833. /**
  834. * RTCP Feedback settings.
  835. */
  836. struct RtcpFbConfig : public PersistentObject
  837. {
  838. /**
  839. * Specify whether transport protocol in SDP media description uses
  840. * RTP/AVP instead of RTP/AVPF. Note that the standard mandates to signal
  841. * AVPF profile, but it may cause SDP negotiation failure when negotiating
  842. * with endpoints that does not support RTCP Feedback (including older
  843. * version of PJSIP).
  844. *
  845. * Default: false.
  846. */
  847. bool dontUseAvpf;
  848. /**
  849. * RTCP Feedback capabilities.
  850. */
  851. RtcpFbCapVector caps;
  852. public:
  853. /**
  854. * Constructor.
  855. */
  856. RtcpFbConfig();
  857. /**
  858. * Convert from pjsip
  859. */
  860. void fromPj(const pjmedia_rtcp_fb_setting &prm);
  861. /**
  862. * Convert to pjsip
  863. */
  864. pjmedia_rtcp_fb_setting toPj() const;
  865. public:
  866. /**
  867. * Read this object from a container node.
  868. *
  869. * @param node Container to read values from.
  870. */
  871. virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
  872. /**
  873. * Write this object to a container node.
  874. *
  875. * @param node Container to write values to.
  876. */
  877. virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
  878. };
  879. /**
  880. * Account media config (applicable for both audio and video). This will be
  881. * specified in AccountConfig.
  882. */
  883. struct AccountMediaConfig : public PersistentObject
  884. {
  885. /**
  886. * Media transport (RTP) configuration.
  887. *
  888. * For \a port and \a portRange settings, RTCP port is selected as
  889. * RTP port+1.
  890. * Example: \a port=5000, \a portRange=4
  891. * - Available ports: 5000, 5002, 5004 (Media/RTP transport)
  892. * 5001, 5003, 5005 (Media/RTCP transport)
  893. */
  894. TransportConfig transportConfig;
  895. /**
  896. * If remote sends SDP answer containing more than one format or codec in
  897. * the media line, send re-INVITE or UPDATE with just one codec to lock
  898. * which codec to use.
  899. *
  900. * Default: True (Yes).
  901. */
  902. bool lockCodecEnabled;
  903. /**
  904. * Specify whether stream keep-alive and NAT hole punching with
  905. * non-codec-VAD mechanism (see PJMEDIA_STREAM_ENABLE_KA) is enabled
  906. * for this account.
  907. *
  908. * Default: False
  909. */
  910. bool streamKaEnabled;
  911. /**
  912. * Specify whether secure media transport should be used for this account.
  913. * Valid values are PJMEDIA_SRTP_DISABLED, PJMEDIA_SRTP_OPTIONAL, and
  914. * PJMEDIA_SRTP_MANDATORY.
  915. *
  916. * Default: PJSUA_DEFAULT_USE_SRTP
  917. */
  918. pjmedia_srtp_use srtpUse;
  919. /**
  920. * Specify whether SRTP requires secure signaling to be used. This option
  921. * is only used when \a use_srtp option above is non-zero.
  922. *
  923. * Valid values are:
  924. * 0: SRTP does not require secure signaling
  925. * 1: SRTP requires secure transport such as TLS
  926. * 2: SRTP requires secure end-to-end transport (SIPS)
  927. *
  928. * Default: PJSUA_DEFAULT_SRTP_SECURE_SIGNALING
  929. */
  930. int srtpSecureSignaling;
  931. /**
  932. * Specify SRTP settings, like cryptos and keying methods.
  933. */
  934. SrtpOpt srtpOpt;
  935. /**
  936. * Specify whether IPv6 should be used on media.
  937. *
  938. * Default: PJSUA_IPV6_ENABLED_PREFER_IPV4
  939. * (Dual stack media, capable to use IPv4/IPv6.
  940. * Outgoing offer will prefer to use IPv4)
  941. */
  942. pjsua_ipv6_use ipv6Use;
  943. /**
  944. * Enable RTP and RTCP multiplexing.
  945. * Default: false
  946. */
  947. bool rtcpMuxEnabled;
  948. /**
  949. * RTCP Feedback settings.
  950. */
  951. RtcpFbConfig rtcpFbConfig;
  952. /**
  953. * Enable RTCP Extended Report (RTCP XR).
  954. *
  955. * Default: PJMEDIA_STREAM_ENABLE_XR
  956. */
  957. bool rtcpXrEnabled;
  958. /**
  959. * Use loopback media transport. This may be useful if application
  960. * doesn't want PJSUA2 to create real media transports/sockets, such as
  961. * when using third party media.
  962. *
  963. * Default: false
  964. */
  965. bool useLoopMedTp;
  966. /**
  967. * Enable local loopback when useLoopMedTp is set to TRUE.
  968. * If enabled, packets sent to the transport will be sent back to
  969. * the streams attached to the transport.
  970. *
  971. * Default: false
  972. */
  973. bool enableLoopback;
  974. public:
  975. /**
  976. * Default constructor
  977. */
  978. AccountMediaConfig()
  979. : lockCodecEnabled(true),
  980. streamKaEnabled(false),
  981. srtpUse(PJSUA_DEFAULT_USE_SRTP),
  982. srtpSecureSignaling(PJSUA_DEFAULT_SRTP_SECURE_SIGNALING),
  983. ipv6Use(PJSUA_IPV6_ENABLED_PREFER_IPV4),
  984. rtcpMuxEnabled(false),
  985. rtcpXrEnabled(PJMEDIA_STREAM_ENABLE_XR),
  986. useLoopMedTp(false),
  987. enableLoopback(false)
  988. {}
  989. /**
  990. * Read this object from a container node.
  991. *
  992. * @param node Container to read values from.
  993. */
  994. virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
  995. /**
  996. * Write this object to a container node.
  997. *
  998. * @param node Container to write values to.
  999. */
  1000. virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
  1001. };
  1002. /**
  1003. * Account video config. This will be specified in AccountConfig.
  1004. */
  1005. struct AccountVideoConfig : public PersistentObject
  1006. {
  1007. /**
  1008. * Specify whether incoming video should be shown to screen by default.
  1009. * This applies to incoming call (INVITE), incoming re-INVITE, and
  1010. * incoming UPDATE requests.
  1011. *
  1012. * Regardless of this setting, application can detect incoming video
  1013. * by implementing \a on_call_media_state() callback and enumerating
  1014. * the media stream(s) with pjsua_call_get_info(). Once incoming
  1015. * video is recognised, application may retrieve the window associated
  1016. * with the incoming video and show or hide it with
  1017. * pjsua_vid_win_set_show().
  1018. *
  1019. * Default: False
  1020. */
  1021. bool autoShowIncoming;
  1022. /**
  1023. * Specify whether outgoing video should be activated by default when
  1024. * making outgoing calls and/or when incoming video is detected. This
  1025. * applies to incoming and outgoing calls, incoming re-INVITE, and
  1026. * incoming UPDATE. If the setting is non-zero, outgoing video
  1027. * transmission will be started as soon as response to these requests
  1028. * is sent (or received).
  1029. *
  1030. * Regardless of the value of this setting, application can start and
  1031. * stop outgoing video transmission with pjsua_call_set_vid_strm().
  1032. *
  1033. * Default: False
  1034. */
  1035. bool autoTransmitOutgoing;
  1036. /**
  1037. * Specify video window's flags. The value is a bitmask combination of
  1038. * pjmedia_vid_dev_wnd_flag.
  1039. *
  1040. * Default: 0
  1041. */
  1042. unsigned windowFlags;
  1043. /**
  1044. * Specify the default capture device to be used by this account. If
  1045. * vidOutAutoTransmit is enabled, this device will be used for
  1046. * capturing video.
  1047. *
  1048. * Default: PJMEDIA_VID_DEFAULT_CAPTURE_DEV
  1049. */
  1050. pjmedia_vid_dev_index defaultCaptureDevice;
  1051. /**
  1052. * Specify the default rendering device to be used by this account.
  1053. *
  1054. * Default: PJMEDIA_VID_DEFAULT_RENDER_DEV
  1055. */
  1056. pjmedia_vid_dev_index defaultRenderDevice;
  1057. /**
  1058. * Rate control method.
  1059. *
  1060. * Default: PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING.
  1061. */
  1062. pjmedia_vid_stream_rc_method rateControlMethod;
  1063. /**
  1064. * Upstream/outgoing bandwidth. If this is set to zero, the video stream
  1065. * will use codec maximum bitrate setting.
  1066. *
  1067. * Default: 0 (follow codec maximum bitrate).
  1068. */
  1069. unsigned rateControlBandwidth;
  1070. /**
  1071. * The number of keyframe to be sent after the stream is created.
  1072. *
  1073. * Default: PJMEDIA_VID_STREAM_START_KEYFRAME_CNT
  1074. */
  1075. unsigned startKeyframeCount;
  1076. /**
  1077. * The keyframe sending interval after the stream is created.
  1078. *
  1079. * Default: PJMEDIA_VID_STREAM_START_KEYFRAME_INTERVAL_MSEC
  1080. */
  1081. unsigned startKeyframeInterval;
  1082. public:
  1083. /**
  1084. * Default constructor
  1085. */
  1086. AccountVideoConfig()
  1087. : autoShowIncoming(false),
  1088. autoTransmitOutgoing(false),
  1089. windowFlags(0),
  1090. defaultCaptureDevice(PJMEDIA_VID_DEFAULT_CAPTURE_DEV),
  1091. defaultRenderDevice(PJMEDIA_VID_DEFAULT_RENDER_DEV),
  1092. rateControlMethod(PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING),
  1093. rateControlBandwidth(0),
  1094. startKeyframeCount(PJMEDIA_VID_STREAM_START_KEYFRAME_CNT),
  1095. startKeyframeInterval(PJMEDIA_VID_STREAM_START_KEYFRAME_INTERVAL_MSEC)
  1096. {}
  1097. /**
  1098. * Read this object from a container node.
  1099. *
  1100. * @param node Container to read values from.
  1101. */
  1102. virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
  1103. /**
  1104. * Write this object to a container node.
  1105. *
  1106. * @param node Container to write values to.
  1107. */
  1108. virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
  1109. };
  1110. /**
  1111. * Account config specific to IP address change.
  1112. */
  1113. typedef struct AccountIpChangeConfig
  1114. {
  1115. /**
  1116. * Shutdown the transport used for account registration. If this is set to
  1117. * PJ_TRUE, the transport will be shutdown altough it's used by multiple
  1118. * account. Shutdown transport will be followed by re-Registration if
  1119. * AccountConfig.natConfig.contactRewriteUse is enabled.
  1120. *
  1121. * Default: true
  1122. */
  1123. bool shutdownTp;
  1124. /**
  1125. * Hangup active calls associated with the acount. If this is set to true,
  1126. * then the calls will be hang up.
  1127. *
  1128. * Default: false
  1129. */
  1130. bool hangupCalls;
  1131. /**
  1132. * Specify the call flags used in the re-INVITE when \a hangupCalls is set
  1133. * to false. If this is set to 0, no re-INVITE will be sent. The
  1134. * re-INVITE will be sent after re-Registration is finished.
  1135. *
  1136. * Default: PJSUA_CALL_REINIT_MEDIA | PJSUA_CALL_UPDATE_CONTACT |
  1137. * PJSUA_CALL_UPDATE_VIA
  1138. */
  1139. unsigned reinviteFlags;
  1140. /**
  1141. * For refreshing the call, use SIP UPDATE, instead of re-INVITE, if
  1142. * remote supports it (by publishing it in Allow header). If remote
  1143. * does not support UPDATE method or somehow the UPDATE attempt fails,
  1144. * it will fallback to using re-INVITE. The \a reinviteFlags will be
  1145. * used regardless whether it is re-INVITE or UPDATE that is sent.
  1146. *
  1147. * Default: PJ_FALSE (using re-INVITE).
  1148. */
  1149. unsigned reinvUseUpdate;
  1150. public:
  1151. /**
  1152. * Virtual destructor
  1153. */
  1154. virtual ~AccountIpChangeConfig()
  1155. {}
  1156. /**
  1157. * Read this object from a container node.
  1158. *
  1159. * @param node Container to read values from.
  1160. */
  1161. virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
  1162. /**
  1163. * Write this object to a container node.
  1164. *
  1165. * @param node Container to write values to.
  1166. */
  1167. virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
  1168. } AccountIpChangeConfig;
  1169. /**
  1170. * Account configuration.
  1171. */
  1172. struct AccountConfig : public PersistentObject
  1173. {
  1174. /**
  1175. * Account priority, which is used to control the order of matching
  1176. * incoming/outgoing requests. The higher the number means the higher
  1177. * the priority is, and the account will be matched first.
  1178. */
  1179. int priority;
  1180. /**
  1181. * The Address of Record or AOR, that is full SIP URL that identifies the
  1182. * account. The value can take name address or URL format, and will look
  1183. * something like "sip:account@serviceprovider".
  1184. *
  1185. * This field is mandatory.
  1186. */
  1187. string idUri;
  1188. /**
  1189. * Registration settings.
  1190. */
  1191. AccountRegConfig regConfig;
  1192. /**
  1193. * SIP settings.
  1194. */
  1195. AccountSipConfig sipConfig;
  1196. /**
  1197. * Call settings.
  1198. */
  1199. AccountCallConfig callConfig;
  1200. /**
  1201. * Presence settings.
  1202. */
  1203. AccountPresConfig presConfig;
  1204. /**
  1205. * MWI (Message Waiting Indication) settings.
  1206. */
  1207. AccountMwiConfig mwiConfig;
  1208. /**
  1209. * NAT settings.
  1210. */
  1211. AccountNatConfig natConfig;
  1212. /**
  1213. * Media settings (applicable for both audio and video).
  1214. */
  1215. AccountMediaConfig mediaConfig;
  1216. /**
  1217. * Video settings.
  1218. */
  1219. AccountVideoConfig videoConfig;
  1220. /**
  1221. * IP Change settings.
  1222. */
  1223. AccountIpChangeConfig ipChangeConfig;
  1224. public:
  1225. /**
  1226. * Default constructor will initialize with default values.
  1227. */
  1228. AccountConfig();
  1229. /**
  1230. * This will return a temporary pjsua_acc_config instance, which contents
  1231. * are only valid as long as this AccountConfig structure remains valid
  1232. * AND no modifications are done to it AND no further toPj() function call
  1233. * is made. Any call to toPj() function will invalidate the content of
  1234. * temporary pjsua_acc_config that was returned by the previous call.
  1235. */
  1236. void toPj(pjsua_acc_config &cfg) const;
  1237. /**
  1238. * Initialize from pjsip.
  1239. */
  1240. void fromPj(const pjsua_acc_config &prm, const pjsua_media_config *mcfg);
  1241. /**
  1242. * Read this object from a container node.
  1243. *
  1244. * @param node Container to read values from.
  1245. */
  1246. virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
  1247. /**
  1248. * Write this object to a container node.
  1249. *
  1250. * @param node Container to write values to.
  1251. */
  1252. virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
  1253. };
  1254. /**
  1255. * Account information. Application can query the account information
  1256. * by calling Account::getInfo().
  1257. */
  1258. struct AccountInfo
  1259. {
  1260. /**
  1261. * The account ID.
  1262. */
  1263. pjsua_acc_id id;
  1264. /**
  1265. * Flag to indicate whether this is the default account.
  1266. */
  1267. bool isDefault;
  1268. /**
  1269. * Account URI
  1270. */
  1271. string uri;
  1272. /**
  1273. * Flag to tell whether this account has registration setting
  1274. * (reg_uri is not empty).
  1275. */
  1276. bool regIsConfigured;
  1277. /**
  1278. * Flag to tell whether this account is currently registered
  1279. * (has active registration session).
  1280. */
  1281. bool regIsActive;
  1282. /**
  1283. * An up to date expiration interval for account registration session.
  1284. */
  1285. unsigned regExpiresSec;
  1286. /**
  1287. * Last registration status code. If status code is zero, the account
  1288. * is currently not registered. Any other value indicates the SIP
  1289. * status code of the registration.
  1290. */
  1291. pjsip_status_code regStatus;
  1292. /**
  1293. * String describing the registration status.
  1294. */
  1295. string regStatusText;
  1296. /**
  1297. * Last registration error code. When the status field contains a SIP
  1298. * status code that indicates a registration failure, last registration
  1299. * error code contains the error code that causes the failure. In any
  1300. * other case, its value is zero.
  1301. */
  1302. pj_status_t regLastErr;
  1303. /**
  1304. * Presence online status for this account.
  1305. */
  1306. bool onlineStatus;
  1307. /**
  1308. * Presence online status text.
  1309. */
  1310. string onlineStatusText;
  1311. public:
  1312. /**
  1313. * Default constructor
  1314. */
  1315. AccountInfo() : id(PJSUA_INVALID_ID),
  1316. isDefault(false),
  1317. regIsConfigured(false),
  1318. regIsActive(false),
  1319. regExpiresSec(0),
  1320. regStatus(PJSIP_SC_NULL),
  1321. regLastErr(-1),
  1322. onlineStatus(false)
  1323. {}
  1324. /** Import from pjsip data */
  1325. void fromPj(const pjsua_acc_info &pai);
  1326. };
  1327. /**
  1328. * This structure contains parameters for onIncomingCall() account callback.
  1329. */
  1330. struct OnIncomingCallParam
  1331. {
  1332. /**
  1333. * The library call ID allocated for the new call.
  1334. */
  1335. int callId;
  1336. /**
  1337. * The incoming INVITE request.
  1338. */
  1339. SipRxData rdata;
  1340. };
  1341. /**
  1342. * This structure contains parameters for onRegStarted() account callback.
  1343. */
  1344. struct OnRegStartedParam
  1345. {
  1346. /**
  1347. * True for registration and False for unregistration.
  1348. */
  1349. bool renew;
  1350. };
  1351. /**
  1352. * This structure contains parameters for onRegState() account callback.
  1353. */
  1354. struct OnRegStateParam
  1355. {
  1356. /**
  1357. * Registration operation status.
  1358. */
  1359. pj_status_t status;
  1360. /**
  1361. * SIP status code received.
  1362. */
  1363. pjsip_status_code code;
  1364. /**
  1365. * SIP reason phrase received.
  1366. */
  1367. string reason;
  1368. /**
  1369. * The incoming message.
  1370. */
  1371. SipRxData rdata;
  1372. /**
  1373. * Next expiration interval.
  1374. */
  1375. unsigned expiration;
  1376. };
  1377. /**
  1378. * This structure contains parameters for onIncomingSubscribe() callback.
  1379. */
  1380. struct OnIncomingSubscribeParam
  1381. {
  1382. /**
  1383. * Server presence subscription instance. If application delays
  1384. * the acceptance of the request, it will need to specify this object
  1385. * when calling Account::presNotify().
  1386. */
  1387. void *srvPres;
  1388. /**
  1389. * Sender URI.
  1390. */
  1391. string fromUri;
  1392. /**
  1393. * The incoming message.
  1394. */
  1395. SipRxData rdata;
  1396. /**
  1397. * The status code to respond to the request. The default value is 200.
  1398. * Application may set this to other final status code to accept or
  1399. * reject the request.
  1400. */
  1401. pjsip_status_code code;
  1402. /**
  1403. * The reason phrase to respond to the request.
  1404. */
  1405. string reason;
  1406. /**
  1407. * Additional data to be sent with the response, if any.
  1408. */
  1409. SipTxOption txOption;
  1410. };
  1411. /**
  1412. * Parameters for onInstantMessage() account callback.
  1413. */
  1414. struct OnInstantMessageParam
  1415. {
  1416. /**
  1417. * Sender From URI.
  1418. */
  1419. string fromUri;
  1420. /**
  1421. * To URI of the request.
  1422. */
  1423. string toUri;
  1424. /**
  1425. * Contact URI of the sender.
  1426. */
  1427. string contactUri;
  1428. /**
  1429. * MIME type of the message body.
  1430. */
  1431. string contentType;
  1432. /**
  1433. * The message body.
  1434. */
  1435. string msgBody;
  1436. /**
  1437. * The whole message.
  1438. */
  1439. SipRxData rdata;
  1440. };
  1441. /**
  1442. * Parameters for onInstantMessageStatus() account callback.
  1443. */
  1444. struct OnInstantMessageStatusParam
  1445. {
  1446. /**
  1447. * Token or a user data that was associated with the pager
  1448. * transmission.
  1449. */
  1450. Token userData;
  1451. /**
  1452. * Destination URI.
  1453. */
  1454. string toUri;
  1455. /**
  1456. * The message body.
  1457. */
  1458. string msgBody;
  1459. /**
  1460. * The SIP status code of the transaction.
  1461. */
  1462. pjsip_status_code code;
  1463. /**
  1464. * The reason phrase of the transaction.
  1465. */
  1466. string reason;
  1467. /**
  1468. * The incoming response that causes this callback to be called.
  1469. * If the transaction fails because of time out or transport error,
  1470. * the content will be empty.
  1471. */
  1472. SipRxData rdata;
  1473. };
  1474. /**
  1475. * Parameters for onTypingIndication() account callback.
  1476. */
  1477. struct OnTypingIndicationParam
  1478. {
  1479. /**
  1480. * Sender/From URI.
  1481. */
  1482. string fromUri;
  1483. /**
  1484. * To URI.
  1485. */
  1486. string toUri;
  1487. /**
  1488. * The Contact URI.
  1489. */
  1490. string contactUri;
  1491. /**
  1492. * Boolean to indicate if sender is typing.
  1493. */
  1494. bool isTyping;
  1495. /**
  1496. * The whole message buffer.
  1497. */
  1498. SipRxData rdata;
  1499. };
  1500. /**
  1501. * Parameters for onMwiInfo() account callback.
  1502. */
  1503. struct OnMwiInfoParam
  1504. {
  1505. /**
  1506. * MWI subscription state.
  1507. */
  1508. pjsip_evsub_state state;
  1509. /**
  1510. * The whole message buffer.
  1511. */
  1512. SipRxData rdata;
  1513. };
  1514. /**
  1515. * Parameters for presNotify() account method.
  1516. */
  1517. struct PresNotifyParam
  1518. {
  1519. /**
  1520. * Server presence subscription instance.
  1521. */
  1522. void *srvPres;
  1523. /**
  1524. * Server presence subscription state to set.
  1525. */
  1526. pjsip_evsub_state state;
  1527. /**
  1528. * Optionally specify the state string name, if state is not "active",
  1529. * "pending", or "terminated".
  1530. */
  1531. string stateStr;
  1532. /**
  1533. * If the new state is PJSIP_EVSUB_STATE_TERMINATED, optionally specify
  1534. * the termination reason.
  1535. */
  1536. string reason;
  1537. /**
  1538. * If the new state is PJSIP_EVSUB_STATE_TERMINATED, this specifies
  1539. * whether the NOTIFY request should contain message body containing
  1540. * account's presence information.
  1541. */
  1542. bool withBody;
  1543. /**
  1544. * Optional list of headers to be sent with the NOTIFY request.
  1545. */
  1546. SipTxOption txOption;
  1547. };
  1548. /**
  1549. * Wrapper class for Buddy matching algo.
  1550. *
  1551. * Default algo is a simple substring lookup of search-token in the
  1552. * Buddy URIs, with case sensitive. Application can implement its own
  1553. * matching algo by overriding this class and specifying its instance
  1554. * in Account::findBuddy().
  1555. */
  1556. class FindBuddyMatch
  1557. {
  1558. public:
  1559. /**
  1560. * Default algo implementation.
  1561. */
  1562. virtual bool match(const string &token, const Buddy &buddy)
  1563. {
  1564. BuddyInfo bi = buddy.getInfo();
  1565. return bi.uri.find(token) != string::npos;
  1566. }
  1567. /**
  1568. * Destructor.
  1569. */
  1570. virtual ~FindBuddyMatch() {}
  1571. };
  1572. /**
  1573. * Account.
  1574. */
  1575. class Account
  1576. {
  1577. public:
  1578. /**
  1579. * Constructor.
  1580. */
  1581. Account();
  1582. /**
  1583. * Destructor. Note that if the account is deleted, it will also delete
  1584. * the corresponding account in the PJSUA-LIB.
  1585. *
  1586. * If application implements a derived class, the derived class should
  1587. * call shutdown() in the beginning stage in its destructor, or
  1588. * alternatively application should call shutdown() before deleting
  1589. * the derived class instance. This is to avoid race condition between
  1590. * the derived class destructor and Account callbacks.
  1591. */
  1592. virtual ~Account();
  1593. /**
  1594. * Create the account.
  1595. *
  1596. * If application implements a derived class, the derived class should
  1597. * call shutdown() in the beginning stage in its destructor, or
  1598. * alternatively application should call shutdown() before deleting
  1599. * the derived class instance. This is to avoid race condition between
  1600. * the derived class destructor and Account callbacks.
  1601. *
  1602. * @param cfg The account config.
  1603. * @param make_default Make this the default account.
  1604. */
  1605. void create(const AccountConfig &cfg,
  1606. bool make_default=false) PJSUA2_THROW(Error);
  1607. /**
  1608. * Shutdown the account. This will initiate unregistration if needed,
  1609. * and delete the corresponding account in the PJSUA-LIB.
  1610. *
  1611. * Note that application must delete all Buddy instances belong to this
  1612. * account before shutting down the account.
  1613. *
  1614. * If application implements a derived class, the derived class should
  1615. * call this method in the beginning stage in its destructor, or
  1616. * alternatively application should call this method before deleting
  1617. * the derived class instance. This is to avoid race condition between
  1618. * the derived class destructor and Account callbacks.
  1619. */
  1620. void shutdown();
  1621. /**
  1622. * Modify the account to use the specified account configuration.
  1623. * Depending on the changes, this may cause unregistration or
  1624. * reregistration on the account.
  1625. *
  1626. * @param cfg New account config to be applied to the
  1627. * account.
  1628. */
  1629. void modify(const AccountConfig &cfg) PJSUA2_THROW(Error);
  1630. /**
  1631. * Check if this account is still valid.
  1632. *
  1633. * @return True if it is.
  1634. */
  1635. bool isValid() const;
  1636. /**
  1637. * Set this as default account to be used when incoming and outgoing
  1638. * requests don't match any accounts.
  1639. */
  1640. void setDefault() PJSUA2_THROW(Error);
  1641. /**
  1642. * Check if this account is the default account. Default account will be
  1643. * used for incoming and outgoing requests that don't match any other
  1644. * accounts.
  1645. *
  1646. * @return True if this is the default account.
  1647. */
  1648. bool isDefault() const;
  1649. /**
  1650. * Get PJSUA-LIB account ID or index associated with this account.
  1651. *
  1652. * @return Integer greater than or equal to zero.
  1653. */
  1654. int getId() const;
  1655. /**
  1656. * Get the Account class for the specified account Id.
  1657. *
  1658. * @param acc_id The account ID to lookup
  1659. *
  1660. * @return The Account instance or NULL if not found.
  1661. */
  1662. static Account *lookup(int acc_id);
  1663. /**
  1664. * Get account info.
  1665. *
  1666. * @return Account info.
  1667. */
  1668. AccountInfo getInfo() const PJSUA2_THROW(Error);
  1669. /**
  1670. * Update registration or perform unregistration. Application normally
  1671. * only needs to call this function if it wants to manually update the
  1672. * registration or to unregister from the server.
  1673. *
  1674. * @param renew If False, this will start unregistration
  1675. * process.
  1676. */
  1677. void setRegistration(bool renew) PJSUA2_THROW(Error);
  1678. /**
  1679. * Set or modify account's presence online status to be advertised to
  1680. * remote/presence subscribers. This would trigger the sending of
  1681. * outgoing NOTIFY request if there are server side presence subscription
  1682. * for this account, and/or outgoing PUBLISH if presence publication is
  1683. * enabled for this account.
  1684. *
  1685. * @param pres_st Presence online status.
  1686. */
  1687. void setOnlineStatus(const PresenceStatus &pres_st) PJSUA2_THROW(Error);
  1688. /**
  1689. * Lock/bind this account to a specific transport/listener. Normally
  1690. * application shouldn't need to do this, as transports will be selected
  1691. * automatically by the library according to the destination.
  1692. *
  1693. * When account is locked/bound to a specific transport, all outgoing
  1694. * requests from this account will use the specified transport (this
  1695. * includes SIP registration, dialog (call and event subscription), and
  1696. * out-of-dialog requests such as MESSAGE).
  1697. *
  1698. * Note that transport id may be specified in AccountConfig too.
  1699. *
  1700. * @param tp_id The transport ID.
  1701. */
  1702. void setTransport(TransportId tp_id) PJSUA2_THROW(Error);
  1703. /**
  1704. * Send NOTIFY to inform account presence status or to terminate server
  1705. * side presence subscription. If application wants to reject the incoming
  1706. * request, it should set the param \a PresNotifyParam.state to
  1707. * PJSIP_EVSUB_STATE_TERMINATED.
  1708. *
  1709. * @param prm The sending NOTIFY parameter.
  1710. */
  1711. void presNotify(const PresNotifyParam &prm) PJSUA2_THROW(Error);
  1712. #if !DEPRECATED_FOR_TICKET_2232
  1713. /**
  1714. * Warning: deprecated, use enumBuddies2() instead. This function is not
  1715. * safe in multithreaded environment.
  1716. *
  1717. * Enumerate all buddies of the account.
  1718. *
  1719. * @return The buddy list.
  1720. */
  1721. const BuddyVector& enumBuddies() const PJSUA2_THROW(Error);
  1722. #endif
  1723. /**
  1724. * Enumerate all buddies of the account.
  1725. *
  1726. * @return The buddy list.
  1727. */
  1728. BuddyVector2 enumBuddies2() const PJSUA2_THROW(Error);
  1729. #if !DEPRECATED_FOR_TICKET_2232
  1730. /**
  1731. * Warning: deprecated, use findBuddy2 instead. This function is not
  1732. * safe in multithreaded environment.
  1733. *
  1734. * Find a buddy in the buddy list with the specified URI.
  1735. *
  1736. * Exception: if buddy is not found, PJ_ENOTFOUND will be thrown.
  1737. *
  1738. * @param uri The buddy URI.
  1739. * @param buddy_match The buddy match algo.
  1740. *
  1741. * @return The pointer to buddy.
  1742. */
  1743. Buddy* findBuddy(string uri, FindBuddyMatch *buddy_match = NULL) const
  1744. PJSUA2_THROW(Error);
  1745. #endif
  1746. /**
  1747. * Find a buddy in the buddy list with the specified URI.
  1748. *
  1749. * Exception: if buddy is not found, PJ_ENOTFOUND will be thrown.
  1750. *
  1751. * @param uri The buddy URI.
  1752. *
  1753. * @return The pointer to buddy.
  1754. */
  1755. Buddy findBuddy2(string uri) const PJSUA2_THROW(Error);
  1756. public:
  1757. /*
  1758. * Callbacks
  1759. */
  1760. /**
  1761. * Notify application on incoming call.
  1762. *
  1763. * @param prm Callback parameter.
  1764. */
  1765. virtual void onIncomingCall(OnIncomingCallParam &prm)
  1766. { PJ_UNUSED_ARG(prm); }
  1767. /**
  1768. * Notify application when registration or unregistration has been
  1769. * initiated. Note that this only notifies the initial registration
  1770. * and unregistration. Once registration session is active, subsequent
  1771. * refresh will not cause this callback to be called.
  1772. *
  1773. * @param prm Callback parameter.
  1774. */
  1775. virtual void onRegStarted(OnRegStartedParam &prm)
  1776. { PJ_UNUSED_ARG(prm); }
  1777. /**
  1778. * Notify application when registration status has changed.
  1779. * Application may then query the account info to get the
  1780. * registration details.
  1781. *
  1782. * @param prm Callback parameter.
  1783. */
  1784. virtual void onRegState(OnRegStateParam &prm)
  1785. { PJ_UNUSED_ARG(prm); }
  1786. /**
  1787. * Notification when incoming SUBSCRIBE request is received. Application
  1788. * may use this callback to authorize the incoming subscribe request
  1789. * (e.g. ask user permission if the request should be granted).
  1790. *
  1791. * If this callback is not implemented, all incoming presence subscription
  1792. * requests will be accepted.
  1793. *
  1794. * If this callback is implemented, application has several choices on
  1795. * what to do with the incoming request:
  1796. * - it may reject the request immediately by specifying non-200 class
  1797. * final response in the IncomingSubscribeParam.code parameter.
  1798. * - it may immediately accept the request by specifying 200 as the
  1799. * IncomingSubscribeParam.code parameter. This is the default value if
  1800. * application doesn't set any value to the IncomingSubscribeParam.code
  1801. * parameter. In this case, the library will automatically send NOTIFY
  1802. * request upon returning from this callback.
  1803. * - it may delay the processing of the request, for example to request
  1804. * user permission whether to accept or reject the request. In this
  1805. * case, the application MUST set the IncomingSubscribeParam.code
  1806. * argument to 202, then IMMEDIATELY calls presNotify() with
  1807. * state PJSIP_EVSUB_STATE_PENDING and later calls presNotify()
  1808. * again to accept or reject the subscription request.
  1809. *
  1810. * Any IncomingSubscribeParam.code other than 200 and 202 will be treated
  1811. * as 200.
  1812. *
  1813. * Application MUST return from this callback immediately (e.g. it must
  1814. * not block in this callback while waiting for user confirmation).
  1815. *
  1816. * @param prm Callback parameter.
  1817. */
  1818. virtual void onIncomingSubscribe(OnIncomingSubscribeParam &prm)
  1819. { PJ_UNUSED_ARG(prm); }
  1820. /**
  1821. * Notify application on incoming instant message or pager (i.e. MESSAGE
  1822. * request) that was received outside call context.
  1823. *
  1824. * @param prm Callback parameter.
  1825. */
  1826. virtual void onInstantMessage(OnInstantMessageParam &prm)
  1827. { PJ_UNUSED_ARG(prm); }
  1828. /**
  1829. * Notify application about the delivery status of outgoing pager/instant
  1830. * message (i.e. MESSAGE) request.
  1831. *
  1832. * @param prm Callback parameter.
  1833. */
  1834. virtual void onInstantMessageStatus(OnInstantMessageStatusParam &prm)
  1835. { PJ_UNUSED_ARG(prm); }
  1836. /**
  1837. * Notify application about typing indication.
  1838. *
  1839. * @param prm Callback parameter.
  1840. */
  1841. virtual void onTypingIndication(OnTypingIndicationParam &prm)
  1842. { PJ_UNUSED_ARG(prm); }
  1843. /**
  1844. * Notification about MWI (Message Waiting Indication) status change.
  1845. * This callback can be called upon the status change of the
  1846. * SUBSCRIBE request (for example, 202/Accepted to SUBSCRIBE is received)
  1847. * or when a NOTIFY reqeust is received.
  1848. *
  1849. * @param prm Callback parameter.
  1850. */
  1851. virtual void onMwiInfo(OnMwiInfoParam &prm)
  1852. { PJ_UNUSED_ARG(prm); }
  1853. private:
  1854. friend class Endpoint;
  1855. friend class Buddy;
  1856. /**
  1857. * An internal function to add a Buddy to Account buddy list.
  1858. * This method is used by Buddy::create().
  1859. */
  1860. void addBuddy(Buddy *buddy);
  1861. /**
  1862. * An internal function to remove a Buddy from Account buddy list.
  1863. * This method is used by Buddy::~Buddy().
  1864. */
  1865. void removeBuddy(Buddy *buddy);
  1866. private:
  1867. pjsua_acc_id id;
  1868. string tmpReason; // for saving response's reason
  1869. #if !DEPRECATED_FOR_TICKET_2232
  1870. BuddyVector buddyList;
  1871. #endif
  1872. };
  1873. /**
  1874. * @} // PJSUA2_ACC
  1875. */
  1876. } // namespace pj
  1877. #endif /* __PJSUA2_ACCOUNT_HPP__ */