summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdb
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Dbx_mdb')
-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
5 files changed, 39 insertions, 156 deletions
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);
}