]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix gremlins in code that worked before then changed it's mind
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 10 Nov 2006 08:13:01 +0000 (08:13 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 10 Nov 2006 08:13:01 +0000 (08:13 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3300 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_am_config.h.in
src/include/switch_types.h
src/mod/applications/mod_commands/mod_commands.c
src/mod/applications/mod_playback/mod_playback.c
src/mod/endpoints/mod_sofia/mod_sofia.c
src/switch_ivr.c

index c2a949cebefad34dbeedbfa1536589dd6bd88616..3e1a92ccaf65c2286357c9d425fa5f513a7ad27a 100644 (file)
 /* Define to rpl_malloc if the replacement function should be used. */
 #undef malloc
 
-/* Define to `unsigned' if <sys/types.h> does not define. */
+/* Define to `unsigned int' if <sys/types.h> does not define. */
 #undef size_t
index 02fb2372290d6fee47fc7e0f58b469a85248f557..fe1b41595d130899127bffbce304e73a68dbf0af 100644 (file)
@@ -87,15 +87,16 @@ SWITCH_BEGIN_EXTERN_C
 #define SWITCH_REMOTE_MEDIA_IP_VARIABLE "_remote_media_ip_"
 #define SWITCH_REMOTE_MEDIA_PORT_VARIABLE "_remote_media_port_"
 #define SWITCH_SPEECH_KEY "_speech_"
-
+#define SWITCH_UUID_BRIDGE "_uuid_bridge_"
 #define SWITCH_BITS_PER_BYTE 8
 typedef uint8_t switch_byte_t;
 
 typedef enum {
        SMF_NONE = 0,
        SMF_REBRIDGE = (1 << 0),
-       SMF_ECHO_BRIDGED = (1 << 1),
-       SMF_FORCE = (1 << 2)
+       SMF_ECHO_ALEG = (1 << 1),
+       SMF_ECHO_BLEG = (1 << 2),
+       SMF_FORCE = (1 << 3),
 } switch_media_flag_t;
 
 typedef enum {
index 42b127baf1c68d58f96f5c0bce4b02501c919e45..2280b34a3eb10b2db532d0b0db91452a2e90e2a4 100644 (file)
@@ -287,8 +287,16 @@ static switch_status_t uuid_broadcast_function(char *cmd, switch_core_session_t
        } else {
                switch_media_flag_t flags = SMF_NONE;
 
-               if (argv[2] && !strcmp(argv[2], "both")) {
-                       flags |= SMF_ECHO_BRIDGED;
+               if (argv[2]) {
+                       if (!strcmp(argv[2], "both")) {
+                               flags |= (SMF_ECHO_ALEG | SMF_ECHO_BLEG);
+                       } else if (!strcmp(argv[2], "aleg")) {
+                               flags |= SMF_ECHO_ALEG;
+                       } else if (!strcmp(argv[2], "bleg")) {
+                               flags |= SMF_ECHO_BLEG;
+                       }
+               } else {
+                       flags |= SMF_ECHO_ALEG;
                }
                
                status = switch_ivr_broadcast(argv[0], argv[1], flags);
index beae8295db193e95e3e5e7be4d2cd644bb1570bc..43f08916738c469a6ceb1ece5d00f7565471a29a 100644 (file)
@@ -111,7 +111,6 @@ static void playback_function(switch_core_session_t *session, char *data)
        switch_channel_t *channel;
        char *timer_name = NULL;
        char *file_name = NULL;
-       switch_status_t status;
 
        file_name = switch_core_session_strdup(session, data);
 
@@ -124,12 +123,8 @@ static void playback_function(switch_core_session_t *session, char *data)
 
        switch_channel_pre_answer(channel);
 
-       status = switch_ivr_play_file(session, NULL, file_name, timer_name, on_dtmf, NULL, 0);
+       switch_ivr_play_file(session, NULL, file_name, timer_name, on_dtmf, NULL, 0);
 
-       if (!switch_channel_ready(channel) || (status != SWITCH_STATUS_SUCCESS && !SWITCH_STATUS_IS_BREAK(status))) {
-               switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-       }
-       
 }
 
 
index 2287b191aa858e5ec1ef6b6d958001fcbd3c8f58..9a2de85f349ee5c2991cbe06672d9e995979455d 100644 (file)
@@ -146,7 +146,7 @@ typedef enum {
 
 typedef enum {
        TFLAG_IO = (1 << 0),
-       TFLAG_USEME = (1 << 1),
+       TFLAG_CHANGE_MEDIA = (1 << 1),
        TFLAG_OUTBOUND = (1 << 2),
        TFLAG_READING = (1 << 3),
        TFLAG_WRITING = (1 << 4),
@@ -1773,7 +1773,6 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
                if (!tech_pvt->local_sdp_str) {
                        tech_absorb_sdp(tech_pvt);
                }
-
                do_invite(session);
        }
                break;
@@ -2403,24 +2402,29 @@ static void sip_i_message(int status,
        }
 }
 
-static void pass_sdp(switch_channel_t *channel, char *sdp) 
+static void pass_sdp(private_object_t *tech_pvt, char *sdp) 
 {
        char *val;
+       switch_channel_t *channel;
        switch_core_session_t *other_session;
        switch_channel_t *other_channel;
        
+       channel = switch_core_session_get_channel(tech_pvt->session);
+       assert(channel != NULL);
+       
        if ((val = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_VARIABLE)) && (other_session = switch_core_session_locate(val))) {
                other_channel = switch_core_session_get_channel(other_session);
                assert(other_channel != NULL);
                if (!switch_channel_get_variable(other_channel, SWITCH_B_SDP_VARIABLE)) {
                        switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, sdp);
                }
-               if (
+               if (!switch_test_flag(tech_pvt, TFLAG_CHANGE_MEDIA) && (
                        switch_channel_test_flag(other_channel, CF_OUTBOUND) && 
                        switch_channel_test_flag(other_channel, CF_NOMEDIA) && 
                        switch_channel_test_flag(channel, CF_OUTBOUND) && 
-                       switch_channel_test_flag(channel, CF_NOMEDIA)) {
+                       switch_channel_test_flag(channel, CF_NOMEDIA))) {
                        switch_ivr_nomedia(val, SMF_FORCE);
+                       switch_set_flag_locked(tech_pvt, TFLAG_CHANGE_MEDIA);
                }
                
                switch_core_session_rwunlock(other_session);
@@ -2481,7 +2485,7 @@ static void sip_i_state(int status,
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Remote SDP:\n%s\n", r_sdp);                    
                        tech_pvt->remote_sdp_str = switch_core_session_strdup(session, (char *)r_sdp);
                        switch_channel_set_variable(channel, SWITCH_R_SDP_VARIABLE, (char *) r_sdp);
-                       pass_sdp(channel, (char *) r_sdp);
+                       pass_sdp(tech_pvt, (char *) r_sdp);
 
                }
        }
@@ -2639,7 +2643,6 @@ static void sip_i_state(int status,
                if (tech_pvt && r_sdp) {
                        if (r_sdp) {
                                if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "What should i do?\n%s\n", r_sdp);
                                        return;
                                } else {
                                        sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
index bc0a534f997cf5114a4629271c5e7af09bd327d7..e8968fba4bb11d9e39797f75c698d9569528757a 100644 (file)
@@ -288,7 +288,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
                        switch_ivr_parse_event(session, event);
                        switch_event_destroy(&event);
                }
-
+               
                if (switch_channel_has_dtmf(channel)) {
                        char dtmf[128];
                        switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
@@ -1949,11 +1949,10 @@ static switch_status_t uuid_bridge_on_transmit(switch_core_session_t *session)
 
 
        if (!switch_channel_test_flag(channel, CF_ORIGINATOR)) {
-               switch_channel_set_flag(channel, CF_TAGGED);
                return SWITCH_STATUS_FALSE;
        }
 
-       if ((other_session = switch_channel_get_private(channel, "_uuid_bridge_"))) {
+       if ((other_session = switch_channel_get_private(channel, SWITCH_UUID_BRIDGE))) {
                switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
                switch_channel_state_t state = switch_channel_get_state(other_channel);
                switch_channel_state_t mystate = switch_channel_get_state(channel);
@@ -1963,7 +1962,7 @@ static switch_status_t uuid_bridge_on_transmit(switch_core_session_t *session)
 
 
                switch_channel_clear_flag(channel, CF_TRANSFER);
-               switch_channel_set_private(channel, "_uuid_bridge_", NULL);
+               switch_channel_set_private(channel, SWITCH_UUID_BRIDGE, NULL);
 
                while (mystate <= CS_HANGUP && state <= CS_HANGUP && !switch_channel_test_flag(other_channel, CF_TAGGED)) {
                        switch_yield(1000);
@@ -2682,14 +2681,15 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_broadcast(char *uuid, char *path, swi
 {
     switch_channel_t *channel;
        int nomedia;
-       switch_core_session_t *session;
+       switch_core_session_t *session, *master;
        switch_event_t *event;
-       switch_core_session_t *other_session;
+       switch_core_session_t *other_session = NULL;
        char *other_uuid = NULL;
 
        if ((session = switch_core_session_locate(uuid))) {
                char *app;
-               
+               master = session;
+
                channel = switch_core_session_get_channel(session);
                assert(channel != NULL);
 
@@ -2704,7 +2704,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_broadcast(char *uuid, char *path, swi
                        app = "playback";
                }
                
-               if ((flags & SMF_ECHO_BRIDGED) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE))
+               if ((flags & SMF_ECHO_BLEG) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE))
                        && (other_session = switch_core_session_locate(other_uuid))) {
                        if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
                                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
@@ -2713,21 +2713,25 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_broadcast(char *uuid, char *path, swi
                                switch_core_session_queue_private_event(other_session, &event);
                        }
                        switch_core_session_rwunlock(other_session);
+                       master = other_session;
                        other_session = NULL;
                }
-
-               if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
-                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
-                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-name", app);
-                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-arg", "%s", path);
-                       switch_core_session_queue_private_event(session, &event);
+               
+               if ((flags & SMF_ECHO_ALEG)) {
+                       if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
+                               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
+                               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-name", app);
+                               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-arg", "%s", path);
+                               switch_core_session_queue_private_event(session, &event);
+                       }
+                       master = session;
                }
 
                if (nomedia) {
                        if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
                                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "nomedia");
                                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "nomedia-uuid", "%s", uuid);
-                               switch_core_session_queue_private_event(session, &event);
+                               switch_core_session_queue_private_event(master, &event);
                        }
                }
                
@@ -2744,19 +2748,24 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(char *uuid, switch_media_flag_t
     switch_core_session_t *session, *other_session;
        switch_core_session_message_t msg = {0};
        switch_status_t status = SWITCH_STATUS_GENERR;
-       
+       uint8_t swap = 0;
+
        msg.message_id = SWITCH_MESSAGE_INDICATE_MEDIA;
        msg.from = __FILE__;
 
        if ((session = switch_core_session_locate(uuid))) {
                channel = switch_core_session_get_channel(session);
                assert(channel != NULL);
+               if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_ORIGINATOR)) {
+                       swap = 1;
+               }
                
                if (switch_channel_test_flag(channel, CF_NOMEDIA)) {
                        status = SWITCH_STATUS_SUCCESS;
                        switch_channel_clear_flag(channel, CF_NOMEDIA);
                        switch_core_session_receive_message(session, &msg);
-                       if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) 
+
+                       if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE)) 
                                && (other_session = switch_core_session_locate(other_uuid))) {
                                other_channel = switch_core_session_get_channel(other_session);
                                assert(other_channel != NULL);
@@ -2772,7 +2781,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(char *uuid, switch_media_flag_t
                switch_core_session_rwunlock(session);
 
                if (other_channel) {
-                       switch_ivr_uuid_bridge(uuid, other_uuid);
+                       if (swap) {
+                               switch_ivr_uuid_bridge(other_uuid, uuid);
+                       } else {
+                               switch_ivr_uuid_bridge(uuid, other_uuid);
+                       }
                }
        }
 
@@ -2787,6 +2800,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(char *uuid, switch_media_flag
     switch_core_session_t *session, *other_session = NULL;
        switch_core_session_message_t msg = {0};
        switch_status_t status = SWITCH_STATUS_GENERR;
+       uint8_t swap = 0;
 
        msg.message_id = SWITCH_MESSAGE_INDICATE_NOMEDIA;
        msg.from = __FILE__;
@@ -2796,6 +2810,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(char *uuid, switch_media_flag
                channel = switch_core_session_get_channel(session);
                assert(channel != NULL);
 
+               if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_ORIGINATOR)) {
+                       swap = 1;
+               }
+
                if ((flags & SMF_FORCE) || !switch_channel_test_flag(channel, CF_NOMEDIA)) {
                        switch_channel_set_flag(channel, CF_NOMEDIA);
                        switch_core_session_receive_message(session, &msg);
@@ -2809,7 +2827,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(char *uuid, switch_media_flag
                        }
                        if (other_channel) {
                                switch_channel_clear_state_handler(channel, NULL);
-                               switch_ivr_signal_bridge(session, other_session);
+                               if (swap) {
+                                       switch_ivr_signal_bridge(other_session, session);
+                               } else {
+                                       switch_ivr_signal_bridge(session, other_session);
+                               }
                                switch_core_session_rwunlock(other_session);
                        }
                }
@@ -2826,7 +2848,7 @@ static switch_status_t signal_bridge_on_hibernate(switch_core_session_t *session
        channel = switch_core_session_get_channel(session);
        assert(channel != NULL);
        switch_channel_clear_flag(channel, CF_TRANSFER);
-       
+
        switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE));
 
        return SWITCH_STATUS_SUCCESS;
@@ -2886,11 +2908,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_signal_bridge(switch_core_session_t *
        caller_channel = switch_core_session_get_channel(session);
        assert(caller_channel != NULL);
 
-       switch_channel_set_flag(caller_channel, CF_ORIGINATOR);
-
        peer_channel = switch_core_session_get_channel(peer_session);
        assert(peer_channel != NULL);
 
+       switch_channel_set_flag(caller_channel, CF_ORIGINATOR);
+
        switch_channel_clear_state_handler(caller_channel, NULL);
        switch_channel_clear_state_handler(peer_channel, NULL);
 
@@ -3095,7 +3117,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(char *originator_uuid, ch
                        switch_channel_set_flag(originator_channel, CF_ORIGINATOR);
                        switch_channel_add_state_handler(originator_channel, &uuid_bridge_state_handlers);
                        switch_channel_add_state_handler(originatee_channel, &uuid_bridge_state_handlers);
-                       switch_channel_set_private(originator_channel, "_uuid_bridge_", originatee_session);
+                       switch_channel_set_flag(originatee_channel, CF_TAGGED);
+                       switch_channel_set_private(originator_channel, SWITCH_UUID_BRIDGE, originatee_session);
 
                        /* switch_channel_set_state_flag sets flags you want to be set when the next state change happens */
                        switch_channel_set_state_flag(originator_channel, CF_TRANSFER);
@@ -3108,8 +3131,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(char *originator_uuid, ch
                        /* change the states and let the chips fall where they may */
                        switch_channel_set_state(originator_channel, CS_TRANSMIT);
                        switch_channel_set_state(originatee_channel, CS_TRANSMIT);
-                       
+
                        status = SWITCH_STATUS_SUCCESS;
+                       
+                       while(switch_channel_get_state(originatee_channel) < CS_HANGUP && switch_channel_test_flag(originatee_channel, CF_TAGGED)) {
+                               switch_yield(20000);
+                       }
                } else {
                        switch_core_session_rwunlock(originator_session);
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no channel for originatee uuid %s\n", originatee_uuid);