From 899221e2d058f5afe30bb2ecdbf168c8ad3c15a6 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 27 Jan 2023 19:48:42 +0300 Subject: Group chats: all old APIs with lookup by module+session removed --- include/m_chat.h | 77 +++++---- libs/win32/mir_app.lib | Bin 232300 -> 235740 bytes libs/win64/mir_app.lib | Bin 228600 -> 232642 bytes plugins/KeyboardNotify/src/main.cpp | 2 +- plugins/MirLua/src/Modules/m_chat.cpp | 2 - plugins/MirLua/src/Modules/m_message.cpp | 2 +- plugins/MirandaG15/src/CAppletManager.cpp | 25 ++- plugins/MirandaG15/src/StdAfx.h | 2 +- plugins/PasteIt/src/PasteIt.cpp | 23 +-- plugins/RecentContacts/src/RecentContacts.cpp | 4 +- plugins/SendScreenshotPlus/src/CSend.cpp | 64 +++----- plugins/XSoundNotify/src/xsn_main.cpp | 2 +- protocols/CloudFile/src/utils.cpp | 4 +- protocols/Discord/src/dispatch.cpp | 33 ++-- protocols/Discord/src/guilds.cpp | 15 +- protocols/Discord/src/proto.h | 1 + protocols/Discord/src/server.cpp | 3 +- protocols/Discord/src/utils.cpp | 7 +- protocols/Facebook/src/groupchats.cpp | 6 +- protocols/Facebook/src/proto.h | 1 + protocols/Facebook/src/server.cpp | 20 +-- protocols/Gadu-Gadu/src/core.cpp | 29 ++-- protocols/Gadu-Gadu/src/gg.h | 2 +- protocols/Gadu-Gadu/src/gg_proto.h | 2 +- protocols/Gadu-Gadu/src/groupchat.cpp | 58 +++---- protocols/ICQ-WIM/src/groupchats.cpp | 14 +- protocols/ICQ-WIM/src/poll.cpp | 2 +- protocols/ICQ-WIM/src/server.cpp | 21 +-- protocols/IRCG/src/commandmonitor.cpp | 41 +++-- protocols/IRCG/src/input.cpp | 14 +- protocols/IRCG/src/irclib.cpp | 208 +++++++++++------------ protocols/IRCG/src/irclib.h | 5 +- protocols/IRCG/src/ircproto.cpp | 4 +- protocols/IRCG/src/ircproto.h | 42 +++-- protocols/IRCG/src/services.cpp | 12 +- protocols/IRCG/src/tools.cpp | 26 ++- protocols/IRCG/src/windows.cpp | 4 +- protocols/JabberG/src/jabber_chat.cpp | 22 +-- protocols/JabberG/src/jabber_groupchat.cpp | 11 +- protocols/JabberG/src/jabber_proto.h | 23 +-- protocols/MinecraftDynmap/src/chat.cpp | 29 ++-- protocols/MinecraftDynmap/src/proto.cpp | 1 - protocols/MinecraftDynmap/src/proto.h | 2 +- protocols/Omegle/src/chat.cpp | 33 ++-- protocols/Omegle/src/proto.h | 4 +- protocols/Sametime/src/conference.cpp | 28 ++-- protocols/SkypeWeb/src/skype_chatrooms.cpp | 33 ++-- protocols/SkypeWeb/src/skype_contacts.cpp | 2 +- protocols/SkypeWeb/src/skype_history_sync.cpp | 2 +- protocols/Twitter/src/chat.cpp | 26 ++- protocols/Twitter/src/connection.cpp | 4 +- protocols/Twitter/src/contacts.cpp | 4 +- protocols/Twitter/src/proto.cpp | 5 +- protocols/Twitter/src/proto.h | 4 +- protocols/VKontakte/src/vk_chats.cpp | 50 +++--- protocols/VKontakte/src/vk_struct.h | 13 +- protocols/WhatsApp/src/appsync.cpp | 15 +- protocols/WhatsApp/src/chats.cpp | 23 ++- protocols/WhatsApp/src/message.cpp | 3 +- src/mir_app/src/chat.h | 16 +- src/mir_app/src/chat_clist.cpp | 2 +- src/mir_app/src/chat_manager.cpp | 80 ++++----- src/mir_app/src/chat_svc.cpp | 228 +++++++++++++------------- src/mir_app/src/mir_app.def | 33 ++-- src/mir_app/src/mir_app64.def | 33 ++-- src/mir_app/src/proto_utils.cpp | 2 +- 66 files changed, 720 insertions(+), 788 deletions(-) diff --git a/include/m_chat.h b/include/m_chat.h index 4a58d625c5..096811cf3c 100644 --- a/include/m_chat.h +++ b/include/m_chat.h @@ -147,7 +147,7 @@ struct GCREGISTER int iMaxText; // Max message length the protocol supports. Will limit the typing area input. 0 = no limit }; -EXTERN_C MIR_APP_DLL(int) Chat_Register(const GCREGISTER*); +MIR_APP_DLL(int) Chat_Register(const GCREGISTER*); /* Step 2. -- CREATE a new SESSION -- @@ -167,7 +167,7 @@ EXTERN_C MIR_APP_DLL(int) Chat_Register(const GCREGISTER*); #define GCW_PRIVMESS 3 // NOT SUPPORTED YET! the session is a 1 to 1 session, but with additional // support for adding more users etc. ex "MSN session". -EXTERN_C MIR_APP_DLL(struct SESSION_INFO*) Chat_NewSession( +MIR_APP_DLL(struct SESSION_INFO*) Chat_NewSession( int iType, // Use one of the GCW_* flags above to set the type of session const char *pszModule, // The name of the protocol owning the session (the same as pszModule when you register) const wchar_t *ptszID, // The unique identifier for the session. @@ -355,10 +355,11 @@ EXTERN_C MIR_APP_DLL(struct SESSION_INFO*) Chat_NewSession( #define GCEF_NOTNOTIFY 0x0004 #define GCEF_UTF8 0x0008 +struct SESSION_INFO; + struct GCEVENT { - 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 + SESSION_INFO *si; // session to deal with int iType; // Use GC_EVENT_* as defined above. Only one event per service call. MAllCStrings pszText; // @@ -374,21 +375,23 @@ struct GCEVENT uint32_t time; // Timestamp of the event }; -EXTERN_C MIR_APP_DLL(int) Chat_Event(GCEVENT*); +MIR_APP_DLL(int) Chat_Event(GCEVENT*); -EXTERN_C MIR_APP_DLL(void*) Chat_GetUserInfo(const char *szModule, const wchar_t *wszId); -EXTERN_C MIR_APP_DLL(int) Chat_SetUserInfo(const char *szModule, const wchar_t *wszId, void *pItemData); +MIR_APP_DLL(void*) Chat_GetUserInfo(SESSION_INFO *si); +MIR_APP_DLL(int) Chat_SetUserInfo(SESSION_INFO *si, void *pItemData); -EXTERN_C MIR_APP_DLL(int) Chat_AddGroup(SESSION_INFO *si, const wchar_t *wszText); -EXTERN_C MIR_APP_DLL(int) Chat_ChangeSessionName(const char *szModule, const wchar_t *wszId, const wchar_t *wszNewName); -EXTERN_C MIR_APP_DLL(int) Chat_ChangeUserId(const char *szModule, const wchar_t *wszId, const wchar_t *wszOldId, const wchar_t *wszNewId); -EXTERN_C MIR_APP_DLL(int) Chat_SendUserMessage(const char *szModule, const wchar_t *wszId, const wchar_t *wszText); -EXTERN_C MIR_APP_DLL(int) Chat_SetStatusbarText(const char *szModule, const wchar_t *wszId, const wchar_t *wszText); +MIR_APP_DLL(int) Chat_AddGroup(SESSION_INFO *si, const wchar_t *wszText); +MIR_APP_DLL(int) Chat_ChangeSessionName(SESSION_INFO *si, const wchar_t *wszNewName); +MIR_APP_DLL(int) Chat_ChangeUserId(const char *szModule, const wchar_t *wszOldId, const wchar_t *wszNewId); +MIR_APP_DLL(int) Chat_ChangeUserId(SESSION_INFO *si, const wchar_t *wszOldId, const wchar_t *wszNewId); +MIR_APP_DLL(int) Chat_SendUserMessage(const char *szModule, const wchar_t *wszText); +MIR_APP_DLL(int) Chat_SendUserMessage(SESSION_INFO *si, const wchar_t *wszText); +MIR_APP_DLL(int) Chat_SetStatusbarText(SESSION_INFO *si, const wchar_t *wszText); -EXTERN_C MIR_APP_DLL(wchar_t*) Chat_GetGroup(void); -EXTERN_C MIR_APP_DLL(void) Chat_SetGroup(const wchar_t*); +MIR_APP_DLL(wchar_t*) Chat_GetGroup(void); +MIR_APP_DLL(void) Chat_SetGroup(const wchar_t*); -EXTERN_C MIR_APP_DLL(wchar_t*) Chat_UnescapeTags(wchar_t *str_in); +MIR_APP_DLL(wchar_t*) Chat_UnescapeTags(wchar_t *str_in); ///////////////////////////////////////////////////////////////////////////////////////// @@ -397,8 +400,8 @@ EXTERN_C MIR_APP_DLL(wchar_t*) Chat_UnescapeTags(wchar_t *str_in); #define GC_SSE_TABDELIMITED 0x0004 // use tabs as delimiters #define GC_SSE_OFFLINE 0x0008 // displays a contact offline, otherwise away -// if wszId == NULL, the status is applied to all windows of specified szModule -EXTERN_C MIR_APP_DLL(int) Chat_SetStatusEx(const char *szModule, const wchar_t *wszId, int flags, const wchar_t *wszText); +MIR_APP_DLL(int) Chat_SetStatusEx(const char *szModule, int flags, const wchar_t *wszText); +MIR_APP_DLL(int) Chat_SetStatusEx(SESSION_INFO *si, int flags, const wchar_t *wszText); ///////////////////////////////////////////////////////////////////////////////////////// @@ -412,22 +415,14 @@ EXTERN_C MIR_APP_DLL(int) Chat_SetStatusEx(const char *szModule, const wchar_t * #define WINDOW_CLEARLOG 6 // clear the log of the room window // if wszId == NULL, this message is broadcasted to all windows of specified szModule -EXTERN_C MIR_APP_DLL(int) Chat_Control(const char *szModule, const wchar_t *wszId, int command); -EXTERN_C MIR_APP_DLL(int) Chat_Terminate(const char *szModule, const wchar_t *wszId, bool bRemoveContact = false); - -///////////////////////////////////////////////////////////////////////////////////////// -// This hook is fired when MS_GC_EVENT is called, with the same wParam and lParam as above. -// It allows external plugins to intercept chat events and display then in other ways +MIR_APP_DLL(int) Chat_Control(SESSION_INFO *si, int command); -#define ME_GC_HOOK_EVENT "GChat/HookEvent" - -/* - -- GETTING info about a SESSION or session data -- - Use this service to get information on different aspects of the sessions that are registered with Chat. +MIR_APP_DLL(int) Chat_Terminate(const char *szModule, bool bRemoveContact = false); +MIR_APP_DLL(int) Chat_Terminate(SESSION_INFO *si, bool bRemoveContact = false); - * Use MS_GC_GETINFO like this: CallService(MS_GC_GETINFO, 0, (LPARAM)(GC_INFO *) &gci; - * returns 0 on success or error code on failure -*/ +///////////////////////////////////////////////////////////////////////////////////////// +// Use this function to get information on different aspects of the sessions that are registered with Chat. +// returns 0 on success or error code on failure // Flags #define GCF_BYINDEX 0x0001 // iItem is valid and should contain the index of the session to get @@ -440,10 +435,9 @@ EXTERN_C MIR_APP_DLL(int) Chat_Terminate(const char *szModule, const wchar_t *ws #define GCF_COUNT 0x0080 // iCount is valid #define GCF_USERS 0x0100 // pszUsers is valid -// The GC_INFO structure struct GC_INFO { - uint32_t Flags; // use a combination of the above flags + uint32_t Flags; // use a combination of the GCF_* flags (look above) int iItem; // session type (GCW_*) int iType; // session type (GCW_*) LPCSTR pszModule; // the module name as registered in MS_GC_REGISTER @@ -456,9 +450,22 @@ struct GC_INFO MCONTACT hContact; // hContact for the session (can be NULL) }; -EXTERN_C MIR_APP_DLL(int) Chat_GetInfo(GC_INFO*); +MIR_APP_DLL(int) Chat_GetInfo(GC_INFO *pInfo); + +///////////////////////////////////////////////////////////////////////////////////////// +// Finds a session by its module & unique id +// returns a pointer to session or NULL on error + +MIR_APP_DLL(SESSION_INFO*) Chat_Find(const wchar_t *pszID, const char *pszModule); //------------------------- HOOKS ------------------------ + +///////////////////////////////////////////////////////////////////////////////////////// +// This hook is fired when MS_GC_EVENT is called, with the same wParam and lParam as above. +// It allows external plugins to intercept chat events and display then in other ways + +#define ME_GC_HOOK_EVENT "GChat/HookEvent" + /* -- user interaction -- Hook this to receive notifications about when user take actions in a chat room window. @@ -541,7 +548,7 @@ typedef struct { #define ME_GC_BUILDMENU "GChat/BuildMenu" -EXTERN_C MIR_APP_DLL(void) Chat_AddMenuItems(HMENU hMenu, int nItems, const gc_item *Item, HPLUGIN pPlugin); +MIR_APP_DLL(void) Chat_AddMenuItems(HMENU hMenu, int nItems, const gc_item *Item, HPLUGIN pPlugin); ////////////////////////////////////////////////////////////////////////// // Get Chat ToolTip Text for buddy diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib index dc36cf5c27..f613afbd72 100644 Binary files a/libs/win32/mir_app.lib and b/libs/win32/mir_app.lib differ diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib index 7726b7ca9b..34a3a10687 100644 Binary files a/libs/win64/mir_app.lib and b/libs/win64/mir_app.lib differ diff --git a/plugins/KeyboardNotify/src/main.cpp b/plugins/KeyboardNotify/src/main.cpp index 5c454d239a..b0b65376aa 100644 --- a/plugins/KeyboardNotify/src/main.cpp +++ b/plugins/KeyboardNotify/src/main.cpp @@ -413,7 +413,7 @@ static int OnGcEvent(WPARAM, LPARAM lParam) { auto *gce = (GCEVENT *)lParam; if (gce->iType == GC_EVENT_MESSAGE && bFlashOnGC) - if (SESSION_INFO *si = g_chatApi.SM_FindSession(gce->pszID.w, gce->pszModule)) + if (SESSION_INFO *si = gce->si) if (contactCheckProtocol(si->pszModule, si->hContact, EVENTTYPE_MESSAGE) && checkNotifyOptions() && checkStatus(si->pszModule)) SetEvent(hFlashEvent); diff --git a/plugins/MirLua/src/Modules/m_chat.cpp b/plugins/MirLua/src/Modules/m_chat.cpp index 8611b6bc08..a5e7ef57e4 100644 --- a/plugins/MirLua/src/Modules/m_chat.cpp +++ b/plugins/MirLua/src/Modules/m_chat.cpp @@ -10,8 +10,6 @@ LUAMOD_API int luaopen_m_chat(lua_State *L) luaL_newlib(L, chatApi); MT(L, "GCEVENT") - .Field(&GCEVENT::pszModule, "Module", LUA_TSTRINGA) - .Field(&GCEVENT::pszID, "Id", LUA_TSTRINGW) .Field(&GCEVENT::iType, "Type", LUA_TINTEGER) .Field(&GCEVENT::time, "Timestamp", LUA_TINTEGER) .Field(&GCEVENT::time, "IsMe", LUA_TINTEGER) diff --git a/plugins/MirLua/src/Modules/m_message.cpp b/plugins/MirLua/src/Modules/m_message.cpp index a00ec285e1..eee8c43f3e 100644 --- a/plugins/MirLua/src/Modules/m_message.cpp +++ b/plugins/MirLua/src/Modules/m_message.cpp @@ -30,7 +30,7 @@ static int message_Send(lua_State *L) if (Contact::IsGroupChat(hContact, szProto)) { ptrW wszChatRoom(Contact::GetInfo(CNF_UNIQUEID, hContact, szProto)); ptrW wszMessage(mir_utf8decodeW(message)); - res = Chat_SendUserMessage(szProto, wszChatRoom, wszMessage); + res = Chat_SendUserMessage(Chat_Find(wszChatRoom, szProto), wszMessage); lua_pushinteger(L, res); } else if ((res = ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)message)) != ACKRESULT_FAILED) { diff --git a/plugins/MirandaG15/src/CAppletManager.cpp b/plugins/MirandaG15/src/CAppletManager.cpp index ed688f189c..62bd9e5ab9 100644 --- a/plugins/MirandaG15/src/CAppletManager.cpp +++ b/plugins/MirandaG15/src/CAppletManager.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include "CConfig.h" #include "CAppletManager.h" -#include "m_system.h" // specifies how long contact status notifications are ignored after signon #define PROTOCOL_NOTIFY_DELAY 1500 @@ -744,7 +743,7 @@ MEVENT CAppletManager::SendMessageToContact(MCONTACT hContact, tstring strMessag return NULL; tstring strID = tstring(wszNick) + L" - " + tstring(_A2T(toNarrowString(pIRCCon->strNetwork).c_str())); - Chat_SendUserMessage(szProto, strID.c_str(), strAscii.c_str()); + Chat_SendUserMessage(Chat_Find(strID.c_str(), szProto), strAscii.c_str()); return 0; } @@ -1051,12 +1050,12 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) return 0; } - TRACE(L"<< [%s:%s] event %04X\n", toTstring(gce->pszModule).c_str(), gce->pszID.w, gce->iType); + TRACE(L"<< [%s:%s] event %04X\n", toTstring(gce->si->pszModule).c_str(), gce->si->ptszID, gce->iType); // get the matching irc connection entry - CIRCConnection *pIRCCon = CAppletManager::GetInstance()->GetIRCConnection(toTstring(gce->pszModule)); + CIRCConnection *pIRCCon = CAppletManager::GetInstance()->GetIRCConnection(toTstring(gce->si->pszModule)); if (!pIRCCon) { - TRACE(L"<< [%s] connection not found, skipping event\n", toTstring(gce->pszModule).c_str()); + TRACE(L"<< [%s] connection not found, skipping event\n", toTstring(gce->si->pszModule).c_str()); return 0; } @@ -1078,13 +1077,13 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) Event.hValue = lParam; CIRCHistory *pHistory = nullptr; - if (gce->pszID.w) { - tstring strChannel = toTstring(gce->pszID.w); + if (gce->si->ptszID) { + tstring strChannel = toTstring(gce->si->ptszID); tstring::size_type pos = strChannel.find('-'); if (pos != tstring::npos) strChannel = strChannel.substr(0, pos - 1); else { - if (mir_wstrcmpi(gce->pszID.w, L"Network log")) + if (mir_wstrcmpi(gce->si->ptszID, L"Network log")) TRACE(L"\t WARNING: ignoring unknown event!\n"); return 0; } @@ -1107,7 +1106,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) Event.hContact = NULL; // Ignore events from hidden chatrooms, except for join events - if (gce->pszID.w != nullptr && Contact::IsHidden(Event.hContact)) { + if (gce->si->ptszID != nullptr && Contact::IsHidden(Event.hContact)) { if (gce->iType == GC_EVENT_JOIN && pHistory) pHistory->LUsers.push_back(toTstring(gce->pszNick.w)); @@ -1243,7 +1242,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) TRACE(L"OK!\n"); return 0; } - if (gce->bIsMe || gce->pszID.w == nullptr) + if (gce->bIsMe || gce->si->ptszID == nullptr) Event.bNotification = false; // set the event's timestamp @@ -1284,7 +1283,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) Event.hContact = (*iter)->hContact; tstring strName = CAppletManager::GetContactDisplayname((*iter)->hContact, true); Event.strDescription = strName + L" - " + Event.strValue; - Event.strSummary = L"(" + toTstring(gce->pszModule) + L") " + strName; + Event.strSummary = L"(" + toTstring(gce->si->pszModule) + L") " + strName; CAppletManager::GetInstance()->HandleEvent(&Event); break; } @@ -1296,7 +1295,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) TRACE(L"OK!\n"); return 0; } - else if (gce->pszID.w != nullptr) { + else if (gce->si->ptszID != nullptr) { TRACE(L"OK!\n"); return 0; } @@ -1307,7 +1306,7 @@ int CAppletManager::HookChatInbound(WPARAM, LPARAM lParam) strChannel = strChannel.erase(CConfig::GetIntSetting(NOTIFY_CHANNELCUTOFF_OFFSET)) + L"..."; } Event.strDescription = strChannel + L" - " + Event.strValue; - Event.strSummary = L"(" + toTstring(gce->pszModule) + L") " + pHistory->strChannel; + Event.strSummary = L"(" + toTstring(gce->si->pszModule) + L") " + pHistory->strChannel; } else Event.strDescription = Event.strValue; diff --git a/plugins/MirandaG15/src/StdAfx.h b/plugins/MirandaG15/src/StdAfx.h index 61fed0dbd1..fba8ef69bf 100644 --- a/plugins/MirandaG15/src/StdAfx.h +++ b/plugins/MirandaG15/src/StdAfx.h @@ -25,7 +25,7 @@ using namespace std; #include #include #include -#include +#include #include #include #include diff --git a/plugins/PasteIt/src/PasteIt.cpp b/plugins/PasteIt/src/PasteIt.cpp index b7fb63df7d..ee1393169e 100644 --- a/plugins/PasteIt/src/PasteIt.cpp +++ b/plugins/PasteIt/src/PasteIt.cpp @@ -122,28 +122,7 @@ static void PasteIt(MCONTACT hContact, int mode) db_event_add(hContact, &dbei); ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)pasteToWeb->szFileLink); } - else { - // PSS_MESSAGE is not compatible with chat rooms - // there are no simple method to send text to all users - // in chat room. - // Next step is to get all protocol sessions and find - // one with correct hContact - int cnt = g_chatApi.SM_GetCount(szProto); - for (int i = 0; i < cnt; i++) { - GC_INFO gci = {}; - gci.iItem = i; - gci.pszModule = szProto; - gci.Flags = GCF_BYINDEX | GCF_HCONTACT | GCF_ID; - Chat_GetInfo(&gci); - if (gci.hContact == hContact) { - // In this place session was finded, gci.pszID contains - // session ID, but it is in unicode or ascii format, - // depends on protocol wersion - Chat_SendUserMessage(szProto, gci.pszID, _A2T(pasteToWeb->szFileLink)); - break; - } - } - } + else Chat_SendUserMessage(szProto, _A2T(pasteToWeb->szFileLink)); // Send message to focus window CallServiceSync(MS_MSG_SENDMESSAGE, hContact, 0); diff --git a/plugins/RecentContacts/src/RecentContacts.cpp b/plugins/RecentContacts/src/RecentContacts.cpp index 9b2970e5af..8787936cc9 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->pszID.w, gce->pszModule); + SESSION_INFO *si = gce->si; 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->pszID.w, gce->pszModule); + SESSION_INFO *si = gce->si; if (si && si->hContact) SaveLastUsedTimeStamp(si->hContact); } diff --git a/plugins/SendScreenshotPlus/src/CSend.cpp b/plugins/SendScreenshotPlus/src/CSend.cpp index 3e83d4b6c6..1591919edf 100644 --- a/plugins/SendScreenshotPlus/src/CSend.cpp +++ b/plugins/SendScreenshotPlus/src/CSend.cpp @@ -177,12 +177,15 @@ INT_PTR CALLBACK CSend::ResultDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, void CSend::svcSendMsgExit(const char* szMessage) { if (m_bSilent) { - Exit(ACKRESULT_SUCCESS); return; + Exit(ACKRESULT_SUCCESS); + return; } + if (!m_hContact) { if (!m_pszFileDesc) m_pszFileDesc = mir_a2u(szMessage); - Exit(CSEND_DIALOG); return; + Exit(CSEND_DIALOG); + return; } if (m_ChatRoom) { @@ -191,46 +194,31 @@ void CSend::svcSendMsgExit(const char* szMessage) tmp.Append(L"\r\n"); tmp.Append(m_pszFileDesc); } - - int res = GC_RESULT_NOSESSION; - int cnt = g_chatApi.SM_GetCount(m_pszProto); - - // loop on all gc session to get the right (save) ptszID for the chatroom from m_hContact - GC_INFO gci = { 0 }; - gci.pszModule = m_pszProto; - for (int i = 0; i < cnt; i++) { - gci.iItem = i; - gci.Flags = GCF_BYINDEX | GCF_HCONTACT | GCF_ID; - Chat_GetInfo(&gci); - if (gci.hContact == m_hContact) { - Chat_SendUserMessage(m_pszProto, gci.pszID, tmp); - res = 200; - break; - } - } - Exit(res); return; + Chat_SendUserMessage(m_pszProto, tmp); + + Exit(200); + return; + } + + m_szEventMsg = szMessage; + if (m_pszFileDesc && m_pszFileDesc[0] != NULL) { + m_szEventMsg.Append("\r\n"); + m_szEventMsg.Append(_T2A(m_pszFileDesc)); + m_cbEventMsg = m_szEventMsg.GetLength() + 1; } - else { - m_szEventMsg = szMessage; - if (m_pszFileDesc && m_pszFileDesc[0] != NULL) { - m_szEventMsg.Append("\r\n"); - m_szEventMsg.Append(_T2A(m_pszFileDesc)); - m_cbEventMsg = m_szEventMsg.GetLength() + 1; - } - // create a HookEventObj on ME_PROTO_ACK - if (!m_hOnSend) - m_hOnSend = HookEventObj(ME_PROTO_ACK, OnSend, this); + // create a HookEventObj on ME_PROTO_ACK + if (!m_hOnSend) + m_hOnSend = HookEventObj(ME_PROTO_ACK, OnSend, this); - // start PSS_MESSAGE service - m_hSend = (HANDLE)ProtoChainSend(m_hContact, PSS_MESSAGE, NULL, ptrA(mir_utf8encode(m_szEventMsg))); + // start PSS_MESSAGE service + m_hSend = (HANDLE)ProtoChainSend(m_hContact, PSS_MESSAGE, NULL, ptrA(mir_utf8encode(m_szEventMsg))); - // check we actually got an ft handle back from the protocol - if (!m_hSend) { - Unhook(); - Error(SS_ERR_INIT, m_pszSendTyp); - Exit(ACKRESULT_FAILED); return; - } + // check we actually got an ft handle back from the protocol + if (!m_hSend) { + Unhook(); + Error(SS_ERR_INIT, m_pszSendTyp); + Exit(ACKRESULT_FAILED); } } diff --git a/plugins/XSoundNotify/src/xsn_main.cpp b/plugins/XSoundNotify/src/xsn_main.cpp index 4abffe43e8..b002b0d66e 100644 --- a/plugins/XSoundNotify/src/xsn_main.cpp +++ b/plugins/XSoundNotify/src/xsn_main.cpp @@ -171,7 +171,7 @@ static int ProcessChatEvent(WPARAM, LPARAM lParam) if (gce->iType != GC_EVENT_MESSAGE) return 0; - auto *si = g_chatApi.SM_FindSession(gce->pszID.w, gce->pszModule); + auto *si = gce->si; if (si && g_chatApi.IsHighlighted(si, gce)) PlayWorker(si->hContact); diff --git a/protocols/CloudFile/src/utils.cpp b/protocols/CloudFile/src/utils.cpp index 69a5c74a60..73e22ef7c0 100644 --- a/protocols/CloudFile/src/utils.cpp +++ b/protocols/CloudFile/src/utils.cpp @@ -67,8 +67,8 @@ void SendToContact(MCONTACT hContact, const wchar_t *data) { const char *szProto = Proto_GetBaseAccountName(hContact); if (Contact::IsGroupChat(hContact, szProto)) { - ptrW tszChatRoom(Contact::GetInfo(CNF_UNIQUEID, hContact, szProto)); - Chat_SendUserMessage(szProto, tszChatRoom, data); + auto *si = Chat_Find(ptrW(Contact::GetInfo(CNF_UNIQUEID, hContact, szProto)), szProto); + Chat_SendUserMessage(si, data); return; } diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 7554fa669c..2c749eb8b9 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -108,8 +108,10 @@ void CDiscordProto::OnCommandChannelDeleted(const JSONNode &pRoot) } else { CDiscordGuild *pGuild = FindGuild(guildId); - if (pGuild != nullptr) - Chat_Terminate(m_szModuleName, pUser->wszUsername, true); + if (pGuild != nullptr) { + Chat_Terminate(pUser->si, true); + pUser->si = nullptr; + } } } @@ -130,14 +132,13 @@ void CDiscordProto::OnCommandChannelUpdated(const JSONNode &pRoot) CMStringW wszName = pRoot["name"].as_mstring(); if (!wszName.IsEmpty()) { CMStringW wszNewName = pGuild->wszName + L"#" + wszName; - Chat_ChangeSessionName(m_szModuleName, pUser->wszUsername, wszNewName); + Chat_ChangeSessionName(pUser->si, wszNewName); } CMStringW wszTopic = pRoot["topic"].as_mstring(); - Chat_SetStatusbarText(m_szModuleName, pUser->wszUsername, wszTopic); + Chat_SetStatusbarText(pUser->si, wszTopic); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_TOPIC }; - gce.pszID.w = pUser->wszUsername; + GCEVENT gce = { pUser->si, GC_EVENT_TOPIC }; gce.pszText.w = wszTopic; gce.time = time(0); Chat_Event(&gce); @@ -184,11 +185,12 @@ void CDiscordProto::OnCommandGuildDeleted(const JSONNode &pRoot) for (auto &it : arUsers.rev_iter()) if (it->pGuild == pGuild) { - Chat_Terminate(m_szModuleName, it->wszUsername, true); + Chat_Terminate(it->si, true); arUsers.removeItem(&it); } - Chat_Terminate(m_szModuleName, pRoot["name"].as_mstring(), true); + Chat_Terminate(pGuild->pParentSi, true); + pGuild->pParentSi = nullptr; arGuilds.remove(pGuild); } @@ -226,7 +228,7 @@ void CDiscordProto::OnCommandGuildMemberListUpdate(const JSONNode &pRoot) else if (iStatus) { CMStringW wszUserId(FORMAT, L"%lld", pm->userId); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_SETCONTACTSTATUS }; + GCEVENT gce = { 0, GC_EVENT_SETCONTACTSTATUS }; gce.time = time(0); gce.pszUID.w = wszUserId; @@ -234,7 +236,7 @@ void CDiscordProto::OnCommandGuildMemberListUpdate(const JSONNode &pRoot) if (!cc->bIsGroup) continue; - gce.pszID.w = cc->wszChannelName; + gce.si = cc->si; gce.dwItemData = iStatus; Chat_Event(&gce); } @@ -258,7 +260,7 @@ void CDiscordProto::OnCommandGuildMemberRemoved(const JSONNode &pRoot) if (pUser->pGuild != pGuild) continue; - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_PART }; + GCEVENT gce = { pUser->si, GC_EVENT_PART }; gce.pszUID.w = pUser->wszUsername; gce.time = time(0); gce.pszUID.w = wszUserId; @@ -294,8 +296,7 @@ void CDiscordProto::OnCommandGuildMemberUpdated(const JSONNode &pRoot) wszOldNick = ui->pszNick; } - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_NICK }; - gce.pszID.w = it->wszUsername; + GCEVENT gce = { si, GC_EVENT_NICK }; gce.time = time(0); gce.pszUID.w = wszUserId; gce.pszNick.w = wszOldNick; @@ -435,8 +436,7 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) ParseSpecialChars(si, wszText); wszText.Replace(L"%", L"%%"); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; - gce.pszID.w = pUser->wszUsername; + GCEVENT gce = { pUser->si, GC_EVENT_MESSAGE }; gce.dwFlags = GCEF_ADDTOLOG; gce.pszUID.w = wszUserId; gce.pszText.w = wszText; @@ -548,8 +548,7 @@ void CDiscordProto::OnCommandTyping(const JSONNode &pRoot) CMStringW wszUerId = pRoot["user_id"].as_mstring(); ProcessGuildUser(pChannel->pGuild, pRoot); // never returns null - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_TYPING }; - gce.pszID.w = pChannel->wszUsername; + GCEVENT gce = { pChannel->si, GC_EVENT_TYPING }; gce.pszUID.w = wszUerId; gce.dwItemData = 1; gce.time = time(0); diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp index 760437ceb0..6095b0a234 100644 --- a/protocols/Discord/src/guilds.cpp +++ b/protocols/Discord/src/guilds.cpp @@ -114,7 +114,7 @@ void CDiscordProto::BatchChatCreate(void *param) void CDiscordProto::CreateChat(CDiscordGuild *pGuild, CDiscordUser *pUser) { - SESSION_INFO *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, pUser->wszUsername, pUser->wszChannelName); + auto *si = pUser->si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, pUser->wszUsername, pUser->wszChannelName); si->pParent = pGuild->pParentSi; pUser->hContact = si->hContact; setId(pUser->hContact, DB_KEY_ID, pUser->channelId); @@ -139,14 +139,13 @@ void CDiscordProto::CreateChat(CDiscordGuild *pGuild, CDiscordUser *pUser) BuildStatusList(pGuild, si); - Chat_Control(m_szModuleName, pUser->wszUsername, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); - Chat_Control(m_szModuleName, pUser->wszUsername, SESSION_ONLINE); + Chat_Control(si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); + Chat_Control(si, SESSION_ONLINE); if (!pUser->wszTopic.IsEmpty()) { - Chat_SetStatusbarText(m_szModuleName, pUser->wszUsername, pUser->wszTopic); + Chat_SetStatusbarText(si, pUser->wszTopic); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_TOPIC }; - gce.pszID.w = pUser->wszUsername; + GCEVENT gce = { si, GC_EVENT_TOPIC }; gce.time = time(0); gce.pszText.w = pUser->wszTopic; Chat_Event(&gce); @@ -177,8 +176,8 @@ void CDiscordProto::ProcessGuild(const JSONNode &pRoot) pGuild->hContact = si->hContact; setId(pGuild->hContact, DB_KEY_CHANNELID, guildId); - Chat_Control(m_szModuleName, pGuild->wszName, WINDOW_HIDDEN); - Chat_Control(m_szModuleName, pGuild->wszName, SESSION_ONLINE); + Chat_Control(si, WINDOW_HIDDEN); + Chat_Control(si, SESSION_ONLINE); for (auto &it : pRoot["roles"]) ProcessRole(pGuild, it); diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index b5262f4e0a..683c0cbb05 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -86,6 +86,7 @@ struct CDiscordUser : public MZeroedObject bool bSynced; struct CDiscordGuild *pGuild; + SESSION_INFO *si; CMStringW wszUsername, wszChannelName, wszTopic; int iDiscriminator; diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index 16f716e89f..8266e11a0b 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -129,8 +129,7 @@ void CDiscordProto::OnReceiveHistory(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest ParseSpecialChars(si, wszText); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; - gce.pszID.w = pUser->wszUsername; + GCEVENT gce = { si, GC_EVENT_MESSAGE }; gce.dwFlags = GCEF_ADDTOLOG; gce.pszUID.w = wszUserId; gce.pszText.w = wszText; diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp index ce12a81443..b9297735e1 100644 --- a/protocols/Discord/src/utils.cpp +++ b/protocols/Discord/src/utils.cpp @@ -185,8 +185,7 @@ void CDiscordProto::PreparePrivateChannel(const JSONNode &root) SnowFlake ownerId = _wtoi64(root["owner_id"].as_mstring()); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; - gce.pszID.w = pUser->wszUsername; + GCEVENT gce = { pUser->si, GC_EVENT_JOIN }; for (auto &it : root["recipients"]) { CMStringW wszId = it["id"].as_mstring(); CMStringW wszNick = it["nick"].as_mstring(); @@ -207,8 +206,8 @@ void CDiscordProto::PreparePrivateChannel(const JSONNode &root) gce.pszStatus.w = (_wtoi64(wszId) == ownerId) ? L"Owners" : L"Participants"; Chat_Event(&gce); - Chat_Control(m_szModuleName, pUser->wszUsername, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); - Chat_Control(m_szModuleName, pUser->wszUsername, SESSION_ONLINE); + Chat_Control(pUser->si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); + Chat_Control(pUser->si, SESSION_ONLINE); } break; diff --git a/protocols/Facebook/src/groupchats.cpp b/protocols/Facebook/src/groupchats.cpp index b43e05696a..cc56860e5a 100644 --- a/protocols/Facebook/src/groupchats.cpp +++ b/protocols/Facebook/src/groupchats.cpp @@ -131,7 +131,7 @@ int FacebookProto::GroupchatMenuHook(WPARAM, LPARAM lParam) if (mir_strcmpi(gcmi->pszModule, m_szModuleName)) return 0; - if (SESSION_INFO *si = g_chatApi.SM_FindSession(gcmi->pszID, gcmi->pszModule)) { + if (SESSION_INFO *si = Chat_Find(gcmi->pszID, gcmi->pszModule)) { if (gcmi->Type == MENU_ON_LOG) Chat_AddMenuItems(gcmi->hMenu, _countof(sttLogListItems), sttLogListItems, &g_plugin); if (gcmi->Type == MENU_ON_NICKLIST) @@ -150,7 +150,7 @@ int FacebookProto::GroupchatEventHook(WPARAM, LPARAM lParam) if (mir_strcmpi(gch->si->pszModule, m_szModuleName)) return 0; - SESSION_INFO *si = g_chatApi.SM_FindSession(gch->si->ptszID, gch->si->pszModule); + SESSION_INFO *si = Chat_Find(gch->si->ptszID, gch->si->pszModule); if (si == nullptr) return 1; @@ -245,7 +245,7 @@ int FacebookProto::Chat_KickUser(SESSION_INFO *si, const wchar_t *pwszUid) static void __cdecl DestroyRoomThread(SESSION_INFO *si) { ::Sleep(100); - Chat_Terminate(si->pszModule, si->ptszID, true); + Chat_Terminate(si, true); } void FacebookProto::Chat_Leave(SESSION_INFO *si) diff --git a/protocols/Facebook/src/proto.h b/protocols/Facebook/src/proto.h index efa5a008d9..fa110918f4 100644 --- a/protocols/Facebook/src/proto.h +++ b/protocols/Facebook/src/proto.h @@ -354,6 +354,7 @@ struct FacebookUser MCONTACT hContact; bool bIsChat; bool bIsChatInitialized; + SESSION_INFO *si; }; ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Facebook/src/server.cpp b/protocols/Facebook/src/server.cpp index e3d1f31736..8a3aa1819d 100644 --- a/protocols/Facebook/src/server.cpp +++ b/protocols/Facebook/src/server.cpp @@ -286,8 +286,7 @@ FacebookUser* FacebookProto::RefreshThread(JSONNode &n) CMStringW userId(ur["id"].as_mstring()); CMStringW userName(ur["name"].as_mstring()); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; - gce.pszID.w = chatId; + GCEVENT gce = { si, GC_EVENT_JOIN }; gce.pszUID.w = userId; gce.pszNick.w = userName; gce.bIsMe = _wtoi64(userId) == m_uid; @@ -295,8 +294,8 @@ FacebookUser* FacebookProto::RefreshThread(JSONNode &n) Chat_Event(&gce); } - Chat_Control(m_szModuleName, chatId, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); - Chat_Control(m_szModuleName, chatId, SESSION_ONLINE); + Chat_Control(si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); + Chat_Control(si, SESSION_ONLINE); __int64 userId = _wtoi64(chatId); auto *pUser = FindUser(userId); @@ -307,6 +306,7 @@ FacebookUser* FacebookProto::RefreshThread(JSONNode &n) m_users.insert(pUser); } else { + pUser->si = si; pUser->hContact = si->hContact; pUser->bIsChatInitialized = true; } @@ -872,8 +872,7 @@ void FacebookProto::OnPublishPrivateMessage(const JSONNode &root) // TODO: GC_EVENT_JOIN for chat participants which are missing (for example added later during group chat) - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; - gce.pszID.w = wszUserId; + GCEVENT gce = { pUser->si, GC_EVENT_MESSAGE }; gce.dwFlags = GCEF_ADDTOLOG; gce.pszUID.w = wszActorFbId; gce.pszText.w = wszText; @@ -939,8 +938,7 @@ void FacebookProto::OnPublishChatJoin(const JSONNode &root) for (auto &it : root["addedParticipants"]) { CMStringW wszNick(it["fullName"].as_mstring()), wszId(it["userFbId"].as_mstring()); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; - gce.pszID.w = wszUserId; + GCEVENT gce = { pUser->si, GC_EVENT_JOIN }; gce.dwFlags = GCEF_ADDTOLOG; gce.pszNick.w = wszNick; gce.pszUID.w = wszId; @@ -968,8 +966,7 @@ void FacebookProto::OnPublishChatLeave(const JSONNode &root) return; CMStringW wszText(metadata["adminText"].as_mstring()), wszId(root["leftParticipantFbId"].as_mstring()); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_PART }; - gce.pszID.w = wszUserId; + GCEVENT gce = { pUser->si, GC_EVENT_PART }; gce.dwFlags = GCEF_ADDTOLOG; gce.pszUID.w = wszId; gce.pszText.w = wszText; @@ -1017,8 +1014,7 @@ bool FacebookProto::CheckOwnMessage(FacebookUser *pUser, __int64 offlineId, cons wchar_t userId[100]; _i64tow_s(pUser->id, userId, _countof(userId), 10); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; - gce.pszID.w = userId; + GCEVENT gce = { pUser->si, GC_EVENT_MESSAGE }; gce.dwFlags = GCEF_ADDTOLOG; gce.pszUID.w = wszId; gce.pszText.w = tmp.wszText; diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp index 6a0698e1cf..19735b87e2 100644 --- a/protocols/Gadu-Gadu/src/core.cpp +++ b/protocols/Gadu-Gadu/src/core.cpp @@ -809,21 +809,20 @@ retry: else if (!e->event.msg.recipients_count || gc_enabled) { // Check if groupchat if (e->event.msg.recipients_count && gc_enabled && !getByte(GG_KEY_IGNORECONF, GG_KEYDEF_IGNORECONF)) { - wchar_t *chat = gc_getchat(e->event.msg.sender, e->event.msg.recipients, e->event.msg.recipients_count); - if (chat) { + auto *si = gc_getchat(e->event.msg.sender, e->event.msg.recipients, e->event.msg.recipients_count); + if (si) { wchar_t id[32]; UIN2IDT(e->event.msg.sender, id); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; + GCEVENT gce = { si, GC_EVENT_MESSAGE }; time_t t = time(0); - gce.pszID.w = chat; gce.pszUID.w = id; wchar_t* messageT = mir_utf8decodeW(e->event.msg.message); 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); + debugLogW(L"mainthread() (%x): Conference message to room %s & id %s.", this, si->ptszID, id); Chat_Event(&gce); mir_free(messageT); } @@ -870,14 +869,12 @@ retry: case GG_EVENT_MULTILOGON_MSG: if (e->event.multilogon_msg.recipients_count && gc_enabled && !getByte(GG_KEY_IGNORECONF, GG_KEYDEF_IGNORECONF)) { - wchar_t *chat = gc_getchat(e->event.multilogon_msg.sender, e->event.multilogon_msg.recipients, e->event.multilogon_msg.recipients_count); - if (chat) - { + auto *si = gc_getchat(e->event.multilogon_msg.sender, e->event.multilogon_msg.recipients, e->event.multilogon_msg.recipients_count); + if (si) { wchar_t id[32]; UIN2IDT(getDword(GG_KEY_UIN, 0), id); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; - gce.pszID.w = chat; + GCEVENT gce = { si, GC_EVENT_MESSAGE }; gce.pszUID.w = id; wchar_t* messageT = mir_utf8decodeW(e->event.multilogon_msg.message); gce.pszText.w = messageT; @@ -886,14 +883,13 @@ retry: nickT = mir_wstrdup(dbv.pwszVal); db_free(&dbv); } - else - nickT = mir_wstrdup(TranslateT("Me")); + else nickT = mir_wstrdup(TranslateT("Me")); gce.pszNick.w = nickT; gce.time = e->event.multilogon_msg.time; gce.bIsMe = 1; gce.dwFlags = GCEF_ADDTOLOG; - debugLogW(L"mainthread() (%x): Sent conference message to room %s.", this, chat); + debugLogW(L"mainthread() (%x): Sent conference message to room %s.", this, si->ptszID); Chat_Event(&gce); mir_free(messageT); mir_free(nickT); @@ -1224,8 +1220,9 @@ void GaduProto::OnContactDeleted(MCONTACT hContact) free(chat->recipients); list_remove(&chats, chat, 1); // Terminate chat window / shouldn't cascade entry is deleted - Chat_Control(m_szModuleName, wszRoomId, SESSION_OFFLINE); - Chat_Terminate(m_szModuleName, wszRoomId); + Chat_Control(chat->si, SESSION_OFFLINE); + Chat_Terminate(chat->si, wszRoomId); + chat->si = nullptr; } return; } @@ -1290,7 +1287,7 @@ int GaduProto::dbsettingchanged(WPARAM hContact, LPARAM lParam) debugLogA("dbsettingchanged(): Conference %s was renamed.", wszId.c_str()); // Mark cascading /* FIXME */ cascade = 1; - Chat_ChangeSessionName(m_szModuleName, wszId, ptszVal); + Chat_ChangeSessionName(Chat_Find(wszId, m_szModuleName), ptszVal); /* FIXME */ cascade = 0; } } diff --git a/protocols/Gadu-Gadu/src/gg.h b/protocols/Gadu-Gadu/src/gg.h index c4ed8826b4..870af10e41 100644 --- a/protocols/Gadu-Gadu/src/gg.h +++ b/protocols/Gadu-Gadu/src/gg.h @@ -104,7 +104,7 @@ struct GGGC { uin_t *recipients; int recipients_count; - wchar_t id[32]; + SESSION_INFO *si; BOOL ignore; }; diff --git a/protocols/Gadu-Gadu/src/gg_proto.h b/protocols/Gadu-Gadu/src/gg_proto.h index f84691c0b8..6142e92838 100644 --- a/protocols/Gadu-Gadu/src/gg_proto.h +++ b/protocols/Gadu-Gadu/src/gg_proto.h @@ -189,7 +189,7 @@ struct GaduProto : public PROTO int gc_init(); void gc_menus_init(HGENMENU hRoot); int gc_destroy(); - wchar_t * gc_getchat(uin_t sender, uin_t *recipients, int recipients_count); + SESSION_INFO* gc_getchat(uin_t sender, uin_t *recipients, int recipients_count); GGGC *gc_lookup(const wchar_t *id); int gc_changenick(MCONTACT hContact, wchar_t *ptszNick); diff --git a/protocols/Gadu-Gadu/src/groupchat.cpp b/protocols/Gadu-Gadu/src/groupchat.cpp index 81deec7393..39bd3a0b98 100644 --- a/protocols/Gadu-Gadu/src/groupchat.cpp +++ b/protocols/Gadu-Gadu/src/groupchat.cpp @@ -98,7 +98,7 @@ GGGC* GaduProto::gc_lookup(const wchar_t *id) for (l = chats; l; l = l->next) { chat = (GGGC *)l->data; - if (chat && !mir_wstrcmp(chat->id, id)) + if (chat && !mir_wstrcmp(chat->si->ptszID, id)) return chat; } @@ -136,8 +136,7 @@ int GaduProto::gc_event(WPARAM, LPARAM lParam) UIN2IDT(uin, id); DBVARIANT dbv; - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; - gce.pszID.w = gch->si->ptszID; + GCEVENT gce = { gch->si, GC_EVENT_MESSAGE }; gce.pszUID.w = id; gce.pszText.w = gch->ptszText; wchar_t* nickT; @@ -190,8 +189,8 @@ typedef struct _gg_gc_echat //////////////////////////////////////////////////////////////////////////////// // This is main groupchat initialization routine -// -wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_count) + +SESSION_INFO* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_count) { list_t l; GGGC *chat; @@ -226,17 +225,19 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c // Found all recipients if (found == recipients_count) { if (chat->ignore) - debugLogW(L"gc_getchat(): Ignoring existing id %s, size %d.", chat->id, chat->recipients_count); + debugLogW(L"gc_getchat(): Ignoring existing id %s, size %d.", chat->si->ptszID, chat->recipients_count); else - debugLogW(L"gc_getchat(): Returning existing id %s, size %d.", chat->id, chat->recipients_count); - return !(chat->ignore) ? chat->id : nullptr; + debugLogW(L"gc_getchat(): Returning existing id %s, size %d.", chat->si->ptszID, chat->recipients_count); + return !(chat->ignore) ? chat->si : nullptr; } } } + wchar_t chatId[32]; + UIN2IDT(gc_id++, chatId); + // Make new uin list to chat mapping chat = (GGGC *)malloc(sizeof(GGGC)); - UIN2IDT(gc_id++, chat->id); chat->ignore = FALSE; // Check groupchat policy (new) / only for incoming @@ -276,7 +277,7 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c for (; i < recipients_count; i++) chat->recipients[i] = recipients[i]; if (sender) chat->recipients[i] = sender; - debugLogW(L"gc_getchat(): Ignoring new chat %s, count %d.", chat->id, chat->recipients_count); + debugLogW(L"gc_getchat(): Ignoring new chat %s, count %d.", chatId, chat->recipients_count); list_add(&chats, chat, 0); return nullptr; } @@ -296,19 +297,19 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c // Create new room CMStringW wszTitle(L"#"); wszTitle.Append(sender ? senderName : TranslateT("Conference")); - SESSION_INFO *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, chat->id, wszTitle, chat); + SESSION_INFO *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, chatId, wszTitle, chat); if (!si) return nullptr; + chat->si = si; - Chat_SetStatusbarText(m_szModuleName, chat->id, status); + Chat_SetStatusbarText(si, status); // Add normal group Chat_AddGroup(si, TranslateT("Participants")); wchar_t id[32]; - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; - gce.pszID.w = chat->id; + GCEVENT gce = { si, GC_EVENT_JOIN }; gce.pszUID.w = id; gce.dwFlags = GCEF_ADDTOLOG; @@ -327,8 +328,7 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c mir_free(nickT); 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); + else debugLogA("gc_getchat(): Myself adding failed with uin %d !!!", uin); // Copy recipient list chat->recipients_count = recipients_count + (sender ? 1 : 0); @@ -353,13 +353,13 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c Chat_Event(&gce); } - Chat_Control(m_szModuleName, chat->id, SESSION_INITDONE); - Chat_Control(m_szModuleName, chat->id, SESSION_ONLINE); + Chat_Control(si, SESSION_INITDONE); + Chat_Control(si, SESSION_ONLINE); - debugLogW(L"gc_getchat(): Returning new chat window %s, count %d.", chat->id, chat->recipients_count); + debugLogW(L"gc_getchat(): Returning new chat window %s, count %d.", chatId, chat->recipients_count); list_add(&chats, chat, 0); - return chat->id; + return si; } static MCONTACT gg_getsubcontact(GaduProto* gg, MCONTACT hContact) @@ -441,9 +441,9 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa if (count > i) i = count; - wchar_t *chat = gg->gc_getchat(0, participants, count); - if (chat) - Chat_Control(gg->m_szModuleName, chat, WINDOW_VISIBLE); + auto *si = gg->gc_getchat(0, participants, count); + if (si) + Chat_Control(si, WINDOW_VISIBLE); free(participants); } @@ -573,23 +573,23 @@ int GaduProto::gc_changenick(MCONTACT hContact, wchar_t *ptszNick) // Lookup for chats having this nick for (l = chats; l; l = l->next) { GGGC *chat = (GGGC *)l->data; - if (chat->recipients && chat->recipients_count) - for (int i = 0; i < chat->recipients_count; i++) + 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) { wchar_t id[32]; UIN2IDT(uin, id); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_NICK }; - gce.pszID.w = chat->id; + GCEVENT gce = { chat->si, GC_EVENT_NICK }; 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); + debugLogW(L"gc_changenick(): Found room %s with uin %d, sending nick change %s.", chat->si->ptszID, uin, id); Chat_Event(&gce); - break; } + } + } } return 1; diff --git a/protocols/ICQ-WIM/src/groupchats.cpp b/protocols/ICQ-WIM/src/groupchats.cpp index 807bec394a..d59e7c6a74 100644 --- a/protocols/ICQ-WIM/src/groupchats.cpp +++ b/protocols/ICQ-WIM/src/groupchats.cpp @@ -35,9 +35,8 @@ void CIcqProto::LoadChatInfo(SESSION_INFO *si) CMStringW role((*node)["role"].as_mstring()); CMStringW sn((*node)["sn"].as_mstring()); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; + GCEVENT gce = { si, GC_EVENT_JOIN }; gce.dwFlags = GCEF_SILENT; - gce.pszID.w = si->ptszID; gce.pszNick.w = nick; gce.pszUID.w = sn; gce.time = ::time(0); @@ -161,7 +160,7 @@ void CIcqProto::LeaveDestroyChat(SESSION_INFO *si) Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/hideChat") << AIMSID(this) << WCHAR_PARAM("buddy", si->ptszID) << INT64_PARAM("lastMsgId", getId(si->hContact, DB_KEY_LASTMSGID))); - Chat_Terminate(si->pszModule, si->ptszID, true); + Chat_Terminate(si, true); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -183,7 +182,7 @@ int CIcqProto::GroupchatMenuHook(WPARAM, LPARAM lParam) if (mir_strcmpi(gcmi->pszModule, m_szModuleName)) return 0; - SESSION_INFO *si = g_chatApi.SM_FindSession(gcmi->pszID, gcmi->pszModule); + SESSION_INFO *si = Chat_Find(gcmi->pszID, gcmi->pszModule); if (si == nullptr) return 0; @@ -202,7 +201,7 @@ int CIcqProto::GroupchatEventHook(WPARAM, LPARAM lParam) if (mir_strcmpi(gch->si->pszModule, m_szModuleName)) return 0; - SESSION_INFO *si = g_chatApi.SM_FindSession(gch->si->ptszID, gch->si->pszModule); + SESSION_INFO *si = Chat_Find(gch->si->ptszID, gch->si->pszModule); if (si == nullptr) return 1; @@ -263,13 +262,12 @@ void CIcqProto::ProcessGroupChat(const JSONNode &ev) { for (auto &it : ev["mchats"]) { CMStringW wszId(it["sender"].as_mstring()); - SESSION_INFO *si = g_chatApi.SM_FindSession(wszId, m_szModuleName); + auto *si = Chat_Find(wszId, m_szModuleName); if (si == nullptr) continue; CMStringW method(it["method"].as_mstring()); - GCEVENT gce = { m_szModuleName, 0, (method == "add_members") ? GC_EVENT_JOIN : GC_EVENT_PART }; - gce.pszID.w = si->ptszID; + GCEVENT gce = { si, (method == "add_members") ? GC_EVENT_JOIN : GC_EVENT_PART }; int iStart = 0; CMStringW members(it["members"].as_mstring()); diff --git a/protocols/ICQ-WIM/src/poll.cpp b/protocols/ICQ-WIM/src/poll.cpp index 6fca78728f..c6c7d0b2e0 100644 --- a/protocols/ICQ-WIM/src/poll.cpp +++ b/protocols/ICQ-WIM/src/poll.cpp @@ -167,7 +167,7 @@ void CIcqProto::ProcessHistData(const JSONNode &ev) auto *pCache = FindContactByUIN(wszId); // might be NULL for groupchats if (IsChat(wszId)) { - SESSION_INFO *si = g_chatApi.SM_FindSession(wszId, m_szModuleName); + SESSION_INFO *si = Chat_Find(wszId, m_szModuleName); if (si == nullptr) return; diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp index e7468d952a..d8f203dfc9 100644 --- a/protocols/ICQ-WIM/src/server.cpp +++ b/protocols/ICQ-WIM/src/server.cpp @@ -300,8 +300,8 @@ MCONTACT CIcqProto::ParseBuddyInfo(const JSONNode &buddy, MCONTACT hContact, boo Chat_AddGroup(si, TranslateT("admin")); Chat_AddGroup(si, TranslateT("member")); - Chat_Control(m_szModuleName, wszChatId, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); - Chat_Control(m_szModuleName, wszChatId, SESSION_ONLINE); + Chat_Control(si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); + Chat_Control(si, SESSION_ONLINE); return si->hContact; } @@ -500,14 +500,15 @@ void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNo delete pFileInfo; } - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; - gce.pszID.w = wszChatId; - gce.dwFlags = GCEF_ADDTOLOG; - gce.pszUID.w = wszSender; - gce.pszText.w = wszText; - gce.time = iMsgTime; - gce.bIsMe = wszSender == m_szOwnId; - Chat_Event(&gce); + if (auto *si = Chat_Find(wszChatId, m_szModuleName)) { + GCEVENT gce = { si, GC_EVENT_MESSAGE}; + gce.dwFlags = GCEF_ADDTOLOG; + gce.pszUID.w = wszSender; + gce.pszText.w = wszText; + gce.time = iMsgTime; + gce.bIsMe = wszSender == m_szOwnId; + Chat_Event(&gce); + } return; } diff --git a/protocols/IRCG/src/commandmonitor.cpp b/protocols/IRCG/src/commandmonitor.cpp index ab9a7e646f..eb846b07af 100644 --- a/protocols/IRCG/src/commandmonitor.cpp +++ b/protocols/IRCG/src/commandmonitor.cpp @@ -371,7 +371,7 @@ bool CIrcProto::OnIrc_QUIT(const CIrcMessage *pmsg) CONTACT user = { pmsg->prefix.sNick, pmsg->prefix.sUser, pmsg->prefix.sHost, false, false, false }; CList_SetOffline(&user); if (pmsg->prefix.sNick == m_info.sNick) - Chat_Control(m_szModuleName, nullptr, SESSION_OFFLINE); + setAllContactStatuses(SESSION_OFFLINE, false); } else ShowMessage(pmsg); @@ -384,7 +384,7 @@ bool CIrcProto::OnIrc_PART(const CIrcMessage *pmsg) CMStringW host = pmsg->prefix.sUser + L"@" + pmsg->prefix.sHost; DoEvent(GC_EVENT_PART, pmsg->parameters[0], pmsg->prefix.sNick, pmsg->parameters.getCount() > 1 ? pmsg->parameters[1].c_str() : nullptr, nullptr, host, NULL, true, false); if (pmsg->prefix.sNick == m_info.sNick) - Chat_Control(m_szModuleName, pmsg->parameters[0], SESSION_OFFLINE); + Chat_Control(pmsg->parameters[0], SESSION_OFFLINE); } else ShowMessage(pmsg); @@ -399,10 +399,10 @@ bool CIrcProto::OnIrc_KICK(const CIrcMessage *pmsg) ShowMessage(pmsg); if (pmsg->parameters[1] == m_info.sNick) { - Chat_Control(m_szModuleName, pmsg->parameters[0], SESSION_OFFLINE); + Chat_Control(pmsg->parameters[0], SESSION_OFFLINE); if (m_rejoinIfKicked) { - CHANNELINFO *wi = (CHANNELINFO *)Chat_GetUserInfo(m_szModuleName, pmsg->parameters[0]); + auto *wi = GetChannelInfo(pmsg->parameters[0]); if (wi && wi->pszPassword) PostIrcMessage(L"/JOIN %s %s", pmsg->parameters[0].c_str(), wi->pszPassword); else @@ -486,7 +486,7 @@ bool CIrcProto::OnIrc_MODE(const CIrcMessage *pmsg) if ((int)pmsg->parameters.getCount() > iParametercount) { if (!mir_wstrcmp(pmsg->parameters[2], m_info.sNick)) { char cModeBit = -1; - CHANNELINFO *wi = (CHANNELINFO*)Chat_GetUserInfo(m_szModuleName, pmsg->parameters[0]); + auto *wi = GetChannelInfo(pmsg->parameters[0]); switch (*p1) { case 'v': cModeBit = 0; break; case 'h': cModeBit = 1; break; @@ -503,7 +503,7 @@ bool CIrcProto::OnIrc_MODE(const CIrcMessage *pmsg) wi->OwnMode &= ~(1 << cModeBit); } - Chat_SetUserInfo(m_szModuleName, pmsg->parameters[0], wi); + SetChannelInfo(pmsg->parameters[0], wi); } DoEvent(bAdd ? GC_EVENT_ADDSTATUS : GC_EVENT_REMOVESTATUS, pmsg->parameters[0], pmsg->parameters[iParametercount], pmsg->prefix.sNick, sStatus, nullptr, NULL, m_oldStyleModes ? false : true, false); iParametercount++; @@ -569,7 +569,7 @@ bool CIrcProto::OnIrc_NICK(const CIrcMessage *pmsg) CMStringW host = pmsg->prefix.sUser + L"@" + pmsg->prefix.sHost; DoEvent(GC_EVENT_NICK, nullptr, pmsg->prefix.sNick, pmsg->parameters[0], nullptr, host, NULL, true, bIsMe); - Chat_ChangeUserId(m_szModuleName, nullptr, pmsg->prefix.sNick, pmsg->parameters[0]); + Chat_ChangeUserId(m_szModuleName, pmsg->prefix.sNick, pmsg->parameters[0]); CONTACT user = { pmsg->prefix.sNick, pmsg->prefix.sUser, pmsg->prefix.sHost, false, false, false }; MCONTACT hContact = CList_FindContact(&user); @@ -1243,7 +1243,7 @@ bool CIrcProto::OnIrc_ENDNAMES(const CIrcMessage *pmsg) } if (bFlag) { - const wchar_t* sChanName = pmsg->parameters[1]; + const wchar_t *sChanName = pmsg->parameters[1]; if (sChanName[0] == '@' || sChanName[0] == '*' || sChanName[0] == '=') sChanName++; @@ -1276,8 +1276,7 @@ bool CIrcProto::OnIrc_ENDNAMES(const CIrcMessage *pmsg) while (PrefixToStatus(sTemp[0]) != pwszNormal) sTemp.Delete(0, 1); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; - gce.pszID.w = sChanName; + GCEVENT gce = { si, GC_EVENT_JOIN }; gce.pszUID.w = sTemp; gce.pszNick.w = sTemp; gce.pszStatus.w = sStat; @@ -1319,7 +1318,7 @@ bool CIrcProto::OnIrc_ENDNAMES(const CIrcMessage *pmsg) //Set the item data for the window { - CHANNELINFO *wi = (CHANNELINFO *)Chat_GetUserInfo(m_szModuleName, sChanName); + auto *wi = GetChannelInfo(sChanName); if (!wi) wi = new CHANNELINFO; wi->OwnMode = btOwnMode; @@ -1328,7 +1327,7 @@ bool CIrcProto::OnIrc_ENDNAMES(const CIrcMessage *pmsg) wi->pszPassword = nullptr; wi->pszTopic = nullptr; wi->codepage = getCodepage(); - Chat_SetUserInfo(m_szModuleName, sChanName, wi); + SetChannelInfo(sChanName, wi); if (!sTopic.IsEmpty() && !mir_wstrcmpi(GetWord(sTopic, 0), sChanName)) { DoEvent(GC_EVENT_TOPIC, sChanName, sTopicName.IsEmpty() ? nullptr : sTopicName.c_str(), GetWordAddress(sTopic, 1), nullptr, sTopicTime.IsEmpty() ? nullptr : sTopicTime.c_str(), NULL, true, false); @@ -1361,17 +1360,17 @@ bool CIrcProto::OnIrc_ENDNAMES(const CIrcMessage *pmsg) save += GetWordAddress(dbv.pwszVal, k); switch (command[0]) { case 'M': - Chat_Control(m_szModuleName, sChanName, WINDOW_HIDDEN); + ::Chat_Control(si, WINDOW_HIDDEN); break; case 'X': - Chat_Control(m_szModuleName, sChanName, WINDOW_VISIBLE); + ::Chat_Control(si, WINDOW_VISIBLE); break; default: - Chat_Control(m_szModuleName, sChanName, SESSION_INITDONE); + ::Chat_Control(si, SESSION_INITDONE); break; } } - else Chat_Control(m_szModuleName, sChanName, SESSION_INITDONE); + else ::Chat_Control(si, SESSION_INITDONE); if (save.IsEmpty()) db_unset(0, m_szModuleName, "JTemp"); @@ -1379,9 +1378,9 @@ bool CIrcProto::OnIrc_ENDNAMES(const CIrcMessage *pmsg) setWString("JTemp", save); db_free(&dbv); } - else Chat_Control(m_szModuleName, sChanName, SESSION_INITDONE); + else ::Chat_Control(si, SESSION_INITDONE); - Chat_Control(m_szModuleName, sChanName, SESSION_ONLINE); + ::Chat_Control(si, SESSION_ONLINE); } } } @@ -1888,7 +1887,7 @@ bool CIrcProto::OnIrc_WHO_END(const CIrcMessage *pmsg) User = GetWord(m_whoReply, 0); } - Chat_SetStatusEx(m_szModuleName, pmsg->parameters[1], GC_SSE_TABDELIMITED, S.IsEmpty() ? nullptr : S.c_str()); + Chat_SetStatusEx(Chat_Find(pmsg->parameters[1], m_szModuleName), GC_SSE_TABDELIMITED, S.IsEmpty() ? nullptr : S.c_str()); return true; } @@ -2278,7 +2277,7 @@ void CIrcProto::OnIrcDisconnected() sDisconn += TranslateT("*Disconnected*"); DoEvent(GC_EVENT_INFORMATION, SERVERWINDOW, nullptr, sDisconn, nullptr, nullptr, NULL, true, false); - Chat_Control(m_szModuleName, nullptr, SESSION_OFFLINE); + setAllContactStatuses(SESSION_OFFLINE, false); if (!Miranda_IsTerminated()) CList_SetAllOffline(m_disconnectDCCChats); @@ -2355,7 +2354,7 @@ bool CIrcProto::DoOnConnect(const CIrcMessage*) } Chat_AddGroup(m_pServer, TranslateT("Normal")); - Chat_Control(m_szModuleName, SERVERWINDOW, SESSION_ONLINE); + Chat_Control(SERVERWINDOW, SESSION_ONLINE); CallFunctionAsync(sttMainThrdOnConnect, this); nickflag = false; diff --git a/protocols/IRCG/src/input.cpp b/protocols/IRCG/src/input.cpp index 51f856bbf5..80c1c1070c 100644 --- a/protocols/IRCG/src/input.cpp +++ b/protocols/IRCG/src/input.cpp @@ -219,7 +219,7 @@ BOOL CIrcProto::DoHardcodedCommand(CMStringW text, wchar_t *window, MCONTACT hCo if (command == L"/servershow" || command == L"/serverhide") { if (m_useServer) - Chat_Control(m_szModuleName, SERVERWINDOW, command == L"/servershow" ? WINDOW_VISIBLE : WINDOW_HIDDEN); + Chat_Control(SERVERWINDOW, command == L"/servershow" ? WINDOW_VISIBLE : WINDOW_HIDDEN); return true; } @@ -245,7 +245,7 @@ BOOL CIrcProto::DoHardcodedCommand(CMStringW text, wchar_t *window, MCONTACT hCo } else S = window; - Chat_Control(m_szModuleName, S, WINDOW_CLEARLOG); + Chat_Control(S, WINDOW_CLEARLOG); return true; } @@ -452,7 +452,7 @@ BOOL CIrcProto::DoHardcodedCommand(CMStringW text, wchar_t *window, MCONTACT hCo PostIrcMessage(L"/PART %s", window); if ((one.IsEmpty() || !IsChannel(one))) { - CHANNELINFO *wi = (CHANNELINFO *)Chat_GetUserInfo(m_szModuleName, window); + auto *wi = GetChannelInfo(window); if (wi && wi->pszPassword) PostIrcMessage(L"/JOIN %s %s", window, wi->pszPassword); else @@ -460,7 +460,7 @@ BOOL CIrcProto::DoHardcodedCommand(CMStringW text, wchar_t *window, MCONTACT hCo return true; } - Chat_Terminate(m_szModuleName, window); + Chat_Terminate(Chat_Find(window, m_szModuleName)); PostIrcMessage(L"/JOIN %s", GetWordAddress(text, 1)); return true; @@ -497,7 +497,7 @@ BOOL CIrcProto::DoHardcodedCommand(CMStringW text, wchar_t *window, MCONTACT hCo CMStringW S = L"/ME " + DoIdentifiers(GetWordAddress(text.c_str(), 1), window); S.Replace(L"%", L"%%"); - Chat_SendUserMessage(m_szModuleName, nullptr, S); + Chat_SendUserMessage(m_szModuleName, S); return true; } @@ -507,7 +507,7 @@ BOOL CIrcProto::DoHardcodedCommand(CMStringW text, wchar_t *window, MCONTACT hCo CMStringW S = DoIdentifiers(GetWordAddress(text.c_str(), 1), window); S.Replace(L"%", L"%%"); - Chat_SendUserMessage(m_szModuleName, nullptr, S); + Chat_SendUserMessage(m_szModuleName, S); return true; } @@ -823,7 +823,7 @@ bool CIrcProto::PostIrcMessageWnd(wchar_t *window, MCONTACT hContact, const wcha if (Message.IsEmpty()) return 0; - CHANNELINFO *wi = (CHANNELINFO *)Chat_GetUserInfo(m_szModuleName, windowname); + auto *wi = GetChannelInfo(windowname); int cp = (wi) ? wi->codepage : getCodepage(); // process the message diff --git a/protocols/IRCG/src/irclib.cpp b/protocols/IRCG/src/irclib.cpp index 6cf422882d..aedbe97af5 100644 --- a/protocols/IRCG/src/irclib.cpp +++ b/protocols/IRCG/src/irclib.cpp @@ -36,23 +36,23 @@ OBJLIST CIrcProto::m_handlers( 30, CompareHandlers ); //////////////////////////////////////////////////////////////////// -CIrcMessage::CIrcMessage( CIrcProto* _pro, const wchar_t* lpszCmdLine, int codepage, bool bIncoming, bool bNotify ) : - m_proto( _pro ), - m_bIncoming( bIncoming ), - m_bNotify( bNotify ), - m_codePage( codepage ), - parameters( 10 ) +CIrcMessage::CIrcMessage(CIrcProto *_pro, const wchar_t *lpszCmdLine, int codepage, bool bIncoming, bool bNotify) : + m_proto(_pro), + m_bIncoming(bIncoming), + m_bNotify(bNotify), + m_codePage(codepage), + parameters(10) { ParseIrcCommand(lpszCmdLine); } -CIrcMessage::CIrcMessage(const CIrcMessage& m) : - sCommand( m.sCommand ), - m_bIncoming( m.m_bIncoming ), - m_bNotify( m.m_bNotify ), - m_codePage( m.m_codePage ), - m_proto( m.m_proto ), - parameters( m.parameters.getCount()) +CIrcMessage::CIrcMessage(const CIrcMessage &m) : + sCommand(m.sCommand), + m_bIncoming(m.m_bIncoming), + m_bNotify(m.m_bNotify), + m_codePage(m.m_codePage), + m_proto(m.m_proto), + parameters(m.parameters.getCount()) { prefix.sNick = m.prefix.sNick; prefix.sUser = m.prefix.sUser; @@ -63,8 +63,7 @@ CIrcMessage::CIrcMessage(const CIrcMessage& m) : } CIrcMessage::~CIrcMessage() -{ -} +{} void CIrcMessage::Reset() { @@ -96,10 +95,10 @@ CIrcMessage& CIrcMessage::operator=(const wchar_t* lpszCmdLine) return *this; } -void CIrcMessage::ParseIrcCommand(const wchar_t* lpszCmdLine) +void CIrcMessage::ParseIrcCommand(const wchar_t *lpszCmdLine) { - const wchar_t* p1 = lpszCmdLine; - const wchar_t* p2 = lpszCmdLine; + const wchar_t *p1 = lpszCmdLine; + const wchar_t *p2 = lpszCmdLine; // prefix exists ? if (*p1 == ':') { @@ -168,18 +167,18 @@ int CIrcProto::getCodepage() const return (con != nullptr) ? codepage : CP_ACP; } -void CIrcProto::SendIrcMessage(const wchar_t* msg, bool bNotify, int cp) +void CIrcProto::SendIrcMessage(const wchar_t *msg, bool bNotify, int cp) { if (cp == -1) cp = getCodepage(); if (this) { - char* str = mir_u2a_cp(msg, cp); + char *str = mir_u2a_cp(msg, cp); rtrim(str); int cbLen = (int)mir_strlen(str); - str = (char*)mir_realloc(str, cbLen + 3); + str = (char *)mir_realloc(str, cbLen + 3); mir_strcat(str, "\r\n"); - NLSend((const uint8_t*)str, cbLen + 2); + NLSend((const uint8_t *)str, cbLen + 2); mir_free(str); if (bNotify) { @@ -190,7 +189,7 @@ void CIrcProto::SendIrcMessage(const wchar_t* msg, bool bNotify, int cp) } } -bool CIrcProto::Connect(const CIrcSessionInfo& info) +bool CIrcProto::Connect(const CIrcSessionInfo &info) { codepage = m_codepage; @@ -268,23 +267,23 @@ void CIrcProto::Disconnect(void) m_info.Reset(); } -void CIrcProto::Notify(const CIrcMessage* pmsg) +void CIrcProto::Notify(const CIrcMessage *pmsg) { OnIrcMessage(pmsg); } -int CIrcProto::NLSend(const unsigned char* buf, int cbBuf) +int CIrcProto::NLSend(const unsigned char *buf, int cbBuf) { if (!con || !buf) return 0; - + if (cbBuf == 0) cbBuf = (int)mir_strlen((const char *)buf); - - return Netlib_Send(con, (const char*)buf, cbBuf, MSG_DUMPASTEXT); + + return Netlib_Send(con, (const char *)buf, cbBuf, MSG_DUMPASTEXT); } -int CIrcProto::NLSend(const wchar_t* fmt, ...) +int CIrcProto::NLSend(const wchar_t *fmt, ...) { va_list marker; va_start(marker, fmt); @@ -293,13 +292,13 @@ int CIrcProto::NLSend(const wchar_t* fmt, ...) mir_vsnwprintf(szBuf, _countof(szBuf), fmt, marker); va_end(marker); - char* buf = mir_u2a_cp(szBuf, getCodepage()); - int result = NLSend((unsigned char*)buf, (int)mir_strlen(buf)); + char *buf = mir_u2a_cp(szBuf, getCodepage()); + int result = NLSend((unsigned char *)buf, (int)mir_strlen(buf)); mir_free(buf); return result; } -int CIrcProto::NLSend(const char* fmt, ...) +int CIrcProto::NLSend(const char *fmt, ...) { va_list marker; va_start(marker, fmt); @@ -308,20 +307,20 @@ int CIrcProto::NLSend(const char* fmt, ...) int cbLen = mir_vsnprintf(szBuf, _countof(szBuf), fmt, marker); va_end(marker); - return NLSend((unsigned char*)szBuf, cbLen); + return NLSend((unsigned char *)szBuf, cbLen); } -int CIrcProto::NLSendNoScript(const unsigned char* buf, int cbBuf) +int CIrcProto::NLSendNoScript(const unsigned char *buf, int cbBuf) { if (con) - return Netlib_Send(con, (const char*)buf, cbBuf, MSG_DUMPASTEXT); + return Netlib_Send(con, (const char *)buf, cbBuf, MSG_DUMPASTEXT); return 0; } -int CIrcProto::NLReceive(unsigned char* buf, int cbBuf) +int CIrcProto::NLReceive(unsigned char *buf, int cbBuf) { - return Netlib_Recv(con, (char*)buf, cbBuf, MSG_DUMPASTEXT); + return Netlib_Recv(con, (char *)buf, cbBuf, MSG_DUMPASTEXT); } void CIrcProto::KillIdent() @@ -333,7 +332,7 @@ void CIrcProto::KillIdent() } } -void CIrcProto::InsertIncomingEvent(wchar_t* pszRaw) +void CIrcProto::InsertIncomingEvent(wchar_t *pszRaw) { CIrcMessage msg(this, pszRaw, true); Notify(&msg); @@ -349,7 +348,7 @@ void CIrcProto::DoReceive() nb.pfnNewConnection = DoIdent; nb.pExtra = this; nb.wPort = m_info.iIdentServerPort; - + hBindPort = Netlib_BindPort(m_hNetlibUser, &nb); if (!hBindPort || nb.wPort != m_info.iIdentServerPort) { debugLogA("Error: unable to bind local port %u", m_info.iIdentServerPort); @@ -360,16 +359,16 @@ void CIrcProto::DoReceive() while (con) { int nLinesProcessed = 0; - int cbRead = NLReceive((unsigned char*)chBuf + cbInBuf, sizeof(chBuf)-cbInBuf - 1); + int cbRead = NLReceive((unsigned char *)chBuf + cbInBuf, sizeof(chBuf) - cbInBuf - 1); if (cbRead <= 0) break; cbInBuf += cbRead; chBuf[cbInBuf] = 0; - char* pStart = chBuf; + char *pStart = chBuf; while (*pStart) { - char* pEnd; + char *pEnd; // seek end-of-line for (pEnd = pStart; *pEnd && *pEnd != '\r' && *pEnd != '\n'; ++pEnd) @@ -388,7 +387,7 @@ void CIrcProto::DoReceive() ptrW ptszMsg; if (codepage != CP_UTF8 && m_utfAutodetect && Utf8CheckString(pStart)) ptszMsg = mir_utf8decodeW(pStart); - + if (ptszMsg == nullptr) ptszMsg = mir_a2u_cp(pStart, codepage); @@ -414,7 +413,7 @@ void CIrcProto::DoReceive() Notify(nullptr); } -void __cdecl CIrcProto::ThreadProc(void*) +void __cdecl CIrcProto::ThreadProc(void *) { Thread_SetName("IRC: CIrcProto"); DoReceive(); @@ -425,14 +424,14 @@ void CIrcProto::AddDCCSession(MCONTACT, CDccSession *dcc) { mir_cslock lck(m_dcc); - CDccSession* p = m_dcc_chats.find(dcc); + CDccSession *p = m_dcc_chats.find(dcc); if (p) m_dcc_chats.remove(p); m_dcc_chats.insert(dcc); } -void CIrcProto::AddDCCSession(DCCINFO*, CDccSession *dcc) +void CIrcProto::AddDCCSession(DCCINFO *, CDccSession *dcc) { mir_cslock lck(m_dcc); m_dcc_xfers.insert(dcc); @@ -461,7 +460,7 @@ void CIrcProto::RemoveDCCSession(DCCINFO *pdci) } } -CDccSession* CIrcProto::FindDCCSession(MCONTACT hContact) +CDccSession *CIrcProto::FindDCCSession(MCONTACT hContact) { mir_cslock lck(m_dcc); @@ -472,7 +471,7 @@ CDccSession* CIrcProto::FindDCCSession(MCONTACT hContact) return nullptr; } -CDccSession* CIrcProto::FindDCCSession(DCCINFO *pdci) +CDccSession *CIrcProto::FindDCCSession(DCCINFO *pdci) { mir_cslock lck(m_dcc); @@ -483,7 +482,7 @@ CDccSession* CIrcProto::FindDCCSession(DCCINFO *pdci) return nullptr; } -CDccSession* CIrcProto::FindDCCSendByPort(int iPort) +CDccSession *CIrcProto::FindDCCSendByPort(int iPort) { mir_cslock lck(m_dcc); @@ -494,7 +493,7 @@ CDccSession* CIrcProto::FindDCCSendByPort(int iPort) return nullptr; } -CDccSession* CIrcProto::FindDCCRecvByPortAndName(int iPort, const wchar_t* szName) +CDccSession *CIrcProto::FindDCCRecvByPortAndName(int iPort, const wchar_t *szName) { mir_cslock lck(m_dcc); @@ -512,7 +511,7 @@ CDccSession* CIrcProto::FindDCCRecvByPortAndName(int iPort, const wchar_t* szNam return nullptr; } -CDccSession* CIrcProto::FindPassiveDCCSend(int iToken) +CDccSession *CIrcProto::FindPassiveDCCSend(int iToken) { mir_cslock lck(m_dcc); @@ -523,7 +522,7 @@ CDccSession* CIrcProto::FindPassiveDCCSend(int iToken) return nullptr; } -CDccSession* CIrcProto::FindPassiveDCCRecv(CMStringW sName, CMStringW sToken) +CDccSession *CIrcProto::FindPassiveDCCRecv(CMStringW sName, CMStringW sToken) { mir_cslock lck(m_dcc); @@ -558,21 +557,18 @@ void CIrcProto::CheckDCCTimeout(void) //////////////////////////////////////////////////////////////////// -CIrcIgnoreItem::CIrcIgnoreItem(const wchar_t* _mask, const wchar_t* _flags) : +CIrcIgnoreItem::CIrcIgnoreItem(const wchar_t *_mask, const wchar_t *_flags) : mask(_mask), flags(_flags) -{ -} +{} -CIrcIgnoreItem::CIrcIgnoreItem(int codepage, const char* _mask, const char* _flags) : - mask((wchar_t*)_A2T(_mask, codepage)), - flags((wchar_t*)_A2T(_flags, codepage)) -{ -} +CIrcIgnoreItem::CIrcIgnoreItem(int codepage, const char *_mask, const char *_flags) : + mask((wchar_t *)_A2T(_mask, codepage)), + flags((wchar_t *)_A2T(_flags, codepage)) +{} CIrcIgnoreItem::~CIrcIgnoreItem() -{ -} +{} //////////////////////////////////////////////////////////////////// @@ -580,10 +576,9 @@ CIrcSessionInfo::CIrcSessionInfo() : iPort(0), bIdentServer(false), iIdentServerPort(0) -{ -} +{} -CIrcSessionInfo::CIrcSessionInfo(const CIrcSessionInfo& si) : +CIrcSessionInfo::CIrcSessionInfo(const CIrcSessionInfo &si) : sServer(si.sServer), sServerName(si.sServerName), iPort(si.iPort), @@ -595,8 +590,7 @@ CIrcSessionInfo::CIrcSessionInfo(const CIrcSessionInfo& si) : m_iSSL(si.m_iSSL), sIdentServerType(si.sIdentServerType), iIdentServerPort(si.iIdentServerPort) -{ -} +{} void CIrcSessionInfo::Reset() { @@ -616,7 +610,7 @@ void CIrcSessionInfo::Reset() //////////////////////////////////////////////////////////////////// -void CIrcProto::OnIrcMessage(const CIrcMessage* pmsg) +void CIrcProto::OnIrcMessage(const CIrcMessage *pmsg) { if (pmsg != nullptr) { PfnIrcMessageHandler pfn = FindMethod(pmsg->sCommand.c_str()); @@ -632,10 +626,10 @@ void CIrcProto::OnIrcMessage(const CIrcMessage* pmsg) else OnIrcDisconnected(); } -PfnIrcMessageHandler CIrcProto::FindMethod(const wchar_t* lpszName) +PfnIrcMessageHandler CIrcProto::FindMethod(const wchar_t *lpszName) { CIrcHandler temp(lpszName, nullptr); - CIrcHandler* p = m_handlers.find(&temp); + CIrcHandler *p = m_handlers.find(&temp); return (p == nullptr) ? nullptr : p->m_handler; } @@ -643,7 +637,7 @@ PfnIrcMessageHandler CIrcProto::FindMethod(const wchar_t* lpszName) #define IPC_ADDR_SIZE 4 /* Size of IP address, change for IPv6. */ -char* ConvertIntegerToIP(unsigned long int_ip_addr) +char *ConvertIntegerToIP(unsigned long int_ip_addr) { IN_ADDR intemp; IN_ADDR in; @@ -657,7 +651,7 @@ char* ConvertIntegerToIP(unsigned long int_ip_addr) return inet_ntoa(in); } -unsigned long ConvertIPToInteger(char* IP) +unsigned long ConvertIPToInteger(char *IP) { IN_ADDR in; IN_ADDR intemp; @@ -677,7 +671,7 @@ unsigned long ConvertIPToInteger(char* IP) //////////////////////////////////////////////////////////////////// // initialize basic stuff needed for the dcc objects, also start a timer for checking the status of connections (timeouts) -CDccSession::CDccSession(CIrcProto* _pro, DCCINFO *pdci) : +CDccSession::CDccSession(CIrcProto *_pro, DCCINFO *pdci) : m_proto(_pro), NewFileName(nullptr), dwWhatNeedsDoing(0), @@ -751,31 +745,31 @@ CDccSession::~CDccSession() // destroy all that needs destroying m_proto->KillChatTimer(m_proto->DCCTimer); // destroy the timer when no dcc objects remain } -int CDccSession::NLSend(const unsigned char* buf, int cbBuf) +int CDccSession::NLSend(const unsigned char *buf, int cbBuf) { tLastActivity = time(0); if (con) - return Netlib_Send(con, (const char*)buf, cbBuf, di->iType == DCC_CHAT ? MSG_DUMPASTEXT : MSG_NODUMP); + return Netlib_Send(con, (const char *)buf, cbBuf, di->iType == DCC_CHAT ? MSG_DUMPASTEXT : MSG_NODUMP); return 0; } -int CDccSession::NLReceive(const unsigned char* buf, int cbBuf) +int CDccSession::NLReceive(const unsigned char *buf, int cbBuf) { int n = 0; if (con) - n = Netlib_Recv(con, (char*)buf, cbBuf, di->iType == DCC_CHAT ? MSG_DUMPASTEXT : MSG_NODUMP); + n = Netlib_Recv(con, (char *)buf, cbBuf, di->iType == DCC_CHAT ? MSG_DUMPASTEXT : MSG_NODUMP); tLastActivity = time(0); return n; } -int CDccSession::SendStuff(const wchar_t* fmt) +int CDccSession::SendStuff(const wchar_t *fmt) { CMStringA buf = _T2A(fmt, m_proto->getCodepage()); - return NLSend((const unsigned char*)buf.c_str(), buf.GetLength()); + return NLSend((const unsigned char *)buf.c_str(), buf.GetLength()); } // called when the user wants to connect/create a new connection given the parameters in the constructor. @@ -797,7 +791,7 @@ void __cdecl CDccSession::ConnectProc(void *pparam) { Thread_SetName("IRC: ConnectProc"); - CDccSession* pThis = (CDccSession*)pparam; + CDccSession *pThis = (CDccSession *)pparam; if (!pThis->con) pThis->SetupConnection(); } @@ -819,11 +813,11 @@ int CDccSession::SetupConnection() // Set up stuff needed for the filetransfer dialog (if it is a filetransfer) if (di->iType == DCC_SEND) { - file[0] = (wchar_t*)di->sFileAndPath.c_str(); + file[0] = (wchar_t *)di->sFileAndPath.c_str(); file[1] = nullptr; - pfts.szCurrentFile.w = (wchar_t*)di->sFileAndPath.c_str(); - pfts.szWorkingDir.w = (wchar_t*)di->sPath.c_str(); + pfts.szCurrentFile.w = (wchar_t *)di->sFileAndPath.c_str(); + pfts.szWorkingDir.w = (wchar_t *)di->sPath.c_str(); pfts.hContact = di->hContact; pfts.flags = PFTS_UNICODE + ((di->bSender) ? PFTS_SENDING : PFTS_RECEIVING); pfts.totalFiles = 1; @@ -841,7 +835,7 @@ int CDccSession::SetupConnection() NETLIBBIND nb = {}; nb.pfnNewConnection = DoIncomingDcc; // this is the (helper) function to be called once an incoming connection is made. The 'real' function that is called is IncomingConnection() nb.pExtra = this; - + hBindPort = Netlib_BindPort(m_proto->hNetlibDCC, &nb); if (hBindPort == nullptr) { delete this; // dcc objects destroy themselves when the connection has been closed or failed for some reasson. @@ -988,7 +982,7 @@ void __cdecl CDccSession::ThreadProc(void *pparam) { Thread_SetName("IRC: CDccSession::ThreadProc"); - CDccSession* pThis = (CDccSession*)pparam; + CDccSession *pThis = (CDccSession *)pparam; // if it is an incoming connection on a listening port, then we should close the listenting port so only one can connect (the one you offered // the connection to) can connect and not evil IRCopers with haxxored IRCDs @@ -1022,7 +1016,7 @@ void CDccSession::DoSendFile() if (wPacketSize > 32 * 1024) wPacketSize = 32 * 1024; - uint8_t* chBuf = new uint8_t[wPacketSize + 1]; + uint8_t *chBuf = new uint8_t[wPacketSize + 1]; // is there a connection? if (con) { @@ -1061,7 +1055,7 @@ void CDccSession::DoSendFile() break; // break out if everything has already been read // send the package - int cbSent = NLSend((unsigned char*)chBuf, iRead); + int cbSent = NLSend((unsigned char *)chBuf, iRead); if (cbSent <= 0) break; // break out if connection is lost or a transmission error has occured @@ -1082,11 +1076,10 @@ void CDccSession::DoSendFile() if (dwRead <= 0) break; // connection closed, or a timeout occurred. - dwPacket = *(uint32_t*)npr.buffer; + dwPacket = *(uint32_t *)npr.buffer; dwLastAck = ntohl(dwPacket); - } - while (con && dwTotal != dwLastAck); + } while (con && dwTotal != dwLastAck); if (!con || dwRead <= 0) goto DCC_STOP; @@ -1102,13 +1095,12 @@ void CDccSession::DoSendFile() if (dwRead <= 0) break; // connection closed, or a timeout occurred. - dwPacket = *(uint32_t*)npr.buffer; + dwPacket = *(uint32_t *)npr.buffer; dwLastAck = ntohl(dwPacket); - } - while (con && (di->dwSize != dwTotal - && dwTotal - dwLastAck >= 100 * 1024 - || di->dwSize == dwTotal // get the last packets when the whole file has been sent - && dwTotal != dwLastAck)); + } while (con && (di->dwSize != dwTotal + && dwTotal - dwLastAck >= 100 * 1024 + || di->dwSize == dwTotal // get the last packets when the whole file has been sent + && dwTotal != dwLastAck)); if (!con || dwRead <= 0) goto DCC_STOP; @@ -1129,7 +1121,7 @@ void CDccSession::DoSendFile() } } - DCC_STOP: +DCC_STOP: // need to close the connection if it isn't allready if (con) { Netlib_CloseHandle(con); @@ -1191,7 +1183,7 @@ void CDccSession::DoReceiveFile() // the while loop will spin around till the connection is dropped, locally or by the remote computer. while (con) { // read - int cbRead = NLReceive((unsigned char*)chBuf, sizeof(chBuf)); + int cbRead = NLReceive((unsigned char *)chBuf, sizeof(chBuf)); if (cbRead <= 0) break; @@ -1257,16 +1249,16 @@ void CDccSession::DoChatReceive() int cbRead; int nLinesProcessed = 0; - cbRead = NLReceive((unsigned char*)chBuf + cbInBuf, sizeof(chBuf)-cbInBuf - 1); + cbRead = NLReceive((unsigned char *)chBuf + cbInBuf, sizeof(chBuf) - cbInBuf - 1); if (cbRead <= 0) break; cbInBuf += cbRead; chBuf[cbInBuf] = 0; - char* pStart = chBuf; + char *pStart = chBuf; while (*pStart) { - char* pEnd; + char *pEnd; // seek end-of-line for (pEnd = pStart; *pEnd && *pEnd != '\r' && *pEnd != '\n'; ++pEnd) @@ -1330,23 +1322,23 @@ VOID CALLBACK DCCTimerProc(HWND, UINT, UINT_PTR idEvent, DWORD) } // helper function for incoming dcc connections. -void DoIncomingDcc(HNETLIBCONN hConnection, uint32_t dwRemoteIP, void * p1) +void DoIncomingDcc(HNETLIBCONN hConnection, uint32_t dwRemoteIP, void *p1) { - CDccSession *dcc = (CDccSession*)p1; + CDccSession *dcc = (CDccSession *)p1; dcc->IncomingConnection(hConnection, dwRemoteIP); } // ident server -void DoIdent(HNETLIBCONN hConnection, uint32_t, void* extra) +void DoIdent(HNETLIBCONN hConnection, uint32_t, void *extra) { - CIrcProto *ppro = (CIrcProto*)extra; + CIrcProto *ppro = (CIrcProto *)extra; char szBuf[1024]; int cbTotal = 0; while (true) { - int cbRead = Netlib_Recv(hConnection, szBuf + cbTotal, sizeof(szBuf)-1 - cbTotal, 0); + int cbRead = Netlib_Recv(hConnection, szBuf + cbTotal, sizeof(szBuf) - 1 - cbTotal, 0); if (cbRead == SOCKET_ERROR || cbRead == 0) break; @@ -1354,7 +1346,7 @@ void DoIdent(HNETLIBCONN hConnection, uint32_t, void* extra) szBuf[cbTotal] = 0; LBL_Parse: - char* EOLPos = strstr(szBuf, "\r\n"); + char *EOLPos = strstr(szBuf, "\r\n"); if (EOLPos == nullptr) continue; @@ -1382,7 +1374,7 @@ LBL_Parse: cbLen = mir_snprintf(buf, "%s : ERROR : INVALID-PORT\r\n", szBuf); } - if (Netlib_Send(hConnection, (const char*)buf, cbLen, 0) > 0) + if (Netlib_Send(hConnection, (const char *)buf, cbLen, 0) > 0) ppro->debugLogA("Sent Ident answer: %s", buf); else ppro->debugLogA("Sending Ident answer failed."); diff --git a/protocols/IRCG/src/irclib.h b/protocols/IRCG/src/irclib.h index fee6eca5a7..07327fee11 100644 --- a/protocols/IRCG/src/irclib.h +++ b/protocols/IRCG/src/irclib.h @@ -74,9 +74,8 @@ public : bool m_bNotify; int m_codePage; - //CIrcMessage( CIrcProto* ); // default constructor - CIrcMessage( CIrcProto*, const wchar_t* lpszCmdLine, int codepage, bool bIncoming=false, bool bNotify = true); // parser constructor - CIrcMessage( const CIrcMessage& m ); // copy constructor + CIrcMessage(CIrcProto *ppro, const wchar_t *lpszCmdLine, int codepage, bool bIncoming = false, bool bNotify = true); // parser constructor + CIrcMessage(const CIrcMessage &m); // copy constructor ~CIrcMessage(); void Reset(); diff --git a/protocols/IRCG/src/ircproto.cpp b/protocols/IRCG/src/ircproto.cpp index 95b233d8dc..77ac527e30 100644 --- a/protocols/IRCG/src/ircproto.cpp +++ b/protocols/IRCG/src/ircproto.cpp @@ -189,9 +189,9 @@ void CIrcProto::OnModulesLoaded() m_pServer = Chat_NewSession(GCW_SERVER, m_szModuleName, SERVERWINDOW, m_tszUserName); if (m_useServer && !m_hideServerWindow) - Chat_Control(m_szModuleName, SERVERWINDOW, WINDOW_VISIBLE); + Chat_Control(SERVERWINDOW, WINDOW_VISIBLE); else - Chat_Control(m_szModuleName, SERVERWINDOW, WINDOW_HIDDEN); + Chat_Control(SERVERWINDOW, WINDOW_HIDDEN); ptrA szNetwork(getStringA("Network")); if (szNetwork) { diff --git a/protocols/IRCG/src/ircproto.h b/protocols/IRCG/src/ircproto.h index 5804e3631a..0e2ee41f68 100644 --- a/protocols/IRCG/src/ircproto.h +++ b/protocols/IRCG/src/ircproto.h @@ -262,23 +262,31 @@ struct CIrcProto : public PROTO void __cdecl DisconnectServerThread(void*); // tools.cpp - void AddToJTemp(wchar_t op, CMStringW& sCommand); - bool AddWindowItemData(CMStringW window, const wchar_t *pszLimit, const wchar_t *pszMode, const wchar_t *pszPassword, const wchar_t *pszTopic); - INT_PTR DoEvent(int iEvent, const wchar_t *pszWindow, const wchar_t *pszNick, const wchar_t *pszText, const wchar_t *pszStatus, const wchar_t *pszUserInfo, DWORD_PTR dwItemData, bool bAddToLog, bool bIsMe, time_t timestamp = 1); - void FindLocalIP(HNETLIBCONN con); - bool FreeWindowItemData(CMStringW window, CHANNELINFO* wis); - bool IsChannel(const char* sName); - bool IsChannel(const wchar_t* sName); - void KillChatTimer(UINT_PTR &nIDEvent); - CMStringW ModeToStatus(int sMode); - CMStringW PrefixToStatus(int cPrefix); - int SetChannelSBText(CMStringW sWindow, CHANNELINFO *wi); - void SetChatTimer(UINT_PTR &nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc); - - void ClearUserhostReasons(int type); - void DoUserhostWithReason(int type, CMStringW reason, bool bSendCommand, const wchar_t *userhostparams, ...); - CMStringW GetNextUserhostReason(int type); - CMStringW PeekAtReasons(int type); + void AddToJTemp(wchar_t op, CMStringW& sCommand); + bool AddWindowItemData(CMStringW window, const wchar_t *pszLimit, const wchar_t *pszMode, const wchar_t *pszPassword, const wchar_t *pszTopic); + INT_PTR DoEvent(int iEvent, const wchar_t *pszWindow, const wchar_t *pszNick, const wchar_t *pszText, const wchar_t *pszStatus, const wchar_t *pszUserInfo, DWORD_PTR dwItemData, bool bAddToLog, bool bIsMe, time_t timestamp = 1); + void FindLocalIP(HNETLIBCONN con); + bool FreeWindowItemData(CMStringW window, CHANNELINFO* wis); + bool IsChannel(const char* sName); + bool IsChannel(const wchar_t* sName); + void KillChatTimer(UINT_PTR &nIDEvent); + CMStringW ModeToStatus(int sMode); + CMStringW PrefixToStatus(int cPrefix); + int SetChannelSBText(CMStringW sWindow, CHANNELINFO *wi); + void SetChatTimer(UINT_PTR &nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc); + + CHANNELINFO *GetChannelInfo(const wchar_t *pwszChatName); + void SetChannelInfo(const wchar_t *pwszChatName, CHANNELINFO *pInfo); + + void ClearUserhostReasons(int type); + void DoUserhostWithReason(int type, CMStringW reason, bool bSendCommand, const wchar_t *userhostparams, ...); + CMStringW GetNextUserhostReason(int type); + CMStringW PeekAtReasons(int type); + + void __forceinline Chat_Control(const wchar_t *pwszChat, int state) + { + ::Chat_Control(Chat_Find(pwszChat, m_szModuleName), state); + } //////////////////////////////////////////////////////////////////////////////////////// // former CIrcSession class diff --git a/protocols/IRCG/src/services.cpp b/protocols/IRCG/src/services.cpp index 0564c7d538..ac585d03b7 100644 --- a/protocols/IRCG/src/services.cpp +++ b/protocols/IRCG/src/services.cpp @@ -180,7 +180,7 @@ void CIrcProto::OnContactDeleted(MCONTACT hContact) S = dbv.pwszVal; if (type == GCW_SERVER) S = SERVERWINDOW; - int i = Chat_Terminate(m_szModuleName, S); + int i = Chat_Terminate(Chat_Find(S, m_szModuleName)); if (i && type == GCW_CHATROOM) PostIrcMessage(L"/PART %s %s", dbv.pwszVal, m_userInfo); } @@ -220,7 +220,7 @@ INT_PTR __cdecl CIrcProto::OnLeaveChat(WPARAM wp, LPARAM) if (!getWString((MCONTACT)wp, "Nick", &dbv)) { if (getByte((MCONTACT)wp, "ChatRoom", 0) == GCW_CHATROOM) { PostIrcMessage(L"/PART %s %s", dbv.pwszVal, m_userInfo); - Chat_Terminate(m_szModuleName, dbv.pwszVal); + Chat_Terminate(Chat_Find(dbv.pwszVal, m_szModuleName)); } db_free(&dbv); } @@ -317,7 +317,7 @@ INT_PTR __cdecl CIrcProto::OnShowListMenuCommand(WPARAM, LPARAM) INT_PTR __cdecl CIrcProto::OnShowServerMenuCommand(WPARAM, LPARAM) { - Chat_Control(m_szModuleName, SERVERWINDOW, WINDOW_VISIBLE); + Chat_Control(SERVERWINDOW, WINDOW_VISIBLE); return 0; } @@ -477,7 +477,7 @@ int __cdecl CIrcProto::GCEventHook(WPARAM, LPARAM lParam) case 3: PostIrcMessage(L"/PART %s %s", p1, m_userInfo); - Chat_Terminate(m_szModuleName, p1); + Chat_Terminate(Chat_Find(p1, m_szModuleName)); break; case 4: // show server window @@ -788,7 +788,7 @@ int __cdecl CIrcProto::GCMenuHook(WPARAM, LPARAM lParam) ulAdr = ConvertIPToInteger(m_IPFromServer ? m_myHost : m_myLocalHost); nickItems[23].bDisabled = ulAdr == 0 ? TRUE : FALSE; // DCC submenu - CHANNELINFO *wi = (CHANNELINFO *)Chat_GetUserInfo(m_szModuleName, gcmi->pszID); + auto *wi = GetChannelInfo(gcmi->pszID); BOOL bServOwner = strchr(sUserModes.c_str(), 'q') == nullptr ? FALSE : TRUE; BOOL bServAdmin = strchr(sUserModes.c_str(), 'a') == nullptr ? FALSE : TRUE; BOOL bOwner = bServOwner ? ((wi->OwnMode >> 4) & 01) : FALSE; @@ -985,7 +985,7 @@ void CIrcProto::DisconnectFromServer(void) if (m_perform && IsConnected()) DoPerform("Event: Disconnect"); - Chat_Terminate(m_szModuleName, nullptr); + Chat_Terminate(m_szModuleName); ForkThread(&CIrcProto::DisconnectServerThread, nullptr); } diff --git a/protocols/IRCG/src/tools.cpp b/protocols/IRCG/src/tools.cpp index b1d3817489..dd0f6d158d 100644 --- a/protocols/IRCG/src/tools.cpp +++ b/protocols/IRCG/src/tools.cpp @@ -21,6 +21,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" +CHANNELINFO *CIrcProto::GetChannelInfo(const wchar_t *pwszChatName) +{ + return (CHANNELINFO *)Chat_GetUserInfo(Chat_Find(pwszChatName, m_szModuleName)); +} + +void CIrcProto::SetChannelInfo(const wchar_t *pwszChatName, CHANNELINFO *pInfo) +{ + Chat_SetUserInfo(Chat_Find(pwszChatName, m_szModuleName), pInfo); +} + ///////////////////////////////////////////////////////////////////////////////////////// void CIrcProto::AddToJTemp(wchar_t op, CMStringW& sCommand) @@ -347,8 +357,8 @@ wchar_t* __stdcall DoColorCodes(const wchar_t *text, bool bStrip, bool bReplaceP return szTemp; } -INT_PTR CIrcProto::DoEvent(int iEvent, const wchar_t* pszWindow, const wchar_t* pszNick, - const wchar_t* pszText, const wchar_t* pszStatus, const wchar_t* pszUserInfo, +INT_PTR CIrcProto::DoEvent(int iEvent, const wchar_t *pszWindow, const wchar_t *pszNick, + const wchar_t *pszText, const wchar_t *pszStatus, const wchar_t *pszUserInfo, DWORD_PTR dwItemData, bool bAddToLog, bool bIsMe, time_t timestamp) { CMStringW sID; @@ -360,12 +370,12 @@ INT_PTR CIrcProto::DoEvent(int iEvent, const wchar_t* pszWindow, const wchar_t* if (pszText) sText = DoColorCodes(pszText, FALSE, TRUE); - GCEVENT gce = { m_szModuleName, nullptr, iEvent }; + GCEVENT gce = { 0, iEvent }; if (pszWindow) { sID = pszWindow; - gce.pszID.w = (wchar_t*)sID.c_str(); + gce.si = Chat_Find(sID.c_str(), m_szModuleName); } - else gce.pszID.w = nullptr; + else gce.si = nullptr; gce.pszStatus.w = pszStatus; gce.dwFlags = (bAddToLog) ? GCEF_ADDTOLOG : 0; @@ -500,7 +510,7 @@ int CIrcProto::SetChannelSBText(CMStringW sWindow, CHANNELINFO *wi) if (wi->pszTopic) sTemp += wi->pszTopic; sTemp = DoColorCodes(sTemp.c_str(), TRUE, FALSE); - Chat_SetStatusbarText(m_szModuleName, sWindow, sTemp); + Chat_SetStatusbarText(Chat_Find(sWindow, m_szModuleName), sTemp); return 0; } @@ -508,7 +518,7 @@ bool CIrcProto::FreeWindowItemData(CMStringW window, CHANNELINFO *wis) { CHANNELINFO *wi; if (!wis) - wi = (CHANNELINFO*)Chat_GetUserInfo(m_szModuleName, window); + wi = GetChannelInfo(window); else wi = wis; if (wi) { @@ -524,7 +534,7 @@ bool CIrcProto::FreeWindowItemData(CMStringW window, CHANNELINFO *wis) bool CIrcProto::AddWindowItemData(CMStringW window, const wchar_t* pszLimit, const wchar_t* pszMode, const wchar_t* pszPassword, const wchar_t* pszTopic) { - CHANNELINFO *wi = (CHANNELINFO *)Chat_GetUserInfo(m_szModuleName, window); + auto *wi = GetChannelInfo(window); if (wi) { if (pszLimit) { wi->pszLimit = (wchar_t*)realloc(wi->pszLimit, sizeof(wchar_t)*(mir_wstrlen(pszLimit) + 1)); diff --git a/protocols/IRCG/src/windows.cpp b/protocols/IRCG/src/windows.cpp index 8a16147cfa..9c3bdafade 100644 --- a/protocols/IRCG/src/windows.cpp +++ b/protocols/IRCG/src/windows.cpp @@ -927,7 +927,7 @@ void CManagerDlg::OnApplyModes(CCtrlButton*) { wchar_t window[256]; GetDlgItemText(m_hwnd, IDC_CAPTION, window, _countof(window)); - CHANNELINFO *wi = (CHANNELINFO*)Chat_GetUserInfo(m_proto->m_szModuleName, window); + auto *wi = m_proto->GetChannelInfo(window); if (wi) { wchar_t toadd[10]; *toadd = 0; wchar_t toremove[10]; *toremove = 0; @@ -1122,7 +1122,7 @@ void CManagerDlg::InitManager(int mode, const wchar_t* window) { SetDlgItemText(m_hwnd, IDC_CAPTION, window); - CHANNELINFO *wi = (CHANNELINFO *)Chat_GetUserInfo(m_proto->m_szModuleName, window); + auto *wi = m_proto->GetChannelInfo(window); if (wi) { if (m_proto->IsConnected()) { wchar_t temp[1000]; diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index 90bf730ac4..6326adf716 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -109,16 +109,16 @@ int JabberGcGetStatus(JABBER_RESOURCE_STATUS *r) return JabberGcGetStatus(r->m_affiliation, r->m_role); } -int CJabberProto::GcInit(JABBER_LIST_ITEM *item) +SESSION_INFO* CJabberProto::GcInit(JABBER_LIST_ITEM *item) { if (item->si) - return 1; + return item->si; Utf2T wszJid(item->jid); ptrA szNick(JabberNickFromJID(item->jid)); SESSION_INFO *si = item->si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszJid, Utf2T(szNick)); if (si == nullptr) - return 2; + return nullptr; item->hContact = si->hContact; @@ -153,15 +153,15 @@ int CJabberProto::GcInit(JABBER_LIST_ITEM *item) for (int i = _countof(sttStatuses) - 1; i >= 0; 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); + Chat_Control(si, (item->bAutoJoin && m_bAutoJoinHidden) ? WINDOW_HIDDEN : SESSION_INITDONE); + Chat_Control(si, SESSION_ONLINE); time_t lastDate = getDword(si->hContact, "LastGetVcard"), now = time(0); if (now - lastDate > 24 * 60 * 60) { SendGetVcard(si->hContact); setDword(si->hContact, "LastGetVcard", now); } - return 0; + return si; } void CJabberProto::GcLogShowInformation(JABBER_LIST_ITEM *item, pResourceStatus &user, TJabberGcLogInfoType type) @@ -226,7 +226,7 @@ void CJabberProto::GcLogShowInformation(JABBER_LIST_ITEM *item, pResourceStatus if (!buf.IsEmpty()) { buf.Replace("%", "%%"); - GCEVENT gce = { m_szModuleName, item->jid, GC_EVENT_INFORMATION }; + GCEVENT gce = { item->si, GC_EVENT_INFORMATION }; gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; gce.pszNick.a = gce.pszUID.a = user->m_szResourceName; gce.pszText.a = buf; @@ -251,7 +251,7 @@ void CJabberProto::GcLogUpdateMemberStatus(JABBER_LIST_ITEM *item, const char *r if (myNick == nullptr) myNick = JabberNickFromJID(m_szJabberJID); - GCEVENT gce = { m_szModuleName, item->jid, 0 }; + GCEVENT gce = { item->si, 0 }; gce.dwFlags = GCEF_UTF8 | ((item->bChatLogging) ? 0 : GCEF_SILENT); gce.pszNick.a = nick; gce.pszUID.a = resource; @@ -292,7 +292,7 @@ void CJabberProto::GcLogUpdateMemberStatus(JABBER_LIST_ITEM *item, const char *r 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, Utf2T(item->jid), flags, Utf2T(nick)); + Chat_SetStatusEx(item->si, flags, Utf2T(nick)); gce.iType = GC_EVENT_SETCONTACTSTATUS; gce.pszText.a = nick; @@ -320,9 +320,9 @@ void CJabberProto::GcQuit(JABBER_LIST_ITEM *item, int code, const TiXmlElement * Utf2T wszRoomJid(item->jid); if (code == 200) - Chat_Terminate(m_szModuleName, wszRoomJid); + Chat_Terminate(item->si); else - Chat_Control(m_szModuleName, wszRoomJid, SESSION_OFFLINE); + Chat_Control(item->si, SESSION_OFFLINE); Contact::Hide(item->hContact, false); item->si = nullptr; diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp index 719144a127..92f774fce6 100644 --- a/protocols/JabberG/src/jabber_groupchat.cpp +++ b/protocols/JabberG/src/jabber_groupchat.cpp @@ -768,11 +768,10 @@ void CJabberProto::RenameParticipantNick(JABBER_LIST_ITEM *item, const char *old setUString(hContact, "MyNick", newNick); } - Chat_ChangeUserId(m_szModuleName, Utf2T(item->jid), Utf2T(oldNick), Utf2T(newNick)); + Chat_ChangeUserId(item->si, Utf2T(oldNick), Utf2T(newNick)); - GCEVENT gce = { m_szModuleName, item->jid, GC_EVENT_NICK }; + GCEVENT gce = { item->si, GC_EVENT_NICK }; gce.dwFlags = GCEF_UTF8; - gce.pszID.a = item->jid; gce.pszUserInfo.a = jid; gce.time = time(0); gce.pszNick.a = oldNick; @@ -1001,7 +1000,7 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node) if (!mir_strcmp(type, "error")) return; - GCEVENT gce = { m_szModuleName, item->jid, 0 }; + GCEVENT gce = {}; gce.dwFlags = GCEF_UTF8; const char *resource = strchr(from, '/'), *msgText; @@ -1056,7 +1055,7 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node) else gce.iType = GC_EVENT_MESSAGE; } - GcInit(item); + gce.si = GcInit(item); time_t msgTime = 0; if (!JabberReadXep203delay(node, msgTime)) { @@ -1095,7 +1094,7 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node) Chat_Event(&gce); if (gce.iType == GC_EVENT_TOPIC) - Chat_SetStatusbarText(m_szModuleName, Utf2T(item->jid), Utf2T(szText)); + Chat_SetStatusbarText(item->si, Utf2T(szText)); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index cf27af0ea8..c2eaba0b3f 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -445,17 +445,18 @@ struct CJabberProto : public PROTO, public IJabberInterface //---- jabber_chat.cpp --------------------------------------------------------------- - int GcInit(JABBER_LIST_ITEM *item); - void GcLogUpdateMemberStatus(JABBER_LIST_ITEM *item, const char *resource, const char *nick, const char *jid, int action, const TiXmlElement *reason, int nStatusCode = -1); - void GcLogShowInformation(JABBER_LIST_ITEM *item, pResourceStatus &user, TJabberGcLogInfoType type); - void GcQuit(JABBER_LIST_ITEM* jid, int code, const TiXmlElement *reason); - - void AdminSet(const char *to, const char *ns, const char *szItem, const char *itemVal, const char *var, const char *varVal); - void AdminGet(const char *to, const char *ns, const char *var, const char *varVal, JABBER_IQ_HANDLER foo, void *pInfo = nullptr); - void AdminSetReason(const char *to, const char *ns, const char *szItem, const char *itemVal, const char *var, const char *varVal, const char *rsn); - void AddMucListItem(JABBER_MUC_JIDLIST_INFO* jidListInfo, const char *str); - void AddMucListItem(JABBER_MUC_JIDLIST_INFO* jidListInfo, const char *str, const char *reason); - void DeleteMucListItem(JABBER_MUC_JIDLIST_INFO* jidListInfo, const char* jid); + SESSION_INFO* GcInit(JABBER_LIST_ITEM *item); + + void GcLogUpdateMemberStatus(JABBER_LIST_ITEM *item, const char *resource, const char *nick, const char *jid, int action, const TiXmlElement *reason, int nStatusCode = -1); + void GcLogShowInformation(JABBER_LIST_ITEM *item, pResourceStatus &user, TJabberGcLogInfoType type); + void GcQuit(JABBER_LIST_ITEM* jid, int code, const TiXmlElement *reason); + + void AdminSet(const char *to, const char *ns, const char *szItem, const char *itemVal, const char *var, const char *varVal); + void AdminGet(const char *to, const char *ns, const char *var, const char *varVal, JABBER_IQ_HANDLER foo, void *pInfo = nullptr); + void AdminSetReason(const char *to, const char *ns, const char *szItem, const char *itemVal, const char *var, const char *varVal, const char *rsn); + void AddMucListItem(JABBER_MUC_JIDLIST_INFO* jidListInfo, const char *str); + void AddMucListItem(JABBER_MUC_JIDLIST_INFO* jidListInfo, const char *str, const char *reason); + void DeleteMucListItem(JABBER_MUC_JIDLIST_INFO* jidListInfo, const char* jid); //---- jabber_console.cpp ------------------------------------------------------------ diff --git a/protocols/MinecraftDynmap/src/chat.cpp b/protocols/MinecraftDynmap/src/chat.cpp index b5bd327d24..e9fe0cba7f 100644 --- a/protocols/MinecraftDynmap/src/chat.cpp +++ b/protocols/MinecraftDynmap/src/chat.cpp @@ -27,7 +27,7 @@ void MinecraftDynmapProto::UpdateChat(const char *name, const char *message, con CMStringA szMessage(message); szMessage.Replace("%", "%%"); - GCEVENT gce = { m_szModuleName, szRoomName, GC_EVENT_MESSAGE }; + GCEVENT gce = {m_si, GC_EVENT_MESSAGE }; gce.dwFlags = GCEF_UTF8; gce.time = timestamp; gce.pszText.a = szMessage.c_str(); @@ -77,7 +77,7 @@ int MinecraftDynmapProto::OnChatEvent(WPARAM, LPARAM lParam) void MinecraftDynmapProto::AddChatContact(const char *name) { - GCEVENT gce = { m_szModuleName, szRoomName, GC_EVENT_JOIN }; + GCEVENT gce = {m_si, GC_EVENT_JOIN }; gce.time = uint32_t(time(0)); gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; gce.pszUID.a = gce.pszNick.a = name; @@ -93,7 +93,7 @@ void MinecraftDynmapProto::AddChatContact(const char *name) void MinecraftDynmapProto::DeleteChatContact(const char *name) { - GCEVENT gce = { m_szModuleName, szRoomName, GC_EVENT_PART }; + GCEVENT gce = {m_si, GC_EVENT_PART }; gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; gce.pszUID.a = gce.pszNick.a = name; gce.time = uint32_t(time(0)); @@ -106,13 +106,13 @@ INT_PTR MinecraftDynmapProto::OnJoinChat(WPARAM,LPARAM suppress) ptrW tszTitle(mir_a2u_cp(m_title.c_str(), CP_UTF8)); // Create the group chat session - SESSION_INFO *si = Chat_NewSession(GCW_PRIVMESS, m_szModuleName, m_tszUserName, tszTitle); - if (!si || m_iStatus == ID_STATUS_OFFLINE) + m_si = Chat_NewSession(GCW_PRIVMESS, m_szModuleName, m_tszUserName, tszTitle); + if (!m_si || m_iStatus == ID_STATUS_OFFLINE) return 0; // Create a group - Chat_AddGroup(si, TranslateT("Admin")); - Chat_AddGroup(si, TranslateT("Normal")); + Chat_AddGroup(m_si, TranslateT("Admin")); + Chat_AddGroup(m_si, TranslateT("Normal")); // Note: Initialization will finish up in SetChatStatus, called separately if (!suppress) @@ -123,7 +123,7 @@ INT_PTR MinecraftDynmapProto::OnJoinChat(WPARAM,LPARAM suppress) void MinecraftDynmapProto::SetTopic(const char *topic) { - GCEVENT gce = { m_szModuleName, szRoomName, GC_EVENT_TOPIC }; + GCEVENT gce = {m_si, GC_EVENT_TOPIC }; gce.dwFlags = GCEF_UTF8; gce.time = ::time(0); gce.pszText.a = topic; @@ -132,8 +132,9 @@ void MinecraftDynmapProto::SetTopic(const char *topic) INT_PTR MinecraftDynmapProto::OnLeaveChat(WPARAM,LPARAM) { - Chat_Control(m_szModuleName, m_tszUserName, SESSION_OFFLINE); - Chat_Terminate(m_szModuleName, m_tszUserName); + Chat_Control(m_si, SESSION_OFFLINE); + Chat_Terminate(m_si); + m_si = nullptr; return 0; } @@ -148,15 +149,15 @@ void MinecraftDynmapProto::SetChatStatus(int status) // Add self contact AddChatContact(m_nick.c_str()); - Chat_Control(m_szModuleName, m_tszUserName, SESSION_INITDONE); - Chat_Control(m_szModuleName, m_tszUserName, SESSION_ONLINE); + Chat_Control(m_si, SESSION_INITDONE); + Chat_Control(m_si, SESSION_ONLINE); } - else Chat_Control(m_szModuleName, m_tszUserName, SESSION_OFFLINE); + else Chat_Control(m_si, SESSION_OFFLINE); } void MinecraftDynmapProto::ClearChat() { - Chat_Control(m_szModuleName, m_tszUserName, WINDOW_CLEARLOG); + Chat_Control(m_si, WINDOW_CLEARLOG); } // TODO: Could this be done better? diff --git a/protocols/MinecraftDynmap/src/proto.cpp b/protocols/MinecraftDynmap/src/proto.cpp index 47c05d5105..f5c780a07a 100644 --- a/protocols/MinecraftDynmap/src/proto.cpp +++ b/protocols/MinecraftDynmap/src/proto.cpp @@ -62,7 +62,6 @@ 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 852edaef74..7cae90dae4 100644 --- a/protocols/MinecraftDynmap/src/proto.h +++ b/protocols/MinecraftDynmap/src/proto.h @@ -24,7 +24,7 @@ along with this program. If not, see . class MinecraftDynmapProto : public PROTO { - ptrA szRoomName; + SESSION_INFO *m_si; public: MinecraftDynmapProto(const char *proto_name, const wchar_t *username); diff --git a/protocols/Omegle/src/chat.cpp b/protocols/Omegle/src/chat.cpp index 484d7b0e34..0cec37e307 100644 --- a/protocols/Omegle/src/chat.cpp +++ b/protocols/Omegle/src/chat.cpp @@ -48,8 +48,7 @@ void OmegleProto::UpdateChat(const wchar_t *name, const wchar_t *message, bool a CMStringW smessage(message); smessage.Replace(L"%", L"%%"); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; - gce.pszID.w = m_tszUserName; + GCEVENT gce = { m_si, GC_EVENT_MESSAGE }; gce.time = ::time(0); gce.pszText.w = smessage.c_str(); @@ -204,8 +203,7 @@ void OmegleProto::SendChatMessage(std::string text) void OmegleProto::AddChatContact(const wchar_t *name) { - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; - gce.pszID.w = m_tszUserName; + GCEVENT gce = { m_si, GC_EVENT_JOIN }; gce.time = uint32_t(time(0)); gce.dwFlags = GCEF_ADDTOLOG; gce.pszNick.w = name; @@ -226,8 +224,7 @@ void OmegleProto::AddChatContact(const wchar_t *name) void OmegleProto::DeleteChatContact(const wchar_t *name) { - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_PART }; - gce.pszID.w = m_tszUserName; + GCEVENT gce = { m_si, GC_EVENT_PART }; gce.dwFlags = GCEF_ADDTOLOG; gce.pszNick.w = name; gce.pszUID.w = gce.pszNick.w; @@ -243,13 +240,13 @@ void OmegleProto::DeleteChatContact(const wchar_t *name) INT_PTR OmegleProto::OnJoinChat(WPARAM, LPARAM suppress) { // Create the group chat session - SESSION_INFO *si = Chat_NewSession(GCW_PRIVMESS, m_szModuleName, m_tszUserName, m_tszUserName); - if (!si || m_iStatus == ID_STATUS_OFFLINE) + m_si = Chat_NewSession(GCW_PRIVMESS, m_szModuleName, m_tszUserName, m_tszUserName); + if (!m_si || m_iStatus == ID_STATUS_OFFLINE) return 0; // Create a group - Chat_AddGroup(si, TranslateT("Admin")); - Chat_AddGroup(si, TranslateT("Normal")); + Chat_AddGroup(m_si, TranslateT("Admin")); + Chat_AddGroup(m_si, TranslateT("Normal")); SetTopic(); @@ -262,8 +259,7 @@ INT_PTR OmegleProto::OnJoinChat(WPARAM, LPARAM suppress) void OmegleProto::SetTopic(const wchar_t *topic) { - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_TOPIC }; - gce.pszID.w = m_tszUserName; + GCEVENT gce = { m_si, GC_EVENT_TOPIC }; gce.time = ::time(0); if (topic == nullptr) @@ -276,8 +272,9 @@ void OmegleProto::SetTopic(const wchar_t *topic) INT_PTR OmegleProto::OnLeaveChat(WPARAM, LPARAM) { - Chat_Control(m_szModuleName, m_tszUserName, SESSION_OFFLINE); - Chat_Terminate(m_szModuleName, m_tszUserName); + Chat_Control(m_si, SESSION_OFFLINE); + Chat_Terminate(m_si); + m_si = nullptr; return 0; } @@ -294,16 +291,16 @@ void OmegleProto::SetChatStatus(int status) // Add self contact AddChatContact(facy.nick_); - Chat_Control(m_szModuleName, m_tszUserName, SESSION_INITDONE); - Chat_Control(m_szModuleName, m_tszUserName, SESSION_ONLINE); + Chat_Control(m_si, SESSION_INITDONE); + Chat_Control(m_si, SESSION_ONLINE); } - else Chat_Control(m_szModuleName, m_tszUserName, SESSION_OFFLINE); + else Chat_Control(m_si, SESSION_OFFLINE); } void OmegleProto::ClearChat() { if (!getByte(OMEGLE_KEY_NO_CLEAR, 0)) - Chat_Control(m_szModuleName, m_tszUserName, WINDOW_CLEARLOG); + Chat_Control(m_si, WINDOW_CLEARLOG); } // TODO: Could this be done better? diff --git a/protocols/Omegle/src/proto.h b/protocols/Omegle/src/proto.h index 839d6ecb25..c1a0c5dcfa 100644 --- a/protocols/Omegle/src/proto.h +++ b/protocols/Omegle/src/proto.h @@ -22,8 +22,10 @@ along with this program. If not, see . #pragma once -class OmegleProto : public PROTO < OmegleProto > +class OmegleProto : public PROTO { + SESSION_INFO *m_si; + public: OmegleProto(const char *proto_name, const wchar_t *username); ~OmegleProto(); diff --git a/protocols/Sametime/src/conference.cpp b/protocols/Sametime/src/conference.cpp index 6d1783958d..4be6b4b9b0 100644 --- a/protocols/Sametime/src/conference.cpp +++ b/protocols/Sametime/src/conference.cpp @@ -120,8 +120,7 @@ void mwServiceConf_conf_opened(mwConference* conf, GList* members) Chat_AddGroup(si, TranslateT("Normal")); // add users - GCEVENT gce = { proto->m_szModuleName, 0, GC_EVENT_JOIN }; - gce.pszID.w = tszConfId; + GCEVENT gce = { si, GC_EVENT_JOIN }; GList *user = members; for (;user; user=user->next) { @@ -132,13 +131,13 @@ void mwServiceConf_conf_opened(mwConference* conf, GList* members) gce.dwFlags = GCEF_ADDTOLOG; 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); + gce.bIsMe = (strcmp(((mwLoginInfo *)user->data)->login_id, proto->my_login_info->login_id) == 0); + Chat_Event(&gce); } // finalize setup (show window) - Chat_Control(proto->m_szModuleName, tszConfId, SESSION_INITDONE); - Chat_Control(proto->m_szModuleName, tszConfId, SESSION_ONLINE); + Chat_Control(si, SESSION_INITDONE); + Chat_Control(si, SESSION_ONLINE); if (conf == proto->my_conference) proto->ClearInviteQueue(); @@ -151,9 +150,9 @@ void mwServiceConf_conf_closed(mwConference* conf, guint32) CSametimeProto* proto = getProtoFromMwConference(conf); proto->debugLogW(L"mwServiceConf_conf_closed() start"); - ptrW tszConfId(mir_utf8decodeW(mwConference_getName(conf))); - Chat_Control(proto->m_szModuleName, tszConfId, SESSION_OFFLINE); - Chat_Terminate(proto->m_szModuleName, tszConfId); + auto *si = Chat_Find(Utf2T(mwConference_getName(conf)), proto->m_szModuleName); + Chat_Control(si, SESSION_OFFLINE); + Chat_Terminate(si); } /** triggered when someone joins the conference */ @@ -182,8 +181,7 @@ void mwServiceConf_on_peer_joined(mwConference* conf, mwLoginInfo *user) ptrW tszUserId(mir_utf8decodeW(user->login_id)); // add user - GCEVENT gce = { proto->m_szModuleName, 0, GC_EVENT_JOIN }; - gce.pszID.w = tszConfId; + GCEVENT gce = { Chat_Find(tszConfId, proto->m_szModuleName), GC_EVENT_JOIN }; gce.dwFlags = GCEF_ADDTOLOG; gce.pszNick.w = tszUserName; gce.pszUID.w = tszUserId; @@ -208,8 +206,7 @@ void mwServiceConf_on_peer_parted(mwConference* conf, mwLoginInfo* user) ptrW tszUserId(mir_utf8decodeW(user->login_id)); // remove user - GCEVENT gce = { proto->m_szModuleName, 0, GC_EVENT_PART }; - gce.pszID.w = tszConfId; + GCEVENT gce = { Chat_Find(tszConfId, proto->m_szModuleName), GC_EVENT_PART }; gce.dwFlags = GCEF_ADDTOLOG; gce.pszNick.w = tszUserName; gce.pszUID.w = tszUserId; @@ -229,8 +226,7 @@ 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, 0, GC_EVENT_MESSAGE }; - gce.pszID.w = tszConfId; + GCEVENT gce = { Chat_Find(tszConfId, proto->m_szModuleName), GC_EVENT_MESSAGE }; gce.dwFlags = GCEF_ADDTOLOG; gce.pszText.w = textT; gce.pszNick.w = tszUserName; @@ -271,7 +267,7 @@ void CSametimeProto::TerminateConference(char* name) conferences = conf = mwServiceConference_getConferences(service_conference); for (;conf;conf = conf->next) if (strcmp(name, mwConference_getName((mwConference*)conf->data)) == 0) - Chat_Terminate(m_szModuleName, ptrW(mir_utf8decodeW(name))); + Chat_Terminate(Chat_Find(ptrW(mir_utf8decodeW(name)), m_szModuleName)); g_list_free(conferences); } diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index 8fcaa6fc31..fabd66162c 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -44,8 +44,8 @@ SESSION_INFO* CSkypeProto::StartChatRoom(const wchar_t *tid, const wchar_t *tnam Chat_AddGroup(si, TranslateT("User")); // Finish initialization - Chat_Control(m_szModuleName, tid, (getBool("HideChats", 1) ? WINDOW_HIDDEN : SESSION_INITDONE)); - Chat_Control(m_szModuleName, tid, SESSION_ONLINE); + Chat_Control(si, (getBool("HideChats", 1) ? WINDOW_HIDDEN : SESSION_INITDONE)); + Chat_Control(si, SESSION_ONLINE); PushRequest(new GetChatInfoRequest(tid)); return si; @@ -191,8 +191,7 @@ int CSkypeProto::OnGroupChatEventHook(WPARAM, LPARAM lParam) if (!mir_wstrcmp(tnick_old, tnick_new)) break; // New nick is same, do nothing - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_NICK }; - gce.pszID.w = si->ptszID; + GCEVENT gce = { si, GC_EVENT_NICK }; gce.dwFlags = GCEF_ADDTOLOG; gce.pszNick.w = tnick_old; gce.bIsMe = IsMe(user_id); @@ -228,8 +227,9 @@ INT_PTR CSkypeProto::OnLeaveChatRoom(WPARAM hContact, LPARAM) if (hContact && IDYES == MessageBox(nullptr, TranslateT("This chat is going to be destroyed forever with all its contents. This action cannot be undone. Are you sure?"), TranslateT("Warning"), MB_YESNO | MB_ICONQUESTION)) { ptrW idT(getWStringA(hContact, SKYPE_SETTINGS_ID)); - Chat_Control(m_szModuleName, idT, SESSION_OFFLINE); - Chat_Terminate(m_szModuleName, idT); + auto *si = Chat_Find(idT, m_szModuleName); + Chat_Control(si, SESSION_OFFLINE); + Chat_Terminate(si); PushRequest(new KickUserRequest(_T2A(idT), m_szSkypename)); @@ -252,7 +252,7 @@ void CSkypeProto::OnChatEvent(const JSONNode &node) int nEmoteOffset = node["skypeemoteoffset"].as_int(); - SESSION_INFO *si = g_chatApi.SM_FindSession(wszChatId, m_szModuleName); + SESSION_INFO *si = Chat_Find(wszChatId, m_szModuleName); if (si == nullptr) { si = StartChatRoom(wszChatId, wszTopic); if (si == nullptr) { @@ -299,10 +299,9 @@ void CSkypeProto::OnChatEvent(const JSONNode &node) if (pRoot) { CMStringW initiator = Utf2T(XmlGetChildText(pRoot, "initiator")); CMStringW value = Utf2T(XmlGetChildText(pRoot, "value")); - Chat_ChangeSessionName(m_szModuleName, wszChatId, value); + Chat_ChangeSessionName(si, value); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_TOPIC }; - gce.pszID.w = wszChatId; + GCEVENT gce = { si, GC_EVENT_TOPIC }; gce.pszUID.w = initiator; gce.pszNick.w = GetSkypeNick(initiator); gce.pszText.w = wszTopic; @@ -324,8 +323,7 @@ void CSkypeProto::OnChatEvent(const JSONNode &node) CMStringW id = Utf2T(UrlToSkypeId(XmlGetChildText(pTarget, "id"))); const char *role = XmlGetChildText(pTarget, "role"); - GCEVENT gce = { m_szModuleName, 0, !mir_strcmpi(role, "Admin") ? GC_EVENT_ADDSTATUS : GC_EVENT_REMOVESTATUS }; - gce.pszID.w = wszChatId; + GCEVENT gce = { si, !mir_strcmpi(role, "Admin") ? GC_EVENT_ADDSTATUS : GC_EVENT_REMOVESTATUS }; gce.dwFlags = GCEF_ADDTOLOG; gce.pszNick.w = id; gce.pszUID.w = id; @@ -361,8 +359,7 @@ void CSkypeProto::AddMessageToChat(SESSION_INFO *si, const wchar_t *from, const { ptrW tnick(GetChatContactNick(si->hContact, from)); - GCEVENT gce = { m_szModuleName, 0, isAction ? GC_EVENT_ACTION : GC_EVENT_MESSAGE }; - gce.pszID.w = si->ptszID; + GCEVENT gce = { si, isAction ? GC_EVENT_ACTION : GC_EVENT_MESSAGE }; gce.bIsMe = IsMe(from); gce.pszNick.w = tnick; gce.time = timestamp; @@ -395,7 +392,7 @@ void CSkypeProto::OnGetChatInfo(NETLIBHTTPREQUEST *response, AsyncHttpRequest*) return; CMStringW wszChatId(UrlToSkypeId(root["messages"].as_mstring())); - auto *si = g_chatApi.SM_FindSession(wszChatId, m_szModuleName); + auto *si = Chat_Find(wszChatId, m_szModuleName); if (si == nullptr) return; @@ -444,8 +441,7 @@ void CSkypeProto::AddChatContact(SESSION_INFO *si, const wchar_t *id, const wcha { ptrW szNick(GetChatContactNick(si->hContact, id)); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; - gce.pszID.w = si->ptszID; + GCEVENT gce = { si, GC_EVENT_JOIN }; gce.dwFlags = GCEF_ADDTOLOG; gce.pszNick.w = szNick; gce.pszUID.w = id; @@ -463,8 +459,7 @@ void CSkypeProto::RemoveChatContact(SESSION_INFO *si, const wchar_t *id, bool is ptrW szNick(GetChatContactNick(si->hContact, id)); ptrW szInitiator(GetChatContactNick(si->hContact, initiator)); - GCEVENT gce = { m_szModuleName, 0, isKick ? GC_EVENT_KICK : GC_EVENT_PART }; - gce.pszID.w = si->ptszID; + GCEVENT gce = { si, isKick ? GC_EVENT_KICK : GC_EVENT_PART }; gce.pszNick.w = szNick; gce.pszUID.w = id; gce.time = time(0); diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index 4de99c709b..29dc9157f2 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -36,7 +36,7 @@ void CSkypeProto::SetChatStatus(MCONTACT hContact, int iStatus) { ptrW tszChatID(getWStringA(hContact, SKYPE_SETTINGS_ID)); if (tszChatID != NULL) - Chat_Control(m_szModuleName, tszChatID, (iStatus == ID_STATUS_OFFLINE) ? SESSION_OFFLINE : SESSION_ONLINE); + Chat_Control(Chat_Find(tszChatID, m_szModuleName), (iStatus == ID_STATUS_OFFLINE) ? SESSION_OFFLINE : SESSION_ONLINE); } MCONTACT CSkypeProto::GetContactFromAuthEvent(MEVENT hEvent) diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index ae72cdb920..0b2a060d03 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -101,7 +101,7 @@ void CSkypeProto::OnGetServerHistory(NETLIBHTTPREQUEST *response, AsyncHttpReque } } else if (userType == 19) { - auto *si = g_chatApi.SM_FindSession(wszChatId, m_szModuleName); + auto *si = Chat_Find(wszChatId, m_szModuleName); if (si == nullptr) return; diff --git a/protocols/Twitter/src/chat.cpp b/protocols/Twitter/src/chat.cpp index 40b344ada0..6a6ba4c214 100644 --- a/protocols/Twitter/src/chat.cpp +++ b/protocols/Twitter/src/chat.cpp @@ -26,7 +26,7 @@ void CTwitterProto::UpdateChat(const twitter_user &update) CMStringA chatText = update.status.text.c_str(); chatText.Replace("%", "%%"); - GCEVENT gce = { m_szModuleName, m_szChatId, GC_EVENT_MESSAGE }; + GCEVENT gce = { m_si, GC_EVENT_MESSAGE }; gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; gce.bIsMe = (update.username.c_str() == m_szUserName); gce.pszUID.a = update.username.c_str(); @@ -75,7 +75,7 @@ int CTwitterProto::OnChatOutgoing(WPARAM, LPARAM lParam) // TODO: remove nick? void CTwitterProto::AddChatContact(const char *name, const char *nick) { - GCEVENT gce = { m_szModuleName, m_szChatId, GC_EVENT_JOIN }; + GCEVENT gce = { m_si, GC_EVENT_JOIN }; gce.dwFlags = GCEF_UTF8; gce.time = uint32_t(time(0)); gce.pszNick.a = nick ? nick : name; @@ -86,7 +86,7 @@ void CTwitterProto::AddChatContact(const char *name, const char *nick) void CTwitterProto::DeleteChatContact(const char *name) { - GCEVENT gce = { m_szModuleName, m_szChatId, GC_EVENT_PART }; + GCEVENT gce = { m_si, GC_EVENT_PART }; gce.dwFlags = GCEF_UTF8; gce.time = uint32_t(time(0)); gce.pszUID.a = gce.pszNick.a = name; @@ -96,12 +96,12 @@ void CTwitterProto::DeleteChatContact(const char *name) INT_PTR CTwitterProto::OnJoinChat(WPARAM, LPARAM suppress) { // ***** Create the group chat session - SESSION_INFO *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, m_tszUserName, m_tszUserName); - if (!si || m_iStatus != ID_STATUS_ONLINE) + m_si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, m_tszUserName, m_tszUserName); + if (!m_si || m_iStatus != ID_STATUS_ONLINE) return 0; // ***** Create a group - Chat_AddGroup(si, TranslateT("Normal")); + Chat_AddGroup(m_si, TranslateT("Normal")); // ***** Hook events HookProtoEvent(ME_GC_EVENT, &CTwitterProto::OnChatOutgoing); @@ -110,16 +110,14 @@ INT_PTR CTwitterProto::OnJoinChat(WPARAM, LPARAM suppress) if (!suppress) SetChatStatus(m_iStatus); - in_chat_ = true; return 0; } INT_PTR CTwitterProto::OnLeaveChat(WPARAM, LPARAM) { - in_chat_ = false; - - Chat_Control(m_szModuleName, m_tszUserName, SESSION_OFFLINE); - Chat_Terminate(m_szModuleName, m_tszUserName); + Chat_Control(m_si, SESSION_OFFLINE); + Chat_Terminate(m_si); + m_si = nullptr; return 0; } @@ -138,8 +136,8 @@ void CTwitterProto::SetChatStatus(int status) // For some reason, I have to send an INITDONE message, even if I'm not actually // initializing the room... - Chat_Control(m_szModuleName, m_tszUserName, SESSION_INITDONE); - Chat_Control(m_szModuleName, m_tszUserName, SESSION_ONLINE); + Chat_Control(m_si, SESSION_INITDONE); + Chat_Control(m_si, SESSION_ONLINE); } - else Chat_Control(m_szModuleName, m_tszUserName, SESSION_OFFLINE); + else Chat_Control(m_si, SESSION_OFFLINE); } diff --git a/protocols/Twitter/src/connection.cpp b/protocols/Twitter/src/connection.cpp index 5e8b88d830..50d9fd6ad0 100644 --- a/protocols/Twitter/src/connection.cpp +++ b/protocols/Twitter/src/connection.cpp @@ -64,7 +64,7 @@ void CTwitterProto::SignOn(void*) } if (NegotiateConnection()) // Could this be? The legendary Go Time?? { - if (!in_chat_ && getByte(TWITTER_KEY_CHATFEED)) + if (!m_si && getByte(TWITTER_KEY_CHATFEED)) OnJoinChat(0, true); setAllContactStatuses(ID_STATUS_ONLINE); @@ -508,7 +508,7 @@ void CTwitterProto::UpdateStatuses(bool pre_read, bool popups, bool tweetToMsg) } for (auto &u : messages.rev_iter()) { - if (!pre_read && in_chat_) + if (!pre_read && m_si) UpdateChat(*u); if (u->username == m_szUserName.c_str()) diff --git a/protocols/Twitter/src/contacts.cpp b/protocols/Twitter/src/contacts.cpp index d17263cccf..dc3b2668ee 100644 --- a/protocols/Twitter/src/contacts.cpp +++ b/protocols/Twitter/src/contacts.cpp @@ -165,7 +165,7 @@ int CTwitterProto::OnContactDeleted(WPARAM wParam, LPARAM) DBVARIANT dbv; if (!getString(hContact, TWITTER_KEY_UN, &dbv)) { - if (in_chat_) + if (m_si) DeleteChatContact(dbv.pszVal); mir_cslock s(twitter_lock_); @@ -242,7 +242,7 @@ MCONTACT CTwitterProto::AddToClientList(const char *name, const char *status) if (hContact) return hContact; - if (in_chat_) + if (m_si) AddChatContact(name); // If not, make a new contact! diff --git a/protocols/Twitter/src/proto.cpp b/protocols/Twitter/src/proto.cpp index ab569e9d5b..3bdb0ee542 100644 --- a/protocols/Twitter/src/proto.cpp +++ b/protocols/Twitter/src/proto.cpp @@ -25,7 +25,6 @@ static volatile LONG g_msgid = 1; CTwitterProto::CTwitterProto(const char *proto_name, const wchar_t *username) : PROTO(proto_name, username), - m_szChatId(mir_utf8encodeW(username)), m_arChatMarks(10, NumericKeySortT) { CreateProtoService(PS_CREATEACCMGRUI, &CTwitterProto::SvcCreateAccMgrUI); @@ -346,11 +345,11 @@ void CTwitterProto::SendTweetWorker(void *p) void CTwitterProto::UpdateSettings() { if (getByte(TWITTER_KEY_CHATFEED)) { - if (!in_chat_) + if (!m_si) OnJoinChat(0, 0); } else { - if (in_chat_) + if (m_si) OnLeaveChat(0, 0); for (MCONTACT hContact = db_find_first(m_szModuleName); hContact;) { diff --git a/protocols/Twitter/src/proto.h b/protocols/Twitter/src/proto.h index 69fca0130a..6868386c29 100644 --- a/protocols/Twitter/src/proto.h +++ b/protocols/Twitter/src/proto.h @@ -58,7 +58,7 @@ struct CChatMark class CTwitterProto : public PROTO { - ptrA m_szChatId; + SESSION_INFO *m_si; http::response request_token(); http::response request_access_tokens(); @@ -99,8 +99,6 @@ class CTwitterProto : public PROTO twitter_id since_id_; twitter_id dm_since_id_; - bool in_chat_; - int disconnectionCount; // OAuthWebRequest used for all OAuth related queries diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index 1af5f49964..f4c9dd1353 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -35,7 +35,6 @@ CVkChatInfo* CVkProto::AppendConversationChat(int iChatId, const JSONNode& jnIte if (iChatId == 0) return nullptr; - const JSONNode& jnConversation = jnItem ? jnItem["conversation"] : nullNode; const JSONNode& jnLastMessage = jnItem ? jnItem["last_message"] : nullNode; const JSONNode& jnChatSettings = jnConversation ? jnConversation["chat_settings"] : nullNode; @@ -53,7 +52,6 @@ CVkChatInfo* CVkProto::AppendConversationChat(int iChatId, const JSONNode& jnIte if (hChatContact && getBool(hChatContact, "kicked")) return nullptr; - CVkChatInfo* vkChatInfo = m_chats.find((CVkChatInfo*)&iChatId); if (vkChatInfo != nullptr) return vkChatInfo; @@ -68,8 +66,6 @@ CVkChatInfo* CVkProto::AppendConversationChat(int iChatId, const JSONNode& jnIte CMStringW sid; sid.Format(L"%d", iChatId); - vkChatInfo->m_wszId = mir_wstrdup(sid); - SESSION_INFO* si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, sid, wszTitle); if (si == nullptr) { @@ -77,7 +73,7 @@ CVkChatInfo* CVkProto::AppendConversationChat(int iChatId, const JSONNode& jnIte return nullptr; } - vkChatInfo->m_hContact = si->hContact; + vkChatInfo->m_si = si; setWString(si->hContact, "Nick", wszTitle); m_chats.insert(vkChatInfo); @@ -97,8 +93,8 @@ CVkChatInfo* CVkProto::AppendConversationChat(int iChatId, const JSONNode& jnIte return nullptr; } - Chat_Control(m_szModuleName, sid, (m_vkOptions.bHideChats) ? WINDOW_HIDDEN : SESSION_INITDONE); - Chat_Control(m_szModuleName, sid, SESSION_ONLINE); + Chat_Control(si, (m_vkOptions.bHideChats) ? WINDOW_HIDDEN : SESSION_INITDONE); + Chat_Control(si, SESSION_ONLINE); RetrieveChatInfo(vkChatInfo); @@ -139,7 +135,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe SetChatTitle(cc, jnInfo["title"].as_mstring()); if (jnInfo["left"].as_bool() || jnInfo["kicked"].as_bool()) { - setByte(cc->m_hContact, "kicked", jnInfo["kicked"].as_bool()); + setByte(cc->m_si->hContact, "kicked", jnInfo["kicked"].as_bool()); LeaveChat(cc->m_iChatId); return; } @@ -178,7 +174,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe bNew = cu->m_bUnknown; cu->m_bDel = false; - CMStringW wszNick(ptrW(db_get_wsa(cc->m_hContact, m_szModuleName, CMStringA(FORMAT, "nick%d", cu->m_uid)))); + CMStringW wszNick(ptrW(db_get_wsa(cc->m_si->hContact, m_szModuleName, CMStringA(FORMAT, "nick%d", cu->m_uid)))); if (wszNick.IsEmpty()) wszNick = bIsGroup ? jnUser["name"].as_mstring() : @@ -189,8 +185,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe cu->m_bUnknown = false; if (bNew) { - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN }; - gce.pszID.w = cc->m_wszId; + GCEVENT gce = { cc->m_si, GC_EVENT_JOIN }; gce.bIsMe = uid == m_myUserId; gce.pszUID.w = wszId; gce.pszNick.w = wszNick; @@ -208,8 +203,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe _itow(cu->m_uid, wszId, 10); CMStringW wszNick(FORMAT, L"%s (%s)", cu->m_wszNick.get(), UserProfileUrl(cu->m_uid).c_str()); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_PART }; - gce.pszID.w = cc->m_wszId; + GCEVENT gce = { cc->m_si, GC_EVENT_PART }; gce.pszUID.w = wszId; gce.dwFlags = GCEF_NOTNOTIFY; gce.time = time(0); @@ -267,9 +261,9 @@ void CVkProto::SetChatTitle(CVkChatInfo *cc, LPCWSTR wszTopic) return; cc->m_wszTopic = mir_wstrdup(wszTopic); - setWString(cc->m_hContact, "Nick", wszTopic); + setWString(cc->m_si->hContact, "Nick", wszTopic); - Chat_ChangeSessionName(m_szModuleName, cc->m_wszId, wszTopic); + Chat_ChangeSessionName(cc->m_si, wszTopic); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -423,7 +417,7 @@ void CVkProto::AppendChatMessage(CVkChatInfo *cc, LONG uid, int msgTime, LPCWSTR CVkChatUser *cu = cc->m_users.find((CVkChatUser*)&uid); if (cu == nullptr) { cc->m_users.insert(cu = new CVkChatUser(uid)); - CMStringW wszNick(ptrW(db_get_wsa(cc->m_hContact, m_szModuleName, CMStringA(FORMAT, "nick%d", cu->m_uid)))); + CMStringW wszNick(ptrW(db_get_wsa(cc->m_si->hContact, m_szModuleName, CMStringA(FORMAT, "nick%d", cu->m_uid)))); cu->m_wszNick = mir_wstrdup(wszNick.IsEmpty() ? (hContact ? ptrW(db_get_wsa(hContact, m_szModuleName, "Nick")) : TranslateT("Unknown")) : wszNick); cu->m_bUnknown = true; } @@ -431,8 +425,7 @@ void CVkProto::AppendChatMessage(CVkChatInfo *cc, LONG uid, int msgTime, LPCWSTR wchar_t wszId[20]; _itow(uid, wszId, 10); - GCEVENT gce = { m_szModuleName, 0, bIsAction ? GC_EVENT_ACTION : GC_EVENT_MESSAGE }; - gce.pszID.w = cc->m_wszId; + GCEVENT gce = { cc->m_si, bIsAction ? GC_EVENT_ACTION : GC_EVENT_MESSAGE }; gce.bIsMe = (uid == m_myUserId); gce.pszUID.w = wszId; gce.time = msgTime; @@ -462,7 +455,7 @@ CVkChatInfo* CVkProto::GetChatByContact(MCONTACT hContact) CVkChatInfo* CVkProto::GetChatById(LPCWSTR pwszId) { for (auto &it : m_chats) - if (!mir_wstrcmp(it->m_wszId, pwszId)) + if (!mir_wstrcmp(it->m_si->ptszID, pwszId)) return it; return nullptr; @@ -474,7 +467,7 @@ void CVkProto::SetChatStatus(MCONTACT hContact, int iStatus) { CVkChatInfo *cc = GetChatByContact(hContact); if (cc != nullptr) - Chat_Control(m_szModuleName, cc->m_wszId, (iStatus == ID_STATUS_OFFLINE) ? SESSION_OFFLINE : SESSION_ONLINE); + Chat_Control(cc->m_si, (iStatus == ID_STATUS_OFFLINE) ? SESSION_OFFLINE : SESSION_ONLINE); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -498,7 +491,7 @@ int CVkProto::OnChatEvent(WPARAM, LPARAM lParam) ptrW pwszBuf(mir_wstrdup(gch->ptszText)); rtrimw(pwszBuf); Chat_UnescapeTags(pwszBuf); - SendMsg(cc->m_hContact, 0, T2Utf(pwszBuf)); + SendMsg(cc->m_si->hContact, 0, T2Utf(pwszBuf)); } break; @@ -648,14 +641,14 @@ void CVkProto::LeaveChat(int chat_id, bool close_window, bool delete_chat) return; if (close_window) - Chat_Terminate(m_szModuleName, cc->m_wszId); + Chat_Terminate(m_szModuleName, cc->m_si->ptszID); else - Chat_Control(m_szModuleName, cc->m_wszId, SESSION_OFFLINE); + Chat_Control(cc->m_si, SESSION_OFFLINE); if (delete_chat) - DeleteContact(cc->m_hContact); + DeleteContact(cc->m_si->hContact); else - setByte(cc->m_hContact, "off", (int)true); + setByte(cc->m_si->hContact, "off", (int)true); m_chats.remove(cc); } @@ -688,7 +681,7 @@ void CVkProto::KickFromChat(int chat_id, LONG user_id, const JSONNode &jnMsg, co AppendChatConversationMessage(chat_id, jnMsg, jnFUsers, false); MsgPopup(hContact, msg, TranslateT("Chat")); - setByte(cc->m_hContact, "kicked", 1); + setByte(cc->m_si->hContact, "kicked", 1); LeaveChat(chat_id); } @@ -776,8 +769,7 @@ void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch) wchar_t wszId[20]; _itow(cu->m_uid, wszId, 10); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_NICK }; - gce.pszID.w = cc->m_wszId; + GCEVENT gce = { cc->m_si, GC_EVENT_NICK }; gce.pszNick.w = mir_wstrdup(cu->m_wszNick); gce.bIsMe = (cu->m_uid == m_myUserId); gce.pszUID.w = wszId; @@ -787,7 +779,7 @@ void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch) Chat_Event(&gce); cu->m_wszNick = mir_wstrdup(wszNewNick); - setWString(cc->m_hContact, CMStringA(FORMAT, "nick%d", cu->m_uid), wszNewNick); + setWString(cc->m_si->hContact, CMStringA(FORMAT, "nick%d", cu->m_uid), wszNewNick); } break; diff --git a/protocols/VKontakte/src/vk_struct.h b/protocols/VKontakte/src/vk_struct.h index f6b1da600d..b9be280032 100644 --- a/protocols/VKontakte/src/vk_struct.h +++ b/protocols/VKontakte/src/vk_struct.h @@ -119,16 +119,13 @@ struct CVkChatInfo : public MZeroedObject CVkChatInfo(int _id) : m_users(10, NumericKeySortT), m_msgs(10, NumericKeySortT), - m_iChatId(_id), - m_iAdminId(0), - m_bHistoryRead(0), - m_hContact(INVALID_CONTACT_ID) + m_iChatId(_id) {} - int m_iChatId, m_iAdminId; - bool m_bHistoryRead; - ptrW m_wszTopic, m_wszId; - MCONTACT m_hContact; + int m_iChatId, m_iAdminId = 0; + bool m_bHistoryRead = false; + ptrW m_wszTopic; + SESSION_INFO *m_si = nullptr; OBJLIST m_users; OBJLIST m_msgs; diff --git a/protocols/WhatsApp/src/appsync.cpp b/protocols/WhatsApp/src/appsync.cpp index 9607045131..3d812be370 100644 --- a/protocols/WhatsApp/src/appsync.cpp +++ b/protocols/WhatsApp/src/appsync.cpp @@ -115,7 +115,7 @@ void WhatsAppProto::OnIqServerSync(const WANode &node) if (dwVersion > pCollection->version) { pCollection->hash.init(); debugLogA("%s: applying snapshot of version %d", pCollection->szName.get(), dwVersion); - for (int i=0; i < snapshot->n_records; i++) + for (unsigned i = 0; i < snapshot->n_records; i++) ParsePatch(pCollection, snapshot->records[i], true); } else debugLogA("%s: skipping snapshot of version %d", pCollection->szName.get(), dwVersion); @@ -132,7 +132,7 @@ void WhatsAppProto::OnIqServerSync(const WANode &node) dwVersion = patch->version->version; if (dwVersion > pCollection->version) { debugLogA("%s: applying patch of version %d", pCollection->szName.get(), dwVersion); - for (int i = 0; i < patch->n_mutations; i++) { + for (unsigned i = 0; i < patch->n_mutations; i++) { auto &jt = *patch->mutations[i]; ParsePatch(pCollection, jt.record, jt.operation == WA__SYNCD_MUTATION__SYNCD_OPERATION__SET); } @@ -255,11 +255,11 @@ void WhatsAppProto::ProcessHistorySync(const Wa__HistorySync *pSync) switch (pSync->synctype) { case WA__HISTORY_SYNC__HISTORY_SYNC_TYPE__INITIAL_BOOTSTRAP: case WA__HISTORY_SYNC__HISTORY_SYNC_TYPE__RECENT: - for (int i = 0; i < pSync->n_conversations; i++) { + for (unsigned i = 0; i < pSync->n_conversations; i++) { auto *pChat = pSync->conversations[i]; auto *pUser = AddUser(pChat->id, false); - for (int j = 0; j < pChat->n_messages; j++) { + for (unsigned j = 0; j < pChat->n_messages; j++) { auto *pMessage = pChat->messages[j]; if (!pMessage->message) continue; @@ -287,9 +287,8 @@ void WhatsAppProto::ProcessHistorySync(const Wa__HistorySync *pSync) if (pChat->name) setUString(pUser->hContact, "Nick", pChat->name); - GCEVENT gce = {m_szModuleName, 0, GC_EVENT_MESSAGE}; + GCEVENT gce = { pUser->si, GC_EVENT_MESSAGE }; gce.dwFlags = GCEF_UTF8; - gce.pszID.a = pUser->szId; gce.pszUID.a = key->participant; gce.bIsMe = key->fromme; gce.pszText.a = szMessageText.GetBuffer(); @@ -305,7 +304,7 @@ void WhatsAppProto::ProcessHistorySync(const Wa__HistorySync *pSync) break; case WA__HISTORY_SYNC__HISTORY_SYNC_TYPE__PUSH_NAME: - for (int i = 0; i < pSync->n_pushnames; i++) { + for (unsigned i = 0; i < pSync->n_pushnames; i++) { auto *pName = pSync->pushnames[i]; if (auto *pUser = AddUser(pName->id, false)) setUString(pUser->hContact, "Nick", pName->pushname); @@ -313,7 +312,7 @@ void WhatsAppProto::ProcessHistorySync(const Wa__HistorySync *pSync) break; case WA__HISTORY_SYNC__HISTORY_SYNC_TYPE__INITIAL_STATUS_V3: - for (int i = 0; i < pSync->n_statusv3messages; i++) { + for (unsigned i = 0; i < pSync->n_statusv3messages; i++) { // TODO // auto *pStatus = pSync->statusv3messages[i]; } diff --git a/protocols/WhatsApp/src/chats.cpp b/protocols/WhatsApp/src/chats.cpp index b0423e5b20..f783c5f567 100644 --- a/protocols/WhatsApp/src/chats.cpp +++ b/protocols/WhatsApp/src/chats.cpp @@ -44,12 +44,12 @@ void WhatsAppProto::GC_ParseMetadata(const WANode *pGroup) CMStringW wszId(Utf2T(pChatUser->szId)); - pChatUser->si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszId, getMStringW(pChatUser->hContact, "Nick")); + auto *si = pChatUser->si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszId, getMStringW(pChatUser->hContact, "Nick")); - Chat_AddGroup(pChatUser->si, TranslateT("Owner")); - Chat_AddGroup(pChatUser->si, TranslateT("SuperAdmin")); - Chat_AddGroup(pChatUser->si, TranslateT("Admin")); - Chat_AddGroup(pChatUser->si, TranslateT("Participant")); + Chat_AddGroup(si, TranslateT("Owner")); + Chat_AddGroup(si, TranslateT("SuperAdmin")); + Chat_AddGroup(si, TranslateT("Admin")); + Chat_AddGroup(si, TranslateT("Participant")); CMStringA szOwner(pGroup->getAttr("creator")), szNick, szRole; @@ -57,9 +57,8 @@ void WhatsAppProto::GC_ParseMetadata(const WANode *pGroup) if (it->title == "description") { CMStringA szDescr = it->getBody(); if (!szDescr.IsEmpty()) { - GCEVENT gce = {m_szModuleName, 0, GC_EVENT_INFORMATION}; + GCEVENT gce = { si, GC_EVENT_INFORMATION }; gce.dwFlags = GCEF_UTF8; - gce.pszID.a = pChatUser->szId; gce.pszText.a = szDescr.c_str(); Chat_Event(&gce); } @@ -75,9 +74,8 @@ void WhatsAppProto::GC_ParseMetadata(const WANode *pGroup) if (role == nullptr) role = szRole; - GCEVENT gce = {m_szModuleName, 0, GC_EVENT_JOIN}; + GCEVENT gce = { si, GC_EVENT_JOIN }; gce.dwFlags = GCEF_UTF8; - gce.pszID.a = pChatUser->szId; gce.pszUID.a = jid; gce.bIsMe = (jid == m_szJid); @@ -112,9 +110,8 @@ void WhatsAppProto::GC_ParseMetadata(const WANode *pGroup) else szNick = WAJid(pszUser).user; - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_TOPIC }; + GCEVENT gce = { si, GC_EVENT_TOPIC }; gce.dwFlags = GCEF_UTF8; - gce.pszID.a = pChatUser->szId; gce.pszUID.a = pszUser; gce.pszText.a = pszSubject; gce.time = iSubjectTime; @@ -124,8 +121,8 @@ void WhatsAppProto::GC_ParseMetadata(const WANode *pGroup) } pChatUser->bInited = true; - Chat_Control(m_szModuleName, wszId, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); - Chat_Control(m_szModuleName, wszId, SESSION_ONLINE); + Chat_Control(si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); + Chat_Control(si, SESSION_ONLINE); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/WhatsApp/src/message.cpp b/protocols/WhatsApp/src/message.cpp index 250a63e4d1..c0efdd3ea1 100644 --- a/protocols/WhatsApp/src/message.cpp +++ b/protocols/WhatsApp/src/message.cpp @@ -223,9 +223,8 @@ void WhatsAppProto::ProcessMessage(WAMSG type, const Wa__WebMessageInfo &msg) ProtoChainRecvMsg(pUser->hContact, &pre); if (pUser->bIsGroupChat) { - GCEVENT gce = {m_szModuleName, 0, GC_EVENT_MESSAGE}; + GCEVENT gce = { pUser->si, GC_EVENT_MESSAGE }; gce.dwFlags = GCEF_UTF8; - gce.pszID.a = pUser->szId; gce.pszUID.a = participant; gce.bIsMe = key->fromme; gce.pszText.a = szMessageText.GetBuffer(); diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h index 9e7a7f731f..b8580e1b51 100644 --- a/src/mir_app/src/chat.h +++ b/src/mir_app/src/chat.h @@ -66,20 +66,20 @@ char* Log_SetStyle(int style); MODULEINFO* MM_AddModule(const char *pszModule); MODULEINFO* MM_FindModule(const char *pszModule); -BOOL SM_AddEvent(const wchar_t *pszID, const char *pszModule, GCEVENT *gce, bool bIsHighlighted); -BOOL SM_ChangeNick(const wchar_t *pszID, const char *pszModule, GCEVENT *gce); +BOOL SM_AddEvent(SESSION_INFO *si, GCEVENT *gce, bool bIsHighlighted); +BOOL SM_ChangeNick(SESSION_INFO *si, GCEVENT *gce); char* SM_GetUsers(SESSION_INFO *si); -BOOL SM_GiveStatus(const wchar_t *pszID, const char *pszModule, const wchar_t *pszUID, const wchar_t *pszStatus); +BOOL SM_GiveStatus(SESSION_INFO *si, const wchar_t *pszUID, const wchar_t *pszStatus); void SM_RemoveAll(void); -int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, bool removeContact); -BOOL SM_RemoveUser(const wchar_t *pszID, const char *pszModule, const wchar_t *pszUID); -BOOL SM_SetContactStatus(const wchar_t *pszID, const char *pszModule, const wchar_t *pszUID, uint16_t wStatus); +int SM_RemoveModule(const char *pszModule, bool removeContact); +int SM_RemoveSession(SESSION_INFO *si, bool removeContact); +BOOL SM_RemoveUser(SESSION_INFO *si, const wchar_t *pszUID); +BOOL SM_SetContactStatus(SESSION_INFO *si, const wchar_t *pszUID, uint16_t wStatus); BOOL SM_SetOffline(const char *pszModule, SESSION_INFO *si); BOOL SM_SetStatus(const char *pszModule, SESSION_INFO *si, int wStatus); -BOOL SM_TakeStatus(const wchar_t *pszID, const char *pszModule, const wchar_t *pszUID, const wchar_t *pszStatus); +BOOL SM_TakeStatus(SESSION_INFO *si, const wchar_t *pszUID, const wchar_t *pszStatus); BOOL SM_UserTyping(GCEVENT* gce); -SESSION_INFO* SM_FindSession(const wchar_t *pszID, const char *pszModule); SESSION_INFO* SM_FindSessionByIndex(const char *pszModule, int iItem); STATUSINFO* TM_AddStatus(STATUSINFO **ppStatusList, const wchar_t *pszStatus, int *iCount); diff --git a/src/mir_app/src/chat_clist.cpp b/src/mir_app/src/chat_clist.cpp index 85b56632c7..3981986acd 100644 --- a/src/mir_app/src/chat_clist.cpp +++ b/src/mir_app/src/chat_clist.cpp @@ -127,7 +127,7 @@ int RoomDoubleclicked(WPARAM hContact, LPARAM) if (roomid == nullptr) return 0; - SESSION_INFO *si = SM_FindSession(roomid, szProto); + SESSION_INFO *si = Chat_Find(roomid, szProto); if (si) { if (si->pDlg != nullptr && !g_clistApi.pfnGetEvent(hContact, 0) && IsWindowVisible(si->pDlg->GetHwnd()) && !IsIconic(si->pDlg->GetHwnd())) { si->pDlg->CloseTab(); diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index 39d2ea158c..608e1bedac 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -67,7 +67,7 @@ static void SetActiveSession(SESSION_INFO *si) static SESSION_INFO* GetActiveSession(void) { - SESSION_INFO *si = SM_FindSession(g_chatApi.szActiveWndID, g_chatApi.szActiveWndModule); + SESSION_INFO *si = Chat_Find(g_chatApi.szActiveWndID, g_chatApi.szActiveWndModule); if (si) return si; @@ -220,21 +220,11 @@ static void SM_FreeSession(SESSION_INFO *si, bool bRemoveContact = false) delete si; } -int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, bool removeContact) +int SM_RemoveModule(const char *pszModule, bool removeContact) { if (pszModule == nullptr) return FALSE; - if (pszID != nullptr) { - SESSION_INFO *si = SM_FindSession(pszID, pszModule); - if (si == nullptr) - return FALSE; - - g_arSessions.remove(si); - SM_FreeSession(si, removeContact); - return TRUE; - } - auto T = g_arSessions.rev_iter(); for (auto &si : T) { if (si->iType != GCW_SERVER && !mir_strcmpi(si->pszModule, pszModule)) { @@ -242,10 +232,21 @@ int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, bool removeCon g_arSessions.removeItem(&si); } } + + return TRUE; +} + +int SM_RemoveSession(SESSION_INFO *si, bool removeContact) +{ + if (si == nullptr) + return FALSE; + + g_arSessions.remove(si); + SM_FreeSession(si, removeContact); return TRUE; } -SESSION_INFO* SM_FindSession(const wchar_t *pszID, const char *pszModule) +MIR_APP_DLL(SESSION_INFO*) Chat_Find(const wchar_t *pszID, const char *pszModule) { if (!pszID || !pszModule) return nullptr; @@ -293,9 +294,8 @@ static HICON SM_GetStatusIcon(SESSION_INFO *si, USERINFO *ui) return g_chatApi.hStatusIcons[0]; } -BOOL SM_AddEvent(const wchar_t *pszID, const char *pszModule, GCEVENT *gce, bool bIsHighlighted) +BOOL SM_AddEvent(SESSION_INFO *si, GCEVENT *gce, bool bIsHighlighted) { - SESSION_INFO *si = SM_FindSession(pszID, pszModule); if (si == nullptr) return TRUE; @@ -321,13 +321,13 @@ BOOL SM_AddEvent(const wchar_t *pszID, const char *pszModule, GCEVENT *gce, bool return TRUE; } -BOOL SM_RemoveUser(const wchar_t *pszID, const char *pszModule, const wchar_t *pszUID) +BOOL SM_RemoveUser(SESSION_INFO *pSI, const wchar_t *pszUID) { - if (!pszModule || !pszUID) + if (!pSI || !pszUID) return FALSE; for (auto &si : g_arSessions) { - if ((pszID && mir_wstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule)) + if (si != pSI || mir_strcmpi(si->pszModule, pSI->pszModule)) continue; USERINFO *ui = UM_FindUser(si, pszUID); @@ -342,7 +342,7 @@ BOOL SM_RemoveUser(const wchar_t *pszID, const char *pszModule, const wchar_t *p if (si->pDlg) si->pDlg->UpdateNickList(); - if (pszID) + // !!!!!!!!!! if (pszID) return TRUE; } } @@ -352,13 +352,12 @@ BOOL SM_RemoveUser(const wchar_t *pszID, const char *pszModule, const wchar_t *p static USERINFO* SM_GetUserFromIndex(const wchar_t *pszID, const char *pszModule, int index) { - SESSION_INFO *si = SM_FindSession(pszID, pszModule); + SESSION_INFO *si = Chat_Find(pszID, pszModule); return (si == nullptr) ? nullptr : g_chatApi.UM_FindUserFromIndex(si, index); } -BOOL SM_GiveStatus(const wchar_t *pszID, const char *pszModule, const wchar_t *pszUID, const wchar_t *pszStatus) +BOOL SM_GiveStatus(SESSION_INFO *si, const wchar_t *pszUID, const wchar_t *pszStatus) { - SESSION_INFO *si = SM_FindSession(pszID, pszModule); if (si == nullptr) return FALSE; @@ -371,9 +370,8 @@ BOOL SM_GiveStatus(const wchar_t *pszID, const char *pszModule, const wchar_t *p return TRUE; } -BOOL SM_SetContactStatus(const wchar_t *pszID, const char *pszModule, const wchar_t *pszUID, uint16_t wStatus) +BOOL SM_SetContactStatus(SESSION_INFO *si, const wchar_t *pszUID, uint16_t wStatus) { - SESSION_INFO *si = SM_FindSession(pszID, pszModule); if (si == nullptr) return FALSE; @@ -386,9 +384,8 @@ BOOL SM_SetContactStatus(const wchar_t *pszID, const char *pszModule, const wcha return TRUE; } -BOOL SM_TakeStatus(const wchar_t *pszID, const char *pszModule, const wchar_t *pszUID, const wchar_t *pszStatus) +BOOL SM_TakeStatus(SESSION_INFO *si, const wchar_t *pszUID, const wchar_t *pszStatus) { - SESSION_INFO *si = SM_FindSession(pszID, pszModule); if (si == nullptr) return FALSE; @@ -426,7 +423,7 @@ BOOL SM_SetStatus(const char *pszModule, SESSION_INFO *si, int wStatus) BOOL SM_UserTyping(GCEVENT *gce) { - SESSION_INFO *si = SM_FindSession(gce->pszID.w, gce->pszModule); + SESSION_INFO *si = gce->si; if (si == nullptr || si->pDlg == nullptr) return FALSE; @@ -438,27 +435,21 @@ BOOL SM_UserTyping(GCEVENT *gce) return TRUE; } -BOOL SM_ChangeNick(const wchar_t *pszID, const char *pszModule, GCEVENT *gce) +BOOL SM_ChangeNick(SESSION_INFO *si, GCEVENT *gce) { - if (!pszModule) + if (!si) return FALSE; - for (auto &si : g_arSessions) { - if ((!pszID || !mir_wstrcmpi(si->ptszID, pszID)) && !mir_strcmpi(si->pszModule, pszModule)) { - USERINFO *ui = UM_FindUser(si, gce->pszUID.w); - if (ui) { - replaceStrW(ui->pszNick, gce->pszText.w); - UM_SortUser(si); - if (si->pDlg) - si->pDlg->UpdateNickList(); - if (g_chatApi.OnChangeNick) - g_chatApi.OnChangeNick(si); - } - - if (pszID) - return TRUE; - } + USERINFO *ui = UM_FindUser(si, gce->pszUID.w); + if (ui) { + replaceStrW(ui->pszNick, gce->pszText.w); + UM_SortUser(si); + if (si->pDlg) + si->pDlg->UpdateNickList(); + if (g_chatApi.OnChangeNick) + g_chatApi.OnChangeNick(si); } + return TRUE; } @@ -905,7 +896,6 @@ static void ResetApi() g_chatApi.SetActiveSession = ::SetActiveSession; g_chatApi.GetActiveSession = ::GetActiveSession; g_chatApi.SM_CreateSession = ::SM_CreateSession; - g_chatApi.SM_FindSession = ::SM_FindSession; g_chatApi.SM_GetStatusIcon = ::SM_GetStatusIcon; g_chatApi.SM_GetCount = ::SM_GetCount; g_chatApi.SM_FindSessionByIndex = ::SM_FindSessionByIndex; diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp index 4544f8f550..d4462ec3d2 100644 --- a/src/mir_app/src/chat_svc.cpp +++ b/src/mir_app/src/chat_svc.cpp @@ -146,7 +146,7 @@ static int SmileyOptionsChanged(WPARAM, LPARAM) ///////////////////////////////////////////////////////////////////////////////////////// // retrieveing chat info -EXTERN_C MIR_APP_DLL(int) Chat_GetInfo(GC_INFO *gci) +MIR_APP_DLL(int) Chat_GetInfo(GC_INFO *gci) { if (!gci || !gci->pszModule) return 1; @@ -155,7 +155,7 @@ EXTERN_C MIR_APP_DLL(int) Chat_GetInfo(GC_INFO *gci) if (gci->Flags & GCF_BYINDEX) si = SM_FindSessionByIndex(gci->pszModule, gci->iItem); else - si = SM_FindSession(gci->pszID, gci->pszModule); + si = Chat_Find(gci->pszID, gci->pszModule); if (si == nullptr) return 1; @@ -201,7 +201,7 @@ MIR_APP_DLL(int) Chat_Register(const GCREGISTER *gcr) ///////////////////////////////////////////////////////////////////////////////////////// // starts new chat session -EXTERN_C MIR_APP_DLL(SESSION_INFO*) Chat_NewSession( +MIR_APP_DLL(SESSION_INFO*) Chat_NewSession( int iType, // Use one of the GCW_* flags above to set the type of session const char *pszModule, // The name of the protocol owning the session (the same as pszModule when you register) const wchar_t *ptszID, // The unique identifier for the session. @@ -214,7 +214,7 @@ EXTERN_C MIR_APP_DLL(SESSION_INFO*) Chat_NewSession( return nullptr; // try to restart a session first - SESSION_INFO *si = SM_FindSession(ptszID, pszModule); + SESSION_INFO *si = Chat_Find(ptszID, pszModule); if (si != nullptr) { UM_RemoveAll(si); g_chatApi.TM_RemoveAll(&si->pStatuses); @@ -268,8 +268,7 @@ EXTERN_C MIR_APP_DLL(SESSION_INFO*) Chat_NewSession( struct ChatConrolParam { - const char *szModule; - const wchar_t *wszId; + SESSION_INFO *si; int command; }; @@ -289,35 +288,26 @@ static INT_PTR __stdcall stubRoomControl(void *param) ChatConrolParam *p = (ChatConrolParam*)param; mir_cslock lck(csChat); - SESSION_INFO *si = nullptr; - if (p->szModule) - si = SM_FindSession(p->wszId, p->szModule); + SESSION_INFO *si = g_arSessions.find(p->si); + if (si == nullptr) + return GC_EVENT_ERROR; switch (p->command) { case WINDOW_HIDDEN: - if (si == nullptr) - return GC_EVENT_ERROR; - SetInitDone(si); g_chatApi.SetActiveSession(si); break; case WINDOW_VISIBLE: case SESSION_INITDONE: - if (si == nullptr) - return GC_EVENT_ERROR; - SetInitDone(si); if (p->command != SESSION_INITDONE || !Chat::bPopupOnJoin) g_chatApi.ShowRoom(si); break; case SESSION_OFFLINE: - if (si == nullptr && p->wszId != nullptr) - return GC_EVENT_ERROR; - - SM_SetOffline(p->szModule, si); - SM_SetStatus(p->szModule, si, ID_STATUS_OFFLINE); + SM_SetOffline(si->pszModule, si); + SM_SetStatus(si->pszModule, si, ID_STATUS_OFFLINE); if (si && si->pDlg) { si->pDlg->UpdateStatusBar(); si->pDlg->UpdateNickList(); @@ -325,18 +315,12 @@ static INT_PTR __stdcall stubRoomControl(void *param) break; case SESSION_ONLINE: - if (si == nullptr && p->wszId != nullptr) - return GC_EVENT_ERROR; - - SM_SetStatus(p->szModule, si, ID_STATUS_ONLINE); + SM_SetStatus(si->pszModule, si, ID_STATUS_ONLINE); if (si && si->pDlg) si->pDlg->UpdateStatusBar(); break; case WINDOW_CLEARLOG: - if (si == nullptr) - return GC_EVENT_ERROR; - g_chatApi.LM_RemoveAll(&si->pLog, &si->pLogEnd); si->iEventCount = 0; si->LastTime = 0; @@ -351,9 +335,9 @@ static INT_PTR __stdcall stubRoomControl(void *param) return 0; } -MIR_APP_DLL(int) Chat_Control(const char *szModule, const wchar_t *wszId, int iCommand) +MIR_APP_DLL(int) Chat_Control(SESSION_INFO *si, int iCommand) { - ChatConrolParam param = { szModule, wszId, iCommand }; + ChatConrolParam param = { si, iCommand }; return CallFunctionSync(stubRoomControl, ¶m); } @@ -362,20 +346,31 @@ MIR_APP_DLL(int) Chat_Control(const char *szModule, const wchar_t *wszId, int iC struct ChatTerminateParam { - const char *szModule; - const wchar_t *wszId; + const char *pszModule; + SESSION_INFO *si; bool bRemoveContact; }; static INT_PTR __stdcall stubRoomTerminate(void *param) { ChatTerminateParam *p = (ChatTerminateParam*)param; - return SM_RemoveSession(p->wszId, p->szModule, p->bRemoveContact); + if (p->si) + return SM_RemoveSession(p->si, p->bRemoveContact); + return SM_RemoveModule(p->pszModule, p->bRemoveContact); +} + +MIR_APP_DLL(int) Chat_Terminate(const char *szModule, bool bRemoveContact) +{ + ChatTerminateParam param = { szModule, 0, bRemoveContact }; + return CallFunctionSync(stubRoomTerminate, ¶m); } -MIR_APP_DLL(int) Chat_Terminate(const char *szModule, const wchar_t *wszId, bool bRemoveContact) +MIR_APP_DLL(int) Chat_Terminate(SESSION_INFO *si, bool bRemoveContact) { - ChatTerminateParam param = { szModule, wszId, bRemoveContact }; + if (!g_arSessions.find(si)) + return GC_EVENT_ERROR; + + ChatTerminateParam param = { 0, si, bRemoveContact }; return CallFunctionSync(stubRoomTerminate, ¶m); } @@ -384,7 +379,7 @@ 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->pszID.w, gce->pszModule); + SESSION_INFO *si = gce->si; if (si == nullptr) return; @@ -414,7 +409,7 @@ static BOOL AddEventToAllMatchingUID(GCEVENT *gce) int bManyFix = 0; for (auto &si : g_arSessions) { - if (!si->bInitDone || mir_strcmpi(si->pszModule, gce->pszModule)) + if (!si->bInitDone || mir_strcmpi(si->pszModule, gce->si->pszModule)) continue; if (!g_chatApi.UM_FindUser(si, gce->pszUID.w)) @@ -424,7 +419,7 @@ static BOOL AddEventToAllMatchingUID(GCEVENT *gce) g_chatApi.OnEventBroadcast(si, gce); if (si->pDlg && si->bInitDone) { - if (SM_AddEvent(si->ptszID, si->pszModule, gce, FALSE)) + if (SM_AddEvent(si, gce, FALSE)) si->pDlg->AddLog(); else RedrawLog2(si); @@ -447,7 +442,6 @@ static INT_PTR CALLBACK sttEventStub(void *_param) GCEVENT gce = *(GCEVENT*)_param; if (gce.dwFlags & GCEF_UTF8) { - gce.pszID.w = (wszId = mir_utf8decodeW(gce.pszID.a)); gce.pszUID.w = (wszUid = mir_utf8decodeW(gce.pszUID.a)); gce.pszNick.w = (wszNick = mir_utf8decodeW(gce.pszNick.a)); gce.pszText.w = (wszText = mir_utf8decodeW(gce.pszText.a)); @@ -464,10 +458,10 @@ 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.pszID.w, gce.pszModule, gce.pszUID.w, (uint16_t)gce.dwItemData); + return SM_SetContactStatus(gce.si, gce.pszUID.w, (uint16_t)gce.dwItemData); case GC_EVENT_TOPIC: - if (SESSION_INFO *si = SM_FindSession(gce.pszID.w, gce.pszModule)) { + if (SESSION_INFO *si = gce.si) { wchar_t *pwszNew = RemoveFormatting(gce.pszText.w); if (!mir_wstrcmp(si->ptszTopic, pwszNew)) // nothing changed? exiting return 0; @@ -491,25 +485,24 @@ static INT_PTR CALLBACK sttEventStub(void *_param) break; case GC_EVENT_ADDSTATUS: - SM_GiveStatus(gce.pszID.w, gce.pszModule, gce.pszUID.w, gce.pszStatus.w); + SM_GiveStatus(gce.si, gce.pszUID.w, gce.pszStatus.w); bIsHighlighted = g_chatApi.IsHighlighted(nullptr, &gce); break; case GC_EVENT_REMOVESTATUS: - SM_TakeStatus(gce.pszID.w, gce.pszModule, gce.pszUID.w, gce.pszStatus.w); + SM_TakeStatus(gce.si, 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.pszID.w && gce.pszText.w) { - SESSION_INFO *si = SM_FindSession(gce.pszID.w, gce.pszModule); - bIsHighlighted = g_chatApi.IsHighlighted(si, &gce); + if (!gce.bIsMe && gce.si && gce.pszText.w) { + bIsHighlighted = g_chatApi.IsHighlighted(gce.si, &gce); } break; case GC_EVENT_NICK: - SM_ChangeNick(gce.pszID.w, gce.pszModule, &gce); + SM_ChangeNick(gce.si, &gce); bIsHighlighted = g_chatApi.IsHighlighted(nullptr, &gce); break; @@ -530,19 +523,14 @@ static INT_PTR CALLBACK sttEventStub(void *_param) } // Decide which window (log) should have the event - LPCTSTR pWnd = nullptr; - LPCSTR pMod = nullptr; - if (gce.pszID.w) { - pWnd = gce.pszID.w; - pMod = gce.pszModule; + SESSION_INFO *si = nullptr; + if (gce.si) { + si = gce.si; } else if (gce.iType == GC_EVENT_NOTICE || gce.iType == GC_EVENT_INFORMATION) { - SESSION_INFO *si = g_chatApi.GetActiveSession(); - if (si && !mir_strcmp(si->pszModule, gce.pszModule)) { - pWnd = si->ptszID; - pMod = si->pszModule; - } - else return 0; + si = g_chatApi.GetActiveSession(); + if (!si) + return 0; } else { // Send the event to all windows with a user pszUID. Used for broadcasting QUIT etc @@ -552,12 +540,10 @@ static INT_PTR CALLBACK sttEventStub(void *_param) } // add to log - if (pWnd) { + if (si) { if (gce.dwFlags & GCEF_SILENT) return 0; - SESSION_INFO *si = SM_FindSession(pWnd, pMod); - // fix for IRC's old style mode notifications. Should not affect any other protocol if ((gce.iType == GC_EVENT_ADDSTATUS || gce.iType == GC_EVENT_REMOVESTATUS) && !(gce.dwFlags & GCEF_ADDTOLOG)) return 0; @@ -572,7 +558,7 @@ static INT_PTR CALLBACK sttEventStub(void *_param) gce.pszNick.w = ui->pszNick; } - int isOk = SM_AddEvent(pWnd, pMod, &gce, bIsHighlighted); + int isOk = SM_AddEvent(si, &gce, bIsHighlighted); if (si->pDlg) { if (isOk) si->pDlg->AddLog(); @@ -592,12 +578,12 @@ static INT_PTR CALLBACK sttEventStub(void *_param) } if (bRemoveFlag) - return SM_RemoveUser(gce.pszID.w, gce.pszModule, gce.pszUID.w) == 0; + return SM_RemoveUser(gce.si, gce.pszUID.w) == 0; return GC_EVENT_ERROR; } -EXTERN_C MIR_APP_DLL(int) Chat_Event(GCEVENT *gce) +MIR_APP_DLL(int) Chat_Event(GCEVENT *gce) { if (gce == nullptr) return GC_EVENT_ERROR; @@ -628,65 +614,59 @@ MIR_APP_DLL(int) Chat_AddGroup(SESSION_INFO *si, const wchar_t *wszText) return 0; } -MIR_APP_DLL(int) Chat_ChangeSessionName(const char *szModule, const wchar_t *wszId, const wchar_t *wszNewName) +MIR_APP_DLL(int) Chat_ChangeSessionName(SESSION_INFO *si, const wchar_t *wszNewName) { - if (wszNewName == nullptr) + if (wszNewName == nullptr || si == nullptr) return GC_EVENT_ERROR; - SESSION_INFO *si = SM_FindSession(wszId, szModule); - if (si != nullptr) { - // nothing really changed? exiting - if (!mir_wstrcmp(si->ptszName, wszNewName)) - return 0; + // nothing really changed? exiting + if (!mir_wstrcmp(si->ptszName, wszNewName)) + return 0; - replaceStrW(si->ptszName, wszNewName); - db_set_ws(si->hContact, szModule, "Nick", wszNewName); - if (si->pDlg) - si->pDlg->UpdateTitle(); - } + replaceStrW(si->ptszName, wszNewName); + db_set_ws(si->hContact, si->pszModule, "Nick", wszNewName); + if (si->pDlg) + si->pDlg->UpdateTitle(); return 0; } -MIR_APP_DLL(int) Chat_ChangeUserId(const char *szModule, const wchar_t *wszId, const wchar_t *wszOldId, const wchar_t *wszNewId) +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Chat_ChangeUserId(const char *szModule, const wchar_t *wszOldId, const wchar_t *wszNewId) { if (szModule == nullptr || wszNewId == nullptr) return GC_EVENT_ERROR; - + mir_cslock lck(csChat); - for (auto &si : g_arSessions) { - if ((wszId && mir_wstrcmpi(si->ptszID, wszId)) || mir_strcmpi(si->pszModule, szModule)) - continue; + for (auto &si : g_arSessions) + if (!mir_strcmpi(si->pszModule, szModule)) + Chat_ChangeUserId(si, wszOldId, wszNewId); - USERINFO *ui = g_chatApi.UM_FindUser(si, wszOldId); - if (ui) { - replaceStrW(ui->pszUID, wszNewId); - UM_SortKeys(si); - } - if (wszId) - break; - } return 0; } -MIR_APP_DLL(void*) Chat_GetUserInfo(const char *szModule, const wchar_t *wszId) +MIR_APP_DLL(int) Chat_ChangeUserId(SESSION_INFO *si, const wchar_t *wszOldId, const wchar_t *wszNewId) { - if (SESSION_INFO *si = SM_FindSession(wszId, szModule)) - return si->pItemData; - return nullptr; + if (wszNewId == nullptr) + return GC_EVENT_ERROR; + + USERINFO *ui = g_chatApi.UM_FindUser(si, wszOldId); + if (ui) { + replaceStrW(ui->pszUID, wszNewId); + UM_SortKeys(si); + } + return 0; } -MIR_APP_DLL(int) Chat_SendUserMessage(const char *szModule, const wchar_t *wszId, const wchar_t *wszText) +MIR_APP_DLL(void*) Chat_GetUserInfo(SESSION_INFO *si) { - if (wszText == nullptr || szModule == nullptr) - return GC_EVENT_ERROR; + return (si) ? si->pItemData : nullptr; +} - if (wszId != nullptr) { - SESSION_INFO *si = SM_FindSession(wszId, szModule); - if (si) - if (si->iType == GCW_CHATROOM || si->iType == GCW_PRIVMESS) - Chat_DoEventHook(si, GC_USER_MESSAGE, nullptr, wszText, 0); - return 0; - } +MIR_APP_DLL(int) Chat_SendUserMessage(const char *szModule, const wchar_t *wszText) +{ + if (!szModule) + return 1; mir_cslock lck(csChat); for (auto &si : g_arSessions) { @@ -699,9 +679,18 @@ MIR_APP_DLL(int) Chat_SendUserMessage(const char *szModule, const wchar_t *wszId return 0; } -MIR_APP_DLL(int) Chat_SetStatusbarText(const char *szModule, const wchar_t *wszId, const wchar_t *wszText) +MIR_APP_DLL(int) Chat_SendUserMessage(SESSION_INFO *si, const wchar_t *wszText) +{ + if (wszText == nullptr || si == nullptr) + return GC_EVENT_ERROR; + + if (si->iType == GCW_CHATROOM || si->iType == GCW_PRIVMESS) + Chat_DoEventHook(si, GC_USER_MESSAGE, nullptr, wszText, 0); + return 0; +} + +MIR_APP_DLL(int) Chat_SetStatusbarText(SESSION_INFO *si, const wchar_t *wszText) { - SESSION_INFO *si = SM_FindSession(wszId, szModule); if (si != nullptr) { replaceStrW(si->ptszStatusbarText, wszText); if (si->ptszStatusbarText) @@ -715,28 +704,33 @@ MIR_APP_DLL(int) Chat_SetStatusbarText(const char *szModule, const wchar_t *wszI return 0; } -MIR_APP_DLL(int) Chat_SetStatusEx(const char *szModule, const wchar_t *wszId, int flags, const wchar_t *wszText) +MIR_APP_DLL(int) Chat_SetStatusEx(SESSION_INFO *si, int flags, const wchar_t *wszText) { - if (!szModule) + if (!si) return GC_EVENT_ERROR; + UM_SetStatusEx(si, wszText, flags); + if (si->pDlg) + RedrawWindow(GetDlgItem(si->pDlg->GetHwnd(), IDC_LIST), nullptr, nullptr, RDW_INVALIDATE); + return 0; +} + +MIR_APP_DLL(int) Chat_SetStatusEx(const char *szModule, int flags, const wchar_t *wszText) +{ + if (!szModule) + return 1; + mir_cslock lck(csChat); - for (auto &si : g_arSessions) { - if ((wszId && mir_wstrcmpi(si->ptszID, wszId)) || mir_strcmpi(si->pszModule, szModule)) - continue; + for (auto &si : g_arSessions) + if (!mir_strcmpi(si->pszModule, szModule)) + Chat_SetStatusEx(si, flags, wszText); - UM_SetStatusEx(si, wszText, flags); - if (si->pDlg) - RedrawWindow(GetDlgItem(si->pDlg->GetHwnd(), IDC_LIST), nullptr, nullptr, RDW_INVALIDATE); - if (wszId) - break; - } return 0; } -MIR_APP_DLL(int) Chat_SetUserInfo(const char *szModule, const wchar_t *wszId, void *pItemData) +MIR_APP_DLL(int) Chat_SetUserInfo(SESSION_INFO *si, void *pItemData) { - if (SESSION_INFO *si = g_chatApi.SM_FindSession(wszId, szModule)) { + if (si) { si->pItemData = pItemData; return 0; } diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index cc94a44a7c..bae7600aec 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -219,20 +219,6 @@ Chat_GetDefaultEventDescr @295 FindDatabasePlugin @296 RegisterDatabasePlugin @298 Chat_CustomizeApi @299 -Chat_Event @300 -Chat_GetInfo @301 -Chat_NewSession @302 -Chat_Register @303 -Chat_GetUserInfo @304 -Chat_SetUserInfo @305 -Chat_ChangeUserId @306 -Chat_ChangeSessionName @307 -Chat_SetStatusbarText @308 -Chat_SendUserMessage @309 -Chat_SetStatusEx @310 -Chat_Terminate @311 -Chat_AddGroup @312 -Chat_Control @313 Clist_FindItem @314 Colour_Get @315 Colour_GetW @316 @@ -811,3 +797,22 @@ Srmm_CreateHotkey @886 NONAME ?getBlob@PROTO_INTERFACE@@QAE?AVMBinBuffer@@PBD@Z @912 NONAME ?UpdateEventId@MDatabaseReadonly@@UAGHIPBD@Z @913 NONAME ?GetAvatarPath@PROTO_INTERFACE@@QBE?AV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@XZ @914 NONAME +?Chat_AddGroup@@YGHPAUSESSION_INFO@@PB_W@Z @915 NONAME +?Chat_ChangeSessionName@@YGHPAUSESSION_INFO@@PB_W@Z @916 NONAME +?Chat_ChangeUserId@@YGHPAUSESSION_INFO@@PB_W1@Z @917 NONAME +?Chat_ChangeUserId@@YGHPBDPB_W1@Z @918 NONAME +?Chat_Control@@YGHPAUSESSION_INFO@@H@Z @919 NONAME +?Chat_Event@@YGHPAUGCEVENT@@@Z @920 NONAME +?Chat_Find@@YGPAUSESSION_INFO@@PB_WPBD@Z @921 NONAME +?Chat_GetInfo@@YGHPAUGC_INFO@@@Z @922 NONAME +?Chat_GetUserInfo@@YGPAXPAUSESSION_INFO@@@Z @923 NONAME +?Chat_NewSession@@YGPAUSESSION_INFO@@HPBDPB_W1PAX@Z @924 NONAME +?Chat_Register@@YGHPBUGCREGISTER@@@Z @925 NONAME +?Chat_SendUserMessage@@YGHPAUSESSION_INFO@@PB_W@Z @926 NONAME +?Chat_SendUserMessage@@YGHPBDPB_W@Z @927 NONAME +?Chat_SetStatusEx@@YGHPAUSESSION_INFO@@HPB_W@Z @928 NONAME +?Chat_SetStatusEx@@YGHPBDHPB_W@Z @929 NONAME +?Chat_SetStatusbarText@@YGHPAUSESSION_INFO@@PB_W@Z @930 NONAME +?Chat_SetUserInfo@@YGHPAUSESSION_INFO@@PAX@Z @931 NONAME +?Chat_Terminate@@YGHPAUSESSION_INFO@@_N@Z @932 NONAME +?Chat_Terminate@@YGHPBD_N@Z @933 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 23413c088a..20cdf0907d 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -219,20 +219,6 @@ Chat_GetDefaultEventDescr @295 FindDatabasePlugin @296 RegisterDatabasePlugin @298 Chat_CustomizeApi @299 -Chat_Event @300 -Chat_GetInfo @301 -Chat_NewSession @302 -Chat_Register @303 -Chat_GetUserInfo @304 -Chat_SetUserInfo @305 -Chat_ChangeUserId @306 -Chat_ChangeSessionName @307 -Chat_SetStatusbarText @308 -Chat_SendUserMessage @309 -Chat_SetStatusEx @310 -Chat_Terminate @311 -Chat_AddGroup @312 -Chat_Control @313 Clist_FindItem @314 Colour_Get @315 Colour_GetW @316 @@ -811,3 +797,22 @@ Srmm_CreateHotkey @886 NONAME ?getBlob@PROTO_INTERFACE@@QEAA?AVMBinBuffer@@PEBD@Z @912 NONAME ?UpdateEventId@MDatabaseReadonly@@UEAAHIPEBD@Z @913 NONAME ?GetAvatarPath@PROTO_INTERFACE@@QEBA?AV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@XZ @914 NONAME +?Chat_AddGroup@@YAHPEAUSESSION_INFO@@PEB_W@Z @915 NONAME +?Chat_ChangeSessionName@@YAHPEAUSESSION_INFO@@PEB_W@Z @916 NONAME +?Chat_ChangeUserId@@YAHPEAUSESSION_INFO@@PEB_W1@Z @917 NONAME +?Chat_ChangeUserId@@YAHPEBDPEB_W1@Z @918 NONAME +?Chat_Control@@YAHPEAUSESSION_INFO@@H@Z @919 NONAME +?Chat_Event@@YAHPEAUGCEVENT@@@Z @920 NONAME +?Chat_Find@@YAPEAUSESSION_INFO@@PEB_WPEBD@Z @921 NONAME +?Chat_GetInfo@@YAHPEAUGC_INFO@@@Z @922 NONAME +?Chat_GetUserInfo@@YAPEAXPEAUSESSION_INFO@@@Z @923 NONAME +?Chat_NewSession@@YAPEAUSESSION_INFO@@HPEBDPEB_W1PEAX@Z @924 NONAME +?Chat_Register@@YAHPEBUGCREGISTER@@@Z @925 NONAME +?Chat_SendUserMessage@@YAHPEAUSESSION_INFO@@PEB_W@Z @926 NONAME +?Chat_SendUserMessage@@YAHPEBDPEB_W@Z @927 NONAME +?Chat_SetStatusEx@@YAHPEAUSESSION_INFO@@HPEB_W@Z @928 NONAME +?Chat_SetStatusEx@@YAHPEBDHPEB_W@Z @929 NONAME +?Chat_SetStatusbarText@@YAHPEAUSESSION_INFO@@PEB_W@Z @930 NONAME +?Chat_SetUserInfo@@YAHPEAUSESSION_INFO@@PEAX@Z @931 NONAME +?Chat_Terminate@@YAHPEAUSESSION_INFO@@_N@Z @932 NONAME +?Chat_Terminate@@YAHPEBD_N@Z @933 NONAME diff --git a/src/mir_app/src/proto_utils.cpp b/src/mir_app/src/proto_utils.cpp index 85ef574e3c..dcb3d051fa 100644 --- a/src/mir_app/src/proto_utils.cpp +++ b/src/mir_app/src/proto_utils.cpp @@ -112,7 +112,7 @@ void PROTO_INTERFACE::setAllContactStatuses(int iStatus, bool bSkipChats) if (!bSkipChats && iStatus == ID_STATUS_OFFLINE) { ptrW wszRoom(Contact::GetInfo(CNF_UNIQUEID, hContact)); if (wszRoom != nullptr) - Chat_Control(m_szModuleName, wszRoom, SESSION_OFFLINE); + Chat_Control(Chat_Find(wszRoom, m_szModuleName), SESSION_OFFLINE); } } else setWord(hContact, "Status", iStatus); -- cgit v1.2.3