summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdbx
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-23 16:58:35 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-23 16:58:35 +0300
commit6a6b08bfbdc3d77874b72ccb4b99cc50c6b8397b (patch)
tree5c0db265d88d596bb0644370f49c84135f0143b4 /plugins/Dbx_mdbx
parent57b7c931f578057739f014734257ed8e6b21713f (diff)
fixes #1195 (Import from mdbx is broken)
Diffstat (limited to 'plugins/Dbx_mdbx')
-rw-r--r--plugins/Dbx_mdbx/src/dbcontacts.cpp18
-rw-r--r--plugins/Dbx_mdbx/src/dbcrypt.cpp26
-rw-r--r--plugins/Dbx_mdbx/src/dbevents.cpp46
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.cpp2
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.h10
-rw-r--r--plugins/Dbx_mdbx/src/dbmodulechain.cpp6
-rw-r--r--plugins/Dbx_mdbx/src/dbsettings.cpp4
-rw-r--r--plugins/Dbx_mdbx/src/stdafx.h10
-rw-r--r--plugins/Dbx_mdbx/src/version.h2
9 files changed, 65 insertions, 59 deletions
diff --git a/plugins/Dbx_mdbx/src/dbcontacts.cpp b/plugins/Dbx_mdbx/src/dbcontacts.cpp
index 8c2efb9df1..ce08f4729c 100644
--- a/plugins/Dbx_mdbx/src/dbcontacts.cpp
+++ b/plugins/Dbx_mdbx/src/dbcontacts.cpp
@@ -51,8 +51,8 @@ STDMETHODIMP_(LONG) CDbxMDBX::DeleteContact(MCONTACT contactID)
MDBX_val key, data;
DBSettingKey keyS = { contactID, 0, 0 };
- txn_ptr txn(m_env);
- cursor_ptr cursor(txn, m_dbSettings);
+ txn_ptr trnlck(StartTran());
+ cursor_ptr cursor(trnlck, m_dbSettings);
key.iov_len = sizeof(keyS); key.iov_base = &keyS;
@@ -63,12 +63,12 @@ STDMETHODIMP_(LONG) CDbxMDBX::DeleteContact(MCONTACT contactID)
mdbx_cursor_del(cursor, 0);
}
- txn.commit();
+ trnlck.commit();
}
MDBX_val key = { &contactID, sizeof(MCONTACT) };
{
- txn_ptr trnlck(m_env);
+ txn_ptr trnlck(StartTran());
if (mdbx_del(trnlck, m_dbContacts, &key, nullptr) != MDBX_SUCCESS)
return 1;
if (trnlck.commit() != MDBX_SUCCESS)
@@ -88,7 +88,7 @@ STDMETHODIMP_(MCONTACT) CDbxMDBX::AddContact()
MDBX_val key = { &dwContactId, sizeof(MCONTACT) };
MDBX_val data = { &cc->dbc, sizeof(cc->dbc) };
- txn_ptr trnlck(m_env);
+ txn_ptr trnlck(StartTran());
if (mdbx_put(trnlck, m_dbContacts, &key, &data, 0) != MDBX_SUCCESS)
return 0;
if (trnlck.commit() != MDBX_SUCCESS)
@@ -132,7 +132,7 @@ BOOL CDbxMDBX::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
for (auto &EI : list) {
{
- txn_ptr trnlck(m_env);
+ txn_ptr trnlck(StartTran());
DBEventSortingKey insVal = { ccMeta->contactID, EI->eventId, EI->ts };
MDBX_val key = { &insVal, sizeof(insVal) }, data = { (void*)"", 1 };
@@ -147,7 +147,7 @@ BOOL CDbxMDBX::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
}
MDBX_val keyc = { &ccMeta->contactID, sizeof(MCONTACT) }, datac = { &ccMeta->dbc, sizeof(ccMeta->dbc) };
- txn_ptr trnlck(m_env);
+ txn_ptr trnlck(StartTran());
if (mdbx_put(trnlck, m_dbContacts, &keyc, &datac, 0) != MDBX_SUCCESS)
return 1;
if (trnlck.commit() != MDBX_SUCCESS)
@@ -164,7 +164,7 @@ BOOL CDbxMDBX::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
for (auto &EI : list) {
{
- txn_ptr trnlck(m_env);
+ txn_ptr trnlck(StartTran());
DBEventSortingKey insVal = { ccMeta->contactID, EI->eventId, EI->ts };
MDBX_val key = { &insVal, sizeof(insVal) };
if (mdbx_del(trnlck, m_dbEventsSort, &key, nullptr) != MDBX_SUCCESS)
@@ -176,7 +176,7 @@ BOOL CDbxMDBX::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
delete EI;
}
- txn_ptr trnlck(m_env);
+ txn_ptr trnlck(StartTran());
MDBX_val keyc = { &ccMeta->contactID, sizeof(MCONTACT) }, datac = { &ccMeta->dbc, sizeof(ccMeta->dbc) };
if (mdbx_put(trnlck, m_dbContacts, &keyc, &datac, 0) != MDBX_SUCCESS)
return 1;
diff --git a/plugins/Dbx_mdbx/src/dbcrypt.cpp b/plugins/Dbx_mdbx/src/dbcrypt.cpp
index 1e73ddddcc..31c2a24b76 100644
--- a/plugins/Dbx_mdbx/src/dbcrypt.cpp
+++ b/plugins/Dbx_mdbx/src/dbcrypt.cpp
@@ -49,16 +49,16 @@ CRYPTO_PROVIDER* CDbxMDBX::SelectProvider()
else pProv = ppProvs[0];
{
- txn_ptr txn(m_env);
+ txn_ptr trnlck(StartTran());
MDBX_val key = { DBKey_Crypto_Provider, sizeof(DBKey_Crypto_Provider) }, value = { pProv->pszName, mir_strlen(pProv->pszName) + 1 };
- if (mdbx_put(txn, m_dbCrypto, &key, &value, 0) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbCrypto, &key, &value, 0) != MDBX_SUCCESS)
return nullptr;
key.iov_len = sizeof(DBKey_Crypto_IsEncrypted); key.iov_base = DBKey_Crypto_IsEncrypted; value.iov_len = sizeof(bool); value.iov_base = &bTotalCrypt;
- if (mdbx_put(txn, m_dbCrypto, &key, &value, 0) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbCrypto, &key, &value, 0) != MDBX_SUCCESS)
return nullptr;
- if (txn.commit() != MDBX_SUCCESS)
+ if (trnlck.commit() != MDBX_SUCCESS)
return nullptr;
}
@@ -126,11 +126,11 @@ void CDbxMDBX::StoreKey()
BYTE *pKey = (BYTE*)_alloca(iKeyLength);
m_crypto->getKey(pKey, iKeyLength);
{
- txn_ptr txn(m_env);
+ txn_ptr trnlck(StartTran());
MDBX_val key = { DBKey_Crypto_Key, sizeof(DBKey_Crypto_Key) }, value = { pKey, iKeyLength };
- int rc = mdbx_put(txn, m_dbCrypto, &key, &value, 0);
+ int rc = mdbx_put(trnlck, m_dbCrypto, &key, &value, 0);
if (rc == MDBX_SUCCESS)
- rc = txn.commit();
+ rc = trnlck.commit();
/* FIXME: throw an exception */
assert(rc == MDBX_SUCCESS);
UNREFERENCED_PARAMETER(rc);
@@ -201,9 +201,9 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted)
dwNewFlags = dbEvent->flags | DBEF_ENCRYPTED;
}
- txn_ptr txn(m_env);
+ txn_ptr trnlck(StartTran());
data.iov_len = sizeof(DBEvent) + nNewBlob;
- if (mdbx_put(txn, m_dbEvents, &key, &data, MDBX_RESERVE) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbEvents, &key, &data, MDBX_RESERVE) != MDBX_SUCCESS)
return 1;
DBEvent *pNewDBEvent = (DBEvent *)data.iov_base;
@@ -212,17 +212,17 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted)
pNewDBEvent->flags = dwNewFlags;
memcpy(pNewDBEvent + 1, pNewBlob, nNewBlob);
- if (txn.commit() != MDBX_SUCCESS)
+ if (trnlck.commit() != MDBX_SUCCESS)
return 1;
}
}
}
- txn_ptr txn(m_env);
+ txn_ptr trnlck(StartTran());
MDBX_val key = { DBKey_Crypto_IsEncrypted, sizeof(DBKey_Crypto_IsEncrypted) }, value = { &bEncrypted, sizeof(bool) };
- if (mdbx_put(txn, m_dbCrypto, &key, &value, 0) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbCrypto, &key, &value, 0) != MDBX_SUCCESS)
return 1;
- if (txn.commit() != MDBX_SUCCESS)
+ if (trnlck.commit() != MDBX_SUCCESS)
return 1;
m_bEncrypted = bEncrypted;
diff --git a/plugins/Dbx_mdbx/src/dbevents.cpp b/plugins/Dbx_mdbx/src/dbevents.cpp
index 711dd58598..0fa08dfc08 100644
--- a/plugins/Dbx_mdbx/src/dbevents.cpp
+++ b/plugins/Dbx_mdbx/src/dbevents.cpp
@@ -81,10 +81,10 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
MEVENT dwEventId = InterlockedIncrement(&m_dwMaxEventId);
{
- txn_ptr txn(m_env);
+ txn_ptr trnlck(StartTran());
MDBX_val key = { &dwEventId, sizeof(MEVENT) }, data = { nullptr, sizeof(DBEvent) + dbe.cbBlob };
- if (mdbx_put(txn, m_dbEvents, &key, &data, MDBX_RESERVE) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbEvents, &key, &data, MDBX_RESERVE) != MDBX_SUCCESS)
return 0;
DBEvent *pNewEvent = (DBEvent*)data.iov_base;
@@ -95,28 +95,28 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
DBEventSortingKey key2 = { contactID, dwEventId, dbe.timestamp };
key.iov_len = sizeof(key2); key.iov_base = &key2;
data.iov_len = 1; data.iov_base = (char*)("");
- if (mdbx_put(txn, m_dbEventsSort, &key, &data, 0) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbEventsSort, &key, &data, 0) != MDBX_SUCCESS)
return 0;
cc->Advance(dwEventId, dbe);
MDBX_val keyc = { &contactID, sizeof(MCONTACT) }, datac = { &cc->dbc, sizeof(DBContact) };
- if (mdbx_put(txn, m_dbContacts, &keyc, &datac, 0) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbContacts, &keyc, &datac, 0) != MDBX_SUCCESS)
return 0;
// insert an event into a sub's history too
if (ccSub != nullptr) {
key2.hContact = ccSub->contactID;
- if (mdbx_put(txn, m_dbEventsSort, &key, &data, 0) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbEventsSort, &key, &data, 0) != MDBX_SUCCESS)
return 0;
ccSub->Advance(dwEventId, dbe);
datac.iov_base = &ccSub->dbc;
keyc.iov_base = &ccSub->contactID;
- if (mdbx_put(txn, m_dbContacts, &keyc, &datac, 0) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbContacts, &keyc, &datac, 0) != MDBX_SUCCESS)
return 0;
}
- if (txn.commit() != MDBX_SUCCESS)
+ if (trnlck.commit() != MDBX_SUCCESS)
return 0;
}
@@ -148,45 +148,45 @@ STDMETHODIMP_(BOOL) CDbxMDBX::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent)
cc2 = m_cache->GetCachedContact(dbe.contactID);
{
- txn_ptr txn(m_env);
+ txn_ptr trnlck(StartTran());
DBEventSortingKey key2 = { contactID, hDbEvent, dbe.timestamp };
MDBX_val key = { &key2, sizeof(key2) }, data;
- if (mdbx_del(txn, m_dbEventsSort, &key, nullptr) != MDBX_SUCCESS)
+ if (mdbx_del(trnlck, m_dbEventsSort, &key, nullptr) != MDBX_SUCCESS)
return 1;
{
key.iov_len = sizeof(MCONTACT); key.iov_base = &contactID;
cc->dbc.dwEventCount--;
if (cc->dbc.evFirstUnread == hDbEvent)
- FindNextUnread(txn, cc, key2);
+ FindNextUnread(trnlck, cc, key2);
data.iov_len = sizeof(DBContact); data.iov_base = &cc->dbc;
- if (mdbx_put(txn, m_dbContacts, &key, &data, 0) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbContacts, &key, &data, 0) != MDBX_SUCCESS)
return 1;
}
if (cc2) {
key2.hContact = dbe.contactID;
- if (mdbx_del(txn, m_dbEventsSort, &key, nullptr) != MDBX_SUCCESS)
+ if (mdbx_del(trnlck, m_dbEventsSort, &key, nullptr) != MDBX_SUCCESS)
return 1;
key.iov_len = sizeof(MCONTACT); key.iov_base = &contactID;
cc2->dbc.dwEventCount--;
if (cc2->dbc.evFirstUnread == hDbEvent)
- FindNextUnread(txn, cc2, key2);
+ FindNextUnread(trnlck, cc2, key2);
data.iov_len = sizeof(DBContact); data.iov_base = &cc2->dbc;
- if (mdbx_put(txn, m_dbContacts, &key, &data, 0) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbContacts, &key, &data, 0) != MDBX_SUCCESS)
return 1;
}
// remove a event
key.iov_len = sizeof(MEVENT); key.iov_base = &hDbEvent;
- if (mdbx_del(txn, m_dbEvents, &key, nullptr) != MDBX_SUCCESS)
+ if (mdbx_del(trnlck, m_dbEvents, &key, nullptr) != MDBX_SUCCESS)
return 1;
- if (txn.commit() != MDBX_SUCCESS)
+ if (trnlck.commit() != MDBX_SUCCESS)
return 1;
}
@@ -286,9 +286,9 @@ STDMETHODIMP_(BOOL) CDbxMDBX::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent)
uint32_t wRetVal = -1;
{
- txn_ptr txn(m_env);
+ txn_ptr trnlck(StartTran());
MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data;
- if (mdbx_get(txn, m_dbEvents, &key, &data) != MDBX_SUCCESS)
+ if (mdbx_get(trnlck, m_dbEvents, &key, &data) != MDBX_SUCCESS)
return -1;
const DBEvent *cdbe = (const DBEvent*)data.iov_base;
@@ -296,7 +296,7 @@ STDMETHODIMP_(BOOL) CDbxMDBX::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent)
return cdbe->flags;
DBEventSortingKey keyVal = { contactID, hDbEvent, cdbe->timestamp };
- if (mdbx_put(txn, m_dbEvents, &key, &data, MDBX_RESERVE) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbEvents, &key, &data, MDBX_RESERVE) != MDBX_SUCCESS)
return -1;
DBEvent *pNewEvent = (DBEvent*)data.iov_base;
@@ -304,13 +304,13 @@ STDMETHODIMP_(BOOL) CDbxMDBX::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent)
wRetVal = (pNewEvent->flags |= DBEF_READ);
- FindNextUnread(txn, cc, keyVal);
+ FindNextUnread(trnlck, cc, keyVal);
key.iov_len = sizeof(MCONTACT); key.iov_base = &contactID;
data.iov_base = &cc->dbc; data.iov_len = sizeof(cc->dbc);
- if (mdbx_put(txn, m_dbContacts, &key, &data, 0) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbContacts, &key, &data, 0) != MDBX_SUCCESS)
return -1;
- if (txn.commit() != MDBX_SUCCESS)
+ if (trnlck.commit() != MDBX_SUCCESS)
return -1;
}
@@ -470,7 +470,7 @@ int CDbxMDBX::CheckEvents1()
if (!mdbx_get(m_txn_ro, m_dbEventsSort, &key, nullptr))
continue;
- txn_ptr txn(m_env);
+ txn_ptr trnlck(StartTran());
if (mdbx_del(txn, m_dbEvents, &key, nullptr) == MDBX_SUCCESS)
txn.commit();
}
diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp
index e9d0b33ad9..aa2cd398b3 100644
--- a/plugins/Dbx_mdbx/src/dbintf.cpp
+++ b/plugins/Dbx_mdbx/src/dbintf.cpp
@@ -66,7 +66,7 @@ int CDbxMDBX::Load(bool bSkipInit)
return EGROKPRF_CANTREAD;
if (!bSkipInit) {
- txn_ptr trnlck(m_env);
+ txn_ptr trnlck(StartTran());
unsigned int defFlags = MDBX_CREATE;
diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h
index 2e97964723..0ef57afdab 100644
--- a/plugins/Dbx_mdbx/src/dbintf.h
+++ b/plugins/Dbx_mdbx/src/dbintf.h
@@ -137,6 +137,16 @@ struct CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZero
int Create(void);
int Check(void);
+ __forceinline MDBX_txn* StartTran() const
+ {
+ MDBX_txn *res = 0;
+ int rc = mdbx_txn_begin(m_env, nullptr, (m_bReadOnly) ? MDBX_RDONLY : 0, &res);
+ /* FIXME: throw an exception */
+ _ASSERT(rc == MDBX_SUCCESS);
+ UNREFERENCED_PARAMETER(rc);
+ return res;
+ }
+
void StoreKey(void);
void SetPassword(const wchar_t *ptszPassword);
void UpdateMenuItem(void);
diff --git a/plugins/Dbx_mdbx/src/dbmodulechain.cpp b/plugins/Dbx_mdbx/src/dbmodulechain.cpp
index c133426350..daaaf494ff 100644
--- a/plugins/Dbx_mdbx/src/dbmodulechain.cpp
+++ b/plugins/Dbx_mdbx/src/dbmodulechain.cpp
@@ -44,10 +44,10 @@ uint32_t CDbxMDBX::GetModuleID(const char *szName)
if (m_Modules.find(iHash) == m_Modules.end()) {
MDBX_val key = { &iHash, sizeof(iHash) }, data = { (void*)szName, strlen(szName) + 1 };
{
- txn_ptr txn(m_env);
- if (mdbx_put(txn, m_dbModules, &key, &data, 0) != MDBX_SUCCESS)
+ txn_ptr trnlck(StartTran());
+ if (mdbx_put(trnlck, m_dbModules, &key, &data, 0) != MDBX_SUCCESS)
return -1;
- if (txn.commit() != MDBX_SUCCESS)
+ if (trnlck.commit() != MDBX_SUCCESS)
return -1;
}
diff --git a/plugins/Dbx_mdbx/src/dbsettings.cpp b/plugins/Dbx_mdbx/src/dbsettings.cpp
index d17543fbd8..31f326df78 100644
--- a/plugins/Dbx_mdbx/src/dbsettings.cpp
+++ b/plugins/Dbx_mdbx/src/dbsettings.cpp
@@ -313,7 +313,7 @@ LBL_WriteString:
}
{
- txn_ptr trnlck(m_env);
+ txn_ptr trnlck(StartTran());
if (mdbx_put(trnlck, m_dbSettings, &key, &data, MDBX_RESERVE) != MDBX_SUCCESS)
return 1;
@@ -366,7 +366,7 @@ STDMETHODIMP_(BOOL) CDbxMDBX::DeleteContactSetting(MCONTACT contactID, LPCSTR sz
keyVal->dwModuleId = GetModuleID(szModule);
memcpy(&keyVal->szSettingName, szSetting, settingNameLen + 1);
- txn_ptr trnlck(m_env);
+ txn_ptr trnlck(StartTran());
MDBX_val key = { keyVal, sizeof(DBSettingKey) + settingNameLen };
if (mdbx_del(trnlck, m_dbSettings, &key, nullptr) != MDBX_SUCCESS)
return 1;
diff --git a/plugins/Dbx_mdbx/src/stdafx.h b/plugins/Dbx_mdbx/src/stdafx.h
index 42e3068ae6..4805e9833a 100644
--- a/plugins/Dbx_mdbx/src/stdafx.h
+++ b/plugins/Dbx_mdbx/src/stdafx.h
@@ -57,13 +57,9 @@ class txn_ptr
{
MDBX_txn *txn;
public:
- __forceinline txn_ptr(MDBX_env *pEnv)
- {
- int rc = mdbx_txn_begin(pEnv, nullptr, 0, &txn);
- /* FIXME: throw an exception */
- _ASSERT(rc == MDBX_SUCCESS);
- UNREFERENCED_PARAMETER(rc);
- }
+ __forceinline txn_ptr(MDBX_txn *_txn) :
+ txn(_txn)
+ {}
__forceinline ~txn_ptr()
{
diff --git a/plugins/Dbx_mdbx/src/version.h b/plugins/Dbx_mdbx/src/version.h
index f8079874d9..aa3c82c33e 100644
--- a/plugins/Dbx_mdbx/src/version.h
+++ b/plugins/Dbx_mdbx/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 95
#define __RELEASE_NUM 8
-#define __BUILD_NUM 3
+#define __BUILD_NUM 4
#include <stdver.h>