summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-02-08 18:13:03 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-02-08 18:13:03 +0000
commit4c8d19f8daa2f9b9692d5995226439b2001ad92f (patch)
tree051c6e2b0bb47040b6458d0347f3a3c97f855466
parent2ccbc4c7f3efc677290f8e1607543676b61c1cbe (diff)
low-level database access functions rewritten to MCONTACT instead of HANDLE hContact
git-svn-id: http://svn.miranda-ng.org/main/trunk@8067 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--include/delphi/m_core.inc4
-rw-r--r--include/delphi/m_db_int.inc56
-rw-r--r--include/m_core.h3
-rw-r--r--include/m_db_int.h59
-rw-r--r--plugins/Db3x_mmap/src/dbcontacts.cpp113
-rw-r--r--plugins/Db3x_mmap/src/dbcrypt.cpp39
-rw-r--r--plugins/Db3x_mmap/src/dbevents.cpp76
-rw-r--r--plugins/Db3x_mmap/src/dbintf.h50
-rw-r--r--plugins/Db3x_mmap/src/dbsettings.cpp67
-rw-r--r--plugins/Dbx_tree/src/Compatibility.cpp149
-rw-r--r--plugins/Dbx_tree/src/DataBase.cpp5
-rw-r--r--plugins/Dbx_tree/src/DataBase.h36
-rw-r--r--plugins/Dbx_tree/src/Services.cpp2
-rw-r--r--plugins/Import/src/import.cpp235
-rw-r--r--src/mir_core/db.cpp55
-rw-r--r--src/modules/database/database.h10
-rw-r--r--src/modules/database/dbintf.cpp6
-rw-r--r--src/modules/database/mdatabasecache.cpp90
-rw-r--r--src/modules/protocols/protochains.cpp12
19 files changed, 543 insertions, 524 deletions
diff --git a/include/delphi/m_core.inc b/include/delphi/m_core.inc
index 79bbe29b3f..7ee88e52c0 100644
--- a/include/delphi/m_core.inc
+++ b/include/delphi/m_core.inc
@@ -53,6 +53,7 @@ const
DBVTF_VARIABLELENGTH = $80; // ?
type
+ MCONTACT = DWORD;
HDBEVENT = THANDLE;
PDBVARIANT = ^TDBVARIANT;
TDBVARIANT = record
@@ -75,6 +76,9 @@ type
end;
const
+ INVALID_CONTACT_ID = MCONTACT(-1);
+
+const
DBEF_FIRST = 1; // internally only, do not use
DBEF_SENT = 2; // if set, the event was sent by the user, otherwise it was received
DBEF_READ = 4; // event has been read by the user -- only needed for history
diff --git a/include/delphi/m_db_int.inc b/include/delphi/m_db_int.inc
index 3b5dd22df1..106cc3bbfe 100644
--- a/include/delphi/m_db_int.inc
+++ b/include/delphi/m_db_int.inc
@@ -41,23 +41,25 @@ type
PDBCachedContact = ^TDBCachedContact;
TDBCachedContact = record
- hContact:THANDLE;
- hNext :THANDLE;
- szProto :PAnsiChar;
- first :PDBCachedContactValue;
- last :PDBCachedContactValue;
+ contactID:MCONTACT;
+ dwDriverData:DWORD;
+ szProto:PAnsiChar;
+ first :PDBCachedContactValue;
+ last :PDBCachedContactValue;
end;
PMIDatabaseCache = ^MIDatabaseCache;
MIDatabaseCache = interface
- function AddContactToCache(hContact:THANDLE):PDBCachedContact; stdcall;
- function GetCachedContact(hContact:THANDLE):PDBCachedContact; stdcall;
- procedure FreeCachedContact(hContact:THANDLE); stdcall;
+ function AddContactToCache(contactID:MCONTACT):PDBCachedContact; stdcall;
+ function GetCachedContact(contactID:MCONTACT):PDBCachedContact; stdcall;
+ function GetFirstContact():PDBCachedContact; stdcall;
+ function GetNextContact(contactID:MCONTACT):PDBCachedContact; stdcall;
+ procedure FreeCachedContact(contactID:MCONTACT); stdcall;
function InsertCachedSetting(szName:pAnsiChar; param:int):pAnsiChar; stdcall;
function GetCachedSetting(szModuleName:pAnsiChar; szSettingName:pAnsiChar; param1:int; param2:int):pAnsiChar; stdcall;
procedure SetCachedVariant(s:PDBVARIANT; d:PDBVARIANT); stdcall;
- function GetCachedValuePtr(hContact:THANDLE; szSetting:pAnsiChar; bAllocate:int):PDBVARIANT; stdcall;
+ function GetCachedValuePtr(contactID:MCONTACT; szSetting:pAnsiChar; bAllocate:int):PDBVARIANT; stdcall;
end;
type
@@ -68,35 +70,35 @@ type
SetCacheSafetyMode:procedure(val:bool); stdcall;
GetContactCount:function():long; stdcall;
- FindFirstContact:function(const szProto:PAnsiChar = NIL):THANDLE; stdcall;
- FindNextContact:function(hContact:THANDLE; const szProto:PAnsiChar = NIL):THANDLE; stdcall;
+ FindFirstContact:function(const szProto:PAnsiChar = NIL):MCONTACT; stdcall;
+ FindNextContact:function(contactID:MCONTACT; const szProto:PAnsiChar = NIL):MCONTACT; stdcall;
- DeleteContact:function(hContact:THANDLE):long; stdcall;
- AddContact:function():THANDLE; stdcall;
- IsDbContact:function(hContact:THANDLE):bool; stdcall;
+ DeleteContact:function(contactID:MCONTACT):long; stdcall;
+ AddContact:function():MCONTACT; stdcall;
+ IsDbContact:function(contactID:MCONTACT):bool; stdcall;
- GetEventCount:function(hContact:THANDLE):long; stdcall;
- AddEvent:function(hContact:THANDLE; dbe:PDBEVENTINFO):THANDLE; stdcall;
- DeleteEvent:function(hContact:THANDLE; hDbEvent:THANDLE):bool; stdcall;
+ GetEventCount:function(contactID:MCONTACT):long; stdcall;
+ AddEvent:function(contactID:MCONTACT; dbe:PDBEVENTINFO):THANDLE; stdcall;
+ DeleteEvent:function(contactID:MCONTACT; hDbEvent:THANDLE):bool; stdcall;
GetBlobSize:function(hDbEvent:THANDLE):long; stdcall;
GetEvent:function(hDbEvent:THANDLE; dbe:PDBEVENTINFO):bool; stdcall;
- MarkEventRead:function(hContact:THANDLE; hDbEvent:THANDLE):bool; stdcall;
+ MarkEventRead:function(contactID:MCONTACT; hDbEvent:THANDLE):bool; stdcall;
GetEventContact:function(hDbEvent:THANDLE):THANDLE; stdcall;
- FindFirstEvent:function(hContact:THANDLE):THANDLE; stdcall;
- FindFirstUnreadEvent:function(hContact:THANDLE):THANDLE; stdcall;
- FindLastEvent:function(hContact:THANDLE):THANDLE; stdcall;
+ FindFirstEvent:function(contactID:MCONTACT):THANDLE; stdcall;
+ FindFirstUnreadEvent:function(contactID:MCONTACT):THANDLE; stdcall;
+ FindLastEvent:function(contactID:MCONTACT):THANDLE; stdcall;
FindNextEvent:function(hDbEvent:THANDLE):THANDLE; stdcall;
FindPrevEvent:function(hDbEvent:THANDLE):THANDLE; stdcall;
EnumModuleNames:function(pFunc:TDBMODULEENUMPROC; pParam:pointer):bool; stdcall;
- GetContactSetting:function(hContact:THANDLE; szModule, szSetting:pAnsiChar; dbv:PDBVARIANT):bool; stdcall;
- GetContactSettingStr:function(hContact:THANDLE; szModule, szSetting:pAnsiChar; dbv:PDBVARIANT):bool; stdcall;
- GetContactSettingStatic:function(hContact:THANDLE; szModule, szSetting:pAnsiChar; dbv:PDBVARIANT):bool; stdcall;
+ GetContactSetting:function(contactID:MCONTACT; szModule, szSetting:pAnsiChar; dbv:PDBVARIANT):bool; stdcall;
+ GetContactSettingStr:function(contactID:MCONTACT; szModule, szSetting:pAnsiChar; dbv:PDBVARIANT):bool; stdcall;
+ GetContactSettingStatic:function(contactID:MCONTACT; szModule, szSetting:pAnsiChar; dbv:PDBVARIANT):bool; stdcall;
FreeVariant:function(dbv:PDBVARIANT):bool; stdcall;
- WriteContactSetting:function(hContact:THANDLE; dbcws:PDBCONTACTWRITESETTING):bool; stdcall;
- DeleteContactSetting:function(hContact:THANDLE; szModule, szSetting:pAnsiChar):bool; stdcall;
- EnumContactSettings:function(hContact:THANDLE; dbces:PDBCONTACTENUMSETTINGS):bool; stdcall;
+ WriteContactSetting:function(contactID:MCONTACT; dbcws:PDBCONTACTWRITESETTING):bool; stdcall;
+ DeleteContactSetting:function(contactID:MCONTACT; szModule, szSetting:pAnsiChar):bool; stdcall;
+ EnumContactSettings:function(contactID:MCONTACT; dbces:PDBCONTACTENUMSETTINGS):bool; stdcall;
SetSettingResident:function(bIsResident:bool; const pszSettingName:PAnsiChar):bool; stdcall;
EnumResidentSettings:function(pFunc:TDBMODULEENUMPROC; pParam:pointer):bool; stdcall;
IsSettingEncrypted:function(szModule:PAnsiChar; szSetting:pAnsiChar):bool; stdcall;
diff --git a/include/m_core.h b/include/m_core.h
index b6ef9ffb1d..4f77e965a5 100644
--- a/include/m_core.h
+++ b/include/m_core.h
@@ -48,6 +48,9 @@ MIR_CORE_DLL(LPCTSTR) CmdLine_GetOption(LPCTSTR ptszParameter);
///////////////////////////////////////////////////////////////////////////////
// database functions
+typedef UINT32 MCONTACT;
+#define INVALID_CONTACT_ID (MCONTACT(-1))
+
// DBVARIANT: used by db/contact/getsetting and db/contact/writesetting
#define DBVT_DELETED 0 //this setting just got deleted, no other values are valid
#define DBVT_BYTE 1 //bVal and cVal are valid
diff --git a/include/m_db_int.h b/include/m_db_int.h
index 8d7adfa9b6..81a6c3a433 100644
--- a/include/m_db_int.h
+++ b/include/m_db_int.h
@@ -33,36 +33,37 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
struct DBCachedGlobalValue
{
- char* name;
+ char *name;
DBVARIANT value;
};
struct DBCachedContactValue
{
- char* name;
+ char *name;
DBVARIANT value;
- DBCachedContactValue* next;
+ DBCachedContactValue *next;
};
struct DBCachedContact
{
- HANDLE hContact;
- HANDLE hNext;
- char *szProto;
- DBCachedContactValue* first;
- DBCachedContactValue* last;
+ MCONTACT contactID;
+ DWORD dwDriverData;
+ char *szProto;
+ DBCachedContactValue *first, *last;
};
interface MIDatabaseCache : public MZeroedObject
{
- STDMETHOD_(DBCachedContact*,AddContactToCache)(HANDLE hContact) PURE;
- STDMETHOD_(DBCachedContact*,GetCachedContact)(HANDLE hContact) PURE;
- STDMETHOD_(void,FreeCachedContact)(HANDLE hContact) PURE;
+ STDMETHOD_(DBCachedContact*,AddContactToCache)(MCONTACT contactID) PURE;
+ STDMETHOD_(DBCachedContact*, GetCachedContact)(MCONTACT contactID) PURE;
+ STDMETHOD_(DBCachedContact*, GetFirstContact)(void) PURE;
+ STDMETHOD_(DBCachedContact*, GetNextContact)(MCONTACT contactID) PURE;
+ STDMETHOD_(void, FreeCachedContact)(MCONTACT contactID) PURE;
STDMETHOD_(char*,InsertCachedSetting)(const char *szName, int) PURE;
STDMETHOD_(char*,GetCachedSetting)(const char *szModuleName, const char *szSettingName, int, int) PURE;
STDMETHOD_(void,SetCachedVariant)(DBVARIANT *s, DBVARIANT *d) PURE;
- STDMETHOD_(DBVARIANT*,GetCachedValuePtr)(HANDLE hContact, char *szSetting, int bAllocate) PURE;
+ STDMETHOD_(DBVARIANT*,GetCachedValuePtr)(MCONTACT contactID, char *szSetting, int bAllocate) PURE;
};
interface MIDatabase
@@ -72,35 +73,35 @@ interface MIDatabase
STDMETHOD_(void,SetCacheSafetyMode)(BOOL) PURE;
STDMETHOD_(LONG,GetContactCount)(void) PURE;
- STDMETHOD_(HANDLE,FindFirstContact)(const char *szProto = NULL) PURE;
- STDMETHOD_(HANDLE,FindNextContact)(HANDLE hContact, const char *szProto = NULL) PURE;
+ STDMETHOD_(MCONTACT,FindFirstContact)(const char *szProto = NULL) PURE;
+ STDMETHOD_(MCONTACT, FindNextContact)(MCONTACT contactID, const char *szProto = NULL) PURE;
- STDMETHOD_(LONG,DeleteContact)(HANDLE hContact) PURE;
+ STDMETHOD_(LONG,DeleteContact)(MCONTACT contactID) PURE;
STDMETHOD_(HANDLE,AddContact)(void) PURE;
- STDMETHOD_(BOOL,IsDbContact)(HANDLE hContact) PURE;
+ STDMETHOD_(BOOL,IsDbContact)(MCONTACT contactID) PURE;
- STDMETHOD_(LONG,GetEventCount)(HANDLE hContact) PURE;
- STDMETHOD_(HANDLE,AddEvent)(HANDLE hContact, DBEVENTINFO *dbe) PURE;
- STDMETHOD_(BOOL,DeleteEvent)(HANDLE hContact, HANDLE hDbEvent) PURE;
+ STDMETHOD_(LONG,GetEventCount)(MCONTACT contactID) PURE;
+ STDMETHOD_(HANDLE,AddEvent)(MCONTACT contactID, DBEVENTINFO *dbe) PURE;
+ STDMETHOD_(BOOL,DeleteEvent)(MCONTACT contactID, HANDLE hDbEvent) PURE;
STDMETHOD_(LONG,GetBlobSize)(HANDLE hDbEvent) PURE;
STDMETHOD_(BOOL,GetEvent)(HANDLE hDbEvent, DBEVENTINFO *dbe) PURE;
- STDMETHOD_(BOOL,MarkEventRead)(HANDLE hContact, HANDLE hDbEvent) PURE;
+ STDMETHOD_(BOOL,MarkEventRead)(MCONTACT contactID, HANDLE hDbEvent) PURE;
STDMETHOD_(HANDLE,GetEventContact)(HANDLE hDbEvent) PURE;
- STDMETHOD_(HANDLE,FindFirstEvent)(HANDLE hContact) PURE;
- STDMETHOD_(HANDLE,FindFirstUnreadEvent)(HANDLE hContact) PURE;
- STDMETHOD_(HANDLE,FindLastEvent)(HANDLE hContact) PURE;
+ STDMETHOD_(HANDLE,FindFirstEvent)(MCONTACT contactID) PURE;
+ STDMETHOD_(HANDLE,FindFirstUnreadEvent)(MCONTACT contactID) PURE;
+ STDMETHOD_(HANDLE,FindLastEvent)(MCONTACT contactID) PURE;
STDMETHOD_(HANDLE,FindNextEvent)(HANDLE hDbEvent) PURE;
STDMETHOD_(HANDLE,FindPrevEvent)(HANDLE hDbEvent) PURE;
STDMETHOD_(BOOL,EnumModuleNames)(DBMODULEENUMPROC pFunc, void *pParam) PURE;
- STDMETHOD_(BOOL,GetContactSetting)(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE;
- STDMETHOD_(BOOL,GetContactSettingStr)(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE;
- STDMETHOD_(BOOL,GetContactSettingStatic)(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE;
+ STDMETHOD_(BOOL,GetContactSetting)(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE;
+ STDMETHOD_(BOOL,GetContactSettingStr)(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE;
+ STDMETHOD_(BOOL,GetContactSettingStatic)(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) PURE;
STDMETHOD_(BOOL,FreeVariant)(DBVARIANT *dbv) PURE;
- STDMETHOD_(BOOL,WriteContactSetting)(HANDLE hContact, DBCONTACTWRITESETTING *dbcws) PURE;
- STDMETHOD_(BOOL,DeleteContactSetting)(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting) PURE;
- STDMETHOD_(BOOL,EnumContactSettings)(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces) PURE;
+ STDMETHOD_(BOOL,WriteContactSetting)(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws) PURE;
+ STDMETHOD_(BOOL,DeleteContactSetting)(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting) PURE;
+ STDMETHOD_(BOOL,EnumContactSettings)(MCONTACT contactID, DBCONTACTENUMSETTINGS* dbces) PURE;
STDMETHOD_(BOOL,SetSettingResident)(BOOL bIsResident, const char *pszSettingName) PURE;
STDMETHOD_(BOOL,EnumResidentSettings)(DBMODULEENUMPROC pFunc, void *pParam) PURE;
STDMETHOD_(BOOL,IsSettingEncrypted)(LPCSTR szModule, LPCSTR szSetting) PURE;
diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp
index c96f888178..de426f5b65 100644
--- a/plugins/Db3x_mmap/src/dbcontacts.cpp
+++ b/plugins/Db3x_mmap/src/dbcontacts.cpp
@@ -23,19 +23,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
-int CDb3Mmap::CheckProto(HANDLE hContact, const char *proto)
+int CDb3Mmap::CheckProto(DBCachedContact *cc, const char *proto)
{
- DBCachedContact *cc = m_cache->GetCachedContact(hContact);
- if (cc == NULL)
- cc = m_cache->AddContactToCache(hContact);
-
if (cc->szProto == NULL) {
char protobuf[MAX_PATH] = { 0 };
DBVARIANT dbv;
dbv.type = DBVT_ASCIIZ;
dbv.pszVal = protobuf;
dbv.cchVal = sizeof(protobuf);
- if (GetContactSettingStatic(hContact, "Protocol", "p", &dbv) != 0 || (dbv.type != DBVT_ASCIIZ))
+ if (GetContactSettingStatic(cc->contactID, "Protocol", "p", &dbv) != 0 || (dbv.type != DBVT_ASCIIZ))
return 0;
cc->szProto = m_cache->GetCachedSetting(NULL, protobuf, 0, (int)strlen(protobuf));
@@ -50,57 +46,51 @@ STDMETHODIMP_(LONG) CDb3Mmap::GetContactCount(void)
return m_dbHeader.contactCount;
}
-STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstContact(const char *szProto)
+STDMETHODIMP_(MCONTACT) CDb3Mmap::FindFirstContact(const char *szProto)
{
mir_cslock lck(m_csDbAccess);
- HANDLE ret = (HANDLE)m_dbHeader.ofsFirstContact;
- if (szProto && !CheckProto(ret, szProto))
- ret = FindNextContact(ret, szProto);
- return ret;
+ DBCachedContact *cc = m_cache->GetFirstContact();
+ if (cc == NULL)
+ return NULL;
+
+ if (!szProto || CheckProto(cc, szProto))
+ return cc->contactID;
+
+ return FindNextContact(cc->contactID, szProto);
}
-STDMETHODIMP_(HANDLE) CDb3Mmap::FindNextContact(HANDLE hContact, const char *szProto)
+STDMETHODIMP_(MCONTACT) CDb3Mmap::FindNextContact(MCONTACT contactID, const char *szProto)
{
mir_cslock lck(m_csDbAccess);
- while (hContact) {
- DBCachedContact *VL = m_cache->GetCachedContact(hContact);
- if (VL != NULL) {
- if (VL->hNext != NULL) {
- if (!szProto || CheckProto(VL->hNext, szProto))
- return VL->hNext;
-
- hContact = VL->hNext;
- continue;
- } }
-
- DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
- if (dbc->signature != DBCONTACT_SIGNATURE)
+ while (contactID) {
+ DBCachedContact *cc = m_cache->GetNextContact(contactID);
+ if (cc == NULL)
break;
- if (VL == NULL)
- VL = m_cache->AddContactToCache(hContact);
+ if (!szProto || CheckProto(cc, szProto))
+ return cc->contactID;
- VL->hNext = (HANDLE)dbc->ofsNext;
- if (VL->hNext != NULL && (!szProto || CheckProto(VL->hNext, szProto)))
- return VL->hNext;
-
- hContact = VL->hNext;
+ contactID = cc->contactID;
}
return NULL;
}
-STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(HANDLE hContact)
+STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(MCONTACT contactID)
{
- if (hContact == NULL)
+ if (contactID == NULL)
return 1;
mir_cslockfull lck(m_csDbAccess);
- DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ DBCachedContact *cc = m_cache->GetNextContact(contactID);
+ if (cc == NULL)
+ return 1;
+
+ DBContact *dbc = (DBContact*)DBRead(cc->dwDriverData, sizeof(DBContact), NULL);
if (dbc->signature != DBCONTACT_SIGNATURE)
return 1;
- if (hContact == (HANDLE)m_dbHeader.ofsUser) {
+ if (cc->dwDriverData == m_dbHeader.ofsUser) {
log0("FATAL: del of user chain attempted.");
return 1;
}
@@ -109,16 +99,15 @@ STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(HANDLE hContact)
log0("del contact");
// call notifier while outside mutex
- NotifyEventHooks(hContactDeletedEvent, (WPARAM)hContact, 0);
+ NotifyEventHooks(hContactDeletedEvent, contactID, 0);
// get back in
lck.lock();
- m_cache->FreeCachedContact(hContact);
- if (hContact == m_hLastCachedContact)
+ m_cache->FreeCachedContact(contactID);
+ if (contactID == m_hLastCachedContact)
m_hLastCachedContact = NULL;
- dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
// delete settings chain
DWORD ofsThis = dbc->ofsFirstSettings;
DWORD ofsFirstEvent = dbc->ofsFirstEvent;
@@ -137,8 +126,8 @@ STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(HANDLE hContact)
ofsThis = ofsNext;
}
//find previous contact in chain and change ofsNext
- dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
- if (m_dbHeader.ofsFirstContact == (DWORD)hContact) {
+ dbc = (DBContact*)DBRead(cc->dwDriverData, sizeof(DBContact), NULL);
+ if (m_dbHeader.ofsFirstContact == cc->dwDriverData) {
m_dbHeader.ofsFirstContact = dbc->ofsNext;
DBWrite(0, &m_dbHeader, sizeof(m_dbHeader));
}
@@ -146,7 +135,7 @@ STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(HANDLE hContact)
DWORD ofsNext = dbc->ofsNext;
ofsThis = m_dbHeader.ofsFirstContact;
DBContact *dbcPrev = (DBContact*)DBRead(ofsThis,sizeof(DBContact),NULL);
- while (dbcPrev->ofsNext != (DWORD)hContact) {
+ while (dbcPrev->ofsNext != cc->dwDriverData) {
if (dbcPrev->ofsNext == 0) DatabaseCorruption(NULL);
ofsThis = dbcPrev->ofsNext;
dbcPrev = (DBContact*)DBRead(ofsThis,sizeof(DBContact),NULL);
@@ -156,7 +145,7 @@ STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(HANDLE hContact)
}
//delete contact
- DeleteSpace((DWORD)hContact, sizeof(DBContact));
+ DeleteSpace(cc->dwDriverData, sizeof(DBContact));
//decrement contact count
m_dbHeader.contactCount--;
DBWrite(0, &m_dbHeader, sizeof(m_dbHeader));
@@ -168,12 +157,13 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::AddContact()
{
DWORD ofsNew;
log0("add contact");
+
+ DBContact dbc = { 0 };
+ dbc.signature = DBCONTACT_SIGNATURE;
{
mir_cslock lck(m_csDbAccess);
ofsNew = CreateNewSpace(sizeof(DBContact));
- DBContact dbc = { 0 };
- dbc.signature = DBCONTACT_SIGNATURE;
dbc.ofsNext = m_dbHeader.ofsFirstContact;
dbc.dwContactID = m_dwMaxContactId++;
m_dbHeader.ofsFirstContact = ofsNew;
@@ -182,21 +172,24 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::AddContact()
DBWrite(0, &m_dbHeader, sizeof(m_dbHeader));
DBFlush(0);
}
- m_cache->AddContactToCache((HANDLE)ofsNew);
+
+ DBCachedContact *cc = m_cache->AddContactToCache(dbc.dwContactID);
+ cc->dwDriverData = ofsNew;
- NotifyEventHooks(hContactAddedEvent, (WPARAM)ofsNew, 0);
+ NotifyEventHooks(hContactAddedEvent, dbc.dwContactID, 0);
return (HANDLE)ofsNew;
}
-STDMETHODIMP_(BOOL) CDb3Mmap::IsDbContact(HANDLE hContact)
+STDMETHODIMP_(BOOL) CDb3Mmap::IsDbContact(MCONTACT contactID)
{
- if (m_cache->GetCachedContact(hContact))
- return TRUE;
+ DBCachedContact *cc = m_cache->GetCachedContact(contactID);
+ if (cc == NULL)
+ return FALSE;
mir_cslock lck(m_csDbAccess);
- DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ DBContact *dbc = (DBContact*)DBRead(cc->dwDriverData, sizeof(DBContact), NULL);
if (dbc->signature == DBCONTACT_SIGNATURE) {
- m_cache->AddContactToCache(hContact);
+ m_cache->AddContactToCache(contactID);
return TRUE;
}
@@ -241,7 +234,19 @@ void CDb3Mmap::FillContacts()
if (p->dwContactID > m_dwMaxContactId)
m_dwMaxContactId = p->dwContactID + 1;
- CheckProto((HANDLE)dwOffset, "");
+ DBCachedContact *cc = m_cache->AddContactToCache(p->dwContactID);
+ cc->dwDriverData = dwOffset;
+ CheckProto(cc, "");
+
dwOffset = p->ofsNext;
}
}
+
+DWORD CDb3Mmap::GetContactOffset(MCONTACT contactID)
+{
+ if (contactID == 0)
+ return m_dbHeader.ofsUser;
+
+ DBCachedContact *cc = m_cache->GetCachedContact(contactID);
+ return (cc == NULL) ? 0 : cc->dwDriverData;
+}
diff --git a/plugins/Db3x_mmap/src/dbcrypt.cpp b/plugins/Db3x_mmap/src/dbcrypt.cpp
index 6e3207adf9..7b0d1af539 100644
--- a/plugins/Db3x_mmap/src/dbcrypt.cpp
+++ b/plugins/Db3x_mmap/src/dbcrypt.cpp
@@ -65,7 +65,7 @@ struct SettingUgraderParam
{
CDb3Mmap *db;
LPCSTR szModule;
- HANDLE hContact;
+ MCONTACT contactID;
OBJLIST<VarDescr>* pList;
};
@@ -74,7 +74,7 @@ int sttSettingUgrader(const char *szSetting, LPARAM lParam)
SettingUgraderParam *param = (SettingUgraderParam*)lParam;
if (param->db->IsSettingEncrypted(param->szModule, szSetting)) {
DBVARIANT dbv = { DBVT_UTF8 };
- if (!param->db->GetContactSettingStr(param->hContact, param->szModule, szSetting, &dbv)) {
+ if (!param->db->GetContactSettingStr(param->contactID, param->szModule, szSetting, &dbv)) {
if (dbv.type == DBVT_UTF8) {
DecodeString(dbv.pszVal);
param->pList->insert(new VarDescr(szSetting, (LPCSTR)dbv.pszVal));
@@ -85,10 +85,10 @@ int sttSettingUgrader(const char *szSetting, LPARAM lParam)
return 0;
}
-void sttContactEnum(HANDLE hContact, const char *szModule, CDb3Mmap *db)
+void sttContactEnum(MCONTACT contactID, const char *szModule, CDb3Mmap *db)
{
OBJLIST<VarDescr> arSettings(1);
- SettingUgraderParam param = { db, szModule, hContact, &arSettings };
+ SettingUgraderParam param = { db, szModule, contactID, &arSettings };
DBCONTACTENUMSETTINGS dbces = { 0 };
dbces.pfnEnumProc = sttSettingUgrader;
@@ -106,7 +106,7 @@ void sttContactEnum(HANDLE hContact, const char *szModule, CDb3Mmap *db)
dbcws.value.type = DBVT_ENCRYPTED;
dbcws.value.pbVal = pResult;
dbcws.value.cpbVal = (WORD)len;
- db->WriteContactSetting(hContact, &dbcws);
+ db->WriteContactSetting(contactID, &dbcws);
mir_free(pResult);
}
@@ -118,8 +118,8 @@ int sttModuleEnum(const char *szModule, DWORD, LPARAM lParam)
CDb3Mmap *db = (CDb3Mmap*)lParam;
sttContactEnum(NULL, szModule, db);
- for (HANDLE hContact = db->FindFirstContact(); hContact; hContact = db->FindNextContact(hContact))
- sttContactEnum(hContact, szModule, db);
+ for (MCONTACT contactID = db->FindFirstContact(); contactID; contactID = db->FindNextContact(contactID))
+ sttContactEnum(contactID, szModule, db);
return 0;
}
@@ -242,9 +242,9 @@ void CDb3Mmap::ToggleEncryption()
ToggleSettingsEncryption(NULL);
ToggleEventsEncryption(NULL);
- for (HANDLE hContact = FindFirstContact(); hContact; hContact = FindNextContact(hContact)) {
- ToggleSettingsEncryption(hContact);
- ToggleEventsEncryption(hContact);
+ for (MCONTACT contactID = FindFirstContact(); contactID; contactID = FindNextContact(contactID)) {
+ ToggleSettingsEncryption(contactID);
+ ToggleEventsEncryption(contactID);
}
m_bEncrypted = !m_bEncrypted;
@@ -260,12 +260,13 @@ void CDb3Mmap::ToggleEncryption()
hEventFilterAddedEvent = hSave4;
}
-void CDb3Mmap::ToggleSettingsEncryption(HANDLE hContact)
+void CDb3Mmap::ToggleSettingsEncryption(MCONTACT contactID)
{
- if (!hContact)
- hContact = (HANDLE)m_dbHeader.ofsUser;
+ DWORD ofsContact = GetContactOffset(contactID);
+ if (ofsContact == 0)
+ return;
- DBContact *contact = (DBContact*)DBRead((DWORD)hContact, sizeof(DBContact), NULL);
+ DBContact *contact = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
if (contact->ofsFirstSettings == 0)
return;
@@ -340,7 +341,7 @@ void CDb3Mmap::ToggleSettingsEncryption(HANDLE hContact)
dbcws.value.type = DBVT_ENCRYPTED;
dbcws.value.pbVal = pResult;
dbcws.value.cpbVal = (WORD)len;
- WriteContactSetting(hContact, &dbcws);
+ WriteContactSetting(contactID, &dbcws);
mir_free(pResult);
}
@@ -353,7 +354,7 @@ void CDb3Mmap::ToggleSettingsEncryption(HANDLE hContact)
dbcws.value.type = DBVT_UNENCRYPTED;
dbcws.value.pszVal = decoded;
dbcws.value.cchVal = (WORD)realLen;
- WriteContactSetting(hContact, &dbcws);
+ WriteContactSetting(contactID, &dbcws);
}
}
}
@@ -367,9 +368,11 @@ void CDb3Mmap::ToggleSettingsEncryption(HANDLE hContact)
}
}
-void CDb3Mmap::ToggleEventsEncryption(HANDLE hContact)
+void CDb3Mmap::ToggleEventsEncryption(MCONTACT contactID)
{
- DWORD ofsContact = (hContact) ? (DWORD)hContact : m_dbHeader.ofsUser;
+ DWORD ofsContact = GetContactOffset(contactID);
+ if (ofsContact == 0)
+ return;
DBContact contact = *(DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
if (contact.ofsFirstEvent == 0 || contact.signature != DBCONTACT_SIGNATURE)
diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp
index fe323e6bad..6afab80691 100644
--- a/plugins/Db3x_mmap/src/dbevents.cpp
+++ b/plugins/Db3x_mmap/src/dbevents.cpp
@@ -28,21 +28,19 @@ char *GetModuleNameByOfs(DWORD ofs);
static HANDLE hEventDeletedEvent, hEventAddedEvent, hEventFilterAddedEvent;
-STDMETHODIMP_(LONG) CDb3Mmap::GetEventCount(HANDLE hContact)
+STDMETHODIMP_(LONG) CDb3Mmap::GetEventCount(MCONTACT contactID)
{
mir_cslock lck(m_csDbAccess);
- if (hContact == 0)
- hContact = (HANDLE)m_dbHeader.ofsUser;
-
- DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ DBContact *dbc = (DBContact*)DBRead(GetContactOffset(contactID), sizeof(DBContact), NULL);
return (dbc->signature != DBCONTACT_SIGNATURE) ? -1 : dbc->eventCount;
}
-STDMETHODIMP_(HANDLE) CDb3Mmap::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
+STDMETHODIMP_(HANDLE) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
{
if (dbei == NULL || dbei->cbSize != sizeof(DBEVENTINFO)) return 0;
if (dbei->timestamp == 0) return 0;
- if (NotifyEventHooks(hEventFilterAddedEvent, (WPARAM)hContact, (LPARAM)dbei))
+
+ if (NotifyEventHooks(hEventFilterAddedEvent, contactID, (LPARAM)dbei))
return 0;
DBEvent dbe;
@@ -67,7 +65,7 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
bool neednotify;
mir_cslockfull lck(m_csDbAccess);
- DWORD ofsContact = (hContact == 0) ? m_dbHeader.ofsUser : (DWORD)hContact;
+ DWORD ofsContact = GetContactOffset(contactID);
DBContact dbc = *(DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
if (dbc.signature != DBCONTACT_SIGNATURE)
return 0;
@@ -77,7 +75,7 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
dbe.ofsModuleName = GetModuleNameOfs(dbei->szModule);
// find where to put it - sort by timestamp
if (dbc.eventCount == 0) {
- dbe.ofsPrev = (DWORD)hContact;
+ dbe.ofsPrev = ofsContact;
dbe.ofsNext = 0;
dbe.flags |= DBEF_FIRST;
dbc.ofsFirstEvent = dbc.ofsLastEvent = ofsNew;
@@ -86,7 +84,7 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
DBEvent *dbeTest = (DBEvent*)DBRead(dbc.ofsFirstEvent, sizeof(DBEvent), NULL);
// Should new event be placed before first event in chain?
if (dbe.timestamp < dbeTest->timestamp) {
- dbe.ofsPrev = (DWORD)hContact;
+ dbe.ofsPrev = ofsContact;
dbe.ofsNext = dbc.ofsFirstEvent;
dbe.flags |= DBEF_FIRST;
dbc.ofsFirstEvent = ofsNew;
@@ -143,18 +141,17 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
// Notify only in safe mode or on really new events
if (neednotify)
- NotifyEventHooks(hEventAddedEvent, (WPARAM)hContact, (LPARAM)ofsNew);
+ NotifyEventHooks(hEventAddedEvent, contactID, (LPARAM)ofsNew);
return (HANDLE)ofsNew;
}
-STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
+STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(MCONTACT contactID, HANDLE hDbEvent)
{
mir_cslockfull lck(m_csDbAccess);
-
- DWORD ofsContact = (hContact == 0) ? m_dbHeader.ofsUser : (DWORD)hContact;
+ DWORD ofsContact = GetContactOffset(contactID);
DBContact dbc = *(DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
- DBEvent dbe = *(DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
+ DBEvent dbe = *(DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL);
if (dbc.signature != DBCONTACT_SIGNATURE || dbe.signature != DBEVENT_SIGNATURE)
return 1;
@@ -162,12 +159,12 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
log1("delete event @ %08x", hContact);
//call notifier while outside mutex
- NotifyEventHooks(hEventDeletedEvent, (WPARAM)hContact, (LPARAM)hDbEvent);
+ NotifyEventHooks(hEventDeletedEvent, contactID, (LPARAM)hDbEvent);
//get back in
lck.lock();
dbc = *(DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
- dbe = *(DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
+ dbe = *(DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL);
//check if this was the first unread, if so, recalc the first unread
if (dbc.ofsFirstUnreadEvent == (DWORD)hDbEvent) {
@@ -229,7 +226,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
STDMETHODIMP_(LONG) CDb3Mmap::GetBlobSize(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
- DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
+ DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL);
return (dbe->signature != DBEVENT_SIGNATURE) ? -1 : dbe->cbBlob;
}
@@ -242,7 +239,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
}
mir_cslock lck(m_csDbAccess);
- DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
+ DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL);
if (dbe->signature != DBEVENT_SIGNATURE)
return 1;
@@ -271,13 +268,12 @@ STDMETHODIMP_(BOOL) CDb3Mmap::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
return 0;
}
-STDMETHODIMP_(BOOL) CDb3Mmap::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
+STDMETHODIMP_(BOOL) CDb3Mmap::MarkEventRead(MCONTACT contactID, HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
- if (hContact == 0)
- hContact = (HANDLE)m_dbHeader.ofsUser;
- DBContact dbc = *(DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
- DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
+ DWORD ofsContact = GetContactOffset(contactID);
+ DBContact dbc = *(DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
+ DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL);
if (dbe->signature != DBEVENT_SIGNATURE || dbc.signature != DBCONTACT_SIGNATURE)
return -1;
@@ -304,7 +300,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
}
}
}
- DBWrite((DWORD)hContact, &dbc, sizeof(DBContact));
+ DBWrite(ofsContact, &dbc, sizeof(DBContact));
DBFlush(0);
return ret;
}
@@ -312,7 +308,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
STDMETHODIMP_(HANDLE) CDb3Mmap::GetEventContact(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
- DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
+ DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL);
if (dbe->signature != DBEVENT_SIGNATURE)
return (HANDLE)-1;
@@ -322,47 +318,41 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::GetEventContact(HANDLE hDbEvent)
return (HANDLE)dbe->ofsPrev;
}
-STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstEvent(HANDLE hContact)
+STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstEvent(MCONTACT contactID)
{
mir_cslock lck(m_csDbAccess);
- if (hContact == 0)
- hContact = (HANDLE)m_dbHeader.ofsUser;
-
- DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ DWORD ofsContact = GetContactOffset(contactID);
+ DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsFirstEvent;
}
-STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstUnreadEvent(HANDLE hContact)
+STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstUnreadEvent(MCONTACT contactID)
{
mir_cslock lck(m_csDbAccess);
- if (hContact == 0)
- hContact = (HANDLE)m_dbHeader.ofsUser;
-
- DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ DWORD ofsContact = GetContactOffset(contactID);
+ DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsFirstUnreadEvent;
}
-STDMETHODIMP_(HANDLE) CDb3Mmap::FindLastEvent(HANDLE hContact)
+STDMETHODIMP_(HANDLE) CDb3Mmap::FindLastEvent(MCONTACT contactID)
{
mir_cslock lck(m_csDbAccess);
- if (hContact == 0)
- hContact = (HANDLE)m_dbHeader.ofsUser;
-
- DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ DWORD ofsContact = GetContactOffset(contactID);
+ DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsLastEvent;
}
STDMETHODIMP_(HANDLE) CDb3Mmap::FindNextEvent(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
- DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
+ DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL);
return (dbe->signature != DBEVENT_SIGNATURE) ? 0 : (HANDLE)dbe->ofsNext;
}
STDMETHODIMP_(HANDLE) CDb3Mmap::FindPrevEvent(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
- DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
+ DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL);
if (dbe->signature != DBEVENT_SIGNATURE) return 0;
return (dbe->flags & DBEF_FIRST) ? 0 : (HANDLE)dbe->ofsPrev;
}
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h
index 284a5842d9..629b2972f8 100644
--- a/plugins/Db3x_mmap/src/dbintf.h
+++ b/plugins/Db3x_mmap/src/dbintf.h
@@ -185,34 +185,34 @@ public:
STDMETHODIMP_(void) SetCacheSafetyMode(BOOL);
STDMETHODIMP_(LONG) GetContactCount(void);
- STDMETHODIMP_(HANDLE) FindFirstContact(const char* szProto = NULL);
- STDMETHODIMP_(HANDLE) FindNextContact(HANDLE hContact, const char* szProto = NULL);
- STDMETHODIMP_(LONG) DeleteContact(HANDLE hContact);
+ STDMETHODIMP_(MCONTACT) FindFirstContact(const char* szProto = NULL);
+ STDMETHODIMP_(MCONTACT) FindNextContact(MCONTACT contactID, const char* szProto = NULL);
+ STDMETHODIMP_(LONG) DeleteContact(MCONTACT contactID);
STDMETHODIMP_(HANDLE) AddContact(void);
- STDMETHODIMP_(BOOL) IsDbContact(HANDLE hContact);
+ STDMETHODIMP_(BOOL) IsDbContact(MCONTACT contactID);
- STDMETHODIMP_(LONG) GetEventCount(HANDLE hContact);
- STDMETHODIMP_(HANDLE) AddEvent(HANDLE hContact, DBEVENTINFO *dbe);
- STDMETHODIMP_(BOOL) DeleteEvent(HANDLE hContact, HANDLE hDbEvent);
+ STDMETHODIMP_(LONG) GetEventCount(MCONTACT contactID);
+ STDMETHODIMP_(HANDLE) AddEvent(MCONTACT contactID, DBEVENTINFO *dbe);
+ STDMETHODIMP_(BOOL) DeleteEvent(MCONTACT contactID, HANDLE hDbEvent);
STDMETHODIMP_(LONG) GetBlobSize(HANDLE hDbEvent);
STDMETHODIMP_(BOOL) GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbe);
- STDMETHODIMP_(BOOL) MarkEventRead(HANDLE hContact, HANDLE hDbEvent);
+ STDMETHODIMP_(BOOL) MarkEventRead(MCONTACT contactID, HANDLE hDbEvent);
STDMETHODIMP_(HANDLE) GetEventContact(HANDLE hDbEvent);
- STDMETHODIMP_(HANDLE) FindFirstEvent(HANDLE hContact);
- STDMETHODIMP_(HANDLE) FindFirstUnreadEvent(HANDLE hContact);
- STDMETHODIMP_(HANDLE) FindLastEvent(HANDLE hContact);
+ STDMETHODIMP_(HANDLE) FindFirstEvent(MCONTACT contactID);
+ STDMETHODIMP_(HANDLE) FindFirstUnreadEvent(MCONTACT contactID);
+ STDMETHODIMP_(HANDLE) FindLastEvent(MCONTACT contactID);
STDMETHODIMP_(HANDLE) FindNextEvent(HANDLE hDbEvent);
STDMETHODIMP_(HANDLE) FindPrevEvent(HANDLE hDbEvent);
STDMETHODIMP_(BOOL) EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam);
- STDMETHODIMP_(BOOL) GetContactSetting(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv);
- STDMETHODIMP_(BOOL) GetContactSettingStr(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv);
- STDMETHODIMP_(BOOL) GetContactSettingStatic(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv);
+ STDMETHODIMP_(BOOL) GetContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv);
+ STDMETHODIMP_(BOOL) GetContactSettingStr(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv);
+ STDMETHODIMP_(BOOL) GetContactSettingStatic(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv);
STDMETHODIMP_(BOOL) FreeVariant(DBVARIANT *dbv);
- STDMETHODIMP_(BOOL) WriteContactSetting(HANDLE hContact, DBCONTACTWRITESETTING *dbcws);
- STDMETHODIMP_(BOOL) DeleteContactSetting(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting);
- STDMETHODIMP_(BOOL) EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces);
+ STDMETHODIMP_(BOOL) WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws);
+ STDMETHODIMP_(BOOL) DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting);
+ STDMETHODIMP_(BOOL) EnumContactSettings(MCONTACT contactID, DBCONTACTENUMSETTINGS* dbces);
STDMETHODIMP_(BOOL) SetSettingResident(BOOL bIsResident, const char *pszSettingName);
STDMETHODIMP_(BOOL) EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam);
STDMETHODIMP_(BOOL) IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting);
@@ -271,15 +271,11 @@ protected:
CRITICAL_SECTION m_csDbAccess;
- int CheckProto(HANDLE hContact, const char *proto);
+ int CheckProto(DBCachedContact *cc, const char *proto);
DWORD CreateNewSpace(int bytes);
void DeleteSpace(DWORD ofs, int bytes);
DWORD ReallocSpace(DWORD ofs, int oldSize, int newSize);
-
- __forceinline PBYTE DBRead(HANDLE hContact, int bytesRequired, int *bytesAvail)
- {
- return DBRead((DWORD)hContact, bytesRequired, bytesAvail);
- }
+ DWORD GetContactOffset(MCONTACT contactID);
////////////////////////////////////////////////////////////////////////////
// settings
@@ -293,7 +289,7 @@ protected:
LIST<ModuleName> m_lMods, m_lOfs;
LIST<char> m_lResidentSettings;
HANDLE hEventAddedEvent, hEventDeletedEvent, hEventFilterAddedEvent;
- HANDLE m_hLastCachedContact;
+ MCONTACT m_hLastCachedContact;
ModuleName *m_lastmn;
void AddToList(char *name, DWORD len, DWORD ofs);
@@ -314,7 +310,7 @@ protected:
DWORD ConvertModuleNameOfs(DWORD ofsOld);
void ConvertOldEvent(DBEvent*& dbei);
- int GetContactSettingWorker(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic);
+ int GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic);
int WorkSettingsChain(DWORD ofsContact, DBContact *dbc, int firstTime);
int WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime);
@@ -331,8 +327,8 @@ protected:
void ConvertContacts(void);
int InitCrypt(void);
- void ToggleEventsEncryption(HANDLE hContact);
- void ToggleSettingsEncryption(HANDLE hContact);
+ void ToggleEventsEncryption(MCONTACT contactID);
+ void ToggleSettingsEncryption(MCONTACT contactID);
void InitDialogs();
bool EnterPassword(const BYTE *pKey, const size_t keyLen);
diff --git a/plugins/Db3x_mmap/src/dbsettings.cpp b/plugins/Db3x_mmap/src/dbsettings.cpp
index 4ea08ca479..fed42bf395 100644
--- a/plugins/Db3x_mmap/src/dbsettings.cpp
+++ b/plugins/Db3x_mmap/src/dbsettings.cpp
@@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
DWORD GetModuleNameOfs(const char *szName);
-DBCachedContact* AddToCachedContactList(HANDLE hContact, int index);
+DBCachedContact* AddToCachedContactList(MCONTACT contactID, int index);
#define VLT(n) ((n == DBVT_UTF8 || n == DBVT_ENCRYPTED)?DBVT_ASCIIZ:n)
@@ -45,7 +45,7 @@ BOOL CDb3Mmap::IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting)
/////////////////////////////////////////////////////////////////////////////////////////
-int CDb3Mmap::GetContactSettingWorker(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic)
+int CDb3Mmap::GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic)
{
if (szSetting == NULL || szModule == NULL)
return 1;
@@ -71,7 +71,7 @@ int CDb3Mmap::GetContactSettingWorker(HANDLE hContact, LPCSTR szModule, LPCSTR s
char *szCachedSettingName = m_cache->GetCachedSetting(szModule, szSetting, moduleNameLen, settingNameLen);
log3("get [%08p] %s (%p)", hContact, szCachedSettingName, szCachedSettingName);
- DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(hContact, szCachedSettingName, 0);
+ DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, 0);
if (pCachedValue != NULL) {
if (pCachedValue->type == DBVT_ASCIIZ || pCachedValue->type == DBVT_UTF8) {
int cbOrigLen = dbv->cchVal;
@@ -106,8 +106,8 @@ int CDb3Mmap::GetContactSettingWorker(HANDLE hContact, LPCSTR szModule, LPCSTR s
return 1;
DWORD ofsModuleName = GetModuleNameOfs(szModule);
- DWORD ofsContact = (hContact == NULL) ? m_dbHeader.ofsUser : (DWORD)hContact;
-
+ DWORD ofsContact = GetContactOffset(contactID);
+
DBContact dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
if (dbc.signature != DBCONTACT_SIGNATURE)
return 1;
@@ -202,7 +202,7 @@ int CDb3Mmap::GetContactSettingWorker(HANDLE hContact, LPCSTR szModule, LPCSTR s
/**** add to cache **********************/
if (iType != DBVT_BLOB && iType != DBVT_ENCRYPTED) {
- DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(hContact, szCachedSettingName, 1);
+ DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, 1);
if (pCachedValue != NULL) {
m_cache->SetCachedVariant(dbv, pCachedValue);
log3("set cached [%08p] %s (%p)", hContact, szCachedSettingName, pCachedValue);
@@ -223,10 +223,10 @@ int CDb3Mmap::GetContactSettingWorker(HANDLE hContact, LPCSTR szModule, LPCSTR s
return 1;
}
-STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSetting(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
+STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
{
dbv->type = 0;
- if (GetContactSettingWorker(hContact, szModule, szSetting, dbv, 0))
+ if (GetContactSettingWorker(contactID, szModule, szSetting, dbv, 0))
return 1;
if (dbv->type == DBVT_UTF8 ) {
@@ -258,11 +258,11 @@ STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSetting(HANDLE hContact, LPCSTR szModule
return 0;
}
-STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStr(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
+STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStr(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
{
int iSaveType = dbv->type;
- if (GetContactSettingWorker(hContact, szModule, szSetting, dbv, 0))
+ if (GetContactSettingWorker(contactID, szModule, szSetting, dbv, 0))
return 1;
if (iSaveType == 0 || iSaveType == dbv->type)
@@ -305,9 +305,9 @@ STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStr(HANDLE hContact, LPCSTR szMod
return 0;
}
-STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStatic(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
+STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStatic(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
{
- if (GetContactSettingWorker(hContact, szModule, szSetting, dbv, 1))
+ if (GetContactSettingWorker(contactID, szModule, szSetting, dbv, 1))
return 1;
if (dbv->type == DBVT_UTF8) {
@@ -355,7 +355,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::SetSettingResident(BOOL bIsResident, const char *p
return 0;
}
-STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(HANDLE hContact, DBCONTACTWRITESETTING *dbcws)
+STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws)
{
if (dbcws == NULL || dbcws->szSetting == NULL || dbcws->szModule == NULL || m_bReadOnly)
return 1;
@@ -376,6 +376,10 @@ STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(HANDLE hContact, DBCONTACTWRIT
return 1;
}
+ DBCachedContact *cc = m_cache->GetCachedContact(contactID);
+ if (cc == NULL)
+ return 1;
+
// used for notifications
DBCONTACTWRITESETTING dbcwNotif = *dbcws;
if (dbcwNotif.value.type == DBVT_WCHAR) {
@@ -439,7 +443,7 @@ LBL_WriteString:
// we don't cache blobs and passwords
if (dbcwWork.value.type != DBVT_BLOB && dbcwWork.value.type != DBVT_ENCRYPTED && !bIsEncrypted) {
- DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(hContact, szCachedSettingName, 1);
+ DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, 1);
if (pCachedValue != NULL) {
bool bIsIdentical = false;
if (pCachedValue->type == dbcwWork.value.type) {
@@ -458,16 +462,16 @@ LBL_WriteString:
if (szCachedSettingName[-1] != 0) {
lck.unlock();
log2(" set resident as %s (%p)", printVariant(&dbcwWork.value), pCachedValue);
- NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&dbcwWork);
+ NotifyEventHooks(hSettingChangeEvent, contactID, (LPARAM)&dbcwWork);
return 0;
}
}
- else m_cache->GetCachedValuePtr(hContact, szCachedSettingName, -1);
+ else m_cache->GetCachedValuePtr(contactID, szCachedSettingName, -1);
log1(" write database as %s", printVariant(&dbcwWork.value));
DWORD ofsModuleName = GetModuleNameOfs(dbcwWork.szModule);
- DWORD ofsBlobPtr, ofsContact = (hContact == 0) ? m_dbHeader.ofsUser : (DWORD)hContact;
+ DWORD ofsBlobPtr, ofsContact = (contactID == 0) ? m_dbHeader.ofsUser : cc->dwDriverData;
DBContact dbc = *(DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
if (dbc.signature != DBCONTACT_SIGNATURE)
return 1;
@@ -567,7 +571,7 @@ LBL_WriteString:
DBFlush(1);
lck.unlock();
// notify
- NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&dbcwNotif);
+ NotifyEventHooks(hSettingChangeEvent, contactID, (LPARAM)&dbcwNotif);
return 0;
}
}
@@ -667,11 +671,11 @@ LBL_WriteString:
lck.unlock();
// notify
- NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&dbcwNotif);
+ NotifyEventHooks(hSettingChangeEvent, contactID, (LPARAM)&dbcwNotif);
return 0;
}
-STDMETHODIMP_(BOOL) CDb3Mmap::DeleteContactSetting(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting)
+STDMETHODIMP_(BOOL) CDb3Mmap::DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting)
{
if (!szModule || !szSetting)
return 1;
@@ -692,20 +696,18 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteContactSetting(HANDLE hContact, LPCSTR szMod
return 1;
}
- WPARAM saveWparam = (WPARAM)hContact;
+ MCONTACT saveContact = contactID;
char *szCachedSettingName = m_cache->GetCachedSetting(szModule, szSetting, moduleNameLen, settingNameLen);
if (szCachedSettingName[-1] == 0) { // it's not a resident variable
mir_cslock lck(m_csDbAccess);
DWORD ofsModuleName = GetModuleNameOfs(szModule);
- if (hContact == 0)
- hContact = (HANDLE)m_dbHeader.ofsUser;
-
- DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ DWORD ofsContact = GetContactOffset(contactID);
+ DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
if (dbc->signature != DBCONTACT_SIGNATURE)
return 1;
// make sure the module group exists
- DWORD ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(dbc, (DWORD)hContact, ofsModuleName);
+ DWORD ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(dbc, ofsContact, ofsModuleName);
if (ofsSettingsGroup == 0)
return 1;
@@ -744,30 +746,33 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteContactSetting(HANDLE hContact, LPCSTR szMod
DBFlush(1);
}
- m_cache->GetCachedValuePtr((HANDLE)saveWparam, szCachedSettingName, -1);
+ m_cache->GetCachedValuePtr(saveContact, szCachedSettingName, -1);
// notify
DBCONTACTWRITESETTING dbcws = { 0 };
dbcws.szModule = szModule;
dbcws.szSetting = szSetting;
dbcws.value.type = DBVT_DELETED;
- NotifyEventHooks(hSettingChangeEvent, saveWparam, (LPARAM)&dbcws);
+ NotifyEventHooks(hSettingChangeEvent, saveContact, (LPARAM)&dbcws);
return 0;
}
-STDMETHODIMP_(BOOL) CDb3Mmap::EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces)
+STDMETHODIMP_(BOOL) CDb3Mmap::EnumContactSettings(MCONTACT contactID, DBCONTACTENUMSETTINGS* dbces)
{
if (!dbces->szModule)
return -1;
mir_cslock lck(m_csDbAccess);
- DWORD ofsModuleName = GetModuleNameOfs(dbces->szModule);
- DWORD ofsContact = (hContact == 0) ? m_dbHeader.ofsUser : (DWORD)hContact;
+ DWORD ofsContact = GetContactOffset(contactID);
+ if (ofsContact == 0)
+ return -1;
+
DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
if (dbc->signature != DBCONTACT_SIGNATURE)
return -1;
+ DWORD ofsModuleName = GetModuleNameOfs(dbces->szModule);
dbces->ofsSettings = GetSettingsGroupOfsByModuleNameOfs(dbc, ofsContact, ofsModuleName);
if (!dbces->ofsSettings)
return -1;
diff --git a/plugins/Dbx_tree/src/Compatibility.cpp b/plugins/Dbx_tree/src/Compatibility.cpp
index d8d119fc25..18b9b6571e 100644
--- a/plugins/Dbx_tree/src/Compatibility.cpp
+++ b/plugins/Dbx_tree/src/Compatibility.cpp
@@ -37,19 +37,15 @@ HANDLE hEventDeletedEvent,
hContactDeletedEvent,
hContactAddedEvent;
-int CDataBase::CheckProto(HANDLE hContact, const char *proto)
+int CDataBase::CheckProto(DBCachedContact *cc, const char *proto)
{
- DBCachedContact *cc = m_cache->GetCachedContact(hContact);
- if (cc == NULL)
- cc = m_cache->AddContactToCache(hContact);
-
if (cc->szProto == NULL) {
char protobuf[MAX_PATH] = {0};
DBVARIANT dbv;
dbv.type = DBVT_ASCIIZ;
dbv.pszVal = protobuf;
dbv.cchVal = sizeof(protobuf);
- if (GetContactSettingStatic(hContact, "Protocol", "p", &dbv) != 0 || (dbv.type != DBVT_ASCIIZ))
+ if (GetContactSettingStatic(cc->contactID, "Protocol", "p", &dbv) != 0 || (dbv.type != DBVT_ASCIIZ))
return 0;
cc->szProto = m_cache->GetCachedSetting(NULL, protobuf, 0, (int)strlen(protobuf));
@@ -68,27 +64,29 @@ STDMETHODIMP_(HANDLE) CDataBase::AddContact(void)
if (res == DBT_INVALIDPARAM)
return (HANDLE)1;
+ m_cache->AddContactToCache(res);
+
NotifyEventHooks(hContactAddedEvent, res, 0);
return (HANDLE)res;
}
-STDMETHODIMP_(LONG) CDataBase::DeleteContact(HANDLE hContact)
+STDMETHODIMP_(LONG) CDataBase::DeleteContact(MCONTACT contactID)
{
- NotifyEventHooks(hContactDeletedEvent, (WPARAM)hContact, 0);
+ NotifyEventHooks(hContactDeletedEvent, contactID, 0);
- int res = DBEntityDelete((WPARAM)hContact, 0);
+ int res = DBEntityDelete(contactID, 0);
if (res == DBT_INVALIDPARAM)
return 1;
if (res == 0)
- m_cache->FreeCachedContact(hContact);
+ m_cache->FreeCachedContact(contactID);
return res;
}
-STDMETHODIMP_(BOOL) CDataBase::IsDbContact(HANDLE hContact)
+STDMETHODIMP_(BOOL) CDataBase::IsDbContact(MCONTACT contactID)
{
- int flags = DBEntityGetFlags((WPARAM)hContact, 0);
+ int flags = DBEntityGetFlags(contactID, 0);
return (flags != DBT_INVALIDPARAM) &&
((flags & DBT_NFM_SpecialEntity) == 0);
}
@@ -118,36 +116,32 @@ STDMETHODIMP_(LONG) CDataBase::GetContactCount(void)
return c;
}
-STDMETHODIMP_(HANDLE) CDataBase::FindFirstContact(const char* szProto)
+STDMETHODIMP_(MCONTACT) CDataBase::FindFirstContact(const char* szProto)
{
- HANDLE hContact = (HANDLE)getEntities().compFirstContact();
- if (!szProto || CheckProto(hContact, szProto))
- return hContact;
+ DBCachedContact *cc = m_cache->GetFirstContact();
+ if (cc == NULL)
+ return NULL;
+
+ if (!szProto || CheckProto(cc, szProto))
+ return cc->contactID;
- return FindNextContact(hContact, szProto);
+ return FindNextContact(cc->contactID, szProto);
}
-STDMETHODIMP_(HANDLE) CDataBase::FindNextContact(HANDLE hContact, const char* szProto)
+STDMETHODIMP_(MCONTACT) CDataBase::FindNextContact(MCONTACT contactID, const char* szProto)
{
- while (hContact) {
- DBCachedContact *VL = m_cache->GetCachedContact(hContact);
- if (VL == NULL)
- VL = m_cache->AddContactToCache(hContact);
+ while (contactID) {
+ DBCachedContact *cc = m_cache->GetNextContact(contactID);
+ if (cc == NULL)
+ break;
- if (VL->hNext != NULL) {
- if (!szProto || CheckProto(VL->hNext, szProto))
- return VL->hNext;
+ if (!szProto || CheckProto(cc, szProto))
+ return cc->contactID;
- hContact = VL->hNext;
- continue;
- }
-
- VL->hNext = (HANDLE)getEntities().compNextContact((WPARAM)hContact);
- if (VL->hNext != NULL && (!szProto || CheckProto(VL->hNext, szProto)))
- return VL->hNext;
-
- hContact = VL->hNext;
+ contactID = cc->contactID;
+ continue;
}
+
return NULL;
}
@@ -189,7 +183,7 @@ __forceinline void DecodeString(LPSTR buf)
/////////////////////////////////////////////////////////////////////////////////////////
-STDMETHODIMP_(BOOL) CDataBase::GetContactSetting(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
+STDMETHODIMP_(BOOL) CDataBase::GetContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
{
dbv->type = 0;
@@ -208,7 +202,7 @@ STDMETHODIMP_(BOOL) CDataBase::GetContactSetting(HANDLE hContact, LPCSTR szModul
TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0};
TDBTSetting set = {0,0,0,0};
desc.cbSize = sizeof(desc);
- desc.Entity = (WPARAM)hContact;
+ desc.Entity = contactID;
desc.pszSettingName = namebuf;
set.cbSize = sizeof(set);
@@ -277,7 +271,7 @@ STDMETHODIMP_(BOOL) CDataBase::GetContactSetting(HANDLE hContact, LPCSTR szModul
return 0;
}
-STDMETHODIMP_(BOOL) CDataBase::GetContactSettingStr(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
+STDMETHODIMP_(BOOL) CDataBase::GetContactSettingStr(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
{
if ((dbv->type & DBVTF_VARIABLELENGTH) == 0)
{
@@ -296,7 +290,7 @@ STDMETHODIMP_(BOOL) CDataBase::GetContactSettingStr(HANDLE hContact, LPCSTR szMo
TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0};
TDBTSetting set = {0,0,0,0};
desc.cbSize = sizeof(desc);
- desc.Entity = (WPARAM)hContact;
+ desc.Entity = contactID;
desc.pszSettingName = namebuf;
set.cbSize = sizeof(set);
@@ -376,7 +370,7 @@ STDMETHODIMP_(BOOL) CDataBase::GetContactSettingStr(HANDLE hContact, LPCSTR szMo
return 0;
}
-STDMETHODIMP_(BOOL) CDataBase::GetContactSettingStatic(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
+STDMETHODIMP_(BOOL) CDataBase::GetContactSettingStatic(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
{
char namebuf[512];
namebuf[0] = 0;
@@ -389,7 +383,7 @@ STDMETHODIMP_(BOOL) CDataBase::GetContactSettingStatic(HANDLE hContact, LPCSTR s
TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0};
TDBTSetting set = {0,0,0,0};
desc.cbSize = sizeof(desc);
- desc.Entity = (WPARAM)hContact;
+ desc.Entity = contactID;
desc.pszSettingName = namebuf;
set.cbSize = sizeof(set);
@@ -504,7 +498,7 @@ STDMETHODIMP_(BOOL) CDataBase::FreeVariant(DBVARIANT *dbv)
return 0;
}
-STDMETHODIMP_(BOOL) CDataBase::WriteContactSetting(HANDLE hContact, DBCONTACTWRITESETTING *dbcws)
+STDMETHODIMP_(BOOL) CDataBase::WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws)
{
char namebuf[512];
namebuf[0] = 0;
@@ -517,7 +511,7 @@ STDMETHODIMP_(BOOL) CDataBase::WriteContactSetting(HANDLE hContact, DBCONTACTWRI
TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0};
TDBTSetting set = {0,0,0,0};
desc.cbSize = sizeof(desc);
- desc.Entity = (WPARAM)hContact;
+ desc.Entity = contactID;
desc.pszSettingName = namebuf;
set.cbSize = sizeof(set);
@@ -586,17 +580,17 @@ STDMETHODIMP_(BOOL) CDataBase::WriteContactSetting(HANDLE hContact, DBCONTACTWRI
dbcws->value.type = DBVT_UTF8;
wchar_t * tmp = dbcws->value.pwszVal;
dbcws->value.pszVal = mir_utf8encodeW(dbcws->value.pwszVal);
- NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)dbcws);
+ NotifyEventHooks(hSettingChangeEvent, contactID, (LPARAM)dbcws);
mir_free(dbcws->value.pszVal);
dbcws->value.type = DBVT_WCHAR;
dbcws->value.pwszVal = tmp;
}
- else NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)dbcws);
+ else NotifyEventHooks(hSettingChangeEvent, contactID, (LPARAM)dbcws);
return 0;
}
-STDMETHODIMP_(BOOL) CDataBase::DeleteContactSetting(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting)
+STDMETHODIMP_(BOOL) CDataBase::DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting)
{
char namebuf[512];
namebuf[0] = 0;
@@ -608,7 +602,7 @@ STDMETHODIMP_(BOOL) CDataBase::DeleteContactSetting(HANDLE hContact, LPCSTR szMo
TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0};
desc.cbSize = sizeof(desc);
- desc.Entity = (WPARAM)hContact;
+ desc.Entity = contactID;
desc.pszSettingName = namebuf;
if (DBSettingDelete(reinterpret_cast<WPARAM>(&desc), 0) == DBT_INVALIDPARAM)
@@ -619,17 +613,17 @@ STDMETHODIMP_(BOOL) CDataBase::DeleteContactSetting(HANDLE hContact, LPCSTR szMo
tmp.szModule = szModule;
tmp.szSetting = szSetting;
tmp.value.type = 0;
- NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp);
+ NotifyEventHooks(hSettingChangeEvent, contactID, (LPARAM)&tmp);
}
return 0;
}
-STDMETHODIMP_(BOOL) CDataBase::EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* pces)
+STDMETHODIMP_(BOOL) CDataBase::EnumContactSettings(MCONTACT contactID, DBCONTACTENUMSETTINGS* pces)
{
TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0};
desc.cbSize = sizeof(desc);
- desc.Entity = (WPARAM)hContact;
+ desc.Entity = contactID;
char namebuf[512];
namebuf[0] = 0;
@@ -640,7 +634,7 @@ STDMETHODIMP_(BOOL) CDataBase::EnumContactSettings(HANDLE hContact, DBCONTACTENU
TDBTSettingIterFilter filter = {0,0,0,0,0,0,0,0};
filter.cbSize = sizeof(filter);
filter.Descriptor = &desc;
- filter.hEntity = (WPARAM)(WPARAM)hContact;
+ filter.hEntity = (WPARAM)contactID;
filter.NameStart = namebuf;
TDBTSettingIterationHandle hiter = DBSettingIterInit(reinterpret_cast<WPARAM>(&filter), 0);
@@ -675,26 +669,25 @@ STDMETHODIMP_(BOOL) CDataBase::EnumContactSettings(HANDLE hContact, DBCONTACTENU
return res;
}
-STDMETHODIMP_(LONG) CDataBase::GetEventCount(HANDLE hContact)
+STDMETHODIMP_(LONG) CDataBase::GetEventCount(MCONTACT contactID)
{
- if (hContact == 0)
- hContact = (HANDLE)getEntities().getRootEntity();
+ if (contactID == 0)
+ contactID = getEntities().getRootEntity();
- return DBEventGetCount((WPARAM)hContact, 0);
+ return DBEventGetCount(contactID, 0);
}
-STDMETHODIMP_(HANDLE) CDataBase::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
+STDMETHODIMP_(HANDLE) CDataBase::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
{
if (dbei->cbSize < sizeof(DBEVENTINFO))
return (HANDLE)-1;
- int tmp = NotifyEventHooks(hEventFilterAddedEvent, (WPARAM)hContact, (LPARAM)dbei);
+ int tmp = NotifyEventHooks(hEventFilterAddedEvent, contactID, (LPARAM)dbei);
if (tmp != 0)
return (HANDLE)tmp;
- if (hContact == 0)
- hContact = (HANDLE)getEntities().getRootEntity();
-
+ if (contactID == 0)
+ contactID = getEntities().getRootEntity();
TDBTEvent ev = {0,0,0,0,0,0,0};
ev.cbSize = sizeof(ev);
@@ -707,21 +700,21 @@ STDMETHODIMP_(HANDLE) CDataBase::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
ev.cbBlob = dbei->cbBlob;
ev.pBlob = dbei->pBlob;
- int res = DBEventAdd((WPARAM)hContact, reinterpret_cast<LPARAM>(&ev));
+ int res = DBEventAdd(contactID, reinterpret_cast<LPARAM>(&ev));
if (res != DBT_INVALIDPARAM)
{
- NotifyEventHooks(hEventAddedEvent, (WPARAM)hContact, res);
+ NotifyEventHooks(hEventAddedEvent, contactID, res);
return (HANDLE)res;
}
return NULL;
}
-STDMETHODIMP_(BOOL) CDataBase::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
+STDMETHODIMP_(BOOL) CDataBase::DeleteEvent(MCONTACT contactID, HANDLE hDbEvent)
{
- int res = NotifyEventHooks(hEventDeletedEvent, (WPARAM)hContact, (WPARAM)hDbEvent);
+ int res = NotifyEventHooks(hEventDeletedEvent, contactID, (WPARAM)hDbEvent);
- if (hContact == 0)
- hContact = (HANDLE)getEntities().getRootEntity();
+ if (contactID == 0)
+ contactID = getEntities().getRootEntity();
if (res == 0)
return DBEventDelete((WPARAM)hDbEvent, 0);
@@ -773,7 +766,7 @@ STDMETHODIMP_(BOOL) CDataBase::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
return res;
}
-STDMETHODIMP_(BOOL) CDataBase::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
+STDMETHODIMP_(BOOL) CDataBase::MarkEventRead(MCONTACT contactID, HANDLE hDbEvent)
{
int res = DBEventMarkRead((WPARAM)hDbEvent, 0);
if ((res != DBT_INVALIDPARAM) && (res & DBEF_SENT))
@@ -790,26 +783,26 @@ STDMETHODIMP_(HANDLE) CDataBase::GetEventContact(HANDLE hDbEvent)
return (HANDLE)res;
}
-STDMETHODIMP_(HANDLE) CDataBase::FindFirstEvent(HANDLE hContact)
+STDMETHODIMP_(HANDLE) CDataBase::FindFirstEvent(MCONTACT contactID)
{
- if (hContact == 0)
- hContact = (HANDLE)getEntities().getRootEntity();
+ if (contactID == 0)
+ contactID = getEntities().getRootEntity();
- return (HANDLE)getEvents().compFirstEvent((WPARAM)hContact);
+ return (HANDLE)getEvents().compFirstEvent(contactID);
}
-STDMETHODIMP_(HANDLE) CDataBase::FindFirstUnreadEvent(HANDLE hContact)
+STDMETHODIMP_(HANDLE) CDataBase::FindFirstUnreadEvent(MCONTACT contactID)
{
- if (hContact == 0)
- hContact = (HANDLE)getEntities().getRootEntity();
- return (HANDLE)getEvents().compFirstUnreadEvent((WPARAM)hContact);
+ if (contactID == 0)
+ contactID = getEntities().getRootEntity();
+ return (HANDLE)getEvents().compFirstUnreadEvent(contactID);
}
-STDMETHODIMP_(HANDLE) CDataBase::FindLastEvent(HANDLE hContact)
+STDMETHODIMP_(HANDLE) CDataBase::FindLastEvent(MCONTACT contactID)
{
- if (hContact == 0)
- hContact = (HANDLE)getEntities().getRootEntity();
- return (HANDLE)getEvents().compLastEvent((WPARAM)hContact);
+ if (contactID == 0)
+ contactID = getEntities().getRootEntity();
+ return (HANDLE)getEvents().compLastEvent(contactID);
}
STDMETHODIMP_(HANDLE) CDataBase::FindNextEvent(HANDLE hDbEvent)
diff --git a/plugins/Dbx_tree/src/DataBase.cpp b/plugins/Dbx_tree/src/DataBase.cpp
index 683f0b66a8..465ceae643 100644
--- a/plugins/Dbx_tree/src/DataBase.cpp
+++ b/plugins/Dbx_tree/src/DataBase.cpp
@@ -243,6 +243,11 @@ int CDataBase::OpenDB()
*m_Entities,
*m_Settings);
+ for (MCONTACT id = m_Entities->compFirstContact(); id != 0; id = m_Entities->compNextContact(id)) {
+ DBCachedContact *cc = m_cache->AddContactToCache(id);
+ CheckProto(cc, "");
+ }
+
return 0;
}
diff --git a/plugins/Dbx_tree/src/DataBase.h b/plugins/Dbx_tree/src/DataBase.h
index 0cff291944..b19ceebb1c 100644
--- a/plugins/Dbx_tree/src/DataBase.h
+++ b/plugins/Dbx_tree/src/DataBase.h
@@ -196,37 +196,37 @@ protected: // to be compatible with the standard Miranda databases
STDMETHODIMP_(void) SetCacheSafetyMode(BOOL);
STDMETHODIMP_(LONG) GetContactCount(void);
- STDMETHODIMP_(HANDLE) FindFirstContact(const char* szProto = NULL);
- STDMETHODIMP_(HANDLE) FindNextContact(HANDLE hContact, const char* szProto = NULL);
- STDMETHODIMP_(LONG) DeleteContact(HANDLE hContact);
+ STDMETHODIMP_(MCONTACT) FindFirstContact(const char* szProto = NULL);
+ STDMETHODIMP_(MCONTACT) FindNextContact(MCONTACT contactID, const char* szProto = NULL);
+ STDMETHODIMP_(LONG) DeleteContact(MCONTACT contactID);
STDMETHODIMP_(HANDLE) AddContact(void);
- STDMETHODIMP_(BOOL) IsDbContact(HANDLE hContact);
+ STDMETHODIMP_(BOOL) IsDbContact(MCONTACT contactID);
- STDMETHODIMP_(LONG) GetEventCount(HANDLE hContact);
- STDMETHODIMP_(HANDLE) AddEvent(HANDLE hContact, DBEVENTINFO *dbe);
- STDMETHODIMP_(BOOL) DeleteEvent(HANDLE hContact, HANDLE hDbEvent);
+ STDMETHODIMP_(LONG) GetEventCount(MCONTACT contactID);
+ STDMETHODIMP_(HANDLE) AddEvent(MCONTACT contactID, DBEVENTINFO *dbe);
+ STDMETHODIMP_(BOOL) DeleteEvent(MCONTACT contactID, HANDLE hDbEvent);
STDMETHODIMP_(LONG) GetBlobSize(HANDLE hDbEvent);
STDMETHODIMP_(BOOL) GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbe);
- STDMETHODIMP_(BOOL) MarkEventRead(HANDLE hContact, HANDLE hDbEvent);
+ STDMETHODIMP_(BOOL) MarkEventRead(MCONTACT contactID, HANDLE hDbEvent);
STDMETHODIMP_(HANDLE) GetEventContact(HANDLE hDbEvent);
- STDMETHODIMP_(HANDLE) FindFirstEvent(HANDLE hContact);
- STDMETHODIMP_(HANDLE) FindFirstUnreadEvent(HANDLE hContact);
- STDMETHODIMP_(HANDLE) FindLastEvent(HANDLE hContact);
+ STDMETHODIMP_(HANDLE) FindFirstEvent(MCONTACT contactID);
+ STDMETHODIMP_(HANDLE) FindFirstUnreadEvent(MCONTACT contactID);
+ STDMETHODIMP_(HANDLE) FindLastEvent(MCONTACT contactID);
STDMETHODIMP_(HANDLE) FindNextEvent(HANDLE hDbEvent);
STDMETHODIMP_(HANDLE) FindPrevEvent(HANDLE hDbEvent);
STDMETHODIMP_(BOOL) EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam);
- STDMETHODIMP_(BOOL) GetContactSetting(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv);
- STDMETHODIMP_(BOOL) GetContactSettingStr(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv);
- STDMETHODIMP_(BOOL) GetContactSettingStatic(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv);
+ STDMETHODIMP_(BOOL) GetContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv);
+ STDMETHODIMP_(BOOL) GetContactSettingStr(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv);
+ STDMETHODIMP_(BOOL) GetContactSettingStatic(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv);
STDMETHODIMP_(BOOL) FreeVariant(DBVARIANT *dbv);
- STDMETHODIMP_(BOOL) WriteContactSetting(HANDLE hContact, DBCONTACTWRITESETTING *dbcws);
- STDMETHODIMP_(BOOL) DeleteContactSetting(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting);
- STDMETHODIMP_(BOOL) EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces);
+ STDMETHODIMP_(BOOL) WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws);
+ STDMETHODIMP_(BOOL) DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting);
+ STDMETHODIMP_(BOOL) EnumContactSettings(MCONTACT contactID, DBCONTACTENUMSETTINGS* dbces);
STDMETHODIMP_(BOOL) SetSettingResident(BOOL bIsResident, const char *pszSettingName);
STDMETHODIMP_(BOOL) EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam);
STDMETHODIMP_(BOOL) IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting);
- int CheckProto(HANDLE hContact, const char *proto);
+ int CheckProto(DBCachedContact *cc, const char *proto);
};
diff --git a/plugins/Dbx_tree/src/Services.cpp b/plugins/Dbx_tree/src/Services.cpp
index f7495e2225..412b05d76b 100644
--- a/plugins/Dbx_tree/src/Services.cpp
+++ b/plugins/Dbx_tree/src/Services.cpp
@@ -369,7 +369,7 @@ void CDataBase::CreateDbService(const char* szService, DbServiceFunc serviceProc
bool CDataBase::RegisterServices()
{
- CreateDbService(MS_DBT_ENTITY_GETROOT, &CDataBase::DBEntityGetRoot);
+ CreateDbService(MS_DBT_ENTITY_GETROOT, &CDataBase::DBEntityGetRoot);
CreateDbService(MS_DBT_ENTITY_CHILDCOUNT, &CDataBase::DBEntityChildCount);
CreateDbService(MS_DBT_ENTITY_GETPARENT, &CDataBase::DBEntityGetParent);
CreateDbService(MS_DBT_ENTITY_MOVE, &CDataBase::DBEntityMove);
diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp
index 7d15029661..dbb6e5a02b 100644
--- a/plugins/Import/src/import.cpp
+++ b/plugins/Import/src/import.cpp
@@ -31,26 +31,26 @@ static MIDatabase *srcDb, *dstDb;
/////////////////////////////////////////////////////////////////////////////////////////
-static int myGet(HANDLE hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv)
+static int myGet(MCONTACT hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv)
{
dbv->type = 0;
return srcDb->GetContactSetting(hContact, szModule, szSetting, dbv);
}
-static TCHAR* myGetWs(HANDLE hContact, const char *szModule, const char *szSetting)
+static TCHAR* myGetWs(MCONTACT hContact, const char *szModule, const char *szSetting)
{
DBVARIANT dbv = { DBVT_TCHAR };
return srcDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv) ? NULL : dbv.ptszVal;
}
-static BOOL myGetS(HANDLE hContact, const char *szModule, const char *szSetting, char* dest)
+static BOOL myGetS(MCONTACT hContact, const char *szModule, const char *szSetting, char* dest)
{
DBVARIANT dbv = { DBVT_ASCIIZ };
dbv.pszVal = dest; dbv.cchVal = 100;
return srcDb->GetContactSettingStatic(hContact, szModule, szSetting, &dbv);
}
-static void mySet(HANDLE hContact, const char *module, const char *var, DBVARIANT *dbv)
+static void mySet(MCONTACT hContact, const char *module, const char *var, DBVARIANT *dbv)
{
DBCONTACTWRITESETTING dbw;
dbw.szModule = module;
@@ -61,79 +61,79 @@ static void mySet(HANDLE hContact, const char *module, const char *var, DBVARIAN
/////////////////////////////////////////////////////////////////////////////////////////
-static HANDLE HContactFromNumericID(char* pszProtoName, char* pszSetting, DWORD dwID)
+static MCONTACT HContactFromNumericID(char *pszProtoName, char *pszSetting, DWORD dwID)
{
- HANDLE hContact = dstDb->FindFirstContact();
+ MCONTACT hContact = dstDb->FindFirstContact();
while (hContact != NULL) {
- if ( db_get_dw(hContact, pszProtoName, pszSetting, 0) == dwID) {
- char* szProto = GetContactProto(hContact);
+ if ( db_get_dw((HANDLE)hContact, pszProtoName, pszSetting, 0) == dwID) {
+ char* szProto = GetContactProto((HANDLE)hContact);
if (szProto != NULL && !lstrcmpA(szProto, pszProtoName))
return hContact;
}
- hContact = dstDb->FindNextContact(hContact);
+ hContact = dstDb->FindNextContact((MCONTACT)hContact);
}
- return INVALID_HANDLE_VALUE;
+ return INVALID_CONTACT_ID;
}
-static HANDLE HContactFromID(char* pszProtoName, char* pszSetting, TCHAR* pwszID)
+static MCONTACT HContactFromID(char *pszProtoName, char *pszSetting, TCHAR *pwszID)
{
- HANDLE hContact = dstDb->FindFirstContact();
+ MCONTACT hContact = dstDb->FindFirstContact();
while (hContact != NULL) {
- char* szProto = GetContactProto(hContact);
+ char* szProto = GetContactProto((HANDLE)hContact);
if ( !lstrcmpA(szProto, pszProtoName)) {
- ptrW id( db_get_tsa(hContact, pszProtoName, pszSetting));
+ ptrW id(db_get_tsa((HANDLE)hContact, pszProtoName, pszSetting));
if ( !lstrcmp(pwszID, id))
return hContact;
}
- hContact = dstDb->FindNextContact(hContact);
+ hContact = (MCONTACT)dstDb->FindNextContact(hContact);
}
- return INVALID_HANDLE_VALUE;
+ return INVALID_CONTACT_ID;
}
-static HANDLE HistoryImportFindContact(HWND hdlgProgress, char* szModuleName, DWORD uin, int addUnknown)
+static MCONTACT HistoryImportFindContact(HWND hdlgProgress, char* szModuleName, DWORD uin, int addUnknown)
{
- HANDLE hContact = HContactFromNumericID(szModuleName, "UIN", uin);
+ MCONTACT hContact = HContactFromNumericID(szModuleName, "UIN", uin);
if (hContact == NULL) {
AddMessage( LPGENT("Ignored event from/to self"));
- return INVALID_HANDLE_VALUE;
+ return INVALID_CONTACT_ID;
}
- if (hContact != INVALID_HANDLE_VALUE)
+ if (hContact != INVALID_CONTACT_ID)
return hContact;
if (!addUnknown)
- return INVALID_HANDLE_VALUE;
+ return INVALID_CONTACT_ID;
- hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0);
- CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)szModuleName);
- db_set_dw(hContact, szModuleName, "UIN", uin);
+ hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
+ CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)szModuleName);
+ db_set_dw((HANDLE)hContact, szModuleName, "UIN", uin);
AddMessage( LPGENT("Added contact %u (found in history)"), uin );
return hContact;
}
/////////////////////////////////////////////////////////////////////////////////////////
-static HANDLE AddContact(HWND hdlgProgress, char* szProto, char* pszUniqueSetting, DBVARIANT* id, const TCHAR* pszUserID, TCHAR *nick, TCHAR *group)
+static MCONTACT AddContact(HWND hdlgProgress, char* szProto, char* pszUniqueSetting, DBVARIANT* id, const TCHAR* pszUserID, TCHAR *nick, TCHAR *group)
{
- HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0);
- if ( CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)szProto) != 0) {
- CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0);
- AddMessage( LPGENT("Failed to add %S contact %s"), szProto, pszUserID );
- return INVALID_HANDLE_VALUE;
+ MCONTACT hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
+ if (CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)szProto) != 0) {
+ CallService(MS_DB_CONTACT_DELETE, hContact, 0);
+ AddMessage(LPGENT("Failed to add %S contact %s"), szProto, pszUserID);
+ return INVALID_CONTACT_ID;
}
- mySet( hContact, szProto, pszUniqueSetting, id );
+ mySet(hContact, szProto, pszUniqueSetting, id);
- CreateGroup(group, hContact);
+ CreateGroup(group, (HANDLE)hContact);
if (nick && *nick) {
- db_set_ws(hContact, "CList", "MyHandle", nick );
- AddMessage( LPGENT("Added %S contact %s, '%s'"), szProto, pszUserID, nick);
+ db_set_ws((HANDLE)hContact, "CList", "MyHandle", nick);
+ AddMessage(LPGENT("Added %S contact %s, '%s'"), szProto, pszUserID, nick);
}
- else AddMessage( LPGENT("Added %S contact %s"), szProto, pszUserID);
+ else AddMessage(LPGENT("Added %S contact %s"), szProto, pszUserID);
- srcDb->FreeVariant( id );
+ srcDb->FreeVariant(id);
return hContact;
}
@@ -164,33 +164,33 @@ static int ImportGroups()
return nGroups;
}
-static HANDLE ImportContact(HANDLE hSrc)
+static MCONTACT ImportContact(MCONTACT hSrc)
{
- HANDLE hDst;
+ MCONTACT hDst;
TCHAR id[ 40 ], *pszUniqueID;
char szProto[100];
// Check what protocol this contact belongs to
- if ( myGetS(hSrc, "Protocol", "p", szProto)) {
- AddMessage( LPGENT("Skipping contact with no protocol"));
+ if (myGetS(hSrc, "Protocol", "p", szProto)) {
+ AddMessage(LPGENT("Skipping contact with no protocol"));
return NULL;
}
- if ( !IsProtocolLoaded(szProto)) {
- AddMessage( LPGENT("Skipping contact, %S not installed."), szProto);
+ if (!IsProtocolLoaded(szProto)) {
+ AddMessage(LPGENT("Skipping contact, %S not installed."), szProto);
return NULL;
}
// Skip protocols with no unique id setting (some non IM protocols return NULL)
char* pszUniqueSetting = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
- if ( !pszUniqueSetting || (INT_PTR)pszUniqueSetting == CALLSERVICE_NOTFOUND ) {
- AddMessage( LPGENT("Skipping non-IM contact (%S)"), szProto );
+ if (!pszUniqueSetting || (INT_PTR)pszUniqueSetting == CALLSERVICE_NOTFOUND) {
+ AddMessage(LPGENT("Skipping non-IM contact (%S)"), szProto);
return NULL;
}
DBVARIANT dbv;
- if ( myGet(hSrc, szProto, pszUniqueSetting, &dbv)) {
- AddMessage( LPGENT("Skipping %S contact, ID not found"), szProto);
+ if (myGet(hSrc, szProto, pszUniqueSetting, &dbv)) {
+ AddMessage(LPGENT("Skipping %S contact, ID not found"), szProto);
return NULL;
}
@@ -198,11 +198,11 @@ static HANDLE ImportContact(HANDLE hSrc)
switch (dbv.type) {
case DBVT_DWORD:
pszUniqueID = _ltot(dbv.dVal, id, 10);
- hDst = HContactFromNumericID( szProto, pszUniqueSetting, dbv.dVal );
+ hDst = HContactFromNumericID(szProto, pszUniqueSetting, dbv.dVal);
break;
case DBVT_ASCIIZ:
- pszUniqueID = NEWTSTR_ALLOCA( _A2T(dbv.pszVal));
+ pszUniqueID = NEWTSTR_ALLOCA(_A2T(dbv.pszVal));
hDst = HContactFromID(szProto, pszUniqueSetting, pszUniqueID);
break;
@@ -212,9 +212,9 @@ static HANDLE ImportContact(HANDLE hSrc)
break;
}
- if (hDst != INVALID_HANDLE_VALUE) {
- AddMessage( LPGENT("Skipping duplicate %S contact %s"), szProto, pszUniqueID );
- srcDb->FreeVariant( &dbv );
+ if (hDst != INVALID_CONTACT_ID) {
+ AddMessage(LPGENT("Skipping duplicate %S contact %s"), szProto, pszUniqueID);
+ srcDb->FreeVariant(&dbv);
return NULL;
}
@@ -225,56 +225,56 @@ static HANDLE ImportContact(HANDLE hSrc)
hDst = AddContact(hdlgProgress, szProto, pszUniqueSetting, &dbv, pszUniqueID, tszNick, tszGroup);
mir_free(tszGroup), mir_free(tszNick);
- if ( hDst != INVALID_HANDLE_VALUE) {
+ if (hDst != INVALID_CONTACT_ID) {
// Hidden?
- if ( !myGet(hSrc, "CList", "Hidden", &dbv )) {
+ if (!myGet(hSrc, "CList", "Hidden", &dbv)) {
mySet(hDst, "CList", "Hidden", &dbv);
srcDb->FreeVariant(&dbv);
}
// Ignore settings
- if ( !myGet(hSrc, "Ignore", "Mask1", &dbv )) {
- mySet( hDst, "Ignore", "Mask1", &dbv );
+ if (!myGet(hSrc, "Ignore", "Mask1", &dbv)) {
+ mySet(hDst, "Ignore", "Mask1", &dbv);
srcDb->FreeVariant(&dbv);
}
// Apparent mode
- if ( !myGet(hSrc, szProto, "ApparentMode", &dbv )) {
- mySet( hDst, szProto, "ApparentMode", &dbv );
+ if (!myGet(hSrc, szProto, "ApparentMode", &dbv)) {
+ mySet(hDst, szProto, "ApparentMode", &dbv);
srcDb->FreeVariant(&dbv);
}
// Nick
- if ( !myGet(hSrc, szProto, "Nick", &dbv )) {
- mySet( hDst, szProto, "Nick", &dbv );
+ if (!myGet(hSrc, szProto, "Nick", &dbv)) {
+ mySet(hDst, szProto, "Nick", &dbv);
srcDb->FreeVariant(&dbv);
}
// Myhandle
- if ( !myGet(hSrc, szProto, "MyHandle", &dbv )) {
- mySet( hDst, szProto, "MyHandle", &dbv );
+ if (!myGet(hSrc, szProto, "MyHandle", &dbv)) {
+ mySet(hDst, szProto, "MyHandle", &dbv);
srcDb->FreeVariant(&dbv);
}
// First name
- if ( !myGet(hSrc, szProto, "FirstName", &dbv )) {
- mySet( hDst, szProto, "FirstName", &dbv );
+ if (!myGet(hSrc, szProto, "FirstName", &dbv)) {
+ mySet(hDst, szProto, "FirstName", &dbv);
srcDb->FreeVariant(&dbv);
}
// Last name
- if ( !myGet(hSrc, szProto, "LastName", &dbv )) {
- mySet( hDst, szProto, "LastName", &dbv );
+ if (!myGet(hSrc, szProto, "LastName", &dbv)) {
+ mySet(hDst, szProto, "LastName", &dbv);
srcDb->FreeVariant(&dbv);
}
// About
- if ( !myGet(hSrc, szProto, "About", &dbv )) {
- mySet( hDst, szProto, "About", &dbv );
+ if (!myGet(hSrc, szProto, "About", &dbv)) {
+ mySet(hDst, szProto, "About", &dbv);
srcDb->FreeVariant(&dbv);
}
}
- else AddMessage( LPGENT("Unknown error while adding %S contact %s"), szProto, pszUniqueID );
+ else AddMessage(LPGENT("Unknown error while adding %S contact %s"), szProto, pszUniqueID);
return hDst;
}
@@ -284,28 +284,28 @@ static HANDLE ImportContact(HANDLE hSrc)
// would only be a repetition of the messages printed during contact
// import.
-static HANDLE convertContact(HANDLE hContact)
+static MCONTACT convertContact(MCONTACT hContact)
{
// Check what protocol this contact belongs to
char szProto[100];
- if ( myGetS(hContact, "Protocol", "p", szProto))
- return INVALID_HANDLE_VALUE;
+ if (myGetS(hContact, "Protocol", "p", szProto))
+ return INVALID_CONTACT_ID;
// Protocol installed?
- if ( !IsProtocolLoaded(szProto))
- return INVALID_HANDLE_VALUE;
+ if (!IsProtocolLoaded(szProto))
+ return INVALID_CONTACT_ID;
// Is contact in database?
char* pszUniqueSetting = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
// Skip protocols with no unique id setting (some non IM protocols return NULL)
- HANDLE hDst = INVALID_HANDLE_VALUE;
- if ( pszUniqueSetting && ( INT_PTR )pszUniqueSetting != CALLSERVICE_NOTFOUND ) {
+ MCONTACT hDst = INVALID_CONTACT_ID;
+ if (pszUniqueSetting && (INT_PTR)pszUniqueSetting != CALLSERVICE_NOTFOUND) {
DBVARIANT dbv;
- if ( !myGet(hContact, szProto, pszUniqueSetting, &dbv)) {
+ if (!myGet(hContact, szProto, pszUniqueSetting, &dbv)) {
switch (dbv.type) {
case DBVT_DWORD:
- hDst = HContactFromNumericID( szProto, pszUniqueSetting, dbv.dVal );
+ hDst = HContactFromNumericID(szProto, pszUniqueSetting, dbv.dVal);
break;
case DBVT_ASCIIZ:
@@ -316,19 +316,19 @@ static HANDLE convertContact(HANDLE hContact)
hDst = HContactFromID(szProto, pszUniqueSetting, dbv.ptszVal);
break;
}
- srcDb->FreeVariant( &dbv );
+ srcDb->FreeVariant(&dbv);
}
}
return hDst;
}
-static void ImportHistory(HANDLE hContact, PROTOACCOUNT **protocol, int protoCount)
+static void ImportHistory(MCONTACT hContact, PROTOACCOUNT **protocol, int protoCount)
{
// Is it contats history import?
- HANDLE hDst = (protoCount == 0) ? convertContact(hContact) : NULL; //system history import
+ MCONTACT hDst = (protoCount == 0) ? convertContact(hContact) : NULL; //system history import
// OK to import this chain?
- if (hDst == INVALID_HANDLE_VALUE) {
+ if (hDst == INVALID_CONTACT_ID) {
nSkippedContacts++;
return;
}
@@ -347,17 +347,17 @@ static void ImportHistory(HANDLE hContact, PROTOACCOUNT **protocol, int protoCou
DBEVENTINFO dbei = { sizeof(DBEVENTINFO) };
dbei.cbBlob = srcDb->GetBlobSize(hEvent);
if (dbei.cbBlob > cbAlloc) {
- cbAlloc = dbei.cbBlob + 4096 - dbei.cbBlob%4096;
+ cbAlloc = dbei.cbBlob + 4096 - dbei.cbBlob % 4096;
eventBuf = (PBYTE)mir_realloc(eventBuf, cbAlloc);
}
dbei.pBlob = eventBuf;
- if ( !srcDb->GetEvent(hEvent, &dbei)) {
+ if (!srcDb->GetEvent(hEvent, &dbei)) {
// check protocols during system history import
if (hDst == NULL) {
skipAll = 1;
for (int i = 0; i < protoCount; i++)
- if ( !strcmp(dbei.szModule, protocol[i]->szModuleName)) {
+ if (!strcmp(dbei.szModule, protocol[i]->szModuleName)) {
skipAll = 0;
break;
}
@@ -375,7 +375,7 @@ static void ImportHistory(HANDLE hContact, PROTOACCOUNT **protocol, int protoCou
if (!skip) {
if (hDst) {
skip = 1;
- switch(dbei.eventType) {
+ switch (dbei.eventType) {
case EVENTTYPE_MESSAGE:
if ((sent ? IOPT_MSGSENT : IOPT_MSGRECV) & nCustomOptions)
skip = 0;
@@ -394,7 +394,7 @@ static void ImportHistory(HANDLE hContact, PROTOACCOUNT **protocol, int protoCou
break;
}
}
- else if ( !( nCustomOptions & IOPT_SYSTEM ))
+ else if (!(nCustomOptions & IOPT_SYSTEM))
skip = 1;
}
@@ -404,29 +404,30 @@ static void ImportHistory(HANDLE hContact, PROTOACCOUNT **protocol, int protoCou
if (!skip) {
// Check for duplicate entries
- if ( !IsDuplicateEvent( hDst, dbei )) {
+ if (!IsDuplicateEvent((HANDLE)hDst, dbei)) {
// Add dbevent
if (!bIsVoidContact)
dbei.flags &= ~DBEF_FIRST;
if (dstDb->AddEvent(hDst, &dbei) != NULL)
nMessagesCount++;
else
- AddMessage( LPGENT("Failed to add message"));
+ AddMessage(LPGENT("Failed to add message"));
}
else
nDupes++;
}
}
- if ( !( i%10 )) {
+ if (!(i % 10)) {
MSG msg;
- if ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
- } }
+ }
+ }
// skip this chain if needed
- if ( skipAll )
+ if (skipAll)
break;
// Get next event
@@ -446,20 +447,20 @@ void MirandaImport(HWND hdlg)
// Just to keep the macros happy
hdlgProgress = hdlg;
if ((dstDb = GetCurrentDatabase()) == NULL) {
- AddMessage( LPGENT("Error retrieving current profile, exiting."));
+ AddMessage(LPGENT("Error retrieving current profile, exiting."));
return;
}
DATABASELINK* dblink = FindDatabasePlugin(importFile);
if (dblink == NULL) {
- AddMessage( LPGENT("There's no database driver to open the input file, exiting."));
+ AddMessage(LPGENT("There's no database driver to open the input file, exiting."));
return;
}
if ((srcDb = dblink->Load(importFile)) == NULL) {
- AddMessage( LPGENT("Error loading source file, exiting."));
+ AddMessage(LPGENT("Error loading source file, exiting."));
return;
- }
+ }
// Reset statistics
nSkippedEvents = 0;
@@ -472,8 +473,8 @@ void MirandaImport(HWND hdlg)
// Get number of contacts
int nNumberOfContacts = srcDb->GetContactCount();
- AddMessage( LPGENT("Number of contacts in database: %d"), nNumberOfContacts );
- AddMessage( _T(""));
+ AddMessage(LPGENT("Number of contacts in database: %d"), nNumberOfContacts);
+ AddMessage(_T(""));
// Configure database for fast writing
dstDb->SetCacheSafetyMode(FALSE);
@@ -483,22 +484,22 @@ void MirandaImport(HWND hdlg)
// Import Groups
if (nImportOption == IMPORT_ALL || (nCustomOptions & IOPT_GROUPS)) {
- AddMessage( LPGENT("Importing groups."));
+ AddMessage(LPGENT("Importing groups."));
nGroupsCount = ImportGroups();
if (nGroupsCount == -1)
- AddMessage( LPGENT("Group import failed."));
+ AddMessage(LPGENT("Group import failed."));
- AddMessage( _T(""));
+ AddMessage(_T(""));
}
// End of Import Groups
// Import Contacts
if (nImportOption != IMPORT_CUSTOM || (nCustomOptions & IOPT_CONTACTS)) {
- AddMessage( LPGENT("Importing contacts."));
+ AddMessage(LPGENT("Importing contacts."));
int i = 1;
- HANDLE hContact = srcDb->FindFirstContact();
+ MCONTACT hContact = srcDb->FindFirstContact();
while (hContact != NULL) {
- if ( ImportContact(hContact))
+ if (ImportContact(hContact))
nContactsCount++;
// Update progress bar
@@ -515,15 +516,15 @@ void MirandaImport(HWND hdlg)
hContact = srcDb->FindNextContact(hContact);
}
}
- else AddMessage( LPGENT("Skipping new contacts import."));
- AddMessage( _T(""));
+ else AddMessage(LPGENT("Skipping new contacts import."));
+ AddMessage(_T(""));
// End of Import Contacts
// Import history
if (nImportOption != IMPORT_CONTACTS) {
// Import NULL contact message chain
if (nImportOption == IMPORT_ALL || (nCustomOptions & IOPT_SYSTEM)) {
- AddMessage( LPGENT("Importing system history."));
+ AddMessage(LPGENT("Importing system history."));
int protoCount;
PROTOACCOUNT **accs;
@@ -532,24 +533,24 @@ void MirandaImport(HWND hdlg)
if (protoCount > 0)
ImportHistory(NULL, accs, protoCount);
}
- else AddMessage( LPGENT("Skipping system history import."));
+ else AddMessage(LPGENT("Skipping system history import."));
- AddMessage( _T(""));
+ AddMessage(_T(""));
// Import other contact messages
if (nImportOption == IMPORT_ALL || (nCustomOptions & 2046)) { // 2 - 1024 types
- AddMessage( LPGENT("Importing history."));
- HANDLE hContact = srcDb->FindFirstContact();
- for (int i=1; hContact != NULL; i++) {
+ AddMessage(LPGENT("Importing history."));
+ MCONTACT hContact = srcDb->FindFirstContact();
+ for (int i = 1; hContact != NULL; i++) {
ImportHistory(hContact, NULL, NULL);
SetProgress(100 * i / nNumberOfContacts);
hContact = srcDb->FindNextContact(hContact);
}
}
- else AddMessage( LPGENT("Skipping history import."));
+ else AddMessage(LPGENT("Skipping history import."));
- AddMessage( _T(""));
+ AddMessage(_T(""));
}
// End of Import History
@@ -563,15 +564,15 @@ void MirandaImport(HWND hdlg)
dwTimer = time(NULL) - dwTimer;
// Print statistics
- AddMessage( LPGENT("Import completed in %d seconds."), dwTimer );
+ AddMessage(LPGENT("Import completed in %d seconds."), dwTimer);
SetProgress(100);
AddMessage((nImportOption == IMPORT_CONTACTS) ?
LPGENT("Added %d contacts and %d groups.") : LPGENT("Added %d contacts, %d groups and %d events."),
nContactsCount, nGroupsCount, nMessagesCount);
- if ( nImportOption != IMPORT_CONTACTS ) {
+ if (nImportOption != IMPORT_CONTACTS) {
if (nSkippedContacts)
- AddMessage( LPGENT("Skipped %d contacts."), nSkippedContacts );
+ AddMessage(LPGENT("Skipped %d contacts."), nSkippedContacts);
AddMessage((nImportOption == IMPORT_CUSTOM) ?
LPGENT("Skipped %d duplicates and %d filtered events.") : LPGENT("Skipped %d duplicates."),
diff --git a/src/mir_core/db.cpp b/src/mir_core/db.cpp
index 2cfbbfc0a1..5912b5125a 100644
--- a/src/mir_core/db.cpp
+++ b/src/mir_core/db.cpp
@@ -33,7 +33,8 @@ MIR_CORE_DLL(int) db_get_b(HANDLE hContact, const char *szModule, const char *sz
{
if (currDb != NULL) {
DBVARIANT dbv;
- if (!currDb->GetContactSetting(hContact, szModule, szSetting, &dbv)) {
+ if (!currDb->GetContactSetting((MCONTACT)hContact, szModule, szSetting, &dbv))
+ {
switch(dbv.type) {
case DBVT_BYTE: return dbv.bVal;
case DBVT_WORD: return BYTE(dbv.wVal);
@@ -49,7 +50,7 @@ MIR_CORE_DLL(int) db_get_w(HANDLE hContact, const char *szModule, const char *sz
{
if (currDb != NULL) {
DBVARIANT dbv;
- if (!currDb->GetContactSetting(hContact, szModule, szSetting, &dbv)) {
+ if (!currDb->GetContactSetting((MCONTACT)hContact, szModule, szSetting, &dbv)) {
switch(dbv.type) {
case DBVT_BYTE: return dbv.bVal;
case DBVT_WORD: return dbv.wVal;
@@ -65,7 +66,7 @@ MIR_CORE_DLL(DWORD) db_get_dw(HANDLE hContact, const char *szModule, const char
{
if (currDb != NULL) {
DBVARIANT dbv;
- if (!currDb->GetContactSetting(hContact, szModule, szSetting, &dbv)) {
+ if (!currDb->GetContactSetting((MCONTACT)hContact, szModule, szSetting, &dbv)) {
switch(dbv.type) {
case DBVT_BYTE: return dbv.bVal;
case DBVT_WORD: return dbv.wVal;
@@ -84,7 +85,7 @@ MIR_CORE_DLL(INT_PTR) db_get(HANDLE hContact, const char *szModule, const char *
if (currDb == NULL)
return 1;
- return currDb->GetContactSetting(hContact, szModule, szSetting, dbv);
+ return currDb->GetContactSetting((MCONTACT)hContact, szModule, szSetting, dbv);
}
MIR_CORE_DLL(INT_PTR) db_get_s(HANDLE hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv, const int nType)
@@ -93,7 +94,7 @@ MIR_CORE_DLL(INT_PTR) db_get_s(HANDLE hContact, const char *szModule, const char
return 1;
dbv->type = (BYTE)nType;
- return currDb->GetContactSettingStr(hContact, szModule, szSetting, dbv);
+ return currDb->GetContactSettingStr((MCONTACT)hContact, szModule, szSetting, dbv);
}
MIR_CORE_DLL(char*) db_get_sa(HANDLE hContact, const char *szModule, const char *szSetting)
@@ -130,7 +131,7 @@ MIR_CORE_DLL(int) db_get_static(HANDLE hContact, const char *szModule, const cha
dbv.type = DBVT_ASCIIZ;
dbv.pszVal = pDest;
dbv.cchVal = cbDest;
- return currDb->GetContactSettingStatic(hContact, szModule, szSetting, &dbv);
+ return currDb->GetContactSettingStatic((MCONTACT)hContact, szModule, szSetting, &dbv);
}
MIR_CORE_DLL(int) db_get_static_utf(HANDLE hContact, const char *szModule, const char *szSetting, char *pDest, int cbDest)
@@ -142,7 +143,7 @@ MIR_CORE_DLL(int) db_get_static_utf(HANDLE hContact, const char *szModule, const
dbv.type = DBVT_UTF8;
dbv.pszVal = pDest;
dbv.cchVal = cbDest;
- return currDb->GetContactSettingStatic(hContact, szModule, szSetting, &dbv);
+ return currDb->GetContactSettingStatic((MCONTACT)hContact, szModule, szSetting, &dbv);
}
MIR_CORE_DLL(int) db_get_wstatic(HANDLE hContact, const char *szModule, const char *szSetting, WCHAR *pDest, int cbDest)
@@ -154,7 +155,7 @@ MIR_CORE_DLL(int) db_get_wstatic(HANDLE hContact, const char *szModule, const ch
dbv.type = DBVT_WCHAR;
dbv.pwszVal = pDest;
dbv.cchVal = cbDest;
- return currDb->GetContactSettingStatic(hContact, szModule, szSetting, &dbv);
+ return currDb->GetContactSettingStatic((MCONTACT)hContact, szModule, szSetting, &dbv);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -168,7 +169,7 @@ MIR_CORE_DLL(INT_PTR) db_set(HANDLE hContact, const char *szModule, const char *
cws.szModule = szModule;
cws.szSetting = szSetting;
cws.value = *dbv;
- return currDb->WriteContactSetting(hContact, &cws);
+ return currDb->WriteContactSetting((MCONTACT)hContact, &cws);
}
MIR_CORE_DLL(INT_PTR) db_set_b(HANDLE hContact, const char *szModule, const char *szSetting, BYTE val)
@@ -180,7 +181,7 @@ MIR_CORE_DLL(INT_PTR) db_set_b(HANDLE hContact, const char *szModule, const char
cws.szSetting = szSetting;
cws.value.type = DBVT_BYTE;
cws.value.bVal = val;
- return currDb->WriteContactSetting(hContact, &cws);
+ return currDb->WriteContactSetting((MCONTACT)hContact, &cws);
}
MIR_CORE_DLL(INT_PTR) db_set_w(HANDLE hContact, const char *szModule, const char *szSetting, WORD val)
@@ -192,7 +193,7 @@ MIR_CORE_DLL(INT_PTR) db_set_w(HANDLE hContact, const char *szModule, const char
cws.szSetting = szSetting;
cws.value.type = DBVT_WORD;
cws.value.wVal = val;
- return currDb->WriteContactSetting(hContact, &cws);
+ return currDb->WriteContactSetting((MCONTACT)hContact, &cws);
}
MIR_CORE_DLL(INT_PTR) db_set_dw(HANDLE hContact, const char *szModule, const char *szSetting, DWORD val)
@@ -204,7 +205,7 @@ MIR_CORE_DLL(INT_PTR) db_set_dw(HANDLE hContact, const char *szModule, const cha
cws.szSetting = szSetting;
cws.value.type = DBVT_DWORD;
cws.value.dVal = val;
- return currDb->WriteContactSetting(hContact, &cws);
+ return currDb->WriteContactSetting((MCONTACT)hContact, &cws);
}
MIR_CORE_DLL(INT_PTR) db_set_s(HANDLE hContact, const char *szModule, const char *szSetting, const char *val)
@@ -216,7 +217,7 @@ MIR_CORE_DLL(INT_PTR) db_set_s(HANDLE hContact, const char *szModule, const char
cws.szSetting = szSetting;
cws.value.type = DBVT_ASCIIZ;
cws.value.pszVal = (char*)(val == NULL ? "" : val);
- return currDb->WriteContactSetting(hContact, &cws);
+ return currDb->WriteContactSetting((MCONTACT)hContact, &cws);
}
MIR_CORE_DLL(INT_PTR) db_set_ws(HANDLE hContact, const char *szModule, const char *szSetting, const WCHAR *val)
@@ -228,7 +229,7 @@ MIR_CORE_DLL(INT_PTR) db_set_ws(HANDLE hContact, const char *szModule, const cha
cws.szSetting = szSetting;
cws.value.type = DBVT_WCHAR;
cws.value.pwszVal = (WCHAR*)(val == NULL ? L"" : val);
- return currDb->WriteContactSetting(hContact, &cws);
+ return currDb->WriteContactSetting((MCONTACT)hContact, &cws);
}
MIR_CORE_DLL(INT_PTR) db_set_utf(HANDLE hContact, const char *szModule, const char *szSetting, const char *val)
@@ -240,7 +241,7 @@ MIR_CORE_DLL(INT_PTR) db_set_utf(HANDLE hContact, const char *szModule, const ch
cws.szSetting = szSetting;
cws.value.type = DBVT_UTF8;
cws.value.pszVal = (char*)(val == NULL ? "" : val);
- return currDb->WriteContactSetting(hContact, &cws);
+ return currDb->WriteContactSetting((MCONTACT)hContact, &cws);
}
MIR_CORE_DLL(INT_PTR) db_set_blob(HANDLE hContact, const char *szModule, const char *szSetting, void *val, unsigned len)
@@ -253,7 +254,7 @@ MIR_CORE_DLL(INT_PTR) db_set_blob(HANDLE hContact, const char *szModule, const c
cws.value.type = DBVT_BLOB;
cws.value.cpbVal = (WORD)len;
cws.value.pbVal = (unsigned char*)val;
- return currDb->WriteContactSetting(hContact, &cws);
+ return currDb->WriteContactSetting((MCONTACT)hContact, &cws);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -261,27 +262,27 @@ MIR_CORE_DLL(INT_PTR) db_set_blob(HANDLE hContact, const char *szModule, const c
MIR_CORE_DLL(HANDLE) db_event_add(HANDLE hContact, DBEVENTINFO *dbei)
{
- return (currDb == NULL) ? 0 : currDb->AddEvent(hContact, dbei);
+ return (currDb == NULL) ? 0 : currDb->AddEvent((MCONTACT)hContact, dbei);
}
MIR_CORE_DLL(int) db_event_count(HANDLE hContact)
{
- return (currDb == NULL) ? 0 : currDb->GetEventCount(hContact);
+ return (currDb == NULL) ? 0 : currDb->GetEventCount((MCONTACT)hContact);
}
MIR_CORE_DLL(int) db_event_delete(HANDLE hContact, HANDLE hDbEvent)
{
- return (currDb == NULL) ? 0 : currDb->DeleteEvent(hContact, hDbEvent);
+ return (currDb == NULL) ? 0 : currDb->DeleteEvent((MCONTACT)hContact, hDbEvent);
}
MIR_CORE_DLL(HANDLE) db_event_first(HANDLE hContact)
{
- return (currDb == NULL) ? 0 : currDb->FindFirstEvent(hContact);
+ return (currDb == NULL) ? 0 : currDb->FindFirstEvent((MCONTACT)hContact);
}
MIR_CORE_DLL(HANDLE) db_event_firstUnread(HANDLE hContact)
{
- return (currDb == NULL) ? 0 : currDb->FindFirstUnreadEvent(hContact);
+ return (currDb == NULL) ? 0 : currDb->FindFirstUnreadEvent((MCONTACT)hContact);
}
MIR_CORE_DLL(int) db_event_get(HANDLE hDbEvent, DBEVENTINFO *dbei)
@@ -299,14 +300,14 @@ MIR_CORE_DLL(HANDLE) db_event_getContact(HANDLE hDbEvent)
return (currDb == NULL) ? 0 : currDb->GetEventContact(hDbEvent);
}
-MIR_CORE_DLL(HANDLE) db_event_last(HANDLE hDbEvent)
+MIR_CORE_DLL(HANDLE) db_event_last(HANDLE hContact)
{
- return (currDb == NULL) ? 0 : currDb->FindLastEvent(hDbEvent);
+ return (currDb == NULL) ? 0 : currDb->FindLastEvent((MCONTACT)hContact);
}
MIR_CORE_DLL(int) db_event_markRead(HANDLE hContact, HANDLE hDbEvent)
{
- return (currDb == NULL) ? 0 : currDb->MarkEventRead(hContact, hDbEvent);
+ return (currDb == NULL) ? 0 : currDb->MarkEventRead((MCONTACT)hContact, hDbEvent);
}
MIR_CORE_DLL(HANDLE) db_event_next(HANDLE hDbEvent)
@@ -332,17 +333,17 @@ MIR_CORE_DLL(INT_PTR) db_unset(HANDLE hContact, const char *szModule, const char
if (currDb == NULL)
return 1;
- return currDb->DeleteContactSetting(hContact, szModule, szSetting);
+ return currDb->DeleteContactSetting((MCONTACT)hContact, szModule, szSetting);
}
MIR_CORE_DLL(HANDLE) db_find_first(const char *szProto)
{
- return (currDb == NULL) ? NULL : currDb->FindFirstContact(szProto);
+ return (currDb == NULL) ? NULL : (HANDLE)currDb->FindFirstContact(szProto);
}
MIR_CORE_DLL(HANDLE) db_find_next(HANDLE hContact, const char *szProto)
{
- return (currDb == NULL) ? NULL : currDb->FindNextContact(hContact, szProto);
+ return (currDb == NULL) ? NULL : (HANDLE)currDb->FindNextContact((MCONTACT)hContact, szProto);
}
extern "C" MIR_CORE_DLL(void) db_setCurrent(MIDatabase* _db)
diff --git a/src/modules/database/database.h b/src/modules/database/database.h
index 33121c8fcf..286c651c02 100644
--- a/src/modules/database/database.h
+++ b/src/modules/database/database.h
@@ -39,12 +39,14 @@ public:
~MDatabaseCache();
protected:
- STDMETHODIMP_(DBCachedContact*) AddContactToCache(HANDLE hContact);
- STDMETHODIMP_(DBCachedContact*) GetCachedContact(HANDLE hContact);
- STDMETHODIMP_(void) FreeCachedContact(HANDLE hContact);
+ STDMETHODIMP_(DBCachedContact*) AddContactToCache(MCONTACT contactID);
+ STDMETHODIMP_(DBCachedContact*) GetCachedContact(MCONTACT contactID);
+ STDMETHODIMP_(DBCachedContact*) GetFirstContact(void);
+ STDMETHODIMP_(DBCachedContact*) GetNextContact(MCONTACT contactID);
+ STDMETHODIMP_(void) FreeCachedContact(MCONTACT contactID);
STDMETHODIMP_(char*) InsertCachedSetting(const char *szName, int);
STDMETHODIMP_(char*) GetCachedSetting(const char *szModuleName, const char *szSettingName, int, int);
STDMETHODIMP_(void) SetCachedVariant(DBVARIANT *s, DBVARIANT *d);
- STDMETHODIMP_(DBVARIANT*) GetCachedValuePtr(HANDLE hContact, char *szSetting, int bAllocate);
+ STDMETHODIMP_(DBVARIANT*) GetCachedValuePtr(MCONTACT contactID, char *szSetting, int bAllocate);
};
diff --git a/src/modules/database/dbintf.cpp b/src/modules/database/dbintf.cpp
index a03ac5b97c..a4a4e7a1a7 100644
--- a/src/modules/database/dbintf.cpp
+++ b/src/modules/database/dbintf.cpp
@@ -52,7 +52,7 @@ static INT_PTR srvDeleteContact(WPARAM wParam, LPARAM)
DeleteFile(dbv.ptszVal);
db_free(&dbv);
}
- return (currDb) ? currDb->DeleteContact((HANDLE)wParam) : 0;
+ return (currDb) ? currDb->DeleteContact(wParam) : 0;
}
static INT_PTR srvAddContact(WPARAM wParam, LPARAM)
@@ -62,7 +62,7 @@ static INT_PTR srvAddContact(WPARAM wParam, LPARAM)
static INT_PTR srvIsDbContact(WPARAM wParam, LPARAM)
{
- return (currDb) ? currDb->IsDbContact((HANDLE)wParam) : 0;
+ return (currDb) ? currDb->IsDbContact(wParam) : 0;
}
///////////////////////////////////////////////////////////////////////////////
@@ -78,7 +78,7 @@ static INT_PTR srvEnumModuleNames(WPARAM wParam,LPARAM lParam)
static INT_PTR srvEnumContactSettings(WPARAM wParam,LPARAM lParam)
{
- return (currDb) ? (INT_PTR)currDb->EnumContactSettings((HANDLE)wParam, (DBCONTACTENUMSETTINGS*)lParam) : 0;
+ return (currDb) ? (INT_PTR)currDb->EnumContactSettings(wParam, (DBCONTACTENUMSETTINGS*)lParam) : 0;
}
static INT_PTR srvEnumResidentSettings(WPARAM wParam,LPARAM lParam)
diff --git a/src/modules/database/mdatabasecache.cpp b/src/modules/database/mdatabasecache.cpp
index f6c13e0cda..1dcd29861e 100644
--- a/src/modules/database/mdatabasecache.cpp
+++ b/src/modules/database/mdatabasecache.cpp
@@ -36,7 +36,7 @@ static int compareGlobals(const DBCachedGlobalValue* p1, const DBCachedGlobalVal
MDatabaseCache::MDatabaseCache() :
m_lSettings(100, stringCompare),
- m_lContacts(50, HandleKeySortT),
+ m_lContacts(50, NumericKeySortT),
m_lGlobalSettings(50, compareGlobals)
{
m_hCacheHeap = HeapCreate(0, 0, 0);
@@ -51,34 +51,48 @@ MDatabaseCache::~MDatabaseCache()
/////////////////////////////////////////////////////////////////////////////////////////
-DBCachedContact* MDatabaseCache::AddContactToCache(HANDLE hContact)
+DBCachedContact* MDatabaseCache::AddContactToCache(MCONTACT contactID)
{
mir_cslock lck(m_cs);
- int index = m_lContacts.getIndex((DBCachedContact*)&hContact);
+ int index = m_lContacts.getIndex((DBCachedContact*)&contactID);
if (index == -1) {
DBCachedContact* VL = (DBCachedContact*)HeapAlloc(m_hCacheHeap, HEAP_ZERO_MEMORY, sizeof(DBCachedContact));
- VL->hContact = hContact;
+ VL->contactID = contactID;
m_lContacts.insert(VL);
return VL;
}
- return m_lContacts[ index ];
+ return m_lContacts[index];
}
-DBCachedContact* MDatabaseCache::GetCachedContact(HANDLE hContact)
+DBCachedContact* MDatabaseCache::GetCachedContact(MCONTACT contactID)
{
mir_cslock lck(m_cs);
- int index = m_lContacts.getIndex((DBCachedContact*)&hContact);
+ int index = m_lContacts.getIndex((DBCachedContact*)&contactID);
return (index == -1) ? NULL : m_lContacts[index];
}
-void MDatabaseCache::FreeCachedContact(HANDLE hContact)
+DBCachedContact* MDatabaseCache::GetFirstContact()
{
mir_cslock lck(m_cs);
+ return m_lContacts[0];
+}
+
+DBCachedContact* MDatabaseCache::GetNextContact(MCONTACT contactID)
+{
+ mir_cslock lck(m_cs);
+
+ int index = m_lContacts.getIndex((DBCachedContact*)&contactID);
+ return (index == -1) ? NULL : m_lContacts[index+1];
+}
- int index = m_lContacts.getIndex((DBCachedContact*)&hContact);
+void MDatabaseCache::FreeCachedContact(MCONTACT contactID)
+{
+ mir_cslock lck(m_cs);
+
+ int index = m_lContacts.getIndex((DBCachedContact*)&contactID);
if (index == -1)
return;
@@ -87,18 +101,12 @@ void MDatabaseCache::FreeCachedContact(HANDLE hContact)
while (V != NULL) {
DBCachedContactValue* V1 = V->next;
FreeCachedVariant(&V->value);
- HeapFree( m_hCacheHeap, 0, V );
+ HeapFree(m_hCacheHeap, 0, V);
V = V1;
}
- HeapFree( m_hCacheHeap, 0, VL );
+ HeapFree(m_hCacheHeap, 0, VL);
m_lContacts.remove(index);
-
- for (int i=0; i < m_lContacts.getCount(); i++) {
- DBCachedContact *cc = m_lContacts[i];
- if (cc->hNext == hContact)
- cc->hNext = NULL;
- }
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -112,14 +120,14 @@ char* MDatabaseCache::InsertCachedSetting(const char* szName, int cbLen)
return newValue;
}
-char* MDatabaseCache::GetCachedSetting(const char *szModuleName,const char *szSettingName, int moduleNameLen, int settingNameLen)
+char* MDatabaseCache::GetCachedSetting(const char *szModuleName, const char *szSettingName, int moduleNameLen, int settingNameLen)
{
char szFullName[512];
const char *szKey;
if (szModuleName != NULL) {
strcpy(szFullName, szModuleName);
szFullName[moduleNameLen] = '/';
- strcpy(szFullName+moduleNameLen+1,szSettingName);
+ strcpy(szFullName + moduleNameLen + 1, szSettingName);
szKey = szFullName;
}
else szKey = szSettingName;
@@ -131,56 +139,56 @@ char* MDatabaseCache::GetCachedSetting(const char *szModuleName,const char *szSe
if (index != -1)
m_lastSetting = m_lSettings[index];
else
- m_lastSetting = InsertCachedSetting(szKey, settingNameLen+moduleNameLen+3);
+ m_lastSetting = InsertCachedSetting(szKey, settingNameLen + moduleNameLen + 3);
return m_lastSetting;
}
-void MDatabaseCache::SetCachedVariant(DBVARIANT* s /* new */, DBVARIANT* d /* cached */ )
+void MDatabaseCache::SetCachedVariant(DBVARIANT* s /* new */, DBVARIANT* d /* cached */)
{
- char* szSave = ( d->type == DBVT_UTF8 || d->type == DBVT_ASCIIZ ) ? d->pszVal : NULL;
+ char* szSave = (d->type == DBVT_UTF8 || d->type == DBVT_ASCIIZ) ? d->pszVal : NULL;
- memcpy( d, s, sizeof( DBVARIANT ));
- if (( s->type == DBVT_UTF8 || s->type == DBVT_ASCIIZ ) && s->pszVal != NULL ) {
- if ( szSave != NULL )
- d->pszVal = (char*)HeapReAlloc(m_hCacheHeap,0,szSave,strlen(s->pszVal)+1);
+ memcpy(d, s, sizeof(DBVARIANT));
+ if ((s->type == DBVT_UTF8 || s->type == DBVT_ASCIIZ) && s->pszVal != NULL) {
+ if (szSave != NULL)
+ d->pszVal = (char*)HeapReAlloc(m_hCacheHeap, 0, szSave, strlen(s->pszVal) + 1);
else
- d->pszVal = (char*)HeapAlloc(m_hCacheHeap,0,strlen(s->pszVal)+1);
- strcpy(d->pszVal,s->pszVal);
+ d->pszVal = (char*)HeapAlloc(m_hCacheHeap, 0, strlen(s->pszVal) + 1);
+ strcpy(d->pszVal, s->pszVal);
}
- else if ( szSave != NULL ) {
- HeapFree(m_hCacheHeap,0,szSave);
+ else if (szSave != NULL) {
+ HeapFree(m_hCacheHeap, 0, szSave);
d->pszVal = NULL;
}
}
void MDatabaseCache::FreeCachedVariant(DBVARIANT* V)
{
- if (( V->type == DBVT_ASCIIZ || V->type == DBVT_UTF8 ) && V->pszVal != NULL )
- HeapFree(m_hCacheHeap,0,V->pszVal);
+ if ((V->type == DBVT_ASCIIZ || V->type == DBVT_UTF8) && V->pszVal != NULL)
+ HeapFree(m_hCacheHeap, 0, V->pszVal);
}
-STDMETHODIMP_(DBVARIANT*) MDatabaseCache::GetCachedValuePtr(HANDLE hContact, char *szSetting, int bAllocate)
+STDMETHODIMP_(DBVARIANT*) MDatabaseCache::GetCachedValuePtr(MCONTACT contactID, char *szSetting, int bAllocate)
{
// a global setting
- if ( hContact == 0 ) {
+ if (contactID == 0) {
DBCachedGlobalValue Vtemp, *V;
Vtemp.name = szSetting;
int index = m_lGlobalSettings.getIndex(&Vtemp);
if (index != -1) {
V = m_lGlobalSettings[index];
- if ( bAllocate == -1 ) {
- FreeCachedVariant( &V->value );
+ if (bAllocate == -1) {
+ FreeCachedVariant(&V->value);
m_lGlobalSettings.remove(index);
- HeapFree(m_hCacheHeap,0,V);
+ HeapFree(m_hCacheHeap, 0, V);
return NULL;
}
}
else {
- if ( bAllocate != 1 )
+ if (bAllocate != 1)
return NULL;
- V = (DBCachedGlobalValue*)HeapAlloc(m_hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedGlobalValue));
+ V = (DBCachedGlobalValue*)HeapAlloc(m_hCacheHeap, HEAP_ZERO_MEMORY, sizeof(DBCachedGlobalValue));
V->name = szSetting;
m_lGlobalSettings.insert(V);
}
@@ -192,14 +200,14 @@ STDMETHODIMP_(DBVARIANT*) MDatabaseCache::GetCachedValuePtr(HANDLE hContact, cha
DBCachedContactValue *V, *V1;
DBCachedContact VLtemp,*VL;
- VLtemp.hContact = hContact;
+ VLtemp.contactID = contactID;
int index = m_lContacts.getIndex(&VLtemp);
if (index == -1) {
if ( bAllocate != 1 )
return NULL;
- VL = AddContactToCache(hContact);
+ VL = AddContactToCache(contactID);
}
else VL = m_lContacts[index];
diff --git a/src/modules/protocols/protochains.cpp b/src/modules/protocols/protochains.cpp
index 3841d1842f..e14837c18f 100644
--- a/src/modules/protocols/protochains.cpp
+++ b/src/modules/protocols/protochains.cpp
@@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern LIST<PROTOCOLDESCRIPTOR> filters;
-static int GetProtocolP(HANDLE hContact, char *szBuf, int cbLen)
+static int GetProtocolP(MCONTACT hContact, char *szBuf, int cbLen)
{
if (currDb == NULL)
return 1;
@@ -69,7 +69,7 @@ INT_PTR CallContactService(HANDLE hContact, const char *szProtoService, WPARAM w
}
char szProto[40];
- if ( GetProtocolP(hContact, szProto, sizeof(szProto)))
+ if ( GetProtocolP((MCONTACT)hContact, szProto, sizeof(szProto)))
return 1;
PROTOACCOUNT *pa = Proto_GetAccount(szProto);
@@ -104,7 +104,7 @@ INT_PTR Proto_CallContactService(WPARAM wParam, LPARAM lParam)
}
char szProto[40];
- if ( GetProtocolP(ccs->hContact, szProto, sizeof(szProto)))
+ if (GetProtocolP((MCONTACT)ccs->hContact, szProto, sizeof(szProto)))
return 1;
PROTOACCOUNT *pa = Proto_GetAccount(szProto);
@@ -144,7 +144,7 @@ static INT_PTR Proto_RecvChain(WPARAM wParam, LPARAM lParam)
//end of chain, call network protocol again
char szProto[40];
- if ( GetProtocolP(ccs->hContact, szProto, sizeof(szProto)))
+ if (GetProtocolP((MCONTACT)ccs->hContact, szProto, sizeof(szProto)))
return 1;
PROTOACCOUNT *pa = Proto_GetAccount(szProto);
@@ -167,7 +167,7 @@ PROTOACCOUNT* __fastcall Proto_GetAccount(HANDLE hContact)
return NULL;
char szProto[40];
- if ( GetProtocolP(hContact, szProto, sizeof(szProto)))
+ if (GetProtocolP((MCONTACT)hContact, szProto, sizeof(szProto)))
return NULL;
return Proto_GetAccount(szProto);
@@ -192,7 +192,7 @@ static INT_PTR Proto_IsProtoOnContact(WPARAM wParam, LPARAM lParam)
return 0;
char szContactProto[40];
- if (!GetProtocolP((HANDLE)wParam, szContactProto, sizeof(szContactProto)))
+ if (!GetProtocolP(wParam, szContactProto, sizeof(szContactProto)))
if (!_stricmp(szProto, szContactProto))
return -1;