From 2b407fabfae4db9029190444b3c59ffee39b1efd Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 18 Jan 2017 12:45:39 +0100 Subject: [PATCH] Fixes for LIME when used with file body handler (requires belle-sip 1.5.0-133 or newer) --- coreapi/chat_file_transfer.c | 5 +++-- coreapi/lime.c | 5 ++++- coreapi/linphonecore.c | 2 +- tester/message_tester.c | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/coreapi/chat_file_transfer.c b/coreapi/chat_file_transfer.c index b1d066f4b..21567daee 100644 --- a/coreapi/chat_file_transfer.c +++ b/coreapi/chat_file_transfer.c @@ -133,7 +133,7 @@ static int on_send_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t * LinphoneImEncryptionEngineCbsUploadingFileCb cb_process_uploading_file = linphone_im_encryption_engine_cbs_get_process_uploading_file(imee_cbs); if (cb_process_uploading_file) { char *encrypted_buffer = (char *)ms_malloc0(*size); - retval = cb_process_uploading_file(imee, msg, offset, (char *)buffer, size, encrypted_buffer); + retval = cb_process_uploading_file(imee, msg, offset, (const char *)buffer, size, encrypted_buffer); if (retval == 0) { memcpy(buffer, encrypted_buffer, *size); } @@ -234,7 +234,8 @@ static void linphone_chat_message_process_response_from_post_file(void *data, if (msg->file_transfer_filepath != NULL) { belle_sip_user_body_handler_t *body_handler = (belle_sip_user_body_handler_t *)first_part_bh; first_part_bh = (belle_sip_body_handler_t *)belle_sip_file_body_handler_new(msg->file_transfer_filepath, - linphone_chat_message_file_transfer_on_progress, msg); + NULL, msg); // No need to add again the callback for progression, otherwise it will be called twice + linphone_content_set_size(msg->file_transfer_information, belle_sip_file_body_handler_get_file_size((belle_sip_file_body_handler_t *)first_part_bh)); belle_sip_file_body_handler_set_user_body_handler((belle_sip_file_body_handler_t *)first_part_bh, body_handler); } else if (linphone_content_get_buffer(msg->file_transfer_information) != NULL) { first_part_bh = (belle_sip_body_handler_t *)belle_sip_memory_body_handler_new_from_buffer( diff --git a/coreapi/lime.c b/coreapi/lime.c index cc231eb08..53c18630a 100644 --- a/coreapi/lime.c +++ b/coreapi/lime.c @@ -1031,13 +1031,16 @@ int lime_im_encryption_engine_process_downloading_file_cb(LinphoneImEncryptionEn } int lime_im_encryption_engine_process_uploading_file_cb(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, size_t offset, const char *buffer, size_t *size, char *encrypted_buffer) { + size_t file_size = linphone_content_get_size(msg->file_transfer_information); if (linphone_content_get_key(msg->file_transfer_information) == NULL) return -1; if (buffer == NULL || *size == 0) { return lime_encryptFile(linphone_content_get_cryptoContext_address(msg->file_transfer_information), NULL, 0, NULL, NULL); } - if (offset + *size < linphone_content_get_size(msg->file_transfer_information)) { + if (file_size == 0) { + ms_warning("File size has not been set, encryption will fail if not done in one step (if file is larger than 16K)"); + } else if (offset + *size < file_size) { *size -= (*size % 16); } diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 4fd54e556..c79366ff6 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2167,7 +2167,7 @@ LinphoneLimeState linphone_core_lime_enabled(const LinphoneCore *lc){ LinphoneLimeState linphone_core_lime_for_file_sharing_enabled(const LinphoneCore *lc){ LinphoneLimeState s = linphone_core_lime_enabled(lc); if (s != LinphoneLimeDisabled) { - s = lp_config_get_int(lc->config,"sip", "lime_for_file_sharing", LinphoneLimeMandatory); + s = lp_config_get_int(lc->config,"sip", "lime_for_file_sharing", 1); } return s; } diff --git a/tester/message_tester.c b/tester/message_tester.c index 4ec384cd5..c1ffc03b1 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -220,8 +220,8 @@ LinphoneChatMessage* create_message_from_nowebcam(LinphoneChatRoom *chat_room) { LinphoneChatMessageCbs *cbs; LinphoneContent* content; LinphoneChatMessage* msg; - size_t file_size; char *send_filepath = bc_tester_res("images/nowebcamVGA.jpg"); + size_t file_size; file_to_send = fopen(send_filepath, "rb"); fseek(file_to_send, 0, SEEK_END); file_size = ftell(file_to_send); @@ -1237,7 +1237,7 @@ void lime_transfer_message_base(bool_t encrypt_file,bool_t download_file_from_st linphone_core_enable_lime(pauline->lc, LinphoneLimeMandatory); if (!encrypt_file) { LpConfig *pauline_lp = linphone_core_get_config(pauline->lc); - lp_config_set_int(pauline_lp,"sip","lime_for_file_sharing",0); + lp_config_set_int(pauline_lp, "sip", "lime_for_file_sharing", 0); } /* 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 */