2
0

switch_ivr_originate.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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. static switch_state_handler_table_t state_handlers = {
  52. /*.on_init */ NULL,
  53. /*.on_routing */ NULL,
  54. /*.on_execute */ NULL,
  55. /*.on_hangup */ NULL,
  56. /*.on_exchange_media */ NULL,
  57. /*.on_soft_execute */ NULL,
  58. /*.on_consume_media */ NULL,
  59. /*.on_hibernate */ NULL,
  60. /*.on_reset */ NULL,
  61. /*.on_park */ NULL,
  62. /*.on_reporting */ my_on_reporting,
  63. /*.on_destroy */ my_on_destroy,
  64. SSH_FLAG_STICKY
  65. };
  66. static int application_hit = 0;
  67. static void loopback_group_confirm_event_handler(switch_event_t *event) // general event handler
  68. {
  69. if (event->event_id == SWITCH_EVENT_CHANNEL_APPLICATION) {
  70. application_hit++;
  71. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "application_hit = %d\n", application_hit);
  72. }
  73. }
  74. FST_CORE_BEGIN("./conf")
  75. {
  76. FST_SUITE_BEGIN(switch_ivr_originate)
  77. {
  78. FST_SETUP_BEGIN()
  79. {
  80. fst_requires_module("mod_loopback");
  81. application_hit = 0;
  82. }
  83. FST_SETUP_END()
  84. FST_TEARDOWN_BEGIN()
  85. {
  86. }
  87. FST_TEARDOWN_END()
  88. FST_TEST_BEGIN(originate_test_early_state_handler)
  89. {
  90. switch_core_session_t *session = NULL;
  91. switch_channel_t *channel = NULL;
  92. switch_status_t status;
  93. switch_call_cause_t cause;
  94. status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
  95. fst_requires(session);
  96. fst_check(status == SWITCH_STATUS_SUCCESS);
  97. channel = switch_core_session_get_channel(session);
  98. fst_requires(channel);
  99. switch_channel_add_state_handler(channel, &state_handlers);
  100. switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
  101. fst_check(!switch_channel_ready(channel));
  102. switch_core_session_rwunlock(session);
  103. switch_sleep(1000000);
  104. fst_check(reporting == 1);
  105. fst_check(destroy == 1);
  106. }
  107. FST_TEST_END()
  108. FST_TEST_BEGIN(originate_test_late_state_handler)
  109. {
  110. switch_core_session_t *session = NULL;
  111. switch_channel_t *channel = NULL;
  112. switch_status_t status;
  113. switch_call_cause_t cause;
  114. status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
  115. fst_requires(session);
  116. fst_check(status == SWITCH_STATUS_SUCCESS);
  117. channel = switch_core_session_get_channel(session);
  118. fst_requires(channel);
  119. switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
  120. switch_sleep(1000000);
  121. switch_channel_add_state_handler(channel, &state_handlers);
  122. switch_core_session_rwunlock(session);
  123. switch_sleep(1000000);
  124. fst_check(reporting == 1);
  125. fst_check(destroy == 2);
  126. }
  127. FST_TEST_END()
  128. FST_TEST_BEGIN(dial_handle_create_json)
  129. {
  130. const char *dh_str = "{\n"
  131. " \"vars\": {\n"
  132. " \"foo\": \"bar\",\n"
  133. " \"absolute_codec_string\": \"opus,pcmu,pcma\",\n"
  134. " \"ignore_early_media\": \"true\"\n"
  135. " },\n"
  136. " \"leg_lists\": [\n"
  137. " { \"legs\": [\n"
  138. " { \n"
  139. " \"dial_string\": \"loopback/dest\", \n"
  140. " \"vars\": {\n"
  141. " \"bar\": \"bar\"\n"
  142. " }\n"
  143. " },\n"
  144. " { \n"
  145. " \"dial_string\": \"sofia/gateway/gw/12345\"\n"
  146. " }\n"
  147. " ] },\n"
  148. " { \"legs\": [\n"
  149. " {\n"
  150. " \"dial_string\": \"sofia/external/foo@example.com^5551231234\",\n"
  151. " \"vars\": {\n"
  152. " \"sip_h_X-Custom\": \"my val\"\n"
  153. " }\n"
  154. " }\n"
  155. " ] },\n"
  156. " { \"legs\": [\n"
  157. " {\n"
  158. " \"dial_string\": \"group/my_group\"\n"
  159. " }\n"
  160. " ] }\n"
  161. " ]\n"
  162. "}";
  163. // create dial handle from json string, convert back to json and compare
  164. switch_dial_handle_t *dh = NULL;
  165. char *dh_str2 = NULL;
  166. char *dh_str3 = NULL;
  167. cJSON *dh_json = NULL;
  168. fst_requires(switch_dial_handle_create_json(&dh, dh_str) == SWITCH_STATUS_SUCCESS);
  169. fst_requires(dh != NULL);
  170. fst_requires(switch_dial_handle_serialize_json_obj(dh, &dh_json) == SWITCH_STATUS_SUCCESS);
  171. fst_requires(dh_json != NULL);
  172. fst_requires(switch_dial_handle_serialize_json(dh, &dh_str2) == SWITCH_STATUS_SUCCESS);
  173. fst_requires(dh_str2 != NULL);
  174. 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\"}]}]}");
  175. dh_str3 = cJSON_PrintUnformatted(dh_json);
  176. fst_requires(dh_str3);
  177. fst_check_string_equals(dh_str2, dh_str3);
  178. switch_safe_free(dh_str2);
  179. switch_safe_free(dh_str3);
  180. cJSON_Delete(dh_json);
  181. switch_dial_handle_destroy(&dh);
  182. }
  183. FST_TEST_END();
  184. FST_TEST_BEGIN(originate_test_empty_dial_string)
  185. {
  186. switch_core_session_t *session = NULL;
  187. switch_channel_t *channel = NULL;
  188. switch_status_t status;
  189. switch_call_cause_t cause;
  190. switch_dial_handle_t *dh;
  191. switch_dial_leg_list_t *ll;
  192. switch_dial_leg_t *leg = NULL;
  193. switch_dial_handle_create(&dh);
  194. switch_dial_handle_add_leg_list(dh, &ll);
  195. /* Dial string is NULL */
  196. switch_dial_leg_list_add_leg(ll, &leg, NULL);
  197. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  198. fst_check(status == SWITCH_STATUS_FALSE);
  199. switch_dial_handle_destroy(&dh);
  200. }
  201. FST_TEST_END()
  202. FST_TEST_BEGIN(originate_test_group_confirm_one_leg)
  203. {
  204. switch_core_session_t *session = NULL;
  205. switch_channel_t *channel = NULL;
  206. switch_status_t status;
  207. switch_call_cause_t cause;
  208. switch_dial_handle_t *dh;
  209. switch_dial_leg_list_t *ll;
  210. switch_dial_leg_t *leg = NULL;
  211. switch_dial_handle_create(&dh);
  212. switch_dial_handle_add_leg_list(dh, &ll);
  213. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  214. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://1000");
  215. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  216. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  217. fst_requires(status == SWITCH_STATUS_SUCCESS);
  218. fst_requires(session);
  219. switch_core_session_rwunlock(session);
  220. switch_dial_handle_destroy(&dh);
  221. }
  222. FST_TEST_END()
  223. FST_TEST_BEGIN(originate_test_group_confirm_no_pre_answer)
  224. {
  225. switch_core_session_t *session = NULL;
  226. switch_channel_t *channel = NULL;
  227. switch_status_t status;
  228. switch_call_cause_t cause;
  229. switch_dial_handle_t *dh;
  230. switch_dial_leg_list_t *ll;
  231. switch_dial_leg_t *leg = NULL;
  232. switch_dial_handle_create(&dh);
  233. switch_dial_handle_add_leg_list(dh, &ll);
  234. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  235. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://1000");
  236. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  237. switch_dial_handle_add_global_var(dh, "null_enable_auto_answer", "1");
  238. switch_dial_handle_add_global_var(dh, "null_auto_answer_delay", "2000");
  239. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  240. fst_requires(status == SWITCH_STATUS_SUCCESS);
  241. fst_requires(session);
  242. switch_core_session_rwunlock(session);
  243. switch_dial_handle_destroy(&dh);
  244. fst_check_duration(3000, 500);
  245. }
  246. FST_TEST_END()
  247. FST_TEST_BEGIN(originate_test_group_confirm_exec_in_pre_answer)
  248. {
  249. switch_core_session_t *session = NULL;
  250. switch_channel_t *channel = NULL;
  251. switch_status_t status;
  252. switch_call_cause_t cause;
  253. switch_dial_handle_t *dh;
  254. switch_dial_leg_list_t *ll;
  255. switch_dial_leg_t *leg = NULL;
  256. switch_dial_handle_create(&dh);
  257. switch_dial_handle_add_leg_list(dh, &ll);
  258. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  259. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://1000");
  260. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  261. switch_dial_handle_add_global_var(dh, "null_enable_auto_answer", "1");
  262. switch_dial_handle_add_global_var(dh, "null_auto_answer_delay", "2000");
  263. switch_dial_handle_add_global_var(dh, "null_pre_answer", "true");
  264. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  265. fst_requires(status == SWITCH_STATUS_SUCCESS);
  266. fst_requires(session);
  267. switch_core_session_rwunlock(session);
  268. switch_dial_handle_destroy(&dh);
  269. fst_check_duration(1000, 500);
  270. }
  271. FST_TEST_END()
  272. FST_TEST_BEGIN(originate_test_group_confirm_exec_after_answer_early_ok)
  273. {
  274. switch_core_session_t *session = NULL;
  275. switch_channel_t *channel = NULL;
  276. switch_status_t status;
  277. switch_call_cause_t cause;
  278. switch_dial_handle_t *dh;
  279. switch_dial_leg_list_t *ll;
  280. switch_dial_leg_t *leg = NULL;
  281. switch_dial_handle_create(&dh);
  282. switch_dial_handle_add_leg_list(dh, &ll);
  283. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  284. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://1000");
  285. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  286. switch_dial_handle_add_global_var(dh, "null_enable_auto_answer", "1");
  287. switch_dial_handle_add_global_var(dh, "null_auto_answer_delay", "2000");
  288. switch_dial_handle_add_global_var(dh, "null_pre_answer", "true");
  289. switch_dial_handle_add_global_var(dh, "group_confirm_early_ok", "false");
  290. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  291. fst_requires(status == SWITCH_STATUS_SUCCESS);
  292. fst_requires(session);
  293. switch_core_session_rwunlock(session);
  294. switch_dial_handle_destroy(&dh);
  295. fst_check_duration(3000, 500);
  296. }
  297. FST_TEST_END()
  298. FST_TEST_BEGIN(originate_test_group_confirm_exec_after_answer_ignore_early_media)
  299. {
  300. switch_core_session_t *session = NULL;
  301. switch_channel_t *channel = NULL;
  302. switch_status_t status;
  303. switch_call_cause_t cause;
  304. switch_dial_handle_t *dh;
  305. switch_dial_leg_list_t *ll;
  306. switch_dial_leg_t *leg = NULL;
  307. switch_dial_handle_create(&dh);
  308. switch_dial_handle_add_leg_list(dh, &ll);
  309. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  310. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://1000");
  311. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  312. switch_dial_handle_add_global_var(dh, "null_enable_auto_answer", "1");
  313. switch_dial_handle_add_global_var(dh, "null_auto_answer_delay", "2000");
  314. switch_dial_handle_add_global_var(dh, "null_pre_answer", "true");
  315. switch_dial_handle_add_global_var(dh, "ignore_early_media", "true");
  316. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  317. fst_requires(status == SWITCH_STATUS_SUCCESS);
  318. fst_requires(session);
  319. switch_core_session_rwunlock(session);
  320. switch_dial_handle_destroy(&dh);
  321. fst_check_duration(3000, 500);
  322. }
  323. FST_TEST_END()
  324. FST_TEST_BEGIN(originate_test_group_confirm_2_legs)
  325. {
  326. switch_core_session_t *session = NULL;
  327. switch_channel_t *channel = NULL;
  328. switch_status_t status;
  329. switch_call_cause_t cause;
  330. switch_dial_handle_t *dh;
  331. switch_dial_leg_list_t *ll;
  332. switch_dial_leg_t *leg = NULL;
  333. switch_dial_handle_create(&dh);
  334. switch_dial_handle_add_leg_list(dh, &ll);
  335. switch_dial_leg_list_add_leg(ll, &leg, "null/test1");
  336. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://1000");
  337. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  338. switch_dial_leg_list_add_leg(ll, &leg, "null/test2");
  339. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://500");
  340. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  341. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  342. fst_requires(status == SWITCH_STATUS_SUCCESS);
  343. fst_requires(session);
  344. const char *name = switch_core_session_get_name(session);
  345. switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "channel %s\n", name);
  346. fst_check_string_equals(name, "null/test2");
  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_global_var)
  352. {
  353. switch_core_session_t *session = NULL;
  354. switch_channel_t *channel = NULL;
  355. switch_status_t status;
  356. switch_call_cause_t cause;
  357. const char *dialstring = "{group_confirm_file='playback silence_stream://1000',group_confirm_key=exec}null/test";
  358. status = switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
  359. fst_requires(status == SWITCH_STATUS_SUCCESS);
  360. fst_requires(session);
  361. const char *name = switch_core_session_get_name(session);
  362. switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "channel %s\n", name);
  363. fst_check_string_equals(name, "null/test");
  364. switch_core_session_rwunlock(session);
  365. }
  366. FST_TEST_END()
  367. FST_TEST_BEGIN(originate_test_group_confirm_local_var)
  368. {
  369. switch_core_session_t *session = NULL;
  370. switch_channel_t *channel = NULL;
  371. switch_status_t status;
  372. switch_call_cause_t cause;
  373. const char *dialstring = "[group_confirm_file='playback silence_stream://1000',group_confirm_key=exec]null/test1,"
  374. "[group_confirm_file='playback silence_stream://500',group_confirm_key=exec]null/test2";
  375. status = switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
  376. fst_requires(status == SWITCH_STATUS_SUCCESS);
  377. fst_requires(session);
  378. const char *name = switch_core_session_get_name(session);
  379. switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "channel %s\n", name);
  380. fst_check_string_equals(name, "null/test2");
  381. switch_core_session_rwunlock(session);
  382. }
  383. FST_TEST_END()
  384. FST_TEST_BEGIN(originate_test_group_confirm_loopback_endpoint_originate)
  385. {
  386. switch_core_session_t *session = NULL;
  387. switch_channel_t *channel = NULL;
  388. switch_status_t status;
  389. switch_call_cause_t cause;
  390. const char *dialstring = "[group_confirm_key=exec,group_confirm_file='event a=1']loopback/loopback";
  391. switch_event_bind("test", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, loopback_group_confirm_event_handler, NULL);
  392. status = switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
  393. fst_requires(status == SWITCH_STATUS_SUCCESS);
  394. fst_requires(session);
  395. switch_yield(2000000);
  396. switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING);
  397. switch_core_session_rwunlock(session);
  398. switch_event_unbind_callback(loopback_group_confirm_event_handler);
  399. fst_check(application_hit == 1);
  400. }
  401. FST_TEST_END()
  402. FST_SESSION_BEGIN(originate_test_group_confirm_loopback_endpoint_bridge)
  403. {
  404. switch_core_session_t *session = NULL;
  405. switch_channel_t *channel = NULL;
  406. switch_status_t status;
  407. switch_call_cause_t cause;
  408. const char *dialstring = "[group_confirm_key=exec,group_confirm_file='event a=1']loopback/loopback";
  409. switch_event_bind("test", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, loopback_group_confirm_event_handler, NULL);
  410. switch_core_session_execute_application(fst_session, "bridge", dialstring);
  411. switch_yield(2000000);
  412. switch_channel_hangup(fst_channel, SWITCH_CAUSE_NORMAL_CLEARING);
  413. fst_check(application_hit == 1);
  414. }
  415. FST_SESSION_END()
  416. FST_TEST_BEGIN(originate_test_group_confirm_leg_timeout_not_finished)
  417. {
  418. switch_core_session_t *session = NULL;
  419. switch_channel_t *channel = NULL;
  420. switch_status_t status;
  421. switch_call_cause_t cause;
  422. switch_dial_handle_t *dh;
  423. switch_dial_leg_list_t *ll;
  424. switch_dial_leg_t *leg = NULL;
  425. switch_dial_handle_create(&dh);
  426. switch_dial_handle_add_leg_list(dh, &ll);
  427. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  428. switch_dial_handle_add_leg_var(leg, "null_enable_auto_answer", "1");
  429. switch_dial_handle_add_leg_var(leg, "null_auto_answer_delay", "2000");
  430. switch_dial_handle_add_leg_var(leg, "leg_timeout", "4");
  431. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://6000");
  432. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  433. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  434. fst_requires(status == SWITCH_STATUS_FALSE);
  435. fst_check(session == NULL);
  436. fst_check_duration(4500, 600); // (>= 3.9 sec, <= 5.1 sec)
  437. switch_dial_handle_destroy(&dh);
  438. }
  439. FST_TEST_END()
  440. FST_TEST_BEGIN(originate_test_group_confirm_leg_timeout_finished)
  441. {
  442. switch_core_session_t *session = NULL;
  443. switch_channel_t *channel = NULL;
  444. switch_status_t status;
  445. switch_call_cause_t cause;
  446. switch_dial_handle_t *dh;
  447. switch_dial_leg_list_t *ll;
  448. switch_dial_leg_t *leg = NULL;
  449. switch_dial_handle_create(&dh);
  450. switch_dial_handle_add_leg_list(dh, &ll);
  451. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  452. switch_dial_handle_add_leg_var(leg, "null_enable_auto_answer", "1");
  453. switch_dial_handle_add_leg_var(leg, "null_auto_answer_delay", "2000");
  454. switch_dial_handle_add_leg_var(leg, "leg_timeout", "6");
  455. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://2000");
  456. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  457. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  458. fst_requires(status == SWITCH_STATUS_SUCCESS);
  459. fst_requires(session);
  460. fst_xcheck(switch_channel_test_flag(switch_core_session_get_channel(session), CF_WINNER), "Expect session is group confirm winner");
  461. switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING);
  462. switch_core_session_rwunlock(session);
  463. switch_dial_handle_destroy(&dh);
  464. fst_check_duration(4000, 500);
  465. }
  466. FST_TEST_END()
  467. FST_TEST_BEGIN(originate_test_group_confirm_timeout_leg)
  468. {
  469. switch_core_session_t *session = NULL;
  470. switch_channel_t *channel = NULL;
  471. switch_status_t status;
  472. switch_call_cause_t cause;
  473. switch_dial_handle_t *dh;
  474. switch_dial_leg_list_t *ll;
  475. switch_dial_leg_t *leg = NULL;
  476. switch_dial_handle_create(&dh);
  477. switch_dial_handle_add_leg_list(dh, &ll);
  478. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  479. switch_dial_handle_add_leg_var(leg, "leg_timeout", "15");
  480. switch_dial_handle_add_leg_var(leg, "null_enable_auto_answer", "1");
  481. switch_dial_handle_add_leg_var(leg, "null_auto_answer_delay", "2000");
  482. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://10000");
  483. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  484. switch_dial_handle_add_leg_var(leg, "group_confirm_timeout", "3");
  485. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  486. fst_requires(status == SWITCH_STATUS_FALSE);
  487. fst_check(session == NULL);
  488. switch_dial_handle_destroy(&dh);
  489. fst_check_duration(5500, 600); // (> 4.9 sec < 6.1 sec) only 1 second resolution with these timeouts
  490. }
  491. FST_TEST_END()
  492. FST_TEST_BEGIN(originate_test_group_confirm_timeout_global)
  493. {
  494. switch_core_session_t *session = NULL;
  495. switch_channel_t *channel = NULL;
  496. switch_status_t status;
  497. switch_call_cause_t cause;
  498. switch_dial_handle_t *dh;
  499. switch_dial_leg_list_t *ll;
  500. switch_dial_leg_t *leg = NULL;
  501. switch_dial_handle_create(&dh);
  502. switch_dial_handle_add_leg_list(dh, &ll);
  503. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  504. switch_dial_handle_add_leg_var(leg, "leg_timeout", "15");
  505. switch_dial_handle_add_leg_var(leg, "null_enable_auto_answer", "1");
  506. switch_dial_handle_add_leg_var(leg, "null_auto_answer_delay", "2000");
  507. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://10000");
  508. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  509. switch_dial_handle_add_global_var(dh, "group_confirm_timeout", "3");
  510. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  511. fst_requires(status == SWITCH_STATUS_FALSE);
  512. fst_check(session == NULL);
  513. fst_check_duration(5500, 600); // (>= 4.9 sec, <= 6.1 sec) only 1 second resolution with these timeouts
  514. switch_dial_handle_destroy(&dh);
  515. }
  516. FST_TEST_END()
  517. FST_TEST_BEGIN(originate_test_group_confirm_cancel_timeout_global)
  518. {
  519. switch_core_session_t *session = NULL;
  520. switch_channel_t *channel = NULL;
  521. switch_status_t status;
  522. switch_call_cause_t cause;
  523. switch_dial_handle_t *dh;
  524. switch_dial_leg_list_t *ll;
  525. switch_dial_leg_t *leg = NULL;
  526. switch_dial_handle_create(&dh);
  527. switch_dial_handle_add_leg_list(dh, &ll);
  528. switch_dial_leg_list_add_leg(ll, &leg, "null/test");
  529. switch_dial_handle_add_leg_var(leg, "leg_timeout", "3");
  530. switch_dial_handle_add_leg_var(leg, "null_enable_auto_answer", "1");
  531. switch_dial_handle_add_leg_var(leg, "null_auto_answer_delay", "2000");
  532. switch_dial_handle_add_leg_var(leg, "group_confirm_file", "playback silence_stream://2000");
  533. switch_dial_handle_add_leg_var(leg, "group_confirm_key", "exec");
  534. switch_dial_handle_add_global_var(dh, "group_confirm_cancel_timeout", "true");
  535. status = switch_ivr_originate(NULL, &session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
  536. fst_requires(status == SWITCH_STATUS_SUCCESS);
  537. fst_requires(session);
  538. fst_xcheck(switch_channel_test_flag(switch_core_session_get_channel(session), CF_WINNER), "Expect session is group confirm winner");
  539. switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING);
  540. switch_core_session_rwunlock(session);
  541. switch_dial_handle_destroy(&dh);
  542. fst_check_duration(4500, 600); // (>= 3.9 sec, <= 5.1 sec)
  543. }
  544. FST_TEST_END()
  545. }
  546. FST_SUITE_END()
  547. }
  548. FST_CORE_END()