diff --git a/src/mod/endpoints/mod_loopback/mod_loopback.c b/src/mod/endpoints/mod_loopback/mod_loopback.c index ded1a7a77f..a61052d62a 100644 --- a/src/mod/endpoints/mod_loopback/mod_loopback.c +++ b/src/mod/endpoints/mod_loopback/mod_loopback.c @@ -314,6 +314,7 @@ static switch_status_t channel_on_routing(switch_core_session_t *session) { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; + const char *app, *arg; channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -324,6 +325,21 @@ static switch_status_t channel_on_routing(switch_core_session_t *session) do_reset(tech_pvt); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL ROUTING\n", switch_channel_get_name(channel)); + + + if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND) && (app = switch_channel_get_variable(channel, "loopback_app"))) { + switch_caller_extension_t *extension = NULL; + arg = switch_channel_get_variable(channel, "loopback_app_arg"); + extension = switch_caller_extension_new(session, app, app); + switch_caller_extension_add_application(session, extension, "pre_answer", NULL); + switch_caller_extension_add_application(session, extension, app, arg); + + switch_channel_set_caller_extension(channel, extension); + switch_channel_set_state(channel, CS_EXECUTE); + return SWITCH_STATUS_FALSE; + } + + return SWITCH_STATUS_SUCCESS; } @@ -555,6 +571,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch if (tech_pvt->write_frame) { switch_frame_free(&tech_pvt->write_frame); } + tech_pvt->write_frame = (switch_frame_t *) pop; tech_pvt->write_frame->codec = &tech_pvt->read_codec; *frame = tech_pvt->write_frame; @@ -571,6 +588,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch *frame = &tech_pvt->cng_frame; tech_pvt->cng_frame.codec = &tech_pvt->read_codec; tech_pvt->cng_frame.datalen = tech_pvt->read_codec.implementation->decoded_bytes_per_packet; + memset(tech_pvt->cng_frame.data, 0, tech_pvt->cng_frame.datalen); memset(&data, 0, sizeof(data)); @@ -797,6 +815,23 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); caller_profile->source = switch_core_strdup(caller_profile->pool, modname); + if (!strncasecmp(caller_profile->destination_number, "app=", 4)) { + char *dest = switch_core_session_strdup(*new_session, caller_profile->destination_number); + char *app = dest + 4; + char *arg = NULL; + + if ((arg = strchr(app, ':'))) { + *arg++ = '\0'; + } + + switch_channel_set_variable(channel, "loopback_app", app); + if (arg) { + switch_channel_set_variable(channel, "loopback_app_arg", arg); + } + + caller_profile->destination_number = switch_core_strdup(caller_profile->pool, app); + } + if ((context = strchr(caller_profile->destination_number, '/'))) { *context++ = '\0'; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 8c2e80e60f..7f6f3707e6 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -4271,7 +4271,11 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t switch_channel_set_variable(channel_b, SWITCH_HOLDING_UUID_VARIABLE, br_a); switch_channel_set_flag(channel_b, CF_XFER_ZOMBIE); + switch_channel_set_flag(channel_b, CF_TRANSFER); + //switch_channel_set_variable(channel_b, "park_timeout", "2"); + //switch_channel_set_state(channel_b, CS_PARK); + if ((a_session = switch_core_session_locate(br_a))) { const char *moh = profile->hold_music; switch_channel_t *a_channel = switch_core_session_get_channel(a_session); @@ -4284,21 +4288,40 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t if (!strcasecmp(moh, "silence")) { moh = NULL; } - + //switch_channel_set_variable(a_channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE, "true"); + if (moh) { - switch_channel_set_variable_printf(a_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE, - "'endless_playback:%s',park:inline", moh); + char *xdest; + //switch_channel_set_variable_printf(a_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE, + // "'endless_playback:%s,park':inline", moh); + xdest = switch_core_session_sprintf(a_session, "endless_playback:%s,park", moh); + switch_ivr_session_transfer(a_session, xdest, "inline", NULL); } else { - switch_channel_set_variable(a_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE, "park:inline"); + //switch_channel_set_variable(a_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE, "park:inline"); + switch_ivr_session_transfer(a_session, "park", "inline", NULL); } //switch_channel_set_variable_printf(a_channel, "park_command", "moh"); switch_core_session_rwunlock(a_session); + + nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"), + NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END()); + + + if (0 && b_tech_pvt) { + sofia_set_flag_locked(b_tech_pvt, TFLAG_BYE); + nua_bye(b_tech_pvt->nh, + SIPTAG_REASON_STR("Q.850;cause=16;text=\"normal_clearing\""), + TAG_IF(!switch_strlen_zero(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), + TAG_END()); + } + } else { + nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"), + NUTAG_SUBSTATE(nua_substate_terminated), + SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"), SIPTAG_EVENT_STR(etmp), TAG_END()); } - nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"), - NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END()); - + //switch_channel_set_variable(channel_b, "park_timeout", "2"); //switch_channel_set_state(channel_b, CS_PARK); diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 6c84a74a51..72dfebe426 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -1283,6 +1283,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_ if (switch_strlen_zero(dialplan)) { dialplan = profile->dialplan; + if (!switch_strlen_zero(dialplan) && !strcasecmp(dialplan, "inline")) { + dialplan = NULL; + } } if (switch_strlen_zero(context)) { diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index d79b9e2cee..5b7c3a9a57 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -364,6 +364,9 @@ static uint8_t check_channel_status(originate_global_t *oglobals, originate_stat if (oglobals->session) { caller_channel = switch_core_session_get_channel(oglobals->session); + if (switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) { + caller_channel = NULL; + } } @@ -1997,8 +2000,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess } if (caller_channel && switch_channel_get_state(caller_channel) != wait_state && !switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) { - oglobals.idx = IDX_NADA; - goto notready; + //oglobals.idx = IDX_NADA; + //goto notready; } if (!oglobals.sent_ring && !oglobals.progress && (progress_timelimit_sec && elapsed > (time_t) progress_timelimit_sec)) { @@ -2162,10 +2165,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess switch_core_session_reset(oglobals.session, SWITCH_FALSE, SWITCH_TRUE); } - if ((oglobals.idx == IDX_TIMEOUT || oglobals.idx == IDX_KEY_CANCEL) && (caller_channel && switch_channel_ready(caller_channel))) { - holding = NULL; - } - if (holding) { if (oglobals.idx > IDX_NADA) { peer_session = originate_status[oglobals.idx].peer_session; @@ -2202,26 +2201,62 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess end_search: - - if (peer_channel && switch_channel_ready(peer_channel)) { - force_reason = SWITCH_CAUSE_ATTENDED_TRANSFER; - switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(peer_session)); - oglobals.idx = IDX_NADA; - if (caller_channel) { - switch_channel_hangup(caller_channel, SWITCH_CAUSE_ATTENDED_TRANSFER); - } - switch_core_session_rwunlock(peer_session); - } else { + if (peer_channel && (oglobals.idx == IDX_TIMEOUT || to || oglobals.idx == IDX_KEY_CANCEL || oglobals.idx == IDX_CANCEL)) { + const char *dest = switch_channel_get_variable(peer_channel, "destination_number"); + const char *context = switch_channel_get_variable(peer_channel, "context"); + const char *dialplan = switch_channel_get_variable(peer_channel, "dialplan"); switch_core_session_t *holding_session; - if ((holding_session = switch_core_session_locate(holding))) { - switch_channel_t *holding_channel = switch_core_session_get_channel(holding_session); - if (caller_channel && switch_channel_ready(caller_channel)) { - switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(session)); - } else { - switch_channel_hangup(holding_channel, SWITCH_CAUSE_NORMAL_UNSPECIFIED); + if (caller_channel) { + if (switch_strlen_zero(context)) { + context = switch_channel_get_variable(caller_channel, "context"); } + if (switch_strlen_zero(dialplan)) { + dialplan = switch_channel_get_variable(caller_channel, "dialplan"); + } + } + + if (switch_strlen_zero(context)) { + context = "default"; + } + + if (switch_strlen_zero(context)) { + dialplan = "XML"; + } + + if ((holding_session = switch_core_session_locate(holding))) { + switch_ivr_session_transfer(holding_session, dest, dialplan, context); switch_core_session_rwunlock(holding_session); + holding = NULL; + holding_session = NULL; + } + + switch_channel_hangup(peer_channel, SWITCH_CAUSE_ATTENDED_TRANSFER); + switch_core_session_rwunlock(peer_session); + } else { + if (peer_channel && switch_channel_ready(peer_channel)) { + force_reason = SWITCH_CAUSE_ATTENDED_TRANSFER; + switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(peer_session)); + oglobals.idx = IDX_NADA; + if (caller_channel && switch_channel_up(caller_channel)) { + switch_channel_hangup(caller_channel, SWITCH_CAUSE_ATTENDED_TRANSFER); + } + caller_channel = NULL; + oglobals.session = NULL; + session = NULL; + switch_core_session_rwunlock(peer_session); + } else { + switch_core_session_t *holding_session; + + if ((holding_session = switch_core_session_locate(holding))) { + switch_channel_t *holding_channel = switch_core_session_get_channel(holding_session); + if (caller_channel && switch_channel_ready(caller_channel)) { + switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(session)); + } else { + switch_channel_hangup(holding_channel, SWITCH_CAUSE_NORMAL_UNSPECIFIED); + } + switch_core_session_rwunlock(holding_session); + } } } @@ -2229,8 +2264,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess peer_channel = NULL; } - - + for (i = 0; i < and_argc; i++) { if (!peer_eligible(originate_status[i].peer_channel)) { continue;