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