summaryrefslogtreecommitdiff
path: root/plugins/Db3x_mmap/src/dbtool/eventchain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Db3x_mmap/src/dbtool/eventchain.cpp')
-rw-r--r--plugins/Db3x_mmap/src/dbtool/eventchain.cpp153
1 files changed, 76 insertions, 77 deletions
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;