Commit f6c4f0f5 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Started to move file transfer related code in ChatMessage into FileTransferChatMessageModifier

parent 987fca94
......@@ -27,6 +27,7 @@
#include "content/content.h"
#include "content/file-content.h"
#include "content/file-transfer-content.h"
#include "chat/modifier/file-transfer-chat-message-modifier.h"
#include "content/content-type.h"
#include "object/object-p.h"
#include "sal/sal.h"
......@@ -39,7 +40,6 @@ class ChatMessagePrivate : public ObjectPrivate {
friend class CpimChatMessageModifier;
friend class EncryptionChatMessageModifier;
friend class MultipartChatMessageModifier;
friend class FileTransferChatMessageModifier;
public:
enum Step {
......@@ -153,6 +153,7 @@ private:
unsigned long backgroundTaskId = 0;
unsigned char currentSendStep = Step::None;
bool applyModifiers = true;
FileTransferChatMessageModifier fileTransferChatMessageModifier;
// Cache for returned values, used for compatibility with previous C API
ContentType cContentType;
std::string cText;
......
......@@ -1257,40 +1257,14 @@ void ChatMessagePrivate::send () {
if ((currentSendStep & ChatMessagePrivate::Step::FileUpload) == ChatMessagePrivate::Step::FileUpload) {
lInfo() << "File upload step already done, skipping";
} else {
// TODO
/*FileTransferChatMessageModifier ftcmm;
ChatMessageModifier::Result result = ftcmm.encode(q->getSharedFromThis(), errorCode);
ChatMessageModifier::Result result = fileTransferChatMessageModifier.encode(q->getSharedFromThis(), errorCode);
if (result == ChatMessageModifier::Result::Error) {
setState(ChatMessage::State::NotDelivered);
return;
} else if (result == ChatMessageModifier::Result::Suspended) {
setState(ChatMessage::State::InProgress);
return;
}
currentSendStep |= ChatMessagePrivate::Step::FileUpload;*/
currentFileContentToTransfer = nullptr;
// For each FileContent, upload it and create a FileTransferContent
for (Content *content : contents) {
ContentType contentType = content->getContentType();
//TODO Improve
if (contentType != ContentType::FileTransfer && contentType != ContentType::PlainText &&
contentType != ContentType::ExternalBody && contentType != ContentType::Imdn &&
contentType != ContentType::ImIsComposing && contentType != ContentType::ResourceLists &&
contentType != ContentType::Sdp && contentType != ContentType::ConferenceInfo &&
contentType != ContentType::Cpim) {
lInfo() << "Found content with type " << contentType.asString() << ", set it for file upload";
FileContent *fileContent = (FileContent *)content;
currentFileContentToTransfer = fileContent;
break;
}
}
if (currentFileContentToTransfer != nullptr) {
/* Open a transaction with the server and send an empty request(RCS5.1 section 3.5.4.8.3.1) */
if (uploadFile() == 0) {
setState(ChatMessage::State::InProgress);
}
return;
}
currentSendStep |= ChatMessagePrivate::Step::FileUpload;
}
......
......@@ -42,6 +42,7 @@ class LINPHONE_PUBLIC ChatMessage : public Object, public CoreAccessor {
friend class ChatRoom;
friend class ChatRoomPrivate;
friend class CpimChatMessageModifier;
friend class FileTransferChatMessageModifier;
friend class MainDbPrivate;
friend class RealTimeTextChatRoomPrivate;
friend class ServerGroupChatRoomPrivate;
......
......@@ -35,6 +35,7 @@ class LINPHONE_PUBLIC ChatRoom : public Object, public CoreAccessor, public Conf
friend class CorePrivate;
friend class ChatMessage;
friend class ChatMessagePrivate;
friend class FileTransferChatMessageModifier;
public:
L_OVERRIDE_SHARED_FROM_THIS(ChatRoom);
......
......@@ -26,15 +26,38 @@
LINPHONE_BEGIN_NAMESPACE
class FileTransferMessageModifier : public ChatMessageModifier {
class Core;
class FileTransferChatMessageModifier : public ChatMessageModifier {
public:
FileTransferMessageModifier () = default;
FileTransferChatMessageModifier () = default;
Result encode (const std::shared_ptr<ChatMessage> &message, int &errorCode) override;
Result decode (const std::shared_ptr<ChatMessage> &message, int &errorCode) override;
int onSendBody (belle_sip_user_body_handler_t *bh, belle_sip_message_t *m, size_t offset, uint8_t *buffer, size_t *size);
void onSendEnd (belle_sip_user_body_handler_t *bh);
void fileUploadBackgroundTaskEnded();
void fileTransferOnProgress (belle_sip_body_handler_t *bh, belle_sip_message_t *m, size_t offset, size_t total);
void processResponseFromPostFile (const belle_http_response_event_t *event);
void processIoErrorUpload (const belle_sip_io_error_event_t *event);
void processAuthRequestedUpload (const belle_sip_auth_event *event);
private:
std::shared_ptr<ChatRoom> chatRoom;
std::shared_ptr<ChatMessage> chatMessage;
FileContent* currentFileContentToTransfer;
unsigned long backgroundTaskId = 0;
belle_http_request_t *httpRequest = nullptr;
belle_http_request_listener_t *httpListener = nullptr;
int uploadFile();
int startHttpTransfer(const std::string &url, const std::string &action, belle_http_request_listener_callbacks_t *cbs);
void fileUploadBeginBackgroundTask();
void fileUploadEndBackgroundTask();
bool isFileTransferInProgressAndValid();
void releaseHttpRequest();
};
LINPHONE_END_NAMESPACE
......
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