diff --git a/include/linphone/api/c-chat-message.h b/include/linphone/api/c-chat-message.h index 1d6a2fb5c0ff669eaaceb7d3fa7800557612de45..369778c8ca42b856ebb2b29181c8058c138d1bf6 100644 --- a/include/linphone/api/c-chat-message.h +++ b/include/linphone/api/c-chat-message.h @@ -88,28 +88,28 @@ LINPHONE_PUBLIC time_t linphone_chat_message_get_time (const LinphoneChatMessage * Returns TRUE if the message has been sent, returns FALSE if the message has been received. * @param[in] msg #LinphoneChatMessage object. */ -LINPHONE_PUBLIC bool_t linphone_chat_message_is_outgoing (LinphoneChatMessage *msg); +LINPHONE_PUBLIC bool_t linphone_chat_message_is_outgoing (const LinphoneChatMessage *msg); /** * Get origin of the message * @param[in] msg #LinphoneChatMessage object. * @return #LinphoneAddress */ -LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_from_address (LinphoneChatMessage *msg); +LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_from_address (const LinphoneChatMessage *msg); /** * Get destination of the message * @param[in] msg #LinphoneChatMessage object. * @return #LinphoneAddress */ -LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_to_address (LinphoneChatMessage *msg); +LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_to_address (const LinphoneChatMessage *msg); /** * Get the content type of a chat message. * @param[in] msg #LinphoneChatMessage object. * @return The content type of the chat message */ -LINPHONE_PUBLIC const char *linphone_chat_message_get_content_type (LinphoneChatMessage *msg); +LINPHONE_PUBLIC const char *linphone_chat_message_get_content_type (const LinphoneChatMessage *msg); /** * Set the content type of a chat message. @@ -125,7 +125,7 @@ LINPHONE_PUBLIC void linphone_chat_message_set_content_type (LinphoneChatMessage * @return text or NULL if no text. * @deprecated use getTextContent() instead */ -LINPHONE_PUBLIC const char *linphone_chat_message_get_text (LinphoneChatMessage* msg); +LINPHONE_PUBLIC const char *linphone_chat_message_get_text (const LinphoneChatMessage* msg); /** * Get the message identifier. @@ -167,7 +167,7 @@ LINPHONE_PUBLIC LinphoneChatRoom *linphone_chat_message_get_chat_room (const Lin * @return The path to the file to use for the file transfer. * @deprecated use linphone_content_get_file_path() instead. */ -LINPHONE_PUBLIC const char *linphone_chat_message_get_file_transfer_filepath (LinphoneChatMessage *msg); +LINPHONE_PUBLIC const char *linphone_chat_message_get_file_transfer_filepath (const LinphoneChatMessage *msg); // ============================================================================= @@ -200,7 +200,7 @@ LINPHONE_PUBLIC LinphoneChatMessageState linphone_chat_message_get_state (const * @param[in] msg #LinphoneChatMessage object. * @return whether the message was encrypted when transfered or not */ -LINPHONE_PUBLIC bool_t linphone_chat_message_is_secured (LinphoneChatMessage *msg); +LINPHONE_PUBLIC bool_t linphone_chat_message_is_secured (const LinphoneChatMessage *msg); /** * Linphone message can carry external body as defined by rfc2017 @@ -223,21 +223,21 @@ LINPHONE_PUBLIC void linphone_chat_message_set_external_body_url (LinphoneChatMe * @param[in] msg #LinphoneChatMessage object. * @return a pointer to the #LinphoneContent structure or NULL if not present. */ -LINPHONE_PUBLIC LinphoneContent *linphone_chat_message_get_file_transfer_information (LinphoneChatMessage *msg); +LINPHONE_PUBLIC LinphoneContent *linphone_chat_message_get_file_transfer_information (const LinphoneChatMessage *msg); /** * Return whether or not a chat message is a file transfer. * @param[in] msg #LinphoneChatMessage object * @return Whether or not the message is a file transfer */ -LINPHONE_PUBLIC bool_t linphone_chat_message_is_file_transfer (LinphoneChatMessage *msg); +LINPHONE_PUBLIC bool_t linphone_chat_message_is_file_transfer (const LinphoneChatMessage *msg); /** * Return whether or not a chat message is a text. * @param[in] msg #LinphoneChatMessage object. * @return Whether or not the message is a text */ -LINPHONE_PUBLIC bool_t linphone_chat_message_is_text (LinphoneChatMessage *msg); +LINPHONE_PUBLIC bool_t linphone_chat_message_is_text (const LinphoneChatMessage *msg); /** * Start the download of the file from remote server @@ -288,14 +288,14 @@ LINPHONE_PUBLIC void linphone_chat_message_send (LinphoneChatMessage *msg); */ LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_chat_message_resend (LinphoneChatMessage *msg); -LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_peer_address (LinphoneChatMessage *msg); +LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_peer_address (const LinphoneChatMessage *msg); /** * Returns the origin address of a message if it was a outgoing message, or the destination address if it was an incoming message. * @param[in] msg #LinphoneChatMessage object. * @return #LinphoneAddress */ -LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_local_address (LinphoneChatMessage *msg); +LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_local_address (const LinphoneChatMessage *msg); /** * Add custom headers to the message. @@ -314,7 +314,7 @@ LINPHONE_PUBLIC void linphone_chat_message_add_custom_header ( * @param[in] msg #LinphoneChatMessage object. * @param header_name header name searched */ -LINPHONE_PUBLIC const char * linphone_chat_message_get_custom_header (LinphoneChatMessage *msg, const char *header_name); +LINPHONE_PUBLIC const char * linphone_chat_message_get_custom_header (const LinphoneChatMessage *msg, const char *header_name); /** * Removes a custom header from the message. @@ -327,9 +327,9 @@ LINPHONE_PUBLIC void linphone_chat_message_remove_custom_header (LinphoneChatMes * Returns TRUE if the message has been read, otherwise returns FALSE. * @param[in] msg #LinphoneChatMessage object. */ -LINPHONE_PUBLIC bool_t linphone_chat_message_is_read (LinphoneChatMessage *msg); +LINPHONE_PUBLIC bool_t linphone_chat_message_is_read (const LinphoneChatMessage *msg); -LINPHONE_PUBLIC LinphoneReason linphone_chat_message_get_reason (LinphoneChatMessage *msg); +LINPHONE_PUBLIC LinphoneReason linphone_chat_message_get_reason (const LinphoneChatMessage *msg); /** * Get full details about delivery error of a chat message. @@ -409,7 +409,7 @@ LINPHONE_PUBLIC const char *linphone_chat_message_get_text_content (const Linpho * @param[in] msg #LinphoneChatMessage object. * @return true if download or upload is in progress, false otherwise */ -LINPHONE_PUBLIC bool_t linphone_chat_message_is_file_transfer_in_progress (LinphoneChatMessage *msg); +LINPHONE_PUBLIC bool_t linphone_chat_message_is_file_transfer_in_progress (const LinphoneChatMessage *msg); /** * Gets the list of participants for which the imdn state has reached the specified state and the time at which they did. diff --git a/src/c-wrapper/api/c-chat-message.cpp b/src/c-wrapper/api/c-chat-message.cpp index ba5902da8ba0954466b7efe20d10784f40b65cf3..0ec345a4694e38aa2c1403f939f3e297a3f5f189 100644 --- a/src/c-wrapper/api/c-chat-message.cpp +++ b/src/c-wrapper/api/c-chat-message.cpp @@ -47,13 +47,15 @@ L_DECLARE_C_OBJECT_IMPL_WITH_XTORS(ChatMessage, _linphone_chat_message_destructor, LinphoneChatMessageCbs *cbs; - LinphoneAddress *from; // cache for shared_ptr<Address> - LinphoneAddress *to; // cache for shared_ptr<Address> LinphoneChatMessageStateChangedCb message_state_changed_cb; void *message_state_changed_user_data; struct Cache { ~Cache () { + if (from) + linphone_address_unref(from); + if (to) + linphone_address_unref(to); if (contents) bctbx_list_free(contents); } @@ -62,6 +64,9 @@ L_DECLARE_C_OBJECT_IMPL_WITH_XTORS(ChatMessage, string textContentBody; string customHeaderValue; + LinphoneAddress *from = nullptr; + LinphoneAddress *to = nullptr; + bctbx_list_t *contents = nullptr; } mutable cache; ) @@ -74,11 +79,6 @@ static void _linphone_chat_message_constructor (LinphoneChatMessage *msg) { static void _linphone_chat_message_destructor (LinphoneChatMessage *msg) { linphone_chat_message_cbs_unref(msg->cbs); msg->cbs = nullptr; - if (msg->from) - linphone_address_unref(msg->from); - if (msg->to) - linphone_address_unref(msg->to); - msg->cache.~Cache(); } @@ -127,11 +127,11 @@ time_t linphone_chat_message_get_time (const LinphoneChatMessage *msg) { return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getTime(); } -bool_t linphone_chat_message_is_secured (LinphoneChatMessage *msg) { +bool_t linphone_chat_message_is_secured (const LinphoneChatMessage *msg) { return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->isSecured(); } -bool_t linphone_chat_message_is_outgoing (LinphoneChatMessage *msg) { +bool_t linphone_chat_message_is_outgoing (const LinphoneChatMessage *msg) { return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getDirection() == LinphonePrivate::ChatMessage::Direction::Outgoing; } @@ -143,7 +143,7 @@ const char* linphone_chat_message_get_message_id (const LinphoneChatMessage *msg return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getImdnMessageId().c_str(); } -bool_t linphone_chat_message_is_read (LinphoneChatMessage *msg) { +bool_t linphone_chat_message_is_read (const LinphoneChatMessage *msg) { return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->isRead(); } @@ -155,21 +155,21 @@ void linphone_chat_message_set_appdata (LinphoneChatMessage *msg, const char *da L_GET_PRIVATE_FROM_C_OBJECT(msg)->setAppdata(L_C_TO_STRING(data)); } -const LinphoneAddress *linphone_chat_message_get_from_address (LinphoneChatMessage *msg) { - if (msg->from) - linphone_address_unref(msg->from); - msg->from = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getFromAddress().asString().c_str()); - return msg->from; +const LinphoneAddress *linphone_chat_message_get_from_address (const LinphoneChatMessage *msg) { + if (msg->cache.from) + linphone_address_unref(msg->cache.from); + msg->cache.from = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getFromAddress().asString().c_str()); + return msg->cache.from; } -const LinphoneAddress *linphone_chat_message_get_to_address (LinphoneChatMessage *msg) { - if (msg->to) - linphone_address_unref(msg->to); - msg->to = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getToAddress().asString().c_str()); - return msg->to; +const LinphoneAddress *linphone_chat_message_get_to_address (const LinphoneChatMessage *msg) { + if (msg->cache.to) + linphone_address_unref(msg->cache.to); + msg->cache.to = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getToAddress().asString().c_str()); + return msg->cache.to; } -const char *linphone_chat_message_get_file_transfer_filepath (LinphoneChatMessage *msg) { +const char *linphone_chat_message_get_file_transfer_filepath (const LinphoneChatMessage *msg) { return L_STRING_TO_C(L_GET_PRIVATE_FROM_C_OBJECT(msg)->getFileTransferFilepath()); } @@ -189,7 +189,7 @@ void linphone_chat_message_remove_custom_header (LinphoneChatMessage *msg, const L_GET_PRIVATE_FROM_C_OBJECT(msg)->removeSalCustomHeader(L_C_TO_STRING(header_name)); } -const char *linphone_chat_message_get_custom_header (LinphoneChatMessage *msg, const char *header_name) { +const char *linphone_chat_message_get_custom_header (const LinphoneChatMessage *msg, const char *header_name) { msg->cache.customHeaderValue = L_GET_PRIVATE_FROM_C_OBJECT(msg)->getSalCustomHeaderValue(L_C_TO_STRING(header_name)); return L_STRING_TO_C(msg->cache.customHeaderValue); } @@ -276,7 +276,7 @@ const char *linphone_chat_message_get_text_content (const LinphoneChatMessage *m return L_STRING_TO_C(msg->cache.textContentBody); } -bool_t linphone_chat_message_is_file_transfer_in_progress (LinphoneChatMessage *msg) { +bool_t linphone_chat_message_is_file_transfer_in_progress (const LinphoneChatMessage *msg) { return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->isFileTransferInProgress(); } @@ -300,7 +300,7 @@ bool_t linphone_chat_message_download_content (LinphoneChatMessage *msg, Linphon // Old listener // ============================================================================= -LinphoneChatMessageStateChangedCb linphone_chat_message_get_message_state_changed_cb(LinphoneChatMessage* msg) { +LinphoneChatMessageStateChangedCb linphone_chat_message_get_message_state_changed_cb (LinphoneChatMessage* msg) { return msg->message_state_changed_cb; } @@ -312,7 +312,7 @@ void linphone_chat_message_set_message_state_changed_cb_user_data (LinphoneChatM msg->message_state_changed_user_data = user_data; } -void * linphone_chat_message_get_message_state_changed_cb_user_data (LinphoneChatMessage* msg) { +void *linphone_chat_message_get_message_state_changed_cb_user_data (LinphoneChatMessage* msg) { return msg->message_state_changed_user_data; } @@ -320,7 +320,7 @@ void * linphone_chat_message_get_message_state_changed_cb_user_data (LinphoneCha // Structure has changed, hard to keep the behavior // ============================================================================= -const char *linphone_chat_message_get_content_type (LinphoneChatMessage *msg) { +const char *linphone_chat_message_get_content_type (const LinphoneChatMessage *msg) { msg->cache.contentType = L_GET_PRIVATE_FROM_C_OBJECT(msg)->getContentType().asString(); return L_STRING_TO_C(msg->cache.contentType); } @@ -329,7 +329,7 @@ void linphone_chat_message_set_content_type (LinphoneChatMessage *msg, const cha L_GET_PRIVATE_FROM_C_OBJECT(msg)->setContentType(LinphonePrivate::ContentType(L_C_TO_STRING(content_type))); } -const char *linphone_chat_message_get_text (LinphoneChatMessage *msg) { +const char *linphone_chat_message_get_text (const LinphoneChatMessage *msg) { return L_STRING_TO_C(L_GET_PRIVATE_FROM_C_OBJECT(msg)->getText()); } @@ -338,7 +338,7 @@ int linphone_chat_message_set_text (LinphoneChatMessage *msg, const char* text) return 0; } -LinphoneContent *linphone_chat_message_get_file_transfer_information (LinphoneChatMessage *msg) { +LinphoneContent *linphone_chat_message_get_file_transfer_information (const LinphoneChatMessage *msg) { const LinphonePrivate::Content *content = L_GET_PRIVATE_FROM_C_OBJECT(msg)->getFileTransferInformation(); if (content) return L_GET_C_BACK_PTR(content); return NULL; @@ -352,25 +352,25 @@ bool_t linphone_chat_message_download_file (LinphoneChatMessage *msg) { // Nothing to do, they call other C API methods // ============================================================================= -const LinphoneAddress *linphone_chat_message_get_peer_address (LinphoneChatMessage *msg) { +const LinphoneAddress *linphone_chat_message_get_peer_address (const LinphoneChatMessage *msg) { return linphone_chat_room_get_peer_address(linphone_chat_message_get_chat_room(msg)); } -const LinphoneAddress *linphone_chat_message_get_local_address (LinphoneChatMessage *msg) { +const LinphoneAddress *linphone_chat_message_get_local_address (const LinphoneChatMessage *msg) { if (L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getDirection() == LinphonePrivate::ChatMessage::Direction::Outgoing) return linphone_chat_message_get_from_address(msg); return linphone_chat_message_get_to_address(msg); } -LinphoneReason linphone_chat_message_get_reason (LinphoneChatMessage *msg) { +LinphoneReason linphone_chat_message_get_reason (const LinphoneChatMessage *msg) { return linphone_error_info_get_reason(linphone_chat_message_get_error_info(msg)); } -bool_t linphone_chat_message_is_file_transfer (LinphoneChatMessage *msg) { +bool_t linphone_chat_message_is_file_transfer (const LinphoneChatMessage *msg) { return L_GET_PRIVATE_FROM_C_OBJECT(msg)->hasFileTransferContent(); } -bool_t linphone_chat_message_is_text (LinphoneChatMessage *msg) { +bool_t linphone_chat_message_is_text (const LinphoneChatMessage *msg) { return L_GET_PRIVATE_FROM_C_OBJECT(msg)->hasTextContent(); } diff --git a/src/chat/chat-message/chat-message-p.h b/src/chat/chat-message/chat-message-p.h index 181a901e6533a0f021d190a5e0248196c02f4e83..4a3e4400e0b60aaac0e46b3efd061b1d92c82278 100644 --- a/src/chat/chat-message/chat-message-p.h +++ b/src/chat/chat-message/chat-message-p.h @@ -112,7 +112,7 @@ public: void addSalCustomHeader (const std::string &name, const std::string &value); void removeSalCustomHeader (const std::string &name); - std::string getSalCustomHeaderValue (const std::string &name); + std::string getSalCustomHeaderValue (const std::string &name) const; void loadFileTransferUrlFromBodyToContent (); std::string createFakeFileTransferFromUrl(const std::string &url); @@ -125,10 +125,10 @@ public: // Deprecated methods only used for C wrapper, to be removed some day... // ----------------------------------------------------------------------------- - const ContentType &getContentType (); + const ContentType &getContentType () const; void setContentType (const ContentType &contentType); - const std::string &getText (); + const std::string &getText () const; void setText (const std::string &text); const std::string &getFileTransferFilepath () const; @@ -197,8 +197,8 @@ private: // Cache for returned values, used for compatibility with previous C API std::string fileTransferFilePath; - ContentType cContentType; - std::string cText; + mutable ContentType cContentType; + mutable std::string cText; // TODO: Remove my comment. VARIABLES OK. // Do not expose. diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index 6e400d474e7d692604c28b8e1b627305b2eb4ab8..011a575279843c16af668827a42f713d685c2969 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -201,7 +201,7 @@ void ChatMessagePrivate::removeSalCustomHeader (const string &name) { salCustomHeaders = sal_custom_header_remove(salCustomHeaders, name.c_str()); } -string ChatMessagePrivate::getSalCustomHeaderValue (const string &name) { +string ChatMessagePrivate::getSalCustomHeaderValue (const string &name) const { return L_C_TO_STRING(sal_custom_header_find(salCustomHeaders, name.c_str())); } @@ -289,7 +289,7 @@ void ChatMessagePrivate::setExternalBodyUrl (const string &url) { externalBodyUrl = url; } -const ContentType &ChatMessagePrivate::getContentType () { +const ContentType &ChatMessagePrivate::getContentType () const { loadContentsFromDatabase(); if (direction == ChatMessage::Direction::Incoming) { if (contents.size() > 0) { @@ -325,7 +325,7 @@ void ChatMessagePrivate::setContentType (const ContentType &contentType) { } } -const string &ChatMessagePrivate::getText () { +const string &ChatMessagePrivate::getText () const { loadContentsFromDatabase(); if (direction == ChatMessage::Direction::Incoming) { if (hasTextContent()) { @@ -1082,7 +1082,7 @@ bool ChatMessage::downloadFile(FileTransferContent *fileTransferContent) { return d->fileTransferChatMessageModifier.downloadFile(getSharedFromThis(), fileTransferContent); } -bool ChatMessage::isFileTransferInProgress() { +bool ChatMessage::isFileTransferInProgress () const { L_D(); return d->fileTransferChatMessageModifier.isFileTransferInProgressAndValid(); } diff --git a/src/chat/chat-message/chat-message.h b/src/chat/chat-message/chat-message.h index 966c086639f9719e01a6f13f1872f22dac254ba1..c07077d4271024f8f1e7a8189a4495a84e05210b 100644 --- a/src/chat/chat-message/chat-message.h +++ b/src/chat/chat-message/chat-message.h @@ -110,7 +110,7 @@ public: void removeCustomHeader (const std::string &headerName); bool downloadFile (FileTransferContent *content); - bool isFileTransferInProgress(); + bool isFileTransferInProgress () const; protected: explicit ChatMessage (ChatMessagePrivate &p); diff --git a/src/chat/modifier/file-transfer-chat-message-modifier.cpp b/src/chat/modifier/file-transfer-chat-message-modifier.cpp index ce9d905b9c42c8fe8d89653c14a040dfb9ec7038..d66d25c959f02aec63718935aedb3644703f6d14 100644 --- a/src/chat/modifier/file-transfer-chat-message-modifier.cpp +++ b/src/chat/modifier/file-transfer-chat-message-modifier.cpp @@ -1016,7 +1016,7 @@ void FileTransferChatMessageModifier::cancelFileTransfer () { releaseHttpRequest(); } -bool FileTransferChatMessageModifier::isFileTransferInProgressAndValid () { +bool FileTransferChatMessageModifier::isFileTransferInProgressAndValid () const { return httpRequest && !belle_http_request_is_cancelled(httpRequest); } diff --git a/src/chat/modifier/file-transfer-chat-message-modifier.h b/src/chat/modifier/file-transfer-chat-message-modifier.h index d2dde9b7dbdd77e86a39cd88a58e322312b6e7c4..f0716e0db61f63308f0a455ed8eb8d4156c46d41 100644 --- a/src/chat/modifier/file-transfer-chat-message-modifier.h +++ b/src/chat/modifier/file-transfer-chat-message-modifier.h @@ -62,7 +62,7 @@ public: bool downloadFile (const std::shared_ptr<ChatMessage> &message, FileTransferContent *fileTransferContent); void cancelFileTransfer (); - bool isFileTransferInProgressAndValid (); + bool isFileTransferInProgressAndValid () const; std::string createFakeFileTransferFromUrl (const std::string &url); private: