check_session.c 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670
  1. /*
  2. * This file is part of the Sofia-SIP package
  3. *
  4. * Copyright (C) 2008 Nokia Corporation.
  5. *
  6. * Contact: Pekka Pessi <pekka.pessi@nokia.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public License
  10. * as published by the Free Software Foundation; either version 2.1 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. /**@CFILE check_session.c
  25. *
  26. * @brief NUA module tests for SIP session handling
  27. *
  28. * @author Pekka Pessi <Pekka.Pessi@nokia.com>
  29. *
  30. * @copyright (C) 2008 Nokia Corporation.
  31. */
  32. #include "config.h"
  33. #undef NDEBUG
  34. #include "check_nua.h"
  35. #include <sofia-sip/sip_status.h>
  36. #include <sofia-sip/sip_header.h>
  37. #include <sofia-sip/soa.h>
  38. #include <sofia-sip/su_tagarg.h>
  39. #include <sofia-sip/su_string.h>
  40. #include <sofia-sip/su_tag_io.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <assert.h>
  44. /* define XXX as 1 in order to see all failing test cases */
  45. #ifndef XXX
  46. #define XXX (0)
  47. #endif
  48. /* ====================================================================== */
  49. static nua_t *nua;
  50. static soa_session_t *soa = NULL;
  51. static struct dialog *dialog = NULL;
  52. #define CRLF "\r\n"
  53. static void call_setup(void)
  54. {
  55. nua = s2_nua_setup("call",
  56. SIPTAG_ORGANIZATION_STR("Pussy Galore's Flying Circus"),
  57. NUTAG_OUTBOUND("no-options-keepalive, no-validate"),
  58. TAG_END());
  59. soa = soa_create(NULL, s2base->root, NULL);
  60. fail_if(!soa);
  61. soa_set_params(soa,
  62. SOATAG_USER_SDP_STR("m=audio 5008 RTP/AVP 8 0" CRLF
  63. "m=video 5010 RTP/AVP 34" CRLF),
  64. TAG_END());
  65. dialog = su_home_new(sizeof *dialog); fail_if(!dialog);
  66. s2_register_setup();
  67. }
  68. static void call_thread_setup(void)
  69. {
  70. s2_nua_thread = 1;
  71. call_setup();
  72. }
  73. static void call_teardown(void)
  74. {
  75. s2_teardown_started("call");
  76. mark_point();
  77. s2_register_teardown();
  78. if (s2->shutdown == 0) {
  79. mark_point();
  80. nua_shutdown(nua);
  81. fail_unless_event(nua_r_shutdown, 200);
  82. }
  83. mark_point();
  84. s2_nua_teardown();
  85. }
  86. static void
  87. add_call_fixtures(TCase *tc, int threading)
  88. {
  89. if (threading)
  90. tcase_add_checked_fixture(tc, call_thread_setup, call_teardown);
  91. else
  92. tcase_add_checked_fixture(tc, call_setup, call_teardown);
  93. }
  94. static void save_sdp_to_soa(struct message *message)
  95. {
  96. sip_payload_t *pl;
  97. char const *body;
  98. isize_t bodylen;
  99. fail_if(!message);
  100. fail_if(!message->sip->sip_content_length);
  101. fail_if(!message->sip->sip_content_type);
  102. fail_if(strcmp(message->sip->sip_content_type->c_type,
  103. "application/sdp"));
  104. fail_if(!message->sip->sip_payload);
  105. pl = message->sip->sip_payload;
  106. body = pl->pl_data, bodylen = pl->pl_len;
  107. fail_if(soa_set_remote_sdp(soa, NULL, body, (issize_t)bodylen) < 0);
  108. }
  109. static void process_offer(struct message *message)
  110. {
  111. save_sdp_to_soa(message);
  112. fail_if(soa_generate_answer(soa, NULL) < 0);
  113. }
  114. static void process_answer(struct message *message)
  115. {
  116. save_sdp_to_soa(message);
  117. fail_if(soa_process_answer(soa, NULL) < 0);
  118. }
  119. static void
  120. respond_with_sdp(struct message *request,
  121. struct dialog *dialog,
  122. int status, char const *phrase,
  123. tag_type_t tag, tag_value_t value, ...)
  124. {
  125. ta_list ta;
  126. char const *body;
  127. isize_t bodylen;
  128. fail_if(soa_get_local_sdp(soa, NULL, &body, &bodylen) != 1);
  129. ta_start(ta, tag, value);
  130. s2_sip_respond_to(request, dialog, status, phrase,
  131. SIPTAG_CONTENT_TYPE_STR("application/sdp"),
  132. SIPTAG_PAYLOAD_STR(body),
  133. SIPTAG_CONTENT_DISPOSITION_STR("session"),
  134. ta_tags(ta));
  135. ta_end(ta);
  136. }
  137. static void
  138. request_with_sdp(struct dialog *dialog,
  139. sip_method_t method, char const *name,
  140. tport_t *tport,
  141. tag_type_t tag, tag_value_t value, ...)
  142. {
  143. ta_list ta;
  144. char const *body;
  145. isize_t bodylen;
  146. fail_if(soa_get_local_sdp(soa, NULL, &body, &bodylen) != 1);
  147. ta_start(ta, tag, value);
  148. fail_if(
  149. s2_sip_request_to(dialog, method, name, tport,
  150. SIPTAG_CONTENT_TYPE_STR("application/sdp"),
  151. SIPTAG_PAYLOAD_STR(body),
  152. ta_tags(ta)));
  153. ta_end(ta);
  154. }
  155. static struct message *
  156. invite_sent_by_nua(nua_handle_t *nh,
  157. tag_type_t tag, tag_value_t value, ...)
  158. {
  159. ta_list ta;
  160. ta_start(ta, tag, value);
  161. nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  162. ta_tags(ta));
  163. ta_end(ta);
  164. fail_unless(s2_check_callstate(nua_callstate_calling));
  165. return s2_sip_wait_for_request(SIP_METHOD_INVITE);
  166. }
  167. static uint32_t s2_rseq;
  168. static struct message *
  169. respond_with_100rel(struct message *invite,
  170. struct dialog *d,
  171. int with_sdp,
  172. int status, char const *phrase,
  173. tag_type_t tag, tag_value_t value, ...)
  174. {
  175. ta_list ta;
  176. sip_rseq_t rs[1];
  177. assert(100 < status && status < 200);
  178. sip_rseq_init(rs);
  179. rs->rs_response = ++s2_rseq;
  180. ta_start(ta, tag, value);
  181. if (with_sdp) {
  182. respond_with_sdp(
  183. invite, dialog, status, phrase,
  184. SIPTAG_REQUIRE_STR("100rel"),
  185. SIPTAG_RSEQ(rs),
  186. ta_tags(ta));
  187. }
  188. else {
  189. s2_sip_respond_to(
  190. invite, dialog, status, phrase,
  191. SIPTAG_REQUIRE_STR("100rel"),
  192. SIPTAG_RSEQ(rs),
  193. ta_tags(ta));
  194. }
  195. ta_end(ta);
  196. fail_unless_event(nua_r_invite, status);
  197. return s2_sip_wait_for_request(SIP_METHOD_PRACK);
  198. }
  199. static void
  200. invite_by_nua(nua_handle_t *nh,
  201. tag_type_t tag, tag_value_t value, ...)
  202. {
  203. struct message *invite;
  204. ta_list ta;
  205. ta_start(ta, tag, value);
  206. invite = invite_sent_by_nua(nh, ta_tags(ta));
  207. ta_end(ta);
  208. process_offer(invite);
  209. respond_with_sdp(
  210. invite, dialog, SIP_180_RINGING,
  211. SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
  212. TAG_END());
  213. fail_unless_event(nua_r_invite, 180);
  214. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  215. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  216. s2_sip_free_message(invite);
  217. fail_unless_event(nua_r_invite, 200);
  218. fail_unless(s2_check_callstate(nua_callstate_ready));
  219. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  220. }
  221. static nua_handle_t *
  222. invite_to_nua(tag_type_t tag, tag_value_t value, ...)
  223. {
  224. ta_list ta;
  225. struct event *invite;
  226. struct message *response;
  227. nua_handle_t *nh;
  228. soa_generate_offer(soa, 1, NULL);
  229. ta_start(ta, tag, value);
  230. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, ta_tags(ta));
  231. ta_end(ta);
  232. invite = s2_wait_for_event(nua_i_invite, 100); fail_unless(invite != NULL);
  233. fail_unless(s2_check_callstate(nua_callstate_received));
  234. nh = invite->nh;
  235. fail_if(!nh);
  236. s2_free_event(invite);
  237. response = s2_sip_wait_for_response(100, SIP_METHOD_INVITE);
  238. fail_if(!response);
  239. nua_respond(nh, SIP_180_RINGING,
  240. SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  241. TAG_END());
  242. fail_unless(s2_check_callstate(nua_callstate_early));
  243. response = s2_sip_wait_for_response(180, SIP_METHOD_INVITE);
  244. fail_if(!response);
  245. s2_sip_update_dialog(dialog, response);
  246. process_answer(response);
  247. s2_sip_free_message(response);
  248. nua_respond(nh, SIP_200_OK, TAG_END());
  249. fail_unless(s2_check_callstate(nua_callstate_completed));
  250. response = s2_sip_wait_for_response(200, SIP_METHOD_INVITE);
  251. fail_if(!response);
  252. s2_sip_update_dialog(dialog, response);
  253. s2_sip_free_message(response);
  254. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL, TAG_END()));
  255. fail_unless_event(nua_i_ack, 200);
  256. fail_unless(s2_check_callstate(nua_callstate_ready));
  257. return nh;
  258. }
  259. static void
  260. bye_by_nua(nua_handle_t *nh,
  261. tag_type_t tag, tag_value_t value, ...)
  262. {
  263. ta_list ta;
  264. struct message *bye;
  265. ta_start(ta, tag, value);
  266. nua_bye(nh, ta_tags(ta));
  267. ta_end(ta);
  268. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  269. fail_if(!bye);
  270. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  271. s2_sip_free_message(bye);
  272. fail_unless_event(nua_r_bye, 200);
  273. fail_unless(s2_check_callstate(nua_callstate_terminated));
  274. }
  275. static void
  276. bye_by_nua_challenged(nua_handle_t *nh,
  277. tag_type_t tag, tag_value_t value, ...)
  278. {
  279. ta_list ta;
  280. struct message *bye;
  281. s2_flush_events();
  282. ta_start(ta, tag, value);
  283. nua_bye(nh, ta_tags(ta));
  284. ta_end(ta);
  285. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  286. fail_if(!bye);
  287. s2_sip_respond_to(bye, dialog, SIP_407_PROXY_AUTH_REQUIRED,
  288. SIPTAG_PROXY_AUTHENTICATE_STR(s2_auth_digest_str),
  289. TAG_END());
  290. s2_sip_free_message(bye);
  291. fail_unless_event(nua_r_bye, 407);
  292. nua_authenticate(nh, NUTAG_AUTH("Digest:\"s2test\":abc:abc"), TAG_END());
  293. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  294. fail_if(!bye);
  295. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  296. s2_sip_free_message(bye);
  297. fail_unless_event(nua_r_bye, 200);
  298. fail_unless(s2_check_callstate(nua_callstate_terminated));
  299. fail_if(s2->events);
  300. }
  301. static void
  302. cancel_by_nua(nua_handle_t *nh,
  303. struct message *invite,
  304. struct dialog *dialog,
  305. tag_type_t tag, tag_value_t value, ...)
  306. {
  307. ta_list ta;
  308. struct message *cancel;
  309. ta_start(ta, tag, value);
  310. nua_cancel(nh, ta_tags(ta));
  311. ta_end(ta);
  312. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  313. fail_if(!cancel);
  314. s2_sip_respond_to(cancel, dialog, SIP_200_OK, TAG_END());
  315. s2_sip_free_message(cancel);
  316. fail_unless_event(nua_r_cancel, 200);
  317. s2_sip_respond_to(invite, dialog, SIP_487_REQUEST_CANCELLED, TAG_END());
  318. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  319. fail_unless_event(nua_r_invite, 487);
  320. }
  321. static void
  322. bye_to_nua(nua_handle_t *nh,
  323. tag_type_t tag, tag_value_t value, ...)
  324. {
  325. ta_list ta;
  326. ta_start(ta, tag, value);
  327. fail_if(s2_sip_request_to(dialog, SIP_METHOD_BYE, NULL, ta_tags(ta)));
  328. ta_end(ta);
  329. fail_unless_event(nua_i_bye, 200);
  330. fail_unless(s2_check_callstate(nua_callstate_terminated));
  331. fail_unless(s2_sip_check_response(200, SIP_METHOD_BYE));
  332. }
  333. /* ====================================================================== */
  334. /* 2 - Call cases */
  335. /* 2.1 - Basic call cases */
  336. START_TEST(call_2_1_1)
  337. {
  338. nua_handle_t *nh;
  339. S2_CASE("2.1.1", "Basic call",
  340. "NUA sends INVITE, NUA sends BYE");
  341. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  342. invite_by_nua(nh, TAG_END());
  343. bye_by_nua(nh, TAG_END());
  344. nua_handle_destroy(nh);
  345. }
  346. END_TEST
  347. START_TEST(call_2_1_2_1)
  348. {
  349. nua_handle_t *nh;
  350. S2_CASE("2.1.2.1", "Basic call",
  351. "NUA sends INVITE, NUA receives BYE");
  352. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  353. invite_by_nua(nh, TAG_END());
  354. bye_to_nua(nh, TAG_END());
  355. nua_handle_destroy(nh);
  356. }
  357. END_TEST
  358. START_TEST(call_2_1_2_2)
  359. {
  360. nua_handle_t *nh;
  361. S2_CASE("2.1.2.2", "Basic call over TCP",
  362. "NUA sends INVITE, NUA receives BYE");
  363. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor),
  364. TAG_END());
  365. invite_by_nua(nh,
  366. NUTAG_PROXY(s2sip->tcp.contact->m_url),
  367. TAG_END());
  368. bye_to_nua(nh, TAG_END());
  369. nua_handle_destroy(nh);
  370. }
  371. END_TEST
  372. START_TEST(call_2_1_3_1)
  373. {
  374. nua_handle_t *nh;
  375. S2_CASE("2.1.3.1", "Incoming call",
  376. "NUA receives INVITE and BYE");
  377. nh = invite_to_nua(TAG_END());
  378. bye_to_nua(nh, TAG_END());
  379. nua_handle_destroy(nh);
  380. }
  381. END_TEST
  382. START_TEST(call_2_1_3_2)
  383. {
  384. nua_handle_t *nh;
  385. S2_CASE("2.1.3.2", "Incoming call over TCP",
  386. "NUA receives INVITE and BYE");
  387. dialog->tport = s2sip->tcp.tport;
  388. nh = invite_to_nua(TAG_END());
  389. bye_to_nua(nh, TAG_END());
  390. nua_handle_destroy(nh);
  391. }
  392. END_TEST
  393. START_TEST(call_2_1_4)
  394. {
  395. nua_handle_t *nh;
  396. S2_CASE("2.1.4", "Incoming call",
  397. "NUA receives INVITE and sends BYE");
  398. nh = invite_to_nua(TAG_END());
  399. bye_by_nua(nh, TAG_END());
  400. nua_handle_destroy(nh);
  401. }
  402. END_TEST
  403. START_TEST(call_2_1_5)
  404. {
  405. nua_handle_t *nh;
  406. S2_CASE("2.1.5", "Incoming call",
  407. "NUA receives INVITE and sends BYE, BYE is challenged");
  408. nh = invite_to_nua(TAG_END());
  409. bye_by_nua_challenged(nh, TAG_END());
  410. nua_handle_destroy(nh);
  411. }
  412. END_TEST
  413. START_TEST(call_2_1_6)
  414. {
  415. nua_handle_t *nh;
  416. struct message *bye;
  417. struct event *invite;
  418. struct message *response;
  419. S2_CASE("2.1.6", "Basic call",
  420. "NUA received INVITE, "
  421. "NUA responds (and saves proxy for dialog), "
  422. "NUA sends BYE");
  423. soa_generate_offer(soa, 1, NULL);
  424. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());
  425. invite = s2_wait_for_event(nua_i_invite, 100); fail_unless(invite != NULL);
  426. fail_unless(s2_check_callstate(nua_callstate_received));
  427. nh = invite->nh;
  428. fail_if(!nh);
  429. s2_free_event(invite);
  430. response = s2_sip_wait_for_response(100, SIP_METHOD_INVITE);
  431. fail_if(!response);
  432. nua_respond(nh, SIP_180_RINGING,
  433. /* Dialog-specific proxy is saved */
  434. NUTAG_PROXY(s2sip->tcp.contact->m_url),
  435. SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  436. TAG_END());
  437. fail_unless(s2_check_callstate(nua_callstate_early));
  438. response = s2_sip_wait_for_response(180, SIP_METHOD_INVITE);
  439. fail_if(!response);
  440. s2_sip_update_dialog(dialog, response);
  441. process_answer(response);
  442. s2_sip_free_message(response);
  443. nua_respond(nh, SIP_200_OK, TAG_END());
  444. fail_unless(s2_check_callstate(nua_callstate_completed));
  445. response = s2_sip_wait_for_response(200, SIP_METHOD_INVITE);
  446. fail_if(!response);
  447. s2_sip_update_dialog(dialog, response);
  448. s2_sip_free_message(response);
  449. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL, TAG_END()));
  450. fail_unless_event(nua_i_ack, 200);
  451. fail_unless(s2_check_callstate(nua_callstate_ready));
  452. nua_bye(nh, TAG_END());
  453. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  454. fail_if(!bye);
  455. /* Check that NUA used dialog-specific proxy with BYE */
  456. fail_unless(tport_is_tcp(bye->tport));
  457. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  458. s2_sip_free_message(bye);
  459. fail_unless_event(nua_r_bye, 200);
  460. fail_unless(s2_check_callstate(nua_callstate_terminated));
  461. nua_handle_destroy(nh);
  462. }
  463. END_TEST
  464. START_TEST(call_2_1_7)
  465. {
  466. nua_handle_t *nh, *nh2;
  467. sip_replaces_t *replaces;
  468. S2_CASE("2.1.7", "Call lookup",
  469. "Test dialog and call-id lookup");
  470. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  471. invite_by_nua(nh, TAG_END());
  472. nh2 = nua_handle_by_call_id(nua, dialog->call_id->i_id);
  473. fail_if(!nh2); fail_if(nh != nh2); nua_handle_unref(nh2);
  474. replaces = sip_replaces_format(NULL, "%s;from-tag=%s;to-tag=%s",
  475. dialog->call_id->i_id,
  476. dialog->local->a_tag,
  477. dialog->remote->a_tag);
  478. fail_if(!replaces);
  479. nh2 = nua_handle_by_replaces(nua, replaces);
  480. fail_if(!nh2); fail_if(nh != nh2); nua_handle_unref(nh2);
  481. msg_header_free_all(NULL, (msg_header_t *)replaces);
  482. bye_by_nua(nh, TAG_END());
  483. nua_handle_destroy(nh);
  484. }
  485. END_TEST
  486. START_TEST(call_2_1_8)
  487. {
  488. nua_handle_t *nh;
  489. struct message *invite, *ack;
  490. S2_CASE("2.1.8", "Call using NUTAG_PROXY()",
  491. "Test handle-specific NUTAG_PROXY().");
  492. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  493. invite = invite_sent_by_nua(
  494. nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  495. NUTAG_PROXY(s2sip->tcp.contact->m_url), TAG_END());
  496. process_offer(invite);
  497. respond_with_sdp(
  498. invite, dialog, SIP_180_RINGING,
  499. SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
  500. TAG_END());
  501. fail_unless_event(nua_r_invite, 180);
  502. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  503. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  504. s2_sip_free_message(invite);
  505. fail_unless_event(nua_r_invite, 200);
  506. fail_unless(s2_check_callstate(nua_callstate_ready));
  507. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  508. fail_unless(ack && tport_is_tcp(ack->tport));
  509. bye_by_nua(nh, TAG_END());
  510. nua_handle_destroy(nh);
  511. }
  512. END_TEST
  513. TCase *invite_tcase(int threading)
  514. {
  515. TCase *tc = tcase_create("2.1 - Basic INVITE");
  516. add_call_fixtures(tc, threading);
  517. {
  518. tcase_add_test(tc, call_2_1_1);
  519. tcase_add_test(tc, call_2_1_2_1);
  520. tcase_add_test(tc, call_2_1_2_2);
  521. tcase_add_test(tc, call_2_1_3_1);
  522. tcase_add_test(tc, call_2_1_3_2);
  523. tcase_add_test(tc, call_2_1_4);
  524. tcase_add_test(tc, call_2_1_5);
  525. tcase_add_test(tc, call_2_1_6);
  526. tcase_add_test(tc, call_2_1_7);
  527. tcase_add_test(tc, call_2_1_8);
  528. }
  529. return tc;
  530. }
  531. /* ---------------------------------------------------------------------- */
  532. /* 2.2 - Call CANCEL cases */
  533. START_TEST(cancel_2_2_1)
  534. {
  535. nua_handle_t *nh;
  536. struct message *invite, *cancel;
  537. S2_CASE("2.2.1", "Cancel call",
  538. "NUA is caller, NUA sends CANCEL immediately");
  539. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  540. nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  541. TAG_END());
  542. fail_unless(s2_check_callstate(nua_callstate_calling));
  543. nua_cancel(nh, TAG_END());
  544. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  545. fail_if(!invite);
  546. fail_if(s2sip->received != NULL);
  547. s2_sip_respond_to(invite, dialog, SIP_100_TRYING, TAG_END());
  548. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  549. fail_if(!cancel);
  550. s2_sip_respond_to(invite, dialog, SIP_487_REQUEST_CANCELLED, TAG_END());
  551. s2_sip_respond_to(cancel, dialog, SIP_200_OK, TAG_END());
  552. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  553. fail_unless_event(nua_r_invite, 487);
  554. fail_unless(s2_check_callstate(nua_callstate_terminated));
  555. fail_unless_event(nua_r_cancel, 200);
  556. fail_if(s2->events != NULL);
  557. nua_handle_destroy(nh);
  558. }
  559. END_TEST
  560. START_TEST(cancel_2_2_2)
  561. {
  562. nua_handle_t *nh;
  563. struct message *invite;
  564. S2_CASE("2.2.2", "Canceled call",
  565. "NUA is caller, NUA sends CANCEL after receiving 100");
  566. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  567. nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  568. TAG_END());
  569. fail_unless(s2_check_callstate(nua_callstate_calling));
  570. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  571. process_offer(invite);
  572. s2_sip_respond_to(invite, dialog, SIP_100_TRYING, TAG_END());
  573. cancel_by_nua(nh, invite, dialog, TAG_END());
  574. fail_unless(s2_check_callstate(nua_callstate_terminated));
  575. nua_handle_destroy(nh);
  576. }
  577. END_TEST
  578. START_TEST(cancel_2_2_3)
  579. {
  580. nua_handle_t *nh;
  581. struct message *invite;
  582. S2_CASE("2.2.3", "Canceled call",
  583. "NUA is caller, NUA sends CANCEL after receiving 180");
  584. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  585. nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  586. TAG_END());
  587. fail_unless(s2_check_callstate(nua_callstate_calling));
  588. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  589. process_offer(invite);
  590. respond_with_sdp(
  591. invite, dialog, SIP_180_RINGING,
  592. SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
  593. TAG_END());
  594. fail_unless_event(nua_r_invite, 180);
  595. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  596. cancel_by_nua(nh, invite, dialog, TAG_END());
  597. fail_unless(s2_check_callstate(nua_callstate_terminated));
  598. nua_handle_destroy(nh);
  599. }
  600. END_TEST
  601. START_TEST(cancel_2_2_4)
  602. {
  603. nua_handle_t *nh;
  604. struct message *invite, *cancel;
  605. S2_CASE("2.2.4", "Cancel and 200 OK glare",
  606. "NUA is caller, NUA sends CANCEL after receiving 180 "
  607. "but UAS already sent 200 OK.");
  608. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  609. nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  610. TAG_END());
  611. fail_unless(s2_check_callstate(nua_callstate_calling));
  612. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  613. process_offer(invite);
  614. respond_with_sdp(
  615. invite, dialog, SIP_180_RINGING,
  616. SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
  617. TAG_END());
  618. fail_unless_event(nua_r_invite, 180);
  619. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  620. nua_cancel(nh, TAG_END());
  621. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  622. fail_if(!cancel);
  623. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  624. s2_sip_respond_to(cancel, dialog, SIP_481_NO_TRANSACTION, TAG_END());
  625. s2_sip_free_message(cancel);
  626. fail_unless_event(nua_r_cancel, 481);
  627. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  628. fail_unless(s2_check_callstate(nua_callstate_ready));
  629. bye_by_nua(nh, TAG_END());
  630. nua_handle_destroy(nh);
  631. }
  632. END_TEST
  633. START_TEST(cancel_2_2_5)
  634. {
  635. nua_handle_t *nh;
  636. struct message *invite, *cancel, *bye;
  637. S2_CASE(
  638. "2.2.5", "Cancel and 200 OK glare",
  639. "NUA is caller, "
  640. "NUA uses nua_bye() to send CANCEL after receiving 180\n"
  641. "but UAS already sent 200 OK.\n"
  642. "Test case checks that NUA really sends BYE after nua_bye() is called\n");
  643. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  644. nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  645. NUTAG_AUTOACK(0),
  646. TAG_END());
  647. fail_unless(s2_check_callstate(nua_callstate_calling));
  648. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  649. process_offer(invite);
  650. respond_with_sdp(
  651. invite, dialog, SIP_180_RINGING,
  652. SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
  653. TAG_END());
  654. fail_unless_event(nua_r_invite, 180);
  655. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  656. nua_bye(nh, TAG_END());
  657. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  658. fail_if(!cancel);
  659. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  660. s2_sip_respond_to(cancel, dialog, SIP_481_NO_TRANSACTION, TAG_END());
  661. s2_sip_free_message(cancel);
  662. fail_unless_event(nua_r_cancel, 481);
  663. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  664. fail_unless(s2_check_callstate(nua_callstate_terminating));
  665. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  666. fail_if(!bye);
  667. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  668. s2_sip_free_message(bye);
  669. fail_unless_event(nua_r_bye, 200);
  670. fail_unless(s2_check_callstate(nua_callstate_terminated));
  671. nua_handle_destroy(nh);
  672. }
  673. END_TEST
  674. START_TEST(cancel_2_2_6)
  675. {
  676. nua_handle_t *nh;
  677. struct event *invite;
  678. struct message *response;
  679. S2_CASE("2.2.6", "Cancel call",
  680. "NUA is callee, sends 100, 180, INVITE gets canceled");
  681. soa_generate_offer(soa, 1, NULL);
  682. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());
  683. invite = s2_wait_for_event(nua_i_invite, 100); fail_unless(invite != NULL);
  684. fail_unless(s2_check_callstate(nua_callstate_received));
  685. nh = invite->nh; fail_if(!nh);
  686. s2_free_event(invite);
  687. response = s2_sip_wait_for_response(100, SIP_METHOD_INVITE);
  688. fail_if(!response);
  689. nua_respond(nh, SIP_180_RINGING,
  690. SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  691. TAG_END());
  692. fail_unless(s2_check_callstate(nua_callstate_early));
  693. response = s2_sip_wait_for_response(180, SIP_METHOD_INVITE);
  694. fail_if(!response);
  695. s2_sip_update_dialog(dialog, response);
  696. process_answer(response);
  697. s2_sip_free_message(response);
  698. fail_if(s2_sip_request_to(dialog, SIP_METHOD_CANCEL, NULL, TAG_END()));
  699. fail_unless_event(nua_i_cancel, 200);
  700. fail_unless(s2_check_callstate(nua_callstate_terminated));
  701. response = s2_sip_wait_for_response(200, SIP_METHOD_CANCEL);
  702. fail_if(!response);
  703. s2_sip_free_message(response);
  704. response = s2_sip_wait_for_response(487, SIP_METHOD_INVITE);
  705. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL,
  706. SIPTAG_VIA(sip_object(dialog->invite)->sip_via),
  707. TAG_END()));
  708. nua_handle_destroy(nh);
  709. }
  710. END_TEST
  711. START_TEST(cancel_2_2_7)
  712. {
  713. nua_handle_t *nh;
  714. struct event *invite;
  715. struct message *response;
  716. char const *via = "SIP/2.0/UDP host.in.invalid;rport";
  717. S2_CASE("2.2.7", "Call gets canceled",
  718. "NUA is callee, sends 100, 180, INVITE gets canceled. "
  719. "Using RFC 2543 dialog and transaction matching.");
  720. soa_generate_offer(soa, 1, NULL);
  721. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL,
  722. SIPTAG_VIA_STR(via),
  723. TAG_END());
  724. invite = s2_wait_for_event(nua_i_invite, 100); fail_unless(invite != NULL);
  725. fail_unless(s2_check_callstate(nua_callstate_received));
  726. nh = invite->nh; fail_if(!nh);
  727. s2_free_event(invite);
  728. response = s2_sip_wait_for_response(100, SIP_METHOD_INVITE);
  729. fail_if(!response);
  730. nua_respond(nh, SIP_180_RINGING,
  731. SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  732. TAG_END());
  733. fail_unless(s2_check_callstate(nua_callstate_early));
  734. response = s2_sip_wait_for_response(180, SIP_METHOD_INVITE);
  735. fail_if(!response);
  736. s2_sip_update_dialog(dialog, response);
  737. process_answer(response);
  738. s2_sip_free_message(response);
  739. fail_if(s2_sip_request_to(dialog, SIP_METHOD_CANCEL, NULL, TAG_END()));
  740. fail_unless_event(nua_i_cancel, 200);
  741. fail_unless(s2_check_callstate(nua_callstate_terminated));
  742. response = s2_sip_wait_for_response(200, SIP_METHOD_CANCEL);
  743. fail_if(!response);
  744. s2_sip_free_message(response);
  745. response = s2_sip_wait_for_response(487, SIP_METHOD_INVITE);
  746. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL,
  747. SIPTAG_VIA(sip_object(dialog->invite)->sip_via),
  748. TAG_END()));
  749. nua_handle_destroy(nh);
  750. }
  751. END_TEST
  752. START_TEST(cancel_2_2_8)
  753. {
  754. nua_handle_t *nh;
  755. struct message *invite, *cancel;
  756. int timeout;
  757. S2_CASE("2.2.8", "CANCEL and INVITE times out",
  758. "NUA is caller, NUA sends CANCEL after receiving 180 "
  759. "but UAS never responds.");
  760. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  761. nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  762. TAG_END());
  763. fail_unless(s2_check_callstate(nua_callstate_calling));
  764. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  765. process_offer(invite);
  766. respond_with_sdp(
  767. invite, dialog, SIP_180_RINGING,
  768. SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
  769. TAG_END());
  770. fail_unless_event(nua_r_invite, 180);
  771. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  772. nua_cancel(nh, TAG_END());
  773. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  774. s2_sip_free_message(cancel);
  775. fail_if(!cancel);
  776. /* Now, time out both CANCEL and INVITE */
  777. for (timeout = 0; timeout < 34; timeout++) {
  778. s2_nua_fast_forward(1, s2base->root);
  779. cancel = s2_sip_next_request(SIP_METHOD_CANCEL);
  780. if (cancel)
  781. s2_sip_free_message(cancel);
  782. }
  783. fail_unless_event(nua_r_cancel, 408);
  784. fail_unless_event(nua_r_invite, 408);
  785. fail_unless(s2_check_callstate(nua_callstate_terminated));
  786. nua_handle_destroy(nh);
  787. }
  788. END_TEST
  789. START_TEST(cancel_2_2_9)
  790. {
  791. nua_handle_t *nh;
  792. struct message *invite, *cancel;
  793. int timeout;
  794. S2_CASE("2.2.9", "CANCEL a RFC2543 UA",
  795. "NUA is caller, NUA sends CANCEL after receiving 180, "
  796. "UAS sends 200 OK to CANCEL but no response to INVITE.");
  797. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  798. nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  799. TAG_END());
  800. fail_unless(s2_check_callstate(nua_callstate_calling));
  801. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  802. process_offer(invite);
  803. respond_with_sdp(
  804. invite, dialog, SIP_180_RINGING,
  805. SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
  806. TAG_END());
  807. fail_unless_event(nua_r_invite, 180);
  808. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  809. nua_cancel(nh, TAG_END());
  810. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  811. fail_if(!cancel);
  812. s2_sip_respond_to(cancel, dialog, SIP_200_OK, TAG_END());
  813. s2_sip_free_message(cancel);
  814. /* Time out INVITE */
  815. for (timeout = 0; timeout < 34; timeout++) {
  816. s2_nua_fast_forward(1, s2base->root);
  817. }
  818. fail_unless_event(nua_r_invite, 408);
  819. fail_unless(s2_check_callstate(nua_callstate_terminated));
  820. nua_handle_destroy(nh);
  821. }
  822. END_TEST
  823. START_TEST(cancel_2_2_10)
  824. {
  825. nua_handle_t *nh;
  826. struct message *invite, *cancel;
  827. struct event *event;
  828. int timeout;
  829. S2_CASE("2.2.10", "CANCEL and INVITE times out",
  830. "NUA is caller, NUA sends CANCEL after receiving 180 "
  831. "but UAS never responds.");
  832. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  833. nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  834. TAG_END());
  835. fail_unless(s2_check_callstate(nua_callstate_calling));
  836. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  837. process_offer(invite);
  838. respond_with_sdp(
  839. invite, dialog, SIP_180_RINGING,
  840. SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
  841. TAG_END());
  842. fail_unless_event(nua_r_invite, 180);
  843. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  844. nua_cancel(nh, TAG_END());
  845. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  846. s2_sip_free_message(cancel);
  847. fail_if(!cancel);
  848. nua_cancel(nh, TAG_END());
  849. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  850. fail_if(!cancel);
  851. s2_sip_respond_to(cancel, dialog, SIP_200_OK, TAG_END());
  852. s2_sip_free_message(cancel);
  853. /* emulate network gone bad below
  854. zap registration handle here
  855. so that s2_register_teardown() does not hang
  856. */
  857. s2->registration->nh = NULL;
  858. nua_set_params(s2->nua, NUTAG_SHUTDOWN_EVENTS(1), TAG_END());
  859. fail_unless_event(nua_r_set_params, 200);
  860. nua_shutdown(s2->nua);
  861. event = s2_wait_for_event(nua_r_shutdown, 100);
  862. fail_unless(event != NULL);
  863. s2_free_event(event);
  864. /* Time out */
  865. for (timeout = 0; timeout < 34; timeout++) {
  866. s2_nua_fast_forward(5, s2base->root);
  867. nua_shutdown(s2->nua);
  868. event = s2_wait_for_event(nua_r_shutdown, 0);
  869. fail_unless(event != NULL);
  870. if (event->data->e_status >= 200)
  871. break;
  872. }
  873. s2->shutdown = 200;
  874. }
  875. END_TEST
  876. TCase *cancel_tcase(int threading)
  877. {
  878. TCase *tc = tcase_create("2.2 - CANCEL");
  879. add_call_fixtures(tc, threading);
  880. tcase_add_test(tc, cancel_2_2_1);
  881. tcase_add_test(tc, cancel_2_2_2);
  882. tcase_add_test(tc, cancel_2_2_3);
  883. tcase_add_test(tc, cancel_2_2_4);
  884. if (XXX) tcase_add_test(tc, cancel_2_2_5);
  885. tcase_add_test(tc, cancel_2_2_6);
  886. tcase_add_test(tc, cancel_2_2_7);
  887. tcase_add_test(tc, cancel_2_2_8);
  888. tcase_add_test(tc, cancel_2_2_9);
  889. tcase_add_test(tc, cancel_2_2_10);
  890. return tc;
  891. }
  892. /* ---------------------------------------------------------------------- */
  893. /* 2.3 - Session timers */
  894. /* Wait for invite from NUA */
  895. static struct message *
  896. invite_timer_round(nua_handle_t *nh,
  897. char const *session_expires,
  898. sip_record_route_t *rr)
  899. {
  900. struct message *invite, *ack;
  901. fail_unless(s2_check_callstate(nua_callstate_calling));
  902. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  903. process_offer(invite);
  904. /* Check that INVITE contains Session-Expires header with refresher=uac */
  905. fail_unless(invite->sip->sip_session_expires != NULL);
  906. fail_unless(su_casematch(invite->sip->sip_session_expires->x_refresher, "uac"));
  907. respond_with_sdp(
  908. invite, dialog, SIP_200_OK,
  909. SIPTAG_SESSION_EXPIRES_STR(session_expires),
  910. SIPTAG_REQUIRE_STR("timer"),
  911. SIPTAG_RECORD_ROUTE(rr),
  912. TAG_END());
  913. s2_sip_free_message(invite);
  914. fail_unless_event(nua_r_invite, 200);
  915. fail_unless(s2_check_callstate(nua_callstate_ready));
  916. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  917. if (rr == NULL)
  918. s2_sip_free_message(ack);
  919. return ack;
  920. }
  921. START_TEST(call_2_3_1)
  922. {
  923. nua_handle_t *nh;
  924. sip_record_route_t rr[1];
  925. struct message *ack;
  926. sip_record_route_init(rr);
  927. *rr->r_url = *s2sip->contact->m_url;
  928. rr->r_url->url_user = "record";
  929. rr->r_url->url_params = "lr";
  930. S2_CASE("2.3.1", "Incoming call with call timers",
  931. "NUA receives INVITE, "
  932. "activates call timers, "
  933. "sends re-INVITE twice, "
  934. "sends BYE.");
  935. nh = invite_to_nua(
  936. SIPTAG_SESSION_EXPIRES_STR("300;refresher=uas"),
  937. SIPTAG_REQUIRE_STR("timer"),
  938. TAG_END());
  939. s2_nua_fast_forward(300, s2base->root);
  940. ack = invite_timer_round(nh, "300;refresher=uac", rr);
  941. fail_if(ack->sip->sip_route &&
  942. su_strmatch(ack->sip->sip_route->r_url->url_user, "record"));
  943. s2_nua_fast_forward(300, s2base->root);
  944. invite_timer_round(nh, "300;refresher=uac", NULL);
  945. bye_by_nua(nh, TAG_END());
  946. nua_handle_destroy(nh);
  947. }
  948. END_TEST
  949. START_TEST(call_2_3_2)
  950. {
  951. nua_handle_t *nh;
  952. S2_CASE("2.3.2", "Incoming call with call timers",
  953. "NUA receives INVITE, "
  954. "activates call timers, "
  955. "sends re-INVITE, "
  956. "sends BYE.");
  957. nh = invite_to_nua(
  958. SIPTAG_SESSION_EXPIRES_STR("300;refresher=uas"),
  959. SIPTAG_REQUIRE_STR("timer"),
  960. TAG_END());
  961. s2_nua_fast_forward(300, s2base->root);
  962. invite_timer_round(nh, "300;refresher=uac", NULL);
  963. s2_nua_fast_forward(300, s2base->root);
  964. invite_timer_round(nh, "300;refresher=uac", NULL);
  965. bye_by_nua(nh, TAG_END());
  966. nua_handle_destroy(nh);
  967. }
  968. END_TEST
  969. TCase *session_timer_tcase(int threading)
  970. {
  971. TCase *tc = tcase_create("2.3 - Session timers");
  972. add_call_fixtures(tc, threading);
  973. {
  974. tcase_add_test(tc, call_2_3_1);
  975. tcase_add_test(tc, call_2_3_2);
  976. }
  977. return tc;
  978. }
  979. /* ====================================================================== */
  980. /* 2.4 - 100rel */
  981. START_TEST(call_2_4_1)
  982. {
  983. nua_handle_t *nh;
  984. struct message *invite, *prack, *ack;
  985. int with_sdp;
  986. sip_record_route_t rr[1];
  987. S2_CASE("2.4.1", "Call with 100rel",
  988. "NUA sends INVITE, "
  989. "receives 183, sends PRACK, receives 200 for it, "
  990. "receives 180, sends PRACK, receives 200 for it, "
  991. "receives 200, send ACK.");
  992. sip_record_route_init(rr);
  993. *rr->r_url = *s2sip->contact->m_url;
  994. rr->r_url->url_user = "record";
  995. rr->r_url->url_params = "lr";
  996. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  997. invite = invite_sent_by_nua(
  998. nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  999. TAG_END());
  1000. process_offer(invite);
  1001. prack = respond_with_100rel(invite, dialog, with_sdp = 1,
  1002. SIP_183_SESSION_PROGRESS,
  1003. SIPTAG_RECORD_ROUTE(rr),
  1004. TAG_END());
  1005. s2_sip_respond_to(prack, dialog, SIP_200_OK, TAG_END());
  1006. s2_sip_free_message(prack), prack = NULL;
  1007. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1008. fail_unless_event(nua_r_prack, 200);
  1009. prack = respond_with_100rel(invite, dialog, with_sdp = 0,
  1010. SIP_180_RINGING,
  1011. TAG_END());
  1012. fail_unless(prack->sip->sip_route != NULL);
  1013. fail_unless(su_strmatch(prack->sip->sip_route->r_url->url_user, "record"));
  1014. s2_sip_respond_to(prack, dialog, SIP_200_OK, TAG_END());
  1015. s2_sip_free_message(prack), prack = NULL;
  1016. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1017. fail_unless_event(nua_r_prack, 200);
  1018. /* Change the record-route */
  1019. rr->r_url->url_user = "record2";
  1020. s2_sip_respond_to(invite, dialog, SIP_200_OK,
  1021. SIPTAG_RECORD_ROUTE(rr),
  1022. TAG_END());
  1023. s2_sip_free_message(invite);
  1024. fail_unless_event(nua_r_invite, 200);
  1025. fail_unless(s2_check_callstate(nua_callstate_ready));
  1026. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  1027. fail_if(!ack);
  1028. fail_unless(su_strmatch(ack->sip->sip_route->r_url->url_user, "record2"));
  1029. s2_sip_free_message(ack);
  1030. bye_to_nua(nh, TAG_END());
  1031. nua_handle_destroy(nh);
  1032. }
  1033. END_TEST
  1034. START_TEST(call_2_4_2)
  1035. {
  1036. nua_handle_t *nh;
  1037. struct message *invite, *prack;
  1038. int with_sdp;
  1039. S2_CASE("2.4.2", "Call with 100rel",
  1040. "NUA sends INVITE, "
  1041. "receives 183, sends PRACK, receives 200 for it, "
  1042. "receives 180, sends PRACK, receives 200 for it, "
  1043. "receives 200, send ACK.");
  1044. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  1045. invite = invite_sent_by_nua(
  1046. nh,
  1047. NUTAG_MEDIA_ENABLE(0),
  1048. SIPTAG_CONTENT_TYPE_STR("application/sdp"),
  1049. SIPTAG_PAYLOAD_STR(
  1050. "v=0" CRLF
  1051. "o=- 6805647540234172778 5821668777690722690 IN IP4 127.0.0.1" CRLF
  1052. "s=-" CRLF
  1053. "c=IN IP4 127.0.0.1" CRLF
  1054. "m=audio 5004 RTP/AVP 0 8" CRLF),
  1055. TAG_END());
  1056. prack = respond_with_100rel(invite, dialog, with_sdp = 0,
  1057. SIP_183_SESSION_PROGRESS,
  1058. TAG_END());
  1059. s2_sip_respond_to(prack, dialog, SIP_200_OK, TAG_END());
  1060. s2_sip_free_message(prack), prack = NULL;
  1061. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1062. fail_unless_event(nua_r_prack, 200);
  1063. prack = respond_with_100rel(invite, dialog, with_sdp = 0,
  1064. SIP_180_RINGING,
  1065. TAG_END());
  1066. s2_sip_respond_to(prack, dialog, SIP_200_OK, TAG_END());
  1067. s2_sip_free_message(prack), prack = NULL;
  1068. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1069. fail_unless_event(nua_r_prack, 200);
  1070. s2_sip_respond_to(invite, dialog, SIP_200_OK, TAG_END());
  1071. s2_sip_free_message(invite);
  1072. fail_unless_event(nua_r_invite, 200);
  1073. fail_unless(s2_check_callstate(nua_callstate_ready));
  1074. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  1075. bye_to_nua(nh, TAG_END());
  1076. nua_handle_destroy(nh);
  1077. }
  1078. END_TEST
  1079. START_TEST(call_2_4_3)
  1080. {
  1081. struct message *response;
  1082. S2_CASE("2.4.3", "Call without 100rel",
  1083. "NUA receives INVITE with Required: 100rel, "
  1084. "rejects it with 420");
  1085. nua_set_params(s2->nua,
  1086. SIPTAG_SUPPORTED(SIP_NONE),
  1087. SIPTAG_SUPPORTED_STR("timer"),
  1088. TAG_END());
  1089. fail_unless_event(nua_r_set_params, 200);
  1090. soa_generate_offer(soa, 1, NULL);
  1091. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL,
  1092. SIPTAG_REQUIRE_STR("100rel"),
  1093. TAG_END());
  1094. response = s2_sip_wait_for_response(420, SIP_METHOD_INVITE);
  1095. fail_if(!response);
  1096. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL, TAG_END()));
  1097. }
  1098. END_TEST
  1099. START_TEST(call_2_4_4)
  1100. {
  1101. nua_handle_t *nh;
  1102. struct event *invite;
  1103. struct message *response;
  1104. S2_CASE("2.4.3", "Call without 100rel",
  1105. "NUA receives INVITE with Supported: 100rel, "
  1106. "proceeds normally");
  1107. nua_set_params(s2->nua,
  1108. SIPTAG_SUPPORTED(SIP_NONE),
  1109. SIPTAG_SUPPORTED_STR("timer"),
  1110. TAG_END());
  1111. fail_unless_event(nua_r_set_params, 200);
  1112. soa_generate_offer(soa, 1, NULL);
  1113. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL,
  1114. SIPTAG_SUPPORTED_STR("100rel"),
  1115. TAG_END());
  1116. invite = s2_wait_for_event(nua_i_invite, 100); fail_unless(invite != NULL);
  1117. fail_unless(s2_check_callstate(nua_callstate_received));
  1118. nh = invite->nh; fail_if(!nh);
  1119. s2_free_event(invite);
  1120. response = s2_sip_wait_for_response(100, SIP_METHOD_INVITE);
  1121. fail_if(!response);
  1122. nua_respond(nh, SIP_183_SESSION_PROGRESS,
  1123. SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  1124. TAG_END());
  1125. fail_unless(s2_check_callstate(nua_callstate_early));
  1126. response = s2_sip_wait_for_response(183, SIP_METHOD_INVITE);
  1127. fail_if(!response);
  1128. fail_if(response->sip->sip_require);
  1129. s2_sip_update_dialog(dialog, response);
  1130. process_answer(response);
  1131. s2_sip_free_message(response);
  1132. nua_respond(nh, SIP_200_OK, TAG_END());
  1133. fail_unless(s2_check_callstate(nua_callstate_completed));
  1134. response = s2_sip_wait_for_response(200, SIP_METHOD_INVITE);
  1135. fail_if(!response);
  1136. s2_sip_update_dialog(dialog, response);
  1137. s2_sip_free_message(response);
  1138. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL, TAG_END()));
  1139. fail_unless_event(nua_i_ack, 200);
  1140. fail_unless(s2_check_callstate(nua_callstate_ready));
  1141. bye_to_nua(nh, TAG_END());
  1142. nua_handle_destroy(nh);
  1143. }
  1144. END_TEST
  1145. START_TEST(call_2_4_5)
  1146. {
  1147. nua_handle_t *nh;
  1148. struct message *invite, *prack, *cancel;
  1149. int i;
  1150. int with_sdp;
  1151. sip_from_t *branch1, *branch2;
  1152. /* Testcase for bug FSCORE-338 -
  1153. forked transactions getting canceled and terminated properly. */
  1154. S2_CASE("2.4.5", "Destroy proceeding call with 100rel",
  1155. "NUA sends INVITE, "
  1156. "receives 183, sends PRACK, receives 200 for it, "
  1157. "receives 180, sends PRACK, receives 200 for it, "
  1158. "handle is destroyed.");
  1159. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  1160. invite = invite_sent_by_nua(
  1161. nh,
  1162. NUTAG_PROXY(s2sip->tcp.contact->m_url),
  1163. NUTAG_MEDIA_ENABLE(0),
  1164. NUTAG_AUTOACK(0),
  1165. SIPTAG_CONTENT_TYPE_STR("application/sdp"),
  1166. SIPTAG_PAYLOAD_STR(
  1167. "v=0" CRLF
  1168. "o=- 6805647540234172778 5821668777690722690 IN IP4 127.0.0.1" CRLF
  1169. "s=-" CRLF
  1170. "c=IN IP4 127.0.0.1" CRLF
  1171. "m=audio 5004 RTP/AVP 0 8" CRLF),
  1172. TAG_END());
  1173. prack = respond_with_100rel(invite, dialog, with_sdp = 0,
  1174. SIP_183_SESSION_PROGRESS,
  1175. SIPTAG_CONTACT(s2sip->tcp.contact),
  1176. TAG_END());
  1177. s2_sip_respond_to(prack, dialog, SIP_200_OK, TAG_END());
  1178. s2_sip_free_message(prack), prack = NULL;
  1179. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1180. fail_unless_event(nua_r_prack, 200);
  1181. prack = respond_with_100rel(invite, dialog, with_sdp = 0,
  1182. SIP_180_RINGING,
  1183. SIPTAG_CONTACT(s2sip->tcp.contact),
  1184. TAG_END());
  1185. s2_sip_respond_to(prack, dialog, SIP_200_OK, TAG_END());
  1186. s2_sip_free_message(prack), prack = NULL;
  1187. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1188. fail_unless_event(nua_r_prack, 200);
  1189. branch1 = dialog->local;
  1190. branch2 = dialog->local = sip_from_dup(dialog->home, invite->sip->sip_to);
  1191. sip_from_tag(dialog->home, dialog->local, s2_sip_generate_tag(dialog->home));
  1192. nua_handle_destroy(nh), nh = NULL;
  1193. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  1194. s2_sip_respond_to(cancel, dialog, SIP_200_OK, TAG_END());
  1195. for (i = 1; i < 4; i++) {
  1196. s2_nua_fast_forward(1, s2base->root);
  1197. }
  1198. s2_sip_respond_to(invite, dialog, SIP_487_REQUEST_CANCELLED, TAG_END());
  1199. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  1200. /* Time out requests */
  1201. for (i = 1; i < 128; i++) {
  1202. s2_nua_fast_forward(1, s2base->root);
  1203. }
  1204. }
  1205. END_TEST
  1206. TCase *invite_100rel_tcase(int threading)
  1207. {
  1208. TCase *tc = tcase_create("2.4 - INVITE with 100rel");
  1209. add_call_fixtures(tc, threading);
  1210. {
  1211. tcase_add_test(tc, call_2_4_1);
  1212. tcase_add_test(tc, call_2_4_2);
  1213. tcase_add_test(tc, call_2_4_3);
  1214. tcase_add_test(tc, call_2_4_4);
  1215. tcase_add_test(tc, call_2_4_5);
  1216. }
  1217. return tc;
  1218. }
  1219. /* ====================================================================== */
  1220. /* 2.5 - Call with preconditions */
  1221. START_TEST(call_2_5_1)
  1222. {
  1223. nua_handle_t *nh;
  1224. struct message *invite, *prack, *update;
  1225. int with_sdp;
  1226. S2_CASE("2.5.1", "Call with preconditions",
  1227. "NUA sends INVITE, "
  1228. "receives 183, sends PRACK, receives 200 for it, "
  1229. "sends UPDATE, receives 200 for it, "
  1230. "receives 180, sends PRACK, receives 200 for it, "
  1231. "receives 200, send ACK.");
  1232. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  1233. invite = invite_sent_by_nua(
  1234. nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  1235. SIPTAG_REQUIRE_STR("precondition"),
  1236. TAG_END());
  1237. process_offer(invite);
  1238. prack = respond_with_100rel(invite, dialog, with_sdp = 1,
  1239. SIP_183_SESSION_PROGRESS,
  1240. TAG_END());
  1241. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1242. process_offer(prack);
  1243. respond_with_sdp(
  1244. prack, dialog, SIP_200_OK,
  1245. SIPTAG_REQUIRE_STR("100rel"),
  1246. TAG_END());
  1247. s2_sip_free_message(prack), prack = NULL;
  1248. fail_unless_event(nua_r_prack, 200);
  1249. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1250. update = s2_sip_wait_for_request(SIP_METHOD_UPDATE);
  1251. /* UPDATE sent by stack, stack sends event for it */
  1252. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1253. process_offer(update);
  1254. respond_with_sdp(
  1255. update, dialog, SIP_200_OK,
  1256. TAG_END());
  1257. s2_sip_free_message(update), update = NULL;
  1258. fail_unless_event(nua_r_update, 200);
  1259. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1260. prack = respond_with_100rel(invite, dialog, with_sdp = 0,
  1261. SIP_180_RINGING,
  1262. TAG_END());
  1263. s2_sip_respond_to(prack, dialog, SIP_200_OK, TAG_END());
  1264. s2_sip_free_message(prack), prack = NULL;
  1265. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1266. fail_unless_event(nua_r_prack, 200);
  1267. s2_sip_respond_to(invite, dialog, SIP_200_OK, TAG_END());
  1268. s2_sip_free_message(invite);
  1269. fail_unless_event(nua_r_invite, 200);
  1270. fail_unless(s2_check_callstate(nua_callstate_ready));
  1271. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  1272. bye_to_nua(nh, TAG_END());
  1273. nua_handle_destroy(nh);
  1274. }
  1275. END_TEST
  1276. START_TEST(call_2_5_2)
  1277. {
  1278. nua_handle_t *nh;
  1279. struct message *invite, *prack, *update;
  1280. sip_rseq_t rs[1];
  1281. sip_rack_t rack[1];
  1282. S2_CASE("2.5.2", "Call with preconditions - send 200 w/ ongoing PRACK ",
  1283. "NUA sends INVITE, "
  1284. "receives 183, sends PRACK, "
  1285. "receives 200 to INVITE, "
  1286. "receives 200 to PRACK, "
  1287. "sends ACK, "
  1288. "sends UPDATE, "
  1289. "receives 200 to UPDATE.");
  1290. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  1291. invite = invite_sent_by_nua(
  1292. nh,
  1293. SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  1294. SIPTAG_REQUIRE_STR("precondition"),
  1295. NUTAG_APPL_METHOD("PRACK"),
  1296. TAG_END());
  1297. process_offer(invite);
  1298. sip_rseq_init(rs)->rs_response = ++s2_rseq;
  1299. respond_with_sdp(
  1300. invite, dialog, SIP_183_SESSION_PROGRESS,
  1301. SIPTAG_REQUIRE_STR("100rel"),
  1302. SIPTAG_RSEQ(rs),
  1303. TAG_END());
  1304. fail_unless_event(nua_r_invite, 183);
  1305. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1306. sip_rack_init(rack)->ra_response = s2_rseq;
  1307. rack->ra_cseq = invite->sip->sip_cseq->cs_seq;
  1308. rack->ra_method = invite->sip->sip_cseq->cs_method;
  1309. rack->ra_method_name = invite->sip->sip_cseq->cs_method_name;
  1310. nua_prack(nh, SIPTAG_RACK(rack), TAG_END());
  1311. prack = s2_sip_wait_for_request(SIP_METHOD_PRACK);
  1312. process_offer(prack);
  1313. s2_sip_respond_to(invite, dialog, SIP_200_OK, TAG_END());
  1314. s2_sip_free_message(invite);
  1315. fail_unless_event(nua_r_invite, 200);
  1316. fail_unless(s2_check_callstate(nua_callstate_completing));
  1317. respond_with_sdp(
  1318. prack, dialog, SIP_200_OK,
  1319. TAG_END());
  1320. s2_sip_free_message(prack), prack = NULL;
  1321. fail_unless_event(nua_r_prack, 200);
  1322. fail_unless(s2_check_callstate(nua_callstate_ready));
  1323. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  1324. update = s2_sip_wait_for_request(SIP_METHOD_UPDATE);
  1325. /* UPDATE sent by stack, stack sends event for it */
  1326. fail_unless(s2_check_callstate(nua_callstate_calling));
  1327. process_offer(update);
  1328. respond_with_sdp(
  1329. update, dialog, SIP_200_OK,
  1330. TAG_END());
  1331. s2_sip_free_message(update), update = NULL;
  1332. fail_unless_event(nua_r_update, 200);
  1333. fail_unless(s2_check_callstate(nua_callstate_ready));
  1334. bye_to_nua(nh, TAG_END());
  1335. nua_handle_destroy(nh);
  1336. }
  1337. END_TEST
  1338. START_TEST(call_2_5_3)
  1339. {
  1340. nua_handle_t *nh;
  1341. struct message *invite, *prack, *update;
  1342. sip_rseq_t rs[1];
  1343. sip_rack_t rack[1];
  1344. S2_CASE("2.5.3", "Call with preconditions - send 200 w/ ongoing UPDATE ",
  1345. "NUA sends INVITE, "
  1346. "receives 183, sends PRACK, receives 200 to PRACK, "
  1347. "sends UPDATE, "
  1348. "receives 200 to INVITE, "
  1349. "receives 200 to UPDATE, "
  1350. "sends ACK.");
  1351. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  1352. invite = invite_sent_by_nua(
  1353. nh,
  1354. SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  1355. SIPTAG_REQUIRE_STR("precondition"),
  1356. NUTAG_APPL_METHOD("PRACK"),
  1357. TAG_END());
  1358. process_offer(invite);
  1359. sip_rseq_init(rs)->rs_response = ++s2_rseq;
  1360. respond_with_sdp(
  1361. invite, dialog, SIP_183_SESSION_PROGRESS,
  1362. SIPTAG_REQUIRE_STR("100rel"),
  1363. SIPTAG_RSEQ(rs),
  1364. TAG_END());
  1365. fail_unless_event(nua_r_invite, 183);
  1366. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1367. sip_rack_init(rack)->ra_response = s2_rseq;
  1368. rack->ra_cseq = invite->sip->sip_cseq->cs_seq;
  1369. rack->ra_method = invite->sip->sip_cseq->cs_method;
  1370. rack->ra_method_name = invite->sip->sip_cseq->cs_method_name;
  1371. nua_prack(nh, SIPTAG_RACK(rack), TAG_END());
  1372. prack = s2_sip_wait_for_request(SIP_METHOD_PRACK);
  1373. process_offer(prack);
  1374. respond_with_sdp(
  1375. prack, dialog, SIP_200_OK,
  1376. TAG_END());
  1377. s2_sip_free_message(prack), prack = NULL;
  1378. fail_unless_event(nua_r_prack, 200);
  1379. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1380. update = s2_sip_wait_for_request(SIP_METHOD_UPDATE);
  1381. /* UPDATE sent by stack, stack sends event for it */
  1382. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  1383. s2_sip_respond_to(invite, dialog, SIP_200_OK, TAG_END());
  1384. s2_sip_free_message(invite);
  1385. fail_unless_event(nua_r_invite, 200);
  1386. fail_unless(s2_check_callstate(nua_callstate_completing));
  1387. process_offer(update);
  1388. respond_with_sdp(
  1389. update, dialog, SIP_200_OK,
  1390. TAG_END());
  1391. s2_sip_free_message(update), update = NULL;
  1392. fail_unless_event(nua_r_update, 200);
  1393. fail_unless(s2_check_callstate(nua_callstate_ready));
  1394. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  1395. bye_to_nua(nh, TAG_END());
  1396. nua_handle_destroy(nh);
  1397. }
  1398. END_TEST
  1399. TCase *invite_precondition_tcase(int threading)
  1400. {
  1401. TCase *tc = tcase_create("2.5 - Call with preconditions");
  1402. add_call_fixtures(tc, threading);
  1403. {
  1404. tcase_add_test(tc, call_2_5_1);
  1405. tcase_add_test(tc, call_2_5_2);
  1406. tcase_add_test(tc, call_2_5_3);
  1407. }
  1408. return tc;
  1409. }
  1410. /* ====================================================================== */
  1411. /* 2.6 - Re-INVITEs */
  1412. START_TEST(call_2_6_1)
  1413. {
  1414. nua_handle_t *nh;
  1415. struct message *invite, *ack;
  1416. int i;
  1417. S2_CASE("2.6.1", "Queued re-INVITEs",
  1418. "NUA receives INVITE, "
  1419. "sends re-INVITE twice, "
  1420. "sends BYE.");
  1421. nh = invite_to_nua(TAG_END());
  1422. nua_invite(nh, TAG_END());
  1423. nua_invite(nh, TAG_END());
  1424. for (i = 0; i < 2; i++) {
  1425. fail_unless(s2_check_callstate(nua_callstate_calling));
  1426. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  1427. fail_if(!invite);
  1428. process_offer(invite);
  1429. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  1430. s2_sip_free_message(invite);
  1431. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  1432. fail_if(!ack);
  1433. s2_sip_free_message(ack);
  1434. fail_unless_event(nua_r_invite, 200);
  1435. fail_unless(s2_check_callstate(nua_callstate_ready));
  1436. }
  1437. bye_by_nua(nh, TAG_END());
  1438. nua_handle_destroy(nh);
  1439. }
  1440. END_TEST
  1441. START_TEST(call_2_6_2)
  1442. {
  1443. nua_handle_t *nh;
  1444. struct message *invite, *ack, *response;
  1445. S2_CASE("2.6.2", "Re-INVITE glare",
  1446. "NUA sends re-INVITE and then receives re-INVITE, "
  1447. "sends BYE.");
  1448. nh = invite_to_nua(TAG_END());
  1449. nua_invite(nh, TAG_END());
  1450. fail_unless(s2_check_callstate(nua_callstate_calling));
  1451. soa_generate_offer(soa, 1, NULL);
  1452. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());
  1453. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  1454. fail_if(!invite);
  1455. s2_sip_respond_to(invite, dialog, SIP_500_INTERNAL_SERVER_ERROR,
  1456. SIPTAG_RETRY_AFTER_STR("8"),
  1457. TAG_END());
  1458. s2_sip_free_message(invite);
  1459. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  1460. fail_if(!ack);
  1461. s2_sip_free_message(ack);
  1462. response = s2_sip_wait_for_response(491, SIP_METHOD_INVITE);
  1463. fail_if(!response);
  1464. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL,
  1465. SIPTAG_VIA(sip_object(dialog->invite)->sip_via),
  1466. TAG_END()));
  1467. s2_sip_free_message(response);
  1468. fail_if(soa_process_reject(soa, NULL) < 0);
  1469. /* We get nua_r_invite with 100 trying (and 500 in sip->sip_status) */
  1470. fail_unless_event(nua_r_invite, 100);
  1471. s2_nua_fast_forward(10, s2base->root);
  1472. fail_unless(s2_check_callstate(nua_callstate_calling));
  1473. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  1474. process_offer(invite);
  1475. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  1476. fail_unless_event(nua_r_invite, 200);
  1477. fail_unless(s2_check_callstate(nua_callstate_ready));
  1478. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  1479. fail_if(!ack);
  1480. s2_sip_free_message(ack);
  1481. bye_by_nua(nh, TAG_END());
  1482. nua_handle_destroy(nh);
  1483. }
  1484. END_TEST
  1485. START_TEST(call_2_6_3)
  1486. {
  1487. nua_handle_t *nh;
  1488. struct message *response;
  1489. S2_CASE("2.6.3", "Handling re-INVITE without SDP gracefully",
  1490. "NUA receives INVITE, "
  1491. "re-INVITE without SDP (w/o NUTAG_REFRESH_WITHOUT_SDP(), "
  1492. "re-INVITE without SDP (using NUTAG_REFRESH_WITHOUT_SDP(), "
  1493. "sends BYE.");
  1494. nh = invite_to_nua(
  1495. TAG_END());
  1496. s2_sip_request_to(dialog, SIP_METHOD_INVITE, NULL,
  1497. SIPTAG_USER_AGENT_STR("evil (evil) evil"),
  1498. TAG_END());
  1499. nua_respond(nh, SIP_200_OK, TAG_END());
  1500. fail_unless(s2_check_callstate(nua_callstate_completed));
  1501. response = s2_sip_wait_for_response(200, SIP_METHOD_INVITE);
  1502. fail_if(!response);
  1503. s2_sip_update_dialog(dialog, response);
  1504. fail_if(!response->sip->sip_content_type);
  1505. s2_sip_free_message(response);
  1506. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL, TAG_END()));
  1507. fail_unless_event(nua_i_ack, 200);
  1508. fail_unless(s2_check_callstate(nua_callstate_ready));
  1509. s2_nua_fast_forward(10, s2base->root);
  1510. nua_set_hparams(nh, NUTAG_REFRESH_WITHOUT_SDP(1), TAG_END());
  1511. fail_unless_event(nua_r_set_params, 200);
  1512. s2_sip_request_to(dialog, SIP_METHOD_INVITE, NULL,
  1513. SIPTAG_USER_AGENT_STR("evil (evil) evil"),
  1514. TAG_END());
  1515. nua_respond(nh, SIP_200_OK, TAG_END());
  1516. fail_unless(s2_check_callstate(nua_callstate_completed));
  1517. response = s2_sip_wait_for_response(200, SIP_METHOD_INVITE);
  1518. fail_if(!response);
  1519. s2_sip_update_dialog(dialog, response);
  1520. fail_if(response->sip->sip_content_type);
  1521. s2_sip_free_message(response);
  1522. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL, TAG_END()));
  1523. fail_unless_event(nua_i_ack, 200);
  1524. fail_unless(s2_check_callstate(nua_callstate_ready));
  1525. bye_by_nua(nh, TAG_END());
  1526. nua_handle_destroy(nh);
  1527. }
  1528. END_TEST
  1529. START_TEST(call_2_6_4)
  1530. {
  1531. nua_handle_t *nh;
  1532. struct message *invite, *ack;
  1533. S2_CASE("2.6.4", "re-INVITEs w/o SDP",
  1534. "NUA sends re-INVITE w/o SDP, "
  1535. "receives SDP w/ offer, "
  1536. "sends ACK w/ answer, "
  1537. "sends BYE.");
  1538. /* Bug reported by Liu Yang 2009-01-11 */
  1539. nh = invite_to_nua(TAG_END());
  1540. nua_invite(nh, SIPTAG_PAYLOAD_STR(""), TAG_END());
  1541. fail_unless(s2_check_callstate(nua_callstate_calling));
  1542. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  1543. fail_if(!invite);
  1544. fail_if(invite->sip->sip_content_type);
  1545. soa_generate_offer(soa, 1, NULL);
  1546. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  1547. s2_sip_free_message(invite);
  1548. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  1549. fail_if(!ack);
  1550. process_answer(ack);
  1551. s2_sip_free_message(ack);
  1552. fail_unless_event(nua_r_invite, 200);
  1553. fail_unless(s2_check_callstate(nua_callstate_ready));
  1554. bye_by_nua(nh, TAG_END());
  1555. nua_handle_destroy(nh);
  1556. }
  1557. END_TEST
  1558. START_TEST(call_2_6_5)
  1559. {
  1560. nua_handle_t *nh;
  1561. struct event *reinvite;
  1562. struct message *invite, *ack, *response;
  1563. /* Test case for FreeSwitch bugs #SFSIP-135, #SFSIP-137 */
  1564. S2_CASE("2.6.5", "Re-INVITE glare and 500 Retry-After",
  1565. "NUA receives re-INVITE, replies with 200, "
  1566. "sends re-INVITE, gets 500, gets ACK, retrys INVITE,"
  1567. "sends BYE.");
  1568. nh = invite_to_nua(TAG_END());
  1569. soa_generate_offer(soa, 1, NULL);
  1570. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());
  1571. reinvite = s2_wait_for_event(nua_i_invite, 200); fail_unless(reinvite != NULL);
  1572. fail_unless(s2_check_callstate(nua_callstate_completed));
  1573. response = s2_sip_wait_for_response(200, SIP_METHOD_INVITE);
  1574. fail_if(!response);
  1575. s2_sip_update_dialog(dialog, response);
  1576. process_answer(response);
  1577. s2_sip_free_message(response);
  1578. nua_invite(nh, TAG_END());
  1579. fail_unless(s2_check_callstate(nua_callstate_calling));
  1580. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  1581. fail_if(!invite);
  1582. s2_sip_respond_to(invite, dialog, SIP_500_INTERNAL_SERVER_ERROR,
  1583. SIPTAG_RETRY_AFTER_STR("7"),
  1584. TAG_END());
  1585. s2_sip_free_message(invite);
  1586. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  1587. fail_if(!ack);
  1588. s2_sip_free_message(ack);
  1589. /* We get nua_r_invite with 100 trying (and 500 in sip->sip_status) */
  1590. fail_unless_event(nua_r_invite, 100);
  1591. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL, TAG_END()));
  1592. fail_unless_event(nua_i_ack, 200);
  1593. fail_unless(s2_check_callstate(nua_callstate_ready));
  1594. s2_nua_fast_forward(10, s2base->root);
  1595. fail_unless(s2_check_callstate(nua_callstate_calling));
  1596. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  1597. process_offer(invite);
  1598. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  1599. fail_unless_event(nua_r_invite, 200);
  1600. fail_unless(s2_check_callstate(nua_callstate_ready));
  1601. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  1602. fail_if(!ack);
  1603. s2_sip_free_message(ack);
  1604. bye_by_nua(nh, TAG_END());
  1605. nua_handle_destroy(nh);
  1606. }
  1607. END_TEST
  1608. TCase *reinvite_tcase(int threading)
  1609. {
  1610. TCase *tc = tcase_create("2.6 - re-INVITEs");
  1611. add_call_fixtures(tc, threading);
  1612. {
  1613. tcase_add_test(tc, call_2_6_1);
  1614. tcase_add_test(tc, call_2_6_2);
  1615. tcase_add_test(tc, call_2_6_3);
  1616. tcase_add_test(tc, call_2_6_4);
  1617. tcase_add_test(tc, call_2_6_5);
  1618. }
  1619. return tc;
  1620. }
  1621. /* ====================================================================== */
  1622. /* 3.1 - Call error cases */
  1623. START_TEST(call_3_1_1)
  1624. {
  1625. nua_handle_t *nh;
  1626. struct message *invite, *ack;
  1627. S2_CASE("3.1.1", "Call failure", "Call fails with 403 response");
  1628. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor),
  1629. TAG_END());
  1630. nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  1631. TAG_END());
  1632. fail_unless(s2_check_callstate(nua_callstate_calling));
  1633. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  1634. fail_if(!invite);
  1635. s2_sip_respond_to(invite, NULL, SIP_403_FORBIDDEN,
  1636. SIPTAG_TO_STR("UAS Changed <sip:To@Header.field.invalid>"),
  1637. TAG_END());
  1638. s2_sip_free_message(invite);
  1639. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  1640. fail_if(!ack);
  1641. fail_if(strcmp(ack->sip->sip_to->a_display, "UAS Changed"));
  1642. s2_sip_free_message(ack);
  1643. fail_unless_event(nua_r_invite, 403);
  1644. fail_unless(s2_check_callstate(nua_callstate_terminated));
  1645. nua_handle_destroy(nh);
  1646. }
  1647. END_TEST
  1648. START_TEST(call_3_1_2)
  1649. {
  1650. nua_handle_t *nh;
  1651. struct message *invite;
  1652. int i;
  1653. S2_CASE("3.1.2", "Call fails after too many retries",
  1654. "Call fails after 4 times 500 Retry-After");
  1655. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor),
  1656. NUTAG_RETRY_COUNT(3),
  1657. TAG_END());
  1658. nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  1659. TAG_END());
  1660. for (i = 0;; i++) {
  1661. fail_unless(s2_check_callstate(nua_callstate_calling));
  1662. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  1663. fail_if(!invite);
  1664. s2_sip_respond_to(invite, NULL, SIP_500_INTERNAL_SERVER_ERROR,
  1665. SIPTAG_RETRY_AFTER_STR("5"),
  1666. TAG_END());
  1667. s2_sip_free_message(invite);
  1668. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  1669. if (i == 3)
  1670. break;
  1671. fail_unless_event(nua_r_invite, 100);
  1672. s2_nua_fast_forward(5, s2base->root);
  1673. }
  1674. fail_unless_event(nua_r_invite, 500);
  1675. fail_unless(s2_check_callstate(nua_callstate_terminated));
  1676. nua_handle_destroy(nh);
  1677. }
  1678. END_TEST
  1679. START_TEST(call_3_2_1)
  1680. {
  1681. nua_handle_t *nh;
  1682. struct message *invite;
  1683. S2_CASE("3.2.1", "Re-INVITE failure", "Re-INVITE fails with 403 response");
  1684. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor),
  1685. TAG_END());
  1686. invite_by_nua(nh, TAG_END());
  1687. nua_invite(nh, TAG_END());
  1688. fail_unless(s2_check_callstate(nua_callstate_calling));
  1689. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  1690. fail_if(!invite);
  1691. s2_sip_respond_to(invite, NULL, SIP_403_FORBIDDEN, TAG_END());
  1692. s2_sip_free_message(invite);
  1693. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  1694. fail_unless_event(nua_r_invite, 403);
  1695. /* Return to previous state */
  1696. fail_unless(s2_check_callstate(nua_callstate_ready));
  1697. bye_by_nua(nh, TAG_END());
  1698. }
  1699. END_TEST
  1700. START_TEST(call_3_2_2)
  1701. {
  1702. nua_handle_t *nh;
  1703. struct message *invite, *bye;
  1704. int i;
  1705. S2_CASE("3.2.2", "Re-INVITE fails after too many retries",
  1706. "Call fails after 4 times 500 Retry-After");
  1707. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor),
  1708. NUTAG_RETRY_COUNT(3),
  1709. TAG_END());
  1710. invite_by_nua(nh, TAG_END());
  1711. nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  1712. TAG_END());
  1713. for (i = 0;; i++) {
  1714. fail_unless(s2_check_callstate(nua_callstate_calling));
  1715. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  1716. fail_if(!invite);
  1717. s2_sip_respond_to(invite, NULL, SIP_500_INTERNAL_SERVER_ERROR,
  1718. SIPTAG_RETRY_AFTER_STR("5"),
  1719. TAG_END());
  1720. s2_sip_free_message(invite);
  1721. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  1722. if (i == 3)
  1723. break;
  1724. fail_unless_event(nua_r_invite, 100);
  1725. s2_nua_fast_forward(5, s2base->root);
  1726. }
  1727. fail_unless_event(nua_r_invite, 500);
  1728. /* Graceful termination */
  1729. fail_unless(s2_check_callstate(nua_callstate_terminating));
  1730. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  1731. fail_if(!bye);
  1732. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  1733. s2_sip_free_message(bye);
  1734. fail_unless_event(nua_r_bye, 200);
  1735. fail_unless(s2_check_callstate(nua_callstate_terminated));
  1736. nua_handle_destroy(nh);
  1737. }
  1738. END_TEST
  1739. START_TEST(call_3_2_3)
  1740. {
  1741. nua_handle_t *nh;
  1742. struct message *invite;
  1743. S2_CASE("3.2.3", "Re-INVITE failure", "Re-INVITE fails with 491 response");
  1744. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor),
  1745. TAG_END());
  1746. invite_by_nua(nh, TAG_END());
  1747. nua_invite(nh, TAG_END());
  1748. fail_unless(s2_check_callstate(nua_callstate_calling));
  1749. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  1750. fail_if(!invite);
  1751. s2_sip_respond_to(invite, NULL, SIP_491_REQUEST_PENDING, TAG_END());
  1752. s2_sip_free_message(invite);
  1753. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  1754. fail_unless_event(nua_r_invite, 491);
  1755. /* Return to previous state */
  1756. fail_unless(s2_check_callstate(nua_callstate_ready));
  1757. bye_by_nua(nh, TAG_END());
  1758. }
  1759. END_TEST
  1760. TCase *invite_error_tcase(int threading)
  1761. {
  1762. TCase *tc = tcase_create("3 - Call Errors");
  1763. add_call_fixtures(tc, threading);
  1764. {
  1765. tcase_add_test(tc, call_3_1_1);
  1766. tcase_add_test(tc, call_3_1_2);
  1767. tcase_add_test(tc, call_3_2_1);
  1768. tcase_add_test(tc, call_3_2_2);
  1769. tcase_add_test(tc, call_3_2_3);
  1770. tcase_set_timeout(tc, 5);
  1771. }
  1772. return tc;
  1773. }
  1774. /* ====================================================================== */
  1775. /* Weird call termination cases */
  1776. START_TEST(bye_4_1_1)
  1777. {
  1778. nua_handle_t *nh;
  1779. struct message *bye, *r481;
  1780. S2_CASE("4.1.1", "Re-INVITE while terminating",
  1781. "NUA sends BYE, "
  1782. "BYE is challenged, "
  1783. "and NUA is re-INVITEd at the same time.");
  1784. nh = invite_to_nua(TAG_END());
  1785. s2_flush_events();
  1786. nua_bye(nh, TAG_END());
  1787. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  1788. fail_if(!bye);
  1789. s2_sip_respond_to(bye, dialog, SIP_407_PROXY_AUTH_REQUIRED,
  1790. SIPTAG_PROXY_AUTHENTICATE_STR(s2_auth_digest_str),
  1791. TAG_END());
  1792. s2_sip_free_message(bye);
  1793. fail_unless_event(nua_r_bye, 407);
  1794. soa_generate_offer(soa, 1, NULL);
  1795. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());
  1796. do {
  1797. r481 = s2_sip_wait_for_response(0, SIP_METHOD_INVITE);
  1798. }
  1799. while (r481->sip->sip_status->st_status < 200);
  1800. s2_sip_update_dialog(dialog, r481); /* send ACK */
  1801. fail_unless(s2_check_callstate(nua_callstate_terminated));
  1802. nua_handle_destroy(nh);
  1803. }
  1804. END_TEST
  1805. START_TEST(bye_4_1_2)
  1806. {
  1807. nua_handle_t *nh;
  1808. struct message *bye, *r481;
  1809. S2_CASE("4.1.2", "Re-INVITE while terminating",
  1810. "NUA sends BYE, and gets re-INVITEd at same time");
  1811. nh = invite_to_nua(TAG_END());
  1812. s2_flush_events();
  1813. nua_bye(nh, TAG_END());
  1814. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  1815. fail_if(!bye);
  1816. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());
  1817. do {
  1818. r481 = s2_sip_wait_for_response(0, SIP_METHOD_INVITE);
  1819. }
  1820. while (r481->sip->sip_status->st_status < 200);
  1821. s2_sip_update_dialog(dialog, r481); /* send ACK */
  1822. fail_unless(s2_check_callstate(nua_callstate_terminated));
  1823. s2_sip_respond_to(bye, dialog, SIP_200_OK,
  1824. TAG_END());
  1825. s2_sip_free_message(bye);
  1826. fail_unless_event(nua_r_bye, 200);
  1827. nua_handle_destroy(nh);
  1828. }
  1829. END_TEST
  1830. START_TEST(bye_4_1_3)
  1831. {
  1832. nua_handle_t *nh;
  1833. struct message *bye;
  1834. struct event *i_bye;
  1835. S2_CASE("4.1.3", "BYE while terminating",
  1836. "NUA sends BYE and receives BYE");
  1837. nh = invite_to_nua(TAG_END());
  1838. mark_point();
  1839. nua_set_hparams(nh, NUTAG_APPL_METHOD("BYE"), TAG_END());
  1840. fail_unless_event(nua_r_set_params, 200);
  1841. s2_flush_events();
  1842. nua_bye(nh, TAG_END());
  1843. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  1844. fail_if(!bye);
  1845. s2_sip_request_to(dialog, SIP_METHOD_BYE, NULL, TAG_END());
  1846. i_bye = s2_wait_for_event(nua_i_bye, 100);
  1847. fail_if(!i_bye);
  1848. nua_respond(nh, 200, "OKOK", NUTAG_WITH(i_bye->data->e_msg), TAG_END());
  1849. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  1850. s2_sip_free_message(bye);
  1851. fail_unless_event(nua_r_bye, 200);
  1852. fail_unless(s2_check_callstate(nua_callstate_terminated));
  1853. fail_unless(s2_sip_check_response(200, SIP_METHOD_BYE));
  1854. nua_handle_destroy(nh);
  1855. }
  1856. END_TEST
  1857. START_TEST(bye_4_1_4)
  1858. {
  1859. nua_handle_t *nh;
  1860. struct message *bye;
  1861. struct event *i_bye;
  1862. S2_CASE("4.1.4", "Send BYE after BYE has been received",
  1863. "NUA receives BYE, tries to send BYE at same time");
  1864. nh = invite_to_nua(TAG_END());
  1865. mark_point();
  1866. nua_set_hparams(nh, NUTAG_APPL_METHOD("BYE"), TAG_END());
  1867. fail_unless_event(nua_r_set_params, 200);
  1868. s2_flush_events();
  1869. s2_sip_request_to(dialog, SIP_METHOD_BYE, NULL, TAG_END());
  1870. i_bye = s2_wait_for_event(nua_i_bye, 100);
  1871. fail_if(!i_bye);
  1872. nua_bye(nh, TAG_END());
  1873. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  1874. fail_if(!bye);
  1875. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  1876. s2_sip_free_message(bye);
  1877. fail_unless_event(nua_r_bye, 200);
  1878. fail_unless(s2_check_callstate(nua_callstate_terminated));
  1879. nua_respond(nh, 200, "OKOK", NUTAG_WITH(i_bye->data->e_msg), TAG_END());
  1880. fail_unless(s2_sip_check_response(200, SIP_METHOD_BYE));
  1881. nua_handle_destroy(nh);
  1882. }
  1883. END_TEST
  1884. START_TEST(bye_4_1_5)
  1885. {
  1886. nua_handle_t *nh;
  1887. struct message *bye;
  1888. struct event *i_bye;
  1889. S2_CASE("4.1.5", "Send BYE after BYE has been received",
  1890. "NUA receives BYE, tries to send BYE at same time");
  1891. nh = invite_to_nua(TAG_END());
  1892. mark_point();
  1893. nua_set_hparams(nh, NUTAG_APPL_METHOD("BYE"), TAG_END());
  1894. fail_unless_event(nua_r_set_params, 200);
  1895. s2_flush_events();
  1896. s2_sip_request_to(dialog, SIP_METHOD_BYE, NULL, TAG_END());
  1897. i_bye = s2_wait_for_event(nua_i_bye, 100);
  1898. fail_if(!i_bye);
  1899. nua_bye(nh, TAG_END());
  1900. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  1901. fail_if(!bye);
  1902. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  1903. s2_sip_free_message(bye);
  1904. fail_unless_event(nua_r_bye, 200);
  1905. fail_unless(s2_check_callstate(nua_callstate_terminated));
  1906. nua_handle_destroy(nh);
  1907. fail_unless(s2_sip_check_response(200, SIP_METHOD_BYE));
  1908. }
  1909. END_TEST
  1910. START_TEST(bye_4_1_6)
  1911. {
  1912. nua_handle_t *nh;
  1913. struct message *bye, *r486;
  1914. S2_CASE("4.1.6", "Send BYE after INVITE has been received",
  1915. "NUA receives INVITE, sends BYE at same time");
  1916. nh = invite_to_nua(TAG_END());
  1917. nua_set_hparams(nh, NUTAG_AUTOANSWER(0), TAG_END());
  1918. fail_unless_event(nua_r_set_params, 200);
  1919. s2_flush_events();
  1920. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());
  1921. fail_unless(s2_sip_check_response(100, SIP_METHOD_INVITE));
  1922. nua_bye(nh, TAG_END());
  1923. fail_unless_event(nua_i_invite, 100);
  1924. fail_unless(s2_check_callstate(nua_callstate_received));
  1925. do {
  1926. r486 = s2_sip_wait_for_response(0, SIP_METHOD_INVITE);
  1927. }
  1928. while (r486->sip->sip_status->st_status < 200);
  1929. s2_sip_update_dialog(dialog, r486); /* send ACK */
  1930. fail_unless(r486->sip->sip_status->st_status == 486);
  1931. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  1932. fail_if(!bye);
  1933. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  1934. s2_sip_free_message(bye);
  1935. nua_handle_destroy(nh);
  1936. }
  1937. END_TEST
  1938. START_TEST(bye_4_1_7)
  1939. {
  1940. nua_handle_t *nh;
  1941. struct message *bye, *r486;
  1942. S2_CASE("4.1.7", "Send BYE after INVITE has been received",
  1943. "NUA receives INVITE, sends BYE at same time");
  1944. nh = invite_to_nua(TAG_END());
  1945. nua_set_hparams(nh, NUTAG_AUTOANSWER(0), TAG_END());
  1946. fail_unless_event(nua_r_set_params, 200);
  1947. s2_flush_events();
  1948. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());
  1949. fail_unless(s2_sip_check_response(100, SIP_METHOD_INVITE));
  1950. nua_bye(nh, TAG_END());
  1951. fail_unless_event(nua_i_invite, 100);
  1952. fail_unless(s2_check_callstate(nua_callstate_received));
  1953. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  1954. fail_if(!bye);
  1955. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  1956. s2_sip_free_message(bye);
  1957. do {
  1958. r486 = s2_sip_wait_for_response(0, SIP_METHOD_INVITE);
  1959. }
  1960. while (r486->sip->sip_status->st_status < 200);
  1961. s2_sip_update_dialog(dialog, r486); /* send ACK */
  1962. fail_unless(r486->sip->sip_status->st_status == 486);
  1963. nua_handle_destroy(nh);
  1964. }
  1965. END_TEST
  1966. START_TEST(bye_4_1_8)
  1967. {
  1968. nua_handle_t *nh;
  1969. struct message *bye, *r486;
  1970. S2_CASE("4.1.8", "BYE followed by response to INVITE",
  1971. "NUA receives INVITE, sends BYE at same time");
  1972. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  1973. invite_by_nua(nh, NUTAG_AUTOANSWER(0), TAG_END());
  1974. s2_flush_events();
  1975. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());
  1976. fail_unless(s2_sip_check_response(100, SIP_METHOD_INVITE));
  1977. nua_bye(nh, TAG_END());
  1978. fail_unless_event(nua_i_invite, 100);
  1979. fail_unless(s2_check_callstate(nua_callstate_received));
  1980. nua_respond(nh, SIP_486_BUSY_HERE, TAG_END());
  1981. do {
  1982. r486 = s2_sip_wait_for_response(0, SIP_METHOD_INVITE);
  1983. }
  1984. while (r486->sip->sip_status->st_status < 200);
  1985. s2_sip_update_dialog(dialog, r486); /* send ACK */
  1986. fail_unless(r486->sip->sip_status->st_status == 486);
  1987. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  1988. fail_if(!bye);
  1989. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  1990. s2_sip_free_message(bye);
  1991. nua_handle_destroy(nh);
  1992. }
  1993. END_TEST
  1994. START_TEST(bye_4_1_9)
  1995. {
  1996. nua_handle_t *nh;
  1997. struct message *bye;
  1998. struct event *i_bye;
  1999. S2_CASE("4.1.6", "Send BYE, receive BYE, destroy",
  2000. "NUA sends BYE, receives BYE and handle gets destroyed");
  2001. nh = invite_to_nua(TAG_END());
  2002. mark_point();
  2003. s2_flush_events();
  2004. nua_bye(nh, TAG_END());
  2005. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  2006. fail_if(!bye);
  2007. s2_sip_request_to(dialog, SIP_METHOD_BYE, NULL, TAG_END());
  2008. i_bye = s2_wait_for_event(nua_i_bye, 200);
  2009. fail_if(!i_bye);
  2010. s2_free_event(i_bye), i_bye = NULL;
  2011. fail_unless(s2_check_callstate(nua_callstate_terminated));
  2012. fail_unless(s2_sip_check_response(200, SIP_METHOD_BYE));
  2013. nua_handle_destroy(nh);
  2014. mark_point();
  2015. su_root_step(s2base->root, 10);
  2016. su_root_step(s2base->root, 10);
  2017. su_root_step(s2base->root, 10);
  2018. mark_point();
  2019. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  2020. s2_sip_free_message(bye);
  2021. mark_point();
  2022. while (su_home_check_alloc((su_home_t *)nua, (void *)nh)) {
  2023. su_root_step(s2base->root, 10);
  2024. }
  2025. }
  2026. END_TEST
  2027. START_TEST(bye_4_1_10)
  2028. {
  2029. nua_handle_t *nh;
  2030. struct message *invite, *bye;
  2031. struct event *i_bye;
  2032. S2_CASE("4.1.6", "Send auto-BYE upon receiving 501, receive BYE, destroy",
  2033. "NUA sends BYE, receives BYE and handle gets destroyed");
  2034. nh = invite_to_nua(TAG_END());
  2035. mark_point();
  2036. s2_flush_events();
  2037. nua_invite(nh, TAG_END());
  2038. invite = s2_sip_wait_for_request(SIP_METHOD_INVITE);
  2039. fail_if(!invite);
  2040. s2_sip_respond_to(invite, dialog, SIP_501_NOT_IMPLEMENTED, TAG_END());
  2041. s2_sip_free_message(invite);
  2042. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  2043. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  2044. fail_if(!bye);
  2045. fail_unless(s2_check_callstate(nua_callstate_calling));
  2046. fail_unless_event(nua_r_invite, 501);
  2047. fail_unless(s2_check_callstate(nua_callstate_terminating));
  2048. s2_sip_request_to(dialog, SIP_METHOD_BYE, NULL, TAG_END());
  2049. i_bye = s2_wait_for_event(nua_i_bye, 200);
  2050. fail_if(!i_bye);
  2051. s2_free_event(i_bye), i_bye = NULL;
  2052. fail_unless(s2_check_callstate(nua_callstate_terminated));
  2053. fail_unless(s2_sip_check_response(200, SIP_METHOD_BYE));
  2054. nua_handle_destroy(nh);
  2055. su_root_step(s2base->root, 10);
  2056. su_root_step(s2base->root, 10);
  2057. su_root_step(s2base->root, 10);
  2058. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  2059. s2_sip_free_message(bye);
  2060. while (su_home_check_alloc((su_home_t *)nua, (void *)nh)) {
  2061. su_root_step(s2base->root, 10);
  2062. }
  2063. }
  2064. END_TEST
  2065. START_TEST(bye_4_1_11)
  2066. {
  2067. nua_handle_t *nh;
  2068. struct message *invite, *ack;
  2069. struct event *i_bye;
  2070. S2_CASE("4.1.11", "Receive BYE in completing state",
  2071. "NUA sends INVITE, receives 200, receives BYE.");
  2072. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  2073. invite = invite_sent_by_nua(nh, NUTAG_AUTOACK(0), TAG_END());
  2074. process_offer(invite);
  2075. s2_sip_respond_to(invite, dialog, SIP_180_RINGING, TAG_END());
  2076. fail_unless_event(nua_r_invite, 180);
  2077. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  2078. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  2079. s2_sip_free_message(invite);
  2080. fail_unless_event(nua_r_invite, 200);
  2081. fail_unless(s2_check_callstate(nua_callstate_completing));
  2082. s2_sip_request_to(dialog, SIP_METHOD_BYE, NULL, TAG_END());
  2083. i_bye = s2_wait_for_event(nua_i_bye, 200);
  2084. fail_if(!i_bye);
  2085. s2_free_event(i_bye), i_bye = NULL;
  2086. fail_unless(s2_check_callstate(nua_callstate_terminated));
  2087. fail_unless(s2_sip_check_response(200, SIP_METHOD_BYE));
  2088. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  2089. fail_if(!ack);
  2090. s2_sip_free_message(ack);
  2091. nua_handle_destroy(nh);
  2092. }
  2093. END_TEST
  2094. START_TEST(bye_4_2_1)
  2095. {
  2096. nua_handle_t *nh;
  2097. struct message *bye;
  2098. S2_CASE("4.2.1", "BYE in progress while call timer expires",
  2099. "NUA receives INVITE, "
  2100. "activates call timers, "
  2101. "sends BYE, BYE challenged, "
  2102. "waits until session expires.");
  2103. nh = invite_to_nua(
  2104. SIPTAG_SESSION_EXPIRES_STR("300;refresher=uas"),
  2105. SIPTAG_REQUIRE_STR("timer"),
  2106. TAG_END());
  2107. s2_nua_fast_forward(300, s2base->root);
  2108. invite_timer_round(nh, "300", NULL);
  2109. nua_bye(nh, TAG_END());
  2110. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  2111. fail_if(!bye);
  2112. s2_sip_respond_to(bye, dialog, SIP_407_PROXY_AUTH_REQUIRED,
  2113. SIPTAG_PROXY_AUTHENTICATE_STR(s2_auth_digest_str),
  2114. TAG_END());
  2115. s2_sip_free_message(bye);
  2116. fail_unless_event(nua_r_bye, 407);
  2117. s2_nua_fast_forward(300, s2base->root);
  2118. nua_authenticate(nh, NUTAG_AUTH("Digest:\"s2test\":abc:abc"), TAG_END());
  2119. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  2120. fail_if(!bye);
  2121. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  2122. s2_sip_free_message(bye);
  2123. fail_unless_event(nua_r_bye, 200);
  2124. fail_unless(s2_check_callstate(nua_callstate_terminated));
  2125. fail_if(s2->events);
  2126. nua_handle_destroy(nh);
  2127. }
  2128. END_TEST
  2129. START_TEST(bye_4_2_2)
  2130. {
  2131. nua_handle_t *nh;
  2132. struct message *bye;
  2133. S2_CASE("4.2.2", "BYE in progress while call timer expires",
  2134. "NUA receives INVITE, "
  2135. "activates call timers, "
  2136. "sends BYE, BYE challenged, "
  2137. "waits until session expires.");
  2138. nh = invite_to_nua(
  2139. SIPTAG_SESSION_EXPIRES_STR("300;refresher=uas"),
  2140. SIPTAG_REQUIRE_STR("timer"),
  2141. TAG_END());
  2142. s2_nua_fast_forward(300, s2base->root);
  2143. invite_timer_round(nh, "300", NULL);
  2144. s2_nua_fast_forward(140, s2base->root);
  2145. nua_bye(nh, TAG_END());
  2146. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  2147. fail_if(!bye);
  2148. s2_sip_respond_to(bye, dialog, SIP_407_PROXY_AUTH_REQUIRED,
  2149. SIPTAG_PROXY_AUTHENTICATE_STR(s2_auth_digest_str),
  2150. TAG_END());
  2151. s2_sip_free_message(bye);
  2152. fail_unless_event(nua_r_bye, 407);
  2153. s2_nua_fast_forward(160, s2base->root);
  2154. nua_authenticate(nh, NUTAG_AUTH(s2_auth_credentials), TAG_END());
  2155. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  2156. fail_if(!bye);
  2157. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  2158. s2_sip_free_message(bye);
  2159. fail_unless_event(nua_r_bye, 200);
  2160. fail_unless(s2_check_callstate(nua_callstate_terminated));
  2161. fail_if(s2->events);
  2162. nua_handle_destroy(nh);
  2163. }
  2164. END_TEST
  2165. TCase *termination_tcase(int threading)
  2166. {
  2167. TCase *tc = tcase_create("4 - Call Termination");
  2168. add_call_fixtures(tc, threading);
  2169. {
  2170. tcase_add_test(tc, bye_4_1_1);
  2171. tcase_add_test(tc, bye_4_1_2);
  2172. tcase_add_test(tc, bye_4_1_3);
  2173. tcase_add_test(tc, bye_4_1_4);
  2174. tcase_add_test(tc, bye_4_1_5);
  2175. tcase_add_test(tc, bye_4_1_6);
  2176. tcase_add_test(tc, bye_4_1_7);
  2177. tcase_add_test(tc, bye_4_1_8);
  2178. tcase_add_test(tc, bye_4_1_9);
  2179. tcase_add_test(tc, bye_4_1_10);
  2180. tcase_add_test(tc, bye_4_1_11);
  2181. tcase_add_test(tc, bye_4_2_1);
  2182. tcase_add_test(tc, bye_4_2_2);
  2183. tcase_set_timeout(tc, 5);
  2184. }
  2185. return tc;
  2186. }
  2187. /* ====================================================================== */
  2188. START_TEST(destroy_4_3_1)
  2189. {
  2190. nua_handle_t *nh;
  2191. struct message *invite, *cancel;
  2192. S2_CASE("4.3.1", "Destroy handle after INVITE sent",
  2193. "NUA sends INVITE, handle gets destroyed.");
  2194. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  2195. invite = invite_sent_by_nua(nh, TAG_END());
  2196. process_offer(invite);
  2197. nua_handle_destroy(nh);
  2198. s2_sip_respond_to(invite, dialog, SIP_100_TRYING, TAG_END());
  2199. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  2200. fail_if(!cancel);
  2201. s2_sip_respond_to(invite, dialog, SIP_487_REQUEST_CANCELLED, TAG_END());
  2202. s2_sip_free_message(invite);
  2203. s2_sip_respond_to(cancel, dialog, SIP_200_OK, TAG_END());
  2204. s2_sip_free_message(cancel);
  2205. }
  2206. END_TEST
  2207. START_TEST(destroy_4_3_2)
  2208. {
  2209. nua_handle_t *nh;
  2210. struct message *invite, *cancel;
  2211. S2_CASE("4.3.2", "Destroy handle in calling state",
  2212. "NUA sends INVITE, receives 180, handle gets destroyed.");
  2213. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  2214. invite = invite_sent_by_nua(nh, TAG_END());
  2215. process_offer(invite);
  2216. s2_sip_respond_to(invite, dialog, SIP_180_RINGING, TAG_END());
  2217. fail_unless_event(nua_r_invite, 180);
  2218. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  2219. nua_handle_destroy(nh);
  2220. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  2221. fail_if(!cancel);
  2222. s2_sip_respond_to(invite, dialog, SIP_487_REQUEST_CANCELLED, TAG_END());
  2223. s2_sip_free_message(invite);
  2224. s2_sip_respond_to(cancel, dialog, SIP_200_OK, TAG_END());
  2225. s2_sip_free_message(cancel);
  2226. }
  2227. END_TEST
  2228. START_TEST(destroy_4_3_3)
  2229. {
  2230. nua_handle_t *nh;
  2231. struct message *invite, *ack, *bye;
  2232. S2_CASE("4.3.3", "Destroy handle in completing state",
  2233. "NUA sends INVITE, receives 200, handle gets destroyed.");
  2234. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  2235. invite = invite_sent_by_nua(nh, NUTAG_AUTOACK(0), TAG_END());
  2236. process_offer(invite);
  2237. s2_sip_respond_to(invite, dialog, SIP_180_RINGING, TAG_END());
  2238. fail_unless_event(nua_r_invite, 180);
  2239. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  2240. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  2241. fail_unless_event(nua_r_invite, 200);
  2242. fail_unless(s2_check_callstate(nua_callstate_completing));
  2243. nua_handle_destroy(nh);
  2244. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  2245. fail_if(!ack);
  2246. s2_sip_free_message(ack);
  2247. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  2248. fail_if(!bye);
  2249. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  2250. s2_sip_free_message(bye);
  2251. s2_sip_free_message(invite);
  2252. }
  2253. END_TEST
  2254. START_TEST(destroy_4_3_4)
  2255. {
  2256. nua_handle_t *nh;
  2257. struct message *invite, *ack, *bye;
  2258. S2_CASE("4.3.3", "Destroy handle in ready state ",
  2259. "NUA sends INVITE, receives 200, handle gets destroyed.");
  2260. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  2261. invite = invite_sent_by_nua(nh, NUTAG_AUTOACK(0), TAG_END());
  2262. process_offer(invite);
  2263. s2_sip_respond_to(invite, dialog, SIP_180_RINGING, TAG_END());
  2264. fail_unless_event(nua_r_invite, 180);
  2265. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  2266. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  2267. fail_unless_event(nua_r_invite, 200);
  2268. fail_unless(s2_check_callstate(nua_callstate_completing));
  2269. nua_ack(nh, TAG_END());
  2270. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  2271. fail_if(!ack);
  2272. s2_sip_free_message(ack);
  2273. fail_unless(s2_check_callstate(nua_callstate_ready));
  2274. nua_handle_destroy(nh);
  2275. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  2276. fail_if(!bye);
  2277. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  2278. s2_sip_free_message(bye);
  2279. s2_sip_free_message(invite);
  2280. }
  2281. END_TEST
  2282. START_TEST(destroy_4_3_5)
  2283. {
  2284. nua_handle_t *nh;
  2285. struct message *invite, *cancel;
  2286. S2_CASE("4.3.5", "Destroy handle in re-INVITE calling state",
  2287. "NUA sends re-INVITE, handle gets destroyed.");
  2288. nh = invite_to_nua(TAG_END());
  2289. invite = invite_sent_by_nua(nh, TAG_END());
  2290. process_offer(invite);
  2291. nua_handle_destroy(nh);
  2292. s2_sip_respond_to(invite, dialog, SIP_100_TRYING, TAG_END());
  2293. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  2294. fail_if(!cancel);
  2295. s2_sip_respond_to(invite, dialog, SIP_487_REQUEST_CANCELLED, TAG_END());
  2296. s2_sip_free_message(invite);
  2297. s2_sip_respond_to(cancel, dialog, SIP_200_OK, TAG_END());
  2298. s2_sip_free_message(cancel);
  2299. }
  2300. END_TEST
  2301. START_TEST(destroy_4_3_6)
  2302. {
  2303. nua_handle_t *nh;
  2304. struct message *invite, *cancel;
  2305. S2_CASE("4.3.6", "Destroy handle in calling state of re-INVITE",
  2306. "NUA sends re-INVITE, receives 180, handle gets destroyed.");
  2307. nh = invite_to_nua(TAG_END());
  2308. invite = invite_sent_by_nua(nh, TAG_END());
  2309. process_offer(invite);
  2310. s2_sip_respond_to(invite, dialog, SIP_180_RINGING, TAG_END());
  2311. fail_unless_event(nua_r_invite, 180);
  2312. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  2313. nua_handle_destroy(nh);
  2314. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  2315. fail_if(!cancel);
  2316. s2_sip_respond_to(invite, dialog, SIP_487_REQUEST_CANCELLED, TAG_END());
  2317. s2_sip_free_message(invite);
  2318. s2_sip_respond_to(cancel, dialog, SIP_200_OK, TAG_END());
  2319. s2_sip_free_message(cancel);
  2320. }
  2321. END_TEST
  2322. START_TEST(destroy_4_3_7)
  2323. {
  2324. nua_handle_t *nh;
  2325. struct message *invite, *ack, *bye;
  2326. S2_CASE("4.3.7", "Destroy handle in completing state of re-INVITE",
  2327. "NUA sends INVITE, receives 200, handle gets destroyed.");
  2328. nh = invite_to_nua(TAG_END());
  2329. invite = invite_sent_by_nua(nh, NUTAG_AUTOACK(0), TAG_END());
  2330. process_offer(invite);
  2331. s2_sip_respond_to(invite, dialog, SIP_180_RINGING, TAG_END());
  2332. fail_unless_event(nua_r_invite, 180);
  2333. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  2334. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  2335. fail_unless_event(nua_r_invite, 200);
  2336. fail_unless(s2_check_callstate(nua_callstate_completing));
  2337. nua_handle_destroy(nh);
  2338. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  2339. fail_if(!ack);
  2340. s2_sip_free_message(ack);
  2341. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  2342. fail_if(!bye);
  2343. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  2344. s2_sip_free_message(bye);
  2345. s2_sip_free_message(invite);
  2346. }
  2347. END_TEST
  2348. START_TEST(destroy_4_3_8)
  2349. {
  2350. nua_handle_t *nh;
  2351. struct message *invite, *ack, *bye;
  2352. S2_CASE("4.3.8", "Destroy handle after INVITE sent",
  2353. "NUA sends INVITE, handle gets destroyed, "
  2354. "but remote end returns 200 OK. "
  2355. "Make sure nua tries to release call properly.");
  2356. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  2357. invite = invite_sent_by_nua(nh, TAG_END());
  2358. process_offer(invite);
  2359. nua_handle_destroy(nh);
  2360. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  2361. s2_sip_free_message(invite);
  2362. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  2363. fail_if(!ack);
  2364. s2_sip_free_message(ack);
  2365. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  2366. fail_if(!bye);
  2367. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  2368. s2_sip_free_message(bye);
  2369. }
  2370. END_TEST
  2371. START_TEST(destroy_4_3_9)
  2372. {
  2373. nua_handle_t *nh;
  2374. struct message *invite, *cancel, *ack, *bye;
  2375. S2_CASE("4.3.9", "Destroy handle in calling state",
  2376. "NUA sends INVITE, receives 180, handle gets destroyed, "
  2377. "but remote end returns 200 OK. "
  2378. "Make sure nua tries to release call properly.");
  2379. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  2380. invite = invite_sent_by_nua(nh, TAG_END());
  2381. process_offer(invite);
  2382. s2_sip_respond_to(invite, dialog, SIP_180_RINGING, TAG_END());
  2383. fail_unless_event(nua_r_invite, 180);
  2384. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  2385. nua_handle_destroy(nh);
  2386. cancel = s2_sip_wait_for_request(SIP_METHOD_CANCEL);
  2387. fail_if(!cancel);
  2388. s2_sip_respond_to(cancel, dialog, SIP_481_NO_TRANSACTION, TAG_END());
  2389. s2_sip_free_message(cancel);
  2390. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  2391. s2_sip_free_message(invite);
  2392. ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
  2393. fail_if(!ack);
  2394. s2_sip_free_message(ack);
  2395. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  2396. fail_if(!bye);
  2397. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  2398. s2_sip_free_message(bye);
  2399. }
  2400. END_TEST
  2401. START_TEST(destroy_4_4_1)
  2402. {
  2403. nua_handle_t *nh;
  2404. struct event *invite;
  2405. struct message *response;
  2406. S2_CASE("4.4.1", "Destroy handle while call is on-going",
  2407. "NUA is callee, sends 100, destroys handle");
  2408. soa_generate_offer(soa, 1, NULL);
  2409. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());
  2410. invite = s2_wait_for_event(nua_i_invite, 100); fail_unless(invite != NULL);
  2411. fail_unless(s2_check_callstate(nua_callstate_received));
  2412. nh = invite->nh; fail_if(!nh);
  2413. s2_free_event(invite);
  2414. response = s2_sip_wait_for_response(100, SIP_METHOD_INVITE);
  2415. fail_if(!response);
  2416. s2_sip_free_message(response);
  2417. nua_handle_destroy(nh);
  2418. response = s2_sip_wait_for_response(480, SIP_METHOD_INVITE);
  2419. fail_if(!response);
  2420. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL,
  2421. SIPTAG_VIA(sip_object(dialog->invite)->sip_via),
  2422. TAG_END()));
  2423. s2_sip_free_message(response);
  2424. }
  2425. END_TEST
  2426. START_TEST(destroy_4_4_2)
  2427. {
  2428. nua_handle_t *nh;
  2429. struct event *invite;
  2430. struct message *response;
  2431. S2_CASE("4.4.1", "Destroy handle while call is on-going",
  2432. "NUA is callee, sends 180, destroys handle");
  2433. soa_generate_offer(soa, 1, NULL);
  2434. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());
  2435. invite = s2_wait_for_event(nua_i_invite, 100); fail_unless(invite != NULL);
  2436. fail_unless(s2_check_callstate(nua_callstate_received));
  2437. nh = invite->nh; fail_if(!nh);
  2438. s2_free_event(invite);
  2439. response = s2_sip_wait_for_response(100, SIP_METHOD_INVITE);
  2440. fail_if(!response);
  2441. s2_sip_free_message(response);
  2442. nua_respond(nh, SIP_180_RINGING, TAG_END());
  2443. response = s2_sip_wait_for_response(180, SIP_METHOD_INVITE);
  2444. fail_if(!response);
  2445. s2_sip_free_message(response);
  2446. nua_handle_destroy(nh);
  2447. response = s2_sip_wait_for_response(480, SIP_METHOD_INVITE);
  2448. fail_if(!response);
  2449. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL,
  2450. SIPTAG_VIA(sip_object(dialog->invite)->sip_via),
  2451. TAG_END()));
  2452. s2_sip_free_message(response);
  2453. }
  2454. END_TEST
  2455. START_TEST(destroy_4_4_3_1)
  2456. {
  2457. nua_handle_t *nh;
  2458. struct event *invite;
  2459. struct message *response, *bye;
  2460. S2_CASE("4.4.3.1", "Destroy handle while call is on-going",
  2461. "NUA is callee, sends 200, destroys handle");
  2462. soa_generate_offer(soa, 1, NULL);
  2463. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());
  2464. invite = s2_wait_for_event(nua_i_invite, 100); fail_unless(invite != NULL);
  2465. fail_unless(s2_check_callstate(nua_callstate_received));
  2466. nh = invite->nh; fail_if(!nh);
  2467. s2_free_event(invite);
  2468. response = s2_sip_wait_for_response(100, SIP_METHOD_INVITE);
  2469. fail_if(!response);
  2470. s2_sip_free_message(response);
  2471. nua_respond(nh, SIP_180_RINGING,
  2472. SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  2473. TAG_END());
  2474. response = s2_sip_wait_for_response(180, SIP_METHOD_INVITE);
  2475. fail_if(!response);
  2476. s2_sip_free_message(response);
  2477. fail_unless(s2_check_callstate(nua_callstate_early));
  2478. nua_respond(nh, SIP_200_OK, TAG_END());
  2479. fail_unless(s2_check_callstate(nua_callstate_completed));
  2480. response = s2_sip_wait_for_response(200, SIP_METHOD_INVITE);
  2481. fail_if(!response);
  2482. nua_handle_destroy(nh);
  2483. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL,
  2484. SIPTAG_VIA(sip_object(dialog->invite)->sip_via),
  2485. TAG_END()));
  2486. s2_sip_free_message(response);
  2487. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  2488. fail_if(!bye);
  2489. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  2490. s2_sip_free_message(bye);
  2491. }
  2492. END_TEST
  2493. START_TEST(destroy_4_4_3_2)
  2494. {
  2495. nua_handle_t *nh;
  2496. struct event *invite;
  2497. struct message *response, *bye;
  2498. S2_CASE("4.4.3.1", "Destroy handle while call is on-going",
  2499. "NUA is callee, sends 200, destroys handle");
  2500. soa_generate_offer(soa, 1, NULL);
  2501. request_with_sdp(dialog, SIP_METHOD_INVITE, NULL, TAG_END());
  2502. invite = s2_wait_for_event(nua_i_invite, 100); fail_unless(invite != NULL);
  2503. fail_unless(s2_check_callstate(nua_callstate_received));
  2504. nh = invite->nh; fail_if(!nh);
  2505. s2_free_event(invite);
  2506. response = s2_sip_wait_for_response(100, SIP_METHOD_INVITE);
  2507. fail_if(!response);
  2508. s2_sip_free_message(response);
  2509. nua_respond(nh, SIP_180_RINGING,
  2510. SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  2511. TAG_END());
  2512. response = s2_sip_wait_for_response(180, SIP_METHOD_INVITE);
  2513. fail_if(!response);
  2514. s2_sip_free_message(response);
  2515. fail_unless(s2_check_callstate(nua_callstate_early));
  2516. nua_respond(nh, SIP_200_OK, TAG_END());
  2517. fail_unless(s2_check_callstate(nua_callstate_completed));
  2518. response = s2_sip_wait_for_response(200, SIP_METHOD_INVITE);
  2519. fail_if(!response);
  2520. nua_handle_destroy(nh);
  2521. bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  2522. fail_if(!bye);
  2523. s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  2524. s2_sip_free_message(bye);
  2525. fail_if(s2_sip_request_to(dialog, SIP_METHOD_ACK, NULL,
  2526. SIPTAG_VIA(sip_object(dialog->invite)->sip_via),
  2527. TAG_END()));
  2528. s2_sip_free_message(response);
  2529. }
  2530. END_TEST
  2531. static TCase *destroy_tcase(int threading)
  2532. {
  2533. TCase *tc = tcase_create("4.3 - Destroying Handle");
  2534. add_call_fixtures(tc, threading);
  2535. {
  2536. tcase_add_test(tc, destroy_4_3_1);
  2537. tcase_add_test(tc, destroy_4_3_2);
  2538. tcase_add_test(tc, destroy_4_3_3);
  2539. tcase_add_test(tc, destroy_4_3_4);
  2540. tcase_add_test(tc, destroy_4_3_5);
  2541. tcase_add_test(tc, destroy_4_3_6);
  2542. tcase_add_test(tc, destroy_4_3_7);
  2543. if (XXX) {
  2544. tcase_add_test(tc, destroy_4_3_8);
  2545. tcase_add_test(tc, destroy_4_3_9);
  2546. }
  2547. tcase_add_test(tc, destroy_4_4_1);
  2548. tcase_add_test(tc, destroy_4_4_2);
  2549. tcase_add_test(tc, destroy_4_4_3_1);
  2550. tcase_add_test(tc, destroy_4_4_3_2);
  2551. tcase_set_timeout(tc, 5);
  2552. }
  2553. return tc;
  2554. }
  2555. /* ====================================================================== */
  2556. static void options_setup(void), options_teardown(void);
  2557. START_TEST(options_5_1_1)
  2558. {
  2559. struct event *options;
  2560. nua_handle_t *nh;
  2561. struct message *response;
  2562. S2_CASE("5.1.1", "Test nua_respond() API",
  2563. "Test nua_respond() API with OPTIONS.");
  2564. s2_sip_request_to(dialog, SIP_METHOD_OPTIONS, NULL, TAG_END());
  2565. options = s2_wait_for_event(nua_i_options, 200);
  2566. fail_unless(options != NULL);
  2567. nh = options->nh; fail_if(!nh);
  2568. response = s2_sip_wait_for_response(200, SIP_METHOD_OPTIONS);
  2569. fail_if(!response);
  2570. s2_sip_free_message(response);
  2571. nua_handle_destroy(nh);
  2572. nua_set_params(nua, NUTAG_APPL_METHOD("OPTIONS"), TAG_END());
  2573. fail_unless_event(nua_r_set_params, 200);
  2574. s2_sip_request_to(dialog, SIP_METHOD_OPTIONS, NULL, TAG_END());
  2575. options = s2_wait_for_event(nua_i_options, 100);
  2576. fail_unless(options != NULL);
  2577. nh = options->nh; fail_if(!nh);
  2578. nua_respond(nh, 202, "okok", NUTAG_WITH_SAVED(options->event), TAG_END());
  2579. response = s2_sip_wait_for_response(202, SIP_METHOD_OPTIONS);
  2580. fail_if(!response);
  2581. s2_sip_free_message(response);
  2582. nua_handle_destroy(nh);
  2583. }
  2584. END_TEST
  2585. #if HAVE_LIBPTHREAD
  2586. #include <pthread.h>
  2587. void *respond_to_options(void *arg)
  2588. {
  2589. struct event *options = (struct event *)arg;
  2590. nua_respond(options->nh, 202, "ok ok",
  2591. NUTAG_WITH_SAVED(options->event),
  2592. TAG_END());
  2593. pthread_exit(arg);
  2594. return NULL;
  2595. }
  2596. START_TEST(options_5_1_2)
  2597. {
  2598. struct event *options;
  2599. nua_handle_t *nh;
  2600. struct message *response;
  2601. pthread_t tid;
  2602. void *thread_return = NULL;
  2603. S2_CASE("5.1.2", "Test nua_respond() API with another thread",
  2604. "Test multithreading nua_respond() API with OPTIONS.");
  2605. nua_set_params(nua, NUTAG_APPL_METHOD("OPTIONS"), TAG_END());
  2606. fail_unless_event(nua_r_set_params, 200);
  2607. s2_sip_request_to(dialog, SIP_METHOD_OPTIONS, NULL, TAG_END());
  2608. options = s2_wait_for_event(nua_i_options, 100);
  2609. fail_unless(options != NULL);
  2610. nh = options->nh; fail_if(!nh);
  2611. fail_if(pthread_create(&tid, NULL, respond_to_options, (void *)options));
  2612. pthread_join(tid, &thread_return);
  2613. fail_unless(thread_return == (void *)options);
  2614. response = s2_sip_wait_for_response(202, SIP_METHOD_OPTIONS);
  2615. fail_if(!response);
  2616. s2_sip_free_message(response);
  2617. nua_handle_destroy(nh);
  2618. }
  2619. END_TEST
  2620. #else
  2621. START_TEST(options_5_1_2)
  2622. {
  2623. }
  2624. END_TEST
  2625. #endif
  2626. TCase *options_tcase(int threading)
  2627. {
  2628. TCase *tc = tcase_create("5 - OPTIONS, etc");
  2629. tcase_add_checked_fixture(tc, options_setup, options_teardown);
  2630. tcase_add_test(tc, options_5_1_1);
  2631. tcase_add_test(tc, options_5_1_2);
  2632. return tc;
  2633. }
  2634. static void options_setup(void)
  2635. {
  2636. s2_nua_thread = 1;
  2637. call_setup();
  2638. }
  2639. static void options_teardown(void)
  2640. {
  2641. s2_teardown_started("options");
  2642. call_teardown();
  2643. }
  2644. /* ====================================================================== */
  2645. /* Test cases for REFER */
  2646. START_TEST(refer_5_2_1)
  2647. {
  2648. nua_handle_t *nh;
  2649. sip_refer_to_t r[1];
  2650. struct event *refer;
  2651. struct message *notify;
  2652. S2_CASE("5.2.1", "Receive REFER",
  2653. "Make a call, receive REFER.");
  2654. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  2655. invite_by_nua(nh, TAG_END());
  2656. *sip_refer_to_init(r)->r_url = *s2sip->aor->a_url;
  2657. r->r_url->url_user = "bob2";
  2658. s2_sip_request_to(dialog, SIP_METHOD_REFER, NULL,
  2659. SIPTAG_REFER_TO(r),
  2660. TAG_END());
  2661. refer = s2_wait_for_event(nua_i_refer, 202);
  2662. bye_by_nua(nh, TAG_END());
  2663. nua_handle_destroy(nh);
  2664. notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
  2665. s2_sip_respond_to(notify, dialog, SIP_200_OK, TAG_END());
  2666. }
  2667. END_TEST
  2668. START_TEST(refer_5_2_2)
  2669. {
  2670. nua_handle_t *nh, *nh2;
  2671. sip_refer_to_t r[1];
  2672. sip_referred_by_t by[1];
  2673. struct event *refer, *notified;
  2674. sip_t const *sip;
  2675. sip_event_t const *refer_event = NULL;
  2676. sip_subscription_state_t const *ss;
  2677. struct message *invite;
  2678. struct message *notify0, *notify1, *notify2;
  2679. struct dialog *dialog1, *dialog2;
  2680. S2_CASE("5.2.2", "Receive REFER",
  2681. "Make a call, receive REFER, "
  2682. "make another call with automatic NOTIFYs");
  2683. dialog2 = su_home_new(sizeof *dialog2); fail_unless(dialog2 != NULL);
  2684. nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
  2685. invite_by_nua(nh, TAG_END());
  2686. *sip_refer_to_init(r)->r_url = *s2sip->aor->a_url;
  2687. r->r_url->url_user = "bob2";
  2688. s2_sip_request_to(dialog, SIP_METHOD_REFER, NULL,
  2689. SIPTAG_REFER_TO(r),
  2690. TAG_END());
  2691. refer = s2_wait_for_event(nua_i_refer, 202);
  2692. sip = sip_object(refer->data->e_msg);
  2693. fail_unless(sip && sip->sip_refer_to);
  2694. bye_by_nua(nh, TAG_END());
  2695. dialog1 = dialog, dialog = dialog2;
  2696. *sip_referred_by_init(by)->b_url =
  2697. *sip->sip_from->a_url;
  2698. fail_unless(tl_gets(refer->data->e_tags,
  2699. NUTAG_REFER_EVENT_REF(refer_event),
  2700. TAG_END()) == 1);
  2701. nua_notify(nh,
  2702. SIPTAG_EVENT(refer_event),
  2703. SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
  2704. SIPTAG_PAYLOAD_STR("SIP/2.0 100 Trying\r\n"),
  2705. NUTAG_SUBSTATE(nua_substate_active),
  2706. TAG_END());
  2707. notify0 = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
  2708. fail_unless((ss = notify0->sip->sip_subscription_state) != NULL);
  2709. fail_unless(su_casematch("active", ss->ss_substate));
  2710. s2_sip_respond_to(notify0, dialog1, SIP_200_OK, TAG_END());
  2711. notified = s2_wait_for_event(nua_r_notify, 200);
  2712. nh2 = nua_handle(nua, NULL, NUTAG_URL(r->r_url), TAG_END());
  2713. invite = invite_sent_by_nua(nh2,
  2714. NUTAG_REFER_EVENT(refer_event),
  2715. NUTAG_NOTIFY_REFER(nh),
  2716. SIPTAG_REFERRED_BY(by),
  2717. TAG_END());
  2718. process_offer(invite);
  2719. respond_with_sdp(
  2720. invite, dialog, SIP_180_RINGING,
  2721. SIPTAG_CONTENT_DISPOSITION_STR("session;handling=optional"),
  2722. TAG_END());
  2723. fail_unless_event(nua_r_invite, 180);
  2724. fail_unless(s2_check_callstate(nua_callstate_proceeding));
  2725. notify1 = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
  2726. s2_sip_respond_to(notify1, dialog1, SIP_200_OK, TAG_END());
  2727. respond_with_sdp(invite, dialog, SIP_200_OK, TAG_END());
  2728. s2_sip_free_message(invite);
  2729. fail_unless_event(nua_r_invite, 200);
  2730. fail_unless(s2_check_callstate(nua_callstate_ready));
  2731. fail_unless(s2_sip_check_request(SIP_METHOD_ACK));
  2732. notify2 = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
  2733. s2_sip_respond_to(notify2, dialog1, SIP_200_OK, TAG_END());
  2734. fail_unless((ss = notify2->sip->sip_subscription_state) != NULL);
  2735. fail_unless(su_casematch("terminated", ss->ss_substate));
  2736. nua_handle_destroy(nh);
  2737. bye_by_nua(nh2, TAG_END());
  2738. nua_handle_destroy(nh2);
  2739. }
  2740. END_TEST
  2741. TCase *refer_tcase(int threading)
  2742. {
  2743. TCase *tc = tcase_create("5.2 - Call Transfer");
  2744. add_call_fixtures(tc, threading);
  2745. tcase_add_test(tc, refer_5_2_1);
  2746. tcase_add_test(tc, refer_5_2_2);
  2747. return tc;
  2748. }
  2749. /* ====================================================================== */
  2750. /* Test case template */
  2751. START_TEST(empty)
  2752. {
  2753. S2_CASE("0.0.0", "Empty test case",
  2754. "Detailed explanation for empty test case.");
  2755. tport_set_params(s2sip->master, TPTAG_LOG(1), TAG_END());
  2756. s2_setup_logs(7);
  2757. s2_setup_logs(0);
  2758. tport_set_params(s2sip->master, TPTAG_LOG(0), TAG_END());
  2759. }
  2760. END_TEST
  2761. TCase *empty_tcase(int threading)
  2762. {
  2763. TCase *tc = tcase_create("0 - Empty");
  2764. add_call_fixtures(tc, threading);
  2765. tcase_add_test(tc, empty);
  2766. return tc;
  2767. }
  2768. /* ====================================================================== */
  2769. void check_session_cases(Suite *suite, int threading)
  2770. {
  2771. suite_add_tcase(suite, invite_tcase(threading));
  2772. suite_add_tcase(suite, cancel_tcase(threading));
  2773. suite_add_tcase(suite, session_timer_tcase(threading));
  2774. suite_add_tcase(suite, invite_100rel_tcase(threading));
  2775. suite_add_tcase(suite, invite_precondition_tcase(threading));
  2776. suite_add_tcase(suite, reinvite_tcase(threading));
  2777. suite_add_tcase(suite, invite_error_tcase(threading));
  2778. suite_add_tcase(suite, termination_tcase(threading));
  2779. suite_add_tcase(suite, destroy_tcase(threading));
  2780. suite_add_tcase(suite, options_tcase(threading));
  2781. suite_add_tcase(suite, refer_tcase(threading));
  2782. if (0) /* Template */
  2783. suite_add_tcase(suite, empty_tcase(threading));
  2784. }