switch_ivr_originate.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. /*
  2. * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  3. * Copyright (C) 2005-2020, Anthony Minessale II <anthm@freeswitch.org>
  4. *
  5. * Version: MPL 1.1
  6. *
  7. * The contents of this file are subject to the Mozilla Public License Version
  8. * 1.1 (the "License"); you may not use this file except in compliance with
  9. * the License. You may obtain a copy of the License at
  10. * http://www.mozilla.org/MPL/
  11. *
  12. * Software distributed under the License is distributed on an "AS IS" basis,
  13. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing rights and limitations under the
  15. * License.
  16. *
  17. * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  18. *
  19. * The Initial Developer of the Original Code is
  20. * Anthony Minessale II <anthm@freeswitch.org>
  21. * Portions created by the Initial Developer are Copyright (C)
  22. * the Initial Developer. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. * Chris Rienzo <chris@signalwire.com>
  26. * Seven Du <dujinfang@gmail.com>
  27. *
  28. *
  29. * switch_ivr_originate.c -- tests originate
  30. *
  31. */
  32. #include <switch.h>
  33. #include <stdlib.h>
  34. #include <test/switch_test.h>
  35. int reporting = 0;
  36. int destroy = 0;
  37. static switch_status_t my_on_reporting(switch_core_session_t *session)
  38. {
  39. switch_assert(session);
  40. reporting++;
  41. switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "session reporting %d\n", reporting);
  42. return SWITCH_STATUS_SUCCESS;
  43. }
  44. static switch_status_t my_on_destroy(switch_core_session_t *session)
  45. {
  46. switch_assert(session);
  47. destroy++;
  48. switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "session destroy %d\n", destroy);
  49. return SWITCH_STATUS_SUCCESS;
  50. }
  51. const char *external_id_to_match = NULL;
  52. static int got_external_id_in_event = 0;
  53. static void on_hangup_event(switch_event_t *event)
  54. {
  55. if (external_id_to_match) {
  56. const char *external_id = switch_event_get_header(event, "Session-External-ID");
  57. if (external_id && !strcmp(external_id_to_match, external_id)) {
  58. got_external_id_in_event = 1;
  59. }
  60. }
  61. }
  62. static switch_state_handler_table_t state_handlers = {
  63. /*.on_init */ NULL,
  64. /*.on_routing */ NULL,
  65. /*.on_execute */ NULL,
  66. /*.on_hangup */ NULL,
  67. /*.on_exchange_media */ NULL,
  68. /*.on_soft_execute */ NULL,
  69. /*.on_consume_media */ NULL,
  70. /*.on_hibernate */ NULL,
  71. /*.on_reset */ NULL,
  72. /*.on_park */ NULL,
  73. /*.on_reporting */ my_on_reporting,
  74. /*.on_destroy */ my_on_destroy,
  75. SSH_FLAG_STICKY
  76. };
  77. static int application_hit = 0;
  78. static void loopback_group_confirm_event_handler(switch_event_t *event) // general event handler
  79. {
  80. if (event->event_id == SWITCH_EVENT_CHANNEL_APPLICATION) {
  81. application_hit++;
  82. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "application_hit = %d\n", application_hit);
  83. }
  84. }
  85. FST_CORE_BEGIN("./conf")
  86. {
  87. FST_SUITE_BEGIN(switch_ivr_originate)
  88. {
  89. FST_SETUP_BEGIN()
  90. {
  91. fst_requires_module("mod_loopback");
  92. application_hit = 0;
  93. external_id_to_match = NULL;
  94. got_external_id_in_event = 0;
  95. }
  96. FST_SETUP_END()
  97. FST_TEARDOWN_BEGIN()
  98. {
  99. }
  100. FST_TEARDOWN_END()
  101. FST_TEST_BEGIN(originate_test_external_id)
  102. {
  103. switch_core_session_t *session = NULL;
  104. switch_channel_t *channel = NULL;
  105. switch_status_t status;
  106. switch_call_cause_t cause;
  107. switch_event_t *ovars = NULL;
  108. switch_event_create(&ovars, SWITCH_EVENT_CLONE);
  109. switch_event_add_header_string(ovars, SWITCH_STACK_BOTTOM, "origination_external_id", "zzzz");
  110. status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, ovars, SOF_NONE, NULL, NULL);
  111. fst_requires(session);
  112. fst_check(status == SWITCH_STATUS_SUCCESS);
  113. switch_event_destroy(&ovars);
  114. switch_core_session_rwunlock(session);
  115. session = switch_core_session_locate("zzzz");
  116. fst_requires(session);
  117. channel = switch_core_session_get_channel(session);
  118. fst_requires(channel);
  119. external_id_to_match = "zzzz";
  120. switch_event_bind("originate_test_external_id", SWITCH_EVENT_CHANNEL_HANGUP, SWITCH_EVENT_SUBCLASS_ANY, on_hangup_event, NULL);
  121. switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
  122. switch_core_session_rwunlock(session);
  123. switch_yield(1000 * 1000);
  124. fst_check(got_external_id_in_event == 1);
  125. switch_event_unbind_callback(on_hangup_event);
  126. }
  127. FST_TEST_END()
  128. FST_TEST_BEGIN(originate_test_early_state_handler)
  129. {
  130. switch_core_session_t *session = NULL;
  131. switch_channel_t *channel = NULL;
  132. switch_status_t status;
  133. switch_call_cause_t cause;
  134. status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
  135. fst_requires(session);
  136. fst_check(status == SWITCH_STATUS_SUCCESS);
  137. channel = switch_core_session_get_channel(session);
  138. fst_requires(channel);
  139. switch_channel_add_state_handler(channel, &state_handlers);
  140. switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
  141. fst_check(!switch_channel_ready(channel));
  142. switch_core_session_rwunlock(session);
  143. switch_sleep(1000000);
  144. fst_check(reporting == 1);
  145. fst_check(destroy == 1);
  146. }
  147. FST_TEST_END()
  148. FST_TEST_BEGIN(originate_test_late_state_handler)
  149. {
  150. switch_core_session_t *session = NULL;
  151. switch_channel_t *channel = NULL;
  152. switch_status_t status;
  153. switch_call_cause_t cause;
  154. status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
  155. fst_requires(session);
  156. fst_check(status == SWITCH_STATUS_SUCCESS);
  157. channel = switch_core_session_get_channel(session);
  158. fst_requires(channel);
  159. switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
  160. switch_sleep(1000000);
  161. switch_channel_add_state_handler(channel, &state_handlers);
  162. switch_core_session_rwunlock(session);
  163. switch_sleep(1000000);
  164. fst_check(reporting == 1);
  165. fst_check(destroy == 2);
  166. }
  167. FST_TEST_END()
  168. FST_TEST_BEGIN(dial_handle_create_json)
  169. {
  170. const char *dh_str = "{\n"
  171. " \"vars\": {\n"
  172. " \"foo\": \"bar\",\n"
  173. " \"absolute_codec_string\": \"opus,pcmu,pcma\",\n"
  174. " \"ignore_early_media\": \"true\"\n"
  175. " },\n"
  176. " \"leg_lists\": [\n"
  177. " { \"legs\": [\n"
  178. " { \n"
  179. " \"dial_string\": \"loopback/dest\", \n"
  180. " \"vars\": {\n"
  181. " \"bar\": \"bar\"\n"
  182. " }\n"
  183. " },\n"
  184. " { \n"
  185. " \"dial_string\": \"sofia/gateway/gw/12345\"\n"
  186. " }\n"
  187. " ] },\n"
  188. " { \"legs\": [\n"
  189. " {\n"
  190. " \"dial_string\": \"sofia/external/foo@example.com^5551231234\",\n"
  191. " \"vars\": {\n"
  192. " \"sip_h_X-Custom\": \"my val\"\n"
  193. " }\n"
  194. " }\n"
  195. " ] },\n"
  196. " { \"legs\": [\n"
  197. " {\n"
  198. " \"dial_string\": \"group/my_group\"\n"
  199. " }\n"
  200. " ] }\n"
  201. " ]\n"
  202. "}";
  203. // create dial handle from json string, convert back to json and compare
  204. switch_dial_handle_t *dh = NULL;
  205. char *dh_str2 = NULL;
  206. char *dh_str3 = NULL;
  207. cJSON *dh_json = NULL;
  208. fst_requires(switch_dial_handle_create_json(&dh, dh_str) == SWITCH_STATUS_SUCCESS);
  209. fst_requires(dh != NULL);
  210. fst_requires(switch_dial_handle_serialize_json_obj(dh, &dh_json) == SWITCH_STATUS_SUCCESS);
  211. fst_requires(dh_json != NULL);
  212. fst_requires(switch_dial_handle_serialize_json(dh, &dh_str2) == SWITCH_STATUS_SUCCESS);
  213. fst_requires(dh_str2 != NULL);
  214. fst_check_string_equals(dh_str2, "{\"vars\":{\"foo\":\"bar\",\"absolute_codec_string\":\"opus,pcmu,pcma\",\"ignore_early_media\":\"true\"},\"leg_lists\":[{\"legs\":[{\"dial_string\":\"loopback/dest\",\"vars\":{\"bar\":\"bar\"}},{\"dial_string\":\"sofia/gateway/gw/12345\"}]},{\"legs\":[{\"dial_string\":\"sofia/external/foo@example.com^5551231234\",\"vars\":{\"sip_h_X-Custom\":\"my val\"}}]},{\"legs\":[{\"dial_string\":\"group/my_group\"}]}]}");
  215. dh_str3 = cJSON_PrintUnformatted(dh_json);
  216. fst_requires(dh_str3);
  217. fst_check_string_equals(dh_str2, dh_str3);
  218. switch_safe_free(dh_str2);
  219. switch_safe_free(dh_str3);
  220. cJSON_Delete(dh_json);
  221. switch_dial_handle_destroy(&dh);
  222. }
  223. FST_TEST_END();
  224. FST_TEST_BEGIN(dial_handle_list_create_json)
  225. {
  226. const char *dh_str_1 = "{\n"
  227. " \"vars\": {\n"
  228. " \"foo\": \"bar\",\n"
  229. " \"absolute_codec_string\": \"pcmu,pcma\",\n"
  230. " \"ignore_early_media\": \"true\"\n"
  231. " },\n"
  232. " \"leg_lists\": [\n"
  233. " { \"legs\": [\n"
  234. " { \n"
  235. " \"dial_string\": \"loopback/dest2\", \n"
  236. " \"vars\": {\n"
  237. " \"bar\": \"bar\"\n"
  238. " }\n"
  239. " },\n"
  240. " { \n"
  241. " \"dial_string\": \"sofia/gateway/gw/123456\"\n"
  242. " }\n"
  243. " ] },\n"
  244. " { \"legs\": [\n"
  245. " {\n"
  246. " \"dial_string\": \"sofia/external/foo@example.com^5551231234\",\n"
  247. " \"vars\": {\n"
  248. " \"sip_h_X-Custom\": \"my val 2\"\n"
  249. " }\n"
  250. " }\n"
  251. " ] },\n"
  252. " { \"legs\": [\n"
  253. " {\n"
  254. " \"dial_string\": \"group/my_group_2\"\n"
  255. " }\n"
  256. " ] }\n"
  257. " ]\n"
  258. "}";
  259. const char *dh_str_2 = "{\n"
  260. " \"vars\": {\n"
  261. " \"foo\": \"bar\",\n"
  262. " \"absolute_codec_string\": \"opus,pcmu,pcma\",\n"
  263. " \"ignore_early_media\": \"true\"\n"
  264. " },\n"
  265. " \"leg_lists\": [\n"
  266. " { \"legs\": [\n"
  267. " { \n"
  268. " \"dial_string\": \"loopback/dest\", \n"
  269. " \"vars\": {\n"
  270. " \"bar\": \"bar\"\n"
  271. " }\n"
  272. " },\n"
  273. " { \n"
  274. " \"dial_string\": \"sofia/gateway/gw/12345\"\n"
  275. " }\n"
  276. " ] },\n"
  277. " { \"legs\": [\n"
  278. " {\n"
  279. " \"dial_string\": \"sofia/external/foo@example.com^5551231234\",\n"
  280. " \"vars\": {\n"
  281. " \"sip_h_X-Custom\": \"my val\"\n"
  282. " }\n"
  283. " }\n"
  284. " ] },\n"
  285. " { \"legs\": [\n"
  286. " {\n"
  287. " \"dial_string\": \"group/my_group\"\n"
  288. " }\n"
  289. " ] }\n"
  290. " ]\n"
  291. "}";
  292. const char *dl_str = switch_core_sprintf(fst_pool, "{ \"handles\": [ %s, %s ], \"vars\": { \"global_1\":\"val_1\" } }", dh_str_1, dh_str_2);
  293. // create dial handle from json string, convert back to json and compare
  294. switch_dial_handle_list_t *dl = NULL;
  295. char *dl_str_2 = NULL;
  296. char *dl_str_3 = NULL;
  297. cJSON *dl_json = NULL;
  298. fst_requires(switch_dial_handle_list_create_json(&dl, dl_str) == SWITCH_STATUS_SUCCESS);
  299. fst_requires(dl != NULL);
  300. fst_requires(switch_dial_handle_list_serialize_json_obj(dl, &dl_json) == SWITCH_STATUS_SUCCESS);
  301. fst_requires(dl_json != NULL);
  302. fst_requires(switch_dial_handle_list_serialize_json(dl, &dl_str_2) == SWITCH_STATUS_SUCCESS);
  303. fst_requires(dl_str_2 != NULL);
  304. fst_check_string_equals(dl_str_2, "{\"vars\":{\"global_1\":\"val_1\"},\"handles\":[{\"vars\":{\"foo\":\"bar\",\"absolute_codec_string\":\"pcmu,pcma\",\"ignore_early_media\":\"true\"},\"leg_lists\":[{\"legs\":[{\"dial_string\":\"loopback/dest2\",\"vars\":{\"bar\":\"bar\"}},{\"dial_string\":\"sofia/gateway/gw/123456\"}]},{\"legs\":[{\"dial_string\":\"sofia/external/foo@example.com^5551231234\",\"vars\":{\"sip_h_X-Custom\":\"my val 2\"}}]},{\"legs\":[{\"dial_string\":\"group/my_group_2\"}]}]},{\"vars\":{\"foo\":\"bar\",\"absolute_codec_string\":\"opus,pcmu,pcma\",\"ignore_early_media\":\"true\"},\"leg_lists\":[{\"legs\":[{\"dial_string\":\"loopback/dest\",\"vars\":{\"bar\":\"bar\"}},{\"dial_string\":\"sofia/gateway/gw/12345\"}]},{\"legs\":[{\"dial_string\":\"sofia/external/foo@example.com^5551231234\",\"vars\":{\"sip_h_X-Custom\":\"my val\"}}]},{\"legs\":[{\"dial_string\":\"group/my_group\"}]}]}]}");
  305. dl_str_3 = cJSON_PrintUnformatted(dl_json);
  306. fst_requires(dl_str_3);
  307. fst_check_string_equals(dl_str_2, dl_str_3);
  308. switch_safe_free(dl_str_2);
  309. switch_safe_free(dl_str_3);
  310. cJSON_Delete(dl_json);
  311. switch_dial_handle_list_destroy(&dl);
  312. }
  313. FST_TEST_END();
  314. FST_TEST_BEGIN(originate_test_empty_dial_string)
  315. {
  316. switch_core_session_t *session = NULL;
  317. switch_status_t status;
  318. switch_call_cause_t cause;
  319. switch_dial_handle_t *dh;
  320. switch_dial_leg_list_t *ll;
  321. switch_dial_leg_t *leg = NULL;
  322. switch_dial_handle_create(&dh);
  323. switch_dial_handle_add_leg_list(dh, &ll);
  324. /* Dial string is NULL */
  325. switch_dial_leg_list_add_leg(ll, &leg, NULL);
  326. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  327. fst_check(status == SWITCH_STATUS_FALSE);
  328. switch_dial_handle_destroy(&dh);
  329. }
  330. FST_TEST_END()
  331. FST_TEST_BEGIN(originate_test_group_confirm_one_leg)
  332. {
  333. switch_core_session_t *session = NULL;
  334. switch_status_t status;
  335. switch_call_cause_t cause;
  336. switch_dial_handle_t *dh;
  337. switch_dial_leg_list_t *ll;
  338. switch_dial_leg_t *leg = NULL;
  339. switch_dial_handle_create(&dh);
  340. switch_dial_handle_add_leg_list(dh, &ll);
  341. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  342. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://1000");
  343. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  344. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  345. fst_requires(status == SWITCH_STATUS_SUCCESS);
  346. fst_requires(session);
  347. switch_core_session_rwunlock(session);
  348. switch_dial_handle_destroy(&dh);
  349. }
  350. FST_TEST_END()
  351. FST_TEST_BEGIN(originate_test_group_confirm_no_pre_answer)
  352. {
  353. switch_core_session_t *session = NULL;
  354. switch_status_t status;
  355. switch_call_cause_t cause;
  356. switch_dial_handle_t *dh;
  357. switch_dial_leg_list_t *ll;
  358. switch_dial_leg_t *leg = NULL;
  359. switch_dial_handle_create(&dh);
  360. switch_dial_handle_add_leg_list(dh, &ll);
  361. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  362. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://1000");
  363. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  364. switch_dial_handle_add_global_var(dh, "null_enable_auto_answer", "1");
  365. switch_dial_handle_add_global_var(dh, "null_auto_answer_delay", "2000");
  366. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  367. fst_requires(status == SWITCH_STATUS_SUCCESS);
  368. fst_requires(session);
  369. switch_core_session_rwunlock(session);
  370. switch_dial_handle_destroy(&dh);
  371. fst_check_duration(3000, 500);
  372. }
  373. FST_TEST_END()
  374. FST_TEST_BEGIN(originate_test_group_confirm_exec_in_pre_answer)
  375. {
  376. switch_core_session_t *session = NULL;
  377. switch_status_t status;
  378. switch_call_cause_t cause;
  379. switch_dial_handle_t *dh;
  380. switch_dial_leg_list_t *ll;
  381. switch_dial_leg_t *leg = NULL;
  382. switch_dial_handle_create(&dh);
  383. switch_dial_handle_add_leg_list(dh, &ll);
  384. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  385. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://1000");
  386. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  387. switch_dial_handle_add_global_var(dh, "null_enable_auto_answer", "1");
  388. switch_dial_handle_add_global_var(dh, "null_auto_answer_delay", "2000");
  389. switch_dial_handle_add_global_var(dh, "null_pre_answer", "true");
  390. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  391. fst_requires(status == SWITCH_STATUS_SUCCESS);
  392. fst_requires(session);
  393. switch_core_session_rwunlock(session);
  394. switch_dial_handle_destroy(&dh);
  395. fst_check_duration(1000, 500);
  396. }
  397. FST_TEST_END()
  398. FST_TEST_BEGIN(originate_test_group_confirm_exec_after_answer_early_ok)
  399. {
  400. switch_core_session_t *session = NULL;
  401. switch_status_t status;
  402. switch_call_cause_t cause;
  403. switch_dial_handle_t *dh;
  404. switch_dial_leg_list_t *ll;
  405. switch_dial_leg_t *leg = NULL;
  406. switch_dial_handle_create(&dh);
  407. switch_dial_handle_add_leg_list(dh, &ll);
  408. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  409. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://1000");
  410. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  411. switch_dial_handle_add_global_var(dh, "null_enable_auto_answer", "1");
  412. switch_dial_handle_add_global_var(dh, "null_auto_answer_delay", "2000");
  413. switch_dial_handle_add_global_var(dh, "null_pre_answer", "true");
  414. switch_dial_handle_add_global_var(dh, "group_confirm_early_ok", "false");
  415. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  416. fst_requires(status == SWITCH_STATUS_SUCCESS);
  417. fst_requires(session);
  418. switch_core_session_rwunlock(session);
  419. switch_dial_handle_destroy(&dh);
  420. fst_check_duration(3000, 500);
  421. }
  422. FST_TEST_END()
  423. FST_TEST_BEGIN(originate_test_group_confirm_exec_after_answer_ignore_early_media)
  424. {
  425. switch_core_session_t *session = NULL;
  426. switch_status_t status;
  427. switch_call_cause_t cause;
  428. switch_dial_handle_t *dh;
  429. switch_dial_leg_list_t *ll;
  430. switch_dial_leg_t *leg = NULL;
  431. switch_dial_handle_create(&dh);
  432. switch_dial_handle_add_leg_list(dh, &ll);
  433. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  434. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://1000");
  435. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  436. switch_dial_handle_add_global_var(dh, "null_enable_auto_answer", "1");
  437. switch_dial_handle_add_global_var(dh, "null_auto_answer_delay", "2000");
  438. switch_dial_handle_add_global_var(dh, "null_pre_answer", "true");
  439. switch_dial_handle_add_global_var(dh, "ignore_early_media", "true");
  440. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  441. fst_requires(status == SWITCH_STATUS_SUCCESS);
  442. fst_requires(session);
  443. switch_core_session_rwunlock(session);
  444. switch_dial_handle_destroy(&dh);
  445. fst_check_duration(3000, 500);
  446. }
  447. FST_TEST_END()
  448. FST_TEST_BEGIN(originate_test_group_confirm_2_legs)
  449. {
  450. const char *name;
  451. switch_core_session_t *session = NULL;
  452. switch_status_t status;
  453. switch_call_cause_t cause;
  454. switch_dial_handle_t *dh;
  455. switch_dial_leg_list_t *ll;
  456. switch_dial_leg_t *leg = NULL;
  457. switch_dial_handle_create(&dh);
  458. switch_dial_handle_add_leg_list(dh, &ll);
  459. switch_dial_leg_list_add_leg(ll, &leg, "null/test1");
  460. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://1000");
  461. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  462. switch_dial_leg_list_add_leg(ll, &leg, "null/test2");
  463. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://500");
  464. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  465. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  466. fst_requires(status == SWITCH_STATUS_SUCCESS);
  467. fst_requires(session);
  468. name = switch_core_session_get_name(session);
  469. switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "channel %s\n", name);
  470. fst_check_string_equals(name, "null/test2");
  471. switch_core_session_rwunlock(session);
  472. switch_dial_handle_destroy(&dh);
  473. }
  474. FST_TEST_END()
  475. FST_TEST_BEGIN(originate_test_group_confirm_global_var)
  476. {
  477. const char *name;
  478. switch_core_session_t *session = NULL;
  479. switch_status_t status;
  480. switch_call_cause_t cause;
  481. const char *dialstring = "{group_confirm_file='playback silence_stream://1000',group_confirm_key=exec}null/test";
  482. status = switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
  483. fst_requires(status == SWITCH_STATUS_SUCCESS);
  484. fst_requires(session);
  485. name = switch_core_session_get_name(session);
  486. switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "channel %s\n", name);
  487. fst_check_string_equals(name, "null/test");
  488. switch_core_session_rwunlock(session);
  489. }
  490. FST_TEST_END()
  491. FST_TEST_BEGIN(originate_test_group_confirm_local_var)
  492. {
  493. const char *name;
  494. switch_core_session_t *session = NULL;
  495. switch_status_t status;
  496. switch_call_cause_t cause;
  497. const char *dialstring = "[group_confirm_file='playback silence_stream://1000',group_confirm_key=exec]null/test1,"
  498. "[group_confirm_file='playback silence_stream://500',group_confirm_key=exec]null/test2";
  499. status = switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
  500. fst_requires(status == SWITCH_STATUS_SUCCESS);
  501. fst_requires(session);
  502. name = switch_core_session_get_name(session);
  503. switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "channel %s\n", name);
  504. fst_check_string_equals(name, "null/test2");
  505. switch_core_session_rwunlock(session);
  506. }
  507. FST_TEST_END()
  508. FST_TEST_BEGIN(originate_test_group_confirm_loopback_endpoint_originate)
  509. {
  510. switch_core_session_t *session = NULL;
  511. switch_status_t status;
  512. switch_call_cause_t cause;
  513. const char *dialstring = "[group_confirm_key=exec,group_confirm_file='event a=1']loopback/loopback";
  514. switch_event_bind("test", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, loopback_group_confirm_event_handler, NULL);
  515. status = switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
  516. fst_requires(status == SWITCH_STATUS_SUCCESS);
  517. fst_requires(session);
  518. switch_yield(2000000);
  519. switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING);
  520. switch_core_session_rwunlock(session);
  521. switch_event_unbind_callback(loopback_group_confirm_event_handler);
  522. fst_check(application_hit == 1);
  523. }
  524. FST_TEST_END()
  525. FST_SESSION_BEGIN(originate_test_group_confirm_loopback_endpoint_bridge)
  526. {
  527. const char *dialstring = "[group_confirm_key=exec,group_confirm_file='event a=1']loopback/loopback";
  528. switch_event_bind("test", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, loopback_group_confirm_event_handler, NULL);
  529. switch_core_session_execute_application(fst_session, "bridge", dialstring);
  530. switch_yield(2000000);
  531. switch_channel_hangup(fst_channel, SWITCH_CAUSE_NORMAL_CLEARING);
  532. fst_check(application_hit == 1);
  533. }
  534. FST_SESSION_END()
  535. FST_TEST_BEGIN(originate_test_group_confirm_leg_timeout_not_finished)
  536. {
  537. switch_core_session_t *session = NULL;
  538. switch_status_t status;
  539. switch_call_cause_t cause;
  540. switch_dial_handle_t *dh;
  541. switch_dial_leg_list_t *ll;
  542. switch_dial_leg_t *leg = NULL;
  543. switch_dial_handle_create(&dh);
  544. switch_dial_handle_add_leg_list(dh, &ll);
  545. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  546. switch_dial_handle_add_leg_var(leg, "null_enable_auto_answer", "1");
  547. switch_dial_handle_add_leg_var(leg, "null_auto_answer_delay", "2000");
  548. switch_dial_handle_add_leg_var(leg, "leg_timeout", "4");
  549. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://6000");
  550. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  551. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  552. fst_requires(status == SWITCH_STATUS_FALSE);
  553. fst_check(session == NULL);
  554. fst_check_duration(4500, 600); // (>= 3.9 sec, <= 5.1 sec)
  555. switch_dial_handle_destroy(&dh);
  556. }
  557. FST_TEST_END()
  558. FST_TEST_BEGIN(originate_test_group_confirm_leg_timeout_finished)
  559. {
  560. switch_core_session_t *session = NULL;
  561. switch_status_t status;
  562. switch_call_cause_t cause;
  563. switch_dial_handle_t *dh;
  564. switch_dial_leg_list_t *ll;
  565. switch_dial_leg_t *leg = NULL;
  566. switch_dial_handle_create(&dh);
  567. switch_dial_handle_add_leg_list(dh, &ll);
  568. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  569. switch_dial_handle_add_leg_var(leg, "null_enable_auto_answer", "1");
  570. switch_dial_handle_add_leg_var(leg, "null_auto_answer_delay", "2000");
  571. switch_dial_handle_add_leg_var(leg, "leg_timeout", "6");
  572. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://2000");
  573. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  574. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  575. fst_requires(status == SWITCH_STATUS_SUCCESS);
  576. fst_requires(session);
  577. fst_xcheck(switch_channel_test_flag(switch_core_session_get_channel(session), CF_WINNER), "Expect session is group confirm winner");
  578. switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING);
  579. switch_core_session_rwunlock(session);
  580. switch_dial_handle_destroy(&dh);
  581. fst_check_duration(4000, 500);
  582. }
  583. FST_TEST_END()
  584. FST_TEST_BEGIN(originate_test_group_confirm_timeout_leg)
  585. {
  586. switch_core_session_t *session = NULL;
  587. switch_status_t status;
  588. switch_call_cause_t cause;
  589. switch_dial_handle_t *dh;
  590. switch_dial_leg_list_t *ll;
  591. switch_dial_leg_t *leg = NULL;
  592. switch_dial_handle_create(&dh);
  593. switch_dial_handle_add_leg_list(dh, &ll);
  594. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  595. switch_dial_handle_add_leg_var(leg, "leg_timeout", "15");
  596. switch_dial_handle_add_leg_var(leg, "null_enable_auto_answer", "1");
  597. switch_dial_handle_add_leg_var(leg, "null_auto_answer_delay", "2000");
  598. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://10000");
  599. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  600. switch_dial_handle_add_leg_var(leg, "group_confirm_timeout", "3");
  601. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  602. fst_requires(status == SWITCH_STATUS_FALSE);
  603. fst_check(session == NULL);
  604. switch_dial_handle_destroy(&dh);
  605. fst_check_duration(5500, 600); // (> 4.9 sec < 6.1 sec) only 1 second resolution with these timeouts
  606. }
  607. FST_TEST_END()
  608. FST_TEST_BEGIN(originate_test_group_confirm_timeout_global)
  609. {
  610. switch_core_session_t *session = NULL;
  611. switch_status_t status;
  612. switch_call_cause_t cause;
  613. switch_dial_handle_t *dh;
  614. switch_dial_leg_list_t *ll;
  615. switch_dial_leg_t *leg = NULL;
  616. switch_dial_handle_create(&dh);
  617. switch_dial_handle_add_leg_list(dh, &ll);
  618. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  619. switch_dial_handle_add_leg_var(leg, "leg_timeout", "15");
  620. switch_dial_handle_add_leg_var(leg, "null_enable_auto_answer", "1");
  621. switch_dial_handle_add_leg_var(leg, "null_auto_answer_delay", "2000");
  622. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://10000");
  623. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  624. switch_dial_handle_add_global_var(dh, "group_confirm_timeout", "3");
  625. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  626. fst_requires(status == SWITCH_STATUS_FALSE);
  627. fst_check(session == NULL);
  628. fst_check_duration(5500, 600); // (>= 4.9 sec, <= 6.1 sec) only 1 second resolution with these timeouts
  629. switch_dial_handle_destroy(&dh);
  630. }
  631. FST_TEST_END()
  632. FST_TEST_BEGIN(originate_test_group_confirm_cancel_timeout_global)
  633. {
  634. switch_core_session_t *session = NULL;
  635. switch_status_t status;
  636. switch_call_cause_t cause;
  637. switch_dial_handle_t *dh;
  638. switch_dial_leg_list_t *ll;
  639. switch_dial_leg_t *leg = NULL;
  640. switch_dial_handle_create(&dh);
  641. switch_dial_handle_add_leg_list(dh, &ll);
  642. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  643. switch_dial_handle_add_leg_var(leg, "leg_timeout", "3");
  644. switch_dial_handle_add_leg_var(leg, "null_enable_auto_answer", "1");
  645. switch_dial_handle_add_leg_var(leg, "null_auto_answer_delay", "2000");
  646. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://2000");
  647. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  648. switch_dial_handle_add_global_var(dh, "group_confirm_cancel_timeout", "true");
  649. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  650. fst_requires(status == SWITCH_STATUS_SUCCESS);
  651. fst_requires(session);
  652. fst_xcheck(switch_channel_test_flag(switch_core_session_get_channel(session), CF_WINNER), "Expect session is group confirm winner");
  653. switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING);
  654. switch_core_session_rwunlock(session);
  655. switch_dial_handle_destroy(&dh);
  656. fst_check_duration(4500, 600); // (>= 3.9 sec, <= 5.1 sec)
  657. }
  658. FST_TEST_END()
  659. FST_TEST_BEGIN(originate_test_video)
  660. {
  661. switch_core_session_t *session = NULL;
  662. switch_channel_t *channel = NULL;
  663. switch_status_t status;
  664. switch_call_cause_t cause;
  665. status = switch_ivr_originate(NULL, &session, &cause, "{null_video_codec=VP8}null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
  666. fst_requires(session);
  667. fst_check(status == SWITCH_STATUS_SUCCESS);
  668. channel = switch_core_session_get_channel(session);
  669. fst_requires(channel);
  670. fst_check(switch_channel_test_flag(channel, CF_VIDEO));
  671. switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
  672. fst_check(!switch_channel_ready(channel));
  673. switch_core_session_rwunlock(session);
  674. switch_sleep(1000000);
  675. }
  676. FST_TEST_END()
  677. FST_TEST_BEGIN(enterprise_originate_test_group_confirm_two_handles)
  678. {
  679. switch_core_session_t *session = NULL;
  680. switch_status_t status;
  681. switch_call_cause_t cause;
  682. switch_dial_handle_list_t *dl;
  683. switch_dial_handle_t *dh;
  684. switch_dial_leg_list_t *ll;
  685. switch_dial_leg_t *leg = NULL;
  686. switch_dial_handle_list_create(&dl);
  687. switch_dial_handle_list_create_handle(dl, &dh);
  688. switch_dial_handle_add_leg_list(dh, &ll);
  689. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  690. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://1000");
  691. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  692. switch_dial_handle_add_leg_var(leg, "expected_winner", "true");
  693. switch_dial_handle_list_create_handle(dl, &dh);
  694. switch_dial_handle_add_leg_list(dh, &ll);
  695. switch_dial_leg_list_add_leg(ll, &leg, "error/user_busy");
  696. switch_dial_handle_list_add_global_var(dl, "continue_on_fail", "true");
  697. switch_dial_handle_list_add_global_var(dl, "is_from_dial_handle_list", "true");
  698. status = switch_ivr_enterprise_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dl);
  699. fst_requires(status == SWITCH_STATUS_SUCCESS);
  700. fst_requires(session);
  701. fst_xcheck(switch_true(switch_channel_get_variable(switch_core_session_get_channel(session), "is_from_dial_handle_list")), "Expect dial handle list global var to be set on channel");
  702. fst_xcheck(switch_true(switch_channel_get_variable(switch_core_session_get_channel(session), "expected_winner")), "Wrong winning leg");
  703. switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING);
  704. switch_core_session_rwunlock(session);
  705. switch_dial_handle_list_destroy(&dl);
  706. }
  707. FST_TEST_END()
  708. FST_SESSION_BEGIN(switch_ivr_enterprise_orig_and_bridge)
  709. {
  710. switch_status_t status;
  711. switch_call_cause_t cause = SWITCH_CAUSE_NONE;
  712. switch_dial_handle_list_t *dl;
  713. switch_dial_handle_t *dh;
  714. switch_dial_leg_list_t *ll;
  715. switch_dial_leg_t *leg = NULL;
  716. switch_dial_handle_list_create(&dl);
  717. switch_dial_handle_list_create_handle(dl, &dh);
  718. switch_dial_handle_add_leg_list(dh, &ll);
  719. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  720. switch_dial_handle_add_leg_var(leg, "execute_on_answer", "sched_hangup +2 normal_clearing");
  721. switch_dial_handle_list_create_handle(dl, &dh);
  722. switch_dial_handle_add_leg_list(dh, &ll);
  723. switch_dial_leg_list_add_leg(ll, &leg, "error/user_busy");
  724. switch_dial_handle_list_add_global_var(dl, "continue_on_fail", "true");
  725. switch_dial_handle_list_add_global_var(dl, "is_from_dial_handle_list", "true");
  726. switch_channel_set_variable(fst_channel, "park_after_bridge", "true");
  727. status = switch_ivr_enterprise_orig_and_bridge(fst_session, NULL, dl, &cause);
  728. fst_xcheck(status == SWITCH_STATUS_SUCCESS, "Expect switch_ivr_enterprise_orig_and_bridge() to succeed");
  729. fst_xcheck(cause == SWITCH_CAUSE_SUCCESS, "Expect called party to answer");
  730. switch_dial_handle_list_destroy(&dl);
  731. }
  732. FST_SESSION_END()
  733. FST_SESSION_BEGIN(switch_ivr_enterprise_orig_and_bridge_fail)
  734. {
  735. switch_status_t status;
  736. switch_call_cause_t cause = SWITCH_CAUSE_NONE;
  737. switch_dial_handle_list_t *dl;
  738. switch_dial_handle_t *dh;
  739. switch_dial_leg_list_t *ll;
  740. switch_dial_leg_t *leg = NULL;
  741. switch_dial_handle_list_create(&dl);
  742. switch_dial_handle_list_create_handle(dl, &dh);
  743. switch_dial_handle_add_leg_list(dh, &ll);
  744. switch_dial_leg_list_add_leg(ll, &leg, "error/no_answer");
  745. switch_dial_handle_list_create_handle(dl, &dh);
  746. switch_dial_handle_add_leg_list(dh, &ll);
  747. switch_dial_leg_list_add_leg(ll, &leg, "error/user_busy");
  748. switch_dial_handle_list_add_global_var(dl, "continue_on_fail", "true");
  749. switch_channel_set_variable(fst_channel, "park_after_bridge", "true");
  750. status = switch_ivr_enterprise_orig_and_bridge(fst_session, NULL, dl, &cause);
  751. fst_xcheck(status == SWITCH_STATUS_FALSE, "Expect switch_ivr_enterprise_orig_and_bridge() to fail");
  752. fst_xcheck(cause == SWITCH_CAUSE_USER_BUSY || cause == SWITCH_CAUSE_NO_ANSWER, "Expect called party not to answer");
  753. switch_dial_handle_list_destroy(&dl);
  754. }
  755. FST_SESSION_END()
  756. }
  757. FST_SUITE_END()
  758. }
  759. FST_CORE_END()