summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-05-03 15:57:32 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-05-03 15:57:32 +0000
commite04bbf1c49acb1f6994d460c519d1bd03ca912d7 (patch)
tree0fcfda093e93eb087ee240cbe9b7b1adae118ffa
parentcaeedd1d82e3018be30ec1a65e98ed8e1841c015 (diff)
database to look up the missing settings for the default sub
git-svn-id: http://svn.miranda-ng.org/main/trunk@9114 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/Db3x_mmap/src/dbcontacts.cpp23
-rw-r--r--plugins/Db3x_mmap/src/dbevents.cpp18
-rw-r--r--plugins/Db3x_mmap/src/dbintf.h2
-rw-r--r--plugins/Db3x_mmap/src/dbsettings.cpp11
4 files changed, 33 insertions, 21 deletions
diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp
index ef95d40e00..539f812744 100644
--- a/plugins/Db3x_mmap/src/dbcontacts.cpp
+++ b/plugins/Db3x_mmap/src/dbcontacts.cpp
@@ -78,19 +78,17 @@ STDMETHODIMP_(MCONTACT) CDb3Mmap::FindNextContact(MCONTACT contactID, const char
STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(MCONTACT contactID)
{
- if (contactID == NULL)
+ if (contactID == 0) // global contact cannot be removed
return 1;
mir_cslockfull lck(m_csDbAccess);
- DBCachedContact *cc = m_cache->GetCachedContact(contactID);
- if (cc == NULL)
- return 1;
+ DWORD ofsContact = GetContactOffset(contactID);
- DBContact *dbc = (DBContact*)DBRead(cc->dwDriverData, sizeof(DBContact), NULL);
+ DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
if (dbc->signature != DBCONTACT_SIGNATURE)
return 1;
- if (cc->dwDriverData == m_dbHeader.ofsUser) {
+ if (ofsContact == m_dbHeader.ofsUser) {
log0("FATAL: del of user chain attempted.");
return 1;
}
@@ -124,7 +122,7 @@ STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(MCONTACT contactID)
}
// find previous contact in chain and change ofsNext
- if (m_dbHeader.ofsFirstContact == cc->dwDriverData) {
+ if (m_dbHeader.ofsFirstContact == ofsContact) {
m_dbHeader.ofsFirstContact = dbc->ofsNext;
DBWrite(0, &m_dbHeader, sizeof(m_dbHeader));
}
@@ -132,7 +130,7 @@ STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(MCONTACT contactID)
DWORD ofsNext = dbc->ofsNext;
ofsThis = m_dbHeader.ofsFirstContact;
DBContact *dbcPrev = (DBContact*)DBRead(ofsThis, sizeof(DBContact), NULL);
- while (dbcPrev->ofsNext != cc->dwDriverData) {
+ while (dbcPrev->ofsNext != ofsContact) {
if (dbcPrev->ofsNext == 0) DatabaseCorruption(NULL);
ofsThis = dbcPrev->ofsNext;
dbcPrev = (DBContact*)DBRead(ofsThis, sizeof(DBContact), NULL);
@@ -142,7 +140,7 @@ STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(MCONTACT contactID)
}
// delete contact
- DeleteSpace(cc->dwDriverData, sizeof(DBContact));
+ DeleteSpace(ofsContact, sizeof(DBContact));
// decrement contact count
m_dbHeader.contactCount--;
@@ -493,11 +491,14 @@ void CDb3Mmap::FillContacts()
}
}
-DWORD CDb3Mmap::GetContactOffset(MCONTACT contactID)
+DWORD CDb3Mmap::GetContactOffset(MCONTACT contactID, DBCachedContact **pcc)
{
- if (contactID == 0)
+ if (contactID == 0) {
+ if (pcc) *pcc = NULL;
return m_dbHeader.ofsUser;
+ }
DBCachedContact *cc = m_cache->GetCachedContact(contactID);
+ if (pcc) *pcc = cc;
return (cc == NULL) ? 0 : cc->dwDriverData;
}
diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp
index d5a608ea32..b5b453ca98 100644
--- a/plugins/Db3x_mmap/src/dbevents.cpp
+++ b/plugins/Db3x_mmap/src/dbevents.cpp
@@ -237,8 +237,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(MCONTACT contactID, HANDLE hDbEvent)
// also update a sub
if (dbc.dwContactID != contactID) {
- DBCachedContact *cc = m_cache->GetCachedContact(dbc.dwContactID);
- DBContact *pSub = (DBContact*)DBRead(cc->dwDriverData, sizeof(DBContact), NULL);
+ DBContact *pSub = (DBContact*)DBRead(GetContactOffset(dbc.dwContactID), sizeof(DBContact), NULL);
if (pSub->eventCount > 0)
pSub->eventCount--;
}
@@ -351,10 +350,11 @@ STDMETHODIMP_(MCONTACT) CDb3Mmap::GetEventContact(HANDLE hDbEvent)
STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstEvent(MCONTACT contactID)
{
- DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL;
+ DBCachedContact *cc;
+ DWORD ofsContact = GetContactOffset(contactID, &cc);
mir_cslock lck(m_csDbAccess);
- DBContact *dbc = (DBContact*)DBRead((cc) ? cc->dwDriverData : m_dbHeader.ofsUser, sizeof(DBContact), NULL);
+ DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
if (dbc->signature != DBCONTACT_SIGNATURE)
return NULL;
if (!cc || !cc->IsSub())
@@ -379,10 +379,11 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstEvent(MCONTACT contactID)
STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstUnreadEvent(MCONTACT contactID)
{
- DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL;
+ DBCachedContact *cc;
+ DWORD ofsContact = GetContactOffset(contactID, &cc);
mir_cslock lck(m_csDbAccess);
- DBContact *dbc = (DBContact*)DBRead((cc) ? cc->dwDriverData : m_dbHeader.ofsUser, sizeof(DBContact), NULL);
+ DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
if (dbc->signature != DBCONTACT_SIGNATURE)
return NULL;
if (!cc || !cc->IsSub())
@@ -407,10 +408,11 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstUnreadEvent(MCONTACT contactID)
STDMETHODIMP_(HANDLE) CDb3Mmap::FindLastEvent(MCONTACT contactID)
{
- DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL;
+ DBCachedContact *cc;
+ DWORD ofsContact = GetContactOffset(contactID, &cc);
mir_cslock lck(m_csDbAccess);
- DBContact *dbc = (DBContact*)DBRead((cc) ? cc->dwDriverData : m_dbHeader.ofsUser, sizeof(DBContact), NULL);
+ DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
if (dbc->signature != DBCONTACT_SIGNATURE)
return NULL;
if (!cc || !cc->IsSub())
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h
index 88483226f1..2953a06b57 100644
--- a/plugins/Db3x_mmap/src/dbintf.h
+++ b/plugins/Db3x_mmap/src/dbintf.h
@@ -306,7 +306,7 @@ protected:
DWORD CreateNewSpace(int bytes);
void DeleteSpace(DWORD ofs, int bytes);
DWORD ReallocSpace(DWORD ofs, int oldSize, int newSize);
- DWORD GetContactOffset(MCONTACT contactID);
+ DWORD GetContactOffset(MCONTACT contactID, DBCachedContact **cc = NULL);
////////////////////////////////////////////////////////////////////////////
// settings
diff --git a/plugins/Db3x_mmap/src/dbsettings.cpp b/plugins/Db3x_mmap/src/dbsettings.cpp
index 4c3f8e4b93..c77889bdf3 100644
--- a/plugins/Db3x_mmap/src/dbsettings.cpp
+++ b/plugins/Db3x_mmap/src/dbsettings.cpp
@@ -71,6 +71,7 @@ int CDb3Mmap::GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCST
char *szCachedSettingName = m_cache->GetCachedSetting(szModule, szSetting, moduleNameLen, settingNameLen);
log3("get [%08p] %s (%p)", hContact, szCachedSettingName, szCachedSettingName);
+LBL_Seek:
DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, 0);
if (pCachedValue != NULL) {
if (pCachedValue->type == DBVT_ASCIIZ || pCachedValue->type == DBVT_UTF8) {
@@ -105,8 +106,10 @@ int CDb3Mmap::GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCST
if (szCachedSettingName[-1] != 0)
return 1;
+ DBCachedContact *cc;
+ DWORD ofsContact = GetContactOffset(contactID, &cc);
+
DWORD ofsModuleName = GetModuleNameOfs(szModule);
- DWORD ofsContact = GetContactOffset(contactID);
DBContact dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
if (dbc.signature != DBCONTACT_SIGNATURE)
@@ -219,6 +222,12 @@ int CDb3Mmap::GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCST
}
}
+ // try to get the missing mc setting from the active sub
+ if (cc && cc->IsMeta()) {
+ contactID = db_mc_getDefault(contactID);
+ goto LBL_Seek;
+ }
+
logg();
return 1;
}