File: | src/switch_ivr_originate.c |
Location: | line 1888, column 47 |
Description: | Value stored to 'myflags' during its initialization is never read |
1 | /* |
2 | * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application |
3 | * Copyright (C) 2005-2014, 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 | * |
26 | * Anthony Minessale II <anthm@freeswitch.org> |
27 | * Michael Jerris <mike@jerris.com> |
28 | * Travis Cross <tc@traviscross.com> |
29 | * |
30 | * switch_ivr_originate.c -- IVR Library (originate) |
31 | * |
32 | */ |
33 | |
34 | #include <switch.h> |
35 | #define QUOTED_ESC_COMMA1 1 |
36 | #define UNQUOTED_ESC_COMMA2 2 |
37 | |
38 | static const switch_state_handler_table_t originate_state_handlers; |
39 | |
40 | static switch_status_t originate_on_consume_media_transmit(switch_core_session_t *session) |
41 | { |
42 | switch_channel_t *channel = switch_core_session_get_channel(session); |
43 | |
44 | if (!switch_channel_test_flag(channel, CF_PROXY_MODE) && switch_channel_test_flag(channel, CF_CONSUME_ON_ORIGINATE)) { |
45 | while (switch_channel_test_flag(channel, CF_ORIGINATING) && |
46 | switch_channel_get_state(channel) == CS_CONSUME_MEDIA && !switch_channel_test_flag(channel, CF_TAGGED)) { |
47 | if (!switch_channel_media_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_TRUE)) { |
48 | switch_yield(10000)switch_sleep(10000);; |
49 | } else { |
50 | switch_ivr_sleep(session, 10, SWITCH_FALSE, NULL((void*)0)); |
51 | } |
52 | switch_ivr_parse_all_messages(session); |
53 | } |
54 | } |
55 | |
56 | switch_channel_clear_state_handler(channel, &originate_state_handlers); |
57 | |
58 | return SWITCH_STATUS_FALSE; |
59 | } |
60 | |
61 | static switch_status_t originate_on_routing(switch_core_session_t *session) |
62 | { |
63 | switch_channel_t *channel = switch_core_session_get_channel(session); |
64 | |
65 | if (switch_channel_get_state(channel) == CS_ROUTING) { |
66 | /* put the channel in a passive state until it is answered */ |
67 | switch_channel_set_state(channel, CS_CONSUME_MEDIA)switch_channel_perform_set_state(channel, "src/switch_ivr_originate.c" , (const char *)__func__, 67, CS_CONSUME_MEDIA); |
68 | } |
69 | |
70 | return SWITCH_STATUS_FALSE; |
71 | } |
72 | |
73 | static const switch_state_handler_table_t originate_state_handlers = { |
74 | /*.on_init */ NULL((void*)0), |
75 | /*.on_routing */ originate_on_routing, |
76 | /*.on_execute */ NULL((void*)0), |
77 | /*.on_hangup */ NULL((void*)0), |
78 | /*.on_exchange_media */ NULL((void*)0), |
79 | /*.on_soft_execute */ originate_on_consume_media_transmit, |
80 | /*.on_consume_media */ originate_on_consume_media_transmit |
81 | }; |
82 | |
83 | |
84 | typedef struct { |
85 | switch_core_session_t *peer_session; |
86 | switch_channel_t *peer_channel; |
87 | switch_caller_profile_t *caller_profile; |
88 | uint8_t ring_ready; |
89 | uint8_t early_media; |
90 | uint8_t answered; |
91 | uint8_t tagged; |
92 | uint32_t per_channel_timelimit_sec; |
93 | uint32_t per_channel_progress_timelimit_sec; |
94 | uint32_t per_channel_delay_start; |
95 | } originate_status_t; |
96 | |
97 | |
98 | typedef struct { |
99 | switch_core_session_t *session; |
100 | int32_t idx; |
101 | uint32_t hups; |
102 | char *file; |
103 | char *error_file; |
104 | int confirm_timeout; |
105 | char key[80]; |
106 | uint8_t early_ok; |
107 | uint8_t ring_ready; |
108 | uint8_t instant_ringback; |
109 | uint8_t sent_ring; |
110 | uint8_t progress; |
111 | uint8_t return_ring_ready; |
112 | uint8_t monitor_early_media_ring; |
113 | uint8_t monitor_early_media_fail; |
114 | uint8_t gen_ringback; |
115 | uint8_t ignore_early_media; |
116 | uint8_t ignore_ring_ready; |
117 | int monitor_early_media_ring_count; |
118 | int monitor_early_media_ring_total; |
119 | int cancel_timeout; |
120 | int continue_on_timeout; |
121 | int ringback_ok; |
122 | int sending_ringback; |
123 | int bridge_early_media; |
124 | switch_thread_t *ethread; |
125 | switch_caller_profile_t *caller_profile_override; |
126 | switch_bool_t check_vars; |
127 | switch_memory_pool_t *pool; |
128 | } originate_global_t; |
129 | |
130 | |
131 | |
132 | typedef enum { |
133 | IDX_XFER = -5, |
134 | IDX_KEY_CANCEL = -4, |
135 | IDX_TIMEOUT = -3, |
136 | IDX_CANCEL = -2, |
137 | IDX_NADA = -1 |
138 | } abort_t; |
139 | |
140 | struct key_collect { |
141 | char *key; |
142 | char *file; |
143 | char *error_file; |
144 | int confirm_timeout; |
145 | switch_core_session_t *session; |
146 | }; |
147 | |
148 | static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void *obj) |
149 | { |
150 | struct key_collect *collect = (struct key_collect *) obj; |
151 | switch_channel_t *channel = switch_core_session_get_channel(collect->session); |
152 | char buf[10] = SWITCH_BLANK_STRING""; |
153 | switch_application_interface_t *application_interface = NULL((void*)0); |
154 | |
155 | if (collect->session) { |
156 | if (switch_core_session_read_lock(collect->session) != SWITCH_STATUS_SUCCESS) { |
157 | return NULL((void*)0); |
158 | } |
159 | } else { |
160 | return NULL((void*)0); |
161 | } |
162 | |
163 | switch_ivr_sleep(collect->session, 0, SWITCH_TRUE, NULL((void*)0)); |
164 | |
165 | if (!strcasecmp(collect->key, "exec")) { |
166 | char *data; |
167 | char *app_name, *app_data; |
168 | |
169 | if (!(data = collect->file)) { |
170 | goto wbreak; |
171 | } |
172 | |
173 | app_name = data; |
174 | |
175 | if ((app_data = strchr(app_name, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (app_name) && (' ') == '\0' ? (char *) __rawmemchr ( app_name, ' ') : __builtin_strchr (app_name, ' '))))) { |
176 | *app_data++ = '\0'; |
177 | } |
178 | |
179 | if ((application_interface = switch_loadable_module_get_application_interface(app_name)) == 0) { |
180 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(collect->session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 180, (const char*)(collect->session), SWITCH_LOG_ERROR, "Invalid Application %s\n", app_name); |
181 | switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER)switch_channel_perform_hangup(channel, "src/switch_ivr_originate.c" , (const char *)__func__, 181, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER ); |
182 | goto wbreak; |
183 | } |
184 | |
185 | if (!application_interface->application_function) { |
186 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(collect->session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 186, (const char*)(collect->session), SWITCH_LOG_ERROR, "No Function for %s\n", app_name); |
187 | switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER)switch_channel_perform_hangup(channel, "src/switch_ivr_originate.c" , (const char *)__func__, 187, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER ); |
188 | goto wbreak; |
189 | } |
190 | |
191 | switch_core_session_exec(collect->session, application_interface, app_data); |
192 | |
193 | if (switch_channel_up_nosig(channel)(switch_channel_get_state(channel) < CS_HANGUP)) { |
194 | switch_channel_set_flag(channel, CF_WINNER)switch_channel_set_flag_value(channel, CF_WINNER, 1); |
195 | switch_channel_set_variable(channel, "group_dial_status", "winner")switch_channel_set_variable_var_check(channel, "group_dial_status" , "winner", SWITCH_TRUE); |
196 | } |
197 | goto wbreak; |
198 | } |
199 | |
200 | if (!switch_channel_up_nosig(channel)(switch_channel_get_state(channel) < CS_HANGUP)) { |
201 | switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER)switch_channel_perform_hangup(channel, "src/switch_ivr_originate.c" , (const char *)__func__, 201, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER ); |
202 | goto wbreak; |
203 | } |
204 | |
205 | while (switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE)) { |
206 | switch_size_t len = strlen(collect->key); |
207 | const char *file = collect->file; |
208 | switch_status_t status; |
209 | |
210 | memset(buf, 0, sizeof(buf)); |
211 | |
212 | if (zstr(file)_zstr(file)) { |
213 | file = "silence"; |
214 | } |
215 | |
216 | status = switch_ivr_read(collect->session, |
217 | (uint32_t)len, |
218 | (uint32_t)len, |
219 | collect->file, NULL((void*)0), buf, sizeof(buf), collect->confirm_timeout, NULL((void*)0), 0); |
220 | |
221 | |
222 | if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK && status != SWITCH_STATUS_TOO_SMALL) { |
223 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(collect->session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 223, (const char*)(collect->session), SWITCH_LOG_ERROR, "%s Error Playing File!\n", |
224 | switch_channel_get_name(channel)); |
225 | switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER)switch_channel_perform_hangup(channel, "src/switch_ivr_originate.c" , (const char *)__func__, 225, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER ); |
226 | } |
227 | |
228 | if (!strcmp(collect->key, buf)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (collect->key) && __builtin_constant_p (buf) && (__s1_len = __builtin_strlen (collect->key), __s2_len = __builtin_strlen (buf), (!((size_t)(const void *)((collect->key) + 1) - (size_t )(const void *)(collect->key) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((buf) + 1) - (size_t)(const void * )(buf) == 1) || __s2_len >= 4)) ? __builtin_strcmp (collect ->key, buf) : (__builtin_constant_p (collect->key) && ((size_t)(const void *)((collect->key) + 1) - (size_t)(const void *)(collect->key) == 1) && (__s1_len = __builtin_strlen (collect->key), __s1_len < 4) ? (__builtin_constant_p ( buf) && ((size_t)(const void *)((buf) + 1) - (size_t) (const void *)(buf) == 1) ? __builtin_strcmp (collect->key , buf) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (buf); int __result = (((const unsigned char *) (const char *) (collect->key))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (collect->key) )[1] - __s2[1]); if (__s1_len > 1 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (collect ->key))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (collect ->key))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (buf) && ((size_t)(const void *)((buf) + 1) - (size_t )(const void *)(buf) == 1) && (__s2_len = __builtin_strlen (buf), __s2_len < 4) ? (__builtin_constant_p (collect-> key) && ((size_t)(const void *)((collect->key) + 1 ) - (size_t)(const void *)(collect->key) == 1) ? __builtin_strcmp (collect->key, buf) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (collect ->key); int __result = (((const unsigned char *) (const char *) (buf))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ( buf))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (buf ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (buf))[ 3] - __s2[3]); } } __result; })))) : __builtin_strcmp (collect ->key, buf)))); })) { |
229 | switch_channel_set_flag(channel, CF_WINNER)switch_channel_set_flag_value(channel, CF_WINNER, 1); |
230 | switch_channel_set_variable(channel, "group_dial_status", "winner")switch_channel_set_variable_var_check(channel, "group_dial_status" , "winner", SWITCH_TRUE); |
231 | goto wbreak; |
232 | } else if (collect->error_file) { |
233 | switch_ivr_play_file(collect->session, NULL((void*)0), collect->error_file, NULL((void*)0)); |
234 | } |
235 | } |
236 | wbreak: |
237 | |
238 | switch_core_session_rwunlock(collect->session); |
239 | |
240 | UNPROTECT_INTERFACE(application_interface)if (application_interface) {switch_mutex_lock(application_interface ->reflock); switch_thread_rwlock_unlock(application_interface ->rwlock); switch_thread_rwlock_unlock(application_interface ->parent->rwlock); application_interface->refs--; application_interface ->parent->refs--; switch_mutex_unlock(application_interface ->reflock);}; |
241 | |
242 | return NULL((void*)0); |
243 | } |
244 | |
245 | static void launch_collect_thread(struct key_collect *collect) |
246 | { |
247 | switch_thread_t *thread; |
248 | switch_threadattr_t *thd_attr = NULL((void*)0); |
249 | |
250 | switch_threadattr_create(&thd_attr, switch_core_session_get_pool(collect->session)); |
251 | switch_threadattr_detach_set(thd_attr, 1); |
252 | switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE240 * 1024); |
253 | switch_thread_create(&thread, thd_attr, collect_thread_run, collect, switch_core_session_get_pool(collect->session)); |
254 | } |
255 | |
256 | static int check_per_channel_timeouts(originate_global_t *oglobals, |
257 | originate_status_t *originate_status, int max, time_t start, switch_call_cause_t *force_reason) |
258 | { |
259 | int x = 0, i, delayed_channels = 0, active_channels = 0; |
260 | uint32_t early_exit_time = 0, delayed_min = 0; |
261 | |
262 | time_t elapsed = switch_epoch_time_now(NULL((void*)0)) - start; |
263 | |
264 | if (oglobals->cancel_timeout > 0) { |
265 | return 0; |
266 | } |
267 | for (i = 0; i < max; i++) { |
268 | if (originate_status[i].peer_channel && switch_channel_get_state(originate_status[i].peer_channel) != CS_DESTROY && |
269 | switch_channel_get_state(originate_status[i].peer_channel) != CS_REPORTING) { |
270 | if (originate_status[i].per_channel_delay_start) { |
271 | delayed_channels++; |
272 | } else { |
273 | active_channels++; |
274 | } |
275 | } |
276 | } |
277 | |
278 | if (active_channels == 0 && delayed_channels) { |
279 | for (i = 0; i < max; i++) { |
280 | if (originate_status[i].peer_channel && originate_status[i].per_channel_delay_start && |
281 | (!delayed_min || delayed_min > originate_status[i].per_channel_delay_start)) { |
282 | delayed_min = originate_status[i].per_channel_delay_start; |
283 | } |
284 | } |
285 | early_exit_time = delayed_min - (uint32_t) elapsed; |
286 | } |
287 | for (i = 0; i < max; i++) { |
288 | if (originate_status[i].peer_channel && originate_status[i].per_channel_delay_start && |
289 | (elapsed > originate_status[i].per_channel_delay_start || active_channels == 0)) { |
290 | if (active_channels == 0) { |
291 | if (originate_status[i].per_channel_timelimit_sec) { |
292 | if (originate_status[i].per_channel_timelimit_sec > early_exit_time) { |
293 | /* IN theory this check is not needed ( should just be if !0 then -= with no else), if its not 0 it should always be greater.... */ |
294 | originate_status[i].per_channel_timelimit_sec -= early_exit_time; |
295 | } else { |
296 | originate_status[i].per_channel_timelimit_sec = 1; |
297 | } |
298 | } |
299 | if (originate_status[i].per_channel_progress_timelimit_sec) { |
300 | if (originate_status[i].per_channel_progress_timelimit_sec > early_exit_time) { |
301 | /* IN theory this check is not needed ( should just be if !0 then -= with no else), if its not 0 it should always be greater.... */ |
302 | originate_status[i].per_channel_progress_timelimit_sec -= early_exit_time; |
303 | } else { |
304 | originate_status[i].per_channel_progress_timelimit_sec = 1; |
305 | } |
306 | } |
307 | originate_status[i].per_channel_delay_start -= delayed_min; |
308 | } else { |
309 | originate_status[i].per_channel_delay_start = 0; |
310 | } |
311 | |
312 | if (!originate_status[i].per_channel_delay_start) { |
313 | switch_channel_clear_flag(originate_status[i].peer_channel, CF_BLOCK_STATE); |
314 | } |
315 | } |
316 | |
317 | if (originate_status[i].peer_channel && switch_channel_up_nosig(originate_status[i].peer_channel)(switch_channel_get_state(originate_status[i].peer_channel) < CS_HANGUP)) { |
318 | if (originate_status[i].per_channel_progress_timelimit_sec && elapsed > originate_status[i].per_channel_progress_timelimit_sec && |
319 | !(switch_channel_test_flag(originate_status[i].peer_channel, CF_RING_READY) || |
320 | switch_channel_test_flag(originate_status[i].peer_channel, CF_ANSWERED) || |
321 | (!oglobals->monitor_early_media_ring && switch_channel_test_flag(originate_status[i].peer_channel, CF_EARLY_MEDIA)) |
322 | ) |
323 | ) { |
324 | switch_channel_hangup(originate_status[i].peer_channel, SWITCH_CAUSE_PROGRESS_TIMEOUT)switch_channel_perform_hangup(originate_status[i].peer_channel , "src/switch_ivr_originate.c", (const char *)__func__, 324, SWITCH_CAUSE_PROGRESS_TIMEOUT ); |
325 | *force_reason = SWITCH_CAUSE_PROGRESS_TIMEOUT; |
326 | x++; |
327 | } |
328 | if (originate_status[i].per_channel_timelimit_sec && elapsed > originate_status[i].per_channel_timelimit_sec) { |
329 | switch_channel_hangup(originate_status[i].peer_channel, SWITCH_CAUSE_ALLOTTED_TIMEOUT)switch_channel_perform_hangup(originate_status[i].peer_channel , "src/switch_ivr_originate.c", (const char *)__func__, 329, SWITCH_CAUSE_ALLOTTED_TIMEOUT ); |
330 | x++; |
331 | } |
332 | } |
333 | } |
334 | |
335 | return x; |
336 | } |
337 | |
338 | static switch_bool_t monitor_callback(switch_core_session_t *session, const char *app, const char *data) |
339 | { |
340 | if (app) { |
341 | switch_channel_t *channel = switch_core_session_get_channel(session); |
342 | if (!strcmp(app, "fail")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (app) && __builtin_constant_p ("fail") && (__s1_len = __builtin_strlen (app), __s2_len = __builtin_strlen ("fail" ), (!((size_t)(const void *)((app) + 1) - (size_t)(const void *)(app) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(("fail") + 1) - (size_t)(const void *)("fail") == 1) || __s2_len >= 4)) ? __builtin_strcmp (app, "fail") : (__builtin_constant_p (app) && ((size_t)(const void *)((app) + 1) - (size_t )(const void *)(app) == 1) && (__s1_len = __builtin_strlen (app), __s1_len < 4) ? (__builtin_constant_p ("fail") && ((size_t)(const void *)(("fail") + 1) - (size_t)(const void * )("fail") == 1) ? __builtin_strcmp (app, "fail") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("fail"); int __result = (((const unsigned char *) ( const char *) (app))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (app))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (app))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (app))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("fail") && ((size_t)(const void *)(("fail") + 1) - ( size_t)(const void *)("fail") == 1) && (__s2_len = __builtin_strlen ("fail"), __s2_len < 4) ? (__builtin_constant_p (app) && ((size_t)(const void *)((app) + 1) - (size_t)(const void *)( app) == 1) ? __builtin_strcmp (app, "fail") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (app); int __result = (((const unsigned char *) (const char *) ("fail"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("fail"))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ("fail"))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ("fail"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (app, "fail")))); })) { |
343 | const char *bd = switch_channel_get_variable(channel, "monitor_fail_dispo")switch_channel_get_variable_dup(channel, "monitor_fail_dispo" , SWITCH_TRUE, -1); |
344 | if (!bd) { |
345 | bd = "monitor_early_media_fail"; |
346 | } |
347 | switch_channel_set_variable(channel, "DIALSTATUS", "BUSY")switch_channel_set_variable_var_check(channel, "DIALSTATUS", "BUSY" , SWITCH_TRUE); |
348 | switch_channel_set_variable(channel, "originate_disposition", bd)switch_channel_set_variable_var_check(channel, "originate_disposition" , bd, SWITCH_TRUE); |
349 | switch_channel_hangup(channel, data ? switch_channel_str2cause(data) : SWITCH_CAUSE_USER_BUSY)switch_channel_perform_hangup(channel, "src/switch_ivr_originate.c" , (const char *)__func__, 349, data ? switch_channel_str2cause (data) : SWITCH_CAUSE_USER_BUSY); |
350 | } else if (!strcmp(app, "ring")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (app) && __builtin_constant_p ("ring") && (__s1_len = __builtin_strlen (app), __s2_len = __builtin_strlen ("ring" ), (!((size_t)(const void *)((app) + 1) - (size_t)(const void *)(app) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(("ring") + 1) - (size_t)(const void *)("ring") == 1) || __s2_len >= 4)) ? __builtin_strcmp (app, "ring") : (__builtin_constant_p (app) && ((size_t)(const void *)((app) + 1) - (size_t )(const void *)(app) == 1) && (__s1_len = __builtin_strlen (app), __s1_len < 4) ? (__builtin_constant_p ("ring") && ((size_t)(const void *)(("ring") + 1) - (size_t)(const void * )("ring") == 1) ? __builtin_strcmp (app, "ring") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("ring"); int __result = (((const unsigned char *) ( const char *) (app))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (app))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (app))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (app))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("ring") && ((size_t)(const void *)(("ring") + 1) - ( size_t)(const void *)("ring") == 1) && (__s2_len = __builtin_strlen ("ring"), __s2_len < 4) ? (__builtin_constant_p (app) && ((size_t)(const void *)((app) + 1) - (size_t)(const void *)( app) == 1) ? __builtin_strcmp (app, "ring") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (app); int __result = (((const unsigned char *) (const char *) ("ring"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("ring"))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ("ring"))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ("ring"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (app, "ring")))); })) { |
351 | originate_global_t *oglobals = (originate_global_t *) switch_channel_get_private(channel, "_oglobals_"); |
352 | const char *bd = switch_channel_get_variable(channel, "monitor_ring_dispo")switch_channel_get_variable_dup(channel, "monitor_ring_dispo" , SWITCH_TRUE, -1); |
353 | if (!bd) { |
354 | bd = "monitor_early_media_ring"; |
355 | } |
356 | switch_channel_set_variable(channel, "originate_disposition", bd)switch_channel_set_variable_var_check(channel, "originate_disposition" , bd, SWITCH_TRUE); |
357 | switch_channel_set_variable(channel, "DIALSTATUS", "EARLY")switch_channel_set_variable_var_check(channel, "DIALSTATUS", "EARLY" , SWITCH_TRUE); |
358 | |
359 | if (oglobals) { |
360 | if (oglobals->monitor_early_media_ring_total && ++oglobals->monitor_early_media_ring_count < oglobals->monitor_early_media_ring_total) { |
361 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 361, (const char*)(session), SWITCH_LOG_DEBUG, "Ring %d/%d\n", |
362 | oglobals->monitor_early_media_ring_count, oglobals->monitor_early_media_ring_total); |
363 | return SWITCH_TRUE; |
364 | } |
365 | |
366 | switch_channel_set_private(channel, "_oglobals_", NULL((void*)0)); |
367 | |
368 | if (!oglobals->progress) { |
369 | oglobals->progress = 1; |
370 | } |
371 | |
372 | if (!oglobals->ring_ready && !oglobals->ignore_ring_ready) { |
373 | oglobals->ring_ready = 1; |
374 | } |
375 | |
376 | if (!oglobals->ignore_early_media && !oglobals->early_ok) { |
377 | oglobals->early_ok = 1; |
378 | } |
379 | } |
380 | } |
381 | } |
382 | |
383 | return SWITCH_FALSE; |
384 | } |
385 | |
386 | static void inherit_codec(switch_channel_t *caller_channel, switch_core_session_t *session) |
387 | { |
388 | const char *var = switch_channel_get_variable(caller_channel, "inherit_codec")switch_channel_get_variable_dup(caller_channel, "inherit_codec" , SWITCH_TRUE, -1); |
389 | switch_channel_t *channel = switch_core_session_get_channel(session); |
390 | |
391 | if (!zstr(var)_zstr(var) && !strcasecmp(var, "passthru")) { |
392 | switch_channel_set_variable(caller_channel, "absolute_codec_string", switch_channel_get_variable(channel, "ep_codec_string"))switch_channel_set_variable_var_check(caller_channel, "absolute_codec_string" , switch_channel_get_variable_dup(channel, "ep_codec_string", SWITCH_TRUE, -1), SWITCH_TRUE); |
393 | } else if (switch_true(var)) { |
394 | switch_codec_implementation_t impl = { 0 }; |
395 | switch_codec_implementation_t video_impl = { 0 }; |
396 | char tmp[128] = ""; |
397 | |
398 | if (switch_core_session_get_read_impl(session, &impl) == SWITCH_STATUS_SUCCESS) { |
399 | const char *ep = switch_channel_get_variable(caller_channel, "ep_codec_string")switch_channel_get_variable_dup(caller_channel, "ep_codec_string" , SWITCH_TRUE, -1); |
400 | |
401 | if (switch_core_session_get_video_read_impl(session, &video_impl) == SWITCH_STATUS_SUCCESS) { |
402 | switch_snprintf(tmp, sizeof(tmp), "%s@%uh@%ui,%s", |
403 | impl.iananame, impl.samples_per_second, (uint32_t)impl.microseconds_per_packet / 1000, |
404 | video_impl.iananame); |
405 | } else { |
406 | switch_snprintf(tmp, sizeof(tmp), "%s@%uh@%ui", |
407 | impl.iananame, impl.samples_per_second, (uint32_t)impl.microseconds_per_packet / 1000); |
408 | } |
409 | |
410 | if (ep && switch_stristr(impl.iananame, ep)) { |
411 | switch_channel_set_variable(caller_channel, "absolute_codec_string", tmp)switch_channel_set_variable_var_check(caller_channel, "absolute_codec_string" , tmp, SWITCH_TRUE); |
412 | switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 412, (const char*)switch_channel_get_session (caller_channel), SWITCH_LOG_DEBUG, "Setting codec string on %s to %s\n", |
413 | switch_channel_get_name(caller_channel), tmp); |
414 | } else { |
415 | switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 415, (const char*)switch_channel_get_session (caller_channel), SWITCH_LOG_DEBUG, "Codec string %s not supported on %s, skipping inheritance\n", |
416 | tmp, switch_channel_get_name(caller_channel)); |
417 | } |
418 | } else { |
419 | switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 419, (const char*)switch_channel_get_session (caller_channel), SWITCH_LOG_WARNING, |
420 | "Error inheriting codec. Channel %s has no read codec yet.\n", |
421 | switch_channel_get_name(channel)); |
422 | } |
423 | |
424 | } |
425 | } |
426 | |
427 | static uint8_t check_channel_status(originate_global_t *oglobals, originate_status_t *originate_status, uint32_t len, switch_call_cause_t *force_reason) |
428 | { |
429 | |
430 | uint32_t i; |
431 | uint8_t rval = 0; |
432 | switch_channel_t *caller_channel = NULL((void*)0); |
433 | int pindex = -1; |
434 | char bug_key[256] = ""; |
435 | int send_ringback = 0; |
436 | uint8_t ring_ready_val = 0; |
437 | int pickups = 0; |
438 | |
439 | oglobals->hups = 0; |
440 | oglobals->idx = IDX_NADA; |
441 | |
442 | |
443 | if (oglobals->session) { |
444 | caller_channel = switch_core_session_get_channel(oglobals->session); |
445 | if (switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) { |
446 | caller_channel = NULL((void*)0); |
447 | } |
448 | } |
449 | |
450 | |
451 | for (i = 0; i < len; i++) { |
452 | if (originate_status[i].peer_channel && switch_channel_test_flag(originate_status[i].peer_channel, CF_CHANNEL_SWAP)) { |
453 | const char *key = switch_channel_get_variable(originate_status[i].peer_channel, "channel_swap_uuid")switch_channel_get_variable_dup(originate_status[i].peer_channel , "channel_swap_uuid", SWITCH_TRUE, -1); |
454 | switch_core_session_t *swap_session, *old_session; |
455 | |
456 | if ((swap_session = switch_core_session_locate(key)switch_core_session_perform_locate(key, "src/switch_ivr_originate.c" , (const char *)__func__, 456))) { |
457 | switch_channel_clear_flag(originate_status[i].peer_channel, CF_CHANNEL_SWAP); |
458 | switch_channel_hangup(originate_status[i].peer_channel, SWITCH_CAUSE_PICKED_OFF)switch_channel_perform_hangup(originate_status[i].peer_channel , "src/switch_ivr_originate.c", (const char *)__func__, 458, SWITCH_CAUSE_PICKED_OFF ); |
459 | |
460 | switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(originate_status[i].peer_channel)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 460, (const char*)switch_channel_get_session (originate_status[i].peer_channel), SWITCH_LOG_DEBUG, "Swapping %s for %s\n", |
461 | switch_core_session_get_name(swap_session)switch_channel_get_name(switch_core_session_get_channel(swap_session )), switch_channel_get_name(originate_status[i].peer_channel)); |
462 | |
463 | |
464 | old_session = originate_status[i].peer_session; |
465 | originate_status[i].peer_session = swap_session; |
466 | originate_status[i].peer_channel = switch_core_session_get_channel(originate_status[i].peer_session); |
467 | originate_status[i].caller_profile = switch_channel_get_caller_profile(originate_status[i].peer_channel); |
468 | switch_channel_set_flag(originate_status[i].peer_channel, CF_ORIGINATING)switch_channel_set_flag_value(originate_status[i].peer_channel , CF_ORIGINATING, 1); |
469 | |
470 | switch_channel_answer(originate_status[i].peer_channel)switch_channel_perform_answer(originate_status[i].peer_channel , "src/switch_ivr_originate.c", (const char *)__func__, 470); |
471 | |
472 | switch_channel_set_variable(originate_status[i].peer_channel, "picked_up_uuid", switch_core_session_get_uuid(old_session))switch_channel_set_variable_var_check(originate_status[i].peer_channel , "picked_up_uuid", switch_core_session_get_uuid(old_session) , SWITCH_TRUE); |
473 | switch_channel_execute_on(originate_status[i].peer_channel, "execute_on_pickup"); |
474 | switch_channel_api_on(originate_status[i].peer_channel, "api_on_pickup"); |
475 | |
476 | switch_core_session_rwunlock(old_session); |
477 | break; |
478 | } |
479 | } |
480 | } |
481 | |
482 | for (i = 0; i < len; i++) { |
483 | switch_channel_state_t state; |
484 | |
485 | if (originate_status[i].tagged && originate_status[i].peer_session) { |
486 | switch_channel_t *channel = switch_core_session_get_channel(originate_status[i].peer_session); |
487 | uint32_t j; |
488 | |
489 | if (switch_channel_down_nosig(channel)(switch_channel_get_state(channel) >= CS_HANGUP)) { |
490 | switch_call_cause_t cause = switch_channel_get_cause(channel); |
491 | |
492 | for (j = 0; j < len; j++) { |
493 | channel = switch_core_session_get_channel(originate_status[j].peer_session); |
494 | switch_channel_hangup(channel, cause)switch_channel_perform_hangup(channel, "src/switch_ivr_originate.c" , (const char *)__func__, 494, cause); |
495 | } |
496 | oglobals->hups = len; |
497 | rval = 0; |
498 | goto end; |
499 | } |
500 | } |
501 | |
502 | |
503 | if (originate_status[i].peer_channel && switch_channel_test_flag(originate_status[i].peer_channel, CF_PICKUP)) { |
504 | pickups++; |
505 | } |
506 | |
507 | if (!(originate_status[i].peer_channel && originate_status[i].peer_session)) { |
508 | oglobals->hups++; |
509 | continue; |
510 | } |
511 | |
512 | if ((ring_ready_val = (uint8_t)switch_channel_test_flag(originate_status[i].peer_channel, CF_RING_READY))) { |
513 | if (!originate_status[i].ring_ready) { |
514 | originate_status[i].ring_ready = ring_ready_val; |
515 | } |
516 | |
517 | if (oglobals->sending_ringback == 1) { |
518 | send_ringback++; |
519 | pindex = (uint32_t) i; |
520 | } else { |
521 | if (!oglobals->ring_ready) { |
522 | oglobals->ring_ready = ring_ready_val; |
523 | if (caller_channel && !oglobals->ignore_ring_ready) { |
524 | if (len == 1) { |
525 | switch_channel_pass_callee_id(originate_status[0].peer_channel, caller_channel); |
526 | } |
527 | switch_channel_ring_ready_value(caller_channel, ring_ready_val)switch_channel_perform_ring_ready_value(caller_channel, ring_ready_val , "src/switch_ivr_originate.c", (const char *)__func__, 527); |
528 | oglobals->sent_ring = ring_ready_val; |
529 | } |
530 | } |
531 | } |
532 | } |
533 | |
534 | if (switch_channel_test_flag(originate_status[i].peer_channel, CF_EARLY_MEDIA)) { |
535 | |
536 | if (oglobals->ignore_early_media == 3 && oglobals->bridge_early_media == -1) { |
537 | oglobals->bridge_early_media = i; |
538 | oglobals->ringback_ok = 1; |
539 | } |
540 | |
541 | if (oglobals->sending_ringback == 1) { |
542 | send_ringback++; |
543 | pindex = (uint32_t) i; |
544 | } else if (!oglobals->sent_ring && oglobals->ignore_early_media == 2 && len == 1 && caller_channel && !oglobals->ignore_ring_ready) { |
545 | switch_channel_pass_callee_id(originate_status[0].peer_channel, caller_channel); |
546 | switch_channel_ring_ready(caller_channel)switch_channel_perform_ring_ready_value(caller_channel, SWITCH_RING_READY_RINGING , "src/switch_ivr_originate.c", (const char *)__func__, 546); |
547 | oglobals->sent_ring = 1; |
548 | } |
549 | |
550 | if (!originate_status[i].early_media) { |
551 | originate_status[i].early_media = 1; |
552 | if (oglobals->early_ok) { |
553 | pindex = i; |
554 | } |
555 | |
556 | if (oglobals->monitor_early_media_fail) { |
557 | const char *var = switch_channel_get_variable(originate_status[i].peer_channel, "monitor_early_media_fail")switch_channel_get_variable_dup(originate_status[i].peer_channel , "monitor_early_media_fail", SWITCH_TRUE, -1); |
558 | if (!zstr(var)_zstr(var)) { |
559 | char *fail_array[128] = { 0 }; |
560 | int fail_count = 0; |
561 | char *fail_data = strdup(var)(__extension__ (__builtin_constant_p (var) && ((size_t )(const void *)((var) + 1) - (size_t)(const void *)(var) == 1 ) ? (((const char *) (var))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (var) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, var, __len); __retval ; })) : __strdup (var))); |
562 | int fx; |
563 | int y = 0; |
564 | |
565 | switch_assert(fail_data)((fail_data) ? (void) (0) : __assert_fail ("fail_data", "src/switch_ivr_originate.c" , 565, __PRETTY_FUNCTION__)); |
566 | fail_count = switch_separate_string(fail_data, '!', fail_array, (sizeof(fail_array) / sizeof(fail_array[0]))); |
567 | |
568 | for (fx = 0; fx < fail_count; fx++) { |
569 | char *cause = fail_array[fx]; |
570 | int hits = 2; |
571 | char *p, *q; |
572 | |
573 | if (!(p = strchr(cause, ':')(__extension__ (__builtin_constant_p (':') && !__builtin_constant_p (cause) && (':') == '\0' ? (char *) __rawmemchr (cause , ':') : __builtin_strchr (cause, ':'))))) { |
574 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 574, (const char*)(originate_status[i].peer_session ), SWITCH_LOG_ERROR, "Parse Error\n"); |
575 | continue; |
576 | } |
577 | *p++ = '\0'; |
578 | |
579 | |
580 | if (!p) { |
581 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 581, (const char*)(originate_status[i].peer_session ), SWITCH_LOG_ERROR, "Parse Error\n"); |
582 | continue; |
583 | } |
584 | |
585 | |
586 | if (!(hits = atoi(p))) { |
587 | hits = 2; |
588 | } |
589 | |
590 | |
591 | if (!(p = strchr(p, ':')(__extension__ (__builtin_constant_p (':') && !__builtin_constant_p (p) && (':') == '\0' ? (char *) __rawmemchr (p, ':') : __builtin_strchr (p, ':'))))) { |
592 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 592, (const char*)(originate_status[i].peer_session ), SWITCH_LOG_ERROR, "Parse Error\n"); |
593 | continue; |
594 | } |
595 | *p++ = '\0'; |
596 | |
597 | if (!p) { |
598 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 598, (const char*)(originate_status[i].peer_session ), SWITCH_LOG_ERROR, "Parse Error\n"); |
599 | continue; |
600 | } |
601 | |
602 | for (q = p; q && *q; q++) { |
603 | if (*q == '+') { |
604 | *q = ','; |
605 | } |
606 | } |
607 | switch_snprintf(bug_key, sizeof(bug_key), "monitor_early_media_fail_%d", ++y); |
608 | switch_ivr_tone_detect_session(originate_status[i].peer_session, bug_key, p, "r", 0, hits, "fail", cause, monitor_callback); |
609 | |
610 | } |
611 | |
612 | switch_safe_free(fail_data)if (fail_data) {free(fail_data);fail_data=((void*)0);}; |
613 | |
614 | } |
615 | } |
616 | |
617 | if (oglobals->monitor_early_media_ring) { |
618 | const char *var = switch_channel_get_variable(originate_status[i].peer_channel, "monitor_early_media_ring")switch_channel_get_variable_dup(originate_status[i].peer_channel , "monitor_early_media_ring", SWITCH_TRUE, -1); |
619 | const char *var_total = switch_channel_get_variable(originate_status[i].peer_channel, "monitor_early_media_ring_total")switch_channel_get_variable_dup(originate_status[i].peer_channel , "monitor_early_media_ring_total", SWITCH_TRUE, -1); |
620 | if (!zstr(var)_zstr(var)) { |
621 | char *ring_array[128] = { 0 }; |
622 | int ring_count = 0; |
623 | char *ring_data = strdup(var)(__extension__ (__builtin_constant_p (var) && ((size_t )(const void *)((var) + 1) - (size_t)(const void *)(var) == 1 ) ? (((const char *) (var))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (var) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, var, __len); __retval ; })) : __strdup (var))); |
624 | int fx; |
625 | int y = 0; |
626 | |
627 | switch_assert(ring_data)((ring_data) ? (void) (0) : __assert_fail ("ring_data", "src/switch_ivr_originate.c" , 627, __PRETTY_FUNCTION__)); |
628 | ring_count = switch_separate_string(ring_data, '!', ring_array, (sizeof(ring_array) / sizeof(ring_array[0]))); |
629 | |
630 | for (fx = 0; fx < ring_count; fx++) { |
631 | int hits = 2; |
632 | char *p = ring_array[fx], *q; |
633 | |
634 | if (!p) { |
635 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 635, (const char*)(originate_status[i].peer_session ), SWITCH_LOG_ERROR, "Parse Error\n"); |
636 | continue; |
637 | } |
638 | |
639 | if (!(hits = atoi(p))) { |
640 | hits = 2; |
641 | } |
642 | |
643 | if (!(p = strchr(p, ':')(__extension__ (__builtin_constant_p (':') && !__builtin_constant_p (p) && (':') == '\0' ? (char *) __rawmemchr (p, ':') : __builtin_strchr (p, ':'))))) { |
644 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 644, (const char*)(originate_status[i].peer_session ), SWITCH_LOG_ERROR, "Parse Error\n"); |
645 | continue; |
646 | } |
647 | *p++ = '\0'; |
648 | |
649 | if (!p) { |
650 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 650, (const char*)(originate_status[i].peer_session ), SWITCH_LOG_ERROR, "Parse Error\n"); |
651 | continue; |
652 | } |
653 | |
654 | for (q = p; q && *q; q++) { |
655 | if (*q == '+') { |
656 | *q = ','; |
657 | } |
658 | } |
659 | |
660 | switch_channel_set_private(originate_status[i].peer_channel, "_oglobals_", oglobals); |
661 | switch_snprintf(bug_key, sizeof(bug_key), "monitor_early_media_ring_%d", ++y); |
662 | switch_ivr_tone_detect_session(originate_status[i].peer_session, bug_key, p, "r", 0, hits, "ring", NULL((void*)0), monitor_callback); |
663 | |
664 | } |
665 | |
666 | if (var_total) { |
667 | int tmp = atoi(var_total); |
668 | if (tmp > 0 && tmp < 100) { |
669 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 669, (const char*)(originate_status[i].peer_session ), SWITCH_LOG_DEBUG, |
670 | "%s setting ring total to %d\n", switch_channel_get_name(originate_status[i].peer_channel), tmp); |
671 | oglobals->monitor_early_media_ring_total = tmp; |
672 | } |
673 | } |
674 | |
675 | switch_safe_free(ring_data)if (ring_data) {free(ring_data);ring_data=((void*)0);}; |
676 | |
677 | } |
678 | } |
679 | } |
680 | |
681 | if (!oglobals->monitor_early_media_ring) { |
682 | |
683 | if (!oglobals->progress) { |
684 | oglobals->progress = 1; |
685 | } |
686 | |
687 | if (!oglobals->ring_ready && !oglobals->ignore_ring_ready) { |
688 | oglobals->ring_ready = 1; |
689 | |
690 | } |
691 | } |
692 | } |
693 | |
694 | if (!switch_channel_test_flag(originate_status[i].peer_channel, CF_PARK) && |
695 | !switch_channel_test_flag(originate_status[i].peer_channel, CF_CONSUME_ON_ORIGINATE)) { |
696 | if (switch_core_session_messages_waiting(originate_status[i].peer_session)) { |
697 | if (switch_channel_test_flag(originate_status[i].peer_channel, CF_THREAD_SLEEPING)) { |
698 | switch_core_session_wake_session_thread(originate_status[i].peer_session); |
699 | } else { |
700 | switch_ivr_parse_all_events(originate_status[i].peer_session); |
701 | } |
702 | } |
703 | } |
704 | |
705 | if (switch_channel_test_flag(originate_status[i].peer_channel, CF_EARLY_OK)) { |
706 | if (!oglobals->early_ok) { |
707 | oglobals->early_ok = 1; |
708 | } |
709 | switch_channel_clear_flag(originate_status[i].peer_channel, CF_EARLY_OK); |
710 | } |
711 | |
712 | if (caller_channel && switch_channel_test_flag(caller_channel, CF_EARLY_OK)) { |
713 | if (!oglobals->early_ok) { |
714 | oglobals->early_ok = 1; |
715 | } |
716 | switch_channel_clear_flag(caller_channel, CF_EARLY_OK); |
717 | } |
718 | |
719 | state = switch_channel_get_state(originate_status[i].peer_channel); |
720 | if (state >= CS_HANGUP || state == CS_RESET || switch_channel_test_flag(originate_status[i].peer_channel, CF_TRANSFER) || |
721 | switch_channel_test_flag(originate_status[i].peer_channel, CF_REDIRECT) || |
722 | switch_channel_test_flag(originate_status[i].peer_channel, CF_BRIDGED) || |
723 | !switch_channel_test_flag(originate_status[i].peer_channel, CF_ORIGINATING) |
724 | ) { |
725 | (oglobals->hups)++; |
726 | if (switch_channel_test_flag(originate_status[i].peer_channel, CF_PICKUP)) { |
727 | pickups--; |
728 | } |
729 | } else if ((switch_channel_test_flag(originate_status[i].peer_channel, CF_ANSWERED) || |
730 | (oglobals->early_ok && switch_channel_test_flag(originate_status[i].peer_channel, CF_EARLY_MEDIA)) || |
731 | (oglobals->ring_ready && oglobals->return_ring_ready && len == 1 && |
732 | switch_channel_test_flag(originate_status[i].peer_channel, CF_RING_READY)) |
733 | ) |
734 | && !switch_channel_test_flag(originate_status[i].peer_channel, CF_TAGGED) |
735 | ) { |
736 | |
737 | if (!zstr(oglobals->key)_zstr(oglobals->key)) { |
738 | struct key_collect *collect; |
739 | |
740 | if (oglobals->cancel_timeout < 0) { |
741 | oglobals->cancel_timeout = 1; |
742 | } |
743 | |
744 | if ((collect = switch_core_session_alloc(originate_status[i].peer_session, sizeof(*collect))switch_core_perform_session_alloc(originate_status[i].peer_session , sizeof(*collect), "src/switch_ivr_originate.c", (const char *)__func__, 744))) { |
745 | switch_channel_set_flag(originate_status[i].peer_channel, CF_TAGGED)switch_channel_set_flag_value(originate_status[i].peer_channel , CF_TAGGED, 1); |
746 | if (!zstr(oglobals->key)_zstr(oglobals->key)) { |
747 | collect->key = switch_core_session_strdup(originate_status[i].peer_session, oglobals->key)switch_core_perform_session_strdup(originate_status[i].peer_session , oglobals->key, "src/switch_ivr_originate.c", (const char *)__func__, 747); |
748 | } |
749 | if (!zstr(oglobals->file)_zstr(oglobals->file)) { |
750 | collect->file = switch_core_session_strdup(originate_status[i].peer_session, oglobals->file)switch_core_perform_session_strdup(originate_status[i].peer_session , oglobals->file, "src/switch_ivr_originate.c", (const char *)__func__, 750); |
751 | } |
752 | if (!zstr(oglobals->error_file)_zstr(oglobals->error_file)) { |
753 | collect->error_file = switch_core_session_strdup(originate_status[i].peer_session, oglobals->error_file)switch_core_perform_session_strdup(originate_status[i].peer_session , oglobals->error_file, "src/switch_ivr_originate.c", (const char *)__func__, 753); |
754 | } |
755 | |
756 | if (oglobals->confirm_timeout) { |
757 | collect->confirm_timeout = oglobals->confirm_timeout; |
758 | } else { |
759 | collect->confirm_timeout = 5000; |
760 | } |
761 | |
762 | switch_channel_audio_sync(originate_status[i].peer_channel)switch_channel_perform_audio_sync(originate_status[i].peer_channel , "src/switch_ivr_originate.c", (const char *)__func__, 762); |
763 | collect->session = originate_status[i].peer_session; |
764 | launch_collect_thread(collect); |
765 | } |
766 | } else { |
767 | oglobals->idx = i; |
768 | pindex = (uint32_t) i; |
769 | rval = 0; |
770 | goto end; |
771 | |
772 | } |
773 | } else if (switch_channel_test_flag(originate_status[i].peer_channel, CF_WINNER)) { |
774 | oglobals->idx = i; |
775 | rval = 0; |
776 | pindex = (uint32_t) i; |
777 | goto end; |
778 | } |
779 | } |
780 | |
781 | if (oglobals->hups > 0 && oglobals->hups + pickups == len) { |
782 | rval = 0; |
783 | } else { |
784 | rval = 1; |
785 | } |
786 | |
787 | end: |
788 | |
789 | if (rval == 0 && pickups) { |
790 | for (i = 0; i < len; i++) { |
791 | if (originate_status[i].peer_channel && switch_channel_test_flag(originate_status[i].peer_channel, CF_PICKUP) && |
792 | switch_channel_up(originate_status[i].peer_channel)(switch_channel_check_signal(originate_status[i].peer_channel , SWITCH_TRUE) || switch_channel_get_state(originate_status[i ].peer_channel) < CS_HANGUP)) { |
793 | switch_channel_hangup(originate_status[i].peer_channel, SWITCH_CAUSE_NO_PICKUP)switch_channel_perform_hangup(originate_status[i].peer_channel , "src/switch_ivr_originate.c", (const char *)__func__, 793, SWITCH_CAUSE_NO_PICKUP ); |
794 | } |
795 | } |
796 | } |
797 | |
798 | |
799 | if (pindex > -1 && caller_channel && switch_channel_ready(caller_channel)switch_channel_test_ready(caller_channel, SWITCH_TRUE, SWITCH_FALSE ) && !switch_channel_media_ready(caller_channel)switch_channel_test_ready(caller_channel, SWITCH_TRUE, SWITCH_TRUE ) && |
800 | switch_channel_media_ready(originate_status[pindex].peer_channel)switch_channel_test_ready(originate_status[pindex].peer_channel , SWITCH_TRUE, SWITCH_TRUE)) { |
801 | inherit_codec(caller_channel, originate_status[pindex].peer_session); |
802 | } |
803 | |
804 | if (send_ringback) { |
805 | oglobals->sending_ringback++; |
806 | } |
807 | |
808 | return rval; |
809 | |
810 | } |
811 | |
812 | struct ringback { |
813 | switch_buffer_t *audio_buffer; |
814 | teletone_generation_session_t ts; |
815 | switch_file_handle_t fhb; |
816 | switch_file_handle_t *fh; |
817 | int silence; |
818 | uint8_t asis; |
819 | }; |
820 | |
821 | typedef struct ringback ringback_t; |
822 | |
823 | static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map) |
824 | { |
825 | ringback_t *tto = ts->user_data; |
826 | int wrote; |
827 | |
828 | if (!tto) { |
829 | return -1; |
830 | } |
831 | wrote = teletone_mux_tones(ts, map); |
832 | switch_buffer_write(tto->audio_buffer, ts->buffer, wrote * 2); |
833 | |
834 | return 0; |
835 | } |
836 | |
837 | |
838 | SWITCH_DECLARE(switch_status_t)__attribute__((visibility("default"))) switch_status_t switch_ivr_wait_for_answer(switch_core_session_t *session, switch_core_session_t *peer_session) |
839 | { |
840 | switch_channel_t *caller_channel = NULL((void*)0); |
841 | switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session); |
842 | const char *ringback_data = NULL((void*)0); |
843 | switch_frame_t write_frame = { 0 }; |
844 | switch_codec_t write_codec = { 0 }; |
845 | switch_codec_t *read_codec = switch_core_session_get_read_codec(session); |
846 | uint8_t pass = 0; |
847 | ringback_t ringback = { 0 }; |
848 | switch_frame_t *read_frame = NULL((void*)0); |
849 | switch_status_t status = SWITCH_STATUS_SUCCESS; |
850 | int timelimit = 60; |
851 | const char *var; |
852 | switch_time_t start = 0; |
853 | const char *cancel_key = NULL((void*)0); |
854 | switch_channel_state_t wait_state = 0; |
855 | |
856 | switch_assert(peer_channel)((peer_channel) ? (void) (0) : __assert_fail ("peer_channel", "src/switch_ivr_originate.c", 856, __PRETTY_FUNCTION__)); |
857 | |
858 | if (switch_channel_get_state(peer_channel) == CS_RESET) { |
859 | switch_channel_set_state(peer_channel, CS_SOFT_EXECUTE)switch_channel_perform_set_state(peer_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 859, CS_SOFT_EXECUTE); |
860 | } |
861 | |
862 | if (session) { |
863 | caller_channel = switch_core_session_get_channel(session); |
864 | } |
865 | |
866 | if ((switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA))) { |
867 | goto end; |
868 | } |
869 | |
870 | switch_zmalloc(write_frame.data, SWITCH_RECOMMENDED_BUFFER_SIZE)(void)((((write_frame.data = calloc(1, (8192)))) ? (void) (0) : __assert_fail ("(write_frame.data = calloc(1, (8192)))", "src/switch_ivr_originate.c" , 870, __PRETTY_FUNCTION__)),write_frame.data); |
871 | write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE8192; |
872 | |
873 | if (caller_channel && (var = switch_channel_get_variable(caller_channel, SWITCH_CALL_TIMEOUT_VARIABLE)switch_channel_get_variable_dup(caller_channel, "call_timeout" , SWITCH_TRUE, -1))) { |
874 | timelimit = atoi(var); |
875 | if (timelimit < 0) { |
876 | timelimit = 60; |
877 | } |
878 | } |
879 | |
880 | timelimit *= 1000000; |
881 | start = switch_micro_time_now(); |
882 | |
883 | if (caller_channel) { |
884 | cancel_key = switch_channel_get_variable(caller_channel, "origination_cancel_key")switch_channel_get_variable_dup(caller_channel, "origination_cancel_key" , SWITCH_TRUE, -1); |
885 | |
886 | if (switch_channel_test_flag(caller_channel, CF_ANSWERED)) { |
887 | ringback_data = switch_channel_get_variable(caller_channel, "transfer_ringback")switch_channel_get_variable_dup(caller_channel, "transfer_ringback" , SWITCH_TRUE, -1); |
888 | } |
889 | |
890 | if (!ringback_data) { |
891 | ringback_data = switch_channel_get_variable(caller_channel, "ringback")switch_channel_get_variable_dup(caller_channel, "ringback", SWITCH_TRUE , -1); |
892 | } |
893 | |
894 | if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE) || switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA)) { |
895 | ringback_data = NULL((void*)0); |
896 | } else if (zstr(ringback_data)_zstr(ringback_data)) { |
897 | if ((var = switch_channel_get_variable(caller_channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)switch_channel_get_variable_dup(caller_channel, "send_silence_when_idle" , SWITCH_TRUE, -1))) { |
898 | int sval = atoi(var); |
899 | |
900 | if (sval) { |
901 | ringback_data = switch_core_session_sprintf(session, "silence:%d", sval); |
902 | } |
903 | } |
904 | } |
905 | } |
906 | |
907 | |
908 | if (read_codec && ringback_data) { |
909 | if (switch_is_file_path(ringback_data)) { |
910 | if (!(strrchr(ringback_data, '.') || strstr(ringback_data, SWITCH_URL_SEPARATOR"://"))) { |
911 | ringback.asis++; |
912 | } |
913 | } |
914 | |
915 | |
916 | |
917 | if (!ringback.asis) { |
918 | if ((pass = (uint8_t) switch_test_flag(read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH)((read_codec)->flags & SWITCH_CODEC_FLAG_PASSTHROUGH))) { |
919 | goto no_ringback; |
920 | } |
921 | |
922 | if (switch_core_codec_init(&write_codec,switch_core_codec_init_with_bitrate(&write_codec, "L16", ( (void*)0), read_codec->implementation->actual_samples_per_second , read_codec->implementation->microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE , ((void*)0), switch_core_session_get_pool(session)) |
923 | "L16",switch_core_codec_init_with_bitrate(&write_codec, "L16", ( (void*)0), read_codec->implementation->actual_samples_per_second , read_codec->implementation->microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE , ((void*)0), switch_core_session_get_pool(session)) |
924 | NULL,switch_core_codec_init_with_bitrate(&write_codec, "L16", ( (void*)0), read_codec->implementation->actual_samples_per_second , read_codec->implementation->microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE , ((void*)0), switch_core_session_get_pool(session)) |
925 | read_codec->implementation->actual_samples_per_second,switch_core_codec_init_with_bitrate(&write_codec, "L16", ( (void*)0), read_codec->implementation->actual_samples_per_second , read_codec->implementation->microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE , ((void*)0), switch_core_session_get_pool(session)) |
926 | read_codec->implementation->microseconds_per_packet / 1000,switch_core_codec_init_with_bitrate(&write_codec, "L16", ( (void*)0), read_codec->implementation->actual_samples_per_second , read_codec->implementation->microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE , ((void*)0), switch_core_session_get_pool(session)) |
927 | 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,switch_core_codec_init_with_bitrate(&write_codec, "L16", ( (void*)0), read_codec->implementation->actual_samples_per_second , read_codec->implementation->microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE , ((void*)0), switch_core_session_get_pool(session)) |
928 | switch_core_session_get_pool(session))switch_core_codec_init_with_bitrate(&write_codec, "L16", ( (void*)0), read_codec->implementation->actual_samples_per_second , read_codec->implementation->microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE , ((void*)0), switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { |
929 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 929, (const char*)(session), SWITCH_LOG_ERROR, "Codec Error!\n"); |
930 | if (caller_channel) { |
931 | switch_channel_hangup(caller_channel, SWITCH_CAUSE_BEARERCAPABILITY_NOTIMPL)switch_channel_perform_hangup(caller_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 931, SWITCH_CAUSE_BEARERCAPABILITY_NOTIMPL ); |
932 | } |
933 | read_codec = NULL((void*)0); |
934 | goto done; |
935 | } else { |
936 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 936, (const char*)(session), SWITCH_LOG_DEBUG, |
937 | "Raw Codec Activation Success L16@%uhz 1 channel %dms\n", |
938 | read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_packet / 1000); |
939 | |
940 | write_frame.codec = &write_codec; |
941 | write_frame.datalen = read_codec->implementation->decoded_bytes_per_packet; |
942 | write_frame.samples = write_frame.datalen / 2; |
943 | memset(write_frame.data, 255, write_frame.datalen); |
944 | switch_core_session_set_read_codec(session, &write_codec); |
945 | } |
946 | } |
947 | |
948 | if (switch_channel_test_flag(caller_channel, CF_DISABLE_RINGBACK)) { |
949 | ringback_data = NULL((void*)0); |
950 | } |
951 | |
952 | if (ringback_data) { |
953 | char *tmp_data = NULL((void*)0); |
954 | |
955 | if (switch_is_file_path(ringback_data)) { |
956 | char *ext; |
957 | |
958 | if (ringback.asis) { |
959 | write_frame.codec = read_codec; |
960 | ext = read_codec->implementation->iananame; |
961 | tmp_data = switch_mprintf("%s.%s", ringback_data, ext); |
962 | ringback_data = tmp_data; |
963 | } |
964 | |
965 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 965, (const char*)(session), SWITCH_LOG_DEBUG, "Play Ringback File [%s]\n", ringback_data); |
966 | |
967 | ringback.fhb.channels = read_codec->implementation->number_of_channels; |
968 | ringback.fhb.samplerate = read_codec->implementation->actual_samples_per_second; |
969 | if (switch_core_file_open(&ringback.fhb,switch_core_perform_file_open("src/switch_ivr_originate.c", ( const char *)__func__, 973, &ringback.fhb, ringback_data, read_codec->implementation->number_of_channels, read_codec ->implementation->actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) |
970 | ringback_data,switch_core_perform_file_open("src/switch_ivr_originate.c", ( const char *)__func__, 973, &ringback.fhb, ringback_data, read_codec->implementation->number_of_channels, read_codec ->implementation->actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) |
971 | read_codec->implementation->number_of_channels,switch_core_perform_file_open("src/switch_ivr_originate.c", ( const char *)__func__, 973, &ringback.fhb, ringback_data, read_codec->implementation->number_of_channels, read_codec ->implementation->actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) |
972 | read_codec->implementation->actual_samples_per_second,switch_core_perform_file_open("src/switch_ivr_originate.c", ( const char *)__func__, 973, &ringback.fhb, ringback_data, read_codec->implementation->number_of_channels, read_codec ->implementation->actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) |
973 | SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL)switch_core_perform_file_open("src/switch_ivr_originate.c", ( const char *)__func__, 973, &ringback.fhb, ringback_data, read_codec->implementation->number_of_channels, read_codec ->implementation->actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) != SWITCH_STATUS_SUCCESS) { |
974 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 974, (const char*)(session), SWITCH_LOG_ERROR, "Error Playing File\n"); |
975 | switch_safe_free(tmp_data)if (tmp_data) {free(tmp_data);tmp_data=((void*)0);}; |
976 | goto done; |
977 | } |
978 | ringback.fh = &ringback.fhb; |
979 | } else { |
980 | if (!strncasecmp(ringback_data, "silence", 7)) { |
981 | const char *p = ringback_data + 7; |
982 | if (*p == ':') { |
983 | p++; |
984 | if (p) { |
985 | ringback.silence = atoi(p); |
986 | } |
987 | } |
988 | SWITCH_IVR_VERIFY_SILENCE_DIVISOR(ringback.silence){ if ((ringback.silence) <= 0 && (ringback.silence ) != -1) { ringback.silence = 400; } }; |
989 | } else { |
990 | switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0); |
991 | switch_buffer_set_loops(ringback.audio_buffer, -1); |
992 | |
993 | teletone_init_session(&ringback.ts, 0, teletone_handler, &ringback); |
994 | ringback.ts.rate = read_codec->implementation->actual_samples_per_second; |
995 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 995, (const char*)(session), SWITCH_LOG_DEBUG, "Play Ringback Tone [%s]\n", ringback_data); |
996 | if (teletone_run(&ringback.ts, ringback_data)) { |
997 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 997, (const char*)(session), SWITCH_LOG_ERROR, "Error Playing Tone\n"); |
998 | teletone_destroy_session(&ringback.ts); |
999 | switch_buffer_destroy(&ringback.audio_buffer); |
1000 | ringback_data = NULL((void*)0); |
1001 | } |
1002 | } |
1003 | } |
1004 | switch_safe_free(tmp_data)if (tmp_data) {free(tmp_data);tmp_data=((void*)0);}; |
1005 | } |
1006 | } |
1007 | |
1008 | no_ringback: |
1009 | |
1010 | if (caller_channel) { |
1011 | wait_state = switch_channel_get_state(caller_channel); |
1012 | } |
1013 | |
1014 | while (switch_channel_ready(peer_channel)switch_channel_test_ready(peer_channel, SWITCH_TRUE, SWITCH_FALSE ) && !switch_channel_media_ready(peer_channel)switch_channel_test_ready(peer_channel, SWITCH_TRUE, SWITCH_TRUE )) { |
1015 | int diff = (int) (switch_micro_time_now() - start); |
1016 | |
1017 | switch_ivr_parse_all_messages(session); |
1018 | |
1019 | if (caller_channel && cancel_key) { |
1020 | if (switch_channel_has_dtmf(caller_channel)) { |
1021 | switch_dtmf_t dtmf = { 0, 0 }; |
1022 | if (switch_channel_dequeue_dtmf(caller_channel, &dtmf) == SWITCH_STATUS_SUCCESS) { |
1023 | if (dtmf.digit == *cancel_key) { |
1024 | status = SWITCH_STATUS_FALSE; |
1025 | goto done; |
1026 | } |
1027 | } |
1028 | } |
1029 | } |
1030 | |
1031 | if (caller_channel && switch_channel_get_state(caller_channel) != wait_state) { |
1032 | goto done; |
1033 | } |
1034 | |
1035 | if (diff > timelimit) { |
1036 | status = SWITCH_STATUS_TIMEOUT; |
1037 | goto done; |
1038 | } |
1039 | |
1040 | if (switch_channel_media_ready(caller_channel)switch_channel_test_ready(caller_channel, SWITCH_TRUE, SWITCH_TRUE )) { |
1041 | status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); |
1042 | if (!SWITCH_READ_ACCEPTABLE(status)(status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK || status == SWITCH_STATUS_INUSE)) { |
1043 | break; |
1044 | } |
1045 | } else { |
1046 | read_frame = NULL((void*)0); |
1047 | } |
1048 | |
1049 | if (read_frame && !pass) { |
1050 | |
1051 | if (ringback.fh) { |
1052 | switch_size_t mlen, olen; |
1053 | unsigned int pos = 0; |
1054 | |
1055 | if (ringback.asis) { |
1056 | mlen = write_frame.codec->implementation->encoded_bytes_per_packet; |
1057 | } else { |
1058 | mlen = write_frame.codec->implementation->samples_per_packet; |
1059 | } |
1060 | |
1061 | olen = mlen; |
1062 | //if (ringback.fh->resampler && ringback.fh->resampler->rfactor > 1) { |
1063 | //olen = (switch_size_t) (olen * ringback.fh->resampler->rfactor); |
1064 | //} |
1065 | switch_core_file_read(ringback.fh, write_frame.data, &olen); |
1066 | |
1067 | if (olen == 0) { |
1068 | olen = mlen; |
1069 | ringback.fh->speed = 0; |
1070 | switch_core_file_seek(ringback.fh, &pos, 0, SEEK_SET0); |
1071 | switch_core_file_read(ringback.fh, write_frame.data, &olen); |
1072 | if (olen == 0) { |
1073 | switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1073, (const char*)switch_channel_get_session (caller_channel), SWITCH_LOG_ERROR, |
1074 | "Failure to read or re-read after seeking to beginning on file [%s]\n", ringback.fh->file_path); |
1075 | break; |
1076 | } |
1077 | } |
1078 | write_frame.datalen = (uint32_t) (ringback.asis ? olen : olen * 2 * ringback.fh->channels); |
1079 | } else if (ringback.audio_buffer) { |
1080 | if ((write_frame.datalen = (uint32_t) switch_buffer_read_loop(ringback.audio_buffer, |
1081 | write_frame.data, |
1082 | write_frame.codec->implementation->decoded_bytes_per_packet)) <= 0) { |
1083 | break; |
1084 | } |
1085 | } else if (ringback.silence) { |
1086 | write_frame.datalen = write_frame.codec->implementation->decoded_bytes_per_packet; |
1087 | switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.datalen / 2, |
1088 | write_frame.codec->implementation->number_of_channels, ringback.silence); |
1089 | } |
1090 | |
1091 | if ((ringback.fh || ringback.silence || ringback.audio_buffer) && write_frame.codec && write_frame.datalen) { |
1092 | if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { |
1093 | break; |
1094 | } |
1095 | } |
1096 | } else { |
1097 | switch_cond_next(); |
1098 | } |
1099 | } |
1100 | |
1101 | done: |
1102 | |
1103 | if (ringback.fh) { |
1104 | switch_core_file_close(ringback.fh); |
1105 | ringback.fh = NULL((void*)0); |
1106 | } else if (ringback.audio_buffer) { |
1107 | teletone_destroy_session(&ringback.ts); |
1108 | switch_buffer_destroy(&ringback.audio_buffer); |
1109 | } |
1110 | |
1111 | |
1112 | switch_ivr_parse_all_events(session); |
1113 | |
1114 | switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE); |
1115 | |
1116 | if (switch_core_codec_ready(&write_codec)) { |
1117 | switch_core_codec_destroy(&write_codec); |
1118 | } |
1119 | |
1120 | switch_safe_free(write_frame.data)if (write_frame.data) {free(write_frame.data);write_frame.data =((void*)0);}; |
1121 | |
1122 | end: |
1123 | |
1124 | if (!switch_channel_media_ready(peer_channel)switch_channel_test_ready(peer_channel, SWITCH_TRUE, SWITCH_TRUE )) { |
1125 | if (switch_channel_up_nosig(peer_channel)(switch_channel_get_state(peer_channel) < CS_HANGUP)) { |
1126 | switch_channel_hangup(peer_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER)switch_channel_perform_hangup(peer_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 1126, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER ); |
1127 | } |
1128 | status = SWITCH_STATUS_FALSE; |
1129 | } |
1130 | |
1131 | if (switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) { |
1132 | switch_channel_state_t peer_state = switch_channel_get_state(peer_channel); |
1133 | |
1134 | while (switch_channel_ready(peer_channel)switch_channel_test_ready(peer_channel, SWITCH_TRUE, SWITCH_FALSE ) && switch_channel_get_state(peer_channel) == peer_state) { |
1135 | switch_ivr_parse_all_messages(session); |
1136 | switch_channel_ready(caller_channel)switch_channel_test_ready(caller_channel, SWITCH_TRUE, SWITCH_FALSE ); |
1137 | switch_yield(20000)switch_sleep(20000);; |
1138 | } |
1139 | } |
1140 | |
1141 | if (caller_channel && !switch_channel_up_nosig(caller_channel)(switch_channel_get_state(caller_channel) < CS_HANGUP)) { |
1142 | status = SWITCH_STATUS_FALSE; |
1143 | } |
1144 | |
1145 | return status; |
1146 | } |
1147 | |
1148 | SWITCH_DECLARE(void)__attribute__((visibility("default"))) void switch_process_import(switch_core_session_t *session, switch_channel_t *peer_channel, const char *varname, const char *prefix) |
1149 | { |
1150 | const char *import, *val; |
1151 | switch_channel_t *caller_channel; |
1152 | |
1153 | switch_assert(session && peer_channel)((session && peer_channel) ? (void) (0) : __assert_fail ("session && peer_channel", "src/switch_ivr_originate.c" , 1153, __PRETTY_FUNCTION__)); |
1154 | caller_channel = switch_core_session_get_channel(session); |
1155 | |
1156 | if ((import = switch_channel_get_variable(caller_channel, varname)switch_channel_get_variable_dup(caller_channel, varname, SWITCH_TRUE , -1))) { |
1157 | char *mydata = switch_core_session_strdup(session, import)switch_core_perform_session_strdup(session, import, "src/switch_ivr_originate.c" , (const char *)__func__, 1157); |
1158 | int i, argc; |
1159 | char *argv[64] = { 0 }; |
1160 | |
1161 | if ((argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) { |
1162 | for (i = 0; i < argc; i++) { |
1163 | if ((val = switch_channel_get_variable(peer_channel, argv[i])switch_channel_get_variable_dup(peer_channel, argv[i], SWITCH_TRUE , -1))) { |
1164 | if (prefix) { |
1165 | char *var = switch_mprintf("%s%s", prefix, argv[i]); |
1166 | switch_channel_set_variable(caller_channel, var, val)switch_channel_set_variable_var_check(caller_channel, var, val , SWITCH_TRUE); |
1167 | free(var); |
1168 | } else { |
1169 | switch_channel_set_variable(caller_channel, argv[i], val)switch_channel_set_variable_var_check(caller_channel, argv[i] , val, SWITCH_TRUE); |
1170 | } |
1171 | } |
1172 | } |
1173 | } |
1174 | } |
1175 | } |
1176 | |
1177 | |
1178 | static switch_status_t setup_ringback(originate_global_t *oglobals, originate_status_t *originate_status, int len, |
1179 | const char *ringback_data, ringback_t *ringback, switch_frame_t *write_frame, switch_codec_t *write_codec) |
1180 | { |
1181 | switch_status_t status = SWITCH_STATUS_SUCCESS; |
1182 | switch_channel_t *caller_channel = switch_core_session_get_channel(oglobals->session); |
1183 | switch_codec_t *read_codec = NULL((void*)0); |
1184 | char *tmp_data = NULL((void*)0); |
1185 | |
1186 | if (!switch_channel_test_flag(caller_channel, CF_ANSWERED) |
1187 | && !switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) { |
1188 | if (oglobals->bridge_early_media > -1 && len == 1 && originate_status[0].peer_session && |
1189 | switch_channel_media_ready(originate_status[0].peer_channel)switch_channel_test_ready(originate_status[0].peer_channel, SWITCH_TRUE , SWITCH_TRUE)) { |
1190 | inherit_codec(caller_channel, originate_status[0].peer_session); |
1191 | } |
1192 | if ((status = switch_channel_pre_answer(caller_channel)switch_channel_perform_pre_answer(caller_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 1192)) != SWITCH_STATUS_SUCCESS) { |
1193 | switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1193, (const char*)switch_channel_get_session (caller_channel), SWITCH_LOG_DEBUG, "%s Media Establishment Failed.\n", |
1194 | switch_channel_get_name(caller_channel)); |
1195 | switch_goto_status(SWITCH_STATUS_BREAK, end)status = SWITCH_STATUS_BREAK; goto end; |
1196 | } |
1197 | } |
1198 | |
1199 | if (oglobals->session && (read_codec = switch_core_session_get_read_codec(oglobals->session))) { |
1200 | if (ringback_data && switch_is_file_path(ringback_data)) { |
1201 | if (!(strrchr(ringback_data, '.') || strstr(ringback_data, SWITCH_URL_SEPARATOR"://"))) { |
1202 | ringback->asis++; |
1203 | } |
1204 | } else if (oglobals->bridge_early_media > -1 && zstr(ringback_data)_zstr(ringback_data) && len == 1 && originate_status[0].peer_session) { |
1205 | switch_codec_implementation_t read_impl = { 0 }, write_impl = { 0 }; |
1206 | |
1207 | if (switch_channel_ready(originate_status[0].peer_channel)switch_channel_test_ready(originate_status[0].peer_channel, SWITCH_TRUE , SWITCH_FALSE) |
1208 | && switch_core_session_get_read_impl(originate_status[0].peer_session, &read_impl) == SWITCH_STATUS_SUCCESS |
1209 | && switch_core_session_get_write_impl(oglobals->session, &write_impl) == SWITCH_STATUS_SUCCESS) { |
1210 | if (read_impl.impl_id == write_impl.impl_id && |
1211 | read_impl.microseconds_per_packet == write_impl.microseconds_per_packet && |
1212 | read_impl.actual_samples_per_second == write_impl.actual_samples_per_second) { |
1213 | ringback->asis++; |
1214 | write_frame->codec = switch_core_session_get_write_codec(originate_status[0].peer_session); |
1215 | write_frame->datalen = write_frame->codec->implementation->decoded_bytes_per_packet; |
1216 | switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1216, (const char*)switch_channel_get_session (caller_channel), SWITCH_LOG_DEBUG, "bridge_early_media: passthrough enabled\n"); |
1217 | } else { |
1218 | switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1218, (const char*)switch_channel_get_session (caller_channel), SWITCH_LOG_DEBUG, "bridge_early_media: codecs don't match (%s@%uh@%di / %s@%uh@%di)\n", |
1219 | read_impl.iananame, read_impl.actual_samples_per_second, read_impl.microseconds_per_packet / 1000, |
1220 | write_impl.iananame, write_impl.actual_samples_per_second, write_impl.microseconds_per_packet / 1000); |
1221 | } |
1222 | } |
1223 | } |
1224 | |
1225 | if (!ringback->asis) { |
1226 | switch_codec_implementation_t peer_read_impl = { 0 }; |
1227 | |
1228 | if (switch_test_flag(read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH)((read_codec)->flags & SWITCH_CODEC_FLAG_PASSTHROUGH)) { |
1229 | switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1229, (const char*)switch_channel_get_session (caller_channel), SWITCH_LOG_WARNING, "%s Ringback not supported in passthrough codec mode.\n", |
1230 | switch_channel_get_name(caller_channel)); |
1231 | switch_goto_status(SWITCH_STATUS_GENERR, end)status = SWITCH_STATUS_GENERR; goto end; |
1232 | } |
1233 | |
1234 | if (oglobals->bridge_early_media > -1 && zstr(ringback_data)_zstr(ringback_data) && len == 1 && originate_status[0].peer_session) { |
1235 | switch_core_session_get_read_impl(originate_status[0].peer_session, &peer_read_impl); |
1236 | } else { |
1237 | switch_core_session_get_read_impl(oglobals->session, &peer_read_impl); |
1238 | } |
1239 | |
1240 | if (switch_core_codec_init(write_codec,switch_core_codec_init_with_bitrate(write_codec, "L16", ((void *)0), peer_read_impl.actual_samples_per_second, peer_read_impl .microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (oglobals->session)) |
1241 | "L16",switch_core_codec_init_with_bitrate(write_codec, "L16", ((void *)0), peer_read_impl.actual_samples_per_second, peer_read_impl .microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (oglobals->session)) |
1242 | NULL,switch_core_codec_init_with_bitrate(write_codec, "L16", ((void *)0), peer_read_impl.actual_samples_per_second, peer_read_impl .microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (oglobals->session)) |
1243 | peer_read_impl.actual_samples_per_second,switch_core_codec_init_with_bitrate(write_codec, "L16", ((void *)0), peer_read_impl.actual_samples_per_second, peer_read_impl .microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (oglobals->session)) |
1244 | peer_read_impl.microseconds_per_packet / 1000,switch_core_codec_init_with_bitrate(write_codec, "L16", ((void *)0), peer_read_impl.actual_samples_per_second, peer_read_impl .microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (oglobals->session)) |
1245 | 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,switch_core_codec_init_with_bitrate(write_codec, "L16", ((void *)0), peer_read_impl.actual_samples_per_second, peer_read_impl .microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (oglobals->session)) |
1246 | switch_core_session_get_pool(oglobals->session))switch_core_codec_init_with_bitrate(write_codec, "L16", ((void *)0), peer_read_impl.actual_samples_per_second, peer_read_impl .microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (oglobals->session)) == SWITCH_STATUS_SUCCESS) { |
1247 | |
1248 | |
1249 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals->session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1249, (const char*)(oglobals->session), SWITCH_LOG_DEBUG, |
1250 | "Raw Codec Activation Success L16@%uhz 1 channel %dms\n", |
1251 | peer_read_impl.actual_samples_per_second, peer_read_impl.microseconds_per_packet / 1000); |
1252 | write_frame->codec = write_codec; |
1253 | write_frame->datalen = read_codec->implementation->decoded_bytes_per_packet; |
1254 | write_frame->samples = write_frame->datalen / 2; |
1255 | memset(write_frame->data, 255, write_frame->datalen); |
1256 | switch_core_session_set_read_codec(oglobals->session, write_codec); |
1257 | } else { |
1258 | switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1258, (const char*)switch_channel_get_session (caller_channel), SWITCH_LOG_ERROR, "Codec Error!\n"); |
1259 | switch_channel_hangup(caller_channel, SWITCH_CAUSE_BEARERCAPABILITY_NOTIMPL)switch_channel_perform_hangup(caller_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 1259, SWITCH_CAUSE_BEARERCAPABILITY_NOTIMPL ); |
1260 | read_codec = NULL((void*)0); |
1261 | switch_goto_status(SWITCH_STATUS_BREAK, end)status = SWITCH_STATUS_BREAK; goto end; |
1262 | } |
1263 | } |
1264 | |
1265 | oglobals->gen_ringback = 1; |
1266 | |
1267 | if (zstr(ringback_data)_zstr(ringback_data)) { |
1268 | switch_goto_status(SWITCH_STATUS_SUCCESS, end)status = SWITCH_STATUS_SUCCESS; goto end; |
1269 | } |
1270 | |
1271 | if (switch_is_file_path(ringback_data)) { |
1272 | char *ext; |
1273 | |
1274 | if (ringback->asis) { |
1275 | write_frame->codec = read_codec; |
1276 | ext = read_codec->implementation->iananame; |
1277 | tmp_data = switch_mprintf("%s.%s", ringback_data, ext); |
1278 | ringback_data = tmp_data; |
1279 | } |
1280 | |
1281 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals->session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1281, (const char*)(oglobals->session), SWITCH_LOG_DEBUG, "Play Ringback File [%s]\n", ringback_data); |
1282 | |
1283 | if (switch_test_flag((&ringback->fhb), SWITCH_FILE_OPEN)(((&ringback->fhb))->flags & SWITCH_FILE_OPEN)) { |
1284 | switch_core_file_close(&ringback->fhb); |
1285 | } |
1286 | |
1287 | |
1288 | ringback->fhb.channels = read_codec->implementation->number_of_channels; |
1289 | ringback->fhb.samplerate = read_codec->implementation->actual_samples_per_second; |
1290 | if (switch_core_file_open(&ringback->fhb,switch_core_perform_file_open("src/switch_ivr_originate.c", ( const char *)__func__, 1294, &ringback->fhb, ringback_data , read_codec->implementation->number_of_channels, read_codec ->implementation->actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) |
1291 | ringback_data,switch_core_perform_file_open("src/switch_ivr_originate.c", ( const char *)__func__, 1294, &ringback->fhb, ringback_data , read_codec->implementation->number_of_channels, read_codec ->implementation->actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) |
1292 | read_codec->implementation->number_of_channels,switch_core_perform_file_open("src/switch_ivr_originate.c", ( const char *)__func__, 1294, &ringback->fhb, ringback_data , read_codec->implementation->number_of_channels, read_codec ->implementation->actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) |
1293 | read_codec->implementation->actual_samples_per_second,switch_core_perform_file_open("src/switch_ivr_originate.c", ( const char *)__func__, 1294, &ringback->fhb, ringback_data , read_codec->implementation->number_of_channels, read_codec ->implementation->actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) |
1294 | SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL)switch_core_perform_file_open("src/switch_ivr_originate.c", ( const char *)__func__, 1294, &ringback->fhb, ringback_data , read_codec->implementation->number_of_channels, read_codec ->implementation->actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) != SWITCH_STATUS_SUCCESS) { |
1295 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals->session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1295, (const char*)(oglobals->session), SWITCH_LOG_ERROR, "Error Playing File\n"); |
1296 | switch_safe_free(tmp_data)if (tmp_data) {free(tmp_data);tmp_data=((void*)0);}; |
1297 | switch_goto_status(SWITCH_STATUS_GENERR, end)status = SWITCH_STATUS_GENERR; goto end; |
1298 | //switch_goto_status(SWITCH_STATUS_FALSE, end); |
1299 | } |
1300 | ringback->fh = &ringback->fhb; |
1301 | |
1302 | } else if (!strncasecmp(ringback_data, "silence", 7)) { |
1303 | const char *c = ringback_data + 7; |
1304 | if (*c == ':') { |
1305 | c++; |
1306 | if (c) { |
1307 | ringback->silence = atoi(c); |
1308 | } |
1309 | } |
1310 | SWITCH_IVR_VERIFY_SILENCE_DIVISOR(ringback->silence){ if ((ringback->silence) <= 0 && (ringback-> silence) != -1) { ringback->silence = 400; } }; |
1311 | } else { |
1312 | switch_buffer_create_dynamic(&ringback->audio_buffer, 512, 1024, 0); |
1313 | switch_buffer_set_loops(ringback->audio_buffer, -1); |
1314 | |
1315 | teletone_init_session(&ringback->ts, 0, teletone_handler, ringback); |
1316 | ringback->ts.rate = read_codec->implementation->actual_samples_per_second; |
1317 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals->session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1317, (const char*)(oglobals->session), SWITCH_LOG_DEBUG, "Play Ringback Tone [%s]\n", ringback_data); |
1318 | /* ringback->ts.debug = 1; |
1319 | ringback->ts.debug_stream = switch_core_get_console(); */ |
1320 | |
1321 | if (teletone_run(&ringback->ts, ringback_data)) { |
1322 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals->session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1322, (const char*)(oglobals->session), SWITCH_LOG_ERROR, "Error Playing Tone\n"); |
1323 | teletone_destroy_session(&ringback->ts); |
1324 | switch_buffer_destroy(&ringback->audio_buffer); |
1325 | switch_goto_status(SWITCH_STATUS_GENERR, end)status = SWITCH_STATUS_GENERR; goto end; |
1326 | } |
1327 | } |
1328 | } |
1329 | |
1330 | end: |
1331 | |
1332 | switch_safe_free(tmp_data)if (tmp_data) {free(tmp_data);tmp_data=((void*)0);}; |
1333 | |
1334 | return status; |
1335 | |
1336 | } |
1337 | |
1338 | |
1339 | #define MAX_PEERS128 128 |
1340 | |
1341 | typedef struct { |
1342 | switch_core_session_t *session; |
1343 | switch_core_session_t *bleg; |
1344 | switch_call_cause_t cause; |
1345 | switch_call_cause_t cancel_cause; |
1346 | const char *bridgeto; |
1347 | uint32_t timelimit_sec; |
1348 | const switch_state_handler_table_t *table; |
1349 | const char *cid_name_override; |
1350 | const char *cid_num_override; |
1351 | switch_caller_profile_t *caller_profile_override; |
1352 | switch_event_t *ovars; |
1353 | switch_originate_flag_t flags; |
1354 | switch_status_t status; |
1355 | int done; |
1356 | switch_thread_t *thread; |
1357 | switch_mutex_t *mutex; |
1358 | } enterprise_originate_handle_t; |
1359 | |
1360 | |
1361 | struct ent_originate_ringback { |
1362 | switch_core_session_t *session; |
1363 | int running; |
1364 | const char *ringback_data; |
1365 | switch_thread_t *thread; |
1366 | }; |
1367 | |
1368 | static void *SWITCH_THREAD_FUNC enterprise_originate_thread(switch_thread_t *thread, void *obj) |
1369 | { |
1370 | enterprise_originate_handle_t *handle = (enterprise_originate_handle_t *) obj; |
1371 | |
1372 | handle->done = 0; |
1373 | handle->status = switch_ivr_originate(NULL((void*)0), &handle->bleg, &handle->cause, |
1374 | handle->bridgeto, handle->timelimit_sec, |
1375 | handle->table, |
1376 | handle->cid_name_override, |
1377 | handle->cid_num_override, handle->caller_profile_override, handle->ovars, handle->flags, &handle->cancel_cause); |
1378 | |
1379 | |
1380 | handle->done = 1; |
1381 | switch_mutex_lock(handle->mutex); |
1382 | switch_mutex_unlock(handle->mutex); |
1383 | |
1384 | if (handle->done != 2) { |
1385 | if (handle->status == SWITCH_STATUS_SUCCESS && handle->bleg) { |
1386 | switch_channel_t *channel = switch_core_session_get_channel(handle->bleg); |
1387 | |
1388 | switch_channel_set_variable(channel, "group_dial_status", "loser")switch_channel_set_variable_var_check(channel, "group_dial_status" , "loser", SWITCH_TRUE); |
1389 | switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE)switch_channel_perform_hangup(channel, "src/switch_ivr_originate.c" , (const char *)__func__, 1389, SWITCH_CAUSE_LOSE_RACE); |
1390 | switch_core_session_rwunlock(handle->bleg); |
1391 | } |
1392 | } |
1393 | |
1394 | return NULL((void*)0); |
1395 | } |
1396 | |
1397 | static void *SWITCH_THREAD_FUNC enterprise_originate_ringback_thread(switch_thread_t *thread, void *obj) |
1398 | { |
1399 | struct ent_originate_ringback *rb_data = (struct ent_originate_ringback *) obj; |
1400 | switch_core_session_t *session = rb_data->session; |
1401 | switch_channel_t *channel = switch_core_session_get_channel(rb_data->session); |
1402 | switch_status_t status = SWITCH_STATUS_FALSE; |
1403 | |
1404 | switch_core_session_read_lock(session); |
1405 | |
1406 | while (rb_data->running && switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE)) { |
1407 | switch_ivr_parse_all_messages(session); |
1408 | if (status != SWITCH_STATUS_BREAK) { |
1409 | if (zstr(rb_data->ringback_data)_zstr(rb_data->ringback_data) || !strcasecmp(rb_data->ringback_data, "silence")) { |
1410 | status = switch_ivr_collect_digits_callback(session, NULL((void*)0), 0, 0); |
1411 | } else if (switch_is_file_path(rb_data->ringback_data)) { |
1412 | status = switch_ivr_play_file(session, NULL((void*)0), rb_data->ringback_data, NULL((void*)0)); |
1413 | } else { |
1414 | status = switch_ivr_gentones(session, rb_data->ringback_data, 0, NULL((void*)0)); |
1415 | } |
1416 | } |
1417 | |
1418 | if (status == SWITCH_STATUS_BREAK) { |
1419 | switch_channel_set_flag(channel, CF_NOT_READY)switch_channel_set_flag_value(channel, CF_NOT_READY, 1); |
1420 | } |
1421 | } |
1422 | switch_core_session_rwunlock(session); |
1423 | |
1424 | rb_data->running = 0; |
1425 | return NULL((void*)0); |
1426 | } |
1427 | |
1428 | |
1429 | SWITCH_DECLARE(switch_status_t)__attribute__((visibility("default"))) switch_status_t switch_ivr_enterprise_originate(switch_core_session_t *session, |
1430 | switch_core_session_t **bleg, |
1431 | switch_call_cause_t *cause, |
1432 | const char *bridgeto, |
1433 | uint32_t timelimit_sec, |
1434 | const switch_state_handler_table_t *table, |
1435 | const char *cid_name_override, |
1436 | const char *cid_num_override, |
1437 | switch_caller_profile_t *caller_profile_override, |
1438 | switch_event_t *ovars, switch_originate_flag_t flags, |
1439 | switch_call_cause_t *cancel_cause) |
1440 | { |
1441 | int x_argc = 0; |
1442 | char *x_argv[MAX_PEERS128] = { 0 }; |
1443 | enterprise_originate_handle_t *hp = NULL((void*)0), handles[MAX_PEERS128] = { {0} }; |
1444 | int i; |
1445 | switch_caller_profile_t *cp = NULL((void*)0); |
1446 | switch_channel_t *channel = NULL((void*)0); |
1447 | char *data; |
1448 | switch_status_t status = SWITCH_STATUS_FALSE; |
1449 | switch_threadattr_t *thd_attr = NULL((void*)0); |
1450 | int running = 0, over = 0; |
1451 | switch_status_t tstatus = SWITCH_STATUS_FALSE; |
1452 | switch_memory_pool_t *pool; |
1453 | switch_event_header_t *hi = NULL((void*)0); |
1454 | struct ent_originate_ringback rb_data = { 0 }; |
1455 | const char *ringback_data = NULL((void*)0); |
1456 | switch_event_t *var_event = NULL((void*)0); |
1457 | int getcause = 1; |
1458 | |
1459 | *cause = SWITCH_CAUSE_SUCCESS; |
1460 | |
1461 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "src/switch_ivr_originate.c" , (const char *)__func__, 1461); |
1462 | |
1463 | if (zstr(bridgeto)_zstr(bridgeto)) { |
1464 | *cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; |
1465 | getcause = 0; |
1466 | switch_goto_status(SWITCH_STATUS_FALSE, end)status = SWITCH_STATUS_FALSE; goto end; |
1467 | } |
1468 | |
1469 | data = switch_core_strdup(pool, bridgeto)switch_core_perform_strdup(pool, bridgeto, "src/switch_ivr_originate.c" , (const char *)__func__, 1469); |
1470 | |
1471 | if (session) { |
1472 | switch_caller_profile_t *cpp = NULL((void*)0); |
1473 | channel = switch_core_session_get_channel(session); |
1474 | if ((cpp = switch_channel_get_caller_profile(channel))) { |
1475 | cp = switch_caller_profile_dup(pool, cpp); |
1476 | } |
1477 | } |
1478 | |
1479 | if (ovars) { |
1480 | var_event = ovars; |
1481 | } else { |
1482 | if (switch_event_create_plain(&var_event, SWITCH_EVENT_CHANNEL_DATA) != SWITCH_STATUS_SUCCESS) { |
1483 | abort(); |
1484 | } |
1485 | } |
1486 | |
1487 | if (session) { |
1488 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "ent_originate_aleg_uuid", switch_core_session_get_uuid(session)); |
1489 | } |
1490 | |
1491 | if (channel) { |
1492 | const char *tmp_var = NULL((void*)0); |
1493 | |
1494 | switch_channel_process_export(channel, NULL((void*)0), var_event, SWITCH_EXPORT_VARS_VARIABLE"export_vars"); |
1495 | |
1496 | if ((tmp_var = switch_channel_get_variable(channel, "effective_ani")switch_channel_get_variable_dup(channel, "effective_ani", SWITCH_TRUE , -1))) { |
1497 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "origination_ani", tmp_var); |
1498 | } |
1499 | |
1500 | if ((tmp_var = switch_channel_get_variable(channel, "effective_aniii")switch_channel_get_variable_dup(channel, "effective_aniii", SWITCH_TRUE , -1))) { |
1501 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "origination_aniii", tmp_var); |
1502 | } |
1503 | |
1504 | if ((tmp_var = switch_channel_get_variable(channel, "effective_caller_id_name")switch_channel_get_variable_dup(channel, "effective_caller_id_name" , SWITCH_TRUE, -1))) { |
1505 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "origination_caller_id_name", tmp_var); |
1506 | } |
1507 | |
1508 | if ((tmp_var = switch_channel_get_variable(channel, "effective_caller_id_number")switch_channel_get_variable_dup(channel, "effective_caller_id_number" , SWITCH_TRUE, -1))) { |
1509 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "origination_caller_id_number", tmp_var); |
1510 | } |
1511 | } |
1512 | |
1513 | /* strip leading spaces */ |
1514 | while (data && *data && *data == ' ') { |
1515 | data++; |
1516 | } |
1517 | |
1518 | /* extract channel variables, allowing multiple sets of braces */ |
1519 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1519, (const char*)(session), SWITCH_LOG_DEBUG, "Parsing ultra-global variables\n"); |
1520 | while (*data == '<') { |
1521 | char *parsed = NULL((void*)0); |
1522 | |
1523 | if (switch_event_create_brackets(data, '<', '>', ',', &var_event, &parsed, SWITCH_FALSE) != SWITCH_STATUS_SUCCESS || !parsed) { |
1524 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1524, (const char*)(session), SWITCH_LOG_ERROR, "Parse Error!\n"); |
1525 | switch_goto_status(SWITCH_STATUS_GENERR, done)status = SWITCH_STATUS_GENERR; goto done; |
1526 | } |
1527 | |
1528 | data = parsed; |
1529 | } |
1530 | |
1531 | /* strip leading spaces (again) */ |
1532 | while (data && *data && *data == ' ') { |
1533 | data++; |
1534 | } |
1535 | |
1536 | if (ovars && ovars != var_event) { |
1537 | for (hi = ovars->headers; hi; hi = hi->next) { |
1538 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, hi->name, hi->value); |
1539 | } |
1540 | } |
1541 | |
1542 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "ignore_early_media", "true"); |
1543 | |
1544 | if (!(x_argc = switch_separate_string_string(data, SWITCH_ENT_ORIGINATE_DELIM":_:", x_argv, MAX_PEERS128))) { |
1545 | *cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; |
1546 | getcause = 0; |
1547 | switch_goto_status(SWITCH_STATUS_FALSE, end)status = SWITCH_STATUS_FALSE; goto end; |
1548 | } |
1549 | |
1550 | switch_threadattr_create(&thd_attr, pool); |
1551 | switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE240 * 1024); |
1552 | |
1553 | for (i = 0; i < x_argc; i++) { |
1554 | handles[i].session = session; |
1555 | handles[i].bleg = NULL((void*)0); |
1556 | handles[i].cause = 0; |
1557 | handles[i].cancel_cause = 0; |
1558 | handles[i].bridgeto = x_argv[i]; |
1559 | handles[i].timelimit_sec = timelimit_sec; |
1560 | handles[i].table = table; |
1561 | handles[i].cid_name_override = cid_name_override; |
1562 | handles[i].cid_num_override = cid_num_override; |
1563 | handles[i].caller_profile_override = cp; |
1564 | switch_event_dup(&handles[i].ovars, var_event); |
1565 | handles[i].flags = flags; |
1566 | switch_mutex_init(&handles[i].mutex, SWITCH_MUTEX_NESTED0x1, pool); |
1567 | switch_mutex_lock(handles[i].mutex); |
1568 | switch_thread_create(&handles[i].thread, thd_attr, enterprise_originate_thread, &handles[i], pool); |
1569 | } |
1570 | |
1571 | if (channel && !switch_channel_test_flag(channel, CF_PROXY_MODE) && !switch_channel_test_flag(channel, CF_PROXY_MEDIA)) { |
1572 | if (switch_channel_test_flag(channel, CF_ANSWERED)) { |
1573 | ringback_data = switch_channel_get_variable(channel, "transfer_ringback")switch_channel_get_variable_dup(channel, "transfer_ringback", SWITCH_TRUE, -1); |
1574 | } |
1575 | |
1576 | if (!ringback_data) { |
1577 | ringback_data = switch_channel_get_variable(channel, "ringback")switch_channel_get_variable_dup(channel, "ringback", SWITCH_TRUE , -1); |
1578 | } |
1579 | |
1580 | if (ringback_data || switch_channel_media_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_TRUE)) { |
1581 | rb_data.ringback_data = ringback_data; |
1582 | rb_data.session = session; |
1583 | rb_data.running = 1; |
1584 | if (!switch_channel_media_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_TRUE)) { |
1585 | if (switch_channel_pre_answer(channel)switch_channel_perform_pre_answer(channel, "src/switch_ivr_originate.c" , (const char *)__func__, 1585) != SWITCH_STATUS_SUCCESS) { |
1586 | goto done; |
1587 | } |
1588 | } |
1589 | switch_thread_create(&rb_data.thread, thd_attr, enterprise_originate_ringback_thread, &rb_data, pool); |
1590 | } |
1591 | } |
1592 | |
1593 | |
1594 | for (;;) { |
1595 | running = 0; |
1596 | over = 0; |
1597 | |
1598 | if (channel && !switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE)) { |
1599 | break; |
1600 | } |
1601 | |
1602 | if (cancel_cause && *cancel_cause > 0) { |
1603 | break; |
1604 | } |
1605 | |
1606 | for (i = 0; i < x_argc; i++) { |
1607 | |
1608 | |
1609 | if (handles[i].done == 0) { |
1610 | running++; |
1611 | } else if (handles[i].done == 1) { |
1612 | if (handles[i].status == SWITCH_STATUS_SUCCESS) { |
1613 | handles[i].done = 2; |
1614 | hp = &handles[i]; |
1615 | goto done; |
1616 | } else { |
1617 | handles[i].done = -1; |
1618 | } |
1619 | } else { |
1620 | over++; |
1621 | } |
1622 | |
1623 | switch_yield(10000)switch_sleep(10000);; |
1624 | } |
1625 | |
1626 | if (!running || over == x_argc) { |
1627 | break; |
1628 | } |
1629 | } |
1630 | |
1631 | |
1632 | done: |
1633 | |
1634 | if (hp) { |
1635 | *cause = hp->cause; |
1636 | getcause = 0; |
1637 | status = hp->status; |
1638 | *bleg = hp->bleg; |
1639 | switch_mutex_unlock(hp->mutex); |
1640 | switch_thread_join(&tstatus, hp->thread); |
1641 | switch_event_destroy(&hp->ovars); |
1642 | } |
1643 | |
1644 | for (i = 0; i < x_argc; i++) { |
1645 | if (hp == &handles[i]) { |
1646 | continue; |
1647 | } |
1648 | |
1649 | if (cancel_cause && *cancel_cause > 0) { |
1650 | handles[i].cancel_cause = *cancel_cause; |
1651 | } else { |
1652 | handles[i].cancel_cause = SWITCH_CAUSE_LOSE_RACE; |
1653 | } |
1654 | } |
1655 | |
1656 | for (i = 0; i < x_argc; i++) { |
1657 | |
1658 | if (channel) { |
1659 | switch_channel_handle_cause(channel, handles[i].cause); |
1660 | } |
1661 | |
1662 | if (hp == &handles[i]) { |
1663 | continue; |
1664 | } |
1665 | switch_mutex_unlock(handles[i].mutex); |
1666 | |
1667 | if (getcause && *cause != handles[i].cause && handles[i].cause != SWITCH_CAUSE_LOSE_RACE && handles[i].cause != SWITCH_CAUSE_NO_PICKUP) { |
1668 | *cause = handles[i].cause; |
1669 | getcause++; |
1670 | } |
1671 | |
1672 | switch_thread_join(&tstatus, handles[i].thread); |
1673 | switch_event_destroy(&handles[i].ovars); |
1674 | } |
1675 | |
1676 | if (channel && rb_data.thread) { |
1677 | switch_channel_set_flag(channel, CF_NOT_READY)switch_channel_set_flag_value(channel, CF_NOT_READY, 1); |
1678 | switch_thread_join(&tstatus, rb_data.thread); |
1679 | switch_channel_clear_flag(channel, CF_NOT_READY); |
1680 | } |
1681 | |
1682 | |
1683 | end: |
1684 | |
1685 | if (getcause == 1 && *cause == SWITCH_CAUSE_SUCCESS) { |
1686 | *cause = SWITCH_CAUSE_NO_ANSWER; |
1687 | } |
1688 | |
1689 | if (channel) { |
1690 | if (*cause == SWITCH_CAUSE_SUCCESS) { |
1691 | switch_channel_set_variable(channel, "originate_disposition", "success")switch_channel_set_variable_var_check(channel, "originate_disposition" , "success", SWITCH_TRUE); |
1692 | } else { |
1693 | switch_channel_set_variable(channel, "originate_disposition", "failure")switch_channel_set_variable_var_check(channel, "originate_disposition" , "failure", SWITCH_TRUE); |
1694 | switch_channel_set_variable(channel, "hangup_cause", switch_channel_cause2str(*cause))switch_channel_set_variable_var_check(channel, "hangup_cause" , switch_channel_cause2str(*cause), SWITCH_TRUE); |
1695 | } |
1696 | } |
1697 | |
1698 | |
1699 | if (var_event && var_event != ovars) { |
1700 | switch_event_destroy(&var_event); |
1701 | } |
1702 | |
1703 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "src/switch_ivr_originate.c" , (const char *)__func__, 1703); |
1704 | |
1705 | return status; |
1706 | |
1707 | } |
1708 | |
1709 | struct early_state { |
1710 | originate_global_t *oglobals; |
1711 | originate_status_t *originate_status; |
1712 | switch_mutex_t *mutex; |
1713 | switch_buffer_t *buffer; |
1714 | int ready; |
1715 | ringback_t *ringback; |
1716 | int ttl; |
1717 | }; |
1718 | typedef struct early_state early_state_t; |
1719 | |
1720 | |
1721 | static void *SWITCH_THREAD_FUNC early_thread_run(switch_thread_t *thread, void *obj) |
1722 | { |
1723 | early_state_t *state = (early_state_t *) obj; |
1724 | originate_status_t originate_status[MAX_PEERS128] = { {0} }; |
1725 | int16_t mux_data[SWITCH_RECOMMENDED_BUFFER_SIZE8192 / 2] = { 0 }; |
1726 | int32_t sample; |
1727 | switch_codec_t read_codecs[MAX_PEERS128] = { {0} }; |
1728 | int i, x, ready = 0, answered = 0, ring_ready = 0; |
1729 | int16_t *data; |
1730 | uint32_t datalen = 0; |
1731 | switch_status_t status; |
1732 | switch_frame_t *read_frame = NULL((void*)0); |
1733 | switch_codec_implementation_t read_impl = { 0 }; |
1734 | |
1735 | for (i = 0; i < MAX_PEERS128 && i < state->ttl; i++) { |
1736 | if (switch_core_session_read_lock(state->originate_status[i].peer_session) == SWITCH_STATUS_SUCCESS) { |
1737 | originate_status[i].peer_session = state->originate_status[i].peer_session; |
1738 | originate_status[i].peer_channel = switch_core_session_get_channel(state->originate_status[i].peer_session); |
1739 | } |
1740 | } |
1741 | |
1742 | if (state->oglobals->session) { |
1743 | switch_core_session_get_read_impl(state->oglobals->session, &read_impl); |
1744 | } |
1745 | |
1746 | while (state->ready) { |
1747 | datalen = 0; |
1748 | memset(mux_data, 0, sizeof(mux_data)); |
1749 | ready = 0; |
1750 | answered = 0; |
1751 | |
1752 | for (i = 0; i < MAX_PEERS128 && i < state->ttl; i++) { |
1753 | switch_core_session_t *session = originate_status[i].peer_session; |
1754 | switch_channel_t *channel = originate_status[i].peer_channel; |
1755 | |
1756 | if (!session) { |
1757 | break; |
1758 | } |
1759 | |
1760 | if (!channel || !switch_channel_up(channel)(switch_channel_check_signal(channel, SWITCH_TRUE) || switch_channel_get_state (channel) < CS_HANGUP)) { |
1761 | continue; |
1762 | } |
1763 | |
1764 | if (switch_channel_media_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_TRUE)) { |
1765 | ready++; |
1766 | |
1767 | if (switch_channel_test_flag(channel, CF_RING_READY)) { |
1768 | ring_ready = 1; |
1769 | state->oglobals->bridge_early_media = -1; |
1770 | state->oglobals->ignore_early_media = 1; |
1771 | } |
1772 | |
1773 | if (switch_channel_test_flag(channel, CF_ANSWERED)) { |
1774 | answered++; |
1775 | } |
1776 | |
1777 | if (!state->ringback->asis) { |
1778 | if (!switch_core_codec_ready((&read_codecs[i]))) { |
1779 | if (switch_core_codec_init(&read_codecs[i],switch_core_codec_init_with_bitrate(&read_codecs[i], "L16" , ((void*)0), read_impl.actual_samples_per_second, read_impl. microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (session)) |
1780 | "L16",switch_core_codec_init_with_bitrate(&read_codecs[i], "L16" , ((void*)0), read_impl.actual_samples_per_second, read_impl. microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (session)) |
1781 | NULL,switch_core_codec_init_with_bitrate(&read_codecs[i], "L16" , ((void*)0), read_impl.actual_samples_per_second, read_impl. microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (session)) |
1782 | read_impl.actual_samples_per_second,switch_core_codec_init_with_bitrate(&read_codecs[i], "L16" , ((void*)0), read_impl.actual_samples_per_second, read_impl. microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (session)) |
1783 | read_impl.microseconds_per_packet / 1000,switch_core_codec_init_with_bitrate(&read_codecs[i], "L16" , ((void*)0), read_impl.actual_samples_per_second, read_impl. microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (session)) |
1784 | 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,switch_core_codec_init_with_bitrate(&read_codecs[i], "L16" , ((void*)0), read_impl.actual_samples_per_second, read_impl. microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (session)) |
1785 | switch_core_session_get_pool(session))switch_core_codec_init_with_bitrate(&read_codecs[i], "L16" , ((void*)0), read_impl.actual_samples_per_second, read_impl. microseconds_per_packet / 1000, 1, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, ((void*)0), switch_core_session_get_pool (session)) != SWITCH_STATUS_SUCCESS) { |
1786 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 1786, (const char*)(session), SWITCH_LOG_ERROR, "Codec Error!\n"); |
1787 | } |
1788 | switch_core_session_set_read_codec(session, NULL((void*)0)); |
1789 | switch_core_session_set_read_codec(session, &read_codecs[i]); |
1790 | } |
1791 | status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); |
1792 | if (SWITCH_READ_ACCEPTABLE(status)(status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK || status == SWITCH_STATUS_INUSE) && !switch_test_flag(read_frame, SFF_CNG)((read_frame)->flags & SFF_CNG)) { |
1793 | data = (int16_t *) read_frame->data; |
1794 | if (datalen < read_frame->datalen) { |
1795 | datalen = read_frame->datalen; |
1796 | } |
1797 | for (x = 0; x < (int) read_frame->datalen / 2; x++) { |
1798 | sample = data[x] + mux_data[x]; |
1799 | switch_normalize_to_16bit(sample)if (sample > 32767) sample = 32767; else if (sample < - 32768) sample = -32768;; |
1800 | mux_data[x] = (int16_t) sample; |
1801 | } |
1802 | } |
1803 | } else { |
1804 | status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); |
1805 | if (SWITCH_READ_ACCEPTABLE(status)(status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK || status == SWITCH_STATUS_INUSE) && !switch_test_flag(read_frame, SFF_CNG)((read_frame)->flags & SFF_CNG)) { |
1806 | datalen = read_frame->datalen; |
1807 | } |
1808 | break; |
1809 | } |
1810 | } |
1811 | } |
1812 | |
1813 | if (!ready || answered || ring_ready) { |
1814 | break; |
1815 | } |
1816 | |
1817 | if (!datalen) { |
1818 | continue; |
1819 | } |
1820 | |
1821 | if (state->ringback->asis) { |
1822 | uint16_t flen = (uint16_t)datalen; |
1823 | switch_mutex_lock(state->mutex); |
1824 | switch_buffer_write(state->buffer, &flen, sizeof(uint16_t)); |
1825 | switch_buffer_write(state->buffer, read_frame->data, datalen); |
1826 | switch_mutex_unlock(state->mutex); |
1827 | } else { |
1828 | switch_mutex_lock(state->mutex); |
1829 | switch_buffer_write(state->buffer, mux_data, datalen); |
1830 | switch_mutex_unlock(state->mutex); |
1831 | } |
1832 | } |
1833 | |
1834 | |
1835 | for (i = 0; i < MAX_PEERS128 && i < state->ttl; i++) { |
1836 | switch_core_session_t *session = originate_status[i].peer_session; |
1837 | switch_channel_t *channel = originate_status[i].peer_channel; |
1838 | |
1839 | if (!session) break; |
1840 | |
1841 | if (switch_core_codec_ready((&read_codecs[i]))) { |
1842 | switch_core_codec_destroy(&read_codecs[i]); |
1843 | } |
1844 | |
1845 | if (switch_channel_up_nosig(channel)(switch_channel_get_state(channel) < CS_HANGUP)) { |
1846 | switch_core_session_reset(session, SWITCH_FALSE, SWITCH_TRUE); |
1847 | } |
1848 | |
1849 | switch_core_session_rwunlock(session); |
1850 | } |
1851 | |
1852 | if (!ring_ready) { |
1853 | state->oglobals->early_ok = 1; |
1854 | } |
1855 | |
1856 | return NULL((void*)0); |
1857 | } |
1858 | |
1859 | #define peer_eligible(_peer)(_peer && !(switch_channel_test_flag(_peer, CF_TRANSFER ) || switch_channel_test_flag(_peer, CF_REDIRECT) || switch_channel_test_flag (_peer, CF_BRIDGED) || switch_channel_get_state(_peer) == CS_RESET || !switch_channel_test_flag(_peer, CF_ORIGINATING))) (_peer && !(switch_channel_test_flag(_peer, CF_TRANSFER) || \ |
1860 | switch_channel_test_flag(_peer, CF_REDIRECT) || \ |
1861 | switch_channel_test_flag(_peer, CF_BRIDGED) || \ |
1862 | switch_channel_get_state(_peer) == CS_RESET || \ |
1863 | !switch_channel_test_flag(_peer, CF_ORIGINATING))) |
1864 | |
1865 | static void wait_for_cause(switch_channel_t *channel) |
1866 | { |
1867 | int sanity = 5; |
1868 | |
1869 | while (--sanity > 0 && peer_eligible(channel)(channel && !(switch_channel_test_flag(channel, CF_TRANSFER ) || switch_channel_test_flag(channel, CF_REDIRECT) || switch_channel_test_flag (channel, CF_BRIDGED) || switch_channel_get_state(channel) == CS_RESET || !switch_channel_test_flag(channel, CF_ORIGINATING ))) && switch_channel_get_cause(channel) == SWITCH_CAUSE_NONE) { |
1870 | switch_yield(10000)switch_sleep(10000);; |
1871 | } |
1872 | } |
1873 | |
1874 | |
1875 | |
1876 | SWITCH_DECLARE(switch_status_t)__attribute__((visibility("default"))) switch_status_t switch_ivr_originate(switch_core_session_t *session, |
1877 | switch_core_session_t **bleg, |
1878 | switch_call_cause_t *cause, |
1879 | const char *bridgeto, |
1880 | uint32_t timelimit_sec, |
1881 | const switch_state_handler_table_t *table, |
1882 | const char *cid_name_override, |
1883 | const char *cid_num_override, |
1884 | switch_caller_profile_t *caller_profile_override, |
1885 | switch_event_t *ovars, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause) |
1886 | { |
1887 | originate_status_t originate_status[MAX_PEERS128] = { {0} }; |
1888 | switch_originate_flag_t dftflags = SOF_NONE, myflags = dftflags; |
Value stored to 'myflags' during its initialization is never read | |
1889 | char *pipe_names[MAX_PEERS128] = { 0 }; |
1890 | char *data = NULL((void*)0); |
1891 | switch_status_t status = SWITCH_STATUS_SUCCESS; |
1892 | switch_channel_t *caller_channel = NULL((void*)0); |
1893 | char *peer_names[MAX_PEERS128] = { 0 }; |
1894 | switch_core_session_t *new_session = NULL((void*)0), *peer_session; |
1895 | switch_caller_profile_t *new_profile = NULL((void*)0), *caller_caller_profile; |
1896 | char *chan_type = NULL((void*)0), *chan_data; |
1897 | switch_channel_t *peer_channel = NULL((void*)0); |
1898 | ringback_t ringback = { 0 }; |
1899 | time_t start; |
1900 | switch_frame_t *read_frame = NULL((void*)0); |
1901 | int r = 0, i, and_argc = 0, or_argc = 0; |
1902 | int32_t sleep_ms = 1000, try = 0, retries = 1; |
1903 | switch_codec_t write_codec = { 0 }; |
1904 | switch_frame_t write_frame = { 0 }; |
1905 | char *odata, *var; |
1906 | switch_call_cause_t reason = SWITCH_CAUSE_NONE; |
1907 | switch_call_cause_t force_reason = SWITCH_CAUSE_NONE; |
1908 | uint8_t to = 0; |
1909 | char *var_val; |
1910 | const char *ringback_data = NULL((void*)0); |
1911 | switch_event_t *var_event = NULL((void*)0); |
1912 | int8_t fail_on_single_reject = 0; |
1913 | int8_t hangup_on_single_reject = 0; |
1914 | char *fail_on_single_reject_var = NULL((void*)0); |
1915 | char *loop_data = NULL((void*)0); |
1916 | uint32_t progress_timelimit_sec = 0; |
1917 | const char *cid_tmp, *lc; |
1918 | originate_global_t oglobals = { 0 }; |
1919 | int cdr_total = 0; |
1920 | int local_clobber = 0; |
1921 | const char *cancel_key = NULL((void*)0); |
1922 | const char *holding = NULL((void*)0); |
1923 | const char *soft_holding = NULL((void*)0); |
1924 | early_state_t early_state = { 0 }; |
1925 | int read_packet = 0; |
1926 | int check_reject = 1; |
1927 | switch_codec_implementation_t read_impl = { 0 }; |
1928 | const char *ani_override = NULL((void*)0); |
1929 | const char *aniii_override = NULL((void*)0); |
1930 | const char *ent_aleg_uuid = NULL((void*)0); |
1931 | switch_core_session_t *a_session = session, *l_session = NULL((void*)0); |
1932 | |
1933 | if (session) { |
1934 | caller_channel = switch_core_session_get_channel(session); |
1935 | |
1936 | if (switch_false(switch_channel_get_variable(caller_channel, "preserve_originated_vars")switch_channel_get_variable_dup(caller_channel, "preserve_originated_vars" , SWITCH_TRUE, -1))) { |
1937 | switch_channel_set_variable(caller_channel, "originated_legs", NULL)switch_channel_set_variable_var_check(caller_channel, "originated_legs" , ((void*)0), SWITCH_TRUE); |
1938 | switch_channel_set_variable(caller_channel, "originate_causes", NULL)switch_channel_set_variable_var_check(caller_channel, "originate_causes" , ((void*)0), SWITCH_TRUE); |
1939 | } |
1940 | } |
1941 | |
1942 | |
1943 | if (strstr(bridgeto, SWITCH_ENT_ORIGINATE_DELIM":_:")) { |
1944 | return switch_ivr_enterprise_originate(session, bleg, cause, bridgeto, timelimit_sec, table, cid_name_override, cid_num_override, |
1945 | caller_profile_override, ovars, flags, cancel_cause); |
1946 | } |
1947 | |
1948 | oglobals.check_vars = SWITCH_TRUE; |
1949 | oglobals.ringback_ok = 1; |
1950 | oglobals.bridge_early_media = -1; |
1951 | oglobals.file = NULL((void*)0); |
1952 | oglobals.error_file = NULL((void*)0); |
1953 | switch_core_new_memory_pool(&oglobals.pool)switch_core_perform_new_memory_pool(&oglobals.pool, "src/switch_ivr_originate.c" , (const char *)__func__, 1953); |
1954 | |
1955 | if (caller_profile_override) { |
1956 | oglobals.caller_profile_override = switch_caller_profile_dup(oglobals.pool, caller_profile_override); |
1957 | } else if (session) { |
1958 | switch_caller_profile_t *cp = switch_channel_get_caller_profile(caller_channel); |
1959 | |
1960 | if (cp) { |
1961 | oglobals.caller_profile_override = switch_caller_profile_dup(oglobals.pool, cp); |
1962 | } |
1963 | } |
1964 | |
1965 | if (session) { |
1966 | const char *to_var, *bypass_media = NULL((void*)0), *proxy_media = NULL((void*)0), *zrtp_passthru = NULL((void*)0); |
1967 | switch_channel_set_flag(caller_channel, CF_ORIGINATOR)switch_channel_set_flag_value(caller_channel, CF_ORIGINATOR, 1 ); |
1968 | oglobals.session = session; |
1969 | |
1970 | switch_channel_execute_on(caller_channel, SWITCH_CHANNEL_EXECUTE_ON_PRE_ORIGINATE_VARIABLE"execute_on_pre_originate"); |
1971 | switch_channel_api_on(caller_channel, SWITCH_CHANNEL_API_ON_PRE_ORIGINATE_VARIABLE"api_on_pre_originate"); |
1972 | |
1973 | switch_core_session_get_read_impl(session, &read_impl); |
1974 | |
1975 | if ((to_var = switch_channel_get_variable(caller_channel, SWITCH_CALL_TIMEOUT_VARIABLE)switch_channel_get_variable_dup(caller_channel, "call_timeout" , SWITCH_TRUE, -1))) { |
1976 | timelimit_sec = atoi(to_var); |
1977 | } |
1978 | |
1979 | proxy_media = switch_channel_get_variable(caller_channel, SWITCH_PROXY_MEDIA_VARIABLE)switch_channel_get_variable_dup(caller_channel, "proxy_media" , SWITCH_TRUE, -1); |
1980 | bypass_media = switch_channel_get_variable(caller_channel, SWITCH_BYPASS_MEDIA_VARIABLE)switch_channel_get_variable_dup(caller_channel, "bypass_media" , SWITCH_TRUE, -1); |
1981 | zrtp_passthru = switch_channel_get_variable(caller_channel, SWITCH_ZRTP_PASSTHRU_VARIABLE)switch_channel_get_variable_dup(caller_channel, "zrtp_passthru" , SWITCH_TRUE, -1); |
1982 | |
1983 | if (!zstr(proxy_media)_zstr(proxy_media)) { |
1984 | if (switch_true(proxy_media)) { |
1985 | switch_channel_set_flag(caller_channel, CF_PROXY_MEDIA)switch_channel_set_flag_value(caller_channel, CF_PROXY_MEDIA, 1); |
1986 | } else if (switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA)) { |
1987 | switch_channel_clear_flag(caller_channel, CF_PROXY_MEDIA); |
1988 | } |
1989 | } |
1990 | |
1991 | if (!zstr(zrtp_passthru)_zstr(zrtp_passthru)) { |
1992 | if (switch_true(zrtp_passthru)) { |
1993 | switch_channel_set_flag(caller_channel, CF_ZRTP_PASSTHRU_REQ)switch_channel_set_flag_value(caller_channel, CF_ZRTP_PASSTHRU_REQ , 1); |
1994 | } else if (switch_channel_test_flag(caller_channel, CF_ZRTP_PASSTHRU_REQ)) { |
1995 | switch_channel_clear_flag(caller_channel, CF_ZRTP_PASSTHRU_REQ); |
1996 | } |
1997 | } |
1998 | |
1999 | if (bypass_media && switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(caller_channel, CF_ANSWERED)) { |
2000 | switch_core_session_message_t msg = { 0 }; |
2001 | |
2002 | msg.message_id = SWITCH_MESSAGE_INDICATE_CLEAR_PROGRESS; |
2003 | msg.from = __FILE__"src/switch_ivr_originate.c"; |
2004 | switch_core_session_receive_message(session, &msg)switch_core_session_perform_receive_message(session, &msg , "src/switch_ivr_originate.c", (const char *)__func__, 2004); |
2005 | } |
2006 | |
2007 | |
2008 | if (!zstr(bypass_media)_zstr(bypass_media) && !switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA)) { |
2009 | if (switch_true(bypass_media)) { |
2010 | switch_channel_set_flag(caller_channel, CF_PROXY_MODE)switch_channel_set_flag_value(caller_channel, CF_PROXY_MODE, 1 ); |
2011 | } else if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE)) { |
2012 | if (!switch_channel_test_flag(caller_channel, CF_ANSWERED) && switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) { |
2013 | switch_channel_set_variable(caller_channel, SWITCH_B_SDP_VARIABLE, NULL)switch_channel_set_variable_var_check(caller_channel, "switch_m_sdp" , ((void*)0), SWITCH_TRUE); |
2014 | switch_channel_answer(caller_channel)switch_channel_perform_answer(caller_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 2014); |
2015 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2015, (const char*)(session), SWITCH_LOG_WARNING, |
2016 | "Must answer channel %s due to SIP PARADOX\n", switch_channel_get_name(caller_channel)); |
2017 | } |
2018 | switch_channel_set_variable(caller_channel, SWITCH_B_SDP_VARIABLE, NULL)switch_channel_set_variable_var_check(caller_channel, "switch_m_sdp" , ((void*)0), SWITCH_TRUE); |
2019 | switch_ivr_media(switch_core_session_get_uuid(session), SMF_NONE); |
2020 | } |
2021 | } |
2022 | |
2023 | if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE) && switch_channel_test_flag(caller_channel, CF_ANSWERED)) { |
2024 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2024, (const char*)(session), SWITCH_LOG_DEBUG, |
2025 | "Channel is already up, delaying proxy mode 'till both legs are answered.\n"); |
2026 | switch_channel_set_variable(caller_channel, "bypass_media_after_bridge", "true")switch_channel_set_variable_var_check(caller_channel, "bypass_media_after_bridge" , "true", SWITCH_TRUE); |
2027 | switch_channel_set_variable(caller_channel, SWITCH_BYPASS_MEDIA_VARIABLE, NULL)switch_channel_set_variable_var_check(caller_channel, "bypass_media" , ((void*)0), SWITCH_TRUE); |
2028 | switch_channel_clear_flag(caller_channel, CF_PROXY_MODE); |
2029 | } |
2030 | } |
2031 | |
2032 | if (timelimit_sec <= 0) { |
2033 | timelimit_sec = 60; |
2034 | } |
2035 | |
2036 | |
2037 | oglobals.idx = IDX_NADA; |
2038 | oglobals.early_ok = 1; |
2039 | |
2040 | *bleg = NULL((void*)0); |
2041 | |
2042 | switch_zmalloc(write_frame.data, SWITCH_RECOMMENDED_BUFFER_SIZE)(void)((((write_frame.data = calloc(1, (8192)))) ? (void) (0) : __assert_fail ("(write_frame.data = calloc(1, (8192)))", "src/switch_ivr_originate.c" , 2042, __PRETTY_FUNCTION__)),write_frame.data); |
2043 | write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE8192; |
2044 | |
2045 | odata = strdup(bridgeto)(__extension__ (__builtin_constant_p (bridgeto) && (( size_t)(const void *)((bridgeto) + 1) - (size_t)(const void * )(bridgeto) == 1) ? (((const char *) (bridgeto))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (bridgeto) + 1; char *__retval = (char *) malloc (__len ); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval , bridgeto, __len); __retval; })) : __strdup (bridgeto))); |
2046 | |
2047 | if (!odata) { |
2048 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2048, (const char*)(session), SWITCH_LOG_ERROR, "Memory Error!\n"); |
2049 | status = SWITCH_STATUS_MEMERR; |
2050 | goto done; |
2051 | } |
2052 | |
2053 | data = odata; |
2054 | |
2055 | |
2056 | /* Some channel are created from an originating channel and some aren't so not all outgoing calls have a way to get params |
2057 | so we will normalize dialstring params and channel variables (when there is an originator) into an event that we |
2058 | will use as a pseudo hash to consult for params as needed. |
2059 | */ |
2060 | |
2061 | if (ovars) { |
2062 | var_event = ovars; |
2063 | } else { |
2064 | if (switch_event_create_plain(&var_event, SWITCH_EVENT_CHANNEL_DATA) != SWITCH_STATUS_SUCCESS) { |
2065 | abort(); |
2066 | } |
2067 | } |
2068 | |
2069 | ent_aleg_uuid = switch_event_get_header(var_event, "ent_originate_aleg_uuid")switch_event_get_header_idx(var_event, "ent_originate_aleg_uuid" , -1); |
2070 | |
2071 | if (caller_channel) { |
2072 | switch_channel_process_export(caller_channel, NULL((void*)0), var_event, SWITCH_EXPORT_VARS_VARIABLE"export_vars"); |
2073 | } |
2074 | |
2075 | /* strip leading spaces */ |
2076 | while (data && *data && *data == ' ') { |
2077 | data++; |
2078 | } |
2079 | |
2080 | if ((ovars && switch_true(switch_event_get_header(ovars,"origination_nested_vars")switch_event_get_header_idx(ovars, "origination_nested_vars", -1))) || |
2081 | (caller_channel && switch_true(switch_channel_get_variable(caller_channel, "origination_nested_vars")switch_channel_get_variable_dup(caller_channel, "origination_nested_vars" , SWITCH_TRUE, -1))) |
2082 | || switch_true(switch_core_get_variable("origination_nested_vars")) || switch_stristr("origination_nested_vars=true", data)) { |
2083 | oglobals.check_vars = SWITCH_FALSE; |
2084 | } |
2085 | |
2086 | |
2087 | /* extract channel variables, allowing multiple sets of braces */ |
2088 | if (*data == '<') { |
2089 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2089, (const char*)(session), SWITCH_LOG_DEBUG, "Parsing ultra-global variables\n"); |
2090 | while (*data == '<') { |
2091 | char *parsed = NULL((void*)0); |
2092 | |
2093 | if (switch_event_create_brackets(data, '<', '>', ',', &var_event, &parsed, SWITCH_FALSE) != SWITCH_STATUS_SUCCESS || !parsed) { |
2094 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2094, (const char*)(session), SWITCH_LOG_ERROR, "Parse Error!\n"); |
2095 | switch_goto_status(SWITCH_STATUS_GENERR, done)status = SWITCH_STATUS_GENERR; goto done; |
2096 | } |
2097 | |
2098 | data = parsed; |
2099 | } |
2100 | } |
2101 | |
2102 | /* extract channel variables, allowing multiple sets of braces */ |
2103 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2103, (const char*)(session), SWITCH_LOG_DEBUG, "Parsing global variables\n"); |
2104 | while (*data == '{') { |
2105 | char *parsed = NULL((void*)0); |
2106 | |
2107 | if (switch_event_create_brackets(data, '{', '}', ',', &var_event, &parsed, SWITCH_FALSE) != SWITCH_STATUS_SUCCESS || !parsed) { |
2108 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2108, (const char*)(session), SWITCH_LOG_ERROR, "Parse Error!\n"); |
2109 | switch_goto_status(SWITCH_STATUS_GENERR, done)status = SWITCH_STATUS_GENERR; goto done; |
2110 | } |
2111 | |
2112 | data = parsed; |
2113 | } |
2114 | |
2115 | |
2116 | /* strip leading spaces (again) */ |
2117 | while (data && *data && *data == ' ') { |
2118 | data++; |
2119 | } |
2120 | |
2121 | if (zstr(data)_zstr(data)) { |
2122 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2122, (const char*)(session), SWITCH_LOG_WARNING, "No origination URL specified!\n"); |
2123 | status = SWITCH_STATUS_GENERR; |
2124 | goto done; |
2125 | } |
2126 | |
2127 | if (!(flags & SOF_NOBLOCK) && var_event && (var = switch_event_get_header(var_event, "originate_delay_start")switch_event_get_header_idx(var_event, "originate_delay_start" , -1))) { |
2128 | int tmp = atoi(var); |
2129 | if (tmp > 0) { |
2130 | while (tmp && (!cancel_cause || *cancel_cause == 0)) { |
2131 | switch_cond_next(); |
2132 | tmp--; |
2133 | } |
2134 | } |
2135 | } |
2136 | |
2137 | if (oglobals.session) { |
2138 | switch_event_header_t *hi; |
2139 | const char *cdr_total_var; |
2140 | const char *cdr_var; |
2141 | const char *json_cdr_var; |
2142 | |
2143 | if ((cdr_var = switch_channel_get_variable(caller_channel, "failed_xml_cdr_prefix")switch_channel_get_variable_dup(caller_channel, "failed_xml_cdr_prefix" , SWITCH_TRUE, -1))) { |
2144 | char buf[128] = ""; |
2145 | switch_snprintf(buf, sizeof(buf), "%s_total", cdr_var); |
2146 | if ((cdr_total_var = switch_channel_get_variable(caller_channel, buf)switch_channel_get_variable_dup(caller_channel, buf, SWITCH_TRUE , -1))) { |
2147 | int tmp = atoi(cdr_total_var); |
2148 | if (tmp > 0) { |
2149 | cdr_total = tmp; |
2150 | } |
2151 | } |
2152 | } |
2153 | |
2154 | if ((json_cdr_var = switch_channel_get_variable(caller_channel, "failed_json_cdr_prefix")switch_channel_get_variable_dup(caller_channel, "failed_json_cdr_prefix" , SWITCH_TRUE, -1))) { |
2155 | char buf[128] = ""; |
2156 | switch_snprintf(buf, sizeof(buf), "%s_total", json_cdr_var); |
2157 | if ((cdr_total_var = switch_channel_get_variable(caller_channel, buf)switch_channel_get_variable_dup(caller_channel, buf, SWITCH_TRUE , -1))) { |
2158 | int tmp = atoi(cdr_total_var); |
2159 | if (tmp > 0) { |
2160 | cdr_total = tmp; |
2161 | } |
2162 | } |
2163 | } |
2164 | |
2165 | /* Copy all the missing applicable channel variables from A-leg into the event */ |
2166 | if ((hi = switch_channel_variable_first(caller_channel))) { |
2167 | for (; hi; hi = hi->next) { |
2168 | int ok = 0; |
2169 | if (!strcasecmp((char *) hi->name, "group_confirm_key")) { |
2170 | ok = 1; |
2171 | } else if (!strcasecmp((char *) hi->name, "group_confirm_file")) { |
2172 | ok = 1; |
2173 | } else if (!strcasecmp((char *) hi->name, "group_confirm_read_timeout")) { |
2174 | ok = 1; |
2175 | } else if (!strcasecmp((char *) hi->name, "group_confirm_cancel_timeout")) { |
2176 | ok = 1; |
2177 | } else if (!strcasecmp((char *) hi->name, "forked_dial")) { |
2178 | ok = 1; |
2179 | } else if (!strcasecmp((char *) hi->name, "fail_on_single_reject")) { |
2180 | ok = 1; |
2181 | } else if (!strcasecmp((char *) hi->name, "hangup_on_single_reject")) { |
2182 | ok = 1; |
2183 | } else if (!strcasecmp((char *) hi->name, "ignore_early_media")) { |
2184 | ok = 1; |
2185 | } else if (!strcasecmp((char *) hi->name, "bridge_early_media")) { |
2186 | ok = 1; |
2187 | } else if (!strcasecmp((char *) hi->name, "originate_continue_on_timeout")) { |
2188 | ok = 1; |
2189 | } else if (!strcasecmp((char *) hi->name, "ignore_ring_ready")) { |
2190 | ok = 1; |
2191 | } else if (!strcasecmp((char *) hi->name, "monitor_early_media_ring")) { |
2192 | ok = 1; |
2193 | } else if (!strcasecmp((char *) hi->name, "monitor_early_media_ring_total")) { |
2194 | ok = 1; |
2195 | } else if (!strcasecmp((char *) hi->name, "monitor_early_media_fail")) { |
2196 | ok = 1; |
2197 | } else if (!strcasecmp((char *) hi->name, "return_ring_ready")) { |
2198 | ok = 1; |
2199 | } else if (!strcasecmp((char *) hi->name, "ring_ready")) { |
2200 | ok = 1; |
2201 | } else if (!strcasecmp((char *) hi->name, "instant_ringback")) { |
2202 | ok = 1; |
2203 | } else if (!strcasecmp((char *) hi->name, "progress_timeout")) { |
2204 | ok = 1; |
2205 | } else if (!strcasecmp((char *) hi->name, "language")) { |
2206 | ok = 1; |
2207 | } |
2208 | |
2209 | if (ok && !switch_event_get_header(var_event, hi->name)switch_event_get_header_idx(var_event, hi->name, -1)) { |
2210 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, (char *) hi->name, (char *) hi->value); |
2211 | } |
2212 | } |
2213 | switch_channel_variable_last(caller_channel); |
2214 | } |
2215 | /* |
2216 | if ((hi = switch_channel_variable_first(caller_channel))) { |
2217 | for (; hi; hi = switch_core_hash_next(&hi)) { |
2218 | switch_core_hash_this(hi, &vvar, NULL, &vval); |
2219 | if (vvar && vval) { |
2220 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, (void *) vvar, (char *) vval); |
2221 | } |
2222 | } |
2223 | switch_channel_variable_last(caller_channel); |
2224 | } |
2225 | */ |
2226 | } |
2227 | |
2228 | if (caller_channel) { /* ringback is only useful when there is an originator */ |
2229 | ringback_data = NULL((void*)0); |
2230 | cancel_key = switch_channel_get_variable(caller_channel, "origination_cancel_key")switch_channel_get_variable_dup(caller_channel, "origination_cancel_key" , SWITCH_TRUE, -1); |
2231 | |
2232 | if (switch_channel_test_flag(caller_channel, CF_ANSWERED)) { |
2233 | ringback_data = switch_channel_get_variable(caller_channel, "transfer_ringback")switch_channel_get_variable_dup(caller_channel, "transfer_ringback" , SWITCH_TRUE, -1); |
2234 | } |
2235 | |
2236 | if (!ringback_data) { |
2237 | ringback_data = switch_channel_get_variable(caller_channel, "ringback")switch_channel_get_variable_dup(caller_channel, "ringback", SWITCH_TRUE , -1); |
2238 | } |
2239 | |
2240 | switch_channel_set_variable(caller_channel, "originate_disposition", "failure")switch_channel_set_variable_var_check(caller_channel, "originate_disposition" , "failure", SWITCH_TRUE); |
2241 | switch_channel_set_variable(caller_channel, "DIALSTATUS", "INVALIDARGS")switch_channel_set_variable_var_check(caller_channel, "DIALSTATUS" , "INVALIDARGS", SWITCH_TRUE); |
2242 | |
2243 | if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE) || switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA)) { |
2244 | ringback_data = NULL((void*)0); |
2245 | } |
2246 | } |
2247 | #if 0 |
2248 | /* changing behaviour ignore_early_media=true must also be explicitly set for previous behaviour */ |
2249 | if (ringback_data) { |
2250 | oglobals.early_ok = 0; |
2251 | } |
2252 | #endif |
2253 | |
2254 | if (switch_true(switch_event_get_header(var_event, "group_confirm_cancel_timeout")switch_event_get_header_idx(var_event, "group_confirm_cancel_timeout" , -1))) { |
2255 | oglobals.cancel_timeout = -1; |
2256 | } |
2257 | |
2258 | if ((var = switch_event_get_header(var_event, "group_confirm_key")switch_event_get_header_idx(var_event, "group_confirm_key", - 1))) { |
2259 | switch_copy_string(oglobals.key, var, sizeof(oglobals.key)); |
2260 | if ((var = switch_event_get_header(var_event, "group_confirm_file")switch_event_get_header_idx(var_event, "group_confirm_file", - 1))) { |
2261 | oglobals.file = strdup(var)(__extension__ (__builtin_constant_p (var) && ((size_t )(const void *)((var) + 1) - (size_t)(const void *)(var) == 1 ) ? (((const char *) (var))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (var) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, var, __len); __retval ; })) : __strdup (var))); |
2262 | } |
2263 | if ((var = switch_event_get_header(var_event, "group_confirm_error_file")switch_event_get_header_idx(var_event, "group_confirm_error_file" , -1))) { |
2264 | oglobals.error_file = strdup(var)(__extension__ (__builtin_constant_p (var) && ((size_t )(const void *)((var) + 1) - (size_t)(const void *)(var) == 1 ) ? (((const char *) (var))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (var) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, var, __len); __retval ; })) : __strdup (var))); |
2265 | } |
2266 | if ((var = switch_event_get_header(var_event, "group_confirm_read_timeout")switch_event_get_header_idx(var_event, "group_confirm_read_timeout" , -1))) { |
2267 | int tmp = atoi(var); |
2268 | |
2269 | if (tmp >= 0) { |
2270 | oglobals.confirm_timeout = tmp; |
2271 | } |
2272 | |
2273 | } |
2274 | } |
2275 | /* When using the AND operator, the fail_on_single_reject flag may be set in order to indicate that a single |
2276 | rejections should terminate the attempt rather than a timeout, answer, or rejection by all. |
2277 | If the value is set to 'true' any fail cause will end the attempt otherwise it can contain a comma (,) separated |
2278 | list of cause names which should be considered fatal |
2279 | */ |
2280 | if ((var = switch_event_get_header(var_event, "hangup_on_single_reject")switch_event_get_header_idx(var_event, "hangup_on_single_reject" , -1))) { |
2281 | hangup_on_single_reject = 1; |
2282 | } |
2283 | |
2284 | if (hangup_on_single_reject || (var = switch_event_get_header(var_event, "fail_on_single_reject")switch_event_get_header_idx(var_event, "fail_on_single_reject" , -1))) { |
2285 | fail_on_single_reject_var = strdup(var)(__extension__ (__builtin_constant_p (var) && ((size_t )(const void *)((var) + 1) - (size_t)(const void *)(var) == 1 ) ? (((const char *) (var))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (var) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, var, __len); __retval ; })) : __strdup (var))); |
2286 | if (switch_true(var)) { |
2287 | fail_on_single_reject = 1; |
2288 | } else { |
2289 | fail_on_single_reject = -1; |
2290 | } |
2291 | } |
2292 | |
2293 | if ((!zstr(oglobals.file)_zstr(oglobals.file)) && (!strcmp(oglobals.file, "undef")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (oglobals.file) && __builtin_constant_p ("undef") && (__s1_len = __builtin_strlen (oglobals.file), __s2_len = __builtin_strlen ("undef"), (!((size_t)(const void *)((oglobals.file) + 1) - ( size_t)(const void *)(oglobals.file) == 1) || __s1_len >= 4 ) && (!((size_t)(const void *)(("undef") + 1) - (size_t )(const void *)("undef") == 1) || __s2_len >= 4)) ? __builtin_strcmp (oglobals.file, "undef") : (__builtin_constant_p (oglobals.file ) && ((size_t)(const void *)((oglobals.file) + 1) - ( size_t)(const void *)(oglobals.file) == 1) && (__s1_len = __builtin_strlen (oglobals.file), __s1_len < 4) ? (__builtin_constant_p ("undef") && ((size_t)(const void *)(("undef") + 1) - (size_t)(const void *)("undef") == 1) ? __builtin_strcmp (oglobals .file, "undef") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("undef"); int __result = (((const unsigned char *) (const char *) (oglobals.file))[ 0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (oglobals .file))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ( oglobals.file))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (oglobals.file))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("undef") && ((size_t)(const void *)(("undef") + 1) - (size_t)(const void *)("undef") == 1) && (__s2_len = __builtin_strlen ("undef"), __s2_len < 4) ? (__builtin_constant_p (oglobals.file) && ((size_t)(const void *)((oglobals .file) + 1) - (size_t)(const void *)(oglobals.file) == 1) ? __builtin_strcmp (oglobals.file, "undef") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (oglobals .file); int __result = (((const unsigned char *) (const char * ) ("undef"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ( "undef"))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ( "undef"))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ("undef" ))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (oglobals .file, "undef")))); }))) { |
2294 | switch_safe_free(oglobals.file)if (oglobals.file) {free(oglobals.file);oglobals.file=((void* )0);}; |
2295 | oglobals.file = NULL((void*)0); |
2296 | } |
2297 | if ((!zstr(oglobals.error_file)_zstr(oglobals.error_file)) && (!strcmp(oglobals.error_file, "undef")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (oglobals.error_file) && __builtin_constant_p ("undef" ) && (__s1_len = __builtin_strlen (oglobals.error_file ), __s2_len = __builtin_strlen ("undef"), (!((size_t)(const void *)((oglobals.error_file) + 1) - (size_t)(const void *)(oglobals .error_file) == 1) || __s1_len >= 4) && (!((size_t )(const void *)(("undef") + 1) - (size_t)(const void *)("undef" ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (oglobals.error_file , "undef") : (__builtin_constant_p (oglobals.error_file) && ((size_t)(const void *)((oglobals.error_file) + 1) - (size_t )(const void *)(oglobals.error_file) == 1) && (__s1_len = __builtin_strlen (oglobals.error_file), __s1_len < 4) ? (__builtin_constant_p ("undef") && ((size_t)(const void *)(("undef") + 1) - (size_t)(const void *)("undef") == 1) ? __builtin_strcmp (oglobals.error_file, "undef") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("undef" ); int __result = (((const unsigned char *) (const char *) (oglobals .error_file))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ( oglobals.error_file))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (oglobals.error_file))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (oglobals.error_file))[3] - __s2[3]); } } __result ; }))) : (__builtin_constant_p ("undef") && ((size_t) (const void *)(("undef") + 1) - (size_t)(const void *)("undef" ) == 1) && (__s2_len = __builtin_strlen ("undef"), __s2_len < 4) ? (__builtin_constant_p (oglobals.error_file) && ((size_t)(const void *)((oglobals.error_file) + 1) - (size_t )(const void *)(oglobals.error_file) == 1) ? __builtin_strcmp (oglobals.error_file, "undef") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (oglobals .error_file); int __result = (((const unsigned char *) (const char *) ("undef"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("undef"))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ("undef"))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ("undef"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (oglobals.error_file, "undef")))); }))) { |
2298 | switch_safe_free(oglobals.error_file)if (oglobals.error_file) {free(oglobals.error_file);oglobals. error_file=((void*)0);}; |
2299 | oglobals.error_file = NULL((void*)0); |
2300 | } |
2301 | |
2302 | if ((var_val = switch_event_get_header(var_event, "bridge_early_media")switch_event_get_header_idx(var_event, "bridge_early_media", - 1))) { |
2303 | if (switch_true(var_val)) { |
2304 | oglobals.early_ok = 0; |
2305 | oglobals.ignore_early_media = 3; |
2306 | } |
2307 | } |
2308 | |
2309 | if ((var_val = switch_event_get_header(var_event, "ignore_early_media")switch_event_get_header_idx(var_event, "ignore_early_media", - 1))) { |
2310 | if (switch_true(var_val)) { |
2311 | oglobals.early_ok = 0; |
2312 | oglobals.ignore_early_media = 1; |
2313 | } else if (!strcmp(var_val, "consume")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (var_val) && __builtin_constant_p ("consume") && (__s1_len = __builtin_strlen (var_val), __s2_len = __builtin_strlen ("consume"), (!((size_t)(const void *)((var_val) + 1) - (size_t )(const void *)(var_val) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(("consume") + 1) - (size_t)(const void *)("consume") == 1) || __s2_len >= 4)) ? __builtin_strcmp (var_val, "consume") : (__builtin_constant_p (var_val) && ((size_t)(const void *)((var_val) + 1) - (size_t)(const void *)(var_val) == 1) && (__s1_len = __builtin_strlen (var_val ), __s1_len < 4) ? (__builtin_constant_p ("consume") && ((size_t)(const void *)(("consume") + 1) - (size_t)(const void *)("consume") == 1) ? __builtin_strcmp (var_val, "consume") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("consume"); int __result = (((const unsigned char *) (const char *) (var_val))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (var_val))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (var_val))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (var_val))[3] - __s2[3]); } } __result ; }))) : (__builtin_constant_p ("consume") && ((size_t )(const void *)(("consume") + 1) - (size_t)(const void *)("consume" ) == 1) && (__s2_len = __builtin_strlen ("consume"), __s2_len < 4) ? (__builtin_constant_p (var_val) && ((size_t )(const void *)((var_val) + 1) - (size_t)(const void *)(var_val ) == 1) ? __builtin_strcmp (var_val, "consume") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (var_val); int __result = (((const unsigned char *) ( const char *) ("consume"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("consume"))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ("consume"))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ("consume"))[3] - __s2[3]); } } __result; } )))) : __builtin_strcmp (var_val, "consume")))); })) { |
2314 | oglobals.early_ok = 0; |
2315 | oglobals.ignore_early_media = 4; |
2316 | } else if (!strcmp(var_val, "ring_ready")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (var_val) && __builtin_constant_p ("ring_ready") && (__s1_len = __builtin_strlen (var_val), __s2_len = __builtin_strlen ("ring_ready"), (!((size_t)(const void *)((var_val) + 1) - ( size_t)(const void *)(var_val) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(("ring_ready") + 1) - (size_t)(const void *)("ring_ready") == 1) || __s2_len >= 4)) ? __builtin_strcmp (var_val, "ring_ready") : (__builtin_constant_p (var_val) && ((size_t)(const void *)((var_val) + 1) - (size_t)(const void *)(var_val) == 1) && (__s1_len = __builtin_strlen (var_val ), __s1_len < 4) ? (__builtin_constant_p ("ring_ready") && ((size_t)(const void *)(("ring_ready") + 1) - (size_t)(const void *)("ring_ready") == 1) ? __builtin_strcmp (var_val, "ring_ready" ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("ring_ready"); int __result = (((const unsigned char *) (const char *) (var_val))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (var_val))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (var_val))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (var_val))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("ring_ready") && ((size_t)(const void *)(("ring_ready") + 1) - (size_t)(const void *)("ring_ready") == 1) && (__s2_len = __builtin_strlen ("ring_ready"), __s2_len < 4) ? (__builtin_constant_p (var_val ) && ((size_t)(const void *)((var_val) + 1) - (size_t )(const void *)(var_val) == 1) ? __builtin_strcmp (var_val, "ring_ready" ) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (var_val); int __result = (((const unsigned char *) (const char *) ("ring_ready"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("ring_ready"))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ("ring_ready"))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ("ring_ready"))[3] - __s2[3]); } } __result ; })))) : __builtin_strcmp (var_val, "ring_ready")))); })) { |
2317 | oglobals.early_ok = 0; |
2318 | oglobals.ignore_early_media = 2; |
2319 | } |
2320 | } |
2321 | |
2322 | if ((var_val = switch_event_get_header(var_event, "originate_continue_on_timeout")switch_event_get_header_idx(var_event, "originate_continue_on_timeout" , -1)) && switch_true(var_val)) { |
2323 | oglobals.continue_on_timeout = 1; |
2324 | } |
2325 | |
2326 | if ((var_val = switch_event_get_header(var_event, "ignore_ring_ready")switch_event_get_header_idx(var_event, "ignore_ring_ready", - 1)) && switch_true(var_val)) { |
2327 | oglobals.ignore_ring_ready = 1; |
2328 | } |
2329 | |
2330 | if ((var_val = switch_event_get_header(var_event, "monitor_early_media_ring")switch_event_get_header_idx(var_event, "monitor_early_media_ring" , -1))) { |
2331 | oglobals.early_ok = 0; |
2332 | oglobals.monitor_early_media_ring = 1; |
2333 | } |
2334 | |
2335 | if ((var_val = switch_event_get_header(var_event, "monitor_early_media_fail")switch_event_get_header_idx(var_event, "monitor_early_media_fail" , -1))) { |
2336 | oglobals.early_ok = 0; |
2337 | oglobals.monitor_early_media_fail = 1; |
2338 | } |
2339 | |
2340 | if ((var_val = switch_event_get_header(var_event, "return_ring_ready")switch_event_get_header_idx(var_event, "return_ring_ready", - 1)) && switch_true(var_val)) { |
2341 | oglobals.return_ring_ready = 1; |
2342 | } |
2343 | |
2344 | if ((var_val = switch_event_get_header(var_event, "ring_ready")switch_event_get_header_idx(var_event, "ring_ready", -1)) && switch_true(var_val)) { |
2345 | oglobals.ring_ready = 1; |
2346 | } |
2347 | |
2348 | if ((var_val = switch_event_get_header(var_event, "instant_ringback")switch_event_get_header_idx(var_event, "instant_ringback", -1 )) && switch_true(var_val)) { |
2349 | oglobals.instant_ringback = 1; |
2350 | } |
2351 | |
2352 | if ((var_val = switch_event_get_header(var_event, "originate_timeout")switch_event_get_header_idx(var_event, "originate_timeout", - 1))) { |
2353 | int tmp = atoi(var_val); |
2354 | if (tmp > 0) { |
2355 | timelimit_sec = (uint32_t) tmp; |
2356 | } |
2357 | } |
2358 | |
2359 | if ((var_val = switch_event_get_header(var_event, "progress_timeout")switch_event_get_header_idx(var_event, "progress_timeout", -1 ))) { |
2360 | int tmp = atoi(var_val); |
2361 | if (tmp > 0) { |
2362 | progress_timelimit_sec = (uint32_t) tmp; |
2363 | } |
2364 | } |
2365 | |
2366 | if ((var_val = switch_event_get_header(var_event, "originate_retries")switch_event_get_header_idx(var_event, "originate_retries", - 1)) && switch_true(var_val)) { |
2367 | int32_t tmp; |
2368 | tmp = atoi(var_val); |
2369 | if (tmp > 0 && tmp < 101) { |
2370 | retries = tmp; |
2371 | } else { |
2372 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2372, (const char*)(session), SWITCH_LOG_WARNING, |
2373 | "Invalid originate_retries setting of %d ignored, value must be between 1 and 100\n", tmp); |
2374 | } |
2375 | } |
2376 | |
2377 | if ((var_val = switch_event_get_header(var_event, "originate_retry_sleep_ms")switch_event_get_header_idx(var_event, "originate_retry_sleep_ms" , -1)) && switch_true(var_val)) { |
2378 | int32_t tmp; |
2379 | tmp = atoi(var_val); |
2380 | if (tmp >= 500 && tmp <= 60000) { |
2381 | sleep_ms = tmp; |
2382 | } else { |
2383 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2383, (const char*)(session), SWITCH_LOG_WARNING, |
2384 | "Invalid originate_retry_sleep_ms setting of %d ignored, value must be between 500 and 60000\n", tmp); |
2385 | } |
2386 | } |
2387 | |
2388 | /* variable to force ANI / ANIII */ |
2389 | ani_override = switch_event_get_header(var_event, "origination_ani")switch_event_get_header_idx(var_event, "origination_ani", -1); |
2390 | aniii_override = switch_event_get_header(var_event, "origination_aniii")switch_event_get_header_idx(var_event, "origination_aniii", - 1); |
2391 | |
2392 | if ((cid_tmp = switch_event_get_header(var_event, "origination_caller_id_name")switch_event_get_header_idx(var_event, "origination_caller_id_name" , -1))) { |
2393 | cid_name_override = cid_tmp; |
2394 | } |
2395 | |
2396 | if (cid_name_override) { |
2397 | if (!cid_tmp) { |
2398 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "origination_caller_id_name", cid_name_override); |
2399 | } |
2400 | } else { |
2401 | cid_name_override = switch_event_get_header(var_event, "origination_caller_id_name")switch_event_get_header_idx(var_event, "origination_caller_id_name" , -1); |
2402 | } |
2403 | |
2404 | if ((cid_tmp = switch_event_get_header(var_event, "origination_caller_id_number")switch_event_get_header_idx(var_event, "origination_caller_id_number" , -1))) { |
2405 | cid_num_override = cid_tmp; |
2406 | } |
2407 | |
2408 | if (cid_num_override) { |
2409 | if (!cid_tmp) { |
2410 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "origination_caller_id_number", cid_num_override); |
2411 | } |
2412 | } else { |
2413 | cid_num_override = switch_event_get_header(var_event, "origination_caller_id_number")switch_event_get_header_idx(var_event, "origination_caller_id_number" , -1); |
2414 | } |
2415 | |
2416 | if (flags & SOF_NO_LIMITS) { |
2417 | dftflags |= SOF_NO_LIMITS; |
2418 | } |
2419 | |
2420 | if (ani_override) { |
2421 | dftflags |= SOF_NO_EFFECTIVE_ANI; |
2422 | } |
2423 | |
2424 | if (aniii_override) { |
2425 | dftflags |= SOF_NO_EFFECTIVE_ANIII; |
2426 | } |
2427 | |
2428 | if (cid_num_override) { |
2429 | dftflags |= SOF_NO_EFFECTIVE_CID_NUM; |
2430 | } |
2431 | |
2432 | if (cid_name_override) { |
2433 | dftflags |= SOF_NO_EFFECTIVE_CID_NAME; |
2434 | } |
2435 | |
2436 | if (!progress_timelimit_sec) { |
2437 | progress_timelimit_sec = timelimit_sec; |
2438 | } |
2439 | |
2440 | for (try = 0; try < retries; try++) { |
2441 | switch_safe_free(loop_data)if (loop_data) {free(loop_data);loop_data=((void*)0);}; |
2442 | loop_data = strdup(data)(__extension__ (__builtin_constant_p (data) && ((size_t )(const void *)((data) + 1) - (size_t)(const void *)(data) == 1) ? (((const char *) (data))[0] == '\0' ? (char *) calloc ( (size_t) 1, (size_t) 1) : ({ size_t __len = strlen (data) + 1 ; char *__retval = (char *) malloc (__len); if (__retval != ( (void*)0)) __retval = (char *) memcpy (__retval, data, __len) ; __retval; })) : __strdup (data))); |
2443 | switch_assert(loop_data)((loop_data) ? (void) (0) : __assert_fail ("loop_data", "src/switch_ivr_originate.c" , 2443, __PRETTY_FUNCTION__)); |
2444 | or_argc = switch_separate_string(loop_data, '|', pipe_names, (sizeof(pipe_names) / sizeof(pipe_names[0]))); |
2445 | |
2446 | if ((flags & SOF_NOBLOCK) && or_argc > 1) { |
2447 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2447, (const char*)(session), SWITCH_LOG_WARNING, "Only calling the first element in the list in this mode.\n"); |
2448 | or_argc = 1; |
2449 | } |
2450 | |
2451 | for (r = 0; r < or_argc && (!cancel_cause || *cancel_cause == 0); r++) { |
2452 | char *p, *end = NULL((void*)0); |
2453 | int q = 0, alt = 0; |
2454 | |
2455 | check_reject = 1; |
2456 | |
2457 | oglobals.hups = 0; |
2458 | |
2459 | reason = SWITCH_CAUSE_NONE; |
2460 | memset(peer_names, 0, sizeof(peer_names)); |
2461 | peer_session = NULL((void*)0); |
2462 | memset(originate_status, 0, sizeof(originate_status)); |
2463 | new_profile = NULL((void*)0); |
2464 | new_session = NULL((void*)0); |
2465 | chan_type = NULL((void*)0); |
2466 | chan_data = NULL((void*)0); |
2467 | peer_channel = NULL((void*)0); |
2468 | start = 0; |
2469 | read_frame = NULL((void*)0); |
2470 | oglobals.ringback_ok = 1; |
2471 | var = NULL((void*)0); |
2472 | to = 0; |
2473 | oglobals.sent_ring = 0; |
2474 | oglobals.progress = 0; |
2475 | myflags = dftflags; |
2476 | |
2477 | |
2478 | if (try > 0) { |
2479 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2479, (const char*)(session), SWITCH_LOG_NOTICE, "Originate attempt %d/%d in %d ms\n", try + 1, retries, |
2480 | sleep_ms); |
2481 | if (caller_channel) { |
2482 | switch_ivr_sleep(oglobals.session, sleep_ms, SWITCH_TRUE, NULL((void*)0)); |
2483 | if (!switch_channel_ready(caller_channel)switch_channel_test_ready(caller_channel, SWITCH_TRUE, SWITCH_FALSE )) { |
2484 | status = SWITCH_STATUS_FALSE; |
2485 | /* set try and retries to 0 */ |
2486 | try = 0; |
2487 | retries = 0; |
2488 | goto done; |
2489 | } |
2490 | } else { |
2491 | switch_yield(sleep_ms * 1000)switch_sleep(sleep_ms * 1000);; |
2492 | } |
2493 | } |
2494 | |
2495 | p = pipe_names[r]; |
2496 | |
2497 | while (p && *p) { |
2498 | if (*p == '[') { |
2499 | end = switch_find_end_paren(p, '[', ']'); |
2500 | if (*(p+1) == '^' && *(p + 2) == '^') { |
2501 | alt = 1; |
2502 | } else { |
2503 | alt = 0; |
2504 | } |
2505 | q = 0; |
2506 | } |
2507 | |
2508 | if (*p == '\'') { |
2509 | q = !q; |
2510 | } |
2511 | |
2512 | if (end && p < end && *p == ',' && *(p-1) != '\\') { |
2513 | |
2514 | if (q || alt) { |
2515 | *p = QUOTED_ESC_COMMA1; |
2516 | } else { |
2517 | *p = UNQUOTED_ESC_COMMA2; |
2518 | } |
2519 | } |
2520 | |
2521 | if (p == end) { |
2522 | end = switch_strchr_strict(p, '[', " "); |
2523 | } |
2524 | |
2525 | p++; |
2526 | } |
2527 | |
2528 | and_argc = switch_separate_string(pipe_names[r], ',', peer_names, (sizeof(peer_names) / sizeof(peer_names[0]))); |
2529 | |
2530 | if ((flags & SOF_NOBLOCK) && and_argc > 1) { |
2531 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2531, (const char*)(session), SWITCH_LOG_WARNING, "Only calling the first element in the list in this mode.\n"); |
2532 | and_argc = 1; |
2533 | } |
2534 | |
2535 | for (i = 0; i < and_argc; i++) { |
2536 | const char *current_variable; |
2537 | switch_event_t *local_var_event = NULL((void*)0), *originate_var_event = NULL((void*)0); |
2538 | |
2539 | end = NULL((void*)0); |
2540 | |
2541 | chan_type = peer_names[i]; |
2542 | |
2543 | |
2544 | /* strip leading spaces */ |
2545 | while (chan_type && *chan_type && *chan_type == ' ') { |
2546 | chan_type++; |
2547 | } |
2548 | |
2549 | /* extract channel variables, allowing multiple sets of braces */ |
2550 | |
2551 | if (*chan_type == '[') { |
2552 | switch_event_create_plain(&local_var_event, SWITCH_EVENT_CHANNEL_DATA); |
2553 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2553, (const char*)(session), SWITCH_LOG_DEBUG, "Parsing session specific variables\n"); |
2554 | } |
2555 | |
2556 | while (*chan_type == '[') { |
2557 | char *parsed = NULL((void*)0); |
2558 | char *bend = switch_find_end_paren(chan_type, '[', ']'); |
2559 | |
2560 | for (p = chan_type + 1; p && p < bend && *p; p++) { |
2561 | if (*p == QUOTED_ESC_COMMA1) { |
2562 | *p = ','; |
2563 | } |
2564 | } |
2565 | |
2566 | if (switch_event_create_brackets(chan_type, '[', ']', UNQUOTED_ESC_COMMA2, |
2567 | &local_var_event, &parsed, SWITCH_FALSE) != SWITCH_STATUS_SUCCESS || !parsed) { |
2568 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2568, (const char*)(session), SWITCH_LOG_ERROR, "Parse Error!\n"); |
2569 | switch_goto_status(SWITCH_STATUS_GENERR, done)status = SWITCH_STATUS_GENERR; goto done; |
2570 | } |
2571 | |
2572 | if (chan_type == parsed) { |
2573 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2573, (const char*)(session), SWITCH_LOG_ERROR, "Parse Error!\n"); |
2574 | switch_goto_status(SWITCH_STATUS_GENERR, done)status = SWITCH_STATUS_GENERR; goto done; |
2575 | } else { |
2576 | chan_type = parsed; |
2577 | } |
2578 | } |
2579 | |
2580 | |
2581 | /* strip leading spaces (again) */ |
2582 | while (chan_type && *chan_type && *chan_type == ' ') { |
2583 | chan_type++; |
2584 | } |
2585 | |
2586 | if ((chan_data = strchr(chan_type, '/')(__extension__ (__builtin_constant_p ('/') && !__builtin_constant_p (chan_type) && ('/') == '\0' ? (char *) __rawmemchr ( chan_type, '/') : __builtin_strchr (chan_type, '/')))) != 0) { |
2587 | *chan_data = '\0'; |
2588 | chan_data++; |
2589 | } |
2590 | |
2591 | if (oglobals.session) { |
2592 | if (!switch_channel_ready(caller_channel)switch_channel_test_ready(caller_channel, SWITCH_TRUE, SWITCH_FALSE )) { |
2593 | status = SWITCH_STATUS_FALSE; |
2594 | goto done; |
2595 | } |
2596 | |
2597 | if ((caller_caller_profile = oglobals.caller_profile_override)) { |
2598 | new_profile = switch_caller_profile_dup(oglobals.pool, caller_caller_profile); |
2599 | } else { |
2600 | new_profile = switch_caller_profile_new(oglobals.pool, |
2601 | NULL((void*)0), |
2602 | NULL((void*)0), |
2603 | cid_name_override, cid_num_override, NULL((void*)0), ani_override, aniii_override, NULL((void*)0), __FILE__"src/switch_ivr_originate.c", NULL((void*)0), chan_data); |
2604 | } |
2605 | |
2606 | new_profile->uuid = SWITCH_BLANK_STRING""; |
2607 | new_profile->chan_name = SWITCH_BLANK_STRING""; |
2608 | new_profile->destination_number = switch_core_strdup(new_profile->pool, chan_data)switch_core_perform_strdup(new_profile->pool, chan_data, "src/switch_ivr_originate.c" , (const char *)__func__, 2608); |
2609 | |
2610 | if (ani_override) { |
2611 | new_profile->ani = switch_core_strdup(new_profile->pool, ani_override)switch_core_perform_strdup(new_profile->pool, ani_override , "src/switch_ivr_originate.c", (const char *)__func__, 2611); |
2612 | } |
2613 | if (aniii_override) { |
2614 | new_profile->aniii = switch_core_strdup(new_profile->pool, aniii_override)switch_core_perform_strdup(new_profile->pool, aniii_override , "src/switch_ivr_originate.c", (const char *)__func__, 2614); |
2615 | } |
2616 | if (cid_name_override) { |
2617 | new_profile->caller_id_name = switch_core_strdup(new_profile->pool, cid_name_override)switch_core_perform_strdup(new_profile->pool, cid_name_override , "src/switch_ivr_originate.c", (const char *)__func__, 2617); |
2618 | } |
2619 | if (cid_num_override) { |
2620 | new_profile->caller_id_number = switch_core_strdup(new_profile->pool, cid_num_override)switch_core_perform_strdup(new_profile->pool, cid_num_override , "src/switch_ivr_originate.c", (const char *)__func__, 2620); |
2621 | } |
2622 | } else { |
2623 | if (oglobals.caller_profile_override) { |
2624 | new_profile = switch_caller_profile_dup(oglobals.pool, oglobals.caller_profile_override); |
2625 | new_profile->destination_number = switch_core_strdup(new_profile->pool, switch_str_nil(chan_data))switch_core_perform_strdup(new_profile->pool, (chan_data ? chan_data : ""), "src/switch_ivr_originate.c", (const char * )__func__, 2625); |
2626 | new_profile->uuid = SWITCH_BLANK_STRING""; |
2627 | new_profile->chan_name = SWITCH_BLANK_STRING""; |
2628 | } else { |
2629 | if (!cid_name_override) { |
2630 | cid_name_override = SWITCH_DEFAULT_CLID_NAME""; |
2631 | } |
2632 | if (!cid_num_override) { |
2633 | cid_num_override = SWITCH_DEFAULT_CLID_NUMBER"0000000000"; |
2634 | } |
2635 | |
2636 | new_profile = switch_caller_profile_new(oglobals.pool, |
2637 | NULL((void*)0), |
2638 | NULL((void*)0), |
2639 | cid_name_override, cid_num_override, NULL((void*)0), ani_override, aniii_override, NULL((void*)0), __FILE__"src/switch_ivr_originate.c", NULL((void*)0), chan_data); |
2640 | } |
2641 | } |
2642 | |
2643 | if (zstr(new_profile->destination_number)_zstr(new_profile->destination_number)) { |
2644 | new_profile->destination_number = switch_core_strdup(new_profile->pool, "service")switch_core_perform_strdup(new_profile->pool, "service", "src/switch_ivr_originate.c" , (const char *)__func__, 2644); |
2645 | } |
2646 | |
2647 | new_profile->callee_id_name = switch_core_strdup(new_profile->pool, "Outbound Call")switch_core_perform_strdup(new_profile->pool, "Outbound Call" , "src/switch_ivr_originate.c", (const char *)__func__, 2647); |
2648 | new_profile->callee_id_number = switch_sanitize_number(switch_core_strdup(new_profile->pool, new_profile->destination_number)switch_core_perform_strdup(new_profile->pool, new_profile-> destination_number, "src/switch_ivr_originate.c", (const char *)__func__, 2648)); |
2649 | |
2650 | originate_status[i].caller_profile = NULL((void*)0); |
2651 | originate_status[i].peer_channel = NULL((void*)0); |
2652 | originate_status[i].peer_session = NULL((void*)0); |
2653 | new_session = NULL((void*)0); |
2654 | |
2655 | if (and_argc > 1 || or_argc > 1) { |
2656 | myflags |= SOF_FORKED_DIAL; |
2657 | } |
2658 | |
2659 | if (var_event) { |
2660 | const char *vvar; |
2661 | if ((vvar = switch_event_get_header(var_event, "forked_dial")switch_event_get_header_idx(var_event, "forked_dial", -1)) && switch_true(vvar)) { |
2662 | myflags |= SOF_FORKED_DIAL; |
2663 | } |
2664 | if ((vvar = switch_event_get_header(var_event, "no_throttle_limits")switch_event_get_header_idx(var_event, "no_throttle_limits", - 1)) && switch_true(vvar)) { |
2665 | myflags |= SOF_NO_LIMITS; |
2666 | } |
2667 | } |
2668 | |
2669 | |
2670 | /* Valid in both {} and [] with [] taking precedence */ |
2671 | |
2672 | /* make a special var event with mixture of the {} and the [] vars to pass down as global vars to the outgoing channel |
2673 | so if something like the user channel does another originate our options will be passed down properly |
2674 | */ |
2675 | |
2676 | switch_event_dup(&originate_var_event, var_event); |
2677 | |
2678 | if (local_var_event) { |
2679 | switch_event_merge(originate_var_event, local_var_event); |
2680 | } |
2681 | |
2682 | if ((current_variable = switch_event_get_header(originate_var_event, "origination_ani")switch_event_get_header_idx(originate_var_event, "origination_ani" , -1))) { |
2683 | new_profile->ani = switch_core_strdup(new_profile->pool, current_variable)switch_core_perform_strdup(new_profile->pool, current_variable , "src/switch_ivr_originate.c", (const char *)__func__, 2683); |
2684 | myflags |= SOF_NO_EFFECTIVE_ANI; |
2685 | } |
2686 | |
2687 | if ((current_variable = switch_event_get_header(originate_var_event, "origination_aniii")switch_event_get_header_idx(originate_var_event, "origination_aniii" , -1))) { |
2688 | new_profile->aniii = switch_core_strdup(new_profile->pool, current_variable)switch_core_perform_strdup(new_profile->pool, current_variable , "src/switch_ivr_originate.c", (const char *)__func__, 2688); |
2689 | myflags |= SOF_NO_EFFECTIVE_ANIII; |
2690 | } |
2691 | |
2692 | if ((current_variable = switch_event_get_header(originate_var_event, "origination_caller_id_number")switch_event_get_header_idx(originate_var_event, "origination_caller_id_number" , -1))) { |
2693 | new_profile->caller_id_number = switch_core_strdup(new_profile->pool, current_variable)switch_core_perform_strdup(new_profile->pool, current_variable , "src/switch_ivr_originate.c", (const char *)__func__, 2693); |
2694 | myflags |= SOF_NO_EFFECTIVE_CID_NUM; |
2695 | } |
2696 | |
2697 | if ((current_variable = switch_event_get_header(originate_var_event, "origination_caller_id_name")switch_event_get_header_idx(originate_var_event, "origination_caller_id_name" , -1))) { |
2698 | new_profile->caller_id_name = switch_core_strdup(new_profile->pool, current_variable)switch_core_perform_strdup(new_profile->pool, current_variable , "src/switch_ivr_originate.c", (const char *)__func__, 2698); |
2699 | myflags |= SOF_NO_EFFECTIVE_CID_NAME; |
2700 | } |
2701 | |
2702 | if ((current_variable = switch_event_get_header(originate_var_event, "origination_privacy")switch_event_get_header_idx(originate_var_event, "origination_privacy" , -1))) { |
2703 | new_profile->flags = SWITCH_CPF_NONE; |
2704 | |
2705 | if (switch_stristr("screen", current_variable)) { |
2706 | switch_set_flag(new_profile, SWITCH_CPF_SCREEN)(new_profile)->flags |= (SWITCH_CPF_SCREEN); |
2707 | } |
2708 | |
2709 | if (switch_stristr("hide_name", current_variable)) { |
2710 | switch_set_flag(new_profile, SWITCH_CPF_HIDE_NAME)(new_profile)->flags |= (SWITCH_CPF_HIDE_NAME); |
2711 | } |
2712 | |
2713 | if (switch_stristr("hide_number", current_variable)) { |
2714 | switch_set_flag(new_profile, SWITCH_CPF_HIDE_NUMBER)(new_profile)->flags |= (SWITCH_CPF_HIDE_NUMBER); |
2715 | } |
2716 | } |
2717 | |
2718 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "originate_early_media", oglobals.early_ok ? "true" : "false"); |
2719 | |
2720 | |
2721 | if (caller_channel && switch_true(switch_channel_get_variable(caller_channel, "push_channel_name")switch_channel_get_variable_dup(caller_channel, "push_channel_name" , SWITCH_TRUE, -1))) { |
2722 | char *new_name = switch_core_session_sprintf(session, "%s__B", switch_channel_get_name(caller_channel)); |
2723 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "origination_channel_name", new_name); |
2724 | new_name = switch_core_session_sprintf(session, "_%s", switch_channel_get_name(caller_channel)); |
2725 | switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "sip_h_X-FS-Channel-Name", new_name); |
2726 | } |
2727 | |
2728 | |
2729 | reason = switch_core_session_outgoing_channel(oglobals.session, originate_var_event, chan_type, |
2730 | new_profile, &new_session, NULL((void*)0), myflags, cancel_cause); |
2731 | |
2732 | switch_event_destroy(&originate_var_event); |
2733 | |
2734 | if (reason != SWITCH_CAUSE_SUCCESS) { |
2735 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2735, (const char*)(session), SWITCH_LOG_NOTICE, "Cannot create outgoing channel of type [%s] cause: [%s]\n", |
2736 | chan_type, switch_channel_cause2str(reason)); |
2737 | if (local_var_event) switch_event_destroy(&local_var_event); |
2738 | |
2739 | if (fail_on_single_reject_var) { |
2740 | const char *cause_str = switch_channel_cause2str(reason); |
2741 | int neg = *fail_on_single_reject_var == '!'; |
2742 | int pos = !!switch_stristr(cause_str, fail_on_single_reject_var); |
2743 | |
2744 | if (neg) { |
2745 | pos = !pos; |
2746 | } |
2747 | |
2748 | check_reject = 0; |
2749 | |
2750 | if (fail_on_single_reject == 1 || pos) { |
2751 | force_reason = reason; |
2752 | status = SWITCH_STATUS_FALSE; |
2753 | goto outer_for; |
2754 | } |
2755 | } |
2756 | continue; |
2757 | } |
2758 | |
2759 | if (switch_core_session_read_lock(new_session) != SWITCH_STATUS_SUCCESS) { |
2760 | status = SWITCH_STATUS_FALSE; |
2761 | if (local_var_event) switch_event_destroy(&local_var_event); |
2762 | goto done; |
2763 | } |
2764 | |
2765 | originate_status[i].peer_channel = switch_core_session_get_channel(new_session); |
2766 | originate_status[i].caller_profile = switch_channel_get_caller_profile(originate_status[i].peer_channel); |
2767 | originate_status[i].peer_session = new_session; |
2768 | |
2769 | switch_channel_set_flag(originate_status[i].peer_channel, CF_ORIGINATING)switch_channel_set_flag_value(originate_status[i].peer_channel , CF_ORIGINATING, 1); |
2770 | |
2771 | if (caller_channel) { |
2772 | switch_channel_set_variable(originate_status[i].peer_channel, "call_uuid", switch_channel_get_variable(caller_channel, "call_uuid"))switch_channel_set_variable_var_check(originate_status[i].peer_channel , "call_uuid", switch_channel_get_variable_dup(caller_channel , "call_uuid", SWITCH_TRUE, -1), SWITCH_TRUE); |
2773 | } |
2774 | |
2775 | |
2776 | if (local_var_event) { |
2777 | const char *device_id = switch_event_get_header(local_var_event, "device_id")switch_event_get_header_idx(local_var_event, "device_id", -1); |
2778 | switch_channel_set_profile_var(originate_status[i].peer_channel, "device_id", device_id); |
2779 | } |
2780 | |
2781 | if ((lc = switch_event_get_header(var_event, "local_var_clobber")switch_event_get_header_idx(var_event, "local_var_clobber", - 1))) { |
2782 | local_clobber = switch_true(lc); |
2783 | } |
2784 | |
2785 | if (switch_channel_test_flag(originate_status[i].peer_channel, CF_NO_PRESENCE)) { |
2786 | if (var_event) { |
2787 | switch_event_del_header(var_event, "presence_id")switch_event_del_header_val(var_event, "presence_id", ((void* )0)); |
2788 | } |
2789 | if (local_var_event) { |
2790 | switch_event_del_header(local_var_event, "presence_id")switch_event_del_header_val(local_var_event, "presence_id", ( (void*)0)); |
2791 | } |
2792 | } |
2793 | |
2794 | |
2795 | if (local_clobber) { |
2796 | if (var_event) { |
2797 | switch_event_header_t *header; |
2798 | /* install the vars from the {} params */ |
2799 | for (header = var_event->headers; header; header = header->next) { |
2800 | switch_channel_set_variable_var_check(originate_status[i].peer_channel, header->name, header->value, oglobals.check_vars); |
2801 | } |
2802 | } |
2803 | } |
2804 | |
2805 | /* copy local originate vars to the channel */ |
2806 | if (local_var_event) { |
2807 | switch_event_header_t *header; |
2808 | for (header = local_var_event->headers; header; header = header->next) { |
2809 | switch_channel_set_variable_var_check(originate_status[i].peer_channel, header->name, header->value, oglobals.check_vars); |
2810 | } |
2811 | switch_event_destroy(&local_var_event); |
2812 | } |
2813 | |
2814 | if (!local_clobber) { |
2815 | if (var_event) { |
2816 | switch_event_header_t *header; |
2817 | /* install the vars from the {} params */ |
2818 | for (header = var_event->headers; header; header = header->next) { |
2819 | switch_channel_set_variable_var_check(originate_status[i].peer_channel, header->name, header->value, oglobals.check_vars); |
2820 | } |
2821 | } |
2822 | } |
2823 | |
2824 | if (originate_status[i].peer_channel) { |
2825 | const char *vvar; |
2826 | |
2827 | if (switch_true(switch_channel_get_variable(originate_status[i].peer_channel, "leg_required")switch_channel_get_variable_dup(originate_status[i].peer_channel , "leg_required", SWITCH_TRUE, -1))) { |
2828 | originate_status[i].tagged = 1; |
2829 | } |
2830 | |
2831 | if ((vvar = switch_channel_get_variable(originate_status[i].peer_channel, "origination_channel_name")switch_channel_get_variable_dup(originate_status[i].peer_channel , "origination_channel_name", SWITCH_TRUE, -1))) { |
2832 | switch_channel_set_name(originate_status[i].peer_channel, vvar); |
2833 | } |
2834 | |
2835 | if ((vvar = switch_channel_get_variable(originate_status[i].peer_channel, "origination_callee_id_name")switch_channel_get_variable_dup(originate_status[i].peer_channel , "origination_callee_id_name", SWITCH_TRUE, -1))) { |
2836 | switch_channel_set_profile_var(originate_status[i].peer_channel, "callee_id_name", vvar); |
2837 | } |
2838 | |
2839 | if ((vvar = switch_channel_get_variable(originate_status[i].peer_channel, "origination_callee_id_number")switch_channel_get_variable_dup(originate_status[i].peer_channel , "origination_callee_id_number", SWITCH_TRUE, -1))) { |
2840 | switch_channel_set_profile_var(originate_status[i].peer_channel, "callee_id_number", vvar); |
2841 | } |
2842 | |
2843 | if ((vvar = switch_channel_get_variable(originate_status[i].peer_channel, "leg_timeout")switch_channel_get_variable_dup(originate_status[i].peer_channel , "leg_timeout", SWITCH_TRUE, -1))) { |
2844 | int val = atoi(vvar); |
2845 | |
2846 | if (val > 0) { |
2847 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2847, (const char*)(session), SWITCH_LOG_DEBUG, "%s Setting leg timeout to %d\n", |
2848 | switch_channel_get_name(originate_status[i].peer_channel), val); |
2849 | originate_status[i].per_channel_timelimit_sec = (uint32_t) val; |
2850 | } |
2851 | } |
2852 | |
2853 | if ((vvar = switch_channel_get_variable(originate_status[i].peer_channel, "leg_progress_timeout")switch_channel_get_variable_dup(originate_status[i].peer_channel , "leg_progress_timeout", SWITCH_TRUE, -1))) { |
2854 | int val = atoi(vvar); |
2855 | if (val > 0) { |
2856 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2856, (const char*)(session), SWITCH_LOG_DEBUG, "%s Setting leg progress timeout to %d\n", |
2857 | switch_channel_get_name(originate_status[i].peer_channel), val); |
2858 | originate_status[i].per_channel_progress_timelimit_sec = (uint32_t) val; |
2859 | } |
2860 | } |
2861 | |
2862 | if ((vvar = switch_channel_get_variable(originate_status[i].peer_channel, "leg_delay_start")switch_channel_get_variable_dup(originate_status[i].peer_channel , "leg_delay_start", SWITCH_TRUE, -1))) { |
2863 | int val = atoi(vvar); |
2864 | if (val > 0) { |
2865 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 2865, (const char*)(session), SWITCH_LOG_DEBUG, "%s Setting leg delay start to %d\n", |
2866 | switch_channel_get_name(originate_status[i].peer_channel), val); |
2867 | originate_status[i].per_channel_delay_start = (uint32_t) val; |
2868 | |
2869 | if (originate_status[i].per_channel_progress_timelimit_sec != 0) { |
2870 | originate_status[i].per_channel_progress_timelimit_sec += originate_status[i].per_channel_delay_start; |
2871 | } |
2872 | |
2873 | if (originate_status[i].per_channel_timelimit_sec != 0) { |
2874 | originate_status[i].per_channel_timelimit_sec += originate_status[i].per_channel_delay_start; |
2875 | } |
2876 | } |
2877 | } |
2878 | |
2879 | if (!zstr(ent_aleg_uuid)_zstr(ent_aleg_uuid)) { |
2880 | l_session = switch_core_session_locate(ent_aleg_uuid)switch_core_session_perform_locate(ent_aleg_uuid, "src/switch_ivr_originate.c" , (const char *)__func__, 2880); |
2881 | a_session = l_session; |
2882 | } |
2883 | |
2884 | if (a_session) { |
2885 | switch_channel_t *channel = switch_core_session_get_channel(a_session); |
2886 | char *val = |
2887 | switch_core_session_sprintf(a_session, "%s;%s;%s", |
2888 | switch_core_session_get_uuid(originate_status[i].peer_session), |
2889 | switch_str_nil(switch_channel_get_variable(originate_status[i].peer_channel, "callee_id_name"))(switch_channel_get_variable_dup(originate_status[i].peer_channel , "callee_id_name", SWITCH_TRUE, -1) ? switch_channel_get_variable_dup (originate_status[i].peer_channel, "callee_id_name", SWITCH_TRUE , -1) : ""), |
2890 | switch_str_nil(switch_channel_get_variable(originate_status[i].peer_channel, "callee_id_number"))(switch_channel_get_variable_dup(originate_status[i].peer_channel , "callee_id_number", SWITCH_TRUE, -1) ? switch_channel_get_variable_dup (originate_status[i].peer_channel, "callee_id_number", SWITCH_TRUE , -1) : "")); |
2891 | |
2892 | |
2893 | switch_channel_set_variable(originate_status[i].peer_channel, "originating_leg_uuid", switch_core_session_get_uuid(a_session))switch_channel_set_variable_var_check(originate_status[i].peer_channel , "originating_leg_uuid", switch_core_session_get_uuid(a_session ), SWITCH_TRUE); |
2894 | |
2895 | switch_channel_add_variable_var_check(channel, "originated_legs", val, SWITCH_FALSE, SWITCH_STACK_PUSH); |
2896 | |
2897 | } |
2898 | |
2899 | if (l_session) { |
2900 | switch_core_session_rwunlock(l_session); |
2901 | l_session = NULL((void*)0); |
2902 | } |
2903 | |
2904 | switch_channel_execute_on(originate_status[i].peer_channel, SWITCH_CHANNEL_EXECUTE_ON_ORIGINATE_VARIABLE"execute_on_originate"); |
2905 | switch_channel_api_on(originate_status[i].peer_channel, SWITCH_CHANNEL_API_ON_ORIGINATE_VARIABLE"api_on_originate"); |
2906 | } |
2907 | |
2908 | if (table) { |
2909 | switch_channel_add_state_handler(originate_status[i].peer_channel, table); |
2910 | } |
2911 | |
2912 | if (oglobals.monitor_early_media_ring || oglobals.monitor_early_media_fail || oglobals.ignore_early_media == 4) { |
2913 | switch_channel_set_flag(originate_status[i].peer_channel, CF_CONSUME_ON_ORIGINATE)switch_channel_set_flag_value(originate_status[i].peer_channel , CF_CONSUME_ON_ORIGINATE, 1); |
2914 | } |
2915 | |
2916 | switch_channel_add_state_handler(originate_status[i].peer_channel, &originate_state_handlers); |
2917 | |
2918 | if ((flags & SOF_NOBLOCK) && originate_status[i].peer_session) { |
2919 | status = SWITCH_STATUS_SUCCESS; |
2920 | *bleg = originate_status[i].peer_session; |
2921 | *cause = SWITCH_CAUSE_SUCCESS; |
2922 | goto outer_for; |
2923 | } |
2924 | |
2925 | if (!switch_core_session_running(originate_status[i].peer_session)) { |
2926 | if (originate_status[i].per_channel_delay_start) { |
2927 | switch_channel_set_flag(originate_status[i].peer_channel, CF_BLOCK_STATE)switch_channel_set_flag_value(originate_status[i].peer_channel , CF_BLOCK_STATE, 1); |
2928 | } |
2929 | switch_core_session_thread_launch(originate_status[i].peer_session); |
2930 | } |
2931 | } |
2932 | |
2933 | switch_epoch_time_now(&start); |
2934 | |
2935 | for (;;) { |
2936 | uint32_t valid_channels = 0; |
2937 | for (i = 0; i < and_argc; i++) { |
2938 | int state; |
2939 | time_t elapsed; |
2940 | |
2941 | if (!originate_status[i].peer_channel) { |
2942 | continue; |
2943 | } |
2944 | |
2945 | state = switch_channel_get_state(originate_status[i].peer_channel); |
2946 | |
2947 | if (state < CS_HANGUP) { |
2948 | valid_channels++; |
2949 | } else { |
2950 | continue; |
2951 | } |
2952 | |
2953 | if (state >= CS_ROUTING) { |
2954 | goto endfor1; |
2955 | } |
2956 | |
2957 | if (caller_channel && !switch_channel_ready(caller_channel)switch_channel_test_ready(caller_channel, SWITCH_TRUE, SWITCH_FALSE )) { |
2958 | goto notready; |
2959 | } |
2960 | |
2961 | elapsed = switch_epoch_time_now(NULL((void*)0)) - start; |
2962 | |
2963 | if (elapsed > (time_t) timelimit_sec) { |
2964 | to++; |
2965 | oglobals.idx = IDX_TIMEOUT; |
2966 | goto notready; |
2967 | } |
2968 | |
2969 | if (!oglobals.sent_ring && !oglobals.ignore_ring_ready && |
2970 | !oglobals.progress && (progress_timelimit_sec && elapsed > (time_t) progress_timelimit_sec)) { |
2971 | to++; |
2972 | oglobals.idx = IDX_TIMEOUT; |
2973 | if (force_reason == SWITCH_CAUSE_NONE) { |
2974 | force_reason = SWITCH_CAUSE_PROGRESS_TIMEOUT; |
2975 | } |
2976 | goto notready; |
2977 | } |
2978 | |
2979 | switch_cond_next(); |
2980 | } |
2981 | |
2982 | check_per_channel_timeouts(&oglobals, originate_status, and_argc, start, &force_reason); |
2983 | |
2984 | |
2985 | if (valid_channels == 0) { |
2986 | status = SWITCH_STATUS_GENERR; |
2987 | goto done; |
2988 | } |
2989 | |
2990 | } |
2991 | |
2992 | endfor1: |
2993 | |
2994 | if (caller_channel) { |
2995 | if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE) || |
2996 | switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA) || switch_channel_test_flag(caller_channel, CF_DISABLE_RINGBACK)) { |
2997 | ringback_data = NULL((void*)0); |
2998 | } |
2999 | } |
3000 | |
3001 | |
3002 | #if 0 |
3003 | /* changing behaviour ignore_early_media=true must also be explicitly set for previous behaviour */ |
3004 | if (ringback_data) { |
3005 | oglobals.early_ok = 0; |
3006 | } |
3007 | #endif |
3008 | |
3009 | if (ringback_data) { |
3010 | oglobals.sending_ringback = 1; |
3011 | } else { |
3012 | oglobals.ringback_ok = 0; |
3013 | } |
3014 | |
3015 | if (caller_channel) { |
3016 | soft_holding = switch_channel_get_variable(caller_channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE)switch_channel_get_variable_dup(caller_channel, "soft_holding_uuid" , SWITCH_TRUE, -1); |
3017 | } |
3018 | |
3019 | while ((!caller_channel || switch_channel_ready(caller_channel)switch_channel_test_ready(caller_channel, SWITCH_TRUE, SWITCH_FALSE ) || switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) && |
3020 | check_channel_status(&oglobals, originate_status, and_argc, &force_reason)) { |
3021 | time_t elapsed = switch_epoch_time_now(NULL((void*)0)) - start; |
3022 | |
3023 | read_packet = 0; |
3024 | |
3025 | if (cancel_cause && *cancel_cause > 0) { |
3026 | if (force_reason == SWITCH_CAUSE_NONE) { |
3027 | force_reason = *cancel_cause; |
3028 | } |
3029 | oglobals.idx = IDX_CANCEL; |
3030 | goto notready; |
3031 | } |
3032 | |
3033 | check_per_channel_timeouts(&oglobals, originate_status, and_argc, start, &force_reason); |
3034 | |
3035 | if (oglobals.session) { |
3036 | switch_ivr_parse_all_events(oglobals.session); |
3037 | } |
3038 | |
3039 | if (!oglobals.sent_ring && !oglobals.progress && (progress_timelimit_sec && elapsed > (time_t) progress_timelimit_sec)) { |
3040 | oglobals.idx = IDX_TIMEOUT; |
3041 | if (force_reason == SWITCH_CAUSE_NONE) { |
3042 | force_reason = SWITCH_CAUSE_PROGRESS_TIMEOUT; |
3043 | } |
3044 | goto notready; |
3045 | } |
3046 | |
3047 | if ((to = (uint8_t) (elapsed >= (time_t) timelimit_sec)) || (fail_on_single_reject && oglobals.hups)) { |
3048 | int ok = 0; |
3049 | |
3050 | if (fail_on_single_reject_var) { |
3051 | if (!switch_true(fail_on_single_reject_var)) { |
3052 | ok = 1; |
3053 | |
3054 | for (i = 0; i < and_argc; i++) { |
3055 | switch_channel_t *pchannel; |
3056 | const char *cause_str; |
3057 | |
3058 | if (!originate_status[i].peer_session) { |
3059 | continue; |
3060 | } |
3061 | pchannel = switch_core_session_get_channel(originate_status[i].peer_session); |
3062 | |
3063 | if (switch_channel_down_nosig(pchannel)(switch_channel_get_state(pchannel) >= CS_HANGUP)) { |
3064 | int neg, pos; |
3065 | cause_str = switch_channel_cause2str(switch_channel_get_cause(pchannel)); |
3066 | neg = *fail_on_single_reject_var == '!'; |
3067 | pos = !!switch_stristr(cause_str, fail_on_single_reject_var); |
3068 | |
3069 | if (neg) { |
3070 | pos = !pos; |
3071 | } |
3072 | |
3073 | if (pos) { |
3074 | ok = 0; |
3075 | break; |
3076 | } |
3077 | } |
3078 | } |
3079 | } |
3080 | } |
3081 | if (!ok) { |
3082 | oglobals.idx = IDX_TIMEOUT; |
3083 | goto notready; |
3084 | } |
3085 | } |
3086 | |
3087 | /* read from the channel while we wait if the audio is up on it */ |
3088 | if (oglobals.session && |
3089 | !switch_channel_test_flag(caller_channel, CF_PROXY_MODE) && |
3090 | !switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA) && |
3091 | !switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE) && |
3092 | (oglobals.ringback_ok |
3093 | || (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)))) { |
3094 | |
3095 | switch_status_t tstatus = SWITCH_STATUS_SUCCESS; |
3096 | int silence = 0; |
3097 | |
3098 | if (caller_channel && cancel_key) { |
3099 | if (switch_channel_has_dtmf(caller_channel)) { |
3100 | switch_dtmf_t dtmf = { 0, 0 }; |
3101 | if (switch_channel_dequeue_dtmf(caller_channel, &dtmf) == SWITCH_STATUS_SUCCESS) { |
3102 | if (dtmf.digit == *cancel_key) { |
3103 | oglobals.idx = IDX_KEY_CANCEL; |
3104 | goto notready; |
3105 | } |
3106 | } |
3107 | } |
3108 | } |
3109 | |
3110 | if (switch_channel_media_ready(caller_channel)switch_channel_test_ready(caller_channel, SWITCH_TRUE, SWITCH_TRUE )) { |
3111 | tstatus = switch_core_session_read_frame(oglobals.session, &read_frame, SWITCH_IO_FLAG_NONE, 0); |
3112 | if (!SWITCH_READ_ACCEPTABLE(tstatus)(tstatus == SWITCH_STATUS_SUCCESS || tstatus == SWITCH_STATUS_BREAK || tstatus == SWITCH_STATUS_INUSE)) { |
3113 | if (soft_holding) { |
3114 | switch_channel_set_flag(caller_channel, CF_XFER_ZOMBIE)switch_channel_set_flag_value(caller_channel, CF_XFER_ZOMBIE, 1); |
3115 | } |
3116 | |
3117 | if (switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) { |
3118 | goto do_continue; |
3119 | } |
3120 | break; |
3121 | } |
3122 | |
3123 | read_packet++; |
3124 | } else { |
3125 | read_frame = NULL((void*)0); |
3126 | } |
3127 | |
3128 | |
3129 | if (oglobals.ringback_ok && (oglobals.ring_ready || oglobals.instant_ringback || |
3130 | oglobals.sending_ringback > 1 || oglobals.bridge_early_media > -1)) { |
3131 | if (oglobals.ringback_ok == 1) { |
3132 | switch_status_t rst; |
3133 | |
3134 | rst = setup_ringback(&oglobals, originate_status, and_argc, ringback_data, &ringback, &write_frame, &write_codec); |
3135 | |
3136 | if (oglobals.bridge_early_media > -1) { |
3137 | switch_threadattr_t *thd_attr = NULL((void*)0); |
3138 | switch_threadattr_create(&thd_attr, switch_core_session_get_pool(session)); |
3139 | switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE240 * 1024); |
3140 | early_state.oglobals = &oglobals; |
3141 | early_state.originate_status = originate_status; |
3142 | early_state.ready = 1; |
3143 | early_state.ringback = &ringback; |
3144 | early_state.ttl = and_argc; |
3145 | switch_mutex_init(&early_state.mutex, SWITCH_MUTEX_NESTED0x1, switch_core_session_get_pool(session)); |
3146 | switch_buffer_create_dynamic(&early_state.buffer, 1024, 1024, 0); |
3147 | switch_thread_create(&oglobals.ethread, thd_attr, early_thread_run, &early_state, switch_core_session_get_pool(session)); |
3148 | } |
3149 | |
3150 | |
3151 | switch (rst) { |
3152 | case SWITCH_STATUS_SUCCESS: |
3153 | oglobals.ringback_ok++; |
3154 | break; |
3155 | case SWITCH_STATUS_FALSE: |
3156 | goto notready; |
3157 | break; |
3158 | case SWITCH_STATUS_BREAK: |
3159 | status = SWITCH_STATUS_FALSE; |
3160 | goto done; |
3161 | break; |
3162 | default: |
3163 | ringback_data = NULL((void*)0); |
3164 | oglobals.ringback_ok = 0; |
3165 | oglobals.sending_ringback = 0; |
3166 | break; |
3167 | } |
3168 | |
3169 | goto do_continue; |
3170 | } |
3171 | |
3172 | if (oglobals.bridge_early_media > -1) { |
3173 | write_frame.datalen = 0; |
3174 | switch_mutex_lock(early_state.mutex); |
3175 | if (ringback.asis) { |
3176 | uint16_t mlen; |
3177 | switch_size_t buflen = switch_buffer_inuse(early_state.buffer); |
3178 | if (buflen > sizeof(uint16_t)) { |
3179 | switch_buffer_peek(early_state.buffer, &mlen, sizeof(uint16_t)); |
3180 | if (buflen >= (mlen + sizeof(uint16_t))) { |
3181 | switch_buffer_toss(early_state.buffer, sizeof(uint16_t)); |
3182 | write_frame.datalen = (uint32_t)switch_buffer_read(early_state.buffer, write_frame.data, mlen); |
3183 | } |
3184 | } |
3185 | } else { |
3186 | if (switch_buffer_inuse(early_state.buffer) >= write_frame.codec->implementation->decoded_bytes_per_packet) { |
3187 | write_frame.datalen = (uint32_t)switch_buffer_read(early_state.buffer, write_frame.data, |
3188 | write_frame.codec->implementation->decoded_bytes_per_packet); |
3189 | } |
3190 | } |
3191 | switch_mutex_unlock(early_state.mutex); |
3192 | } else if (ringback.fh) { |
3193 | switch_size_t mlen, olen; |
3194 | unsigned int pos = 0; |
3195 | |
3196 | if (ringback.asis) { |
3197 | mlen = write_frame.codec->implementation->encoded_bytes_per_packet; |
3198 | } else { |
3199 | mlen = write_frame.codec->implementation->samples_per_packet; |
3200 | } |
3201 | |
3202 | olen = mlen; |
3203 | |
3204 | //if (ringback.fh->resampler && ringback.fh->resampler->rfactor > 1) { |
3205 | //olen = (switch_size_t) (olen * ringback.fh->resampler->rfactor); |
3206 | //} |
3207 | |
3208 | switch_core_file_read(ringback.fh, write_frame.data, &olen); |
3209 | |
3210 | if (olen == 0) { |
3211 | olen = mlen; |
3212 | ringback.fh->speed = 0; |
3213 | switch_core_file_seek(ringback.fh, &pos, 0, SEEK_SET0); |
3214 | switch_core_file_read(ringback.fh, write_frame.data, &olen); |
3215 | if (olen == 0) { |
3216 | break; |
3217 | } |
3218 | } |
3219 | write_frame.datalen = (uint32_t) (ringback.asis ? olen : olen * 2 * ringback.fh->channels); |
3220 | write_frame.samples = (uint32_t) olen; |
3221 | |
3222 | } else if (ringback.audio_buffer) { |
3223 | if ((write_frame.datalen = (uint32_t) switch_buffer_read_loop(ringback.audio_buffer, |
3224 | write_frame.data, |
3225 | write_frame.codec->implementation->decoded_bytes_per_packet)) <= |
3226 | 0) { |
3227 | |
3228 | if (soft_holding) { |
3229 | switch_channel_set_flag(caller_channel, CF_XFER_ZOMBIE)switch_channel_set_flag_value(caller_channel, CF_XFER_ZOMBIE, 1); |
3230 | goto do_continue; |
3231 | } |
3232 | |
3233 | break; |
3234 | } |
3235 | } else if (ringback.silence) { |
3236 | silence = ringback.silence; |
3237 | } |
3238 | } else { |
3239 | silence = 600; |
3240 | } |
3241 | |
3242 | if ((ringback.fh || silence || ringback.audio_buffer || oglobals.bridge_early_media > -1) && write_frame.codec && write_frame.codec->implementation && write_frame.datalen) { |
3243 | if (silence) { |
3244 | write_frame.datalen = read_impl.decoded_bytes_per_packet; |
3245 | switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.datalen / 2, write_frame.codec->implementation->number_of_channels, silence); |
3246 | } |
3247 | |
3248 | if (switch_core_session_write_frame(oglobals.session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { |
3249 | if (soft_holding) { |
3250 | switch_channel_set_flag(caller_channel, CF_XFER_ZOMBIE)switch_channel_set_flag_value(caller_channel, CF_XFER_ZOMBIE, 1); |
3251 | } |
3252 | if (switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) { |
3253 | goto do_continue; |
3254 | } |
3255 | break; |
3256 | } |
3257 | } |
3258 | |
3259 | } |
3260 | |
3261 | do_continue: |
3262 | |
3263 | if (!read_packet) { |
3264 | switch_yield(20000)switch_sleep(20000);; |
3265 | } |
3266 | } |
3267 | |
3268 | notready: |
3269 | |
3270 | if (caller_channel) { |
3271 | holding = switch_channel_get_variable(caller_channel, SWITCH_HOLDING_UUID_VARIABLE)switch_channel_get_variable_dup(caller_channel, "holding_uuid" , SWITCH_TRUE, -1); |
3272 | switch_channel_set_variable(caller_channel, SWITCH_HOLDING_UUID_VARIABLE, NULL)switch_channel_set_variable_var_check(caller_channel, "holding_uuid" , ((void*)0), SWITCH_TRUE); |
3273 | |
3274 | if (soft_holding && switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) { |
3275 | holding = soft_holding; |
3276 | soft_holding = NULL((void*)0); |
3277 | switch_channel_set_variable(caller_channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE, NULL)switch_channel_set_variable_var_check(caller_channel, "soft_holding_uuid" , ((void*)0), SWITCH_TRUE); |
3278 | } |
3279 | } |
3280 | |
3281 | if (caller_channel && !switch_channel_ready(caller_channel)switch_channel_test_ready(caller_channel, SWITCH_TRUE, SWITCH_FALSE ) && !switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) { |
3282 | oglobals.idx = IDX_CANCEL; |
3283 | } |
3284 | |
3285 | if (oglobals.session && (ringback_data || !(switch_channel_test_flag(caller_channel, CF_PROXY_MODE) || |
3286 | switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA)))) { |
3287 | switch_core_session_reset(oglobals.session, SWITCH_FALSE, SWITCH_TRUE); |
3288 | } |
3289 | |
3290 | if (holding) { |
3291 | if (oglobals.idx > IDX_NADA) { |
3292 | peer_session = originate_status[oglobals.idx].peer_session; |
3293 | peer_channel = originate_status[oglobals.idx].peer_channel; |
3294 | originate_status[oglobals.idx].peer_channel = NULL((void*)0); |
3295 | } else if (and_argc == 1) { |
3296 | peer_session = originate_status[0].peer_session; |
3297 | peer_channel = originate_status[0].peer_channel; |
3298 | originate_status[0].peer_channel = NULL((void*)0); |
3299 | } else { |
3300 | for (i = 0; i < and_argc; i++) { |
3301 | if (!peer_eligible(originate_status[i].peer_channel)(originate_status[i].peer_channel && !(switch_channel_test_flag (originate_status[i].peer_channel, CF_TRANSFER) || switch_channel_test_flag (originate_status[i].peer_channel, CF_REDIRECT) || switch_channel_test_flag (originate_status[i].peer_channel, CF_BRIDGED) || switch_channel_get_state (originate_status[i].peer_channel) == CS_RESET || !switch_channel_test_flag (originate_status[i].peer_channel, CF_ORIGINATING)))) { |
3302 | continue; |
3303 | } |
3304 | if (switch_channel_media_ready(originate_status[i].peer_channel)switch_channel_test_ready(originate_status[i].peer_channel, SWITCH_TRUE , SWITCH_TRUE)) { |
3305 | peer_session = originate_status[i].peer_session; |
3306 | peer_channel = originate_status[i].peer_channel; |
3307 | originate_status[i].peer_channel = NULL((void*)0); |
3308 | goto end_search; |
3309 | } |
3310 | } |
3311 | for (i = 0; i < and_argc; i++) { |
3312 | if (!peer_eligible(originate_status[i].peer_channel)(originate_status[i].peer_channel && !(switch_channel_test_flag (originate_status[i].peer_channel, CF_TRANSFER) || switch_channel_test_flag (originate_status[i].peer_channel, CF_REDIRECT) || switch_channel_test_flag (originate_status[i].peer_channel, CF_BRIDGED) || switch_channel_get_state (originate_status[i].peer_channel) == CS_RESET || !switch_channel_test_flag (originate_status[i].peer_channel, CF_ORIGINATING)))) { |
3313 | continue; |
3314 | } |
3315 | if (switch_channel_up_nosig(originate_status[i].peer_channel)(switch_channel_get_state(originate_status[i].peer_channel) < CS_HANGUP)) { |
3316 | peer_session = originate_status[i].peer_session; |
3317 | peer_channel = originate_status[i].peer_channel; |
3318 | originate_status[i].peer_channel = NULL((void*)0); |
3319 | break; |
3320 | } |
3321 | } |
3322 | } |
3323 | |
3324 | end_search: |
3325 | |
3326 | if (peer_channel && switch_channel_down_nosig(peer_channel)(switch_channel_get_state(peer_channel) >= CS_HANGUP)) { |
3327 | switch_core_session_rwunlock(peer_session); |
3328 | peer_session = NULL((void*)0); |
3329 | peer_channel = NULL((void*)0); |
3330 | |
3331 | } |
3332 | |
3333 | if (oglobals.idx == IDX_TIMEOUT || to || oglobals.idx == IDX_KEY_CANCEL || oglobals.idx == IDX_CANCEL || |
3334 | (!peer_session && oglobals.idx == IDX_NADA)) { |
3335 | const char *dest = NULL((void*)0); |
3336 | const char *context = NULL((void*)0); |
3337 | const char *dialplan = NULL((void*)0); |
3338 | switch_core_session_t *holding_session; |
3339 | |
3340 | if (caller_channel) { |
3341 | if (zstr(context)_zstr(context)) { |
3342 | context = switch_channel_get_variable(caller_channel, "context")switch_channel_get_variable_dup(caller_channel, "context", SWITCH_TRUE , -1); |
3343 | } |
3344 | if (zstr(dialplan)_zstr(dialplan)) { |
3345 | dialplan = switch_channel_get_variable(caller_channel, "dialplan")switch_channel_get_variable_dup(caller_channel, "dialplan", SWITCH_TRUE , -1); |
3346 | } |
3347 | } |
3348 | |
3349 | if (zstr(context)_zstr(context)) { |
3350 | context = "default"; |
3351 | } |
3352 | |
3353 | if (zstr(context)_zstr(context)) { |
3354 | dialplan = "XML"; |
3355 | } |
3356 | |
3357 | if ((holding_session = switch_core_session_locate(holding)switch_core_session_perform_locate(holding, "src/switch_ivr_originate.c" , (const char *)__func__, 3357))) { |
3358 | switch_channel_t *holding_channel = switch_core_session_get_channel(holding_session); |
3359 | switch_status_t mstatus = SWITCH_STATUS_FALSE; |
3360 | |
3361 | if (caller_channel) { |
3362 | if ((mstatus = switch_channel_caller_extension_masquerade(caller_channel, holding_channel, 0)) == SWITCH_STATUS_SUCCESS) { |
3363 | switch_channel_restart(holding_channel); |
3364 | } |
3365 | } |
3366 | |
3367 | if (mstatus != SWITCH_STATUS_SUCCESS) { |
3368 | if (peer_channel) { |
3369 | dest = switch_channel_get_variable(peer_channel, "destination_number")switch_channel_get_variable_dup(peer_channel, "destination_number" , SWITCH_TRUE, -1); |
3370 | context = switch_channel_get_variable(peer_channel, "context")switch_channel_get_variable_dup(peer_channel, "context", SWITCH_TRUE , -1); |
3371 | dialplan = switch_channel_get_variable(peer_channel, "dialplan")switch_channel_get_variable_dup(peer_channel, "dialplan", SWITCH_TRUE , -1); |
3372 | } else if (caller_channel) { |
3373 | dest = switch_channel_get_variable(caller_channel, "destination_number")switch_channel_get_variable_dup(caller_channel, "destination_number" , SWITCH_TRUE, -1); |
3374 | } |
3375 | if (dest) { |
3376 | switch_ivr_session_transfer(holding_session, dest, dialplan, context); |
3377 | } |
3378 | } |
3379 | |
3380 | switch_core_session_rwunlock(holding_session); |
3381 | holding = NULL((void*)0); |
3382 | holding_session = NULL((void*)0); |
3383 | } |
3384 | |
3385 | if (peer_channel) { |
3386 | switch_channel_hangup(peer_channel, SWITCH_CAUSE_ATTENDED_TRANSFER)switch_channel_perform_hangup(peer_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 3386, SWITCH_CAUSE_ATTENDED_TRANSFER ); |
3387 | switch_core_session_rwunlock(peer_session); |
3388 | } |
3389 | if (force_reason == SWITCH_CAUSE_NONE) { |
3390 | force_reason = SWITCH_CAUSE_ATTENDED_TRANSFER; |
3391 | } |
3392 | } else if (zstr(soft_holding)_zstr(soft_holding)) { |
3393 | |
3394 | if (peer_channel && switch_channel_ready(peer_channel)switch_channel_test_ready(peer_channel, SWITCH_TRUE, SWITCH_FALSE )) { |
3395 | switch_core_session_t *holding_session; |
3396 | |
3397 | if (force_reason == SWITCH_CAUSE_NONE) { |
3398 | force_reason = SWITCH_CAUSE_ATTENDED_TRANSFER; |
3399 | } |
3400 | |
3401 | if ((holding_session = switch_core_session_locate(holding)switch_core_session_perform_locate(holding, "src/switch_ivr_originate.c" , (const char *)__func__, 3401))) { |
3402 | switch_channel_set_variable(switch_core_session_get_channel(holding_session), SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "true")switch_channel_set_variable_var_check(switch_core_session_get_channel (holding_session), "hangup_after_bridge", "true", SWITCH_TRUE ); |
3403 | switch_core_session_rwunlock(holding_session); |
3404 | } |
3405 | switch_channel_set_flag(peer_channel, CF_LAZY_ATTENDED_TRANSFER)switch_channel_set_flag_value(peer_channel, CF_LAZY_ATTENDED_TRANSFER , 1); |
3406 | switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(peer_session)); |
3407 | holding = NULL((void*)0); |
3408 | oglobals.idx = IDX_XFER; |
3409 | if (caller_channel && switch_channel_up_nosig(caller_channel)(switch_channel_get_state(caller_channel) < CS_HANGUP) && !switch_channel_test_flag(caller_channel, CF_INTERCEPTED)) { |
3410 | switch_channel_hangup(caller_channel, SWITCH_CAUSE_ATTENDED_TRANSFER)switch_channel_perform_hangup(caller_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 3410, SWITCH_CAUSE_ATTENDED_TRANSFER ); |
3411 | } |
3412 | caller_channel = NULL((void*)0); |
3413 | oglobals.session = NULL((void*)0); |
3414 | session = NULL((void*)0); |
3415 | switch_core_session_rwunlock(peer_session); |
3416 | } else { |
3417 | switch_core_session_t *holding_session; |
3418 | |
3419 | if ((holding_session = switch_core_session_locate(holding)switch_core_session_perform_locate(holding, "src/switch_ivr_originate.c" , (const char *)__func__, 3419))) { |
3420 | switch_channel_t *holding_channel = switch_core_session_get_channel(holding_session); |
3421 | |
3422 | if (caller_channel && switch_channel_ready(caller_channel)switch_channel_test_ready(caller_channel, SWITCH_TRUE, SWITCH_FALSE )) { |
3423 | switch_channel_set_variable(holding_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "true")switch_channel_set_variable_var_check(holding_channel, "hangup_after_bridge" , "true", SWITCH_TRUE); |
3424 | switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(session)); |
3425 | holding = NULL((void*)0); |
3426 | } else { |
3427 | switch_channel_hangup(holding_channel, SWITCH_CAUSE_NORMAL_UNSPECIFIED)switch_channel_perform_hangup(holding_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 3427, SWITCH_CAUSE_NORMAL_UNSPECIFIED ); |
3428 | } |
3429 | switch_core_session_rwunlock(holding_session); |
3430 | } |
3431 | } |
3432 | } |
3433 | |
3434 | peer_session = NULL((void*)0); |
3435 | peer_channel = NULL((void*)0); |
3436 | } |
3437 | |
3438 | for (i = 0; i < and_argc; i++) { |
3439 | if (!peer_eligible(originate_status[i].peer_channel)(originate_status[i].peer_channel && !(switch_channel_test_flag (originate_status[i].peer_channel, CF_TRANSFER) || switch_channel_test_flag (originate_status[i].peer_channel, CF_REDIRECT) || switch_channel_test_flag (originate_status[i].peer_channel, CF_BRIDGED) || switch_channel_get_state (originate_status[i].peer_channel) == CS_RESET || !switch_channel_test_flag (originate_status[i].peer_channel, CF_ORIGINATING)))) { |
3440 | continue; |
3441 | } |
3442 | |
3443 | if (i != oglobals.idx) { |
3444 | holding = NULL((void*)0); |
3445 | |
3446 | if (oglobals.idx == IDX_TIMEOUT || to) { |
3447 | reason = SWITCH_CAUSE_NO_ANSWER; |
3448 | } else { |
3449 | if (oglobals.idx == IDX_CANCEL) { |
3450 | reason = SWITCH_CAUSE_ORIGINATOR_CANCEL; |
3451 | } else { |
3452 | if (and_argc > 1) { |
3453 | reason = SWITCH_CAUSE_LOSE_RACE; |
3454 | } else if (!switch_channel_ready(originate_status[i].peer_channel)switch_channel_test_ready(originate_status[i].peer_channel, SWITCH_TRUE , SWITCH_FALSE)) { |
3455 | wait_for_cause(originate_status[i].peer_channel); |
3456 | if (switch_channel_down_nosig(originate_status[i].peer_channel)(switch_channel_get_state(originate_status[i].peer_channel) >= CS_HANGUP)) { |
3457 | reason = switch_channel_get_cause(originate_status[i].peer_channel); |
3458 | } |
3459 | } else { |
3460 | reason = SWITCH_CAUSE_NO_ANSWER; |
3461 | } |
3462 | } |
3463 | } |
3464 | if (switch_channel_up_nosig(originate_status[i].peer_channel)(switch_channel_get_state(originate_status[i].peer_channel) < CS_HANGUP)) { |
3465 | if (caller_channel && i == 0) { |
3466 | holding = switch_channel_get_variable(caller_channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE)switch_channel_get_variable_dup(caller_channel, "soft_holding_uuid" , SWITCH_TRUE, -1); |
3467 | switch_channel_set_variable(caller_channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE, NULL)switch_channel_set_variable_var_check(caller_channel, "soft_holding_uuid" , ((void*)0), SWITCH_TRUE); |
3468 | } |
3469 | |
3470 | if (holding && oglobals.idx != IDX_TIMEOUT && oglobals.idx != IDX_KEY_CANCEL && oglobals.idx < 0) { |
3471 | switch_core_session_t *holding_session; |
3472 | |
3473 | if ((holding_session = switch_core_session_locate(holding)switch_core_session_perform_locate(holding, "src/switch_ivr_originate.c" , (const char *)__func__, 3473))) { |
3474 | switch_channel_t *holding_channel = switch_core_session_get_channel(holding_session); |
3475 | |
3476 | switch_channel_set_variable(holding_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "true")switch_channel_set_variable_var_check(holding_channel, "hangup_after_bridge" , "true", SWITCH_TRUE); |
3477 | |
3478 | if (caller_channel && switch_true(switch_channel_get_variable(caller_channel, "recording_follow_transfer")switch_channel_get_variable_dup(caller_channel, "recording_follow_transfer" , SWITCH_TRUE, -1))) { |
3479 | switch_core_media_bug_transfer_recordings(session, originate_status[i].peer_session); |
3480 | } |
3481 | |
3482 | if (switch_true(switch_channel_get_variable(holding_channel, "recording_follow_transfer")switch_channel_get_variable_dup(holding_channel, "recording_follow_transfer" , SWITCH_TRUE, -1))) { |
3483 | switch_core_media_bug_transfer_recordings(holding_session, originate_status[i].peer_session); |
3484 | } |
3485 | |
3486 | switch_core_session_rwunlock(holding_session); |
3487 | } |
3488 | switch_channel_set_flag(originate_status[i].peer_channel, CF_LAZY_ATTENDED_TRANSFER)switch_channel_set_flag_value(originate_status[i].peer_channel , CF_LAZY_ATTENDED_TRANSFER, 1); |
3489 | switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(originate_status[i].peer_session)); |
3490 | holding = NULL((void*)0); |
3491 | } else { |
3492 | if (force_reason == SWITCH_CAUSE_LOSE_RACE || reason == SWITCH_CAUSE_LOSE_RACE) { |
3493 | switch_channel_set_variable(originate_status[i].peer_channel, "group_dial_status", "loser")switch_channel_set_variable_var_check(originate_status[i].peer_channel , "group_dial_status", "loser", SWITCH_TRUE); |
3494 | } |
3495 | switch_channel_hangup(originate_status[i].peer_channel, force_reason ? force_reason : reason)switch_channel_perform_hangup(originate_status[i].peer_channel , "src/switch_ivr_originate.c", (const char *)__func__, 3495, force_reason ? force_reason : reason); |
3496 | } |
3497 | } |
3498 | } |
3499 | } |
3500 | |
3501 | |
3502 | |
3503 | if (oglobals.idx > IDX_NADA) { |
3504 | if ((peer_session = originate_status[oglobals.idx].peer_session)) { |
3505 | peer_channel = switch_core_session_get_channel(originate_status[oglobals.idx].peer_session); |
3506 | } |
3507 | } else { |
3508 | status = SWITCH_STATUS_FALSE; |
3509 | if (caller_channel && peer_channel) { |
3510 | switch_process_import(oglobals.session, peer_channel, "import", NULL((void*)0)); |
3511 | } |
3512 | peer_channel = NULL((void*)0); |
3513 | goto done; |
3514 | } |
3515 | |
3516 | if (caller_channel) { |
3517 | if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) { |
3518 | switch_channel_pass_callee_id(peer_channel, caller_channel); |
3519 | if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE)) { |
3520 | status = SWITCH_STATUS_SUCCESS; |
3521 | } else { |
3522 | status = switch_channel_answer(caller_channel)switch_channel_perform_answer(caller_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 3522); |
3523 | } |
3524 | } else if (switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) { |
3525 | if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE)) { |
3526 | status = SWITCH_STATUS_SUCCESS; |
3527 | } else { |
3528 | switch_channel_pass_callee_id(peer_channel, caller_channel); |
3529 | status = switch_channel_pre_answer(caller_channel)switch_channel_perform_pre_answer(caller_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 3529); |
3530 | } |
3531 | } else { |
3532 | status = SWITCH_STATUS_SUCCESS; |
3533 | } |
3534 | |
3535 | if (status != SWITCH_STATUS_SUCCESS) { |
3536 | switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(peer_channel)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 3536, (const char*)switch_channel_get_session (peer_channel), SWITCH_LOG_DEBUG, "%s Media Establishment Failed.\n", |
3537 | switch_channel_get_name(caller_channel)); |
3538 | switch_channel_hangup(peer_channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION)switch_channel_perform_hangup(peer_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 3538, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION ); |
3539 | } |
3540 | } |
3541 | |
3542 | if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || |
3543 | (oglobals.early_ok && switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) || |
3544 | (oglobals.return_ring_ready && switch_channel_test_flag(peer_channel, CF_RING_READY)) |
3545 | ) { |
3546 | *bleg = peer_session; |
3547 | |
3548 | if (oglobals.monitor_early_media_ring || oglobals.monitor_early_media_fail) { |
3549 | switch_ivr_stop_tone_detect_session(peer_session); |
3550 | switch_channel_set_private(peer_channel, "_oglobals_", NULL((void*)0)); |
3551 | } |
3552 | |
3553 | status = SWITCH_STATUS_SUCCESS; |
3554 | } else { |
3555 | status = SWITCH_STATUS_FALSE; |
3556 | } |
3557 | |
3558 | done: |
3559 | |
3560 | *cause = SWITCH_CAUSE_NONE; |
3561 | |
3562 | if (caller_channel && !switch_channel_ready(caller_channel)switch_channel_test_ready(caller_channel, SWITCH_TRUE, SWITCH_FALSE )) { |
3563 | status = SWITCH_STATUS_FALSE; |
3564 | } |
3565 | |
3566 | if (status == SWITCH_STATUS_SUCCESS) { |
3567 | if (caller_channel) { |
3568 | switch_channel_set_variable(caller_channel, "originate_disposition", "call accepted")switch_channel_set_variable_var_check(caller_channel, "originate_disposition" , "call accepted", SWITCH_TRUE); |
3569 | if (peer_channel) { |
3570 | switch_process_import(oglobals.session, peer_channel, "import", NULL((void*)0)); |
3571 | |
3572 | if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) { |
3573 | switch_channel_set_variable(caller_channel, "DIALSTATUS", "EARLY")switch_channel_set_variable_var_check(caller_channel, "DIALSTATUS" , "EARLY", SWITCH_TRUE); |
3574 | } else { |
3575 | switch_channel_set_variable(caller_channel, "DIALSTATUS", "ANSWER")switch_channel_set_variable_var_check(caller_channel, "DIALSTATUS" , "ANSWER", SWITCH_TRUE); |
3576 | } |
3577 | |
3578 | } |
3579 | } |
3580 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals.session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 3580, (const char*)(oglobals.session), SWITCH_LOG_DEBUG, "Originate Resulted in Success: [%s]\n", |
3581 | switch_channel_get_name(peer_channel)); |
3582 | *cause = SWITCH_CAUSE_SUCCESS; |
3583 | |
3584 | } else { |
3585 | const char *cdr_var = NULL((void*)0); |
3586 | const char *json_cdr_var = NULL((void*)0); |
3587 | |
3588 | switch_xml_t cdr = NULL((void*)0); |
3589 | cJSON *json_cdr = NULL((void*)0); |
3590 | |
3591 | char *json_text; |
3592 | char *xml_text; |
3593 | char buf[128] = "", buf2[128] = ""; |
3594 | |
3595 | if (caller_channel) { |
3596 | cdr_var = switch_channel_get_variable(caller_channel, "failed_xml_cdr_prefix")switch_channel_get_variable_dup(caller_channel, "failed_xml_cdr_prefix" , SWITCH_TRUE, -1); |
3597 | } |
3598 | |
3599 | if (caller_channel) { |
3600 | json_cdr_var = switch_channel_get_variable(caller_channel, "failed_json_cdr_prefix")switch_channel_get_variable_dup(caller_channel, "failed_json_cdr_prefix" , SWITCH_TRUE, -1); |
3601 | } |
3602 | |
3603 | if (peer_channel) { |
3604 | wait_for_cause(peer_channel); |
3605 | *cause = switch_channel_get_cause(peer_channel); |
3606 | } else { |
3607 | for (i = 0; i < and_argc; i++) { |
3608 | if (!originate_status[i].peer_channel) { |
3609 | continue; |
3610 | } |
3611 | *cause = switch_channel_get_cause(originate_status[i].peer_channel); |
3612 | break; |
3613 | } |
3614 | } |
3615 | |
3616 | if (cdr_var) { |
3617 | for (i = 0; i < and_argc; i++) { |
3618 | switch_channel_t *channel; |
3619 | |
3620 | if (!originate_status[i].peer_session) { |
3621 | continue; |
3622 | } |
3623 | |
3624 | channel = switch_core_session_get_channel(originate_status[i].peer_session); |
3625 | |
3626 | switch_channel_wait_for_state_timeout(channel, CS_REPORTING, 5000); |
3627 | |
3628 | if (!switch_channel_test_flag(channel, CF_TIMESTAMP_SET)) { |
3629 | switch_channel_set_timestamps(channel); |
3630 | } |
3631 | |
3632 | if (switch_ivr_generate_xml_cdr(originate_status[i].peer_session, &cdr) == SWITCH_STATUS_SUCCESS) { |
3633 | if ((xml_text = switch_xml_toxml(cdr, SWITCH_FALSE))) { |
3634 | switch_snprintf(buf, sizeof(buf), "%s_%d", cdr_var, ++cdr_total); |
3635 | switch_channel_set_variable(caller_channel, buf, xml_text)switch_channel_set_variable_var_check(caller_channel, buf, xml_text , SWITCH_TRUE); |
3636 | switch_safe_free(xml_text)if (xml_text) {free(xml_text);xml_text=((void*)0);}; |
3637 | } |
3638 | switch_xml_free(cdr); |
3639 | cdr = NULL((void*)0); |
3640 | } |
3641 | |
3642 | } |
3643 | switch_snprintf(buf, sizeof(buf), "%s_total", cdr_var); |
3644 | switch_snprintf(buf2, sizeof(buf2), "%d", cdr_total ? cdr_total : 0); |
3645 | switch_channel_set_variable(caller_channel, buf, buf2)switch_channel_set_variable_var_check(caller_channel, buf, buf2 , SWITCH_TRUE); |
3646 | } |
3647 | |
3648 | if (json_cdr_var) { |
3649 | for (i = 0; i < and_argc; i++) { |
3650 | switch_channel_t *channel; |
3651 | |
3652 | if (!originate_status[i].peer_session) { |
3653 | continue; |
3654 | } |
3655 | |
3656 | channel = switch_core_session_get_channel(originate_status[i].peer_session); |
3657 | |
3658 | switch_channel_wait_for_state_timeout(channel, CS_REPORTING, 5000); |
3659 | |
3660 | if (!switch_channel_test_flag(channel, CF_TIMESTAMP_SET)) { |
3661 | switch_channel_set_timestamps(channel); |
3662 | } |
3663 | |
3664 | if (switch_ivr_generate_json_cdr(originate_status[i].peer_session, &json_cdr, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) { |
3665 | json_text = cJSON_PrintUnformatted(json_cdr); |
3666 | switch_snprintf(buf, sizeof(buf), "%s_%d", json_cdr_var, ++cdr_total); |
3667 | switch_channel_set_variable(caller_channel, buf, json_text)switch_channel_set_variable_var_check(caller_channel, buf, json_text , SWITCH_TRUE); |
3668 | // switch_safe_free(json_text); |
3669 | cJSON_Delete(json_cdr); |
3670 | json_cdr = NULL((void*)0); |
3671 | } |
3672 | |
3673 | } |
3674 | switch_snprintf(buf, sizeof(buf), "%s_total", json_cdr_var); |
3675 | switch_snprintf(buf2, sizeof(buf2), "%d", cdr_total ? cdr_total : 0); |
3676 | switch_channel_set_variable(caller_channel, buf, buf2)switch_channel_set_variable_var_check(caller_channel, buf, buf2 , SWITCH_TRUE); |
3677 | } |
3678 | |
3679 | if (caller_channel && switch_channel_test_flag(caller_channel, CF_INTERCEPTED)) { |
3680 | *cause = SWITCH_CAUSE_PICKED_OFF; |
3681 | } |
3682 | |
3683 | if (!*cause) { |
3684 | if (reason) { |
3685 | *cause = reason; |
3686 | } else if (caller_channel) { |
3687 | *cause = switch_channel_get_cause(caller_channel); |
3688 | } else { |
3689 | *cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; |
3690 | for (i = 0; i < and_argc; i++) { |
3691 | if (!peer_eligible(originate_status[i].peer_channel)(originate_status[i].peer_channel && !(switch_channel_test_flag (originate_status[i].peer_channel, CF_TRANSFER) || switch_channel_test_flag (originate_status[i].peer_channel, CF_REDIRECT) || switch_channel_test_flag (originate_status[i].peer_channel, CF_BRIDGED) || switch_channel_get_state (originate_status[i].peer_channel) == CS_RESET || !switch_channel_test_flag (originate_status[i].peer_channel, CF_ORIGINATING)))) { |
3692 | continue; |
3693 | } |
3694 | |
3695 | wait_for_cause(originate_status[i].peer_channel); |
3696 | |
3697 | if (switch_channel_down_nosig(originate_status[i].peer_channel)(switch_channel_get_state(originate_status[i].peer_channel) >= CS_HANGUP)) { |
3698 | *cause = switch_channel_get_cause(originate_status[i].peer_channel); |
3699 | break; |
3700 | } |
3701 | |
3702 | } |
3703 | } |
3704 | } |
3705 | |
3706 | if (*cause == SWITCH_CAUSE_SUCCESS || *cause == SWITCH_CAUSE_NONE) { |
3707 | *cause = SWITCH_CAUSE_ORIGINATOR_CANCEL; |
3708 | } |
3709 | |
3710 | if (oglobals.idx == IDX_CANCEL) { |
3711 | *cause = SWITCH_CAUSE_ORIGINATOR_CANCEL; |
3712 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals.session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 3712, (const char*)(oglobals.session), SWITCH_LOG_DEBUG, |
3713 | "Originate Cancelled by originator termination Cause: %d [%s]\n", *cause, switch_channel_cause2str(*cause)); |
3714 | |
3715 | } else if (oglobals.idx == IDX_TIMEOUT) { |
3716 | *cause = SWITCH_CAUSE_NO_ANSWER; |
3717 | } else { |
3718 | if (oglobals.idx == IDX_XFER) { |
3719 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals.session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 3719, (const char*)(oglobals.session), SWITCH_LOG_DEBUG, |
3720 | "Originate Resulted in Attended Transfer Cause: %d [%s]\n", *cause, switch_channel_cause2str(*cause)); |
3721 | } else { |
3722 | |
3723 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals.session)SWITCH_CHANNEL_ID_SESSION, "src/switch_ivr_originate.c", (const char *)__func__, 3723, (const char*)(oglobals.session), SWITCH_LOG_DEBUG, |
3724 | "Originate Resulted in Error Cause: %d [%s]\n", *cause, switch_channel_cause2str(*cause)); |
3725 | } |
3726 | } |
3727 | } |
3728 | |
3729 | if (caller_channel) { |
3730 | switch_channel_set_variable(caller_channel, "originate_disposition", switch_channel_cause2str(*cause))switch_channel_set_variable_var_check(caller_channel, "originate_disposition" , switch_channel_cause2str(*cause), SWITCH_TRUE); |
3731 | |
3732 | switch (*cause) { |
3733 | case SWITCH_CAUSE_ORIGINATOR_CANCEL: |
3734 | switch_channel_set_variable(caller_channel, "DIALSTATUS", "CANCEL")switch_channel_set_variable_var_check(caller_channel, "DIALSTATUS" , "CANCEL", SWITCH_TRUE); |
3735 | break; |
3736 | case SWITCH_CAUSE_USER_BUSY: |
3737 | switch_channel_set_variable(caller_channel, "DIALSTATUS", "BUSY")switch_channel_set_variable_var_check(caller_channel, "DIALSTATUS" , "BUSY", SWITCH_TRUE); |
3738 | break; |
3739 | case SWITCH_CAUSE_NO_ANSWER: |
3740 | switch_channel_set_variable(caller_channel, "DIALSTATUS", "NOANSWER")switch_channel_set_variable_var_check(caller_channel, "DIALSTATUS" , "NOANSWER", SWITCH_TRUE); |
3741 | break; |
3742 | case SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER: |
3743 | case SWITCH_CAUSE_INVALID_PROFILE: |
3744 | switch_channel_set_variable(caller_channel, "DIALSTATUS", "INVALIDARGS")switch_channel_set_variable_var_check(caller_channel, "DIALSTATUS" , "INVALIDARGS", SWITCH_TRUE); |
3745 | break; |
3746 | case SWITCH_CAUSE_CALL_REJECTED: |
3747 | switch_channel_set_variable(caller_channel, "DIALSTATUS", "DONTCALL")switch_channel_set_variable_var_check(caller_channel, "DIALSTATUS" , "DONTCALL", SWITCH_TRUE); |
3748 | break; |
3749 | default: |
3750 | switch_channel_set_variable(caller_channel, "DIALSTATUS", switch_channel_cause2str(*cause))switch_channel_set_variable_var_check(caller_channel, "DIALSTATUS" , switch_channel_cause2str(*cause), SWITCH_TRUE); |
3751 | break; |
3752 | } |
3753 | } |
3754 | |
3755 | early_state.ready = 0; |
3756 | |
3757 | if (oglobals.ethread) { |
3758 | switch_status_t st; |
3759 | switch_thread_join(&st, oglobals.ethread); |
3760 | } |
3761 | |
3762 | if (early_state.buffer) { |
3763 | switch_buffer_destroy(&early_state.buffer); |
3764 | } |
3765 | |
3766 | if (ringback.fh) { |
3767 | switch_core_file_close(ringback.fh); |
3768 | ringback.fh = NULL((void*)0); |
3769 | } else if (ringback.audio_buffer) { |
3770 | teletone_destroy_session(&ringback.ts); |
3771 | switch_buffer_destroy(&ringback.audio_buffer); |
3772 | } |
3773 | |
3774 | if (oglobals.session) { |
3775 | switch_core_session_reset(oglobals.session, SWITCH_FALSE, SWITCH_TRUE); |
3776 | } |
3777 | |
3778 | if (switch_core_codec_ready(&write_codec)) { |
3779 | switch_core_codec_destroy(&write_codec); |
3780 | } |
3781 | |
3782 | for (i = 0; i < and_argc; i++) { |
3783 | switch_channel_state_t state; |
3784 | switch_core_session_t *peer_session; |
3785 | char *val; |
3786 | |
3787 | if (!originate_status[i].peer_channel) { |
3788 | continue; |
3789 | } |
3790 | |
3791 | if (session) { |
3792 | val = switch_core_session_sprintf(originate_status[i].peer_session, "%s;%s", |
3793 | switch_core_session_get_uuid(originate_status[i].peer_session), |
3794 | switch_channel_cause2str(switch_channel_get_cause(originate_status[i].peer_channel))); |
3795 | |
3796 | switch_channel_add_variable_var_check(switch_core_session_get_channel(session), "originate_causes", val, SWITCH_FALSE, SWITCH_STACK_PUSH); |
3797 | } |
3798 | |
3799 | if (status == SWITCH_STATUS_SUCCESS) { |
3800 | switch_channel_clear_flag(originate_status[i].peer_channel, CF_ORIGINATING); |
3801 | if (bleg && *bleg && *bleg == originate_status[i].peer_session) { |
3802 | continue; |
3803 | } |
3804 | } else if ((state = switch_channel_get_state(originate_status[i].peer_channel)) < CS_HANGUP && |
3805 | switch_channel_test_flag(originate_status[i].peer_channel, CF_ORIGINATING)) { |
3806 | if (!(state == CS_RESET || switch_channel_test_flag(originate_status[i].peer_channel, CF_TRANSFER) || |
3807 | switch_channel_test_flag(originate_status[i].peer_channel, CF_REDIRECT) || |
3808 | switch_channel_test_flag(originate_status[i].peer_channel, CF_BRIDGED))) { |
3809 | if (caller_channel && switch_channel_test_flag(caller_channel, CF_INTERCEPTED)) { |
3810 | switch_channel_set_flag(originate_status[i].peer_channel, CF_INTERCEPT)switch_channel_set_flag_value(originate_status[i].peer_channel , CF_INTERCEPT, 1); |
3811 | } |
3812 | switch_channel_hangup(originate_status[i].peer_channel, *cause)switch_channel_perform_hangup(originate_status[i].peer_channel , "src/switch_ivr_originate.c", (const char *)__func__, 3812, *cause); |
3813 | } |
3814 | } |
3815 | switch_channel_clear_flag(originate_status[i].peer_channel, CF_ORIGINATING); |
3816 | |
3817 | peer_session = originate_status[i].peer_session; |
3818 | originate_status[i].peer_session = NULL((void*)0); |
3819 | originate_status[i].peer_channel = NULL((void*)0); |
3820 | switch_core_session_rwunlock(peer_session); |
3821 | } |
3822 | |
3823 | if (status == SWITCH_STATUS_SUCCESS || oglobals.idx == IDX_XFER) { |
3824 | goto outer_for; |
3825 | } else { |
3826 | int ok = 1; |
3827 | |
3828 | if (fail_on_single_reject && check_reject && !switch_true(fail_on_single_reject_var)) { |
3829 | for (i = 0; i < and_argc; i++) { |
3830 | switch_channel_t *pchannel; |
3831 | const char *cause_str; |
3832 | |
3833 | if (!originate_status[i].peer_session) { |
3834 | continue; |
3835 | } |
3836 | |
3837 | pchannel = switch_core_session_get_channel(originate_status[i].peer_session); |
3838 | wait_for_cause(pchannel); |
3839 | |
3840 | if (switch_channel_down_nosig(pchannel)(switch_channel_get_state(pchannel) >= CS_HANGUP)) { |
3841 | int neg, pos; |
3842 | |
3843 | cause_str = switch_channel_cause2str(switch_channel_get_cause(pchannel)); |
3844 | |
3845 | neg = *fail_on_single_reject_var == '!'; |
3846 | pos = !!switch_stristr(cause_str, fail_on_single_reject_var); |
3847 | |
3848 | if (neg) { |
3849 | pos = !pos; |
3850 | } |
3851 | |
3852 | |
3853 | if (pos) { |
3854 | ok = 0; |
3855 | break; |
3856 | } |
3857 | } |
3858 | } |
3859 | } |
3860 | |
3861 | if (!ok) { |
3862 | goto outer_for; |
3863 | } |
3864 | |
3865 | if (to && !oglobals.continue_on_timeout) { |
3866 | goto outer_for; |
3867 | } |
3868 | } |
3869 | } |
3870 | } |
3871 | outer_for: |
3872 | switch_safe_free(loop_data)if (loop_data) {free(loop_data);loop_data=((void*)0);}; |
3873 | switch_safe_free(odata)if (odata) {free(odata);odata=((void*)0);}; |
3874 | switch_safe_free(oglobals.file)if (oglobals.file) {free(oglobals.file);oglobals.file=((void* )0);}; |
3875 | switch_safe_free(oglobals.error_file)if (oglobals.error_file) {free(oglobals.error_file);oglobals. error_file=((void*)0);}; |
3876 | |
3877 | if (bleg && status != SWITCH_STATUS_SUCCESS) { |
3878 | *bleg = NULL((void*)0); |
3879 | } |
3880 | |
3881 | if (bleg && !*bleg && status == SWITCH_STATUS_SUCCESS) { |
3882 | status = SWITCH_STATUS_FALSE; |
3883 | } |
3884 | |
3885 | if (bleg && *bleg) { |
3886 | switch_channel_t *bchan = switch_core_session_get_channel(*bleg); |
3887 | |
3888 | if (session && caller_channel) { |
3889 | switch_caller_profile_t *cloned_profile, *peer_profile = switch_channel_get_caller_profile(switch_core_session_get_channel(*bleg)); |
3890 | |
3891 | if (peer_profile) { |
3892 | if ((cloned_profile = switch_caller_profile_clone(session, peer_profile)) != 0) { |
3893 | switch_channel_set_originatee_caller_profile(caller_channel, cloned_profile); |
3894 | } |
3895 | } |
3896 | |
3897 | switch_channel_set_variable(caller_channel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(*bleg))switch_channel_set_variable_var_check(caller_channel, "signal_bond" , switch_core_session_get_uuid(*bleg), SWITCH_TRUE); |
3898 | // Now main SWITCH_SIGNAL_BOND_VARIABLE is populated, don't need this one anymore... |
3899 | switch_channel_set_variable(caller_channel, SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE, NULL)switch_channel_set_variable_var_check(caller_channel, "originate_signal_bond" , ((void*)0), SWITCH_TRUE); |
3900 | } |
3901 | |
3902 | |
3903 | switch_channel_execute_on(bchan, SWITCH_CHANNEL_EXECUTE_ON_POST_ORIGINATE_VARIABLE"execute_on_post_originate"); |
3904 | switch_channel_api_on(bchan, SWITCH_CHANNEL_API_ON_POST_ORIGINATE_VARIABLE"api_on_post_originate"); |
3905 | |
3906 | |
3907 | while(switch_channel_state_change_pending(bchan)) { |
3908 | switch_cond_next(); |
3909 | } |
3910 | |
3911 | switch_channel_audio_sync(bchan)switch_channel_perform_audio_sync(bchan, "src/switch_ivr_originate.c" , (const char *)__func__, 3911); |
3912 | |
3913 | if (caller_channel) { |
3914 | switch_channel_audio_sync(caller_channel)switch_channel_perform_audio_sync(caller_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 3914); |
3915 | } |
3916 | } |
3917 | |
3918 | if (oglobals.session) { |
3919 | switch_ivr_parse_all_events(oglobals.session); |
3920 | } |
3921 | |
3922 | if (oglobals.session && status == SWITCH_STATUS_SUCCESS) { |
3923 | switch_ivr_sleep(oglobals.session, 0, SWITCH_TRUE, NULL((void*)0)); |
3924 | } |
3925 | |
3926 | if (var_event && var_event != ovars) { |
3927 | switch_event_destroy(&var_event); |
3928 | } |
3929 | |
3930 | switch_safe_free(write_frame.data)if (write_frame.data) {free(write_frame.data);write_frame.data =((void*)0);}; |
3931 | switch_safe_free(fail_on_single_reject_var)if (fail_on_single_reject_var) {free(fail_on_single_reject_var );fail_on_single_reject_var=((void*)0);}; |
3932 | |
3933 | if (force_reason != SWITCH_CAUSE_NONE) { |
3934 | *cause = force_reason; |
3935 | } |
3936 | |
3937 | if (caller_channel) { |
3938 | |
3939 | switch_channel_execute_on(caller_channel, SWITCH_CHANNEL_EXECUTE_ON_POST_ORIGINATE_VARIABLE"execute_on_post_originate"); |
3940 | switch_channel_api_on(caller_channel, SWITCH_CHANNEL_API_ON_POST_ORIGINATE_VARIABLE"api_on_post_originate"); |
3941 | |
3942 | switch_channel_clear_flag(caller_channel, CF_ORIGINATOR); |
3943 | switch_channel_clear_flag(caller_channel, CF_XFER_ZOMBIE); |
3944 | |
3945 | if (hangup_on_single_reject) { |
3946 | switch_channel_hangup(caller_channel, *cause)switch_channel_perform_hangup(caller_channel, "src/switch_ivr_originate.c" , (const char *)__func__, 3946, *cause); |
3947 | } |
3948 | } |
3949 | |
3950 | |
3951 | switch_core_destroy_memory_pool(&oglobals.pool)switch_core_perform_destroy_memory_pool(&oglobals.pool, "src/switch_ivr_originate.c" , (const char *)__func__, 3951); |
3952 | |
3953 | return status; |
3954 | } |
3955 | |
3956 | /* For Emacs: |
3957 | * Local Variables: |
3958 | * mode:c |
3959 | * indent-tabs-mode:t |
3960 | * tab-width:4 |
3961 | * c-basic-offset:4 |
3962 | * End: |
3963 | * For VIM: |
3964 | * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: |
3965 | */ |