summaryrefslogtreecommitdiff
path: root/plugins/Db3x_mmap
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Db3x_mmap')
-rw-r--r--plugins/Db3x_mmap/src/dbcache.cpp32
-rw-r--r--plugins/Db3x_mmap/src/dbevents.cpp6
-rw-r--r--plugins/Db3x_mmap/src/dbintf.cpp23
-rw-r--r--plugins/Db3x_mmap/src/dbintf.h55
-rw-r--r--plugins/Db3x_mmap/src/dbintfm.cpp17
-rw-r--r--plugins/Db3x_mmap/src/dbsettings.cpp38
-rw-r--r--plugins/Db3x_mmap/src/dbtool/eventchain.cpp4
7 files changed, 107 insertions, 68 deletions
diff --git a/plugins/Db3x_mmap/src/dbcache.cpp b/plugins/Db3x_mmap/src/dbcache.cpp
index 7f07540b56..d5700d2db7 100644
--- a/plugins/Db3x_mmap/src/dbcache.cpp
+++ b/plugins/Db3x_mmap/src/dbcache.cpp
@@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
-void CDb3Mmap::Map()
+void CDb3Base::Map()
{
m_hMap = CreateFileMapping(m_hDbFile, NULL, PAGE_READWRITE, 0, m_dwFileSize, NULL);
if (m_hMap) {
@@ -34,7 +34,7 @@ void CDb3Mmap::Map()
else DatabaseCorruption( _T("%s (CreateFileMapping failed. Code: %d)"));
}
-void CDb3Mmap::ReMap(DWORD needed)
+void CDb3Base::ReMap(DWORD needed)
{
KillTimer(NULL,m_flushBuffersTimerId);
@@ -58,7 +58,7 @@ void CDb3Mmap::ReMap(DWORD needed)
Map();
}
-void CDb3Mmap::DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes)
+void CDb3Base::DBMoveChunk(DWORD ofsDest, DWORD ofsSource, int bytes)
{
int x = 0;
//log3("move %d %08x->%08x",bytes,ofsSource,ofsDest);
@@ -76,7 +76,7 @@ void CDb3Mmap::DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes)
}
//we are assumed to be in a mutex here
-PBYTE CDb3Mmap::DBRead(DWORD ofs,int bytesRequired,int *bytesAvail)
+PBYTE CDb3Base::DBRead(DWORD ofs, int bytesRequired, int *bytesAvail)
{
// buggy read
if (ofs >= m_dwFileSize) {
@@ -90,7 +90,7 @@ PBYTE CDb3Mmap::DBRead(DWORD ofs,int bytesRequired,int *bytesAvail)
}
//we are assumed to be in a mutex here
-void CDb3Mmap::DBWrite(DWORD ofs,PVOID pData,int bytes)
+void CDb3Base::DBWrite(DWORD ofs, PVOID pData, int bytes)
{
//log2("write %d@%08x",bytes,ofs);
if (ofs+bytes > m_dwFileSize) ReMap(ofs+bytes-m_dwFileSize);
@@ -99,7 +99,7 @@ void CDb3Mmap::DBWrite(DWORD ofs,PVOID pData,int bytes)
}
//we are assumed to be in a mutex here
-void CDb3Mmap::DBFill(DWORD ofs,int bytes)
+void CDb3Base::DBFill(DWORD ofs, int bytes)
{
//log2("zerofill %d@%08x",bytes,ofs);
if (ofs+bytes <= m_dwFileSize)
@@ -110,7 +110,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++) {
- CDb3Mmap* db = g_Dbs[i];
+ CDb3Base *db = g_Dbs[i];
if (db->m_flushBuffersTimerId != idEvent)
continue;
@@ -130,7 +130,7 @@ static VOID CALLBACK DoBufferFlushTimerProc(HWND hwnd, UINT message, UINT_PTR id
}
}
-void CDb3Mmap::DBFlush(int setting)
+void CDb3Base::DBFlush(int setting)
{
if (!setting) {
log0("nflush1");
@@ -151,7 +151,7 @@ void CDb3Mmap::DBFlush(int setting)
m_flushBuffersTimerId = SetTimer(NULL, m_flushBuffersTimerId, 50, DoBufferFlushTimerProc);
}
-int CDb3Mmap::InitCache(void)
+int CDb3Base::InitCache(void)
{
m_dwFileSize = GetFileSize(m_hDbFile, NULL);
@@ -166,3 +166,17 @@ int CDb3Mmap::InitCache(void)
m_pNull = (PBYTE)calloc(m_ChunkSize, 1);
return 0;
}
+
+DWORD CDb3Base::GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc, DWORD ofsContact, DWORD ofsModuleName)
+{
+ DWORD ofsThis = dbc->ofsFirstSettings;
+ while (ofsThis) {
+ DBContactSettings *dbcs = (DBContactSettings*)DBRead(ofsThis, sizeof(DBContactSettings), NULL);
+ if (dbcs->signature != DBCONTACTSETTINGS_SIGNATURE) DatabaseCorruption(NULL);
+ if (dbcs->ofsModuleName == ofsModuleName)
+ return ofsThis;
+
+ ofsThis = dbcs->ofsNext;
+ }
+ return 0;
+}
diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp
index 7f9e55cdae..3399459539 100644
--- a/plugins/Db3x_mmap/src/dbevents.cpp
+++ b/plugins/Db3x_mmap/src/dbevents.cpp
@@ -123,7 +123,7 @@ STDMETHODIMP_(HANDLE) CDb3Base::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
DBWrite(ofsContact,&dbc,sizeof(DBContact));
DBWrite(ofsNew,&dbe,offsetof(DBEvent,blob));
- DBWrite(ofsNew+offsetof(DBEvent,blob),dbei->pBlob,dbei->cbBlob); // encode
+ EncodeDBWrite(ofsNew + offsetof(DBEvent, blob), dbei->pBlob, dbei->cbBlob); // encode
DBFlush(0);
lck.unlock();
@@ -243,10 +243,10 @@ STDMETHODIMP_(BOOL) CDb3Base::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
if (bytesToCopy && dbei->pBlob) {
for (int i = 0;;i += MAXCACHEDREADSIZE) {
if (bytesToCopy-i <= MAXCACHEDREADSIZE) {
- MoveMemory(dbei->pBlob + i, DBRead(DWORD(hDbEvent) + offsetof(DBEvent, blob) + i, bytesToCopy - i, NULL), bytesToCopy - i); // decode
+ DecodeCopyMemory(dbei->pBlob + i, DBRead(DWORD(hDbEvent) + offsetof(DBEvent, blob) + i, bytesToCopy - i, NULL), bytesToCopy - i); // decode
break;
}
- MoveMemory(dbei->pBlob + i, DBRead(DWORD(hDbEvent) + offsetof(DBEvent, blob) + i, MAXCACHEDREADSIZE, NULL), MAXCACHEDREADSIZE); // decode
+ DecodeCopyMemory(dbei->pBlob + i, DBRead(DWORD(hDbEvent) + offsetof(DBEvent, blob) + i, MAXCACHEDREADSIZE, NULL), MAXCACHEDREADSIZE); // decode
}
}
return 0;
diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp
index 5ca465d5ee..f5f1b3738b 100644
--- a/plugins/Db3x_mmap/src/dbintf.cpp
+++ b/plugins/Db3x_mmap/src/dbintf.cpp
@@ -128,7 +128,6 @@ int CDb3Base::Load(bool bSkipInit)
if (!bSkipInit) {
if (InitCache()) return 1;
if (InitModuleNames()) return 1;
- if (InitCrypt()) return 1;
m_bReadOnly = false;
@@ -157,9 +156,31 @@ STDMETHODIMP_(void) CDb3Base::SetCacheSafetyMode(BOOL bIsSet)
DBFlush(1);
}
+void CDb3Base::EncodeCopyMemory(void *dst, void *src, size_t size)
+{
+ MoveMemory(dst, src, size);
+}
+
+void CDb3Base::DecodeCopyMemory(void *dst, void *src, size_t size)
+{
+ MoveMemory(dst, src, size);
+}
+
+void CDb3Base::EncodeDBWrite(DWORD ofs, void *src, int size)
+{
+ DBWrite(ofs, src, size);
+}
+
+void CDb3Base::DecodeDBWrite(DWORD ofs, void *src, int size)
+{
+ DBWrite(ofs, src, size);
+}
+
///////////////////////////////////////////////////////////////////////////////
// MIDatabaseChecker
+typedef int (CDb3Base::*CheckWorker)(int);
+
static CheckWorker Workers[6] =
{
&CDb3Base::WorkInitialChecks,
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h
index c512b27ecb..0724f14cd5 100644
--- a/plugins/Db3x_mmap/src/dbintf.h
+++ b/plugins/Db3x_mmap/src/dbintf.h
@@ -196,17 +196,27 @@ protected:
STDMETHODIMP_(VOID) Destroy();
protected:
- virtual DWORD GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc,DWORD ofsContact,DWORD ofsModuleName) = 0;
- virtual void InvalidateSettingsGroupOfsCacheEntry(DWORD ofsSettingsGroup) {}
- virtual int WorkInitialCheckHeaders(void);
-
- virtual void DBMoveChunk(DWORD ofsDest, DWORD ofsSource, int bytes) = 0;
- virtual PBYTE DBRead(DWORD ofs, int bytesRequired, int *bytesAvail) = 0;
- virtual void DBWrite(DWORD ofs, PVOID pData, int bytes) = 0;
- virtual void DBFill(DWORD ofs, int bytes) = 0;
- virtual void DBFlush(int setting) = 0;
- virtual int InitCache(void) = 0;
- virtual int InitCrypt(void) { return 0; }
+ virtual void EncodeCopyMemory(void *dst, void *src, size_t size);
+ virtual void DecodeCopyMemory(void *dst, void *src, size_t size);
+ virtual void EncodeDBWrite(DWORD ofs, void *src, int size);
+ virtual void DecodeDBWrite(DWORD ofs, void *src, int size);
+
+protected:
+ DWORD GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc, DWORD ofsContact, DWORD ofsModuleName);
+ void InvalidateSettingsGroupOfsCacheEntry(DWORD ofsSettingsGroup) {}
+ int WorkInitialCheckHeaders(void);
+
+ void DBMoveChunk(DWORD ofsDest, DWORD ofsSource, int bytes);
+ PBYTE DBRead(DWORD ofs, int bytesRequired, int *bytesAvail);
+ void DBWrite(DWORD ofs, PVOID pData, int bytes);
+ void DBFill(DWORD ofs, int bytes);
+ void DBFlush(int setting);
+ int InitCache(void);
+
+ PBYTE m_pNull;
+
+ void Map();
+ void ReMap(DWORD needed);
public: // Check functions
int WorkInitialChecks(int);
@@ -299,30 +309,19 @@ struct CDb3Mmap : public CDb3Base
CDb3Mmap(const TCHAR* ptszFileName);
~CDb3Mmap();
- void StoreKey(void);
- void SetPassword(const TCHAR *ptszPassword);
- void UpdateMenuItem(void);
+ int Load(bool bSkipInit);
+
+ void StoreKey(void);
+ void SetPassword(const TCHAR *ptszPassword);
+ void UpdateMenuItem(void);
__forceinline LPSTR GetMenuTitle() const { return m_bUsesPassword ? LPGEN("Change/remove password") : LPGEN("Set password"); }
protected:
- virtual DWORD GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc,DWORD ofsContact,DWORD ofsModuleName);
- virtual void DBMoveChunk(DWORD ofsDest, DWORD ofsSource, int bytes);
- virtual PBYTE DBRead(DWORD ofs, int bytesRequired, int *bytesAvail);
- virtual void DBWrite(DWORD ofs, PVOID pData, int bytes);
- virtual void DBFill(DWORD ofs, int bytes);
- virtual void DBFlush(int setting);
- virtual int InitCache(void);
- virtual int InitCrypt(void);
+ int InitCrypt(void);
protected:
- PBYTE m_pNull;
-
- void Map();
- void ReMap(DWORD needed);
-
void InitDialogs();
bool EnterPassword(const BYTE *pKey, const size_t keyLen);
};
-typedef int (CDb3Base::*CheckWorker)(int);
diff --git a/plugins/Db3x_mmap/src/dbintfm.cpp b/plugins/Db3x_mmap/src/dbintfm.cpp
index 352728299f..3dc1e91294 100644
--- a/plugins/Db3x_mmap/src/dbintfm.cpp
+++ b/plugins/Db3x_mmap/src/dbintfm.cpp
@@ -36,16 +36,13 @@ CDb3Mmap::~CDb3Mmap()
free(m_pNull);
}
-DWORD CDb3Mmap::GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc,DWORD ofsContact,DWORD ofsModuleName)
+int CDb3Mmap::Load(bool bSkipInit)
{
- DWORD ofsThis = dbc->ofsFirstSettings;
- while (ofsThis) {
- DBContactSettings *dbcs = (DBContactSettings*)DBRead(ofsThis,sizeof(DBContactSettings),NULL);
- if (dbcs->signature != DBCONTACTSETTINGS_SIGNATURE) DatabaseCorruption(NULL);
- if (dbcs->ofsModuleName == ofsModuleName)
- return ofsThis;
-
- ofsThis = dbcs->ofsNext;
+ int res = CDb3Base::Load(bSkipInit);
+ if (!res) {
+ if (!bSkipInit)
+ if (InitCrypt()) return 1;
}
- return 0;
+
+ return res;
}
diff --git a/plugins/Db3x_mmap/src/dbsettings.cpp b/plugins/Db3x_mmap/src/dbsettings.cpp
index bd5915cbb1..77affa8b2c 100644
--- a/plugins/Db3x_mmap/src/dbsettings.cpp
+++ b/plugins/Db3x_mmap/src/dbsettings.cpp
@@ -142,9 +142,9 @@ int CDb3Base::GetContactSettingWorker(HANDLE hContact, DBCONTACTGETSETTING *dbcg
dbcgs->pValue->type = DBVT_DELETED;
return 2;
- case DBVT_BYTE: dbcgs->pValue->bVal = pBlob[1]; break;
- case DBVT_WORD: MoveMemory(&(dbcgs->pValue->wVal), (PWORD)(pBlob + 1), 2); break;
- case DBVT_DWORD: MoveMemory(&(dbcgs->pValue->dVal), (PDWORD)(pBlob + 1), 4); break;
+ case DBVT_BYTE: dbcgs->pValue->bVal = pBlob[1]; break;
+ case DBVT_WORD: DecodeCopyMemory(&(dbcgs->pValue->wVal), (PWORD)(pBlob + 1), 2); break;
+ case DBVT_DWORD: DecodeCopyMemory(&(dbcgs->pValue->dVal), (PDWORD)(pBlob + 1), 4); break;
case DBVT_UTF8:
case DBVT_ASCIIZ:
@@ -154,13 +154,13 @@ int CDb3Base::GetContactSettingWorker(HANDLE hContact, DBCONTACTGETSETTING *dbcg
dbcgs->pValue->cchVal--;
if (varLen < dbcgs->pValue->cchVal)
dbcgs->pValue->cchVal = varLen;
- MoveMemory(dbcgs->pValue->pszVal, pBlob + 3, dbcgs->pValue->cchVal); // decode
+ DecodeCopyMemory(dbcgs->pValue->pszVal, pBlob + 3, dbcgs->pValue->cchVal); // decode
dbcgs->pValue->pszVal[dbcgs->pValue->cchVal] = 0;
dbcgs->pValue->cchVal = varLen;
}
else {
dbcgs->pValue->pszVal = (char*)mir_alloc(1 + varLen);
- MoveMemory(dbcgs->pValue->pszVal, pBlob + 3, varLen);
+ DecodeCopyMemory(dbcgs->pValue->pszVal, pBlob + 3, varLen);
dbcgs->pValue->pszVal[varLen] = 0;
}
break;
@@ -171,11 +171,11 @@ int CDb3Base::GetContactSettingWorker(HANDLE hContact, DBCONTACTGETSETTING *dbcg
if (isStatic) {
if (varLen < dbcgs->pValue->cpbVal)
dbcgs->pValue->cpbVal = varLen;
- MoveMemory(dbcgs->pValue->pbVal, pBlob + 3, dbcgs->pValue->cpbVal);
+ DecodeCopyMemory(dbcgs->pValue->pbVal, pBlob + 3, dbcgs->pValue->cpbVal);
}
else {
dbcgs->pValue->pbVal = (BYTE *)mir_alloc(varLen);
- MoveMemory(dbcgs->pValue->pbVal, pBlob + 3, varLen);
+ DecodeCopyMemory(dbcgs->pValue->pbVal, pBlob + 3, varLen);
}
dbcgs->pValue->cpbVal = varLen;
break;
@@ -544,15 +544,17 @@ STDMETHODIMP_(BOOL) CDb3Base::WriteContactSetting(HANDLE hContact, DBCONTACTWRIT
MoveAlong(1); //skip data type
switch (tmp.value.type) {
case DBVT_BYTE: DBWrite(ofsBlobPtr, &tmp.value.bVal, 1); break;
- case DBVT_WORD: DBWrite(ofsBlobPtr, &tmp.value.wVal, 2); break;
- case DBVT_DWORD: DBWrite(ofsBlobPtr, &tmp.value.dVal, 4); break;
+ case DBVT_WORD: EncodeDBWrite(ofsBlobPtr, &tmp.value.wVal, 2); break;
+ case DBVT_DWORD: EncodeDBWrite(ofsBlobPtr, &tmp.value.dVal, 4); break;
case DBVT_BLOB:
+ EncodeDBWrite(ofsBlobPtr + 2, tmp.value.pbVal, tmp.value.cpbVal);
+ break;
case DBVT_ENCRYPTED:
DBWrite(ofsBlobPtr + 2, tmp.value.pbVal, tmp.value.cpbVal);
break;
case DBVT_UTF8:
case DBVT_ASCIIZ:
- DBWrite(ofsBlobPtr + 2, tmp.value.pszVal, tmp.value.cchVal);
+ EncodeDBWrite(ofsBlobPtr + 2, tmp.value.pszVal, tmp.value.cchVal);
break;
}
//quit
@@ -627,18 +629,24 @@ STDMETHODIMP_(BOOL) CDb3Base::WriteContactSetting(HANDLE hContact, DBCONTACTWRIT
MoveAlong(1);
switch (tmp.value.type) {
case DBVT_BYTE: DBWrite(ofsBlobPtr, &tmp.value.bVal, 1); MoveAlong(1); break;
- case DBVT_WORD: DBWrite(ofsBlobPtr, &tmp.value.wVal, 2); MoveAlong(2); break;
- case DBVT_DWORD: DBWrite(ofsBlobPtr, &tmp.value.dVal, 4); MoveAlong(4); 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;
- case DBVT_BLOB: case DBVT_ENCRYPTED:
+ case DBVT_BLOB:
+ DBWrite(ofsBlobPtr, &tmp.value.cpbVal, 2);
+ EncodeDBWrite(ofsBlobPtr + 2, tmp.value.pbVal, tmp.value.cpbVal);
+ MoveAlong(2 + tmp.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);
break;
-
+
case DBVT_UTF8: case DBVT_ASCIIZ:
DBWrite(ofsBlobPtr, &tmp.value.cchVal, 2);
- DBWrite(ofsBlobPtr + 2, tmp.value.pszVal, tmp.value.cchVal);
+ EncodeDBWrite(ofsBlobPtr + 2, tmp.value.pszVal, tmp.value.cchVal);
MoveAlong(2 + tmp.value.cchVal);
break;
}
diff --git a/plugins/Db3x_mmap/src/dbtool/eventchain.cpp b/plugins/Db3x_mmap/src/dbtool/eventchain.cpp
index ee35fec362..a5a03cbecd 100644
--- a/plugins/Db3x_mmap/src/dbtool/eventchain.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/eventchain.cpp
@@ -232,12 +232,12 @@ int CDb3Base::WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
DWORD oldSize = dbeNew->cbBlob;
BYTE* pOldMemo = (BYTE*)_alloca(dbeNew->cbBlob);
memcpy(pOldMemo, dbeNew->blob, dbeNew->cbBlob);
- CopyMemory(dbeNew->blob, pOldMemo, dbeNew->cbBlob); // decode
+ DecodeCopyMemory(dbeNew->blob, pOldMemo, dbeNew->cbBlob); // decode
ConvertOldEvent(dbeNew);
if (dbeNew->cbBlob > oldSize)
pOldMemo = (BYTE*)_alloca(dbeNew->cbBlob);
memcpy(pOldMemo, dbeNew->blob, dbeNew->cbBlob);
- MoveMemory(dbeNew->blob, pOldMemo, dbeNew->cbBlob); // encode
+ EncodeCopyMemory(dbeNew->blob, pOldMemo, dbeNew->cbBlob); // encode
}
if (dbePrev) {