diff --git a/libretroshare/src/chat/p3chatservice.cc b/libretroshare/src/chat/p3chatservice.cc index e3734b7e4..c34ce69f8 100644 --- a/libretroshare/src/chat/p3chatservice.cc +++ b/libretroshare/src/chat/p3chatservice.cc @@ -509,25 +509,42 @@ void p3ChatService::handleRecvChatAvatarItem(RsChatAvatarItem *ca) RsServer::notify()->notifyPeerHasNewAvatar(ca->PeerId().toStdString()) ; } -int p3ChatService::getMaxMessageSecuritySize() +uint32_t p3ChatService::getMaxMessageSecuritySize(int type) { + switch (type) + { + case RS_CHAT_TYPE_PUBLIC: + case RS_CHAT_TYPE_LOBBY: + return MAX_MESSAGE_SECURITY_SIZE; + + case RS_CHAT_TYPE_PRIVATE: + case RS_CHAT_TYPE_DISTANT: + return 0; // unlimited + } + + std::cerr << "p3ChatService::getMaxMessageSecuritySize: Unknown chat type " << type << std::endl; + return MAX_MESSAGE_SECURITY_SIZE; } bool p3ChatService::checkForMessageSecurity(RsChatMsgItem *ci) { // Remove too big messages - if (ci->message.length() > MAX_MESSAGE_SECURITY_SIZE && (ci->chatFlags & RS_CHAT_FLAG_LOBBY)) + if (ci->chatFlags & RS_CHAT_FLAG_LOBBY) { - std::ostringstream os; - os << getMaxMessageSecuritySize(); + uint32_t maxMessageSize = getMaxMessageSecuritySize(RS_CHAT_TYPE_LOBBY); + if (maxMessageSize > 0 && ci->message.length() > maxMessageSize) + { + std::ostringstream os; + os << getMaxMessageSecuritySize(RS_CHAT_TYPE_LOBBY); - ci->message = "**** Security warning: Message bigger than "; - ci->message += os.str(); - ci->message += " characters, forwarded to you by "; - ci->message += rsPeers->getPeerName(ci->PeerId()); - ci->message += ", dropped. ****"; - return false; + ci->message = "**** Security warning: Message bigger than "; + ci->message += os.str(); + ci->message += " characters, forwarded to you by "; + ci->message += rsPeers->getPeerName(ci->PeerId()); + ci->message += ", dropped. ****"; + return false; + } } // The following code has been suggested, but is kept suspended since it is a bit too much restrictive. diff --git a/libretroshare/src/chat/p3chatservice.h b/libretroshare/src/chat/p3chatservice.h index a90ff93c6..ce5d5341f 100644 --- a/libretroshare/src/chat/p3chatservice.h +++ b/libretroshare/src/chat/p3chatservice.h @@ -159,8 +159,10 @@ class p3ChatService: public p3Service, public DistantChatService, public Distrib /*! * Return the max message size for security forwarding + * @param type RS_CHAT_TYPE_... + * return 0 unlimited */ - static int getMaxMessageSecuritySize(); + static uint32_t getMaxMessageSecuritySize(int type); /*! * Checks message security, especially remove billion laughs attacks diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 4410d9aeb..ffa6c194c 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -83,6 +83,11 @@ #define RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC 1 /* lobby is visible by friends. Friends can connect.*/ #define RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE 2 /* lobby invisible by friends. Peers on invitation only .*/ +#define RS_CHAT_TYPE_PUBLIC 1 +#define RS_CHAT_TYPE_PRIVATE 2 +#define RS_CHAT_TYPE_LOBBY 3 +#define RS_CHAT_TYPE_DISTANT 4 + const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE( 0x00000001 ) ; typedef uint64_t ChatLobbyId ; @@ -384,7 +389,7 @@ virtual int getPrivateChatQueueCount(bool incoming) = 0; virtual bool getPrivateChatQueueIds(bool incoming, std::list &ids) = 0; virtual bool getPrivateChatQueue(bool incoming, const RsPeerId& id, std::list &chats) = 0; virtual bool clearPrivateChatQueue(bool incoming, const RsPeerId& id) = 0; -virtual int getMaxMessageSecuritySize() = 0; +virtual uint32_t getMaxMessageSecuritySize(int type) = 0; virtual void sendStatusString(const RsPeerId& id,const std::string& status_string) = 0 ; virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 029666c07..20afa09de 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -252,9 +252,9 @@ bool p3Msgs::clearPrivateChatQueue(bool incoming, const RsPeerId& id) return mChatSrv->clearPrivateChatQueue(incoming, id); } -int p3Msgs::getMaxMessageSecuritySize() +uint32_t p3Msgs::getMaxMessageSecuritySize(int type) { - return mChatSrv->getMaxMessageSecuritySize(); + return mChatSrv->getMaxMessageSecuritySize(type); } void p3Msgs::getOwnAvatarData(unsigned char *& data,int& size) diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index eb22e6ac7..0bbaf393d 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -161,7 +161,7 @@ class p3Msgs: public RsMsgs /*! * Return the max message size for security forwarding */ - virtual int getMaxMessageSecuritySize(); + virtual uint32_t getMaxMessageSecuritySize(int type); /*! * sends immediate status string to a specific peer, e.g. in a private chat diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index eb3256cb4..9c7e15e8f 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -848,10 +848,29 @@ void ChatWidget::updateLenOfChatTextEdit() QString text; RsHtml::optimizeHtml(chatWidget, text); std::wstring msg = text.toStdWString(); - bool msgToLarge = (msg.length()>=size_t(rsMsgs->getMaxMessageSecuritySize())); + + uint32_t maxMessageSize = 0; + switch (chatType()) { + case CHATTYPE_UNKNOWN: + break; + case CHATTYPE_PRIVATE: + maxMessageSize = rsMsgs->getMaxMessageSecuritySize(RS_CHAT_TYPE_PRIVATE); + break; + case CHATTYPE_LOBBY: + maxMessageSize = rsMsgs->getMaxMessageSecuritySize(RS_CHAT_TYPE_LOBBY); + break; + case CHATTYPE_DISTANT: + maxMessageSize = rsMsgs->getMaxMessageSecuritySize(RS_CHAT_TYPE_DISTANT); + break; + } + + bool msgToLarge = false; + if (maxMessageSize > 0) { + msgToLarge = (msg.length() >= maxMessageSize); + } ui->sendButton->setEnabled(!msgToLarge); - text = tr("%1This message counts %2 characters.").arg(msgToLarge?tr("Warning: "):"").arg(msg.length()); + text = tr("%1This message counts %2 characters.").arg(msgToLarge ? tr("Warning: ") : "").arg(msg.length()); ui->sendButton->setToolTip(text); ui->chatTextEdit->setToolTip(msgToLarge?text:""); }