From 2932c1fa17c589f3e47178553f78195fe08cf22d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 14 Jul 2011 00:17:05 -0500 Subject: [PATCH] FS-3386 Try this revision please --- .../mod_spandsp/mod_spandsp_codecs.c | 3 +- src/mod/endpoints/mod_sofia/mod_sofia.c | 3 +- src/mod/endpoints/mod_sofia/mod_sofia.h | 7 +- src/mod/endpoints/mod_sofia/sofia.c | 109 +++++++++--------- src/mod/endpoints/mod_sofia/sofia_glue.c | 2 +- src/mod/endpoints/mod_sofia/sofia_presence.c | 16 ++- src/mod/endpoints/mod_sofia/sofia_reg.c | 19 ++- 7 files changed, 83 insertions(+), 76 deletions(-) diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_codecs.c b/src/mod/applications/mod_spandsp/mod_spandsp_codecs.c index 4e7f048ef7..c75db05449 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_codecs.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_codecs.c @@ -34,6 +34,7 @@ #include "mod_spandsp.h" +#if SWITCH_MAX_INTERVAL >= 90 /* LPC10 - START */ struct lpc10_context { @@ -123,7 +124,7 @@ static switch_status_t switch_lpc10_decode(switch_codec_t *codec, } /* LPC10 - END */ - +#endif /* GSM - START */ struct gsm_context { diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 7ebbe33f70..cea774ff99 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -553,9 +553,8 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) *tech_pvt->sofia_private->uuid = '\0'; } - sofia_glue_set_rtp_stats(tech_pvt); - + switch_mutex_unlock(tech_pvt->sofia_mutex); return SWITCH_STATUS_SUCCESS; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 8b1422ba8c..00dcd71897 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -33,7 +33,7 @@ * mod_sofia.h -- SOFIA SIP Endpoint * */ - +//#define HAVE_MEMLEAK_LOG 1 /*Defines etc..*/ /*************************************************************************************************************************************************************/ #define MANUAL_BYE 1 @@ -151,10 +151,11 @@ struct sofia_private { char gateway_name[256]; char auth_gateway_name[256]; int destroy_nh; - int destroy_me; int is_call; + int got_bye; int is_static; sofia_dispatch_event_t *de; + nua_handle_t *nh; }; #define set_param(ptr,val) if (ptr) {free(ptr) ; ptr = NULL;} if (val) {ptr = strdup(val);} @@ -318,7 +319,7 @@ typedef enum { } TFLAGS; #define SOFIA_MAX_MSG_QUEUE 51 -#define SOFIA_MSG_QUEUE_SIZE 2000 +#define SOFIA_MSG_QUEUE_SIZE 200 struct mod_sofia_globals { switch_memory_pool_t *pool; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 81a04792b5..5f42fa31d2 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -486,12 +486,7 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status, end: - if (sub_state == nua_substate_terminated && sofia_private && sofia_private != &mod_sofia_globals.destroy_private && - sofia_private != &mod_sofia_globals.keep_private) { - sofia_private->destroy_nh = 1; - sofia_private->destroy_me = 1; - } - + return; } void sofia_handle_sip_i_bye(switch_core_session_t *session, int status, @@ -558,13 +553,9 @@ void sofia_handle_sip_i_bye(switch_core_session_t *session, int status, switch_channel_hangup(channel, cause); nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)), TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END()); - + switch_safe_free(extra_headers); - if (sofia_private) { - sofia_private->destroy_me = 1; - sofia_private->destroy_nh = 1; - } #endif @@ -585,6 +576,8 @@ void sofia_handle_sip_i_bye(switch_core_session_t *session, int status, } tech_pvt->got_bye = 1; + sofia_private->got_bye = 1; + switch_channel_set_variable(channel, "sip_hangup_disposition", "recv_bye"); return; @@ -1075,28 +1068,19 @@ static void our_sofia_event_callback(nua_event_t event, } if (check_destroy) { - if (nh && ((sofia_private && sofia_private->destroy_nh) || !nua_handle_magic(nh))) { + if (0 && nh && ((sofia_private && sofia_private->destroy_nh) || !nua_handle_magic(nh))) { + + printf("FUCKER2\n"); + if (sofia_private) { nua_handle_bind(nh, NULL); } + nua_handle_destroy(nh); nh = NULL; } } - if (sofia_private && sofia_private->destroy_me) { - if (tech_pvt) { - tech_pvt->sofia_private = NULL; - } - - if (nh) { - nua_handle_bind(nh, NULL); - } - sofia_private->destroy_me = 12; - sofia_private_free(sofia_private); - - } - if (gateway) { sofia_reg_release_gateway(gateway); } @@ -1115,15 +1099,22 @@ void sofia_process_dispatch_event(sofia_dispatch_event_t **dep) sofia_dispatch_event_t *de = *dep; nua_handle_t *nh = de->nh; nua_t *nua = de->nua; - + sofia_private_t *sofia_private = nua_handle_magic(de->nh); + *dep = NULL; - our_sofia_event_callback(de->data->e_event, de->data->e_status, de->data->e_phrase, de->nua, de->profile, - de->nh, nua_handle_magic(de->nh), de->sip, de, (tagi_t *) de->data->e_tags); + sofia_private = nua_handle_magic(nh); - nua_destroy_event(de->event); - su_free(nh->nh_home, de); + //printf("QUEUE EVENT %s\n", nua_event_name(de->data->e_event)); + + + our_sofia_event_callback(de->data->e_event, de->data->e_status, de->data->e_phrase, de->nua, de->profile, + nh, sofia_private, de->sip, de, (tagi_t *) de->data->e_tags); + + //printf("/QUEUE EVENT %s\n", nua_event_name(de->data->e_event)); + nua_destroy_event(de->event); + su_free(nh->nh_home, de); nua_handle_unref(nh); nua_stack_unref(nua); } @@ -1222,24 +1213,55 @@ void sofia_event_callback(nua_event_t event, { sofia_dispatch_event_t *de; + //printf("EVENT %s\n", nua_event_name(event)); + + + + if (event == nua_i_terminated) { + if (sofia_private && sofia_private->nh) { + nua_handle_bind(nh, NULL); + nua_handle_destroy(sofia_private->nh); + } + + return; + } + + de = su_alloc(nh->nh_home, sizeof(*de)); memset(de, 0, sizeof(*de)); nua_save_event(nua, de->event); de->nh = nua_handle_ref(nh); - de->nh = nh; de->data = nua_event_data(de->event); de->sip = sip_object(de->data->e_msg); de->profile = profile; de->nua = nua_stack_ref(nua); + + if (event == nua_i_state) { + int ss_state = nua_callstate_init; + tl_gets(tags, NUTAG_CALLSTATE_REF(ss_state), TAG_END()); + + //printf("state [%s][%d]\n", nua_callstate_name(ss_state), status); + + if (ss_state == nua_callstate_terminated || ss_state == nua_callstate_terminating) { + sofia_process_dispatch_event(&de); + return; + } + } + + + + + if (event == nua_i_invite && !sofia_private) { if (!(sofia_private = su_alloc(nh->nh_home, sizeof(*sofia_private)))) { abort(); } memset(sofia_private, 0, sizeof(*sofia_private)); - sofia_private->is_call++; + sofia_private->is_call = 2; sofia_private->de = de; + sofia_private->nh = nua_handle_ref(nh); nua_handle_bind(nh, sofia_private); return; } @@ -1266,7 +1288,6 @@ void sofia_event_callback(nua_event_t event, } } - sofia_queue_message(de); } @@ -4347,7 +4368,6 @@ static void sofia_handle_sip_r_options(switch_core_session_t *session, int statu if (sofia_private && !zstr(sofia_private->gateway_name)) { gateway = sofia_reg_find_gateway(sofia_private->gateway_name); - sofia_private->destroy_me = 1; } if (gateway) { @@ -5067,10 +5087,6 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, goto done; } } - - if (sofia_private) { - sofia_private->destroy_me = 1; - } } if (session) { @@ -5806,21 +5822,6 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_channel_hangup(channel, cause); } - - if (ss_state == nua_callstate_terminated) { - if (tech_pvt->sofia_private) { - tech_pvt->sofia_private = NULL; - } - - nua_handle_unref(tech_pvt->nh); - tech_pvt->nh = NULL; - - if (nh) { - nua_handle_bind(nh, NULL); - nua_handle_destroy(nh); - } - } - break; } @@ -7929,8 +7930,6 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ switch_mutex_unlock(tech_pvt->profile->flag_mutex); } - nua_handle_bind(nh, NULL); - sofia_private_free(sofia_private); switch_core_session_destroy(&session); nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END()); return; diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index e6a6052c4a..2c35b60223 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -2214,7 +2214,6 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) switch_safe_free(d_url); return SWITCH_STATUS_FALSE; } - nua_handle_ref(tech_pvt->nh); if (tech_pvt->dest && (strstr(tech_pvt->dest, ";fs_nat") || strstr(tech_pvt->dest, ";received") || ((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val)))) { @@ -2309,6 +2308,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) memset(sofia_private, 0, sizeof(*sofia_private)); sofia_private->is_call++; + sofia_private->nh = nua_handle_ref(tech_pvt->nh); tech_pvt->sofia_private = sofia_private; switch_copy_string(tech_pvt->sofia_private->uuid, switch_core_session_get_uuid(session), sizeof(tech_pvt->sofia_private->uuid)); diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 34c6799991..aa74e6040c 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -1790,8 +1790,12 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char * switch_safe_free(pl); switch_safe_free(to); - if (nh && kill_handle) { - nua_handle_destroy(nh); + if (nh) { + if (kill_handle) { + nua_handle_destroy(nh); + } else { + nua_handle_unref(nh); + } } return 0; @@ -1841,6 +1845,10 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char * end: + if (nh) { + nua_handle_unref(nh); + } + if (ext_profile) { sofia_glue_release_profile(ext_profile); } @@ -1931,6 +1939,8 @@ static int broadsoft_sla_notify_callback(void *pArg, int argc, char **argv, char nua_notify(nh, SIPTAG_EXPIRES_STR("0"), SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"), SIPTAG_EVENT_STR("line-seize"), SIPTAG_CALL_INFO_STR(tmp), TAG_END()); + + nua_handle_unref(nh); return 0; } @@ -1939,6 +1949,7 @@ static int broadsoft_sla_notify_callback(void *pArg, int argc, char **argv, char TAG_IF(*expires_str, SIPTAG_EXPIRES_STR(expires_str)), SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR("call-info"), SIPTAG_CALL_INFO_STR(tmp), TAG_END()); + nua_handle_unref(nh); } return 0; @@ -2629,6 +2640,7 @@ static int sofia_counterpath_crutch(void *pArg, int argc, char **argv, char **co SIPTAG_EXPIRES_STR(expstr), SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event_type), SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"), SIPTAG_PAYLOAD_STR(pl), TAG_END()); + nua_handle_unref(nh); } return 0; diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 88c5dd4ec6..3f7736a1ec 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -54,8 +54,9 @@ static void sofia_reg_new_handle(sofia_gateway_t *gateway_ptr, int attach) NUTAG_CALLSTATE_REF(ss_state), SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END()); if (attach) { if (!gateway_ptr->sofia_private) { - gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private)); - switch_assert(gateway_ptr->sofia_private); + if (!(gateway_ptr->sofia_private = su_alloc(gateway_ptr->nh->nh_home, sizeof(*gateway_ptr->sofia_private)))) { + abort(); + } } memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private)); @@ -186,9 +187,10 @@ void sofia_sub_check_gateway(sofia_profile_t *profile, time_t now) NUTAG_CALLSTATE_REF(ss_state), SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END()); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "subscribing to [%s] on gateway [%s]\n", gw_sub_ptr->event, gateway_ptr->name); - gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private)); - switch_assert(gateway_ptr->sofia_private); + if (!(gateway_ptr->sofia_private = su_alloc(gateway_ptr->sub_nh->nh_home, sizeof(*gateway_ptr->sofia_private)))) { + abort(); + } memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private)); gateway_ptr->sofia_private->gateway = gateway_ptr; @@ -290,7 +292,6 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now) if (gateway_ptr->ping && !gateway_ptr->pinging && (now >= gateway_ptr->ping && (ostate == REG_STATE_NOREG || ostate == REG_STATE_REGED)) && !gateway_ptr->deleted) { nua_handle_t *nh = nua_handle(profile->nua, NULL, NUTAG_URL(gateway_ptr->register_url), TAG_END()); - sofia_private_t *pvt; register_host = sofia_glue_get_register_host(gateway_ptr->register_proxy); @@ -301,13 +302,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now) switch_safe_free(register_host); - pvt = malloc(sizeof(*pvt)); - switch_assert(pvt); - memset(pvt, 0, sizeof(*pvt)); - pvt->destroy_nh = 1; - pvt->destroy_me = 1; - switch_copy_string(pvt->gateway_name, gateway_ptr->name, sizeof(pvt->gateway_name)); - nua_handle_bind(nh, pvt); + nua_handle_bind(nh, &mod_sofia_globals.destroy_private); gateway_ptr->pinging = 1; nua_options(nh,