diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 6820c6ded9..09d64e787d 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -136,7 +136,7 @@ static switch_status_t sofia_on_execute(switch_core_session_t *session) // map QSIG cause codes to SIP from RFC4497 section 8.4.1 static int hangup_cause_to_sip(switch_call_cause_t cause) -{ +{ switch (cause) { case SWITCH_CAUSE_NO_ROUTE_TRANSIT_NET: case SWITCH_CAUSE_NO_ROUTE_DESTINATION: @@ -175,12 +175,11 @@ static int hangup_cause_to_sip(switch_call_cause_t cause) case SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL: return 503; case SWITCH_CAUSE_BEARERCAPABILITY_NOTIMPL: + case SWITCH_CAUSE_INCOMPATIBLE_DESTINATION: return 488; case SWITCH_CAUSE_FACILITY_NOT_IMPLEMENTED: case SWITCH_CAUSE_SERVICE_NOT_IMPLEMENTED: return 501; - case SWITCH_CAUSE_INCOMPATIBLE_DESTINATION: - return 503; case SWITCH_CAUSE_RECOVERY_ON_TIMER_EXPIRE: return 504; case SWITCH_CAUSE_ORIGINATOR_CANCEL: @@ -852,7 +851,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session if (!(tech_pvt = (struct private_object *) switch_core_session_alloc(nsession, sizeof(*tech_pvt)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error Creating Session\n"); - sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__); + switch_core_session_destroy(&nsession); goto done; } switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(nsession)); @@ -867,7 +866,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session if (!(gw = strchr(profile_name, '/'))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n"); - sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__); + switch_core_session_destroy(&nsession); cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT; goto done; } @@ -876,7 +875,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session if (!(dest = strchr(gw, '/'))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n"); - sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__); + switch_core_session_destroy(&nsession); cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT; goto done; } @@ -885,7 +884,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session if (!(gateway_ptr = sofia_reg_find_gateway(gw))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Gateway\n"); - sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__); + switch_core_session_destroy(&nsession); cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT; goto done; } @@ -901,7 +900,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session } else { if (!(dest = strchr(profile_name, '/'))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n"); - sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__); + switch_core_session_destroy(&nsession); cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT; goto done; } @@ -909,7 +908,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session if (!(profile = sofia_glue_find_profile(profile_name))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n"); - sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__); + switch_core_session_destroy(&nsession); cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; goto done; } @@ -931,7 +930,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate registered user %s@%s\n", dest, host); cause = SWITCH_CAUSE_NO_ROUTE_DESTINATION; - sofia_glue_terminate_session(&nsession, cause, __FILE__, __LINE__); + switch_core_session_destroy(&nsession); goto done; } } else if (!strchr(dest, '@')) { @@ -943,7 +942,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate registered user %s@%s\n", dest, profile_name); cause = SWITCH_CAUSE_NO_ROUTE_DESTINATION; - sofia_glue_terminate_session(&nsession, cause, __FILE__, __LINE__); + switch_core_session_destroy(&nsession); goto done; } } else { diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index aaf5a4d934..0c129d7144 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -343,8 +343,6 @@ void sofia_glue_tech_prepare_codecs(private_object_t *tech_pvt); void sofia_glue_attach_private(switch_core_session_t *session, sofia_profile_t *profile, private_object_t *tech_pvt, const char *channame); -void sofia_glue_terminate_session(switch_core_session_t **session, switch_call_cause_t cause, const char *file, int line); - switch_status_t sofia_glue_tech_choose_port(private_object_t *tech_pvt); switch_status_t sofia_glue_do_invite(switch_core_session_t *session); diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index ee44092a22..9e3dfe97d2 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -180,18 +180,8 @@ void sofia_event_callback(nua_event_t event, done: if (session) { - if (tech_pvt->hangup_status) { - if (!switch_core_session_running(session)) { - switch_core_session_rwunlock(session); - switch_core_session_destroy(&session); - } else { - switch_channel_hangup(channel, sofia_glue_sip_cause_to_freeswitch(tech_pvt->hangup_status)); - switch_core_session_rwunlock(session); - } - tech_pvt->hangup_status = 0; - } else { - switch_core_session_rwunlock(session); - } + switch_core_session_rwunlock(session); + } } @@ -919,7 +909,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, if (sofia_glue_tech_media(tech_pvt, (char *) r_sdp) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + switch_channel_hangup(channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION); } } goto done; @@ -941,9 +931,9 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, if (r_sdp) { if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) { switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "RECEIVED_NOMEDIA"); - switch_channel_set_state(channel, CS_INIT); switch_set_flag_locked(tech_pvt, TFLAG_READY); - switch_core_session_thread_launch(session); + switch_channel_set_state(channel, CS_INIT); + //switch_core_session_thread_launch(session); goto done; } else { sdp_parser_t *parser; @@ -963,10 +953,9 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, nua_handle_t *bnh; sip_replaces_t *replaces; switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "RECEIVED"); - switch_channel_set_state(channel, CS_INIT); switch_set_flag_locked(tech_pvt, TFLAG_READY); - - switch_core_session_thread_launch(session); + switch_channel_set_state(channel, CS_INIT); + //switch_core_session_thread_launch(session); if (replaces_str && (replaces = sip_replaces_make(tech_pvt->sofia_private->home, replaces_str)) && (bnh = nua_handle_by_replaces(nua, replaces))) { @@ -1000,6 +989,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "NO CODECS"); nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); + switch_channel_hangup(channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION); } } else { if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) { @@ -1131,6 +1121,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "NO CODECS"); nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); + switch_channel_hangup(channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION); } } @@ -1148,7 +1139,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, } else { snprintf(st, sizeof(st), "%d", status); switch_channel_set_variable(channel, "sip_term_status", st); - tech_pvt->hangup_status = status; + switch_channel_hangup(channel, sofia_glue_sip_cause_to_freeswitch(status)); } } @@ -1600,7 +1591,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ if (!(tech_pvt = (private_object_t *) switch_core_session_alloc(session, sizeof(private_object_t)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); nua_respond(nh, SIP_503_SERVICE_UNAVAILABLE, TAG_END()); - sofia_glue_terminate_session(&session, SWITCH_CAUSE_SWITCH_CONGESTION, __FILE__, __LINE__); + switch_core_session_destroy(&session); return; } switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); @@ -1757,6 +1748,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ switch_copy_string(tech_pvt->sofia_private->uuid, switch_core_session_get_uuid(session), sizeof(tech_pvt->sofia_private->uuid)); nua_handle_bind(nh, tech_pvt->sofia_private); tech_pvt->nh = nh; + switch_core_session_thread_launch(session); } void sofia_handle_sip_i_options(int status, diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 6ea6768a8b..f8e158b6c2 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -236,30 +236,6 @@ void sofia_glue_attach_private(switch_core_session_t *session, sofia_profile_t * } -void sofia_glue_terminate_session(switch_core_session_t **session, switch_call_cause_t cause, const char *file, int line) -{ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Term called from %s line: %d\n", file, line); - if (*session) { - switch_channel_t *channel = switch_core_session_get_channel(*session); - struct private_object *tech_pvt = NULL; - unsigned running = switch_core_session_running(*session); - tech_pvt = switch_core_session_get_private(*session); - - if (running) { - switch_channel_hangup(channel, cause); - } else { - if (tech_pvt) { - sofia_on_hangup(*session); - } - if (session && *session) { - switch_core_session_destroy(session); - } - } - } -} - - - switch_status_t sofia_glue_ext_address_lookup(char **ip, switch_port_t *port, char *sourceip, switch_memory_pool_t *pool) { char *error; @@ -759,7 +735,7 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt) } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP REPORTS ERROR: [%s]\n", err); - sofia_glue_terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__); + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_clear_flag_locked(tech_pvt, TFLAG_IO); return SWITCH_STATUS_FALSE; } @@ -1037,7 +1013,7 @@ switch_call_cause_t sofia_glue_sip_cause_to_freeswitch(int status) return SWITCH_CAUSE_INVALID_NUMBER_FORMAT; case 488: case 606: - return SWITCH_CAUSE_BEARERCAPABILITY_NOTIMPL; + return SWITCH_CAUSE_INCOMPATIBLE_DESTINATION; case 502: return SWITCH_CAUSE_NETWORK_OUT_OF_ORDER; case 405: