diff options
-rw-r--r-- | plugins/Dbx_mdb/src/commonheaders.h | 1 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbcontacts.cpp | 68 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbevents.cpp | 103 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbintf.cpp | 14 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbintf.h | 61 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbmodulechain.cpp | 7 |
6 files changed, 54 insertions, 200 deletions
diff --git a/plugins/Dbx_mdb/src/commonheaders.h b/plugins/Dbx_mdb/src/commonheaders.h index aed6533011..57db50bdb3 100644 --- a/plugins/Dbx_mdb/src/commonheaders.h +++ b/plugins/Dbx_mdb/src/commonheaders.h @@ -55,7 +55,6 @@ extern "C" extern HINSTANCE g_hInst;
extern LIST<CDbxMdb> g_Dbs;
-extern DBSignature dbSignatureU, dbSignatureE, dbSignatureIM, dbSignatureSA, dbSignatureSD;
#ifdef __GNUC__
#define mir_i64(x) (x##LL)
diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp index 9d398ee4f3..ae960f8696 100644 --- a/plugins/Dbx_mdb/src/dbcontacts.cpp +++ b/plugins/Dbx_mdb/src/dbcontacts.cpp @@ -92,16 +92,29 @@ 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, data; + key.mv_size = sizeof(DWORD); key.mv_data = &dwContactId; + data.mv_size = sizeof(DBContact); data.mv_data = &dbc; + + MDB_txn *txn; + mdb_txn_begin(m_pMdbEnv, NULL, 0, &txn); + mdb_put(txn, m_dbContacts, &key, &data, 0); + mdb_txn_commit(txn); }
- DBCachedContact *cc = m_cache->AddContactToCache(dbc.dwContactID);
+ DBCachedContact *cc = m_cache->AddContactToCache(dwContactId);
+ cc->dwDriverData = 0;
- NotifyEventHooks(hContactAddedEvent, dbc.dwContactID, 0);
- return dbc.dwContactID;
+ NotifyEventHooks(hContactAddedEvent, dwContactId, 0);
+ return dwContactId;
}
STDMETHODIMP_(BOOL) CDbxMdb::IsDbContact(MCONTACT contactID)
@@ -156,42 +169,41 @@ BOOL CDbxMdb::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) /////////////////////////////////////////////////////////////////////////////////////////
// initial cycle to fill the contacts' cache
-struct COldMeta
-{
- COldMeta(DWORD _id, DBCachedContact *_cc) :
- hMetaID(_id), cc(_cc)
- {}
-
- DWORD hMetaID;
- DBCachedContact *cc;
-};
-
void CDbxMdb::FillContacts()
{
- OBJLIST<COldMeta> arMetas(10, NumericKeySortT);
-
- for (DWORD dwOffset = 0; dwOffset != 0;) {
-
- int dwContactID = 0;
- DBCachedContact *cc = m_cache->AddContactToCache(dwContactID);
- cc->dwDriverData = dwOffset;
+ m_contactCount = 0;
+
+ MDB_cursor *cursor; + mdb_cursor_open(m_txn, m_dbModules, &cursor); + + DWORD dwContactId; + DBContact value; + + MDB_val key, data; + key.mv_size = sizeof(DWORD); key.mv_data = &dwContactId; + data.mv_size = sizeof(DBContact); data.mv_data = &value; +
+ while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == 0) {
+ DBCachedContact *cc = m_cache->AddContactToCache(dwContactId);
+ cc->dwDriverData = 0;
CheckProto(cc, "");
+
+ m_dwMaxContactId = dwContactId + 1;
+ m_contactCount++;
DBVARIANT dbv; dbv.type = DBVT_DWORD;
- cc->nSubs = (0 != GetContactSetting(dwContactID, META_PROTO, "NumContacts", &dbv)) ? -1 : dbv.dVal;
+ cc->nSubs = (0 != GetContactSetting(dwContactId, META_PROTO, "NumContacts", &dbv)) ? -1 : dbv.dVal;
if (cc->nSubs != -1) {
cc->pSubs = (MCONTACT*)mir_alloc(cc->nSubs*sizeof(MCONTACT));
for (int i = 0; i < cc->nSubs; i++) {
char setting[100];
mir_snprintf(setting, SIZEOF(setting), "Handle%d", i);
- cc->pSubs[i] = (0 != GetContactSetting(dwContactID, META_PROTO, setting, &dbv)) ? NULL : dbv.dVal;
+ cc->pSubs[i] = (0 != GetContactSetting(dwContactId, META_PROTO, setting, &dbv)) ? NULL : dbv.dVal;
}
}
- cc->nDefault = (0 != GetContactSetting(dwContactID, META_PROTO, "Default", &dbv)) ? -1 : dbv.dVal;
- cc->parentID = (0 != GetContactSetting(dwContactID, META_PROTO, "ParentMeta", &dbv)) ? NULL : dbv.dVal;
-
- // whether we need conversion or not
- if (!GetContactSetting(dwContactID, META_PROTO, "MetaID", &dbv))
- arMetas.insert(new COldMeta(dbv.dVal, cc));
+ cc->nDefault = (0 != GetContactSetting(dwContactId, META_PROTO, "Default", &dbv)) ? -1 : dbv.dVal;
+ cc->parentID = (0 != GetContactSetting(dwContactId, META_PROTO, "ParentMeta", &dbv)) ? NULL : dbv.dVal;
}
+
+ mdb_cursor_close(cursor);
}
diff --git a/plugins/Dbx_mdb/src/dbevents.cpp b/plugins/Dbx_mdb/src/dbevents.cpp index cd25e6e479..dc9638b3dd 100644 --- a/plugins/Dbx_mdb/src/dbevents.cpp +++ b/plugins/Dbx_mdb/src/dbevents.cpp @@ -152,91 +152,24 @@ STDMETHODIMP_(BOOL) CDbxMdb::MarkEventRead(MCONTACT contactID, HANDLE hDbEvent) STDMETHODIMP_(MCONTACT) CDbxMdb::GetEventContact(HANDLE hDbEvent)
{
mir_cslock lck(m_csDbAccess);
- DBEvent *dbe = AdaptEvent((DWORD)hDbEvent, INVALID_CONTACT_ID);
- return (dbe->signature != DBEVENT_SIGNATURE) ? INVALID_CONTACT_ID : dbe->contactID;
+ return INVALID_CONTACT_ID;
}
STDMETHODIMP_(HANDLE) CDbxMdb::FindFirstEvent(MCONTACT contactID)
{
- DBCachedContact *cc;
-
mir_cslock lck(m_csDbAccess);
- DBContact *dbc = NULL;
- if (dbc->signature != DBCONTACT_SIGNATURE)
- return NULL;
- if (!cc || !cc->IsSub())
- return HANDLE(dbc->ofsFirstEvent);
-
- if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL)
- return NULL;
- dbc = NULL;
- if (dbc->signature != DBCONTACT_SIGNATURE)
- return NULL;
-
- for (DWORD dwOffset = dbc->ofsFirstEvent; dwOffset != 0;) {
- DBEvent *dbe = AdaptEvent(dwOffset, contactID);
- if (dbe->signature != DBEVENT_SIGNATURE)
- return NULL;
- if (dbe->contactID == contactID)
- return HANDLE(dwOffset);
- dwOffset = dbe->ofsNext;
- }
return NULL;
}
STDMETHODIMP_(HANDLE) CDbxMdb::FindFirstUnreadEvent(MCONTACT contactID)
{
- DBCachedContact *cc;
-
mir_cslock lck(m_csDbAccess);
- DBContact *dbc = NULL;
- if (dbc->signature != DBCONTACT_SIGNATURE)
- return NULL;
- if (!cc || !cc->IsSub())
- return HANDLE(dbc->ofsFirstUnread);
-
- if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL)
- return NULL;
- dbc = NULL;
- if (dbc->signature != DBCONTACT_SIGNATURE)
- return NULL;
-
- for (DWORD dwOffset = dbc->ofsFirstUnread; dwOffset != 0;) {
- DBEvent *dbe = AdaptEvent(dwOffset, contactID);
- if (dbe->signature != DBEVENT_SIGNATURE)
- return NULL;
- if (dbe->contactID == contactID && !dbe->markedRead())
- return HANDLE(dwOffset);
- dwOffset = dbe->ofsNext;
- }
return NULL;
}
STDMETHODIMP_(HANDLE) CDbxMdb::FindLastEvent(MCONTACT contactID)
{
- DBCachedContact *cc;
-
mir_cslock lck(m_csDbAccess);
- DBContact *dbc = NULL;
- if (dbc->signature != DBCONTACT_SIGNATURE)
- return NULL;
- if (!cc || !cc->IsSub())
- return HANDLE(dbc->ofsLastEvent);
-
- if ((cc = m_cache->GetCachedContact(cc->parentID)) == NULL)
- return NULL;
- dbc = NULL;
- if (dbc->signature != DBCONTACT_SIGNATURE)
- return NULL;
-
- for (DWORD dwOffset = dbc->ofsLastEvent; dwOffset != 0;) {
- DBEvent *dbe = AdaptEvent(dwOffset, contactID);
- if (dbe->signature != DBEVENT_SIGNATURE)
- return NULL;
- if (dbe->contactID == contactID)
- return HANDLE(dwOffset);
- dwOffset = dbe->ofsPrev;
- }
return NULL;
}
@@ -245,20 +178,6 @@ STDMETHODIMP_(HANDLE) CDbxMdb::FindNextEvent(MCONTACT contactID, HANDLE hDbEvent DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL;
mir_cslock lck(m_csDbAccess);
- DBEvent *dbe = AdaptEvent((DWORD)hDbEvent, contactID);
- if (dbe->signature != DBEVENT_SIGNATURE)
- return NULL;
- if (!cc || !cc->IsSub())
- return HANDLE(dbe->ofsNext);
-
- for (DWORD dwOffset = dbe->ofsNext; dwOffset != 0;) {
- dbe = AdaptEvent(dwOffset, contactID);
- if (dbe->signature != DBEVENT_SIGNATURE)
- return NULL;
- if (dbe->contactID == contactID)
- return HANDLE(dwOffset);
- dwOffset = dbe->ofsNext;
- }
return NULL;
}
@@ -267,25 +186,6 @@ STDMETHODIMP_(HANDLE) CDbxMdb::FindPrevEvent(MCONTACT contactID, HANDLE hDbEvent DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL;
mir_cslock lck(m_csDbAccess);
- DBEvent *dbe = AdaptEvent((DWORD)hDbEvent, contactID);
- if (dbe->signature != DBEVENT_SIGNATURE)
- return NULL;
- if (!cc || !cc->IsSub())
- return HANDLE(dbe->ofsPrev);
-
- for (DWORD dwOffset = dbe->ofsPrev; dwOffset != 0;) {
- dbe = AdaptEvent(dwOffset, contactID);
- if (dbe->signature != DBEVENT_SIGNATURE)
- return NULL;
- if (dbe->contactID == contactID)
- return HANDLE(dwOffset);
- dwOffset = dbe->ofsPrev;
- }
- return NULL;
-}
-
-DBEvent* CDbxMdb::AdaptEvent(DWORD ofs, DWORD dwContactID)
-{
return NULL;
}
@@ -295,6 +195,5 @@ DBEvent* CDbxMdb::AdaptEvent(DWORD ofs, DWORD dwContactID) int CDbxMdb::WipeContactHistory(DBContact *dbc)
{
// drop subContact's history if any
- dbc->eventCount = 0; dbc->ofsFirstEvent = dbc->ofsLastEvent = dbc->ofsFirstUnread = dbc->tsFirstUnread = 0;
return 0;
}
diff --git a/plugins/Dbx_mdb/src/dbintf.cpp b/plugins/Dbx_mdb/src/dbintf.cpp index 9562f58de8..880c0c80fd 100644 --- a/plugins/Dbx_mdb/src/dbintf.cpp +++ b/plugins/Dbx_mdb/src/dbintf.cpp @@ -51,8 +51,8 @@ CDbxMdb::CDbxMdb(const TCHAR *tszFileName, int iMode) : InitDbInstance(this);
mdb_env_create(&m_pMdbEnv);
- mdb_env_set_maxdbs(m_pMdbEnv, 4);
-
+ mdb_env_set_maxdbs(m_pMdbEnv, 10);
+ m_codePage = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);
m_hModHeap = HeapCreate(0, 0, 0);
}
@@ -95,8 +95,14 @@ int CDbxMdb::Load(bool bSkipInit) return EGROKPRF_CANTREAD;
if (!bSkipInit) {
- if (InitModuleNames()) return 1;
- if (InitCrypt()) return EGROKPRF_CANTREAD;
+ mdb_txn_begin(m_pMdbEnv, NULL, 0, &m_txn); +
+ mdb_open(m_txn, "modules", MDB_CREATE | MDB_INTEGERKEY, &m_dbModules); + mdb_open(m_txn, "contacts", MDB_CREATE | MDB_INTEGERKEY, &m_dbContacts); + mdb_open(m_txn, "events", MDB_CREATE | MDB_INTEGERKEY, &m_dbEvents); +
+ if (InitModuleNames()) return EGROKPRF_CANTREAD;
+ if (InitCrypt()) return EGROKPRF_CANTREAD;
// everything is ok, go on
if (!m_bReadOnly) {
diff --git a/plugins/Dbx_mdb/src/dbintf.h b/plugins/Dbx_mdb/src/dbintf.h index b3f3042244..cb1b238ee1 100644 --- a/plugins/Dbx_mdb/src/dbintf.h +++ b/plugins/Dbx_mdb/src/dbintf.h @@ -72,12 +72,6 @@ DWORD __forceinline GetSettingValueLength(PBYTE pSetting) return pSetting[0];
}
-struct DBSignature
-{
- char name[15];
- BYTE eof;
-};
-
struct ModuleName
{
char *name;
@@ -85,34 +79,12 @@ 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
- 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, // 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;
};
#define DBMODULENAME_SIGNATURE 0x4DDECADEu
@@ -123,42 +95,12 @@ struct DBModuleName 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
-};
-
#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;
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
@@ -267,6 +209,7 @@ public: protected:
MDB_env *m_pMdbEnv;
+ MDB_txn *m_txn;
HANDLE hSettingChangeEvent, hContactDeletedEvent, hContactAddedEvent, hEventMarkedRead;
@@ -291,7 +234,7 @@ protected: ////////////////////////////////////////////////////////////////////////////
// events
- DBEvent* AdaptEvent(DWORD offset, DWORD hContact);
+ MDB_dbi m_dbEvents;
////////////////////////////////////////////////////////////////////////////
// modules
diff --git a/plugins/Dbx_mdb/src/dbmodulechain.cpp b/plugins/Dbx_mdb/src/dbmodulechain.cpp index 33cb289561..6f9a8fc15e 100644 --- a/plugins/Dbx_mdb/src/dbmodulechain.cpp +++ b/plugins/Dbx_mdb/src/dbmodulechain.cpp @@ -35,12 +35,8 @@ void CDbxMdb::AddToList(char *name, DWORD ofs) int CDbxMdb::InitModuleNames(void)
{
- MDB_txn *txn; - mdb_txn_begin(m_pMdbEnv, NULL, 0, &txn); - mdb_open(txn, "mods", MDB_CREATE | MDB_DUPSORT | MDB_DUPFIXED, &m_dbModules); -
MDB_cursor *cursor; - mdb_cursor_open(txn, m_dbModules, &cursor); + mdb_cursor_open(m_txn, m_dbModules, &cursor); int rc, moduleId; char moduleName[100]; @@ -49,7 +45,6 @@ int CDbxMdb::InitModuleNames(void) AddToList(moduleName, moduleId);
mdb_cursor_close(cursor); - mdb_txn_abort(txn); return 0;
}
|