diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 6525d06ce0..e466d261d3 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1114,7 +1114,7 @@ static switch_status_t sofia_receive_event(switch_core_session_t *session, switc msg_nh = nua_handle(tech_pvt->profile->nua, NULL, SIPTAG_FROM_STR(tech_pvt->chat_from), NUTAG_URL(tech_pvt->chat_to), SIPTAG_TO_STR(tech_pvt->chat_to), SIPTAG_CONTACT_STR(tech_pvt->profile->url), TAG_END()); - + nua_handle_bind(msg_nh, &mod_sofia_globals.destroy_private); nua_message(msg_nh, SIPTAG_CONTENT_TYPE_STR("text/html"), SIPTAG_PAYLOAD_STR(body), TAG_END()); } diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index ffe97ff8aa..785a0ac30e 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -71,7 +71,7 @@ void sofia_handle_sip_r_notify(switch_core_session_t *session, int status, { if (status >= 300 && sip && sip->sip_call_id) { char *sql; - + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "delete subscriptions for failed notify\n"); sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", sip->sip_call_id->i_id); switch_assert(sql != NULL); sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE); @@ -159,21 +159,6 @@ void sofia_handle_sip_i_bye(switch_core_session_t *session, int status, void sofia_handle_sip_r_message(int status, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip) { - if (status == 503) { - const char *user = NULL, *host = NULL; - char *sql; - - if (sip->sip_to && sip->sip_to->a_url) { - user = sip->sip_to->a_url->url_user; - host = sip->sip_to->a_url->url_host; - - sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", user, host); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Deleting registration for %s@%s\n", user, host); - sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE); - } - } - - nua_handle_destroy(nh); } void sofia_event_callback(nua_event_t event, @@ -354,7 +339,7 @@ void sofia_event_callback(nua_event_t event, done: - if (sofia_private && sofia_private->destroy_nh) { + if ((sofia_private && sofia_private->destroy_nh) || !nua_handle_magic(nh)) { //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy handle requested.\n"); nua_handle_destroy(nh); } @@ -1554,7 +1539,6 @@ static void sofia_handle_sip_r_options(switch_core_session_t *session, int statu ); sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE); } - nua_handle_destroy(nh); } @@ -3139,7 +3123,6 @@ void sofia_handle_sip_i_options(int status, nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END()); - nua_handle_destroy(nh); } static void sofia_info_send_sipfrag(switch_core_session_t *aleg, switch_core_session_t *bleg) diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index de87e4142d..07358c48af 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -107,7 +107,7 @@ switch_status_t sofia_presence_chat_send(char *proto, char *from, char *to, char SIPTAG_CONTACT_STR(profile->url), TAG_END()); switch_safe_free(contact); - + nua_handle_bind(msg_nh, &mod_sofia_globals.destroy_private); nua_message(msg_nh, SIPTAG_CONTENT_TYPE_STR("text/html"), SIPTAG_PAYLOAD_STR(body), TAG_END()); switch_safe_free(ffrom); diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 6c15656e87..890967b30d 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -87,7 +87,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now) pvt = malloc(sizeof(*pvt)); switch_assert(pvt); memset(pvt, 0, sizeof(*pvt)); - + pvt->destroy_nh = 1; switch_copy_string(pvt->gateway_name, gateway_ptr->name, sizeof(pvt->gateway_name)); nua_handle_bind(nh, pvt); @@ -196,7 +196,7 @@ int sofia_reg_nat_callback(void *pArg, int argc, char **argv, char **columnNames contact = sofia_glue_get_url_from_contact(argv[3], 1); nh = nua_handle(profile->nua, NULL, SIPTAG_FROM_STR(profile->url), SIPTAG_TO_STR(to), NUTAG_URL(contact), SIPTAG_CONTACT_STR(profile->url), TAG_END()); - + nua_handle_bind(nh, &mod_sofia_globals.destroy_private); nua_options(nh, TAG_END()); switch_safe_free(contact);