From 45bf5f51cc788cb8f19e1b8fcd5b8818dc7a2e00 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 25 Feb 2019 21:02:11 +0300 Subject: GCEVENT::GCEF_UTF8 - flag for direct communication with utf8-encoded chat events (UTF16LE by default) --- include/m_chat.h | 19 +- include/m_core.h | 16 +- plugins/MirLua/src/Modules/m_chat.cpp | 10 +- plugins/MirandaG15/src/CAppletManager.cpp | 38 ++-- plugins/RecentContacts/src/RecentContacts.cpp | 4 +- plugins/TabSRMM/src/chat_tools.cpp | 14 +- plugins/TabSRMM/src/muchighlight.cpp | 12 +- plugins/XSoundNotify/src/xsn_main.cpp | 6 +- protocols/Discord/src/dispatch.cpp | 28 +-- protocols/Discord/src/guilds.cpp | 5 +- protocols/Discord/src/server.cpp | 7 +- protocols/FacebookRM/src/chat.cpp | 64 +++---- protocols/Gadu-Gadu/src/core.cpp | 18 +- protocols/Gadu-Gadu/src/groupchat.cpp | 261 +++++++++++--------------- protocols/ICQ-WIM/src/groupchats.cpp | 16 +- protocols/ICQ-WIM/src/server.cpp | 7 +- protocols/IRCG/src/commandmonitor.cpp | 11 +- protocols/IRCG/src/tools.cpp | 16 +- protocols/JabberG/src/jabber_chat.cpp | 77 ++++---- protocols/JabberG/src/jabber_groupchat.cpp | 41 ++-- protocols/MSN/src/msn_chat.cpp | 54 +++--- protocols/MinecraftDynmap/src/chat.cpp | 48 ++--- protocols/MinecraftDynmap/src/proto.cpp | 1 + protocols/MinecraftDynmap/src/proto.h | 3 +- protocols/Omegle/src/chat.cpp | 34 ++-- protocols/Sametime/src/conference.cpp | 34 ++-- protocols/SkypeWeb/src/skype_chatrooms.cpp | 240 +++++++++++------------ protocols/SkypeWeb/src/skype_history_sync.cpp | 2 +- protocols/SkypeWeb/src/skype_proto.h | 14 +- protocols/Twitter/src/chat.cpp | 45 ++--- protocols/Twitter/src/proto.cpp | 3 +- protocols/Twitter/src/proto.h | 2 + protocols/VKontakte/src/vk_chats.cpp | 34 ++-- src/mir_app/src/chat_manager.cpp | 12 +- src/mir_app/src/chat_svc.cpp | 46 +++-- src/mir_app/src/chat_tools.cpp | 116 ++++++------ utils/std_string_utils.cpp | 2 +- 37 files changed, 661 insertions(+), 699 deletions(-) diff --git a/include/m_chat.h b/include/m_chat.h index 6701507374..cd290c04e4 100644 --- a/include/m_chat.h +++ b/include/m_chat.h @@ -347,18 +347,19 @@ EXTERN_C MIR_APP_DLL(struct SESSION_INFO*) Chat_NewSession( #define GCEF_ADDTOLOG 0x0001 // force adding to log #define GCEF_SILENT 0x0002 // never add to log #define GCEF_NOTNOTIFY 0x0004 +#define GCEF_UTF8 0x0008 struct GCEVENT { - LPCSTR pszModule; // Name of the protocol (same as you registered with) - LPCTSTR ptszID; // Unique identifier of the session, or NULL to broadcast to all sessions as specified above - int iType; // Use GC_EVENT_* as defined above. Only one event per service call. - - LPCTSTR ptszText; // - LPCTSTR ptszNick; // - LPCTSTR ptszUID; // - LPCTSTR ptszStatus; // - LPCTSTR ptszUserInfo; // + LPCSTR pszModule; // Name of the protocol (same as you registered with) + MAllCStrings pszID; // Unique identifier of the session, or NULL to broadcast to all sessions as specified above + int iType; // Use GC_EVENT_* as defined above. Only one event per service call. + + MAllCStrings pszText; // + MAllCStrings pszNick; // + MAllCStrings pszUID; // + MAllCStrings pszStatus; // + MAllCStrings pszUserInfo; // BOOL bIsMe; // Is this event from the Miranda user? DWORD dwFlags; // event flags: GCEF_* diff --git a/include/m_core.h b/include/m_core.h index b75cd0c700..610a04ff7e 100644 --- a/include/m_core.h +++ b/include/m_core.h @@ -428,15 +428,23 @@ __forceinline char* lrtrimp(char *str) { return ltrimp(rtrim(str)); }; /////////////////////////////////////////////////////////////////////////////// // text conversion functions -typedef union { +union MAllStrings +{ char *a; // utf8 or ansi strings wchar_t *w; // strings of WCHARs -} MAllStrings; +}; -typedef union { +union MAllCStrings +{ + const char *a; // utf8 or ansi strings + const wchar_t *w; // strings of WCHARs +}; + +union MAllStringArray +{ char **a; // array of utf8 or ansi strings wchar_t **w; // array of strings of WCHARs -} MAllStringArray; +}; MIR_CORE_DLL(wchar_t*) mir_a2u_cp(const char* src, int codepage); MIR_CORE_DLL(wchar_t*) mir_a2u(const char* src); diff --git a/plugins/MirLua/src/Modules/m_chat.cpp b/plugins/MirLua/src/Modules/m_chat.cpp index c1a2a65d9b..8611b6bc08 100644 --- a/plugins/MirLua/src/Modules/m_chat.cpp +++ b/plugins/MirLua/src/Modules/m_chat.cpp @@ -11,15 +11,15 @@ LUAMOD_API int luaopen_m_chat(lua_State *L) MT(L, "GCEVENT") .Field(&GCEVENT::pszModule, "Module", LUA_TSTRINGA) - .Field(&GCEVENT::ptszID, "Id", LUA_TSTRINGW) + .Field(&GCEVENT::pszID, "Id", LUA_TSTRINGW) .Field(&GCEVENT::iType, "Type", LUA_TINTEGER) .Field(&GCEVENT::time, "Timestamp", LUA_TINTEGER) .Field(&GCEVENT::time, "IsMe", LUA_TINTEGER) .Field(&GCEVENT::time, "Flags", LUA_TINTEGER) - .Field(&GCEVENT::ptszNick, "Nick", LUA_TSTRINGW) - .Field(&GCEVENT::ptszUID, "Uid", LUA_TSTRINGW) - .Field(&GCEVENT::ptszStatus, "Status", LUA_TSTRINGW) - .Field(&GCEVENT::ptszText, "Text", LUA_TSTRINGW); + .Field(&GCEVENT::pszNick, "Nick", LUA_TSTRINGW) + .Field(&GCEVENT::pszUID, "Uid", LUA_TSTRINGW) + .Field(&GCEVENT::pszStatus, "Status", LUA_TSTRINGW) + .Field(&GCEVENT::pszText, "Text", LUA_TSTRINGW); return 1; } diff --git a/plugins/MirandaG15/src/CAppletManager.cpp b/plugins/MirandaG15/src/CAppletManager.cpp index 58cc434bc0..da2980fe03 100644 --- a/plugins/MirandaG15/src/CAppletManager.cpp +++ b/plugins/MirandaG15/src/CAppletManager.cpp @@ -1078,7 +1078,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) return 0; } - TRACE(L"<< [%s:%s] event %04X\n", toTstring(gce->pszModule).c_str(), gce->ptszID, gce->iType); + TRACE(L"<< [%s:%s] event %04X\n", toTstring(gce->pszModule).c_str(), gce->pszID.w, gce->iType); // get the matching irc connection entry CIRCConnection *pIRCCon = CAppletManager::GetInstance()->GetIRCConnection(toTstring(gce->pszModule)); @@ -1105,13 +1105,13 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) Event.hValue = lParam; CIRCHistory *pHistory = nullptr; - if (gce->ptszID) { - tstring strChannel = toTstring(gce->ptszID); + if (gce->pszID.w) { + tstring strChannel = toTstring(gce->pszID.w); tstring::size_type pos = strChannel.find('-'); if (pos != tstring::npos) strChannel = strChannel.substr(0, pos - 1); else { - if (mir_wstrcmpi(gce->ptszID, L"Network log")) + if (mir_wstrcmpi(gce->pszID.w, L"Network log")) TRACE(L"\t WARNING: ignoring unknown event!\n"); return 0; } @@ -1120,7 +1120,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) if (gce->iType == GC_EVENT_JOIN) { pHistory = CAppletManager::GetInstance()->CreateIRCHistoryByName(pIRCCon->strProtocol, strChannel); if (pHistory) - pHistory->LUsers.push_back(toTstring(gce->ptszNick)); + pHistory->LUsers.push_back(toTstring(gce->pszNick.w)); } return 0; } @@ -1134,17 +1134,17 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) Event.hContact = NULL; // Ignore events from hidden chatrooms, except for join events - if (gce->ptszID != nullptr && db_get_b(Event.hContact, "CList", "Hidden", 0)) { + if (gce->pszID.w != nullptr && db_get_b(Event.hContact, "CList", "Hidden", 0)) { if (gce->iType == GC_EVENT_JOIN && pHistory) - pHistory->LUsers.push_back(toTstring(gce->ptszNick)); + pHistory->LUsers.push_back(toTstring(gce->pszNick.w)); TRACE(L"\t Chatroom is hidden, skipping event!\n"); return 0; } - tstring strText = StripIRCFormatting(toTstring(gce->ptszText)); - tstring strNick = toTstring(gce->ptszNick); - tstring strStatus = toTstring(gce->ptszStatus); + tstring strText = StripIRCFormatting(toTstring(gce->pszText.w)); + tstring strNick = toTstring(gce->pszNick.w); + tstring strStatus = toTstring(gce->pszStatus.w); if (CConfig::GetBoolSetting(NOTIFY_NICKCUTOFF) && strNick.length() > (tstring::size_type)CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET)) strNick = strNick.erase(CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET)) + L"..."; @@ -1174,7 +1174,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) break; case GC_EVENT_JOIN: // Add the user to the list - pHistory->LUsers.push_back(toTstring(gce->ptszNick)); + pHistory->LUsers.push_back(toTstring(gce->pszNick.w)); if (CConfig::GetBoolSetting(NOTIFY_IRC_USERS)) Event.bNotification = true; @@ -1188,7 +1188,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) { if (CConfig::GetBoolSetting(NOTIFY_IRC_USERS)) Event.bNotification = true; - tstring strFullNick = toTstring(gce->ptszNick); + tstring strFullNick = toTstring(gce->pszNick.w); Event.strValue = TranslateString(strText.empty() ? L"%s has left" : L"%s has left: %s", strNick.c_str(), strText.c_str()); if (pHistory) { // Remove the user from the list @@ -1217,7 +1217,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) { if (CConfig::GetBoolSetting(NOTIFY_IRC_USERS)) Event.bNotification = true; - tstring strFullNick = toTstring(gce->ptszNick); + tstring strFullNick = toTstring(gce->pszNick.w); if (CConfig::GetBoolSetting(NOTIFY_NICKCUTOFF) && strText.length() > (tstring::size_type)CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET)) strText = strText.erase(CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET)) + L"..."; @@ -1248,7 +1248,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) { if (CConfig::GetBoolSetting(NOTIFY_IRC_STATUS)) Event.bNotification = true; - tstring strNick2 = toTstring(gce->ptszStatus); + tstring strNick2 = toTstring(gce->pszStatus.w); if (CConfig::GetBoolSetting(NOTIFY_NICKCUTOFF) && strNick2.length() > (tstring::size_type)CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET)) strNick2 = strNick2.erase(CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET)) + L"..."; @@ -1259,7 +1259,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) { if (CConfig::GetBoolSetting(NOTIFY_IRC_STATUS)) Event.bNotification = true; - tstring strNick2 = toTstring(gce->ptszStatus); + tstring strNick2 = toTstring(gce->pszStatus.w); if (CConfig::GetBoolSetting(NOTIFY_NICKCUTOFF) && strNick2.length() > (tstring::size_type)CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET)) strNick2 = strNick2.erase(CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET)) + L"..."; @@ -1270,7 +1270,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) TRACE(L"OK!\n"); return 0; } - if (gce->bIsMe || gce->ptszID == nullptr) + if (gce->bIsMe || gce->pszID.w == nullptr) Event.bNotification = false; // set the event's timestamp @@ -1291,8 +1291,8 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) if (pHistory->LMessages.size() > CConfig::GetIntSetting(SESSION_LOGSIZE)) pHistory->LMessages.pop_front(); } - else if (gce->ptszNick && gce->iType == GC_EVENT_QUIT) { - strNick = toTstring(gce->ptszNick); + else if (gce->pszNick.w && gce->iType == GC_EVENT_QUIT) { + strNick = toTstring(gce->pszNick.w); if (!CAppletManager::GetInstance()->m_LIRCHistorys.empty()) { list::iterator iter = CAppletManager::GetInstance()->m_LIRCHistorys.begin(); @@ -1323,7 +1323,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) TRACE(L"OK!\n"); return 0; } - else if (gce->ptszID != nullptr) { + else if (gce->pszID.w != nullptr) { TRACE(L"OK!\n"); return 0; } diff --git a/plugins/RecentContacts/src/RecentContacts.cpp b/plugins/RecentContacts/src/RecentContacts.cpp index 6512b02690..2cdd83d937 100644 --- a/plugins/RecentContacts/src/RecentContacts.cpp +++ b/plugins/RecentContacts/src/RecentContacts.cpp @@ -455,7 +455,7 @@ static int OnGCInEvent(WPARAM, LPARAM lParam) { GCEVENT *gce = (GCEVENT*)lParam; if (gce->iType == GC_EVENT_MESSAGE) { - SESSION_INFO *si = g_chatApi.SM_FindSession(gce->ptszID, gce->pszModule); + SESSION_INFO *si = g_chatApi.SM_FindSession(gce->pszID.w, gce->pszModule); if (si && si->hContact) { // skip old events if (gce->time && gce->time <= GetLastUsedTimeStamp(si->hContact)) @@ -470,7 +470,7 @@ static int OnGCOutEvent(WPARAM, LPARAM lParam) { GCEVENT *gce = (GCEVENT*)lParam; if (gce->iType == GC_USER_MESSAGE) { - SESSION_INFO *si = g_chatApi.SM_FindSession(gce->ptszID, gce->pszModule); + SESSION_INFO *si = g_chatApi.SM_FindSession(gce->pszID.w, gce->pszModule); if (si && si->hContact) SaveLastUsedTimeStamp(si->hContact); } diff --git a/plugins/TabSRMM/src/chat_tools.cpp b/plugins/TabSRMM/src/chat_tools.cpp index da5f904b30..cac75f3c7e 100644 --- a/plugins/TabSRMM/src/chat_tools.cpp +++ b/plugins/TabSRMM/src/chat_tools.cpp @@ -193,7 +193,7 @@ passed: if (iNewEvent == GC_EVENT_MESSAGE) { ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_MESSAGE], si->pszModule, si->ptszName, clr ? clr : g_chatApi.aFonts[9].color, - TranslateT("%s%s says:%s %s"), bbStart, gce->ptszNick, bbEnd, g_chatApi.RemoveFormatting(gce->ptszText)); + TranslateT("%s%s says:%s %s"), bbStart, gce->pszNick.w, bbEnd, g_chatApi.RemoveFormatting(gce->pszText.w)); } else oldDoPopup(si, gce); @@ -556,17 +556,17 @@ bool IsHighlighted(SESSION_INFO *si, GCEVENT *gce) GCEVENT evTmp = *gce; int dwMask = 0; - if (gce->ptszText != nullptr) + if (gce->pszText.w != nullptr) dwMask |= CMUCHighlight::MATCH_TEXT; - if (gce->ptszNick != nullptr) { + if (gce->pszNick.w != nullptr) { dwMask |= CMUCHighlight::MATCH_NICKNAME; if (si && g_Settings.bLogClassicIndicators) { - size_t len = mir_wstrlen(gce->ptszNick) + 1; + size_t len = mir_wstrlen(gce->pszNick.w) + 1; wchar_t *tmp = (wchar_t*)_alloca(sizeof(wchar_t)*(len + 1)); - *tmp = GetIndicator(si, gce->ptszNick, nullptr); - mir_wstrcpy(tmp + 1, gce->ptszNick); - evTmp.ptszNick = tmp; + *tmp = GetIndicator(si, gce->pszNick.w, nullptr); + mir_wstrcpy(tmp + 1, gce->pszNick.w); + evTmp.pszNick.w = tmp; } } return g_Settings.Highlight->match(&evTmp, si, dwMask); diff --git a/plugins/TabSRMM/src/muchighlight.cpp b/plugins/TabSRMM/src/muchighlight.cpp index bf60e719a5..d69b6c7393 100644 --- a/plugins/TabSRMM/src/muchighlight.cpp +++ b/plugins/TabSRMM/src/muchighlight.cpp @@ -118,7 +118,7 @@ bool CMUCHighlight::match(const GCEVENT *pgce, const SESSION_INFO *psi, DWORD dw return false; if ((m_dwFlags & MATCH_TEXT) && (dwFlags & MATCH_TEXT) && (m_fHighlightMe || m_iTextPatterns > 0) && psi != nullptr) { - wchar_t *p = g_chatApi.RemoveFormatting(pgce->ptszText); + wchar_t *p = g_chatApi.RemoveFormatting(pgce->pszText.w); p = NEWWSTR_ALLOCA(p); if (p == nullptr) return false; @@ -164,12 +164,12 @@ bool CMUCHighlight::match(const GCEVENT *pgce, const SESSION_INFO *psi, DWORD dw skip_textpatterns: // optionally, match the nickname against the list of nicks to highlight - if ((m_dwFlags & MATCH_NICKNAME) && (dwFlags & MATCH_NICKNAME) && pgce->ptszNick && m_iNickPatterns > 0) { + if ((m_dwFlags & MATCH_NICKNAME) && (dwFlags & MATCH_NICKNAME) && pgce->pszNick.w && m_iNickPatterns > 0) { for (UINT i = 0; i < m_iNickPatterns && !nResult; i++) { - if (pgce->ptszNick) - nResult = wildcmpw(pgce->ptszNick, m_NickPatterns[i]) ? MATCH_NICKNAME : 0; - if ((m_dwFlags & MATCH_UIN) && pgce->ptszUserInfo) - nResult = wildcmpw(pgce->ptszUserInfo, m_NickPatterns[i]) ? MATCH_NICKNAME : 0; + if (pgce->pszNick.w) + nResult = wildcmpw(pgce->pszNick.w, m_NickPatterns[i]) ? MATCH_NICKNAME : 0; + if ((m_dwFlags & MATCH_UIN) && pgce->pszUserInfo.w) + nResult = wildcmpw(pgce->pszUserInfo.w, m_NickPatterns[i]) ? MATCH_NICKNAME : 0; } } diff --git a/plugins/XSoundNotify/src/xsn_main.cpp b/plugins/XSoundNotify/src/xsn_main.cpp index be0e1ef411..9b0da63ff9 100644 --- a/plugins/XSoundNotify/src/xsn_main.cpp +++ b/plugins/XSoundNotify/src/xsn_main.cpp @@ -143,13 +143,13 @@ static int ProcessChatEvent(WPARAM, LPARAM lParam) if (gce->iType != GC_EVENT_MESSAGE) return 0; - MCONTACT hContact = g_chatApi.FindRoom(gce->pszModule, gce->ptszID); + MCONTACT hContact = g_chatApi.FindRoom(gce->pszModule, gce->pszID.w); if (hContact != 0) { ptrW nick(db_get_wsa(hContact, gce->pszModule, "MyNick")); - if (nick == NULL || gce->ptszText == nullptr) + if (nick == NULL || gce->pszText.w == nullptr) return 0; - if (wcsstr(gce->ptszText, nick)) { + if (wcsstr(gce->pszText.w, nick)) { isIgnoreSound = g_plugin.getByte(hContact, SETTINGSIGNOREKEY, 0); DBVARIANT dbv; if (!isIgnoreSound && !g_plugin.getWString(hContact, SETTINGSKEY, &dbv)) { diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 57b78c4df9..13441bcf08 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -143,8 +143,9 @@ void CDiscordProto::OnCommandChannelUpdated(const JSONNode &pRoot) CMStringW wszTopic = pRoot["topic"].as_mstring(); Chat_SetStatusbarText(m_szModuleName, pUser->wszUsername, wszTopic); - GCEVENT gce = { m_szModuleName, pUser->wszUsername, GC_EVENT_TOPIC }; - gce.ptszText = wszTopic; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_TOPIC }; + gce.pszID.w = pUser->wszUsername; + gce.pszText.w = wszTopic; gce.time = time(0); Chat_Event(&gce); } @@ -226,9 +227,10 @@ void CDiscordProto::OnCommandGuildMemberRemoved(const JSONNode &pRoot) if (pUser->pGuild != pGuild) continue; - GCEVENT gce = { m_szModuleName, pUser->wszUsername, GC_EVENT_PART }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_PART }; + gce.pszUID.w = pUser->wszUsername; gce.time = time(0); - gce.ptszUID = wszUserId; + gce.pszUID.w = wszUserId; Chat_Event(&gce); } } @@ -260,11 +262,12 @@ void CDiscordProto::OnCommandGuildMemberUpdated(const JSONNode &pRoot) wszOldNick = ui->pszNick; } - GCEVENT gce = { m_szModuleName, it->wszUsername, GC_EVENT_NICK }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_NICK }; + gce.pszID.w = it->wszUsername; gce.time = time(0); - gce.ptszUID = wszUserId; - gce.ptszNick = wszOldNick; - gce.ptszText = gm->wszNick; + gce.pszUID.w = wszUserId; + gce.pszNick.w = wszOldNick; + gce.pszText.w = gm->wszNick; Chat_Event(&gce); } } @@ -417,15 +420,16 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) ParseSpecialChars(si, wszText); - GCEVENT gce = { m_szModuleName, pUser->wszUsername, GC_EVENT_MESSAGE }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; + gce.pszID.w = pUser->wszUsername; gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszUID = wszUserId; - gce.ptszText = wszText; + gce.pszUID.w = wszUserId; + gce.pszText.w = wszText; gce.time = (DWORD)StringToDate(pRoot["timestamp"].as_mstring()); gce.bIsMe = bOurMessage; Chat_Event(&gce); - debugLogW(L"New channel %s message from %s: %s", si->ptszID, gce.ptszUID, gce.ptszText); + debugLogW(L"New channel %s message from %s: %s", si->ptszID, gce.pszUID.w, gce.pszText.w); } } diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp index 76fafb1918..5cda9d41e8 100644 --- a/protocols/Discord/src/guilds.cpp +++ b/protocols/Discord/src/guilds.cpp @@ -112,9 +112,10 @@ void CDiscordProto::CreateChat(CDiscordGuild *pGuild, CDiscordUser *pUser) if (!pUser->wszTopic.IsEmpty()) { Chat_SetStatusbarText(m_szModuleName, pUser->wszUsername, pUser->wszTopic); - GCEVENT gce = { m_szModuleName, pUser->wszUsername, GC_EVENT_TOPIC }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_TOPIC }; + gce.pszID.w = pUser->wszUsername; gce.time = time(0); - gce.ptszText = pUser->wszTopic; + gce.pszText.w = pUser->wszTopic; Chat_Event(&gce); } } diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index f1d1db3a5e..661e313290 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -117,10 +117,11 @@ void CDiscordProto::OnReceiveHistory(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest else { ParseSpecialChars(si, wszText); - GCEVENT gce = { m_szModuleName, pUser->wszUsername, GC_EVENT_MESSAGE }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; + gce.pszID.w = pUser->wszUsername; gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszUID = wszUserId; - gce.ptszText = wszText; + gce.pszUID.w = wszUserId; + gce.pszText.w = wszText; gce.time = dwTimeStamp; gce.bIsMe = authorid == m_ownId; Chat_Event(&gce); diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp index c732567407..30db7ca1dd 100644 --- a/protocols/FacebookRM/src/chat.cpp +++ b/protocols/FacebookRM/src/chat.cpp @@ -50,23 +50,18 @@ void FacebookProto::UpdateChat(const char *chat_id, const char *id, const char * std::string smessage = message; utils::text::replace_all(&smessage, "%", "%%"); - ptrW tid(mir_a2u(id)); - ptrW tnick(mir_a2u_cp(name, CP_UTF8)); - ptrW ttext(mir_a2u_cp(smessage.c_str(), CP_UTF8)); - ptrW tchat_id(mir_a2u(chat_id)); - - GCEVENT gce = { m_szModuleName, tchat_id, GC_EVENT_MESSAGE }; - gce.ptszText = ttext; + GCEVENT gce = { m_szModuleName, chat_id, GC_EVENT_MESSAGE }; + gce.pszText.a = smessage.c_str(); gce.time = timestamp ? timestamp : ::time(0); if (id != nullptr) gce.bIsMe = !mir_strcmp(id, facy.self_.user_id.c_str()); - gce.dwFlags |= GCEF_ADDTOLOG; + gce.dwFlags = GCEF_ADDTOLOG | GCEF_UTF8; if (is_old) { gce.dwFlags |= GCEF_NOTNOTIFY; gce.dwFlags &= ~GCEF_ADDTOLOG; } - gce.ptszNick = tnick; - gce.ptszUID = tid; + gce.pszNick.a = name; + gce.pszUID.a = id; Chat_Event(&gce); facy.erase_reader(ChatIDToHContact(chat_id)); @@ -74,9 +69,7 @@ void FacebookProto::UpdateChat(const char *chat_id, const char *id, const char * void FacebookProto::RenameChat(const char *chat_id, const char *name) { - ptrW tchat_id(mir_a2u(chat_id)); - ptrW tname(mir_a2u_cp(name, CP_UTF8)); - Chat_ChangeSessionName(m_szModuleName, tchat_id, tname); + Chat_ChangeSessionName(m_szModuleName, _A2T(chat_id), Utf2T(name)); } int FacebookProto::OnGCEvent(WPARAM, LPARAM lParam) @@ -172,30 +165,26 @@ void FacebookProto::AddChatContact(const char *chat_id, const chatroom_participa if (IsChatContact(chat_id, user.user_id.c_str())) return; - ptrW tchat_id(mir_a2u(chat_id)); - ptrW tnick(mir_a2u_cp(user.nick.c_str(), CP_UTF8)); - ptrW tid(mir_a2u(user.user_id.c_str())); - - GCEVENT gce = { m_szModuleName, tchat_id, GC_EVENT_JOIN }; - gce.dwFlags = addToLog ? GCEF_ADDTOLOG : 0; - gce.ptszNick = tnick; - gce.ptszUID = tid; + GCEVENT gce = { m_szModuleName, chat_id, GC_EVENT_JOIN }; + gce.dwFlags = GCEF_UTF8 + (addToLog ? GCEF_ADDTOLOG : 0); + gce.pszNick.a = user.nick.c_str(); + gce.pszUID.a = user.user_id.c_str(); gce.time = ::time(0); gce.bIsMe = (user.role == ROLE_ME); if (user.is_former) { - gce.ptszStatus = TranslateT("Former"); + gce.pszStatus.a = TranslateU("Former"); } else { switch (user.role) { case ROLE_ME: - gce.ptszStatus = TranslateT("Myself"); + gce.pszStatus.a = TranslateU("Myself"); break; case ROLE_FRIEND: - gce.ptszStatus = TranslateT("Friend"); + gce.pszStatus.a = TranslateU("Friend"); break; case ROLE_NONE: - gce.ptszStatus = TranslateT("User"); + gce.pszStatus.a = TranslateU("User"); break; } } @@ -205,14 +194,10 @@ void FacebookProto::AddChatContact(const char *chat_id, const chatroom_participa void FacebookProto::RemoveChatContact(const char *chat_id, const char *id, const char *name) { - ptrW tchat_id(mir_a2u(chat_id)); - ptrW tnick(mir_a2u_cp(name, CP_UTF8)); - ptrW tid(mir_a2u(id)); - - GCEVENT gce = { m_szModuleName, tchat_id, GC_EVENT_PART }; - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = tnick; - gce.ptszUID = tid; + GCEVENT gce = { m_szModuleName, chat_id, GC_EVENT_PART }; + gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; + gce.pszNick.a = name; + gce.pszUID.a = id; gce.time = ::time(0); gce.bIsMe = false; @@ -387,16 +372,13 @@ void FacebookProto::UpdateNotificationsChatRoom(facebook_notification *notificat std::string message = text.str(); utils::text::replace_all(&message, "%", "%%"); - ptrW idT(mir_wstrdup(_A2W(FACEBOOK_NOTIFICATIONS_CHATROOM))); - ptrW messageT(mir_a2u_cp(message.c_str(), CP_UTF8)); - - GCEVENT gce = { m_szModuleName, _A2W(FACEBOOK_NOTIFICATIONS_CHATROOM), GC_EVENT_MESSAGE }; - gce.ptszText = messageT; + GCEVENT gce = { m_szModuleName, FACEBOOK_NOTIFICATIONS_CHATROOM, GC_EVENT_MESSAGE }; + gce.pszText.a = message.c_str(); gce.time = notification->time ? notification->time : ::time(0); gce.bIsMe = false; - gce.dwFlags |= GCEF_ADDTOLOG; - gce.ptszNick = TranslateT("Notifications"); - gce.ptszUID = idT; + gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; + gce.pszNick.a = TranslateU("Notifications"); + gce.pszUID.a = FACEBOOK_NOTIFICATIONS_CHATROOM; Chat_Event(&gce); } diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp index d9c96a6a97..a65719ad25 100644 --- a/protocols/Gadu-Gadu/src/core.cpp +++ b/protocols/Gadu-Gadu/src/core.cpp @@ -814,12 +814,13 @@ retry: wchar_t id[32]; UIN2IDT(e->event.msg.sender, id); - GCEVENT gce = { m_szModuleName, chat, GC_EVENT_MESSAGE }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; time_t t = time(0); - gce.ptszUID = id; + gce.pszID.w = chat; + gce.pszUID.w = id; wchar_t* messageT = mir_utf8decodeW(e->event.msg.message); - gce.ptszText = messageT; - gce.ptszNick = (wchar_t*)Clist_GetContactDisplayName(getcontact(e->event.msg.sender, 1, 0, nullptr)); + gce.pszText.w = messageT; + gce.pszNick.w = (wchar_t*)Clist_GetContactDisplayName(getcontact(e->event.msg.sender, 1, 0, nullptr)); gce.time = (!(e->event.msg.msgclass & GG_CLASS_OFFLINE) || e->event.msg.time > (t - timeDeviation)) ? t : e->event.msg.time; gce.dwFlags = GCEF_ADDTOLOG; debugLogW(L"mainthread() (%x): Conference message to room %s & id %s.", this, chat, id); @@ -875,10 +876,11 @@ retry: wchar_t id[32]; UIN2IDT(getDword(GG_KEY_UIN, 0), id); - GCEVENT gce = { m_szModuleName, chat, GC_EVENT_MESSAGE }; - gce.ptszUID = id; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; + gce.pszID.w = chat; + gce.pszUID.w = id; wchar_t* messageT = mir_utf8decodeW(e->event.multilogon_msg.message); - gce.ptszText = messageT; + gce.pszText.w = messageT; wchar_t* nickT; if (!getWString(GG_KEY_NICK, &dbv)) { nickT = mir_wstrdup(dbv.pwszVal); @@ -887,7 +889,7 @@ retry: else nickT = mir_wstrdup(TranslateT("Me")); - gce.ptszNick = nickT; + gce.pszNick.w = nickT; gce.time = e->event.multilogon_msg.time; gce.bIsMe = 1; gce.dwFlags = GCEF_ADDTOLOG; diff --git a/protocols/Gadu-Gadu/src/groupchat.cpp b/protocols/Gadu-Gadu/src/groupchat.cpp index aab963f4e9..648bb662a0 100644 --- a/protocols/Gadu-Gadu/src/groupchat.cpp +++ b/protocols/Gadu-Gadu/src/groupchat.cpp @@ -82,8 +82,7 @@ void GaduProto::gc_menus_init(HGENMENU hRoot) int GaduProto::gc_destroy() { list_t l; - for (l = chats; l; l = l->next) - { + for (l = chats; l; l = l->next) { GGGC *chat = (GGGC *)l->data; free(chat->recipients); } @@ -97,8 +96,7 @@ GGGC* GaduProto::gc_lookup(const wchar_t *id) GGGC *chat; list_t l; - for (l = chats; l; l = l->next) - { + for (l = chats; l; l = l->next) { chat = (GGGC *)l->data; if (chat && !mir_wstrcmp(chat->id, id)) return chat; @@ -123,8 +121,7 @@ int GaduProto::gc_event(WPARAM, LPARAM lParam) return 0; // Window terminated (Miranda exit) - if (gch->iType == SESSION_TERMINATE) - { + if (gch->iType == SESSION_TERMINATE) { debugLogW(L"gc_event(): Terminating chat %x, id %s from chat window...", chat, gch->ptszID); // Destroy chat entry free(chat->recipients); @@ -150,9 +147,10 @@ int GaduProto::gc_event(WPARAM, LPARAM lParam) UIN2IDT(uin, id); DBVARIANT dbv; - GCEVENT gce = { m_szModuleName, gch->ptszID, GC_EVENT_MESSAGE }; - gce.ptszUID = id; - gce.ptszText = gch->ptszText; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; + gce.pszID.w = gch->ptszID; + gce.pszUID.w = id; + gce.pszText.w = gch->ptszText; wchar_t* nickT; if (!getWString(GG_KEY_NICK, &dbv)) { nickT = mir_wstrdup(dbv.pwszVal); @@ -161,7 +159,7 @@ int GaduProto::gc_event(WPARAM, LPARAM lParam) else nickT = mir_wstrdup(TranslateT("Me")); - gce.ptszNick = nickT; + gce.pszNick.w = nickT; // Get rid of CRLF at back int lc = (int)mir_wstrlen(gch->ptszText) - 1; @@ -183,8 +181,7 @@ int GaduProto::gc_event(WPARAM, LPARAM lParam) } // Privmessage selected - if (gch->iType == GC_USER_PRIVMESS) - { + if (gch->iType == GC_USER_PRIVMESS) { MCONTACT hContact = NULL; if ((uin = _wtoi(gch->ptszUID)) && (hContact = getcontact(uin, 1, 0, nullptr))) CallService(MS_MSG_SENDMESSAGE, hContact, 0); @@ -215,18 +212,15 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c return nullptr; // Look for existing chat - for (l = chats; l; l = l->next) - { + for (l = chats; l; l = l->next) { chat = (GGGC *)l->data; if (!chat) continue; - if (chat->recipients_count == recipients_count + (sender ? 1 : 0)) - { + if (chat->recipients_count == recipients_count + (sender ? 1 : 0)) { int sok = (sender == 0); if (!sok) { for (int i = 0; i < chat->recipients_count; i++) { - if (sender == chat->recipients[i]) - { + if (sender == chat->recipients[i]) { sok = 1; break; } @@ -241,8 +235,7 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c ++found; // Found all recipients - if (found == recipients_count) - { + if (found == recipients_count) { if (chat->ignore) debugLogW(L"gc_getchat(): Ignoring existing id %s, size %d.", chat->id, chat->recipients_count); else @@ -258,8 +251,7 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c chat->ignore = FALSE; // Check groupchat policy (new) / only for incoming - if (sender) - { + if (sender) { int unknown = (getcontact(sender, 0, 0, nullptr) == NULL), unknownSender = unknown; for (int i = 0; i < recipients_count; i++) @@ -270,8 +262,7 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c (getWord(GG_KEY_GC_POLICY_TOTAL, GG_KEYDEF_GC_POLICY_TOTAL) == 2 && recipients_count >= getWord(GG_KEY_GC_COUNT_TOTAL, GG_KEYDEF_GC_COUNT_TOTAL)) || (getWord(GG_KEY_GC_POLICY_UNKNOWN, GG_KEYDEF_GC_POLICY_UNKNOWN) == 2 && - unknown >= getWord(GG_KEY_GC_COUNT_UNKNOWN, GG_KEYDEF_GC_COUNT_UNKNOWN))) - { + unknown >= getWord(GG_KEY_GC_COUNT_UNKNOWN, GG_KEYDEF_GC_COUNT_UNKNOWN))) { chat->ignore = TRUE; } @@ -279,8 +270,7 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c (getWord(GG_KEY_GC_POLICY_TOTAL, GG_KEYDEF_GC_POLICY_TOTAL) == 1 && recipients_count >= getWord(GG_KEY_GC_COUNT_TOTAL, GG_KEYDEF_GC_COUNT_TOTAL)) || (getWord(GG_KEY_GC_POLICY_UNKNOWN, GG_KEYDEF_GC_POLICY_UNKNOWN) == 1 && - unknown >= getWord(GG_KEY_GC_COUNT_UNKNOWN, GG_KEYDEF_GC_COUNT_UNKNOWN)))) - { + unknown >= getWord(GG_KEY_GC_COUNT_UNKNOWN, GG_KEYDEF_GC_COUNT_UNKNOWN)))) { wchar_t *senderName = unknownSender ? TranslateT("Unknown") : Clist_GetContactDisplayName(getcontact(sender, 0, 0, nullptr)); wchar_t error[256]; @@ -289,8 +279,7 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c chat->ignore = MessageBox(nullptr, error, m_tszUserName, MB_OKCANCEL | MB_ICONEXCLAMATION) != IDOK; } - if (chat->ignore) - { + if (chat->ignore) { // Copy recipient list chat->recipients_count = recipients_count + 1; chat->recipients = (uin_t *)calloc(chat->recipients_count, sizeof(uin_t)); @@ -307,13 +296,11 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c // Create new chat window wchar_t status[256]; wchar_t *senderName; - if (sender) - { + if (sender) { senderName = Clist_GetContactDisplayName(getcontact(sender, 1, 0, nullptr)); mir_snwprintf(status, TranslateT("%s initiated the conference."), senderName); } - else - { + else { senderName = nullptr; mir_snwprintf(status, TranslateT("This is my own conference.")); } @@ -331,25 +318,25 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c wchar_t id[32]; - GCEVENT gce = { m_szModuleName, chat->id, GC_EVENT_JOIN }; - gce.ptszUID = id; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; + gce.pszID.w = chat->id; + gce.pszUID.w = id; gce.dwFlags = GCEF_ADDTOLOG; // Add myself uin_t uin = getDword(GG_KEY_UIN, 0); - if (uin) - { + if (uin) { UIN2IDT(uin, id); ptrW nickT(getWStringA(GG_KEY_NICK)); if (nickT == NULL) nickT = mir_wstrdup(TranslateT("Me")); - gce.ptszNick = nickT; + gce.pszNick.w = nickT; gce.bIsMe = 1; Chat_Event(&gce); mir_free(nickT); - debugLogW(L"gc_getchat(): Myself %s: %s (%s) to the list...", gce.ptszUID, gce.ptszNick, gce.ptszStatus); + debugLogW(L"gc_getchat(): Myself %s: %s (%s) to the list...", gce.pszUID.w, gce.pszNick.w, gce.pszStatus.w); } else debugLogA("gc_getchat(): Myself adding failed with uin %d !!!", uin); @@ -368,12 +355,12 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c MCONTACT hContact = getcontact(chat->recipients[i], 1, 0, nullptr); UIN2IDT(chat->recipients[i], id); if (hContact) - gce.ptszNick = Clist_GetContactDisplayName(hContact); + gce.pszNick.w = Clist_GetContactDisplayName(hContact); else - gce.ptszNick = TranslateT("'Unknown'"); + gce.pszNick.w = TranslateT("'Unknown'"); gce.bIsMe = 0; gce.dwFlags = 0; - debugLogW(L"gc_getchat(): Added %s: %s (%s) to the list...", gce.ptszUID, gce.ptszNick, gce.ptszStatus); + debugLogW(L"gc_getchat(): Added %s: %s (%s) to the list...", gce.pszUID.w, gce.pszNick.w, gce.pszStatus.w); Chat_Event(&gce); } @@ -423,78 +410,67 @@ static int gg_gc_countcheckmarks(HWND hwndList) static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { - switch (message) - { + switch (message) { case WM_INITDIALOG: - { - CLCINFOITEM cii = { 0 }; - HANDLE hMetaContactsEvent; - - SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)lParam); - TranslateDialogDefault(hwndDlg); - Window_SetIcon_IcoLib(hwndDlg, GetIconHandle(IDI_CONFERENCE)); - gg_gc_resetclistopts(GetDlgItem(hwndDlg, IDC_CLIST)); - - // Hook MetaContacts event (if available) - hMetaContactsEvent = HookEventMessage(ME_MC_SUBCONTACTSCHANGED, hwndDlg, HM_SUBCONTACTSCHANGED); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)hMetaContactsEvent); - } - return TRUE; + { + SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)lParam); + TranslateDialogDefault(hwndDlg); + Window_SetIcon_IcoLib(hwndDlg, GetIconHandle(IDI_CONFERENCE)); + gg_gc_resetclistopts(GetDlgItem(hwndDlg, IDC_CLIST)); + + // Hook MetaContacts event (if available) + HANDLE hMetaContactsEvent = HookEventMessage(ME_MC_SUBCONTACTSCHANGED, hwndDlg, HM_SUBCONTACTSCHANGED); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)hMetaContactsEvent); + } + return TRUE; case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDOK: { - HWND hwndList = GetDlgItem(hwndDlg, IDC_CLIST); - GaduProto* gg = (GaduProto*)GetWindowLongPtr(hwndDlg, DWLP_USER); - int count = 0, i = 0; - // Check if connected - if (!gg->isonline()) - { - MessageBox(nullptr, - TranslateT("You have to be connected to open new conference."), - gg->m_tszUserName, MB_OK | MB_ICONSTOP); - } - else if (hwndList && (count = gg_gc_countcheckmarks(hwndList)) >= 2) - { - // Create new participiants table - uin_t* participants = (uin_t*)calloc(count, sizeof(uin_t)); - gg->debugLogA("gg_gc_openconfdlg(): WM_COMMAND IDOK Opening new conference for %d contacts.", count); - for (auto &hContact : Contacts()) { - HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); - if (hItem && SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) { - MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support - participants[i++] = db_get_dw(hMetaContact ? hMetaContact : hContact, gg->m_szModuleName, GG_KEY_UIN, 0); + switch (LOWORD(wParam)) { + case IDOK: + { + HWND hwndList = GetDlgItem(hwndDlg, IDC_CLIST); + GaduProto* gg = (GaduProto*)GetWindowLongPtr(hwndDlg, DWLP_USER); + int count = 0, i = 0; + // Check if connected + if (!gg->isonline()) { + MessageBox(nullptr, + TranslateT("You have to be connected to open new conference."), + gg->m_tszUserName, MB_OK | MB_ICONSTOP); } - } - if (count > i) - i = count; + else if (hwndList && (count = gg_gc_countcheckmarks(hwndList)) >= 2) { + // Create new participiants table + uin_t* participants = (uin_t*)calloc(count, sizeof(uin_t)); + gg->debugLogA("gg_gc_openconfdlg(): WM_COMMAND IDOK Opening new conference for %d contacts.", count); + for (auto &hContact : Contacts()) { + HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0); + if (hItem && SendMessage(hwndList, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) { + MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support + participants[i++] = db_get_dw(hMetaContact ? hMetaContact : hContact, gg->m_szModuleName, GG_KEY_UIN, 0); + } + } + if (count > i) + i = count; - wchar_t *chat = gg->gc_getchat(0, participants, count); - if (chat) - Chat_Control(gg->m_szModuleName, chat, WINDOW_VISIBLE); + wchar_t *chat = gg->gc_getchat(0, participants, count); + if (chat) + Chat_Control(gg->m_szModuleName, chat, WINDOW_VISIBLE); - free(participants); + free(participants); + } + } + // fall through + case IDCANCEL: + DestroyWindow(hwndDlg); + break; } } - // fall through - case IDCANCEL: - DestroyWindow(hwndDlg); - break; - } break; - } case WM_NOTIFY: - { - switch (((NMHDR*)lParam)->idFrom) - { + switch (((NMHDR*)lParam)->idFrom) { case IDC_CLIST: - { - switch (((NMHDR*)lParam)->code) - { + switch (((NMHDR*)lParam)->code) { case CLN_OPTIONSCHANGED: gg_gc_resetclistopts(GetDlgItem(hwndDlg, IDC_CLIST)); break; @@ -502,34 +478,34 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa case CLN_NEWCONTACT: case CLN_CONTACTMOVED: case CLN_LISTREBUILT: - { - char* szProto; - uin_t uin; - GaduProto* gg = (GaduProto*)GetWindowLongPtr(hwndDlg, DWLP_USER); + { + char* szProto; + uin_t uin; + GaduProto* gg = (GaduProto*)GetWindowLongPtr(hwndDlg, DWLP_USER); - if (!gg) - break; + if (!gg) + break; - // Delete non-gg contacts - for (auto &hContact : Contacts()) { - MCONTACT hItem = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); - if (hItem) { - MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support - if (hMetaContact) { - szProto = gg->m_szModuleName; - uin = (uin_t)gg->getDword(hMetaContact, GG_KEY_UIN, 0); - } - else { - szProto = GetContactProto(hContact); - uin = (uin_t)gg->getDword(hContact, GG_KEY_UIN, 0); + // Delete non-gg contacts + for (auto &hContact : Contacts()) { + MCONTACT hItem = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_FINDCONTACT, hContact, 0); + if (hItem) { + MCONTACT hMetaContact = gg_getsubcontact(gg, hContact); // MetaContacts support + if (hMetaContact) { + szProto = gg->m_szModuleName; + uin = (uin_t)gg->getDword(hMetaContact, GG_KEY_UIN, 0); + } + else { + szProto = GetContactProto(hContact); + uin = (uin_t)gg->getDword(hContact, GG_KEY_UIN, 0); + } + + if (szProto == nullptr || mir_strcmp(szProto, gg->m_szModuleName) || !uin || uin == gg->getDword(GG_KEY_UIN, 0)) + SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_DELETEITEM, (WPARAM)hItem, 0); } - - if (szProto == nullptr || mir_strcmp(szProto, gg->m_szModuleName) || !uin || uin == gg->getDword(GG_KEY_UIN, 0)) - SendDlgItemMessage(hwndDlg, IDC_CLIST, CLM_DELETEITEM, (WPARAM)hItem, 0); } } - } - break; + break; case CLN_CHECKCHANGED: EnableWindow(GetDlgItem(hwndDlg, IDOK), gg_gc_countcheckmarks(GetDlgItem(hwndDlg, IDC_CLIST)) >= 2); @@ -537,31 +513,27 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa } break; } - } break; - } case HM_SUBCONTACTSCHANGED: - { - HWND hwndList = GetDlgItem(hwndDlg, IDC_CLIST); - SendMessage(hwndList, CLM_AUTOREBUILD, 0, 0); - EnableWindow(GetDlgItem(hwndDlg, IDOK), gg_gc_countcheckmarks(hwndList) >= 2); + { + HWND hwndList = GetDlgItem(hwndDlg, IDC_CLIST); + SendMessage(hwndList, CLM_AUTOREBUILD, 0, 0); + EnableWindow(GetDlgItem(hwndDlg, IDOK), gg_gc_countcheckmarks(hwndList) >= 2); + } break; - } case WM_CLOSE: DestroyWindow(hwndDlg); break; case WM_DESTROY: - { HANDLE hMetaContactsEvent = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); if (hMetaContactsEvent) UnhookEvent(hMetaContactsEvent); Window_FreeIcon_IcoLib(hwndDlg); break; } - } return FALSE; } @@ -570,12 +542,10 @@ INT_PTR GaduProto::gc_clearignored(WPARAM, LPARAM) { list_t l = chats; BOOL cleared = FALSE; - while (l) - { + while (l) { GGGC *chat = (GGGC *)l->data; l = l->next; - if (chat->ignore) - { + if (chat->ignore) { free(chat->recipients); list_remove(&chats, chat, 1); cleared = TRUE; @@ -585,8 +555,7 @@ INT_PTR GaduProto::gc_clearignored(WPARAM, LPARAM) cleared ? TranslateT("All ignored conferences are now unignored and the conference policy will act again.") : TranslateT("There are no ignored conferences."), - m_tszUserName, MB_OK | MB_ICONINFORMATION - ); + m_tszUserName, MB_OK | MB_ICONINFORMATION); return 0; } @@ -594,12 +563,10 @@ INT_PTR GaduProto::gc_clearignored(WPARAM, LPARAM) INT_PTR GaduProto::gc_openconf(WPARAM, LPARAM) { // Check if connected - if (!isonline()) - { + if (!isonline()) { MessageBox(nullptr, TranslateT("You have to be connected to open new conference."), - m_tszUserName, MB_OK | MB_ICONSTOP - ); + m_tszUserName, MB_OK | MB_ICONSTOP); return 0; } @@ -620,14 +587,14 @@ int GaduProto::gc_changenick(MCONTACT hContact, wchar_t *ptszNick) if (chat->recipients && chat->recipients_count) for (int i = 0; i < chat->recipients_count; i++) // Rename this window if it's exising in the chat - if (chat->recipients[i] == uin) - { + if (chat->recipients[i] == uin) { wchar_t id[32]; UIN2IDT(uin, id); - GCEVENT gce = { m_szModuleName, chat->id, GC_EVENT_NICK }; - gce.ptszUID = id; - gce.ptszText = ptszNick; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_NICK }; + gce.pszID.w = chat->id; + gce.pszUID.w = id; + gce.pszText.w = ptszNick; debugLogW(L"gc_changenick(): Found room %s with uin %d, sending nick change %s.", chat->id, uin, id); Chat_Event(&gce); diff --git a/protocols/ICQ-WIM/src/groupchats.cpp b/protocols/ICQ-WIM/src/groupchats.cpp index 7d61b15407..5f5854b6b6 100644 --- a/protocols/ICQ-WIM/src/groupchats.cpp +++ b/protocols/ICQ-WIM/src/groupchats.cpp @@ -35,13 +35,14 @@ void CIcqProto::LoadChatInfo(SESSION_INFO *si) CMStringW role((*node)["role"].as_mstring()); CMStringW sn((*node)["sn"].as_mstring()); - GCEVENT gce = { m_szModuleName, si->ptszID, GC_EVENT_JOIN }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; gce.dwFlags = GCEF_SILENT; - gce.ptszNick = nick; - gce.ptszUID = sn; + gce.pszID.w = si->ptszID; + gce.pszNick.w = nick; + gce.pszUID.w = sn; gce.time = ::time(0); gce.bIsMe = sn == m_szOwnId; - gce.ptszStatus = TranslateW(role); + gce.pszStatus.w = TranslateW(role); Chat_Event(&gce); json_delete(node); @@ -279,7 +280,8 @@ void CIcqProto::ProcessGroupChat(const JSONNode &ev) continue; CMStringW method(it["method"].as_mstring()); - GCEVENT gce = { m_szModuleName, si->ptszID, (method == "add_members") ? GC_EVENT_JOIN : GC_EVENT_PART }; + GCEVENT gce = { m_szModuleName, 0, (method == "add_members") ? GC_EVENT_JOIN : GC_EVENT_PART }; + gce.pszID.w = si->ptszID; int iStart = 0; CMStringW members(it["members"].as_mstring()); @@ -292,8 +294,8 @@ void CIcqProto::ProcessGroupChat(const JSONNode &ev) if (pCache == nullptr) continue; - gce.ptszNick = Clist_GetContactDisplayName(pCache->m_hContact); - gce.ptszUID = member; + gce.pszNick.w = Clist_GetContactDisplayName(pCache->m_hContact); + gce.pszUID.w = member; gce.time = ::time(0); gce.bIsMe = member == m_szOwnId; Chat_Event(&gce); diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp index b086a9bd53..6567e8a390 100644 --- a/protocols/ICQ-WIM/src/server.cpp +++ b/protocols/ICQ-WIM/src/server.cpp @@ -351,10 +351,11 @@ void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNo CMStringW wszSender(it["chat"]["sender"].as_mstring()); CMStringW wszChatId(getMStringW(hContact, "ChatRoomID")); - GCEVENT gce = { m_szModuleName, wszChatId, GC_EVENT_MESSAGE }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; + gce.pszID.w = wszChatId; gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszUID = wszSender; - gce.ptszText = wszText; + gce.pszUID.w = wszSender; + gce.pszText.w = wszText; gce.time = iMsgTime; gce.bIsMe = wszSender == m_szOwnId; Chat_Event(&gce); diff --git a/protocols/IRCG/src/commandmonitor.cpp b/protocols/IRCG/src/commandmonitor.cpp index fcc1da7901..d1b42d6434 100644 --- a/protocols/IRCG/src/commandmonitor.cpp +++ b/protocols/IRCG/src/commandmonitor.cpp @@ -1298,11 +1298,12 @@ bool CIrcProto::OnIrc_ENDNAMES(const CIrcMessage *pmsg) while (PrefixToStatus(sTemp[0]) != pwszNormal) sTemp.Delete(0, 1); - GCEVENT gce = { m_szModuleName, sID, GC_EVENT_JOIN }; - gce.ptszUID = sTemp; - gce.ptszNick = sTemp; - gce.ptszStatus = sStat; - gce.bIsMe = (!mir_wstrcmpi(gce.ptszNick, m_info.sNick)) ? TRUE : FALSE; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; + gce.pszID.w = sID; + gce.pszUID.w = sTemp; + gce.pszNick.w = sTemp; + gce.pszStatus.w = sStat; + gce.bIsMe = (!mir_wstrcmpi(gce.pszNick.w, m_info.sNick)) ? TRUE : FALSE; if (gce.bIsMe) { char BitNr = -1; switch (sTemp2[0]) { diff --git a/protocols/IRCG/src/tools.cpp b/protocols/IRCG/src/tools.cpp index 740a331842..02ca2c5b6d 100644 --- a/protocols/IRCG/src/tools.cpp +++ b/protocols/IRCG/src/tools.cpp @@ -377,21 +377,21 @@ INT_PTR CIrcProto::DoEvent(int iEvent, const wchar_t* pszWindow, const wchar_t* sID = pszWindow + (CMStringW)L" - " + m_info.sNetwork; else sID = pszWindow; - gce.ptszID = (wchar_t*)sID.c_str(); + gce.pszID.w = (wchar_t*)sID.c_str(); } - else gce.ptszID = nullptr; + else gce.pszID.w = nullptr; - gce.ptszStatus = pszStatus; + gce.pszStatus.w = pszStatus; gce.dwFlags = (bAddToLog) ? GCEF_ADDTOLOG : 0; - gce.ptszNick = pszNick; - gce.ptszUID = pszNick; + gce.pszNick.w = pszNick; + gce.pszUID.w = pszNick; if (iEvent == GC_EVENT_TOPIC) - gce.ptszUserInfo = pszUserInfo; + gce.pszUserInfo.w = pszUserInfo; else - gce.ptszUserInfo = m_showAddresses ? pszUserInfo : nullptr; + gce.pszUserInfo.w = m_showAddresses ? pszUserInfo : nullptr; if (!sText.IsEmpty()) - gce.ptszText = sText.c_str(); + gce.pszText.w = sText.c_str(); gce.dwItemData = dwItemData; if (timestamp == 1) diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index 70dd3e66cc..e29c2a9d75 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -97,7 +97,7 @@ static TRoleOrAffiliationInfo sttRoleItems[] = ///////////////////////////////////////////////////////////////////////////////////////// // JabberGcInit - initializes the new chat -static const wchar_t *sttStatuses[] = { LPGENW("Visitors"), LPGENW("Participants"), LPGENW("Moderators"), LPGENW("Owners") }; +static const char *sttStatuses[] = { LPGEN("Owners"), LPGEN("Moderators"), LPGEN("Participants"), LPGEN("Visitors") }; int JabberGcGetStatus(JABBER_GC_AFFILIATION a, JABBER_GC_ROLE r) { @@ -162,7 +162,7 @@ int CJabberProto::GcInit(JABBER_LIST_ITEM *item) item->bChatActive = true; for (int i = _countof(sttStatuses) - 1; i >= 0; i--) - Chat_AddGroup(si, TranslateW(sttStatuses[i])); + Chat_AddGroup(si, TranslateW(Utf2T(sttStatuses[i]))); Chat_Control(m_szModuleName, wszJid, (item->bAutoJoin && m_bAutoJoinHidden) ? WINDOW_HIDDEN : SESSION_INITDONE); Chat_Control(m_szModuleName, wszJid, SESSION_ONLINE); @@ -173,69 +173,67 @@ void CJabberProto::GcLogShowInformation(JABBER_LIST_ITEM *item, pResourceStatus { if (!item || !user || (item->bChatActive != 2)) return; - CMStringW buf; - Utf2T wszRoomJid(item->jid), wszUserId(user->m_szResourceName); + CMStringA buf; switch (type) { case INFO_BAN: if (m_bGcLogBans) - buf.Format(TranslateT("User %s is now banned."), wszUserId.get()); + buf.Format(TranslateU("User %s is now banned."), user->m_szResourceName); break; case INFO_STATUS: if (m_bGcLogStatuses) { wchar_t *ptszDescr = Clist_GetStatusModeDescription(user->m_iStatus, 0); if (user->m_szStatusMessage) - buf.Format(TranslateT("User %s changed status to %s with message: %s"), wszUserId.get(), ptszDescr, user->m_szStatusMessage); + buf.Format(TranslateU("User %s changed status to %s with message: %s"), user->m_szResourceName, ptszDescr, user->m_szStatusMessage); else - buf.Format(TranslateT("User %s changed status to %s"), wszUserId.get(), ptszDescr); + buf.Format(TranslateU("User %s changed status to %s"), user->m_szResourceName, ptszDescr); } break; case INFO_CONFIG: if (m_bGcLogConfig) - buf.Format(TranslateT("Room configuration was changed.")); + buf.Append(TranslateU("Room configuration was changed.")); break; case INFO_AFFILIATION: if (m_bGcLogAffiliations) { - wchar_t *name = nullptr; + const char *name = nullptr; switch (user->m_affiliation) { - case AFFILIATION_NONE: name = TranslateT("None"); break; - case AFFILIATION_MEMBER: name = TranslateT("Member"); break; - case AFFILIATION_ADMIN: name = TranslateT("Admin"); break; - case AFFILIATION_OWNER: name = TranslateT("Owner"); break; - case AFFILIATION_OUTCAST: name = TranslateT("Outcast"); break; + case AFFILIATION_NONE: name = TranslateU("None"); break; + case AFFILIATION_MEMBER: name = TranslateU("Member"); break; + case AFFILIATION_ADMIN: name = TranslateU("Admin"); break; + case AFFILIATION_OWNER: name = TranslateU("Owner"); break; + case AFFILIATION_OUTCAST: name = TranslateU("Outcast"); break; } if (name) - buf.Format(TranslateT("Affiliation of %s was changed to '%s'."), wszUserId.get(), name); + buf.Format(TranslateU("Affiliation of %s was changed to '%s'."), user->m_szResourceName, name); } break; case INFO_ROLE: if (m_bGcLogRoles) { - wchar_t *name = nullptr; + const char *name = nullptr; switch (user->m_role) { - case ROLE_NONE: name = TranslateT("None"); break; - case ROLE_VISITOR: name = TranslateT("Visitor"); break; - case ROLE_PARTICIPANT: name = TranslateT("Participant"); break; - case ROLE_MODERATOR: name = TranslateT("Moderator"); break; + case ROLE_NONE: name = TranslateU("None"); break; + case ROLE_VISITOR: name = TranslateU("Visitor"); break; + case ROLE_PARTICIPANT: name = TranslateU("Participant"); break; + case ROLE_MODERATOR: name = TranslateU("Moderator"); break; } if (name) - buf.Format(TranslateT("Role of %s was changed to '%s'."), wszUserId.get(), name); + buf.Format(Translate("Role of %s was changed to '%s'."), user->m_szResourceName, name); } break; } if (!buf.IsEmpty()) { - buf.Replace(L"%", L"%%"); + buf.Replace("%", "%%"); - GCEVENT gce = { m_szModuleName, wszRoomJid, GC_EVENT_INFORMATION }; - gce.ptszNick = wszUserId; - gce.ptszUID = wszUserId; - gce.ptszText = buf; - gce.dwFlags = GCEF_ADDTOLOG; + GCEVENT gce = { m_szModuleName, item->jid, GC_EVENT_INFORMATION }; + gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; + gce.pszNick.a = gce.pszUID.a = user->m_szResourceName; + gce.pszText.a = buf; gce.time = time(0); Chat_Event(&gce); } @@ -257,12 +255,12 @@ void CJabberProto::GcLogUpdateMemberStatus(JABBER_LIST_ITEM *item, const char *r if (myNick == nullptr) myNick = JabberNickFromJID(m_szJabberJID); - Utf2T wszRoomJid(item->jid), wszNick(nick), wszUserId(resource), wszText(szReason), wszUserInfo(jid); - GCEVENT gce = { m_szModuleName, wszRoomJid }; - gce.ptszNick = wszNick; - gce.ptszUID = wszUserId; - gce.ptszUserInfo = wszUserInfo; - gce.ptszText = wszText; + GCEVENT gce = { m_szModuleName, item->jid, 0 }; + gce.dwFlags = GCEF_UTF8; + gce.pszNick.a = nick; + gce.pszUID.a = resource; + gce.pszUserInfo.a = jid; + gce.pszText.a = szReason; if (item->bChatActive == 2) { gce.dwFlags |= GCEF_ADDTOLOG; gce.time = time(0); @@ -271,7 +269,7 @@ void CJabberProto::GcLogUpdateMemberStatus(JABBER_LIST_ITEM *item, const char *r switch (gce.iType = action) { case GC_EVENT_PART: break; case GC_EVENT_KICK: - gce.ptszStatus = TranslateT("Moderator"); + gce.pszStatus.a = TranslateU("Moderator"); break; default: @@ -285,27 +283,26 @@ void CJabberProto::GcLogUpdateMemberStatus(JABBER_LIST_ITEM *item, const char *r case GC_EVENT_REMOVESTATUS: gce.dwFlags &= ~GCEF_ADDTOLOG; } - gce.ptszText = TranslateT("Moderator"); + gce.pszText.a = TranslateU("Moderator"); } - gce.ptszStatus = TranslateW(sttStatuses[JabberGcGetStatus(JS)]); + gce.pszStatus.a = TranslateU(sttStatuses[JabberGcGetStatus(JS)]); gce.bIsMe = (mir_strcmp(nick, myNick) == 0); statusToSet = JS->m_iStatus; break; } } } - Chat_Event(&gce); if (statusToSet != 0) { int flags = GC_SSE_ONLYLISTED; if (statusToSet == ID_STATUS_AWAY || statusToSet == ID_STATUS_NA || statusToSet == ID_STATUS_DND) flags += GC_SSE_ONLINE; - Chat_SetStatusEx(m_szModuleName, wszRoomJid, flags, wszNick); + Chat_SetStatusEx(m_szModuleName, Utf2T(item->jid), flags, Utf2T(nick)); gce.iType = GC_EVENT_SETCONTACTSTATUS; - gce.ptszText = wszNick; - gce.ptszUID = wszUserId; + gce.pszText.a = nick; + gce.pszUID.a = resource; gce.dwItemData = statusToSet; Chat_Event(&gce); } diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp index 682de9e84a..2719ba4690 100644 --- a/protocols/JabberG/src/jabber_groupchat.cpp +++ b/protocols/JabberG/src/jabber_groupchat.cpp @@ -788,15 +788,16 @@ void CJabberProto::RenameParticipantNick(JABBER_LIST_ITEM *item, const char *old setUString(hContact, "MyNick", newNick); } - Utf2T wszRoomId(item->jid), wszOld(oldNick), wszNew(newNick), wszInfo(jid); - Chat_ChangeUserId(m_szModuleName, wszRoomId, wszOld, wszNew); + Chat_ChangeUserId(m_szModuleName, Utf2T(item->jid), Utf2T(oldNick), Utf2T(newNick)); - GCEVENT gce = { m_szModuleName, wszRoomId, GC_EVENT_NICK }; - gce.ptszUserInfo = wszInfo; + GCEVENT gce = { m_szModuleName, item->jid, GC_EVENT_NICK }; + gce.dwFlags = GCEF_UTF8; + gce.pszID.a = item->jid; + gce.pszUserInfo.a = jid; gce.time = time(0); - gce.ptszNick = wszOld; - gce.ptszUID = wszNew; - gce.ptszText = wszNew; + gce.pszNick.a = oldNick; + gce.pszUID.a = newNick; + gce.pszText.a = newNick; Chat_Event(&gce); } @@ -1010,7 +1011,7 @@ void CJabberProto::GroupchatProcessPresence(const TiXmlElement *node) void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node) { const TiXmlElement *n, *m; - const char *from, *type, *p, *nick, *resource; + const char *from, *type, *p, *nick; JABBER_LIST_ITEM *item; CMStringW imgLink; @@ -1022,12 +1023,10 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node) if (!mir_strcmp(type, "error")) return; - Utf2T roomJid(item->jid); - GCEVENT gce = { m_szModuleName, roomJid, 0 }; + GCEVENT gce = { m_szModuleName, item->jid, 0 }; + gce.dwFlags = GCEF_UTF8; - const char *msgText = nullptr; - - resource = strchr(from, '/'); + const char *resource = strchr(from, '/'), *msgText; if (resource != nullptr && *++resource == '\0') resource = nullptr; @@ -1051,6 +1050,7 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node) resource = tmpnick; } } + item->getTemp()->m_szStatusMessage = mir_strdup(msgText); } else { @@ -1093,15 +1093,14 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node) } else nick = nullptr; - CMStringW tszText(Utf2T(msgText).get()); - tszText.Replace(L"%", L"%%"); - tszText += imgLink; + CMStringA szText(msgText); + szText.Replace("%", "%%"); + szText += imgLink; - Utf2T wszUserId(resource), wszNick(nick); - gce.ptszUID = wszUserId; - gce.ptszNick = wszNick; + gce.pszUID.a = resource; + gce.pszNick.a = nick; gce.time = msgTime; - gce.ptszText = tszText; + gce.pszText.a = szText; gce.bIsMe = nick == nullptr ? FALSE : (mir_strcmp(resource, item->nick) == 0); if (!isHistory) @@ -1115,7 +1114,7 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node) item->bChatActive = 2; if (gce.iType == GC_EVENT_TOPIC) - Chat_SetStatusbarText(m_szModuleName, roomJid, tszText); + Chat_SetStatusbarText(m_szModuleName, Utf2T(item->jid), Utf2T(szText)); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/MSN/src/msn_chat.cpp b/protocols/MSN/src/msn_chat.cpp index d23b5c1f5e..b18124501a 100644 --- a/protocols/MSN/src/msn_chat.cpp +++ b/protocols/MSN/src/msn_chat.cpp @@ -166,20 +166,22 @@ void CMsnProto::MSN_GCProcessThreadActivity(ezxml_t xmli, const wchar_t *mChatID { if (!mir_strcmp(xmli->name, "topicupdate")) { ezxml_t initiator = ezxml_child(xmli, "initiator"); - GCEVENT gce = { m_szModuleName, mChatID, GC_EVENT_TOPIC }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_TOPIC }; + gce.pszID.w = mChatID; gce.dwFlags = GCEF_ADDTOLOG; gce.time = MsnTSToUnixtime(ezxml_txt(ezxml_child(xmli, "eventtime"))); - gce.ptszUID = initiator ? mir_a2u(initiator->txt) : nullptr; + gce.pszUID.w = initiator ? mir_a2u(initiator->txt) : nullptr; MCONTACT hContInitiator = MSN_HContactFromEmail(initiator ? initiator->txt : nullptr); - gce.ptszNick = GetContactNameT(hContInitiator); - gce.ptszText = mir_a2u(ezxml_txt(ezxml_child(xmli, "value"))); + gce.pszNick.w = GetContactNameT(hContInitiator); + gce.pszText.w = mir_a2u(ezxml_txt(ezxml_child(xmli, "value"))); Chat_Event(&gce); - mir_free((wchar_t*)gce.ptszUID); - mir_free((wchar_t*)gce.ptszText); + mir_free((wchar_t*)gce.pszUID.w); + mir_free((wchar_t*)gce.pszText.w); } else if (ezxml_t target = ezxml_child(xmli, "target")) { MCONTACT hContInitiator = NULL; - GCEVENT gce = { m_szModuleName, mChatID, 0 }; + GCEVENT gce = { m_szModuleName, 0, 0 }; + gce.pszID.w = mChatID; gce.dwFlags = GCEF_ADDTOLOG; if (!mir_strcmp(xmli->name, "deletemember")) { @@ -187,7 +189,7 @@ void CMsnProto::MSN_GCProcessThreadActivity(ezxml_t xmli, const wchar_t *mChatID if (ezxml_t initiator = ezxml_child(xmli, "initiator")) { if (mir_strcmp(initiator->txt, target->txt)) { hContInitiator = MSN_HContactFromEmail(initiator->txt); - gce.ptszStatus = GetContactNameT(hContInitiator); + gce.pszStatus.w = GetContactNameT(hContInitiator); gce.iType = GC_EVENT_KICK; } } @@ -199,9 +201,9 @@ void CMsnProto::MSN_GCProcessThreadActivity(ezxml_t xmli, const wchar_t *mChatID gce.iType = GC_EVENT_ADDSTATUS; if (ezxml_t initiator = ezxml_child(xmli, "initiator")) { hContInitiator = MSN_HContactFromEmail(initiator->txt); - gce.ptszText= GetContactNameT(hContInitiator); + gce.pszText.w= GetContactNameT(hContInitiator); } - gce.ptszStatus = L"admin"; + gce.pszStatus.w = L"admin"; } if (gce.iType) { @@ -211,7 +213,7 @@ void CMsnProto::MSN_GCProcessThreadActivity(ezxml_t xmli, const wchar_t *mChatID while (target) { switch (gce.iType) { case GC_EVENT_JOIN: - gce.ptszStatus = MSN_GCGetRole(MSN_GetThreadByChatId(mChatID), target->txt); + gce.pszStatus.w = MSN_GCGetRole(MSN_GetThreadByChatId(mChatID), target->txt); __fallthrough; case GC_EVENT_KICK: @@ -227,11 +229,11 @@ void CMsnProto::MSN_GCProcessThreadActivity(ezxml_t xmli, const wchar_t *mChatID char *szEmail, *szNet; parseWLID(NEWSTR_ALLOCA(pszTarget), &szNet, &szEmail, nullptr); gce.bIsMe = !mir_strcmpi(szEmail, GetMyUsername(atoi(szNet))); - gce.ptszUID = mir_a2u(pszTarget); + gce.pszUID.w = mir_a2u(pszTarget); MCONTACT hContTarget = MSN_HContactFromEmail(pszTarget); - gce.ptszNick = GetContactNameT(hContTarget); + gce.pszNick.w = GetContactNameT(hContTarget); Chat_Event(&gce); - mir_free((wchar_t*)gce.ptszUID); + mir_free((wchar_t*)gce.pszUID.w); if ((gce.iType == GC_EVENT_PART || gce.iType == GC_EVENT_KICK) && gce.bIsMe) { Chat_Control(m_szModuleName, mChatID, SESSION_OFFLINE); break; @@ -263,20 +265,21 @@ void CMsnProto::MSN_GCRefreshThreadsInfo(void) void CMsnProto::MSN_GCAddMessage(wchar_t *mChatID, MCONTACT hContact, char *email, time_t ts, bool sentMsg, char *msgBody) { - GCEVENT gce = { m_szModuleName, mChatID, GC_EVENT_MESSAGE }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; + gce.pszID.w = mChatID; gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszUID = mir_a2u(email); - gce.ptszNick = GetContactNameT(hContact); + gce.pszUID.w = mir_a2u(email); + gce.pszNick.w = GetContactNameT(hContact); gce.time = ts; gce.bIsMe = sentMsg; wchar_t* p = mir_utf8decodeW(msgBody); - gce.ptszText = EscapeChatTags(p); + gce.pszText.w = EscapeChatTags(p); mir_free(p); Chat_Event(&gce); - mir_free((void*)gce.ptszUID); - mir_free((void*)gce.ptszText); + mir_free((void*)gce.pszUID.w); + mir_free((void*)gce.pszText.w); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -482,16 +485,17 @@ int CMsnProto::MSN_GCEventHook(WPARAM, LPARAM lParam) DBVARIANT dbv; int bError = getWString("Nick", &dbv); - GCEVENT gce = { m_szModuleName, gch->ptszID, GC_EVENT_MESSAGE }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; + gce.pszID.w = gch->ptszID; gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = bError ? L"" : dbv.pwszVal; - gce.ptszUID = mir_a2u(MyOptions.szEmail); + gce.pszNick.w = bError ? L"" : dbv.pwszVal; + gce.pszUID.w = mir_a2u(MyOptions.szEmail); gce.time = time(0); - gce.ptszText = gch->ptszText; + gce.pszText.w = gch->ptszText; gce.bIsMe = TRUE; Chat_Event(&gce); - mir_free((void*)gce.ptszUID); + mir_free((void*)gce.pszUID.w); if (!bError) db_free(&dbv); } diff --git a/protocols/MinecraftDynmap/src/chat.cpp b/protocols/MinecraftDynmap/src/chat.cpp index 7e267dda79..be33afe618 100644 --- a/protocols/MinecraftDynmap/src/chat.cpp +++ b/protocols/MinecraftDynmap/src/chat.cpp @@ -27,25 +27,22 @@ void MinecraftDynmapProto::UpdateChat(const char *name, const char *message, con std::string smessage = message; utils::text::replace_all(&smessage, "%", "%%"); - ptrW tmessage(mir_a2u_cp(smessage.c_str(), CP_UTF8)); - ptrW tname(mir_a2u_cp(name, CP_UTF8)); - - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_MESSAGE }; + GCEVENT gce = { m_szModuleName, szRoomName, GC_EVENT_MESSAGE }; + gce.dwFlags = GCEF_UTF8; gce.time = timestamp; - gce.ptszText = tmessage; + gce.pszText.a = smessage.c_str(); - if (tname == NULL) { + if (name == NULL) { gce.iType = GC_EVENT_INFORMATION; - tname = mir_wstrdup(TranslateT("Server")); + name = TranslateU("Server"); gce.bIsMe = false; } else gce.bIsMe = (m_nick == name); if (addtolog) - gce.dwFlags |= GCEF_ADDTOLOG; + gce.dwFlags |= GCEF_ADDTOLOG; - gce.ptszNick = tname; - gce.ptszUID = gce.ptszNick; + gce.pszUID.a = gce.pszNick.a = name; Chat_Event(&gce); } @@ -84,34 +81,27 @@ int MinecraftDynmapProto::OnChatEvent(WPARAM, LPARAM lParam) void MinecraftDynmapProto::AddChatContact(const char *name) { - ptrW tname(mir_a2u_cp(name, CP_UTF8)); - - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_JOIN }; + GCEVENT gce = { m_szModuleName, szRoomName, GC_EVENT_JOIN }; gce.time = DWORD(time(0)); - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = tname; - gce.ptszUID = gce.ptszNick; + gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; + gce.pszUID.a = gce.pszNick.a = name; gce.bIsMe = (m_nick == name); if (gce.bIsMe) - gce.ptszStatus = L"Admin"; + gce.pszStatus.a = "Admin"; else - gce.ptszStatus = L"Normal"; + gce.pszStatus.a = "Normal"; Chat_Event(&gce); } void MinecraftDynmapProto::DeleteChatContact(const char *name) { - ptrW tname(mir_a2u_cp(name, CP_UTF8)); - - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_PART }; - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = tname; - gce.ptszUID = gce.ptszNick; + GCEVENT gce = { m_szModuleName, szRoomName, GC_EVENT_PART }; + gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; + gce.pszUID.a = gce.pszNick.a = name; gce.time = DWORD(time(0)); gce.bIsMe = (m_nick == name); - Chat_Event(&gce); } @@ -137,12 +127,10 @@ INT_PTR MinecraftDynmapProto::OnJoinChat(WPARAM,LPARAM suppress) void MinecraftDynmapProto::SetTopic(const char *topic) { - ptrW ttopic(mir_a2u_cp(topic, CP_UTF8)); - - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_TOPIC }; + GCEVENT gce = { m_szModuleName, szRoomName, GC_EVENT_TOPIC }; + gce.dwFlags = GCEF_UTF8; gce.time = ::time(0); - gce.ptszText = ttopic; - + gce.pszText.a = topic; Chat_Event( &gce); } diff --git a/protocols/MinecraftDynmap/src/proto.cpp b/protocols/MinecraftDynmap/src/proto.cpp index da4ad2d994..9f1b06b19a 100644 --- a/protocols/MinecraftDynmap/src/proto.cpp +++ b/protocols/MinecraftDynmap/src/proto.cpp @@ -58,6 +58,7 @@ MinecraftDynmapProto::MinecraftDynmapProto(const char* proto_name, const wchar_t // Client instantiation this->error_count_ = 0; this->chatHandle_ = nullptr; + this->szRoomName = mir_utf8encodeW(username); } MinecraftDynmapProto::~MinecraftDynmapProto() diff --git a/protocols/MinecraftDynmap/src/proto.h b/protocols/MinecraftDynmap/src/proto.h index 108f80a7ec..495d651071 100644 --- a/protocols/MinecraftDynmap/src/proto.h +++ b/protocols/MinecraftDynmap/src/proto.h @@ -24,6 +24,8 @@ along with this program. If not, see . class MinecraftDynmapProto : public PROTO { + ptrA szRoomName; + public: MinecraftDynmapProto(const char *proto_name, const wchar_t *username); ~MinecraftDynmapProto(); @@ -65,7 +67,6 @@ public: void __cdecl SendMsgWorker(void*); // Chat handling - void AddChat(const char *id, const char *name); void UpdateChat(const char *name, const char *message, const time_t timestamp = time(0), bool addtochat = true); void AddChatContact(const char *nick); void DeleteChatContact(const char *name); diff --git a/protocols/Omegle/src/chat.cpp b/protocols/Omegle/src/chat.cpp index 0b37532c8d..28e6fff0a7 100644 --- a/protocols/Omegle/src/chat.cpp +++ b/protocols/Omegle/src/chat.cpp @@ -48,9 +48,10 @@ void OmegleProto::UpdateChat(const wchar_t *name, const wchar_t *message, bool a CMStringW smessage(message); smessage.Replace(L"%", L"%%"); - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_MESSAGE }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; + gce.pszID.w = m_tszUserName; gce.time = ::time(0); - gce.ptszText = smessage.c_str(); + gce.pszText.w = smessage.c_str(); if (name == nullptr) { gce.iType = GC_EVENT_INFORMATION; @@ -62,8 +63,8 @@ void OmegleProto::UpdateChat(const wchar_t *name, const wchar_t *message, bool a if (addtolog) gce.dwFlags |= GCEF_ADDTOLOG; - gce.ptszNick = name; - gce.ptszUID = gce.ptszNick; + gce.pszNick.w = name; + gce.pszUID.w = gce.pszNick.w; Chat_Event(&gce); } @@ -204,11 +205,12 @@ void OmegleProto::SendChatMessage(std::string text) void OmegleProto::AddChatContact(const wchar_t *name) { - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_JOIN }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; + gce.pszID.w = m_tszUserName; gce.time = DWORD(time(0)); gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = name; - gce.ptszUID = gce.ptszNick; + gce.pszNick.w = name; + gce.pszUID.w = gce.pszNick.w; if (name == nullptr) gce.bIsMe = false; @@ -216,19 +218,20 @@ void OmegleProto::AddChatContact(const wchar_t *name) gce.bIsMe = mir_wstrcmp(name, this->facy.nick_); if (gce.bIsMe) - gce.ptszStatus = L"Admin"; + gce.pszStatus.w = L"Admin"; else - gce.ptszStatus = L"Normal"; + gce.pszStatus.w = L"Normal"; Chat_Event(&gce); } void OmegleProto::DeleteChatContact(const wchar_t *name) { - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_PART }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_PART }; + gce.pszID.w = m_tszUserName; gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = name; - gce.ptszUID = gce.ptszNick; + gce.pszNick.w = name; + gce.pszUID.w = gce.pszNick.w; gce.time = DWORD(time(0)); if (name == nullptr) gce.bIsMe = false; @@ -260,13 +263,14 @@ INT_PTR OmegleProto::OnJoinChat(WPARAM, LPARAM suppress) void OmegleProto::SetTopic(const wchar_t *topic) { - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_TOPIC }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_TOPIC }; + gce.pszID.w = m_tszUserName; gce.time = ::time(0); if (topic == nullptr) - gce.ptszText = TranslateT("Omegle is a great way of meeting new friends!"); + gce.pszText.w = TranslateT("Omegle is a great way of meeting new friends!"); else - gce.ptszText = topic; + gce.pszText.w = topic; Chat_Event(&gce); } diff --git a/protocols/Sametime/src/conference.cpp b/protocols/Sametime/src/conference.cpp index c08924a9a6..19cfa0cc16 100644 --- a/protocols/Sametime/src/conference.cpp +++ b/protocols/Sametime/src/conference.cpp @@ -120,7 +120,8 @@ void mwServiceConf_conf_opened(mwConference* conf, GList* members) Chat_AddGroup(si, TranslateT("Normal")); // add users - GCEVENT gce = { proto->m_szModuleName, tszConfId, GC_EVENT_JOIN }; + GCEVENT gce = { proto->m_szModuleName, 0, GC_EVENT_JOIN }; + gce.pszID.w = tszConfId; GList *user = members; for (;user; user=user->next) { @@ -129,8 +130,8 @@ void mwServiceConf_conf_opened(mwConference* conf, GList* members) ptrW tszUserName(mir_utf8decodeW(((mwLoginInfo*)user->data)->user_name)); ptrW tszUserId(mir_utf8decodeW(((mwLoginInfo*)user->data)->login_id)); gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = tszUserName; - gce.ptszUID = tszUserId; + gce.pszNick.w = tszUserName; + gce.pszUID.w = tszUserId; gce.bIsMe = (strcmp(((mwLoginInfo*)user->data)->login_id, proto->my_login_info->login_id) == 0); Chat_Event( &gce); } @@ -181,11 +182,12 @@ void mwServiceConf_on_peer_joined(mwConference* conf, mwLoginInfo *user) ptrW tszUserId(mir_utf8decodeW(user->login_id)); // add user - GCEVENT gce = { proto->m_szModuleName, tszConfId, GC_EVENT_JOIN }; + GCEVENT gce = { proto->m_szModuleName, 0, GC_EVENT_JOIN }; + gce.pszID.w = tszConfId; gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = tszUserName; - gce.ptszUID = tszUserId; - gce.ptszStatus = L"Normal"; + gce.pszNick.w = tszUserName; + gce.pszUID.w = tszUserId; + gce.pszStatus.w = L"Normal"; gce.time = (DWORD)time(0); Chat_Event( &gce); @@ -206,11 +208,12 @@ void mwServiceConf_on_peer_parted(mwConference* conf, mwLoginInfo* user) ptrW tszUserId(mir_utf8decodeW(user->login_id)); // remove user - GCEVENT gce = { proto->m_szModuleName, tszConfId, GC_EVENT_PART }; + GCEVENT gce = { proto->m_szModuleName, 0, GC_EVENT_PART }; + gce.pszID.w = tszConfId; gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = tszUserName; - gce.ptszUID = tszUserId; - gce.ptszStatus = L"Normal"; + gce.pszNick.w = tszUserName; + gce.pszUID.w = tszUserId; + gce.pszStatus.w = L"Normal"; gce.time = (DWORD)time(0); Chat_Event(&gce); } @@ -226,11 +229,12 @@ void mwServiceConf_on_text(mwConference* conf, mwLoginInfo* user, const char* wh ptrW tszUserId(mir_utf8decodeW(user->login_id)); ptrW tszUserName(mir_utf8decodeW(user->user_name)); - GCEVENT gce = { proto->m_szModuleName, tszConfId, GC_EVENT_MESSAGE }; + GCEVENT gce = { proto->m_szModuleName, 0, GC_EVENT_MESSAGE }; + gce.pszID.w = tszConfId; gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszText = textT; - gce.ptszNick = tszUserName; - gce.ptszUID = tszUserId; + gce.pszText.w = textT; + gce.pszNick.w = tszUserName; + gce.pszUID.w = tszUserId; gce.time = (DWORD)time(0); Chat_Event(&gce); } diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index a95cf6a191..44ee84166b 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -96,18 +96,18 @@ int CSkypeProto::OnGroupChatEventHook(WPARAM, LPARAM lParam) if (mir_strcmp(gch->pszModule, m_szModuleName) != 0) return 0; - _T2A chat_id(gch->ptszID); + T2Utf chat_id(gch->ptszID), user_id(gch->ptszUID); switch (gch->iType) { case GC_USER_MESSAGE: - OnSendChatMessage(gch->ptszID, gch->ptszText); + OnSendChatMessage(chat_id, gch->ptszText); break; case GC_USER_PRIVMESS: { - MCONTACT hContact = FindContact(_T2A(gch->ptszUID)); + MCONTACT hContact = FindContact(user_id); if (hContact == NULL) { - hContact = AddContact(_T2A(gch->ptszUID), true); + hContact = AddContact(user_id, true); setWord(hContact, "Status", ID_STATUS_ONLINE); db_set_b(hContact, "CList", "Hidden", 1); setWString(hContact, "Nick", gch->ptszUID); @@ -154,62 +154,57 @@ int CSkypeProto::OnGroupChatEventHook(WPARAM, LPARAM lParam) break; case GC_USER_NICKLISTMENU: - { - _T2A user_id(gch->ptszUID); - - switch (gch->dwData) { - case 10: - SendRequest(new KickUserRequest(chat_id, user_id, li)); - break; - case 30: - SendRequest(new InviteUserToChatRequest(chat_id, user_id, "Admin", li)); - break; - case 40: - SendRequest(new InviteUserToChatRequest(chat_id, user_id, "User", li)); - break; - case 50: - ptrW tnick_old(GetChatContactNick(chat_id, _T2A(gch->ptszUID), _T2A(gch->ptszText))); - - ENTER_STRING pForm = { sizeof(pForm) }; - pForm.type = ESF_COMBO; - pForm.recentCount = 0; - pForm.caption = TranslateT("Enter new nickname"); - pForm.ptszInitVal = tnick_old; - pForm.szModuleName = m_szModuleName; - pForm.szDataPrefix = "renamenick_"; - - if (EnterString(&pForm)) { - MCONTACT hChatContact = FindChatRoom(chat_id); - if (hChatContact == NULL) - break; // This probably shouldn't happen, but if chat is NULL for some reason, do nothing - - ptrW tnick_new(pForm.ptszResult); - bool reset = mir_wstrlen(tnick_new) == 0; - if (reset) { - // User fill blank name, which means we reset the custom nick - db_unset(hChatContact, "UsersNicks", _T2A(gch->ptszUID)); - tnick_new = GetChatContactNick(chat_id, _T2A(gch->ptszUID), _T2A(gch->ptszText)); - } - - if (!mir_wstrcmp(tnick_old, tnick_new)) - break; // New nick is same, do nothing - - GCEVENT gce = { m_szModuleName, gch->ptszID, GC_EVENT_NICK }; - gce.ptszNick = tnick_old; - gce.bIsMe = IsMe(user_id); - gce.ptszUID = gch->ptszUID; - gce.ptszText = tnick_new; - gce.dwFlags = GCEF_ADDTOLOG; - gce.time = time(0); - Chat_Event(&gce); - - if (!reset) - db_set_ws(hChatContact, "UsersNicks", _T2A(gch->ptszUID), tnick_new); + switch (gch->dwData) { + case 10: + SendRequest(new KickUserRequest(chat_id, user_id, li)); + break; + case 30: + SendRequest(new InviteUserToChatRequest(chat_id, user_id, "Admin", li)); + break; + case 40: + SendRequest(new InviteUserToChatRequest(chat_id, user_id, "User", li)); + break; + case 50: + ptrA tnick_old(GetChatContactNick(chat_id, user_id, T2Utf(gch->ptszText))); + + ENTER_STRING pForm = { sizeof(pForm) }; + pForm.type = ESF_COMBO; + pForm.recentCount = 0; + pForm.caption = TranslateT("Enter new nickname"); + pForm.szModuleName = m_szModuleName; + pForm.szDataPrefix = "renamenick_"; + + if (EnterString(&pForm)) { + MCONTACT hChatContact = FindChatRoom(chat_id); + if (hChatContact == NULL) + break; // This probably shouldn't happen, but if chat is NULL for some reason, do nothing + + ptrA tnick_new(mir_utf8encodeW(pForm.ptszResult)); + bool reset = mir_strlen(tnick_new) == 0; + if (reset) { + // User fill blank name, which means we reset the custom nick + db_unset(hChatContact, "UsersNicks", user_id); + tnick_new = GetChatContactNick(chat_id, user_id, _T2A(gch->ptszText)); } - break; + + if (!mir_strcmp(tnick_old, tnick_new)) + break; // New nick is same, do nothing + + GCEVENT gce = { m_szModuleName, chat_id, GC_EVENT_NICK }; + gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; + gce.pszNick.a = tnick_old; + gce.bIsMe = IsMe(user_id); + gce.pszUID.a = user_id; + gce.pszText.a = tnick_new; + gce.time = time(0); + Chat_Event(&gce); + + if (!reset) + db_set_utf(hChatContact, "UsersNicks", user_id, tnick_new); } break; } + break; } return 0; } @@ -261,7 +256,7 @@ void CSkypeProto::OnChatEvent(const JSONNode &node) std::string messageType = node["messagetype"].as_string(); if (messageType == "Text" || messageType == "RichText") { ptrA szClearedContent(messageType == "RichText" ? RemoveHtml(strContent.c_str()) : mir_strdup(strContent.c_str())); - AddMessageToChat(_A2T(szConversationName), _A2T(szFromSkypename), szClearedContent, nEmoteOffset != NULL, nEmoteOffset, timestamp); + AddMessageToChat(szConversationName, szFromSkypename, szClearedContent, nEmoteOffset != NULL, nEmoteOffset, timestamp); } else if (messageType == "ThreadActivity/AddMember") { // 14291862291648:initiator8:user @@ -271,7 +266,7 @@ void CSkypeProto::OnChatEvent(const JSONNode &node) if (auto *pRoot = doc.FirstChildElement("addMember")) { CMStringA target = ParseUrl(pRoot->FirstChildElement("target")->Value(), "8:"); - AddChatContact(_A2T(szConversationName), target, target, L"User"); + AddChatContact(szConversationName, target, target, "User"); } } else if (messageType == "ThreadActivity/DeleteMember") { @@ -283,7 +278,7 @@ void CSkypeProto::OnChatEvent(const JSONNode &node) if (auto *pRoot = doc.FirstChildElement("deletemember")) { CMStringA target = ParseUrl(pRoot->FirstChildElement("target")->Value(), "8:"); CMStringA initiator = ParseUrl(pRoot->FirstChildElement("initiator")->Value(), "8:"); - RemoveChatContact(_A2T(szConversationName), target, target, true, initiator); + RemoveChatContact(szConversationName, target, target, true, initiator); } } else if (messageType == "ThreadActivity/TopicUpdate") { @@ -315,25 +310,21 @@ void CSkypeProto::OnChatEvent(const JSONNode &node) CMStringA id = ParseUrl(pTarget->FirstChildElement("id")->Value(), "8:"); const char *role = pTarget->FirstChildElement("role")->Value(); - ptrW tszId(mir_a2u(id)); - ptrW tszRole(mir_a2u(role)); - ptrW tszInitiator(mir_a2u(initiator)); - - GCEVENT gce = { m_szModuleName, _A2T(szConversationName), !mir_strcmpi(role, "Admin") ? GC_EVENT_ADDSTATUS : GC_EVENT_REMOVESTATUS }; - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = tszId; - gce.ptszUID = tszId; - gce.ptszText = tszInitiator; + GCEVENT gce = { m_szModuleName, szConversationName, !mir_strcmpi(role, "Admin") ? GC_EVENT_ADDSTATUS : GC_EVENT_REMOVESTATUS }; + gce.dwFlags = GCEF_ADDTOLOG + GCEF_UTF8; + gce.pszNick.a = id; + gce.pszUID.a = id; + gce.pszText.a = initiator; gce.time = time(0); gce.bIsMe = IsMe(id); - gce.ptszStatus = TranslateT("Admin"); + gce.pszStatus.a = TranslateU("Admin"); Chat_Event(&gce); } } } } -void CSkypeProto::OnSendChatMessage(const wchar_t *chat_id, const wchar_t *tszMessage) +void CSkypeProto::OnSendChatMessage(const char *chat_id, const wchar_t *tszMessage) { if (!IsOnline()) return; @@ -342,33 +333,33 @@ void CSkypeProto::OnSendChatMessage(const wchar_t *chat_id, const wchar_t *tszMe rtrimw(buf); Chat_UnescapeTags(buf); - ptrA szChatId(mir_u2a(chat_id)); ptrA szMessage(mir_utf8encodeW(buf)); if (strncmp(szMessage, "/me ", 4) == 0) - SendRequest(new SendChatActionRequest(szChatId, time(0), szMessage, li)); + SendRequest(new SendChatActionRequest(chat_id, time(0), szMessage, li)); else - SendRequest(new SendChatMessageRequest(szChatId, time(0), szMessage, li)); + SendRequest(new SendChatMessageRequest(chat_id, time(0), szMessage, li)); } -void CSkypeProto::AddMessageToChat(const wchar_t *chat_id, const wchar_t *from, const char *content, bool isAction, int emoteOffset, time_t timestamp, bool isLoading) +void CSkypeProto::AddMessageToChat(const char *chat_id, const char *from, const char *content, bool isAction, int emoteOffset, time_t timestamp, bool isLoading) { - ptrW tnick(GetChatContactNick(_T2A(chat_id), _T2A(from), _T2A(from))); + ptrA tnick(GetChatContactNick(chat_id, from, from)); GCEVENT gce = { m_szModuleName, chat_id, isAction ? GC_EVENT_ACTION : GC_EVENT_MESSAGE }; - gce.bIsMe = IsMe(_T2A(from)); - gce.ptszNick = tnick; + gce.dwFlags = GCEF_UTF8; + gce.bIsMe = IsMe(from); + gce.pszNick.a = tnick; gce.time = timestamp; - gce.ptszUID = from; + gce.pszUID.a = from; - CMStringW tszText(ptrW(mir_utf8decodeW(content))); - tszText.Replace(L"%", L"%%"); + CMStringA szText(content); + szText.Replace("%", "%%"); if (!isAction) { - gce.ptszText = tszText; - gce.dwFlags = GCEF_ADDTOLOG; + gce.pszText.a = szText; + gce.dwFlags |= GCEF_ADDTOLOG; } - else gce.ptszText = &(tszText.GetBuffer())[emoteOffset]; + else gce.pszText.a = szText.GetBuffer() + emoteOffset; if (isLoading) gce.dwFlags |= GCEF_NOTNOTIFY; @@ -398,8 +389,8 @@ void CSkypeProto::OnGetChatInfo(const NETLIBHTTPREQUEST *response, void *p) CMStringA username(UrlToSkypename(member["userLink"].as_string().c_str())); std::string role = member["role"].as_string(); - if (!IsChatContact(_A2T(chatId), username)) - AddChatContact(_A2T(chatId), username, username, _A2T(role.c_str()), true); + if (!IsChatContact(chatId, username)) + AddChatContact(chatId, username, username, role.c_str(), true); } PushRequest(new GetHistoryRequest(chatId, 15, true, 0, li), &CSkypeProto::OnGetServerHistory); } @@ -413,107 +404,100 @@ void CSkypeProto::RenameChat(const char *chat_id, const char *name) void CSkypeProto::ChangeChatTopic(const char *chat_id, const char *topic, const char *initiator) { - ptrW tchat_id(mir_a2u(chat_id)); - ptrW tname(mir_a2u(initiator)); - ptrW ttopic(mir_utf8decodeW(topic)); - - GCEVENT gce = { m_szModuleName, tchat_id, GC_EVENT_TOPIC }; - gce.ptszUID = tname; - gce.ptszNick = tname; - gce.ptszText = ttopic; + GCEVENT gce = { m_szModuleName, chat_id, GC_EVENT_TOPIC }; + gce.dwFlags = GCEF_UTF8; + gce.pszUID.a = initiator; + gce.pszNick.a = initiator; + gce.pszText.a = topic; Chat_Event(&gce); } -bool CSkypeProto::IsChatContact(const wchar_t *chat_id, const char *id) +bool CSkypeProto::IsChatContact(const char *chat_id, const char *id) { ptrA users(GetChatUsers(chat_id)); return (users != NULL && strstr(users, id) != nullptr); } -char *CSkypeProto::GetChatUsers(const wchar_t *chat_id) +char* CSkypeProto::GetChatUsers(const char *chat_id) { + Utf2T id(chat_id); + GC_INFO gci = { 0 }; gci.Flags = GCF_USERS; gci.pszModule = m_szModuleName; - gci.pszID = chat_id; + gci.pszID = id; Chat_GetInfo(&gci); return gci.pszUsers; } -wchar_t* CSkypeProto::GetChatContactNick(const char *chat_id, const char *id, const char *name) +char* CSkypeProto::GetChatContactNick(const char *chat_id, const char *id, const char *name) { // Check if there is custom nick for this chat contact if (chat_id != nullptr) { - if (wchar_t *tname = db_get_wsa(FindChatRoom(chat_id), "UsersNicks", id)) + if (char *tname = db_get_utfa(FindChatRoom(chat_id), "UsersNicks", id)) return tname; } // Check if we have this contact in database if (IsMe(id)) { // Return my nick - if (wchar_t *tname = getWStringA(NULL, "Nick")) + if (char *tname = getUStringA(NULL, "Nick")) return tname; } else { MCONTACT hContact = FindContact(id); if (hContact != NULL) { // Primarily return custom name - if (wchar_t *tname = db_get_wsa(hContact, "CList", "MyHandle")) + if (char *tname = db_get_utfa(hContact, "CList", "MyHandle")) return tname; // If not exists, then user nick - if (wchar_t *tname = getWStringA(hContact, "Nick")) + if (char *tname = getUStringA(hContact, "Nick")) return tname; } } // Return default value as nick - given name or user id if (name != nullptr) - return mir_a2u_cp(name, CP_UTF8); - else - return mir_a2u(id); + return mir_strdup(name); + return mir_strdup(id); } -void CSkypeProto::AddChatContact(const wchar_t *tchat_id, const char *id, const char *name, const wchar_t *role, bool isChange) +void CSkypeProto::AddChatContact(const char *chat_id, const char *id, const char *name, const char *role, bool isChange) { - if (IsChatContact(tchat_id, id)) + if (IsChatContact(chat_id, id)) return; - ptrW tnick(GetChatContactNick(_T2A(tchat_id), id, name)); - ptrW tid(mir_a2u(id)); + ptrA szNick(GetChatContactNick(chat_id, id, name)); - GCEVENT gce = { m_szModuleName, tchat_id, GC_EVENT_JOIN }; - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = tnick; - gce.ptszUID = tid; + GCEVENT gce = { m_szModuleName, chat_id, GC_EVENT_JOIN }; + gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; + gce.pszNick.a = szNick; + gce.pszUID.a = id; gce.time = !isChange ? time(0) : NULL; gce.bIsMe = IsMe(id); - gce.ptszStatus = TranslateW(role); - + gce.pszStatus.a = TranslateU(role); Chat_Event(&gce); } -void CSkypeProto::RemoveChatContact(const wchar_t *tchat_id, const char *id, const char *name, bool isKick, const char *initiator) +void CSkypeProto::RemoveChatContact(const char *chat_id, const char *id, const char *name, bool isKick, const char *initiator) { if (IsMe(id)) return; - ptrW tnick(GetChatContactNick(_T2A(tchat_id), id, name)); - ptrW tinitiator(GetChatContactNick(_T2A(tchat_id), initiator, initiator)); + ptrA szNick(GetChatContactNick(chat_id, id, name)); + ptrA szInitiator(GetChatContactNick(chat_id, initiator, initiator)); ptrW tid(mir_a2u(id)); - GCEVENT gce = { m_szModuleName, tchat_id, isKick ? GC_EVENT_KICK : GC_EVENT_PART }; - if (isKick) { - gce.ptszUID = tid; - gce.ptszNick = tnick; - gce.ptszStatus = tinitiator; - gce.time = time(0); - } + GCEVENT gce = { m_szModuleName, chat_id, isKick ? GC_EVENT_KICK : GC_EVENT_PART }; + gce.dwFlags = GCEF_UTF8; + gce.pszNick.a = szNick; + gce.pszUID.a = id; + gce.time = time(0); + if (isKick) + gce.pszStatus.a = szInitiator; else { - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = tnick; - gce.ptszUID = tid; - gce.time = time(0); + gce.dwFlags += GCEF_ADDTOLOG; gce.bIsMe = IsMe(id); } diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index 643114156a..7c68efabbf 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -96,7 +96,7 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) CMStringA chatname(UrlToSkypename(conversationLink.c_str())); ptrA szMessage(messageType == "RichText" ? RemoveHtml(content.c_str()) : mir_strdup(content.c_str())); if (messageType == "Text" || messageType == "RichText") { - AddMessageToChat(_A2T(chatname), _A2T(skypename), szMessage, emoteOffset != NULL, emoteOffset, timestamp, true); + AddMessageToChat(chatname, skypename, szMessage, emoteOffset != NULL, emoteOffset, timestamp, true); } } } diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 043cd49db2..3ca8336a1b 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -324,13 +324,13 @@ private: void OnGetChatInfo(const NETLIBHTTPREQUEST *response, void *p); void OnChatEvent(const JSONNode &node); - void OnSendChatMessage(const wchar_t *chat_id, const wchar_t * tszMessage); - char* GetChatUsers(const wchar_t *chat_id); - bool IsChatContact(const wchar_t *chat_id, const char *id); - void AddMessageToChat(const wchar_t *chat_id, const wchar_t *from, const char *content, bool isAction, int emoteOffset, time_t timestamp, bool isLoading = false); - void AddChatContact(const wchar_t *tchat_id, const char *id, const char *name, const wchar_t *role, bool isChange = false); - void RemoveChatContact(const wchar_t *tchat_id, const char *id, const char *name, bool isKick = false, const char *initiator = ""); - wchar_t* GetChatContactNick(const char *chat_id, const char *id, const char *name); + void OnSendChatMessage(const char *chat_id, const wchar_t *tszMessage); + char* GetChatUsers(const char *chat_id); + bool IsChatContact(const char *chat_id, const char *id); + void AddMessageToChat(const char *chat_id, const char *from, const char *content, bool isAction, int emoteOffset, time_t timestamp, bool isLoading = false); + void AddChatContact(const char *chat_id, const char *id, const char *name, const char *role, bool isChange = false); + void RemoveChatContact(const char *chat_id, const char *id, const char *name, bool isKick = false, const char *initiator = ""); + char* GetChatContactNick(const char *chat_id, const char *id, const char *name); void RenameChat(const char *chat_id, const char *name); void ChangeChatTopic(const char * chat_id, const char *topic, const char *initiator); diff --git a/protocols/Twitter/src/chat.cpp b/protocols/Twitter/src/chat.cpp index cbd2ee90aa..49601fc0ac 100644 --- a/protocols/Twitter/src/chat.cpp +++ b/protocols/Twitter/src/chat.cpp @@ -24,34 +24,31 @@ along with this program. If not, see . void TwitterProto::UpdateChat(const twitter_user &update) { - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_MESSAGE }; + GCEVENT gce = { m_szModuleName, m_szChatId, GC_EVENT_MESSAGE }; + gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; gce.bIsMe = (update.username == twit_.get_username()); - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszUID = mir_a2u(update.username.c_str()); + gce.pszUID.a = update.username.c_str(); //TODO: write code here to replace % with %% in update.status.text (which is a std::string) std::string chatText = update.status.text; replaceAll(chatText, "%", "%%"); - gce.ptszText = mir_a2u_cp(chatText.c_str(), CP_UTF8); - //gce.ptszText = mir_a2u_cp(update.status.text.c_str(),CP_UTF8); + gce.pszText.a = chatText.c_str(); gce.time = static_cast(update.status.time); - DBVARIANT nick; MCONTACT hContact = UsernameToHContact(update.username.c_str()); - if (hContact && !db_get_s(hContact, "CList", "MyHandle", &nick)) { - gce.ptszNick = mir_a2u(nick.pszVal); - db_free(&nick); - } + CMStringA szNick = db_get_sm(hContact, "CList", "MyHandle"); + if (hContact && !szNick.IsEmpty()) + gce.pszNick.a = szNick; else - gce.ptszNick = mir_a2u(update.username.c_str()); + gce.pszNick.a = update.username.c_str(); Chat_Event(&gce); - mir_free(const_cast(gce.ptszNick)); - mir_free(const_cast(gce.ptszUID)); - mir_free(const_cast(gce.ptszText)); + mir_free(const_cast(gce.pszNick.w)); + mir_free(const_cast(gce.pszUID.w)); + mir_free(const_cast(gce.pszText.w)); } int TwitterProto::OnChatOutgoing(WPARAM, LPARAM lParam) @@ -88,25 +85,21 @@ int TwitterProto::OnChatOutgoing(WPARAM, LPARAM lParam) // TODO: remove nick? void TwitterProto::AddChatContact(const char *name, const char *nick) { - ptrW wszId(mir_a2u(name)); - ptrW wszNick(mir_a2u(nick ? nick : name)); - - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_JOIN }; + GCEVENT gce = { m_szModuleName, m_szChatId, GC_EVENT_JOIN }; + gce.dwFlags = GCEF_UTF8; gce.time = DWORD(time(0)); - gce.ptszNick = wszNick; - gce.ptszUID = wszId; - gce.ptszStatus = L"Normal"; + gce.pszNick.a = nick ? nick : name; + gce.pszUID.a = name; + gce.pszStatus.a = "Normal"; Chat_Event(&gce); } void TwitterProto::DeleteChatContact(const char *name) { - ptrW wszId(mir_a2u(name)); - - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_PART }; + GCEVENT gce = { m_szModuleName, m_szChatId, GC_EVENT_PART }; + gce.dwFlags = GCEF_UTF8; gce.time = DWORD(time(0)); - gce.ptszNick = wszId; - gce.ptszUID = gce.ptszNick; + gce.pszUID.a = gce.pszNick.a = name; Chat_Event(&gce); } diff --git a/protocols/Twitter/src/proto.cpp b/protocols/Twitter/src/proto.cpp index 8ef5a20493..7ad53590e0 100644 --- a/protocols/Twitter/src/proto.cpp +++ b/protocols/Twitter/src/proto.cpp @@ -27,7 +27,8 @@ along with this program. If not, see . static volatile LONG g_msgid = 1; TwitterProto::TwitterProto(const char *proto_name, const wchar_t *username) : - PROTO(proto_name, username) + PROTO(proto_name, username), + m_szChatId(mir_utf8encodeW(username)) { CreateProtoService(PS_CREATEACCMGRUI, &TwitterProto::SvcCreateAccMgrUI); diff --git a/protocols/Twitter/src/proto.h b/protocols/Twitter/src/proto.h index eb7eec67b2..b7d05b5686 100644 --- a/protocols/Twitter/src/proto.h +++ b/protocols/Twitter/src/proto.h @@ -22,6 +22,8 @@ along with this program. If not, see . class TwitterProto : public PROTO { + ptrA m_szChatId; + public: TwitterProto(const char*,const wchar_t*); ~TwitterProto(); diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index 7603de598a..e72a0e0634 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -166,11 +166,12 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe cu->m_bUnknown = false; if (bNew) { - GCEVENT gce = { m_szModuleName, cc->m_wszId, GC_EVENT_JOIN }; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; + gce.pszID.w = cc->m_wszId; gce.bIsMe = uid == m_myUserId; - gce.ptszUID = wszId; - gce.ptszNick = wszNick; - gce.ptszStatus = TranslateW(sttStatuses[uid == cc->m_iAdminId]); + gce.pszUID.w = wszId; + gce.pszNick.w = wszNick; + gce.pszStatus.w = TranslateW(sttStatuses[uid == cc->m_iAdminId]); gce.dwItemData = (INT_PTR)cu; Chat_Event(&gce); } @@ -184,11 +185,12 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe wchar_t wszId[20]; _itow(cu->m_uid, wszId, 10); - GCEVENT gce = { m_szModuleName, cc->m_wszId, GC_EVENT_PART }; - gce.ptszUID = wszId; + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_PART }; + gce.pszID.w = cc->m_wszId; + gce.pszUID.w = wszId; gce.dwFlags = GCEF_NOTNOTIFY; gce.time = time(0); - gce.ptszNick = mir_wstrdup(CMStringW(FORMAT, L"%s (https://vk.com/id%s)", cu->m_wszNick, wszId)); + gce.pszNick.w = mir_wstrdup(CMStringW(FORMAT, L"%s (https://vk.com/id%s)", cu->m_wszNick, wszId)); Chat_Event(&gce); cc->m_users.remove(T.indexOf(&cu)); @@ -397,13 +399,14 @@ void CVkProto::AppendChatMessage(CVkChatInfo *cc, int uid, int msgTime, LPCWSTR wchar_t wszId[20]; _itow(uid, wszId, 10); - GCEVENT gce = { m_szModuleName, cc->m_wszId, bIsAction ? GC_EVENT_ACTION : GC_EVENT_MESSAGE }; + GCEVENT gce = { m_szModuleName, 0, bIsAction ? GC_EVENT_ACTION : GC_EVENT_MESSAGE }; + gce.pszID.w = cc->m_wszId; gce.bIsMe = (uid == m_myUserId); - gce.ptszUID = wszId; + gce.pszUID.w = wszId; gce.time = msgTime; gce.dwFlags = (bIsHistory) ? GCEF_NOTNOTIFY : GCEF_ADDTOLOG; - gce.ptszNick = cu->m_wszNick ? mir_wstrdup(cu->m_wszNick) : mir_wstrdup(hContact ? ptrW(db_get_wsa(hContact, m_szModuleName, "Nick")) : TranslateT("Unknown")); - gce.ptszText = IsEmpty((wchar_t *)pwszBody) ? mir_wstrdup(L"...") : mir_wstrdup(pwszBody); + gce.pszNick.w = cu->m_wszNick ? mir_wstrdup(cu->m_wszNick) : mir_wstrdup(hContact ? ptrW(db_get_wsa(hContact, m_szModuleName, "Nick")) : TranslateT("Unknown")); + gce.pszText.w = IsEmpty((wchar_t *)pwszBody) ? mir_wstrdup(L"...") : mir_wstrdup(pwszBody); Chat_Event(&gce); StopChatContactTyping(cc->m_iChatId, uid); } @@ -731,11 +734,12 @@ void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch) wchar_t wszId[20]; _itow(cu->m_uid, wszId, 10); - GCEVENT gce = { m_szModuleName, cc->m_wszId, GC_EVENT_NICK }; - gce.ptszNick = mir_wstrdup(cu->m_wszNick); + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_NICK }; + gce.pszID.w = cc->m_wszId; + gce.pszNick.w = mir_wstrdup(cu->m_wszNick); gce.bIsMe = (cu->m_uid == m_myUserId); - gce.ptszUID = wszId; - gce.ptszText = mir_wstrdup(wszNewNick); + gce.pszUID.w = wszId; + gce.pszText.w = mir_wstrdup(wszNewNick); gce.dwFlags = GCEF_ADDTOLOG; gce.time = time(0); Chat_Event(&gce); diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index 77b6a8a905..ce741b594f 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -212,10 +212,10 @@ BOOL SM_AddEvent(const wchar_t *pszID, const char *pszModule, GCEVENT *gce, bool si->iEventCount++; li->iType = gce->iType; - li->ptszNick = mir_wstrdup(gce->ptszNick); - li->ptszText = mir_wstrdup(gce->ptszText); - li->ptszStatus = mir_wstrdup(gce->ptszStatus); - li->ptszUserInfo = mir_wstrdup(gce->ptszUserInfo); + li->ptszNick = mir_wstrdup(gce->pszNick.w); + li->ptszText = mir_wstrdup(gce->pszText.w); + li->ptszStatus = mir_wstrdup(gce->pszStatus.w); + li->ptszUserInfo = mir_wstrdup(gce->pszUserInfo.w); li->bIsMe = gce->bIsMe; li->time = gce->time; @@ -360,9 +360,9 @@ BOOL SM_ChangeNick(const wchar_t *pszID, const char *pszModule, GCEVENT *gce) for (auto &si : g_arSessions) { if ((!pszID || !mir_wstrcmpi(si->ptszID, pszID)) && !mir_strcmpi(si->pszModule, pszModule)) { - USERINFO *ui = g_chatApi.UM_FindUser(si, gce->ptszUID); + USERINFO *ui = g_chatApi.UM_FindUser(si, gce->pszUID.w); if (ui) { - replaceStrW(ui->pszNick, gce->ptszText); + replaceStrW(ui->pszNick, gce->pszText.w); UM_SortUser(si, ui->pszUID); if (si->pDlg) si->pDlg->UpdateNickList(); diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp index cda5f7efda..1c0bd9d969 100644 --- a/src/mir_app/src/chat_svc.cpp +++ b/src/mir_app/src/chat_svc.cpp @@ -363,13 +363,13 @@ MIR_APP_DLL(int) Chat_Terminate(const char *szModule, const wchar_t *wszId, bool static void AddUser(GCEVENT *gce) { - SESSION_INFO *si = SM_FindSession(gce->ptszID, gce->pszModule); + SESSION_INFO *si = SM_FindSession(gce->pszID.w, gce->pszModule); if (si == nullptr) return; - WORD status = TM_StringToWord(si->pStatuses, gce->ptszStatus); + WORD status = TM_StringToWord(si->pStatuses, gce->pszStatus.w); - USERINFO *ui = g_chatApi.UM_AddUser(si, gce->ptszUID, gce->ptszNick, status); + USERINFO *ui = g_chatApi.UM_AddUser(si, gce->pszUID.w, gce->pszNick.w, status); if (ui == nullptr) return; @@ -396,7 +396,7 @@ static BOOL AddEventToAllMatchingUID(GCEVENT *gce) if (!si->bInitDone || mir_strcmpi(si->pszModule, gce->pszModule)) continue; - if (!g_chatApi.UM_FindUser(si, gce->ptszUID)) + if (!g_chatApi.UM_FindUser(si, gce->pszUID.w)) continue; if (g_chatApi.OnEventBroadcast) @@ -423,6 +423,16 @@ static BOOL AddEventToAllMatchingUID(GCEVENT *gce) static INT_PTR CALLBACK sttEventStub(void *_param) { GCEVENT *gce = (GCEVENT*)_param; + if (gce->dwFlags & GCEF_UTF8) { + gce->pszID.w = NEWWSTR_ALLOCA(Utf2T(gce->pszID.a)); + gce->pszUID.w = NEWWSTR_ALLOCA(Utf2T(gce->pszUID.a)); + gce->pszNick.w = NEWWSTR_ALLOCA(Utf2T(gce->pszNick.a)); + gce->pszText.w = NEWWSTR_ALLOCA(Utf2T(gce->pszText.a)); + gce->pszStatus.w = NEWWSTR_ALLOCA(Utf2T(gce->pszStatus.a)); + gce->pszUserInfo.w = NEWWSTR_ALLOCA(Utf2T(gce->pszUserInfo.a)); + gce->dwFlags &= ~GCEF_UTF8; + } + if (NotifyEventHooks(hHookEvent, 0, LPARAM(gce))) return 1; @@ -431,11 +441,11 @@ static INT_PTR CALLBACK sttEventStub(void *_param) // Do different things according to type of event switch (gce->iType) { case GC_EVENT_SETCONTACTSTATUS: - return SM_SetContactStatus(gce->ptszID, gce->pszModule, gce->ptszUID, (WORD)gce->dwItemData); + return SM_SetContactStatus(gce->pszID.w, gce->pszModule, gce->pszUID.w, (WORD)gce->dwItemData); case GC_EVENT_TOPIC: - if (SESSION_INFO *si = SM_FindSession(gce->ptszID, gce->pszModule)) { - wchar_t *pwszNew = RemoveFormatting(gce->ptszText); + if (SESSION_INFO *si = SM_FindSession(gce->pszID.w, gce->pszModule)) { + wchar_t *pwszNew = RemoveFormatting(gce->pszText.w); if (!mir_wstrcmp(si->ptszTopic, pwszNew)) // nothing changed? exiting return 0; @@ -458,25 +468,25 @@ static INT_PTR CALLBACK sttEventStub(void *_param) break; case GC_EVENT_ADDSTATUS: - SM_GiveStatus(gce->ptszID, gce->pszModule, gce->ptszUID, gce->ptszStatus); + SM_GiveStatus(gce->pszID.w, gce->pszModule, gce->pszUID.w, gce->pszStatus.w); bIsHighlighted = g_chatApi.IsHighlighted(nullptr, gce); break; case GC_EVENT_REMOVESTATUS: - SM_TakeStatus(gce->ptszID, gce->pszModule, gce->ptszUID, gce->ptszStatus); + SM_TakeStatus(gce->pszID.w, gce->pszModule, gce->pszUID.w, gce->pszStatus.w); bIsHighlighted = g_chatApi.IsHighlighted(nullptr, gce); break; case GC_EVENT_MESSAGE: case GC_EVENT_ACTION: - if (!gce->bIsMe && gce->ptszID && gce->ptszText) { - SESSION_INFO *si = SM_FindSession(gce->ptszID, gce->pszModule); + if (!gce->bIsMe && gce->pszID.w && gce->pszText.w) { + SESSION_INFO *si = SM_FindSession(gce->pszID.w, gce->pszModule); bIsHighlighted = g_chatApi.IsHighlighted(si, gce); } break; case GC_EVENT_NICK: - SM_ChangeNick(gce->ptszID, gce->pszModule, gce); + SM_ChangeNick(gce->pszID.w, gce->pszModule, gce); bIsHighlighted = g_chatApi.IsHighlighted(nullptr, gce); break; @@ -496,8 +506,8 @@ static INT_PTR CALLBACK sttEventStub(void *_param) // Decide which window (log) should have the event LPCTSTR pWnd = nullptr; LPCSTR pMod = nullptr; - if (gce->ptszID) { - pWnd = gce->ptszID; + if (gce->pszID.w) { + pWnd = gce->pszID.w; pMod = gce->pszModule; } else if (gce->iType == GC_EVENT_NOTICE || gce->iType == GC_EVENT_INFORMATION) { @@ -530,10 +540,10 @@ static INT_PTR CALLBACK sttEventStub(void *_param) return 0; if (si && (si->bInitDone || gce->iType == GC_EVENT_TOPIC || (gce->iType == GC_EVENT_JOIN && gce->bIsMe))) { - if (gce->ptszNick == nullptr && gce->ptszUID != nullptr) { - USERINFO *ui = g_chatApi.UM_FindUser(si, gce->ptszUID); + if (gce->pszNick.w == nullptr && gce->pszUID.w != nullptr) { + USERINFO *ui = g_chatApi.UM_FindUser(si, gce->pszUID.w); if (ui != nullptr) - gce->ptszNick = ui->pszNick; + gce->pszNick.w = ui->pszNick; } int isOk = SM_AddEvent(pWnd, pMod, gce, bIsHighlighted); @@ -556,7 +566,7 @@ static INT_PTR CALLBACK sttEventStub(void *_param) } if (bRemoveFlag) - return SM_RemoveUser(gce->ptszID, gce->pszModule, gce->ptszUID) == 0; + return SM_RemoveUser(gce->pszID.w, gce->pszModule, gce->pszUID.w) == 0; return GC_EVENT_ERROR; } diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index 74c86116e6..51f1317b54 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -85,31 +85,31 @@ BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce) switch (gce->iType) { case GC_EVENT_MESSAGE | GC_EVENT_HIGHLIGHT: case GC_EVENT_ACTION | GC_EVENT_HIGHLIGHT: - g_chatApi.AddEvent(si->hContact, Skin_LoadIcon(SKINICON_EVENT_MESSAGE), GC_FAKE_EVENT, 0, TranslateT("%s wants your attention in %s"), gce->ptszNick, si->ptszName); + g_chatApi.AddEvent(si->hContact, Skin_LoadIcon(SKINICON_EVENT_MESSAGE), GC_FAKE_EVENT, 0, TranslateT("%s wants your attention in %s"), gce->pszNick.w, si->ptszName); break; case GC_EVENT_MESSAGE: - g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_MESSAGE], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s speaks in %s"), gce->ptszNick, si->ptszName); + g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_MESSAGE], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s speaks in %s"), gce->pszNick.w, si->ptszName); break; case GC_EVENT_ACTION: - g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_ACTION], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s speaks in %s"), gce->ptszNick, si->ptszName); + g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_ACTION], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s speaks in %s"), gce->pszNick.w, si->ptszName); break; case GC_EVENT_JOIN: - g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_JOIN], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s has joined %s"), gce->ptszNick, si->ptszName); + g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_JOIN], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s has joined %s"), gce->pszNick.w, si->ptszName); break; case GC_EVENT_PART: - g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_PART], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s has left %s"), gce->ptszNick, si->ptszName); + g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_PART], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s has left %s"), gce->pszNick.w, si->ptszName); break; case GC_EVENT_QUIT: - g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_QUIT], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s has disconnected"), gce->ptszNick); + g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_QUIT], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s has disconnected"), gce->pszNick.w); break; case GC_EVENT_NICK: - g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_NICK], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s is now known as %s"), gce->ptszNick, gce->ptszText); + g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_NICK], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s is now known as %s"), gce->pszNick.w, gce->pszText.w); break; case GC_EVENT_KICK: - g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_KICK], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s kicked %s from %s"), gce->ptszStatus, gce->ptszNick, si->ptszName); + g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_KICK], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s kicked %s from %s"), gce->pszStatus.w, gce->pszNick.w, si->ptszName); break; case GC_EVENT_NOTICE: - g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_NOTICE], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("Notice from %s"), gce->ptszNick); + g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_NOTICE], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("Notice from %s"), gce->pszNick.w); break; case GC_EVENT_TOPIC: g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_TOPIC], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("Topic change in %s"), si->ptszName); @@ -118,10 +118,10 @@ BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce) g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_INFO], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("Information in %s"), si->ptszName); break; case GC_EVENT_ADDSTATUS: - g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_ADDSTATUS], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s enables '%s' status for %s in %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick, si->ptszName); + g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_ADDSTATUS], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s enables '%s' status for %s in %s"), gce->pszText.w, gce->pszStatus.w, gce->pszNick.w, si->ptszName); break; case GC_EVENT_REMOVESTATUS: - g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_REMSTATUS], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s disables '%s' status for %s in %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick, si->ptszName); + g_chatApi.AddEvent(si->hContact, g_chatApi.hIcons[ICON_REMSTATUS], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s disables '%s' status for %s in %s"), gce->pszText.w, gce->pszStatus.w, gce->pszNick.w, si->ptszName); break; } @@ -210,58 +210,58 @@ BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce) { switch (gce->iType) { case GC_EVENT_MESSAGE | GC_EVENT_HIGHLIGHT: - g_chatApi.ShowPopup(si->hContact, si, Skin_LoadIcon(SKINICON_EVENT_MESSAGE), si->pszModule, si->ptszName, g_chatApi.aFonts[16].color, TranslateT("%s says: %s"), gce->ptszNick, RemoveFormatting(gce->ptszText)); + g_chatApi.ShowPopup(si->hContact, si, Skin_LoadIcon(SKINICON_EVENT_MESSAGE), si->pszModule, si->ptszName, g_chatApi.aFonts[16].color, TranslateT("%s says: %s"), gce->pszNick.w, RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_ACTION | GC_EVENT_HIGHLIGHT: - g_chatApi.ShowPopup(si->hContact, si, Skin_LoadIcon(SKINICON_EVENT_MESSAGE), si->pszModule, si->ptszName, g_chatApi.aFonts[16].color, L"%s %s", gce->ptszNick, RemoveFormatting(gce->ptszText)); + g_chatApi.ShowPopup(si->hContact, si, Skin_LoadIcon(SKINICON_EVENT_MESSAGE), si->pszModule, si->ptszName, g_chatApi.aFonts[16].color, L"%s %s", gce->pszNick.w, RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_MESSAGE: - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_MESSAGE], si->pszModule, si->ptszName, g_chatApi.aFonts[9].color, TranslateT("%s says: %s"), gce->ptszNick, RemoveFormatting(gce->ptszText)); + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_MESSAGE], si->pszModule, si->ptszName, g_chatApi.aFonts[9].color, TranslateT("%s says: %s"), gce->pszNick.w, RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_ACTION: - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_ACTION], si->pszModule, si->ptszName, g_chatApi.aFonts[15].color, L"%s %s", gce->ptszNick, RemoveFormatting(gce->ptszText)); + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_ACTION], si->pszModule, si->ptszName, g_chatApi.aFonts[15].color, L"%s %s", gce->pszNick.w, RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_JOIN: - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_JOIN], si->pszModule, si->ptszName, g_chatApi.aFonts[3].color, TranslateT("%s has joined"), gce->ptszNick); + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_JOIN], si->pszModule, si->ptszName, g_chatApi.aFonts[3].color, TranslateT("%s has joined"), gce->pszNick.w); break; case GC_EVENT_PART: - if (!gce->ptszText) - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_PART], si->pszModule, si->ptszName, g_chatApi.aFonts[4].color, TranslateT("%s has left"), gce->ptszNick); + if (!gce->pszText.w) + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_PART], si->pszModule, si->ptszName, g_chatApi.aFonts[4].color, TranslateT("%s has left"), gce->pszNick.w); else - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_PART], si->pszModule, si->ptszName, g_chatApi.aFonts[4].color, TranslateT("%s has left (%s)"), gce->ptszNick, RemoveFormatting(gce->ptszText)); + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_PART], si->pszModule, si->ptszName, g_chatApi.aFonts[4].color, TranslateT("%s has left (%s)"), gce->pszNick.w, RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_QUIT: - if (!gce->ptszText) - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_QUIT], si->pszModule, si->ptszName, g_chatApi.aFonts[5].color, TranslateT("%s has disconnected"), gce->ptszNick); + if (!gce->pszText.w) + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_QUIT], si->pszModule, si->ptszName, g_chatApi.aFonts[5].color, TranslateT("%s has disconnected"), gce->pszNick.w); else - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_QUIT], si->pszModule, si->ptszName, g_chatApi.aFonts[5].color, TranslateT("%s has disconnected (%s)"), gce->ptszNick, RemoveFormatting(gce->ptszText)); + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_QUIT], si->pszModule, si->ptszName, g_chatApi.aFonts[5].color, TranslateT("%s has disconnected (%s)"), gce->pszNick.w, RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_NICK: - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_NICK], si->pszModule, si->ptszName, g_chatApi.aFonts[7].color, TranslateT("%s is now known as %s"), gce->ptszNick, gce->ptszText); + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_NICK], si->pszModule, si->ptszName, g_chatApi.aFonts[7].color, TranslateT("%s is now known as %s"), gce->pszNick.w, gce->pszText.w); break; case GC_EVENT_KICK: - if (!gce->ptszText) - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_KICK], si->pszModule, si->ptszName, g_chatApi.aFonts[6].color, TranslateT("%s kicked %s"), (char *)gce->ptszStatus, gce->ptszNick); + if (!gce->pszText.w) + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_KICK], si->pszModule, si->ptszName, g_chatApi.aFonts[6].color, TranslateT("%s kicked %s"), gce->pszStatus.w, gce->pszNick.w); else - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_KICK], si->pszModule, si->ptszName, g_chatApi.aFonts[6].color, TranslateT("%s kicked %s (%s)"), (char *)gce->ptszStatus, gce->ptszNick, RemoveFormatting(gce->ptszText)); + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_KICK], si->pszModule, si->ptszName, g_chatApi.aFonts[6].color, TranslateT("%s kicked %s (%s)"), gce->pszStatus.w, gce->pszNick.w, RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_NOTICE: - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_NOTICE], si->pszModule, si->ptszName, g_chatApi.aFonts[8].color, TranslateT("Notice from %s: %s"), gce->ptszNick, RemoveFormatting(gce->ptszText)); + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_NOTICE], si->pszModule, si->ptszName, g_chatApi.aFonts[8].color, TranslateT("Notice from %s: %s"), gce->pszNick.w, RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_TOPIC: - if (!gce->ptszNick) - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_TOPIC], si->pszModule, si->ptszName, g_chatApi.aFonts[11].color, TranslateT("The topic is '%s'"), RemoveFormatting(gce->ptszText)); + if (!gce->pszNick.w) + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_TOPIC], si->pszModule, si->ptszName, g_chatApi.aFonts[11].color, TranslateT("The topic is '%s'"), RemoveFormatting(gce->pszText.w)); else - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_TOPIC], si->pszModule, si->ptszName, g_chatApi.aFonts[11].color, TranslateT("The topic is '%s' (set by %s)"), RemoveFormatting(gce->ptszText), gce->ptszNick); + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_TOPIC], si->pszModule, si->ptszName, g_chatApi.aFonts[11].color, TranslateT("The topic is '%s' (set by %s)"), RemoveFormatting(gce->pszText.w), gce->pszNick.w); break; case GC_EVENT_INFORMATION: - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_INFO], si->pszModule, si->ptszName, g_chatApi.aFonts[12].color, L"%s", RemoveFormatting(gce->ptszText)); + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_INFO], si->pszModule, si->ptszName, g_chatApi.aFonts[12].color, L"%s", RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_ADDSTATUS: - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_ADDSTATUS], si->pszModule, si->ptszName, g_chatApi.aFonts[13].color, TranslateT("%s enables '%s' status for %s"), gce->ptszText, (char *)gce->ptszStatus, gce->ptszNick); + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_ADDSTATUS], si->pszModule, si->ptszName, g_chatApi.aFonts[13].color, TranslateT("%s enables '%s' status for %s"), gce->pszText.w, (char *)gce->pszStatus.w, gce->pszNick.w); break; case GC_EVENT_REMOVESTATUS: - g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_REMSTATUS], si->pszModule, si->ptszName, g_chatApi.aFonts[14].color, TranslateT("%s disables '%s' status for %s"), gce->ptszText, (char *)gce->ptszStatus, gce->ptszNick); + g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_REMSTATUS], si->pszModule, si->ptszName, g_chatApi.aFonts[14].color, TranslateT("%s disables '%s' status for %s"), gce->pszText.w, (char *)gce->pszStatus.w, gce->pszNick.w); break; } @@ -363,14 +363,14 @@ bool IsHighlighted(SESSION_INFO *si, GCEVENT *gce) if (!g_Settings->bHighlightEnabled || !g_Settings->pszHighlightWords || !gce || !si) return FALSE; - if (gce->ptszText == nullptr) + if (gce->pszText.w == nullptr) return FALSE; USERINFO *pMe = si->getMe(); if (pMe == nullptr) return FALSE; - wchar_t *buf = RemoveFormatting(NEWWSTR_ALLOCA(gce->ptszText)); + wchar_t *buf = RemoveFormatting(NEWWSTR_ALLOCA(gce->pszText.w)); int iStart = 0; CMStringW tszHighlightWords(g_Settings->pszHighlightWords); @@ -427,15 +427,15 @@ BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce) wchar_t* pszNick = nullptr; if (bFileJustCreated) fputws((const wchar_t*)"\377\376", hFile); //UTF-16 LE BOM == FF FE - if (gce->ptszNick) { - if (g_Settings->bLogLimitNames && mir_wstrlen(gce->ptszNick) > 20) { - mir_wstrncpy(szTemp2, gce->ptszNick, 20); + if (gce->pszNick.w) { + if (g_Settings->bLogLimitNames && mir_wstrlen(gce->pszNick.w) > 20) { + mir_wstrncpy(szTemp2, gce->pszNick.w, 20); mir_wstrncpy(szTemp2 + 20, L"...", 4); } - else mir_wstrncpy(szTemp2, gce->ptszNick, 511); + else mir_wstrncpy(szTemp2, gce->pszNick.w, 511); - if (gce->ptszUserInfo) - mir_snwprintf(szTemp, L"%s (%s)", szTemp2, gce->ptszUserInfo); + if (gce->pszUserInfo.w) + mir_snwprintf(szTemp, L"%s (%s)", szTemp2, gce->pszUserInfo.w); else wcsncpy_s(szTemp, szTemp2, _TRUNCATE); pszNick = szTemp; @@ -445,12 +445,12 @@ BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce) case GC_EVENT_MESSAGE: case GC_EVENT_MESSAGE | GC_EVENT_HIGHLIGHT: p = '*'; - mir_snwprintf(szBuffer, L"%s: %s", gce->ptszNick, g_chatApi.RemoveFormatting(gce->ptszText)); + mir_snwprintf(szBuffer, L"%s: %s", gce->pszNick.w, g_chatApi.RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_ACTION: case GC_EVENT_ACTION | GC_EVENT_HIGHLIGHT: p = '*'; - mir_snwprintf(szBuffer, L"%s %s", gce->ptszNick, g_chatApi.RemoveFormatting(gce->ptszText)); + mir_snwprintf(szBuffer, L"%s %s", gce->pszNick.w, g_chatApi.RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_JOIN: p = '>'; @@ -458,51 +458,51 @@ BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce) break; case GC_EVENT_PART: p = '<'; - if (!gce->ptszText) + if (!gce->pszText.w) mir_snwprintf(szBuffer, TranslateT("%s has left"), pszNick); else - mir_snwprintf(szBuffer, TranslateT("%s has left (%s)"), pszNick, g_chatApi.RemoveFormatting(gce->ptszText)); + mir_snwprintf(szBuffer, TranslateT("%s has left (%s)"), pszNick, g_chatApi.RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_QUIT: p = '<'; - if (!gce->ptszText) + if (!gce->pszText.w) mir_snwprintf(szBuffer, TranslateT("%s has disconnected"), pszNick); else - mir_snwprintf(szBuffer, TranslateT("%s has disconnected (%s)"), pszNick, g_chatApi.RemoveFormatting(gce->ptszText)); + mir_snwprintf(szBuffer, TranslateT("%s has disconnected (%s)"), pszNick, g_chatApi.RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_NICK: p = '^'; - mir_snwprintf(szBuffer, TranslateT("%s is now known as %s"), gce->ptszNick, gce->ptszText); + mir_snwprintf(szBuffer, TranslateT("%s is now known as %s"), gce->pszNick.w, gce->pszText.w); break; case GC_EVENT_KICK: p = '~'; - if (!gce->ptszText) - mir_snwprintf(szBuffer, TranslateT("%s kicked %s"), gce->ptszStatus, gce->ptszNick); + if (!gce->pszText.w) + mir_snwprintf(szBuffer, TranslateT("%s kicked %s"), gce->pszStatus.w, gce->pszNick.w); else - mir_snwprintf(szBuffer, TranslateT("%s kicked %s (%s)"), gce->ptszStatus, gce->ptszNick, g_chatApi.RemoveFormatting(gce->ptszText)); + mir_snwprintf(szBuffer, TranslateT("%s kicked %s (%s)"), gce->pszStatus.w, gce->pszNick.w, g_chatApi.RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_NOTICE: p = 'o'; - mir_snwprintf(szBuffer, TranslateT("Notice from %s: %s"), gce->ptszNick, g_chatApi.RemoveFormatting(gce->ptszText)); + mir_snwprintf(szBuffer, TranslateT("Notice from %s: %s"), gce->pszNick.w, g_chatApi.RemoveFormatting(gce->pszText.w)); break; case GC_EVENT_TOPIC: p = '#'; - if (!gce->ptszNick) - mir_snwprintf(szBuffer, TranslateT("The topic is '%s'"), g_chatApi.RemoveFormatting(gce->ptszText)); + if (!gce->pszNick.w) + mir_snwprintf(szBuffer, TranslateT("The topic is '%s'"), g_chatApi.RemoveFormatting(gce->pszText.w)); else - mir_snwprintf(szBuffer, TranslateT("The topic is '%s' (set by %s)"), g_chatApi.RemoveFormatting(gce->ptszText), gce->ptszNick); + mir_snwprintf(szBuffer, TranslateT("The topic is '%s' (set by %s)"), g_chatApi.RemoveFormatting(gce->pszText.w), gce->pszNick.w); break; case GC_EVENT_INFORMATION: p = '!'; - wcsncpy_s(szBuffer, g_chatApi.RemoveFormatting(gce->ptszText), _TRUNCATE); + wcsncpy_s(szBuffer, g_chatApi.RemoveFormatting(gce->pszText.w), _TRUNCATE); break; case GC_EVENT_ADDSTATUS: p = '+'; - mir_snwprintf(szBuffer, TranslateT("%s enables '%s' status for %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick); + mir_snwprintf(szBuffer, TranslateT("%s enables '%s' status for %s"), gce->pszText.w, gce->pszStatus.w, gce->pszNick.w); break; case GC_EVENT_REMOVESTATUS: p = '-'; - mir_snwprintf(szBuffer, TranslateT("%s disables '%s' status for %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick); + mir_snwprintf(szBuffer, TranslateT("%s disables '%s' status for %s"), gce->pszText.w, gce->pszStatus.w, gce->pszNick.w); break; } diff --git a/utils/std_string_utils.cpp b/utils/std_string_utils.cpp index bac8957325..7f4ff47be6 100644 --- a/utils/std_string_utils.cpp +++ b/utils/std_string_utils.cpp @@ -21,7 +21,7 @@ along with this program. If not, see . std::string utils::url::encode(const std::string &s) { - return mir_urlEncode(s.c_str()); + return std::string(mir_urlEncode(s.c_str())); } std::string utils::url::decode(std::string data) -- cgit v1.2.3