]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 26 Apr 2006 23:09:48 +0000 (23:09 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 26 Apr 2006 23:09:48 +0000 (23:09 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1272 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_exosip/mod_exosip.c
src/switch_channel.c
src/switch_core.c
src/switch_ivr.c

index d9aa136686c94e811543f1f76b95d0e01ee6b7f2..7c7594a391a2fb18a46cf22abff0f9b374c302b3 100644 (file)
@@ -1385,10 +1385,11 @@ static switch_status exosip_create_call(eXosip_event_t * event)
 
 }
 
-static void destroy_call_by_event(eXosip_event_t * event)
+static void destroy_call_by_event(eXosip_event_t *event)
 {
        struct private_object *tech_pvt;
        switch_channel *channel = NULL;
+       switch_call_cause_t cause;
 
        if ((tech_pvt = get_pvt_by_call_id(event->cid)) == 0) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "cannot destroy nonexistant call [%d]!\n", event->cid);
@@ -1400,7 +1401,28 @@ static void destroy_call_by_event(eXosip_event_t * event)
 
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "destroy %s\n", switch_channel_get_name(channel));
        exosip_kill_channel(tech_pvt->session, SWITCH_SIG_KILL);
-       switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+
+       switch (event->type) {
+       case EXOSIP_CALL_RELEASED:
+       case EXOSIP_CALL_CLOSED:
+               cause = SWITCH_CAUSE_NORMAL_CLEARING;
+               break;
+       case EXOSIP_CALL_NOANSWER:
+               cause = SWITCH_CAUSE_NO_ANSWER;
+               break;
+       case EXOSIP_CALL_REQUESTFAILURE:
+               cause = SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL;
+               break;
+       case EXOSIP_CALL_SERVERFAILURE:
+       case EXOSIP_CALL_GLOBALFAILURE:
+               cause = SWITCH_CAUSE_CALL_REJECTED;
+               break;
+       default:
+               cause = SWITCH_CAUSE_SWITCH_CONGESTION;
+               break;
+       }
+
+       switch_channel_hangup(channel, cause);
 
 }
 
@@ -1825,7 +1847,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
                case EXOSIP_CALL_REINVITE:
                        /* See what the reinvite is about - on hold or whatever */
                        //handle_reinvite(event);
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Got a reinvite.\n");
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got a reinvite.\n");
                        break;
                case EXOSIP_CALL_MESSAGE_NEW:
                        if (event->request != NULL && MSG_IS_REFER(event->request)) {
@@ -1836,7 +1858,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
                        /* If audio is not flowing and this has SDP - fire it up! */
                        break;
                case EXOSIP_CALL_ANSWERED:
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "The call was answered.\n");
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "The call was answered.\n");
                        handle_answer(event);
                        break;
                case EXOSIP_CALL_PROCEEDING:
@@ -1846,7 +1868,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
                        //handle_ringing(event);
                        break;
                case EXOSIP_CALL_REDIRECTED:
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Call was redirect\n");
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call was redirect\n");
                        break;
                case EXOSIP_CALL_CLOSED:
                        destroy_call_by_event(event);
@@ -1855,24 +1877,24 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
                        destroy_call_by_event(event);
                        break;
                case EXOSIP_CALL_NOANSWER:
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "The call was not answered.\n");
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "The call was not answered.\n");
                        destroy_call_by_event(event);
                        break;
                case EXOSIP_CALL_REQUESTFAILURE:
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Request failure\n");
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Request failure\n");
                        destroy_call_by_event(event);
                        break;
                case EXOSIP_CALL_SERVERFAILURE:
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Server failure\n");
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Server failure\n");
                        destroy_call_by_event(event);
                        break;
                case EXOSIP_CALL_GLOBALFAILURE:
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Global failure\n");
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Global failure\n");
                        destroy_call_by_event(event);
                        break;
                        /* Registration related stuff */
                case EXOSIP_REGISTRATION_NEW:
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Received registration attempt\n");
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Received registration attempt\n");
                        break;
                default:
                        /* Unknown event... casually absorb it for now */
