diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index b7ae95afd8..72840a4a4e 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -169,11 +169,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses \param session originating session \param bleg B leg session \param bridgeto the desired remote callstring + \param table optional state handler table to install on the channel + \param cid_name_override override the caller id name + \param cid_num_override override the caller id number \return SWITCH_STATUS_SUCCESS if bleg is a running session. */ -SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *session, - switch_core_session_t **bleg, - char *bridgeto); +SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *session, + switch_core_session_t **bleg, + char *bridgeto, + const switch_state_handler_table_t *table, + char *cid_name_override, + char *cid_num_override); /*! \brief Bridge Audio from one session to another diff --git a/src/mod/applications/mod_bridgecall/mod_bridgecall.c b/src/mod/applications/mod_bridgecall/mod_bridgecall.c index 3c8729b541..c1e2f76a73 100644 --- a/src/mod/applications/mod_bridgecall/mod_bridgecall.c +++ b/src/mod/applications/mod_bridgecall/mod_bridgecall.c @@ -45,7 +45,7 @@ static void audio_bridge_function(switch_core_session_t *session, char *data) caller_channel = switch_core_session_get_channel(session); assert(caller_channel != NULL); - if (switch_ivr_outcall(session, &peer_session, data) != SWITCH_STATUS_SUCCESS) { + if (switch_ivr_originate(session, &peer_session, data, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n"); switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL); return; diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 3f61c5a9d3..aeb0d74bd4 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -1974,148 +1974,32 @@ static const switch_state_handler_table_t audio_bridge_peer_state_handlers = { static switch_status_t conference_outcall(conference_obj_t *conference, switch_core_session_t *session, char *bridgeto, char *cid_name, char *cid_num) { switch_core_session_t *peer_session; - switch_caller_profile_t *caller_profile, *caller_caller_profile; - char *chan_type, *chan_data; - unsigned int timelimit = 60; switch_channel_t *peer_channel; - time_t start; - switch_frame_t *read_frame = NULL; switch_status_t status = SWITCH_STATUS_SUCCESS; switch_channel_t *caller_channel = NULL; - chan_type = strdup(bridgeto); - - if ((chan_data = strchr(chan_type, '/')) != 0) { - *chan_data = '\0'; - chan_data++; - } - - if (session) { - caller_channel = switch_core_session_get_channel(session); - assert(caller_channel != NULL); - caller_caller_profile = switch_channel_get_caller_profile(caller_channel); - if (!cid_name) { - cid_name = caller_caller_profile->caller_id_name; - } - - if (!cid_num) { - cid_num = caller_caller_profile->caller_id_number; - } - - caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), - caller_caller_profile->username, - caller_caller_profile->dialplan, - cid_name, - cid_num, - caller_caller_profile->network_addr, - NULL, - NULL, - caller_caller_profile->rdnis, - caller_caller_profile->source, - caller_caller_profile->context, - chan_data); - } else { - - if (!cid_name) { - cid_name = conference->caller_id_name; - } - - if (!cid_num) { - cid_num = conference->caller_id_number; - } - - caller_profile = switch_caller_profile_new(conference->pool, - NULL, - NULL, - cid_name, - cid_num, - NULL, - NULL, - NULL, - NULL, - (char *) global_app_name, - NULL, - chan_data); - } - - - - if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session, NULL) != - SWITCH_STATUS_SUCCESS) { + if (switch_ivr_originate(session, &peer_session, bridgeto, &audio_bridge_peer_state_handlers, cid_name, cid_num) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n"); - if (caller_channel) { + if (session) { + caller_channel = switch_core_session_get_channel(session); switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL); } - status = SWITCH_STATUS_FALSE; goto done; } + + switch_core_session_rwunlock(peer_session); peer_channel = switch_core_session_get_channel(peer_session); assert(peer_channel != NULL); - - switch_channel_add_state_handler(peer_channel, &audio_bridge_peer_state_handlers); - - if (switch_core_session_runing(peer_session)) { - switch_channel_set_state(peer_channel, CS_RING); - } else { - switch_core_session_thread_launch(peer_session); - } - - time(&start); - - for (;;) { - int state = switch_channel_get_state(peer_channel); - if (state >= CS_RING) { - break; - } - - if (caller_channel && !switch_channel_ready(caller_channel)) { - break; - } - - if ((time(NULL) - start) > (time_t)timelimit) { - break; - } - switch_yield(1000); - } - - if (caller_channel) { - switch_channel_pre_answer(caller_channel); - } - - while ((!caller_channel || switch_channel_ready(caller_channel)) && - !switch_channel_test_flag(peer_channel, CF_ANSWERED) && - !switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA) && - ((time(NULL) - start) < (time_t)timelimit)) { - - /* read from the channel while we wait if the audio is up on it */ - if (session && (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA))) { - switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0); - - if (!SWITCH_READ_ACCEPTABLE(status)) { - break; - } - if (read_frame) { - if (switch_core_session_write_frame(session, read_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) { - break; - } - } - - } else { - switch_yield(1000); - } - - } - + if (caller_channel && switch_channel_test_flag(peer_channel, CF_ANSWERED)) { switch_channel_answer(caller_channel); } if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) { switch_caller_extension_t *extension = NULL; - if ((extension = switch_caller_extension_new(peer_session, caller_profile->destination_number, - caller_profile->destination_number)) == 0) { + if ((extension = switch_caller_extension_new(peer_session, conference->name, conference->name)) == 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n"); status = SWITCH_STATUS_MEMERR; goto done; @@ -2132,7 +2016,6 @@ static switch_status_t conference_outcall(conference_obj_t *conference, switch_c } done: - free(chan_type); return status; } diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 80b2aacf0e..cbb449d1de 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -1142,9 +1142,12 @@ static const switch_state_handler_table_t audio_bridge_peer_state_handlers = { -SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *session, - switch_core_session_t **bleg, - char *bridgeto) +SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *session, + switch_core_session_t **bleg, + char *bridgeto, + const switch_state_handler_table_t *table, + char *cid_name_override, + char *cid_num_override) { switch_core_session_t *peer_session; @@ -1170,12 +1173,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio assert(caller_channel != NULL); caller_caller_profile = switch_channel_get_caller_profile(caller_channel); + if (!cid_name_override) { + cid_name_override = caller_caller_profile->caller_id_name; + } + if (!cid_num_override) { + cid_num_override = caller_caller_profile->caller_id_number; + } caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), caller_caller_profile->username, caller_caller_profile->dialplan, - caller_caller_profile->caller_id_name, - caller_caller_profile->caller_id_number, + cid_name_override, + cid_num_override, caller_caller_profile->network_addr, NULL, NULL, @@ -1184,12 +1193,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio caller_caller_profile->context, chan_data); } else { - + if (!cid_name_override) { + cid_name_override = "FreeSWITCH"; + } + if (!cid_num_override) { + cid_num_override = "0000000000"; + } caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), NULL, NULL, - "FreeSWITCH", - "0000000000", + cid_name_override, + cid_num_override, NULL, NULL, NULL, @@ -1212,7 +1226,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio peer_channel = switch_core_session_get_channel(peer_session); assert(peer_channel != NULL); - switch_channel_add_state_handler(peer_channel, &audio_bridge_peer_state_handlers); + if (!table) { + table = &audio_bridge_peer_state_handlers; + } + + switch_channel_add_state_handler(peer_channel, table); if (switch_core_session_runing(peer_session)) { switch_channel_set_state(peer_channel, CS_RING); @@ -1246,7 +1264,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio !switch_channel_test_flag(peer_channel, CF_ANSWERED) && !switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA) && ((time(NULL) - start) < (time_t)timelimit)) { - + /* read from the channel while we wait if the audio is up on it */ if (session && (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA))) { switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0); @@ -1263,7 +1281,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio } else { switch_yield(1000); } - + } if (caller_channel && switch_channel_test_flag(peer_channel, CF_ANSWERED)) { @@ -1278,6 +1296,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_outcall(switch_core_session_t *sessio status = SWITCH_STATUS_FALSE; } + done: free(chan_type); return status;