diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h index eb0290bb4a..4824a0c8a3 100644 --- a/src/include/switch_channel.h +++ b/src/include/switch_channel.h @@ -78,7 +78,8 @@ SWITCH_DECLARE(int) switch_channel_test_ready(switch_channel_t *channel, switch_ #define switch_channel_ready(_channel) switch_channel_test_ready(_channel, SWITCH_FALSE) #define switch_channel_media_ready(_channel) switch_channel_test_ready(_channel, SWITCH_TRUE) - +#define switch_channel_up(_channel) (switch_channel_get_state(_channel) < CS_HANGUP) +#define switch_channel_down(_channel) (switch_channel_get_state(_channel) >= CS_HANGUP) SWITCH_DECLARE(void) switch_channel_wait_for_state(switch_channel_t *channel, switch_channel_t *other_channel, switch_channel_state_t want_state); SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_flag(switch_channel_t *channel, diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 18b05af868..1a1df50fcf 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -1532,7 +1532,7 @@ SWITCH_STANDARD_APP(att_xfer_function) switch_channel_clear_flag(peer_channel, CF_INNER_BRIDGE); switch_channel_clear_flag(channel, CF_INNER_BRIDGE); - if (!switch_channel_get_state(peer_channel) >= CS_HANGUP) { + if (!switch_channel_down(peer_channel)) { switch_core_session_rwunlock(peer_session); goto end; } diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c index f8435cf4ab..c9a5eed172 100644 --- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c +++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c @@ -1091,7 +1091,7 @@ static switch_status_t negotiate_media(switch_core_session_t *session) now = switch_micro_time_now(); elapsed = (unsigned int) ((now - started) / 1000); - if (switch_channel_get_state(channel) >= CS_HANGUP || switch_test_flag(tech_pvt, TFLAG_BYE)) { + if (switch_channel_down(channel) || switch_test_flag(tech_pvt, TFLAG_BYE)) { goto out; } @@ -1119,7 +1119,7 @@ static switch_status_t negotiate_media(switch_core_session_t *session) switch_cond_next(); } - if (switch_channel_get_state(channel) >= CS_HANGUP || switch_test_flag(tech_pvt, TFLAG_BYE)) { + if (switch_channel_down(channel) || switch_test_flag(tech_pvt, TFLAG_BYE)) { goto out; } @@ -2542,7 +2542,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "using Existing session for %s\n", ldl_session_get_id(dlsession)); - if (switch_channel_get_state(channel) >= CS_HANGUP) { + if (switch_channel_down(channel)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call %s is already over\n", switch_channel_get_name(channel)); status = LDL_STATUS_FALSE; goto done; diff --git a/src/mod/endpoints/mod_iax/mod_iax.c b/src/mod/endpoints/mod_iax/mod_iax.c index 4fb019ad3a..a7e4b8d0b1 100644 --- a/src/mod/endpoints/mod_iax/mod_iax.c +++ b/src/mod/endpoints/mod_iax/mod_iax.c @@ -1081,7 +1081,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime) break; case IAX_EVENT_VOICE: if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen) != 0) { - if (channel && switch_channel_get_state(channel) <= CS_HANGUP) { + if (channel && switch_channel_up(channel)) { int bytes = 0, frames = 1; if (!switch_test_flag(tech_pvt, TFLAG_CODEC) || !tech_pvt->read_codec.implementation) { diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index df048c199a..6751078f00 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -959,7 +959,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi private_object_t *tech_pvt = switch_core_session_get_private(session); switch_status_t status = SWITCH_STATUS_SUCCESS; - if (switch_channel_get_state(channel) >= CS_HANGUP || !tech_pvt) { + if (switch_channel_down(channel) || !tech_pvt) { status = SWITCH_STATUS_FALSE; goto end; } @@ -997,7 +997,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi /* ones that do need to lock sofia mutex */ switch_mutex_lock(tech_pvt->sofia_mutex); - if (switch_channel_get_state(channel) >= CS_HANGUP || !tech_pvt) { + if (switch_channel_down(channel) || !tech_pvt) { status = SWITCH_STATUS_FALSE; goto end_lock; } diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 076f5fe786..f42f1dc8da 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -364,7 +364,7 @@ void sofia_event_callback(nua_event_t event, } if (session) { - if (channel && switch_channel_get_state(channel) >= CS_HANGUP) { + if (channel && switch_channel_down(channel)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is already hungup.\n"); goto done; } @@ -3325,7 +3325,7 @@ void *SWITCH_THREAD_FUNC nightmare_xfer_thread_run(switch_thread_t *thread, void status = switch_ivr_originate(a_session, &tsession, &cause, nhelper->exten, timeout, NULL, NULL, NULL, NULL, NULL, SOF_NONE); - if ((switch_channel_get_state(channel_a) < CS_HANGUP)) { + if ((switch_channel_up(channel_a))) { if (status != SWITCH_STATUS_SUCCESS || cause != SWITCH_CAUSE_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel! [%s]\n", nhelper->exten); diff --git a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c index fb8ad359ce..5df830820c 100644 --- a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c +++ b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c @@ -1234,7 +1234,7 @@ SWITCH_STANDARD_APP(erlang_outbound_function) switch_ivr_park(session, NULL); /* keep app thread running for lifetime of session */ - if (switch_channel_get_state(switch_core_session_get_channel(session)) >= CS_HANGUP) { + if (switch_channel_down(switch_core_session_get_channel(session))) { while (switch_test_flag(session_element, LFLAG_SESSION_ALIVE)) { switch_yield(100000); } diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c index 77f65776c6..aff4288c1c 100644 --- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c +++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c @@ -430,7 +430,7 @@ SWITCH_STANDARD_APP(socket_function) listener_run(NULL, (void *) listener); } - if (switch_channel_get_state(channel) >= CS_HANGUP) { + if (switch_channel_down(channel)) { while (switch_test_flag(listener, LFLAG_SESSION)) { switch_yield(100000); } @@ -1192,7 +1192,7 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event, } } - if (channel && switch_channel_get_state(channel) >= CS_HANGUP && !switch_test_flag(listener, LFLAG_HANDLE_DISCO)) { + if (channel && switch_channel_down(channel) && !switch_test_flag(listener, LFLAG_HANDLE_DISCO)) { switch_set_flag_locked(listener, LFLAG_HANDLE_DISCO); if (switch_test_flag(listener, LFLAG_LINGER)) { char message[128] = ""; diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c index d2e9cebc11..36d2c207df 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c @@ -2152,7 +2152,7 @@ static JSBool session_wait_for_media(JSContext * cx, JSObject * obj, uintN argc, saveDepth = JS_SuspendRequest(cx); for (;;) { if (((elapsed = (unsigned int) ((switch_micro_time_now() - started) / 1000)) > (switch_time_t) timeout) - || switch_channel_get_state(channel) >= CS_HANGUP) { + || switch_channel_down(channel)) { *rval = BOOLEAN_TO_JSVAL(JS_FALSE); break; } @@ -2200,7 +2200,7 @@ static JSBool session_wait_for_answer(JSContext * cx, JSObject * obj, uintN argc saveDepth = JS_SuspendRequest(cx); for (;;) { if (((elapsed = (unsigned int) ((switch_micro_time_now() - started) / 1000)) > (switch_time_t) timeout) - || switch_channel_get_state(channel) >= CS_HANGUP) { + || switch_channel_down(channel)) { *rval = BOOLEAN_TO_JSVAL(JS_FALSE); break; } diff --git a/src/switch_channel.c b/src/switch_channel.c index 4ff1ebb082..1d278fe087 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1590,7 +1590,6 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_NOTICE, "Hangup %s [%s] [%s]\n", channel->name, state_names[last_state], switch_channel_cause2str(channel->hangup_cause)); - switch_core_media_bug_remove_all(channel->session); switch_channel_set_variable(channel, "hangup_cause", switch_channel_cause2str(channel->hangup_cause)); switch_channel_presence(channel, "unavailable", switch_channel_cause2str(channel->hangup_cause), NULL); diff --git a/src/switch_core_io.c b/src/switch_core_io.c index eaf8512641..50e4627fa5 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -41,7 +41,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(switch_cor switch_io_event_hook_video_write_frame_t *ptr; switch_status_t status = SWITCH_STATUS_FALSE; - if (switch_channel_get_state(session->channel) >= CS_HANGUP) { + if (switch_channel_down(session->channel)) { return SWITCH_STATUS_FALSE; } @@ -65,7 +65,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core switch_assert(session != NULL); - if (switch_channel_get_state(session->channel) >= CS_HANGUP) { + if (switch_channel_down(session->channel)) { return SWITCH_STATUS_FALSE; } @@ -123,7 +123,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi top: - if (switch_channel_get_state(session->channel) >= CS_HANGUP) { + if (switch_channel_down(session->channel)) { *frame = NULL; status = SWITCH_STATUS_FALSE; goto even_more_done; } @@ -1066,7 +1066,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(switch_core_sessio switch_status_t status; switch_dtmf_t new_dtmf; - if (switch_channel_get_state(session->channel) >= CS_HANGUP) { + if (switch_channel_down(session->channel)) { return SWITCH_STATUS_FALSE; } @@ -1096,7 +1096,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio switch_status_t status = SWITCH_STATUS_FALSE; switch_dtmf_t new_dtmf; - if (switch_channel_get_state(session->channel) >= CS_HANGUP) { + if (switch_channel_down(session->channel)) { return SWITCH_STATUS_FALSE; } @@ -1144,7 +1144,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core switch_assert(session != NULL); - if (switch_channel_get_state(session->channel) >= CS_HANGUP) { + if (switch_channel_down(session->channel)) { return SWITCH_STATUS_FALSE; } diff --git a/src/switch_core_rwlock.c b/src/switch_core_rwlock.c index 161f9d3c74..aba781614b 100644 --- a/src/switch_core_rwlock.c +++ b/src/switch_core_rwlock.c @@ -45,7 +45,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock(switch_core_sessio switch_status_t status = SWITCH_STATUS_FALSE; if (session->rwlock) { - if (switch_test_flag(session, SSF_DESTROYED) || switch_channel_get_state(session->channel) >= CS_HANGUP) { + if (switch_test_flag(session, SSF_DESTROYED) || switch_channel_down(session->channel)) { status = SWITCH_STATUS_FALSE; #ifdef SWITCH_DEBUG_RWLOCKS switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "%s Read lock FAIL\n", diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 11a0d31ae7..b95e7740b3 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -91,7 +91,7 @@ SWITCH_DECLARE(void) switch_core_session_hupall_matching_var(const char *var_nam const char *this_val; session = (switch_core_session_t *) val; if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) { - if (switch_channel_get_state(session->channel) < CS_HANGUP && + if (switch_channel_up(session->channel) && (this_val = switch_channel_get_variable(session->channel, var_name)) && (!strcmp(this_val, var_val))) { switch_channel_hangup(session->channel, cause); } @@ -163,7 +163,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_message_send(const char *uui if ((session = switch_core_hash_find(session_manager.session_table, uuid_str)) != 0) { /* Acquire a read lock on the session or forget it the channel is dead */ if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) { - if (switch_channel_get_state(session->channel) < CS_HANGUP) { + if (switch_channel_up(session->channel)) { status = switch_core_session_receive_message(session, message); } switch_core_session_rwunlock(session); @@ -183,7 +183,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_event_send(const char *uuid_ if ((session = switch_core_hash_find(session_manager.session_table, uuid_str)) != 0) { /* Acquire a read lock on the session or forget it the channel is dead */ if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) { - if (switch_channel_get_state(session->channel) < CS_HANGUP) { + if (switch_channel_up(session->channel)) { status = switch_core_session_queue_event(session, event); } switch_core_session_rwunlock(session); @@ -470,7 +470,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(swit switch_assert(session != NULL); - if (switch_channel_get_state(session->channel) >= CS_HANGUP) { + if (switch_channel_down(session->channel)) { return SWITCH_STATUS_FALSE; } @@ -626,7 +626,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_receive_event(switch_core_se /* Acquire a read lock on the session or forget it the channel is dead */ if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) { - if (switch_channel_get_state(session->channel) < CS_HANGUP) { + if (switch_channel_up(session->channel)) { if (session->endpoint_interface->io_routines->receive_event) { status = session->endpoint_interface->io_routines->receive_event(session, *event); } @@ -1247,7 +1247,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application(switch_c { switch_application_interface_t *application_interface; - if (switch_channel_get_state(session->channel) >= CS_HANGUP) { + if (switch_channel_down(session->channel)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is hungup, aborting execution of application: %s\n", app); return SWITCH_STATUS_FALSE; } diff --git a/src/switch_core_state_machine.c b/src/switch_core_state_machine.c index 5528b7a43a..f675c8313a 100644 --- a/src/switch_core_state_machine.c +++ b/src/switch_core_state_machine.c @@ -390,7 +390,6 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) break; case CS_DONE: goto done; - /* HANGUP INIT ROUTING and RESET are all short term so we signal lock during their callbacks */ case CS_HANGUP: /* Deactivate and end the thread */ { const char *var = switch_channel_get_variable(session->channel, SWITCH_PROCESS_CDR_VARIABLE); @@ -410,10 +409,10 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) do_extra_handlers = 0; } } + + switch_core_media_bug_remove_all(session); STATE_MACRO(hangup, "HANGUP"); - - switch_core_media_bug_remove_all(session); hook_var = switch_channel_get_variable(session->channel, SWITCH_API_HANGUP_HOOK_VARIABLE); if (switch_true(switch_channel_get_variable(session->channel, SWITCH_SESSION_IN_HANGUP_HOOK_VARIABLE))) { diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 69923f8367..f1a661b1d9 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -1774,13 +1774,14 @@ static void *SWITCH_THREAD_FUNC speech_thread(switch_thread_t *thread, void *obj sth->ready = 1; - while (switch_channel_ready(channel) && !switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED)) { + while (switch_channel_up(channel) && !switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED)) { char *xmlstr = NULL; switch_thread_cond_wait(sth->cond, sth->mutex); - if (switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED)) + if (switch_channel_down(channel) || switch_test_flag(sth->ah, SWITCH_ASR_FLAG_CLOSED)) { break; + } if (switch_core_asr_check_results(sth->ah, &flags) == SWITCH_STATUS_SUCCESS) { switch_event_t *event; diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c index 865e0e9446..b883788e42 100644 --- a/src/switch_ivr_bridge.c +++ b/src/switch_ivr_bridge.c @@ -206,7 +206,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj) goto end_of_bridge_loop; } - if ((b_state = switch_channel_get_state(chan_b)) >= CS_HANGUP) { + if ((b_state = switch_channel_down(chan_b))) { goto end_of_bridge_loop; } @@ -398,7 +398,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj) } - if (switch_channel_get_state(chan_b) >= CS_HANGUP) { + if (switch_channel_down(chan_b)) { if (originator && switch_channel_ready(chan_a) && !switch_channel_test_flag(chan_a, CF_ANSWERED)) { switch_channel_hangup(chan_a, switch_channel_get_cause(chan_b)); } @@ -409,7 +409,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj) msg.from = __FILE__; switch_core_session_receive_message(session_a, &msg); - if (!inner_bridge && switch_channel_get_state(chan_a) < CS_HANGUP) { + if (!inner_bridge && switch_channel_up(chan_a)) { if ((app_name = switch_channel_get_variable(chan_a, SWITCH_EXEC_AFTER_BRIDGE_APP_VARIABLE))) { switch_caller_extension_t *extension = NULL; if ((extension = switch_caller_extension_new(session_a, app_name, app_name)) == 0) { @@ -693,7 +693,7 @@ static switch_status_t signal_bridge_on_hangup(switch_core_session_t *session) switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, NULL); switch_channel_set_variable(other_channel, SWITCH_BRIDGE_VARIABLE, NULL); - if (switch_channel_get_state(other_channel) < CS_HANGUP) { + if (switch_channel_up(other_channel)) { switch_channel_hangup(other_channel, switch_channel_get_cause(channel)); } } @@ -723,7 +723,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_signal_bridge(switch_core_session_t * switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session); switch_event_t *event; - if (switch_channel_get_state(peer_channel) >= CS_HANGUP) { + if (switch_channel_down(peer_channel)) { switch_channel_hangup(caller_channel, switch_channel_get_cause(peer_channel)); return SWITCH_STATUS_FALSE; } @@ -1013,7 +1013,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu originator_channel = switch_core_session_get_channel(originator_session); originatee_channel = switch_core_session_get_channel(originatee_session); - if (switch_channel_get_state(originator_channel) >= CS_HANGUP) { + if (switch_channel_down(originator_channel)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s is hungup refusing to bridge.\n", switch_channel_get_name(originatee_channel)); switch_core_session_rwunlock(originator_session); switch_core_session_rwunlock(originatee_session); diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index 1e5d31f522..806fd6d37e 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -171,7 +171,7 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void switch_core_session_exec(collect->session, application_interface, app_data); - if (switch_channel_get_state(channel) < CS_HANGUP) { + if (switch_channel_up(channel)) { switch_channel_set_flag(channel, CF_WINNER); } goto wbreak; @@ -228,7 +228,7 @@ static int check_per_channel_timeouts(originate_global_t *oglobals, time_t elapsed = switch_epoch_time_now(NULL) - start; for (i = 0; i < max; i++) { - if (originate_status[i].peer_channel && switch_channel_get_state(originate_status[i].peer_channel) < CS_HANGUP) { + if (originate_status[i].peer_channel && switch_channel_up(originate_status[i].peer_channel)) { if (originate_status[i].per_channel_progress_timelimit_sec && elapsed > originate_status[i].per_channel_progress_timelimit_sec && !( switch_channel_test_flag(originate_status[i].peer_channel, CF_RING_READY) || @@ -1719,7 +1719,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess } pchannel = switch_core_session_get_channel(originate_status[i].peer_session); - if (switch_channel_get_state(pchannel) >= CS_HANGUP) { + if (switch_channel_down(pchannel)) { cause_str = switch_channel_cause2str(switch_channel_get_cause(pchannel)); if (switch_stristr(cause_str, fail_on_single_reject_var)) { ok = 0;