summaryrefslogtreecommitdiff
path: root/plugins/Db3x_mmap
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Db3x_mmap')
-rw-r--r--plugins/Db3x_mmap/src/dbcrypt.cpp225
-rw-r--r--plugins/Db3x_mmap/src/dbevents.cpp161
-rw-r--r--plugins/Db3x_mmap/src/dbintf.cpp1
-rw-r--r--plugins/Db3x_mmap/src/dbintf.h15
-rw-r--r--plugins/Db3x_mmap/src/dbsettings.cpp205
-rw-r--r--plugins/Db3x_mmap/src/dbtool/aggressive.cpp14
-rw-r--r--plugins/Db3x_mmap/src/dbtool/contactchain.cpp38
-rw-r--r--plugins/Db3x_mmap/src/dbtool/disk.cpp25
-rw-r--r--plugins/Db3x_mmap/src/dbtool/eventchain.cpp153
-rw-r--r--plugins/Db3x_mmap/src/dbtool/finaltasks.cpp5
-rw-r--r--plugins/Db3x_mmap/src/dbtool/initialchecks.cpp22
-rw-r--r--plugins/Db3x_mmap/src/dbtool/modulechain.cpp139
-rw-r--r--plugins/Db3x_mmap/src/dbtool/settingschain.cpp40
-rw-r--r--plugins/Db3x_mmap/src/dbtool/user.cpp25
-rw-r--r--plugins/Db3x_mmap/src/ui.cpp7
15 files changed, 659 insertions, 416 deletions
diff --git a/plugins/Db3x_mmap/src/dbcrypt.cpp b/plugins/Db3x_mmap/src/dbcrypt.cpp
index 00cab246e8..18d9fd5043 100644
--- a/plugins/Db3x_mmap/src/dbcrypt.cpp
+++ b/plugins/Db3x_mmap/src/dbcrypt.cpp
@@ -47,8 +47,20 @@ struct VarDescr
szVar(mir_strdup(var)),
szValue(mir_strdup(value))
{}
-
+
+ VarDescr(LPCSTR var, LPSTR value) :
+ szVar(mir_strdup(var)),
+ szValue(value)
+ {}
+
+ VarDescr(LPCSTR var, PBYTE value, int len) :
+ szVar(mir_strdup(var)),
+ szValue((char*)memcpy(mir_alloc(len), value, len)),
+ iLen(len)
+ {}
+
ptrA szVar, szValue;
+ int iLen;
};
struct SettingUgraderParam
@@ -68,7 +80,7 @@ int sttSettingUgrader(const char *szSetting, LPARAM lParam)
if (!param->db->GetContactSettingStr(param->hContact, &dbcgs)) {
if (dbv.type == DBVT_UTF8) {
DecodeString(dbv.pszVal);
- param->pList->insert(new VarDescr(szSetting, dbv.pszVal));
+ param->pList->insert(new VarDescr(szSetting, (LPCSTR)dbv.pszVal));
}
param->db->FreeVariant(&dbv);
}
@@ -162,7 +174,7 @@ LBL_SetNewKey:
goto LBL_SetNewKey;
if (!m_crypto->setKey(dbv.pbVal, iKeyLength)) {
- if (!m_bEncrypted)
+ if (memcmp(m_dbHeader.signature, &dbSignatureE, sizeof(m_dbHeader.signature)))
goto LBL_SetNewKey;
if (!EnterPassword(dbv.pbVal, iKeyLength)) { // password protected?
@@ -178,9 +190,7 @@ LBL_SetNewKey:
FreeVariant(&dbv);
}
- if (memcmp(&m_dbHeader.signature, &dbSignatureU, sizeof(m_dbHeader.signature)) &&
- memcmp(&m_dbHeader.signature, &dbSignatureE, sizeof(m_dbHeader.signature)))
- {
+ if (!memcmp(&m_dbHeader.signature, &dbSignatureIM, sizeof(m_dbHeader.signature))) {
EnumModuleNames(sttModuleEnum, this);
// upgrade signature
@@ -192,6 +202,11 @@ LBL_SetNewKey:
DBWrite(sizeof(dbSignatureU), &m_dbHeader.version, sizeof(m_dbHeader.version));
}
+ dbv.type = DBVT_BYTE;
+ dbcgs.szSetting = "DatabaseEncryption";
+ if (!GetContactSetting(NULL, &dbcgs))
+ m_bEncrypted = dbv.bVal != 0;
+
InitDialogs();
return 0;
}
@@ -223,3 +238,201 @@ void CDb3Mmap::SetPassword(LPCTSTR ptszPassword)
}
UpdateMenuItem();
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void CDb3Mmap::ToggleEncryption()
+{
+ HANDLE hSave1 = hSettingChangeEvent; hSettingChangeEvent = NULL;
+ HANDLE hSave2 = hEventAddedEvent; hEventAddedEvent = NULL;
+ HANDLE hSave3 = hEventDeletedEvent; hEventDeletedEvent = NULL;
+ HANDLE hSave4 = hEventFilterAddedEvent; hEventFilterAddedEvent = NULL;
+
+ mir_cslock lck(m_csDbAccess);
+ ToggleSettingsEncryption(NULL);
+ ToggleEventsEncryption(NULL);
+
+ for (HANDLE hContact = FindFirstContact(); hContact; hContact = FindNextContact(hContact)) {
+ ToggleSettingsEncryption(hContact);
+ ToggleEventsEncryption(hContact);
+ }
+
+ m_bEncrypted = !m_bEncrypted;
+
+ DBCONTACTWRITESETTING dbcws = { "CryptoEngine", "DatabaseEncryption" };
+ dbcws.value.type = DBVT_BYTE;
+ dbcws.value.bVal = m_bEncrypted;
+ WriteContactSetting(NULL, &dbcws);
+
+ hSettingChangeEvent = hSave1;
+ hEventAddedEvent = hSave2;
+ hEventDeletedEvent = hSave3;
+ hEventFilterAddedEvent = hSave4;
+}
+
+void CDb3Mmap::ToggleSettingsEncryption(HANDLE hContact)
+{
+ if (!hContact)
+ hContact = (HANDLE)m_dbHeader.ofsUser;
+
+ DBContact *contact = (DBContact*)DBRead((DWORD)hContact, sizeof(DBContact), NULL);
+ if (contact->ofsFirstSettings == 0)
+ return;
+
+ // fast cycle through all settings
+ DBContactSettings *setting = (DBContactSettings*)DBRead(contact->ofsFirstSettings, sizeof(DBContactSettings), NULL);
+ DWORD offset = contact->ofsFirstSettings;
+ char *szModule = GetModuleNameByOfs(setting->ofsModuleName);
+ if (szModule == NULL)
+ return;
+
+ while (true) {
+ OBJLIST<VarDescr> arSettings(10);
+ char szSetting[256];
+ int bytesRemaining, len;
+ DWORD ofsBlobPtr = offset + offsetof(DBContactSettings, blob), ofsNext = setting->ofsNext;
+ PBYTE pBlob = (PBYTE)DBRead(ofsBlobPtr, 1, &bytesRemaining);
+ while (pBlob[0]) {
+ NeedBytes(1);
+ len = pBlob[0];
+ memcpy(szSetting, pBlob + 1, len); szSetting[len] = 0;
+ NeedBytes(1 + pBlob[0]);
+ MoveAlong(1 + pBlob[0]);
+ NeedBytes(5);
+
+ switch (pBlob[0]) {
+ case DBVT_ASCIIZ:
+ len = *(PWORD)(pBlob+1);
+ // we need to convert a string into utf8 and encrypt it
+ if (!m_bEncrypted) {
+ BYTE bSave = pBlob[len + 3]; pBlob[len + 3] = 0;
+ arSettings.insert(new VarDescr(szSetting, mir_utf8encode((LPCSTR)pBlob+3)));
+ pBlob[len + 3] = bSave;
+ }
+ NeedBytes(3 + len);
+ break;
+
+ case DBVT_UTF8:
+ len = *(PWORD)(pBlob + 1);
+ // we need to encrypt these strings
+ if (!m_bEncrypted) {
+ BYTE bSave = pBlob[len + 3]; pBlob[len + 3] = 0;
+ arSettings.insert(new VarDescr(szSetting, (LPCSTR)pBlob + 3));
+ pBlob[len + 3] = bSave;
+ }
+ NeedBytes(3 + len);
+ break;
+
+ case DBVT_ENCRYPTED:
+ len = *(PWORD)(pBlob + 1);
+ // we need to decrypt these strings
+ if (m_bEncrypted && !::isEncrypted(szModule, szSetting))
+ arSettings.insert(new VarDescr(szSetting, pBlob + 3, len));
+ NeedBytes(3 + len);
+ break;
+
+ case DBVT_BLOB:
+ NeedBytes(3 + *(PWORD)(pBlob + 1));
+ break;
+ }
+ NeedBytes(3);
+ MoveAlong(1 + GetSettingValueLength(pBlob));
+ NeedBytes(1);
+ }
+
+ for (int i = 0; i < arSettings.getCount(); i++) {
+ VarDescr &p = arSettings[i];
+ if (!m_bEncrypted) {
+ size_t len;
+ BYTE *pResult = m_crypto->encodeString(p.szValue, &len);
+ if (pResult != NULL) {
+ DBCONTACTWRITESETTING dbcws = { szModule, p.szVar };
+ dbcws.value.type = DBVT_ENCRYPTED;
+ dbcws.value.pbVal = pResult;
+ dbcws.value.cpbVal = (WORD)len;
+ WriteContactSetting(hContact, &dbcws);
+
+ mir_free(pResult);
+ }
+ }
+ else {
+ size_t realLen;
+ ptrA decoded(m_crypto->decodeString((PBYTE)(char*)p.szValue, p.iLen, &realLen));
+ if (decoded != NULL) {
+ DBCONTACTWRITESETTING dbcws = { szModule, p.szVar };
+ dbcws.value.type = DBVT_UTF8;
+ dbcws.value.pszVal = decoded;
+ dbcws.value.cchVal = (WORD)len;
+ WriteContactSetting(hContact, &dbcws);
+ }
+ }
+ }
+
+ if (!ofsNext)
+ break;
+
+ setting = (DBContactSettings *)DBRead(offset = ofsNext, sizeof(DBContactSettings), NULL);
+ if ((szModule = GetModuleNameByOfs(setting->ofsModuleName)) == NULL)
+ break;
+ }
+}
+
+void CDb3Mmap::ToggleEventsEncryption(HANDLE hContact)
+{
+ DWORD ofsContact = (hContact) ? (DWORD)hContact : m_dbHeader.ofsUser;
+
+ DBContact contact = *(DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
+ if (contact.ofsFirstEvent == 0 || contact.signature != DBCONTACT_SIGNATURE)
+ return;
+
+ // fast cycle through all events
+ for (DWORD offset = contact.ofsFirstEvent; offset != 0;) {
+ DBEvent evt = *(DBEvent*)DBRead(offset, sizeof(DBEvent), NULL);
+ if (evt.signature != DBEVENT_SIGNATURE)
+ return;
+
+ size_t len;
+ DWORD ofsDest;
+ mir_ptr<BYTE> pBlob;
+ if (!m_bEncrypted) { // we need more space
+ if ((pBlob = m_crypto->encodeBuffer(DBRead(offset + offsetof(DBEvent, blob), evt.cbBlob, 0), evt.cbBlob, &len)) == NULL)
+ return;
+
+ ofsDest = ReallocSpace(offset, offsetof(DBEvent, blob) + evt.cbBlob, offsetof(DBEvent, blob) + (DWORD)len);
+
+ if (evt.ofsNext) {
+ DBEvent *e = (DBEvent*)DBRead(evt.ofsNext, sizeof(DBEvent), NULL);
+ e->ofsPrev = ofsDest;
+ DBWrite(evt.ofsNext, e, sizeof(DBEvent));
+ }
+ if (evt.ofsPrev) {
+ DBEvent *e = (DBEvent*)DBRead(evt.ofsPrev, sizeof(DBEvent), NULL);
+ e->ofsNext = ofsDest;
+ DBWrite(evt.ofsPrev, e, sizeof(DBEvent));
+ }
+ if (contact.ofsFirstEvent == offset)
+ contact.ofsFirstEvent = ofsDest;
+ if (contact.ofsLastEvent == offset)
+ contact.ofsLastEvent = ofsDest;
+ if (contact.ofsFirstUnreadEvent == offset)
+ contact.ofsFirstUnreadEvent = ofsDest;
+
+ evt.flags |= DBEF_ENCRYPTED;
+ }
+ else {
+ if ((pBlob = (BYTE*)m_crypto->decodeBuffer(evt.blob, evt.cbBlob, &len)) == NULL)
+ return;
+
+ ofsDest = offset; // reuse the old space
+ evt.flags &= ~DBEF_ENCRYPTED;
+ }
+ evt.cbBlob = (DWORD)len;
+
+ DBWrite(ofsDest, &evt, offsetof(DBEvent, blob));
+ DBWrite(ofsDest + offsetof(DBEvent, blob), pBlob, (DWORD)len);
+
+ offset = evt.ofsNext;
+ }
+
+ DBWrite(ofsContact, &contact, sizeof(DBContact));
+}
diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp
index a998bc2484..d45c37eaa8 100644
--- a/plugins/Db3x_mmap/src/dbevents.cpp
+++ b/plugins/Db3x_mmap/src/dbevents.cpp
@@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
DWORD GetModuleNameOfs(const char *szName);
char *GetModuleNameByOfs(DWORD ofs);
-static HANDLE hEventDeletedEvent,hEventAddedEvent,hEventFilterAddedEvent;
+static HANDLE hEventDeletedEvent, hEventAddedEvent, hEventFilterAddedEvent;
STDMETHODIMP_(LONG) CDb3Base::GetEventCount(HANDLE hContact)
{
@@ -34,7 +34,7 @@ STDMETHODIMP_(LONG) CDb3Base::GetEventCount(HANDLE hContact)
if (hContact == 0)
hContact = (HANDLE)m_dbHeader.ofsUser;
- DBContact *dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
return (dbc->signature != DBCONTACT_SIGNATURE) ? -1 : dbc->eventCount;
}
@@ -45,25 +45,37 @@ STDMETHODIMP_(HANDLE) CDb3Base::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
if (NotifyEventHooks(hEventFilterAddedEvent, (WPARAM)hContact, (LPARAM)dbei))
return 0;
+ DBEvent dbe;
+ dbe.signature = DBEVENT_SIGNATURE;
+ dbe.timestamp = dbei->timestamp;
+ dbe.flags = dbei->flags;
+ dbe.eventType = dbei->eventType;
+ dbe.cbBlob = dbei->cbBlob;
+ BYTE *pBlob = dbei->pBlob;
+
+ mir_ptr<BYTE> pCryptBlob;
+ if (m_bEncrypted) {
+ size_t len;
+ BYTE *pResult = m_crypto->encodeBuffer(pBlob, dbe.cbBlob, &len);
+ if (pResult != NULL) {
+ pCryptBlob = pBlob = pResult;
+ dbe.cbBlob = (DWORD)len;
+ dbe.flags |= DBEF_ENCRYPTED;
+ }
+ }
+
bool neednotify;
mir_cslockfull lck(m_csDbAccess);
DWORD ofsContact = (hContact == 0) ? m_dbHeader.ofsUser : (DWORD)hContact;
- DBContact dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
+ DBContact dbc = *(DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
if (dbc.signature != DBCONTACT_SIGNATURE)
- return 0;
+ return 0;
- DWORD ofsNew = CreateNewSpace(offsetof(DBEvent,blob) + dbei->cbBlob);
- DWORD ofsModuleName = GetModuleNameOfs(dbei->szModule);
+ DWORD ofsNew = CreateNewSpace(offsetof(DBEvent, blob) + dbe.cbBlob);
- DBEvent dbe;
- dbe.signature = DBEVENT_SIGNATURE;
- dbe.ofsModuleName = ofsModuleName;
- dbe.timestamp = dbei->timestamp;
- dbe.flags = dbei->flags;
- dbe.eventType = dbei->eventType;
- dbe.cbBlob = dbei->cbBlob;
- //find where to put it - sort by timestamp
+ dbe.ofsModuleName = GetModuleNameOfs(dbei->szModule);
+ // find where to put it - sort by timestamp
if (dbc.eventCount == 0) {
dbe.ofsPrev = (DWORD)hContact;
dbe.ofsNext = 0;
@@ -71,17 +83,17 @@ STDMETHODIMP_(HANDLE) CDb3Base::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
dbc.ofsFirstEvent = dbc.ofsLastEvent = ofsNew;
}
else {
- DBEvent *dbeTest = (DBEvent*)DBRead(dbc.ofsFirstEvent,sizeof(DBEvent),NULL);
+ DBEvent *dbeTest = (DBEvent*)DBRead(dbc.ofsFirstEvent, sizeof(DBEvent), NULL);
// Should new event be placed before first event in chain?
- if (dbei->timestamp < dbeTest->timestamp) {
+ if (dbe.timestamp < dbeTest->timestamp) {
dbe.ofsPrev = (DWORD)hContact;
dbe.ofsNext = dbc.ofsFirstEvent;
dbe.flags |= DBEF_FIRST;
dbc.ofsFirstEvent = ofsNew;
- dbeTest = (DBEvent*)DBRead(dbe.ofsNext,sizeof(DBEvent),NULL);
+ dbeTest = (DBEvent*)DBRead(dbe.ofsNext, sizeof(DBEvent), NULL);
dbeTest->flags &= ~DBEF_FIRST;
dbeTest->ofsPrev = ofsNew;
- DBWrite(dbe.ofsNext,dbeTest,sizeof(DBEvent));
+ DBWrite(dbe.ofsNext, dbeTest, sizeof(DBEvent));
}
else {
// Loop through the chain, starting at the end
@@ -112,22 +124,22 @@ STDMETHODIMP_(HANDLE) CDb3Base::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
}
dbc.eventCount++;
- if (!(dbe.flags&(DBEF_READ|DBEF_SENT))) {
- if (dbe.timestamp<dbc.timestampFirstUnread || dbc.timestampFirstUnread == 0) {
+ if (!(dbe.flags & (DBEF_READ | DBEF_SENT))) {
+ if (dbe.timestamp < dbc.timestampFirstUnread || dbc.timestampFirstUnread == 0) {
dbc.timestampFirstUnread = dbe.timestamp;
dbc.ofsFirstUnreadEvent = ofsNew;
}
- neednotify = TRUE;
+ neednotify = true;
}
else neednotify = m_safetyMode;
- DBWrite(ofsContact,&dbc,sizeof(DBContact));
- DBWrite(ofsNew,&dbe,offsetof(DBEvent,blob));
- EncodeDBWrite(ofsNew + offsetof(DBEvent, blob), dbei->pBlob, dbei->cbBlob); // encode
+ DBWrite(ofsContact, &dbc, sizeof(DBContact));
+ DBWrite(ofsNew, &dbe, offsetof(DBEvent, blob));
+ EncodeDBWrite(ofsNew + offsetof(DBEvent, blob), pBlob, dbe.cbBlob);
DBFlush(0);
lck.unlock();
-
- log1("add event @ %08x",ofsNew);
+
+ log1("add event @ %08x", ofsNew);
// Notify only in safe mode or on really new events
if (neednotify)
@@ -148,15 +160,15 @@ STDMETHODIMP_(BOOL) CDb3Base::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
lck.unlock();
log1("delete event @ %08x", hContact);
-
+
//call notifier while outside mutex
- NotifyEventHooks(hEventDeletedEvent,(WPARAM)hContact, (LPARAM)hDbEvent);
+ NotifyEventHooks(hEventDeletedEvent, (WPARAM)hContact, (LPARAM)hDbEvent);
//get back in
lck.lock();
- dbc = *(DBContact*)DBRead(ofsContact,sizeof(DBContact),NULL);
- dbe = *(DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
-
+ dbc = *(DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
+ dbe = *(DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
+
//check if this was the first unread, if so, recalc the first unread
if (dbc.ofsFirstUnreadEvent == (DWORD)hDbEvent) {
DBEvent *dbeNext = &dbe;
@@ -167,8 +179,8 @@ STDMETHODIMP_(BOOL) CDb3Base::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
break;
}
DWORD ofsThis = dbeNext->ofsNext;
- dbeNext = (DBEvent*)DBRead(ofsThis,sizeof(DBEvent),NULL);
- if ( !(dbeNext->flags & (DBEF_READ | DBEF_SENT))) {
+ dbeNext = (DBEvent*)DBRead(ofsThis, sizeof(DBEvent), NULL);
+ if (!(dbeNext->flags & (DBEF_READ | DBEF_SENT))) {
dbc.ofsFirstUnreadEvent = ofsThis;
dbc.timestampFirstUnread = dbeNext->timestamp;
break;
@@ -177,39 +189,39 @@ STDMETHODIMP_(BOOL) CDb3Base::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
}
//get previous and next events in chain and change offsets
- if (dbe.flags&DBEF_FIRST) {
+ if (dbe.flags & DBEF_FIRST) {
if (dbe.ofsNext == 0)
dbc.ofsFirstEvent = dbc.ofsLastEvent = 0;
else {
- DBEvent *dbeNext = (DBEvent*)DBRead(dbe.ofsNext,sizeof(DBEvent),NULL);
+ DBEvent *dbeNext = (DBEvent*)DBRead(dbe.ofsNext, sizeof(DBEvent), NULL);
dbeNext->flags |= DBEF_FIRST;
dbeNext->ofsPrev = dbe.ofsPrev;
- DBWrite(dbe.ofsNext,dbeNext,sizeof(DBEvent));
+ DBWrite(dbe.ofsNext, dbeNext, sizeof(DBEvent));
dbc.ofsFirstEvent = dbe.ofsNext;
}
}
else {
if (dbe.ofsNext == 0) {
- DBEvent *dbePrev = (DBEvent*)DBRead(dbe.ofsPrev,sizeof(DBEvent),NULL);
+ DBEvent *dbePrev = (DBEvent*)DBRead(dbe.ofsPrev, sizeof(DBEvent), NULL);
dbePrev->ofsNext = 0;
- DBWrite(dbe.ofsPrev,dbePrev,sizeof(DBEvent));
+ DBWrite(dbe.ofsPrev, dbePrev, sizeof(DBEvent));
dbc.ofsLastEvent = dbe.ofsPrev;
}
else {
- DBEvent *dbePrev = (DBEvent*)DBRead(dbe.ofsPrev,sizeof(DBEvent),NULL);
+ DBEvent *dbePrev = (DBEvent*)DBRead(dbe.ofsPrev, sizeof(DBEvent), NULL);
dbePrev->ofsNext = dbe.ofsNext;
- DBWrite(dbe.ofsPrev,dbePrev,sizeof(DBEvent));
-
- DBEvent *dbeNext = (DBEvent*)DBRead(dbe.ofsNext,sizeof(DBEvent),NULL);
+ DBWrite(dbe.ofsPrev, dbePrev, sizeof(DBEvent));
+
+ DBEvent *dbeNext = (DBEvent*)DBRead(dbe.ofsNext, sizeof(DBEvent), NULL);
dbeNext->ofsPrev = dbe.ofsPrev;
- DBWrite(dbe.ofsNext,dbeNext,sizeof(DBEvent));
+ DBWrite(dbe.ofsNext, dbeNext, sizeof(DBEvent));
}
}
//delete event
- DeleteSpace((DWORD)hDbEvent, offsetof(DBEvent,blob)+dbe.cbBlob);
+ DeleteSpace((DWORD)hDbEvent, offsetof(DBEvent, blob) + dbe.cbBlob);
//decrement event count
dbc.eventCount--;
- DBWrite(ofsContact,&dbc,sizeof(DBContact));
+ DBWrite(ofsContact, &dbc, sizeof(DBContact));
DBFlush(0);
return 0;
}
@@ -230,9 +242,9 @@ STDMETHODIMP_(BOOL) CDb3Base::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
}
mir_cslock lck(m_csDbAccess);
- DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
if (dbe->signature != DBEVENT_SIGNATURE)
- return 1;
+ return 1;
dbei->szModule = GetModuleNameByOfs(dbe->ofsModuleName);
dbei->timestamp = dbe->timestamp;
@@ -241,37 +253,40 @@ STDMETHODIMP_(BOOL) CDb3Base::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
int bytesToCopy = (dbei->cbBlob < dbe->cbBlob) ? dbei->cbBlob : dbe->cbBlob;
dbei->cbBlob = dbe->cbBlob;
if (bytesToCopy && dbei->pBlob) {
- for (int i = 0;;i += MAXCACHEDREADSIZE) {
- if (bytesToCopy-i <= MAXCACHEDREADSIZE) {
- DecodeCopyMemory(dbei->pBlob + i, DBRead(DWORD(hDbEvent) + offsetof(DBEvent, blob) + i, bytesToCopy - i, NULL), bytesToCopy - i); // decode
- break;
- }
- DecodeCopyMemory(dbei->pBlob + i, DBRead(DWORD(hDbEvent) + offsetof(DBEvent, blob) + i, MAXCACHEDREADSIZE, NULL), MAXCACHEDREADSIZE); // decode
+ BYTE *pSrc = DBRead(DWORD(hDbEvent) + offsetof(DBEvent, blob), bytesToCopy, NULL);
+ if (dbe->flags & DBEF_ENCRYPTED) {
+ dbei->flags &= ~DBEF_ENCRYPTED;
+ size_t len;
+ BYTE* pBlob = (BYTE*)m_crypto->decodeBuffer(pSrc, dbe->cbBlob, &len);
+ if (pBlob == NULL)
+ return 1;
+
+ memcpy(dbei->pBlob, pBlob, bytesToCopy);
+ if (bytesToCopy > len)
+ memset(dbei->pBlob + len, 0, bytesToCopy - len);
+ mir_free(pBlob);
}
+ else DecodeCopyMemory(dbei->pBlob, pSrc, bytesToCopy);
}
return 0;
}
STDMETHODIMP_(BOOL) CDb3Base::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
{
- DBEvent *dbe;
- DBContact dbc;
- DWORD ofsThis;
-
mir_cslock lck(m_csDbAccess);
if (hContact == 0)
hContact = (HANDLE)m_dbHeader.ofsUser;
- dbc = *(DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
- dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
+ DBContact dbc = *(DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
if (dbe->signature != DBEVENT_SIGNATURE || dbc.signature != DBCONTACT_SIGNATURE)
- return -1;
+ return -1;
if ((dbe->flags & DBEF_READ) || (dbe->flags & DBEF_SENT))
return (INT_PTR)dbe->flags;
//log1("mark read @ %08x", hContact);
dbe->flags |= DBEF_READ;
- DBWrite((DWORD)hDbEvent,dbe,sizeof(DBEvent));
+ DBWrite((DWORD)hDbEvent, dbe, sizeof(DBEvent));
BOOL ret = dbe->flags;
if (dbc.ofsFirstUnreadEvent == (DWORD)hDbEvent) {
for (;;) {
@@ -280,9 +295,9 @@ STDMETHODIMP_(BOOL) CDb3Base::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
dbc.timestampFirstUnread = 0;
break;
}
- ofsThis = dbe->ofsNext;
- dbe = (DBEvent*)DBRead(ofsThis,sizeof(DBEvent),NULL);
- if ( !(dbe->flags & (DBEF_READ | DBEF_SENT))) {
+ DWORD ofsThis = dbe->ofsNext;
+ dbe = (DBEvent*)DBRead(ofsThis, sizeof(DBEvent), NULL);
+ if (!(dbe->flags & (DBEF_READ | DBEF_SENT))) {
dbc.ofsFirstUnreadEvent = ofsThis;
dbc.timestampFirstUnread = dbe->timestamp;
break;
@@ -297,13 +312,13 @@ STDMETHODIMP_(BOOL) CDb3Base::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
STDMETHODIMP_(HANDLE) CDb3Base::GetEventContact(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
- DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
if (dbe->signature != DBEVENT_SIGNATURE)
- return (HANDLE)-1;
+ return (HANDLE)-1;
while (!(dbe->flags & DBEF_FIRST))
- dbe = (DBEvent*)DBRead(dbe->ofsPrev,sizeof(DBEvent),NULL);
-
+ dbe = (DBEvent*)DBRead(dbe->ofsPrev, sizeof(DBEvent), NULL);
+
return (HANDLE)dbe->ofsPrev;
}
@@ -312,7 +327,7 @@ STDMETHODIMP_(HANDLE) CDb3Base::FindFirstEvent(HANDLE hContact)
mir_cslock lck(m_csDbAccess);
if (hContact == 0)
hContact = (HANDLE)m_dbHeader.ofsUser;
-
+
DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsFirstEvent;
}
@@ -323,7 +338,7 @@ STDMETHODIMP_(HANDLE) CDb3Base::FindFirstUnreadEvent(HANDLE hContact)
if (hContact == 0)
hContact = (HANDLE)m_dbHeader.ofsUser;
- DBContact *dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsFirstUnreadEvent;
}
@@ -333,21 +348,21 @@ STDMETHODIMP_(HANDLE) CDb3Base::FindLastEvent(HANDLE hContact)
if (hContact == 0)
hContact = (HANDLE)m_dbHeader.ofsUser;
- DBContact *dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsLastEvent;
}
STDMETHODIMP_(HANDLE) CDb3Base::FindNextEvent(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
- DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
return (dbe->signature != DBEVENT_SIGNATURE) ? 0 : (HANDLE)dbe->ofsNext;
}
STDMETHODIMP_(HANDLE) CDb3Base::FindPrevEvent(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
- DBEvent *dbe = (DBEvent*)DBRead(hDbEvent,sizeof(DBEvent),NULL);
+ DBEvent *dbe = (DBEvent*)DBRead(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.cpp b/plugins/Db3x_mmap/src/dbintf.cpp
index 9a1b7e9fba..0efc944518 100644
--- a/plugins/Db3x_mmap/src/dbintf.cpp
+++ b/plugins/Db3x_mmap/src/dbintf.cpp
@@ -126,7 +126,6 @@ int CDb3Base::Load(bool bSkipInit)
if (InitModuleNames()) return 1;
m_bReadOnly = false;
- m_bEncrypted = 0 == memcmp(m_dbHeader.signature, &dbSignatureE, sizeof(m_dbHeader.signature));
hContactDeletedEvent = CreateHookableEvent(ME_DB_CONTACT_DELETED);
hContactAddedEvent = CreateHookableEvent(ME_DB_CONTACT_ADDED);
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h
index eb0b67535f..3e76d9a49a 100644
--- a/plugins/Db3x_mmap/src/dbintf.h
+++ b/plugins/Db3x_mmap/src/dbintf.h
@@ -54,6 +54,16 @@ DBHeader
#define DBVT_ENCRYPTED 250
+#define NeedBytes(n) if (bytesRemaining<(n)) pBlob = (PBYTE)DBRead(ofsBlobPtr,(n),&bytesRemaining)
+#define MoveAlong(n) {int x = n; pBlob += (x); ofsBlobPtr += (x); bytesRemaining -= (x);}
+
+DWORD __forceinline GetSettingValueLength(PBYTE pSetting)
+{
+ if (pSetting[0] & DBVTF_VARIABLELENGTH)
+ return 2 + *(PWORD)(pSetting + 1);
+ return pSetting[0];
+}
+
struct DBSignature
{
char name[15];
@@ -142,8 +152,6 @@ struct DBEvent
#include <poppack.h>
-#define MAXCACHEDREADSIZE 65536
-
struct CDb3Base : public MIDatabase, public MIDatabaseChecker, public MZeroedObject
{
CDb3Base(const TCHAR* tszFileName);
@@ -318,6 +326,7 @@ struct CDb3Mmap : public CDb3Base
int Load(bool bSkipInit);
+ void ToggleEncryption(void);
void StoreKey(void);
void SetPassword(const TCHAR *ptszPassword);
void UpdateMenuItem(void);
@@ -326,6 +335,8 @@ struct CDb3Mmap : public CDb3Base
protected:
int InitCrypt(void);
+ void ToggleEventsEncryption(HANDLE hContact);
+ void ToggleSettingsEncryption(HANDLE hContact);
protected:
void InitDialogs();
diff --git a/plugins/Db3x_mmap/src/dbsettings.cpp b/plugins/Db3x_mmap/src/dbsettings.cpp
index 254718fa9a..6598890072 100644
--- a/plugins/Db3x_mmap/src/dbsettings.cpp
+++ b/plugins/Db3x_mmap/src/dbsettings.cpp
@@ -26,15 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
DWORD GetModuleNameOfs(const char *szName);
DBCachedContact* AddToCachedContactList(HANDLE hContact, int index);
-DWORD __forceinline GetSettingValueLength(PBYTE pSetting)
-{
- if (pSetting[0] & DBVTF_VARIABLELENGTH)
- return 2+*(PWORD)(pSetting+1);
- return pSetting[0];
-}
-
-#define NeedBytes(n) if (bytesRemaining<(n)) pBlob = (PBYTE)DBRead(ofsBlobPtr,(n),&bytesRemaining)
-#define MoveAlong(n) {int x = n; pBlob += (x); ofsBlobPtr += (x); bytesRemaining -= (x);}
#define VLT(n) ((n == DBVT_UTF8 || n == DBVT_ENCRYPTED)?DBVT_ASCIIZ:n)
bool isEncrypted(LPCSTR szModule, LPCSTR szSetting)
@@ -83,14 +74,13 @@ int CDb3Base::GetContactSettingWorker(HANDLE hContact, DBCONTACTGETSETTING *dbcg
DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(hContact, szCachedSettingName, 0);
if (pCachedValue != NULL) {
if (pCachedValue->type == DBVT_ASCIIZ || pCachedValue->type == DBVT_UTF8) {
- bool bIsEncrypted = /*m_bEncrypted || */ ::isEncrypted(dbcgs->szModule, dbcgs->szSetting);
int cbOrigLen = dbcgs->pValue->cchVal;
char *cbOrigPtr = dbcgs->pValue->pszVal;
memcpy(dbcgs->pValue, pCachedValue, sizeof(DBVARIANT));
if (isStatic) {
int cbLen = 0;
- if ( pCachedValue->pszVal != NULL )
- cbLen = (int)strlen( pCachedValue->pszVal );
+ if (pCachedValue->pszVal != NULL)
+ cbLen = (int)strlen(pCachedValue->pszVal);
cbOrigLen--;
dbcgs->pValue->pszVal = cbOrigPtr;
@@ -101,11 +91,11 @@ int CDb3Base::GetContactSettingWorker(HANDLE hContact, DBCONTACTGETSETTING *dbcg
dbcgs->pValue->cchVal = cbLen;
}
else {
- dbcgs->pValue->pszVal = (char*)mir_alloc(strlen(pCachedValue->pszVal)+1);
- strcpy(dbcgs->pValue->pszVal,pCachedValue->pszVal);
+ dbcgs->pValue->pszVal = (char*)mir_alloc(strlen(pCachedValue->pszVal) + 1);
+ strcpy(dbcgs->pValue->pszVal, pCachedValue->pszVal);
}
}
- else memcpy( dbcgs->pValue, pCachedValue, sizeof( DBVARIANT ));
+ else memcpy(dbcgs->pValue, pCachedValue, sizeof(DBVARIANT));
log2("get cached %s (%p)", printVariant(dbcgs->pValue), pCachedValue);
return (pCachedValue->type == DBVT_DELETED) ? 1 : 0;
@@ -386,45 +376,48 @@ STDMETHODIMP_(BOOL) CDb3Base::WriteContactSetting(HANDLE hContact, DBCONTACTWRIT
return 1;
}
- DBCONTACTWRITESETTING tmp = *dbcws;
- if (tmp.value.type == DBVT_WCHAR) {
- if (tmp.value.pszVal != NULL) {
- char* val = mir_utf8encodeW(tmp.value.pwszVal);
+ // used for notifications
+ DBCONTACTWRITESETTING dbcwNotif = *dbcws;
+ if (dbcwNotif.value.type == DBVT_WCHAR) {
+ if (dbcwNotif.value.pszVal != NULL) {
+ char* val = mir_utf8encodeW(dbcwNotif.value.pwszVal);
if (val == NULL)
return 1;
- tmp.value.pszVal = (char*)alloca(strlen(val) + 1);
- strcpy(tmp.value.pszVal, val);
+ dbcwNotif.value.pszVal = (char*)alloca(strlen(val) + 1);
+ strcpy(dbcwNotif.value.pszVal, val);
mir_free(val);
- tmp.value.type = DBVT_UTF8;
+ dbcwNotif.value.type = DBVT_UTF8;
}
else return 1;
}
- if (tmp.szModule == NULL || tmp.szSetting == NULL)
+ if (dbcwNotif.szModule == NULL || dbcwNotif.szSetting == NULL)
return 1;
+ DBCONTACTWRITESETTING dbcwWork = dbcwNotif;
+
mir_ptr<BYTE> pEncoded(NULL);
bool bIsEncrypted = false;
- switch (tmp.value.type) {
+ switch (dbcwWork.value.type) {
case DBVT_BYTE: case DBVT_WORD: case DBVT_DWORD:
break;
case DBVT_ASCIIZ: case DBVT_UTF8:
- if (tmp.value.pszVal == NULL) return 1;
- tmp.value.cchVal = (WORD)strlen(tmp.value.pszVal);
- bIsEncrypted = /*m_bEncrypted ||*/ ::isEncrypted(dbcws->szModule, dbcws->szSetting);
+ if (dbcwWork.value.pszVal == NULL) return 1;
+ dbcwWork.value.cchVal = (WORD)strlen(dbcwWork.value.pszVal);
+ bIsEncrypted = m_bEncrypted || ::isEncrypted(dbcws->szModule, dbcws->szSetting);
if (bIsEncrypted) {
size_t len;
- BYTE *pResult = m_crypto->encodeString(tmp.value.pszVal, &len);
+ BYTE *pResult = m_crypto->encodeString(dbcwWork.value.pszVal, &len);
if (pResult != NULL) {
- pEncoded = tmp.value.pbVal = pResult;
- tmp.value.cpbVal = (WORD)len;
- tmp.value.type = DBVT_ENCRYPTED;
+ pEncoded = dbcwWork.value.pbVal = pResult;
+ dbcwWork.value.cpbVal = (WORD)len;
+ dbcwWork.value.type = DBVT_ENCRYPTED;
}
}
break;
case DBVT_BLOB: case DBVT_ENCRYPTED:
- if (tmp.value.pbVal == NULL) return 1;
+ if (dbcwWork.value.pbVal == NULL) return 1;
break;
default:
return 1;
@@ -432,58 +425,59 @@ STDMETHODIMP_(BOOL) CDb3Base::WriteContactSetting(HANDLE hContact, DBCONTACTWRIT
mir_cslockfull lck(m_csDbAccess);
- char *szCachedSettingName = m_cache->GetCachedSetting(tmp.szModule, tmp.szSetting, moduleNameLen, settingNameLen);
+ char *szCachedSettingName = m_cache->GetCachedSetting(dbcwWork.szModule, dbcwWork.szSetting, moduleNameLen, settingNameLen);
log3("set [%08p] %s (%p)", hContact, szCachedSettingName, szCachedSettingName);
- if (tmp.value.type != DBVT_BLOB && tmp.value.type != DBVT_ENCRYPTED && !bIsEncrypted) {
+ // 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);
if (pCachedValue != NULL) {
bool bIsIdentical = false;
- if (pCachedValue->type == tmp.value.type) {
- switch (tmp.value.type) {
- case DBVT_BYTE: bIsIdentical = pCachedValue->bVal == tmp.value.bVal; break;
- case DBVT_WORD: bIsIdentical = pCachedValue->wVal == tmp.value.wVal; break;
- case DBVT_DWORD: bIsIdentical = pCachedValue->dVal == tmp.value.dVal; break;
+ if (pCachedValue->type == dbcwWork.value.type) {
+ switch (dbcwWork.value.type) {
+ case DBVT_BYTE: bIsIdentical = pCachedValue->bVal == dbcwWork.value.bVal; break;
+ case DBVT_WORD: bIsIdentical = pCachedValue->wVal == dbcwWork.value.wVal; break;
+ case DBVT_DWORD: bIsIdentical = pCachedValue->dVal == dbcwWork.value.dVal; break;
case DBVT_UTF8:
- case DBVT_ASCIIZ: bIsIdentical = strcmp(pCachedValue->pszVal, tmp.value.pszVal) == 0; break;
+ case DBVT_ASCIIZ: bIsIdentical = strcmp(pCachedValue->pszVal, dbcwWork.value.pszVal) == 0; break;
}
if (bIsIdentical)
return 0;
}
- m_cache->SetCachedVariant(&tmp.value, pCachedValue);
+ m_cache->SetCachedVariant(&dbcwWork.value, pCachedValue);
}
if (szCachedSettingName[-1] != 0) {
lck.unlock();
- log2(" set resident as %s (%p)", printVariant(&tmp.value), pCachedValue);
- NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp);
+ log2(" set resident as %s (%p)", printVariant(&dbcwWork.value), pCachedValue);
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&dbcwWork);
return 0;
}
}
else m_cache->GetCachedValuePtr(hContact, szCachedSettingName, -1);
- log1(" write database as %s", printVariant(&tmp.value));
+ log1(" write database as %s", printVariant(&dbcwWork.value));
- DWORD ofsModuleName = GetModuleNameOfs(tmp.szModule);
+ DWORD ofsModuleName = GetModuleNameOfs(dbcwWork.szModule);
DWORD ofsBlobPtr, ofsContact = (hContact == 0) ? m_dbHeader.ofsUser : (DWORD)hContact;
DBContact dbc = *(DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
if (dbc.signature != DBCONTACT_SIGNATURE)
return 1;
- //make sure the module group exists
+ // make sure the module group exists
PBYTE pBlob;
int bytesRequired, bytesRemaining;
DBContactSettings dbcs;
DWORD ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(&dbc, ofsContact, ofsModuleName);
if (ofsSettingsGroup == 0) { //module group didn't exist - make it
- switch (tmp.value.type) {
+ switch (dbcwWork.value.type) {
case DBVT_ASCIIZ: case DBVT_UTF8:
- bytesRequired = tmp.value.cchVal + 2;
+ bytesRequired = dbcwWork.value.cchVal + 2;
break;
case DBVT_BLOB: case DBVT_ENCRYPTED:
- bytesRequired = tmp.value.cpbVal + 2;
+ bytesRequired = dbcwWork.value.cpbVal + 2;
break;
default:
- bytesRequired = tmp.value.type;
+ bytesRequired = dbcwWork.value.type;
}
bytesRequired += 2 + settingNameLen;
bytesRequired += (DB_SETTINGS_RESIZE_GRANULARITY - (bytesRequired % DB_SETTINGS_RESIZE_GRANULARITY)) % DB_SETTINGS_RESIZE_GRANULARITY;
@@ -501,12 +495,13 @@ STDMETHODIMP_(BOOL) CDb3Base::WriteContactSetting(HANDLE hContact, DBCONTACTWRIT
}
else {
dbcs = *(DBContactSettings*)DBRead(ofsSettingsGroup, sizeof(DBContactSettings), &bytesRemaining);
- //find if the setting exists
+
+ // find if the setting exists
ofsBlobPtr = ofsSettingsGroup + offsetof(DBContactSettings, blob);
pBlob = (PBYTE)DBRead(ofsBlobPtr, 1, &bytesRemaining);
while (pBlob[0]) {
NeedBytes(settingNameLen + 1);
- if (pBlob[0] == settingNameLen && !memcmp(pBlob + 1, tmp.szSetting, settingNameLen))
+ if (pBlob[0] == settingNameLen && !memcmp(pBlob + 1, dbcwWork.szSetting, settingNameLen))
break;
NeedBytes(1);
MoveAlong(pBlob[0] + 1);
@@ -514,15 +509,17 @@ STDMETHODIMP_(BOOL) CDb3Base::WriteContactSetting(HANDLE hContact, DBCONTACTWRIT
MoveAlong(1 + GetSettingValueLength(pBlob));
NeedBytes(1);
}
- if (pBlob[0]) { //setting already existed, and up to end of name is in cache
+
+ // setting already existed, and up to end of name is in cache
+ if (pBlob[0]) {
MoveAlong(1 + settingNameLen);
- //if different type or variable length and length is different
+ // if different type or variable length and length is different
NeedBytes(3);
- if (pBlob[0] != tmp.value.type ||
- ((pBlob[0] == DBVT_ASCIIZ || pBlob[0] == DBVT_UTF8) && *(PWORD)(pBlob + 1) != tmp.value.cchVal) ||
- ((pBlob[0] == DBVT_BLOB || pBlob[0] == DBVT_ENCRYPTED) && *(PWORD)(pBlob + 1) != tmp.value.cpbVal))
+ if (pBlob[0] != dbcwWork.value.type ||
+ ((pBlob[0] == DBVT_ASCIIZ || pBlob[0] == DBVT_UTF8) && *(PWORD)(pBlob + 1) != dbcwWork.value.cchVal) ||
+ ((pBlob[0] == DBVT_BLOB || pBlob[0] == DBVT_ENCRYPTED) && *(PWORD)(pBlob + 1) != dbcwWork.value.cpbVal))
{
- //bin it
+ // bin it
NeedBytes(3);
int nameLen = 1 + settingNameLen;
int valLen = 1 + GetSettingValueLength(pBlob);
@@ -540,57 +537,58 @@ STDMETHODIMP_(BOOL) CDb3Base::WriteContactSetting(HANDLE hContact, DBCONTACTWRIT
pBlob = (PBYTE)DBRead(ofsBlobPtr, 1, &bytesRemaining);
}
else {
- //replace existing setting at pBlob
- MoveAlong(1); //skip data type
- switch (tmp.value.type) {
- case DBVT_BYTE: DBWrite(ofsBlobPtr, &tmp.value.bVal, 1); break;
- case DBVT_WORD: EncodeDBWrite(ofsBlobPtr, &tmp.value.wVal, 2); break;
- case DBVT_DWORD: EncodeDBWrite(ofsBlobPtr, &tmp.value.dVal, 4); break;
+ // replace existing setting at pBlob
+ MoveAlong(1); // skip data type
+ switch (dbcwWork.value.type) {
+ case DBVT_BYTE: DBWrite(ofsBlobPtr, &dbcwWork.value.bVal, 1); break;
+ case DBVT_WORD: EncodeDBWrite(ofsBlobPtr, &dbcwWork.value.wVal, 2); break;
+ case DBVT_DWORD: EncodeDBWrite(ofsBlobPtr, &dbcwWork.value.dVal, 4); break;
case DBVT_BLOB:
- EncodeDBWrite(ofsBlobPtr + 2, tmp.value.pbVal, tmp.value.cpbVal);
+ EncodeDBWrite(ofsBlobPtr + 2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal);
break;
case DBVT_ENCRYPTED:
- DBWrite(ofsBlobPtr + 2, tmp.value.pbVal, tmp.value.cpbVal);
+ DBWrite(ofsBlobPtr + 2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal);
break;
case DBVT_UTF8:
case DBVT_ASCIIZ:
- EncodeDBWrite(ofsBlobPtr + 2, tmp.value.pszVal, tmp.value.cchVal);
+ EncodeDBWrite(ofsBlobPtr + 2, dbcwWork.value.pszVal, dbcwWork.value.cchVal);
break;
}
- //quit
+ // quit
DBFlush(1);
lck.unlock();
- //notify
- NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp);
+ // notify
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&dbcwNotif);
return 0;
}
}
}
- //cannot do a simple replace, add setting to end of list
- //pBlob already points to end of list
- //see if it fits
- switch (tmp.value.type) {
+
+ // cannot do a simple replace, add setting to end of list
+ // pBlob already points to end of list
+ // see if it fits
+ switch (dbcwWork.value.type) {
case DBVT_ASCIIZ: case DBVT_UTF8:
- bytesRequired = tmp.value.cchVal + 2;
+ bytesRequired = dbcwWork.value.cchVal + 2;
break;
case DBVT_BLOB: case DBVT_ENCRYPTED:
- bytesRequired = tmp.value.cpbVal + 2;
+ bytesRequired = dbcwWork.value.cpbVal + 2;
break;
default:
- bytesRequired = tmp.value.type;
+ bytesRequired = dbcwWork.value.type;
}
bytesRequired += 2 + settingNameLen;
bytesRequired += ofsBlobPtr + 1 - (ofsSettingsGroup + offsetof(DBContactSettings, blob));
if ((DWORD)bytesRequired > dbcs.cbBlob) {
- //doesn't fit: move entire group
+ // doesn't fit: move entire group
DBContactSettings *dbcsPrev;
DWORD ofsDbcsPrev, ofsNew;
InvalidateSettingsGroupOfsCacheEntry(ofsSettingsGroup);
bytesRequired += (DB_SETTINGS_RESIZE_GRANULARITY - (bytesRequired % DB_SETTINGS_RESIZE_GRANULARITY)) % DB_SETTINGS_RESIZE_GRANULARITY;
- //find previous group to change its offset
+ // find previous group to change its offset
ofsDbcsPrev = dbc.ofsFirstSettings;
if (ofsDbcsPrev == ofsSettingsGroup) ofsDbcsPrev = 0;
else {
@@ -602,7 +600,7 @@ STDMETHODIMP_(BOOL) CDb3Base::WriteContactSetting(HANDLE hContact, DBCONTACTWRIT
}
}
- //create the new one
+ // create the new one
ofsNew = ReallocSpace(ofsSettingsGroup, dbcs.cbBlob + offsetof(DBContactSettings, blob), bytesRequired + offsetof(DBContactSettings, blob));
dbcs.cbBlob = bytesRequired;
@@ -621,45 +619,46 @@ STDMETHODIMP_(BOOL) CDb3Base::WriteContactSetting(HANDLE hContact, DBCONTACTWRIT
ofsSettingsGroup = ofsNew;
pBlob = (PBYTE)DBRead(ofsBlobPtr, 1, &bytesRemaining);
}
- //we now have a place to put it and enough space: make it
+
+ // we now have a place to put it and enough space: make it
DBWrite(ofsBlobPtr, &settingNameLen, 1);
- DBWrite(ofsBlobPtr + 1, (PVOID)tmp.szSetting, settingNameLen);
+ DBWrite(ofsBlobPtr + 1, (PVOID)dbcwWork.szSetting, settingNameLen);
MoveAlong(1 + settingNameLen);
- DBWrite(ofsBlobPtr, &tmp.value.type, 1);
+ DBWrite(ofsBlobPtr, &dbcwWork.value.type, 1);
MoveAlong(1);
- switch (tmp.value.type) {
- case DBVT_BYTE: DBWrite(ofsBlobPtr, &tmp.value.bVal, 1); MoveAlong(1); break;
- case DBVT_WORD: EncodeDBWrite(ofsBlobPtr, &tmp.value.wVal, 2); MoveAlong(2); break;
- case DBVT_DWORD: EncodeDBWrite(ofsBlobPtr, &tmp.value.dVal, 4); MoveAlong(4); break;
+ switch (dbcwWork.value.type) {
+ case DBVT_BYTE: DBWrite(ofsBlobPtr, &dbcwWork.value.bVal, 1); MoveAlong(1); break;
+ case DBVT_WORD: EncodeDBWrite(ofsBlobPtr, &dbcwWork.value.wVal, 2); MoveAlong(2); break;
+ case DBVT_DWORD: EncodeDBWrite(ofsBlobPtr, &dbcwWork.value.dVal, 4); MoveAlong(4); break;
case DBVT_BLOB:
- DBWrite(ofsBlobPtr, &tmp.value.cpbVal, 2);
- EncodeDBWrite(ofsBlobPtr + 2, tmp.value.pbVal, tmp.value.cpbVal);
- MoveAlong(2 + tmp.value.cpbVal);
+ DBWrite(ofsBlobPtr, &dbcwWork.value.cpbVal, 2);
+ EncodeDBWrite(ofsBlobPtr + 2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal);
+ MoveAlong(2 + dbcwWork.value.cpbVal);
break;
case DBVT_ENCRYPTED:
- DBWrite(ofsBlobPtr, &tmp.value.cpbVal, 2);
- DBWrite(ofsBlobPtr + 2, tmp.value.pbVal, tmp.value.cpbVal);
- MoveAlong(2 + tmp.value.cpbVal);
+ DBWrite(ofsBlobPtr, &dbcwWork.value.cpbVal, 2);
+ DBWrite(ofsBlobPtr + 2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal);
+ MoveAlong(2 + dbcwWork.value.cpbVal);
break;
case DBVT_UTF8: case DBVT_ASCIIZ:
- DBWrite(ofsBlobPtr, &tmp.value.cchVal, 2);
- EncodeDBWrite(ofsBlobPtr + 2, tmp.value.pszVal, tmp.value.cchVal);
- MoveAlong(2 + tmp.value.cchVal);
+ DBWrite(ofsBlobPtr, &dbcwWork.value.cchVal, 2);
+ EncodeDBWrite(ofsBlobPtr + 2, dbcwWork.value.pszVal, dbcwWork.value.cchVal);
+ MoveAlong(2 + dbcwWork.value.cchVal);
break;
}
BYTE zero = 0;
DBWrite(ofsBlobPtr, &zero, 1);
- //quit
+ // quit
DBFlush(1);
lck.unlock();
- //notify
- NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&tmp);
+ // notify
+ NotifyEventHooks(hSettingChangeEvent, (WPARAM)hContact, (LPARAM)&dbcwNotif);
return 0;
}
@@ -696,12 +695,12 @@ STDMETHODIMP_(BOOL) CDb3Base::DeleteContactSetting(HANDLE hContact, DBCONTACTGET
if (dbc->signature != DBCONTACT_SIGNATURE)
return 1;
- //make sure the module group exists
+ // make sure the module group exists
DWORD ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(dbc, (DWORD)hContact, ofsModuleName);
if (ofsSettingsGroup == 0)
return 1;
- //find if the setting exists
+ // find if the setting exists
DWORD ofsBlobPtr = ofsSettingsGroup + offsetof(DBContactSettings, blob);
int bytesRemaining;
PBYTE pBlob = (PBYTE)DBRead(ofsBlobPtr, 1, &bytesRemaining);
@@ -718,7 +717,7 @@ STDMETHODIMP_(BOOL) CDb3Base::DeleteContactSetting(HANDLE hContact, DBCONTACTGET
if (!pBlob[0]) //setting didn't exist
return 1;
- //bin it
+ // bin it
MoveAlong(1 + settingNameLen);
NeedBytes(3);
int nameLen = 1 + settingNameLen;
@@ -738,7 +737,7 @@ STDMETHODIMP_(BOOL) CDb3Base::DeleteContactSetting(HANDLE hContact, DBCONTACTGET
m_cache->GetCachedValuePtr((HANDLE)saveWparam, szCachedSettingName, -1);
- //notify
+ // notify
DBCONTACTWRITESETTING dbcws = { 0 };
dbcws.szModule = dbcgs->szModule;
dbcws.szSetting = dbcgs->szSetting;
diff --git a/plugins/Db3x_mmap/src/dbtool/aggressive.cpp b/plugins/Db3x_mmap/src/dbtool/aggressive.cpp
index 0a47754920..92266f37b3 100644
--- a/plugins/Db3x_mmap/src/dbtool/aggressive.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/aggressive.cpp
@@ -26,27 +26,27 @@ int CDb3Base::WorkAggressive(int firstTime)
if (!cb->bAggressive)
return ERROR_NO_MORE_ITEMS;
- cb->pfnAddLogMessage(STATUS_MESSAGE,TranslateT("Performing aggressive pass"));
+ cb->pfnAddLogMessage(STATUS_MESSAGE, TranslateT("Performing aggressive pass"));
ofsAggrCur = 0;
cb->spaceProcessed = 0;
}
-
- int blockBytes = min(BLOCKSIZE+3,(int)(sourceFileSize-ofsAggrCur));
+
+ int blockBytes = min(BLOCKSIZE + 3, (int)(sourceFileSize - ofsAggrCur));
if (blockBytes <= 0)
return ERROR_NO_MORE_ITEMS;
BYTE *buf = m_pDbCache + ofsAggrCur;
blockBytes -= 3;
- for (int i=0; i < blockBytes; i++) {
+ for (int i = 0; i < blockBytes; i++) {
if (buf[i]) {
if ((*(PDWORD)&buf[i] & 0x00FFFFFF) != 0xDECADE)
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Aggressive: random junk at %08X: skipping"),ofsAggrCur+i);
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Aggressive: random junk at %08X: skipping"), ofsAggrCur + i);
else
//TODO: give user the option of placing manually
- cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Aggressive: unlinked data at %08X: can't automatically place"),ofsAggrCur+i);
+ cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Aggressive: unlinked data at %08X: can't automatically place"), ofsAggrCur + i);
for (; i < blockBytes; i++)
- if (buf[i] == 0) {i--; break;}
+ if (buf[i] == 0) { i--; break; }
}
}
ofsAggrCur += BLOCKSIZE;
diff --git a/plugins/Db3x_mmap/src/dbtool/contactchain.cpp b/plugins/Db3x_mmap/src/dbtool/contactchain.cpp
index 80c4b62168..d1aa5a933e 100644
--- a/plugins/Db3x_mmap/src/dbtool/contactchain.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/contactchain.cpp
@@ -19,9 +19,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "..\commonheaders.h"
-static DWORD ofsThisContact,ofsDestPrevContact;
+static DWORD ofsThisContact, ofsDestPrevContact;
static DWORD contactCount;
-static DWORD ofsDestThis,ofsNextContact;
+static DWORD ofsDestThis, ofsNextContact;
static int phase;
static DBContact dbc;
@@ -31,7 +31,7 @@ int CDb3Base::WorkContactChain(int firstTime)
int ret;
if (firstTime) {
- cb->pfnAddLogMessage(STATUS_MESSAGE,TranslateT("Processing contact chain"));
+ cb->pfnAddLogMessage(STATUS_MESSAGE, TranslateT("Processing contact chain"));
ofsDestPrevContact = 0;
ofsThisContact = m_dbHeader.ofsFirstContact;
contactCount = 0;
@@ -39,54 +39,58 @@ int CDb3Base::WorkContactChain(int firstTime)
phase = 0;
}
- switch(phase) {
+ switch (phase) {
case 0:
if (ofsThisContact == 0) {
LBL_FinishUp:
if (contactCount != m_dbHeader.contactCount)
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Contact count marked wrongly: correcting"));
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Contact count marked wrongly: correcting"));
m_dbHeader.contactCount = contactCount;
return ERROR_NO_MORE_ITEMS;
}
- if (!SignatureValid(ofsThisContact,DBCONTACT_SIGNATURE)) {
- cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Contact chain corrupted, further entries ignored"));
+ if (!SignatureValid(ofsThisContact, DBCONTACT_SIGNATURE)) {
+ cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Contact chain corrupted, further entries ignored"));
goto LBL_FinishUp;
}
- if (ReadSegment(ofsThisContact,&dbc,sizeof(dbc)) != ERROR_SUCCESS)
+ if (ReadSegment(ofsThisContact, &dbc, sizeof(dbc)) != ERROR_SUCCESS)
goto LBL_FinishUp;
ofsNextContact = dbc.ofsNext;
dbc.ofsNext = 0;
if (!cb->bCheckOnly) {
- if ((ofsDestThis = WriteSegment(WSOFS_END,&dbc,sizeof(dbc))) == WS_ERROR)
+ if ((ofsDestThis = WriteSegment(WSOFS_END, &dbc, sizeof(dbc))) == WS_ERROR)
return ERROR_HANDLE_DISK_FULL;
- if (ofsDestPrevContact)
- WriteSegment(ofsDestPrevContact+offsetof(DBContact,ofsNext),&ofsDestThis,sizeof(DWORD));
- else
+ if (ofsDestPrevContact)
+ WriteSegment(ofsDestPrevContact + offsetof(DBContact, ofsNext), &ofsDestThis, sizeof(DWORD));
+ else
m_dbHeader.ofsFirstContact = ofsDestThis;
- } else
- ofsDestThis = ofsThisContact; // needed in event chain worker
+ }
+ else ofsDestThis = ofsThisContact; // needed in event chain worker
+
contactCount++;
phase++; first = 1;
+
//fall thru
case 1:
- ret = WorkSettingsChain(ofsDestThis,&dbc,first);
+ ret = WorkSettingsChain(ofsDestThis, &dbc, first);
if (ret == ERROR_NO_MORE_ITEMS) {
phase++; first = 1;
}
else if (ret) return ret;
else break;
+
//fall thru
case 2:
- ret = WorkEventChain(ofsDestThis,&dbc,first);
+ ret = WorkEventChain(ofsDestThis, &dbc, first);
if (ret == ERROR_NO_MORE_ITEMS) {
phase++; first = 1;
}
else if (ret) return ret;
else break;
+
//fall thru
case 3:
- if (WriteSegment(ofsDestThis,&dbc,sizeof(DBContact)) == WS_ERROR)
+ if (WriteSegment(ofsDestThis, &dbc, sizeof(DBContact)) == WS_ERROR)
return ERROR_HANDLE_DISK_FULL;
ofsDestPrevContact = ofsDestThis;
ofsThisContact = ofsNextContact;
diff --git a/plugins/Db3x_mmap/src/dbtool/disk.cpp b/plugins/Db3x_mmap/src/dbtool/disk.cpp
index a5178c8ea2..d22afb70d9 100644
--- a/plugins/Db3x_mmap/src/dbtool/disk.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/disk.cpp
@@ -21,28 +21,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
int CDb3Base::SignatureValid(DWORD ofs, DWORD signature)
{
- DWORD sig;
-
- if (ofs+sizeof(sig) >= sourceFileSize) {
+ if (ofs + sizeof(DWORD) >= sourceFileSize) {
cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Invalid offset found (database truncated?)"));
return 0;
}
- sig = *(DWORD*)(m_pDbCache+ofs);
-
+ DWORD sig = *(DWORD*)(m_pDbCache + ofs);
return sig == signature;
}
int CDb3Base::PeekSegment(DWORD ofs, PVOID buf, int cbBytes)
{
- DWORD bytesRead;
-
if (ofs >= sourceFileSize) {
cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Invalid offset found"));
return ERROR_SEEK;
}
- if (ofs+cbBytes > sourceFileSize)
+ DWORD bytesRead;
+ if (ofs + cbBytes > sourceFileSize)
bytesRead = sourceFileSize - ofs;
else
bytesRead = cbBytes;
@@ -52,7 +48,7 @@ int CDb3Base::PeekSegment(DWORD ofs, PVOID buf, int cbBytes)
return ERROR_READ_FAULT;
}
- CopyMemory(buf, m_pDbCache+ofs, bytesRead);
+ CopyMemory(buf, m_pDbCache + ofs, bytesRead);
if ((int)bytesRead<cbBytes) return ERROR_HANDLE_EOF;
return ERROR_SUCCESS;
@@ -64,12 +60,11 @@ int CDb3Base::ReadSegment(DWORD ofs, PVOID buf, int cbBytes)
if (ret != ERROR_SUCCESS && ret != ERROR_HANDLE_EOF) return ret;
if (cb->bAggressive) {
- if (ofs+cbBytes > sourceFileSize) {
+ if (ofs + cbBytes > sourceFileSize) {
cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Can't write to working file, aggressive mode may be too aggressive now"));
- ZeroMemory(m_pDbCache+ofs, sourceFileSize-ofs);
+ ZeroMemory(m_pDbCache + ofs, sourceFileSize - ofs);
}
- else
- ZeroMemory(m_pDbCache+ofs, cbBytes);
+ else ZeroMemory(m_pDbCache + ofs, cbBytes);
}
cb->spaceProcessed += cbBytes;
return ERROR_SUCCESS;
@@ -85,7 +80,7 @@ DWORD CDb3Base::WriteSegment(DWORD ofs, PVOID buf, int cbBytes)
}
SetFilePointer(cb->hOutFile, ofs, NULL, FILE_BEGIN);
WriteFile(cb->hOutFile, buf, cbBytes, &bytesWritten, NULL);
- if ((int)bytesWritten<cbBytes) {
+ if ((int)bytesWritten < cbBytes) {
cb->pfnAddLogMessage(STATUS_FATAL, TranslateT("Can't write to output file - disk full? (%u)"), GetLastError());
return WS_ERROR;
}
@@ -101,7 +96,7 @@ int CDb3Base::ReadWrittenSegment(DWORD ofs, PVOID buf, int cbBytes)
SetFilePointer(cb->hOutFile, ofs, NULL, FILE_BEGIN);
ReadFile(cb->hOutFile, buf, cbBytes, &bytesRead, NULL);
- if ((int)bytesRead<cbBytes)
+ if ((int)bytesRead < cbBytes)
return ERROR_READ_FAULT;
return ERROR_SUCCESS;
diff --git a/plugins/Db3x_mmap/src/dbtool/eventchain.cpp b/plugins/Db3x_mmap/src/dbtool/eventchain.cpp
index 1aa5b2ecb4..872809503e 100644
--- a/plugins/Db3x_mmap/src/dbtool/eventchain.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/eventchain.cpp
@@ -24,12 +24,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "..\commonheaders.h"
+#define DBEF_ALL (DBEF_FIRST | DBEF_READ | DBEF_SENT | DBEF_RTL | DBEF_UTF | DBEF_ENCRYPTED)
+
static BOOL backLookup;
-static DWORD ofsThisEvent,ofsPrevEvent;
+static DWORD ofsThisEvent, ofsPrevEvent;
static DWORD ofsDestPrevEvent;
static DWORD eventCount;
static DWORD lastTimestamp;
-static DWORD ofsFirstUnread,timestampFirstUnread;
+static DWORD ofsFirstUnread, timestampFirstUnread;
static DWORD memsize = 0;
static DBEvent* memblock = NULL;
static DBEvent* dbePrevEvent = NULL;
@@ -37,10 +39,10 @@ static DBEvent* dbePrevEvent = NULL;
void CDb3Base::ConvertOldEvent(DBEvent*& dbei)
{
int msglen = (int)strlen((char*)dbei->blob) + 1, msglenW = 0;
- if (msglen != (int) dbei->cbBlob) {
+ if (msglen != (int)dbei->cbBlob) {
int i, count = ((dbei->cbBlob - msglen) / sizeof(WCHAR));
- WCHAR* p = (WCHAR*)&dbei->blob[ msglen ];
- for ( i = 0; i < count; i++) {
+ WCHAR* p = (WCHAR*)&dbei->blob[msglen];
+ for (i = 0; i < count; i++) {
if (p[i] == 0) {
msglenW = i;
break;
@@ -53,34 +55,35 @@ void CDb3Base::ConvertOldEvent(DBEvent*& dbei)
}
if (msglenW > 0 && msglenW <= msglen) {
- char* utf8str = Utf8EncodeW((WCHAR*)&dbei->blob[ msglen ]);
+ char* utf8str = Utf8EncodeW((WCHAR*)&dbei->blob[msglen]);
if (utf8str == NULL)
return;
- dbei->cbBlob = (DWORD)strlen(utf8str)+1;
+ dbei->cbBlob = (DWORD)strlen(utf8str) + 1;
dbei->flags |= DBEF_UTF;
- if (offsetof(DBEvent,blob)+dbei->cbBlob > memsize) {
- memsize = offsetof(DBEvent,blob)+dbei->cbBlob;
+ if (offsetof(DBEvent, blob) + dbei->cbBlob > memsize) {
+ memsize = offsetof(DBEvent, blob) + dbei->cbBlob;
memblock = (DBEvent*)realloc(memblock, memsize);
dbei = memblock;
}
memcpy(&dbei->blob, utf8str, dbei->cbBlob);
mir_free(utf8str);
-} }
+ }
+}
-void CDb3Base::WriteOfsNextToPrevious(DWORD ofsPrev,DBContact *dbc,DWORD ofsNext)
+void CDb3Base::WriteOfsNextToPrevious(DWORD ofsPrev, DBContact *dbc, DWORD ofsNext)
{
if (ofsPrev)
- WriteSegment(ofsPrev+offsetof(DBEvent,ofsNext),&ofsNext,sizeof(DWORD));
+ WriteSegment(ofsPrev + offsetof(DBEvent, ofsNext), &ofsNext, sizeof(DWORD));
else
dbc->ofsFirstEvent = ofsNext;
}
-void CDb3Base::FinishUp(DWORD ofsLast,DBContact *dbc)
+void CDb3Base::FinishUp(DWORD ofsLast, DBContact *dbc)
{
- WriteOfsNextToPrevious(ofsLast,dbc,0);
+ WriteOfsNextToPrevious(ofsLast, dbc, 0);
if (eventCount != dbc->eventCount)
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event count marked wrongly: correcting"));
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Event count marked wrongly: correcting"));
dbc->eventCount = eventCount;
dbc->ofsLastEvent = ofsLast;
if (cb->bMarkRead) {
@@ -100,7 +103,7 @@ void CDb3Base::FinishUp(DWORD ofsLast,DBContact *dbc)
DWORD CDb3Base::WriteEvent(DBEvent *dbe)
{
- DWORD ofs = WriteSegment(WSOFS_END, dbe, offsetof(DBEvent,blob)+dbe->cbBlob);
+ DWORD ofs = WriteSegment(WSOFS_END, dbe, offsetof(DBEvent, blob) + dbe->cbBlob);
if (ofs == WS_ERROR) {
free(memblock);
memblock = NULL;
@@ -110,9 +113,9 @@ DWORD CDb3Base::WriteEvent(DBEvent *dbe)
return ofs;
}
-int CDb3Base::WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
+int CDb3Base::WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime)
{
- DBEvent *dbeNew,dbeOld;
+ DBEvent *dbeNew, dbeOld;
DBEvent *dbePrev = NULL;
DWORD ofsDestThis;
int isUnread = 0;
@@ -133,88 +136,90 @@ int CDb3Base::WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
dbc->ofsFirstUnreadEvent = 0;
dbc->timestampFirstUnread = 0;
return ERROR_NO_MORE_ITEMS;
- } }
+ }
+ }
if (ofsThisEvent == 0) {
- FinishUp(ofsDestPrevEvent,dbc);
+ FinishUp(ofsDestPrevEvent, dbc);
return ERROR_NO_MORE_ITEMS;
}
- if ( !SignatureValid(ofsThisEvent,DBEVENT_SIGNATURE)) {
+ if (!SignatureValid(ofsThisEvent, DBEVENT_SIGNATURE)) {
DWORD ofsNew = 0;
DWORD ofsTmp = dbc->ofsLastEvent;
if (!backLookup && ofsTmp) {
backLookup = 1;
- while ( SignatureValid(ofsTmp,DBEVENT_SIGNATURE)) {
- if (PeekSegment(ofsTmp,&dbeOld,sizeof(dbeOld)) != ERROR_SUCCESS)
+ while (SignatureValid(ofsTmp, DBEVENT_SIGNATURE)) {
+ if (PeekSegment(ofsTmp, &dbeOld, sizeof(dbeOld)) != ERROR_SUCCESS)
break;
ofsNew = ofsTmp;
ofsTmp = dbeOld.ofsPrev;
}
}
if (ofsNew) {
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event chain corrupted, trying to recover..."));
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Event chain corrupted, trying to recover..."));
ofsThisEvent = ofsNew;
}
else {
- cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Event chain corrupted, further entries ignored"));
- FinishUp(ofsDestPrevEvent,dbc);
+ cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Event chain corrupted, further entries ignored"));
+ FinishUp(ofsDestPrevEvent, dbc);
return ERROR_NO_MORE_ITEMS;
}
}
- if (PeekSegment(ofsThisEvent,&dbeOld,sizeof(dbeOld)) != ERROR_SUCCESS) {
- FinishUp(ofsDestPrevEvent,dbc);
+ if (PeekSegment(ofsThisEvent, &dbeOld, sizeof(dbeOld)) != ERROR_SUCCESS) {
+ FinishUp(ofsDestPrevEvent, dbc);
return ERROR_NO_MORE_ITEMS;
}
if (firstTime) {
- if (!(dbeOld.flags&DBEF_FIRST)) {
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("First event not marked as such: correcting"));
+ if (!(dbeOld.flags & DBEF_FIRST)) {
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("First event not marked as such: correcting"));
dbeOld.flags |= DBEF_FIRST;
}
dbeOld.ofsPrev = ofsContact;
lastTimestamp = dbeOld.timestamp;
}
- else if (dbeOld.flags&DBEF_FIRST) {
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event marked as first which is not: correcting"));
+ else if (dbeOld.flags & DBEF_FIRST) {
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Event marked as first which is not: correcting"));
dbeOld.flags &= ~DBEF_FIRST;
}
- if (dbeOld.flags & ~(DBEF_FIRST | DBEF_READ | DBEF_SENT | DBEF_RTL | DBEF_UTF)) {
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Extra flags found in event: removing"));
- dbeOld.flags &= (DBEF_FIRST | DBEF_READ | DBEF_SENT | DBEF_RTL | DBEF_UTF);
+ if (dbeOld.flags & ~DBEF_ALL) {
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Extra flags found in event: removing"));
+ dbeOld.flags &= DBEF_ALL;
}
if (!(dbeOld.flags & (DBEF_READ | DBEF_SENT))) {
if (cb->bMarkRead) dbeOld.flags |= DBEF_READ;
else if (ofsFirstUnread == 0) {
if (dbc->ofsFirstUnreadEvent != ofsThisEvent || dbc->timestampFirstUnread != dbeOld.timestamp)
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("First unread event marked wrong: fixing"));
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("First unread event marked wrong: fixing"));
isUnread = 1;
- } }
+ }
+ }
- if (dbeOld.cbBlob > 1024*1024 || dbeOld.cbBlob == 0) {
- cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Infeasibly large event blob: skipping"));
+ if (dbeOld.cbBlob > 1024 * 1024 || dbeOld.cbBlob == 0) {
+ cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Infeasibly large event blob: skipping"));
ofsThisEvent = dbeOld.ofsNext;
return ERROR_SUCCESS;
}
if (dbePrevEvent && dbeOld.timestamp == lastTimestamp) {
- int len = offsetof(DBEvent,blob)+dbePrevEvent->cbBlob;
+ int len = offsetof(DBEvent, blob) + dbePrevEvent->cbBlob;
dbePrev = (DBEvent*)malloc(len);
memcpy(dbePrev, dbePrevEvent, len);
}
- if (offsetof(DBEvent,blob)+dbeOld.cbBlob > memsize) {
- memsize = offsetof(DBEvent,blob)+dbeOld.cbBlob;
+ if (offsetof(DBEvent, blob) + dbeOld.cbBlob > memsize) {
+ memsize = offsetof(DBEvent, blob) + dbeOld.cbBlob;
memblock = (DBEvent*)realloc(memblock, memsize);
}
dbeNew = memblock;
- if (ReadSegment(ofsThisEvent,dbeNew,offsetof(DBEvent,blob)+dbeOld.cbBlob) != ERROR_SUCCESS) {
- FinishUp(ofsDestPrevEvent,dbc);
+ if (ReadSegment(ofsThisEvent, dbeNew, offsetof(DBEvent, blob) + dbeOld.cbBlob) != ERROR_SUCCESS) {
+ FinishUp(ofsDestPrevEvent, dbc);
return ERROR_NO_MORE_ITEMS;
}
@@ -224,7 +229,7 @@ int CDb3Base::WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
}
if (!firstTime && dbeOld.ofsPrev != ofsPrevEvent)
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event not backlinked correctly: fixing"));
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Event not backlinked correctly: fixing"));
dbeNew->flags = dbeOld.flags;
dbeNew->ofsPrev = ofsDestPrevEvent;
@@ -244,12 +249,12 @@ int CDb3Base::WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
if (dbePrev) {
if (dbePrev->cbBlob == dbeNew->cbBlob &&
- dbePrev->ofsModuleName == dbeNew->ofsModuleName &&
- dbePrev->eventType == dbeNew->eventType &&
- (dbePrev->flags & DBEF_SENT) == (dbeNew->flags & DBEF_SENT) &&
+ dbePrev->ofsModuleName == dbeNew->ofsModuleName &&
+ dbePrev->eventType == dbeNew->eventType &&
+ (dbePrev->flags & DBEF_SENT) == (dbeNew->flags & DBEF_SENT) &&
!memcmp(dbePrev->blob, dbeNew->blob, dbeNew->cbBlob)
) {
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Duplicate event was found: skipping"));
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Duplicate event was found: skipping"));
if (dbc->eventCount)
dbc->eventCount--;
free(dbePrev);
@@ -260,37 +265,31 @@ int CDb3Base::WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
}
free(dbePrev);
}
- else if (!firstTime && dbeNew->timestamp < lastTimestamp)
- {
+ else if (!firstTime && dbeNew->timestamp < lastTimestamp) {
DWORD found = 0;
DBEvent dbeTmp;
DWORD ofsTmp;
- if (cb->bCheckOnly)
- {
- if (!cb->bAggressive)
- {
+ if (cb->bCheckOnly) {
+ if (!cb->bAggressive) {
ofsTmp = dbeOld.ofsPrev;
- while(PeekSegment(ofsTmp,&dbeTmp,sizeof(dbeTmp)) == ERROR_SUCCESS)
- {
+ while (PeekSegment(ofsTmp, &dbeTmp, sizeof(dbeTmp)) == ERROR_SUCCESS) {
if (dbeTmp.ofsPrev == ofsContact) {
- found = 1;
- break;
+ found = 1;
+ break;
}
if (dbeTmp.timestamp < dbeNew->timestamp) {
- found = 2;
- break;
+ found = 2;
+ break;
}
ofsTmp = dbeTmp.ofsPrev;
}
}
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event position in chain is not correct"));
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Event position in chain is not correct"));
}
- else
- {
+ else {
ofsTmp = ofsDestPrevEvent;
- while(ReadWrittenSegment(ofsTmp,&dbeTmp,sizeof(dbeTmp)) == ERROR_SUCCESS)
- {
+ while (ReadWrittenSegment(ofsTmp, &dbeTmp, sizeof(dbeTmp)) == ERROR_SUCCESS) {
if (dbeTmp.ofsPrev == ofsContact) {
found = 1;
break;
@@ -302,9 +301,9 @@ int CDb3Base::WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
ofsTmp = dbeTmp.ofsPrev;
}
if (found)
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event position in chain is not correct: fixing"));
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Event position in chain is not correct: fixing"));
else
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event position in chain is not correct: unable to fix"));
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Event position in chain is not correct: unable to fix"));
}
// insert before FIRST
@@ -317,16 +316,16 @@ int CDb3Base::WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
if (!ofsDestThis)
return ERROR_HANDLE_DISK_FULL;
- if (isUnread && timestampFirstUnread >= dbeNew->timestamp) {
+ if (isUnread && timestampFirstUnread >= dbeNew->timestamp) {
ofsFirstUnread = ofsDestThis;
timestampFirstUnread = dbeNew->timestamp;
}
// fix first event
- WriteOfsNextToPrevious(0,dbc,ofsDestThis);
+ WriteOfsNextToPrevious(0, dbc, ofsDestThis);
// fix next event
- WriteSegment(dbeNew->ofsNext+offsetof(DBEvent,ofsPrev),&ofsDestThis,sizeof(DWORD));
- dbeTmp.flags &= ~DBEF_FIRST;
- WriteSegment(dbeNew->ofsNext+offsetof(DBEvent,flags),&dbeTmp.flags,sizeof(DWORD));
+ WriteSegment(dbeNew->ofsNext + offsetof(DBEvent, ofsPrev), &ofsDestThis, sizeof(DWORD));
+ dbeTmp.flags &= ~DBEF_FIRST;
+ WriteSegment(dbeNew->ofsNext + offsetof(DBEvent, flags), &dbeTmp.flags, sizeof(DWORD));
}
else if (found == 2 && !cb->bCheckOnly) {
@@ -337,14 +336,14 @@ int CDb3Base::WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
if (!ofsDestThis)
return ERROR_HANDLE_DISK_FULL;
- if (isUnread && timestampFirstUnread >= dbeNew->timestamp) {
+ if (isUnread && timestampFirstUnread >= dbeNew->timestamp) {
ofsFirstUnread = ofsDestThis;
timestampFirstUnread = dbeNew->timestamp;
}
// fix previous event
- WriteOfsNextToPrevious(dbeNew->ofsPrev,dbc,ofsDestThis);
+ WriteOfsNextToPrevious(dbeNew->ofsPrev, dbc, ofsDestThis);
// fix next event
- WriteSegment(dbeNew->ofsNext+offsetof(DBEvent,ofsPrev),&ofsDestThis,sizeof(DWORD));
+ WriteSegment(dbeNew->ofsNext + offsetof(DBEvent, ofsPrev), &ofsDestThis, sizeof(DWORD));
}
if (found) {
@@ -369,7 +368,7 @@ int CDb3Base::WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
}
eventCount++;
- WriteOfsNextToPrevious(ofsDestPrevEvent,dbc,ofsDestThis);
+ WriteOfsNextToPrevious(ofsDestPrevEvent, dbc, ofsDestThis);
ofsDestPrevEvent = ofsDestThis;
ofsPrevEvent = ofsThisEvent;
diff --git a/plugins/Db3x_mmap/src/dbtool/finaltasks.cpp b/plugins/Db3x_mmap/src/dbtool/finaltasks.cpp
index a307c0b9fb..a7f9c8ef46 100644
--- a/plugins/Db3x_mmap/src/dbtool/finaltasks.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/finaltasks.cpp
@@ -16,14 +16,15 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+
#include "..\commonheaders.h"
int CDb3Base::WorkFinalTasks(int firstTime)
{
FreeModuleChain();
- cb->pfnAddLogMessage(STATUS_MESSAGE,TranslateT("Processing final tasks"));
+ cb->pfnAddLogMessage(STATUS_MESSAGE, TranslateT("Processing final tasks"));
m_dbHeader.slackSpace = 0;
- if (WriteSegment(0,&m_dbHeader,sizeof(m_dbHeader)) == WS_ERROR)
+ if (WriteSegment(0, &m_dbHeader, sizeof(m_dbHeader)) == WS_ERROR)
return ERROR_WRITE_FAULT;
if (m_hDbFile) {
diff --git a/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp b/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp
index 6258f59c16..2d9dfae04c 100644
--- a/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp
@@ -16,18 +16,20 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+
#include "..\commonheaders.h"
int CDb3Base::WorkInitialCheckHeaders()
{
if (memcmp(m_dbHeader.signature, &dbSignatureU, sizeof(m_dbHeader.signature)) &&
+ memcmp(m_dbHeader.signature, &dbSignatureE, sizeof(m_dbHeader.signature)) &&
memcmp(m_dbHeader.signature, &dbSignatureIM, sizeof(m_dbHeader.signature)))
{
- cb->pfnAddLogMessage(STATUS_FATAL,TranslateT("Database signature is corrupted, automatic repair is impossible"));
+ cb->pfnAddLogMessage(STATUS_FATAL, TranslateT("Database signature is corrupted, automatic repair is impossible"));
return ERROR_BAD_FORMAT;
}
if (m_dbHeader.version != DB_OLD_VERSION && m_dbHeader.version != DB_THIS_VERSION) {
- cb->pfnAddLogMessage(STATUS_FATAL,TranslateT("Database is marked as belonging to an unknown version of Miranda"));
+ cb->pfnAddLogMessage(STATUS_FATAL, TranslateT("Database is marked as belonging to an unknown version of Miranda"));
return ERROR_BAD_FORMAT;
}
return ERROR_SUCCESS;
@@ -35,10 +37,10 @@ int CDb3Base::WorkInitialCheckHeaders()
int CDb3Base::WorkInitialChecks(int firstTime)
{
- sourceFileSize = GetFileSize(m_hDbFile,NULL);
+ sourceFileSize = GetFileSize(m_hDbFile, NULL);
if (sourceFileSize == 0) {
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Database is newly created and has no data to process"));
- cb->pfnAddLogMessage(STATUS_SUCCESS,TranslateT("Processing completed successfully"));
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Database is newly created and has no data to process"));
+ cb->pfnAddLogMessage(STATUS_SUCCESS, TranslateT("Processing completed successfully"));
return ERROR_INVALID_DATA;
}
@@ -50,21 +52,21 @@ int CDb3Base::WorkInitialChecks(int firstTime)
if (m_hMap)
m_pDbCache = (BYTE*)MapViewOfFile(m_hMap, cb->bAggressive ? FILE_MAP_COPY : FILE_MAP_READ, 0, 0, 0);
else {
- cb->pfnAddLogMessage(STATUS_FATAL,TranslateT("Can't create file mapping (%u)"),GetLastError());
+ cb->pfnAddLogMessage(STATUS_FATAL, TranslateT("Can't create file mapping (%u)"), GetLastError());
return ERROR_ACCESS_DENIED;
}
if (!m_pDbCache) {
- cb->pfnAddLogMessage(STATUS_FATAL,TranslateT("Can't create map view of file (%u)"),GetLastError());
+ cb->pfnAddLogMessage(STATUS_FATAL, TranslateT("Can't create map view of file (%u)"), GetLastError());
return ERROR_ACCESS_DENIED;
}
- if (ReadSegment(0,&m_dbHeader,sizeof(m_dbHeader)) != ERROR_SUCCESS)
+ if (ReadSegment(0, &m_dbHeader, sizeof(m_dbHeader)) != ERROR_SUCCESS)
return ERROR_READ_FAULT;
- if (WriteSegment(0,&m_dbHeader,sizeof(m_dbHeader)) == WS_ERROR)
+ if (WriteSegment(0, &m_dbHeader, sizeof(m_dbHeader)) == WS_ERROR)
return ERROR_HANDLE_DISK_FULL;
- cb->spaceUsed = m_dbHeader.ofsFileEnd-m_dbHeader.slackSpace;
+ cb->spaceUsed = m_dbHeader.ofsFileEnd - m_dbHeader.slackSpace;
m_dbHeader.ofsFileEnd = sizeof(m_dbHeader);
return ERROR_NO_MORE_ITEMS;
}
diff --git a/plugins/Db3x_mmap/src/dbtool/modulechain.cpp b/plugins/Db3x_mmap/src/dbtool/modulechain.cpp
index 0326166d7f..c846455474 100644
--- a/plugins/Db3x_mmap/src/dbtool/modulechain.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/modulechain.cpp
@@ -32,10 +32,10 @@ static int last_mod = 0;
int CDb3Base::WorkModuleChain(int firstTime)
{
- DBModuleName moduleName,*newModName;
+ DBModuleName moduleName, *newModName;
if (firstTime) {
- cb->pfnAddLogMessage(STATUS_MESSAGE,TranslateT("Processing module name chain"));
+ cb->pfnAddLogMessage(STATUS_MESSAGE, TranslateT("Processing module name chain"));
modChainCount = 0;
last_mod = 0;
free(modChain);
@@ -43,93 +43,90 @@ int CDb3Base::WorkModuleChain(int firstTime)
phase = 0;
ofsCurrent = m_dbHeader.ofsFirstModuleName;
}
- switch(phase) {
- case 0:
- if (ofsCurrent == 0) {
- phase++;
- return ERROR_SUCCESS;
- }
- if (!SignatureValid(ofsCurrent,DBMODULENAME_SIGNATURE)) {
- cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Module chain corrupted, further entries ignored"));
- phase++;
- return ERROR_SUCCESS;
- }
- if (PeekSegment(ofsCurrent,&moduleName,offsetof(DBModuleName,name)) != ERROR_SUCCESS) {
- phase++;
- return ERROR_SUCCESS;
- }
- modChain = (ModChainEntry*)realloc(modChain,sizeof(ModChainEntry)*++modChainCount);
-
- modChain[modChainCount-1].ofsOld = ofsCurrent;
- modChain[modChainCount-1].size = offsetof(DBModuleName,name)+moduleName.cbName;
- modChain[modChainCount-1].ofsNew = 0;
-
- if (moduleName.cbName)
- PeekSegment(ofsCurrent+offsetof(DBModuleName,name),&modChain[modChainCount-1].name,moduleName.cbName);
- modChain[modChainCount-1].name[moduleName.cbName] = 0;
- ofsCurrent = moduleName.ofsNext;
- break;
- case 1:
- ofsLast = 0;
- iCurrentModName = 0;
- m_dbHeader.ofsFirstModuleName = 0;
+
+ switch (phase) {
+ case 0:
+ if (ofsCurrent == 0) {
+ phase++;
+ return ERROR_SUCCESS;
+ }
+ if (!SignatureValid(ofsCurrent, DBMODULENAME_SIGNATURE)) {
+ cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Module chain corrupted, further entries ignored"));
+ phase++;
+ return ERROR_SUCCESS;
+ }
+ if (PeekSegment(ofsCurrent, &moduleName, offsetof(DBModuleName, name)) != ERROR_SUCCESS) {
phase++;
- case 2:
- if (iCurrentModName >= modChainCount) {
- DWORD dw = 0;
- if (ofsLast) WriteSegment(ofsLast+offsetof(DBModuleName,ofsNext),&dw,sizeof(DWORD));
+ return ERROR_SUCCESS;
+ }
+ modChain = (ModChainEntry*)realloc(modChain, sizeof(ModChainEntry)*++modChainCount);
+
+ modChain[modChainCount - 1].ofsOld = ofsCurrent;
+ modChain[modChainCount - 1].size = offsetof(DBModuleName, name) + moduleName.cbName;
+ modChain[modChainCount - 1].ofsNew = 0;
+
+ if (moduleName.cbName)
+ PeekSegment(ofsCurrent + offsetof(DBModuleName, name), &modChain[modChainCount - 1].name, moduleName.cbName);
+ modChain[modChainCount - 1].name[moduleName.cbName] = 0;
+ ofsCurrent = moduleName.ofsNext;
+ break;
+ case 1:
+ ofsLast = 0;
+ iCurrentModName = 0;
+ m_dbHeader.ofsFirstModuleName = 0;
+ phase++;
+ case 2:
+ if (iCurrentModName >= modChainCount) {
+ DWORD dw = 0;
+ if (ofsLast) WriteSegment(ofsLast + offsetof(DBModuleName, ofsNext), &dw, sizeof(DWORD));
+ return ERROR_NO_MORE_ITEMS;
+ }
+ if (modChain[iCurrentModName].ofsNew == 0) {
+ newModName = (DBModuleName*)_alloca(modChain[iCurrentModName].size);
+ if (ReadSegment(modChain[iCurrentModName].ofsOld, newModName, modChain[iCurrentModName].size) != ERROR_SUCCESS)
return ERROR_NO_MORE_ITEMS;
- }
- if (modChain[iCurrentModName].ofsNew == 0) {
- newModName = (DBModuleName*)_alloca(modChain[iCurrentModName].size);
- if (ReadSegment(modChain[iCurrentModName].ofsOld,newModName,modChain[iCurrentModName].size) != ERROR_SUCCESS)
- return ERROR_NO_MORE_ITEMS;
- if ((modChain[iCurrentModName].ofsNew = WriteSegment(WSOFS_END,newModName,modChain[iCurrentModName].size)) == WS_ERROR)
- return ERROR_HANDLE_DISK_FULL;
- { // check duplicated modulenames
- int i, n = 0;
- for (i = iCurrentModName+1;i<modChainCount;i++)
- if (!strcmp(modChain[i].name, modChain[iCurrentModName].name)) {
- modChain[i].ofsNew = modChain[iCurrentModName].ofsNew;
- n++;
- }
- if (n) {
- TCHAR *pszModuleName;
-
- TCHAR szModuleName[257];
- MultiByteToWideChar(CP_ACP, 0, modChain[iCurrentModName].name, -1, szModuleName, sizeof(szModuleName) / sizeof(TCHAR));
- pszModuleName = szModuleName;
-
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Module name '%s' is not unique: %d duplicates found"), pszModuleName, n);
- }
+ if ((modChain[iCurrentModName].ofsNew = WriteSegment(WSOFS_END, newModName, modChain[iCurrentModName].size)) == WS_ERROR)
+ return ERROR_HANDLE_DISK_FULL;
+
+ // check duplicated modulenames
+ int i, n = 0;
+ for (i = iCurrentModName + 1; i < modChainCount; i++)
+ if (!strcmp(modChain[i].name, modChain[iCurrentModName].name)) {
+ modChain[i].ofsNew = modChain[iCurrentModName].ofsNew;
+ n++;
}
- if (iCurrentModName == 0)
- m_dbHeader.ofsFirstModuleName = modChain[iCurrentModName].ofsNew;
- else
- if (WriteSegment(ofsLast+offsetof(DBModuleName,ofsNext),&modChain[iCurrentModName].ofsNew,sizeof(DWORD)) == WS_ERROR)
- return ERROR_HANDLE_DISK_FULL;
- ofsLast = modChain[iCurrentModName].ofsNew;
+ if (n) {
+ TCHAR szModuleName[257];
+ MultiByteToWideChar(CP_ACP, 0, modChain[iCurrentModName].name, -1, szModuleName, SIZEOF(szModuleName));
+ TCHAR *pszModuleName = szModuleName;
+
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Module name '%s' is not unique: %d duplicates found"), pszModuleName, n);
}
- iCurrentModName++;
- break;
+
+ if (iCurrentModName == 0)
+ m_dbHeader.ofsFirstModuleName = modChain[iCurrentModName].ofsNew;
+ else if (WriteSegment(ofsLast + offsetof(DBModuleName, ofsNext), &modChain[iCurrentModName].ofsNew, sizeof(DWORD)) == WS_ERROR)
+ return ERROR_HANDLE_DISK_FULL;
+ ofsLast = modChain[iCurrentModName].ofsNew;
+ }
+ iCurrentModName++;
+ break;
}
return ERROR_SUCCESS;
}
DWORD CDb3Base::ConvertModuleNameOfs(DWORD ofsOld)
{
- int i;
-
if (modChain[last_mod].ofsOld == ofsOld)
return modChain[last_mod].ofsNew;
- for (i = 0;i<modChainCount;i++)
+ for (int i = 0; i < modChainCount; i++)
if (modChain[i].ofsOld == ofsOld) {
last_mod = i;
return modChain[last_mod].ofsNew;
}
- cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Invalid module name offset, skipping data"));
+ cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Invalid module name offset, skipping data"));
return 0;
}
diff --git a/plugins/Db3x_mmap/src/dbtool/settingschain.cpp b/plugins/Db3x_mmap/src/dbtool/settingschain.cpp
index aaa52d9e22..1311b58661 100644
--- a/plugins/Db3x_mmap/src/dbtool/settingschain.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/settingschain.cpp
@@ -19,11 +19,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "..\commonheaders.h"
-static DWORD ofsThisSettings,ofsDestPrevSettings;
+static DWORD ofsThisSettings, ofsDestPrevSettings;
-int CDb3Base::WorkSettingsChain(DWORD ofsContact,DBContact *dbc,int firstTime)
+int CDb3Base::WorkSettingsChain(DWORD ofsContact, DBContact *dbc, int firstTime)
{
- DBContactSettings *dbcsNew,dbcsOld;
DWORD ofsDestThis;
int ret;
@@ -35,39 +34,44 @@ int CDb3Base::WorkSettingsChain(DWORD ofsContact,DBContact *dbc,int firstTime)
if (ofsThisSettings == 0)
return ERROR_NO_MORE_ITEMS;
- if (!SignatureValid(ofsThisSettings,DBCONTACTSETTINGS_SIGNATURE)) {
- cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Settings chain corrupted, further entries ignored"));
+ if (!SignatureValid(ofsThisSettings, DBCONTACTSETTINGS_SIGNATURE)) {
+ cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Settings chain corrupted, further entries ignored"));
return ERROR_NO_MORE_ITEMS;
}
- if (PeekSegment(ofsThisSettings,&dbcsOld,sizeof(dbcsOld)) != ERROR_SUCCESS)
+ DBContactSettings dbcsOld;
+ if (PeekSegment(ofsThisSettings, &dbcsOld, sizeof(dbcsOld)) != ERROR_SUCCESS)
return ERROR_NO_MORE_ITEMS;
- if (dbcsOld.cbBlob>256*1024 || dbcsOld.cbBlob == 0) {
- cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Infeasibly large settings blob: skipping"));
+
+ if (dbcsOld.cbBlob > 256 * 1024 || dbcsOld.cbBlob == 0) {
+ cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Infeasibly large settings blob: skipping"));
ofsThisSettings = dbcsOld.ofsNext;
return ERROR_SUCCESS;
}
- dbcsNew = (DBContactSettings*)_alloca(offsetof(DBContactSettings,blob)+dbcsOld.cbBlob);
- if ((ret = ReadSegment(ofsThisSettings,dbcsNew,offsetof(DBContactSettings,blob)+dbcsOld.cbBlob)) != ERROR_SUCCESS) {
- if (ret != ERROR_HANDLE_EOF) { //eof is OK because blank space at the end doesn't matter
+
+ DBContactSettings *dbcsNew = (DBContactSettings*)_alloca(offsetof(DBContactSettings, blob) + dbcsOld.cbBlob);
+ if ((ret = ReadSegment(ofsThisSettings, dbcsNew, offsetof(DBContactSettings, blob) + dbcsOld.cbBlob)) != ERROR_SUCCESS)
+ if (ret != ERROR_HANDLE_EOF) //eof is OK because blank space at the end doesn't matter
return ERROR_NO_MORE_ITEMS;
- }
- }
+
if ((dbcsNew->ofsModuleName = ConvertModuleNameOfs(dbcsOld.ofsModuleName)) == 0) {
ofsThisSettings = dbcsOld.ofsNext;
return ERROR_SUCCESS;
}
+
if (dbcsNew->blob[0] == 0) {
- cb->pfnAddLogMessage(STATUS_MESSAGE,TranslateT("Empty settings group at %08X: skipping"),ofsThisSettings);
+ cb->pfnAddLogMessage(STATUS_MESSAGE, TranslateT("Empty settings group at %08X: skipping"), ofsThisSettings);
ofsThisSettings = dbcsOld.ofsNext;
return ERROR_SUCCESS;
}
dbcsNew->ofsNext = 0;
//TODO? validate all settings in blob/compact if necessary
- if ((ofsDestThis = WriteSegment(WSOFS_END,dbcsNew,offsetof(DBContactSettings,blob)+dbcsNew->cbBlob)) == WS_ERROR) {
+ if ((ofsDestThis = WriteSegment(WSOFS_END, dbcsNew, offsetof(DBContactSettings, blob) + dbcsNew->cbBlob)) == WS_ERROR)
return ERROR_HANDLE_DISK_FULL;
- }
- if (ofsDestPrevSettings) WriteSegment(ofsDestPrevSettings+offsetof(DBContactSettings,ofsNext),&ofsDestThis,sizeof(DWORD));
- else dbc->ofsFirstSettings = ofsDestThis;
+
+ if (ofsDestPrevSettings)
+ WriteSegment(ofsDestPrevSettings + offsetof(DBContactSettings, ofsNext), &ofsDestThis, sizeof(DWORD));
+ else
+ dbc->ofsFirstSettings = ofsDestThis;
ofsDestPrevSettings = ofsDestThis;
ofsThisSettings = dbcsOld.ofsNext;
return ERROR_SUCCESS;
diff --git a/plugins/Db3x_mmap/src/dbtool/user.cpp b/plugins/Db3x_mmap/src/dbtool/user.cpp
index ac200d2409..7b56e29c06 100644
--- a/plugins/Db3x_mmap/src/dbtool/user.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/user.cpp
@@ -28,32 +28,32 @@ int CDb3Base::WorkUser(int firstTime)
int first = 0;
if (firstTime) {
- cb->pfnAddLogMessage(STATUS_MESSAGE,TranslateT("Processing user data"));
- if ( !SignatureValid(m_dbHeader.ofsUser, DBCONTACT_SIGNATURE)) {
- cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("User corrupted, this could cause major problems"));
+ cb->pfnAddLogMessage(STATUS_MESSAGE, TranslateT("Processing user data"));
+ if (!SignatureValid(m_dbHeader.ofsUser, DBCONTACT_SIGNATURE)) {
+ cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("User corrupted, this could cause major problems"));
return ERROR_NO_MORE_ITEMS;
}
- if ( ReadSegment(m_dbHeader.ofsUser,&user,sizeof(DBContact)) != ERROR_SUCCESS)
+ if (ReadSegment(m_dbHeader.ofsUser, &user, sizeof(DBContact)) != ERROR_SUCCESS)
return ERROR_NO_MORE_ITEMS;
if (user.ofsNext) {
- cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("More than one user contact: keeping only first"));
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("More than one user contact: keeping only first"));
user.ofsNext = 0;
}
- if ((ofsUser = WriteSegment(WSOFS_END,&user,sizeof(DBContact))) == WS_ERROR)
+ if ((ofsUser = WriteSegment(WSOFS_END, &user, sizeof(DBContact))) == WS_ERROR)
return ERROR_HANDLE_DISK_FULL;
m_dbHeader.ofsUser = ofsUser;
phase = 0;
first = 1;
}
-
+
int ret;
- switch(phase) {
+ switch (phase) {
case 0:
- ret = WorkSettingsChain(ofsUser,&user,first);
+ ret = WorkSettingsChain(ofsUser, &user, first);
if (ret == ERROR_NO_MORE_ITEMS) {
phase++; first = 1;
}
@@ -61,13 +61,14 @@ int CDb3Base::WorkUser(int firstTime)
else break;
case 1:
- ret = WorkEventChain(ofsUser,&user,first);
+ ret = WorkEventChain(ofsUser, &user, first);
if (ret == ERROR_NO_MORE_ITEMS) {
- if (WriteSegment(ofsUser,&user,sizeof(DBContact)) == WS_ERROR)
+ if (WriteSegment(ofsUser, &user, sizeof(DBContact)) == WS_ERROR)
return ERROR_HANDLE_DISK_FULL;
return ERROR_NO_MORE_ITEMS;
}
- else if (ret) return ret;
+ else if (ret)
+ return ret;
break;
}
return ERROR_SUCCESS;
diff --git a/plugins/Db3x_mmap/src/ui.cpp b/plugins/Db3x_mmap/src/ui.cpp
index a8fa3f787a..73ec799079 100644
--- a/plugins/Db3x_mmap/src/ui.cpp
+++ b/plugins/Db3x_mmap/src/ui.cpp
@@ -266,8 +266,11 @@ INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
case WM_NOTIFY:
if (((LPNMHDR)lParam)->code == PSN_APPLY) {
- if (IsDlgButtonChecked(hwndDlg, IDC_TOTAL) == (BOOL)db->isEncrypted())
- break;
+ if (IsDlgButtonChecked(hwndDlg, IDC_TOTAL) != (BOOL)db->isEncrypted()) {
+ db->ToggleEncryption();
+ CheckRadioButton(hwndDlg, IDC_STANDARD, IDC_TOTAL, IDC_STANDARD + db->isEncrypted());
+ }
+ break;
}
break;
}