Commit 057db033 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Moved from a list of Content to a list of Content* to be able to cast content...

Moved from a list of Content to a list of Content* to be able to cast content to specialized version
parent ba89633e
......@@ -294,10 +294,10 @@ LinphoneStatus linphone_chat_message_put_char(LinphoneChatMessage *msg, uint32_t
}
void linphone_chat_message_add_text_content(LinphoneChatMessage *msg, const char *c_content) {
LinphonePrivate::Content content;
LinphonePrivate::Content *content = new LinphonePrivate::Content();
LinphonePrivate::ContentType contentType = LinphonePrivate::ContentType::PlainText;
content.setContentType(contentType);
content.setBody(L_C_TO_STRING(c_content));
content->setContentType(contentType);
content->setBody(L_C_TO_STRING(c_content));
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->addContent(content);
}
......@@ -306,11 +306,11 @@ bool_t linphone_chat_message_has_text_content(const LinphoneChatMessage *msg) {
}
const char * linphone_chat_message_get_text_content(const LinphoneChatMessage *msg) {
LinphonePrivate::Content content = L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getTextContent();
if (content == LinphonePrivate::Content::Empty) {
const LinphonePrivate::Content *content = L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getTextContent();
if (*content == LinphonePrivate::Content::Empty) {
return NULL;
}
return L_STRING_TO_C(content.getBodyAsString());
return L_STRING_TO_C(content->getBodyAsString());
}
// =============================================================================
......
......@@ -140,7 +140,7 @@ private:
std::string rttMessage;
bool isSecured = false;
bool isReadOnly = false;
std::list<Content > contents;
std::list<Content* > contents;
Content internalContent;
FileContent *currentFileContentToTransfer;
std::unordered_map<std::string, std::string> customHeaders;
......@@ -170,7 +170,7 @@ private:
belle_http_request_listener_callbacks_t *cbs
);
void releaseHttpRequest();
void createFileTransferInformationsFromVndGsmaRcsFtHttpXml(FileTransferContent &content);
void createFileTransferInformationsFromVndGsmaRcsFtHttpXml(FileTransferContent* content);
L_DECLARE_PUBLIC(ChatMessage);
};
......
This diff is collapsed.
......@@ -96,16 +96,15 @@ public:
bool isRead () const;
bool isReadOnly () const;
const std::list<Content> &getContents () const;
void addContent (Content &&content);
void addContent (const Content &content);
void removeContent (const Content &content);
const std::list<Content *> &getContents () const;
void addContent (Content *content);
void removeContent (Content *content);
bool hasTextContent() const;
const Content &getTextContent() const;
const Content* getTextContent() const;
bool hasFileTransferContent() const;
const Content &getFileTransferContent() const;
const Content* getFileTransferContent() const;
const Content &getInternalContent () const;
void setInternalContent (const Content &content);
......@@ -114,7 +113,7 @@ public:
void addCustomHeader (const std::string &headerName, const std::string &headerValue);
void removeCustomHeader (const std::string &headerName);
int downloadFile (FileTransferContent& content);
int downloadFile (FileTransferContent *content);
private:
L_DECLARE_PRIVATE(ChatMessage);
......
......@@ -118,9 +118,9 @@ void ChatRoomPrivate::sendImdn (const string &payload, LinphoneReason reason) {
msg->setFromAddress(Address(identity));
msg->setToAddress(peerAddress);
Content content;
content.setContentType("message/imdn+xml");
content.setBody(payload);
Content *content = new Content();
content->setContentType("message/imdn+xml");
content->setBody(payload);
msg->addContent(content);
/* Do not try to encrypt the notification when it is reporting an error (maybe it should be bypassed only for some reasons). */
......@@ -163,9 +163,9 @@ void ChatRoomPrivate::sendIsComposingNotification () {
string payload = isComposingHandler->marshal(isComposing);
if (!payload.empty()) {
shared_ptr<ChatMessage> msg = q->createMessage();
Content content;
content.setContentType("application/im-iscomposing+xml");
content.setBody(payload);
Content *content = new Content();
content->setContentType("application/im-iscomposing+xml");
content->setBody(payload);
msg->addContent(content);
msg->getPrivate()->send();
}
......@@ -465,9 +465,9 @@ shared_ptr<ChatMessage> ChatRoom::createFileTransferMessage (const LinphoneConte
shared_ptr<ChatMessage> ChatRoom::createMessage (const string &message) {
shared_ptr<ChatMessage> chatMessage = createMessage();
Content content;
content.setContentType(ContentType::PlainText);
content.setBody(message);
Content *content = new Content();
content->setContentType(ContentType::PlainText);
content->setBody(message);
chatMessage->addContent(content);
return chatMessage;
}
......
......@@ -46,10 +46,10 @@ ChatMessageModifier::Result CpimChatMessageModifier::encode (const shared_ptr<Ch
cpimToHeader.setValue(cpimAddressAsString(message->getToAddress()));
cpimMessage.addMessageHeader(cpimToHeader);
Content content;
const Content *content;
if (!message->getInternalContent().isEmpty()) {
// Another ChatMessageModifier was called before this one, we apply our changes on the private content
content = message->getInternalContent();
content = &(message->getInternalContent());
} else {
// We're the first ChatMessageModifier to be called, we'll create the private content from the public one
// We take the first one because if there is more of them, the multipart modifier should have been called first
......@@ -59,10 +59,10 @@ ChatMessageModifier::Result CpimChatMessageModifier::encode (const shared_ptr<Ch
Cpim::GenericHeader contentTypeHeader;
contentTypeHeader.setName("Content-Type");
contentTypeHeader.setValue(content.getContentType().asString());
contentTypeHeader.setValue(content->getContentType().asString());
cpimMessage.addContentHeader(contentTypeHeader);
const string contentBody = content.getBodyAsString();
const string contentBody = content->getBodyAsString();
cpimMessage.setContent(contentBody);
if (!cpimMessage.isValid()) {
......@@ -80,18 +80,18 @@ ChatMessageModifier::Result CpimChatMessageModifier::encode (const shared_ptr<Ch
}
ChatMessageModifier::Result CpimChatMessageModifier::decode (const shared_ptr<ChatMessage> &message, int &errorCode) {
Content content;
const Content *content;
if (!message->getInternalContent().isEmpty())
content = message->getInternalContent();
content = &(message->getInternalContent());
else
content = message->getContents().front();
if (content.getContentType() != ContentType::Cpim) {
lError() << "[CPIM] Message is not CPIM but " << content.getContentType().asString();
if (content->getContentType() != ContentType::Cpim) {
lError() << "[CPIM] Message is not CPIM but " << content->getContentType().asString();
return ChatMessageModifier::Result::Skipped;
}
const string contentBody = content.getBodyAsString();
const string contentBody = content->getBodyAsString();
const shared_ptr<const Cpim::Message> cpimMessage = Cpim::Message::createFromString(contentBody);
if (!cpimMessage || !cpimMessage->isValid()) {
lError() << "[CPIM] Message is invalid: " << contentBody;
......
......@@ -24,6 +24,7 @@
#include "chat/chat-message/chat-message.h"
#include "chat/chat-room/chat-room.h"
#include "content/content-type.h"
#include "content/file-transfer-content.h"
#include "logger/logger.h"
#include "core/core.h"
......@@ -49,10 +50,10 @@ ChatMessageModifier::Result MultipartChatMessageModifier::encode (
stringstream multipartMessage;
multipartMessage << "--" << boundary;
for (const auto &content : message->getContents()) {
for (Content *content : message->getContents()) {
multipartMessage << "\r\n";
multipartMessage << "Content-Type: " << content.getContentType().asString() << "\r\n\r\n";
multipartMessage << content.getBodyAsString() << "\r\n\r\n";
multipartMessage << "Content-Type: " << content->getContentType().asString() << "\r\n\r\n";
multipartMessage << content->getBodyAsString() << "\r\n\r\n";
multipartMessage << "--" << boundary;
}
multipartMessage << "--";
......@@ -111,9 +112,14 @@ ChatMessageModifier::Result MultipartChatMessageModifier::decode (const shared_p
endOfLinePos += 4; // 4 is two time the size of \r\n
string contentBody = contentString.substr(endOfLinePos, contentString.length() - (endOfLinePos + 4)); // 4 is two time the size of \r\n
Content content;
content.setContentType(contentType);
content.setBody(contentBody);
Content *content;
if (contentType == ContentType::FileTransfer) {
content = new FileTransferContent();
} else {
content = new Content();
}
content->setContentType(contentType);
content->setBody(contentBody);
message->addContent(content);
lInfo() << "Parsed and added content with type " << contentType.asString();
......
......@@ -31,7 +31,7 @@ class FileContentPrivate : public ContentPrivate {
public:
string fileName;
string filePath;
size_t fileSize;
size_t fileSize = 0;
};
// -----------------------------------------------------------------------------
......@@ -98,7 +98,7 @@ void FileContent::setFileName(const string &name) {
d->fileName = name;
}
string FileContent::getFileName() const {
const string& FileContent::getFileName() const {
L_D();
return d->fileName;
}
......@@ -108,7 +108,7 @@ void FileContent::setFilePath(const string &path) {
d->filePath = path;
}
string FileContent::getFilePath() const {
const string& FileContent::getFilePath() const {
L_D();
return d->filePath;
}
......
......@@ -42,10 +42,10 @@ public:
size_t getFileSize() const;
void setFileName(const std::string &name);
std::string getFileName() const;
const std::string& getFileName() const;
void setFilePath(const std::string &path);
std::string getFilePath() const;
const std::string& getFilePath() const;
LinphoneContent * toLinphoneContent() const override;
......
......@@ -31,7 +31,7 @@ class FileTransferContentPrivate : public ContentPrivate {
public:
string fileUrl;
string filePath;
FileContent fileContent;
FileContent *fileContent = nullptr;
};
// -----------------------------------------------------------------------------
......@@ -87,7 +87,7 @@ void FileTransferContent::setFileUrl(const string &url) {
d->fileUrl = url;
}
string FileTransferContent::getFileUrl() const {
const string& FileTransferContent::getFileUrl() const {
L_D();
return d->fileUrl;
}
......@@ -97,17 +97,17 @@ void FileTransferContent::setFilePath(const string &path) {
d->filePath = path;
}
string FileTransferContent::getFilePath() const {
const string& FileTransferContent::getFilePath() const {
L_D();
return d->filePath;
}
void FileTransferContent::setFileContent(const FileContent &content) {
void FileTransferContent::setFileContent(FileContent *content) {
L_D();
d->fileContent = content;
}
FileContent FileTransferContent::getFileContent() const {
FileContent* FileTransferContent::getFileContent() const {
L_D();
return d->fileContent;
}
......
......@@ -40,13 +40,13 @@ public:
bool operator== (const FileTransferContent &content) const;
void setFileUrl(const std::string &url);
std::string getFileUrl() const;
const std::string& getFileUrl() const;
void setFilePath(const std::string &path);
std::string getFilePath() const;
const std::string& getFilePath() const;
void setFileContent(const FileContent &content);
FileContent getFileContent() const;
void setFileContent(FileContent *content);
FileContent* getFileContent() const;
LinphoneContent * toLinphoneContent() const override;
......
......@@ -478,8 +478,8 @@ MainDb::MainDb (const shared_ptr<Core> &core) : AbstractDb(*new MainDbPrivate),
soci::use(static_cast<int>(chatMessage->getState())), soci::use(static_cast<int>(chatMessage->getDirection())),
soci::use(chatMessage->getImdnMessageId()), soci::use(chatMessage->isSecured() ? 1 : 0);
for (const auto &content : chatMessage->getContents())
insertContent(eventId, content);
for (Content *content : chatMessage->getContents())
insertContent(eventId, *content);
return eventId;
}
......
......@@ -399,9 +399,9 @@ static void cpim_chat_message_modifier_base(bool_t use_multipart) {
shared_ptr<ChatMessage> marieMessage = marieRoom->createMessage("Hello CPIM");
if (use_multipart) {
Content content;
content.setContentType(ContentType::PlainText);
content.setBody("Hello Part 2");
Content *content = new Content();
content->setContentType(ContentType::PlainText);
content->setBody("Hello Part 2");
marieMessage->addContent(content);
}
marieMessage->send();
......
......@@ -21,6 +21,7 @@
#include "chat/chat-room/basic-chat-room.h"
#include "content/content-type.h"
#include "content/content.h"
#include "content/file-content.h"
#include "core/core.h"
// TODO: Remove me later.
......@@ -60,14 +61,14 @@ static void chat_message_multipart_modifier_base(bool first_file_transfer, bool
linphone_content_set_subtype(initialContent,"mkv");
linphone_content_set_name(initialContent,"sintel_trailer_opus_h264.mkv");
Content content;
content.setContentType(ContentType::FileTransfer);
content.setBody(linphone_content_get_string_buffer(initialContent));
FileContent *content = new FileContent();
content->setContentType(ContentType::FileTransfer);
content->setBody(linphone_content_get_string_buffer(initialContent));
marieMessage->addContent(content);
} else {
Content content;
content.setContentType(ContentType::PlainText);
content.setBody("Hello Part 2");
Content *content = new Content();
content->setContentType(ContentType::PlainText);
content->setBody("Hello Part 2");
marieMessage->addContent(content);
}
marieMessage->send();
......
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