[Core] Add new switch_core_hash_insert_dup_auto_free() API
This commit is contained in:
parent
0b0f5fff65
commit
58abf91d1d
|
@ -1446,6 +1446,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_pointer(switch_hash_t *h
|
|||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_auto_free(switch_hash_t *hash, const char *key, const void *data);
|
||||
|
||||
/*!
|
||||
\brief Insert strdup(str) into a hash and set flags so the value is automatically freed on delete
|
||||
\param hash the hash to add str to
|
||||
\param key the name of the key to add the str to
|
||||
\param str string to strdup and add
|
||||
\return SWITCH_STATUS_SUCCESS if the data is added
|
||||
\note the string key must be a constant or a dynamic string
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_dup_auto_free(switch_hash_t *hash, const char *key, const char *str);
|
||||
|
||||
/*!
|
||||
\brief Insert data into a hash
|
||||
\param hash the hash to add data to
|
||||
|
@ -1469,10 +1479,10 @@ SWITCH_DECLARE(void *) switch_core_hash_insert_alloc_destructor(_In_ switch_hash
|
|||
#define switch_core_hash_insert_alloc(_h, _k, _s) switch_core_hash_insert_alloc_destructor(_h, _k, _s, NULL)
|
||||
|
||||
/*!
|
||||
\brief Insert strdup(data) into a hash
|
||||
\param hash the hash to add data to
|
||||
\param key the name of the key to add the data to
|
||||
\param data string to strdup and add
|
||||
\brief Insert strdup(str) into a hash
|
||||
\param hash the hash to add str to
|
||||
\param key the name of the key to add the str to
|
||||
\param str string to strdup and add
|
||||
\return SWITCH_STATUS_SUCCESS if the data is added
|
||||
\note the string key must be a constant or a dynamic string
|
||||
*/
|
||||
|
|
|
@ -2441,16 +2441,11 @@ void sofia_event_callback(nua_event_t event,
|
|||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "detaching session %s\n", sofia_private->uuid);
|
||||
|
||||
if (!zstr(tech_pvt->call_id)) {
|
||||
char *uuid = strdup(switch_core_session_get_uuid(session));
|
||||
tech_pvt->sofia_private = NULL;
|
||||
tech_pvt->nh = NULL;
|
||||
sofia_set_flag(tech_pvt, TFLAG_BYE);
|
||||
switch_mutex_lock(profile->flag_mutex);
|
||||
|
||||
if (switch_core_hash_insert_auto_free(profile->chat_hash, tech_pvt->call_id, uuid) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_safe_free(uuid);
|
||||
}
|
||||
|
||||
switch_core_hash_insert_dup_auto_free(profile->chat_hash, tech_pvt->call_id, switch_core_session_get_uuid(session));
|
||||
switch_mutex_unlock(profile->flag_mutex);
|
||||
nua_handle_destroy(nh);
|
||||
} else {
|
||||
|
|
|
@ -85,6 +85,23 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_auto_free(switch_hash_t
|
|||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_dup_auto_free(switch_hash_t *hash, const char *key, const char *str)
|
||||
{
|
||||
char *dkey = strdup(key);
|
||||
char *dup = strdup(str);
|
||||
|
||||
assert(dup);
|
||||
|
||||
if (switch_hashtable_insert_destructor(hash, dkey, (void *)dup, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE | HASHTABLE_DUP_CHECK, NULL)) {
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_safe_free(dup);
|
||||
switch_safe_free(dkey);
|
||||
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(void *) switch_core_hash_insert_alloc_destructor(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ size_t size, hashtable_destructor_t destructor) {
|
||||
char *dkey;
|
||||
void *data;
|
||||
|
|
Loading…
Reference in New Issue