From b946ee94b2584aaf9b939507ea0489d770c7aea3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 4 Aug 2011 01:04:21 -0500 Subject: [PATCH] update call_uuid stuff --- src/switch_channel.c | 2 ++ src/switch_core_session.c | 4 ++++ src/switch_core_sqldb.c | 14 +++++++++++--- src/switch_core_state_machine.c | 5 +++++ src/switch_ivr_bridge.c | 6 ++++++ src/switch_ivr_originate.c | 32 +++++--------------------------- 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/switch_channel.c b/src/switch_channel.c index 3f96616794..bd2f84b779 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -2121,6 +2121,8 @@ SWITCH_DECLARE(void) switch_channel_event_set_basic_data(switch_channel_t *chann if ((v = switch_channel_get_variable(channel, "call_uuid"))) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-UUID", v); + } else { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-UUID", switch_core_session_get_uuid(channel->session)); } if (switch_channel_down(channel)) { diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 168bec3695..23aa8bed52 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -1427,6 +1427,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_uuid(switch_core_session profile->uuid = switch_core_strdup(profile->pool, use_uuid); } + switch_channel_set_variable(session->channel, "uuid", use_uuid); + switch_channel_set_variable(session->channel, "call_uuid", use_uuid); + switch_event_create(&event, SWITCH_EVENT_CHANNEL_UUID); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Old-Unique-ID", session->uuid_str); switch_core_hash_delete(session_manager.session_table, session->uuid_str); @@ -1729,6 +1732,7 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(switch_ } switch_channel_set_variable(session->channel, "uuid", session->uuid_str); + switch_channel_set_variable(session->channel, "call_uuid", session->uuid_str); session->endpoint_interface = endpoint_interface; session->raw_write_frame.data = session->raw_write_buf; diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index ee37c612f9..897cbe9ebd 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -1221,6 +1221,11 @@ static void core_event_handler(switch_event_t *event) switch_event_get_header_nil(event, "unique-id"), switch_event_get_header_nil(event, "old-unique-id") ); + + new_sql() = switch_mprintf("update channels set call_uuid='%q' where call_uuid='%q'", + switch_event_get_header_nil(event, "unique-id"), + switch_event_get_header_nil(event, "old-unique-id") + ); break; } case SWITCH_EVENT_CHANNEL_CREATE: @@ -1402,9 +1407,9 @@ static void core_event_handler(switch_event_t *event) b_uuid = switch_event_get_header_nil(event, "other-leg-unique-id"); } - new_sql() = switch_mprintf("update channels set call_uuid='%q' where uuid='%s'", - switch_event_get_header_nil(event, "channel-call-uuid"), - switch_event_get_header_nil(event, "unique-id")); + new_sql() = switch_mprintf("update channels set call_uuid='%q' where uuid='%s' or uuid='%s'", + switch_event_get_header_nil(event, "channel-call-uuid"), a_uuid, b_uuid); + new_sql() = switch_mprintf("insert into calls (call_uuid,call_created,call_created_epoch," "caller_uuid,callee_uuid,hostname) " @@ -1422,6 +1427,9 @@ static void core_event_handler(switch_event_t *event) { char *uuid = switch_event_get_header_nil(event, "caller-unique-id"); + new_sql() = switch_mprintf("update channels set call_uuid=uuid where call_uuid='%s'", + switch_event_get_header_nil(event, "channel-call-uuid")); + new_sql() = switch_mprintf("delete from calls where (caller_uuid='%q' or callee_uuid='%q')", uuid, uuid); break; diff --git a/src/switch_core_state_machine.c b/src/switch_core_state_machine.c index 2e45dde559..1ab9af91a9 100644 --- a/src/switch_core_state_machine.c +++ b/src/switch_core_state_machine.c @@ -62,6 +62,7 @@ static void switch_core_standard_on_destroy(switch_core_session_t *session) static void switch_core_standard_on_reset(switch_core_session_t *session) { + switch_channel_set_variable(session->channel, "call_uuid", switch_core_session_get_uuid(session)); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Standard RESET\n", switch_channel_get_name(session->channel)); } @@ -76,6 +77,8 @@ static void switch_core_standard_on_routing(switch_core_session_t *session) switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Standard ROUTING\n", switch_channel_get_name(session->channel)); + switch_channel_set_variable(session->channel, "call_uuid", switch_core_session_get_uuid(session)); + if ((switch_channel_test_flag(session->channel, CF_ANSWERED) || switch_channel_test_flag(session->channel, CF_EARLY_MEDIA) || switch_channel_test_flag(session->channel, CF_SIGNAL_BRIDGE_TTL)) && switch_channel_test_flag(session->channel, CF_PROXY_MODE)) { @@ -156,6 +159,8 @@ static void switch_core_standard_on_execute(switch_core_session_t *session) switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Standard EXECUTE\n", switch_channel_get_name(session->channel)); + switch_channel_set_variable(session->channel, "call_uuid", switch_core_session_get_uuid(session)); + if (switch_channel_get_variable(session->channel, "recovered") && !switch_channel_test_flag(session->channel, CF_RECOVERED)) { switch_channel_set_flag(session->channel, CF_RECOVERED); } diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c index 32d1451a6e..9dbd4aecab 100644 --- a/src/switch_ivr_bridge.c +++ b/src/switch_ivr_bridge.c @@ -968,6 +968,7 @@ static switch_status_t signal_bridge_on_hangup(switch_core_session_t *session) switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL); switch_channel_set_variable(other_channel, SWITCH_BRIDGE_VARIABLE, NULL); + switch_channel_set_variable(other_channel, "call_uuid", switch_core_session_get_uuid(other_session)); if (switch_channel_up(other_channel)) { @@ -1044,6 +1045,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_signal_bridge(switch_core_session_t * switch_channel_set_variable(caller_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, switch_core_session_get_uuid(peer_session)); switch_channel_set_variable(peer_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, switch_core_session_get_uuid(session)); + switch_channel_set_variable(peer_channel, "call_uuid", switch_core_session_get_uuid(session)); switch_channel_set_flag_recursive(caller_channel, CF_BRIDGE_ORIGINATOR); switch_channel_clear_flag(peer_channel, CF_BRIDGE_ORIGINATOR); @@ -1152,6 +1154,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses switch_channel_set_state(peer_channel, CS_CONSUME_MEDIA); + switch_channel_set_variable(peer_channel, "call_uuid", switch_core_session_get_uuid(session)); + if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(session)); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", switch_core_session_get_uuid(peer_session)); @@ -1303,6 +1307,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses done: + switch_channel_set_variable(peer_channel, "call_uuid", switch_core_session_get_uuid(peer_session)); + if (br && switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(caller_channel, event); switch_event_fire(&event); diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index cf0fca1d9d..6df4f40782 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -1843,33 +1843,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess } } - if (var_event) { - switch_uuid_t uuid; - char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; - char *use_uuid; - - if (caller_channel) { - use_uuid = switch_core_session_get_uuid(session); - } else { - switch_uuid_get(&uuid); - switch_uuid_format(uuid_str, &uuid); - use_uuid = uuid_str; - } - - switch_event_del_header(var_event, "call_uuid"); - switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "call_uuid", use_uuid); - - if (caller_channel) { - switch_channel_set_variable(caller_channel, "call_uuid", use_uuid); - } - } - - if (caller_channel) { - switch_channel_process_export(caller_channel, NULL, var_event, SWITCH_EXPORT_VARS_VARIABLE); - } - - - /* strip leading spaces */ while (data && *data && *data == ' ') { data++; @@ -2478,6 +2451,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess originate_status[i].peer_session = new_session; switch_channel_set_flag(originate_status[i].peer_channel, CF_ORIGINATING); + + if (caller_channel) { + switch_channel_set_variable(originate_status[i].peer_channel, "call_uuid", switch_channel_get_variable(caller_channel, "call_uuid")); + } + if ((lc = switch_event_get_header(var_event, "local_var_clobber"))) { local_clobber = switch_true(lc);