From d364e9f2b81465d40415a67fe11aef3f4bb71a9c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 3 Aug 2011 23:43:41 -0500 Subject: [PATCH] display fixes and add 2 new cols to channels to store last sent display data --- .../mod_spandsp/mod_spandsp_fax.c | 2 + src/mod/endpoints/mod_sofia/mod_sofia.c | 14 +++++-- src/mod/endpoints/mod_sofia/sofia.c | 17 ++++----- src/switch_core_sqldb.c | 38 ++++++++++++++++--- src/switch_ivr_bridge.c | 16 ++++++++ 5 files changed, 70 insertions(+), 17 deletions(-) diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c index 9b36d03cca..34562faadd 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c @@ -1570,6 +1570,8 @@ static switch_status_t t38_gateway_on_consume_media(switch_core_session_t *sessi switch_core_session_receive_message(session, &msg); 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", peer_uuid); switch_channel_event_set_data(channel, event); switch_event_fire(&event); } diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 3165484b0e..b7db7985c6 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -2013,13 +2013,21 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi tech_pvt->last_sent_callee_id_name = switch_core_session_strdup(tech_pvt->session, name); tech_pvt->last_sent_callee_id_number = switch_core_session_strdup(tech_pvt->session, number); + switch_channel_set_variable(channel, "last_sent_callee_id_name", name); + switch_channel_set_variable(channel, "last_sent_callee_id_number", number); + + if (switch_event_create(&event, SWITCH_EVENT_CALL_UPDATE) == SWITCH_STATUS_SUCCESS) { const char *uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Direction", "SEND"); - switch_channel_set_profile_var(channel, "callee_id_name", name); - switch_channel_set_profile_var(channel, "callee_id_number", number); - + + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Sent-Callee-ID-Name", name); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Sent-Callee-ID-Number", number); + + //switch_channel_set_profile_var(channel, "callee_id_name", name); + //switch_channel_set_profile_var(channel, "callee_id_number", number); + if (uuid) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridged-To", uuid); } diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 4ca0e91054..865feebbde 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -952,8 +952,9 @@ static void our_sofia_event_callback(nua_event_t event, } } case nua_r_ack: - if (channel) + if (channel) { switch_channel_set_flag(channel, CF_MEDIA_ACK); + } break; case nua_r_shutdown: if (status >= 200) { @@ -4968,6 +4969,12 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status sofia_clear_flag(tech_pvt, TFLAG_RECOVERING); } + if ((status == 180 || status == 183) && switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { + const char *val; + if ((val = switch_channel_get_variable(channel, "sip_auto_answer")) && switch_true(val)) { + nua_notify(nh, NUTAG_NEWSUB(1), NUTAG_SUBSTATE(nua_substate_active), SIPTAG_EVENT_STR("talk"), TAG_END()); + } + } } end: @@ -5158,14 +5165,6 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, status = 183; } - if (channel && (status == 180 || status == 183) && switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { - const char *val; - if ((val = switch_channel_get_variable(channel, "sip_auto_answer")) && switch_true(val)) { - nua_notify(nh, NUTAG_NEWSUB(1), NUTAG_SUBSTATE(nua_substate_active), SIPTAG_EVENT_STR("talk"), TAG_END()); - } - } - - state_process: diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 3ef516a80b..ee37c612f9 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -1291,10 +1291,12 @@ static void core_event_handler(switch_event_t *event) break; case SWITCH_EVENT_CALL_UPDATE: { - new_sql() = switch_mprintf("update channels set callee_name='%q',callee_num='%q',callee_direction='%q'," + new_sql() = switch_mprintf("update channels set callee_name='%q',callee_num='%q',sent_callee_name='%q',sent_callee_num='%q',callee_direction='%q'," "cid_name='%q',cid_num='%q' where uuid='%s'", switch_event_get_header_nil(event, "caller-callee-id-name"), switch_event_get_header_nil(event, "caller-callee-id-number"), + switch_event_get_header_nil(event, "sent-callee-id-name"), + switch_event_get_header_nil(event, "sent-callee-id-number"), switch_event_get_header_nil(event, "direction"), switch_event_get_header_nil(event, "caller-caller-id-name"), switch_event_get_header_nil(event, "caller-caller-id-number"), @@ -1337,6 +1339,7 @@ static void core_event_handler(switch_event_t *event) case CS_ROUTING: if ((extra_cols = parse_presence_data_cols(event))) { new_sql() = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q',callee_name='%q',callee_num='%q'," + "sent_callee_name='%q',sent_callee_num='%q'," "ip_addr='%s',dest='%q',dialplan='%q',context='%q',presence_id='%q',presence_data='%q',%s " "where uuid='%s'", switch_event_get_header_nil(event, "channel-state"), @@ -1344,6 +1347,8 @@ static void core_event_handler(switch_event_t *event) switch_event_get_header_nil(event, "caller-caller-id-number"), switch_event_get_header_nil(event, "caller-callee-id-name"), switch_event_get_header_nil(event, "caller-callee-id-number"), + switch_event_get_header_nil(event, "sent-callee-id-name"), + switch_event_get_header_nil(event, "sent-callee-id-number"), switch_event_get_header_nil(event, "caller-network-addr"), switch_event_get_header_nil(event, "caller-destination-number"), switch_event_get_header_nil(event, "caller-dialplan"), @@ -1354,7 +1359,8 @@ static void core_event_handler(switch_event_t *event) switch_event_get_header_nil(event, "unique-id")); free(extra_cols); } else { - new_sql() = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q',callee_name='%q',callee_num='%q'," + new_sql() = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q',callee_name='%q'," + "sent_callee_name='%q',sent_callee_num='%q', callee_num='%q'," "ip_addr='%s',dest='%q',dialplan='%q',context='%q',presence_id='%q',presence_data='%q' " "where uuid='%s'", switch_event_get_header_nil(event, "channel-state"), @@ -1362,6 +1368,8 @@ static void core_event_handler(switch_event_t *event) switch_event_get_header_nil(event, "caller-caller-id-number"), switch_event_get_header_nil(event, "caller-callee-id-name"), switch_event_get_header_nil(event, "caller-callee-id-number"), + switch_event_get_header_nil(event, "sent-callee-id-name"), + switch_event_get_header_nil(event, "sent-callee-id-number"), switch_event_get_header_nil(event, "caller-network-addr"), switch_event_get_header_nil(event, "caller-destination-number"), switch_event_get_header_nil(event, "caller-dialplan"), @@ -1384,6 +1392,15 @@ static void core_event_handler(switch_event_t *event) } case SWITCH_EVENT_CHANNEL_BRIDGE: { + const char *a_uuid, *b_uuid; + + a_uuid = switch_event_get_header(event, "Bridge-A-Unique-ID"); + b_uuid = switch_event_get_header(event, "Bridge-B-Unique-ID"); + + if (zstr(a_uuid) || zstr(b_uuid)) { + a_uuid = switch_event_get_header_nil(event, "caller-unique-id"); + 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"), @@ -1395,8 +1412,8 @@ static void core_event_handler(switch_event_t *event) switch_event_get_header_nil(event, "channel-call-uuid"), switch_event_get_header_nil(event, "event-date-local"), (long) switch_epoch_time_now(NULL), - switch_event_get_header_nil(event, "caller-unique-id"), - switch_event_get_header_nil(event, "Other-Leg-unique-id"), + a_uuid, + b_uuid, switch_core_get_switchname() ); } @@ -1554,7 +1571,9 @@ static char create_channels_sql[] = " callee_name VARCHAR(1024),\n" " callee_num VARCHAR(256),\n" " callee_direction VARCHAR(5),\n" - " call_uuid VARCHAR(256)\n" + " call_uuid VARCHAR(256),\n" + " sent_callee_name VARCHAR(1024),\n" + " sent_callee_num VARCHAR(256)\n" ");\n" "create index chidx1 on channels (hostname);\n" "create index uuindex on channels (uuid);\n" @@ -1650,6 +1669,8 @@ static char detailed_calls_sql[] = "a.callee_num as callee_num," "a.callee_direction as callee_direction," "a.call_uuid as call_uuid," + "a.sent_callee_name as sent_callee_name," + "a.sent_callee_num as sent_callee_num," "b.uuid as b_uuid," "b.direction as b_direction," "b.created as b_created," @@ -1679,6 +1700,8 @@ static char detailed_calls_sql[] = "b.callee_num as b_callee_num," "b.callee_direction as b_callee_direction," "b.call_uuid as b_call_uuid," + "b.sent_callee_name as b_sent_callee_name," + "b.sent_callee_num as b_sent_callee_num," "c.call_created_epoch as call_created_epoch " "from channels a " "left join calls c on a.uuid = c.caller_uuid and a.hostname = c.hostname " @@ -1707,6 +1730,9 @@ static char basic_calls_sql[] = "a.callee_direction as callee_direction," "a.call_uuid as call_uuid," "a.hostname as hostname," + "a.sent_callee_name as sent_callee_name," + "a.sent_callee_num as sent_callee_num," + "b.uuid as b_uuid," "b.direction as b_direction," @@ -1725,6 +1751,8 @@ static char basic_calls_sql[] = "b.callee_name as b_callee_name," "b.callee_num as b_callee_num," "b.callee_direction as b_callee_direction," + "b.sent_callee_name as b_sent_callee_name," + "b.sent_callee_num as b_sent_callee_num," "c.call_created_epoch as call_created_epoch " "from channels a " diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c index 0fecc309f7..32d1451a6e 100644 --- a/src/switch_ivr_bridge.c +++ b/src/switch_ivr_bridge.c @@ -918,6 +918,8 @@ static switch_status_t signal_bridge_on_hibernate(switch_core_session_t *session if (switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) { 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", msg.string_arg); switch_channel_event_set_data(channel, event); switch_event_fire(&event); } @@ -1151,6 +1153,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses switch_channel_set_state(peer_channel, CS_CONSUME_MEDIA); 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)); switch_channel_event_set_data(caller_channel, event); switch_event_fire(&event); br = 1; @@ -1398,6 +1402,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu originator_channel = switch_core_session_get_channel(originator_session); originatee_channel = switch_core_session_get_channel(originatee_session); + + 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(originator_channel)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s is hungup refusing to bridge.\n", switch_channel_get_name(originatee_channel)); switch_core_session_rwunlock(originator_session);