From b72d2c32d7a5cbbfbf1ae14ec9d2d54fb87b75ef Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 1 Apr 2013 23:02:29 -0500 Subject: [PATCH] do some more caller-id cleanup --- src/mod/applications/mod_fifo/mod_fifo.c | 4 + src/mod/endpoints/mod_loopback/mod_loopback.c | 22 +++-- src/mod/endpoints/mod_sofia/sofia.c | 11 ++- src/switch_channel.c | 6 ++ src/switch_ivr_bridge.c | 89 +++++++++++++------ 5 files changed, 99 insertions(+), 33 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 685517beef..9c57a36650 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -3078,6 +3078,10 @@ SWITCH_STANDARD_APP(fifo_function) switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session); + if (!switch_channel_test_flag(other_channel, CF_TRANSFER) || !switch_channel_up(other_channel)) { + switch_channel_set_variable(other_channel, "fifo_initiated_bridge", "true"); + } + if (outbound_id) { long now = (long) switch_epoch_time_now(NULL); diff --git a/src/mod/endpoints/mod_loopback/mod_loopback.c b/src/mod/endpoints/mod_loopback/mod_loopback.c index 1f29a1431e..6010bd70a9 100644 --- a/src/mod/endpoints/mod_loopback/mod_loopback.c +++ b/src/mod/endpoints/mod_loopback/mod_loopback.c @@ -954,12 +954,22 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s case SWITCH_MESSAGE_INDICATE_DISPLAY: { - if (!zstr(msg->string_array_arg[0])) { - switch_channel_set_profile_var(tech_pvt->other_channel, "callee_id_name", msg->string_array_arg[0]); - } - - if (!zstr(msg->string_array_arg[1])) { - switch_channel_set_profile_var(tech_pvt->other_channel, "callee_id_number", msg->string_array_arg[1]); + if (switch_test_flag(tech_pvt, TFLAG_BLEG)) { + if (!zstr(msg->string_array_arg[0])) { + switch_channel_set_profile_var(tech_pvt->other_channel, "caller_id_name", msg->string_array_arg[0]); + } + + if (!zstr(msg->string_array_arg[1])) { + switch_channel_set_profile_var(tech_pvt->other_channel, "caller_id_number", msg->string_array_arg[1]); + } + } else { + if (!zstr(msg->string_array_arg[0])) { + switch_channel_set_profile_var(tech_pvt->other_channel, "callee_id_name", msg->string_array_arg[0]); + } + + if (!zstr(msg->string_array_arg[1])) { + switch_channel_set_profile_var(tech_pvt->other_channel, "callee_id_number", msg->string_array_arg[1]); + } } pass = 1; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 42593e4050..1a647c6bfb 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -6672,6 +6672,8 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Process REFER to [%s@%s]\n", exten, (char *) refer_to->r_url->url_host); + switch_channel_set_variable(tech_pvt->channel, "transfer_disposition", "recv_replace"); + if (refer_to->r_url && refer_to->r_url->url_headers) { rep = (char *) switch_stristr("Replaces=", refer_to->r_url->url_headers); @@ -6724,6 +6726,8 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t b_tech_pvt = (private_object_t *) switch_core_session_get_private(b_session); channel_b = switch_core_session_get_channel(b_session); + switch_channel_set_variable(channel_b, "transfer_disposition", "replaced"); + br_a = switch_channel_get_partner_uuid(channel_a); br_b = switch_channel_get_partner_uuid(channel_b); @@ -6868,6 +6872,8 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t switch_channel_set_flag(tchannel, CF_BYPASS_MEDIA_AFTER_BRIDGE); } + switch_channel_set_variable(tchannel, "transfer_disposition", "bridge"); + switch_channel_set_flag(tchannel, CF_ATTENDED_TRANSFER); switch_core_session_rwunlock(tmp); } @@ -6881,6 +6887,7 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t if (switch_true(switch_channel_get_variable(channel_a, "recording_follow_transfer")) && (tmp = switch_core_session_locate(br_a))) { + switch_channel_set_variable(switch_core_session_get_channel(tmp), "transfer_disposition", "bridge"); switch_core_media_bug_transfer_recordings(session, tmp); switch_core_session_rwunlock(tmp); } @@ -6894,9 +6901,9 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t switch_channel_set_variable_printf(channel_a, "transfer_to", "att:%s", br_b); - mark_transfer_record(session, br_b, br_a); + mark_transfer_record(session, br_a, br_b); - switch_ivr_uuid_bridge(br_b, br_a); + switch_ivr_uuid_bridge(br_a, br_b); switch_channel_set_variable(channel_b, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER"); nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"), NUTAG_SUBSTATE(nua_substate_terminated),SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK\r\n"), SIPTAG_EVENT_STR(etmp), diff --git a/src/switch_channel.c b/src/switch_channel.c index 0668e8b293..bcb93c8b2a 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -3032,6 +3032,12 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan switch_channel_set_variable_partner(channel, "last_bridge_" SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE, var); } + if (switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) { + switch_channel_set_variable(channel, "last_bridge_role", "originator"); + } else if (switch_channel_test_flag(channel, CF_BRIDGED)) { + switch_channel_set_variable(channel, "last_bridge_role", "originatee"); + } + if (!switch_core_session_running(channel->session) && !switch_core_session_started(channel->session)) { switch_core_session_thread_launch(channel->session); diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c index 695105b8da..a5280c2076 100644 --- a/src/switch_ivr_bridge.c +++ b/src/switch_ivr_bridge.c @@ -100,26 +100,26 @@ static void send_display(switch_core_session_t *session, switch_core_session_t * caller_channel = switch_core_session_get_channel(session); caller_profile = switch_channel_get_caller_profile(caller_channel); - if (switch_channel_direction(caller_channel) == SWITCH_CALL_DIRECTION_OUTBOUND && !switch_channel_test_flag(caller_channel, CF_DIALPLAN)) { + + if (switch_channel_test_flag(caller_channel, CF_BRIDGE_ORIGINATOR)) { + name = caller_profile->caller_id_name; + number = caller_profile->caller_id_number; + + if (zstr(number)) { + number = "UNKNOWN"; + } + } else { name = caller_profile->callee_id_name; number = caller_profile->callee_id_number; - if (zstr(name)) { - name = caller_profile->destination_number; - } if (zstr(number)) { number = caller_profile->destination_number; } - } else { - name = caller_profile->caller_id_name; - number = caller_profile->caller_id_number; + } - if (zstr(name)) { - name = caller_profile->destination_number; - } - if (zstr(number)) { - number = caller_profile->destination_number; - } + + if (zstr(name)) { + name = number; } if ((p = strrchr(number, '/'))) { @@ -129,6 +129,9 @@ static void send_display(switch_core_session_t *session, switch_core_session_t * name = p + 1; } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SEND %s [%s][%s]\n", switch_core_session_get_name(peer_session), name, number); + msg = switch_core_session_alloc(peer_session, sizeof(*msg)); MESSAGE_STAMP_FFL(msg); msg->message_id = SWITCH_MESSAGE_INDICATE_DISPLAY; @@ -1576,18 +1579,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu } - - if (switch_channel_direction(originatee_channel) == SWITCH_CALL_DIRECTION_OUTBOUND && !switch_channel_test_flag(originatee_channel, CF_DIALPLAN)) { - switch_channel_flip_cid(originatee_channel); - switch_channel_set_flag(originatee_channel, CF_DIALPLAN); - } - if (switch_channel_direction(originator_channel) == SWITCH_CALL_DIRECTION_OUTBOUND && !switch_channel_test_flag(originator_channel, CF_DIALPLAN)) { switch_channel_flip_cid(originator_channel); switch_channel_set_flag(originator_channel, CF_DIALPLAN); } - if (switch_channel_down_nosig(originator_channel)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originator_session), SWITCH_LOG_DEBUG, "%s is hungup refusing to bridge.\n", switch_channel_get_name(originatee_channel)); switch_core_session_rwunlock(originator_session); @@ -1639,6 +1635,21 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu originator_cp = switch_channel_get_caller_profile(originator_channel); originatee_cp = switch_channel_get_caller_profile(originatee_channel); + if (switch_channel_inbound_display(originatee_channel)) { + const char *tname = originatee_cp->caller_id_name; + const char *tnum = originatee_cp->caller_id_number; + +#ifdef DEEP_DEBUG_CID + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SWAP [%s][%s] [%s][%s]\n", originatee_cp->caller_id_name, originatee_cp->caller_id_number, originatee_cp->callee_id_name, originatee_cp->callee_id_number); +#endif + + originatee_cp->caller_id_name = originatee_cp->callee_id_name; + originatee_cp->caller_id_number = originatee_cp->callee_id_number; + + originatee_cp->callee_id_name = tname; + originatee_cp->callee_id_number = tnum; + } + switch_channel_set_variable(originatee_channel, "original_destination_number", originatee_cp->destination_number); switch_channel_set_variable(originatee_channel, "original_caller_id_name", originatee_cp->caller_id_name); @@ -1654,15 +1665,43 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu originator_cp = switch_channel_get_caller_profile(originator_channel); originatee_cp = switch_channel_get_caller_profile(originatee_channel); + +#ifdef DEEP_DEBUG_CID + { + switch_event_t *event; + + if (switch_event_create_plain(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { + //switch_channel_event_set_basic_data(originator_channel, event); + switch_caller_profile_event_set_data(originator_cp, "ORIGINATOR", event); + switch_caller_profile_event_set_data(originatee_cp, "ORIGINATEE", event); + DUMP_EVENT(event); + switch_event_destroy(&event); + } + } +#endif + switch_channel_set_originator_caller_profile(originatee_channel, switch_caller_profile_clone(originatee_session, originator_cp)); switch_channel_set_originatee_caller_profile(originator_channel, switch_caller_profile_clone(originator_session, originatee_cp)); - originator_cp->callee_id_name = switch_core_strdup(originator_cp->pool, originatee_cp->caller_id_name); - originator_cp->callee_id_number = switch_core_strdup(originator_cp->pool, originatee_cp->caller_id_number); + originator_cp->callee_id_name = switch_core_strdup(originator_cp->pool, originatee_cp->callee_id_name); + originator_cp->callee_id_number = switch_core_strdup(originator_cp->pool, originatee_cp->callee_id_number); - originatee_cp->callee_id_name = switch_core_strdup(originatee_cp->pool, originator_cp->caller_id_name); - originatee_cp->callee_id_number = switch_core_strdup(originatee_cp->pool, originator_cp->caller_id_number); - + originatee_cp->caller_id_name = switch_core_strdup(originatee_cp->pool, originator_cp->caller_id_name); + originatee_cp->caller_id_number = switch_core_strdup(originatee_cp->pool, originator_cp->caller_id_number); + +#ifdef DEEP_DEBUG_CID + { + switch_event_t *event; + + if (switch_event_create_plain(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { + //switch_channel_event_set_basic_data(originator_channel, event); + switch_caller_profile_event_set_data(originator_cp, "POST-ORIGINATOR", event); + switch_caller_profile_event_set_data(originatee_cp, "POST-ORIGINATEE", event); + DUMP_EVENT(event); + switch_event_destroy(&event); + } + } +#endif switch_channel_stop_broadcast(originator_channel); switch_channel_stop_broadcast(originatee_channel);