diff options
author | George Hazan <ghazan@miranda.im> | 2018-03-28 20:01:30 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-03-28 20:01:30 +0300 |
commit | e7b69721b0d390cec3f81f97134a51bfef228cf8 (patch) | |
tree | a56ef2bd15fa3c995a031bec35ce0113dec22b28 /src | |
parent | 81ce57622c3166830b23eae534dacc6b008c659d (diff) |
PFLAG_UNIQUEIDSETTING removed, its functionality transferred to Proto_SetUniqueId / Proto_GetUniqueId
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_app/src/clc.cpp | 4 | ||||
-rw-r--r-- | src/mir_app/src/contacts.cpp | 12 | ||||
-rw-r--r-- | src/mir_app/src/meta_edit.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/meta_utils.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 2 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 2 | ||||
-rw-r--r-- | src/mir_app/src/miranda.h | 8 | ||||
-rw-r--r-- | src/mir_app/src/proto_accs.cpp | 6 | ||||
-rw-r--r-- | src/mir_app/src/proto_chains.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/proto_utils.cpp | 8 | ||||
-rw-r--r-- | src/mir_app/src/protocols.cpp | 49 |
11 files changed, 71 insertions, 26 deletions
diff --git a/src/mir_app/src/clc.cpp b/src/mir_app/src/clc.cpp index 8ece944316..6fb781a2b8 100644 --- a/src/mir_app/src/clc.cpp +++ b/src/mir_app/src/clc.cpp @@ -106,8 +106,8 @@ static int ClcSettingChanged(WPARAM hContact, LPARAM lParam) // something is being written to a protocol module
if (!strcmp(szProto, cws->szModule)) {
// was a unique setting key written?
- char *id = (char *)CallProtoServiceInt(0, szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
- if ((INT_PTR)id != CALLSERVICE_NOTFOUND && id != nullptr && !strcmp(id, cws->szSetting))
+ const char *id = Proto_GetUniqueId(szProto);
+ if (id != nullptr && !strcmp(id, cws->szSetting))
Clist_Broadcast(INTM_PROTOCHANGED, hContact, lParam);
}
}
diff --git a/src/mir_app/src/contacts.cpp b/src/mir_app/src/contacts.cpp index 382ef24d8b..b53fb0bcd5 100644 --- a/src/mir_app/src/contacts.cpp +++ b/src/mir_app/src/contacts.cpp @@ -95,7 +95,7 @@ MIR_APP_DLL(wchar_t*) Contact_GetInfo(int type, MCONTACT hContact, const char *s if (szProto == nullptr)
return nullptr;
- char *uid;
+ const char *uid;
wchar_t *res;
DBVARIANT dbv;
switch (type) {
@@ -184,8 +184,8 @@ MIR_APP_DLL(wchar_t*) Contact_GetInfo(int type, MCONTACT hContact, const char *s return mir_wstrdup(buf);
}
- uid = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
- if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid)
+ uid = Proto_GetUniqueId(szProto);
+ if (uid)
return ProcessDatabaseValueDefault(hContact, szProto, uid);
break;
@@ -193,8 +193,8 @@ MIR_APP_DLL(wchar_t*) Contact_GetInfo(int type, MCONTACT hContact, const char *s if (res = ProcessDatabaseValueDefault(hContact, szProto, "display_uid"))
return res;
- uid = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
- if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid)
+ uid = Proto_GetUniqueId(szProto);
+ if (uid)
return ProcessDatabaseValueDefault(hContact, szProto, uid);
break;
@@ -228,7 +228,7 @@ MIR_APP_DLL(wchar_t*) Contact_GetInfo(int type, MCONTACT hContact, const char *s case 5: // Unique id
// protocol must define a PFLAG_UNIQUEIDSETTING
- uid = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
+ uid = Proto_GetUniqueId(szProto);
if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid) {
if (!GetDatabaseString(hContact, szProto, uid, &dbv)) {
if (dbv.type == DBVT_BYTE || dbv.type == DBVT_WORD || dbv.type == DBVT_DWORD) {
diff --git a/src/mir_app/src/meta_edit.cpp b/src/mir_app/src/meta_edit.cpp index 345bd98927..bb233f4ef1 100644 --- a/src/mir_app/src/meta_edit.cpp +++ b/src/mir_app/src/meta_edit.cpp @@ -65,7 +65,7 @@ static void FillContactList(HWND hList) if (szProto) {
PROTOACCOUNT *pa = Proto_GetAccount(szProto);
- char *szField = (char *)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
+ const char *szField = Proto_GetUniqueId(szProto);
DBVARIANT dbv;
if (!db_get(g_data.hContact[i], szProto, szField, &dbv)) {
diff --git a/src/mir_app/src/meta_utils.cpp b/src/mir_app/src/meta_utils.cpp index 5b590129c0..7a1b8565a0 100644 --- a/src/mir_app/src/meta_utils.cpp +++ b/src/mir_app/src/meta_utils.cpp @@ -70,7 +70,7 @@ BOOL Meta_Assign(MCONTACT hSub, MCONTACT hMeta, BOOL set_as_default) }
// Get the login of the subcontact
- char *field = (char *)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
+ const char *field = Proto_GetUniqueId(szProto);
DBVARIANT dbv;
if (db_get(hSub, szProto, field, &dbv)) {
MessageBox(nullptr, TranslateT("Could not get unique ID of contact"), TranslateT("Assignment error"), MB_OK | MB_ICONWARNING);
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 97445ad173..922fd0e0b5 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -527,3 +527,5 @@ Proto_ActivateAccount @512 ?setWord@CMPluginBase@@QAEXPBDG@Z @545 NONAME
?tryOpenLog@CMPluginBase@@AAEXXZ @546 NONAME
?RegisterProtocol@CMPluginBase@@IAEXHP6APAUPROTO_INTERFACE@@PBDPB_W@ZP6AHPAU2@@Z@Z @547 NONAME
+Proto_GetUniqueId @548
+Proto_SetUniqueId @549
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index fbc4904145..8456025d4e 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -527,3 +527,5 @@ Proto_ActivateAccount @512 ?setWord@CMPluginBase@@QEAAXPEBDG@Z @545 NONAME
?tryOpenLog@CMPluginBase@@AEAAXXZ @546 NONAME
?RegisterProtocol@CMPluginBase@@IEAAXHP6APEAUPROTO_INTERFACE@@PEBDPEB_W@ZP6AHPEAU2@@Z@Z @547 NONAME
+Proto_GetUniqueId @548
+Proto_SetUniqueId @549
diff --git a/src/mir_app/src/miranda.h b/src/mir_app/src/miranda.h index 5cad812460..36b14b2022 100644 --- a/src/mir_app/src/miranda.h +++ b/src/mir_app/src/miranda.h @@ -134,7 +134,13 @@ extern OBJLIST<CListEvent> g_cliEvents; #define OFFSET_NAME 800
extern LIST<PROTOACCOUNT> accounts;
-extern LIST<PROTOCOLDESCRIPTOR> protos;
+
+struct MBaseProto : public PROTOCOLDESCRIPTOR
+{
+ char *szUniqueId; // name of the unique setting that identifies a contact
+};
+
+extern LIST<MBaseProto> protos, filters;
INT_PTR ProtoCallService(const char *szModule, const char *szService, WPARAM wParam, LPARAM lParam);
diff --git a/src/mir_app/src/proto_accs.cpp b/src/mir_app/src/proto_accs.cpp index 6319a270fd..163e693527 100644 --- a/src/mir_app/src/proto_accs.cpp +++ b/src/mir_app/src/proto_accs.cpp @@ -392,8 +392,10 @@ void UnloadAccount(PROTOACCOUNT *pa, bool bIsDynamic, bool bErase) {
DeactivateAccount(pa, bIsDynamic, bErase);
- mir_free(pa->tszAccountName);
- mir_free(pa->szProtoName);
+ replaceStrW(pa->tszAccountName, 0);
+ replaceStr(pa->szProtoName, 0);
+ replaceStr(pa->szUniqueId, 0);
+
// szModuleName should be freed only on a program's exit.
// otherwise many plugins dependand on static protocol names will crash!
// do NOT fix this 'leak', please
diff --git a/src/mir_app/src/proto_chains.cpp b/src/mir_app/src/proto_chains.cpp index 6bfb1df0a9..d405cccae9 100644 --- a/src/mir_app/src/proto_chains.cpp +++ b/src/mir_app/src/proto_chains.cpp @@ -24,8 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h"
-extern LIST<PROTOCOLDESCRIPTOR> filters;
-
static int GetProtocolP(MCONTACT hContact, char *szBuf, int cbLen)
{
if (currDb == nullptr)
diff --git a/src/mir_app/src/proto_utils.cpp b/src/mir_app/src/proto_utils.cpp index 53301d7269..16c094e51b 100644 --- a/src/mir_app/src/proto_utils.cpp +++ b/src/mir_app/src/proto_utils.cpp @@ -23,12 +23,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h"
-static int CompareProtos(const PROTOCOLDESCRIPTOR *p1, const PROTOCOLDESCRIPTOR *p2)
+static int CompareProtos(const MBaseProto *p1, const MBaseProto *p2)
{
return strcmp(p1->szName, p2->szName);
}
-LIST<PROTOCOLDESCRIPTOR> protos(10, CompareProtos);
+LIST<MBaseProto> protos(10, CompareProtos);
extern HANDLE hAckEvent;
@@ -39,7 +39,7 @@ MIR_APP_DLL(PROTOCOLDESCRIPTOR*) Proto_IsProtocolLoaded(const char *szProtoName) if (szProtoName == nullptr)
return nullptr;
- PROTOCOLDESCRIPTOR tmp;
+ MBaseProto tmp;
tmp.szName = (char*)szProtoName;
return protos.find(&tmp);
}
@@ -49,7 +49,7 @@ MIR_APP_DLL(PROTOCOLDESCRIPTOR*) Proto_IsProtocolLoaded(const char *szProtoName) MIR_APP_DLL(void) Proto_EnumProtocols(int *nProtos, PROTOCOLDESCRIPTOR ***pProtos)
{
if (nProtos) *nProtos = protos.getCount();
- if (pProtos) *pProtos = protos.getArray();
+ if (pProtos) *pProtos = (PROTOCOLDESCRIPTOR **)protos.getArray();
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/mir_app/src/protocols.cpp b/src/mir_app/src/protocols.cpp index 7043c99e2c..3ac0e4b117 100644 --- a/src/mir_app/src/protocols.cpp +++ b/src/mir_app/src/protocols.cpp @@ -81,7 +81,7 @@ static TServiceListItem serviceItems[] = //------------------------------------------------------------------------------------
-static int CompareProtos(const PROTOCOLDESCRIPTOR *p1, const PROTOCOLDESCRIPTOR *p2)
+static int CompareProtos(const MBaseProto *p1, const MBaseProto *p2)
{
if (p1->type != p2->type)
return p1->type - p2->type;
@@ -89,7 +89,7 @@ static int CompareProtos(const PROTOCOLDESCRIPTOR *p1, const PROTOCOLDESCRIPTOR return mir_strcmp(p1->szName, p2->szName);
}
-LIST<PROTOCOLDESCRIPTOR> filters(10, CompareProtos);
+LIST<MBaseProto> filters(10, CompareProtos);
//------------------------------------------------------------------------------------
@@ -108,12 +108,13 @@ MIR_APP_DLL(int) Proto_RegisterModule(PROTOCOLDESCRIPTOR *pd) if (pd->cbSize != sizeof(PROTOCOLDESCRIPTOR) && pd->cbSize != PROTOCOLDESCRIPTOR_V3_SIZE)
return 1;
- PROTOCOLDESCRIPTOR *p = (PROTOCOLDESCRIPTOR*)mir_calloc(sizeof(PROTOCOLDESCRIPTOR));
- if (!p)
- return 2;
-
- memcpy(p, pd, pd->cbSize);
+ MBaseProto *p = (MBaseProto*)mir_calloc(sizeof(MBaseProto));
p->szName = mir_strdup(pd->szName);
+ p->type = pd->type;
+ if (pd->cbSize == sizeof(PROTOCOLDESCRIPTOR)) {
+ p->fnInit = pd->fnInit;
+ p->fnUninit = pd->fnUninit;
+ }
protos.insert(p);
if (p->fnInit == nullptr && (p->type == PROTOTYPE_PROTOCOL || p->type == PROTOTYPE_VIRTUAL)) {
@@ -146,6 +147,39 @@ MIR_APP_DLL(int) Proto_RegisterModule(PROTOCOLDESCRIPTOR *pd) }
/////////////////////////////////////////////////////////////////////////////////////////
+
+MIR_APP_DLL(void) Proto_SetUniqueId(const char *szModuleName, const char *pszUniqueId)
+{
+ PROTOACCOUNT *pa = Proto_GetAccount(szModuleName);
+ if (pa != nullptr) {
+ pa->szUniqueId = mir_strdup(pszUniqueId);
+ return;
+ }
+
+ MBaseProto tmp;
+ tmp.szName = (char*)szModuleName;
+ MBaseProto *pd = protos.find(&tmp);
+ if (pd != nullptr)
+ pd->szUniqueId = mir_strdup(pszUniqueId);
+}
+
+MIR_APP_DLL(const char*) Proto_GetUniqueId(const char *szModuleName)
+{
+ MBaseProto tmp;
+ PROTOACCOUNT *pa = Proto_GetAccount(szModuleName);
+ if (pa != nullptr) {
+ if (pa->szUniqueId != nullptr)
+ return pa->szUniqueId;
+
+ tmp.szName = pa->szProtoName;
+ }
+ else tmp.szName = (char*)szModuleName;
+
+ MBaseProto *pd = protos.find(&tmp);
+ return (pd != nullptr) ? pd->szUniqueId : nullptr;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
// Basic core services
MIR_APP_DLL(MEVENT) Proto_AuthRecv(const char *szProtoName, PROTORECVEVENT *pcre)
@@ -425,6 +459,7 @@ void UnloadProtocolsModule() if (!bModuleInitialized) return;
for (auto &p : protos) {
+ mir_free(p->szUniqueId);
mir_free(p->szName);
mir_free(p);
}
|