summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-11-24 13:15:32 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-11-24 13:15:32 +0300
commit355c41643beadff74d490dc36f2c0432a2286e4c (patch)
tree9f5320227208ddc3e767e341af3c632a4a521c9a /plugins
parent6d6cb956a78b2dbfa7e8d62f4234d8f27b100468 (diff)
more common database code moved to MDatabaseCommon
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Db3x_mmap/src/dbcontacts.cpp58
-rw-r--r--plugins/Db3x_mmap/src/dbcrypt.cpp2
-rw-r--r--plugins/Db3x_mmap/src/dbintf.h16
-rw-r--r--plugins/Db3x_mmap/src/dbsettings.cpp17
-rw-r--r--plugins/Db3x_mmap/src/dbtool/disk.cpp2
-rw-r--r--plugins/Dbx_mdb/src/dbcontacts.cpp89
-rw-r--r--plugins/Dbx_mdb/src/dbcrypt.cpp78
-rw-r--r--plugins/Dbx_mdb/src/dbintf.h9
-rw-r--r--plugins/Dbx_mdb/src/dbsettings.cpp17
-rw-r--r--plugins/Dbx_mdb/src/ui.cpp2
10 files changed, 46 insertions, 244 deletions
diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp
index 55e4aa8c23..b9d1eb614d 100644
--- a/plugins/Db3x_mmap/src/dbcontacts.cpp
+++ b/plugins/Db3x_mmap/src/dbcontacts.cpp
@@ -23,23 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-int CDb3Mmap::CheckProto(DBCachedContact *cc, const char *proto)
-{
- if (cc->szProto == nullptr) {
- char protobuf[MAX_PATH] = { 0 };
- DBVARIANT dbv;
- dbv.type = DBVT_ASCIIZ;
- dbv.pszVal = protobuf;
- dbv.cchVal = sizeof(protobuf);
- if (GetContactSettingStatic(cc->contactID, "Protocol", "p", &dbv) != 0 || (dbv.type != DBVT_ASCIIZ))
- return 0;
-
- cc->szProto = m_cache->GetCachedSetting(nullptr, protobuf, 0, (int)mir_strlen(protobuf));
- }
-
- return !mir_strcmp(cc->szProto, proto);
-}
-
STDMETHODIMP_(LONG) CDb3Mmap::GetContactCount(void)
{
mir_cslock lck(m_csDbAccess);
@@ -51,36 +34,6 @@ STDMETHODIMP_(LONG) CDb3Mmap::GetContactSize(void)
return sizeof(DBCachedContact);
}
-STDMETHODIMP_(MCONTACT) CDb3Mmap::FindFirstContact(const char *szProto)
-{
- mir_cslock lck(m_csDbAccess);
- DBCachedContact *cc = m_cache->GetFirstContact();
- if (cc == nullptr)
- return 0;
-
- if (!szProto || CheckProto(cc, szProto))
- return cc->contactID;
-
- return FindNextContact(cc->contactID, szProto);
-}
-
-STDMETHODIMP_(MCONTACT) CDb3Mmap::FindNextContact(MCONTACT contactID, const char *szProto)
-{
- mir_cslock lck(m_csDbAccess);
- while (contactID) {
- DBCachedContact *cc = m_cache->GetNextContact(contactID);
- if (cc == nullptr)
- break;
-
- if (!szProto || CheckProto(cc, szProto))
- return cc->contactID;
-
- contactID = cc->contactID;
- }
-
- return 0;
-}
-
STDMETHODIMP_(LONG) CDb3Mmap::DeleteContact(MCONTACT contactID)
{
if (contactID == 0) // global contact cannot be removed
@@ -206,17 +159,6 @@ STDMETHODIMP_(BOOL) CDb3Mmap::IsDbContact(MCONTACT contactID)
/////////////////////////////////////////////////////////////////////////////////////////
// metacontacts support
-BOOL CDb3Mmap::MetaDetouchSub(DBCachedContact *cc, int nSub)
-{
- db_delete_module(cc->pSubs[nSub], META_PROTO);
- return 0;
-}
-
-BOOL CDb3Mmap::MetaSetDefault(DBCachedContact *cc)
-{
- return db_set_dw(cc->contactID, META_PROTO, "Default", cc->nDefault);
-}
-
static int SortEvent(const DBEvent *p1, const DBEvent *p2)
{
return (LONG)p1->timestamp - (LONG)p2->timestamp;
diff --git a/plugins/Db3x_mmap/src/dbcrypt.cpp b/plugins/Db3x_mmap/src/dbcrypt.cpp
index d2368e5b68..608cfa689d 100644
--- a/plugins/Db3x_mmap/src/dbcrypt.cpp
+++ b/plugins/Db3x_mmap/src/dbcrypt.cpp
@@ -225,7 +225,7 @@ void CDb3Mmap::StoreKey()
SecureZeroMemory(pKey, iKeyLength);
}
-void CDb3Mmap::SetPassword(LPCTSTR ptszPassword)
+void CDb3Mmap::SetPassword(const wchar_t *ptszPassword)
{
if (ptszPassword == nullptr || *ptszPassword == 0) {
m_bUsesPassword = false;
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h
index 1a6024bb20..4a194063a7 100644
--- a/plugins/Db3x_mmap/src/dbintf.h
+++ b/plugins/Db3x_mmap/src/dbintf.h
@@ -89,13 +89,13 @@ struct ModuleName
#include <pshpack1.h>
struct DBHeader
{
- BYTE signature[16]; // 'Miranda ICQ DB',0,26
+ 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
+ // 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
@@ -111,7 +111,7 @@ struct DBContact
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
+ 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;
@@ -212,8 +212,6 @@ public:
STDMETHODIMP_(void) SetCacheSafetyMode(BOOL);
STDMETHODIMP_(LONG) GetContactCount(void);
- STDMETHODIMP_(MCONTACT) FindFirstContact(const char *szProto = nullptr);
- STDMETHODIMP_(MCONTACT) FindNextContact(MCONTACT contactID, const char *szProto = nullptr);
STDMETHODIMP_(LONG) DeleteContact(MCONTACT contactID);
STDMETHODIMP_(MCONTACT) AddContact(void);
STDMETHODIMP_(BOOL) IsDbContact(MCONTACT contactID);
@@ -239,10 +237,7 @@ public:
STDMETHODIMP_(BOOL) DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting);
STDMETHODIMP_(BOOL) EnumContactSettings(MCONTACT hContact, DBSETTINGENUMPROC pfnEnumProc, const char *szModule, void *param);
STDMETHODIMP_(BOOL) EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam);
- STDMETHODIMP_(BOOL) IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting);
- STDMETHODIMP_(BOOL) MetaDetouchSub(DBCachedContact *cc, int nSub);
- STDMETHODIMP_(BOOL) MetaSetDefault(DBCachedContact *cc);
STDMETHODIMP_(BOOL) MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub);
STDMETHODIMP_(BOOL) MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub);
@@ -298,7 +293,6 @@ protected:
DWORD m_dwFileSize, m_dwMaxContactId;
HANDLE hSettingChangeEvent, hContactDeletedEvent, hContactAddedEvent, hEventMarkedRead;
- int CheckProto(DBCachedContact *cc, const char *proto);
DWORD CreateNewSpace(int bytes);
void DeleteSpace(DWORD ofs, int bytes);
DWORD ReallocSpace(DWORD ofs, int oldSize, int newSize);
diff --git a/plugins/Db3x_mmap/src/dbsettings.cpp b/plugins/Db3x_mmap/src/dbsettings.cpp
index 76225aec4c..758f80c769 100644
--- a/plugins/Db3x_mmap/src/dbsettings.cpp
+++ b/plugins/Db3x_mmap/src/dbsettings.cpp
@@ -27,23 +27,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define VLT(n) ((n == DBVT_UTF8 || n == DBVT_ENCRYPTED) ? DBVT_ASCIIZ : n)
-BOOL CDb3Mmap::IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting)
-{
- if (!_strnicmp(szSetting, "password", 8)) return true;
- if (!mir_strcmp(szSetting, "NLProxyAuthPassword")) return true;
- if (!mir_strcmp(szSetting, "LNPassword")) return true;
- if (!mir_strcmp(szSetting, "FileProxyPassword")) return true;
- if (!mir_strcmp(szSetting, "TokenSecret")) return true;
-
- if (!mir_strcmp(szModule, "SecureIM")) {
- if (!mir_strcmp(szSetting, "pgp")) return true;
- if (!mir_strcmp(szSetting, "pgpPrivKey")) return true;
- }
- return false;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
static bool ValidLookupName(LPCSTR szModule, LPCSTR szSetting)
{
if (!mir_strcmp(szModule, META_PROTO))
diff --git a/plugins/Db3x_mmap/src/dbtool/disk.cpp b/plugins/Db3x_mmap/src/dbtool/disk.cpp
index da18f9a1d6..3310c7dd67 100644
--- a/plugins/Db3x_mmap/src/dbtool/disk.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/disk.cpp
@@ -72,7 +72,7 @@ int CDb3Mmap::ReadSegment(DWORD ofs, PVOID buf, int cbBytes)
DWORD CDb3Mmap::WriteSegment(DWORD ofs, PVOID buf, int cbBytes)
{
- DWORD bytesWritten;
+ DWORD bytesWritten;
if (cb->bCheckOnly) return 0xbfbfbfbf;
if (ofs == WSOFS_END) {
ofs = m_dbHeader.ofsFileEnd;
diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp
index 3ae1d7c973..63de975d68 100644
--- a/plugins/Dbx_mdb/src/dbcontacts.cpp
+++ b/plugins/Dbx_mdb/src/dbcontacts.cpp
@@ -23,23 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-int CDbxMdb::CheckProto(DBCachedContact *cc, const char *proto)
-{
- if (cc->szProto == NULL) {
- char protobuf[MAX_PATH] = { 0 };
- DBVARIANT dbv;
- dbv.type = DBVT_ASCIIZ;
- dbv.pszVal = protobuf;
- dbv.cchVal = sizeof(protobuf);
- if (GetContactSettingStatic(cc->contactID, "Protocol", "p", &dbv) != 0 || (dbv.type != DBVT_ASCIIZ))
- return 0;
-
- cc->szProto = m_cache->GetCachedSetting(NULL, protobuf, 0, (int)strlen(protobuf));
- }
-
- return !strcmp(cc->szProto, proto);
-}
-
STDMETHODIMP_(LONG) CDbxMdb::GetContactCount(void)
{
return m_contactCount;
@@ -50,51 +33,16 @@ STDMETHODIMP_(LONG) CDbxMdb::GetContactSize(void)
return sizeof(DBCachedContact);
}
-STDMETHODIMP_(MCONTACT) CDbxMdb::FindFirstContact(const char *szProto)
-{
- DBCachedContact *cc = m_cache->GetFirstContact();
- 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;
-
- return FindNextContact(cc->contactID, szProto);
-}
-
-STDMETHODIMP_(MCONTACT) CDbxMdb::FindNextContact(MCONTACT contactID, const char *szProto)
-{
- while (contactID) {
- DBCachedContact *cc = m_cache->GetNextContact(contactID);
- if (cc == NULL)
- break;
-
- if (!szProto || CheckProto(cc, szProto))
- return cc->contactID;
-
- contactID = cc->contactID;
- }
-
- return NULL;
-}
-
STDMETHODIMP_(LONG) CDbxMdb::DeleteContact(MCONTACT contactID)
{
if (contactID == 0) // global contact cannot be removed
return 1;
NotifyEventHooks(hContactDeletedEvent, contactID, 0);
-
-
{
OBJLIST<EventItem> events(50);
GatherContactHistory(contactID, events);
- while (events.getCount())
- {
+ while (events.getCount()) {
DeleteEvent(contactID, events[0].eventId);
events.remove(0);
}
@@ -108,8 +56,7 @@ STDMETHODIMP_(LONG) CDbxMdb::DeleteContact(MCONTACT contactID)
key.iov_len = sizeof(keyS); key.iov_base = &keyS;
- for (int res = mdbx_cursor_get(cursor, &key, &data, MDBX_SET_RANGE); res == MDBX_SUCCESS; res = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT))
- {
+ for (int res = mdbx_cursor_get(cursor, &key, &data, MDBX_SET_RANGE); res == MDBX_SUCCESS; res = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) {
const DBSettingKey *pKey = (const DBSettingKey*)key.iov_base;
if (pKey->hContact != contactID)
break;
@@ -120,8 +67,7 @@ STDMETHODIMP_(LONG) CDbxMdb::DeleteContact(MCONTACT contactID)
}
MDBX_val key = { &contactID, sizeof(MCONTACT) };
- for (;; Remap())
- {
+ for (;; Remap()) {
txn_ptr trnlck(m_pMdbEnv);
MDBX_CHECK(mdbx_del(trnlck, m_dbContacts, &key, nullptr), 1);
if (trnlck.commit() == MDBX_SUCCESS)
@@ -161,20 +107,6 @@ STDMETHODIMP_(BOOL) CDbxMdb::IsDbContact(MCONTACT contactID)
}
/////////////////////////////////////////////////////////////////////////////////////////
-// metacontacts support
-
-BOOL CDbxMdb::MetaDetouchSub(DBCachedContact *cc, int nSub)
-{
- db_delete_module(cc->pSubs[nSub], META_PROTO);
- return 0;
-}
-
-BOOL CDbxMdb::MetaSetDefault(DBCachedContact *cc)
-{
- return db_set_dw(cc->contactID, META_PROTO, "Default", cc->nDefault);
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
void CDbxMdb::GatherContactHistory(MCONTACT hContact, LIST<EventItem> &list)
{
@@ -184,8 +116,7 @@ void CDbxMdb::GatherContactHistory(MCONTACT hContact, LIST<EventItem> &list)
txn_ptr_ro trnlck(m_txn);
cursor_ptr_ro cursor(m_curEventsSort);
- for (int res = mdbx_cursor_get(cursor, &key, &data, MDBX_SET_RANGE); res == MDBX_SUCCESS; res = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT))
- {
+ for (int res = mdbx_cursor_get(cursor, &key, &data, MDBX_SET_RANGE); res == MDBX_SUCCESS; res = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) {
const DBEventSortingKey *pKey = (const DBEventSortingKey*)key.iov_base;
if (pKey->hContact != hContact)
return;
@@ -202,8 +133,7 @@ BOOL CDbxMdb::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
for (int i = 0; i < list.getCount(); i++) {
EventItem *EI = list[i];
- for (;; Remap())
- {
+ for (;; Remap()) {
txn_ptr trnlck(m_pMdbEnv);
DBEventSortingKey insVal = { EI->eventId, EI->ts, ccMeta->contactID };
MDBX_val key = { &insVal, sizeof(insVal) }, data = { (void*)"", 1 };
@@ -217,8 +147,7 @@ BOOL CDbxMdb::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
MDBX_val keyc = { &ccMeta->contactID, sizeof(MCONTACT) }, datac = { &ccMeta->dbc, sizeof(ccMeta->dbc) };
- for (;; Remap())
- {
+ for (;; Remap()) {
txn_ptr trnlck(m_pMdbEnv);
MDBX_CHECK(mdbx_put(trnlck, m_dbContacts, &keyc, &datac, 0), 1);
if (trnlck.commit() == MDBX_SUCCESS)
@@ -251,8 +180,7 @@ BOOL CDbxMdb::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
MDBX_val keyc = { &ccMeta->contactID, sizeof(MCONTACT) }, datac = { &ccMeta->dbc, sizeof(ccMeta->dbc) };
- for (;; Remap())
- {
+ for (;; Remap()) {
txn_ptr trnlck(m_pMdbEnv);
MDBX_CHECK(mdbx_put(trnlck, m_dbContacts, &keyc, &datac, 0), 1);
if (trnlck.commit() == MDBX_SUCCESS)
@@ -297,8 +225,7 @@ void CDbxMdb::FillContacts()
cursor_ptr_ro cursor(m_curContacts);
MDBX_val key, data;
- while (mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS)
- {
+ while (mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS) {
DBCachedContact *cc = m_cache->AddContactToCache(*(MCONTACT*)key.iov_base);
cc->dbc = *(DBContact*)data.iov_base;
diff --git a/plugins/Dbx_mdb/src/dbcrypt.cpp b/plugins/Dbx_mdb/src/dbcrypt.cpp
index 3699b97e6a..9e382ae84d 100644
--- a/plugins/Dbx_mdb/src/dbcrypt.cpp
+++ b/plugins/Dbx_mdb/src/dbcrypt.cpp
@@ -25,8 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/////////////////////////////////////////////////////////////////////////////////////////
-char DBKey_Crypto_Provider [] = "Provider";
-char DBKey_Crypto_Key [] = "Key";
+char DBKey_Crypto_Provider[] = "Provider";
+char DBKey_Crypto_Key[] = "Key";
char DBKey_Crypto_IsEncrypted[] = "EncryptedDB";
CRYPTO_PROVIDER* CDbxMdb::SelectProvider()
@@ -40,8 +40,7 @@ CRYPTO_PROVIDER* CDbxMdb::SelectProvider()
bool bTotalCrypt = false;
- if (iNumProvs > 1)
- {
+ if (iNumProvs > 1) {
CSelectCryptoDialog dlg(ppProvs, iNumProvs);
dlg.DoModal();
pProv = dlg.GetSelected();
@@ -49,8 +48,7 @@ CRYPTO_PROVIDER* CDbxMdb::SelectProvider()
}
else pProv = ppProvs[0];
- for (;; Remap())
- {
+ for (;; Remap()) {
txn_ptr txn(m_pMdbEnv);
MDBX_val key = { DBKey_Crypto_Provider, sizeof(DBKey_Crypto_Provider) }, value = { pProv->pszName, mir_strlen(pProv->pszName) + 1 };
@@ -73,36 +71,29 @@ int CDbxMdb::InitCrypt()
txn_ptr_ro txn(m_txn);
MDBX_val key = { DBKey_Crypto_Provider, sizeof(DBKey_Crypto_Provider) }, value;
- if (mdbx_get(txn, m_dbCrypto, &key, &value) == MDBX_SUCCESS)
- {
+ if (mdbx_get(txn, m_dbCrypto, &key, &value) == MDBX_SUCCESS) {
pProvider = Crypto_GetProvider((const char*)value.iov_base);
if (pProvider == nullptr)
pProvider = SelectProvider();
}
- else
- {
- pProvider = SelectProvider();
- }
- if (pProvider == nullptr)
+ else pProvider = SelectProvider();
+
+ if (pProvider == nullptr)
return 1;
if ((m_crypto = pProvider->pFactory()) == nullptr)
return 3;
key.iov_len = sizeof(DBKey_Crypto_Key); key.iov_base = DBKey_Crypto_Key;
- if (mdbx_get(txn, m_dbCrypto, &key, &value) == MDBX_SUCCESS && (value.iov_len == m_crypto->getKeyLength()))
- {
- if (!m_crypto->setKey((const BYTE*)value.iov_base, value.iov_len))
- {
+ if (mdbx_get(txn, m_dbCrypto, &key, &value) == MDBX_SUCCESS && (value.iov_len == m_crypto->getKeyLength())) {
+ if (!m_crypto->setKey((const BYTE*)value.iov_base, value.iov_len)) {
DlgChangePassParam param = { this };
CEnterPasswordDialog dlg(&param);
- while (true)
- {
+ while (true) {
if (-128 != dlg.DoModal())
return 4;
m_crypto->setPassword(pass_ptrA(mir_utf8encodeW(param.newPass)));
- if (m_crypto->setKey((const BYTE*)value.iov_base, value.iov_len))
- {
+ if (m_crypto->setKey((const BYTE*)value.iov_base, value.iov_len)) {
m_bUsesPassword = true;
SecureZeroMemory(&param, sizeof(param));
break;
@@ -111,18 +102,17 @@ int CDbxMdb::InitCrypt()
}
}
}
- else
- {
+ else {
if (!m_crypto->generateKey())
return 6;
StoreKey();
}
key.iov_len = sizeof(DBKey_Crypto_IsEncrypted); key.iov_base = DBKey_Crypto_IsEncrypted;
-
+
if (mdbx_get(txn, m_dbCrypto, &key, &value) == MDBX_SUCCESS)
m_bEncrypted = *(const bool*)value.iov_base;
- else
+ else
m_bEncrypted = false;
InitDialogs();
@@ -135,8 +125,7 @@ void CDbxMdb::StoreKey()
BYTE *pKey = (BYTE*)_alloca(iKeyLength);
m_crypto->getKey(pKey, iKeyLength);
- for (;; Remap())
- {
+ for (;; Remap()) {
txn_ptr txn(m_pMdbEnv);
MDBX_val key = { DBKey_Crypto_Key, sizeof(DBKey_Crypto_Key) }, value = { pKey, iKeyLength };
mdbx_put(txn, m_dbCrypto, &key, &value, 0);
@@ -146,15 +135,13 @@ void CDbxMdb::StoreKey()
SecureZeroMemory(pKey, iKeyLength);
}
-void CDbxMdb::SetPassword(LPCTSTR ptszPassword)
+void CDbxMdb::SetPassword(const wchar_t *ptszPassword)
{
- if (ptszPassword == NULL || *ptszPassword == 0)
- {
+ if (ptszPassword == NULL || *ptszPassword == 0) {
m_bUsesPassword = false;
m_crypto->setPassword(NULL);
}
- else
- {
+ else {
m_bUsesPassword = true;
m_crypto->setPassword(pass_ptrA(mir_utf8encodeW(ptszPassword)));
}
@@ -168,7 +155,6 @@ int CDbxMdb::EnableEncryption(bool bEncrypted)
if (m_bEncrypted == bEncrypted)
return 0;
-
{
txn_ptr_ro txn(m_txn);
@@ -181,14 +167,12 @@ int CDbxMdb::EnableEncryption(bool bEncrypted)
{
cursor_ptr_ro cursor(m_curEvents);
MDBX_val key, data;
- while (mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS)
- {
+ while (mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT) == MDBX_SUCCESS) {
const MEVENT hDbEvent = *(const MEVENT*)key.iov_base;
lstEvents.push_back(hDbEvent);
}
}
- for (auto it = lstEvents.begin(); it != lstEvents.end(); ++it)
- {
+ 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);
@@ -196,27 +180,23 @@ int CDbxMdb::EnableEncryption(bool bEncrypted)
const DBEvent *dbEvent = (const DBEvent*)data.iov_base;
const BYTE *pBlob = (BYTE*)(dbEvent + 1);
- if (((dbEvent->flags & DBEF_ENCRYPTED) != 0) != bEncrypted)
- {
+ if (((dbEvent->flags & DBEF_ENCRYPTED) != 0) != bEncrypted) {
mir_ptr<BYTE> pNewBlob;
size_t nNewBlob;
uint32_t dwNewFlags;
- if (dbEvent->flags & DBEF_ENCRYPTED)
- {
+ if (dbEvent->flags & DBEF_ENCRYPTED) {
pNewBlob = (BYTE*)m_crypto->decodeBuffer(pBlob, dbEvent->cbBlob, &nNewBlob);
dwNewFlags = dbEvent->flags & (~DBEF_ENCRYPTED);
}
- else
- {
+ else {
pNewBlob = m_crypto->encodeBuffer(pBlob, dbEvent->cbBlob, &nNewBlob);
dwNewFlags = dbEvent->flags | DBEF_ENCRYPTED;
}
- for (;; Remap())
- {
+ for (;; Remap()) {
txn_ptr txn(m_pMdbEnv);
- data.iov_len = sizeof(DBEvent)+nNewBlob;
+ data.iov_len = sizeof(DBEvent) + nNewBlob;
MDBX_CHECK(mdbx_put(txn, m_dbEvents, &key, &data, MDBX_RESERVE), 1);
DBEvent *pNewDBEvent = (DBEvent *)data.iov_base;
@@ -233,14 +213,14 @@ int CDbxMdb::EnableEncryption(bool bEncrypted)
}
}
- for (;; Remap())
- {
+ for (;; Remap()) {
txn_ptr txn(m_pMdbEnv);
MDBX_val key = { DBKey_Crypto_IsEncrypted, sizeof(DBKey_Crypto_IsEncrypted) }, value = { &bEncrypted, sizeof(bool) };
MDBX_CHECK(mdbx_put(txn, m_dbCrypto, &key, &value, 0), 1);
if (txn.commit() == MDBX_SUCCESS)
break;
}
+
m_bEncrypted = bEncrypted;
return 0;
-} \ No newline at end of file
+}
diff --git a/plugins/Dbx_mdb/src/dbintf.h b/plugins/Dbx_mdb/src/dbintf.h
index 4c1c757aed..c3cf04c1cf 100644
--- a/plugins/Dbx_mdb/src/dbintf.h
+++ b/plugins/Dbx_mdb/src/dbintf.h
@@ -139,7 +139,7 @@ struct CDbxMdb : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe
void DatabaseCorruption(const TCHAR *ptszText);
void StoreKey(void);
- void SetPassword(const TCHAR *ptszPassword);
+ void SetPassword(const wchar_t *ptszPassword);
void UpdateMenuItem(void);
int PrepareCheck(int*);
@@ -154,8 +154,6 @@ public:
STDMETHODIMP_(void) SetCacheSafetyMode(BOOL);
STDMETHODIMP_(LONG) GetContactCount(void);
- STDMETHODIMP_(MCONTACT) FindFirstContact(const char *szProto = NULL);
- STDMETHODIMP_(MCONTACT) FindNextContact(MCONTACT contactID, const char *szProto = NULL);
STDMETHODIMP_(LONG) DeleteContact(MCONTACT contactID);
STDMETHODIMP_(MCONTACT) AddContact(void);
STDMETHODIMP_(BOOL) IsDbContact(MCONTACT contactID);
@@ -181,10 +179,7 @@ public:
STDMETHODIMP_(BOOL) DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting);
STDMETHODIMP_(BOOL) EnumContactSettings(MCONTACT hContact, DBSETTINGENUMPROC pfnEnumProc, const char *szModule, void *param);
STDMETHODIMP_(BOOL) EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam);
- STDMETHODIMP_(BOOL) IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting);
- STDMETHODIMP_(BOOL) MetaDetouchSub(DBCachedContact *cc, int nSub);
- STDMETHODIMP_(BOOL) MetaSetDefault(DBCachedContact *cc);
STDMETHODIMP_(BOOL) MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub);
STDMETHODIMP_(BOOL) MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub);
@@ -218,8 +213,6 @@ protected:
HANDLE hSettingChangeEvent, hContactDeletedEvent, hContactAddedEvent, hEventMarkedRead;
- int CheckProto(DBCachedContact *cc, const char *proto);
-
////////////////////////////////////////////////////////////////////////////
// settings
diff --git a/plugins/Dbx_mdb/src/dbsettings.cpp b/plugins/Dbx_mdb/src/dbsettings.cpp
index 5e287292f5..5c1750b23c 100644
--- a/plugins/Dbx_mdb/src/dbsettings.cpp
+++ b/plugins/Dbx_mdb/src/dbsettings.cpp
@@ -25,23 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define VLT(n) ((n == DBVT_UTF8 || n == DBVT_ENCRYPTED)?DBVT_ASCIIZ:n)
-BOOL CDbxMdb::IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting)
-{
- if (!_strnicmp(szSetting, "password", 8)) return true;
- if (!strcmp(szSetting, "NLProxyAuthPassword")) return true;
- if (!strcmp(szSetting, "LNPassword")) return true;
- if (!strcmp(szSetting, "FileProxyPassword")) return true;
- if (!strcmp(szSetting, "TokenSecret")) return true;
-
- if (!strcmp(szModule, "SecureIM")) {
- if (!strcmp(szSetting, "pgp")) return true;
- if (!strcmp(szSetting, "pgpPrivKey")) return true;
- }
- return false;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
static bool ValidLookupName(LPCSTR szModule, LPCSTR szSetting)
{
if (!strcmp(szModule, META_PROTO))
diff --git a/plugins/Dbx_mdb/src/ui.cpp b/plugins/Dbx_mdb/src/ui.cpp
index a679984f77..b6fe84f78b 100644
--- a/plugins/Dbx_mdb/src/ui.cpp
+++ b/plugins/Dbx_mdb/src/ui.cpp
@@ -99,7 +99,7 @@ static INT_PTR CALLBACK sttChangePassword(HWND hwndDlg, UINT uMsg, WPARAM wParam
}
else {
// param->db->WriteSignature(dbSignatureU);
- param->db->SetPassword(NULL);
+ param->db->SetPassword(nullptr);
param->db->StoreKey();
EndDialog(hwndDlg, IDREMOVE);
}