From 81ce57622c3166830b23eae534dacc6b008c659d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 28 Mar 2018 16:34:30 +0300 Subject: common protocol instance management code went into template --- include/m_plugin.h | 50 ++++++++++++++++ protocols/Discord/src/main.cpp | 19 +----- protocols/Dummy/src/main.cpp | 20 +------ protocols/FacebookRM/src/main.cpp | 35 +---------- protocols/FacebookRM/src/proto.h | 7 +++ protocols/FacebookRM/src/theme.cpp | 19 +----- protocols/Gadu-Gadu/src/gg.cpp | 47 +-------------- protocols/Gadu-Gadu/src/gg.h | 1 - protocols/Gadu-Gadu/src/gg_proto.h | 6 ++ protocols/Gadu-Gadu/src/libgadu/libgadu.cpp | 4 +- protocols/Gadu-Gadu/src/links.cpp | 6 +- protocols/IRCG/src/irclib.cpp | 2 +- protocols/IRCG/src/main.cpp | 34 +---------- protocols/IRCG/src/services.cpp | 43 +++++--------- protocols/IRCG/src/stdafx.h | 9 ++- protocols/IcqOscarJ/src/icq_menu.cpp | 28 ++------- protocols/IcqOscarJ/src/icq_proto.h | 7 +++ protocols/IcqOscarJ/src/init.cpp | 26 +------- protocols/IcqOscarJ/src/stdafx.h | 1 - protocols/JabberG/src/jabber.cpp | 35 +---------- protocols/JabberG/src/jabber_menu.cpp | 92 +++++++++++++---------------- protocols/JabberG/src/jabber_proto.h | 7 ++- protocols/MRA/src/Mra.cpp | 30 +--------- protocols/MRA/src/MraProto.cpp | 2 +- protocols/MRA/src/MraProto.h | 7 +++ protocols/MRA/src/Mra_proto.cpp | 2 +- protocols/MRA/src/stdafx.h | 9 --- protocols/MSN/src/msn.cpp | 28 +-------- protocols/MSN/src/msn_http.cpp | 10 ++-- protocols/MSN/src/msn_links.cpp | 6 +- protocols/MSN/src/msn_menu.cpp | 37 ++++-------- protocols/MSN/src/msn_proto.h | 7 ++- protocols/MinecraftDynmap/src/main.cpp | 31 +--------- protocols/MinecraftDynmap/src/proto.h | 6 ++ protocols/Omegle/src/main.cpp | 35 +---------- protocols/Omegle/src/proto.h | 11 ++-- protocols/Omegle/src/theme.cpp | 2 - protocols/Sametime/src/sametime.cpp | 29 +-------- protocols/Sametime/src/sametime.h | 2 - protocols/Sametime/src/sametime_proto.h | 12 ++-- protocols/SkypeWeb/src/main.cpp | 13 +--- protocols/SkypeWeb/src/skype_accounts.cpp | 32 ---------- protocols/SkypeWeb/src/skype_menus.cpp | 2 +- protocols/SkypeWeb/src/skype_proto.h | 19 +++--- protocols/SkypeWeb/src/skype_timers.cpp | 4 +- protocols/SkypeWeb/src/skype_utils.cpp | 2 +- protocols/Steam/src/main.cpp | 13 +--- protocols/Steam/src/steam_accounts.cpp | 35 ----------- protocols/Steam/src/steam_menus.cpp | 15 +++-- protocols/Steam/src/steam_proto.h | 17 +++--- protocols/Tox/src/main.cpp | 13 +--- protocols/Tox/src/tox_accounts.cpp | 30 ---------- protocols/Tox/src/tox_proto.h | 16 +++-- protocols/Tox/src/tox_utils.cpp | 4 +- protocols/Twitter/src/main.cpp | 36 +---------- protocols/Twitter/src/proto.h | 7 +++ protocols/Twitter/src/theme.cpp | 26 ++------ protocols/VKontakte/src/main.cpp | 20 +------ 58 files changed, 278 insertions(+), 790 deletions(-) delete mode 100644 protocols/Steam/src/steam_accounts.cpp diff --git a/include/m_plugin.h b/include/m_plugin.h index b54d64aea3..233e03a432 100644 --- a/include/m_plugin.h +++ b/include/m_plugin.h @@ -189,3 +189,53 @@ protected: CreateServiceFunctionObjParam(str, (MIRANDASERVICEOBJPARAM)*(void**)&pFunc, this, param); } }; + +///////////////////////////////////////////////////////////////////////////////////////// +// Basic class for protocols with accounts + +struct CMPlugin; + +template class ACCPROTOPLUGIN : public PLUGIN +{ + typedef PLUGIN CSuper; + +protected: + ACCPROTOPLUGIN(const char *moduleName) : + CSuper(moduleName) + { + CMPluginBase::RegisterProtocol(PROTOTYPE_PROTOCOL, &fnInit, &fnUninit); + } + + static PROTO_INTERFACE* fnInit(const char *szModuleName, const wchar_t *wszAccountName) + { + P *ppro = new P(szModuleName, wszAccountName); + g_arInstances.insert(ppro); + return ppro; + } + + static int fnUninit(PROTO_INTERFACE *ppro) + { + g_arInstances.remove((P*)ppro); + return 0; + } + +public: + static OBJLIST

g_arInstances; + + static P* getInstance(const char *szProto) + { + for (auto &it : g_arInstances) + if (mir_strcmp(szProto, it->m_szModuleName) == 0) + return it; + + return nullptr; + } + + static P* getInstance(MCONTACT hContact) + { + return getInstance(::GetContactProto(hContact)); + } +}; + +template +OBJLIST

ACCPROTOPLUGIN

