]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-3688 refactor of cancel handling code in bridge
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 7 Dec 2011 23:42:52 +0000 (17:42 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 7 Dec 2011 23:42:52 +0000 (17:42 -0600)
src/switch_ivr_bridge.c
src/switch_ivr_originate.c

index a8feb938daf9ae9f18acd612e97d4391c6090520..bd245d2373faf094f1bdbe833a41ed49be406aab 100644 (file)
@@ -1151,6 +1151,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_signal_bridge(switch_core_session_t *
        return SWITCH_STATUS_SUCCESS;
 }
 
+static void abort_call(switch_channel_t *caller_channel, switch_channel_t *peer_channel)
+{
+       switch_call_cause_t cause = switch_channel_get_cause(caller_channel);
+       
+       if (!cause) {
+               cause = SWITCH_CAUSE_ORIGINATOR_CANCEL;
+       }
+       
+       switch_channel_hangup(peer_channel, cause);
+}
+
 SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_session_t *session,
                                                                                                                                 switch_core_session_t *peer_session,
                                                                                                                                 switch_input_callback_function_t input_callback, void *session_data,
@@ -1208,21 +1219,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
                switch_channel_test_flag(peer_channel, CF_RING_READY)) {
                const char *app, *data;
                
-               if (switch_channel_get_state(peer_channel) == CS_CONSUME_MEDIA) {
-                       switch_channel_set_state(peer_channel, CS_HIBERNATE);
-                       switch_channel_wait_for_state(peer_channel, caller_channel, CS_HIBERNATE);
-               }
-
-               if (!switch_channel_ready(caller_channel)) {
-                       switch_call_cause_t cause = switch_channel_get_cause(caller_channel);
-
-                       if (cause) {
-                               switch_channel_hangup(peer_channel, cause);
-                               goto done;
-                       }
+               if (!switch_channel_ready(caller_channel)) {
+                       abort_call(caller_channel, peer_channel);
+                       goto done;
                }
 
-
                switch_channel_set_state(peer_channel, CS_CONSUME_MEDIA);
 
                switch_channel_set_variable(peer_channel, "call_uuid", switch_core_session_get_uuid(session));
@@ -1241,6 +1242,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
                        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_ready(caller_channel)) {
+                               abort_call(caller_channel, peer_channel);
+                               goto done;
+                       }
+
                        if (!switch_channel_media_ready(caller_channel) ||
                                (!switch_channel_test_flag(peer_channel, CF_ANSWERED) && !switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA))) {
                                if ((status = switch_ivr_wait_for_answer(session, peer_session)) != SWITCH_STATUS_SUCCESS || !switch_channel_ready(caller_channel)) {
@@ -1260,6 +1266,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
                                                        switch_channel_hangup(caller_channel, SWITCH_CAUSE_ALLOTTED_TIMEOUT);
                                                }
                                        }
+                                       abort_call(caller_channel, peer_channel);
                                        switch_core_session_rwunlock(peer_session);
                                        goto done;
                                }
@@ -1279,6 +1286,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
 
                        if (switch_core_session_receive_message(peer_session, &msg) != SWITCH_STATUS_SUCCESS) {
                                status = SWITCH_STATUS_FALSE;
+                               abort_call(caller_channel, peer_channel);
                                switch_core_session_rwunlock(peer_session);
                                goto done;
                        }
@@ -1286,6 +1294,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
                        msg.string_arg = switch_core_session_strdup(session, switch_core_session_get_uuid(peer_session));
                        if (switch_core_session_receive_message(session, &msg) != SWITCH_STATUS_SUCCESS) {
                                status = SWITCH_STATUS_FALSE;
+                               abort_call(caller_channel, peer_channel);
                                switch_core_session_rwunlock(peer_session);
                                goto done;
                        }
index 50c829f379c0df5f99c371cada3e039423fdabcf..71cdfacde545c2aaafcd2ad0f73f68e556f787e3 100644 (file)
@@ -3510,11 +3510,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
        if (*bleg) {
                switch_channel_t *bchan = switch_core_session_get_channel(*bleg);
 
-               if (switch_channel_get_state(bchan) == CS_CONSUME_MEDIA) {
-                       switch_channel_set_state(bchan, CS_HIBERNATE);
-                       switch_channel_wait_for_state(bchan, caller_channel, CS_HIBERNATE);
-               }
-
                if (session && caller_channel) {
                        switch_caller_profile_t *cloned_profile, *peer_profile = switch_channel_get_caller_profile(switch_core_session_get_channel(*bleg));