summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-03-22 15:11:48 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-03-22 15:11:48 +0000
commitd2c91898a866006be4bd56b00e5cd36112ca5e06 (patch)
tree614d9d17e05739433fdbe68d247c5f199cdba019 /plugins
parentce1bf81b56ff2dad89b1f783d6377b20eebea0a4 (diff)
dbx_lmdb: some fixes
git-svn-id: http://svn.miranda-ng.org/main/trunk@16522 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Dbx_mdb/src/dbcontacts.cpp12
-rw-r--r--plugins/Dbx_mdb/src/dbcrypt.cpp55
-rw-r--r--plugins/Dbx_mdb/src/dbintf.cpp9
-rw-r--r--plugins/Dbx_mdb/src/dbintf.h2
-rw-r--r--plugins/Dbx_mdb/src/dbmodulechain.cpp5
-rw-r--r--plugins/Dbx_mdb/src/dbsettings.cpp7
-rw-r--r--plugins/Dbx_mdb/src/lmdb/mdb.c6
7 files changed, 40 insertions, 56 deletions
diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp
index e2c67c3981..c77eb3dfba 100644
--- a/plugins/Dbx_mdb/src/dbcontacts.cpp
+++ b/plugins/Dbx_mdb/src/dbcontacts.cpp
@@ -90,19 +90,16 @@ STDMETHODIMP_(LONG) CDbxMdb::DeleteContact(MCONTACT contactID)
if (contactID == 0) // global contact cannot be removed
return 1;
- // delete
- // call notifier while outside mutex
NotifyEventHooks(hContactDeletedEvent, contactID, 0);
- mir_cslockfull lck(m_csDbAccess);
+ mir_cslock lck(m_csDbAccess);
{
- LIST<EventItem> events(50);
+ OBJLIST<EventItem> events(50);
GatherContactHistory(contactID, events);
while (events.getCount())
{
- DeleteEvent(contactID, events[0]->eventId);
- delete events[0];
+ DeleteEvent(contactID, events[0].eventId);
events.remove(0);
}
}
@@ -144,9 +141,6 @@ STDMETHODIMP_(LONG) CDbxMdb::DeleteContact(MCONTACT contactID)
if (contactID == m_hLastCachedContact)
m_hLastCachedContact = NULL;
-
- lck.unlock();
-
return 0;
}
diff --git a/plugins/Dbx_mdb/src/dbcrypt.cpp b/plugins/Dbx_mdb/src/dbcrypt.cpp
index 3e23dfdfa6..76e92cbea8 100644
--- a/plugins/Dbx_mdb/src/dbcrypt.cpp
+++ b/plugins/Dbx_mdb/src/dbcrypt.cpp
@@ -90,35 +90,24 @@ int CDbxMdb::InitCrypt()
return 3;
key.mv_size = sizeof(DBKEY_KEY); key.mv_data = DBKEY_KEY;
- if (mdb_get(txn, m_dbCrypto, &key, &value) == MDB_SUCCESS)
+ if (mdb_get(txn, m_dbCrypto, &key, &value) == MDB_SUCCESS && (value.mv_size == m_crypto->getKeyLength()))
{
- if (value.mv_size != m_crypto->getKeyLength())
- {
- if (!m_crypto->generateKey())
- return 6;
- StoreKey();
- }
- else
+ if (!m_crypto->setKey((const BYTE*)value.mv_data, value.mv_size))
{
- if (!m_crypto->setKey((const BYTE*)value.mv_data, value.mv_size))
+ DlgChangePassParam param = { this };
+ CEnterPasswordDialog dlg(&param);
+ while (true)
{
- DlgChangePassParam param = { this };
- CEnterPasswordDialog dlg(&param);
- while (true)
+ if (-128 != dlg.DoModal())
+ return 4;
+ m_crypto->setPassword(pass_ptrA(mir_utf8encodeT(param.newPass)));
+ if (m_crypto->setKey((const BYTE*)value.mv_data, value.mv_size))
{
- if (-128 != dlg.DoModal())
- return 4;
-
- m_crypto->setPassword(pass_ptrA(mir_utf8encodeT(param.newPass)));
- if (m_crypto->setKey((const BYTE*)value.mv_data, value.mv_size))
- {
- m_bUsesPassword = true;
- SecureZeroMemory(&param, sizeof(param));
- break;
- }
-
- param.wrongPass++;
+ m_bUsesPassword = true;
+ SecureZeroMemory(&param, sizeof(param));
+ break;
}
+ param.wrongPass++;
}
}
}
@@ -181,24 +170,21 @@ int CDbxMdb::EnableEncryption(bool bEncrypted)
mir_cslock lck(m_csDbAccess);
-/* { WTF ?!
+#ifdef DEBUG
+ {
txn_ptr_ro txn(m_txn);
std::vector<MEVENT> lstEvents;
{
cursor_ptr_ro cursor(m_curEvents);
MDB_val key, data;
- if (mdb_cursor_get(cursor, &key, &data, MDB_FIRST) == MDB_SUCCESS)
+ while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS)
{
- do
- {
- const MEVENT hDbEvent = *(MEVENT*)key.mv_data;
- lstEvents.push_back(hDbEvent);
- } while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS);
+ const MEVENT hDbEvent = *(const MEVENT*)key.mv_data;
+ lstEvents.push_back(hDbEvent);
}
}
- for (auto it = lstEvents.begin(); it != lstEvents.end(); ++it)
+ for (MEVENT &hDbEvent : lstEvents)
{
- MEVENT &hDbEvent = *it;
MDB_val key = { sizeof(MEVENT), &hDbEvent }, data;
mdb_get(txn, m_dbEvents, &key, &data);
@@ -244,8 +230,7 @@ int CDbxMdb::EnableEncryption(bool bEncrypted)
}
}
}
-*/
-
+#endif
for (;; Remap())
{
diff --git a/plugins/Dbx_mdb/src/dbintf.cpp b/plugins/Dbx_mdb/src/dbintf.cpp
index bd9a39d64c..e129bbd600 100644
--- a/plugins/Dbx_mdb/src/dbintf.cpp
+++ b/plugins/Dbx_mdb/src/dbintf.cpp
@@ -47,6 +47,7 @@ CDbxMdb::CDbxMdb(const TCHAR *tszFileName, int iMode) :
mdb_env_create(&m_pMdbEnv);
mdb_env_set_maxdbs(m_pMdbEnv, 10);
+ mdb_env_set_userctx(m_pMdbEnv, this);
m_codePage = Langpack_GetDefaultCodePage();
m_hModHeap = HeapCreate(0, 0, 0);
@@ -209,7 +210,7 @@ bool CDbxMdb::Map()
m_dwFileSize += 0x100000;
mdb_env_set_mapsize(m_pMdbEnv, m_dwFileSize);
- unsigned int mode = MDB_NOSYNC | MDB_NOSUBDIR | MDB_NOLOCK; // nolock - miranda using m_csDbAccess lock
+ unsigned int mode = MDB_NOSYNC | MDB_NOSUBDIR | MDB_NOLOCK;
// if (m_bReadOnly)
// mode |= MDB_RDONLY;
// else
@@ -246,6 +247,12 @@ EXTERN_C void __cdecl dbpanic(void *)
TerminateProcess(GetCurrentProcess(), 255);
}
+
+EXTERN_C void LMDB_FailAssert(void *p, const char *text)
+{
+ ((CDbxMdb*)p)->DatabaseCorruption(_A2T(text));
+}
+
void CDbxMdb::DatabaseCorruption(const TCHAR *text)
{
int kill = 0;
diff --git a/plugins/Dbx_mdb/src/dbintf.h b/plugins/Dbx_mdb/src/dbintf.h
index 1d3e4b5649..5211ac6557 100644
--- a/plugins/Dbx_mdb/src/dbintf.h
+++ b/plugins/Dbx_mdb/src/dbintf.h
@@ -188,8 +188,6 @@ protected:
STDMETHODIMP_(VOID) Destroy();
protected:
- void InvalidateSettingsGroupOfsCacheEntry(DWORD) {}
- int WorkInitialCheckHeaders(void);
void FillContacts(void);
diff --git a/plugins/Dbx_mdb/src/dbmodulechain.cpp b/plugins/Dbx_mdb/src/dbmodulechain.cpp
index 5b83d02804..b85388eeff 100644
--- a/plugins/Dbx_mdb/src/dbmodulechain.cpp
+++ b/plugins/Dbx_mdb/src/dbmodulechain.cpp
@@ -94,6 +94,8 @@ DWORD CDbxMdb::GetModuleNameOfs(const char *szName)
int nameLen = (int)strlen(szName);
+ mir_cslock lck(m_csDbAccess);
+
// need to create the module name
int newIdx = ++m_maxModuleID;
DBModuleName *pmod = (DBModuleName*)_alloca(sizeof(DBModuleName) + nameLen + 1);
@@ -133,8 +135,7 @@ STDMETHODIMP_(BOOL) CDbxMdb::EnumModuleNames(DBMODULEENUMPROC pFunc, void *pPara
{
for (int i = 0; i < m_lMods.getCount(); i++) {
ModuleName *pmn = m_lMods[i];
- int ret = pFunc(pmn->name, pmn->ofs, (LPARAM)pParam);
- if (ret)
+ if (int ret = pFunc(pmn->name, pmn->ofs, (LPARAM)pParam))
return ret;
}
return 0;
diff --git a/plugins/Dbx_mdb/src/dbsettings.cpp b/plugins/Dbx_mdb/src/dbsettings.cpp
index 6ea4d009cb..ed7ec5011c 100644
--- a/plugins/Dbx_mdb/src/dbsettings.cpp
+++ b/plugins/Dbx_mdb/src/dbsettings.cpp
@@ -595,9 +595,8 @@ STDMETHODIMP_(BOOL) CDbxMdb::EnumContactSettings(MCONTACT contactID, DBCONTACTEN
STDMETHODIMP_(BOOL) CDbxMdb::EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam)
{
- for (int i = 0; i < m_lResidentSettings.getCount(); i++) {
- int ret = pFunc(m_lResidentSettings[i], 0, (LPARAM)pParam);
- if (ret) return ret;
- }
+ for (int i = 0; i < m_lResidentSettings.getCount(); i++)
+ if (int ret = pFunc(m_lResidentSettings[i], 0, (LPARAM)pParam))
+ return ret;
return 0;
}
diff --git a/plugins/Dbx_mdb/src/lmdb/mdb.c b/plugins/Dbx_mdb/src/lmdb/mdb.c
index 57f03fc6db..deca377af2 100644
--- a/plugins/Dbx_mdb/src/lmdb/mdb.c
+++ b/plugins/Dbx_mdb/src/lmdb/mdb.c
@@ -1392,7 +1392,7 @@ mdb_strerror(int err)
# define mdb_assert0(env, expr, expr_txt) ((expr) ? (void)0 : \
mdb_assert_fail(env, expr_txt, mdb_func_, __FILE__, __LINE__))
-extern void __cdecl dbpanic(void *);
+extern void __cdecl LMDB_FailAssert(void *, const char*);
static void
mdb_assert_fail(MDB_env *env, const char *expr_txt,
@@ -1406,8 +1406,8 @@ mdb_assert_fail(MDB_env *env, const char *expr_txt,
fprintf(stderr, "%s\n", buf);
if (IsDebuggerPresent())
DebugBreak();
- _beginthread(dbpanic, 0, 0);
- Sleep(INFINITE);
+
+ LMDB_FailAssert(env->me_userctx, buf);
}
#else
# define mdb_assert0(env, expr, expr_txt) ((void) 0)