]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[core] allow external ID to be same as the session UUID
authorChris Rienzo <chris@signalwire.com>
Wed, 24 Jun 2020 02:31:09 +0000 (02:31 +0000)
committerAndrey Volk <andywolk@gmail.com>
Sat, 23 Oct 2021 19:00:26 +0000 (22:00 +0300)
src/switch_core_session.c
tests/unit/switch_core_session.c

index 23c787fb23f3f46ba4448aa1220e3c59ae79ecf7..acda5eaf7b00ae9d3e7c5d89f51db918c0e67e1d 100644 (file)
@@ -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;
index 0319683000184657d03ce316678752612f9b61a7..57beea3beeedd0a54d005a6b8a9badb009f6bb3a 100644 (file)
@@ -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);