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 --- 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 +- 47 files changed, 439 insertions(+), 472 deletions(-) (limited to 'protocols') 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(); -- cgit v1.2.3