Commit 0531b031 authored by Sylvain Berfini's avatar Sylvain Berfini 🐮
Browse files

Prevent crash if returned chat room is null & prevent creating another basic...

Prevent crash if returned chat room is null & prevent creating another basic chat room for same local/remote addresses couple
parent bd9611a0
......@@ -140,7 +140,8 @@ LinphoneChatRoom *linphone_core_create_chat_room_6(LinphoneCore *lc, const Linph
bool withGruu = chatRoomParams ? chatRoomParams->getChatRoomBackend() == LinphonePrivate::ChatRoomParams::ChatRoomBackend::FlexisipChat : false;
LinphonePrivate::IdentityAddress identityAddress = localAddr ? LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(localAddr)) : L_GET_PRIVATE_FROM_C_OBJECT(lc)->getDefaultLocalAddress(nullptr, withGruu);
shared_ptr<LinphonePrivate::AbstractChatRoom> room = L_GET_PRIVATE_FROM_C_OBJECT(lc)->createChatRoom(chatRoomParams, identityAddress, participantsList);
return L_GET_C_BACK_PTR(room);
if (room) return L_GET_C_BACK_PTR(room);
return NULL;
}
LinphoneChatRoom *linphone_core_search_chat_room(const LinphoneCore *lc, const LinphoneChatRoomParams *params, const LinphoneAddress *localAddr, const LinphoneAddress *remoteAddr, const bctbx_list_t *participants) {
......@@ -152,7 +153,8 @@ LinphoneChatRoom *linphone_core_search_chat_room(const LinphoneCore *lc, const L
LinphonePrivate::IdentityAddress identityAddress = localAddr ? LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(localAddr)) : L_GET_PRIVATE_FROM_C_OBJECT(lc)->getDefaultLocalAddress(nullptr, withGruu);
LinphonePrivate::IdentityAddress remoteAddress = remoteAddr ? LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(remoteAddr)) : LinphonePrivate::IdentityAddress();
shared_ptr<LinphonePrivate::AbstractChatRoom> room = L_GET_PRIVATE_FROM_C_OBJECT(lc)->searchChatRoom(chatRoomParams, identityAddress, remoteAddress, participantsList);
return L_GET_C_BACK_PTR(room);
if (room) return L_GET_C_BACK_PTR(room);
return NULL;
}
LinphoneChatRoomParams *linphone_core_create_default_chat_room_params(LinphoneCore *lc) {
......
......@@ -4723,11 +4723,10 @@ LINPHONE_PUBLIC const bctbx_list_t *linphone_core_get_linphone_specs_list (Linph
* @param params The chat room creation parameters #LinphoneChatRoomParams @maybenil
* @param localAddr #LinphoneAddress representing the local proxy configuration to use for the chat room creation or NULL @maybenil
* @param participants \bctbx_list{LinphoneAddress} The initial list of participants of the chat room @notnil
* @return The newly created chat room or NULL. @maybenil
* @return The newly created chat room (can be an existing one if backend is Basic) or NULL. @maybenil
*/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_create_chat_room_6(LinphoneCore *core, const LinphoneChatRoomParams *params, const LinphoneAddress *localAddr, const bctbx_list_t *participants);
/**
* Find a chat room.
*
......
......@@ -362,11 +362,17 @@ shared_ptr<AbstractChatRoom> CorePrivate::createChatRoom(const shared_ptr<ChatRo
}
ChatRoom::CapabilitiesMask capabilities = ChatRoomParams::toCapabilities(params);
chatRoom = createBasicChatRoom(ConferenceId(IdentityAddress(participants.front()), localAddr),
capabilities,
params);
insertChatRoom(chatRoom);
insertChatRoomWithDb(chatRoom);
IdentityAddress remoteAddr = IdentityAddress(participants.front());
list<IdentityAddress> emptyList;
chatRoom = searchChatRoom(params, localAddr, remoteAddr, emptyList);
if (chatRoom == nullptr) {
chatRoom = createBasicChatRoom(ConferenceId(remoteAddr, localAddr), capabilities, params);
insertChatRoom(chatRoom);
insertChatRoomWithDb(chatRoom);
} else {
lInfo() << "Found an existing BasicChatRoom with this participant, using it instead of creating a new one";
}
}
return chatRoom;
}
......
......@@ -273,6 +273,30 @@ static void file_transfer_content(void) {
linphone_core_manager_destroy(pauline);
}
static void create_two_basic_chat_room_with_same_remote(void) {
LinphoneCoreManager* laure = linphone_core_manager_new("laure_tcp_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("pauline_tcp_rc");
LinphoneChatRoomParams *chat_room_params = linphone_core_create_default_chat_room_params(pauline->lc);
linphone_chat_room_params_set_backend(chat_room_params, LinphoneChatRoomBackendBasic);
linphone_chat_room_params_enable_encryption(chat_room_params, FALSE);
linphone_chat_room_params_enable_group(chat_room_params, FALSE);
linphone_chat_room_params_enable_rtt(chat_room_params, FALSE);
bctbx_list_t *participants = bctbx_list_append(NULL, laure->identity);
LinphoneChatRoom *chat_room = linphone_core_create_chat_room_6(pauline->lc, chat_room_params, pauline->identity, participants);
BC_ASSERT_PTR_NOT_NULL(chat_room);
LinphoneChatRoom *chat_room2 = linphone_core_create_chat_room_6(pauline->lc, chat_room_params, pauline->identity, participants);
BC_ASSERT_PTR_NOT_NULL(chat_room2);
BC_ASSERT_PTR_EQUAL(chat_room, chat_room2);
bctbx_list_free(participants);
linphone_chat_room_params_unref(chat_room_params);
linphone_chat_room_unref(chat_room);
linphone_core_manager_destroy(laure);
linphone_core_manager_destroy(pauline);
}
static void text_message(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
......@@ -3466,6 +3490,7 @@ static void migration_from_messages_db (void) {
test_t message_tests[] = {
TEST_NO_TAG("File transfer content", file_transfer_content),
TEST_NO_TAG("Create two basic chat rooms with same remote", create_two_basic_chat_room_with_same_remote),
TEST_NO_TAG("Text message", text_message),
TEST_NO_TAG("Transfer forward message", text_forward_message),
TEST_NO_TAG("Text message UTF8", text_message_with_utf8),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment