summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-02-25 19:51:01 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-02-25 19:51:01 +0000
commitd84c40216b5e60224eb365f633b5f142d459fc9e (patch)
treec64402a3813b8c452f8bb80bb9c13bf5b6529e18 /plugins
parentf8ad8c89b9b308a79ad1f4081a478338eb504c26 (diff)
merge from branch
git-svn-id: http://svn.miranda-ng.org/main/trunk@8274 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Db3x_mmap/src/database.cpp4
-rw-r--r--plugins/Db3x_mmap/src/dbcache.cpp41
-rw-r--r--plugins/Db3x_mmap/src/dbcontacts.cpp2
-rw-r--r--plugins/Db3x_mmap/src/dbcrypt.cpp4
-rw-r--r--plugins/Db3x_mmap/src/dbevents.cpp92
-rw-r--r--plugins/Db3x_mmap/src/dbheaders.cpp15
-rw-r--r--plugins/Db3x_mmap/src/dbintf.cpp11
-rw-r--r--plugins/Db3x_mmap/src/dbintf.h177
-rw-r--r--plugins/Db3x_mmap/src/dbmodulechain.cpp6
-rw-r--r--plugins/Db3x_mmap/src/dbtool/eventchain.cpp37
-rw-r--r--plugins/Db3x_mmap/src/dbtool/initialchecks.cpp2
-rw-r--r--plugins/Db3x_mmap/src/dbtool/modulechain.cpp6
-rw-r--r--plugins/Db3x_mmap/src/version.h2
13 files changed, 239 insertions, 160 deletions
diff --git a/plugins/Db3x_mmap/src/database.cpp b/plugins/Db3x_mmap/src/database.cpp
index 723ddea5a7..47b12b2c70 100644
--- a/plugins/Db3x_mmap/src/database.cpp
+++ b/plugins/Db3x_mmap/src/database.cpp
@@ -32,6 +32,8 @@ DWORD CDb3Mmap::CreateNewSpace(int bytes)
{
DWORD ofsNew = m_dbHeader.ofsFileEnd;
m_dbHeader.ofsFileEnd += bytes;
+ if (m_dbHeader.ofsFileEnd > m_dwFileSize)
+ ReMap(m_dbHeader.ofsFileEnd - m_dwFileSize);
DBWrite(0, &m_dbHeader, sizeof(m_dbHeader));
log2("newspace %d@%08x", bytes, ofsNew);
return ofsNew;
@@ -65,7 +67,7 @@ DWORD CDb3Mmap::ReallocSpace(DWORD ofs, int oldSize, int newSize)
}
else {
ofsNew = CreateNewSpace(newSize);
- DBMoveChunk(ofsNew,ofs,oldSize);
+ DBMoveChunk(ofsNew, ofs, oldSize);
DeleteSpace(ofs,oldSize);
}
return ofsNew;
diff --git a/plugins/Db3x_mmap/src/dbcache.cpp b/plugins/Db3x_mmap/src/dbcache.cpp
index c0bf00e738..4ea4c71985 100644
--- a/plugins/Db3x_mmap/src/dbcache.cpp
+++ b/plugins/Db3x_mmap/src/dbcache.cpp
@@ -34,27 +34,27 @@ void CDb3Mmap::Map()
dwProtectMode = PAGE_READWRITE, dwAccess = FILE_MAP_ALL_ACCESS;
m_hMap = CreateFileMapping(m_hDbFile, NULL, dwProtectMode, 0, m_dwFileSize, NULL);
- if (m_hMap) {
+ if (m_hMap) {
m_pDbCache = (PBYTE)MapViewOfFile(m_hMap, dwAccess, 0, 0, 0);
if (!m_pDbCache)
- DatabaseCorruption( _T("%s (MapViewOfFile failed. Code: %d)"));
+ DatabaseCorruption(_T("%s (MapViewOfFile failed. Code: %d)"));
}
- else DatabaseCorruption( _T("%s (CreateFileMapping failed. Code: %d)"));
+ else DatabaseCorruption(_T("%s (CreateFileMapping failed. Code: %d)"));
}
void CDb3Mmap::ReMap(DWORD needed)
{
- KillTimer(NULL,m_flushBuffersTimerId);
+ KillTimer(NULL, m_flushBuffersTimerId);
- log3("remapping %d + %d (file end: %d)",m_dwFileSize,needed,m_dbHeader.ofsFileEnd);
+ log3("remapping %d + %d (file end: %d)", m_dwFileSize, needed, m_dbHeader.ofsFileEnd);
if (needed > 0) {
if (needed > m_ChunkSize) {
if (needed + m_dwFileSize > m_dbHeader.ofsFileEnd + m_ChunkSize)
DatabaseCorruption(_T("%s (Too large increment)"));
else {
- DWORD x = m_dbHeader.ofsFileEnd/m_ChunkSize;
- m_dwFileSize = (x+1)*m_ChunkSize;
+ DWORD x = m_dbHeader.ofsFileEnd / m_ChunkSize;
+ m_dwFileSize = (x + 1)*m_ChunkSize;
}
}
else m_dwFileSize += m_ChunkSize;
@@ -71,15 +71,17 @@ void CDb3Mmap::DBMoveChunk(DWORD ofsDest, DWORD ofsSource, int bytes)
{
int x = 0;
//log3("move %d %08x->%08x",bytes,ofsSource,ofsDest);
- if (ofsDest+bytes > m_dwFileSize) ReMap(ofsDest+bytes-m_dwFileSize);
- if (ofsSource+bytes > m_dwFileSize) {
- x = ofsSource+bytes-m_dwFileSize;
+ if (ofsDest + bytes > m_dwFileSize)
+ ReMap(ofsDest + bytes - m_dwFileSize);
+
+ if (ofsSource + bytes > m_dwFileSize) {
+ x = ofsSource + bytes - m_dwFileSize;
log0("buggy move!");
}
if (x > 0)
- ZeroMemory(m_pDbCache+ofsDest+bytes-x, x);
+ ZeroMemory(m_pDbCache + ofsDest + bytes - x, x);
if (ofsSource < m_dwFileSize)
- MoveMemory(m_pDbCache+ofsDest,m_pDbCache+ofsSource, bytes-x);
+ MoveMemory(m_pDbCache + ofsDest, m_pDbCache + ofsSource, bytes - x);
logg();
}
@@ -90,19 +92,22 @@ PBYTE CDb3Mmap::DBRead(DWORD ofs, int bytesRequired, int *bytesAvail)
// buggy read
if (ofs >= m_dwFileSize) {
//log2("read from outside %d@%08x",bytesRequired,ofs);
- if (bytesAvail != NULL) *bytesAvail = m_ChunkSize;
+ if (bytesAvail != NULL)
+ *bytesAvail = m_ChunkSize;
return m_pNull;
}
//log3((ofs+bytesRequired > m_dwFileSize)?"read %d@%08x, only %d avaliable":"read %d@%08x",bytesRequired,ofs,m_dwFileSize-ofs);
- if (bytesAvail != NULL) *bytesAvail = m_dwFileSize - ofs;
- return m_pDbCache+ofs;
+ if (bytesAvail != NULL)
+ *bytesAvail = m_dwFileSize - ofs;
+ return m_pDbCache + ofs;
}
//we are assumed to be in a mutex here
void CDb3Mmap::DBWrite(DWORD ofs, PVOID pData, int bytes)
{
//log2("write %d@%08x",bytes,ofs);
- if (ofs+bytes > m_dwFileSize) ReMap(ofs+bytes-m_dwFileSize);
+ if (ofs+bytes > m_dwFileSize)
+ ReMap(ofs+bytes-m_dwFileSize);
MoveMemory(m_pDbCache+ofs,pData,bytes);
logg();
}
@@ -118,7 +123,7 @@ void CDb3Mmap::DBFill(DWORD ofs, int bytes)
static VOID CALLBACK DoBufferFlushTimerProc(HWND hwnd, UINT message, UINT_PTR idEvent, DWORD dwTime)
{
- for (int i=0; i < g_Dbs.getCount(); i++) {
+ for (int i = 0; i < g_Dbs.getCount(); i++) {
CDb3Mmap *db = g_Dbs[i];
if (db->m_flushBuffersTimerId != idEvent)
continue;
@@ -162,7 +167,7 @@ void CDb3Mmap::DBFlush(int setting)
int CDb3Mmap::InitMap(void)
{
- m_dwFileSize = GetFileSize(m_hDbFile, NULL);
+ m_dwFileSize = GetFileSize(m_hDbFile, NULL);
// Align to chunk
if (!m_bReadOnly) {
diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp
index 0f305a2532..576b19a4f8 100644
--- a/plugins/Db3x_mmap/src/dbcontacts.cpp
+++ b/plugins/Db3x_mmap/src/dbcontacts.cpp
@@ -235,7 +235,7 @@ void CDb3Mmap::FillContacts()
break;
DWORD dwContactID;
- if (m_dbHeader.version == DB_095_VERSION) {
+ if (m_dbHeader.version >= DB_095_VERSION) {
dwContactID = p->dwContactID;
if (dwContactID > m_dwMaxContactId)
m_dwMaxContactId = dwContactID + 1;
diff --git a/plugins/Db3x_mmap/src/dbcrypt.cpp b/plugins/Db3x_mmap/src/dbcrypt.cpp
index fcd4fd2017..48731212d7 100644
--- a/plugins/Db3x_mmap/src/dbcrypt.cpp
+++ b/plugins/Db3x_mmap/src/dbcrypt.cpp
@@ -411,8 +411,8 @@ void CDb3Mmap::ToggleEventsEncryption(MCONTACT contactID)
contact.ofsFirstEvent = ofsDest;
if (contact.ofsLastEvent == offset)
contact.ofsLastEvent = ofsDest;
- if (contact.ofsFirstUnreadEvent == offset)
- contact.ofsFirstUnreadEvent = ofsDest;
+ if (contact.ofsFirstUnread == offset)
+ contact.ofsFirstUnread = ofsDest;
evt.flags |= DBEF_ENCRYPTED;
}
diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp
index 2866dc6bc2..0c0294297b 100644
--- a/plugins/Db3x_mmap/src/dbevents.cpp
+++ b/plugins/Db3x_mmap/src/dbevents.cpp
@@ -44,7 +44,7 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
dbe.signature = DBEVENT_SIGNATURE;
dbe.timestamp = dbei->timestamp;
dbe.flags = dbei->flags;
- dbe.eventType = dbei->eventType;
+ dbe.wEventType = dbei->eventType;
dbe.cbBlob = dbei->cbBlob;
BYTE *pBlob = dbei->pBlob;
@@ -120,9 +120,9 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
dbc.eventCount++;
if (!(dbe.flags & (DBEF_READ | DBEF_SENT))) {
- if (dbe.timestamp < dbc.timestampFirstUnread || dbc.timestampFirstUnread == 0) {
- dbc.timestampFirstUnread = dbe.timestamp;
- dbc.ofsFirstUnreadEvent = ofsNew;
+ if (dbe.timestamp < dbc.tsFirstUnread || dbc.tsFirstUnread == 0) {
+ dbc.tsFirstUnread = dbe.timestamp;
+ dbc.ofsFirstUnread = ofsNew;
}
neednotify = true;
}
@@ -164,19 +164,19 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(MCONTACT contactID, HANDLE hDbEvent)
dbe = *(DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL);
//check if this was the first unread, if so, recalc the first unread
- if (dbc.ofsFirstUnreadEvent == (DWORD)hDbEvent) {
+ if (dbc.ofsFirstUnread == (DWORD)hDbEvent) {
DBEvent *dbeNext = &dbe;
for (;;) {
if (dbeNext->ofsNext == 0) {
- dbc.ofsFirstUnreadEvent = 0;
- dbc.timestampFirstUnread = 0;
+ dbc.ofsFirstUnread = 0;
+ dbc.tsFirstUnread = 0;
break;
}
DWORD ofsThis = dbeNext->ofsNext;
dbeNext = (DBEvent*)DBRead(ofsThis, sizeof(DBEvent), NULL);
if (!(dbeNext->flags & (DBEF_READ | DBEF_SENT))) {
- dbc.ofsFirstUnreadEvent = ofsThis;
- dbc.timestampFirstUnread = dbeNext->timestamp;
+ dbc.ofsFirstUnread = ofsThis;
+ dbc.tsFirstUnread = dbeNext->timestamp;
break;
}
}
@@ -243,7 +243,7 @@ STDMETHODIMP_(BOOL) CDb3Mmap::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
dbei->szModule = GetModuleNameByOfs(dbe->ofsModuleName);
dbei->timestamp = dbe->timestamp;
dbei->flags = dbe->flags;
- dbei->eventType = dbe->eventType;
+ dbei->eventType = dbe->wEventType;
int bytesToCopy = (dbei->cbBlob < dbe->cbBlob) ? dbei->cbBlob : dbe->cbBlob;
dbei->cbBlob = dbe->cbBlob;
if (bytesToCopy && dbei->pBlob) {
@@ -281,18 +281,18 @@ STDMETHODIMP_(BOOL) CDb3Mmap::MarkEventRead(MCONTACT contactID, HANDLE hDbEvent)
dbe->flags |= DBEF_READ;
DBWrite((DWORD)hDbEvent, dbe, sizeof(DBEvent));
BOOL ret = dbe->flags;
- if (dbc.ofsFirstUnreadEvent == (DWORD)hDbEvent) {
+ if (dbc.ofsFirstUnread == (DWORD)hDbEvent) {
for (;;) {
if (dbe->ofsNext == 0) {
- dbc.ofsFirstUnreadEvent = 0;
- dbc.timestampFirstUnread = 0;
+ dbc.ofsFirstUnread = 0;
+ dbc.tsFirstUnread = 0;
break;
}
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;
+ dbc.ofsFirstUnread = ofsThis;
+ dbc.tsFirstUnread = dbe->timestamp;
break;
}
}
@@ -309,13 +309,7 @@ STDMETHODIMP_(MCONTACT) CDb3Mmap::GetEventContact(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
DBEvent *dbe = (DBEvent*)DBRead((DWORD)hDbEvent, sizeof(DBEvent), NULL);
- if (dbe->signature != DBEVENT_SIGNATURE)
- return INVALID_CONTACT_ID;
-
- while (!(dbe->flags & DBEF_FIRST))
- dbe = (DBEvent*)DBRead(dbe->ofsPrev, sizeof(DBEvent), NULL);
-
- return dbe->ofsPrev;
+ return (dbe->signature != DBEVENT_SIGNATURE) ? INVALID_CONTACT_ID : dbe->contactID;
}
STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstEvent(MCONTACT contactID)
@@ -331,7 +325,7 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstUnreadEvent(MCONTACT contactID)
mir_cslock lck(m_csDbAccess);
DWORD ofsContact = GetContactOffset(contactID);
DBContact *dbc = (DBContact*)DBRead(ofsContact, sizeof(DBContact), NULL);
- return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsFirstUnreadEvent;
+ return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsFirstUnread;
}
STDMETHODIMP_(HANDLE) CDb3Mmap::FindLastEvent(MCONTACT contactID)
@@ -356,3 +350,55 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::FindPrevEvent(HANDLE hDbEvent)
if (dbe->signature != DBEVENT_SIGNATURE) return 0;
return (dbe->flags & DBEF_FIRST) ? 0 : (HANDLE)dbe->ofsPrev;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// events convertor for DB_095_1_VERSION
+
+void CDb3Mmap::ConvertContactEvents(DBContact *cc)
+{
+ mir_ptr<BYTE> pBlob((PBYTE)mir_alloc(65536));
+ DWORD ofsPrev = 0;
+
+ for (DWORD ofsEvent = cc->ofsFirstEvent; ofsEvent != 0;) {
+ DBEvent_094 pOld = *(DBEvent_094*)DBRead(ofsEvent, sizeof(DBEvent_094), NULL);
+ memcpy(pBlob, m_pDbCache + ofsEvent + offsetof(DBEvent_094, blob), pOld.cbBlob);
+
+ DWORD ofsNew = ReallocSpace(ofsEvent, offsetof(DBEvent_094, blob) + pOld.cbBlob, offsetof(DBEvent, blob) + pOld.cbBlob);
+ DBEvent *pNew = (DBEvent*)&m_pDbCache[ofsNew];
+ pNew->signature = pOld.signature;
+ pNew->contactID = cc->dwContactID;
+ memcpy(&pNew->ofsPrev, &pOld.ofsPrev, offsetof(DBEvent_094, blob) - sizeof(DWORD));
+ memcpy(&pNew->blob, pBlob, pNew->cbBlob);
+
+ if (ofsPrev == 0) // first event
+ cc->ofsFirstEvent = ofsNew, pNew->ofsPrev = 0;
+ else {
+ DBEvent *pPrev = (DBEvent*)&m_pDbCache[ofsPrev];
+ pPrev->ofsNext = ofsNew, pNew->ofsPrev = ofsPrev;
+ }
+
+ if (cc->ofsFirstUnread == ofsEvent)
+ cc->ofsFirstUnread = ofsNew;
+ if (cc->ofsLastEvent == ofsEvent)
+ cc->ofsLastEvent = ofsNew;
+
+ ofsPrev = ofsNew;
+ ofsEvent = pNew->ofsNext;
+ }
+}
+
+void CDb3Mmap::ConvertEvents()
+{
+ DBContact cc = *(DBContact*)DBRead(m_dbHeader.ofsUser, sizeof(DBContact), NULL);
+ ConvertContactEvents(&cc);
+ DBWrite(m_dbHeader.ofsUser, &cc, sizeof(cc));
+
+ for (DWORD dwOffset = m_dbHeader.ofsFirstContact; dwOffset != 0;) {
+ DBContact cc = *(DBContact*)DBRead(dwOffset, sizeof(DBContact), NULL);
+ ConvertContactEvents(&cc);
+ DBWrite(dwOffset, &cc, sizeof(cc));
+ dwOffset = cc.ofsNext;
+ }
+
+ FlushViewOfFile(m_pDbCache, 0);
+}
diff --git a/plugins/Db3x_mmap/src/dbheaders.cpp b/plugins/Db3x_mmap/src/dbheaders.cpp
index de8ce57bac..102fd56fac 100644
--- a/plugins/Db3x_mmap/src/dbheaders.cpp
+++ b/plugins/Db3x_mmap/src/dbheaders.cpp
@@ -31,12 +31,12 @@ int CDb3Mmap::CreateDbHeaders(const DBSignature& _sign)
CopyMemory(m_dbHeader.signature, &_sign, sizeof(m_dbHeader.signature));
- m_dbHeader.version = DB_095_VERSION;
+ m_dbHeader.version = DB_095_1_VERSION;
m_dbHeader.ofsFileEnd = sizeof(struct DBHeader);
m_dbHeader.slackSpace = 0;
m_dbHeader.contactCount = 0;
m_dbHeader.ofsFirstContact = 0;
- m_dbHeader.ofsFirstModuleName = 0;
+ m_dbHeader.ofsModuleNames = 0;
m_dbHeader.ofsUser = 0;
//create user
m_dbHeader.ofsUser = m_dbHeader.ofsFileEnd;
@@ -59,8 +59,15 @@ int CDb3Mmap::CheckDbHeaders()
memcmp(m_dbHeader.signature, &dbSignatureIM, sizeof(m_dbHeader.signature)))
return EGROKPRF_UNKHEADER;
- if (m_dbHeader.version != DB_095_VERSION && m_dbHeader.version != DB_094_VERSION && m_dbHeader.version != DB_OLD_VERSION)
+ switch (m_dbHeader.version) {
+ case DB_095_1_VERSION:
+ case DB_095_VERSION:
+ case DB_094_VERSION:
+ case DB_OLD_VERSION:
+ break;
+ default:
return EGROKPRF_VERNEWER;
+ }
if (m_dbHeader.ofsUser == 0)
return EGROKPRF_DAMAGED;
@@ -72,4 +79,4 @@ void CDb3Mmap::WriteSignature(DBSignature &sign)
{
memcpy(&m_dbHeader.signature, &sign, sizeof(DBSignature));
DBWrite(0, &sign, sizeof(DBSignature));
-} \ No newline at end of file
+}
diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp
index 2a6b3be65c..d481fd1afa 100644
--- a/plugins/Db3x_mmap/src/dbintf.cpp
+++ b/plugins/Db3x_mmap/src/dbintf.cpp
@@ -135,10 +135,19 @@ int CDb3Mmap::Load(bool bSkipInit)
// everything is ok, go on
if (!m_bReadOnly) {
+ bool bConversion = false;
if (m_dbHeader.version < DB_095_VERSION) {
ConvertContacts();
+ bConversion = true;
+ }
+
+ if (m_dbHeader.version < DB_095_1_VERSION) {
+ ConvertEvents();
+ bConversion = true;
+ }
- m_dbHeader.version = DB_095_VERSION;
+ if (bConversion) {
+ m_dbHeader.version = DB_095_1_VERSION;
DBWrite(sizeof(dbSignatureU), &m_dbHeader.version, sizeof(m_dbHeader.version));
}
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h
index ff42141458..6cb02f0344 100644
--- a/plugins/Db3x_mmap/src/dbintf.h
+++ b/plugins/Db3x_mmap/src/dbintf.h
@@ -47,6 +47,7 @@ DBHeader
#define DB_OLD_VERSION 0x00000700u
#define DB_094_VERSION 0x00000701u
#define DB_095_VERSION 0x00000800u
+#define DB_095_1_VERSION 0x00000801u
#define DB_SETTINGS_RESIZE_GRANULARITY 128
@@ -81,37 +82,31 @@ struct ModuleName
#include <pshpack1.h>
struct DBHeader
{
- BYTE signature[16]; // 'Miranda ICQ DB',0,26
- DWORD version; //as 4 bytes, ie 1.2.3.10 = 0x0102030a
- //this version is 0x00000700
- DWORD ofsFileEnd; //offset of the end of the database - place to write
- //new structures
- DWORD slackSpace; //a counter of the number of bytes that have been
- //wasted so far due to deleting structures and/or
- //re-making them at the end. We should compact when
- //this gets above a threshold
- DWORD contactCount; //number of contacts in the chain,excluding the user
- DWORD ofsFirstContact; //offset to first DBContact in the chain
- DWORD ofsUser; //offset to DBContact representing the user
- DWORD ofsFirstModuleName; //offset to first struct DBModuleName in the chain
+ BYTE signature[16]; // 'Miranda ICQ DB',0,26
+ DWORD version; // as 4 bytes, ie 1.2.3.10 = 0x0102030a
+ DWORD ofsFileEnd; // offset of the end of the database - place to write new structures
+ DWORD slackSpace; // a counter of the number of bytes that have been
+ // wasted so far due to deleting structures and/or
+ // re-making them at the end. We should compact when
+ // this gets above a threshold
+ DWORD contactCount; // number of contacts in the chain,excluding the user
+ DWORD ofsFirstContact; // offset to first DBContact in the chain
+ DWORD ofsUser; // offset to DBContact representing the user
+ DWORD ofsModuleNames; // offset to first struct DBModuleName in the chain
};
#define DBCONTACT_SIGNATURE 0x43DECADEu
-
struct DBContact
{
DWORD signature;
- DWORD ofsNext; //offset to the next contact in the chain. zero if
- //this is the 'user' contact or the last contact
- //in the chain
- DWORD ofsFirstSettings; //offset to the first DBContactSettings in the
- //chain for this contact.
- DWORD eventCount; //number of events in the chain for this contact
- DWORD ofsFirstEvent, ofsLastEvent; //offsets to the first and last DBEvent in
- //the chain for this contact
- DWORD ofsFirstUnreadEvent; //offset to the first (chronological) unread event
- //in the chain, 0 if all are read
- DWORD timestampFirstUnread; //timestamp of the event at ofsFirstUnreadEvent
+ DWORD ofsNext; // offset to the next contact in the chain. zero if
+ // this is the 'user' contact or the last contact in the chain
+ DWORD ofsFirstSettings; // offset to the first DBContactSettings in the chain for this contact.
+ DWORD eventCount; // number of events in the chain for this contact
+ DWORD ofsFirstEvent, // offsets to the first and
+ ofsLastEvent; // last DBEvent in the chain for this contact
+ DWORD ofsFirstUnread; // offset to the first (chronological) unread event in the chain, 0 if all are read
+ DWORD tsFirstUnread; // timestamp of the event at ofsFirstUnread
DWORD dwContactID;
};
@@ -119,45 +114,59 @@ struct DBContact
struct DBModuleName
{
DWORD signature;
- DWORD ofsNext; //offset to the next module name in the chain
- BYTE cbName; //number of characters in this module name
- char name[1]; //name, no nul terminator
+ DWORD ofsNext; // offset to the next module name in the chain
+ BYTE cbName; // number of characters in this module name
+ char name[1]; // name, no nul terminator
};
#define DBCONTACTSETTINGS_SIGNATURE 0x53DECADEu
struct DBContactSettings
{
DWORD signature;
- DWORD ofsNext; //offset to the next contactsettings in the chain
- DWORD ofsModuleName; //offset to the DBModuleName of the owner of these
- //settings
- DWORD cbBlob; //size of the blob in bytes. May be larger than the
- //actual size for reducing the number of moves
- //required using granularity in resizing
- BYTE blob[1]; //the blob. a back-to-back sequence of DBSetting
- //structs, the last has cbName = 0
+ DWORD ofsNext; // offset to the next contactsettings in the chain
+ DWORD ofsModuleName; // offset to the DBModuleName of the owner of these settings
+ DWORD cbBlob; // size of the blob in bytes. May be larger than the
+ // actual size for reducing the number of moves
+ // required using granularity in resizing
+ BYTE blob[1]; // the blob. a back-to-back sequence of DBSetting
+ // structs, the last has cbName = 0
};
#define DBEVENT_SIGNATURE 0x45DECADEu
+struct DBEvent_094 // previous event storage format
+{
+ DWORD signature;
+ DWORD ofsPrev, ofsNext; // offset to the previous and next events in the
+ // chain. Chain is sorted chronologically
+ DWORD ofsModuleName; // offset to a DBModuleName struct of the name of
+ // the owner of this event
+ DWORD timestamp; // seconds since 00:00:00 01/01/1970
+ DWORD flags; // see m_database.h, db/event/add
+ WORD wEventType; // module-defined event type
+ DWORD cbBlob; // number of bytes in the blob
+ BYTE blob[1]; // the blob. module-defined formatting
+};
+
struct DBEvent
{
DWORD signature;
- DWORD ofsPrev, ofsNext; //offset to the previous and next events in the
- //chain. Chain is sorted chronologically
- DWORD ofsModuleName; //offset to a DBModuleName struct of the name of
- //the owner of this event
- DWORD timestamp; //seconds since 00:00:00 01/01/1970
- DWORD flags; //see m_database.h, db/event/add
- WORD eventType; //module-defined event type
- DWORD cbBlob; //number of bytes in the blob
- BYTE blob[1]; //the blob. module-defined formatting
+ MCONTACT contactID; // a contact this event belongs to
+ DWORD ofsPrev, ofsNext; // offset to the previous and next events in the
+ // chain. Chain is sorted chronologically
+ DWORD ofsModuleName; // offset to a DBModuleName struct of the name of
+ // the owner of this event
+ DWORD timestamp; // seconds since 00:00:00 01/01/1970
+ DWORD flags; // see m_database.h, db/event/add
+ WORD wEventType; // module-defined event type
+ DWORD cbBlob; // number of bytes in the blob
+ BYTE blob[1]; // the blob. module-defined formatting
};
#include <poppack.h>
struct CDb3Mmap : public MIDatabase, public MIDatabaseChecker, public MZeroedObject
{
- CDb3Mmap(const TCHAR* tszFileName, bool bReadOnly);
+ CDb3Mmap(const TCHAR *tszFileName, bool bReadOnly);
~CDb3Mmap();
int Load(bool bSkipInit);
@@ -185,8 +194,8 @@ public:
STDMETHODIMP_(void) SetCacheSafetyMode(BOOL);
STDMETHODIMP_(LONG) GetContactCount(void);
- STDMETHODIMP_(MCONTACT) FindFirstContact(const char* szProto = NULL);
- STDMETHODIMP_(MCONTACT) FindNextContact(MCONTACT contactID, const char* szProto = NULL);
+ STDMETHODIMP_(MCONTACT) FindFirstContact(const char *szProto = NULL);
+ STDMETHODIMP_(MCONTACT) FindNextContact(MCONTACT contactID, const char *szProto = NULL);
STDMETHODIMP_(LONG) DeleteContact(MCONTACT contactID);
STDMETHODIMP_(HANDLE) AddContact(void);
STDMETHODIMP_(BOOL) IsDbContact(MCONTACT contactID);
@@ -212,7 +221,7 @@ public:
STDMETHODIMP_(BOOL) FreeVariant(DBVARIANT *dbv);
STDMETHODIMP_(BOOL) WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws);
STDMETHODIMP_(BOOL) DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting);
- STDMETHODIMP_(BOOL) EnumContactSettings(MCONTACT contactID, DBCONTACTENUMSETTINGS* dbces);
+ STDMETHODIMP_(BOOL) EnumContactSettings(MCONTACT contactID, DBCONTACTENUMSETTINGS *dbces);
STDMETHODIMP_(BOOL) SetSettingResident(BOOL bIsResident, const char *pszSettingName);
STDMETHODIMP_(BOOL) EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam);
STDMETHODIMP_(BOOL) IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting);
@@ -271,65 +280,67 @@ protected:
CRITICAL_SECTION m_csDbAccess;
- int CheckProto(DBCachedContact *cc, const char *proto);
- DWORD CreateNewSpace(int bytes);
- void DeleteSpace(DWORD ofs, int bytes);
- DWORD ReallocSpace(DWORD ofs, int oldSize, int newSize);
- DWORD GetContactOffset(MCONTACT contactID);
+ int CheckProto(DBCachedContact *cc, const char *proto);
+ DWORD CreateNewSpace(int bytes);
+ void DeleteSpace(DWORD ofs, int bytes);
+ DWORD ReallocSpace(DWORD ofs, int oldSize, int newSize);
+ DWORD GetContactOffset(MCONTACT contactID);
////////////////////////////////////////////////////////////////////////////
// settings
- int m_codePage;
+ int m_codePage;
////////////////////////////////////////////////////////////////////////////
// modules
- HANDLE m_hModHeap;
+ HANDLE m_hModHeap;
LIST<ModuleName> m_lMods, m_lOfs;
LIST<char> m_lResidentSettings;
- HANDLE hEventAddedEvent, hEventDeletedEvent, hEventFilterAddedEvent;
+ HANDLE hEventAddedEvent, hEventDeletedEvent, hEventFilterAddedEvent;
MCONTACT m_hLastCachedContact;
ModuleName *m_lastmn;
- void AddToList(char *name, DWORD len, DWORD ofs);
- DWORD FindExistingModuleNameOfs(const char *szName);
- int InitModuleNames(void);
- DWORD GetModuleNameOfs(const char *szName);
- char *GetModuleNameByOfs(DWORD ofs);
+ void AddToList(char *name, DWORD len, DWORD ofs);
+ DWORD FindExistingModuleNameOfs(const char *szName);
+ int InitModuleNames(void);
+ DWORD GetModuleNameOfs(const char *szName);
+ char* GetModuleNameByOfs(DWORD ofs);
////////////////////////////////////////////////////////////////////////////
// checker
- int PeekSegment(DWORD ofs, PVOID buf, int cbBytes);
- int ReadSegment(DWORD ofs, PVOID buf, int cbBytes);
- int ReadWrittenSegment(DWORD ofs, PVOID buf, int cbBytes);
- int SignatureValid(DWORD ofs, DWORD signature);
- void FreeModuleChain();
+ int PeekSegment(DWORD ofs, PVOID buf, int cbBytes);
+ int ReadSegment(DWORD ofs, PVOID buf, int cbBytes);
+ int ReadWrittenSegment(DWORD ofs, PVOID buf, int cbBytes);
+ int SignatureValid(DWORD ofs, DWORD signature);
+ void FreeModuleChain();
- DWORD ConvertModuleNameOfs(DWORD ofsOld);
- void ConvertOldEvent(DBEvent*& dbei);
+ DWORD ConvertModuleNameOfs(DWORD ofsOld);
+ void ConvertOldEvent(DBEvent*& dbei);
- int GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic);
- int WorkSettingsChain(DWORD ofsContact, DBContact *dbc, int firstTime);
- int WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime);
+ int GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic);
+ int WorkSettingsChain(DWORD ofsContact, DBContact *dbc, int firstTime);
+ int WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime);
- DWORD WriteSegment(DWORD ofs, PVOID buf, int cbBytes);
- DWORD WriteEvent(DBEvent *dbe);
- void WriteOfsNextToPrevious(DWORD ofsPrev, DBContact *dbc, DWORD ofsNext);
- void FinishUp(DWORD ofsLast, DBContact *dbc);
+ DWORD WriteSegment(DWORD ofs, PVOID buf, int cbBytes);
+ DWORD WriteEvent(DBEvent *dbe);
+ void WriteOfsNextToPrevious(DWORD ofsPrev, DBContact *dbc, DWORD ofsNext);
+ void FinishUp(DWORD ofsLast, DBContact *dbc);
DBCHeckCallback *cb;
- DWORD sourceFileSize, ofsAggrCur;
+ DWORD sourceFileSize, ofsAggrCur;
////////////////////////////////////////////////////////////////////////////
// encryption
- void ConvertContacts(void);
- int InitCrypt(void);
- void ToggleEventsEncryption(MCONTACT contactID);
- void ToggleSettingsEncryption(MCONTACT contactID);
+ void ConvertContacts(void);
+ void ConvertContactEvents(DBContact *dbc);
+ void ConvertEvents(void);
+ int InitCrypt(void);
+ void ToggleEventsEncryption(MCONTACT contactID);
+ void ToggleSettingsEncryption(MCONTACT contactID);
- void InitDialogs();
- bool EnterPassword(const BYTE *pKey, const size_t keyLen);
+ void InitDialogs();
+ bool EnterPassword(const BYTE *pKey, const size_t keyLen);
};
diff --git a/plugins/Db3x_mmap/src/dbmodulechain.cpp b/plugins/Db3x_mmap/src/dbmodulechain.cpp
index 2eedd6653a..fbdb9d512a 100644
--- a/plugins/Db3x_mmap/src/dbmodulechain.cpp
+++ b/plugins/Db3x_mmap/src/dbmodulechain.cpp
@@ -40,7 +40,7 @@ void CDb3Mmap::AddToList(char *name, DWORD len, DWORD ofs)
int CDb3Mmap::InitModuleNames(void)
{
- DWORD ofsThis = m_dbHeader.ofsFirstModuleName;
+ DWORD ofsThis = m_dbHeader.ofsModuleNames;
DBModuleName *dbmn = (struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
while (ofsThis) {
if (dbmn->signature != DBMODULENAME_SIGNATURE)
@@ -94,8 +94,8 @@ DWORD CDb3Mmap::GetModuleNameOfs(const char *szName)
DBModuleName dbmn;
dbmn.signature = DBMODULENAME_SIGNATURE;
dbmn.cbName = nameLen;
- dbmn.ofsNext = m_dbHeader.ofsFirstModuleName;
- m_dbHeader.ofsFirstModuleName = ofsNew;
+ dbmn.ofsNext = m_dbHeader.ofsModuleNames;
+ m_dbHeader.ofsModuleNames = ofsNew;
DBWrite(0, &m_dbHeader, sizeof(m_dbHeader));
DBWrite(ofsNew, &dbmn, offsetof(struct DBModuleName, name));
DBWrite(ofsNew + offsetof(struct DBModuleName, name), (PVOID)szName, nameLen);
diff --git a/plugins/Db3x_mmap/src/dbtool/eventchain.cpp b/plugins/Db3x_mmap/src/dbtool/eventchain.cpp
index 362f86436d..ff5defe281 100644
--- a/plugins/Db3x_mmap/src/dbtool/eventchain.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/eventchain.cpp
@@ -31,7 +31,7 @@ static DWORD ofsThisEvent, ofsPrevEvent;
static DWORD ofsDestPrevEvent;
static DWORD eventCount;
static DWORD lastTimestamp;
-static DWORD ofsFirstUnread, timestampFirstUnread;
+static DWORD ofsFirstUnread, tsFirstUnread;
static DWORD memsize = 0;
static DBEvent* memblock = NULL;
static DBEvent* dbePrevEvent = NULL;
@@ -87,12 +87,12 @@ void CDb3Mmap::FinishUp(DWORD ofsLast, DBContact *dbc)
dbc->eventCount = eventCount;
dbc->ofsLastEvent = ofsLast;
if (cb->bMarkRead) {
- dbc->ofsFirstUnreadEvent = 0;
- dbc->timestampFirstUnread = 0;
+ dbc->ofsFirstUnread = 0;
+ dbc->tsFirstUnread = 0;
}
else {
- dbc->ofsFirstUnreadEvent = ofsFirstUnread;
- dbc->timestampFirstUnread = timestampFirstUnread;
+ dbc->ofsFirstUnread = ofsFirstUnread;
+ dbc->tsFirstUnread = tsFirstUnread;
}
if (memsize && memblock) {
free(memblock);
@@ -128,13 +128,13 @@ int CDb3Mmap::WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime)
eventCount = 0;
backLookup = 0;
lastTimestamp = 0;
- ofsFirstUnread = timestampFirstUnread = 0;
+ ofsFirstUnread = tsFirstUnread = 0;
if (cb->bEraseHistory) {
dbc->eventCount = 0;
dbc->ofsFirstEvent = 0;
dbc->ofsLastEvent = 0;
- dbc->ofsFirstUnreadEvent = 0;
- dbc->timestampFirstUnread = 0;
+ dbc->ofsFirstUnread = 0;
+ dbc->tsFirstUnread = 0;
return ERROR_NO_MORE_ITEMS;
}
}
@@ -194,7 +194,7 @@ int CDb3Mmap::WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime)
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)
+ if (dbc->ofsFirstUnread != ofsThisEvent || dbc->tsFirstUnread != dbeOld.timestamp)
cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("First unread event marked wrong: fixing"));
isUnread = 1;
}
@@ -235,7 +235,7 @@ int CDb3Mmap::WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime)
dbeNew->ofsPrev = ofsDestPrevEvent;
dbeNew->ofsNext = 0;
- if (dbeOld.eventType == EVENTTYPE_MESSAGE && cb->bConvertUtf && !(dbeOld.flags & DBEF_ENCRYPTED)) {
+ if (dbeOld.wEventType == EVENTTYPE_MESSAGE && cb->bConvertUtf && !(dbeOld.flags & DBEF_ENCRYPTED)) {
DWORD oldSize = dbeNew->cbBlob;
BYTE* pOldMemo = (BYTE*)_alloca(dbeNew->cbBlob);
memcpy(pOldMemo, dbeNew->blob, dbeNew->cbBlob);
@@ -249,10 +249,9 @@ int CDb3Mmap::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) &&
- !memcmp(dbePrev->blob, dbeNew->blob, dbeNew->cbBlob))
+ dbePrev->ofsModuleName == dbeNew->ofsModuleName &&
+ dbePrev->wEventType == dbeNew->wEventType &&
+ (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"));
if (dbc->eventCount)
@@ -316,9 +315,9 @@ int CDb3Mmap::WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime)
if (!ofsDestThis)
return ERROR_HANDLE_DISK_FULL;
- if (isUnread && timestampFirstUnread >= dbeNew->timestamp) {
+ if (isUnread && tsFirstUnread >= dbeNew->timestamp) {
ofsFirstUnread = ofsDestThis;
- timestampFirstUnread = dbeNew->timestamp;
+ tsFirstUnread = dbeNew->timestamp;
}
// fix first event
WriteOfsNextToPrevious(0, dbc, ofsDestThis);
@@ -335,9 +334,9 @@ int CDb3Mmap::WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime)
if (!ofsDestThis)
return ERROR_HANDLE_DISK_FULL;
- if (isUnread && timestampFirstUnread >= dbeNew->timestamp) {
+ if (isUnread && tsFirstUnread >= dbeNew->timestamp) {
ofsFirstUnread = ofsDestThis;
- timestampFirstUnread = dbeNew->timestamp;
+ tsFirstUnread = dbeNew->timestamp;
}
// fix previous event
WriteOfsNextToPrevious(dbeNew->ofsPrev, dbc, ofsDestThis);
@@ -363,7 +362,7 @@ int CDb3Mmap::WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime)
if (isUnread) {
ofsFirstUnread = ofsDestThis;
- timestampFirstUnread = dbeOld.timestamp;
+ tsFirstUnread = dbeOld.timestamp;
}
eventCount++;
diff --git a/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp b/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp
index 549c8937fe..86bad8729d 100644
--- a/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp
@@ -27,7 +27,7 @@ int CDb3Mmap::WorkInitialCheckHeaders()
cb->pfnAddLogMessage(STATUS_FATAL, TranslateT("Database signature is corrupted, automatic repair is impossible"));
return ERROR_BAD_FORMAT;
}
- if (m_dbHeader.version != DB_095_VERSION) {
+ if (m_dbHeader.version != DB_095_1_VERSION) {
cb->pfnAddLogMessage(STATUS_FATAL, TranslateT("Database version doesn't match this driver's one. Convert a database first"));
return ERROR_BAD_FORMAT;
}
diff --git a/plugins/Db3x_mmap/src/dbtool/modulechain.cpp b/plugins/Db3x_mmap/src/dbtool/modulechain.cpp
index 011c7eaa62..135935e4ed 100644
--- a/plugins/Db3x_mmap/src/dbtool/modulechain.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/modulechain.cpp
@@ -41,7 +41,7 @@ int CDb3Mmap::WorkModuleChain(int firstTime)
free(modChain);
modChain = (ModChainEntry*)malloc(sizeof(ModChainEntry));
phase = 0;
- ofsCurrent = m_dbHeader.ofsFirstModuleName;
+ ofsCurrent = m_dbHeader.ofsModuleNames;
}
switch (phase) {
@@ -73,7 +73,7 @@ int CDb3Mmap::WorkModuleChain(int firstTime)
case 1:
ofsLast = 0;
iCurrentModName = 0;
- m_dbHeader.ofsFirstModuleName = 0;
+ m_dbHeader.ofsModuleNames = 0;
phase++;
case 2:
if (iCurrentModName >= modChainCount) {
@@ -104,7 +104,7 @@ int CDb3Mmap::WorkModuleChain(int firstTime)
}
if (iCurrentModName == 0)
- m_dbHeader.ofsFirstModuleName = modChain[iCurrentModName].ofsNew;
+ m_dbHeader.ofsModuleNames = 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;
diff --git a/plugins/Db3x_mmap/src/version.h b/plugins/Db3x_mmap/src/version.h
index d23bd34d4f..7e85a65adc 100644
--- a/plugins/Db3x_mmap/src/version.h
+++ b/plugins/Db3x_mmap/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 95
#define __RELEASE_NUM 0
-#define __BUILD_NUM 2
+#define __BUILD_NUM 3
#include <stdver.h>