SipSession.cxx 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. #include "SipSession.h"
  23. #include "SipStack.h"
  24. #include "MediaSessionMgr.h"
  25. #include "SipUri.h"
  26. #include "Msrp.h"
  27. /* ======================== AsyncAction ========================*/
  28. typedef struct twrap_async_action_s {
  29. const tsip_ssession_handle_t *session;
  30. const ActionConfig* config;
  31. }
  32. twrap_async_action_t;
  33. /* ======================== SipSession ========================*/
  34. SipSession::SipSession(SipStack* stack)
  35. {
  36. init(stack);
  37. }
  38. SipSession::SipSession(SipStack* stack, tsip_ssession_handle_t* pHandle)
  39. {
  40. init(stack, pHandle);
  41. }
  42. SipSession::~SipSession()
  43. {
  44. tsip_ssession_set(m_pHandle,
  45. TSIP_SSESSION_SET_USERDATA(tsk_null),
  46. TSIP_SSESSION_SET_NULL());
  47. TSK_OBJECT_SAFE_FREE(m_pHandle);
  48. }
  49. void SipSession::init(SipStack* pStack, tsip_ssession_handle_t* pHandle/*=tsk_null*/)
  50. {
  51. if(pHandle) {
  52. /* "server-side-session" */
  53. if(tsip_ssession_have_ownership(pHandle)) {
  54. tsk_object_ref(pHandle);
  55. }
  56. else if(tsip_ssession_take_ownership(pHandle) != 0) { /* should never happen */
  57. TSK_DEBUG_ERROR("Failed to take ownership");
  58. return;
  59. }
  60. m_pHandle = pHandle;
  61. }
  62. else {
  63. /* "client-side-session" */
  64. m_pHandle = tsip_ssession_create(pStack->getHandle(),
  65. TSIP_SSESSION_SET_USERDATA(this),
  66. TSIP_SSESSION_SET_NULL());
  67. }
  68. /* set userdata (context) and ref. the stack handle */
  69. tsip_ssession_set(m_pHandle,
  70. TSIP_SSESSION_SET_USERDATA(this),
  71. TSIP_SSESSION_SET_NULL());
  72. m_pStack = pStack;
  73. }
  74. bool SipSession::addHeader(const char* name, const char* value)
  75. {
  76. return (tsip_ssession_set(m_pHandle,
  77. TSIP_SSESSION_SET_HEADER(name, value),
  78. TSIP_SSESSION_SET_NULL()) == 0);
  79. }
  80. bool SipSession::haveOwnership()
  81. {
  82. return (tsip_ssession_have_ownership(m_pHandle) == tsk_true);
  83. }
  84. bool SipSession::removeHeader(const char* name)
  85. {
  86. return (tsip_ssession_set(m_pHandle,
  87. TSIP_SSESSION_UNSET_HEADER(name),
  88. TSIP_SSESSION_SET_NULL()) == 0);
  89. }
  90. bool SipSession::addCaps(const char* name, const char* value)
  91. {
  92. return (tsip_ssession_set(m_pHandle,
  93. TSIP_SSESSION_SET_CAPS(name, value),
  94. TSIP_SSESSION_SET_NULL()) == 0);
  95. }
  96. bool SipSession::addCaps(const char* name)
  97. {
  98. return (tsip_ssession_set(m_pHandle,
  99. TSIP_SSESSION_SET_CAPS(name, tsk_null),
  100. TSIP_SSESSION_SET_NULL()) == 0);
  101. }
  102. bool SipSession::removeCaps(const char* name)
  103. {
  104. return (tsip_ssession_set(m_pHandle,
  105. TSIP_SSESSION_UNSET_CAPS(name),
  106. TSIP_SSESSION_SET_NULL()) == 0);
  107. }
  108. bool SipSession::setExpires(unsigned expires)
  109. {
  110. return (tsip_ssession_set(m_pHandle,
  111. TSIP_SSESSION_SET_EXPIRES(expires),
  112. TSIP_SSESSION_SET_NULL()) == 0);
  113. }
  114. bool SipSession::setFromUri(const char* fromUriString)
  115. {
  116. return (tsip_ssession_set(m_pHandle,
  117. TSIP_SSESSION_SET_FROM_STR(fromUriString),
  118. TSIP_SSESSION_SET_NULL()) == 0);
  119. }
  120. bool SipSession::setFromUri(const SipUri* fromUri)
  121. {
  122. return (tsip_ssession_set(m_pHandle,
  123. TSIP_SSESSION_SET_FROM_OBJ(fromUri->getWrappedUri()),
  124. TSIP_SSESSION_SET_NULL()) == 0);
  125. }
  126. bool SipSession::setToUri(const char* toUriString)
  127. {
  128. return (tsip_ssession_set(m_pHandle,
  129. TSIP_SSESSION_SET_TO_STR(toUriString),
  130. TSIP_SSESSION_SET_NULL()) == 0);
  131. }
  132. bool SipSession::setToUri(const SipUri* toUri)
  133. {
  134. return (tsip_ssession_set(m_pHandle,
  135. TSIP_SSESSION_SET_TO_OBJ(toUri->getWrappedUri()),
  136. TSIP_SSESSION_SET_NULL()) == 0);
  137. }
  138. bool SipSession::setSilentHangup(bool silent)
  139. {
  140. return (tsip_ssession_set(m_pHandle,
  141. TSIP_SSESSION_SET_SILENT_HANGUP(silent ? tsk_true : tsk_false),
  142. TSIP_SSESSION_SET_NULL()) == 0);
  143. }
  144. bool SipSession::addSigCompCompartment(const char* compId)
  145. {
  146. return (tsip_ssession_set(m_pHandle,
  147. TSIP_SSESSION_SET_SIGCOMP_COMPARTMENT(compId),
  148. TSIP_SSESSION_SET_NULL()) == 0);
  149. }
  150. bool SipSession::setAuth(const char* authHa1, const char* authIMPI)
  151. {
  152. return (tsip_ssession_set(m_pHandle,
  153. TSIP_SSESSION_SET_AUTH_HA1(authHa1),
  154. TSIP_SSESSION_SET_AUTH_IMPI(authIMPI),
  155. TSIP_SSESSION_SET_NULL()) == 0);
  156. }
  157. bool SipSession::removeSigCompCompartment()
  158. {
  159. return (tsip_ssession_set(m_pHandle,
  160. TSIP_SSESSION_UNSET_SIGCOMP_COMPARTMENT(),
  161. TSIP_SSESSION_SET_NULL()) == 0);
  162. }
  163. // FIXME: should be "uint64_t" instead of "unsigned"
  164. unsigned SipSession::getId()const
  165. {
  166. return (unsigned)tsip_ssession_get_id(m_pHandle);
  167. }
  168. bool SipSession::setWebSocketSrc(const char* host, int32_t port, const char* proto)
  169. {
  170. return (tsip_ssession_set(m_pHandle,
  171. TSIP_SSESSION_SET_WEBSOCKET_SRC(host, port, proto),
  172. TSIP_SSESSION_SET_NULL()) == 0);
  173. }
  174. const SipStack* SipSession::getStack()const
  175. {
  176. return m_pStack;
  177. }
  178. /* ======================== InviteSession ========================*/
  179. InviteSession::InviteSession(SipStack* pStack)
  180. : SipSession(pStack), m_pMediaMgr(tsk_null)
  181. {
  182. }
  183. InviteSession::InviteSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
  184. : SipSession(pStack, pHandle), m_pMediaMgr(tsk_null)
  185. {
  186. }
  187. InviteSession::~InviteSession()
  188. {
  189. if(m_pMediaMgr) {
  190. delete m_pMediaMgr, m_pMediaMgr = tsk_null;
  191. }
  192. }
  193. bool InviteSession::hangup(ActionConfig* config/*=tsk_null*/)
  194. {
  195. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  196. return (tsip_api_invite_send_bye(m_pHandle,
  197. TSIP_ACTION_SET_CONFIG(action_cfg),
  198. TSIP_ACTION_SET_NULL()) == 0);
  199. }
  200. bool InviteSession::reject(ActionConfig* config/*=tsk_null*/)
  201. {
  202. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  203. return (tsip_api_common_reject(m_pHandle,
  204. TSIP_ACTION_SET_CONFIG(action_cfg),
  205. TSIP_ACTION_SET_NULL()) == 0);
  206. }
  207. bool InviteSession::accept(ActionConfig* config/*=tsk_null*/)
  208. {
  209. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  210. return (tsip_api_common_accept(m_pHandle,
  211. TSIP_ACTION_SET_CONFIG(action_cfg),
  212. TSIP_ACTION_SET_NULL()) == 0);
  213. }
  214. bool InviteSession::sendInfo(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/)
  215. {
  216. int ret;
  217. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  218. if(payload && len) {
  219. ret = tsip_api_invite_send_info(m_pHandle,
  220. TSIP_ACTION_SET_PAYLOAD(payload, len),
  221. TSIP_ACTION_SET_CONFIG(action_cfg),
  222. TSIP_ACTION_SET_NULL());
  223. }
  224. else {
  225. ret = tsip_api_invite_send_info(m_pHandle,
  226. TSIP_ACTION_SET_CONFIG(action_cfg),
  227. TSIP_ACTION_SET_NULL());
  228. }
  229. return (ret == 0);
  230. }
  231. const MediaSessionMgr* InviteSession::getMediaMgr()
  232. {
  233. if(!m_pMediaMgr && m_pHandle) {
  234. tmedia_session_mgr_t* mgr = tsip_session_get_mediamgr(m_pHandle);
  235. if(mgr) {
  236. m_pMediaMgr = new MediaSessionMgr(mgr); // new() it's not yours: see "m_pMediaMgr" which is destroy in the destructor()
  237. tsk_object_unref(mgr);
  238. }
  239. else {
  240. TSK_DEBUG_WARN("No media session associated to this session");
  241. }
  242. }
  243. return m_pMediaMgr;
  244. }
  245. /* ======================== CallSession ========================*/
  246. CallSession::CallSession(SipStack* Stack)
  247. : InviteSession(Stack)
  248. {
  249. }
  250. CallSession::CallSession(SipStack* Stack, tsip_ssession_handle_t* handle)
  251. : InviteSession(Stack, handle)
  252. , m_pT140Callback(tsk_null)
  253. , m_pRtcpCallback(tsk_null)
  254. {
  255. }
  256. CallSession::~CallSession()
  257. {
  258. }
  259. /* @deprecated */
  260. bool CallSession::callAudio(const SipUri* remoteUri, ActionConfig* config/*=tsk_null*/)
  261. {
  262. return call(remoteUri, twrap_media_audio, config);
  263. }
  264. /* @deprecated */
  265. bool CallSession::callAudio(const char* remoteUriString, ActionConfig* config/*=tsk_null*/)
  266. {
  267. return call(remoteUriString, twrap_media_audio, config);
  268. }
  269. /* @deprecated */
  270. bool CallSession::callAudioVideo(const SipUri* remoteUri, ActionConfig* config/*=tsk_null*/)
  271. {
  272. return call(remoteUri, twrap_media_audio_video, config);
  273. }
  274. /* @deprecated */
  275. bool CallSession::callAudioVideo(const char* remoteUriString, ActionConfig* config/*=tsk_null*/)
  276. {
  277. return call(remoteUriString, twrap_media_audio_video, config);
  278. }
  279. /* @deprecated */
  280. bool CallSession::callVideo(const SipUri* remoteUri, ActionConfig* config/*=tsk_null*/)
  281. {
  282. return call(remoteUri, twrap_media_video, config);
  283. }
  284. /* @deprecated */
  285. bool CallSession::callVideo(const char* remoteUriString, ActionConfig* config/*=tsk_null*/)
  286. {
  287. return call(remoteUriString, twrap_media_video, config);
  288. }
  289. bool CallSession::call(const char* remoteUriString, twrap_media_type_t media, ActionConfig* config/*=tsk_null*/)
  290. {
  291. SipUri sipUri(remoteUriString);
  292. if(sipUri.isValid()) {
  293. return call(&sipUri, media, config);
  294. }
  295. TSK_DEBUG_ERROR("Failed to parse sip uri=%s", remoteUriString);
  296. return false;
  297. }
  298. bool CallSession::call(const SipUri* remoteUri, twrap_media_type_t media, ActionConfig* config/*=tsk_null*/)
  299. {
  300. if(!remoteUri) {
  301. TSK_DEBUG_ERROR("Invalid parameter");
  302. return false;
  303. }
  304. tsip_ssession_set(m_pHandle,
  305. TSIP_SSESSION_SET_TO_OBJ(remoteUri->getWrappedUri()),
  306. TSIP_SSESSION_SET_NULL());
  307. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  308. return (tsip_api_invite_send_invite(m_pHandle, twrap_get_native_media_type(media),
  309. TSIP_ACTION_SET_CONFIG(action_cfg),
  310. TSIP_ACTION_SET_NULL()) == 0);
  311. }
  312. bool CallSession::setSupportedCodecs(int32_t codecs)
  313. {
  314. return (tsip_ssession_set(m_pHandle,
  315. TSIP_SSESSION_SET_MEDIA(
  316. TSIP_MSESSION_SET_CODECS(codecs),
  317. TSIP_MSESSION_SET_NULL()
  318. ),
  319. TSIP_SSESSION_SET_NULL()) == 0);
  320. }
  321. int32_t CallSession::getNegotiatedCodecs()
  322. {
  323. return (int32_t) tsip_ssession_get_codecs_neg(m_pHandle);
  324. }
  325. bool CallSession::setMediaSSRC(twrap_media_type_t media, uint32_t ssrc)
  326. {
  327. return (tsip_ssession_set(m_pHandle,
  328. TSIP_SSESSION_SET_MEDIA(
  329. TSIP_MSESSION_SET_RTP_SSRC(twrap_get_native_media_type(media), ssrc),
  330. TSIP_MSESSION_SET_NULL()
  331. ),
  332. TSIP_SSESSION_SET_NULL()) == 0);
  333. }
  334. bool CallSession::setSessionTimer(unsigned timeout, const char* refresher)
  335. {
  336. return (tsip_ssession_set(m_pHandle,
  337. TSIP_SSESSION_SET_MEDIA(
  338. TSIP_MSESSION_SET_TIMERS(timeout, refresher),
  339. TSIP_MSESSION_SET_NULL()
  340. ),
  341. TSIP_SSESSION_SET_NULL()) == 0);
  342. }
  343. bool CallSession::set100rel(bool enabled)
  344. {
  345. return (tsip_ssession_set(m_pHandle,
  346. TSIP_SSESSION_SET_MEDIA(
  347. TSIP_MSESSION_SET_100rel(enabled ? tsk_true : tsk_false),
  348. TSIP_MSESSION_SET_NULL()
  349. ),
  350. TSIP_SSESSION_SET_NULL()) == 0);
  351. }
  352. bool CallSession::setRtcp(bool enabled)
  353. {
  354. return (tsip_ssession_set(m_pHandle,
  355. TSIP_SSESSION_SET_MEDIA(
  356. TSIP_MSESSION_SET_RTCP(enabled ? tsk_true : tsk_false),
  357. TSIP_MSESSION_SET_NULL()
  358. ),
  359. TSIP_SSESSION_SET_NULL()) == 0);
  360. }
  361. bool CallSession::setRtcpMux(bool enabled)
  362. {
  363. return (tsip_ssession_set(m_pHandle,
  364. TSIP_SSESSION_SET_MEDIA(
  365. TSIP_MSESSION_SET_RTCPMUX(enabled ? tsk_true : tsk_false),
  366. TSIP_MSESSION_SET_NULL()
  367. ),
  368. TSIP_SSESSION_SET_NULL()) == 0);
  369. }
  370. bool CallSession::setSRtpMode(enum tmedia_srtp_mode_e mode)
  371. {
  372. return (tsip_ssession_set(m_pHandle,
  373. TSIP_SSESSION_SET_MEDIA(
  374. TSIP_MSESSION_SET_SRTP_MODE(mode),
  375. TSIP_MSESSION_SET_NULL()
  376. ),
  377. TSIP_SSESSION_SET_NULL()) == 0);
  378. }
  379. bool CallSession::setAvpfMode(enum tmedia_mode_e mode)
  380. {
  381. return (tsip_ssession_set(m_pHandle,
  382. TSIP_SSESSION_SET_MEDIA(
  383. TSIP_MSESSION_SET_AVPF_MODE(mode),
  384. TSIP_MSESSION_SET_NULL()
  385. ),
  386. TSIP_SSESSION_SET_NULL()) == 0);
  387. }
  388. bool CallSession::setICE(bool enabled)
  389. {
  390. return (tsip_ssession_set(m_pHandle,
  391. TSIP_SSESSION_SET_MEDIA(
  392. TSIP_MSESSION_SET_ICE(enabled ? tsk_true : tsk_false),
  393. TSIP_MSESSION_SET_NULL()
  394. ),
  395. TSIP_SSESSION_SET_NULL()) == 0);
  396. }
  397. bool CallSession::setICEStun(bool enabled)
  398. {
  399. return (tsip_ssession_set(m_pHandle,
  400. TSIP_SSESSION_SET_MEDIA(
  401. TSIP_MSESSION_SET_ICE_STUN(enabled ? tsk_true : tsk_false),
  402. TSIP_MSESSION_SET_NULL()
  403. ),
  404. TSIP_SSESSION_SET_NULL()) == 0);
  405. }
  406. bool CallSession::setICETurn(bool enabled)
  407. {
  408. return (tsip_ssession_set(m_pHandle,
  409. TSIP_SSESSION_SET_MEDIA(
  410. TSIP_MSESSION_SET_ICE_TURN(enabled ? tsk_true : tsk_false),
  411. TSIP_MSESSION_SET_NULL()
  412. ),
  413. TSIP_SSESSION_SET_NULL()) == 0);
  414. }
  415. bool CallSession::setSTUNServer(const char* hostname, uint16_t port)
  416. {
  417. return (tsip_ssession_set(m_pHandle,
  418. TSIP_SSESSION_SET_MEDIA(
  419. TSIP_MSESSION_SET_STUN_SERVER(hostname, port),
  420. TSIP_MSESSION_SET_NULL()
  421. ),
  422. TSIP_SSESSION_SET_NULL()) == 0);
  423. }
  424. bool CallSession::setSTUNCred(const char* username, const char* password)
  425. {
  426. return (tsip_ssession_set(m_pHandle,
  427. TSIP_SSESSION_SET_MEDIA(
  428. TSIP_MSESSION_SET_STUN_CRED(username, password),
  429. TSIP_MSESSION_SET_NULL()
  430. ),
  431. TSIP_SSESSION_SET_NULL()) == 0);
  432. }
  433. bool CallSession::setVideoFps(int32_t fps)
  434. {
  435. return (tsip_ssession_set(m_pHandle,
  436. TSIP_SSESSION_SET_MEDIA(
  437. TSIP_MSESSION_SET_VIDEO_FPS(fps),
  438. TSIP_MSESSION_SET_NULL()
  439. ),
  440. TSIP_SSESSION_SET_NULL()) == 0);
  441. }
  442. bool CallSession::setVideoBandwidthUploadMax(int32_t max)
  443. {
  444. return (tsip_ssession_set(m_pHandle,
  445. TSIP_SSESSION_SET_MEDIA(
  446. TSIP_MSESSION_SET_VIDEO_BW_UP(max),
  447. TSIP_MSESSION_SET_NULL()
  448. ),
  449. TSIP_SSESSION_SET_NULL()) == 0);
  450. }
  451. bool CallSession::setVideoBandwidthDownloadMax(int32_t max)
  452. {
  453. return (tsip_ssession_set(m_pHandle,
  454. TSIP_SSESSION_SET_MEDIA(
  455. TSIP_MSESSION_SET_VIDEO_BW_DOWN(max),
  456. TSIP_MSESSION_SET_NULL()
  457. ),
  458. TSIP_SSESSION_SET_NULL()) == 0);
  459. }
  460. bool CallSession::setVideoPrefSize(tmedia_pref_video_size_t pref_video_size)
  461. {
  462. return (tsip_ssession_set(m_pHandle,
  463. TSIP_SSESSION_SET_MEDIA(
  464. TSIP_MSESSION_SET_VIDEO_PREFSIZE(pref_video_size),
  465. TSIP_MSESSION_SET_NULL()
  466. ),
  467. TSIP_SSESSION_SET_NULL()) == 0);
  468. }
  469. bool CallSession::setQoS(tmedia_qos_stype_t type, tmedia_qos_strength_t strength)
  470. {
  471. return (tsip_ssession_set(m_pHandle,
  472. TSIP_SSESSION_SET_MEDIA(
  473. TSIP_MSESSION_SET_QOS(type, strength),
  474. TSIP_MSESSION_SET_NULL()
  475. ),
  476. TSIP_SSESSION_SET_NULL()) == 0);
  477. }
  478. bool CallSession::hold(ActionConfig* config/*=tsk_null*/)
  479. {
  480. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  481. return (tsip_api_invite_send_hold(m_pHandle, tmedia_all,
  482. TSIP_ACTION_SET_CONFIG(action_cfg),
  483. TSIP_ACTION_SET_NULL()) ==0 );
  484. }
  485. bool CallSession::resume(ActionConfig* config/*=tsk_null*/)
  486. {
  487. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  488. return (tsip_api_invite_send_resume(m_pHandle, tmedia_all,
  489. TSIP_ACTION_SET_CONFIG(action_cfg),
  490. TSIP_ACTION_SET_NULL()) == 0);
  491. }
  492. bool CallSession::transfer(const char* referToUriString, ActionConfig* config/*=tsk_null*/)
  493. {
  494. if(tsk_strnullORempty(referToUriString)) {
  495. TSK_DEBUG_ERROR("Invalid parameter");
  496. return false;
  497. }
  498. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  499. return (tsip_api_invite_send_ect(m_pHandle, referToUriString,
  500. TSIP_ACTION_SET_CONFIG(action_cfg),
  501. TSIP_ACTION_SET_NULL()) == 0);
  502. }
  503. bool CallSession::acceptTransfer(ActionConfig* config/*=tsk_null*/)
  504. {
  505. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  506. return (tsip_api_invite_send_ect_accept(m_pHandle,
  507. TSIP_ACTION_SET_CONFIG(action_cfg),
  508. TSIP_ACTION_SET_NULL()) == 0);
  509. }
  510. bool CallSession::rejectTransfer(ActionConfig* config/*=tsk_null*/)
  511. {
  512. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  513. return (tsip_api_invite_send_ect_reject(m_pHandle,
  514. TSIP_ACTION_SET_CONFIG(action_cfg),
  515. TSIP_ACTION_SET_NULL()) == 0);
  516. }
  517. bool CallSession::sendDTMF(int number)
  518. {
  519. return (tsip_api_invite_send_dtmf(m_pHandle, number,
  520. TSIP_ACTION_SET_NULL()) == 0);
  521. }
  522. unsigned CallSession::getSessionTransferId()
  523. {
  524. return (unsigned)tsip_ssession_get_id_parent(m_pHandle);
  525. }
  526. bool CallSession::sendT140Data(enum tmedia_t140_data_type_e data_type, const void* data_ptr /*= NULL*/, unsigned data_size /*= 0*/)
  527. {
  528. const tmedia_session_mgr_t* pWrappedMgr;
  529. const MediaSessionMgr* pMgr;
  530. if((pMgr = getMediaMgr()) && (pWrappedMgr = pMgr->getWrappedMgr())) {
  531. return (tmedia_session_mgr_send_t140_data((tmedia_session_mgr_t*)pWrappedMgr, data_type, data_ptr, data_size) == 0);
  532. }
  533. return false;
  534. }
  535. bool CallSession::setT140Callback(const T140Callback* pT140Callback)
  536. {
  537. const tmedia_session_mgr_t* pWrappedMgr;
  538. const MediaSessionMgr* pMgr;
  539. if((pMgr = getMediaMgr()) && (pWrappedMgr = pMgr->getWrappedMgr())) {
  540. if((m_pT140Callback = pT140Callback)) {
  541. return (tmedia_session_mgr_set_t140_ondata_cbfn((tmedia_session_mgr_t*)pWrappedMgr, this, &CallSession::t140OnDataCallback) == 0);
  542. }
  543. else {
  544. return (tmedia_session_mgr_set_t140_ondata_cbfn((tmedia_session_mgr_t*)pWrappedMgr, this, tsk_null) == 0);
  545. }
  546. }
  547. return false;
  548. }
  549. bool CallSession::sendRtcpEvent(enum tmedia_rtcp_event_type_e event_type, twrap_media_type_t media_type, uint32_t ssrc_media /*= 0*/)
  550. {
  551. const tmedia_session_mgr_t* pWrappedMgr;
  552. const MediaSessionMgr* pMgr;
  553. if((pMgr = getMediaMgr()) && (pWrappedMgr = pMgr->getWrappedMgr())) {
  554. return (tmedia_session_mgr_send_rtcp_event((tmedia_session_mgr_t*)pWrappedMgr, twrap_get_native_media_type(media_type), event_type, ssrc_media) == 0);
  555. }
  556. TSK_DEBUG_ERROR("No media manager");
  557. return false;
  558. }
  559. bool CallSession::setRtcpCallback(const RtcpCallback* pRtcpCallback, twrap_media_type_t media_type)
  560. {
  561. const tmedia_session_mgr_t* pWrappedMgr;
  562. const MediaSessionMgr* pMgr;
  563. if((pMgr = getMediaMgr()) && (pWrappedMgr = pMgr->getWrappedMgr())) {
  564. if((m_pRtcpCallback = pRtcpCallback)) {
  565. return (tmedia_session_mgr_set_onrtcp_cbfn((tmedia_session_mgr_t*)pWrappedMgr, twrap_get_native_media_type(media_type), this, &CallSession::rtcpOnCallback) == 0);
  566. }
  567. else {
  568. return (tmedia_session_mgr_set_onrtcp_cbfn((tmedia_session_mgr_t*)pWrappedMgr, twrap_get_native_media_type(media_type), this, tsk_null) == 0);
  569. }
  570. }
  571. return false;
  572. }
  573. const T140Callback* CallSession::getT140Callback() const
  574. {
  575. return m_pT140Callback;
  576. }
  577. int CallSession::t140OnDataCallback(const void* context, enum tmedia_t140_data_type_e data_type, const void* data_ptr, unsigned data_size)
  578. {
  579. const CallSession* session = dyn_cast<const CallSession*>((const CallSession*)context);
  580. if(session && session->getT140Callback()) {
  581. T140CallbackData* dataObj = new T140CallbackData(data_type, data_ptr, data_size);
  582. if(dataObj) {
  583. int ret = const_cast<T140Callback*>(session->getT140Callback())->ondata(dataObj);
  584. delete dataObj;
  585. return ret;
  586. }
  587. }
  588. return 0;
  589. }
  590. const RtcpCallback* CallSession::getRtcpCallback() const
  591. {
  592. return m_pRtcpCallback;
  593. }
  594. int CallSession::rtcpOnCallback(const void* context, enum tmedia_rtcp_event_type_e event_type, uint32_t ssrc_media)
  595. {
  596. const CallSession* session = dyn_cast<const CallSession*>((const CallSession*)context);
  597. if(session && session->getRtcpCallback()) {
  598. RtcpCallbackData* dataObj = new RtcpCallbackData(event_type, ssrc_media);
  599. if(dataObj) {
  600. int ret = const_cast<RtcpCallback*>(session->getRtcpCallback())->onevent(dataObj);
  601. delete dataObj;
  602. return ret;
  603. }
  604. }
  605. TSK_DEBUG_INFO("Not Sending RTCP packet (no callback)");
  606. return 0;
  607. }
  608. /* ======================== MsrpSession ========================*/
  609. MsrpSession::MsrpSession(SipStack* pStack, MsrpCallback* pCallback)
  610. : InviteSession(pStack), m_pCallback(pCallback)
  611. {
  612. tsip_ssession_set(m_pHandle,
  613. TSIP_SSESSION_SET_MEDIA(
  614. TSIP_MSESSION_SET_MSRP_CB(twrap_msrp_cb),
  615. TSIP_MSESSION_SET_NULL()
  616. ),
  617. TSIP_SSESSION_SET_NULL());
  618. }
  619. MsrpSession::MsrpSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
  620. : InviteSession(pStack, pHandle), m_pCallback(tsk_null)
  621. {
  622. tsip_ssession_set(m_pHandle,
  623. TSIP_SSESSION_SET_MEDIA(
  624. TSIP_MSESSION_SET_MSRP_CB(twrap_msrp_cb),
  625. TSIP_MSESSION_SET_NULL()
  626. ),
  627. TSIP_SSESSION_SET_NULL());
  628. }
  629. MsrpSession::~MsrpSession()
  630. {
  631. }
  632. bool MsrpSession::setCallback(MsrpCallback* pCallback)
  633. {
  634. m_pCallback = pCallback;
  635. return true;
  636. }
  637. bool MsrpSession::callMsrp(const SipUri* remoteUri, ActionConfig* config/*=tsk_null*/)
  638. {
  639. if(!remoteUri) {
  640. TSK_DEBUG_ERROR("Invalid parameter");
  641. return false;
  642. }
  643. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  644. tsip_ssession_set(m_pHandle,
  645. TSIP_SSESSION_SET_TO_OBJ(remoteUri->getWrappedUri()),
  646. TSIP_SSESSION_SET_NULL());
  647. return (tsip_api_invite_send_invite(m_pHandle, tmedia_msrp,
  648. TSIP_ACTION_SET_CONFIG(action_cfg),
  649. TSIP_ACTION_SET_NULL()) == 0);
  650. }
  651. bool MsrpSession::callMsrp(const char* remoteUriString, ActionConfig* config/*=tsk_null*/)
  652. {
  653. SipUri sipUri(remoteUriString);
  654. if(sipUri.isValid()) {
  655. return callMsrp(&sipUri, config);
  656. }
  657. TSK_DEBUG_ERROR("Failed to parse sip uri=%s", remoteUriString);
  658. return false;
  659. }
  660. bool MsrpSession::sendMessage(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/)
  661. {
  662. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  663. return (tsip_api_invite_send_large_message(m_pHandle,
  664. TSIP_ACTION_SET_PAYLOAD(payload, len),
  665. TSIP_ACTION_SET_CONFIG(action_cfg),
  666. TSIP_ACTION_SET_NULL()) == 0);
  667. }
  668. bool MsrpSession::sendFile(ActionConfig* config/*=tsk_null*/)
  669. {
  670. return false;
  671. }
  672. /* ======================== MessagingSession ========================*/
  673. MessagingSession::MessagingSession(SipStack* pStack)
  674. : SipSession(pStack)
  675. {
  676. }
  677. MessagingSession::MessagingSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
  678. : SipSession(pStack, pHandle)
  679. {
  680. }
  681. MessagingSession::~MessagingSession()
  682. {
  683. }
  684. bool MessagingSession::send(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/)
  685. {
  686. int ret;
  687. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  688. if(payload && len) {
  689. ret = tsip_api_message_send_message(m_pHandle,
  690. TSIP_ACTION_SET_PAYLOAD(payload, len),
  691. TSIP_ACTION_SET_CONFIG(action_cfg),
  692. TSIP_ACTION_SET_NULL());
  693. }
  694. else {
  695. ret = tsip_api_message_send_message(m_pHandle,
  696. TSIP_ACTION_SET_NULL());
  697. }
  698. return (ret == 0);
  699. }
  700. bool MessagingSession::accept(ActionConfig* config/*=tsk_null*/)
  701. {
  702. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  703. return (tsip_api_common_accept(m_pHandle,
  704. TSIP_ACTION_SET_CONFIG(action_cfg),
  705. TSIP_ACTION_SET_NULL()) == 0);
  706. }
  707. bool MessagingSession::reject(ActionConfig* config/*=tsk_null*/)
  708. {
  709. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  710. return (tsip_api_common_reject(m_pHandle,
  711. TSIP_ACTION_SET_CONFIG(action_cfg),
  712. TSIP_ACTION_SET_NULL()) == 0);
  713. }
  714. /* ======================== InfoSession ========================*/
  715. InfoSession::InfoSession(SipStack* pStack)
  716. : SipSession(pStack)
  717. {
  718. }
  719. InfoSession::InfoSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
  720. : SipSession(pStack, pHandle)
  721. {
  722. }
  723. InfoSession::~InfoSession()
  724. {
  725. }
  726. bool InfoSession::send(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/)
  727. {
  728. int ret;
  729. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  730. if(payload && len) {
  731. ret = tsip_api_info_send_info(m_pHandle,
  732. TSIP_ACTION_SET_PAYLOAD(payload, len),
  733. TSIP_ACTION_SET_CONFIG(action_cfg),
  734. TSIP_ACTION_SET_NULL());
  735. }
  736. else {
  737. ret = tsip_api_info_send_info(m_pHandle,
  738. TSIP_ACTION_SET_NULL());
  739. }
  740. return (ret == 0);
  741. }
  742. bool InfoSession::accept(ActionConfig* config/*=tsk_null*/)
  743. {
  744. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  745. return (tsip_api_common_accept(m_pHandle,
  746. TSIP_ACTION_SET_CONFIG(action_cfg),
  747. TSIP_ACTION_SET_NULL()) == 0);
  748. }
  749. bool InfoSession::reject(ActionConfig* config/*=tsk_null*/)
  750. {
  751. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  752. return (tsip_api_common_reject(m_pHandle,
  753. TSIP_ACTION_SET_CONFIG(action_cfg),
  754. TSIP_ACTION_SET_NULL()) == 0);
  755. }
  756. /* ======================== OptionsSession ========================*/
  757. OptionsSession::OptionsSession(SipStack* pStack)
  758. : SipSession(pStack)
  759. {
  760. }
  761. OptionsSession::OptionsSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
  762. : SipSession(pStack, pHandle)
  763. {
  764. }
  765. OptionsSession::~OptionsSession()
  766. {
  767. }
  768. bool OptionsSession::send(ActionConfig* config/*=tsk_null*/)
  769. {
  770. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  771. return (tsip_api_options_send_options(m_pHandle,
  772. TSIP_ACTION_SET_CONFIG(action_cfg),
  773. TSIP_ACTION_SET_NULL()) == 0);
  774. }
  775. bool OptionsSession::accept(ActionConfig* config/*=tsk_null*/)
  776. {
  777. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  778. return (tsip_api_common_accept(m_pHandle,
  779. TSIP_ACTION_SET_CONFIG(action_cfg),
  780. TSIP_ACTION_SET_NULL()) == 0);
  781. }
  782. bool OptionsSession::reject(ActionConfig* config/*=tsk_null*/)
  783. {
  784. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  785. return (tsip_api_common_reject(m_pHandle,
  786. TSIP_ACTION_SET_CONFIG(action_cfg),
  787. TSIP_ACTION_SET_NULL()) == 0);
  788. }
  789. /* ======================== PublicationSession ========================*/
  790. PublicationSession::PublicationSession(SipStack* Stack)
  791. : SipSession(Stack)
  792. {
  793. }
  794. PublicationSession::PublicationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
  795. : SipSession(pStack, pHandle)
  796. {
  797. }
  798. PublicationSession::~PublicationSession()
  799. {
  800. }
  801. bool PublicationSession::publish(const void* payload, unsigned len, ActionConfig* config/*=tsk_null*/)
  802. {
  803. int ret;
  804. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  805. if(payload && len) {
  806. ret = tsip_api_publish_send_publish(m_pHandle,
  807. TSIP_ACTION_SET_PAYLOAD(payload, len),
  808. TSIP_ACTION_SET_NULL());
  809. }
  810. else {
  811. ret = tsip_api_publish_send_publish(m_pHandle,
  812. TSIP_ACTION_SET_CONFIG(action_cfg),
  813. TSIP_ACTION_SET_NULL());
  814. }
  815. return (ret == 0);
  816. }
  817. bool PublicationSession::unPublish(ActionConfig* config/*=tsk_null*/)
  818. {
  819. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  820. return (tsip_api_publish_send_unpublish(m_pHandle,
  821. TSIP_ACTION_SET_CONFIG(action_cfg),
  822. TSIP_ACTION_SET_NULL()) == 0);
  823. }
  824. /* ======================== RegistrationSession ========================*/
  825. RegistrationSession::RegistrationSession(SipStack* pStack)
  826. : SipSession(pStack)
  827. {
  828. }
  829. RegistrationSession::RegistrationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
  830. : SipSession(pStack, pHandle)
  831. {
  832. }
  833. RegistrationSession::~RegistrationSession()
  834. {
  835. }
  836. bool RegistrationSession::register_(ActionConfig* config/*=tsk_null*/)
  837. {
  838. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  839. return (tsip_api_register_send_register(m_pHandle,
  840. TSIP_ACTION_SET_CONFIG(action_cfg),
  841. TSIP_ACTION_SET_NULL()) == 0);
  842. }
  843. bool RegistrationSession::unRegister(ActionConfig* config/*=tsk_null*/)
  844. {
  845. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  846. return (tsip_api_register_send_unregister(m_pHandle,
  847. TSIP_ACTION_SET_CONFIG(action_cfg),
  848. TSIP_ACTION_SET_NULL()) == 0);
  849. }
  850. bool RegistrationSession::accept(ActionConfig* config/*=tsk_null*/)
  851. {
  852. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  853. return (tsip_api_common_accept(m_pHandle,
  854. TSIP_ACTION_SET_CONFIG(action_cfg),
  855. TSIP_ACTION_SET_NULL()) == 0);
  856. }
  857. bool RegistrationSession::reject(ActionConfig* config/*=tsk_null*/)
  858. {
  859. const tsip_action_handle_t* action_cfg = config ? config->getHandle() : tsk_null;
  860. return (tsip_api_common_reject(m_pHandle,
  861. TSIP_ACTION_SET_CONFIG(action_cfg),
  862. TSIP_ACTION_SET_NULL()) == 0);
  863. }
  864. /* ======================== SubscriptionSession ========================*/
  865. SubscriptionSession::SubscriptionSession(SipStack* pStack)
  866. : SipSession(pStack)
  867. {
  868. }
  869. SubscriptionSession::SubscriptionSession(SipStack* pStack, tsip_ssession_handle_t* pHandle)
  870. : SipSession(pStack, pHandle)
  871. {
  872. }
  873. SubscriptionSession::~SubscriptionSession()
  874. {
  875. }
  876. bool SubscriptionSession::subscribe()
  877. {
  878. return (tsip_api_subscribe_send_subscribe(m_pHandle,
  879. TSIP_ACTION_SET_NULL()) == 0);
  880. }
  881. bool SubscriptionSession::unSubscribe()
  882. {
  883. return (tsip_api_subscribe_send_unsubscribe(m_pHandle,
  884. TSIP_ACTION_SET_NULL()) == 0);
  885. }