From d6c17a16837371c343389c88eafb1f3b19c288ad Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Mon, 5 Mar 2018 11:39:38 +0100 Subject: [PATCH] add priority header with 'non-urgent' valu to imdn & is-composing --- src/chat/chat-message/chat-message-p.h | 3 ++ src/chat/chat-message/chat-message.cpp | 3 ++ src/chat/chat-message/chat-message.h | 1 + src/chat/chat-room/chat-room.cpp | 32 +++++++++++-------- src/sip-tools/sip-headers.h | 43 ++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 src/sip-tools/sip-headers.h diff --git a/src/chat/chat-message/chat-message-p.h b/src/chat/chat-message/chat-message-p.h index ebca8138c..740900df0 100644 --- a/src/chat/chat-message/chat-message-p.h +++ b/src/chat/chat-message/chat-message-p.h @@ -160,7 +160,10 @@ private: bool isSecured = false; mutable bool isReadOnly = false; Content internalContent; + + // TODO: to replace salCustomheaders std::unordered_map customHeaders; + mutable LinphoneErrorInfo * errorInfo = nullptr; SalOp *salOp = nullptr; SalCustomHeader *salCustomHeaders = nullptr; diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index 7f76b9efe..4031ceedb 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -40,6 +40,7 @@ #include "core/core-p.h" #include "logger/logger.h" #include "chat/notification/imdn.h" +#include "sip-tools/sip-headers.h" #include "ortp/b64.h" @@ -402,7 +403,9 @@ void ChatMessagePrivate::sendImdn (Imdn::Type imdnType, LinphoneReason reason) { if (reason != LinphoneReasonNone) msg->getPrivate()->setEncryptionPrevented(true); + msg->setToBeStored(false); + msg->getPrivate()->addSalCustomHeader(PriorityHeader::HeaderName, PriorityHeader::NonUrgent); msg->getPrivate()->send(); } diff --git a/src/chat/chat-message/chat-message.h b/src/chat/chat-message/chat-message.h index 1108bcb70..5ed06b1e9 100644 --- a/src/chat/chat-message/chat-message.h +++ b/src/chat/chat-message/chat-message.h @@ -100,6 +100,7 @@ public: const Content &getInternalContent () const; void setInternalContent (const Content &content); + // TODO: to replace salCustomheaders std::string getCustomHeaderValue (const std::string &headerName) const; void addCustomHeader (const std::string &headerName, const std::string &headerValue); void removeCustomHeader (const std::string &headerName); diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index dc5e378f5..232ef6175 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -25,6 +25,7 @@ #include "chat/chat-message/chat-message-p.h" #include "chat/chat-room/chat-room-p.h" #include "core/core-p.h" +#include "sip-tools/sip-headers.h" // ============================================================================= @@ -50,7 +51,7 @@ void ChatRoomPrivate::sendChatMessage (const shared_ptr &chatMessag dChatMessage->setTime(ms_time(0)); dChatMessage->send(); - LinphoneChatRoom *cr = L_GET_C_BACK_PTR(q); + LinphoneChatRoom *cr = L_GET_C_BACK_PTR(q); // TODO: server currently don't stock message, remove condition in the future. if (!linphone_core_conference_server_enabled(q->getCore()->getCCore())) { shared_ptr event = static_pointer_cast( @@ -71,18 +72,23 @@ void ChatRoomPrivate::sendChatMessage (const shared_ptr &chatMessag void ChatRoomPrivate::sendIsComposingNotification () { L_Q(); LinphoneImNotifPolicy *policy = linphone_core_get_im_notif_policy(q->getCore()->getCCore()); - if (linphone_im_notif_policy_get_send_is_composing(policy)) { - string payload = isComposingHandler->marshal(isComposing); - if (!payload.empty()) { - shared_ptr chatMessage = createChatMessage(ChatMessage::Direction::Outgoing); - chatMessage->setToBeStored(false); - Content *content = new Content(); - content->setContentType(ContentType::ImIsComposing); - content->setBody(payload); - chatMessage->addContent(*content); - chatMessage->getPrivate()->send(); - } - } + if (!linphone_im_notif_policy_get_send_is_composing(policy)) + return; + + string payload = isComposingHandler->marshal(isComposing); + if (payload.empty()) + return; + + Content *content = new Content(); + content->setContentType(ContentType::ImIsComposing); + content->setBody(payload); + + shared_ptr chatMessage = createChatMessage(ChatMessage::Direction::Outgoing); + chatMessage->setToBeStored(false); + chatMessage->addContent(*content); + chatMessage->getPrivate()->addSalCustomHeader(PriorityHeader::HeaderName, PriorityHeader::NonUrgent); + + chatMessage->getPrivate()->send(); } // ----------------------------------------------------------------------------- diff --git a/src/sip-tools/sip-headers.h b/src/sip-tools/sip-headers.h new file mode 100644 index 000000000..969735841 --- /dev/null +++ b/src/sip-tools/sip-headers.h @@ -0,0 +1,43 @@ +/* + * sip-headers.h + * Copyright (C) 2010-2018 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _L_SIP_HEADERS_H_ +#define _L_SIP_HEADERS_H_ + +#include "linphone/utils/general.h" + +// ============================================================================= + +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +namespace PriorityHeader { + constexpr const char HeaderName[] = "Priority"; + + // Values + constexpr const char NonUrgent[] = "non-urgent"; + constexpr const char Urgent[] = "urgent"; + constexpr const char Emergency[] = "emergency"; + constexpr const char Normal[] = "normal"; +} + +LINPHONE_END_NAMESPACE + +#endif // _L_SIP_HEADERS_H_