summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdb/src/dbcrypt.cpp
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-02-27 15:28:11 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-02-27 15:28:11 +0000
commit2814cd2a0f6ed89dab0c4dca6b8dbb2c7523bef9 (patch)
tree07be53471abaafa30b04d0973882695739053488 /plugins/Dbx_mdb/src/dbcrypt.cpp
parentb5516cbe14bd01912dc2917be0f9f892bdbd74c4 (diff)
dbx_lmdb: gui rewritted to ui_utils
git-svn-id: http://svn.miranda-ng.org/main/trunk@16362 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mdb/src/dbcrypt.cpp')
-rw-r--r--plugins/Dbx_mdb/src/dbcrypt.cpp75
1 files changed, 37 insertions, 38 deletions
diff --git a/plugins/Dbx_mdb/src/dbcrypt.cpp b/plugins/Dbx_mdb/src/dbcrypt.cpp
index 1a4fe39276..31d7f69dda 100644
--- a/plugins/Dbx_mdb/src/dbcrypt.cpp
+++ b/plugins/Dbx_mdb/src/dbcrypt.cpp
@@ -45,10 +45,14 @@ CRYPTO_PROVIDER* CDbxMdb::SelectProvider()
}
else pProv = ppProvs[0];
- txn_ptr txn(m_pMdbEnv);
- MDB_val key = { sizeof(DBKEY_PROVIDER), DBKEY_PROVIDER }, value = { mir_strlen(pProv->pszName) + 1, pProv->pszName };
- mdb_put(txn, m_dbCrypto, &key, &value, 0);
- txn.commit();
+ for (;; Remap())
+ {
+ txn_ptr txn(m_pMdbEnv);
+ MDB_val key = { sizeof(DBKEY_PROVIDER), DBKEY_PROVIDER }, value = { mir_strlen(pProv->pszName) + 1, pProv->pszName };
+ mdb_put(txn, m_dbCrypto, &key, &value, 0);
+ if (txn.commit())
+ break;
+ }
return pProv;
}
@@ -102,7 +106,7 @@ int CDbxMdb::InitCrypt()
key.mv_size = sizeof(DBKEY_IS_ENCRYPTED); key.mv_data = DBKEY_IS_ENCRYPTED;
if (mdb_get(txn, m_dbCrypto, &key, &value) == MDB_SUCCESS)
- m_bEncrypted = *(const BYTE*)value.mv_data != 0;
+ m_bEncrypted = *(const bool*)value.mv_data;
else
m_bEncrypted = false;
@@ -116,11 +120,14 @@ void CDbxMdb::StoreKey()
BYTE *pKey = (BYTE*)_alloca(iKeyLength);
m_crypto->getKey(pKey, iKeyLength);
- txn_ptr txn(m_pMdbEnv);
- MDB_val key = { sizeof(DBKEY_KEY), DBKEY_KEY }, value = { iKeyLength, pKey };
- mdb_put(txn, m_dbCrypto, &key, &value, 0);
- txn.commit();
-
+ for (;; Remap())
+ {
+ txn_ptr txn(m_pMdbEnv);
+ MDB_val key = { sizeof(DBKEY_KEY), DBKEY_KEY }, value = { iKeyLength, pKey };
+ mdb_put(txn, m_dbCrypto, &key, &value, 0);
+ if (txn.commit())
+ break;
+ }
SecureZeroMemory(pKey, iKeyLength);
}
@@ -139,39 +146,31 @@ void CDbxMdb::SetPassword(LPCTSTR ptszPassword)
/////////////////////////////////////////////////////////////////////////////////////////
-void CDbxMdb::ToggleEncryption()
+int CDbxMdb::EnableEncryption(bool bEncrypted)
{
- HANDLE hSave1 = hSettingChangeEvent; hSettingChangeEvent = NULL;
- HANDLE hSave2 = hEventAddedEvent; hEventAddedEvent = NULL;
- HANDLE hSave3 = hEventDeletedEvent; hEventDeletedEvent = NULL;
- HANDLE hSave4 = hEventFilterAddedEvent; hEventFilterAddedEvent = NULL;
+ if (m_bEncrypted == bEncrypted)
+ return 0;
mir_cslock lck(m_csDbAccess);
- ToggleSettingsEncryption(NULL);
- ToggleEventsEncryption(NULL);
-
- for (MCONTACT contactID = FindFirstContact(); contactID; contactID = FindNextContact(contactID)) {
- ToggleSettingsEncryption(contactID);
- ToggleEventsEncryption(contactID);
+ for (MCONTACT contactID = FindFirstContact(); contactID; contactID = FindNextContact(contactID))
+ {
+ EnableContactEncryption(contactID, bEncrypted);
}
- m_bEncrypted = !m_bEncrypted;
-
- txn_ptr txn(m_pMdbEnv);
- MDB_val key = { sizeof(DBKEY_IS_ENCRYPTED), DBKEY_IS_ENCRYPTED }, value = { sizeof(BYTE), &m_bEncrypted };
- mdb_put(txn, m_dbCrypto, &key, &value, 0);
- txn.commit();
-
- hSettingChangeEvent = hSave1;
- hEventAddedEvent = hSave2;
- hEventDeletedEvent = hSave3;
- hEventFilterAddedEvent = hSave4;
-}
-
-void CDbxMdb::ToggleSettingsEncryption(MCONTACT /*contactID*/)
-{
+ for (;; Remap())
+ {
+ txn_ptr txn(m_pMdbEnv);
+ MDB_val key = { sizeof(DBKEY_IS_ENCRYPTED), DBKEY_IS_ENCRYPTED }, value = { sizeof(bool), &bEncrypted };
+ MDB_CHECK(mdb_put(txn, m_dbCrypto, &key, &value, 0), 1);
+ if (txn.commit())
+ break;
+ }
+ m_bEncrypted = bEncrypted;
+ return 0;
}
-void CDbxMdb::ToggleEventsEncryption(MCONTACT /*contactID*/)
+int CDbxMdb::EnableContactEncryption(MCONTACT hContact, bool bEncrypted)
{
-}
+ //TODO: encrypt/decrypt all contact events and settings
+ return 0;
+} \ No newline at end of file