summaryrefslogtreecommitdiff
path: root/plugins/Db3x_mmap/src
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 /plugins/Db3x_mmap/src
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
Diffstat (limited to 'plugins/Db3x_mmap/src')
-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
5 files changed, 172 insertions, 173 deletions
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;