From 45edec4ce360dacd4ceaf3e3d127141f05988cbc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 29 Mar 2011 12:52:06 -0500 Subject: [PATCH] FS-3193 note I changed the variable name to auto_cause --- .../applications/mod_dptools/mod_dptools.c | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 346cdaa9f8..1500ff1b5e 100755 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -2473,6 +2473,11 @@ SWITCH_STANDARD_APP(audio_bridge_function) { switch_channel_t *caller_channel = switch_core_session_get_channel(session); switch_core_session_t *peer_session = NULL; + + const char *transfer_on_fail = NULL; + char *tof_data = NULL; + char *tof_array[4] = { 0 }; + int tof_arrayc = 0; const char *continue_on_fail = NULL, *failure_causes = NULL, *v_campon = NULL, *v_campon_retries, *v_campon_sleep, *v_campon_timeout, *v_campon_fallback_exten = NULL; switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; @@ -2489,8 +2494,14 @@ SWITCH_STANDARD_APP(audio_bridge_function) } continue_on_fail = switch_channel_get_variable(caller_channel, "continue_on_fail"); - failure_causes = switch_channel_get_variable(caller_channel, "failure_causes"); + transfer_on_fail = switch_channel_get_variable(caller_channel, "transfer_on_fail"); + tof_data = switch_core_session_strdup(session, transfer_on_fail); + tof_arrayc = switch_split(tof_data, ' ', tof_array); + transfer_on_fail = tof_array[0]; + + failure_causes = switch_channel_get_variable(caller_channel, "failure_causes"); + if ((v_campon = switch_channel_get_variable(caller_channel, "campon")) && switch_true(v_campon)) { const char *cid_name = NULL; const char *cid_number = NULL; @@ -2681,6 +2692,57 @@ SWITCH_STANDARD_APP(audio_bridge_function) return; } } + + if (transfer_on_fail || failure_causes) { + const char *cause_str; + char cause_num[35] = ""; + + cause_str = switch_channel_cause2str(cause); + switch_snprintf(cause_num, sizeof(cause_num), "%u", cause); + + if ((tof_array[1] == NULL ) || (!strcasecmp(tof_array[1], "auto_cause"))){ + tof_array[1] = (char *) cause_str; + } + + if (failure_causes) { + char *lbuf = switch_core_session_strdup(session, failure_causes); + char *argv[256] = { 0 }; + int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0]))); + int i, x = 0; + + for (i = 0; i < argc; i++) { + if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) { + x++; + break; + } + } + if (!x) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, + "Failure causes [%s]: Cause: %s\n", failure_causes, cause_str); + + switch_ivr_session_transfer(session, tof_array[1], tof_array[2], tof_array[3]); + } + } + + if (transfer_on_fail) { + if (switch_true(transfer_on_fail)) { + return; + } else { + char *lbuf = switch_core_session_strdup(session, transfer_on_fail); + char *argv[256] = { 0 }; + int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0]))); + int i; + + for (i = 0; i < argc; i++) { + if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, + "Transfer on fail [%s]: Cause: %s\n", transfer_on_fail, cause_str); + switch_ivr_session_transfer(session, tof_array[1], tof_array[2], tof_array[3]); + } + } + } + } + } } if (!switch_channel_test_flag(caller_channel, CF_TRANSFER) && switch_channel_get_state(caller_channel) != CS_ROUTING) { switch_channel_hangup(caller_channel, cause);