Commit c2706c77 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Fixed IMDN id issue when re-sending a message in group chat

parent aae65f05
......@@ -1220,6 +1220,11 @@ void ChatMessage::send () {
return;
}
// Remove the modifiers flag so the message will go through CPIM, Multipart and Encryption again in case of resent
d->currentSendStep &= (unsigned char)~ChatMessagePrivate::Step::Multipart;
d->currentSendStep &= (unsigned char)~ChatMessagePrivate::Step::Cpim;
d->currentSendStep &= (unsigned char)~ChatMessagePrivate::Step::Encryption;
d->loadContentsFromDatabase();
getChatRoom()->getPrivate()->sendChatMessage(getSharedFromThis());
}
......
......@@ -55,12 +55,19 @@ ChatMessageModifier::Result CpimChatMessageModifier::encode (const shared_ptr<Ch
const string imdnNamespace = "imdn";
cpimMessage.addMessageHeader(Cpim::NsHeader("urn:ietf:params:imdn", imdnNamespace));
char token[13];
belle_sip_random_token(token, sizeof(token));
cpimMessage.addMessageHeader(
Cpim::GenericHeader("Message-ID", token) // TODO: Replace by imdnNamespace + ".Message-ID");
);
message->getPrivate()->setImdnMessageId(token);
const string &previousToken = message->getImdnMessageId();
if (previousToken.empty()) {
char token[13];
belle_sip_random_token(token, sizeof(token));
cpimMessage.addMessageHeader(
Cpim::GenericHeader("Message-ID", token) // TODO: Replace by imdnNamespace + ".Message-ID");
);
message->getPrivate()->setImdnMessageId(token);
} else {
cpimMessage.addMessageHeader(
Cpim::GenericHeader("Message-ID", previousToken) // TODO: Replace by imdnNamespace + ".Message-ID");
);
}
vector<string> dispositionNotificationValues;
if (message->getPrivate()->getPositiveDeliveryNotificationRequired())
......
......@@ -379,7 +379,7 @@ end:
linphone_core_manager_destroy(pauline);
}
static void lime_x3dh_message_test (bool_t with_composing, bool_t with_response) {
static void lime_x3dh_message_test (bool_t with_composing, bool_t with_response, bool_t sal_error) {
LinphoneCoreManager *marie = linphone_core_manager_create("marie_lime_x3dh_rc");
LinphoneCoreManager *pauline = linphone_core_manager_create("pauline_lime_x3dh_rc");
bctbx_list_t *coresManagerList = NULL;
......@@ -455,6 +455,25 @@ static void lime_x3dh_message_test (bool_t with_composing, bool_t with_response)
BC_ASSERT_EQUAL(linphone_chat_room_get_security_level(marieCr), LinphoneChatRoomSecurityLevelEncrypted, int, "%d");
BC_ASSERT_EQUAL(linphone_chat_room_get_security_level(paulineCr), LinphoneChatRoomSecurityLevelEncrypted, int, "%d");
if (sal_error) {
sal_set_send_error(linphone_core_get_sal(marie->lc), -1);
LinphoneChatMessage* msg = _send_message(marieCr, "Bli bli bli");
const char *message_id = linphone_chat_message_get_message_id(msg);
BC_ASSERT_STRING_NOT_EQUAL(message_id, "");
wait_for_list(coresList, NULL, 0, 1000);
sal_set_send_error(linphone_core_get_sal(marie->lc), 0);
linphone_chat_message_send(msg);
const char *message_id_2 = linphone_chat_message_get_message_id(msg);
BC_ASSERT_STRING_NOT_EQUAL(message_id_2, "");
BC_ASSERT_STRING_EQUAL(message_id, message_id_2);
wait_for_list(coresList, NULL, 0, 1000);
linphone_chat_message_unref(msg);
}
end:
// Clean db from chat room
......@@ -468,19 +487,23 @@ end:
}
static void group_chat_lime_x3dh_send_encrypted_message (void) {
lime_x3dh_message_test(FALSE, FALSE);
lime_x3dh_message_test(FALSE, FALSE, FALSE);
}
static void group_chat_lime_x3dh_send_encrypted_message_with_error(void) {
lime_x3dh_message_test(FALSE, FALSE, TRUE);
}
static void group_chat_lime_x3dh_send_encrypted_message_with_composing (void) {
lime_x3dh_message_test(TRUE, FALSE);
lime_x3dh_message_test(TRUE, FALSE, FALSE);
}
static void group_chat_lime_x3dh_send_encrypted_message_with_response (void) {
lime_x3dh_message_test(FALSE, TRUE);
lime_x3dh_message_test(FALSE, TRUE, FALSE);
}
static void group_chat_lime_x3dh_send_encrypted_message_with_response_and_composing (void) {
lime_x3dh_message_test(TRUE, TRUE);
lime_x3dh_message_test(TRUE, TRUE, FALSE);
}
static void group_chat_lime_x3dh_encrypted_message_to_devices_with_and_without_keys (void) {
......@@ -2529,6 +2552,7 @@ test_t secure_group_chat_tests[] = {
TEST_TWO_TAGS("LIME X3DH encrypted chatrooms", group_chat_lime_x3dh_encrypted_chatrooms, "LimeX3DH", "LeaksMemory"),
TEST_TWO_TAGS("LIME X3DH basic chatrooms", group_chat_lime_x3dh_basic_chat_rooms, "LimeX3DH", "LeaksMemory"),
TEST_TWO_TAGS("LIME X3DH message", group_chat_lime_x3dh_send_encrypted_message, "LimeX3DH", "LeaksMemory"),
TEST_TWO_TAGS("LIME X3DH message with error", group_chat_lime_x3dh_send_encrypted_message_with_error, "LimeX3DH", "LeaksMemory"),
TEST_TWO_TAGS("LIME X3DH message with composing", group_chat_lime_x3dh_send_encrypted_message_with_composing, "LimeX3DH", "LeaksMemory"),
TEST_TWO_TAGS("LIME X3DH message with response", group_chat_lime_x3dh_send_encrypted_message_with_response, "LimeX3DH", "LeaksMemory"),
TEST_TWO_TAGS("LIME X3DH message with response and composing", group_chat_lime_x3dh_send_encrypted_message_with_response_and_composing, "LimeX3DH", "LeaksMemory"),
......
......@@ -873,7 +873,7 @@ static int im_encryption_engine_process_outgoing_message_cb(LinphoneImEncryption
return -1;
}
static void group_chat_room_message (bool_t encrypt) {
static void group_chat_room_message (bool_t encrypt, bool_t sal_error) {
LinphoneCoreManager *marie = linphone_core_manager_create("marie_rc");
LinphoneCoreManager *pauline = linphone_core_manager_create("pauline_rc");
LinphoneCoreManager *chloe = linphone_core_manager_create("chloe_rc");
......@@ -963,6 +963,25 @@ static void group_chat_room_message (bool_t encrypt) {
BC_ASSERT_TRUE(linphone_address_weak_equal(paulineAddr, linphone_chat_message_get_from_address(marieLastMsg)));
linphone_address_unref(paulineAddr);
if (sal_error) {
sal_set_send_error(linphone_core_get_sal(marie->lc), -1);
LinphoneChatMessage* msg = _send_message(marieCr, "Bli bli bli");
const char *message_id = linphone_chat_message_get_message_id(msg);
BC_ASSERT_STRING_NOT_EQUAL(message_id, "");
wait_for_list(coresList, NULL, 0, 1000);
sal_set_send_error(linphone_core_get_sal(marie->lc), 0);
linphone_chat_message_send(msg);
const char *message_id_2 = linphone_chat_message_get_message_id(msg);
BC_ASSERT_STRING_NOT_EQUAL(message_id_2, "");
BC_ASSERT_STRING_EQUAL(message_id, message_id_2);
wait_for_list(coresList, NULL, 0, 1000);
linphone_chat_message_unref(msg);
}
end:
// Clean db from chat room
linphone_core_manager_delete_chat_room(marie, marieCr, coresList);
......@@ -980,11 +999,15 @@ end:
}
static void group_chat_room_send_message(void) {
group_chat_room_message(FALSE);
group_chat_room_message(FALSE, FALSE);
}
static void group_chat_room_send_message_encrypted(void) {
group_chat_room_message(TRUE);
group_chat_room_message(TRUE, FALSE);
}
static void group_chat_room_send_message_with_error(void) {
group_chat_room_message(FALSE, TRUE);
}
static void group_chat_room_invite_multi_register_account (void) {
......@@ -5419,6 +5442,7 @@ test_t group_chat_tests[] = {
TEST_ONE_TAG("Add participant", group_chat_room_add_participant, "LeaksMemory"),
TEST_NO_TAG("Send message", group_chat_room_send_message),
TEST_NO_TAG("Send encrypted message", group_chat_room_send_message_encrypted),
TEST_NO_TAG("Send message with error", group_chat_room_send_message_with_error),
TEST_NO_TAG("Send invite on a multi register account", group_chat_room_invite_multi_register_account),
TEST_NO_TAG("Add admin", group_chat_room_add_admin),
TEST_NO_TAG("Add admin lately notified", group_chat_room_add_admin_lately_notified),
......
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