summaryrefslogtreecommitdiff
path: root/src/mir_app
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-06-14 18:49:20 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-06-14 18:49:20 +0300
commit6d1d7cdc32568724e21bc68a4ab3370588a6c30a (patch)
tree57e23ea4f267eb335efdb84e5d5f0e32295b587a /src/mir_app
parentad0922106e6750e3beece0150c79c41fb32f9e90 (diff)
Proto_GetInstance: handy helper to obtain PROTO_INTERFACE for a hContact / szModule
Diffstat (limited to 'src/mir_app')
-rw-r--r--src/mir_app/mir_app.vcxproj1
-rw-r--r--src/mir_app/mir_app.vcxproj.filters3
-rw-r--r--src/mir_app/src/mir_app.def3
-rw-r--r--src/mir_app/src/mir_app64.def3
-rw-r--r--src/mir_app/src/proto_accs.cpp12
-rw-r--r--src/mir_app/src/proto_interface.cpp320
-rw-r--r--src/mir_app/src/proto_utils.cpp318
-rw-r--r--src/mir_app/src/protocols.cpp91
8 files changed, 401 insertions, 350 deletions
diff --git a/src/mir_app/mir_app.vcxproj b/src/mir_app/mir_app.vcxproj
index ccd5d38f05..3c7ca84a6f 100644
--- a/src/mir_app/mir_app.vcxproj
+++ b/src/mir_app/mir_app.vcxproj
@@ -133,6 +133,7 @@
<ClCompile Include="src\protocols.cpp" />
<ClCompile Include="src\proto_accs.cpp" />
<ClCompile Include="src\proto_chains.cpp" />
+ <ClCompile Include="src\proto_interface.cpp" />
<ClCompile Include="src\proto_internal.cpp" />
<ClCompile Include="src\proto_opts.cpp" />
<ClCompile Include="src\proto_order.cpp" />
diff --git a/src/mir_app/mir_app.vcxproj.filters b/src/mir_app/mir_app.vcxproj.filters
index 3864ed1ace..8dbf493879 100644
--- a/src/mir_app/mir_app.vcxproj.filters
+++ b/src/mir_app/mir_app.vcxproj.filters
@@ -383,6 +383,9 @@
<ClCompile Include="src\visibility.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\proto_interface.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\chat.h">
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index c97af5c615..bcd2992d42 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -735,3 +735,6 @@ ProtoBroadcastAsync @814 NONAME
?EventCursor@MDatabaseCommon@@UAGPAV0DB@@II@Z @822 NONAME
?EventCursorRev@MDatabaseCommon@@UAGPAVEventCursor@DB@@II@Z @823 NONAME
Chat_CreateMenu @824 NONAME
+?PasteFilesAsURL@CSrmmBaseDialog@@IAE_NPAUHDROP__@@@Z @825 NONAME
+?Proto_GetInstance@@YGPAUPROTO_INTERFACE@@I@Z @826 NONAME
+?Proto_GetInstance@@YGPAUPROTO_INTERFACE@@PBD@Z @827 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index 2f2c292b58..e7833f4d48 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -735,3 +735,6 @@ ProtoBroadcastAsync @814 NONAME
?EventCursor@MDatabaseCommon@@UEAAPEAV0DB@@II@Z @822 NONAME
?EventCursorRev@MDatabaseCommon@@UEAAPEAVEventCursor@DB@@II@Z @823 NONAME
Chat_CreateMenu @824 NONAME
+?PasteFilesAsURL@CSrmmBaseDialog@@IEAA_NPEAUHDROP__@@@Z @825 NONAME
+?Proto_GetInstance@@YAPEAUPROTO_INTERFACE@@I@Z @826 NONAME
+?Proto_GetInstance@@YAPEAUPROTO_INTERFACE@@PEBD@Z @827 NONAME
diff --git a/src/mir_app/src/proto_accs.cpp b/src/mir_app/src/proto_accs.cpp
index e3fe8d0f3c..e3005c4cd7 100644
--- a/src/mir_app/src/proto_accs.cpp
+++ b/src/mir_app/src/proto_accs.cpp
@@ -152,11 +152,8 @@ void WriteDbAccounts()
static int OnContactDeleted(WPARAM hContact, LPARAM)
{
- if (hContact) {
- PROTOACCOUNT *pa = Proto_GetAccount(hContact);
- if (pa->IsEnabled() && pa->ppro)
- pa->ppro->OnContactDeleted(hContact);
- }
+ if (auto *ppro = Proto_GetInstance(hContact))
+ ppro->OnContactDeleted(hContact);
return 0;
}
@@ -172,9 +169,10 @@ static int InitializeStaticAccounts(WPARAM, LPARAM)
if (!pa->bOldProto)
count++;
- }
- BuildProtoMenus();
+ if (pa->IsVisible())
+ pa->ppro->OnBuildProtoMenu();
+ }
if (count == 0 && !db_get_b(0, "FirstRun", "AccManager", 0)) {
db_set_b(0, "FirstRun", "AccManager", 1);
diff --git a/src/mir_app/src/proto_interface.cpp b/src/mir_app/src/proto_interface.cpp
new file mode 100644
index 0000000000..8a917ad694
--- /dev/null
+++ b/src/mir_app/src/proto_interface.cpp
@@ -0,0 +1,320 @@
+/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright (C) 2012-20 Miranda NG team,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "stdafx.h"
+
+static HGENMENU hReqAuth = nullptr, hGrantAuth = nullptr, hRevokeAuth = nullptr;
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// protocol constructor & destructor
+
+PROTO_INTERFACE::PROTO_INTERFACE(const char *pszModuleName, const wchar_t *ptszUserName)
+{
+ m_iVersion = 2;
+ m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
+ m_szModuleName = mir_strdup(pszModuleName);
+ m_tszUserName = mir_wstrdup(ptszUserName);
+ db_set_resident(m_szModuleName, "Status");
+
+ m_hmiReqAuth = hReqAuth;
+ m_hmiGrantAuth = hGrantAuth;
+ m_hmiRevokeAuth = hRevokeAuth;
+}
+
+PROTO_INTERFACE::~PROTO_INTERFACE()
+{
+ if (m_hNetlibUser)
+ Netlib_CloseHandle(m_hNetlibUser);
+
+ mir_free(m_szModuleName);
+ mir_free(m_tszUserName);
+
+ WindowList_Destroy(m_hWindowList);
+}
+
+void PROTO_INTERFACE::OnBuildProtoMenu()
+{}
+
+void PROTO_INTERFACE::OnContactDeleted(MCONTACT)
+{}
+
+void PROTO_INTERFACE::OnErase()
+{}
+
+void PROTO_INTERFACE::OnModulesLoaded()
+{}
+
+bool PROTO_INTERFACE::IsReadyToExit()
+{
+ return true;
+}
+
+void PROTO_INTERFACE::OnShutdown()
+{}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// default PROTO_INTERFACE method implementations
+
+MCONTACT PROTO_INTERFACE::AddToList(int, PROTOSEARCHRESULT*)
+{
+ return 0; // error
+}
+
+MCONTACT PROTO_INTERFACE::AddToListByEvent(int, int, MEVENT)
+{
+ return 0; // error
+}
+
+int PROTO_INTERFACE::Authorize(MEVENT)
+{
+ return 1; // error
+}
+
+int PROTO_INTERFACE::AuthDeny(MEVENT, const wchar_t*)
+{
+ return 1; // error
+}
+
+int PROTO_INTERFACE::AuthRecv(MCONTACT, PROTORECVEVENT*)
+{
+ return 1; // error
+}
+
+int PROTO_INTERFACE::AuthRequest(MCONTACT, const wchar_t*)
+{
+ return 1; // error
+}
+
+HANDLE PROTO_INTERFACE::FileAllow(MCONTACT, HANDLE, const wchar_t*)
+{
+ return nullptr; // error
+}
+
+int PROTO_INTERFACE::FileCancel(MCONTACT, HANDLE)
+{
+ return 1; // error
+}
+
+int PROTO_INTERFACE::FileDeny(MCONTACT, HANDLE, const wchar_t*)
+{
+ return 1; // error
+}
+
+int PROTO_INTERFACE::FileResume(HANDLE, int, const wchar_t*)
+{
+ return 1; // error
+}
+
+INT_PTR PROTO_INTERFACE::GetCaps(int, MCONTACT)
+{
+ return 0; // empty value
+}
+
+int PROTO_INTERFACE::GetInfo(MCONTACT, int)
+{
+ return 1; // error
+}
+
+HANDLE PROTO_INTERFACE::SearchBasic(const wchar_t*)
+{
+ return nullptr; // error
+}
+
+HANDLE PROTO_INTERFACE::SearchByEmail(const wchar_t*)
+{
+ return nullptr; // error
+}
+
+HANDLE PROTO_INTERFACE::SearchByName(const wchar_t*, const wchar_t*, const wchar_t*)
+{
+ return nullptr; // error
+}
+
+HWND PROTO_INTERFACE::SearchAdvanced(HWND)
+{
+ return nullptr; // error
+}
+
+HWND PROTO_INTERFACE::CreateExtendedSearchUI(HWND)
+{
+ return nullptr; // error
+}
+
+int PROTO_INTERFACE::RecvContacts(MCONTACT, PROTORECVEVENT*)
+{
+ return 1; // error
+}
+
+int PROTO_INTERFACE::RecvFile(MCONTACT hContact, PROTORECVFILE *pcre)
+{
+ CCSDATA ccs = { hContact, PSR_FILE, 0, (LPARAM)pcre };
+ return CallService(MS_PROTO_RECVFILET, 0, (LPARAM)&ccs);
+}
+
+MEVENT PROTO_INTERFACE::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre)
+{
+ if (pre->szMessage == nullptr)
+ return 0;
+
+ ptrA pszTemp;
+ mir_ptr<BYTE> pszBlob;
+
+ DBEVENTINFO dbei = {};
+ dbei.flags = DBEF_UTF;
+ dbei.szModule = Proto_GetBaseAccountName(hContact);
+ dbei.timestamp = pre->timestamp;
+ dbei.eventType = EVENTTYPE_MESSAGE;
+ dbei.cbBlob = (DWORD)mir_strlen(pre->szMessage) + 1;
+ dbei.pBlob = (PBYTE)pre->szMessage;
+
+ if (pre->flags & PREF_CREATEREAD)
+ dbei.flags |= DBEF_READ;
+ if (pre->flags & PREF_SENT)
+ dbei.flags |= DBEF_SENT;
+
+ // if it's possible to find an existing event by its id, do that
+ if ((GetCaps(PFLAGNUM_4) & PF4_SERVERMSGID) && pre->szMsgId != nullptr) {
+ MEVENT hDbEvent = db_event_getById(m_szModuleName, pre->szMsgId);
+ if (hDbEvent == 0 || db_event_edit(hContact, hDbEvent, &dbei)) {
+ hDbEvent = db_event_add(hContact, &dbei);
+ if (hDbEvent)
+ db_event_setId(m_szModuleName, hDbEvent, pre->szMsgId);
+ }
+
+ return hDbEvent;
+ }
+
+ // event is new? add it
+ return (INT_PTR)db_event_add(hContact, &dbei);
+}
+
+int PROTO_INTERFACE::SendContacts(MCONTACT, int, int, MCONTACT*)
+{
+ return 1; // error
+}
+
+HANDLE PROTO_INTERFACE::SendFile(MCONTACT, const wchar_t*, wchar_t**)
+{
+ return nullptr; // error
+}
+
+int PROTO_INTERFACE::SendMsg(MCONTACT, int, const char*)
+{
+ return 0; // error
+}
+
+int PROTO_INTERFACE::SetApparentMode(MCONTACT, int)
+{
+ return 1; // error
+}
+
+int PROTO_INTERFACE::SetStatus(int)
+{
+ return 1; // you better declare it
+}
+
+HANDLE PROTO_INTERFACE::GetAwayMsg(MCONTACT)
+{
+ return nullptr; // no away message
+}
+
+int PROTO_INTERFACE::RecvAwayMsg(MCONTACT, int, PROTORECVEVENT*)
+{
+ return 1; // error
+}
+
+int PROTO_INTERFACE::SetAwayMsg(int, const wchar_t*)
+{
+ return 1; // error
+}
+
+int PROTO_INTERFACE::UserIsTyping(MCONTACT, int)
+{
+ return 1; // error
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// protocol menus
+
+static INT_PTR __cdecl stubRequestAuth(WPARAM hContact, LPARAM)
+{
+ const char *szProto = Proto_GetBaseAccountName(hContact);
+ if (szProto)
+ ProtoCallService(szProto, PS_MENU_REQAUTH, hContact, 0);
+ return 0;
+}
+
+static INT_PTR __cdecl stubGrantAuth(WPARAM hContact, LPARAM)
+{
+ const char *szProto = Proto_GetBaseAccountName(hContact);
+ if (szProto)
+ ProtoCallService(szProto, PS_MENU_GRANTAUTH, hContact, 0);
+ return 0;
+}
+
+static INT_PTR __cdecl stubRevokeAuth(WPARAM hContact, LPARAM)
+{
+ const char *szProto = Proto_GetBaseAccountName(hContact);
+ if (szProto)
+ ProtoCallService(szProto, PS_MENU_REVOKEAUTH, hContact, 0);
+ return 0;
+}
+
+static int __cdecl ProtoPrebuildContactMenu(WPARAM, LPARAM)
+{
+ Menu_ShowItem(hReqAuth, false);
+ Menu_ShowItem(hGrantAuth, false);
+ Menu_ShowItem(hRevokeAuth, false);
+ return 0;
+}
+
+void InitProtoMenus(void)
+{
+ // "Request authorization"
+ CMenuItem mi(&g_plugin);
+ SET_UID(mi, 0x36375a1f, 0xc142, 0x4d6e, 0xa6, 0x57, 0xe4, 0x76, 0x5d, 0xbc, 0x59, 0x8e);
+ mi.pszService = "Proto/Menu/ReqAuth";
+ mi.name.a = LPGEN("Request authorization");
+ mi.position = -2000001002;
+ mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_REQUEST);
+ hReqAuth = Menu_AddContactMenuItem(&mi);
+ CreateServiceFunction(mi.pszService, stubRequestAuth);
+
+ // "Grant authorization"
+ SET_UID(mi, 0x4c90452a, 0x869a, 0x4a81, 0xaf, 0xa8, 0x28, 0x34, 0xaf, 0x2b, 0x6b, 0x30);
+ mi.pszService = "Proto/Menu/GrantAuth";
+ mi.name.a = LPGEN("Grant authorization");
+ mi.position = -2000001001;
+ mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_GRANT);
+ hGrantAuth = Menu_AddContactMenuItem(&mi);
+
+ // "Revoke authorization"
+ SET_UID(mi, 0x619efdcb, 0x99c0, 0x44a8, 0xbf, 0x28, 0xc3, 0xe0, 0x2f, 0xb3, 0x7e, 0x77);
+ mi.pszService = "Proto/Menu/RevokeAuth";
+ mi.name.a = LPGEN("Revoke authorization");
+ mi.position = -2000001000;
+ mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_REVOKE);
+ hRevokeAuth = Menu_AddContactMenuItem(&mi);
+
+ HookEvent(ME_CLIST_PREBUILDCONTACTMENU, ProtoPrebuildContactMenu);
+}
diff --git a/src/mir_app/src/proto_utils.cpp b/src/mir_app/src/proto_utils.cpp
index ea34ddbed2..771ebc9cff 100644
--- a/src/mir_app/src/proto_utils.cpp
+++ b/src/mir_app/src/proto_utils.cpp
@@ -52,6 +52,28 @@ MIR_APP_DLL(PROTOCOLDESCRIPTOR*) Proto_IsProtocolLoaded(const char *szProtoName)
/////////////////////////////////////////////////////////////////////////////////////////
+MIR_APP_DLL(PROTO_INTERFACE *) Proto_GetInstance(MCONTACT hContact)
+{
+ PROTOACCOUNT *pa = Proto_GetAccount(hContact);
+ if (pa == nullptr || pa->bOldProto)
+ return nullptr;
+
+ PROTO_INTERFACE *ppi = pa->ppro;
+ return (ppi != nullptr && ppi->m_iVersion > 1) ? ppi : nullptr;
+}
+
+MIR_APP_DLL(PROTO_INTERFACE *) Proto_GetInstance(const char *szModule)
+{
+ PROTOACCOUNT *pa = Proto_GetAccount(szModule);
+ if (pa == nullptr || pa->bOldProto)
+ return nullptr;
+
+ PROTO_INTERFACE *ppi = pa->ppro;
+ return (ppi != nullptr && ppi->m_iVersion > 1) ? ppi : nullptr;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
MIR_APP_DLL(void) Proto_EnumProtocols(int *nProtos, PROTOCOLDESCRIPTOR ***pProtos)
{
if (nProtos) *nProtos = g_arProtos.getCount();
@@ -98,121 +120,6 @@ void PROTO_INTERFACE::setAllContactStatuses(int iStatus, bool bSkipChats)
}
/////////////////////////////////////////////////////////////////////////////////////////
-// protocol menus
-
-static HGENMENU hReqAuth = nullptr, hGrantAuth = nullptr, hRevokeAuth = nullptr;
-
-static INT_PTR __cdecl stubRequestAuth(WPARAM hContact, LPARAM)
-{
- const char *szProto = Proto_GetBaseAccountName(hContact);
- if (szProto)
- ProtoCallService(szProto, PS_MENU_REQAUTH, hContact, 0);
- return 0;
-}
-
-static INT_PTR __cdecl stubGrantAuth(WPARAM hContact, LPARAM)
-{
- const char *szProto = Proto_GetBaseAccountName(hContact);
- if (szProto)
- ProtoCallService(szProto, PS_MENU_GRANTAUTH, hContact, 0);
- return 0;
-}
-
-static INT_PTR __cdecl stubRevokeAuth(WPARAM hContact, LPARAM)
-{
- const char *szProto = Proto_GetBaseAccountName(hContact);
- if (szProto)
- ProtoCallService(szProto, PS_MENU_REVOKEAUTH, hContact, 0);
- return 0;
-}
-
-static int __cdecl ProtoPrebuildContactMenu(WPARAM, LPARAM)
-{
- Menu_ShowItem(hReqAuth, false);
- Menu_ShowItem(hGrantAuth, false);
- Menu_ShowItem(hRevokeAuth, false);
- return 0;
-}
-
-void InitProtoMenus(void)
-{
- // "Request authorization"
- CMenuItem mi(&g_plugin);
- SET_UID(mi, 0x36375a1f, 0xc142, 0x4d6e, 0xa6, 0x57, 0xe4, 0x76, 0x5d, 0xbc, 0x59, 0x8e);
- mi.pszService = "Proto/Menu/ReqAuth";
- mi.name.a = LPGEN("Request authorization");
- mi.position = -2000001002;
- mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_REQUEST);
- hReqAuth = Menu_AddContactMenuItem(&mi);
- CreateServiceFunction(mi.pszService, stubRequestAuth);
-
- // "Grant authorization"
- SET_UID(mi, 0x4c90452a, 0x869a, 0x4a81, 0xaf, 0xa8, 0x28, 0x34, 0xaf, 0x2b, 0x6b, 0x30);
- mi.pszService = "Proto/Menu/GrantAuth";
- mi.name.a = LPGEN("Grant authorization");
- mi.position = -2000001001;
- mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_GRANT);
- hGrantAuth = Menu_AddContactMenuItem(&mi);
-
- // "Revoke authorization"
- SET_UID(mi, 0x619efdcb, 0x99c0, 0x44a8, 0xbf, 0x28, 0xc3, 0xe0, 0x2f, 0xb3, 0x7e, 0x77);
- mi.pszService = "Proto/Menu/RevokeAuth";
- mi.name.a = LPGEN("Revoke authorization");
- mi.position = -2000001000;
- mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_REVOKE);
- hRevokeAuth = Menu_AddContactMenuItem(&mi);
-
- HookEvent(ME_CLIST_PREBUILDCONTACTMENU, ProtoPrebuildContactMenu);
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// protocol constructor & destructor
-
-PROTO_INTERFACE::PROTO_INTERFACE(const char *pszModuleName, const wchar_t *ptszUserName)
-{
- m_iVersion = 2;
- m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
- m_szModuleName = mir_strdup(pszModuleName);
- m_tszUserName = mir_wstrdup(ptszUserName);
- db_set_resident(m_szModuleName, "Status");
-
- m_hmiReqAuth = hReqAuth;
- m_hmiGrantAuth = hGrantAuth;
- m_hmiRevokeAuth = hRevokeAuth;
-}
-
-PROTO_INTERFACE::~PROTO_INTERFACE()
-{
- if (m_hNetlibUser)
- Netlib_CloseHandle(m_hNetlibUser);
-
- mir_free(m_szModuleName);
- mir_free(m_tszUserName);
-
- WindowList_Destroy(m_hWindowList);
-}
-
-void PROTO_INTERFACE::OnBuildProtoMenu()
-{}
-
-void PROTO_INTERFACE::OnContactDeleted(MCONTACT)
-{}
-
-void PROTO_INTERFACE::OnErase()
-{}
-
-void PROTO_INTERFACE::OnModulesLoaded()
-{}
-
-bool PROTO_INTERFACE::IsReadyToExit()
-{
- return true;
-}
-
-void PROTO_INTERFACE::OnShutdown()
-{}
-
-/////////////////////////////////////////////////////////////////////////////////////////
// protocol services
MIR_APP_DLL(void) ProtoCreateService(PROTO_INTERFACE *pThis, const char* szService, ProtoServiceFunc serviceProc)
@@ -416,184 +323,3 @@ MIR_APP_DLL(int) ProtoGetAvatarFormatByMimeType(const char *pwszMimeType)
return PA_FORMAT_UNKNOWN;
}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// default PROTO_INTERFACE method implementations
-
-MCONTACT PROTO_INTERFACE::AddToList(int, PROTOSEARCHRESULT*)
-{
- return 0; // error
-}
-
-MCONTACT PROTO_INTERFACE::AddToListByEvent(int, int, MEVENT)
-{
- return 0; // error
-}
-
-int PROTO_INTERFACE::Authorize(MEVENT)
-{
- return 1; // error
-}
-
-int PROTO_INTERFACE::AuthDeny(MEVENT, const wchar_t*)
-{
- return 1; // error
-}
-
-int PROTO_INTERFACE::AuthRecv(MCONTACT, PROTORECVEVENT*)
-{
- return 1; // error
-}
-
-int PROTO_INTERFACE::AuthRequest(MCONTACT, const wchar_t*)
-{
- return 1; // error
-}
-
-HANDLE PROTO_INTERFACE::FileAllow(MCONTACT, HANDLE, const wchar_t*)
-{
- return nullptr; // error
-}
-
-int PROTO_INTERFACE::FileCancel(MCONTACT, HANDLE)
-{
- return 1; // error
-}
-
-int PROTO_INTERFACE::FileDeny(MCONTACT, HANDLE, const wchar_t*)
-{
- return 1; // error
-}
-
-int PROTO_INTERFACE::FileResume(HANDLE, int, const wchar_t*)
-{
- return 1; // error
-}
-
-INT_PTR PROTO_INTERFACE::GetCaps(int, MCONTACT)
-{
- return 0; // empty value
-}
-
-int PROTO_INTERFACE::GetInfo(MCONTACT, int)
-{
- return 1; // error
-}
-
-HANDLE PROTO_INTERFACE::SearchBasic(const wchar_t*)
-{
- return nullptr; // error
-}
-
-HANDLE PROTO_INTERFACE::SearchByEmail(const wchar_t*)
-{
- return nullptr; // error
-}
-
-HANDLE PROTO_INTERFACE::SearchByName(const wchar_t*, const wchar_t*, const wchar_t*)
-{
- return nullptr; // error
-}
-
-HWND PROTO_INTERFACE::SearchAdvanced(HWND)
-{
- return nullptr; // error
-}
-
-HWND PROTO_INTERFACE::CreateExtendedSearchUI(HWND)
-{
- return nullptr; // error
-}
-
-int PROTO_INTERFACE::RecvContacts(MCONTACT, PROTORECVEVENT*)
-{
- return 1; // error
-}
-
-int PROTO_INTERFACE::RecvFile(MCONTACT hContact, PROTORECVFILE *pcre)
-{
- CCSDATA ccs = { hContact, PSR_FILE, 0, (LPARAM)pcre };
- return CallService(MS_PROTO_RECVFILET, 0, (LPARAM)&ccs);
-}
-
-MEVENT PROTO_INTERFACE::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre)
-{
- if (pre->szMessage == nullptr)
- return 0;
-
- ptrA pszTemp;
- mir_ptr<BYTE> pszBlob;
-
- DBEVENTINFO dbei = {};
- dbei.flags = DBEF_UTF;
- dbei.szModule = Proto_GetBaseAccountName(hContact);
- dbei.timestamp = pre->timestamp;
- dbei.eventType = EVENTTYPE_MESSAGE;
- dbei.cbBlob = (DWORD)mir_strlen(pre->szMessage) + 1;
- dbei.pBlob = (PBYTE)pre->szMessage;
-
- if (pre->flags & PREF_CREATEREAD)
- dbei.flags |= DBEF_READ;
- if (pre->flags & PREF_SENT)
- dbei.flags |= DBEF_SENT;
-
- // if it's possible to find an existing event by its id, do that
- if ((GetCaps(PFLAGNUM_4) & PF4_SERVERMSGID) && pre->szMsgId != nullptr) {
- MEVENT hDbEvent = db_event_getById(m_szModuleName, pre->szMsgId);
- if (hDbEvent == 0 || db_event_edit(hContact, hDbEvent, &dbei)) {
- hDbEvent = db_event_add(hContact, &dbei);
- if (hDbEvent)
- db_event_setId(m_szModuleName, hDbEvent, pre->szMsgId);
- }
-
- return hDbEvent;
- }
-
- // event is new? add it
- return (INT_PTR)db_event_add(hContact, &dbei);
-}
-
-int PROTO_INTERFACE::SendContacts(MCONTACT, int, int, MCONTACT*)
-{
- return 1; // error
-}
-
-HANDLE PROTO_INTERFACE::SendFile(MCONTACT, const wchar_t*, wchar_t**)
-{
- return nullptr; // error
-}
-
-int PROTO_INTERFACE::SendMsg(MCONTACT, int, const char*)
-{
- return 0; // error
-}
-
-int PROTO_INTERFACE::SetApparentMode(MCONTACT, int)
-{
- return 1; // error
-}
-
-int PROTO_INTERFACE::SetStatus(int)
-{
- return 1; // you better declare it
-}
-
-HANDLE PROTO_INTERFACE::GetAwayMsg(MCONTACT)
-{
- return nullptr; // no away message
-}
-
-int PROTO_INTERFACE::RecvAwayMsg(MCONTACT, int, PROTORECVEVENT*)
-{
- return 1; // error
-}
-
-int PROTO_INTERFACE::SetAwayMsg(int, const wchar_t*)
-{
- return 1; // error
-}
-
-int PROTO_INTERFACE::UserIsTyping(MCONTACT, int)
-{
- return 1; // error
-}
diff --git a/src/mir_app/src/protocols.cpp b/src/mir_app/src/protocols.cpp
index 2578c0ef81..3c55ecaefe 100644
--- a/src/mir_app/src/protocols.cpp
+++ b/src/mir_app/src/protocols.cpp
@@ -389,54 +389,51 @@ MIR_APP_DLL(INT_PTR) CallProtoService(const char* szModule, const char* szServic
INT_PTR CallProtoServiceInt(MCONTACT hContact, const char *szModule, const char *szService, WPARAM wParam, LPARAM lParam)
{
- PROTOACCOUNT *pa = Proto_GetAccount(szModule);
- if (pa && !pa->bOldProto) {
- PROTO_INTERFACE *ppi = pa->ppro;
- if (ppi != nullptr && ppi->m_iVersion > 1) {
- TServiceListItem *item = (TServiceListItem*)bsearch(&szService, serviceItems, _countof(serviceItems), sizeof(serviceItems[0]), CompareServiceItems);
- if (item) {
- switch (item->id) {
- case 1: return (INT_PTR)ppi->AddToList(wParam, (PROTOSEARCHRESULT*)lParam);
- case 2: return (INT_PTR)ppi->AddToListByEvent(LOWORD(wParam), HIWORD(wParam), (MEVENT)lParam);
- case 3: return (INT_PTR)ppi->Authorize((MEVENT)wParam);
- case 4: return (INT_PTR)ppi->AuthDeny((MEVENT)wParam, (wchar_t*)lParam);
- case 5: return (INT_PTR)ppi->AuthRecv(hContact, (PROTORECVEVENT*)lParam);
- case 6: return (INT_PTR)ppi->AuthRequest(hContact, (wchar_t*)lParam);
- case 8: return (INT_PTR)ppi->FileAllow(hContact, (HANDLE)wParam, (wchar_t*)lParam);
- case 9: return (INT_PTR)ppi->FileCancel(hContact, (HANDLE)wParam);
- case 10: return (INT_PTR)ppi->FileDeny(hContact, (HANDLE)wParam, (wchar_t*)lParam);
- case 11: {
- PROTOFILERESUME *pfr = (PROTOFILERESUME*)lParam;
- return (INT_PTR)ppi->FileResume((HANDLE)wParam, pfr->action, (const wchar_t*)pfr->szFilename);
- }
-
- case 12: return (INT_PTR)ppi->GetCaps(wParam, lParam);
- case 13: return (INT_PTR)Proto_GetIcon(ppi, wParam);
- case 14: return (INT_PTR)ppi->GetInfo(hContact, wParam);
- case 15: return (INT_PTR)ppi->SearchBasic((wchar_t*)lParam);
- case 16: return (INT_PTR)ppi->SearchByEmail((wchar_t*)lParam);
- case 17: {
- PROTOSEARCHBYNAME *psbn = (PROTOSEARCHBYNAME*)lParam;
- return (INT_PTR)ppi->SearchByName(psbn->pszNick, psbn->pszFirstName, psbn->pszLastName);
- }
- case 18: return (INT_PTR)ppi->SearchAdvanced((HWND)lParam);
- case 19: return (INT_PTR)ppi->CreateExtendedSearchUI((HWND)lParam);
- case 20: return (INT_PTR)ppi->RecvContacts(hContact, (PROTORECVEVENT*)lParam);
- case 21: return (INT_PTR)ppi->RecvFile(hContact, (PROTORECVFILE*)lParam);
- case 22: return (INT_PTR)ppi->RecvMsg(hContact, (PROTORECVEVENT*)lParam);
- case 23: return (INT_PTR)ppi->SendContacts(hContact, LOWORD(wParam), HIWORD(wParam), (MCONTACT*)lParam);
- case 24: return (INT_PTR)ppi->SendFile(hContact, (wchar_t*)wParam, (wchar_t**)lParam);
- case 25: return (INT_PTR)ppi->SendMsg(hContact, wParam, (const char*)lParam);
- case 26: return (INT_PTR)ppi->SetApparentMode(hContact, wParam);
- case 27: return (INT_PTR)ppi->SetStatus(wParam);
- case 28: return (INT_PTR)ppi->GetAwayMsg(hContact);
- case 29: return (INT_PTR)ppi->RecvAwayMsg(hContact, wParam, (PROTORECVEVENT*)lParam);
- case 30: return (INT_PTR)ppi->SetAwayMsg(wParam, (wchar_t*)lParam);
- case 31: return (INT_PTR)ppi->UserIsTyping(wParam, lParam);
- case 32: mir_strncpy((char*)lParam, ppi->m_szModuleName, wParam); return 0;
- case 33:
- return ppi->m_iStatus;
+ auto *ppi = Proto_GetInstance(szModule);
+ if (ppi != nullptr) {
+ TServiceListItem *item = (TServiceListItem*)bsearch(&szService, serviceItems, _countof(serviceItems), sizeof(serviceItems[0]), CompareServiceItems);
+ if (item) {
+ switch (item->id) {
+ case 1: return (INT_PTR)ppi->AddToList(wParam, (PROTOSEARCHRESULT *)lParam);
+ case 2: return (INT_PTR)ppi->AddToListByEvent(LOWORD(wParam), HIWORD(wParam), (MEVENT)lParam);
+ case 3: return (INT_PTR)ppi->Authorize((MEVENT)wParam);
+ case 4: return (INT_PTR)ppi->AuthDeny((MEVENT)wParam, (wchar_t *)lParam);
+ case 5: return (INT_PTR)ppi->AuthRecv(hContact, (PROTORECVEVENT *)lParam);
+ case 6: return (INT_PTR)ppi->AuthRequest(hContact, (wchar_t *)lParam);
+ case 8: return (INT_PTR)ppi->FileAllow(hContact, (HANDLE)wParam, (wchar_t *)lParam);
+ case 9: return (INT_PTR)ppi->FileCancel(hContact, (HANDLE)wParam);
+ case 10: return (INT_PTR)ppi->FileDeny(hContact, (HANDLE)wParam, (wchar_t *)lParam);
+ case 11: {
+ PROTOFILERESUME *pfr = (PROTOFILERESUME *)lParam;
+ return (INT_PTR)ppi->FileResume((HANDLE)wParam, pfr->action, (const wchar_t *)pfr->szFilename);
+ }
+
+ case 12: return (INT_PTR)ppi->GetCaps(wParam, lParam);
+ case 13: return (INT_PTR)Proto_GetIcon(ppi, wParam);
+ case 14: return (INT_PTR)ppi->GetInfo(hContact, wParam);
+ case 15: return (INT_PTR)ppi->SearchBasic((wchar_t *)lParam);
+ case 16: return (INT_PTR)ppi->SearchByEmail((wchar_t *)lParam);
+ case 17: {
+ PROTOSEARCHBYNAME *psbn = (PROTOSEARCHBYNAME *)lParam;
+ return (INT_PTR)ppi->SearchByName(psbn->pszNick, psbn->pszFirstName, psbn->pszLastName);
}
+ case 18: return (INT_PTR)ppi->SearchAdvanced((HWND)lParam);
+ case 19: return (INT_PTR)ppi->CreateExtendedSearchUI((HWND)lParam);
+ case 20: return (INT_PTR)ppi->RecvContacts(hContact, (PROTORECVEVENT *)lParam);
+ case 21: return (INT_PTR)ppi->RecvFile(hContact, (PROTORECVFILE *)lParam);
+ case 22: return (INT_PTR)ppi->RecvMsg(hContact, (PROTORECVEVENT *)lParam);
+ case 23: return (INT_PTR)ppi->SendContacts(hContact, LOWORD(wParam), HIWORD(wParam), (MCONTACT *)lParam);
+ case 24: return (INT_PTR)ppi->SendFile(hContact, (wchar_t *)wParam, (wchar_t **)lParam);
+ case 25: return (INT_PTR)ppi->SendMsg(hContact, wParam, (const char *)lParam);
+ case 26: return (INT_PTR)ppi->SetApparentMode(hContact, wParam);
+ case 27: return (INT_PTR)ppi->SetStatus(wParam);
+ case 28: return (INT_PTR)ppi->GetAwayMsg(hContact);
+ case 29: return (INT_PTR)ppi->RecvAwayMsg(hContact, wParam, (PROTORECVEVENT *)lParam);
+ case 30: return (INT_PTR)ppi->SetAwayMsg(wParam, (wchar_t *)lParam);
+ case 31: return (INT_PTR)ppi->UserIsTyping(wParam, lParam);
+ case 32: mir_strncpy((char *)lParam, ppi->m_szModuleName, wParam); return 0;
+ case 33:
+ return ppi->m_iStatus;
}
}
}