From 3fd55c4a2bb81be4449d297bfebdbdbce4a01f1d Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 15 Mar 2018 14:31:57 +0100 Subject: [PATCH] Fixes + tests for external body URL --- src/c-wrapper/api/c-chat-room.cpp | 7 +++- src/chat/chat-message/chat-message.cpp | 4 +-- src/chat/chat-room/chat-room.cpp | 2 ++ tester/message_tester.c | 48 ++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index e549964e0..91dbad4c0 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -113,7 +113,12 @@ const LinphoneAddress *linphone_chat_room_get_local_address (LinphoneChatRoom *c } LinphoneChatMessage *linphone_chat_room_create_message (LinphoneChatRoom *cr, const char *message) { - shared_ptr cppPtr = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createChatMessage(L_C_TO_STRING(message)); + shared_ptr cppPtr; + if (message && strlen(message) > 0) { + cppPtr = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createChatMessage(L_C_TO_STRING(message)); + } else { + cppPtr = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createChatMessage(); + } LinphoneChatMessage *object = L_INIT(ChatMessage); L_SET_CPP_PTR_FROM_C_OBJECT(object, cppPtr); return object; diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index 86b126cfa..7e12324ee 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -722,7 +722,7 @@ void ChatMessagePrivate::send () { if (internalContent.isEmpty()) { if (contents.size() > 0) { internalContent = *(contents.front()); - } else if (!externalBodyUrl.empty()) { // When using external body url, there is no content + } else if (externalBodyUrl.empty()) { // When using external body url, there is no content lError() << "Trying to send a message without any content !"; return; } @@ -730,7 +730,7 @@ void ChatMessagePrivate::send () { auto msgOp = dynamic_cast(op); if (!externalBodyUrl.empty()) { - char *content_type = ms_strdup_printf("message/external-body; access-type=URL; URL=\"%s\"", externalBodyUrl); + char *content_type = ms_strdup_printf("message/external-body; access-type=URL; URL=\"%s\"", externalBodyUrl.c_str()); msgOp->send_message(content_type, NULL); ms_free(content_type); } else if (internalContent.getContentType().isValid()) { diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index 8f69fda03..cbd6ef4c3 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -26,6 +26,7 @@ #include "chat/chat-room/chat-room-p.h" #include "core/core-p.h" #include "sip-tools/sip-headers.h" +#include "logger/logger.h" // ============================================================================= @@ -194,6 +195,7 @@ LinphoneReason ChatRoomPrivate::onSipMessageReceived (SalOp *op, const SalMessag Content content; if (message->url && strcmp(message->content_type, ContentType::ExternalBody.asString().c_str()) == 0) { + lInfo() << "Received a message with an external body URL " << message->url; content.setContentType(ContentType::FileTransfer); content.setBody(msg->getPrivate()->createFakeFileTransferFromUrl(message->url)); } else { diff --git a/tester/message_tester.c b/tester/message_tester.c index 0d639eac0..cfca82130 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -730,6 +730,52 @@ static void file_transfer_2_messages_simultaneously(void) { } } +static void file_transfer_external_body_url(bool_t use_file_body_handler_in_download) { + LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); + LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); + LinphoneChatRoom* chat_room = linphone_core_get_chat_room(marie->lc, pauline->identity); + LinphoneChatMessage* msg = linphone_chat_room_create_message(chat_room, NULL); + LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg); + char *receive_filepath = bc_tester_file("receive_file.dump"); + + linphone_chat_message_set_external_body_url(msg, "https://www.linphone.org/img/linphone-open-source-voip-projectX2.png"); + linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); + linphone_chat_room_send_chat_message(chat_room, msg); + linphone_chat_message_unref(msg); + + BC_ASSERT_TRUE(wait_for_until(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageReceivedWithFile, 1, 60000)); + + if (pauline->stat.last_received_chat_message) { + LinphoneChatMessage *recv_msg = pauline->stat.last_received_chat_message; + cbs = linphone_chat_message_get_callbacks(recv_msg); + linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); + linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received); + linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication); + if (use_file_body_handler_in_download) { + /* Remove any previously downloaded file */ + remove(receive_filepath); + linphone_chat_message_set_file_transfer_filepath(recv_msg, receive_filepath); + } + linphone_chat_message_download_file(recv_msg); + + /* wait for a long time in case the DNS SRV resolution takes times - it should be immediate though */ + BC_ASSERT_TRUE(wait_for_until(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneFileTransferDownloadSuccessful, 1, 55000)); + } + + remove(receive_filepath); + bc_free(receive_filepath); + linphone_core_manager_destroy(marie); + linphone_core_manager_destroy(pauline); +} + +static void file_transfer_using_external_body_url(void) { + file_transfer_external_body_url(FALSE); +} + +static void file_transfer_using_external_body_url_2(void) { + file_transfer_external_body_url(TRUE); +} + static void text_message_denied(void) { LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); @@ -2439,6 +2485,8 @@ test_t message_tests[] = { TEST_NO_TAG("Transfer message upload cancelled", transfer_message_upload_cancelled), TEST_NO_TAG("Transfer message download cancelled", transfer_message_download_cancelled), TEST_NO_TAG("Transfer 2 messages simultaneously", file_transfer_2_messages_simultaneously), + TEST_NO_TAG("Transfer using external body URL", file_transfer_using_external_body_url), + TEST_NO_TAG("Transfer using external body URL 2", file_transfer_using_external_body_url_2), TEST_NO_TAG("Text message denied", text_message_denied), TEST_NO_TAG("IsComposing notification", is_composing_notification), TEST_NO_TAG("IMDN notifications", imdn_notifications),