diff --git a/include/linphone/api/c-chat-room.h b/include/linphone/api/c-chat-room.h index 948a3708a..aa12b800a 100644 --- a/include/linphone/api/c-chat-room.h +++ b/include/linphone/api/c-chat-room.h @@ -141,6 +141,13 @@ LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_chat_room_send_message2(Linpho */ LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_chat_room_send_chat_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg); +/** + * Used to receive a chat message when using async mechanism with IM encryption engine + * @param[in] cr LinphoneChatRoom object + * @param[in] msg LinphoneChatMessage object + */ +LINPHONE_PUBLIC void linphone_chat_room_receive_chat_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg); + /** * Mark all messages of the conversation as read * @param[in] cr The #LinphoneChatRoom object corresponding to the conversation. diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index 133704ade..046f8b1e1 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -150,6 +150,10 @@ void linphone_chat_room_send_chat_message (LinphoneChatRoom *cr, LinphoneChatMes L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg)); } +void linphone_chat_room_receive_chat_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg) { + L_GET_PRIVATE_FROM_C_OBJECT(msg)->receive(); +} + uint32_t linphone_chat_room_get_char (const LinphoneChatRoom *cr) { if (linphone_core_realtime_text_enabled(linphone_chat_room_get_core(cr))) return L_GET_CPP_PTR_FROM_C_OBJECT(cr, RealTimeTextChatRoom)->getChar(); diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index c1bd24bae..b820e9466 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -492,15 +492,18 @@ void ChatMessagePrivate::send () { // Start of message modification // --------------------------------------- - if (applyModifiers && q->getChatRoom()->canHandleParticipants()) { // Do not multipart, encrypt or encapsulate with CPIM in an old ChatRoom to maintain backward compatibility - if ((currentSendStep &ChatMessagePrivate::Step::Multipart) == ChatMessagePrivate::Step::Multipart) { - lInfo() << "Multipart step already done, skipping"; - } else { - if (contents.size() > 1) { - MultipartChatMessageModifier mcmm; - mcmm.encode(q->getSharedFromThis(), errorCode); + if (applyModifiers) { + // Do not multipart or encapsulate with CPIM in an old ChatRoom to maintain backward compatibility + if (q->getChatRoom()->canHandleParticipants()) { + if ((currentSendStep &ChatMessagePrivate::Step::Multipart) == ChatMessagePrivate::Step::Multipart) { + lInfo() << "Multipart step already done, skipping"; + } else { + if (contents.size() > 1) { + MultipartChatMessageModifier mcmm; + mcmm.encode(q->getSharedFromThis(), errorCode); + } + currentSendStep |= ChatMessagePrivate::Step::Multipart; } - currentSendStep |= ChatMessagePrivate::Step::Multipart; } if ((currentSendStep &ChatMessagePrivate::Step::Encryption) == ChatMessagePrivate::Step::Encryption) { @@ -519,15 +522,17 @@ void ChatMessagePrivate::send () { currentSendStep |= ChatMessagePrivate::Step::Encryption; } - if ((currentSendStep &ChatMessagePrivate::Step::Cpim) == ChatMessagePrivate::Step::Cpim) { - lInfo() << "Cpim step already done, skipping"; - } else { - int defaultValue = !!lp_config_get_string(core->getCCore()->config, "misc", "conference_factory_uri", nullptr); - if (lp_config_get_int(core->getCCore()->config, "sip", "use_cpim", defaultValue) == 1) { - CpimChatMessageModifier ccmm; - ccmm.encode(q->getSharedFromThis(), errorCode); + if (q->getChatRoom()->canHandleParticipants()) { + if ((currentSendStep &ChatMessagePrivate::Step::Cpim) == ChatMessagePrivate::Step::Cpim) { + lInfo() << "Cpim step already done, skipping"; + } else { + int defaultValue = !!lp_config_get_string(core->getCCore()->config, "misc", "conference_factory_uri", nullptr); + if (lp_config_get_int(core->getCCore()->config, "sip", "use_cpim", defaultValue) == 1) { + CpimChatMessageModifier ccmm; + ccmm.encode(q->getSharedFromThis(), errorCode); + } + currentSendStep |= ChatMessagePrivate::Step::Cpim; } - currentSendStep |= ChatMessagePrivate::Step::Cpim; } } diff --git a/src/chat/modifier/encryption-chat-message-modifier.cpp b/src/chat/modifier/encryption-chat-message-modifier.cpp index 75d755f19..6aaeb19b1 100644 --- a/src/chat/modifier/encryption-chat-message-modifier.cpp +++ b/src/chat/modifier/encryption-chat-message-modifier.cpp @@ -84,7 +84,7 @@ ChatMessageModifier::Result EncryptionChatMessageModifier::decode ( return ChatMessageModifier::Result::Skipped; int retval = cbProcessIncomingMessage(imee, L_GET_C_BACK_PTR(chatRoom), L_GET_C_BACK_PTR(message)); - if (retval != 0 && retval != -1) { + if (retval != 0 && retval != -1 && retval != 1) { errorCode = retval; return ChatMessageModifier::Result::Error; } diff --git a/tester/message_tester.c b/tester/message_tester.c index 2f7732039..38461d640 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -2238,6 +2238,16 @@ static int im_encryption_engine_process_incoming_message_cb(LinphoneImEncryption return 500; } +static bool_t im_encryption_engine_process_incoming_message_async_impl(LinphoneChatMessage** msg) { + if (*msg) { + im_encryption_engine_process_incoming_message_cb(NULL,NULL,*msg); + linphone_chat_room_receive_chat_message(linphone_chat_message_get_chat_room(*msg), *msg); + linphone_chat_message_unref(*msg); + *msg=NULL; + } + return TRUE; +} + static int im_encryption_engine_process_outgoing_message_cb(LinphoneImEncryptionEngine *engine, LinphoneChatRoom *room, LinphoneChatMessage *msg) { if (strcmp(linphone_chat_message_get_content_type(msg),"text/plain") == 0) { size_t b64Size = 0; @@ -2265,6 +2275,7 @@ static bool_t im_encryption_engine_process_outgoing_message_async_impl(LinphoneC } static LinphoneChatMessage* pending_message=NULL; /*limited to one message at a time */ +static LinphoneChatMessage* incoming_pending_message=NULL; /*limited to one message at a time */ static int im_encryption_engine_process_outgoing_message_async(LinphoneImEncryptionEngine *engine, LinphoneChatRoom *room, LinphoneChatMessage *msg) { pending_message=msg; @@ -2273,6 +2284,13 @@ static int im_encryption_engine_process_outgoing_message_async(LinphoneImEncrypt return 1;/*temporaly code to defer message sending*/ } +static int im_encryption_engine_process_incoming_message_async(LinphoneImEncryptionEngine *engine, LinphoneChatRoom *room, LinphoneChatMessage *msg) { + incoming_pending_message=msg; + linphone_chat_message_ref(incoming_pending_message); + linphone_core_add_iterate_hook(linphone_chat_room_get_core(room), (LinphoneCoreIterateHook)im_encryption_engine_process_incoming_message_async_impl,&incoming_pending_message); + return 1;/*temporaly code to defer message receiving*/ +} + void im_encryption_engine_b64_base(bool_t async) { LinphoneChatMessage *chat_msg = NULL; LinphoneChatRoom* chat_room = NULL; @@ -2283,13 +2301,14 @@ void im_encryption_engine_b64_base(bool_t async) { LinphoneImEncryptionEngine *pauline_imee = linphone_im_encryption_engine_new(); LinphoneImEncryptionEngineCbs *pauline_cbs = linphone_im_encryption_engine_get_callbacks(pauline_imee); - linphone_im_encryption_engine_cbs_set_process_incoming_message(marie_cbs, im_encryption_engine_process_incoming_message_cb); linphone_im_encryption_engine_cbs_set_process_outgoing_message(marie_cbs, im_encryption_engine_process_outgoing_message_cb); linphone_im_encryption_engine_cbs_set_process_incoming_message(pauline_cbs, im_encryption_engine_process_incoming_message_cb); if (async) { linphone_im_encryption_engine_cbs_set_process_outgoing_message(pauline_cbs, im_encryption_engine_process_outgoing_message_async); + linphone_im_encryption_engine_cbs_set_process_incoming_message(marie_cbs, im_encryption_engine_process_incoming_message_async); } else { linphone_im_encryption_engine_cbs_set_process_outgoing_message(pauline_cbs, im_encryption_engine_process_outgoing_message_cb); + linphone_im_encryption_engine_cbs_set_process_incoming_message(marie_cbs, im_encryption_engine_process_incoming_message_cb); } linphone_core_set_im_encryption_engine(marie->lc, marie_imee);