]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add last_bridge_to var to keep uuid of last bridged channel and fix race in show...
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 20 Aug 2010 18:28:17 +0000 (13:28 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 20 Aug 2010 18:53:08 +0000 (13:53 -0500)
src/include/switch_types.h
src/switch_core_sqldb.c
src/switch_ivr_bridge.c

index b965ecea5d3cd539893c9ac1960316a9b862425d..70ae155fe6d5cf07df56d2e80545453f88779616 100644 (file)
@@ -160,6 +160,7 @@ SWITCH_BEGIN_EXTERN_C
 #define SWITCH_L_SDP_VARIABLE "switch_l_sdp"
 #define SWITCH_B_SDP_VARIABLE "switch_m_sdp"
 #define SWITCH_BRIDGE_VARIABLE "bridge_to"
+#define SWITCH_LAST_BRIDGE_VARIABLE "last_bridge_to"
 #define SWITCH_SIGNAL_BRIDGE_VARIABLE "signal_bridge_to"
 #define SWITCH_SIGNAL_BOND_VARIABLE "signal_bond"
 #define SWITCH_ORIGINATOR_VARIABLE "originator"
index 978bf4623d99cf43fe952a0cdab64e66f9191448..856cc668b30fd912e5ab18a88392206cff4eef76 100644 (file)
@@ -1052,8 +1052,19 @@ static void core_event_handler(switch_event_t *event)
                }
                break;
        case SWITCH_EVENT_CHANNEL_DESTROY:
-               new_sql() = switch_mprintf("delete from channels where uuid='%q' and hostname='%q'",
-                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+               {
+                       const char *uuid = switch_event_get_header(event, "unique-id");
+                       const char *sig = switch_event_get_header(event, "signal_bridge");
+                       
+                       if (uuid) {
+                               new_sql() = switch_mprintf("delete from channels where uuid='%q' and hostname='%q'",
+                                                                                  uuid, switch_core_get_variable("hostname"));
+                               if (switch_true(sig)) {
+                                       new_sql() = switch_mprintf("delete from calls where caller_uuid='%q' and hostname='%q'",
+                                                                                          uuid, switch_core_get_variable("hostname"));
+                               }
+                       }
+               }
                break;
        case SWITCH_EVENT_CHANNEL_UUID:
                {
index b9a2feafbb1d4a69b7048e38b36545271a9cb641..b317cef62898b2b5617489c07682c4b9eeaa625d 100644 (file)
@@ -877,6 +877,7 @@ static switch_status_t signal_bridge_on_hibernate(switch_core_session_t *session
        }
 
        switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE));
+       switch_channel_set_variable(channel, SWITCH_LAST_BRIDGE_VARIABLE, switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE));
 
        if (switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
                if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) {
@@ -993,6 +994,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_signal_bridge(switch_core_session_t *
        switch_channel_add_state_handler(caller_channel, &signal_bridge_state_handlers);
        switch_channel_add_state_handler(peer_channel, &signal_bridge_state_handlers);
 
+       switch_channel_set_variable(caller_channel, "signal_bridge", "true");
+       switch_channel_set_variable(peer_channel, "signal_bridge", "true");
+
        /* fire events that will change the data table from "show channels" */
        if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
                switch_channel_event_set_data(caller_channel, event);
@@ -1093,6 +1097,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
                if (switch_core_session_read_lock(peer_session) == SWITCH_STATUS_SUCCESS) {
                        switch_channel_set_variable(caller_channel, SWITCH_BRIDGE_VARIABLE, switch_core_session_get_uuid(peer_session));
                        switch_channel_set_variable(peer_channel, SWITCH_BRIDGE_VARIABLE, switch_core_session_get_uuid(session));
+                       switch_channel_set_variable(caller_channel, SWITCH_LAST_BRIDGE_VARIABLE, switch_core_session_get_uuid(peer_session));
+                       switch_channel_set_variable(peer_channel, SWITCH_LAST_BRIDGE_VARIABLE, switch_core_session_get_uuid(session));
 
                        if (!switch_channel_media_ready(caller_channel) ||
                                (!switch_channel_test_flag(peer_channel, CF_ANSWERED) && !switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA))) {