mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-22 22:21:09 -04:00
changed std::wstring for std::string+utf8 in chat, and messages
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@6795 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
420fadb5c3
commit
695e417fd5
24 changed files with 132 additions and 135 deletions
|
@ -141,7 +141,7 @@ int p3ChatService::status()
|
|||
|
||||
/***************** Chat Stuff **********************/
|
||||
|
||||
int p3ChatService::sendPublicChat(const std::wstring &msg)
|
||||
int p3ChatService::sendPublicChat(const std::string &msg)
|
||||
{
|
||||
/* go through all the peers */
|
||||
|
||||
|
@ -460,7 +460,7 @@ bool p3ChatService::isOnline(const std::string& id)
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool p3ChatService::sendPrivateChat(const std::string &id, const std::wstring &msg)
|
||||
bool p3ChatService::sendPrivateChat(const std::string &id, const std::string &msg)
|
||||
{
|
||||
// look into ID. Is it a peer, or a chat lobby?
|
||||
|
||||
|
@ -643,7 +643,7 @@ bool p3ChatService::locked_checkAndRebuildPartialMessage(RsChatLobbyMsgItem *ci)
|
|||
#ifdef CHAT_DEBUG
|
||||
std::cerr << " Message is complete ! Re-forming it and returning true." << std::endl;
|
||||
#endif
|
||||
std::wstring msg ;
|
||||
std::string msg ;
|
||||
uint32_t flags = 0 ;
|
||||
|
||||
for(uint32_t i=0;i<it->second.size();++i)
|
||||
|
@ -998,20 +998,18 @@ bool p3ChatService::checkForMessageSecurity(RsChatMsgItem *ci)
|
|||
// https://en.wikipedia.org/wiki/Billion_laughs
|
||||
// This should be done for all incoming HTML messages (also in forums
|
||||
// etc.) so this should be a function in some other file.
|
||||
wchar_t tmp[10];
|
||||
mbstowcs(tmp, "<!", 9);
|
||||
|
||||
if (ci->message.find(tmp) != std::string::npos)
|
||||
if (ci->message.find("<!") != std::string::npos)
|
||||
{
|
||||
// Drop any message with "<!doctype" or "<!entity"...
|
||||
// TODO: check what happens with partial messages
|
||||
//
|
||||
std::wcout << "handleRecvChatMsgItem: " << ci->message << std::endl;
|
||||
std::wcout << "**********" << std::endl;
|
||||
std::wcout << "********** entity attack by " << ci->PeerId().c_str() << std::endl;
|
||||
std::wcout << "**********" << std::endl;
|
||||
std::cout << "handleRecvChatMsgItem: " << ci->message << std::endl;
|
||||
std::cout << "**********" << std::endl;
|
||||
std::cout << "********** entity attack by " << ci->PeerId().c_str() << std::endl;
|
||||
std::cout << "**********" << std::endl;
|
||||
|
||||
ci->message = L"**** This message has been removed because it breaks security rules.****" ;
|
||||
ci->message = "**** This message has been removed because it breaks security rules.****" ;
|
||||
return false;
|
||||
}
|
||||
// For a future whitelist:
|
||||
|
@ -1146,8 +1144,9 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *ci)
|
|||
ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
||||
}
|
||||
|
||||
std::string message;
|
||||
librs::util::ConvertUtf16ToUtf8(ci->message, message);
|
||||
std::string message = ci->message;
|
||||
//librs::util::ConvertUtf16ToUtf8(ci->message, message);
|
||||
|
||||
if (ci->chatFlags & RS_CHAT_FLAG_PRIVATE) {
|
||||
/* notify private chat message */
|
||||
getPqiNotify()->AddPopupMessage(popupChatFlag, ci->PeerId(), name, message);
|
||||
|
@ -1691,7 +1690,7 @@ void p3ChatService::sendAvatarJpegData(const std::string& peer_id)
|
|||
RsChatAvatarItem *ci = makeOwnAvatarItem();
|
||||
ci->PeerId(peer_id);
|
||||
|
||||
// take avatar, and embed it into a std::wstring.
|
||||
// take avatar, and embed it into a std::string.
|
||||
//
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::sending avatar image to peer" << peer_id << ", image size = " << ci->image_size << std::endl ;
|
||||
|
@ -2142,7 +2141,7 @@ void p3ChatService::locked_initLobbyBouncableObject(const ChatLobbyId& lobby_id,
|
|||
item.nick = lobby.nick_name ;
|
||||
}
|
||||
|
||||
bool p3ChatService::sendLobbyChat(const std::string &id, const std::wstring& msg, const ChatLobbyId& lobby_id)
|
||||
bool p3ChatService::sendLobbyChat(const std::string &id, const std::string& msg, const ChatLobbyId& lobby_id)
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Sending chat lobby message to lobby " << std::hex << lobby_id << std::dec << std::endl;
|
||||
|
@ -2461,7 +2460,7 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id)
|
|||
item->lobby_id = entry.lobby_id ;
|
||||
item->msg_id = 0 ;
|
||||
item->nick = "Lobby management" ;
|
||||
item->message = std::wstring(L"Welcome to chat lobby") ;
|
||||
item->message = std::string("Welcome to chat lobby") ;
|
||||
item->PeerId(entry.virtual_peer_id) ;
|
||||
item->chatFlags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_LOBBY ;
|
||||
|
||||
|
|
|
@ -70,14 +70,14 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
|
|||
/*!
|
||||
* public chat sent to all peers
|
||||
*/
|
||||
int sendPublicChat(const std::wstring &msg);
|
||||
int sendPublicChat(const std::string &msg);
|
||||
|
||||
/********* RsMsgs ***********/
|
||||
/*!
|
||||
* chat is sent to specifc peer
|
||||
* @param id peer to send chat msg to
|
||||
*/
|
||||
bool sendPrivateChat(const std::string &id, const std::wstring &msg);
|
||||
bool sendPrivateChat(const std::string &id, const std::string &msg);
|
||||
|
||||
/*!
|
||||
* can be used to send 'immediate' status msgs, these status updates are meant for immediate use by peer (not saved by rs)
|
||||
|
@ -244,7 +244,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
|
|||
|
||||
/// receive and handle chat lobby item
|
||||
bool recvLobbyChat(RsChatLobbyMsgItem*,const std::string& src_peer_id) ;
|
||||
bool sendLobbyChat(const std::string &id, const std::wstring&, const ChatLobbyId&) ;
|
||||
bool sendLobbyChat(const std::string &id, const std::string&, const ChatLobbyId&) ;
|
||||
void handleRecvLobbyInvite(RsChatLobbyInviteItem*) ;
|
||||
void checkAndRedirectMsgToLobby(RsChatMsgItem*) ;
|
||||
void handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item) ;
|
||||
|
|
|
@ -138,14 +138,10 @@ void p3MsgService::processMsg(RsMsgItem *mi, bool incoming)
|
|||
pqiNotify *notify = getPqiNotify();
|
||||
if (notify)
|
||||
{
|
||||
std::string title, message;
|
||||
librs::util::ConvertUtf16ToUtf8(mi->subject, title);
|
||||
librs::util::ConvertUtf16ToUtf8(mi->message, message);
|
||||
|
||||
if(mi->msgFlags & RS_MSG_FLAGS_ENCRYPTED)
|
||||
notify->AddPopupMessage(RS_POPUP_ENCRYPTED_MSG, mi->PeerId(), title, message);
|
||||
notify->AddPopupMessage(RS_POPUP_ENCRYPTED_MSG, mi->PeerId(), mi->subject, mi->message);
|
||||
else
|
||||
notify->AddPopupMessage(RS_POPUP_MSG, mi->PeerId(), title, message);
|
||||
notify->AddPopupMessage(RS_POPUP_MSG, mi->PeerId(), mi->subject, mi->message);
|
||||
|
||||
std::string out;
|
||||
rs_sprintf(out, "%lu", mi->msgId);
|
||||
|
@ -669,12 +665,12 @@ void p3MsgService::loadWelcomeMsg()
|
|||
msg -> recvTime = time(NULL);
|
||||
msg -> msgFlags = RS_MSG_FLAGS_NEW;
|
||||
|
||||
msg -> subject = L"Welcome to Retroshare";
|
||||
msg -> subject = "Welcome to Retroshare";
|
||||
|
||||
msg -> message = L"Send and receive messages with your friends...\n";
|
||||
msg -> message += L"These can hold recommendations from your local shared files.\n\n";
|
||||
msg -> message += L"Add recommendations through the Local Files Dialog.\n\n";
|
||||
msg -> message += L"Enjoy.";
|
||||
msg -> message = "Send and receive messages with your friends...\n";
|
||||
msg -> message += "These can hold recommendations from your local shared files.\n\n";
|
||||
msg -> message += "Add recommendations through the Local Files Dialog.\n\n";
|
||||
msg -> message += "Enjoy.";
|
||||
|
||||
msg -> msgId = getNewUniqueMsgId();
|
||||
|
||||
|
@ -1072,7 +1068,7 @@ bool p3MsgService::MessageSend(MessageInfo &info)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool p3MsgService::SystemMessage(const std::wstring &title, const std::wstring &message, uint32_t systemFlag)
|
||||
bool p3MsgService::SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag)
|
||||
{
|
||||
if ((systemFlag & RS_MSG_SYSTEM) == 0) {
|
||||
/* no flag specified */
|
||||
|
@ -1829,22 +1825,21 @@ bool p3MsgService::encryptMessage(const std::string& pgp_id,RsMsgItem *item)
|
|||
#endif
|
||||
// Now turn the binary encrypted chunk into a readable radix string.
|
||||
//
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << " Converting to radix64" << std::endl;
|
||||
#endif
|
||||
std::string armoured_data ;
|
||||
Radix64::encode((char *)encrypted_data,encrypted_size,armoured_data) ;
|
||||
delete[] encrypted_data ;
|
||||
|
||||
std::wstring encrypted_msg ;
|
||||
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << " Converting to radix64" << std::endl;
|
||||
#endif
|
||||
if(!librs::util::ConvertUtf8ToUtf16(armoured_data,encrypted_msg))
|
||||
return false;
|
||||
//std::wstring encrypted_msg = armoured_data;
|
||||
//if(!librs::util::ConvertUtf8ToUtf16(armoured_data,encrypted_msg))
|
||||
// return false;
|
||||
|
||||
// wipe the item clean and replace the message by the encrypted data.
|
||||
|
||||
item->message = encrypted_msg ;
|
||||
item->subject = L"" ;
|
||||
item->message = armoured_data ;
|
||||
item->subject = "" ;
|
||||
item->msgcc.ids.clear() ;
|
||||
item->msgbcc.ids.clear() ;
|
||||
item->msgto.ids.clear() ;
|
||||
|
@ -1870,11 +1865,13 @@ bool p3MsgService::decryptMessage(const std::string& mId)
|
|||
|
||||
std::map<uint32_t, RsMsgItem *>::iterator mit = imsg.find(msgId);
|
||||
|
||||
if(mit == imsg.end() || !librs::util::ConvertUtf16ToUtf8(mit->second->message,encrypted_string))
|
||||
if(mit == imsg.end())
|
||||
{
|
||||
std::cerr << "Can't find this message in msg list. Id=" << mId << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
encrypted_string = mit->second->message ;
|
||||
}
|
||||
|
||||
char *encrypted_data ;
|
||||
|
|
|
@ -66,7 +66,7 @@ bool getMsgParentId(const std::string &msgId, std::string &msgParentId);
|
|||
bool setMsgParentId(uint32_t msgId, uint32_t msgParentId);
|
||||
|
||||
bool MessageSend(MessageInfo &info);
|
||||
bool SystemMessage(const std::wstring &title, const std::wstring &message, uint32_t systemFlag);
|
||||
bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag);
|
||||
bool MessageToDraft(MessageInfo &info, const std::string &msgParentId);
|
||||
bool MessageToTrash(const std::string &mid, bool bTrash);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue