diff --git a/coreapi/chat.c b/coreapi/chat.c index cc8bc895a..11c63af6d 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -1075,10 +1075,17 @@ static void linphone_chat_process_response_headers_from_get_file(void *data, con body_size = message->file_transfer_information->size; } - belle_sip_message_set_body_handler( - (belle_sip_message_t*)event->response, - (belle_sip_body_handler_t*)belle_sip_user_body_handler_new(body_size, linphone_chat_message_file_transfer_on_progress,on_recv_body,NULL,message) - ); + if (message->file_transfer_filepath == NULL) { + belle_sip_message_set_body_handler( + (belle_sip_message_t*)event->response, + (belle_sip_body_handler_t*)belle_sip_user_body_handler_new(body_size, linphone_chat_message_file_transfer_on_progress,on_recv_body,NULL,message) + ); + } else { + belle_sip_message_set_body_handler( + (belle_sip_message_t *)event->response, + (belle_sip_body_handler_t *)belle_sip_file_body_handler_new(message->file_transfer_filepath, linphone_chat_message_file_transfer_on_progress, message) + ); + } } } @@ -1362,6 +1369,18 @@ LinphoneReason linphone_chat_message_get_reason(LinphoneChatMessage* msg) { } +/** + * Set the path to the file to read from or write to during the file transfer. + * @param[in] msg LinphoneChatMessage object + * @param[in] filepath The path to the file to use for the file transfer. + */ +void linphone_chat_message_set_file_transfer_filepath(LinphoneChatMessage *msg, const char *filepath) { + if (msg->file_transfer_filepath != NULL) { + ms_free(msg->file_transfer_filepath); + } + msg->file_transfer_filepath = ms_strdup(filepath); +} + /** * Create a message attached to a dedicated chat room with a particular content. Use #linphone_chat_room_send_message2 to initiate the transfer @@ -1385,15 +1404,6 @@ LinphoneChatMessage* linphone_chat_room_create_file_transfer_message(LinphoneCha return msg; } -LinphoneChatMessage * linphone_chat_room_create_file_transfer_message_from_file(LinphoneChatRoom *cr, LinphoneContent *initial_content, const char *filepath) { - LinphoneChatMessage *msg = linphone_chat_room_create_file_transfer_message(cr, initial_content); - if (msg->file_transfer_filepath != NULL) { - ms_free(msg->file_transfer_filepath); - } - msg->file_transfer_filepath = ms_strdup(filepath); - return msg; -} - /** * @} */ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index f3fbe22cb..9ed211fae 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -1450,6 +1450,7 @@ LINPHONE_PUBLIC bool_t linphone_chat_message_is_outgoing(LinphoneChatMessage* me LINPHONE_PUBLIC unsigned int linphone_chat_message_get_storage_id(LinphoneChatMessage* message); LINPHONE_PUBLIC LinphoneReason linphone_chat_message_get_reason(LinphoneChatMessage* msg); LINPHONE_PUBLIC const LinphoneErrorInfo *linphone_chat_message_get_error_info(const LinphoneChatMessage *msg); +LINPHONE_PUBLIC void linphone_chat_message_set_file_transfer_filepath(LinphoneChatMessage *msg, const char *filepath); /** * @} */