diff options
author | George Hazan <george.hazan@gmail.com> | 2014-02-07 14:08:15 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-02-07 14:08:15 +0000 |
commit | 7b8b7fa685ea5de62002d5637b4c34e19dfedeee (patch) | |
tree | e56c7f34d2470edc5cf40dea77d8e6ca0f6a17ac | |
parent | 7f2e5db6faeded54a61e9e1595d6d1596647db4d (diff) |
- the internal DBContact structure extended to hold one more DWORD: contact ID;
- when called from dbchecker, mmap now refuses to check the old versions of database;
- old classes hierarchy removed, all classes were merged into one due to the death of db3x & mmap_sa;
- version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@8061 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
27 files changed, 223 insertions, 261 deletions
diff --git a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj index a3515c6de8..8373b7d80f 100644 --- a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj +++ b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj @@ -198,7 +198,6 @@ <ClCompile Include="src\dbevents.cpp" />
<ClCompile Include="src\dbheaders.cpp" />
<ClCompile Include="src\dbintf.cpp" />
- <ClCompile Include="src\dbintfm.cpp" />
<ClCompile Include="src\dbmodulechain.cpp" />
<ClCompile Include="src\dbsettings.cpp" />
<ClCompile Include="src\dbtool\aggressive.cpp">
diff --git a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters index a8cd5dfc1e..0bf55561c0 100644 --- a/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters +++ b/plugins/Db3x_mmap/db3x_mmap_10.vcxproj.filters @@ -39,9 +39,6 @@ <ClCompile Include="src\dbintf.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\dbintfm.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="src\dbmodulechain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/plugins/Db3x_mmap/db3x_mmap_11.vcxproj b/plugins/Db3x_mmap/db3x_mmap_11.vcxproj index 270c7f54f4..9c244bf425 100644 --- a/plugins/Db3x_mmap/db3x_mmap_11.vcxproj +++ b/plugins/Db3x_mmap/db3x_mmap_11.vcxproj @@ -201,7 +201,6 @@ <ClCompile Include="src\dbevents.cpp" />
<ClCompile Include="src\dbheaders.cpp" />
<ClCompile Include="src\dbintf.cpp" />
- <ClCompile Include="src\dbintfm.cpp" />
<ClCompile Include="src\dbmodulechain.cpp" />
<ClCompile Include="src\dbsettings.cpp" />
<ClCompile Include="src\dbtool\aggressive.cpp">
diff --git a/plugins/Db3x_mmap/db3x_mmap_11.vcxproj.filters b/plugins/Db3x_mmap/db3x_mmap_11.vcxproj.filters index dde8eca53c..7120a74b41 100644 --- a/plugins/Db3x_mmap/db3x_mmap_11.vcxproj.filters +++ b/plugins/Db3x_mmap/db3x_mmap_11.vcxproj.filters @@ -39,9 +39,6 @@ <ClCompile Include="src\dbintf.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\dbintfm.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="src\dbmodulechain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/plugins/Db3x_mmap/db3x_mmap_12.vcxproj b/plugins/Db3x_mmap/db3x_mmap_12.vcxproj index ebce8e1d03..bc1d620b8c 100644 --- a/plugins/Db3x_mmap/db3x_mmap_12.vcxproj +++ b/plugins/Db3x_mmap/db3x_mmap_12.vcxproj @@ -201,7 +201,6 @@ <ClCompile Include="src\dbevents.cpp" />
<ClCompile Include="src\dbheaders.cpp" />
<ClCompile Include="src\dbintf.cpp" />
- <ClCompile Include="src\dbintfm.cpp" />
<ClCompile Include="src\dbmodulechain.cpp" />
<ClCompile Include="src\dbsettings.cpp" />
<ClCompile Include="src\dbtool\aggressive.cpp">
diff --git a/plugins/Db3x_mmap/db3x_mmap_12.vcxproj.filters b/plugins/Db3x_mmap/db3x_mmap_12.vcxproj.filters index 40ffb74580..50aadeb1d9 100644 --- a/plugins/Db3x_mmap/db3x_mmap_12.vcxproj.filters +++ b/plugins/Db3x_mmap/db3x_mmap_12.vcxproj.filters @@ -36,9 +36,6 @@ <ClCompile Include="src\dbintf.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\dbintfm.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="src\dbmodulechain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/plugins/Db3x_mmap/src/database.cpp b/plugins/Db3x_mmap/src/database.cpp index 82085bb7fc..723ddea5a7 100644 --- a/plugins/Db3x_mmap/src/database.cpp +++ b/plugins/Db3x_mmap/src/database.cpp @@ -24,11 +24,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
int InitModuleNames(void);
-int InitCache(void);
+int InitMap(void);
int InitIni(void);
void UninitIni(void);
-DWORD CDb3Base::CreateNewSpace(int bytes)
+DWORD CDb3Mmap::CreateNewSpace(int bytes)
{
DWORD ofsNew = m_dbHeader.ofsFileEnd;
m_dbHeader.ofsFileEnd += bytes;
@@ -37,7 +37,7 @@ DWORD CDb3Base::CreateNewSpace(int bytes) return ofsNew;
}
-void CDb3Base::DeleteSpace(DWORD ofs, int bytes)
+void CDb3Mmap::DeleteSpace(DWORD ofs, int bytes)
{
if (ofs+bytes == m_dbHeader.ofsFileEnd) {
log2("freespace %d@%08x",bytes,ofs);
@@ -51,7 +51,7 @@ void CDb3Base::DeleteSpace(DWORD ofs, int bytes) DBFill(ofs, bytes);
}
-DWORD CDb3Base::ReallocSpace(DWORD ofs, int oldSize, int newSize)
+DWORD CDb3Mmap::ReallocSpace(DWORD ofs, int oldSize, int newSize)
{
if (oldSize >= newSize)
return ofs;
@@ -96,7 +96,7 @@ void __cdecl dbpanic(void *arg) TerminateProcess(GetCurrentProcess(),255);
}
-void CDb3Base::DatabaseCorruption(TCHAR *text)
+void CDb3Mmap::DatabaseCorruption(TCHAR *text)
{
int kill = 0;
diff --git a/plugins/Db3x_mmap/src/dbcache.cpp b/plugins/Db3x_mmap/src/dbcache.cpp index b91362bf3b..c0bf00e738 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 CDb3Base::Map()
+void CDb3Mmap::Map()
{
DWORD dwProtectMode, dwAccess;
if (cb && cb->bAggressive)
@@ -42,7 +42,7 @@ void CDb3Base::Map() else DatabaseCorruption( _T("%s (CreateFileMapping failed. Code: %d)"));
}
-void CDb3Base::ReMap(DWORD needed)
+void CDb3Mmap::ReMap(DWORD needed)
{
KillTimer(NULL,m_flushBuffersTimerId);
@@ -67,7 +67,7 @@ void CDb3Base::ReMap(DWORD needed) Map();
}
-void CDb3Base::DBMoveChunk(DWORD ofsDest, DWORD ofsSource, int bytes)
+void CDb3Mmap::DBMoveChunk(DWORD ofsDest, DWORD ofsSource, int bytes)
{
int x = 0;
//log3("move %d %08x->%08x",bytes,ofsSource,ofsDest);
@@ -85,7 +85,7 @@ void CDb3Base::DBMoveChunk(DWORD ofsDest, DWORD ofsSource, int bytes) }
//we are assumed to be in a mutex here
-PBYTE CDb3Base::DBRead(DWORD ofs, int bytesRequired, int *bytesAvail)
+PBYTE CDb3Mmap::DBRead(DWORD ofs, int bytesRequired, int *bytesAvail)
{
// buggy read
if (ofs >= m_dwFileSize) {
@@ -99,7 +99,7 @@ PBYTE CDb3Base::DBRead(DWORD ofs, int bytesRequired, int *bytesAvail) }
//we are assumed to be in a mutex here
-void CDb3Base::DBWrite(DWORD ofs, PVOID pData, int bytes)
+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);
@@ -108,7 +108,7 @@ void CDb3Base::DBWrite(DWORD ofs, PVOID pData, int bytes) }
//we are assumed to be in a mutex here
-void CDb3Base::DBFill(DWORD ofs, int bytes)
+void CDb3Mmap::DBFill(DWORD ofs, int bytes)
{
//log2("zerofill %d@%08x",bytes,ofs);
if (ofs+bytes <= m_dwFileSize)
@@ -119,7 +119,7 @@ void CDb3Base::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++) {
- CDb3Base *db = g_Dbs[i];
+ CDb3Mmap *db = g_Dbs[i];
if (db->m_flushBuffersTimerId != idEvent)
continue;
@@ -139,7 +139,7 @@ static VOID CALLBACK DoBufferFlushTimerProc(HWND hwnd, UINT message, UINT_PTR id }
}
-void CDb3Base::DBFlush(int setting)
+void CDb3Mmap::DBFlush(int setting)
{
if (!setting) {
log0("nflush1");
@@ -160,7 +160,7 @@ void CDb3Base::DBFlush(int setting) m_flushBuffersTimerId = SetTimer(NULL, m_flushBuffersTimerId, 50, DoBufferFlushTimerProc);
}
-int CDb3Base::InitCache(void)
+int CDb3Mmap::InitMap(void)
{
m_dwFileSize = GetFileSize(m_hDbFile, NULL);
@@ -178,7 +178,7 @@ int CDb3Base::InitCache(void) return 0;
}
-DWORD CDb3Base::GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc, DWORD ofsContact, DWORD ofsModuleName)
+DWORD CDb3Mmap::GetSettingsGroupOfsByModuleNameOfs(DBContact *dbc, DWORD ofsContact, DWORD ofsModuleName)
{
DWORD ofsThis = dbc->ofsFirstSettings;
while (ofsThis) {
diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp index 13d5a0fb78..c96f888178 100644 --- a/plugins/Db3x_mmap/src/dbcontacts.cpp +++ b/plugins/Db3x_mmap/src/dbcontacts.cpp @@ -23,16 +23,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
-int CDb3Base::CheckProto(HANDLE hContact, const char *proto)
+int CDb3Mmap::CheckProto(HANDLE hContact, const char *proto)
{
DBCachedContact *cc = m_cache->GetCachedContact(hContact);
if (cc == NULL)
cc = m_cache->AddContactToCache(hContact);
if (cc->szProto == NULL) {
- char protobuf[MAX_PATH] = {0};
+ char protobuf[MAX_PATH] = { 0 };
DBVARIANT dbv;
- dbv.type = DBVT_ASCIIZ;
+ dbv.type = DBVT_ASCIIZ;
dbv.pszVal = protobuf;
dbv.cchVal = sizeof(protobuf);
if (GetContactSettingStatic(hContact, "Protocol", "p", &dbv) != 0 || (dbv.type != DBVT_ASCIIZ))
@@ -44,13 +44,13 @@ int CDb3Base::CheckProto(HANDLE hContact, const char *proto) return !strcmp(cc->szProto, proto);
}
-STDMETHODIMP_(LONG) CDb3Base::GetContactCount(void)
+STDMETHODIMP_(LONG) CDb3Mmap::GetContactCount(void)
{
mir_cslock lck(m_csDbAccess);
return m_dbHeader.contactCount;
}
-STDMETHODIMP_(HANDLE) CDb3Base::FindFirstContact(const char *szProto)
+STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstContact(const char *szProto)
{
mir_cslock lck(m_csDbAccess);
HANDLE ret = (HANDLE)m_dbHeader.ofsFirstContact;
@@ -59,7 +59,7 @@ STDMETHODIMP_(HANDLE) CDb3Base::FindFirstContact(const char *szProto) return ret;
}
-STDMETHODIMP_(HANDLE) CDb3Base::FindNextContact(HANDLE hContact, const char *szProto)
+STDMETHODIMP_(HANDLE) CDb3Mmap::FindNextContact(HANDLE hContact, const char *szProto)
{
mir_cslock lck(m_csDbAccess);
while (hContact) {
@@ -90,7 +90,7 @@ STDMETHODIMP_(HANDLE) CDb3Base::FindNextContact(HANDLE hContact, const char *szP return NULL;
}
-STDMETHODIMP_(LONG) CDb3Base::DeleteContact(HANDLE hContact)
+STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(HANDLE hContact)
{
if (hContact == NULL)
return 1;
@@ -119,7 +119,7 @@ STDMETHODIMP_(LONG) CDb3Base::DeleteContact(HANDLE hContact) m_hLastCachedContact = NULL;
dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
- //delete settings chain
+ // delete settings chain
DWORD ofsThis = dbc->ofsFirstSettings;
DWORD ofsFirstEvent = dbc->ofsFirstEvent;
while (ofsThis) {
@@ -128,7 +128,7 @@ STDMETHODIMP_(LONG) CDb3Base::DeleteContact(HANDLE hContact) DeleteSpace(ofsThis,offsetof(DBContactSettings,blob)+dbcs->cbBlob);
ofsThis = ofsNext;
}
- //delete event chain
+ // delete event chain
ofsThis = ofsFirstEvent;
while (ofsThis) {
DBEvent *dbe = (DBEvent*)DBRead(ofsThis,sizeof(DBEvent),NULL);
@@ -164,17 +164,18 @@ STDMETHODIMP_(LONG) CDb3Base::DeleteContact(HANDLE hContact) return 0;
}
-STDMETHODIMP_(HANDLE) CDb3Base::AddContact()
+STDMETHODIMP_(HANDLE) CDb3Mmap::AddContact()
{
DWORD ofsNew;
log0("add contact");
- {
+ {
mir_cslock lck(m_csDbAccess);
ofsNew = CreateNewSpace(sizeof(DBContact));
DBContact dbc = { 0 };
dbc.signature = DBCONTACT_SIGNATURE;
dbc.ofsNext = m_dbHeader.ofsFirstContact;
+ dbc.dwContactID = m_dwMaxContactId++;
m_dbHeader.ofsFirstContact = ofsNew;
m_dbHeader.contactCount++;
DBWrite(ofsNew, &dbc, sizeof(DBContact));
@@ -183,17 +184,17 @@ STDMETHODIMP_(HANDLE) CDb3Base::AddContact() }
m_cache->AddContactToCache((HANDLE)ofsNew);
- NotifyEventHooks(hContactAddedEvent,(WPARAM)ofsNew,0);
+ NotifyEventHooks(hContactAddedEvent, (WPARAM)ofsNew, 0);
return (HANDLE)ofsNew;
}
-STDMETHODIMP_(BOOL) CDb3Base::IsDbContact(HANDLE hContact)
+STDMETHODIMP_(BOOL) CDb3Mmap::IsDbContact(HANDLE hContact)
{
if (m_cache->GetCachedContact(hContact))
return TRUE;
mir_cslock lck(m_csDbAccess);
- DBContact *dbc = (DBContact*)DBRead(hContact,sizeof(DBContact),NULL);
+ DBContact *dbc = (DBContact*)DBRead(hContact, sizeof(DBContact), NULL);
if (dbc->signature == DBCONTACT_SIGNATURE) {
m_cache->AddContactToCache(hContact);
return TRUE;
@@ -201,3 +202,46 @@ STDMETHODIMP_(BOOL) CDb3Base::IsDbContact(HANDLE hContact) return FALSE;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// contacts convertor
+
+#define OLD_CONTACT_SIZE offsetof(DBContact, dwContactID)
+
+void CDb3Mmap::ConvertContacts()
+{
+ DBContact *pPrev = NULL;
+
+ m_dbHeader.ofsUser = ReallocSpace(m_dbHeader.ofsUser, OLD_CONTACT_SIZE, sizeof(DBContact));
+
+ for (DWORD dwOffset = m_dbHeader.ofsFirstContact; dwOffset != 0;) {
+ DBContact *pOld = (DBContact*)DBRead(dwOffset, sizeof(DBContact), NULL);
+ DWORD dwNew = ReallocSpace(dwOffset, OLD_CONTACT_SIZE, sizeof(DBContact));
+ DBContact *pNew = (DBContact*)DBRead(dwNew, sizeof(DBContact), NULL);
+ pNew->dwContactID = m_dwMaxContactId++;
+
+ if (pPrev == NULL)
+ m_dbHeader.ofsFirstContact = dwNew;
+ else
+ pPrev->ofsNext = dwNew;
+ pPrev = pNew;
+ dwOffset = pNew->ofsNext;
+ }
+
+ FlushViewOfFile(m_pDbCache, 0);
+}
+
+void CDb3Mmap::FillContacts()
+{
+ for (DWORD dwOffset = m_dbHeader.ofsFirstContact; dwOffset != 0;) {
+ DBContact *p = (DBContact*)DBRead(dwOffset, sizeof(DBContact), NULL);
+ if (p->signature != DBCONTACT_SIGNATURE)
+ break;
+
+ if (p->dwContactID > m_dwMaxContactId)
+ m_dwMaxContactId = p->dwContactID + 1;
+
+ CheckProto((HANDLE)dwOffset, "");
+ dwOffset = p->ofsNext;
+ }
+}
diff --git a/plugins/Db3x_mmap/src/dbcrypt.cpp b/plugins/Db3x_mmap/src/dbcrypt.cpp index 057438fd08..6e3207adf9 100644 --- a/plugins/Db3x_mmap/src/dbcrypt.cpp +++ b/plugins/Db3x_mmap/src/dbcrypt.cpp @@ -174,7 +174,7 @@ LBL_SetNewKey: goto LBL_SetNewKey;
if (!EnterPassword(dbv.pbVal, iKeyLength)) { // password protected?
- if (m_dbHeader.version == DB_THIS_VERSION)
+ if (m_dbHeader.version >= DB_094_VERSION)
return 4;
// one of the early used version of mmap was replaced then by mmap_sa
@@ -193,11 +193,6 @@ LBL_SetNewKey: WriteSignature(dbSignatureU);
}
- if (m_dbHeader.version == DB_OLD_VERSION) {
- m_dbHeader.version = DB_THIS_VERSION;
- DBWrite(sizeof(dbSignatureU), &m_dbHeader.version, sizeof(m_dbHeader.version));
- }
-
dbv.type = DBVT_BYTE;
if (!GetContactSetting(NULL, "CryptoEngine", "DatabaseEncryption", &dbv))
m_bEncrypted = dbv.bVal != 0;
diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp index d30458249c..fe323e6bad 100644 --- a/plugins/Db3x_mmap/src/dbevents.cpp +++ b/plugins/Db3x_mmap/src/dbevents.cpp @@ -28,7 +28,7 @@ char *GetModuleNameByOfs(DWORD ofs); static HANDLE hEventDeletedEvent, hEventAddedEvent, hEventFilterAddedEvent;
-STDMETHODIMP_(LONG) CDb3Base::GetEventCount(HANDLE hContact)
+STDMETHODIMP_(LONG) CDb3Mmap::GetEventCount(HANDLE hContact)
{
mir_cslock lck(m_csDbAccess);
if (hContact == 0)
@@ -38,7 +38,7 @@ STDMETHODIMP_(LONG) CDb3Base::GetEventCount(HANDLE hContact) return (dbc->signature != DBCONTACT_SIGNATURE) ? -1 : dbc->eventCount;
}
-STDMETHODIMP_(HANDLE) CDb3Base::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
+STDMETHODIMP_(HANDLE) CDb3Mmap::AddEvent(HANDLE hContact, DBEVENTINFO *dbei)
{
if (dbei == NULL || dbei->cbSize != sizeof(DBEVENTINFO)) return 0;
if (dbei->timestamp == 0) return 0;
@@ -135,7 +135,7 @@ STDMETHODIMP_(HANDLE) CDb3Base::AddEvent(HANDLE hContact, DBEVENTINFO *dbei) DBWrite(ofsContact, &dbc, sizeof(DBContact));
DBWrite(ofsNew, &dbe, offsetof(DBEvent, blob));
- EncodeDBWrite(ofsNew + offsetof(DBEvent, blob), pBlob, dbe.cbBlob);
+ DBWrite(ofsNew + offsetof(DBEvent, blob), pBlob, dbe.cbBlob);
DBFlush(0);
lck.unlock();
@@ -148,7 +148,7 @@ STDMETHODIMP_(HANDLE) CDb3Base::AddEvent(HANDLE hContact, DBEVENTINFO *dbei) return (HANDLE)ofsNew;
}
-STDMETHODIMP_(BOOL) CDb3Base::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
+STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(HANDLE hContact, HANDLE hDbEvent)
{
mir_cslockfull lck(m_csDbAccess);
@@ -226,14 +226,14 @@ STDMETHODIMP_(BOOL) CDb3Base::DeleteEvent(HANDLE hContact, HANDLE hDbEvent) return 0;
}
-STDMETHODIMP_(LONG) CDb3Base::GetBlobSize(HANDLE hDbEvent)
+STDMETHODIMP_(LONG) CDb3Mmap::GetBlobSize(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
return (dbe->signature != DBEVENT_SIGNATURE) ? -1 : dbe->cbBlob;
}
-STDMETHODIMP_(BOOL) CDb3Base::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
+STDMETHODIMP_(BOOL) CDb3Mmap::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei)
{
if (dbei == NULL || dbei->cbSize != sizeof(DBEVENTINFO)) return 1;
if (dbei->cbBlob > 0 && dbei->pBlob == NULL) {
@@ -266,12 +266,12 @@ STDMETHODIMP_(BOOL) CDb3Base::GetEvent(HANDLE hDbEvent, DBEVENTINFO *dbei) memset(dbei->pBlob + len, 0, bytesToCopy - len);
mir_free(pBlob);
}
- else DecodeCopyMemory(dbei->pBlob, pSrc, bytesToCopy);
+ else MoveMemory(dbei->pBlob, pSrc, bytesToCopy);
}
return 0;
}
-STDMETHODIMP_(BOOL) CDb3Base::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
+STDMETHODIMP_(BOOL) CDb3Mmap::MarkEventRead(HANDLE hContact, HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
if (hContact == 0)
@@ -309,7 +309,7 @@ STDMETHODIMP_(BOOL) CDb3Base::MarkEventRead(HANDLE hContact, HANDLE hDbEvent) return ret;
}
-STDMETHODIMP_(HANDLE) CDb3Base::GetEventContact(HANDLE hDbEvent)
+STDMETHODIMP_(HANDLE) CDb3Mmap::GetEventContact(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
@@ -322,7 +322,7 @@ STDMETHODIMP_(HANDLE) CDb3Base::GetEventContact(HANDLE hDbEvent) return (HANDLE)dbe->ofsPrev;
}
-STDMETHODIMP_(HANDLE) CDb3Base::FindFirstEvent(HANDLE hContact)
+STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstEvent(HANDLE hContact)
{
mir_cslock lck(m_csDbAccess);
if (hContact == 0)
@@ -332,7 +332,7 @@ STDMETHODIMP_(HANDLE) CDb3Base::FindFirstEvent(HANDLE hContact) return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsFirstEvent;
}
-STDMETHODIMP_(HANDLE) CDb3Base::FindFirstUnreadEvent(HANDLE hContact)
+STDMETHODIMP_(HANDLE) CDb3Mmap::FindFirstUnreadEvent(HANDLE hContact)
{
mir_cslock lck(m_csDbAccess);
if (hContact == 0)
@@ -342,7 +342,7 @@ STDMETHODIMP_(HANDLE) CDb3Base::FindFirstUnreadEvent(HANDLE hContact) return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsFirstUnreadEvent;
}
-STDMETHODIMP_(HANDLE) CDb3Base::FindLastEvent(HANDLE hContact)
+STDMETHODIMP_(HANDLE) CDb3Mmap::FindLastEvent(HANDLE hContact)
{
mir_cslock lck(m_csDbAccess);
if (hContact == 0)
@@ -352,14 +352,14 @@ STDMETHODIMP_(HANDLE) CDb3Base::FindLastEvent(HANDLE hContact) return (dbc->signature != DBCONTACT_SIGNATURE) ? 0 : (HANDLE)dbc->ofsLastEvent;
}
-STDMETHODIMP_(HANDLE) CDb3Base::FindNextEvent(HANDLE hDbEvent)
+STDMETHODIMP_(HANDLE) CDb3Mmap::FindNextEvent(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
return (dbe->signature != DBEVENT_SIGNATURE) ? 0 : (HANDLE)dbe->ofsNext;
}
-STDMETHODIMP_(HANDLE) CDb3Base::FindPrevEvent(HANDLE hDbEvent)
+STDMETHODIMP_(HANDLE) CDb3Mmap::FindPrevEvent(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
DBEvent *dbe = (DBEvent*)DBRead(hDbEvent, sizeof(DBEvent), NULL);
diff --git a/plugins/Db3x_mmap/src/dbheaders.cpp b/plugins/Db3x_mmap/src/dbheaders.cpp index 97e7b915fe..de8ce57bac 100644 --- a/plugins/Db3x_mmap/src/dbheaders.cpp +++ b/plugins/Db3x_mmap/src/dbheaders.cpp @@ -25,13 +25,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //the cache has not been loaded when these functions are used
-int CDb3Base::CreateDbHeaders(const DBSignature& _sign)
+int CDb3Mmap::CreateDbHeaders(const DBSignature& _sign)
{
DWORD bytesWritten;
CopyMemory(m_dbHeader.signature, &_sign, sizeof(m_dbHeader.signature));
- m_dbHeader.version = DB_THIS_VERSION;
+ m_dbHeader.version = DB_095_VERSION;
m_dbHeader.ofsFileEnd = sizeof(struct DBHeader);
m_dbHeader.slackSpace = 0;
m_dbHeader.contactCount = 0;
@@ -52,14 +52,14 @@ int CDb3Base::CreateDbHeaders(const DBSignature& _sign) return 0;
}
-int CDb3Base::CheckDbHeaders()
+int CDb3Mmap::CheckDbHeaders()
{
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)))
return EGROKPRF_UNKHEADER;
- if (m_dbHeader.version != DB_THIS_VERSION && m_dbHeader.version != DB_OLD_VERSION)
+ if (m_dbHeader.version != DB_095_VERSION && m_dbHeader.version != DB_094_VERSION && m_dbHeader.version != DB_OLD_VERSION)
return EGROKPRF_VERNEWER;
if (m_dbHeader.ofsUser == 0)
@@ -68,7 +68,7 @@ int CDb3Base::CheckDbHeaders() return 0;
}
-void CDb3Base::WriteSignature(DBSignature &sign)
+void CDb3Mmap::WriteSignature(DBSignature &sign)
{
memcpy(&m_dbHeader.signature, &sign, sizeof(DBSignature));
DBWrite(0, &sign, sizeof(DBSignature));
diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp index 07634ae46d..3481ccccb0 100644 --- a/plugins/Db3x_mmap/src/dbintf.cpp +++ b/plugins/Db3x_mmap/src/dbintf.cpp @@ -43,10 +43,11 @@ static int stringCompare2(const char *p1, const char *p2) return strcmp(p1, p2);
}
-CDb3Base::CDb3Base(const TCHAR *tszFileName) :
+CDb3Mmap::CDb3Mmap(const TCHAR *tszFileName) :
m_hDbFile(INVALID_HANDLE_VALUE),
m_safetyMode(true),
m_bReadOnly(true),
+ m_dwMaxContactId(1),
m_lMods(50, ModCompare),
m_lOfs(50, OfsCompare),
m_lResidentSettings(50, stringCompare2)
@@ -64,7 +65,7 @@ CDb3Base::CDb3Base(const TCHAR *tszFileName) : m_hModHeap = HeapCreate(0, 0, 0);
}
-CDb3Base::~CDb3Base()
+CDb3Mmap::~CDb3Mmap()
{
// destroy modules
HeapDestroy(m_hModHeap);
@@ -102,9 +103,11 @@ CDb3Base::~CDb3Base() DestroyDbInstance(this);
mir_free(m_tszProfileName);
+
+ free(m_pNull);
}
-int CDb3Base::Load(bool bSkipInit)
+int CDb3Mmap::Load(bool bSkipInit)
{
log0("DB logging running");
@@ -121,11 +124,25 @@ int CDb3Base::Load(bool bSkipInit) return EGROKPRF_CANTREAD;
}
+ if (!memcmp(&m_dbHeader.signature, &dbSignatureSA, sizeof(m_dbHeader.signature)))
+ memcpy(&m_dbHeader.signature, &dbSignatureIM, sizeof(m_dbHeader.signature));
+
if (!bSkipInit) {
m_bReadOnly = false;
- if (InitCache()) return 1;
+ if (InitMap()) return 1;
if (InitModuleNames()) return 1;
+ if (InitCrypt()) return EGROKPRF_CANTREAD;
+
+ // everything is ok, go on
+ if (m_dbHeader.version < DB_095_VERSION) {
+ ConvertContacts();
+
+ m_dbHeader.version = DB_095_VERSION;
+ DBWrite(sizeof(dbSignatureU), &m_dbHeader.version, sizeof(m_dbHeader.version));
+ }
+
+ FillContacts();
// we don't need events in the service mode
if (ServiceExists(MS_DB_SETSAFETYMODE)) {
@@ -138,66 +155,61 @@ int CDb3Base::Load(bool bSkipInit) hEventFilterAddedEvent = CreateHookableEvent(ME_DB_EVENT_FILTER_ADD);
}
}
- return 0;
+
+ return ERROR_SUCCESS;
}
-int CDb3Base::Create()
+int CDb3Mmap::Create()
{
m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
return (m_hDbFile == INVALID_HANDLE_VALUE);
}
-STDMETHODIMP_(void) CDb3Base::SetCacheSafetyMode(BOOL bIsSet)
-{
- { mir_cslock lck(m_csDbAccess);
- m_safetyMode = bIsSet != 0;
- }
- DBFlush(1);
-}
-
-void CDb3Base::EncodeCopyMemory(void *dst, void *src, size_t size)
+int CDb3Mmap::PrepareCheck()
{
- MoveMemory(dst, src, size);
-}
+ int ret = CheckDbHeaders();
+ if (ret != ERROR_SUCCESS)
+ return ret;
-void CDb3Base::DecodeCopyMemory(void *dst, void *src, size_t size)
-{
- MoveMemory(dst, src, size);
-}
+ InitMap();
+ InitModuleNames();
+ if ((ret = InitCrypt()) != ERROR_SUCCESS)
+ return ret;
-void CDb3Base::EncodeDBWrite(DWORD ofs, void *src, int size)
-{
- DBWrite(ofs, src, size);
+ return ERROR_SUCCESS;
}
-void CDb3Base::DecodeDBWrite(DWORD ofs, void *src, int size)
+STDMETHODIMP_(void) CDb3Mmap::SetCacheSafetyMode(BOOL bIsSet)
{
- DBWrite(ofs, src, size);
+ { mir_cslock lck(m_csDbAccess);
+ m_safetyMode = bIsSet != 0;
+ }
+ DBFlush(1);
}
///////////////////////////////////////////////////////////////////////////////
// MIDatabaseChecker
-typedef int (CDb3Base::*CheckWorker)(int);
+typedef int (CDb3Mmap::*CheckWorker)(int);
static CheckWorker Workers[6] =
{
- &CDb3Base::WorkInitialChecks,
- &CDb3Base::WorkModuleChain,
- &CDb3Base::WorkUser,
- &CDb3Base::WorkContactChain,
- &CDb3Base::WorkAggressive,
- &CDb3Base::WorkFinalTasks
+ &CDb3Mmap::WorkInitialChecks,
+ &CDb3Mmap::WorkModuleChain,
+ &CDb3Mmap::WorkUser,
+ &CDb3Mmap::WorkContactChain,
+ &CDb3Mmap::WorkAggressive,
+ &CDb3Mmap::WorkFinalTasks
};
-int CDb3Base::Start(DBCHeckCallback *callback)
+int CDb3Mmap::Start(DBCHeckCallback *callback)
{
cb = callback;
ReMap(0);
return ERROR_SUCCESS;
}
-int CDb3Base::CheckDb(int phase, int firstTime)
+int CDb3Mmap::CheckDb(int phase, int firstTime)
{
if (phase >= SIZEOF(Workers))
return ERROR_OUT_OF_PAPER;
@@ -205,7 +217,7 @@ int CDb3Base::CheckDb(int phase, int firstTime) return (this->*Workers[phase])(firstTime);
}
-void CDb3Base::Destroy()
+void CDb3Mmap::Destroy()
{
delete this;
}
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h index 129ef0b3c8..284a5842d9 100644 --- a/plugins/Db3x_mmap/src/dbintf.h +++ b/plugins/Db3x_mmap/src/dbintf.h @@ -45,7 +45,8 @@ DBHeader */
#define DB_OLD_VERSION 0x00000700u
-#define DB_THIS_VERSION 0x00000701u
+#define DB_094_VERSION 0x00000701u
+#define DB_095_VERSION 0x00000800u
#define DB_SETTINGS_RESIZE_GRANULARITY 128
@@ -111,6 +112,7 @@ struct DBContact 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 dwContactID;
};
#define DBMODULENAME_SIGNATURE 0x4DDECADEu
@@ -153,16 +155,25 @@ struct DBEvent #include <poppack.h>
-struct CDb3Base : public MIDatabase, public MIDatabaseChecker, public MZeroedObject
+struct CDb3Mmap : public MIDatabase, public MIDatabaseChecker, public MZeroedObject
{
- CDb3Base(const TCHAR* tszFileName);
- ~CDb3Base();
+ CDb3Mmap(const TCHAR* tszFileName);
+ ~CDb3Mmap();
int Load(bool bSkipInit);
int Create(void);
int CreateDbHeaders(const DBSignature&);
int CheckDbHeaders();
+ void ToggleEncryption(void);
+ void StoreKey(void);
+ void SetPassword(const TCHAR *ptszPassword);
+ void UpdateMenuItem(void);
+
+ int PrepareCheck(void);
+
+ __forceinline LPSTR GetMenuTitle() const { return m_bUsesPassword ? LPGEN("Change/remove password") : LPGEN("Set password"); }
+
void DatabaseCorruption(TCHAR *text);
void WriteSignature(DBSignature&);
@@ -212,12 +223,6 @@ protected: STDMETHODIMP_(VOID) Destroy();
protected:
- 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);
@@ -227,7 +232,8 @@ protected: void DBWrite(DWORD ofs, PVOID pData, int bytes);
void DBFill(DWORD ofs, int bytes);
void DBFlush(int setting);
- int InitCache(void);
+ int InitMap(void);
+ void FillContacts(void);
PBYTE m_pNull;
@@ -260,7 +266,7 @@ public: MICryptoEngine *m_crypto;
protected:
- DWORD m_dwFileSize;
+ DWORD m_dwFileSize, m_dwMaxContactId;
HANDLE hSettingChangeEvent, hContactDeletedEvent, hContactAddedEvent;
CRITICAL_SECTION m_csDbAccess;
@@ -319,30 +325,15 @@ protected: DBCHeckCallback *cb;
DWORD sourceFileSize, ofsAggrCur;
-};
-
-struct CDb3Mmap : public CDb3Base
-{
- CDb3Mmap(const TCHAR* ptszFileName);
- ~CDb3Mmap();
-
- int Load(bool bSkipInit);
-
- void ToggleEncryption(void);
- void StoreKey(void);
- void SetPassword(const TCHAR *ptszPassword);
- void UpdateMenuItem(void);
-
- int PrepareCheck(void);
- __forceinline LPSTR GetMenuTitle() const { return m_bUsesPassword ? LPGEN("Change/remove password") : LPGEN("Set password"); }
+ ////////////////////////////////////////////////////////////////////////////
+ // encryption
-protected:
- int InitCrypt(void);
+ void ConvertContacts(void);
+ int InitCrypt(void);
void ToggleEventsEncryption(HANDLE hContact);
void ToggleSettingsEncryption(HANDLE hContact);
-protected:
- 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/dbintfm.cpp b/plugins/Db3x_mmap/src/dbintfm.cpp deleted file mode 100644 index 0af9c6d79a..0000000000 --- a/plugins/Db3x_mmap/src/dbintfm.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/*
-
-Miranda NG: the free IM client for Microsoft* Windows*
-
-Copyright 2012-14 Miranda NG project,
-all portions of this codebase are copyrighted to the people
-listed in contributors.txt.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-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"
-
-CDb3Mmap::CDb3Mmap(const TCHAR* tszFileName) :
- CDb3Base(tszFileName)
-{
- SYSTEM_INFO sinf;
- GetSystemInfo(&sinf);
- m_ChunkSize = sinf.dwAllocationGranularity;
-}
-
-CDb3Mmap::~CDb3Mmap()
-{
- free(m_pNull);
-}
-
-int CDb3Mmap::Load(bool bSkipInit)
-{
- int res = CDb3Base::Load(bSkipInit);
- if (res)
- return res;
-
- if (!memcmp(&m_dbHeader.signature, &dbSignatureSA, sizeof(m_dbHeader.signature)))
- memcpy(&m_dbHeader.signature, &dbSignatureIM, sizeof(m_dbHeader.signature));
-
- if (!bSkipInit)
- if (InitCrypt())
- return EGROKPRF_CANTREAD;
-
- return ERROR_SUCCESS;
-}
-
-int CDb3Mmap::PrepareCheck()
-{
- int ret = CheckDbHeaders();
- if (ret != ERROR_SUCCESS)
- return ret;
-
- InitCache();
- InitModuleNames();
- if ((ret = InitCrypt()) != ERROR_SUCCESS)
- return ret;
-
- return ERROR_SUCCESS;
-}
diff --git a/plugins/Db3x_mmap/src/dbmodulechain.cpp b/plugins/Db3x_mmap/src/dbmodulechain.cpp index 3b61a236fa..bf193717bd 100644 --- a/plugins/Db3x_mmap/src/dbmodulechain.cpp +++ b/plugins/Db3x_mmap/src/dbmodulechain.cpp @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
-void CDb3Base::AddToList(char *name, DWORD len, DWORD ofs)
+void CDb3Mmap::AddToList(char *name, DWORD len, DWORD ofs)
{
ModuleName *mn = (ModuleName*)HeapAlloc(m_hModHeap,0,sizeof(ModuleName));
mn->name = name;
@@ -38,7 +38,7 @@ void CDb3Base::AddToList(char *name, DWORD len, DWORD ofs) m_lOfs.insert(mn);
}
-int CDb3Base::InitModuleNames(void)
+int CDb3Mmap::InitModuleNames(void)
{
DWORD ofsThis = m_dbHeader.ofsFirstModuleName;
DBModuleName *dbmn = (struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
@@ -60,7 +60,7 @@ int CDb3Base::InitModuleNames(void) return 0;
}
-DWORD CDb3Base::FindExistingModuleNameOfs(const char *szName)
+DWORD CDb3Mmap::FindExistingModuleNameOfs(const char *szName)
{
ModuleName mn = { (char*)szName, 0 };
if (m_lastmn && !strcmp(mn.name, m_lastmn->name))
@@ -77,7 +77,7 @@ DWORD CDb3Base::FindExistingModuleNameOfs(const char *szName) }
//will create the offset if it needs to
-DWORD CDb3Base::GetModuleNameOfs(const char *szName)
+DWORD CDb3Mmap::GetModuleNameOfs(const char *szName)
{
struct DBModuleName dbmn;
int nameLen;
@@ -109,7 +109,7 @@ DWORD CDb3Base::GetModuleNameOfs(const char *szName) return ofsNew;
}
-char* CDb3Base::GetModuleNameByOfs(DWORD ofs)
+char* CDb3Mmap::GetModuleNameByOfs(DWORD ofs)
{
if (m_lastmn && m_lastmn->ofs == ofs)
return m_lastmn->name;
@@ -126,7 +126,7 @@ char* CDb3Base::GetModuleNameByOfs(DWORD ofs) return NULL;
}
-STDMETHODIMP_(BOOL) CDb3Base::EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam)
+STDMETHODIMP_(BOOL) CDb3Mmap::EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam)
{
for (int i = 0; i < m_lMods.getCount(); i++) {
ModuleName *pmn = m_lMods[i];
diff --git a/plugins/Db3x_mmap/src/dbsettings.cpp b/plugins/Db3x_mmap/src/dbsettings.cpp index a0d91e5281..4ea08ca479 100644 --- a/plugins/Db3x_mmap/src/dbsettings.cpp +++ b/plugins/Db3x_mmap/src/dbsettings.cpp @@ -28,7 +28,7 @@ DBCachedContact* AddToCachedContactList(HANDLE hContact, int index); #define VLT(n) ((n == DBVT_UTF8 || n == DBVT_ENCRYPTED)?DBVT_ASCIIZ:n)
-BOOL CDb3Base::IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting)
+BOOL CDb3Mmap::IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting)
{
if (!_strnicmp(szSetting, "password", 8)) return true;
if (!strcmp(szSetting, "NLProxyAuthPassword")) return true;
@@ -45,7 +45,7 @@ BOOL CDb3Base::IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting) /////////////////////////////////////////////////////////////////////////////////////////
-int CDb3Base::GetContactSettingWorker(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic)
+int CDb3Mmap::GetContactSettingWorker(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic)
{
if (szSetting == NULL || szModule == NULL)
return 1;
@@ -133,8 +133,8 @@ int CDb3Base::GetContactSettingWorker(HANDLE hContact, LPCSTR szModule, LPCSTR s return 2;
case DBVT_BYTE: dbv->bVal = pBlob[1]; break;
- case DBVT_WORD: DecodeCopyMemory(&(dbv->wVal), (PWORD)(pBlob + 1), 2); break;
- case DBVT_DWORD: DecodeCopyMemory(&(dbv->dVal), (PDWORD)(pBlob + 1), 4); break;
+ case DBVT_WORD: MoveMemory(&(dbv->wVal), (PWORD)(pBlob + 1), 2); break;
+ case DBVT_DWORD: MoveMemory(&(dbv->dVal), (PDWORD)(pBlob + 1), 4); break;
case DBVT_UTF8:
case DBVT_ASCIIZ:
@@ -144,13 +144,13 @@ int CDb3Base::GetContactSettingWorker(HANDLE hContact, LPCSTR szModule, LPCSTR s dbv->cchVal--;
if (varLen < dbv->cchVal)
dbv->cchVal = varLen;
- DecodeCopyMemory(dbv->pszVal, pBlob + 3, dbv->cchVal); // decode
+ MoveMemory(dbv->pszVal, pBlob + 3, dbv->cchVal); // decode
dbv->pszVal[dbv->cchVal] = 0;
dbv->cchVal = varLen;
}
else {
dbv->pszVal = (char*)mir_alloc(1 + varLen);
- DecodeCopyMemory(dbv->pszVal, pBlob + 3, varLen);
+ MoveMemory(dbv->pszVal, pBlob + 3, varLen);
dbv->pszVal[varLen] = 0;
}
break;
@@ -161,11 +161,11 @@ int CDb3Base::GetContactSettingWorker(HANDLE hContact, LPCSTR szModule, LPCSTR s if (isStatic) {
if (varLen < dbv->cpbVal)
dbv->cpbVal = varLen;
- DecodeCopyMemory(dbv->pbVal, pBlob + 3, dbv->cpbVal);
+ MoveMemory(dbv->pbVal, pBlob + 3, dbv->cpbVal);
}
else {
dbv->pbVal = (BYTE *)mir_alloc(varLen);
- DecodeCopyMemory(dbv->pbVal, pBlob + 3, varLen);
+ MoveMemory(dbv->pbVal, pBlob + 3, varLen);
}
dbv->cpbVal = varLen;
break;
@@ -223,7 +223,7 @@ int CDb3Base::GetContactSettingWorker(HANDLE hContact, LPCSTR szModule, LPCSTR s return 1;
}
-STDMETHODIMP_(BOOL) CDb3Base::GetContactSetting(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
+STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSetting(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
{
dbv->type = 0;
if (GetContactSettingWorker(hContact, szModule, szSetting, dbv, 0))
@@ -258,7 +258,7 @@ STDMETHODIMP_(BOOL) CDb3Base::GetContactSetting(HANDLE hContact, LPCSTR szModule return 0;
}
-STDMETHODIMP_(BOOL) CDb3Base::GetContactSettingStr(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
+STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStr(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
{
int iSaveType = dbv->type;
@@ -305,7 +305,7 @@ STDMETHODIMP_(BOOL) CDb3Base::GetContactSettingStr(HANDLE hContact, LPCSTR szMod return 0;
}
-STDMETHODIMP_(BOOL) CDb3Base::GetContactSettingStatic(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
+STDMETHODIMP_(BOOL) CDb3Mmap::GetContactSettingStatic(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
{
if (GetContactSettingWorker(hContact, szModule, szSetting, dbv, 1))
return 1;
@@ -318,7 +318,7 @@ STDMETHODIMP_(BOOL) CDb3Base::GetContactSettingStatic(HANDLE hContact, LPCSTR sz return 0;
}
-STDMETHODIMP_(BOOL) CDb3Base::FreeVariant(DBVARIANT *dbv)
+STDMETHODIMP_(BOOL) CDb3Mmap::FreeVariant(DBVARIANT *dbv)
{
if (dbv == 0) return 1;
@@ -338,7 +338,7 @@ STDMETHODIMP_(BOOL) CDb3Base::FreeVariant(DBVARIANT *dbv) return 0;
}
-STDMETHODIMP_(BOOL) CDb3Base::SetSettingResident(BOOL bIsResident, const char *pszSettingName)
+STDMETHODIMP_(BOOL) CDb3Mmap::SetSettingResident(BOOL bIsResident, const char *pszSettingName)
{
char *szSetting = m_cache->GetCachedSetting(NULL, pszSettingName, 0, (int)strlen(pszSettingName));
szSetting[-1] = (char)bIsResident;
@@ -355,7 +355,7 @@ STDMETHODIMP_(BOOL) CDb3Base::SetSettingResident(BOOL bIsResident, const char *p return 0;
}
-STDMETHODIMP_(BOOL) CDb3Base::WriteContactSetting(HANDLE hContact, DBCONTACTWRITESETTING *dbcws)
+STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(HANDLE hContact, DBCONTACTWRITESETTING *dbcws)
{
if (dbcws == NULL || dbcws->szSetting == NULL || dbcws->szModule == NULL || m_bReadOnly)
return 1;
@@ -550,17 +550,17 @@ LBL_WriteString: 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_WORD: DBWrite(ofsBlobPtr, &dbcwWork.value.wVal, 2); break;
+ case DBVT_DWORD: DBWrite(ofsBlobPtr, &dbcwWork.value.dVal, 4); break;
case DBVT_BLOB:
- EncodeDBWrite(ofsBlobPtr + 2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal);
+ DBWrite(ofsBlobPtr + 2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal);
break;
case DBVT_ENCRYPTED:
DBWrite(ofsBlobPtr + 2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal);
break;
case DBVT_UTF8:
case DBVT_ASCIIZ:
- EncodeDBWrite(ofsBlobPtr + 2, dbcwWork.value.pszVal, dbcwWork.value.cchVal);
+ DBWrite(ofsBlobPtr + 2, dbcwWork.value.pszVal, dbcwWork.value.cchVal);
break;
}
// quit
@@ -637,12 +637,12 @@ LBL_WriteString: MoveAlong(1);
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_WORD: DBWrite(ofsBlobPtr, &dbcwWork.value.wVal, 2); MoveAlong(2); break;
+ case DBVT_DWORD: DBWrite(ofsBlobPtr, &dbcwWork.value.dVal, 4); MoveAlong(4); break;
case DBVT_BLOB:
DBWrite(ofsBlobPtr, &dbcwWork.value.cpbVal, 2);
- EncodeDBWrite(ofsBlobPtr + 2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal);
+ DBWrite(ofsBlobPtr + 2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal);
MoveAlong(2 + dbcwWork.value.cpbVal);
break;
@@ -654,7 +654,7 @@ LBL_WriteString: case DBVT_UTF8: case DBVT_ASCIIZ:
DBWrite(ofsBlobPtr, &dbcwWork.value.cchVal, 2);
- EncodeDBWrite(ofsBlobPtr + 2, dbcwWork.value.pszVal, dbcwWork.value.cchVal);
+ DBWrite(ofsBlobPtr + 2, dbcwWork.value.pszVal, dbcwWork.value.cchVal);
MoveAlong(2 + dbcwWork.value.cchVal);
break;
}
@@ -671,7 +671,7 @@ LBL_WriteString: return 0;
}
-STDMETHODIMP_(BOOL) CDb3Base::DeleteContactSetting(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting)
+STDMETHODIMP_(BOOL) CDb3Mmap::DeleteContactSetting(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting)
{
if (!szModule || !szSetting)
return 1;
@@ -755,7 +755,7 @@ STDMETHODIMP_(BOOL) CDb3Base::DeleteContactSetting(HANDLE hContact, LPCSTR szMod return 0;
}
-STDMETHODIMP_(BOOL) CDb3Base::EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces)
+STDMETHODIMP_(BOOL) CDb3Mmap::EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces)
{
if (!dbces->szModule)
return -1;
@@ -793,7 +793,7 @@ STDMETHODIMP_(BOOL) CDb3Base::EnumContactSettings(HANDLE hContact, DBCONTACTENUM return result;
}
-STDMETHODIMP_(BOOL) CDb3Base::EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam)
+STDMETHODIMP_(BOOL) CDb3Mmap::EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam)
{
for (int i = 0; i < m_lResidentSettings.getCount(); i++) {
int ret = pFunc(m_lResidentSettings[i], 0, (LPARAM)pParam);
diff --git a/plugins/Db3x_mmap/src/dbtool/aggressive.cpp b/plugins/Db3x_mmap/src/dbtool/aggressive.cpp index 92266f37b3..e5146e9660 100644 --- a/plugins/Db3x_mmap/src/dbtool/aggressive.cpp +++ b/plugins/Db3x_mmap/src/dbtool/aggressive.cpp @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define BLOCKSIZE 65536
-int CDb3Base::WorkAggressive(int firstTime)
+int CDb3Mmap::WorkAggressive(int firstTime)
{
if (firstTime) {
if (!cb->bAggressive)
diff --git a/plugins/Db3x_mmap/src/dbtool/contactchain.cpp b/plugins/Db3x_mmap/src/dbtool/contactchain.cpp index d1aa5a933e..979071fad4 100644 --- a/plugins/Db3x_mmap/src/dbtool/contactchain.cpp +++ b/plugins/Db3x_mmap/src/dbtool/contactchain.cpp @@ -25,7 +25,7 @@ static DWORD ofsDestThis, ofsNextContact; static int phase;
static DBContact dbc;
-int CDb3Base::WorkContactChain(int firstTime)
+int CDb3Mmap::WorkContactChain(int firstTime)
{
int first = 0;
int ret;
diff --git a/plugins/Db3x_mmap/src/dbtool/disk.cpp b/plugins/Db3x_mmap/src/dbtool/disk.cpp index d22afb70d9..7cd4dfd88c 100644 --- a/plugins/Db3x_mmap/src/dbtool/disk.cpp +++ b/plugins/Db3x_mmap/src/dbtool/disk.cpp @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "..\commonheaders.h"
-int CDb3Base::SignatureValid(DWORD ofs, DWORD signature)
+int CDb3Mmap::SignatureValid(DWORD ofs, DWORD signature)
{
if (ofs + sizeof(DWORD) >= sourceFileSize) {
cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Invalid offset found (database truncated?)"));
@@ -30,7 +30,7 @@ int CDb3Base::SignatureValid(DWORD ofs, DWORD signature) return sig == signature;
}
-int CDb3Base::PeekSegment(DWORD ofs, PVOID buf, int cbBytes)
+int CDb3Mmap::PeekSegment(DWORD ofs, PVOID buf, int cbBytes)
{
if (ofs >= sourceFileSize) {
cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Invalid offset found"));
@@ -54,7 +54,7 @@ int CDb3Base::PeekSegment(DWORD ofs, PVOID buf, int cbBytes) return ERROR_SUCCESS;
}
-int CDb3Base::ReadSegment(DWORD ofs, PVOID buf, int cbBytes)
+int CDb3Mmap::ReadSegment(DWORD ofs, PVOID buf, int cbBytes)
{
int ret = PeekSegment(ofs, buf, cbBytes);
if (ret != ERROR_SUCCESS && ret != ERROR_HANDLE_EOF) return ret;
@@ -70,7 +70,7 @@ int CDb3Base::ReadSegment(DWORD ofs, PVOID buf, int cbBytes) return ERROR_SUCCESS;
}
-DWORD CDb3Base::WriteSegment(DWORD ofs, PVOID buf, int cbBytes)
+DWORD CDb3Mmap::WriteSegment(DWORD ofs, PVOID buf, int cbBytes)
{
DWORD bytesWritten;
if (cb->bCheckOnly) return 0xbfbfbfbf;
@@ -87,7 +87,7 @@ DWORD CDb3Base::WriteSegment(DWORD ofs, PVOID buf, int cbBytes) return ofs;
}
-int CDb3Base::ReadWrittenSegment(DWORD ofs, PVOID buf, int cbBytes)
+int CDb3Mmap::ReadWrittenSegment(DWORD ofs, PVOID buf, int cbBytes)
{
DWORD bytesRead;
if (cb->bCheckOnly) return 0xbfbfbfbf;
diff --git a/plugins/Db3x_mmap/src/dbtool/eventchain.cpp b/plugins/Db3x_mmap/src/dbtool/eventchain.cpp index 9062d2f389..362f86436d 100644 --- a/plugins/Db3x_mmap/src/dbtool/eventchain.cpp +++ b/plugins/Db3x_mmap/src/dbtool/eventchain.cpp @@ -36,7 +36,7 @@ static DWORD memsize = 0; static DBEvent* memblock = NULL;
static DBEvent* dbePrevEvent = NULL;
-void CDb3Base::ConvertOldEvent(DBEvent*& dbei)
+void CDb3Mmap::ConvertOldEvent(DBEvent*& dbei)
{
int msglen = (int)strlen((char*)dbei->blob) + 1, msglenW = 0;
if (msglen != (int)dbei->cbBlob) {
@@ -71,7 +71,7 @@ void CDb3Base::ConvertOldEvent(DBEvent*& dbei) }
}
-void CDb3Base::WriteOfsNextToPrevious(DWORD ofsPrev, DBContact *dbc, DWORD ofsNext)
+void CDb3Mmap::WriteOfsNextToPrevious(DWORD ofsPrev, DBContact *dbc, DWORD ofsNext)
{
if (ofsPrev)
WriteSegment(ofsPrev + offsetof(DBEvent, ofsNext), &ofsNext, sizeof(DWORD));
@@ -79,7 +79,7 @@ void CDb3Base::WriteOfsNextToPrevious(DWORD ofsPrev, DBContact *dbc, DWORD ofsNe dbc->ofsFirstEvent = ofsNext;
}
-void CDb3Base::FinishUp(DWORD ofsLast, DBContact *dbc)
+void CDb3Mmap::FinishUp(DWORD ofsLast, DBContact *dbc)
{
WriteOfsNextToPrevious(ofsLast, dbc, 0);
if (eventCount != dbc->eventCount)
@@ -101,7 +101,7 @@ void CDb3Base::FinishUp(DWORD ofsLast, DBContact *dbc) }
}
-DWORD CDb3Base::WriteEvent(DBEvent *dbe)
+DWORD CDb3Mmap::WriteEvent(DBEvent *dbe)
{
DWORD ofs = WriteSegment(WSOFS_END, dbe, offsetof(DBEvent, blob) + dbe->cbBlob);
if (ofs == WS_ERROR) {
@@ -113,7 +113,7 @@ DWORD CDb3Base::WriteEvent(DBEvent *dbe) return ofs;
}
-int CDb3Base::WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime)
+int CDb3Mmap::WorkEventChain(DWORD ofsContact, DBContact *dbc, int firstTime)
{
DBEvent *dbeNew, dbeOld;
DBEvent *dbePrev = NULL;
@@ -239,12 +239,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);
- DecodeCopyMemory(dbeNew->blob, pOldMemo, dbeNew->cbBlob); // decode
+ MoveMemory(dbeNew->blob, pOldMemo, dbeNew->cbBlob); // decode
ConvertOldEvent(dbeNew);
if (dbeNew->cbBlob > oldSize)
pOldMemo = (BYTE*)_alloca(dbeNew->cbBlob);
memcpy(pOldMemo, dbeNew->blob, dbeNew->cbBlob);
- EncodeCopyMemory(dbeNew->blob, pOldMemo, dbeNew->cbBlob); // encode
+ MoveMemory(dbeNew->blob, pOldMemo, dbeNew->cbBlob); // encode
}
if (dbePrev) {
diff --git a/plugins/Db3x_mmap/src/dbtool/finaltasks.cpp b/plugins/Db3x_mmap/src/dbtool/finaltasks.cpp index dc1e05463c..972999524b 100644 --- a/plugins/Db3x_mmap/src/dbtool/finaltasks.cpp +++ b/plugins/Db3x_mmap/src/dbtool/finaltasks.cpp @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "..\commonheaders.h"
-int CDb3Base::WorkFinalTasks(int firstTime)
+int CDb3Mmap::WorkFinalTasks(int firstTime)
{
FreeModuleChain();
cb->pfnAddLogMessage(STATUS_MESSAGE, TranslateT("Processing final tasks"));
diff --git a/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp b/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp index 4501162263..549c8937fe 100644 --- a/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp +++ b/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp @@ -19,23 +19,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "..\commonheaders.h"
-int CDb3Base::WorkInitialCheckHeaders()
+int CDb3Mmap::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)))
+ memcmp(m_dbHeader.signature, &dbSignatureE, sizeof(m_dbHeader.signature)))
{
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"));
+ if (m_dbHeader.version != DB_095_VERSION) {
+ cb->pfnAddLogMessage(STATUS_FATAL, TranslateT("Database version doesn't match this driver's one. Convert a database first"));
return ERROR_BAD_FORMAT;
}
return ERROR_SUCCESS;
}
-int CDb3Base::WorkInitialChecks(int firstTime)
+int CDb3Mmap::WorkInitialChecks(int firstTime)
{
sourceFileSize = GetFileSize(m_hDbFile, NULL);
if (sourceFileSize == 0) {
diff --git a/plugins/Db3x_mmap/src/dbtool/modulechain.cpp b/plugins/Db3x_mmap/src/dbtool/modulechain.cpp index c846455474..011c7eaa62 100644 --- a/plugins/Db3x_mmap/src/dbtool/modulechain.cpp +++ b/plugins/Db3x_mmap/src/dbtool/modulechain.cpp @@ -30,7 +30,7 @@ static int phase,iCurrentModName; static DWORD ofsLast;
static int last_mod = 0;
-int CDb3Base::WorkModuleChain(int firstTime)
+int CDb3Mmap::WorkModuleChain(int firstTime)
{
DBModuleName moduleName, *newModName;
@@ -115,7 +115,7 @@ int CDb3Base::WorkModuleChain(int firstTime) return ERROR_SUCCESS;
}
-DWORD CDb3Base::ConvertModuleNameOfs(DWORD ofsOld)
+DWORD CDb3Mmap::ConvertModuleNameOfs(DWORD ofsOld)
{
if (modChain[last_mod].ofsOld == ofsOld)
return modChain[last_mod].ofsNew;
@@ -130,7 +130,7 @@ DWORD CDb3Base::ConvertModuleNameOfs(DWORD ofsOld) return 0;
}
-void CDb3Base::FreeModuleChain()
+void CDb3Mmap::FreeModuleChain()
{
if (modChain != NULL) {
free(modChain);
diff --git a/plugins/Db3x_mmap/src/dbtool/settingschain.cpp b/plugins/Db3x_mmap/src/dbtool/settingschain.cpp index 1311b58661..8911f86e07 100644 --- a/plugins/Db3x_mmap/src/dbtool/settingschain.cpp +++ b/plugins/Db3x_mmap/src/dbtool/settingschain.cpp @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static DWORD ofsThisSettings, ofsDestPrevSettings;
-int CDb3Base::WorkSettingsChain(DWORD ofsContact, DBContact *dbc, int firstTime)
+int CDb3Mmap::WorkSettingsChain(DWORD ofsContact, DBContact *dbc, int firstTime)
{
DWORD ofsDestThis;
int ret;
diff --git a/plugins/Db3x_mmap/src/dbtool/user.cpp b/plugins/Db3x_mmap/src/dbtool/user.cpp index 7b56e29c06..72d403f509 100644 --- a/plugins/Db3x_mmap/src/dbtool/user.cpp +++ b/plugins/Db3x_mmap/src/dbtool/user.cpp @@ -23,7 +23,7 @@ static DBContact user; static int phase;
static DWORD ofsUser;
-int CDb3Base::WorkUser(int firstTime)
+int CDb3Mmap::WorkUser(int firstTime)
{
int first = 0;
diff --git a/plugins/Db3x_mmap/src/version.h b/plugins/Db3x_mmap/src/version.h index a354f07f84..ef422c81fb 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 11
+#define __MINOR_VERSION 95
#define __RELEASE_NUM 0
-#define __BUILD_NUM 2
+#define __BUILD_NUM 1
#include <stdver.h>
|