add deflect parsing support for mod_loopback and fix unloop bug

This commit is contained in:
Anthony Minessale 2013-06-17 10:44:43 -05:00
parent 80669e8466
commit 50e1f58d5b
1 changed files with 32 additions and 8 deletions

View File

@ -429,20 +429,20 @@ static switch_status_t channel_on_execute(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel));
if (switch_test_flag(tech_pvt, TFLAG_BOWOUT) || switch_test_flag(tech_pvt, TFLAG_BLEG)) {
bow = 0;
} else if ((bowout = switch_channel_get_variable(tech_pvt->channel, "loopback_bowout_on_execute")) && switch_true(bowout)) {
if ((bowout = switch_channel_get_variable(tech_pvt->channel, "loopback_bowout_on_execute")) && switch_true(bowout)) {
/* loopback_bowout_on_execute variable is set */
bow = 1;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "WILL BOW\n");
} else if ((exten = switch_channel_get_caller_extension(channel))) {
/* check for bowout flag */
switch_caller_application_t *app_p;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "CHEKCING APPS\n");
for (app_p = exten->applications; app_p; app_p = app_p->next) {
int32_t flags;
switch_core_session_get_app_flags(app_p->application_name, &flags);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "CHECK %s %d\n", app_p->application_name, (flags & SAF_NO_LOOPBACK));
if ((flags & SAF_NO_LOOPBACK)) {
bow = 1;
@ -455,14 +455,16 @@ static switch_status_t channel_on_execute(switch_core_session_t *session)
switch_core_session_t *other_session = NULL;
switch_caller_profile_t *cp, *clone;
const char *other_uuid = NULL;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "BOWING\n");
switch_set_flag(tech_pvt, TFLAG_BOWOUT);
if ((find_non_loopback_bridge(tech_pvt->other_session, &other_session, &other_uuid) == SWITCH_STATUS_SUCCESS)) {
switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
/* Wait for real channel to be exchanging media */
switch_channel_wait_for_state(other_channel, channel, CS_EXCHANGE_MEDIA);
if (switch_channel_test_flag(other_channel, CF_BRIDGED)) {
/* Wait for real channel to be exchanging media */
switch_channel_wait_for_state(other_channel, channel, CS_EXCHANGE_MEDIA);
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_INFO, "BOWOUT Replacing loopback channel with real channel: %s\n",
switch_channel_get_name(other_channel));
@ -929,6 +931,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
switch_channel_t *channel;
loopback_private_t *tech_pvt;
int done = 1, pass = 0;
switch_core_session_t *other_session;
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
@ -1011,16 +1014,37 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
pass = 1;
}
break;
case SWITCH_MESSAGE_INDICATE_DEFLECT:
{
pass = 0;
if (!zstr(msg->string_arg) && switch_core_session_get_partner(tech_pvt->other_session, &other_session) == SWITCH_STATUS_SUCCESS) {
char *ext = switch_core_session_strdup(other_session, msg->string_arg);
char *context = NULL, *dp = NULL;
if ((context = strchr(ext, ' '))) {
*context++ = '\0';
if ((dp = strchr(context, ' '))) {
*dp++ = '\0';
}
}
switch_ivr_session_transfer(other_session, ext, context, dp);
switch_core_session_rwunlock(other_session);
}
}
break;
default:
break;
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "done:%d pass:%d running:%d\n", done, pass, switch_test_flag(tech_pvt, TFLAG_RUNNING_APP));
if (!done && tech_pvt->other_session && (pass || switch_test_flag(tech_pvt, TFLAG_RUNNING_APP))) {
switch_status_t r = SWITCH_STATUS_FALSE;
switch_core_session_t *other_session;
if (switch_core_session_get_partner(tech_pvt->other_session, &other_session) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "PASS TO %s\n", switch_core_session_get_name(other_session));
r = switch_core_session_receive_message(other_session, msg);
switch_core_session_rwunlock(other_session);
}