summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-04-18 23:04:26 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-04-18 23:04:26 +0300
commitabf8cd813bb0ac4f4f5451d2af929279d816abac (patch)
tree4fb7451f2f99fac23a9f891c1aa9dc9fe6e0f8c6 /src
parent9ffe3c7ba4eb7011279e14ff1c5b5357bf874114 (diff)
core changes:
- PROTOCOLDESCRIPTOR's implementation hidden inside mir_app; - Proto_RegisterModule now doesn't need a PROTOCOLDESCRIPTOR structure; - PROTOTYPE_PROTOWITHACCS type added for protos that work with accounts
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/CMPluginBase.cpp22
-rw-r--r--src/mir_app/src/ignore.cpp6
-rw-r--r--src/mir_app/src/meta_main.cpp11
-rw-r--r--src/mir_app/src/miranda.h5
-rw-r--r--src/mir_app/src/proto_accs.cpp2
-rw-r--r--src/mir_app/src/proto_chains.cpp2
-rw-r--r--src/mir_app/src/proto_opts.cpp4
-rw-r--r--src/mir_app/src/proto_order.cpp2
-rw-r--r--src/mir_app/src/proto_ui.cpp2
-rw-r--r--src/mir_app/src/proto_utils.cpp12
-rw-r--r--src/mir_app/src/protocols.cpp57
-rw-r--r--src/mir_app/src/stdafx.h1
12 files changed, 60 insertions, 66 deletions
diff --git a/src/mir_app/src/CMPluginBase.cpp b/src/mir_app/src/CMPluginBase.cpp
index 55b557c0cc..e30fdb3320 100644
--- a/src/mir_app/src/CMPluginBase.cpp
+++ b/src/mir_app/src/CMPluginBase.cpp
@@ -68,12 +68,18 @@ void CMPluginBase::debugLogW(LPCWSTR wszFormat, ...)
void CMPluginBase::RegisterProtocol(int type, pfnInitProto fnInit, pfnUninitProto fnUninit)
{
- PROTOCOLDESCRIPTOR pd = {};
- pd.cbSize = (fnInit == nullptr) ? PROTOCOLDESCRIPTOR_V3_SIZE : sizeof(pd);
- pd.szName = (char*)m_szModuleName;
- pd.type = type;
- pd.fnInit = fnInit;
- pd.fnUninit = fnUninit;
- pd.hInst = m_hInst;
- Proto_RegisterModule(&pd);
+ if (type == PROTOTYPE_PROTOCOL && fnInit != nullptr)
+ type = PROTOTYPE_PROTOWITHACCS;
+
+ MBaseProto *pd = (MBaseProto*)Proto_RegisterModule(type, m_szModuleName);
+ if (pd) {
+ pd->fnInit = fnInit;
+ pd->fnUninit = fnUninit;
+ pd->hInst = m_hInst;
+ }
+}
+
+void CMPluginBase::SetUniqueId(const char *pszUniqueId)
+{
+ ::Proto_SetUniqueId(m_szModuleName, pszUniqueId);
}
diff --git a/src/mir_app/src/ignore.cpp b/src/mir_app/src/ignore.cpp
index 37d5471e88..bf7e23e659 100644
--- a/src/mir_app/src/ignore.cpp
+++ b/src/mir_app/src/ignore.cpp
@@ -418,11 +418,7 @@ static int IgnoreAddedNotify(WPARAM, LPARAM lParam)
int LoadIgnoreModule(void)
{
- PROTOCOLDESCRIPTOR pd = { 0 };
- pd.cbSize = sizeof(pd);
- pd.szName = "Ignore";
- pd.type = PROTOTYPE_IGNORE;
- Proto_RegisterModule(&pd);
+ Proto_RegisterModule(PROTOTYPE_IGNORE, "Ignore");
CreateProtoServiceFunction("Ignore", PSR_MESSAGE, IgnoreRecvMessage);
CreateProtoServiceFunction("Ignore", PSR_URL, IgnoreRecvUrl);
diff --git a/src/mir_app/src/meta_main.cpp b/src/mir_app/src/meta_main.cpp
index 9746d605c4..e753ac4e57 100644
--- a/src/mir_app/src/meta_main.cpp
+++ b/src/mir_app/src/meta_main.cpp
@@ -57,15 +57,8 @@ void UnloadMetacontacts(void)
static int RegisterMeta(WPARAM, LPARAM)
{
- PROTOCOLDESCRIPTOR pd = { 0 };
- pd.cbSize = sizeof(pd);
- pd.szName = META_FILTER;
- pd.type = PROTOTYPE_FILTER;
- Proto_RegisterModule(&pd);
-
- pd.szName = META_PROTO;
- pd.type = PROTOTYPE_VIRTUAL;
- Proto_RegisterModule(&pd);
+ Proto_RegisterModule(PROTOTYPE_FILTER, META_FILTER);
+ Proto_RegisterModule(PROTOTYPE_VIRTUAL, META_PROTO);
return 0;
}
diff --git a/src/mir_app/src/miranda.h b/src/mir_app/src/miranda.h
index 81360cc8fb..ad3370ff48 100644
--- a/src/mir_app/src/miranda.h
+++ b/src/mir_app/src/miranda.h
@@ -145,6 +145,10 @@ extern LIST<PROTOACCOUNT> accounts;
struct MBaseProto : public PROTOCOLDESCRIPTOR
{
+ pfnInitProto fnInit;
+ pfnUninitProto fnUninit;
+
+ HINSTANCE hInst;
char *szUniqueId; // name of the unique setting that identifies a contact
};
@@ -179,6 +183,7 @@ void HotkeyToName(wchar_t *buf, int size, BYTE shift, BYTE key);
WORD GetHotkeyValue(INT_PTR idHotkey);
HBITMAP ConvertIconToBitmap(HIMAGELIST hIml, int iconId);
+MBaseProto* Proto_GetProto(const char *szProtoName);
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/mir_app/src/proto_accs.cpp b/src/mir_app/src/proto_accs.cpp
index 8e05ba2c48..0bc5621fb8 100644
--- a/src/mir_app/src/proto_accs.cpp
+++ b/src/mir_app/src/proto_accs.cpp
@@ -288,7 +288,7 @@ static HANDLE CreateProtoServiceEx(const char* szModule, const char* szService,
bool ActivateAccount(PROTOACCOUNT *pa, bool bIsDynamic)
{
- PROTOCOLDESCRIPTOR* ppd = Proto_IsProtocolLoaded(pa->szProtoName);
+ MBaseProto *ppd = Proto_GetProto(pa->szProtoName);
if (ppd == nullptr)
return false;
diff --git a/src/mir_app/src/proto_chains.cpp b/src/mir_app/src/proto_chains.cpp
index adefcd9fd4..f295886181 100644
--- a/src/mir_app/src/proto_chains.cpp
+++ b/src/mir_app/src/proto_chains.cpp
@@ -187,7 +187,7 @@ MIR_APP_DLL(int) Proto_AddToContact(MCONTACT hContact, const char *szProto)
return 1;
}
- if (pd->type == PROTOTYPE_PROTOCOL || pd->type == PROTOTYPE_VIRTUAL)
+ if (pd->type == PROTOTYPE_PROTOCOL || pd->type == PROTOTYPE_VIRTUAL || pd->type == PROTOTYPE_PROTOWITHACCS)
db_set_s(hContact, "Protocol", "p", szProto);
return 0;
diff --git a/src/mir_app/src/proto_opts.cpp b/src/mir_app/src/proto_opts.cpp
index 70fdd82876..c0b561d3a1 100644
--- a/src/mir_app/src/proto_opts.cpp
+++ b/src/mir_app/src/proto_opts.cpp
@@ -599,7 +599,7 @@ public:
m_accList.ResetContent();
for (auto &p : accounts) {
PROTOCOLDESCRIPTOR *pd = Proto_IsProtocolLoaded(p->szProtoName);
- if (pd != nullptr && pd->type != PROTOTYPE_PROTOCOL)
+ if (pd != nullptr && pd->type != PROTOTYPE_PROTOWITHACCS && pd->type != PROTOTYPE_PROTOCOL)
continue;
int iItem = m_accList.AddString(p->tszAccountName);
@@ -823,7 +823,7 @@ void CAccountFormDlg::OnInitDialog()
{
int cnt = 0;
for (auto &it : g_arProtos)
- if (it->type == PROTOTYPE_PROTOCOL && it->cbSize == sizeof(PROTOCOLDESCRIPTOR)) {
+ if (it->type == PROTOTYPE_PROTOWITHACCS) {
m_prototype.AddStringA(it->szName);
++cnt;
}
diff --git a/src/mir_app/src/proto_order.cpp b/src/mir_app/src/proto_order.cpp
index afa44d91cf..4eefd4c359 100644
--- a/src/mir_app/src/proto_order.cpp
+++ b/src/mir_app/src/proto_order.cpp
@@ -102,7 +102,7 @@ static bool ProtoToInclude(PROTOACCOUNT *pa)
return false;
PROTOCOLDESCRIPTOR *pd = Proto_IsProtocolLoaded(pa->szProtoName);
- return (pd != nullptr && pd->type == PROTOTYPE_PROTOCOL);
+ return (pd != nullptr && pd->type == PROTOTYPE_PROTOWITHACCS);
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/mir_app/src/proto_ui.cpp b/src/mir_app/src/proto_ui.cpp
index ba10aeb279..4740148f13 100644
--- a/src/mir_app/src/proto_ui.cpp
+++ b/src/mir_app/src/proto_ui.cpp
@@ -29,7 +29,7 @@ HINSTANCE ProtoGetInstance(const char *szModuleName)
if (pa == nullptr)
return nullptr;
- PROTOCOLDESCRIPTOR *p = Proto_IsProtocolLoaded(pa->szProtoName);
+ MBaseProto *p = Proto_GetProto(pa->szProtoName);
return (p == nullptr) ? nullptr : GetInstByAddress(p->fnInit);
}
diff --git a/src/mir_app/src/proto_utils.cpp b/src/mir_app/src/proto_utils.cpp
index 932d8e6e7f..399943562c 100644
--- a/src/mir_app/src/proto_utils.cpp
+++ b/src/mir_app/src/proto_utils.cpp
@@ -34,14 +34,20 @@ extern HANDLE hAckEvent;
/////////////////////////////////////////////////////////////////////////////////////////
+MBaseProto* Proto_GetProto(const char *szProtoName)
+{
+ if (szProtoName == nullptr)
+ return nullptr;
+
+ return g_arProtos.find((MBaseProto*)&szProtoName);
+}
+
MIR_APP_DLL(PROTOCOLDESCRIPTOR*) Proto_IsProtocolLoaded(const char *szProtoName)
{
if (szProtoName == nullptr)
return nullptr;
- MBaseProto tmp;
- tmp.szName = (char*)szProtoName;
- return g_arProtos.find(&tmp);
+ return g_arProtos.find((MBaseProto*)&szProtoName);
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/mir_app/src/protocols.cpp b/src/mir_app/src/protocols.cpp
index 7e0b49cdfc..14f679ea9b 100644
--- a/src/mir_app/src/protocols.cpp
+++ b/src/mir_app/src/protocols.cpp
@@ -98,44 +98,33 @@ static PROTO_INTERFACE* defInitProto(const char *szModule, const wchar_t*)
return AddDefaultAccount(szModule);
}
-MIR_APP_DLL(int) Proto_RegisterModule(PROTOCOLDESCRIPTOR *pd)
+MIR_APP_DLL(PROTOCOLDESCRIPTOR*) Proto_RegisterModule(int type, const char *szName)
{
- if (pd == nullptr)
- return 1;
-
- if (pd->cbSize != sizeof(PROTOCOLDESCRIPTOR) && pd->cbSize != PROTOCOLDESCRIPTOR_V3_SIZE)
- return 1;
+ if (szName == nullptr)
+ return nullptr;
bool bTryActivate = false;
- MBaseProto tmp;
- tmp.szName = (char*)pd->szName;
- MBaseProto *p = g_arProtos.find(&tmp);
- if (p == nullptr) {
- p = (MBaseProto*)mir_calloc(sizeof(MBaseProto));
- p->cbSize = pd->cbSize;
- p->szName = mir_strdup(pd->szName);
- g_arProtos.insert(p);
+ MBaseProto *pd = Proto_GetProto(szName);
+ if (pd == nullptr) {
+ pd = (MBaseProto*)mir_calloc(sizeof(MBaseProto));
+ pd->szName = mir_strdup(szName);
+ g_arProtos.insert(pd);
}
else bTryActivate = true;
- p->type = pd->type;
- p->hInst = pd->hInst;
- if (pd->cbSize == sizeof(PROTOCOLDESCRIPTOR)) {
- p->fnInit = pd->fnInit;
- p->fnUninit = pd->fnUninit;
- }
+ pd->type = type;
- if (p->fnInit == nullptr && (p->type == PROTOTYPE_PROTOCOL || p->type == PROTOTYPE_VIRTUAL)) {
+ if (pd->type == PROTOTYPE_PROTOCOL || pd->type == PROTOTYPE_VIRTUAL) {
// let's create a new container
- PROTO_INTERFACE *ppi = AddDefaultAccount(pd->szName);
+ PROTO_INTERFACE *ppi = AddDefaultAccount(szName);
if (ppi) {
- ppi->m_iVersion = (pd->cbSize == PROTOCOLDESCRIPTOR_V3_SIZE) ? 1 : 2;
+ ppi->m_iVersion = 1;
PROTOACCOUNT *pa = Proto_GetAccount(pd->szName);
if (pa == nullptr) {
pa = (PROTOACCOUNT*)mir_calloc(sizeof(PROTOACCOUNT));
- pa->szModuleName = mir_strdup(pd->szName);
- pa->szProtoName = mir_strdup(pd->szName);
- pa->tszAccountName = mir_a2u(pd->szName);
+ pa->szModuleName = mir_strdup(szName);
+ pa->szProtoName = mir_strdup(szName);
+ pa->tszAccountName = mir_a2u(szName);
pa->bIsVisible = pa->bIsEnabled = true;
pa->iOrder = accounts.getCount();
pa->iIconBase = -1;
@@ -143,16 +132,16 @@ MIR_APP_DLL(int) Proto_RegisterModule(PROTOCOLDESCRIPTOR *pd)
accounts.insert(pa);
}
pa->bOldProto = true;
- pa->bIsVirtual = (p->type == PROTOTYPE_VIRTUAL);
+ pa->bIsVirtual = (pd->type == PROTOTYPE_VIRTUAL);
pa->ppro = ppi;
- p->fnInit = defInitProto;
- p->fnUninit = FreeDefaultAccount;
+ pd->fnInit = defInitProto;
+ pd->fnUninit = FreeDefaultAccount;
}
}
- if (p->type != PROTOTYPE_PROTOCOL && p->type != PROTOTYPE_VIRTUAL)
- g_arFilters.insert(p);
- return 0;
+ if (pd->type != PROTOTYPE_PROTOCOL && pd->type != PROTOTYPE_VIRTUAL && pd->type != PROTOTYPE_PROTOWITHACCS)
+ g_arFilters.insert(pd);
+ return pd;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -360,7 +349,7 @@ bool PROTOACCOUNT::IsVisible() const
{
if (this != nullptr && bIsVisible && IsEnabled() && ppro) {
PROTOCOLDESCRIPTOR *pd = Proto_IsProtocolLoaded(szProtoName);
- if (pd == nullptr || pd->type != PROTOTYPE_PROTOCOL)
+ if (pd == nullptr || (pd->type != PROTOTYPE_PROTOCOL && pd->type != PROTOTYPE_PROTOWITHACCS))
return false;
return (ppro->GetCaps(PFLAGNUM_2, 0) & ~ppro->GetCaps(PFLAGNUM_5, 0));
@@ -520,6 +509,6 @@ void UnloadProtocolsModule()
pfnUninitProto GetProtocolDestructor(char *szProto)
{
- PROTOCOLDESCRIPTOR *p = Proto_IsProtocolLoaded(szProto);
+ MBaseProto *p = Proto_GetProto(szProto);
return (p == nullptr) ? nullptr : p->fnUninit;
}
diff --git a/src/mir_app/src/stdafx.h b/src/mir_app/src/stdafx.h
index 8163839d31..edc880de52 100644
--- a/src/mir_app/src/stdafx.h
+++ b/src/mir_app/src/stdafx.h
@@ -92,7 +92,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <m_gui.h>
#include <m_srmm_int.h>
#include <m_imgsrvc.h>
-#include <m_plugin.h>
#include "miranda.h"