index 9a622f3af68f67dc02b05781047f11f4489f689f..9978ac3401ffae66a3f44a05bdcef9ecf001cdb5 100644 (file)
@@ -297,6 +297,7 @@ SWITCH_DECLARE(switch_status) switch_channel_set_name(switch_channel *channel, c
        channel->name = NULL;
        if (name) {
                channel->name = switch_core_session_strdup(channel->session, name);
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New Channel %s\n", name);
        }
        return SWITCH_STATUS_SUCCESS;
 }
@@ -700,7 +701,7 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_hangup(switch_channel *chann
 
                channel->state = CS_HANGUP;
                channel->hangup_cause = hangup_cause;
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Hangup %s [%s] [%s]\n", channel->name,
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s [%s] [%s]\n", channel->name,
                                                  state_names[last_state], switch_channel_cause2str(channel->hangup_cause));
                if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_STATE) == SWITCH_STATUS_SUCCESS) {
                        switch_channel_event_set_data(channel, event);
index 5b2b96a28981d9877903c2ab7a39f8554e1181a9..9f21563618d5063d2b9334e21dc0f55c27ec6bfe 100644 (file)
@@ -1847,12 +1847,12 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
 
                        switch (state) {
                        case CS_NEW:            /* Just created, Waiting for first instructions */
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State NEW\n", switch_channel_get_name(session->channel));
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State NEW\n", switch_channel_get_name(session->channel));
                                break;
                        case CS_DONE:
                                continue;
                        case CS_HANGUP: /* Deactivate and end the thread */
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State HANGUP\n", switch_channel_get_name(session->channel));
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State HANGUP\n", switch_channel_get_name(session->channel));
                                if (!driver_state_handler->on_hangup ||
                                        (driver_state_handler->on_hangup &&
                                         driver_state_handler->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
@@ -1891,7 +1891,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
                                midstate = switch_channel_get_state(session->channel);
                                break;
                        case CS_INIT:           /* Basic setup tasks */
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State INIT\n", switch_channel_get_name(session->channel));
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State INIT\n", switch_channel_get_name(session->channel));
                                if (!driver_state_handler->on_init ||
                                        (driver_state_handler->on_init &&
                                         driver_state_handler->on_init(session) == SWITCH_STATUS_SUCCESS &&
@@ -1927,7 +1927,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
                                }
                                break;
                        case CS_RING:           /* Look for a dialplan and find something to do */
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State RING\n", switch_channel_get_name(session->channel));
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State RING\n", switch_channel_get_name(session->channel));
                                if (!driver_state_handler->on_ring ||
                                        (driver_state_handler->on_ring &&
                                         driver_state_handler->on_ring(session) == SWITCH_STATUS_SUCCESS &&
@@ -1963,7 +1963,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
                                }
                                break;
                        case CS_EXECUTE:        /* Execute an Operation */
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State EXECUTE\n", switch_channel_get_name(session->channel));
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State EXECUTE\n", switch_channel_get_name(session->channel));
                                if (!driver_state_handler->on_execute ||
                                        (driver_state_handler->on_execute &&
                                         driver_state_handler->on_execute(session) == SWITCH_STATUS_SUCCESS &&
@@ -1999,7 +1999,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
                                }
                                break;
                        case CS_LOOPBACK:       /* loop all data back to source */
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State LOOPBACK\n", switch_channel_get_name(session->channel));
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State LOOPBACK\n", switch_channel_get_name(session->channel));
                                if (!driver_state_handler->on_loopback ||
                                        (driver_state_handler->on_loopback &&
                                         driver_state_handler->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
@@ -2035,7 +2035,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
                                }
                                break;
                        case CS_TRANSMIT:       /* send/recieve data to/from another channel */
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "(%s) State TRANSMIT\n", switch_channel_get_name(session->channel));
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State TRANSMIT\n", switch_channel_get_name(session->channel));
                                if (!driver_state_handler->on_transmit ||
                                        (driver_state_handler->on_transmit &&
                                         driver_state_handler->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
@@ -2093,6 +2093,8 @@ SWITCH_DECLARE(void) switch_core_session_destroy(switch_core_session **session)
        switch_memory_pool *pool;
        switch_event *event;
 
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Close Channel %s\n", switch_channel_get_name((*session)->channel));
+
        if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DESTROY) == SWITCH_STATUS_SUCCESS) {
                switch_channel_event_set_data((*session)->channel, event);
                switch_event_fire(&event);
index d76786b10bb81af27dda33fe50a3ba0c4ff07088..eac7095ac082734e3cabcddd3434a54134ada745 100644 (file)
@@ -802,7 +802,7 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj)
        return NULL;
 }
 
-static switch_status audio_bridge_on_transmit(switch_core_session *session)
+static switch_status audio_bridge_on_loopback(switch_core_session *session)
 {
        switch_channel *channel = NULL;
        void *arg;
@@ -829,13 +829,21 @@ static switch_status audio_bridge_on_ring(switch_core_session *session)
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CUSTOM RING\n");
 
        /* put the channel in a passive state so we can loop audio to it */
-       if (switch_channel_test_flag(channel, CF_OUTBOUND)) {
-               //switch_channel_set_state(channel, CS_TRANSMIT);
-               return SWITCH_STATUS_FALSE;
-       }
+       switch_channel_set_state(channel, CS_TRANSMIT);
+       return SWITCH_STATUS_FALSE;
+}
 
+static switch_status audio_bridge_on_transmit(switch_core_session *session)
+{
+       switch_channel *channel = NULL;
 
-       return SWITCH_STATUS_SUCCESS;
+       channel = switch_core_session_get_channel(session);
+       assert(channel != NULL);
+
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CUSTOM TRANSMIT\n");
+
+       /* put the channel in a passive state so we can loop audio to it */
+       return SWITCH_STATUS_FALSE;
 }
 
 static const switch_state_handler_table audio_bridge_peer_state_handlers = {
@@ -843,8 +851,8 @@ static const switch_state_handler_table audio_bridge_peer_state_handlers = {
        /*.on_ring */ audio_bridge_on_ring,
        /*.on_execute */ NULL,
        /*.on_hangup */ NULL,
-       /*.on_loopback */ NULL,
-       /*.on_transmit */ audio_bridge_on_transmit
+       /*.on_loopback */ audio_bridge_on_loopback,
+       /*.on_transmit */ audio_bridge_on_transmit,
 };
 
 
@@ -953,6 +961,8 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
                switch_event *event;
                switch_core_session_message msg = {0};
 
+               switch_channel_set_state(peer_channel, CS_TRANSMIT);
+
                if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) {
                        switch_channel_event_set_data(caller_channel, event);
                        switch_event_fire(&event);
@@ -968,7 +978,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
 
                switch_channel_set_flag(peer_channel, CF_LOCK_THREAD);
                switch_channel_set_private(peer_channel, &other_audio_thread);  
-               switch_channel_set_state(peer_channel, CS_TRANSMIT);
+               switch_channel_set_state(peer_channel, CS_LOOPBACK);
                audio_bridge_thread(NULL, (void *) &this_audio_thread);
 
                if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
@@ -976,6 +986,12 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
                        switch_event_fire(&event);
                }
                switch_channel_clear_flag(peer_channel, CF_LOCK_THREAD);
+       } else {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Bridge Failed %s->%s\n", 
+                                                 switch_channel_get_name(caller_channel),
+                                                 switch_channel_get_name(peer_channel)
+                                                 );
+               return SWITCH_STATUS_FALSE;
        }
        return SWITCH_STATUS_SUCCESS;
 }