test_manager.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * Copyright (C) 2009 Mamadou Diop.
  3. * Copyright (C) 2012 Doubango Telecom <http://doubango.org>.
  4. *
  5. * This file is part of Open Source Doubango Framework.
  6. *
  7. * DOUBANGO is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * DOUBANGO is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with DOUBANGO.
  19. *
  20. */
  21. #ifndef TEST_TINYSIGCOMP_MANAGER_H
  22. #define TEST_TINYSIGCOMP_MANAGER_H
  23. #define SIGCOMP_TESTS SIGCOMP_TESTS_CALL
  24. #define COMPARTMENT_ID_CLIENT "urn:uuid:2e5fdc76-00be-4314-8202-1116fa82a474"
  25. #define COMPARTMENT_ID_SERVER "urn:uuid:2e5fdc76-00be-4314-8202-1116fa82a475"
  26. #define SIGCOMP_DMS 8192//4096//8192//65536
  27. #define SIGCOMP_SMS 8192//4096//8192//65536
  28. #define SIGCOMP_CPB 64
  29. #define SIGCOMP_LOOP_COUNT 10
  30. #define USE_ONLY_ACKED_STATES tsk_false // Should be false unless you know what you're doing
  31. typedef struct sigcomp_test_s {
  32. const char* description;
  33. const char* msg;
  34. tsk_bool_t is_client;
  35. tsk_bool_t tobe_lost;
  36. }
  37. sigcomp_test_t;
  38. #define IS_CLIENT_YES tsk_true
  39. #define IS_CLIENT_NO tsk_false
  40. #define TOBE_LOST_YES tsk_true
  41. #define TOBE_LOST_NO tsk_false
  42. static const sigcomp_test_t SIGCOMP_TESTS_CALL[]= {
  43. {
  44. "REGISTER (client -> server)",
  45. "REGISTER sip:doubango.org SIP/2.0\r\n"
  46. "Via: SIP/2.0/UDP 192.168.0.11:64549;branch=z9hG4bK357158829;rport;comp=sigcomp;sigcomp-id=\"urn:uuid:d343a50a-2961-4a25-93d8-4e0677b68e6b\"\r\n"
  47. "From: <sip:001@doubango.org>;tag=357151115\r\n"
  48. "To: <sip:001@doubango.org>\r\n"
  49. "Contact: <sip:001@192.168.0.11:64549;transport=udp;sigcomp-id=urn:uuid:d343a50a-2961-4a25-93d8-4e0677b68e6b>;expires=3600;+g.oma.sip-im;language=\"en,fr\";+g.3gpp.smsip;+g.oma.sip-im.large-message;audio;+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-application.ims.iari.gsma-vs\";+g.3gpp.cs-voice\r\n"
  50. "Call-ID: 0473e8ff-2cd6-fada-70ab-ce8c9523db8c\r\n"
  51. "CSeq: 5493 REGISTER\r\n"
  52. "Content-Length: 0\r\n"
  53. "Max-Forwards: 70\r\n"
  54. "Allow: INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER\r\n"
  55. "Privacy: none\r\n"
  56. "P-Access-Network-Info: ADSL;utran-cell-id-3gpp=00000000\r\n"
  57. "User-Agent: IM-client/OMA1.0 Boghe/v2.0.121.757\r\n"
  58. "P-Preferred-Identity: <sip:001@doubango.org>\r\n"
  59. "Supported: path\r\n"
  60. "\r\n",
  61. IS_CLIENT_YES,
  62. TOBE_LOST_NO
  63. },
  64. {
  65. "200 REGISTER (server -> client)",
  66. "SIP/2.0 200 OK\r\n"
  67. "Via: SIP/2.0/UDP 192.168.0.11:64549;branch=z9hG4bK357158829;rport=64549;comp=sigcomp;sigcomp-id=\"urn:uuid:d343a50a-2961-4a25-93d8-4e0677b68e6b\"\r\n"
  68. "Contact: <sip:001@192.168.0.11:54027;transport=udp;sigcomp-id=\"urn:uuid:7556d001-9ca7-41a3-80b0-5b7725a91cc4\">;expires=2761;language=\"en,fr\";+g.oma.sip-im;+g.3gpp.smsip;+g.oma.sip-im.large-message;audio;+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-application.ims.iari.gsma-vs\";+g.3gpp.cs-voice\r\n"
  69. "Contact: <sip:001@192.168.0.11:50417;transport=udp;sigcomp-id=\"urn:uuid:6a8b493e-7dd8-45fb-b104-085723cbfb7b\">;expires=3025;language=\"en,fr\";+g.oma.sip-im;+g.3gpp.smsip;+g.oma.sip-im.large-message;audio;+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-application.ims.iari.gsma-vs\";+g.3gpp.cs-voice\r\n"
  70. "Contact: <sip:001@192.168.0.11:50464;transport=udp;sigcomp-id=\"urn:uuid:c5534343-0fb1-41a8-b4bc-612f04913d2a\">;expires=3409;language=\"en,fr\";+g.oma.sip-im;+g.3gpp.smsip;+g.oma.sip-im.large-message;audio;+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-application.ims.iari.gsma-vs\";+g.3gpp.cs-voice\r\n"
  71. "Contact: <sip:001@192.168.0.11:64547;transport=udp;sigcomp-id=\"urn:uuid:40ce6b6c-90b3-487d-8768-ae180a8153b1\">;expires=3487;language=\"en,fr\";+g.oma.sip-im;+g.3gpp.smsip;+g.oma.sip-im.large-message;audio;+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-application.ims.iari.gsma-vs\";+g.3gpp.cs-voice\r\n"
  72. "Contact: <sip:001@192.168.0.11:64549;transport=udp;sigcomp-id=\"urn:uuid:d343a50a-2961-4a25-93d8-4e0677b68e6b\">;expires=3600;language=\"en,fr\";+g.oma.sip-im;+g.3gpp.smsip;+g.oma.sip-im.large-message;audio;+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-application.ims.iari.gsma-vs\";+g.3gpp.cs-voice\r\n"
  73. "To: <sip:001@doubango.org>;tag=4345c04e\r\n"
  74. "From: <sip:001@doubango.org>;tag=357151115\r\n"
  75. "Call-ID: 0473e8ff-2cd6-fada-70ab-ce8c9523db8c\r\n"
  76. "CSeq: 5493 REGISTER\r\n"
  77. "Content-Length: 0\r\n"
  78. "\r\n",
  79. IS_CLIENT_NO,
  80. TOBE_LOST_NO
  81. },
  82. {
  83. "INVITE (client -> server)",
  84. "INVITE sip:13131313@sip2sip.info SIP/2.0\r\n"
  85. "Via: SIP/2.0/UDP 192.168.0.11:64549;branch=z9hG4bK357179240;rport;comp=sigcomp;sigcomp-id=\"urn:uuid:d343a50a-2961-4a25-93d8-4e0677b68e6b\"\r\n"
  86. "From: <sip:001@doubango.org>;tag=357203612\r\n"
  87. "To: <sip:13131313@sip2sip.info>\r\n"
  88. "Contact: <sip:001@192.168.0.11:64549;transport=udp;sigcomp-id=urn:uuid:d343a50a-2961-4a25-93d8-4e0677b68e6b>;+g.oma.sip-im;language=\"en,fr\";+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel\"\r\n"
  89. "Call-ID: da91debf-0033-dd9e-9c8d-e9018f825c8f\r\n"
  90. "CSeq: 14727 INVITE\r\n"
  91. "Content-Type: application/sdp\r\n"
  92. "Content-Length: 989\r\n"
  93. "Max-Forwards: 70\r\n"
  94. "Accept-Contact: *;+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel\"\r\n"
  95. "P-Preferred-Service: urn:urn-7:3gpp-service.ims.icsi.mmtel\r\n"
  96. "Allow: INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER\r\n"
  97. "Privacy: none\r\n"
  98. "P-Access-Network-Info: ADSL;utran-cell-id-3gpp=00000000\r\n"
  99. "User-Agent: IM-client/OMA1.0 Boghe/v2.0.121.757\r\n"
  100. "Supported: 100rel\r\n"
  101. "\r\n"
  102. "v=0\r\n"
  103. "o=doubango 1983 678901 IN IP4 192.168.0.11\r\n"
  104. "s=-\r\n"
  105. "c=IN IP4 192.168.0.11\r\n"
  106. "t=0 0\r\n"
  107. "m=audio 64550 RTP/SAVPF 0 8 97 101\r\n"
  108. "c=IN IP4 192.168.0.11\r\n"
  109. "a=ptime:20\r\n"
  110. "a=silenceSupp:off - - - -\r\n"
  111. "a=rtpmap:0 PCMU/8000/1\r\n"
  112. "a=rtpmap:8 PCMA/8000/1\r\n"
  113. "a=rtpmap:97 SPEEX/8000/1\r\n"
  114. "a=rtpmap:101 telephone-event/8000/1\r\n"
  115. "a=fmtp:101 0-16\r\n"
  116. "a=sendrecv\r\n"
  117. "a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:JaJaTgwhqSd2A7yQ842YPXASomulb95aX/Wa96T7\r\n"
  118. "a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:T3yTUA2dVXTr6v0jb+E1TR3Btj4xP3mPeaAtQbeC\r\n"
  119. "a=rtcp-mux\r\n"
  120. "a=ssrc:3301897658 cname:ldjWoB60jbyQlR6e\r\n"
  121. "a=ssrc:3301897658 mslabel:6994f7d1-6ce9-4fbd-acfd-84e5131ca2e2\r\n"
  122. "a=ssrc:3301897658 label:Doubango\r\n"
  123. "a=ice-ufrag:zNevtNKAGk6h7gJ\r\n"
  124. "a=ice-pwd:YaOV3FlWUkBmifZ87SP51\r\n"
  125. "a=mid:audio\r\n"
  126. "a=candidate:CuNeg0Keh 1 udp 2130706431 192.168.0.11 64550 typ host\r\n"
  127. "a=candidate:CuNeg0Keh 2 udp 2130706430 192.168.0.11 64551 typ host\r\n"
  128. "a=candidate:srflxCuNe 1 udp 1694498815 88.179.39.5 64550 typ srflx\r\n"
  129. "a=candidate:srflxCuNe 2 udp 1694498814 88.179.39.5 64551 typ srflx\r\n"
  130. "\r\n",
  131. IS_CLIENT_YES,
  132. TOBE_LOST_NO
  133. },
  134. {
  135. "100 TRYING (server -> client)",
  136. "SIP/2.0 100 Trying\r\n"
  137. "Via: SIP/2.0/UDP 192.168.0.11:64549;branch=z9hG4bK357179240;rport=64549;comp=sigcomp;sigcomp-id=\"urn:uuid:d343a50a-2961-4a25-93d8-4e0677b68e6b\"\r\n"
  138. "To: <sip:13131313@sip2sip.info>\r\n"
  139. "From: <sip:001@doubango.org>;tag=357203612\r\n"
  140. "Call-ID: da91debf-0033-dd9e-9c8d-e9018f825c8f\r\n"
  141. "CSeq: 14727 INVITE\r\n"
  142. "Content-Length: 0\r\n"
  143. "\r\n",
  144. IS_CLIENT_NO,
  145. TOBE_LOST_NO
  146. },
  147. {
  148. "488 Not acceptable (server -> client)",
  149. "SIP/2.0 488 Not acceptable here\r\n"
  150. "Via: SIP/2.0/UDP 192.168.0.11:64549;branch=z9hG4bK357179240;rport=64549;comp=sigcomp;sigcomp-id=\"urn:uuid:d343a50a-2961-4a25-93d8-4e0677b68e6b\"\r\n"
  151. "To: <sip:13131313@sip2sip.info>;tag=as6edf9ce2\r\n"
  152. "From: <sip:001@doubango.org>;tag=357203612\r\n"
  153. "Call-ID: da91debf-0033-dd9e-9c8d-e9018f825c8f\r\n"
  154. "CSeq: 14727 INVITE\r\n"
  155. "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH\r\n"
  156. "Server: Asterisk PBX\r\n"
  157. "Supported: replaces, timer\r\n"
  158. "Content-Length: 0\r\n"
  159. "\r\n",
  160. IS_CLIENT_NO,
  161. TOBE_LOST_NO
  162. },
  163. {
  164. "ACK (client -> server)",
  165. "ACK sip:13131313@sip2sip.info SIP/2.0\r\n"
  166. "Via: SIP/2.0/UDP 192.168.0.11:64549;branch=z9hG4bK357179240;rport;comp=sigcomp;sigcomp-id=\"urn:uuid:d343a50a-2961-4a25-93d8-4e0677b68e6b\"\r\n"
  167. "From: <sip:001@doubango.org>;tag=357203612\r\n"
  168. "To: <sip:13131313@sip2sip.info>;tag=as6edf9ce2\r\n"
  169. "Call-ID: da91debf-0033-dd9e-9c8d-e9018f825c8f\r\n"
  170. "CSeq: 14727 ACK\r\n"
  171. "Content-Length: 0\r\n"
  172. "Max-Forwards: 70\r\n"
  173. "\r\n",
  174. IS_CLIENT_YES,
  175. TOBE_LOST_NO
  176. }
  177. };
  178. static const sigcomp_test_t SIGCOMP_TESTS_SUBSCRIBE[]= {
  179. {
  180. "REGISTER (client -> server)",
  181. "REGISTER sip:test.3gpp.com SIP/2.0\r\n"
  182. "Via: SIP/2.0/TCP 156.141.115.182:62493;branch=z9hG4bK1403432184;rport;comp=sigcomp;sigcomp-id=\"urn:uuid:41147e2b-d2b9-47c1-a698-c732f6f036f4\"\r\n"
  183. "From: <sip:johndoe@test.3gpp.com>;tag=1403421024\r\n"
  184. "To: <sip:johndoe@test.3gpp.com>\r\n"
  185. "Contact: <sip:johndoe@156.141.115.182:62493;transport=tcp;sigcomp-id=urn:uuid:41147e2b-d2b9-47c1-a698-c732f6f036f4>;expires=600000;+g.oma.sip-im;language=\"en,fr\";+g.3gpp.smsip;+g.oma.sip-im.large-message;audio;+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-application.ims.iari.gsma-vs\";+g.3gpp.cs-voice\r\n"
  186. "Call-ID: afac1d20-b998-2720-6407-7bbbc77ace9b\r\n"
  187. "CSeq: 27335 REGISTER\r\n"
  188. "Content-Length: 0\r\n"
  189. "Max-Forwards: 70\r\n"
  190. "Authorization: Digest username=\"johndoe@test.3gpp.com\",realm=\"test.3gpp.com\",nonce=\"\",uri=\"sip:test.3gpp.com\",response=\"\"\r\n"
  191. "Allow: INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER\r\n"
  192. "Privacy: none\r\n"
  193. "P-Access-Network-Info: ADSL;utran-cell-id-3gpp=00000000\r\n"
  194. "User-Agent: IM-client/OMA1.0 Boghe/v2.0.132.808\r\n"
  195. "P-Preferred-Identity: <sip:johndoe@test.3gpp.com>\r\n"
  196. "Supported: path\r\n"
  197. "\r\n",
  198. IS_CLIENT_YES,
  199. TOBE_LOST_NO
  200. },
  201. {
  202. "200 REGISTER (server -> client)",
  203. "SIP/2.0 200 OK\r\n"
  204. "Via: SIP/2.0/TCP 156.141.115.182:62493;branch=z9hG4bK1403432184;rport;comp=sigcomp;sigcomp-id=\"urn:uuid:41147e2b-d2b9-47c1-a698-c732f6f036f4\"\r\n"
  205. "From: <sip:johndoe@test.3gpp.com>;tag=1403421024\r\n"
  206. "To: <sip:johndoe@test.3gpp.com>;tag=T91612B6\r\n"
  207. "Call-ID: afac1d20-b998-2720-6407-7bbbc77ace9b\r\n"
  208. "CSeq: 27335 REGISTER\r\n"
  209. "Contact: <sip:johndoe@156.141.115.182:62493;transport=tcp;sigcomp-id=urn:uuid:41147e2b-d2b9-47c1-a698-c732f6f036f4>;q=0.500;expires = 600000;+g.oma.sip-im;language=\"en,fr\";+g.3gpp.smsip;+g.oma.sip-im.large-message;audio;+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-application.ims.iari.gsma-vs\";+g.3gpp.cs-voice\r\n"
  210. "Content-Length: 0\r\n"
  211. "Date: Fri, 25 Jan 2013 09:20:31 GMT\r\n"
  212. "P-Associated-URI: <sip:johndoe@test.3gpp.com>\r\n"
  213. "Server: Agilent_IMS-SIP_Server/4.11.0.0\r\n"
  214. "\r\n",
  215. IS_CLIENT_NO,
  216. TOBE_LOST_NO
  217. },
  218. {
  219. "SUBSCRIBE-1 (client -> server)",
  220. "SUBSCRIBE sip:johndoe@test.3gpp.com SIP/2.0\r\n"
  221. "Via: SIP/2.0/TCP 156.141.115.182:62493;branch=z9hG4bK1403431204;rport;comp=sigcomp;sigcomp-id=\"urn:uuid:41147e2b-d2b9-47c1-a698-c732f6f036f4\"\r\n"
  222. "From: <sip:johndoe@test.3gpp.com>;tag=1403442750\r\n"
  223. "To: <sip:johndoe@test.3gpp.com>\r\n"
  224. "Contact: <sip:johndoe@156.141.115.182:62493;transport=tcp;sigcomp-id=urn:uuid:41147e2b-d2b9-47c1-a698-c732f6f036f4>;+g.oma.sip-im;language=\"en,fr\"\r\n"
  225. "Call-ID: 8c1a2260-c6e7-d415-2492-88493471d6fd\r\n"
  226. "CSeq: 24466 SUBSCRIBE\r\n"
  227. "Expires: 600000\r\n"
  228. "Content-Length: 0\r\n"
  229. "Max-Forwards: 70\r\n"
  230. "Event: reg\r\n"
  231. "Accept: application/reginfo+xml\r\n"
  232. "Allow-Events: refer, presence, presence.winfo, xcap-diff, conference\r\n"
  233. "Allow: INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER\r\n"
  234. "Privacy: none\r\n"
  235. "P-Access-Network-Info: ADSL;utran-cell-id-3gpp=00000000\r\n"
  236. "User-Agent: IM-client/OMA1.0 Boghe/v2.0.132.808\r\n"
  237. "P-Preferred-Identity: <sip:johndoe@test.3gpp.com>\r\n"
  238. "\r\n",
  239. IS_CLIENT_YES,
  240. TOBE_LOST_NO
  241. },
  242. {
  243. "SUBSCRIBE-2 (client -> server)",
  244. "SUBSCRIBE sip:johndoe@test.3gpp.com SIP/2.0\r\n"
  245. "Via: SIP/2.0/TCP 156.141.115.182:62493;branch=z9hG4bK1403422374;rport;comp=sigcomp;sigcomp-id=\"urn:uuid:41147e2b-d2b9-47c1-a698-c732f6f036f4\"\r\n"
  246. "From: <sip:johndoe@test.3gpp.com>;tag=1403431575\r\n"
  247. "To: <sip:johndoe@test.3gpp.com>\r\n"
  248. "Contact: <sip:johndoe@156.141.115.182:62493;transport=tcp;sigcomp-id=urn:uuid:41147e2b-d2b9-47c1-a698-c732f6f036f4>;+g.oma.sip-im;language=\"en,fr\"\r\n"
  249. "Call-ID: 05952487-8f39-ddbd-ebac-72a3f33eaf8d\r\n"
  250. "CSeq: 32393 SUBSCRIBE\r\n"
  251. "Expires: 600000\r\n"
  252. "Content-Length: 0\r\n"
  253. "Max-Forwards: 70\r\n"
  254. "Event: message-summary\r\n"
  255. "Accept: application/simple-message-summary\r\n"
  256. "Allow-Events: refer, presence, presence.winfo, xcap-diff, conference\r\n"
  257. "Allow: INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER\r\n"
  258. "Privacy: none\r\n"
  259. "P-Access-Network-Info: ADSL;utran-cell-id-3gpp=00000000\r\n"
  260. "User-Agent: IM-client/OMA1.0 Boghe/v2.0.132.808\r\n"
  261. "P-Preferred-Identity: <sip:johndoe@test.3gpp.com>\r\n"
  262. "\r\n",
  263. IS_CLIENT_YES,
  264. TOBE_LOST_NO
  265. },
  266. };
  267. static int handle_nack(tcomp_result_t *nack, tcomp_manager_handle_t* manager)
  268. {
  269. if(nack->isNack) {
  270. tsk_size_t nack_info_size;
  271. if(nack->nack_info && (nack_info_size = tcomp_buffer_getSize(nack->nack_info))) {
  272. char buff[MAX_BUFFER_SIZE];
  273. tcomp_result_t* result = tcomp_result_create();
  274. tcomp_result_setOutputBuffer(result, buff, sizeof(buff), IS_STREAM, STREAM_ID);
  275. tcomp_manager_decompress(manager, tcomp_buffer_getBuffer(nack->nack_info), nack_info_size, result);
  276. TSK_OBJECT_SAFE_FREE(result);
  277. return 0;
  278. }
  279. }
  280. return -1;
  281. }
  282. static int test_manager()
  283. {
  284. size_t i, j;
  285. size_t outLen;
  286. const sigcomp_test_t* test;
  287. tcomp_manager_handle_t *client = tsk_null, *server = tsk_null;
  288. tcomp_result_t *result_client = tsk_null, *result_server = tsk_null;
  289. /* temporary buffers --> will hold compression/decompression results */
  290. char buff_client[MAX_BUFFER_SIZE];
  291. char buff_server[MAX_BUFFER_SIZE];
  292. /* Managers */
  293. client = tcomp_manager_create();
  294. server = tcomp_manager_create();
  295. /* Add SIP/Presence dictionnaries */
  296. tcomp_manager_addSipSdpDictionary(client);
  297. tcomp_manager_addPresenceDictionary(client);
  298. tcomp_manager_addSipSdpDictionary(server);
  299. tcomp_manager_addPresenceDictionary(server);
  300. /* Results --> it is recomanded to use one result struct for each manager */
  301. result_client = tcomp_result_create();
  302. result_server = tcomp_result_create();
  303. /* Sets compartment Ids */
  304. tcomp_result_setCompartmentId(result_client, COMPARTMENT_ID_CLIENT, strlen(COMPARTMENT_ID_CLIENT));
  305. tcomp_result_setCompartmentId(result_server, COMPARTMENT_ID_SERVER, strlen(COMPARTMENT_ID_SERVER));
  306. /* Set DMS and SMS */
  307. tcomp_manager_setDecompression_Memory_Size(client, SIGCOMP_DMS);
  308. tcomp_manager_setDecompression_Memory_Size(server, SIGCOMP_DMS);
  309. tcomp_manager_setCycles_Per_Bit(client, SIGCOMP_CPB);
  310. tcomp_manager_setCycles_Per_Bit(server, SIGCOMP_CPB);
  311. tcomp_manager_setState_Memory_Size(client, SIGCOMP_SMS);
  312. tcomp_manager_setState_Memory_Size(server, SIGCOMP_SMS);
  313. /* Set wehther to use only ACKed states (should be false) */
  314. tcomp_manager_setUseOnlyACKedStates(client, USE_ONLY_ACKED_STATES);
  315. tcomp_manager_setUseOnlyACKedStates(server, USE_ONLY_ACKED_STATES);
  316. tcomp_result_setOutputBuffer(result_client, buff_client, sizeof(buff_client), IS_STREAM, STREAM_ID);
  317. tcomp_result_setOutputBuffer(result_server, buff_server, sizeof(buff_server), IS_STREAM, STREAM_ID);
  318. for(j = 0; j < SIGCOMP_LOOP_COUNT; ++j) {
  319. for(i = 0; i < sizeof(SIGCOMP_TESTS)/sizeof(SIGCOMP_TESTS[0]); ++i) {
  320. test = &SIGCOMP_TESTS[i];
  321. // compress
  322. outLen = tcomp_manager_compress(
  323. test->is_client ? client : server,
  324. test->is_client ? COMPARTMENT_ID_CLIENT : COMPARTMENT_ID_SERVER,
  325. tsk_strlen((test->is_client ? COMPARTMENT_ID_CLIENT : COMPARTMENT_ID_SERVER)),
  326. test->msg,
  327. tsk_strlen(test->msg),
  328. test->is_client ? buff_client : buff_server,
  329. test->is_client ? sizeof(buff_client) : sizeof(buff_server),
  330. IS_STREAM);
  331. if(!outLen) {
  332. TSK_DEBUG_ERROR("Failed to compress %s message", test->description);
  333. goto bail;
  334. }
  335. TSK_DEBUG_INFO("==%s compression ratio = %f%%==", test->description, ((float)tsk_strlen(test->msg) / (float)outLen) * 100.f);
  336. // decompress
  337. if(!test->tobe_lost) {
  338. tsk_bool_t server_decompress = test->is_client; // decompress using server manager if compressed using client mgr
  339. memset(server_decompress ? buff_server : buff_client, '\0', server_decompress ? sizeof(buff_server) : sizeof(buff_client));
  340. outLen = tcomp_manager_decompress(server_decompress ? server : client, server_decompress ? buff_client : buff_server, outLen, server_decompress ? result_server : result_client);
  341. if(!outLen) {
  342. TSK_DEBUG_ERROR("Failed to decompress %s message", test->description);
  343. // pass NACK to remote peer (sendto())
  344. if(handle_nack(server_decompress ? result_server : result_client, server_decompress ? client : server) != 0) {
  345. goto bail;
  346. }
  347. }
  348. tcomp_manager_provideCompartmentId(server_decompress ? server : client, server_decompress ? result_server : result_client); // save states
  349. TSK_DEBUG_INFO("Decompressed message:\n%s = %s", test->description, server_decompress ? buff_server : buff_client);
  350. }
  351. }// for (i < count(SIGCOMP_TESTS))
  352. } // for (j < SIGCOMP_LOOP_COUNT)
  353. bail:
  354. // Close compartments
  355. tcomp_manager_closeCompartment(client, COMPARTMENT_ID_CLIENT, tsk_strlen(COMPARTMENT_ID_CLIENT));
  356. tcomp_manager_closeCompartment(server, COMPARTMENT_ID_SERVER, tsk_strlen(COMPARTMENT_ID_SERVER));
  357. // Delete Results
  358. TSK_OBJECT_SAFE_FREE(result_client);
  359. TSK_OBJECT_SAFE_FREE(result_server);
  360. // Delete managers
  361. TSK_OBJECT_SAFE_FREE(client);
  362. TSK_OBJECT_SAFE_FREE(server);
  363. return 0;
  364. }
  365. #endif /* TEST_TINYSIGCOMP_MANAGER_H */