From 3ac678bae9a2d502835f50ddb06ac4a67b335e34 Mon Sep 17 00:00:00 2001
From: Andrea Gianarda <andrea.gianarda@belledonne-communications.com>
Date: Fri, 7 Mar 2025 07:12:54 +0100
Subject: [PATCH] Conference informations are stored in the database with an
 address without the GRUU parameter therefore it must be pruned from the
 conference address should it be present

---
 src/db/main-db.cpp                           |  6 ++++--
 tester/local-conference-edition-tester.cpp   |  2 ++
 tester/local-conference-tester-functions.cpp |  7 ++++++-
 tester/local-conference-tester-functions.h   |  3 ++-
 tester/local-encrypted-conference-tester.cpp |  6 +++---
 tester/local-scheduled-conference-tester.cpp | 10 +++++-----
 6 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp
index 09a3772534..f978e0d5c5 100644
--- a/src/db/main-db.cpp
+++ b/src/db/main-db.cpp
@@ -432,7 +432,8 @@ long long MainDbPrivate::insertChatRoom(const shared_ptr<AbstractChatRoom> &chat
 	L_Q();
 	if (q->isInitialized()) {
 		const ConferenceId &conferenceId = chatRoom->getConferenceId();
-		const long long &peerSipAddressId = insertSipAddress(conferenceId.getPeerAddress());
+		const auto &peerAddress = conferenceId.getPeerAddress();
+		const long long &peerSipAddressId = insertSipAddress(peerAddress);
 		const long long &localSipAddressId = insertSipAddress(conferenceId.getLocalAddress());
 
 		long long chatRoomId = selectChatRoomId(peerSipAddressId, localSipAddressId);
@@ -462,7 +463,8 @@ long long MainDbPrivate::insertChatRoom(const shared_ptr<AbstractChatRoom> &chat
 			const string &subject = chatRoomParams->getUtf8Subject();
 			int ephemeralEnabled = chatRoom->ephemeralEnabled() ? 1 : 0;
 			long ephemeralLifeTime = chatRoom->getEphemeralLifetime();
-			const long long &dbConferenceInfoId = selectConferenceInfoId(peerSipAddressId);
+			const long long peerSipAddressNoGruuId = selectSipAddressId(peerAddress->getUriWithoutGruu(), true);
+			const long long &dbConferenceInfoId = selectConferenceInfoId(peerSipAddressNoGruuId);
 			const long long conferenceInfoId = (dbConferenceInfoId <= 0) ? 0 : dbConferenceInfoId;
 			*dbSession.getBackendSession() << "INSERT INTO chat_room ("
 			                                  "  peer_sip_address_id, local_sip_address_id, creation_time,"
diff --git a/tester/local-conference-edition-tester.cpp b/tester/local-conference-edition-tester.cpp
index 9aa36257da..5f6768ac08 100644
--- a/tester/local-conference-edition-tester.cpp
+++ b/tester/local-conference-edition-tester.cpp
@@ -305,6 +305,8 @@ static void edit_simple_conference_base(bool_t from_organizer,
 		focus.registerAsParticipantDevice(michelle);
 		focus.registerAsParticipantDevice(lise);
 
+		linphone_core_enable_gruu_in_conference_address(focus.getLc(), TRUE);
+
 		setup_conference_info_cbs(marie.getCMgr());
 		linphone_core_set_file_transfer_server(marie.getLc(), file_transfer_url);
 
diff --git a/tester/local-conference-tester-functions.cpp b/tester/local-conference-tester-functions.cpp
index 0fe956a59f..39785a865e 100644
--- a/tester/local-conference-tester-functions.cpp
+++ b/tester/local-conference-tester-functions.cpp
@@ -7127,7 +7127,8 @@ void create_conference_with_chat_base(LinphoneConferenceSecurityLevel security_l
                                       bool_t use_relay_ice_candidates,
                                       bool_t client_reenter_conference,
                                       bool_t network_drops,
-                                      time_t start_time) {
+                                      time_t start_time,
+                                      bool_t enable_gruu_in_conference_address) {
 
 	Focus focus("chloe_rc");
 	{ // to make sure focus is destroyed after clients.
@@ -7157,6 +7158,10 @@ void create_conference_with_chat_base(LinphoneConferenceSecurityLevel security_l
 			linphone_core_set_video_activation_policy(mgr->lc, pol);
 			linphone_video_activation_policy_unref(pol);
 
+			if (mgr != pauline.getCMgr()) {
+				linphone_core_enable_gruu_in_conference_address(mgr->lc, enable_gruu_in_conference_address);
+			}
+
 			linphone_core_set_video_device(mgr->lc, liblinphone_tester_mire_id);
 			linphone_core_enable_video_capture(mgr->lc, TRUE);
 			linphone_core_enable_video_display(mgr->lc, TRUE);
diff --git a/tester/local-conference-tester-functions.h b/tester/local-conference-tester-functions.h
index a18290ce88..aeae4f68bb 100644
--- a/tester/local-conference-tester-functions.h
+++ b/tester/local-conference-tester-functions.h
@@ -360,7 +360,8 @@ void create_conference_with_chat_base(LinphoneConferenceSecurityLevel security_l
                                       bool_t slow_ice_negotiation,
                                       bool_t client_reenter_conference,
                                       bool_t network_drops,
-                                      time_t start_time);
+                                      time_t start_time,
+                                      bool_t enable_gruu_in_conference_address);
 
 void configure_end_to_end_encrypted_conference_server(Focus &focus);
 
diff --git a/tester/local-encrypted-conference-tester.cpp b/tester/local-encrypted-conference-tester.cpp
index 553f194e4d..2bd0225d07 100644
--- a/tester/local-encrypted-conference-tester.cpp
+++ b/tester/local-encrypted-conference-tester.cpp
@@ -904,17 +904,17 @@ static void create_simple_end_to_end_encrypted_conference_with_participant_added
 
 static void create_encrypted_conference_with_chat() {
 	create_conference_with_chat_base(LinphoneConferenceSecurityLevelEndToEnd, FALSE, FALSE, TRUE, 1, FALSE, TRUE, FALSE,
-	                                 ms_time(NULL));
+	                                 ms_time(NULL), FALSE);
 }
 
 static void create_encrypted_conference_with_chat_and_cores_restart(void) {
 	create_conference_with_chat_base(LinphoneConferenceSecurityLevelEndToEnd, TRUE, TRUE, TRUE, 1, FALSE, TRUE, FALSE,
-	                                 (ms_time(NULL) - 45));
+	                                 (ms_time(NULL) - 45), FALSE);
 }
 
 static void create_encrypted_conference_with_chat_network_drops_and_participant_rejoining(void) {
 	create_conference_with_chat_base(LinphoneConferenceSecurityLevelEndToEnd, FALSE, FALSE, FALSE, -1, TRUE, TRUE, TRUE,
-	                                 (ms_time(NULL) - 45));
+	                                 (ms_time(NULL) - 45), TRUE);
 }
 
 static void scheduling_failure_check(LinphoneConferenceScheduler *scheduler, LinphoneConferenceSchedulerState state) {
diff --git a/tester/local-scheduled-conference-tester.cpp b/tester/local-scheduled-conference-tester.cpp
index e6fb504dce..a18edb287c 100644
--- a/tester/local-scheduled-conference-tester.cpp
+++ b/tester/local-scheduled-conference-tester.cpp
@@ -6145,27 +6145,27 @@ static void create_simple_conference_in_sfu_payload_mode(void) {
 
 static void create_conference_with_chat(void) {
 	create_conference_with_chat_base(LinphoneConferenceSecurityLevelNone, FALSE, FALSE, TRUE, 1, TRUE, FALSE, FALSE,
-	                                 ms_time(NULL));
+	                                 ms_time(NULL), FALSE);
 }
 
 static void create_point_to_point_encrypted_conference_with_chat(void) {
 	create_conference_with_chat_base(LinphoneConferenceSecurityLevelPointToPoint, FALSE, FALSE, TRUE, -1, TRUE, FALSE,
-	                                 FALSE, ms_time(NULL));
+	                                 FALSE, ms_time(NULL), FALSE);
 }
 
 static void create_conference_with_chat_and_participant_rejoining(void) {
 	create_conference_with_chat_base(LinphoneConferenceSecurityLevelNone, FALSE, FALSE, TRUE, -1, TRUE, TRUE, FALSE,
-	                                 (ms_time(NULL) - 45));
+	                                 (ms_time(NULL) - 45), FALSE);
 }
 
 static void create_conference_with_chat_and_cores_restart(void) {
 	create_conference_with_chat_base(LinphoneConferenceSecurityLevelNone, TRUE, TRUE, TRUE, 1, FALSE, FALSE, FALSE,
-	                                 (ms_time(NULL) - 45));
+	                                 (ms_time(NULL) - 45), TRUE);
 }
 
 static void create_conference_with_chat_network_drops_and_participant_rejoining(void) {
 	create_conference_with_chat_base(LinphoneConferenceSecurityLevelNone, FALSE, FALSE, FALSE, -1, TRUE, TRUE, TRUE,
-	                                 (ms_time(NULL) - 45));
+	                                 (ms_time(NULL) - 45), FALSE);
 }
 
 #ifndef HAVE_EKT_SERVER_PLUGIN
-- 
GitLab