diff --git a/src/c-wrapper/api/c-chat-message.cpp b/src/c-wrapper/api/c-chat-message.cpp
index 0695bb0f5..1b14f8829 100644
--- a/src/c-wrapper/api/c-chat-message.cpp
+++ b/src/c-wrapper/api/c-chat-message.cpp
@@ -94,7 +94,9 @@ LinphoneChatRoom *linphone_chat_message_get_chat_room(const LinphoneChatMessage
}
const char *linphone_chat_message_get_external_body_url(const LinphoneChatMessage *msg) {
- return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getExternalBodyUrl().c_str();
+ const string& external_body_url = L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getExternalBodyUrl();
+ if (external_body_url.empty()) return NULL;
+ return external_body_url.c_str();
}
void linphone_chat_message_set_external_body_url(LinphoneChatMessage *msg, const char *url) {
@@ -162,7 +164,9 @@ bool_t linphone_chat_message_is_read(LinphoneChatMessage *msg) {
}
const char *linphone_chat_message_get_appdata(const LinphoneChatMessage *msg) {
- return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getAppdata().c_str();
+ const string& appData = L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getAppdata();
+ if (appData.empty()) return NULL;
+ return appData.c_str();
}
void linphone_chat_message_set_appdata(LinphoneChatMessage *msg, const char *data) {
@@ -192,7 +196,9 @@ const LinphoneAddress *linphone_chat_message_get_to_address(LinphoneChatMessage
}
const char *linphone_chat_message_get_file_transfer_filepath(LinphoneChatMessage *msg) {
- return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getFileTransferFilepath().c_str();
+ const string& path = L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getFileTransferFilepath();
+ if (path.empty()) return NULL;
+ return path.c_str();
}
void linphone_chat_message_set_file_transfer_filepath(LinphoneChatMessage *msg, const char *filepath) {
@@ -241,7 +247,9 @@ void linphone_chat_message_remove_custom_header(LinphoneChatMessage *msg, const
}
const char *linphone_chat_message_get_custom_header(LinphoneChatMessage *msg, const char *header_name) {
- return L_GET_PRIVATE_FROM_C_OBJECT(msg)->getSalCustomHeaderValue(header_name).c_str();
+ const string& header = L_GET_PRIVATE_FROM_C_OBJECT(msg)->getSalCustomHeaderValue(header_name);
+ if (header.empty()) return NULL;
+ return header.c_str();
}
const LinphoneErrorInfo *linphone_chat_message_get_error_info(const LinphoneChatMessage *msg) {
@@ -321,7 +329,9 @@ void * linphone_chat_message_get_message_state_changed_cb_user_data(LinphoneChat
// =============================================================================
const char * linphone_chat_message_get_content_type(const LinphoneChatMessage *msg) {
- return L_GET_PRIVATE_FROM_C_OBJECT(msg)->getContentType().c_str();
+ const string& contentType = L_GET_PRIVATE_FROM_C_OBJECT(msg)->getContentType();
+ if (contentType.empty()) return NULL;
+ return contentType.c_str();
}
void linphone_chat_message_set_content_type(LinphoneChatMessage *msg, const char *content_type) {
@@ -329,7 +339,9 @@ void linphone_chat_message_set_content_type(LinphoneChatMessage *msg, const char
}
const char *linphone_chat_message_get_text(const LinphoneChatMessage *msg) {
- return L_GET_PRIVATE_FROM_C_OBJECT(msg)->getText().c_str();
+ const string& text = L_GET_PRIVATE_FROM_C_OBJECT(msg)->getText();
+ if (text.empty()) return NULL;
+ return text.c_str();
}
int linphone_chat_message_set_text(LinphoneChatMessage *msg, const char* text) {
diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp
index 02fd19102..8c3c6a8a5 100644
--- a/src/c-wrapper/api/c-chat-room.cpp
+++ b/src/c-wrapper/api/c-chat-room.cpp
@@ -72,7 +72,9 @@ void linphone_chat_room_remove_transient_message (LinphoneChatRoom *cr, Linphone
}
void linphone_chat_room_send_message (LinphoneChatRoom *cr, const char *msg) {
- L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(msg));
+ LinphoneChatMessage *message = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(msg);
+ ms_error("%s / %s", linphone_chat_message_get_text(message), linphone_chat_message_get_content_type(message));
+ L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(message);
}
bool_t linphone_chat_room_is_remote_composing (const LinphoneChatRoom *cr) {
diff --git a/src/chat/chat-message-p.h b/src/chat/chat-message-p.h
index fab4e79d9..f062be033 100644
--- a/src/chat/chat-message-p.h
+++ b/src/chat/chat-message-p.h
@@ -65,11 +65,11 @@ public:
// Methods only used for C wrapper
// -----------------------------------------------------------------------------
- std::string getContentType() const;
- void setContentType(std::string contentType);
+ const std::string& getContentType() const;
+ void setContentType(const std::string& contentType);
- std::string getText() const;
- void setText(std::string text);
+ const std::string& getText() const;
+ void setText(const std::string& text);
LinphoneContent * getFileTransferInformation() const;
void setFileTransferInformation(LinphoneContent *content);
@@ -104,11 +104,11 @@ private:
std::shared_ptr
from;
std::shared_ptr to;
time_t time = 0;
- std::string id;
- std::string appData;
- std::string fileTransferFilePath;
- std::string externalBodyUrl;
- std::string rttMessage;
+ std::string id = "";
+ std::string appData = "";
+ std::string fileTransferFilePath = "";
+ std::string externalBodyUrl = "";
+ std::string rttMessage = "";
bool isSecured = false;
bool isReadOnly = false;
bool isToBeStored = false;
@@ -116,16 +116,16 @@ private:
std::shared_ptr internalContent;
std::unordered_map customHeaders;
std::shared_ptr eventsDb;
- mutable LinphoneErrorInfo * errorInfo;
- belle_http_request_t *httpRequest;
- belle_http_request_listener_t *httpListener;
- SalOp *salOp;
- SalCustomHeader *salCustomHeaders;
+ mutable LinphoneErrorInfo * errorInfo = NULL;
+ belle_http_request_t *httpRequest = NULL;
+ belle_http_request_listener_t *httpListener = NULL;
+ SalOp *salOp = NULL;
+ SalCustomHeader *salCustomHeaders = NULL;
unsigned long backgroundTaskId;
// Used for compatibility with previous C API
- std::string cContentType;
- std::string cText;
- LinphoneContent *cFileTransferInformation;
+ std::string cContentType = "";
+ std::string cText = "";
+ LinphoneContent *cFileTransferInformation = NULL;
// -----------------------------------------------------------------------------
diff --git a/src/chat/chat-message.cpp b/src/chat/chat-message.cpp
index 6ad7fa3cc..65fb33b70 100644
--- a/src/chat/chat-message.cpp
+++ b/src/chat/chat-message.cpp
@@ -46,7 +46,8 @@ using namespace std;
// =============================================================================
ChatMessagePrivate::ChatMessagePrivate (const shared_ptr &room)
-: chatRoom(room) {}
+: chatRoom(room) {
+}
ChatMessagePrivate::~ChatMessagePrivate () {}
@@ -132,19 +133,19 @@ string ChatMessagePrivate::getSalCustomHeaderValue(string name) {
// -----------------------------------------------------------------------------
-string ChatMessagePrivate::getContentType() const {
+const string& ChatMessagePrivate::getContentType() const {
return cContentType;
}
-void ChatMessagePrivate::setContentType(string contentType) {
+void ChatMessagePrivate::setContentType(const string& contentType) {
cContentType = contentType;
}
-string ChatMessagePrivate::getText() const {
+const string& ChatMessagePrivate::getText() const {
return cText;
}
-void ChatMessagePrivate::setText(string text) {
+void ChatMessagePrivate::setText(const string& text) {
cText = text;
}
@@ -876,7 +877,7 @@ shared_ptr ChatMessage::getChatRoom () const {
// -----------------------------------------------------------------------------
-string ChatMessage::getExternalBodyUrl() const {
+const string& ChatMessage::getExternalBodyUrl() const {
L_D();
return d->externalBodyUrl;
}
@@ -921,12 +922,12 @@ ChatMessage::State ChatMessage::getState() const {
return d->state;
}
-string ChatMessage::getId () const {
+const string& ChatMessage::getId () const {
L_D();
return d->id;
}
-void ChatMessage::setId (string id) {
+void ChatMessage::setId (const string& id) {
L_D();
d->id = id;
}
@@ -941,7 +942,7 @@ bool ChatMessage::isRead() const {
return d->state == Delivered || d->state == Displayed || d->state == DeliveredToUser;
}
-string ChatMessage::getAppdata () const {
+const string& ChatMessage::getAppdata () const {
L_D();
return d->appData;
}
@@ -972,7 +973,7 @@ void ChatMessage::setToAddress(shared_ptr to) {
d->to = to;
}
-string ChatMessage::getFileTransferFilepath() const {
+const string& ChatMessage::getFileTransferFilepath() const {
L_D();
return d->fileTransferFilePath;
}
@@ -1035,7 +1036,7 @@ string ChatMessage::getCustomHeaderValue (const string &headerName) const {
} catch (const exception &) {
// Key doesn't exist.
}
- return "";
+ return nullptr;
}
void ChatMessage::addCustomHeader (const string &headerName, const string &headerValue) {
@@ -1080,8 +1081,6 @@ void ChatMessage::send () {
ccmm.encode(d);
}
- // TODO.
-
d->isReadOnly = true;
}
diff --git a/src/chat/chat-message.h b/src/chat/chat-message.h
index bf0ec5a29..153bab0aa 100644
--- a/src/chat/chat-message.h
+++ b/src/chat/chat-message.h
@@ -87,7 +87,7 @@ public:
bool isOutgoing () const;
bool isIncoming () const;
- std::string getExternalBodyUrl() const;
+ const std::string& getExternalBodyUrl() const;
void setExternalBodyUrl(const std::string &url);
time_t getTime () const;
@@ -97,12 +97,12 @@ public:
State getState() const;
- std::string getId () const;
- void setId (std::string);
+ const std::string& getId () const;
+ void setId (const std::string&);
bool isRead() const;
- std::string getAppdata () const;
+ const std::string& getAppdata () const;
void setAppdata (const std::string &appData);
std::shared_ptr getFromAddress () const;
@@ -111,7 +111,7 @@ public:
std::shared_ptr getToAddress () const;
void setToAddress(std::shared_ptr to);
- std::string getFileTransferFilepath() const;
+ const std::string& getFileTransferFilepath() const;
void setFileTransferFilepath(const std::string &path);
bool isToBeStored() const;
diff --git a/src/chat/chat-room.cpp b/src/chat/chat-room.cpp
index 2cd001716..8557d2fb1 100644
--- a/src/chat/chat-room.cpp
+++ b/src/chat/chat-room.cpp
@@ -27,7 +27,7 @@
#include "imdn.h"
#include "logger/logger.h"
-#include "chat-message.h"
+#include "chat-message-p.h"
#include "chat-room.h"
// =============================================================================
@@ -592,31 +592,28 @@ void ChatRoom::compose () {
LinphoneChatMessage *ChatRoom::createFileTransferMessage (const LinphoneContent *initialContent) {
L_D();
- LinphoneChatMessage *msg = createMessage("");
- linphone_chat_message_set_text(msg, NULL);
- linphone_chat_message_set_file_transfer_information(msg, linphone_content_copy(initialContent));
- linphone_chat_message_set_outgoing(msg);
- LinphoneAddress *peer = linphone_address_new(d->peerAddress.asString().c_str());
- linphone_chat_message_set_to_address(msg, peer);
- linphone_address_unref(peer);
- linphone_chat_message_set_from_address(msg, linphone_address_new(linphone_core_get_identity(d->core)));
- /* This will be set to application/vnd.gsma.rcs-ft-http+xml when we will transfer the xml reply from server to the peers */
- linphone_chat_message_set_content_type(msg, NULL);
- /* This will store the http request during file upload to the server */
- linphone_chat_message_set_http_request(msg, NULL);
- linphone_chat_message_set_time(msg, ms_time(0));
+
+ shared_ptr chatMessage = make_shared(static_pointer_cast(shared_from_this()));
+
+ chatMessage->getPrivate()->setTime(ms_time(0));
+ chatMessage->getPrivate()->setContentType("text/plain");
+ chatMessage->getPrivate()->setDirection(ChatMessage::Direction::Outgoing);
+ chatMessage->getPrivate()->setFileTransferInformation(linphone_content_copy(initialContent));
+ chatMessage->setToAddress(make_shared(d->peerAddress.asString().c_str()));
+ chatMessage->setFromAddress(make_shared(linphone_core_get_identity(d->core)));
+
+ LinphoneChatMessage *msg = chatMessage->getBackPtr();
return msg;
}
LinphoneChatMessage *ChatRoom::createMessage (const string &message) {
shared_ptr chatMessage = make_shared(static_pointer_cast(shared_from_this()));
+
+ chatMessage->getPrivate()->setTime(ms_time(0));
+ chatMessage->getPrivate()->setContentType("text/plain");
+ chatMessage->getPrivate()->setText(message);
+
LinphoneChatMessage *msg = chatMessage->getBackPtr();
- linphone_chat_message_set_state(msg, LinphoneChatMessageStateIdle);
- linphone_chat_message_set_text(msg, message.empty() ? nullptr : ms_strdup(message.c_str()));
- linphone_chat_message_set_content_type(msg, ms_strdup("text/plain"));
- linphone_chat_message_set_file_transfer_information(msg, nullptr);
- linphone_chat_message_set_http_request(msg, NULL);
- linphone_chat_message_set_time(msg, ms_time(0));
return msg;
}