From eeeb4fa445248ea45c70bffd598d31f9b76851b4 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 24 Apr 2013 16:35:58 -0500 Subject: [PATCH] FS-5340 --resolve --- src/mod/endpoints/mod_sofia/mod_sofia.h | 2 ++ src/mod/endpoints/mod_sofia/sofia.c | 5 +++- src/mod/endpoints/mod_sofia/sofia_reg.c | 38 +++++++++++++++++++++---- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 1d2186657d..88fb47461b 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -600,6 +600,7 @@ struct sofia_profile { sofia_gateway_t *gateways; //su_home_t *home; switch_hash_t *chat_hash; + switch_hash_t *reg_nh_hash; switch_hash_t *mwi_debounce_hash; //switch_core_db_t *master_db; switch_thread_rwlock_t *rwlock; @@ -1107,6 +1108,7 @@ int sofia_glue_check_nat(sofia_profile_t *profile, const char *network_ip); switch_status_t sofia_glue_ext_address_lookup(sofia_profile_t *profile, char **ip, switch_port_t *port, const char *sourceip, switch_memory_pool_t *pool); void sofia_reg_check_socket(sofia_profile_t *profile, const char *call_id, const char *network_addr, const char *network_ip); +void sofia_reg_close_handles(sofia_profile_t *profile); /* For Emacs: * Local Variables: diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 9af181dd73..2bb9ea5d2f 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -2611,6 +2611,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void } sofia_clear_pflag_locked(profile, PFLAG_RUNNING); + sofia_reg_close_handles(profile); switch_core_session_hupall_matching_var("sofia_profile_name", profile->name, SWITCH_CAUSE_MANAGER_REQUEST); sanity = 10; @@ -2628,7 +2629,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void sofia_reg_unregister(profile); nua_shutdown(profile->nua); - sanity = 10; + sanity = 100; while (!sofia_test_pflag(profile, PFLAG_SHUTDOWN) || profile->queued_events > 0) { su_root_step(profile->s_root, 1000); if (!--sanity) { @@ -2702,6 +2703,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void sofia_glue_del_profile(profile); switch_core_hash_destroy(&profile->chat_hash); + switch_core_hash_destroy(&profile->reg_nh_hash); switch_core_hash_destroy(&profile->mwi_debounce_hash); switch_thread_rwlock_unlock(profile->rwlock); @@ -3622,6 +3624,7 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) profile->dbname = switch_core_strdup(profile->pool, url); switch_core_hash_init(&profile->chat_hash, profile->pool); + switch_core_hash_init(&profile->reg_nh_hash, profile->pool); switch_core_hash_init(&profile->mwi_debounce_hash, profile->pool); switch_thread_rwlock_create(&profile->rwlock, profile->pool); switch_mutex_init(&profile->flag_mutex, SWITCH_MUTEX_NESTED, profile->pool); diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 461eaea875..01730611a9 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -644,9 +644,10 @@ void sofia_reg_check_socket(sofia_profile_t *profile, const char *call_id, const switch_snprintf(key, sizeof(key), "%s%s%s", call_id, network_addr, network_ip); switch_mutex_lock(profile->flag_mutex); - if ((hnh = switch_core_hash_find(profile->chat_hash, key))) { - switch_core_hash_delete(profile->chat_hash, key); + if ((hnh = switch_core_hash_find(profile->reg_nh_hash, key))) { + switch_core_hash_delete(profile->reg_nh_hash, key); nua_handle_unref(hnh); + nua_handle_destroy(hnh); } switch_mutex_unlock(profile->flag_mutex); } @@ -1081,7 +1082,34 @@ static int debounce_check(sofia_profile_t *profile, const char *user, const char return r; } - + +void sofia_reg_close_handles(sofia_profile_t *profile) +{ + nua_handle_t *nh = NULL; + switch_hash_index_t *hi; + const void *var; + void *val; + + + switch_mutex_lock(profile->flag_mutex); + if (profile->reg_nh_hash) { + top: + for (hi = switch_hash_first(NULL, profile->reg_nh_hash); hi; hi = switch_hash_next(hi)) { + switch_hash_this(hi, &var, NULL, &val); + if ((nh = (nua_handle_t *) val)) { + nua_handle_unref(nh); + nua_handle_destroy(nh); + switch_core_hash_delete(profile->reg_nh_hash, (char *) var); + goto top; + } + } + } + switch_mutex_unlock(profile->flag_mutex); + + return; + +} + uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip, sofia_dispatch_event_t *de, sofia_regtype_t regtype, char *key, @@ -1699,7 +1727,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand switch_snprintf(key, sizeof(key), "%s%s%s", call_id, network_ip, network_port_c); switch_mutex_lock(profile->flag_mutex); - hnh = switch_core_hash_find(profile->chat_hash, key); + hnh = switch_core_hash_find(profile->reg_nh_hash, key); switch_mutex_unlock(profile->flag_mutex); if (!hnh) { @@ -1716,7 +1744,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand *sofia_private_p = sofia_private; nua_handle_bind(nh, sofia_private); nua_handle_ref(nh); - switch_core_hash_insert(profile->chat_hash, key, nh); + switch_core_hash_insert(profile->reg_nh_hash, key, nh); } }