From 062c5ba2308edd1bfd04bd8bc73d4ec78d3a1a5b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 22 Feb 2008 15:02:16 +0000 Subject: [PATCH] update git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7723 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/mod_sofia.c | 26 +++++++++++++------------ src/mod/endpoints/mod_sofia/sofia.c | 17 ++++++++-------- src/mod/endpoints/mod_sofia/sofia_reg.c | 2 +- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index b0fb1d38b4..58eecf31b4 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -278,26 +278,25 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) switch_mutex_lock(tech_pvt->profile->flag_mutex); if (tech_pvt->nh && !switch_test_flag(tech_pvt, TFLAG_BYE)) { + char reason[128] = ""; + if (cause > 1 && cause < 128) { + switch_snprintf(reason, sizeof(reason), "Q.850;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause)); + } else if (cause == SWITCH_CAUSE_PICKED_OFF) { + switch_snprintf(reason, sizeof(reason), "SIP;cause=200;text=\"Call completed elsewhere\""); + } else { + switch_snprintf(reason, sizeof(reason), "FreeSWITCH;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause)); + } + if (switch_test_flag(tech_pvt, TFLAG_ANS)) { - char reason[128] = ""; - if (cause > 1 && cause < 128) { - switch_snprintf(reason, sizeof(reason), "Q.850;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause)); - } else { - switch_snprintf(reason, sizeof(reason), "FreeSWITCH;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause)); - } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending BYE to %s\n", switch_channel_get_name(channel)); nua_bye(tech_pvt->nh, SIPTAG_REASON_STR(reason), TAG_END()); } else { if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) { - switch_call_cause_t causecode = switch_channel_get_cause(channel); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending CANCEL to %s\n", switch_channel_get_name(channel)); - nua_cancel(tech_pvt->nh, TAG_IF(causecode == SWITCH_CAUSE_PICKED_OFF, - SIPTAG_REASON_STR("SIP;cause=200;text=\"Call completed elsewhere\"")), TAG_END()); + nua_cancel(tech_pvt->nh, SIPTAG_REASON_STR(reason), TAG_END()); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Responding to INVITE with: %d\n", sip_cause); - nua_respond(tech_pvt->nh, sip_cause, sip_status_phrase(sip_cause), TAG_END()); + nua_respond(tech_pvt->nh, sip_cause, sip_status_phrase(sip_cause), SIPTAG_REASON_STR(reason), TAG_END()); } } switch_set_flag(tech_pvt, TFLAG_BYE); @@ -882,6 +881,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi if (msg->string_arg) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-directing to %s\n", msg->string_arg); nua_respond(tech_pvt->nh, SIP_302_MOVED_TEMPORARILY, SIPTAG_CONTACT_STR(msg->string_arg), TAG_END()); + switch_set_flag_locked(tech_pvt, TFLAG_BYE); } break; @@ -958,6 +958,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi nua_respond(tech_pvt->nh, code, reason, TAG_IF(to_uri, SIPTAG_CONTACT_STR(to_uri)), SIPTAG_SUPPORTED_STR(NULL), SIPTAG_ACCEPT_STR(NULL), TAG_IF(!switch_strlen_zero(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)), TAG_END()); + switch_set_flag_locked(tech_pvt, TFLAG_BYE); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Responding with %d %s\n", code, reason); @@ -974,6 +975,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi } else { nua_respond(tech_pvt->nh, code, reason, SIPTAG_CONTACT_STR(tech_pvt->reply_contact), TAG_END()); } + switch_set_flag_locked(tech_pvt, TFLAG_BYE); } } diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 591dd7224c..eda8a99528 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1642,7 +1642,6 @@ 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 { @@ -1816,7 +1815,6 @@ 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); } } @@ -2362,12 +2360,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ return; } - if (!(sip->sip_contact && sip->sip_contact->m_url)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO CONTACT!\n"); - nua_respond(nh, 400, "Missing Contact Header", TAG_END()); - return; - } - + get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr); if ((profile->pflags & PFLAG_AUTH_CALLS) || sip->sip_proxy_authorization || sip->sip_authorization) { @@ -2383,6 +2376,14 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ } is_auth++; } + + + if (!(sip->sip_contact && sip->sip_contact->m_url)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO CONTACT!\n"); + nua_respond(nh, 400, "Missing Contact Header", TAG_END()); + return; + } + if (!sofia_endpoint_interface || !(session = switch_core_session_request(sofia_endpoint_interface, NULL))) { nua_respond(nh, SIP_503_SERVICE_UNAVAILABLE, TAG_END()); diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 40495b9af3..d114e55ce4 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -650,7 +650,7 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_ { char key[128] = ""; switch_event_t *v_event = NULL; - + if (!sip || !sip->sip_request || !sip->sip_request->rq_method_name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received an invalid packet!\n"); nua_respond(nh, SIP_500_INTERNAL_SERVER_ERROR, TAG_END());