summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdbx
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-01-08 14:54:51 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-01-08 14:54:51 +0300
commit64579d553e4089d55c136140bd0058696d2cf526 (patch)
tree7b7e6c5cd03b9060bd7080b5981938005436b432 /plugins/Dbx_mdbx
parentdae0d079ad629d499034ff911e0b1a807c19fce0 (diff)
another bunch of duplicate code moved to the core
Diffstat (limited to 'plugins/Dbx_mdbx')
-rw-r--r--plugins/Dbx_mdbx/res/dbx_mdbx.rc13
-rw-r--r--plugins/Dbx_mdbx/src/dbcrypt.cpp89
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.h3
-rw-r--r--plugins/Dbx_mdbx/src/resource.h4
-rw-r--r--plugins/Dbx_mdbx/src/ui.cpp6
5 files changed, 9 insertions, 106 deletions
diff --git a/plugins/Dbx_mdbx/res/dbx_mdbx.rc b/plugins/Dbx_mdbx/res/dbx_mdbx.rc
index 81d739e697..61530296f2 100644
--- a/plugins/Dbx_mdbx/res/dbx_mdbx.rc
+++ b/plugins/Dbx_mdbx/res/dbx_mdbx.rc
@@ -23,19 +23,6 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
// Dialog
//
-IDD_SELECT_CRYPTOPROVIDER DIALOGEX 0, 0, 229, 76
-STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Select crypto provider"
-FONT 8, "MS Shell Dlg", 400, 0, 0x1
-BEGIN
- DEFPUSHBUTTON "OK",IDOK,113,55,50,14
- PUSHBUTTON "Cancel",IDCANCEL,172,55,50,14
- COMBOBOX IDC_SELECTCRYPT_COMBO,16,12,199,30,CBS_DROPDOWNLIST | CBS_SORT | WS_TABSTOP
- LTEXT "",IDC_CRYPTOPROVIDER_DESCR,17,29,197,14,NOT WS_GROUP
- CONTROL "Total encryption (Recommended only for paranoid users)",IDC_CHECK_TOTALCRYPT,
- "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,14,45,89,24
-END
-
IDD_LOGIN DIALOGEX 0, 0, 190, 86
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW
diff --git a/plugins/Dbx_mdbx/src/dbcrypt.cpp b/plugins/Dbx_mdbx/src/dbcrypt.cpp
index 2f8f10ce7e..d20315b773 100644
--- a/plugins/Dbx_mdbx/src/dbcrypt.cpp
+++ b/plugins/Dbx_mdbx/src/dbcrypt.cpp
@@ -23,96 +23,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-class CSelectCryptoDialog : public CDlgBase
-{
- CCtrlCombo m_combo;
- CCtrlData m_descr;
- CCtrlCheck m_chkTotalCrypt;
- CRYPTO_PROVIDER **m_provs;
- size_t m_provscount;
- CRYPTO_PROVIDER *m_selected;
- bool m_bTotalEncryption;
-
- bool OnInitDialog() override
- {
- for (size_t i = 0; i < m_provscount; i++) {
- CRYPTO_PROVIDER *prov = m_provs[i];
- m_combo.AddStringA(prov->pszName, i);
- }
- m_combo.SetCurSel(0);
- m_descr.SetText(m_provs[0]->szDescr.w);
- return true;
- }
-
- bool OnApply() override
- {
- m_selected = m_provs[m_combo.GetItemData(m_combo.GetCurSel())];
- m_bTotalEncryption = m_chkTotalCrypt.GetState() != 0;
- return true;
- }
-
- void OnComboChanged(CCtrlCombo*)
- {
- m_descr.SetText(m_provs[m_combo.GetItemData(m_combo.GetCurSel())]->szDescr.w);
- }
-
-public:
- CSelectCryptoDialog(CRYPTO_PROVIDER **provs, size_t count) :
- CDlgBase(g_plugin, IDD_SELECT_CRYPTOPROVIDER),
- m_combo(this, IDC_SELECTCRYPT_COMBO),
- m_descr(this, IDC_CRYPTOPROVIDER_DESCR),
- m_chkTotalCrypt(this, IDC_CHECK_TOTALCRYPT),
- m_provs(provs),
- m_provscount(count),
- m_selected(nullptr)
- {
- m_combo.OnChange = Callback(this, &CSelectCryptoDialog::OnComboChanged);
- }
-
- inline CRYPTO_PROVIDER* GetSelected()
- { return m_selected;
- }
- inline bool TotalSelected()
- { return m_bTotalEncryption;
- }
-};
-
char DBKey_Crypto_Provider[] = "Provider";
char DBKey_Crypto_Key[] = "Key";
char DBKey_Crypto_IsEncrypted[] = "EncryptedDB";
-CRYPTO_PROVIDER* CDbxMDBX::SelectProvider()
+STDMETHODIMP_(BOOL) CDbxMDBX::StoreProvider(CRYPTO_PROVIDER *pProv)
{
- CRYPTO_PROVIDER **ppProvs, *pProv;
- int iNumProvs;
- Crypto_EnumProviders(&iNumProvs, &ppProvs);
-
- if (iNumProvs == 0)
- return nullptr;
-
- bool bTotalCrypt = false;
-
- if (iNumProvs > 1) {
- CSelectCryptoDialog dlg(ppProvs, iNumProvs);
- dlg.DoModal();
- pProv = dlg.GetSelected();
- bTotalCrypt = dlg.TotalSelected();
- }
- else pProv = ppProvs[0];
-
- {
- txn_ptr trnlck(this);
- MDBX_val key = { DBKey_Crypto_Provider, sizeof(DBKey_Crypto_Provider) }, value = { pProv->pszName, mir_strlen(pProv->pszName) + 1 };
- if (mdbx_put(trnlck, m_dbCrypto, &key, &value, MDBX_UPSERT) != 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(trnlck, m_dbCrypto, &key, &value, MDBX_UPSERT) != MDBX_SUCCESS)
- return nullptr;
- }
+ txn_ptr trnlck(this);
+ MDBX_val key = { DBKey_Crypto_Provider, sizeof(DBKey_Crypto_Provider) }, value = { pProv->pszName, mir_strlen(pProv->pszName) + 1 };
+ if (mdbx_put(trnlck, m_dbCrypto, &key, &value, MDBX_UPSERT) != MDBX_SUCCESS)
+ return FALSE;
DBFlush();
- return pProv;
+ return TRUE;
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h
index c802b05d3b..1003c31c7c 100644
--- a/plugins/Dbx_mdbx/src/dbintf.h
+++ b/plugins/Dbx_mdbx/src/dbintf.h
@@ -225,8 +225,6 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe
MDBX_dbi m_dbCrypto;
int InitCrypt(void);
- CRYPTO_PROVIDER* SelectProvider();
-
void InitDialogs();
public:
@@ -283,6 +281,7 @@ public:
STDMETHODIMP_(BOOL) MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) override;
STDMETHODIMP_(BOOL) MetaRemoveSubHistory(DBCachedContact *ccSub) override;
+ STDMETHODIMP_(BOOL) StoreProvider(CRYPTO_PROVIDER*);
STDMETHODIMP_(BOOL) Compact();
STDMETHODIMP_(BOOL) Backup(const wchar_t*);
diff --git a/plugins/Dbx_mdbx/src/resource.h b/plugins/Dbx_mdbx/src/resource.h
index dfc3ffc748..a6c8f8644e 100644
--- a/plugins/Dbx_mdbx/src/resource.h
+++ b/plugins/Dbx_mdbx/src/resource.h
@@ -8,7 +8,6 @@
#define IDD_NEWPASS 103
#define IDD_CHANGEPASS 104
#define IDD_OPTIONS 105
-#define IDD_SELECT_CRYPTOPROVIDER 106
#define IDI_COMPACT 107
#define IDC_HEADERBAR 1001
#define IDC_LANG 1002
@@ -18,9 +17,6 @@
#define IDC_OLDPASS 1006
#define IDC_STANDARD 1007
#define IDC_TOTAL 1008
-#define IDC_SELECTCRYPT_COMBO 1010
-#define IDC_CRYPTOPROVIDER_DESCR 1011
-#define IDC_CHECK_TOTALCRYPT 1012
// Next default values for new objects
//
diff --git a/plugins/Dbx_mdbx/src/ui.cpp b/plugins/Dbx_mdbx/src/ui.cpp
index 971f31c8db..6b7ce1fe83 100644
--- a/plugins/Dbx_mdbx/src/ui.cpp
+++ b/plugins/Dbx_mdbx/src/ui.cpp
@@ -43,13 +43,11 @@ void LanguageChanged(HWND hwndDlg)
static bool CheckOldPassword(HWND hwndDlg, CDbxMDBX *db)
{
- if (db->usesPassword())
- {
+ if (db->usesPassword()) {
wchar_t buf[100];
GetDlgItemText(hwndDlg, IDC_OLDPASS, buf, _countof(buf));
pass_ptrA oldPass(mir_utf8encodeW(buf));
- if (!db->getCrypt()->checkPassword(oldPass))
- {
+ if (!db->getCrypt()->checkPassword(oldPass)) {
SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Wrong old password entered!"));
return false;
}