From 0ad50afcb9b77a5d92ccade06a443552f702bdc3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 24 Nov 2017 18:18:59 +0300 Subject: Dbx_mdb: - fix for settings sorting order; - warning fixes --- plugins/Dbx_mdb/src/dbcontacts.cpp | 2 +- plugins/Dbx_mdb/src/dbcrypt.cpp | 8 +++---- plugins/Dbx_mdb/src/dbintf.cpp | 48 +++++++++++++++++++------------------- plugins/Dbx_mdb/src/dbintf.h | 3 +-- plugins/Dbx_mdb/src/dbsettings.cpp | 14 +++++------ plugins/Dbx_mdb/src/dbutils.cpp | 2 +- plugins/Dbx_mdb/src/version.h | 2 +- 7 files changed, 39 insertions(+), 40 deletions(-) (limited to 'plugins') diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp index 63de975d68..f6d513b6e4 100644 --- a/plugins/Dbx_mdb/src/dbcontacts.cpp +++ b/plugins/Dbx_mdb/src/dbcontacts.cpp @@ -49,7 +49,7 @@ STDMETHODIMP_(LONG) CDbxMdb::DeleteContact(MCONTACT contactID) } { MDBX_val key, data; - DBSettingKey keyS = { contactID, 0 }; + DBSettingKey keyS = { contactID, 0, 0 }; txn_ptr txn(m_pMdbEnv); cursor_ptr cursor(txn, m_dbSettings); diff --git a/plugins/Dbx_mdb/src/dbcrypt.cpp b/plugins/Dbx_mdb/src/dbcrypt.cpp index 9e382ae84d..8b67755711 100644 --- a/plugins/Dbx_mdb/src/dbcrypt.cpp +++ b/plugins/Dbx_mdb/src/dbcrypt.cpp @@ -156,10 +156,10 @@ int CDbxMdb::EnableEncryption(bool bEncrypted) return 0; { - txn_ptr_ro txn(m_txn); + txn_ptr_ro txnro(m_txn); MDBX_stat st; - mdbx_dbi_stat(txn, m_dbEvents, &st, sizeof(st)); + mdbx_dbi_stat(txnro, m_dbEvents, &st, sizeof(st)); std::vector lstEvents; lstEvents.reserve(st.ms_entries); @@ -175,7 +175,7 @@ int CDbxMdb::EnableEncryption(bool bEncrypted) for (auto it = lstEvents.begin(); it != lstEvents.end(); ++it) { MEVENT &hDbEvent = *it; MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data; - mdbx_get(txn, m_dbEvents, &key, &data); + mdbx_get(txnro, m_dbEvents, &key, &data); const DBEvent *dbEvent = (const DBEvent*)data.iov_base; const BYTE *pBlob = (BYTE*)(dbEvent + 1); @@ -201,7 +201,7 @@ int CDbxMdb::EnableEncryption(bool bEncrypted) DBEvent *pNewDBEvent = (DBEvent *)data.iov_base; *pNewDBEvent = *dbEvent; - pNewDBEvent->cbBlob = nNewBlob; + pNewDBEvent->cbBlob = (uint16_t)nNewBlob; pNewDBEvent->flags = dwNewFlags; memcpy(pNewDBEvent + 1, pNewBlob, nNewBlob); diff --git a/plugins/Dbx_mdb/src/dbintf.cpp b/plugins/Dbx_mdb/src/dbintf.cpp index 8a85123eeb..a432ac3e29 100644 --- a/plugins/Dbx_mdb/src/dbintf.cpp +++ b/plugins/Dbx_mdb/src/dbintf.cpp @@ -79,31 +79,31 @@ int CDbxMdb::Load(bool bSkipInit) mdbx_dbi_open_ex(trnlck, "eventsrt", defFlags, &m_dbEventsSort, DBEventSortingKey::Compare, nullptr); mdbx_dbi_open_ex(trnlck, "settings", defFlags, &m_dbSettings, DBSettingKey::Compare, nullptr); - - uint32_t keyVal = 1; - MDBX_val key = { &keyVal, sizeof(keyVal) }, data; - if (mdbx_get(trnlck, m_dbGlobal, &key, &data) == MDBX_SUCCESS) { - const DBHeader *hdr = (const DBHeader*)data.iov_base; - if (hdr->dwSignature != DBHEADER_SIGNATURE) - return EGROKPRF_DAMAGED; - if (hdr->dwVersion != DBHEADER_VERSION) - return EGROKPRF_OBSOLETE; - - m_header = *hdr; - } - else { - m_header.dwSignature = DBHEADER_SIGNATURE; - m_header.dwVersion = DBHEADER_VERSION; - data.iov_base = &m_header; data.iov_len = sizeof(m_header); - mdbx_put(trnlck, m_dbGlobal, &key, &data, 0); - - keyVal = 0; - DBContact dbc = { 0, 0, 0 }; - data.iov_base = &dbc; data.iov_len = sizeof(dbc); - mdbx_put(trnlck, m_dbContacts, &key, &data, 0); + { + uint32_t keyVal = 1; + MDBX_val key = { &keyVal, sizeof(keyVal) }, data; + if (mdbx_get(trnlck, m_dbGlobal, &key, &data) == MDBX_SUCCESS) { + const DBHeader *hdr = (const DBHeader*)data.iov_base; + if (hdr->dwSignature != DBHEADER_SIGNATURE) + return EGROKPRF_DAMAGED; + if (hdr->dwVersion != DBHEADER_VERSION) + return EGROKPRF_OBSOLETE; + + m_header = *hdr; + } + else { + m_header.dwSignature = DBHEADER_SIGNATURE; + m_header.dwVersion = DBHEADER_VERSION; + data.iov_base = &m_header; data.iov_len = sizeof(m_header); + mdbx_put(trnlck, m_dbGlobal, &key, &data, 0); + + keyVal = 0; + DBContact dbc = { 0, 0, 0 }; + data.iov_base = &dbc; data.iov_len = sizeof(dbc); + mdbx_put(trnlck, m_dbContacts, &key, &data, 0); + } + trnlck.commit(); } - trnlck.commit(); - { MDBX_val key, val; diff --git a/plugins/Dbx_mdb/src/dbintf.h b/plugins/Dbx_mdb/src/dbintf.h index d35fafba77..d331c027f2 100644 --- a/plugins/Dbx_mdb/src/dbintf.h +++ b/plugins/Dbx_mdb/src/dbintf.h @@ -81,10 +81,9 @@ struct DBSettingKey { MCONTACT hContact; uint32_t dwModuleId; - char szSettingName[]; + char szSettingName[1]; static int Compare(const MDBX_val*, const MDBX_val*); - }; struct DBSettingValue diff --git a/plugins/Dbx_mdb/src/dbsettings.cpp b/plugins/Dbx_mdb/src/dbsettings.cpp index 741fc9b307..b61f9d8ec0 100644 --- a/plugins/Dbx_mdb/src/dbsettings.cpp +++ b/plugins/Dbx_mdb/src/dbsettings.cpp @@ -84,13 +84,13 @@ LBL_Seek: txn_ptr_ro trnlck(m_txn); - DBSettingKey *keyVal = (DBSettingKey *)_alloca(sizeof(DBSettingKey) + settingNameLen + 1); + DBSettingKey *keyVal = (DBSettingKey *)_alloca(sizeof(DBSettingKey) + settingNameLen); keyVal->hContact = contactID; keyVal->dwModuleId = GetModuleID(szModule); memcpy(&keyVal->szSettingName, szSetting, settingNameLen + 1); - MDBX_val key = { keyVal, sizeof(DBSettingKey) + settingNameLen + 1 }, data; + MDBX_val key = { keyVal, sizeof(DBSettingKey) + settingNameLen }, data; if (mdbx_get(trnlck, m_dbSettings, &key, &data) != MDBX_SUCCESS) { // try to get the missing mc setting from the active sub if (cc && cc->IsMeta() && ValidLookupName(szModule, szSetting)) { @@ -283,13 +283,13 @@ LBL_WriteString: } else m_cache->GetCachedValuePtr(contactID, szCachedSettingName, -1); - DBSettingKey *keyVal = (DBSettingKey *)_alloca(sizeof(DBSettingKey) + settingNameLen + 1); + DBSettingKey *keyVal = (DBSettingKey *)_alloca(sizeof(DBSettingKey) + settingNameLen); keyVal->hContact = contactID; keyVal->dwModuleId = GetModuleID(dbcws->szModule); memcpy(&keyVal->szSettingName, dbcws->szSetting, settingNameLen + 1); - MDBX_val key = { keyVal, sizeof(DBSettingKey) + settingNameLen + 1 }, data; + MDBX_val key = { keyVal, sizeof(DBSettingKey) + settingNameLen }, data; switch (dbcwWork.value.type) { case DBVT_BYTE: data.iov_len = 2; break; @@ -351,12 +351,12 @@ STDMETHODIMP_(BOOL) CDbxMdb::DeleteContactSetting(MCONTACT contactID, LPCSTR szM if (szCachedSettingName[-1] == 0) // it's not a resident variable { - DBSettingKey *keyVal = (DBSettingKey*)_alloca(sizeof(DBSettingKey) + settingNameLen + 1); + DBSettingKey *keyVal = (DBSettingKey*)_alloca(sizeof(DBSettingKey) + settingNameLen); keyVal->hContact = contactID; keyVal->dwModuleId = GetModuleID(szModule); memcpy(&keyVal->szSettingName, szSetting, settingNameLen + 1); - MDBX_val key = { keyVal, sizeof(DBSettingKey) + settingNameLen + 1 }; + MDBX_val key = { keyVal, sizeof(DBSettingKey) + settingNameLen }; for (;; Remap()) { txn_ptr trnlck(m_pMdbEnv); @@ -381,7 +381,7 @@ STDMETHODIMP_(BOOL) CDbxMdb::EnumContactSettings(MCONTACT hContact, DBSETTINGENU { int result = -1; - DBSettingKey keyVal = { hContact, GetModuleID(szModule) }; + DBSettingKey keyVal = { hContact, GetModuleID(szModule), 0 }; txn_ptr_ro txn(m_txn); cursor_ptr_ro cursor(m_curSettings); diff --git a/plugins/Dbx_mdb/src/dbutils.cpp b/plugins/Dbx_mdb/src/dbutils.cpp index 27dcf4147a..ebd7780cbc 100644 --- a/plugins/Dbx_mdb/src/dbutils.cpp +++ b/plugins/Dbx_mdb/src/dbutils.cpp @@ -43,5 +43,5 @@ int DBSettingKey::Compare(const MDBX_val *ax, const MDBX_val *bx) CMP_UINT(a->hContact, b->hContact); CMP_UINT(a->dwModuleId, b->dwModuleId); - return (min(ax->iov_len, bx->iov_len) > sizeof(DBSettingKey)) ? strcmp(a->szSettingName, b->szSettingName) : 0; + return strcmp(a->szSettingName, b->szSettingName); } diff --git a/plugins/Dbx_mdb/src/version.h b/plugins/Dbx_mdb/src/version.h index 5c88029725..8789f57bf8 100644 --- a/plugins/Dbx_mdb/src/version.h +++ b/plugins/Dbx_mdb/src/version.h @@ -1,6 +1,6 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 95 -#define __RELEASE_NUM 3 +#define __RELEASE_NUM 8 #define __BUILD_NUM 1 #include -- cgit v1.2.3