test_stack.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. /*
  2. * Copyright (C) 2009 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]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. #ifndef _TEST_STACK_H
  23. #define _TEST_STACK_H
  24. #ifndef LOCAL_IP
  25. # ifdef ANDROID
  26. # define LOCAL_IP "10.0.2.15"
  27. # else
  28. # define LOCAL_IP TNET_SOCKET_HOST_ANY
  29. # endif
  30. #endif
  31. #define TEST_STACK_SDP \
  32. "v=0\r\n" \
  33. "o=bob 2890844730 2890844731 IN IP4 host.example.com\r\n" \
  34. "s=\r\n" \
  35. "c=IN IP4 192.168.0.12\r\n" \
  36. "t=0 0\r\n" \
  37. "m=audio 54344 RTP/AVP 0\r\n" \
  38. "a=rtpmap:0 PCMU/8000\r\n"
  39. #define TEST_STACK_PIDF \
  40. "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
  41. "<presence xmlns:cp=\"urn:ietf:params:xml:ns:pidf:cipid\" xmlns:caps=\"urn:ietf:params:xml:ns:pidf:caps\" xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" xmlns:pdm=\"urn:ietf:params:xml:ns:pidf:data-model\" xmlns:p=\"urn:ietf:params:xml:ns:pidf-diff\" xmlns:op=\"urn:oma:xml:prs:pidf:oma-pres\" entity=\"sip:mamadou@"DOMAIN"\" xmlns=\"urn:ietf:params:xml:ns:pidf\">"\
  42. " <pdm:person id=\"CRUVREZS\">"\
  43. " <op:overriding-willingness>"\
  44. " <op:basic>open</op:basic>"\
  45. " </op:overriding-willingness>"\
  46. " <rpid:activities>"\
  47. " <rpid:unknown />"\
  48. " </rpid:activities>"\
  49. " <rpid:mood>"\
  50. " <rpid:neutral />"\
  51. " </rpid:mood>"\
  52. " <pdm:note>Hello world</pdm:note>"\
  53. " </pdm:person>"\
  54. " <pdm:device id=\"d0001\">"\
  55. " <status>"\
  56. " <basic>open</basic>"\
  57. " </status>"\
  58. " <caps:devcaps>"\
  59. " <caps:mobility>"\
  60. " <caps:supported>"\
  61. " <caps:fixed />"\
  62. " </caps:supported>"\
  63. " </caps:mobility>"\
  64. " </caps:devcaps>"\
  65. " <op:network-availability>"\
  66. " <op:network id=\"IMS\">"\
  67. " <op:active />"\
  68. " </op:network>"\
  69. " </op:network-availability>"\
  70. " <pdm:deviceID>urn:uuid:dd1289fa-c3d7-47bd-a40d-f1f1b2cc5ffc</pdm:deviceID>"\
  71. " </pdm:device>"\
  72. "</presence>"
  73. int test_stack_callback(const tsip_event_t *sipevent)
  74. {
  75. TSK_DEBUG_INFO("\n====\nSTACK event: %d [%s] with opid=%lld\n=====",
  76. sipevent->code, sipevent->phrase, tsip_ssession_get_id(sipevent->ss));
  77. // For ssessions created by the stack ==> call tsk_object_ref(sipevent->ssession);
  78. // to take ownership.
  79. switch(sipevent->type) {
  80. //
  81. // REGISTER
  82. //
  83. case tsip_event_register: {
  84. const tsip_register_event_t* _event;
  85. TSK_DEBUG_INFO("SIP event(REGISTER)");
  86. _event = TSIP_REGISTER_EVENT(sipevent);
  87. switch(_event->type) {
  88. case tsip_ao_register: { /* Answer to Outgoing REGISTER */
  89. if(TSIP_RESPONSE_IS_2XX(sipevent->sipmessage)) {
  90. TSK_DEBUG_INFO("Registration succeed.");
  91. }
  92. else {
  93. TSK_DEBUG_INFO("Registration failed.");
  94. }
  95. break;
  96. }
  97. case tsip_ao_unregister: { /* Answer to Outgoing UNREGISTER */
  98. if(TSIP_RESPONSE_IS_2XX(sipevent->sipmessage)) {
  99. TSK_DEBUG_INFO("UnRegistration succeed.");
  100. }
  101. else {
  102. TSK_DEBUG_INFO("UnRegistration failed.");
  103. }
  104. break;
  105. }
  106. default:
  107. break;
  108. }
  109. break;
  110. }
  111. //
  112. // INVITE
  113. //
  114. case tsip_event_invite: {
  115. TSK_DEBUG_INFO("SIP event(INVITE)");
  116. break;
  117. }
  118. //
  119. // MESSAGE
  120. //
  121. case tsip_event_message: {
  122. const tsip_message_event_t* _event;
  123. TSK_DEBUG_INFO("SIP event(MESSAGE)");
  124. _event = TSIP_MESSAGE_EVENT(sipevent);
  125. switch(_event->type) {
  126. case tsip_i_message: { /* Incoming MESSAGE */
  127. if(TSIP_MESSAGE_HAS_CONTENT(sipevent->sipmessage)) {
  128. TSK_DEBUG_INFO("MESSAGE Content: %s", TSIP_MESSAGE_CONTENT(sipevent->sipmessage));
  129. }
  130. break;
  131. }
  132. case tsip_ao_message: { /* Answer to Outgoing MESSAGE */
  133. if(TSIP_RESPONSE_IS_2XX(sipevent->sipmessage)) {
  134. TSK_DEBUG_INFO("MESSAGE successfully sent.");
  135. }
  136. else {
  137. TSK_DEBUG_INFO("Failed to send MESSAGE (sip code:%d).", TSIP_RESPONSE_CODE(sipevent->sipmessage));
  138. }
  139. }
  140. default:
  141. break;
  142. }
  143. break;
  144. }
  145. //
  146. // PUBLISH
  147. //
  148. case tsip_event_publish: {
  149. TSK_DEBUG_INFO("SIP event(PUBLISH)");
  150. break;
  151. }
  152. //
  153. // SUBSCRIBE
  154. //
  155. case tsip_event_subscribe: {
  156. const tsip_subscribe_event_t* _event;
  157. TSK_DEBUG_INFO("SIP event(SUBSCRIBE)");
  158. _event = TSIP_SUBSCRIBE_EVENT(sipevent);
  159. switch(_event->type) {
  160. case tsip_i_notify: { /* Incoming NOTIFY */
  161. if(TSIP_MESSAGE_CONTENT_DATA(sipevent->sipmessage)) {
  162. TSK_DEBUG_INFO("NOTIFY Content: %s", TSIP_MESSAGE_CONTENT(sipevent->sipmessage));
  163. }
  164. break;
  165. }
  166. case tsip_ao_subscribe: { /* Answer to Outgoing SUBSCRIBE */
  167. if(TSIP_RESPONSE_IS_2XX(sipevent->sipmessage)) {
  168. TSK_DEBUG_INFO("Subscription succeed.");
  169. }
  170. else {
  171. TSK_DEBUG_INFO("Subscription failed.");
  172. }
  173. break;
  174. }
  175. case tsip_ao_unsubscribe: { /* Answer to Outgoing UNSUBSCRIBE */
  176. if(TSIP_RESPONSE_IS_2XX(sipevent->sipmessage)) {
  177. TSK_DEBUG_INFO("UnSubscription succeed.");
  178. }
  179. else {
  180. TSK_DEBUG_INFO("UnSubscription failed.");
  181. }
  182. break;
  183. }
  184. default:
  185. break;
  186. }
  187. break;
  188. }
  189. default: {
  190. TSK_DEBUG_INFO("SIP event(UNKNOWN)");
  191. break;
  192. }
  193. }
  194. //tsk_thread_sleep(1000000);
  195. return 0;
  196. }
  197. void test_stack()
  198. {
  199. #define DOMAIN "ericsson.com"
  200. //#define DOMAIN "micromethod.com"
  201. //#define DOMAIN "ims.inexbee.com"
  202. //#define DOMAIN "sip2sip.info"
  203. const void* usr_context = tsk_null;
  204. int ret;
  205. uint16_t AMF = 0x0001;
  206. /*
  207. tsip_stack_handle_t *stack = tsip_stack_create(test_stack_callback,
  208. TSIP_STACK_SET_DISPLAY_NAME("2233392625"),
  209. TSIP_STACK_SET_PUBLIC_IDENTITY("sip:2233392625@"DOMAIN),
  210. TSIP_STACK_SET_PRIVATE_IDENTITY("2233392625"),
  211. TSIP_STACK_SET_PASSWORD("d3sb7j4fb8"),
  212. TSIP_STACK_SET_REALM("sip:"DOMAIN), // FIXME: without sip:
  213. TSIP_STACK_SET_LOCAL_IP(LOCAL_IP),
  214. //TSIP_STACK_SET_DISCOVERY_NAPTR(1),
  215. //TSIP_STACK_SET_PROXY_CSCF("proxy.sipthor.net", "udp", 0),
  216. //TSIP_STACK_SET_PROXY_CSCF("192.168.0.15", "udp", 0),
  217. TSIP_STACK_SET_PROXY_CSCF_PORT(5060),
  218. TSIP_STACK_SET_MOBILITY("fixed"),
  219. TSIP_STACK_SET_DEVICE_ID("dd1289fa-c3d7-47bd-a40d-f1f1b2cc5ffc"),
  220. TSIP_STACK_SET_NETINFO("ADSL;utran-cell-id-3gpp=00000000"),
  221. TSIP_STACK_SET_PRIVACY("header;id"),
  222. */
  223. /*
  224. tsip_stack_handle_t *stack = tsip_stack_create(test_stack_callback,
  225. TSIP_STACK_SET_DISPLAY_NAME("Mamadou"),
  226. TSIP_STACK_SET_PUBLIC_IDENTITY("sip:mamadou@"DOMAIN),
  227. TSIP_STACK_SET_PRIVATE_IDENTITY("mamadou@"DOMAIN),
  228. TSIP_STACK_SET_PASSWORD("mamadou"),
  229. TSIP_STACK_SET_REALM("sip:"DOMAIN), // FIXME: without sip:
  230. TSIP_STACK_SET_LOCAL_IP(LOCAL_IP),
  231. //TSIP_STACK_SET_DISCOVERY_NAPTR(1),
  232. TSIP_STACK_SET_PROXY_CSCF("192.168.0.15", "udp", 0),
  233. //TSIP_STACK_SET_PROXY_CSCF_PORT(5081),
  234. TSIP_STACK_SET_PROXY_CSCF_PORT(5060),
  235. //TSIP_STACK_SET_SECAGREE_IPSEC("hmac-md5-96", "null", "trans", "esp"),
  236. TSIP_STACK_SET_MOBILITY("fixed"),
  237. TSIP_STACK_SET_DEVICE_ID("dd1289fa-c3d7-47bd-a40d-f1f1b2cc5ffc"),
  238. TSIP_STACK_SET_NETINFO("ADSL;utran-cell-id-3gpp=00000000"),
  239. TSIP_STACK_SET_PRIVACY("header;id"),
  240. */
  241. int32_t port = 4060;
  242. /*
  243. tsip_stack_handle_t *stack = tsip_stack_create(test_stack_callback, "sip:"DOMAIN, "mamadou@"DOMAIN, "sip:mamadou@"DOMAIN,
  244. TSIP_STACK_SET_DISPLAY_NAME("Mamadou"),
  245. TSIP_STACK_SET_PASSWORD("mamadou"),
  246. TSIP_STACK_SET_IMS_AKA_AMF(AMF),
  247. TSIP_STACK_SET_IMS_AKA_OPERATOR_ID("0xff08"),
  248. TSIP_STACK_SET_HEADER("User-Agent", "IM-client/OMA1.0 doubango/v1.0.0"),
  249. TSIP_STACK_SET_PROXY_CSCF("192.168.16.225", port, "udp", "ipv4"),
  250. TSIP_STACK_SET_EARLY_IMS(tsk_true),
  251. */
  252. tsip_stack_handle_t *stack = tsip_stack_create(test_stack_callback, "sip:"DOMAIN, "mamadou@"DOMAIN, "sip:mamadou@"DOMAIN,
  253. TSIP_STACK_SET_DISPLAY_NAME("Mamadou"),
  254. TSIP_STACK_SET_PASSWORD("mamadou"),
  255. TSIP_STACK_SET_IMS_AKA_AMF(AMF),
  256. TSIP_STACK_SET_IMS_AKA_OPERATOR_ID("0xff08"),
  257. TSIP_STACK_SET_HEADER("User-Agent", "IM-client/OMA1.0 doubango/v1.0.0"),
  258. TSIP_STACK_SET_PROXY_CSCF("192.168.0.13", 5081, "tcp", "ipv4"),
  259. TSIP_STACK_SET_LOCAL_IP(LOCAL_IP),
  260. TSIP_STACK_SET_EARLY_IMS(tsk_true),
  261. /*
  262. tsip_stack_handle_t *stack = tsip_stack_create(test_stack_callback, "sip:"DOMAIN, "2233392625", "sip:2233392625@"DOMAIN,
  263. TSIP_STACK_SET_DISPLAY_NAME("Mamadou"),
  264. TSIP_STACK_SET_PASSWORD("d3sb7j4fb8"),
  265. TSIP_STACK_SET_EARLY_IMS(tsk_true),
  266. TSIP_STACK_SET_HEADER("User-Agent", "IM-client/OMA1.0 doubango/v1.0.0"),
  267. */
  268. /*
  269. tsip_stack_handle_t *stack = tsip_stack_create(test_stack_callback,
  270. TSIP_STACK_SET_DISPLAY_NAME("Mamadou"),
  271. TSIP_STACK_SET_PUBLIC_IDENTITY("sip:mamadou@"DOMAIN),
  272. TSIP_STACK_SET_PRIVATE_IDENTITY("mamadou@"DOMAIN),
  273. TSIP_STACK_SET_PASSWORD("mamadou"),
  274. TSIP_STACK_SET_REALM("sip:"DOMAIN), // FIXME: without sip:
  275. TSIP_STACK_SET_LOCAL_IP(LOCAL_IP),
  276. //TSIP_STACK_SET_DISCOVERY_NAPTR(1),
  277. TSIP_STACK_SET_PROXY_CSCF("192.168.16.104", "udp", 0),
  278. //TSIP_STACK_SET_PROXY_CSCF("192.168.0.15", "udp", 0),
  279. TSIP_STACK_SET_PROXY_CSCF_PORT(5060),
  280. //TSIP_STACK_SET_SECAGREE_IPSEC("hmac-md5-96", "null", "trans", "esp"),
  281. TSIP_STACK_SET_MOBILITY("fixed"),
  282. TSIP_STACK_SET_DEVICE_ID("dd1289fa-c3d7-47bd-a40d-f1f1b2cc5ffc"),
  283. TSIP_STACK_SET_NETINFO("ADSL;utran-cell-id-3gpp=00000000"),
  284. TSIP_STACK_SET_PRIVACY("header;id"),
  285. */
  286. TSIP_STACK_SET_NULL());
  287. //tsip_ssession_handle_t *op = tsip_ssession_create(stack,
  288. // TSIP_SSESSION_SET_CONTEXT(usr_context),
  289. // TSIP_SSESSION_SET_HEADER("expires", "30"),
  290. // TSIP_SSESSION_SET_HEADER("Persistence", "session"),
  291. //
  292. // TSIP_SSESSION_SET_CAPS("language", "\"en,fr\""),
  293. // TSIP_SSESSION_SET_CAPS("+audio", ""),
  294. // TSIP_SSESSION_SET_CAPS("+g.oma.sip-im", ""),
  295. //
  296. // tsk_null);
  297. tsip_ssession_handle_t *op = tsip_ssession_create(stack,
  298. TSIP_SSESSION_SET_EXPIRES(30),
  299. TSIP_SSESSION_SET_CAPS("+g.oma.sip-im", ""),
  300. TSIP_SSESSION_SET_CAPS("+audio", ""),
  301. TSIP_SSESSION_SET_CAPS("automata", ""),
  302. TSIP_SSESSION_SET_CAPS("language", "\"en,fr\""),
  303. TSIP_SSESSION_SET_HEADER("Supported", "ssl"),
  304. TSIP_SSESSION_SET_HEADER("P-Access-Network-Info", "3GPP-UTRAN-TDD;utran-cell-id-3gpp=AAAAA0000BBBB"),
  305. TSIP_SSESSION_UNSET_HEADER("P-Access-Network-Info"),
  306. TSIP_SSESSION_SET_NULL());
  307. //tsip_ssession_id_t opid = tsip_ssession_get_id(op);
  308. if((ret = tsip_stack_start(stack))) {
  309. goto bail;
  310. }
  311. tsip_action_REGISTER(op,
  312. TSIP_ACTION_SET_HEADER("My-Header-1", "My-Value-1"),
  313. TSIP_ACTION_SET_HEADER("My-Header-2", "My-Value-1"),
  314. TSIP_ACTION_SET_NULL());
  315. getchar();
  316. //tsk_thread_sleep(2000);
  317. tsip_action_UNREGISTER(op,
  318. TSIP_ACTION_SET_NULL()
  319. );
  320. getchar();
  321. tsk_thread_sleep(2000);
  322. //tsip_unregister(op,
  323. // TSIP_ACTION_SET_HEADER("Persistence2", "action"),
  324. //
  325. // tsk_null);
  326. /*
  327. tsip_subscribe(op,
  328. TSIP_ACTION_SET_HEADER("Persistence", "action"),
  329. tsk_null);
  330. tsk_thread_sleep(5000);
  331. tsip_unsubscribe(op,
  332. TSIP_ACTION_SET_HEADER("Persistence2", "action"),
  333. tsk_null);
  334. */
  335. /* INVITE */
  336. /*
  337. {
  338. tsip_ssession_handle_t *call = TSIP_SSESSION_CREATE(stack,
  339. TSIP_SSESSION_SET_HEADER("to", "sip:samba@"DOMAIN),
  340. TSIP_SSESSION_SET_CAPS("+g.3gpp.icsi-ref", "\"urn%3Aurn-7%3gpp-service.ims.icsi.mmtel\""),
  341. TSIP_SSESSION_SET_HEADER("Supported", "timer, norefersub, precondition"),
  342. TSIP_SSESSION_SET_HEADER("Require", "100rel"),
  343. TSIP_SSESSION_SET_PARAM("content", TEST_STACK_SDP),
  344. TSIP_SSESSION_SET_NULL());
  345. tsip_invite(stack, call);
  346. }
  347. */
  348. /* SUBSCRIBE */
  349. //{
  350. // tsip_ssession_handle_t *ss2 = tsip_ssession_create(stack,
  351. // TSIP_SSESSION_SET_CONTEXT(usr_context),
  352. // TSIP_SSESSION_SET_HEADER("expires", "35"),
  353. // TSIP_SSESSION_SET_HEADER("Event", "reg"),
  354. // TSIP_SSESSION_SET_HEADER("Accept", "application/reginfo+xml"),
  355. // TSIP_SSESSION_SET_HEADER("Allow-Events", "refer, presence, presence.winfo, xcap-diff"),
  356. // TSIP_SSESSION_SET_HEADER("Allow", "INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER"),
  357. //
  358. // tsk_null);
  359. // tsip_subscribe(ss2,
  360. // TSIP_ACTION_SET_HEADER("Description", "subscribing"),
  361. // tsk_null);
  362. // getchar();
  363. // tsip_unsubscribe(ss2,
  364. // TSIP_ACTION_SET_HEADER("Test", "unsubscribing"),
  365. //
  366. // tsk_null);
  367. //}
  368. /* MESSAGE */
  369. //{
  370. // tsip_ssession_handle_t *ss3 = TSIP_SSESSION_CREATE(stack,
  371. // TSIP_SSESSION_SET_HEADER("to", "sip:alice@"DOMAIN),
  372. // TSIP_SSESSION_SET_HEADER("Accept-Contact", "*;+g.oma.sip-im"),
  373. //
  374. // tsk_null);
  375. // tsip_message(ss3,
  376. // TSIP_ACTION_SET_HEADER("Content-Type", "text/plain"),
  377. // TSIP_ACTION_SET_PAYLOAD("Hello world!", tsk_strlen("Hello world!")),
  378. // tsk_null
  379. // );
  380. //}
  381. /* PUBLISH */
  382. /*{
  383. tsip_ssession_handle_t *ss4 = TSIP_SSESSION_CREATE(stack,
  384. TSIP_SSESSION_SET_HEADER("expires", "30"),
  385. TSIP_SSESSION_SET_HEADER("to", "sip:mamadou@"DOMAIN),
  386. TSIP_SSESSION_SET_HEADER("Accept-Contact", "*;+g.oma.sip-im"),
  387. TSIP_SSESSION_SET_HEADER("Event", "presence"),
  388. tsk_null);
  389. tsip_publish(ss4,
  390. TSIP_ACTION_SET_HEADER("Description", "publish"),
  391. TSIP_ACTION_SET_HEADER("Content-Type", "application/pidf+xml"),
  392. TSIP_ACTION_SET_PAYLOAD(TEST_STACK_PIDF, tsk_strlen(TEST_STACK_PIDF)),
  393. tsk_null);
  394. getchar();
  395. tsip_unpublish(ss4,
  396. TSIP_ACTION_SET_HEADER("Description", "unpublish"),
  397. tsk_null);
  398. }
  399. */
  400. // /*getchar();
  401. // tsip_ssession_set(op4,
  402. // TSIP_SSESSION_SET_PARAM("content", TEST_STACK_PIDF),
  403. // TSIP_SSESSION_SET_NULL());
  404. // tsip_publish(stack, op4);*/
  405. //
  406. // getchar();
  407. // tsip_ssession_hangup(op4);
  408. //
  409. //}
  410. bail:
  411. //while(1);//tsk_thread_sleep(500);
  412. //while(1)
  413. //tsk_thread_sleep(50000);
  414. getchar();
  415. tsip_stack_stop(stack);
  416. TSK_OBJECT_SAFE_FREE(op);
  417. TSK_OBJECT_SAFE_FREE(stack);
  418. TSK_DEBUG_INFO("==================");
  419. TSK_DEBUG_INFO("==================");
  420. TSK_DEBUG_INFO("==================");
  421. TSK_DEBUG_INFO("==================");
  422. }
  423. #endif /* _TEST_STACK_H */