From 8dc1556b95c9e56ada0114fc758f9e23c85f520a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 10 Nov 2006 08:13:01 +0000 Subject: [PATCH] fix gremlins in code that worked before then changed it's mind git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3300 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_am_config.h.in | 2 +- src/include/switch_types.h | 7 +- .../applications/mod_commands/mod_commands.c | 12 ++- .../applications/mod_playback/mod_playback.c | 7 +- src/mod/endpoints/mod_sofia/mod_sofia.c | 17 +++-- src/switch_ivr.c | 75 +++++++++++++------ 6 files changed, 77 insertions(+), 43 deletions(-) diff --git a/src/include/switch_am_config.h.in b/src/include/switch_am_config.h.in index c2a949cebe..3e1a92ccaf 100644 --- a/src/include/switch_am_config.h.in +++ b/src/include/switch_am_config.h.in @@ -124,5 +124,5 @@ /* Define to rpl_malloc if the replacement function should be used. */ #undef malloc -/* Define to `unsigned' if does not define. */ +/* Define to `unsigned int' if does not define. */ #undef size_t diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 02fb237229..fe1b41595d 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -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 { diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 42b127baf1..2280b34a3e 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -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); diff --git a/src/mod/applications/mod_playback/mod_playback.c b/src/mod/applications/mod_playback/mod_playback.c index beae8295db..43f0891673 100644 --- a/src/mod/applications/mod_playback/mod_playback.c +++ b/src/mod/applications/mod_playback/mod_playback.c @@ -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); - } - } diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 2287b191aa..9a2de85f34 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -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); diff --git a/src/switch_ivr.c b/src/switch_ivr.c index bc0a534f99..e8968fba4b 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -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);