mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 00:49:28 -05:00
Added size limit for chat types - Public, Private, Lobby, Distant
Set the size limit for private and distant chat to unlimited. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7761 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
93f77a0e2c
commit
55be6675af
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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<RsPeerId> &ids) = 0;
|
||||
virtual bool getPrivateChatQueue(bool incoming, const RsPeerId& id, std::list<ChatInfo> &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 ;
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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:"");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user