::g_arInstances(1, PtrKeySortT); diff --git a/protocols/Discord/src/main.cpp b/protocols/Discord/src/main.cpp index 2bed58e39a..9a1c6aa7dd 100644 --- a/protocols/Discord/src/main.cpp +++ b/protocols/Discord/src/main.cpp @@ -82,24 +82,11 @@ extern "C" int __declspec(dllexport) Unload(void) ///////////////////////////////////////////////////////////////////////////////////////// -static PROTO_INTERFACE* protoInit(const char *proto_name, const wchar_t *username) -{ - return new CDiscordProto(proto_name, username); -} - -static int protoUninit(PROTO_INTERFACE *proto) -{ - delete (CDiscordProto*)proto; - return 0; -} - -struct CMPlugin : public CMPluginBase +struct CMPlugin : public ACCPROTOPLUGIN { CMPlugin() : - CMPluginBase("Discord") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, protoInit, protoUninit); - } + ACCPROTOPLUGIN("Discord") + {} } g_plugin; diff --git a/protocols/Dummy/src/main.cpp b/protocols/Dummy/src/main.cpp index da1fccd10a..906ee1182a 100644 --- a/protocols/Dummy/src/main.cpp +++ b/protocols/Dummy/src/main.cpp @@ -81,24 +81,10 @@ extern "C" int __declspec(dllexport) Unload(void) ///////////////////////////////////////////////////////////////////////////////////////// -static PROTO_INTERFACE* dummyProtoInit(const char* pszProtoName, const wchar_t *tszUserName) -{ - CDummyProto *ppro = new CDummyProto(pszProtoName, tszUserName); - return ppro; -} - -static int dummyProtoUninit(PROTO_INTERFACE *ppro) -{ - delete (CDummyProto*)ppro; - return 0; -} - -struct CMPlugin : public CMPluginBase +struct CMPlugin : public ACCPROTOPLUGIN { CMPlugin() : - CMPluginBase("Dummy") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, dummyProtoInit, dummyProtoUninit); - } + ACCPROTOPLUGIN("Dummy") + {} } g_plugin; diff --git a/protocols/FacebookRM/src/main.cpp b/protocols/FacebookRM/src/main.cpp index 28bc66d172..2e7f7849dd 100644 --- a/protocols/FacebookRM/src/main.cpp +++ b/protocols/FacebookRM/src/main.cpp @@ -24,6 +24,7 @@ along with this program. If not, see . // TODO: Make following as "globals" structure? +CMPlugin g_plugin; CLIST_INTERFACE *pcli; int hLangpack; @@ -44,15 +45,6 @@ PLUGININFOEX pluginInfo = { { 0x8432b009, 0xff32, 0x4727, { 0xaa, 0xe6, 0xa9, 0x3, 0x50, 0x38, 0xfd, 0x58 } } }; -///////////////////////////////////////////////////////////////////////////// -// Protocol instances -static int compare_protos(const FacebookProto *p1, const FacebookProto *p2) -{ - return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName); -} - -OBJLIST g_Instances(1, compare_protos); - DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID) { g_hInstance = hInstance; @@ -73,19 +65,6 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOC ///////////////////////////////////////////////////////////////////////////////////////// // Load -static PROTO_INTERFACE* protoInit(const char *proto_name, const wchar_t *username) -{ - FacebookProto *proto = new FacebookProto(proto_name, username); - g_Instances.insert(proto); - return proto; -} - -static int protoUninit(PROTO_INTERFACE* proto) -{ - g_Instances.remove((FacebookProto*)proto); - return EXIT_SUCCESS; -} - extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); @@ -120,15 +99,3 @@ extern "C" int __declspec(dllexport) Unload(void) { return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase(FACEBOOK_NAME) - { - RegisterProtocol(PROTOTYPE_PROTOCOL, protoInit, protoUninit); - } -} - g_plugin; diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index 98262699ff..8f4b547e61 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -286,3 +286,10 @@ public: HWND NotifyEvent(wchar_t* title, wchar_t* text, MCONTACT contact, EventType type, std::string *url = nullptr, std::string *notification_id = nullptr, const char *icon = nullptr); void ShowNotifications(); }; + +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN(FACEBOOK_NAME) + {} +}; diff --git a/protocols/FacebookRM/src/theme.cpp b/protocols/FacebookRM/src/theme.cpp index 91d7931076..ce5fb25df3 100644 --- a/protocols/FacebookRM/src/theme.cpp +++ b/protocols/FacebookRM/src/theme.cpp @@ -22,8 +22,6 @@ along with this program. If not, see . #include "stdafx.h" -extern OBJLIST g_Instances; - // Contact menu items HGENMENU g_hContactMenuVisitProfile; HGENMENU g_hContactMenuVisitFriendship; @@ -69,23 +67,10 @@ HANDLE GetIconHandle(const char* name) } // Helper functions -static FacebookProto * GetInstanceByHContact(MCONTACT hContact) -{ - char *proto = GetContactProto(hContact); - if (!proto) - return nullptr; - - for (auto &it : g_Instances) - if (!mir_strcmp(proto, it->m_szModuleName)) - return it; - - return nullptr; -} - template INT_PTR GlobalService(WPARAM wParam, LPARAM lParam) { - FacebookProto *proto = GetInstanceByHContact(MCONTACT(wParam)); + FacebookProto *proto = CMPlugin::getInstance(MCONTACT(wParam)); return proto ? (proto->*Fcn)(wParam, lParam) : 0; } @@ -102,7 +87,7 @@ static int PrebuildContactMenu(WPARAM wParam, LPARAM lParam) Menu_ShowItem(g_hContactMenuLoadHistory, false); // Process them in correct account - FacebookProto *proto = GetInstanceByHContact(MCONTACT(wParam)); + FacebookProto *proto = CMPlugin::getInstance(MCONTACT(wParam)); return proto ? proto->OnPrebuildContactMenu(wParam, lParam) : 0; } diff --git a/protocols/Gadu-Gadu/src/gg.cpp b/protocols/Gadu-Gadu/src/gg.cpp index 31ba420df2..8aeffc1391 100644 --- a/protocols/Gadu-Gadu/src/gg.cpp +++ b/protocols/Gadu-Gadu/src/gg.cpp @@ -38,12 +38,12 @@ PLUGININFOEX pluginInfo = { }; // Other variables +CMPlugin g_plugin; HINSTANCE hInstance; SSL_API sslApi; CLIST_INTERFACE *pcli; int hLangpack; -LIST g_Instances(1, PtrKeySortT); static unsigned long crc_table[256]; @@ -213,28 +213,12 @@ static int gg_modulesloaded(WPARAM, LPARAM) return 0; } -////////////////////////////////////////////////////////// -// Gets protocol instance associated with a contact -// -static GaduProto* gg_getprotoinstance(MCONTACT hContact) -{ - char* szProto = GetContactProto(hContact); - if (szProto == nullptr) - return nullptr; - - for (auto &it : g_Instances) - if (mir_strcmp(szProto, it->m_szModuleName) == 0) - return it; - - return nullptr; -} - ////////////////////////////////////////////////////////// // Handles PrebuildContactMenu event // static int gg_prebuildcontactmenu(WPARAM hContact, LPARAM) { - GaduProto* gg = gg_getprotoinstance(hContact); + GaduProto* gg = CMPlugin::getInstance(hContact); if (gg == nullptr) return 0; @@ -437,30 +421,3 @@ BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD, LPVOID) #endif return TRUE; } - -///////////////////////////////////////////////////////////////////////////////////////// - -static PROTO_INTERFACE* gg_proto_init(const char *pszProtoName, const wchar_t *tszUserName) -{ - GaduProto *gg = new GaduProto(pszProtoName, tszUserName); - g_Instances.insert(gg); - return gg; -} - -static int gg_proto_uninit(PROTO_INTERFACE *proto) -{ - GaduProto *gg = (GaduProto*)proto; - g_Instances.remove(gg); - delete gg; - return 0; -} - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase(GGDEF_PROTO) - { - RegisterProtocol(PROTOTYPE_PROTOCOL, gg_proto_init, gg_proto_uninit); - } -} - g_plugin; diff --git a/protocols/Gadu-Gadu/src/gg.h b/protocols/Gadu-Gadu/src/gg.h index 558c3227d3..2e74058d02 100644 --- a/protocols/Gadu-Gadu/src/gg.h +++ b/protocols/Gadu-Gadu/src/gg.h @@ -260,7 +260,6 @@ struct GaduProto; extern HINSTANCE hInstance; extern CLIST_INTERFACE *pcli; -extern LIST g_Instances; extern PLUGININFOEX pluginInfo; extern IconItem iconList[]; extern SSL_API sslApi; diff --git a/protocols/Gadu-Gadu/src/gg_proto.h b/protocols/Gadu-Gadu/src/gg_proto.h index 543c936ea4..ff973f010d 100644 --- a/protocols/Gadu-Gadu/src/gg_proto.h +++ b/protocols/Gadu-Gadu/src/gg_proto.h @@ -309,5 +309,11 @@ inline void GaduProto::gg_sleep(DWORD miliseconds, BOOL alterable, char* calling #endif } +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN(GGDEF_PROTO) + {} +}; #endif diff --git a/protocols/Gadu-Gadu/src/libgadu/libgadu.cpp b/protocols/Gadu-Gadu/src/libgadu/libgadu.cpp index edfc7fd034..931d55810d 100644 --- a/protocols/Gadu-Gadu/src/libgadu/libgadu.cpp +++ b/protocols/Gadu-Gadu/src/libgadu/libgadu.cpp @@ -565,8 +565,8 @@ void *gg_recv_packet(struct gg_session *sess) h.type = gg_fix32(h.type); h.length = gg_fix32(h.length); - } else - memcpy(&h, sess->recv_buf, sizeof(h)); + } + else memcpy(&h, sess->recv_buf, sizeof(h)); /* jakieÅ› sensowne limity na rozmiar pakietu */ if (h.length > 65535) { diff --git a/protocols/Gadu-Gadu/src/links.cpp b/protocols/Gadu-Gadu/src/links.cpp index 295e9dbcf2..4d95b0fc01 100644 --- a/protocols/Gadu-Gadu/src/links.cpp +++ b/protocols/Gadu-Gadu/src/links.cpp @@ -41,7 +41,7 @@ static INT_PTR gg_parselink(WPARAM, LPARAM lParam) { char *arg = (char*)lParam; - if (g_Instances.getCount() == 0) + if (CMPlugin::g_arInstances.getCount() == 0) return 0; if (arg == nullptr) @@ -60,7 +60,7 @@ static INT_PTR gg_parselink(WPARAM, LPARAM lParam) GaduProto *gg = nullptr; int items = 0; - for (auto &it : g_Instances) { + for (auto &it : CMPlugin::g_arInstances) { gg = it; if (it->m_iStatus > ID_STATUS_OFFLINE) { ++items; @@ -117,7 +117,7 @@ void GaduProto::links_instance_init() if (ServiceExists(MS_ASSOCMGR_ADDNEWURLTYPE)) { CMenuItem mi; mi.flags = CMIF_UNICODE; - mi.position = g_Instances.getCount(); + mi.position = CMPlugin::g_arInstances.getCount(); mi.name.w = m_tszUserName; hInstanceMenuItem = Menu_AddItem(hInstanceMenu, &mi, this); } diff --git a/protocols/IRCG/src/irclib.cpp b/protocols/IRCG/src/irclib.cpp index 28db677271..1dea025bbe 100644 --- a/protocols/IRCG/src/irclib.cpp +++ b/protocols/IRCG/src/irclib.cpp @@ -1412,7 +1412,7 @@ LBL_Parse: if (iParamCnt != 2) cbLen = mir_snprintf(buf, "%s : ERROR : UNKNOWN-ERROR\r\n", szBuf); else { - for (auto &it : g_Instances) + for (auto &it : CMPlugin::g_arInstances) if (PeerPortNrRcvd == it->m_info.iPort && LocalPortNrRcvd == it->m_myLocalPort) { cbLen = mir_snprintf(buf, "%s : USERID : %S : %S\r\n", szBuf, it->m_info.sIdentServerType.c_str(), it->m_info.sUserID.c_str()); diff --git a/protocols/IRCG/src/main.cpp b/protocols/IRCG/src/main.cpp index 81ff6f6581..1dd78c6e77 100644 --- a/protocols/IRCG/src/main.cpp +++ b/protocols/IRCG/src/main.cpp @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include "version.h" +CMPlugin g_plugin; CHAT_MANAGER *pci; CLIST_INTERFACE *pcli; HINSTANCE hInst = nullptr; @@ -35,13 +36,6 @@ static int CompareServers( const SERVER_INFO* p1, const SERVER_INFO* p2 ) OBJLIST g_servers( 20, CompareServers ); -static int sttCompareProtocols(const CIrcProto *p1, const CIrcProto *p2) -{ - return mir_strcmp(p1->m_szModuleName, p2->m_szModuleName); -} - -LIST g_Instances(1, sttCompareProtocols); - void UninitTimers( void ); // Information about the plugin @@ -93,29 +87,3 @@ extern "C" int __declspec(dllexport) Unload(void) UninitTimers(); return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// - -static PROTO_INTERFACE* ircProtoInit(const char* pszProtoName, const wchar_t* tszUserName) -{ - CIrcProto *ppro = new CIrcProto(pszProtoName, tszUserName); - g_Instances.insert(ppro); - return ppro; -} - -static int ircProtoUninit(PROTO_INTERFACE *ppro) -{ - g_Instances.remove((CIrcProto*)ppro); - delete (CIrcProto*)ppro; - return 0; -} - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase("IRC") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, ircProtoInit, ircProtoUninit); - } -} - g_plugin; diff --git a/protocols/IRCG/src/services.cpp b/protocols/IRCG/src/services.cpp index 1bb2274f9c..b6775b8b05 100644 --- a/protocols/IRCG/src/services.cpp +++ b/protocols/IRCG/src/services.cpp @@ -64,52 +64,39 @@ void CIrcProto::InitMainMenus(void) static HGENMENU hUMenuChanSettings, hUMenuWhois, hUMenuDisconnect, hUMenuIgnore; -static CIrcProto* IrcGetInstanceByHContact(MCONTACT hContact) +static INT_PTR IrcMenuChanSettings(WPARAM hContact, LPARAM lParam) { - char* szProto = GetContactProto(hContact); - if (szProto == nullptr) - return nullptr; - - for (auto &it : g_Instances) - if (!mir_strcmp(szProto, it->m_szModuleName)) - return it; - - return nullptr; -} - -static INT_PTR IrcMenuChanSettings(WPARAM wParam, LPARAM lParam) -{ - CIrcProto *ppro = IrcGetInstanceByHContact(wParam); - return (ppro) ? ppro->OnMenuChanSettings(wParam, lParam) : 0; + CIrcProto *ppro = CMPlugin::getInstance(hContact); + return (ppro) ? ppro->OnMenuChanSettings(hContact, lParam) : 0; } -static INT_PTR IrcMenuWhois(WPARAM wParam, LPARAM lParam) +static INT_PTR IrcMenuWhois(WPARAM hContact, LPARAM lParam) { - CIrcProto *ppro = IrcGetInstanceByHContact(wParam); - return (ppro) ? ppro->OnMenuWhois(wParam, lParam) : 0; + CIrcProto *ppro = CMPlugin::getInstance(hContact); + return (ppro) ? ppro->OnMenuWhois(hContact, lParam) : 0; } -static INT_PTR IrcMenuDisconnect(WPARAM wParam, LPARAM lParam) +static INT_PTR IrcMenuDisconnect(WPARAM hContact, LPARAM lParam) { - CIrcProto *ppro = IrcGetInstanceByHContact(wParam); - return (ppro) ? ppro->OnMenuDisconnect(wParam, lParam) : 0; + CIrcProto *ppro = CMPlugin::getInstance(hContact); + return (ppro) ? ppro->OnMenuDisconnect(hContact, lParam) : 0; } -static INT_PTR IrcMenuIgnore(WPARAM wParam, LPARAM lParam) +static INT_PTR IrcMenuIgnore(WPARAM hContact, LPARAM lParam) { - CIrcProto *ppro = IrcGetInstanceByHContact(wParam); - return (ppro) ? ppro->OnMenuIgnore(wParam, lParam) : 0; + CIrcProto *ppro = CMPlugin::getInstance(hContact); + return (ppro) ? ppro->OnMenuIgnore(hContact, lParam) : 0; } -int IrcPrebuildContactMenu(WPARAM wParam, LPARAM lParam) +int IrcPrebuildContactMenu(WPARAM hContact, LPARAM lParam) { Menu_ShowItem(hUMenuChanSettings, false); Menu_ShowItem(hUMenuWhois, false); Menu_ShowItem(hUMenuDisconnect, false); Menu_ShowItem(hUMenuIgnore, false); - CIrcProto *ppro = IrcGetInstanceByHContact(wParam); - return (ppro) ? ppro->OnMenuPreBuild(wParam, lParam) : 0; + CIrcProto *ppro = CMPlugin::getInstance(hContact); + return (ppro) ? ppro->OnMenuPreBuild(hContact, lParam) : 0; } void InitContactMenus(void) diff --git a/protocols/IRCG/src/stdafx.h b/protocols/IRCG/src/stdafx.h index eef1cb6a10..6b0f5e659e 100644 --- a/protocols/IRCG/src/stdafx.h +++ b/protocols/IRCG/src/stdafx.h @@ -587,6 +587,13 @@ private: CMStringW sNick4Perform; }; +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN("IRC") + {} +}; + // map actual member functions to their associated IRC command. // put any number of this macro in the class's constructor. #define IRC_MAP_ENTRY(name, member) \ @@ -598,8 +605,6 @@ private: //main.cpp extern HINSTANCE hInst; -extern LIST g_Instances; - extern OBJLIST g_servers; CIrcProto* GetTimerOwner(UINT_PTR eventId); diff --git a/protocols/IcqOscarJ/src/icq_menu.cpp b/protocols/IcqOscarJ/src/icq_menu.cpp index 97fa93ab52..827f3e9c09 100644 --- a/protocols/IcqOscarJ/src/icq_menu.cpp +++ b/protocols/IcqOscarJ/src/icq_menu.cpp @@ -30,41 +30,21 @@ HGENMENU g_hContactMenuItems[3]; HANDLE g_hContactMenuSvc[3]; -static int sttCompareProtocols(const CIcqProto *p1, const CIcqProto *p2) -{ - return mir_strcmp(p1->m_szModuleName, p2->m_szModuleName); -} - -LIST g_Instances(1, sttCompareProtocols); - -static CIcqProto* IcqGetInstanceByHContact(MCONTACT hContact) -{ - char* szProto = GetContactProto(hContact); - if (szProto == nullptr) - return nullptr; - - for (auto &it : g_Instances) - if (!mir_strcmp(szProto, it->m_szModuleName)) - return it; - - return nullptr; -} - static INT_PTR IcqMenuHandleAddServContact(WPARAM wParam, LPARAM lParam) { - CIcqProto* ppro = IcqGetInstanceByHContact(wParam); + CIcqProto* ppro = CMPlugin::getInstance(wParam); return (ppro) ? ppro->AddServerContact(wParam, lParam) : 0; } static INT_PTR IcqMenuHandleXStatusDetails(WPARAM wParam, LPARAM lParam) { - CIcqProto* ppro = IcqGetInstanceByHContact(wParam); + CIcqProto* ppro = CMPlugin::getInstance(wParam); return (ppro) ? ppro->ShowXStatusDetails(wParam, lParam) : 0; } static INT_PTR IcqMenuHandleOpenProfile(WPARAM wParam, LPARAM lParam) { - CIcqProto* ppro = IcqGetInstanceByHContact(wParam); + CIcqProto* ppro = CMPlugin::getInstance(wParam); return (ppro) ? ppro->OpenWebProfile(wParam, lParam) : 0; } @@ -74,7 +54,7 @@ static int IcqPrebuildContactMenu( WPARAM wParam, LPARAM lParam ) Menu_ShowItem(g_hContactMenuItems[ICMI_XSTATUS_DETAILS], FALSE); Menu_ShowItem(g_hContactMenuItems[ICMI_OPEN_PROFILE], FALSE); - CIcqProto* ppro = IcqGetInstanceByHContact(wParam); + CIcqProto* ppro = CMPlugin::getInstance(wParam); return (ppro) ? ppro->OnPreBuildContactMenu(wParam, lParam) : 0; } diff --git a/protocols/IcqOscarJ/src/icq_proto.h b/protocols/IcqOscarJ/src/icq_proto.h index 004a7148ed..08fff03c9e 100644 --- a/protocols/IcqOscarJ/src/icq_proto.h +++ b/protocols/IcqOscarJ/src/icq_proto.h @@ -895,4 +895,11 @@ struct CIcqProto : public PROTO bool validateStatusMessageRequest(MCONTACT hContact, WORD byMessageType); }; +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN(ICQ_PROTOCOL_NAME) + {} +}; + #endif diff --git a/protocols/IcqOscarJ/src/init.cpp b/protocols/IcqOscarJ/src/init.cpp index fb53d2312e..46e5b68c17 100644 --- a/protocols/IcqOscarJ/src/init.cpp +++ b/protocols/IcqOscarJ/src/init.cpp @@ -28,6 +28,7 @@ #include "m_extraicons.h" #include "m_icolib.h" +CMPlugin g_plugin; HINSTANCE hInst; int hLangpack; CLIST_INTERFACE *pcli; @@ -161,28 +162,3 @@ void CIcqProto::UpdateGlobalSettings() m_bMoodsEnabled = getByte("MoodsEnabled", DEFAULT_MOODS_ENABLED); } -///////////////////////////////////////////////////////////////////////////////////////// - -static PROTO_INTERFACE* icqProtoInit(const char* pszProtoName, const wchar_t* tszUserName) -{ - CIcqProto *ppro = new CIcqProto(pszProtoName, tszUserName); - g_Instances.insert(ppro); - return ppro; -} - -static int icqProtoUninit(PROTO_INTERFACE* ppro) -{ - g_Instances.remove((CIcqProto*)ppro); - delete (CIcqProto*)ppro; - return 0; -} - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase(ICQ_PROTOCOL_NAME) - { - RegisterProtocol(PROTOTYPE_PROTOCOL, icqProtoInit, icqProtoUninit); - } -} - g_plugin; diff --git a/protocols/IcqOscarJ/src/stdafx.h b/protocols/IcqOscarJ/src/stdafx.h index 61877a2a58..303c6f363e 100644 --- a/protocols/IcqOscarJ/src/stdafx.h +++ b/protocols/IcqOscarJ/src/stdafx.h @@ -118,6 +118,5 @@ #include "icq_popups.h" #include "icq_proto.h" -extern LIST g_Instances; extern bool g_bTerminated; extern IconItem iconList[]; \ No newline at end of file diff --git a/protocols/JabberG/src/jabber.cpp b/protocols/JabberG/src/jabber.cpp index 06523ae7eb..b5860eb292 100755 --- a/protocols/JabberG/src/jabber.cpp +++ b/protocols/JabberG/src/jabber.cpp @@ -38,6 +38,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. HINSTANCE hInst; HMODULE hMsftedit; +CMPlugin g_plugin; int hLangpack; unsigned int g_nTempFileId; CHAT_MANAGER *pci; @@ -70,14 +71,6 @@ void JabberUserInfoUninit(void); bool bSecureIM, bMirOTR, bNewGPG, bPlatform; -///////////////////////////////////////////////////////////////////////////// -// Protocol instances -static int sttCompareProtocols(const CJabberProto *p1, const CJabberProto *p2) -{ - return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName); -} - -LIST g_Instances(1, sttCompareProtocols); ///////////////////////////////////////////////////////////////////////////// BOOL WINAPI DllMain(HINSTANCE hModule, DWORD, LPVOID) @@ -227,29 +220,3 @@ extern "C" int __declspec(dllexport) Unload(void) g_MenuUninit(); return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// - -static PROTO_INTERFACE* jabberProtoInit(const char* pszProtoName, const wchar_t *tszUserName) -{ - CJabberProto *ppro = new CJabberProto(pszProtoName, tszUserName); - g_Instances.insert(ppro); - return ppro; -} - -static int jabberProtoUninit(PROTO_INTERFACE *ppro) -{ - g_Instances.remove((CJabberProto*)ppro); - delete (CJabberProto*)ppro; - return 0; -} - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase(GLOBAL_SETTING_MODULE) - { - RegisterProtocol(PROTOTYPE_PROTOCOL, jabberProtoInit, jabberProtoUninit); - } -} - g_plugin; diff --git a/protocols/JabberG/src/jabber_menu.cpp b/protocols/JabberG/src/jabber_menu.cpp index 63f4cd2899..585f7c2b58 100644 --- a/protocols/JabberG/src/jabber_menu.cpp +++ b/protocols/JabberG/src/jabber_menu.cpp @@ -72,74 +72,61 @@ static INT_PTR JabberMenuChooseService(WPARAM wParam, LPARAM lParam) return 0; } -static CJabberProto* JabberGetInstanceByHContact(MCONTACT hContact) +static INT_PTR JabberMenuConvertChatContact(WPARAM hContact, LPARAM lParam) { - char *szProto = GetContactProto(hContact); - if (szProto == nullptr) - return nullptr; - - for (auto &it : g_Instances) - if (!mir_strcmp(szProto, it->m_szModuleName)) - return it; - - return nullptr; -} - -static INT_PTR JabberMenuConvertChatContact(WPARAM wParam, LPARAM lParam) -{ - CJabberProto *ppro = JabberGetInstanceByHContact(wParam); - return(ppro) ? ppro->OnMenuConvertChatContact(wParam, lParam) : 0; + CJabberProto *ppro = CMPlugin::getInstance(hContact); + return(ppro) ? ppro->OnMenuConvertChatContact(hContact, lParam) : 0; } -static INT_PTR JabberMenuRosterAdd(WPARAM wParam, LPARAM lParam) +static INT_PTR JabberMenuRosterAdd(WPARAM hContact, LPARAM lParam) { - CJabberProto *ppro = JabberGetInstanceByHContact(wParam); - return(ppro) ? ppro->OnMenuRosterAdd(wParam, lParam) : 0; + CJabberProto *ppro = CMPlugin::getInstance(hContact); + return(ppro) ? ppro->OnMenuRosterAdd(hContact, lParam) : 0; } -static INT_PTR JabberMenuBookmarkAdd(WPARAM wParam, LPARAM lParam) +static INT_PTR JabberMenuBookmarkAdd(WPARAM hContact, LPARAM lParam) { - CJabberProto *ppro = JabberGetInstanceByHContact(wParam); - return(ppro) ? ppro->OnMenuBookmarkAdd(wParam, lParam) : 0; + CJabberProto *ppro = CMPlugin::getInstance(hContact); + return(ppro) ? ppro->OnMenuBookmarkAdd(hContact, lParam) : 0; } -static INT_PTR JabberMenuTransportLogin(WPARAM wParam, LPARAM lParam) +static INT_PTR JabberMenuTransportLogin(WPARAM hContact, LPARAM lParam) { - CJabberProto *ppro = JabberGetInstanceByHContact(wParam); - return(ppro) ? ppro->OnMenuTransportLogin(wParam, lParam) : 0; + CJabberProto *ppro = CMPlugin::getInstance(hContact); + return(ppro) ? ppro->OnMenuTransportLogin(hContact, lParam) : 0; } -static INT_PTR JabberMenuTransportResolve(WPARAM wParam, LPARAM lParam) +static INT_PTR JabberMenuTransportResolve(WPARAM hContact, LPARAM lParam) { - CJabberProto *ppro = JabberGetInstanceByHContact(wParam); - return(ppro) ? ppro->OnMenuTransportResolve(wParam, lParam) : 0; + CJabberProto *ppro = CMPlugin::getInstance(hContact); + return(ppro) ? ppro->OnMenuTransportResolve(hContact, lParam) : 0; } -static INT_PTR JabberContactMenuRunCommands(WPARAM wParam, LPARAM lParam) +static INT_PTR JabberContactMenuRunCommands(WPARAM hContact, LPARAM lParam) { - CJabberProto *ppro = JabberGetInstanceByHContact(wParam); - return(ppro) ? ppro->ContactMenuRunCommands(wParam, lParam) : 0; + CJabberProto *ppro = CMPlugin::getInstance(hContact); + return(ppro) ? ppro->ContactMenuRunCommands(hContact, lParam) : 0; } -static INT_PTR JabberMenuSendNote(WPARAM wParam, LPARAM lParam) +static INT_PTR JabberMenuSendNote(WPARAM hContact, LPARAM lParam) { - CJabberProto *ppro = JabberGetInstanceByHContact(wParam); - return(ppro) ? ppro->OnMenuSendNote(wParam, lParam) : 0; + CJabberProto *ppro = CMPlugin::getInstance(hContact); + return(ppro) ? ppro->OnMenuSendNote(hContact, lParam) : 0; } -static INT_PTR JabberMenuHandleResource(WPARAM wParam, LPARAM lParam, LPARAM lRes) +static INT_PTR JabberMenuHandleResource(WPARAM hContact, LPARAM lParam, LPARAM lRes) { - CJabberProto *ppro = JabberGetInstanceByHContact(wParam); - return(ppro) ? ppro->OnMenuHandleResource(wParam, lParam, lRes) : 0; + CJabberProto *ppro = CMPlugin::getInstance(hContact); + return(ppro) ? ppro->OnMenuHandleResource(hContact, lParam, lRes) : 0; } -static INT_PTR JabberMenuHandleDirectPresence(WPARAM wParam, LPARAM lParam, LPARAM lRes) +static INT_PTR JabberMenuHandleDirectPresence(WPARAM hContact, LPARAM lParam, LPARAM lRes) { - CJabberProto *ppro = JabberGetInstanceByHContact(wParam); - return(ppro) ? ppro->OnMenuHandleDirectPresence(wParam, lParam, lRes) : 0; + CJabberProto *ppro = CMPlugin::getInstance(hContact); + return(ppro) ? ppro->OnMenuHandleDirectPresence(hContact, lParam, lRes) : 0; } -static int JabberPrebuildContactMenu(WPARAM wParam, LPARAM lParam) +static int JabberPrebuildContactMenu(WPARAM hContact, LPARAM lParam) { Menu_ShowItem(g_hMenuCommands, FALSE); Menu_ShowItem(g_hMenuSendNote, FALSE); @@ -151,8 +138,8 @@ static int JabberPrebuildContactMenu(WPARAM wParam, LPARAM lParam) Menu_ShowItem(g_hMenuResourcesRoot, FALSE); Menu_ShowItem(g_hMenuDirectPresence[0], FALSE); - CJabberProto *ppro = JabberGetInstanceByHContact(wParam); - return(ppro) ? ppro->OnPrebuildContactMenu(wParam, lParam) : 0; + CJabberProto *ppro = CMPlugin::getInstance(hContact); + return(ppro) ? ppro->OnPrebuildContactMenu(hContact, lParam) : 0; } void g_MenuInit(void) @@ -790,7 +777,7 @@ static INT_PTR g_ToolbarHandleServiceDiscovery(WPARAM w, LPARAM l) int g_OnToolbarInit(WPARAM, LPARAM) { - if (g_Instances.getCount() == 0) + if (CMPlugin::g_arInstances.getCount() == 0) return 0; TTBButton ttb = {}; @@ -1043,25 +1030,26 @@ INT_PTR __cdecl CJabberProto::OnMenuHandleDirectPresence(WPARAM hContact, LPARAM CJabberProto* JabberChooseInstance(bool bIsLink) { - if (g_Instances.getCount() == 0) + if (CMPlugin::g_arInstances.getCount() == 0) return nullptr; - if (g_Instances.getCount() == 1) { - if (g_Instances[0]->m_iStatus != ID_STATUS_OFFLINE && g_Instances[0]->m_iStatus != ID_STATUS_CONNECTING) - return g_Instances[0]; + if (CMPlugin::g_arInstances.getCount() == 1) { + if (CMPlugin::g_arInstances[0].m_iStatus != ID_STATUS_OFFLINE && CMPlugin::g_arInstances[0].m_iStatus != ID_STATUS_CONNECTING) + return &CMPlugin::g_arInstances[0]; + return nullptr; } if (bIsLink) - for (auto &it : g_Instances) + for (auto &it : CMPlugin::g_arInstances) if (it->m_bProcessXMPPLinks) return it; int nItems = 0, lastItemId = 0; - for (auto &ppro : g_Instances) { + for (auto &ppro : CMPlugin::g_arInstances) { if (ppro->m_iStatus != ID_STATUS_OFFLINE && ppro->m_iStatus != ID_STATUS_CONNECTING) { ++nItems; - lastItemId = g_Instances.indexOf(&ppro) + 1; + lastItemId = CMPlugin::g_arInstances.indexOf(&ppro) + 1; Menu_ModifyItem(ppro->m_hChooseMenuItem, nullptr, Skin_LoadProtoIcon(ppro->m_szModuleName, ppro->m_iStatus)); } else Menu_ShowItem(ppro->m_hChooseMenuItem, false); @@ -1085,5 +1073,5 @@ CJabberProto* JabberChooseInstance(bool bIsLink) return nullptr; } - return lastItemId ? g_Instances[lastItemId - 1] : nullptr; + return lastItemId ? &CMPlugin::g_arInstances[lastItemId - 1] : nullptr; } diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 729ca52efe..15ce0aeb26 100755 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -933,6 +933,11 @@ private: JabberFeatCapPairDynamic *FindFeature(const wchar_t *szFeature); }; -extern LIST g_Instances; +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN("JABBER") + {} +}; #endif diff --git a/protocols/MRA/src/Mra.cpp b/protocols/MRA/src/Mra.cpp index 49eded7d0a..79dfebf977 100644 --- a/protocols/MRA/src/Mra.cpp +++ b/protocols/MRA/src/Mra.cpp @@ -1,9 +1,9 @@ #include "stdafx.h" -LIST g_Instances(1, PtrKeySortT); +CMPlugin g_plugin; -CLIST_INTERFACE *pcli; int hLangpack; +CLIST_INTERFACE *pcli; PLUGININFOEX pluginInfoEx = { sizeof(PLUGININFOEX), @@ -78,29 +78,3 @@ extern "C" __declspec(dllexport) int Unload(void) return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// - -static PROTO_INTERFACE* mraProtoInit(const char* pszProtoName, const wchar_t* tszUserName) -{ - CMraProto *ppro = new CMraProto(pszProtoName, tszUserName); - g_Instances.insert(ppro); - return ppro; -} - -static int mraProtoUninit(PROTO_INTERFACE *ppro) -{ - g_Instances.remove((CMraProto*)ppro); - delete (CMraProto*)ppro; - return 0; -} - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase("MRA") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, mraProtoInit, mraProtoUninit); - } -} - g_plugin; diff --git a/protocols/MRA/src/MraProto.cpp b/protocols/MRA/src/MraProto.cpp index 5fd2a0f03f..89f2046dae 100644 --- a/protocols/MRA/src/MraProto.cpp +++ b/protocols/MRA/src/MraProto.cpp @@ -2,7 +2,7 @@ static int MraExtraIconsApplyAll(WPARAM, LPARAM) { - for (auto &it : g_Instances) + for (auto &it : CMPlugin::g_arInstances) it->MraExtraIconsApply(0, 0); return 0; } diff --git a/protocols/MRA/src/MraProto.h b/protocols/MRA/src/MraProto.h index a9a95fbc07..b6f2bede82 100644 --- a/protocols/MRA/src/MraProto.h +++ b/protocols/MRA/src/MraProto.h @@ -339,3 +339,10 @@ struct CMraProto : public PROTO void __cdecl MraAvatarsThreadProc(LPVOID lpParameter); }; + +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN("MRA") + {} +}; diff --git a/protocols/MRA/src/Mra_proto.cpp b/protocols/MRA/src/Mra_proto.cpp index 35faa0405c..bad5ab3340 100644 --- a/protocols/MRA/src/Mra_proto.cpp +++ b/protocols/MRA/src/Mra_proto.cpp @@ -1647,7 +1647,7 @@ DWORD CMraProto::MraRecvCommand_Message(DWORD dwTime, DWORD dwFlags, CMStringA & debugLogA("Processing message: %08X, from '%s', text '%S'\n", dwFlags, plpsFrom.c_str(), wszMessage.c_str()); // processing - if (dwFlags & (MESSAGE_FLAG_SMS | MESSAGE_SMS_DELIVERY_REPORT)) {// SMS //if (IsPhone(plpsFrom->lpszData, plpsFrom->dwSize)) + if (dwFlags & (MESSAGE_FLAG_SMS | MESSAGE_SMS_DELIVERY_REPORT)) { // SMS INTERNET_TIME itTime; InternetTimeGetCurrentTime(&itTime); CMStringA szTime = InternetTimeGetString(&itTime); diff --git a/protocols/MRA/src/stdafx.h b/protocols/MRA/src/stdafx.h index dd94bdfbb9..df92980ad9 100644 --- a/protocols/MRA/src/stdafx.h +++ b/protocols/MRA/src/stdafx.h @@ -169,12 +169,8 @@ extern WCHAR g_szMirWorkDirPath[MAX_FILEPATH]; ///////////////////////////////////////////////////////////////////////////////////////// // External variables -extern LIST g_Instances; - extern HANDLE hXStatusAdvancedStatusIcons[]; -void InitExtraIcons(); - CMStringA MraGetSelfVersionString(); #define SetBit(bytes, bitpos) bytes |= (1<. #include "msn_proto.h" #include "version.h" +CMPlugin g_plugin; CLIST_INTERFACE *pcli; HINSTANCE g_hInst, g_hOpenssl = nullptr; int hLangpack; @@ -60,8 +61,6 @@ static int sttCompareProtocols(const CMsnProto *p1, const CMsnProto *p2) return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName); } -OBJLIST g_Instances(1, sttCompareProtocols); - // Main DLL function extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID) { @@ -114,28 +113,3 @@ extern "C" __declspec(dllexport) const PLUGININFOEX* MirandaPluginInfoEx(DWORD) // MirandaInterfaces - returns the protocol interface to the core extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; - -///////////////////////////////////////////////////////////////////////////////////////// - -static PROTO_INTERFACE* msnProtoInit(const char *pszProtoName, const wchar_t *tszUserName) -{ - CMsnProto *ppro = new CMsnProto(pszProtoName, tszUserName); - g_Instances.insert(ppro); - return ppro; -} - -static int msnProtoUninit(PROTO_INTERFACE *ppro) -{ - g_Instances.remove((CMsnProto*)ppro); - return 0; -} - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase("MSN") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, msnProtoInit, msnProtoUninit); - } -} - g_plugin; diff --git a/protocols/MSN/src/msn_http.cpp b/protocols/MSN/src/msn_http.cpp index 6acf97a6d4..5c7fb3079d 100644 --- a/protocols/MSN/src/msn_http.cpp +++ b/protocols/MSN/src/msn_http.cpp @@ -25,11 +25,13 @@ along with this program. If not, see . static ThreadData* FindThreadConn(HNETLIBCONN hConn) { - ThreadData *res = nullptr; - for (int i = 0; i < g_Instances.getCount() && res == nullptr; ++i) - res = g_Instances[i].MSN_GetThreadByConnection(hConn); + for (auto &it : CMPlugin::g_arInstances) { + ThreadData *res = it->MSN_GetThreadByConnection(hConn); + if (res != nullptr) + return res; + } - return res; + return nullptr; } //======================================================================================= diff --git a/protocols/MSN/src/msn_links.cpp b/protocols/MSN/src/msn_links.cpp index efbc79408b..dbfe54c4dc 100644 --- a/protocols/MSN/src/msn_links.cpp +++ b/protocols/MSN/src/msn_links.cpp @@ -68,10 +68,10 @@ static INT_PTR ServiceParseMsnimLink(WPARAM, LPARAM lParam) arg = NEWWSTR_ALLOCA(arg); - if (g_Instances.getCount() == 0) return 0; + if (CMPlugin::g_arInstances.getCount() == 0) return 0; - CMsnProto *proto = &g_Instances[0]; - for (auto &it : g_Instances) + CMsnProto *proto = &CMPlugin::g_arInstances[0]; + for (auto &it : CMPlugin::g_arInstances) if (it->m_iStatus > ID_STATUS_OFFLINE) { proto = it; break; diff --git a/protocols/MSN/src/msn_menu.cpp b/protocols/MSN/src/msn_menu.cpp index 65807adcc6..397fabc8ec 100644 --- a/protocols/MSN/src/msn_menu.cpp +++ b/protocols/MSN/src/msn_menu.cpp @@ -186,42 +186,29 @@ void CMsnProto::MSN_EnableMenuItems(bool bEnable) ////////////////////////////////////////////////////////////////////////////////////// -static CMsnProto* GetProtoInstanceByHContact(MCONTACT hContact) +static INT_PTR MsnMenuBlockCommand(WPARAM hContact, LPARAM lParam) { - char* szProto = GetContactProto(hContact); - if (szProto == nullptr) - return nullptr; - - for (auto &it : g_Instances) - if (!mir_strcmp(szProto, it->m_szModuleName)) - return it; - - return nullptr; -} - -static INT_PTR MsnMenuBlockCommand(WPARAM wParam, LPARAM lParam) -{ - CMsnProto* ppro = GetProtoInstanceByHContact(wParam); - return (ppro) ? ppro->MsnBlockCommand(wParam, lParam) : 0; + CMsnProto* ppro = CMPlugin::getInstance(hContact); + return (ppro) ? ppro->MsnBlockCommand(hContact, lParam) : 0; } -static INT_PTR MsnMenuViewProfile(WPARAM wParam, LPARAM lParam) +static INT_PTR MsnMenuViewProfile(WPARAM hContact, LPARAM lParam) { - CMsnProto* ppro = GetProtoInstanceByHContact(wParam); - return (ppro) ? ppro->MsnViewProfile(wParam, lParam) : 0; + CMsnProto* ppro = CMPlugin::getInstance(hContact); + return (ppro) ? ppro->MsnViewProfile(hContact, lParam) : 0; } -static INT_PTR MsnMenuSendHotmail(WPARAM wParam, LPARAM lParam) +static INT_PTR MsnMenuSendHotmail(WPARAM hContact, LPARAM lParam) { - CMsnProto* ppro = GetProtoInstanceByHContact(wParam); - return (ppro) ? ppro->MsnSendHotmail(wParam, lParam) : 0; + CMsnProto* ppro = CMPlugin::getInstance(hContact); + return (ppro) ? ppro->MsnSendHotmail(hContact, lParam) : 0; } -static int MSN_OnPrebuildContactMenu(WPARAM wParam, LPARAM lParam) +static int MSN_OnPrebuildContactMenu(WPARAM hContact, LPARAM lParam) { - CMsnProto* ppro = GetProtoInstanceByHContact(wParam); + CMsnProto* ppro = CMPlugin::getInstance(hContact); if (ppro) - ppro->OnPrebuildContactMenu(wParam, lParam); + ppro->OnPrebuildContactMenu(hContact, lParam); else { Menu_ShowItem(hBlockMenuItem, false); Menu_ShowItem(hLiveSpaceMenuItem, false); diff --git a/protocols/MSN/src/msn_proto.h b/protocols/MSN/src/msn_proto.h index 511c311b0f..ece0e0d6a2 100644 --- a/protocols/MSN/src/msn_proto.h +++ b/protocols/MSN/src/msn_proto.h @@ -492,6 +492,11 @@ struct CMsnProto : public PROTO void setStringUtf(MCONTACT hContact, const char* name, const char* value); }; -extern OBJLIST g_Instances; +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN("MSN") + {} +}; #endif diff --git a/protocols/MinecraftDynmap/src/main.cpp b/protocols/MinecraftDynmap/src/main.cpp index 525a037711..3c39f05077 100644 --- a/protocols/MinecraftDynmap/src/main.cpp +++ b/protocols/MinecraftDynmap/src/main.cpp @@ -22,6 +22,7 @@ along with this program. If not, see . #include "stdafx.h" +CMPlugin g_plugin; CLIST_INTERFACE* pcli; int hLangpack; @@ -44,12 +45,6 @@ PLUGININFOEX pluginInfo = { ///////////////////////////////////////////////////////////////////////////// // Protocol instances -static int compare_protos(const MinecraftDynmapProto *p1, const MinecraftDynmapProto *p2) -{ - return wcscmp(p1->m_tszUserName, p2->m_tszUserName); -} - -OBJLIST g_Instances(1, compare_protos); DWORD WINAPI DllMain(HINSTANCE hInstance,DWORD,LPVOID) { @@ -114,27 +109,3 @@ extern "C" int __declspec(dllexport) Unload(void) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// - -static PROTO_INTERFACE* protoInit(const char *proto_name, const wchar_t *username) -{ - MinecraftDynmapProto *proto = new MinecraftDynmapProto(proto_name, username); - g_Instances.insert(proto); - return proto; -} - -static int protoUninit(PROTO_INTERFACE* proto) -{ - g_Instances.remove((MinecraftDynmapProto*)proto); - return EXIT_SUCCESS; -} - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase("MinecraftDynmap") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, protoInit, protoUninit); - } -} - g_plugin; diff --git a/protocols/MinecraftDynmap/src/proto.h b/protocols/MinecraftDynmap/src/proto.h index 15327988f5..15be7bac17 100644 --- a/protocols/MinecraftDynmap/src/proto.h +++ b/protocols/MinecraftDynmap/src/proto.h @@ -129,5 +129,11 @@ public: std::string m_timestamp; int m_interval; int m_updateRate; +}; +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN("MinecraftDynmap") + {} }; diff --git a/protocols/Omegle/src/main.cpp b/protocols/Omegle/src/main.cpp index 4d5cc3be73..d1226e7f6e 100644 --- a/protocols/Omegle/src/main.cpp +++ b/protocols/Omegle/src/main.cpp @@ -24,6 +24,7 @@ along with this program. If not, see . // TODO: Make following as "globals" structure? +CMPlugin g_plugin; CLIST_INTERFACE* pcli; int hLangpack; @@ -44,15 +45,6 @@ PLUGININFOEX pluginInfo = { { 0x9e1d9244, 0x606c, 0x4ef4, { 0x99, 0xa0, 0x1d, 0x7d, 0x23, 0xcb, 0x76, 0x1 } } }; -///////////////////////////////////////////////////////////////////////////// -// Protocol instances -static int compare_protos(const OmegleProto *p1, const OmegleProto *p2) -{ - return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName); -} - -OBJLIST g_Instances(1, compare_protos); - DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID) { g_hInstance = hInstance; @@ -117,28 +109,3 @@ extern "C" int __declspec(dllexport) Unload(void) return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// - -static PROTO_INTERFACE* protoInit(const char *proto_name, const wchar_t *username) -{ - OmegleProto *proto = new OmegleProto(proto_name, username); - g_Instances.insert(proto); - return proto; -} - -static int protoUninit(PROTO_INTERFACE* proto) -{ - g_Instances.remove((OmegleProto*)proto); - return EXIT_SUCCESS; -} - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase("Omegle") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, protoInit, protoUninit); - } -} - g_plugin; diff --git a/protocols/Omegle/src/proto.h b/protocols/Omegle/src/proto.h index 4eac66f67e..332746c792 100644 --- a/protocols/Omegle/src/proto.h +++ b/protocols/Omegle/src/proto.h @@ -84,11 +84,7 @@ public: void StopChat(bool disconnect = true); void NewChat(); - // Contacts handling - //bool IsMyContact(HANDLE, bool include_chat = false); - // Chat handling - void AddChat(const wchar_t *id, const wchar_t *name); void UpdateChat(const wchar_t *name, const wchar_t *message, bool addtochat = true); void SendChatMessage(std::string message); void AddChatContact(const wchar_t *nick); @@ -107,3 +103,10 @@ public: static void CALLBACK APC_callback(ULONG_PTR p); }; + +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN("Omegle") + {} +}; diff --git a/protocols/Omegle/src/theme.cpp b/protocols/Omegle/src/theme.cpp index 0dd1f6d27f..fa89da9717 100644 --- a/protocols/Omegle/src/theme.cpp +++ b/protocols/Omegle/src/theme.cpp @@ -22,8 +22,6 @@ along with this program. If not, see . #include "stdafx.h" -extern OBJLIST g_Instances; - static IconItem icons[] = { { LPGEN("Omegle Icon"), "omegle", IDI_OMEGLE }, diff --git a/protocols/Sametime/src/sametime.cpp b/protocols/Sametime/src/sametime.cpp index faebb0d6c3..f66a1fdddc 100644 --- a/protocols/Sametime/src/sametime.cpp +++ b/protocols/Sametime/src/sametime.cpp @@ -16,6 +16,7 @@ PLUGININFOEX pluginInfo = { 0xf1b0ba1b, 0xc91, 0x4313, { 0x85, 0xeb, 0x22, 0x50, 0x69, 0xd4, 0x4d, 0x1 } } // {F1B0BA1B-0C91-4313-85EB-225069D44D01} }; +CMPlugin g_plugin; CLIST_INTERFACE *pcli; HINSTANCE hInst; LIST g_Instances(1, PtrKeySortT); @@ -255,33 +256,5 @@ extern "C" int __declspec(dllexport) Load(void) extern "C" int __declspec(dllexport) Unload() { - g_Instances.destroy(); return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// - -static PROTO_INTERFACE* sametime_proto_init(const char* pszProtoName, const wchar_t* tszUserName) -{ - CSametimeProto* proto = new CSametimeProto(pszProtoName, tszUserName); - g_Instances.insert(proto); - return proto; -} - -static int sametime_proto_uninit(PROTO_INTERFACE* ppro) -{ - CSametimeProto* proto = (CSametimeProto*)ppro; - g_Instances.remove(proto); - delete proto; - return 0; -} - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase("Sametime") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, sametime_proto_init, sametime_proto_uninit); - } -} - g_plugin; diff --git a/protocols/Sametime/src/sametime.h b/protocols/Sametime/src/sametime.h index 2458028af0..f5da14c480 100644 --- a/protocols/Sametime/src/sametime.h +++ b/protocols/Sametime/src/sametime.h @@ -107,8 +107,6 @@ struct CSametimeProto; extern HINSTANCE hInst; extern PLUGININFOEX pluginInfo; -extern LIST g_Instances; - #include "sametime_proto.h" diff --git a/protocols/Sametime/src/sametime_proto.h b/protocols/Sametime/src/sametime_proto.h index 92170d575e..0742839875 100644 --- a/protocols/Sametime/src/sametime_proto.h +++ b/protocols/Sametime/src/sametime_proto.h @@ -143,9 +143,6 @@ struct CSametimeProto : public PROTO void InitPlaces(mwSession* session); void DeinitPlaces(mwSession* session); - - - /* properties */ char szProtoGroups[128]; @@ -196,7 +193,12 @@ struct CSametimeProto : public PROTO }; - +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN("Sametime") + {} +}; typedef struct tag_TFakeAckParams { CSametimeProto* proto; @@ -226,6 +228,4 @@ struct PopupData { CSametimeProto* proto; }; - #endif //#ifndef _SAMETIME_PROTO_H - diff --git a/protocols/SkypeWeb/src/main.cpp b/protocols/SkypeWeb/src/main.cpp index 678d2003a1..b7d5c38b26 100644 --- a/protocols/SkypeWeb/src/main.cpp +++ b/protocols/SkypeWeb/src/main.cpp @@ -17,6 +17,7 @@ along with this program. If not, see . #include "stdafx.h" +CMPlugin g_plugin; int hLangpack; HINSTANCE g_hInstance; CLIST_INTERFACE *pcli; @@ -91,15 +92,3 @@ int CSkypeProto::OnModulesLoaded(WPARAM, LPARAM) } return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase("SKYPE") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, (pfnInitProto)CSkypeProto::InitAccount, (pfnUninitProto)CSkypeProto::UninitAccount); - } -} - g_plugin; diff --git a/protocols/SkypeWeb/src/skype_accounts.cpp b/protocols/SkypeWeb/src/skype_accounts.cpp index 2016fac51c..9ab67acff8 100644 --- a/protocols/SkypeWeb/src/skype_accounts.cpp +++ b/protocols/SkypeWeb/src/skype_accounts.cpp @@ -17,38 +17,6 @@ along with this program. If not, see . #include "stdafx.h" -LIST CSkypeProto::Accounts(1, CSkypeProto::CompareAccounts); - -int CSkypeProto::CompareAccounts(const CSkypeProto *p1, const CSkypeProto *p2) -{ - return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName); -} - -CSkypeProto* CSkypeProto::InitAccount(const char *protoName, const wchar_t *userName) -{ - mir_cslock lck(accountsLock); - CSkypeProto *proto = new CSkypeProto(protoName, userName); - Accounts.insert(proto); - return proto; -} - -int CSkypeProto::UninitAccount(CSkypeProto *proto) -{ - mir_cslock lck(accountsLock); - Accounts.remove(proto); - delete proto; - return 0; -} - -CSkypeProto* CSkypeProto::GetContactAccount(MCONTACT hContact) -{ - mir_cslock lck(accountsLock); - for (auto &it : Accounts) - if (mir_strcmpi(GetContactProto(hContact), it->m_szModuleName) == 0) - return it; - return nullptr; -} - int CSkypeProto::OnAccountLoaded(WPARAM, LPARAM) { setAllContactStatuses(ID_STATUS_OFFLINE, true); diff --git a/protocols/SkypeWeb/src/skype_menus.cpp b/protocols/SkypeWeb/src/skype_menus.cpp index 55c4a4288f..5811ab33da 100644 --- a/protocols/SkypeWeb/src/skype_menus.cpp +++ b/protocols/SkypeWeb/src/skype_menus.cpp @@ -48,7 +48,7 @@ int CSkypeProto::PrebuildContactMenu(WPARAM hContact, LPARAM lParam) { for (auto &it : ContactMenuItems) Menu_ShowItem(it, false); - CSkypeProto *proto = CSkypeProto::GetContactAccount(hContact); + CSkypeProto *proto = CMPlugin::getInstance(hContact); return proto ? proto->OnPrebuildContactMenu(hContact, lParam) : 0; } diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 5bdd124995..3584fde7c4 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -55,10 +55,6 @@ public: virtual HANDLE __cdecl GetAwayMsg(MCONTACT hContact); virtual int __cdecl SetAwayMsg(int m_iStatus, const wchar_t *msg); - // accounts - static CSkypeProto* InitAccount(const char *protoName, const wchar_t *userName); - static int UninitAccount(CSkypeProto *proto); - // icons static void InitIcons(); @@ -123,11 +119,6 @@ private: static UINT_PTR m_timer; - //---Accounts - static LIST CSkypeProto::Accounts; - static int CompareAccounts(const CSkypeProto *p1, const CSkypeProto *p2); - //---/ - RequestQueue *requestQueue; bool m_bHistorySynced; @@ -165,7 +156,6 @@ private: EventHandle m_hTrouterHealthEvent; - static CSkypeProto* GetContactAccount(MCONTACT hContact); int __cdecl OnAccountLoaded(WPARAM, LPARAM); INT_PTR __cdecl OnAccountManagerInit(WPARAM, LPARAM); @@ -427,9 +417,16 @@ private: template static INT_PTR __cdecl GlobalService(WPARAM wParam, LPARAM lParam) { - CSkypeProto *proto = GetContactAccount((MCONTACT)wParam); + CSkypeProto *proto = CMPlugin::getInstance((MCONTACT)wParam); return proto ? (proto->*Service)(wParam, lParam) : 0; } }; +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN("SKYPE") + {} +}; + #endif //_SKYPE_PROTO_H_ \ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_timers.cpp b/protocols/SkypeWeb/src/skype_timers.cpp index 7004188d76..3e5a5e8446 100644 --- a/protocols/SkypeWeb/src/skype_timers.cpp +++ b/protocols/SkypeWeb/src/skype_timers.cpp @@ -31,7 +31,7 @@ void CSkypeProto::ProcessTimer() void CALLBACK CSkypeProto::TimerProc(HWND, UINT, UINT_PTR, DWORD) { mir_cslock lck(accountsLock); - for (auto &it : Accounts) + for (auto &it : CMPlugin::g_arInstances) it->ProcessTimer(); } @@ -45,7 +45,7 @@ void CSkypeProto::SkypeSetTimer() void CSkypeProto::SkypeUnsetTimer() { mir_cslock lck(timerLock); - if (m_timer && Accounts.getCount() == 0) + if (m_timer && CMPlugin::g_arInstances.getCount() == 0) KillTimer(nullptr, m_timer); m_timer = 0; } diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index 6350b40c8c..ffed1601de 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -593,7 +593,7 @@ INT_PTR CSkypeProto::ParseSkypeUriService(WPARAM, LPARAM lParam) INT_PTR CSkypeProto::GlobalParseSkypeUriService(WPARAM wParam, LPARAM lParam) { mir_cslock lck(accountsLock); - for (auto &it : Accounts) + for (auto &it : CMPlugin::g_arInstances) if (it->IsOnline()) return it->ParseSkypeUriService(wParam, lParam); diff --git a/protocols/Steam/src/main.cpp b/protocols/Steam/src/main.cpp index 57632115d9..7464db16e2 100644 --- a/protocols/Steam/src/main.cpp +++ b/protocols/Steam/src/main.cpp @@ -2,6 +2,7 @@ int hLangpack; HINSTANCE g_hInstance; +CMPlugin g_plugin; HANDLE hExtraXStatus; @@ -52,15 +53,3 @@ extern "C" int __declspec(dllexport) Unload(void) { return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase("STEAM") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, (pfnInitProto)CSteamProto::InitAccount, (pfnUninitProto)CSteamProto::UninitAccount); - } -} - g_plugin; diff --git a/protocols/Steam/src/steam_accounts.cpp b/protocols/Steam/src/steam_accounts.cpp deleted file mode 100644 index 8fedcc6181..0000000000 --- a/protocols/Steam/src/steam_accounts.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "stdafx.h" - -LIST CSteamProto::Accounts(1, CSteamProto::CompareProtos); - -int CSteamProto::CompareProtos(const CSteamProto *p1, const CSteamProto *p2) -{ - return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName); -} - -CSteamProto* CSteamProto::InitAccount(const char* protoName, const wchar_t* userName) -{ - CSteamProto *ppro = new CSteamProto(protoName, userName); - Accounts.insert(ppro); - return ppro; -} - -int CSteamProto::UninitAccount(CSteamProto* ppro) -{ - Accounts.remove(ppro); - delete ppro; - return 0; -} - -CSteamProto* CSteamProto::GetContactAccount(MCONTACT hContact) -{ - char *proto = GetContactProto(hContact); - if (proto == nullptr) - return nullptr; - - for (auto &it : Accounts) - if (!mir_strcmp(proto, it->m_szModuleName)) - return it; - - return nullptr; -} \ No newline at end of file diff --git a/protocols/Steam/src/steam_menus.cpp b/protocols/Steam/src/steam_menus.cpp index 30b6550293..40f84551d1 100644 --- a/protocols/Steam/src/steam_menus.cpp +++ b/protocols/Steam/src/steam_menus.cpp @@ -4,10 +4,10 @@ int CSteamProto::hChooserMenu; HGENMENU CSteamProto::contactMenuItems[CMI_MAX]; template -INT_PTR GlobalService(WPARAM wParam, LPARAM lParam) +INT_PTR GlobalService(WPARAM hContact, LPARAM lParam) { - CSteamProto *ppro = CSteamProto::GetContactAccount((MCONTACT)wParam); - return ppro ? (ppro->*Service)(wParam, lParam) : 0; + CSteamProto *ppro = CMPlugin::getInstance((MCONTACT)hContact); + return ppro ? (ppro->*Service)(hContact, lParam) : 0; } INT_PTR CSteamProto::AuthRequestCommand(WPARAM hContact, LPARAM) @@ -81,9 +81,8 @@ INT_PTR CSteamProto::OpenBlockListCommand(WPARAM, LPARAM) return 0; } -int CSteamProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM) +int CSteamProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM) { - MCONTACT hContact = (MCONTACT)wParam; if (!hContact) return 0; @@ -106,13 +105,13 @@ int CSteamProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM) return 0; } -int CSteamProto::PrebuildContactMenu(WPARAM wParam, LPARAM lParam) +int CSteamProto::PrebuildContactMenu(WPARAM hContact, LPARAM lParam) { for (int i = 0; i < CMI_MAX; i++) Menu_ShowItem(CSteamProto::contactMenuItems[i], false); - CSteamProto* ppro = CSteamProto::GetContactAccount((MCONTACT)wParam); - return (ppro) ? ppro->OnPrebuildContactMenu(wParam, lParam) : 0; + CSteamProto* ppro = CMPlugin::getInstance((MCONTACT)hContact); + return (ppro) ? ppro->OnPrebuildContactMenu(hContact, lParam) : 0; } void CSteamProto::OnInitStatusMenu() diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 1f41dfec84..93e8aca4be 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -75,12 +75,6 @@ public: virtual int __cdecl OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam); - // instances - static CSteamProto* InitAccount(const char* protoName, const wchar_t *userName); - static int UninitAccount(CSteamProto* ppro); - - static CSteamProto* GetContactAccount(MCONTACT hContact); - // menus static void InitMenus(); @@ -110,10 +104,6 @@ protected: */ time_t m_lastMessageTS; - // instances - static LIST Accounts; - static int CompareProtos(const CSteamProto *p1, const CSteamProto *p2); - // requests void SendRequest(HttpRequest *request); void SendRequest(HttpRequest *request, HttpCallback callback, void *param = nullptr); @@ -284,6 +274,13 @@ protected: } }; +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN("STEAM") + {} +}; + int OnReloadIcons(WPARAM wParam, LPARAM lParam); void SetContactExtraIcon(MCONTACT hContact, int status); diff --git a/protocols/Tox/src/main.cpp b/protocols/Tox/src/main.cpp index 8cf2c4b80d..9022f56569 100644 --- a/protocols/Tox/src/main.cpp +++ b/protocols/Tox/src/main.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" int hLangpack; +CMPlugin g_plugin; CHAT_MANAGER *pci; CLIST_INTERFACE *pcli; HINSTANCE g_hInstance; @@ -63,15 +64,3 @@ extern "C" int __declspec(dllexport) Unload(void) { return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase("TOX") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, (pfnInitProto)CToxProto::InitAccount, (pfnUninitProto)CToxProto::UninitAccount); - } -} - g_plugin; diff --git a/protocols/Tox/src/tox_accounts.cpp b/protocols/Tox/src/tox_accounts.cpp index d70d6bad54..c9cb35c921 100644 --- a/protocols/Tox/src/tox_accounts.cpp +++ b/protocols/Tox/src/tox_accounts.cpp @@ -1,35 +1,5 @@ #include "stdafx.h" -LIST CToxProto::Accounts(1, CToxProto::CompareAccounts); - -int CToxProto::CompareAccounts(const CToxProto *p1, const CToxProto *p2) -{ - return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName); -} - -CToxProto* CToxProto::InitAccount(const char *protoName, const wchar_t *userName) -{ - CToxProto *proto = new CToxProto(protoName, userName); - Accounts.insert(proto); - return proto; -} - -int CToxProto::UninitAccount(CToxProto *proto) -{ - Accounts.remove(proto); - delete proto; - return 0; -} - -CToxProto* CToxProto::GetContactAccount(MCONTACT hContact) -{ - for (auto &it : Accounts) - if (mir_strcmpi(GetContactProto(hContact), it->m_szModuleName) == 0) - return it; - - return nullptr; -} - int CToxProto::OnAccountLoaded(WPARAM, LPARAM) { Clist_GroupCreate(0, m_defaultGroup); diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 8a4fd782cd..ac71b30686 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -48,10 +48,6 @@ public: virtual int __cdecl OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam); - // accounts - static CToxProto* InitAccount(const char *protoName, const wchar_t *userName); - static int UninitAccount(CToxProto *proto); - // icons static void InitIcons(); @@ -116,11 +112,6 @@ private: void __cdecl PollingThread(void*); // accounts - static LIST Accounts; - static int CompareAccounts(const CToxProto *p1, const CToxProto *p2); - - static CToxProto* GetContactAccount(MCONTACT hContact); - int __cdecl OnAccountLoaded(WPARAM, LPARAM); int __cdecl OnAccountRenamed(WPARAM, LPARAM); @@ -256,4 +247,11 @@ private: MEVENT AddEventToDb(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, PBYTE pBlob, size_t cbBlob); }; +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN("TOX") + {} +}; + #endif //_TOX_PROTO_H_ \ No newline at end of file diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index d7c2d1408b..231a2b2106 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -146,11 +146,11 @@ INT_PTR CToxProto::ParseToxUri(WPARAM, LPARAM lParam) if (mir_wstrlen(uri) <= 4) return 1; - if (Accounts.getCount() == 0) + if (CMPlugin::g_arInstances.getCount() == 0) return 1; CToxProto *proto = nullptr; - for (auto &it : Accounts) { + for (auto &it : CMPlugin::g_arInstances) { if (it->IsOnline()) { proto = it; break; diff --git a/protocols/Twitter/src/main.cpp b/protocols/Twitter/src/main.cpp index a4e714ba7e..14e91dc39e 100644 --- a/protocols/Twitter/src/main.cpp +++ b/protocols/Twitter/src/main.cpp @@ -22,6 +22,7 @@ along with this program. If not, see . #include "proto.h" #include "theme.h" +CMPlugin g_plugin; CLIST_INTERFACE* pcli; HINSTANCE g_hInstance; @@ -40,16 +41,6 @@ PLUGININFOEX pluginInfo = { { 0xbc09a71b, 0xb86e, 0x4d33, { 0xb1, 0x8d, 0x82, 0xd3, 0x4, 0x51, 0xdd, 0x3c } } }; -///////////////////////////////////////////////////////////////////////////// -// Protocol instances - -static int compare_protos(const TwitterProto *p1, const TwitterProto *p2) -{ - return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName); -} - -OBJLIST g_Instances(1, compare_protos); - DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID) { g_hInstance = hInstance; @@ -87,28 +78,3 @@ extern "C" int __declspec(dllexport) Unload(void) { return 0; } - -///////////////////////////////////////////////////////////////////////////////////////// - -static PROTO_INTERFACE* protoInit(const char *proto_name, const wchar_t *username) -{ - TwitterProto *proto = new TwitterProto(proto_name, username); - g_Instances.insert(proto); - return proto; -} - -static int protoUninit(PROTO_INTERFACE *proto) -{ - g_Instances.remove(static_cast(proto)); - return 0; -} - -struct CMPlugin : public CMPluginBase -{ - CMPlugin() : - CMPluginBase("Twitter") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, protoInit, protoUninit); - } -} - g_plugin; diff --git a/protocols/Twitter/src/proto.h b/protocols/Twitter/src/proto.h index 46facedcc2..a73b5caacc 100644 --- a/protocols/Twitter/src/proto.h +++ b/protocols/Twitter/src/proto.h @@ -129,6 +129,13 @@ private: wstring AuthorizeUrl; }; +struct CMPlugin : public ACCPROTOPLUGIN +{ + CMPlugin() : + ACCPROTOPLUGIN("Twitter") + {} +}; + // TODO: remove this inline std::string profile_base_url(const std::string &url) { diff --git a/protocols/Twitter/src/theme.cpp b/protocols/Twitter/src/theme.cpp index ca6338edc7..75c5252f34 100644 --- a/protocols/Twitter/src/theme.cpp +++ b/protocols/Twitter/src/theme.cpp @@ -20,8 +20,6 @@ along with this program. If not, see . #include "theme.h" #include "proto.h" -extern OBJLIST g_Instances; - static IconItem icons[] = { { LPGEN("Twitter Icon"), "twitter", IDI_TWITTER }, @@ -57,32 +55,20 @@ HANDLE GetIconHandle(const char *name) static HGENMENU g_hMenuItems[2]; // Helper functions -static TwitterProto* GetInstanceByHContact(MCONTACT hContact) -{ - char *proto = GetContactProto(hContact); - if (!proto) - return nullptr; - - for (auto &it : g_Instances) - if (!mir_strcmp(proto, it->m_szModuleName)) - return it; - - return nullptr; -} template -INT_PTR GlobalService(WPARAM wParam, LPARAM lParam) +INT_PTR GlobalService(WPARAM hContact, LPARAM lParam) { - TwitterProto *proto = GetInstanceByHContact(MCONTACT(wParam)); - return proto ? (proto->*Fcn)(wParam, lParam) : 0; + TwitterProto *proto = CMPlugin::getInstance(MCONTACT(hContact)); + return proto ? (proto->*Fcn)(hContact, lParam) : 0; } -static int PrebuildContactMenu(WPARAM wParam, LPARAM lParam) +static int PrebuildContactMenu(WPARAM hContact, LPARAM lParam) { ShowContactMenus(false); - TwitterProto *proto = GetInstanceByHContact(MCONTACT(wParam)); - return proto ? proto->OnPrebuildContactMenu(wParam, lParam) : 0; + TwitterProto *proto = CMPlugin::getInstance(MCONTACT(hContact)); + return proto ? proto->OnPrebuildContactMenu(hContact, lParam) : 0; } void InitContactMenus() diff --git a/protocols/VKontakte/src/main.cpp b/protocols/VKontakte/src/main.cpp index 1db46892eb..8516360ba0 100644 --- a/protocols/VKontakte/src/main.cpp +++ b/protocols/VKontakte/src/main.cpp @@ -73,24 +73,10 @@ extern "C" int __declspec(dllexport) Unload(void) ///////////////////////////////////////////////////////////////////////////////////////// -static PROTO_INTERFACE* protoInit(const char *pszProtoName, const wchar_t *wszUserName) -{ - CVkProto *ppro = new CVkProto(pszProtoName, wszUserName); - return ppro; -} - -static int protoUninit(PROTO_INTERFACE *ppro) -{ - delete (CVkProto*)ppro; - return 0; -} - -struct CMPlugin : public CMPluginBase +struct CMPlugin : public ACCPROTOPLUGIN { CMPlugin() : - CMPluginBase("VKontakte") - { - RegisterProtocol(PROTOTYPE_PROTOCOL, protoInit, protoUninit); - } + ACCPROTOPLUGIN("VKontakte") + {} } g_plugin; -- cgit v1.2.3