Commit 3dede7cc authored by Ronan's avatar Ronan

fix(core): fix downloadFile method, returns bool instead of int! There is no...

fix(core): fix downloadFile method, returns bool instead of int! There is no reason to return -1 on error like a C function
parent b001af37
......@@ -4689,10 +4689,10 @@ extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setFileTransferFi
ReleaseStringUTFChars(env, jpath, path);
}
extern "C" jint Java_org_linphone_core_LinphoneChatMessageImpl_downloadFile(JNIEnv* env
extern "C" jboolean Java_org_linphone_core_LinphoneChatMessageImpl_downloadFile(JNIEnv* env
,jobject thiz
,jlong ptr) {
return (jint) linphone_chat_message_download_file((LinphoneChatMessage*)ptr);
return linphone_chat_message_download_file((LinphoneChatMessage*)ptr);
}
extern "C" jboolean Java_org_linphone_core_LinphoneChatMessageImpl_isSecured(JNIEnv* env
......
......@@ -257,7 +257,7 @@ LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_chat_message_start_file_downlo
* Start the download of the file referenced in a #LinphoneChatMessage from remote server.
* @param[in] msg #LinphoneChatMessage object.
*/
LINPHONE_PUBLIC LinphoneStatus linphone_chat_message_download_file (LinphoneChatMessage *msg);
LINPHONE_PUBLIC bool_t linphone_chat_message_download_file (LinphoneChatMessage *msg);
/**
* Cancel an ongoing file transfer attached to this message.(upload or download)
......
......@@ -225,7 +225,7 @@ public interface LinphoneChatMessage {
/**
* Start the download of the file referenced in a LinphoneChatMessage from remote server.
*/
int downloadFile();
boolean downloadFile();
/**
* Set the callbacks associated with the LinphoneChatMessage.
......
......@@ -16,7 +16,7 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage {
private native void store(long ptr);
private native int getStorageId(long ptr);
private native void setFileTransferFilepath(long ptr, String path);
private native int downloadFile(long ptr);
private native boolean downloadFile(long ptr);
private native void setListener(long ptr, LinphoneChatMessageListener listener);
private native void unref(long ptr);
......@@ -146,7 +146,7 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage {
}
@Override
public int downloadFile() {
public boolean downloadFile() {
return downloadFile(nativePtr);
}
......
This diff is collapsed.
......@@ -312,7 +312,7 @@ void FileTransferChatMessageModifier::processResponseFromPostFile (const belle_h
if (c->isFileTransfer()) {
FileTransferContent *tmpContent = static_cast<FileTransferContent *>(c);
if (!tmpContent->getFileContent() && tmpContent->getSize() == 0) {
// If FileTransferContent doesn't have a FileContent yet and is empty
// If FileTransferContent doesn't have a FileContent yet and is empty
// It's the one we seek, otherwise it may be a previous uploaded FileTransferContent
fileTransferContent = tmpContent;
break;
......@@ -546,7 +546,7 @@ void FileTransferChatMessageModifier::fileUploadEndBackgroundTask () {
// ----------------------------------------------------------
static void fillFileTransferContentInformationsFromVndGsmaRcsFtHttpXml(FileTransferContent *fileTransferContent) {
static void fillFileTransferContentInformationsFromVndGsmaRcsFtHttpXml (FileTransferContent *fileTransferContent) {
xmlChar *fileUrl = nullptr;
xmlDocPtr xmlMessageBody;
xmlNodePtr cur;
......@@ -947,24 +947,27 @@ void FileTransferChatMessageModifier::processResponseFromGetFile (const belle_ht
}
}
int FileTransferChatMessageModifier::downloadFile(const shared_ptr<ChatMessage> &message, FileTransferContent *fileTransferContent) {
bool FileTransferChatMessageModifier::downloadFile (
const shared_ptr<ChatMessage> &message,
FileTransferContent *fileTransferContent
) {
chatMessage = message;
if (httpRequest) {
lError() << "linphone_chat_message_download_file(): there is already a download in progress";
return -1;
lError() << "There is already a download in progress.";
return false;
}
if (fileTransferContent->getContentType() != ContentType::FileTransfer) {
lError() << "linphone_chat_message_download_file(): content type is not FileTransfer";
return -1;
lError() << "Content type is not a FileTransfer.";
return false;
}
createFileTransferInformationsFromVndGsmaRcsFtHttpXml(fileTransferContent);
FileContent *fileContent = fileTransferContent->getFileContent();
currentFileContentToTransfer = fileContent;
if (!currentFileContentToTransfer)
return -1;
return false;
// THIS IS ONLY FOR BACKWARD C API COMPAT
if (currentFileContentToTransfer->getFilePath().empty() && !message->getPrivate()->getFileTransferFilepath().empty()) {
......@@ -978,10 +981,10 @@ int FileTransferChatMessageModifier::downloadFile(const shared_ptr<ChatMessage>
cbs.process_auth_requested = _chat_message_process_auth_requested_download;
int err = startHttpTransfer(fileTransferContent->getFileUrl(), "GET", &cbs); // File URL has been set by createFileTransferInformationsFromVndGsmaRcsFtHttpXml
if (err == -1)
return -1;
return false;
// start the download, status is In Progress
message->getPrivate()->setState(ChatMessage::State::InProgress);
return 0;
return true;
}
// ----------------------------------------------------------
......@@ -1024,7 +1027,7 @@ void FileTransferChatMessageModifier::releaseHttpRequest () {
}
}
string FileTransferChatMessageModifier::createFakeFileTransferFromUrl(const string &url) {
string FileTransferChatMessageModifier::createFakeFileTransferFromUrl (const string &url) {
string fileName = url.substr(url.find_last_of("/") + 1);
stringstream fakeXml;
fakeXml << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
......
......@@ -53,25 +53,25 @@ public:
void processIoErrorUpload (const belle_sip_io_error_event_t *event);
void processAuthRequestedUpload (const belle_sip_auth_event *event);
void onRecvBody(belle_sip_user_body_handler_t *bh, belle_sip_message_t *m, size_t offset, uint8_t *buffer, size_t size);
void onRecvEnd(belle_sip_user_body_handler_t *bh);
void processResponseHeadersFromGetFile(const belle_http_response_event_t *event);
void processAuthRequestedDownload(const belle_sip_auth_event *event);
void processIoErrorDownload(const belle_sip_io_error_event_t *event);
void processResponseFromGetFile(const belle_http_response_event_t *event);
int downloadFile(const std::shared_ptr<ChatMessage> &message, FileTransferContent *fileTransferContent);
void cancelFileTransfer();
bool isFileTransferInProgressAndValid();
std::string createFakeFileTransferFromUrl(const std::string &url);
void onRecvBody (belle_sip_user_body_handler_t *bh, belle_sip_message_t *m, size_t offset, uint8_t *buffer, size_t size);
void onRecvEnd (belle_sip_user_body_handler_t *bh);
void processResponseHeadersFromGetFile (const belle_http_response_event_t *event);
void processAuthRequestedDownload (const belle_sip_auth_event *event);
void processIoErrorDownload (const belle_sip_io_error_event_t *event);
void processResponseFromGetFile (const belle_http_response_event_t *event);
bool downloadFile (const std::shared_ptr<ChatMessage> &message, FileTransferContent *fileTransferContent);
void cancelFileTransfer ();
bool isFileTransferInProgressAndValid ();
std::string createFakeFileTransferFromUrl (const std::string &url);
private:
int uploadFile();
int startHttpTransfer(const std::string &url, const std::string &action, belle_http_request_listener_callbacks_t *cbs);
void fileUploadBeginBackgroundTask();
void fileUploadEndBackgroundTask();
int uploadFile ();
int startHttpTransfer (const std::string &url, const std::string &action, belle_http_request_listener_callbacks_t *cbs);
void fileUploadBeginBackgroundTask ();
void fileUploadEndBackgroundTask ();
void releaseHttpRequest();
void releaseHttpRequest ();
std::weak_ptr<ChatMessage> chatMessage;
FileContent* currentFileContentToTransfer = nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment