From 6b6b721c1060b3dcbe292f2ec6dea74103048759 Mon Sep 17 00:00:00 2001 From: Chris Rienzo Date: Wed, 24 Jun 2020 02:31:09 +0000 Subject: [PATCH] [core] allow external ID to be same as the session UUID --- src/switch_core_session.c | 10 +++++++--- tests/unit/switch_core_session.c | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 23c787fb23..acda5eaf7b 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -2080,7 +2080,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_external_id(switch_core_ switch_mutex_lock(runtime.session_hash_mutex); - if (switch_core_hash_find(session_manager.session_table, use_external_id)) { + if (strcmp(use_external_id, session->uuid_str) && switch_core_hash_find(session_manager.session_table, use_external_id)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Duplicate External ID!\n"); switch_mutex_unlock(runtime.session_hash_mutex); return SWITCH_STATUS_FALSE; @@ -2088,11 +2088,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_external_id(switch_core_ switch_channel_set_variable(session->channel, "session_external_id", use_external_id); - if (session->external_id) { + if (session->external_id && strcmp(session->external_id, session->uuid_str)) { switch_core_hash_delete(session_manager.session_table, session->external_id); } + session->external_id = switch_core_session_strdup(session, use_external_id); - switch_core_hash_insert(session_manager.session_table, session->external_id, session); + + if (strcmp(session->external_id, session->uuid_str)) { + switch_core_hash_insert(session_manager.session_table, session->external_id, session); + } switch_mutex_unlock(runtime.session_hash_mutex); return SWITCH_STATUS_SUCCESS; diff --git a/tests/unit/switch_core_session.c b/tests/unit/switch_core_session.c index 0319683000..57beea3bee 100644 --- a/tests/unit/switch_core_session.c +++ b/tests/unit/switch_core_session.c @@ -48,7 +48,8 @@ FST_CORE_BEGIN("./conf") FST_SESSION_BEGIN(session_external_id) { - fst_check(switch_core_session_set_external_id(fst_session, switch_core_session_get_uuid(fst_session)) != SWITCH_STATUS_SUCCESS); + fst_check(switch_core_session_set_external_id(fst_session, switch_core_session_get_uuid(fst_session)) == SWITCH_STATUS_SUCCESS); + fst_check_string_equals(switch_core_session_get_external_id(fst_session), switch_core_session_get_uuid(fst_session)); fst_check(switch_core_session_set_external_id(fst_session, "foo") == SWITCH_STATUS_SUCCESS); switch_core_session_t *session = switch_core_session_locate("foo"); fst_requires(session);