From 7bb41bcc7824ab4ae248992df3ac82e6b148720f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 31 Jan 2018 19:48:57 +0300 Subject: useless wrappers removed & replaced with PROTO_INTERFACE method calls --- src/mir_app/src/miranda.h | 2 +- src/mir_app/src/proto_internal.cpp | 5 ++++- src/mir_app/src/proto_utils.cpp | 37 ++++++++++++++++++++++++++++++++----- src/mir_app/src/protocols.cpp | 36 ------------------------------------ 4 files changed, 37 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/mir_app/src/miranda.h b/src/mir_app/src/miranda.h index 476c80b070..0e2c27aec4 100644 --- a/src/mir_app/src/miranda.h +++ b/src/mir_app/src/miranda.h @@ -131,7 +131,7 @@ extern OBJLIST g_cliEvents; extern LIST accounts; extern LIST protos; -INT_PTR ProtoCallService(LPCSTR szModule, const char *szService, WPARAM wParam, LPARAM lParam); +INT_PTR ProtoCallService(const char *szModule, const char *szService, WPARAM wParam, LPARAM lParam); PROTOACCOUNT* Proto_CreateAccount(const char *szModuleName, const char *szBaseProto, const wchar_t *tszAccountName); diff --git a/src/mir_app/src/proto_internal.cpp b/src/mir_app/src/proto_internal.cpp index 437f9cd0a4..bb57cde70c 100644 --- a/src/mir_app/src/proto_internal.cpp +++ b/src/mir_app/src/proto_internal.cpp @@ -46,6 +46,8 @@ void FreeFilesMatrix(wchar_t ***files) struct DEFAULT_PROTO_INTERFACE : public PROTO_INTERFACE { + typedef PROTO_INTERFACE CSuper; + DEFAULT_PROTO_INTERFACE(const char *pszModuleName, const wchar_t *ptszUserName) : PROTO_INTERFACE(pszModuleName, ptszUserName) {} @@ -200,7 +202,8 @@ struct DEFAULT_PROTO_INTERFACE : public PROTO_INTERFACE virtual int __cdecl RecvMsg(MCONTACT hContact, PROTORECVEVENT* evt) override { CCSDATA ccs = { hContact, PSR_MESSAGE, 0, (LPARAM)evt }; - return (int)ProtoCallService(m_szModuleName, PSR_MESSAGE, 0, (LPARAM)&ccs); + INT_PTR res = ProtoCallService(m_szModuleName, PSR_MESSAGE, 0, (LPARAM)&ccs); + return (res != CALLSERVICE_NOTFOUND) ? (int)res : CSuper::RecvMsg(hContact, evt); } virtual int __cdecl RecvUrl(MCONTACT hContact, PROTORECVEVENT* evt) override diff --git a/src/mir_app/src/proto_utils.cpp b/src/mir_app/src/proto_utils.cpp index f667522e06..199e730fd8 100644 --- a/src/mir_app/src/proto_utils.cpp +++ b/src/mir_app/src/proto_utils.cpp @@ -388,15 +388,42 @@ int PROTO_INTERFACE::RecvContacts(MCONTACT, PROTORECVEVENT*) return 1; // error } -int PROTO_INTERFACE::RecvFile(MCONTACT hContact, PROTORECVFILE *evt) +int PROTO_INTERFACE::RecvFile(MCONTACT hContact, PROTORECVFILE *pcre) { - return ::Proto_RecvFile(hContact, evt); // default file receiver + CCSDATA ccs = { hContact, PSR_FILE, 0, (LPARAM)pcre }; + return CallService(MS_PROTO_RECVFILET, 0, (LPARAM)&ccs); } -int PROTO_INTERFACE::RecvMsg(MCONTACT hContact, PROTORECVEVENT *evt) +int PROTO_INTERFACE::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre) { - ::Proto_RecvMessage(hContact, evt); // default message receiver - return 0; + if (pre->szMessage == nullptr) + return 0; + + ptrA pszTemp; + mir_ptr pszBlob; + + DBEVENTINFO dbei = {}; + dbei.flags = DBEF_UTF; + dbei.szModule = GetContactProto(hContact); + dbei.timestamp = pre->timestamp; + dbei.eventType = EVENTTYPE_MESSAGE; + dbei.cbBlob = (DWORD)mir_strlen(pre->szMessage) + 1; + dbei.pBlob = (PBYTE)pre->szMessage; + + if (pre->cbCustomDataSize != 0) { + pszBlob = (PBYTE)mir_alloc(dbei.cbBlob + pre->cbCustomDataSize); + memcpy(pszBlob, dbei.pBlob, dbei.cbBlob); + memcpy((PBYTE)pszBlob + dbei.cbBlob, pre->pCustomData, pre->cbCustomDataSize); + dbei.pBlob = pszBlob; + dbei.cbBlob += pre->cbCustomDataSize; + } + + if (pre->flags & PREF_CREATEREAD) + dbei.flags |= DBEF_READ; + if (pre->flags & PREF_SENT) + dbei.flags |= DBEF_SENT; + + return (INT_PTR)db_event_add(hContact, &dbei); } int PROTO_INTERFACE::RecvUrl(MCONTACT, PROTORECVEVENT*) diff --git a/src/mir_app/src/protocols.cpp b/src/mir_app/src/protocols.cpp index 2e9d6652b8..8e2896414d 100644 --- a/src/mir_app/src/protocols.cpp +++ b/src/mir_app/src/protocols.cpp @@ -148,40 +148,6 @@ MIR_APP_DLL(int) Proto_RegisterModule(PROTOCOLDESCRIPTOR *pd) ///////////////////////////////////////////////////////////////////////////////////////// // Basic core services -static INT_PTR Proto_RecvMessage(WPARAM, LPARAM lParam) -{ - CCSDATA *ccs = (CCSDATA*)lParam; - PROTORECVEVENT *pre = (PROTORECVEVENT*)ccs->lParam; - if (pre->szMessage == nullptr) - return 0; - - ptrA pszTemp; - mir_ptr pszBlob; - - DBEVENTINFO dbei = {}; - dbei.flags = DBEF_UTF; - dbei.szModule = GetContactProto(ccs->hContact); - dbei.timestamp = pre->timestamp; - dbei.eventType = EVENTTYPE_MESSAGE; - dbei.cbBlob = (DWORD)mir_strlen(pre->szMessage) + 1; - dbei.pBlob = (PBYTE)pre->szMessage; - - if (pre->cbCustomDataSize != 0) { - pszBlob = (PBYTE)mir_alloc(dbei.cbBlob + pre->cbCustomDataSize); - memcpy(pszBlob, dbei.pBlob, dbei.cbBlob); - memcpy((PBYTE)pszBlob + dbei.cbBlob, pre->pCustomData, pre->cbCustomDataSize); - dbei.pBlob = pszBlob; - dbei.cbBlob += pre->cbCustomDataSize; - } - - if (pre->flags & PREF_CREATEREAD) - dbei.flags |= DBEF_READ; - if (pre->flags & PREF_SENT) - dbei.flags |= DBEF_SENT; - - return (INT_PTR)db_event_add(ccs->hContact, &dbei); -} - MIR_APP_DLL(MEVENT) Proto_AuthRecv(const char *szProtoName, PROTORECVEVENT *pcre) { if (szProtoName == nullptr || pcre == nullptr) @@ -460,8 +426,6 @@ int LoadProtocolsModule(void) CreateServiceFunction(MS_PROTO_SELFISTYPING, Proto_SelfIsTyping); CreateServiceFunction(MS_PROTO_CONTACTISTYPING, Proto_ContactIsTyping); - CreateServiceFunction(MS_PROTO_RECVMSG, Proto_RecvMessage); - CreateServiceFunction(MS_PROTO_CREATEACCOUNT, srvProto_CreateAccount); // just to make QuickSearch happy -- cgit v1.2.3