summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Dbx_mdb/src/commonheaders.h14
-rw-r--r--plugins/Dbx_mdb/src/dbcontacts.cpp42
-rw-r--r--plugins/Dbx_mdb/src/dbevents.cpp151
-rw-r--r--plugins/Dbx_mdb/src/dbintf.cpp10
-rw-r--r--plugins/Dbx_mdb/src/dbintf.h26
-rw-r--r--plugins/Dbx_mdb/src/dbmodulechain.cpp40
6 files changed, 164 insertions, 119 deletions
diff --git a/plugins/Dbx_mdb/src/commonheaders.h b/plugins/Dbx_mdb/src/commonheaders.h
index c9f9d4b44d..2d1a6ae580 100644
--- a/plugins/Dbx_mdb/src/commonheaders.h
+++ b/plugins/Dbx_mdb/src/commonheaders.h
@@ -48,13 +48,6 @@ extern "C"
#include "lmdb\lmdb.h"
};
-#include "dbintf.h"
-#include "resource.h"
-#include "version.h"
-
-extern HINSTANCE g_hInst;
-extern LIST<CDbxMdb> g_Dbs;
-
class txn_ptr
{
MDB_txn *m_txn;
@@ -107,6 +100,13 @@ public:
__forceinline operator MDB_cursor*() const { return m_cursor; }
};
+#include "dbintf.h"
+#include "resource.h"
+#include "version.h"
+
+extern HINSTANCE g_hInst;
+extern LIST<CDbxMdb> g_Dbs;
+
#ifdef __GNUC__
#define mir_i64(x) (x##LL)
#else
diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp
index 14267ab9ff..094cb0331e 100644
--- a/plugins/Dbx_mdb/src/dbcontacts.cpp
+++ b/plugins/Dbx_mdb/src/dbcontacts.cpp
@@ -58,6 +58,10 @@ STDMETHODIMP_(MCONTACT) CDbxMdb::FindFirstContact(const char *szProto)
if (cc == NULL)
return NULL;
+ if (cc->contactID == 0)
+ if ((cc = m_cache->GetNextContact(0)) == NULL)
+ return NULL;
+
if (!szProto || CheckProto(cc, szProto))
return cc->contactID;
@@ -92,7 +96,7 @@ STDMETHODIMP_(LONG) CDbxMdb::DeleteContact(MCONTACT contactID)
// delete
mir_cslock lck(m_csDbAccess);
- MDB_val key = { sizeof(DWORD), &contactID };
+ MDB_val key = { sizeof(MCONTACT), &contactID };
for (;; Remap()) {
txn_ptr trnlck(m_pMdbEnv);
@@ -106,15 +110,15 @@ STDMETHODIMP_(LONG) CDbxMdb::DeleteContact(MCONTACT contactID)
STDMETHODIMP_(MCONTACT) CDbxMdb::AddContact()
{
DWORD dwContactId;
-
- DBContact dbc = { 0 };
- dbc.signature = DBCONTACT_SIGNATURE;
{
mir_cslock lck(m_csDbAccess);
dwContactId = m_dwMaxContactId++;
- MDB_val key = { sizeof(DWORD), &dwContactId };
- MDB_val data = { sizeof(DBContact), &dbc };
+ DBCachedContact *cc = m_cache->AddContactToCache(dwContactId);
+ cc->dbc.dwSignature = DBCONTACT_SIGNATURE;
+
+ MDB_val key = { sizeof(MCONTACT), &dwContactId };
+ MDB_val data = { sizeof(cc->dbc), &cc->dbc };
for (;; Remap()) {
txn_ptr trnlck(m_pMdbEnv);
@@ -122,8 +126,6 @@ STDMETHODIMP_(MCONTACT) CDbxMdb::AddContact()
if (trnlck.commit())
break;
}
-
- m_cache->AddContactToCache(dwContactId);
}
NotifyEventHooks(hContactAddedEvent, dwContactId, 0);
@@ -170,6 +172,21 @@ BOOL CDbxMdb::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
}
/////////////////////////////////////////////////////////////////////////////////////////
+
+void DBCachedContact::Advance(DWORD id, DBEvent &dbe)
+{
+ dbc.dwEventCount++;
+
+ if (dbe.flags & (DBEF_READ | DBEF_SENT))
+ return;
+
+ if (dbe.timestamp < dbc.tsFirstUnread || dbc.tsFirstUnread == 0) {
+ dbc.tsFirstUnread = dbe.timestamp;
+ dbc.dwFirstUnread = id;
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
// initial cycle to fill the contacts' cache
void CDbxMdb::FillContacts()
@@ -184,13 +201,14 @@ void CDbxMdb::FillContacts()
MDB_val key, data;
while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == 0) {
DBContact *dbc = (DBContact*)data.mv_data;
- if (dbc->signature != DBCONTACT_SIGNATURE)
+ if (dbc->dwSignature != DBCONTACT_SIGNATURE)
DatabaseCorruption(NULL);
DBCachedContact *cc = m_cache->AddContactToCache(*(DWORD*)key.mv_data);
- cc->dwEventCount = dbc->eventCount;
- cc->dwFirstUnread = dbc->dwFirstUnread;
- cc->tsFirstUnread = dbc->tsFirstUnread;
+ cc->dbc.dwSignature = DBCONTACT_SIGNATURE;
+ cc->dbc.dwEventCount = dbc->dwEventCount;
+ cc->dbc.dwFirstUnread = dbc->dwFirstUnread;
+ cc->dbc.tsFirstUnread = dbc->tsFirstUnread;
arContacts.insert(cc);
}
}
diff --git a/plugins/Dbx_mdb/src/dbevents.cpp b/plugins/Dbx_mdb/src/dbevents.cpp
index 720956817d..ce7f23fe3f 100644
--- a/plugins/Dbx_mdb/src/dbevents.cpp
+++ b/plugins/Dbx_mdb/src/dbevents.cpp
@@ -23,19 +23,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
-struct DBEventSortingKey
-{
- DWORD dwContactId, ts, dwEventId;
-};
-
STDMETHODIMP_(LONG) CDbxMdb::GetEventCount(MCONTACT contactID)
{
- mir_cslock lck(m_csDbAccess);
- if (contactID == NULL)
- return m_header.eventCount;
-
DBCachedContact *cc = m_cache->GetCachedContact(contactID);
- return (cc == NULL) ? 0 : cc->dwEventCount;
+ return (cc == NULL) ? 0 : cc->dbc.dwEventCount;
}
STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
@@ -44,7 +35,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
if (dbei->timestamp == 0) return 0;
DBEvent dbe;
- dbe.signature = DBEVENT_SIGNATURE;
+ dbe.dwSignature = DBEVENT_SIGNATURE;
dbe.contactID = contactID; // store native or subcontact's id
dbe.ofsModuleName = GetModuleNameOfs(dbei->szModule);
dbe.timestamp = dbei->timestamp;
@@ -54,24 +45,23 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
BYTE *pBlob = dbei->pBlob;
MCONTACT contactNotifyID = contactID;
- DBCachedContact *cc = NULL, *ccSub = NULL;
- if (contactID != 0) {
- if ((cc = m_cache->GetCachedContact(contactID)) == NULL)
- return 0;
+ DBCachedContact *cc, *ccSub = NULL;
+ if ((cc = m_cache->GetCachedContact(contactID)) == NULL)
+ return 0;
- if (cc->IsSub()) {
- ccSub = cc;
- // set default sub to the event's source
- if (!(dbei->flags & DBEF_SENT))
- db_mc_setDefault(cc->parentID, contactID, false);
- contactID = cc->parentID; // and add an event to a metahistory
- if (db_mc_isEnabled())
- contactNotifyID = contactID;
- }
+ if (cc->IsSub()) {
+ ccSub = cc;
+ // set default sub to the event's source
+ if (!(dbei->flags & DBEF_SENT))
+ db_mc_setDefault(cc->parentID, contactID, false);
+ contactID = cc->parentID; // and add an event to a metahistory
+ if (db_mc_isEnabled())
+ contactNotifyID = contactID;
}
- if (NotifyEventHooks(hEventFilterAddedEvent, contactNotifyID, (LPARAM)dbei))
- return NULL;
+ if (m_safetyMode)
+ if (NotifyEventHooks(hEventFilterAddedEvent, contactNotifyID, (LPARAM)dbei))
+ return NULL;
mir_ptr<BYTE> pCryptBlob;
if (m_bEncrypted) {
@@ -85,7 +75,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
}
mir_cslockfull lck(m_csDbAccess);
- DWORD dwEventId = (contactID == NULL) ? ++m_header.eventCount : ++m_dwMaxEventId;
+ DWORD dwEventId = ++m_dwMaxEventId;
txn_ptr txn(m_pMdbEnv);
@@ -105,26 +95,19 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
if (mdb_put(txn, m_dbEventsSort, &key, &data, 0) != MDB_SUCCESS)
return 0;
- if (contactID != NULL) {
- DBContact dbc = { DBCONTACT_SIGNATURE, ++cc->dwEventCount };
- MDB_val keyc = { sizeof(int), &contactID }, datac = { sizeof(DBContact), &dbc };
- mdb_put(txn, m_dbContacts, &keyc, &datac, 0);
+ cc->Advance(dwEventId, dbe);
+ MDB_val keyc = { sizeof(int), &contactID }, datac = { sizeof(DBContact), &cc->dbc };
+ mdb_put(txn, m_dbContacts, &keyc, &datac, 0);
- // insert an event into a sub's history too
- if (ccSub != NULL) {
- key2.dwContactId = ccSub->contactID;
- mdb_put(txn, m_dbEventsSort, &key, &data, 0);
+ // insert an event into a sub's history too
+ if (ccSub != NULL) {
+ key2.dwContactId = ccSub->contactID;
+ mdb_put(txn, m_dbEventsSort, &key, &data, 0);
- dbc.eventCount = ++ccSub->dwEventCount;
- keyc.mv_data = &ccSub->contactID;
- mdb_put(txn, m_dbContacts, &keyc, &datac, 0);
- }
- }
- else {
- DWORD keyVal = 1;
- MDB_val key = { sizeof(DWORD), &keyVal };
- data.mv_data = &m_header; data.mv_size = sizeof(m_header);
- mdb_put(txn, m_dbGlobal, &key, &data, 0);
+ ccSub->Advance(dwEventId, dbe);
+ datac.mv_data = &ccSub->dbc;
+ keyc.mv_data = &ccSub->contactID;
+ mdb_put(txn, m_dbContacts, &keyc, &datac, 0);
}
if (txn.commit())
@@ -134,13 +117,18 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
lck.unlock();
// Notify only in safe mode or on really new events
- NotifyEventHooks(hEventAddedEvent, contactNotifyID, dwEventId);
+ if (m_safetyMode)
+ NotifyEventHooks(hEventAddedEvent, contactNotifyID, dwEventId);
return dwEventId;
}
STDMETHODIMP_(BOOL) CDbxMdb::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent)
{
+ DBCachedContact *cc = m_cache->GetCachedContact(contactID);
+ if (cc == NULL || cc->dbc.dwEventCount == 0)
+ return 1;
+
mir_cslockfull lck(m_csDbAccess);
txn_ptr txn(m_pMdbEnv);
@@ -164,6 +152,12 @@ STDMETHODIMP_(BOOL) CDbxMdb::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent)
mdb_del(txn, m_dbEventsSort, &key, &data);
}
+ // update a contact
+ key.mv_size = sizeof(int); key.mv_data = &contactID;
+ cc->dbc.dwEventCount--;
+ if (cc->dbc.dwFirstUnread == hDbEvent)
+ FindNextUnread(txn, cc, key2);
+
if (txn.commit())
break;
}
@@ -187,7 +181,7 @@ STDMETHODIMP_(LONG) CDbxMdb::GetBlobSize(MEVENT hDbEvent)
return 0;
DBEvent *dbe = (DBEvent*)data.mv_data;
- return (dbe->signature == DBEVENT_SIGNATURE) ? dbe->cbBlob : 0;
+ return (dbe->dwSignature == DBEVENT_SIGNATURE) ? dbe->cbBlob : 0;
}
STDMETHODIMP_(BOOL) CDbxMdb::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
@@ -206,7 +200,7 @@ STDMETHODIMP_(BOOL) CDbxMdb::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
return 1;
DBEvent *dbe = (DBEvent*)data.mv_data;
- if (dbe->signature != DBEVENT_SIGNATURE)
+ if (dbe->dwSignature != DBEVENT_SIGNATURE)
return 1;
dbei->szModule = GetModuleNameByOfs(dbe->ofsModuleName);
@@ -234,17 +228,30 @@ STDMETHODIMP_(BOOL) CDbxMdb::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
return 0;
}
+void CDbxMdb::FindNextUnread(const txn_ptr &txn, DBCachedContact *cc, DBEventSortingKey &key2)
+{
+ cursor_ptr cursor(txn, m_dbEventsSort);
+
+ MDB_val key = { sizeof(key2), &key2 }, data;
+ key2.dwEventId++;
+ mdb_cursor_get(cursor, &key, &data, MDB_SET_KEY);
+ while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == 0) {
+ DBEvent *dbe = (DBEvent*)data.mv_data;
+ if (!dbe->markedRead()) {
+ cc->dbc.dwFirstUnread = key2.dwEventId;
+ cc->dbc.tsFirstUnread = key2.ts;
+ return;
+ }
+ }
+
+ cc->dbc.dwFirstUnread = cc->dbc.tsFirstUnread = 0;
+}
+
STDMETHODIMP_(BOOL) CDbxMdb::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent)
{
- DBCachedContact *cc;
- if (contactID) {
- if ((cc = m_cache->GetCachedContact(contactID)) == NULL)
- return -1;
- if (cc->IsSub())
- if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL)
- return -1;
- }
- else cc = NULL;
+ DBCachedContact *cc = m_cache->GetCachedContact(contactID);
+ if (cc == NULL)
+ return -1;
mir_cslockfull lck(m_csDbAccess);
txn_ptr txn(m_pMdbEnv);
@@ -254,14 +261,22 @@ STDMETHODIMP_(BOOL) CDbxMdb::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent)
return 0;
DBEvent *dbe = (DBEvent*)data.mv_data;
- if (dbe->signature != DBEVENT_SIGNATURE)
+ if (dbe->dwSignature != DBEVENT_SIGNATURE)
return -1;
if (dbe->markedRead())
return dbe->flags;
+ DBEventSortingKey key2 = { contactID, dbe->timestamp, hDbEvent };
+
dbe->flags |= DBEF_READ;
mdb_put(txn, m_dbEvents, &key, &data, 0);
+
+ FindNextUnread(txn, cc, key2);
+ key.mv_data = &contactID;
+ data.mv_data = &cc->dbc; data.mv_size = sizeof(cc->dbc);
+ mdb_put(txn, m_dbContacts, &key, &data, 0);
+
txn.commit();
lck.unlock();
@@ -279,7 +294,7 @@ STDMETHODIMP_(MCONTACT) CDbxMdb::GetEventContact(MEVENT hDbEvent)
return 0;
DBEvent *dbe = (DBEvent*)data.mv_data;
- return (dbe->signature == DBEVENT_SIGNATURE) ? dbe->contactID: INVALID_CONTACT_ID;
+ return (dbe->dwSignature == DBEVENT_SIGNATURE) ? dbe->contactID: INVALID_CONTACT_ID;
}
STDMETHODIMP_(MEVENT) CDbxMdb::FindFirstEvent(MCONTACT contactID)
@@ -300,8 +315,8 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindFirstEvent(MCONTACT contactID)
STDMETHODIMP_(MEVENT) CDbxMdb::FindFirstUnreadEvent(MCONTACT contactID)
{
- mir_cslock lck(m_csDbAccess);
- return NULL;
+ DBCachedContact *cc = m_cache->GetCachedContact(contactID);
+ return (cc == NULL) ? 0 : cc->dbc.dwFirstUnread;
}
STDMETHODIMP_(MEVENT) CDbxMdb::FindLastEvent(MCONTACT contactID)
@@ -331,13 +346,14 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindNextEvent(MCONTACT contactID, MEVENT hDbEvent
return 0;
DBEvent *dbe = (DBEvent*)data.mv_data;
- DBEventSortingKey keyVal = { contactID, dbe->timestamp, hDbEvent+1 };
+ DBEventSortingKey keyVal = { contactID, dbe->timestamp, hDbEvent };
key.mv_size = sizeof(keyVal); key.mv_data = &keyVal;
cursor_ptr cursor(txn, m_dbEventsSort);
if (mdb_cursor_get(cursor, &key, &data, MDB_SET_KEY) != MDB_SUCCESS)
- if (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) != MDB_SUCCESS)
- return 0;
+ return 0;
+ if (mdb_cursor_get(cursor, &key, &data, MDB_NEXT_NODUP) != MDB_SUCCESS)
+ return 0;
DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
return (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
@@ -354,13 +370,14 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent
return 0;
DBEvent *dbe = (DBEvent*)data.mv_data;
- DBEventSortingKey keyVal = { contactID, dbe->timestamp, hDbEvent - 1 };
+ DBEventSortingKey keyVal = { contactID, dbe->timestamp, hDbEvent };
key.mv_size = sizeof(keyVal); key.mv_data = &keyVal;
cursor_ptr cursor(txn, m_dbEventsSort);
if (mdb_cursor_get(cursor, &key, &data, MDB_SET_KEY) != MDB_SUCCESS)
- if (mdb_cursor_get(cursor, &key, &data, MDB_PREV) != MDB_SUCCESS)
- return 0;
+ return 0;
+ if (mdb_cursor_get(cursor, &key, &data, MDB_PREV_NODUP) != MDB_SUCCESS)
+ return 0;
DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
return (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
diff --git a/plugins/Dbx_mdb/src/dbintf.cpp b/plugins/Dbx_mdb/src/dbintf.cpp
index 01bbfe4fed..b4a13a78f3 100644
--- a/plugins/Dbx_mdb/src/dbintf.cpp
+++ b/plugins/Dbx_mdb/src/dbintf.cpp
@@ -101,17 +101,21 @@ int CDbxMdb::Load(bool bSkipInit)
MDB_val key = { sizeof(DWORD), &keyVal }, data;
if (mdb_get(trnlck, m_dbGlobal, &key, &data) == MDB_SUCCESS) {
DBHeader *hdr = (DBHeader*)data.mv_data;
- if (hdr->signature != DBHEADER_SIGNATURE)
+ if (hdr->dwSignature != DBHEADER_SIGNATURE)
DatabaseCorruption(NULL);
memcpy(&m_header, data.mv_data, sizeof(m_header));
}
else {
- m_header.signature = DBHEADER_SIGNATURE;
+ m_header.dwSignature = DBHEADER_SIGNATURE;
m_header.dwVersion = 1;
- m_header.eventCount = 0;
data.mv_data = &m_header; data.mv_size = sizeof(m_header);
mdb_put(trnlck, m_dbGlobal, &key, &data, 0);
+
+ keyVal = 0;
+ DBContact dbc = { DBCONTACT_SIGNATURE, 0, 0, 0 };
+ data.mv_data = &dbc; data.mv_size = sizeof(dbc);
+ mdb_put(trnlck, m_dbContacts, &key, &data, 0);
}
trnlck.commit();
diff --git a/plugins/Dbx_mdb/src/dbintf.h b/plugins/Dbx_mdb/src/dbintf.h
index ea3d2feb0f..5590b44c09 100644
--- a/plugins/Dbx_mdb/src/dbintf.h
+++ b/plugins/Dbx_mdb/src/dbintf.h
@@ -65,16 +65,15 @@ struct ModuleName
#define DBHEADER_SIGNATURE 0x40DECADEu
struct DBHeader
{
- DWORD signature;
+ DWORD dwSignature;
DWORD dwVersion; // database format version
- DWORD eventCount; // number of events in the chain for this contact
};
#define DBCONTACT_SIGNATURE 0x43DECADEu
struct DBContact
{
- DWORD signature;
- DWORD eventCount; // number of events in the chain for this contact
+ DWORD dwSignature;
+ DWORD dwEventCount; // number of events in the chain for this contact
DWORD tsFirstUnread;
DWORD dwFirstUnread;
};
@@ -82,7 +81,7 @@ struct DBContact
#define DBMODULENAME_SIGNATURE 0x4DDECADEu
struct DBModuleName
{
- DWORD signature;
+ DWORD dwSignature;
BYTE cbName; // number of characters in this module name
char name[1]; // name, no nul terminator
};
@@ -90,7 +89,7 @@ struct DBModuleName
#define DBEVENT_SIGNATURE 0x45DECADEu
struct DBEvent
{
- DWORD signature;
+ DWORD dwSignature;
MCONTACT contactID; // a contact this event belongs to
DWORD ofsModuleName; // offset to a DBModuleName struct of the name of
DWORD timestamp; // seconds since 00:00:00 01/01/1970
@@ -106,11 +105,16 @@ struct DBEvent
#include <poppack.h>
+struct DBEventSortingKey
+{
+ DWORD dwContactId, ts, dwEventId;
+};
+
struct DBCachedContact : public DBCachedContactBase
{
- DWORD dwEventCount;
- DWORD tsFirstUnread;
- DWORD dwFirstUnread;
+ void Advance(DWORD id, DBEvent &dbe);
+
+ DBContact dbc;
};
struct CDbxMdb : public MIDatabase, public MIDatabaseChecker, public MZeroedObject
@@ -241,6 +245,8 @@ protected:
MDB_dbi m_dbEvents, m_dbEventsSort;
DWORD m_dwMaxEventId;
+ void FindNextUnread(const txn_ptr &_txn, DBCachedContact *cc, DBEventSortingKey &key2);
+
////////////////////////////////////////////////////////////////////////////
// modules
@@ -264,7 +270,7 @@ protected:
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);
+ int SignatureValid(DWORD ofs, DWORD dwSignature);
void FreeModuleChain();
DWORD ConvertModuleNameOfs(DWORD ofsOld);
diff --git a/plugins/Dbx_mdb/src/dbmodulechain.cpp b/plugins/Dbx_mdb/src/dbmodulechain.cpp
index 1a78284d78..a42ab0b221 100644
--- a/plugins/Dbx_mdb/src/dbmodulechain.cpp
+++ b/plugins/Dbx_mdb/src/dbmodulechain.cpp
@@ -42,24 +42,24 @@ int CDbxMdb::InitModuleNames(void)
{
m_maxModuleID = 0;
- txn_ptr trnlck(m_pMdbEnv);
- mdb_open(trnlck, "modules", MDB_INTEGERKEY, &m_dbModules);
-
- cursor_ptr cursor(trnlck, m_dbModules);
- if (!cursor)
- return 1;
-
- MDB_val key, data;
- while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == 0) {
- DBModuleName *pmod = (DBModuleName*)data.mv_data;
- if (pmod->signature != DBMODULENAME_SIGNATURE)
- DatabaseCorruption(NULL);
-
- char *pVal = (char*)HeapAlloc(m_hModHeap, 0, pmod->cbName+1);
+ txn_ptr trnlck(m_pMdbEnv);
+ mdb_open(trnlck, "modules", MDB_INTEGERKEY, &m_dbModules);
+
+ cursor_ptr cursor(trnlck, m_dbModules);
+ if (!cursor)
+ return 1;
+
+ MDB_val key, data;
+ while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == 0) {
+ DBModuleName *pmod = (DBModuleName*)data.mv_data;
+ if (pmod->dwSignature != DBMODULENAME_SIGNATURE)
+ DatabaseCorruption(NULL);
+
+ char *pVal = (char*)HeapAlloc(m_hModHeap, 0, pmod->cbName+1);
memcpy(pVal, pmod->name, pmod->cbName);
pVal[pmod->cbName] = 0;
-
- int moduleId = *(int*)key.mv_data;
+
+ int moduleId = *(int*)key.mv_data;
AddToList(pVal, moduleId);
if (moduleId > m_maxModuleID)
@@ -94,15 +94,15 @@ DWORD CDbxMdb::GetModuleNameOfs(const char *szName)
// need to create the module name
int newIdx = ++m_maxModuleID;
DBModuleName *pmod = (DBModuleName*)_alloca(sizeof(DBModuleName) + nameLen);
- pmod->signature = DBMODULENAME_SIGNATURE;
+ pmod->dwSignature = DBMODULENAME_SIGNATURE;
pmod->cbName = (char)nameLen;
strcpy(pmod->name, szName);
- MDB_val key = { sizeof(int), &newIdx }, data = { sizeof(DBModuleName) + nameLen, pmod };
+ MDB_val key = { sizeof(int), &newIdx }, data = { sizeof(DBModuleName) + nameLen, pmod };
for (;; Remap()) {
- txn_ptr trnlck(m_pMdbEnv);
- mdb_open(trnlck, "modules", MDB_INTEGERKEY, &m_dbModules);
+ txn_ptr trnlck(m_pMdbEnv);
+ mdb_open(trnlck, "modules", MDB_INTEGERKEY, &m_dbModules);
mdb_put(trnlck, m_dbModules, &key, &data, 0);
if (trnlck.commit())
break;