diff --git a/coreapi/chat.c b/coreapi/chat.c index cd4ed54e7..1e6202d49 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -705,8 +705,23 @@ static void linphone_chat_room_notify_is_composing(LinphoneChatRoom *cr, const c void linphone_core_is_composing_received(LinphoneCore *lc, SalOp *op, const SalIsComposing *is_composing) { LinphoneAddress *addr = linphone_address_new(is_composing->from); LinphoneChatRoom *cr = _linphone_core_get_chat_room(lc, addr); + LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(lc); + if (cr != NULL) { - linphone_chat_room_notify_is_composing(cr, is_composing->text); + int retval = -1; + LinphoneChatMessage *msg = linphone_chat_room_create_message(cr, is_composing->text); + linphone_chat_message_set_from_address(msg, addr); + if (imee) { + LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee); + LinphoneImEncryptionEngineIncomingMessageCb cb_process_incoming_message = linphone_im_encryption_engine_cbs_get_process_incoming_message(imee_cbs); + if (cb_process_incoming_message) { + retval = cb_process_incoming_message(lc, cr, msg); + } + } + if (retval <= 0) { + linphone_chat_room_notify_is_composing(cr, msg->message); + } + linphone_chat_message_unref(msg); } linphone_address_destroy(addr); } @@ -836,6 +851,9 @@ static void linphone_chat_room_send_is_composing_notification(LinphoneChatRoom * const char *identity = NULL; char *content = NULL; LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(cr->lc, cr->peer_url); + LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(cr->lc); + LinphoneChatMessage *msg = NULL; + if (proxy) identity = linphone_proxy_config_get_identity(proxy); else @@ -847,7 +865,29 @@ static void linphone_chat_room_send_is_composing_notification(LinphoneChatRoom * content = linphone_chat_room_create_is_composing_xml(cr); if (content != NULL) { - sal_message_send(op, identity, cr->peer, "application/im-iscomposing+xml", content, NULL); + int retval = -1; + LinphoneAddress *from_addr = linphone_address_new(identity); + LinphoneAddress *to_addr = linphone_address_new(cr->peer); + msg = linphone_chat_room_create_message(cr, content); + linphone_chat_message_set_from_address(msg, from_addr); + linphone_chat_message_set_to_address(msg, to_addr); + msg->content_type = ms_strdup("application/im-iscomposing+xml"); + + if (imee) { + LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee); + LinphoneImEncryptionEngineOutgoingMessageCb cb_process_outgoing_message = linphone_im_encryption_engine_cbs_get_process_outgoing_message(imee_cbs); + if (cb_process_outgoing_message) { + retval = cb_process_outgoing_message(cr->lc, cr, msg); + } + } + + if (retval <= 0) { + sal_message_send(op, identity, cr->peer, msg->content_type, msg->message, NULL); + } + + linphone_chat_message_unref(msg); + linphone_address_destroy(from_addr); + linphone_address_destroy(to_addr); ms_free(content); sal_op_unref(op); } diff --git a/coreapi/lime.c b/coreapi/lime.c index 9d3511af5..bcb79e8d3 100644 --- a/coreapi/lime.c +++ b/coreapi/lime.c @@ -930,15 +930,18 @@ int lime_im_encryption_engine_process_incoming_message_cb(LinphoneCore* lc, Linp int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneCore* lc, LinphoneChatRoom *room, LinphoneChatMessage *msg) { int errcode = -1; - char *content_type = NULL; + char *content_type = "xml/cipher"; if (linphone_chat_room_lime_available(room)) { - if (msg->content_type && strcmp(msg->content_type, "application/vnd.gsma.rcs-ft-http+xml") == 0) { - /* it's a file transfer, content type shall be set to - application/cipher.vnd.gsma.rcs-ft-http+xml*/ - content_type = "application/cipher.vnd.gsma.rcs-ft-http+xml"; - } else { - content_type = "xml/cipher"; + if (msg->content_type) { + if (strcmp(msg->content_type, "application/vnd.gsma.rcs-ft-http+xml") == 0) { + /* it's a file transfer, content type shall be set to + application/cipher.vnd.gsma.rcs-ft-http+xml*/ + content_type = "application/cipher.vnd.gsma.rcs-ft-http+xml"; + } else if (strcmp(msg->content_type, "application/im-iscomposing+xml") == 0) { + /* We don't encrypt composing messages */ + return errcode; + } } msg->content_type = ms_strdup(content_type); diff --git a/tester/message_tester.c b/tester/message_tester.c index d4e217f30..a6ecc6b32 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -809,12 +809,48 @@ static void info_message_with_body(void){ info_message_base(TRUE); } -static void is_composing_notification(void) { +static FILE* fopen_from_write_dir(const char * name, const char * mode) { + char *filepath = bc_tester_file(name); + FILE * file = fopen(filepath,mode); + bc_free(filepath); + return file; +} + +static void _is_composing_notification(bool_t lime_enabled) { LinphoneChatRoom* chat_room; int dummy = 0; + char* filepath = NULL; + FILE *ZIDCacheMarieFD = NULL, *ZIDCachePaulineFD = NULL; LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); + + if (lime_enabled) { + if (!linphone_core_lime_available(marie->lc)) { + ms_warning("Lime not available, skiping"); + goto end; + } + /* make sure lime is enabled */ + linphone_core_enable_lime(marie->lc, 1); + linphone_core_enable_lime(pauline->lc, 1); + + /* set the zid caches files : create two ZID cache from this valid one inserting the auto-generated sip URI for the peer account as keys in ZID cache are indexed by peer sip uri */ + ZIDCacheMarieFD = fopen_from_write_dir("tmpZIDCacheMarie.xml", "w"); + ZIDCachePaulineFD = fopen_from_write_dir("tmpZIDCachePauline.xml", "w"); + fprintf(ZIDCacheMarieFD, "\nef7692d0792a67491ae2d44e005dbe0399643d953a2202dd9b5c8f06f3b6c2c695f2dfc3c26f31f5fef8661f8c5fe7c95aeb5c5b0435b045f8324dd18ea905171ec2be89f879d01d5994132048d92ea020778cbdf31c605e2fdcef69380937c2cf221f7d11526f286c39f49641452ba9012521c705094899%s08df5907d30959b8cb70f6fff2d8febd88fb41b0c8afc39e4b972f86dd5cfe2d60f020a3fe11dc2cc0e1e8ed9341b4cd14944db806ca4fc95456bbe45d95c43a5f9aa1e5e4c7ec88fa389a9f6b8879b42d3c57bb28e62068d2df23e8f9b77193bcffd51e7316a6c6f53a50fcf01b01bf2d3c57bb28e62068d2df23e8f9b7719300000078000001cf011234567889643d953a2202ee9b5c8f06f3b6c2c695f2dfc3c26f31f5fef8661f8c5fe7c95aeb5c5b0435b045f8324dd18ea905171ec2be89f879d01d5994132048d92ea020778cbdf31c605e2fdcef69380937c2cf221f7d11526f286c39f49641452ba9012521c705094899%s72d80ab1cad243cf45634980c1d02cfb2df81ce0dd5dfcf1ebeacfc5345a917625d9ac653a83c4559cb0ae7394e7cd3b2d3c57bb28e62068d2df23e8f9b77193f69aa1e5e4c7ec88fa389a9f6b8879b42d3c57bb28e62068d2df23e8f9b7719322ffd51e7316a6c6f53a50fcf01b01bf2d3c57bb28e62068d2df23e8f9b771930000000f00000000", linphone_address_as_string_uri_only(pauline->identity), linphone_address_as_string_uri_only(pauline->identity)); + fprintf(ZIDCachePaulineFD, "\n005dbe0399643d953a2202ddef7692d0792a67491ae2d44e9b5c8f06f3b6c2c695f2dfc3c26f31f5fef8661f8c5fe7c95aeb5c5b0435b045f8324dd18ea905171ec2be89f879d01d5994132048d92ea020778cbdf31c605e2fdcef69380937c2cf221f7d11526f286c39f49641452ba9012521c705094899%s08df5907d30959b8cb70f6fff2d8febd88fb41b0c8afc39e4b972f86dd5cfe2d60f020a3fe11dc2cc0e1e8ed9341b4cd14944db806ca4fc95456bbe45d95c43a5f9aa1e5e4c7ec88fa389a9f6b8879b42d3c57bb28e62068d2df23e8f9b77193bcffd51e7316a6c6f53a50fcf01b01bf2d3c57bb28e62068d2df23e8f9b7719300000078000001cf011234567889643d953a2202ee9b5c8f06f3b6c2c695f2dfc3c26f31f5fef8661f8c5fe7c95aeb5c5b0435b045f8324dd18ea905171ec2be89f879d01d5994132048d92ea020778cbdf31c605e2fdcef69380937c2cf221f7d11526f286c39f49641452ba9012521c705094899%s81e6e6362c34dc974263d1f77cbb9a8d6d6a718330994379099a8fa19fb12faa25d9ac653a83c4559cb0ae7394e7cd3b2d3c57bb28e62068d2df23e8f9b77193f69aa1e5e4c7ec88fa389a9f6b8879b42d3c57bb28e62068d2df23e8f9b7719322ffd51e7316a6c6f53a50fcf01b01bf2d3c57bb28e62068d2df23e8f9b771930000002e0000000001", linphone_address_as_string_uri_only(marie->identity), linphone_address_as_string_uri_only(marie->identity)); + fclose(ZIDCacheMarieFD); + fclose(ZIDCachePaulineFD); + + filepath = bc_tester_file("tmpZIDCacheMarie.xml"); + linphone_core_set_zrtp_secrets_file(marie->lc, filepath); + bc_free(filepath); + + filepath = bc_tester_file("tmpZIDCachePauline.xml"); + linphone_core_set_zrtp_secrets_file(pauline->lc, filepath); + bc_free(filepath); + } + chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); linphone_core_get_chat_room(marie->lc, pauline->identity); /*make marie create the chatroom with pauline, which is necessary for receiving the is-composing*/ linphone_chat_room_compose(chat_room); @@ -822,15 +858,18 @@ static void is_composing_notification(void) { linphone_chat_room_send_message(chat_room, "Composing a msg"); BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingActiveReceived, 1)); BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingIdleReceived, 2)); + +end: linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); } -static FILE* fopen_from_write_dir(const char * name, const char * mode) { - char *filepath = bc_tester_file(name); - FILE * file = fopen(filepath,mode); - bc_free(filepath); - return file; +static void is_composing_notification() { + _is_composing_notification(FALSE); +} + +static void is_composing_notification_with_lime() { + _is_composing_notification(TRUE); } static void lime_text_message(void) { @@ -1976,6 +2015,7 @@ test_t message_tests[] = { TEST_NO_TAG("Info message", info_message), TEST_NO_TAG("Info message with body", info_message_with_body), TEST_NO_TAG("IsComposing notification", is_composing_notification), + TEST_NO_TAG("IsComposing notification lime", is_composing_notification_with_lime), TEST_NO_TAG("Lime text message", lime_text_message), TEST_NO_TAG("Lime text message to non lime", lime_text_message_to_non_lime), TEST_NO_TAG("Lime transfer message", lime_transfer_message),