From 8a7cfe66d65e3f55687a7bf394d5cacbc7c2d983 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Sun, 4 Oct 2015 21:13:22 +0200 Subject: [PATCH] don't notify a NotDelivered state if an incoming file transfer fails --- coreapi/chat_file_transfer.c | 24 +++++++++++++++++------- coreapi/linphonecore.h | 2 +- coreapi/private.h | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/coreapi/chat_file_transfer.c b/coreapi/chat_file_transfer.c index fecbcfc69..30d82f960 100644 --- a/coreapi/chat_file_transfer.c +++ b/coreapi/chat_file_transfer.c @@ -451,7 +451,7 @@ static void linphone_chat_process_response_from_get_file(void *data, const belle } } -void _linphone_chat_room_start_http_transfer(LinphoneChatMessage *msg, const char* url, const char* action, const belle_http_request_listener_callbacks_t *cbs) { +int _linphone_chat_room_start_http_transfer(LinphoneChatMessage *msg, const char* url, const char* action, const belle_http_request_listener_callbacks_t *cbs) { belle_generic_uri_t *uri = NULL; char* ua; @@ -479,31 +479,41 @@ void _linphone_chat_room_start_http_transfer(LinphoneChatMessage *msg, const cha /* give msg to listener to be able to start the actual file upload when server answer a 204 No content */ msg->http_listener = belle_http_request_listener_create_from_callbacks(cbs, linphone_chat_message_ref(msg)); belle_http_provider_send_request(msg->chat_room->lc->http_provider, msg->http_request, msg->http_listener); - return; + return 0; error: if (uri) { belle_sip_object_unref(uri); } - linphone_chat_message_set_state(msg, LinphoneChatMessageStateNotDelivered); + return -1; } -void linphone_chat_room_upload_file(LinphoneChatMessage *msg) { +int linphone_chat_room_upload_file(LinphoneChatMessage *msg) { belle_http_request_listener_callbacks_t cbs = {0}; + int err; + cbs.process_response = linphone_chat_message_process_response_from_post_file; cbs.process_io_error = linphone_chat_message_process_io_error_upload; cbs.process_auth_requested = linphone_chat_message_process_auth_requested_upload; - _linphone_chat_room_start_http_transfer(msg, linphone_core_get_file_transfer_server(msg->chat_room->lc), "POST", &cbs); + err = _linphone_chat_room_start_http_transfer(msg, linphone_core_get_file_transfer_server(msg->chat_room->lc), "POST", &cbs); + if (err == -1){ + linphone_chat_message_set_state(msg, LinphoneChatMessageStateNotDelivered); + } + return err; } -void linphone_chat_message_download_file(LinphoneChatMessage *msg) { +int linphone_chat_message_download_file(LinphoneChatMessage *msg) { belle_http_request_listener_callbacks_t cbs = {0}; + int err; + cbs.process_response_headers = linphone_chat_process_response_headers_from_get_file; cbs.process_response = linphone_chat_process_response_from_get_file; cbs.process_io_error = linphone_chat_message_process_io_error_download; cbs.process_auth_requested = linphone_chat_message_process_auth_requested_download; - _linphone_chat_room_start_http_transfer(msg, msg->external_body_url, "GET", &cbs); + err = _linphone_chat_room_start_http_transfer(msg, msg->external_body_url, "GET", &cbs); + if (err == -1) return -1; /* start the download, status is In Progress */ linphone_chat_message_set_state(msg, LinphoneChatMessageStateInProgress); + return 0; } void linphone_chat_message_start_file_download(LinphoneChatMessage *msg, diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 0ac3af839..0d9326967 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -1556,7 +1556,7 @@ LINPHONE_PUBLIC void linphone_chat_message_start_file_download(LinphoneChatMessa * Start the download of the file referenced in a LinphoneChatMessage from remote server. * @param[in] message LinphoneChatMessage object. */ -LINPHONE_PUBLIC void linphone_chat_message_download_file(LinphoneChatMessage *message); +LINPHONE_PUBLIC int linphone_chat_message_download_file(LinphoneChatMessage *message); /** * Cancel an ongoing file transfer attached to this message.(upload or download) * @param msg #LinphoneChatMessage diff --git a/coreapi/private.h b/coreapi/private.h index f08d5ea39..1f1042fab 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -518,7 +518,7 @@ void linphone_chat_room_release(LinphoneChatRoom *cr); void linphone_chat_message_destroy(LinphoneChatMessage* msg); void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMessageState new_state); void linphone_chat_message_set_state(LinphoneChatMessage *msg, LinphoneChatMessageState state); -void linphone_chat_room_upload_file(LinphoneChatMessage *msg); +int linphone_chat_room_upload_file(LinphoneChatMessage *msg); void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg); LinphoneChatMessageCbs *linphone_chat_message_cbs_new(void); LinphoneChatRoom *_linphone_core_create_chat_room_from_call(LinphoneCall *call);