From cf751286442fa9b4b4843ae1091625e6a6c7ba2d Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Fri, 19 Feb 2016 15:20:53 +0000 Subject: dbx_lmdb: fixed writing settings; CryptoProvider selector; correct transactions revert git-svn-id: http://svn.miranda-ng.org/main/trunk@16310 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dbx_mdb/db3x_lmdb.vcxproj | 33 ------------------- plugins/Dbx_mdb/db3x_lmdb.vcxproj.filters | 4 --- plugins/Dbx_mdb/dbx_lmdb.vcxproj | 33 +++++++++++++++++++ plugins/Dbx_mdb/dbx_lmdb.vcxproj.filters | 4 +++ plugins/Dbx_mdb/res/dbx_mdb.rc | 11 +++++++ plugins/Dbx_mdb/src/dbcontacts.cpp | 13 +++++++- plugins/Dbx_mdb/src/dbcrypt.cpp | 11 +++++-- plugins/Dbx_mdb/src/dbevents.cpp | 9 ++++-- plugins/Dbx_mdb/src/dbintf.cpp | 13 -------- plugins/Dbx_mdb/src/dbintf.h | 17 +++++++--- plugins/Dbx_mdb/src/dbmodulechain.cpp | 2 +- plugins/Dbx_mdb/src/dbsettings.cpp | 43 ++++++++++--------------- plugins/Dbx_mdb/src/resource.h | 8 +++-- plugins/Dbx_mdb/src/stdafx.h | 10 ++---- plugins/Dbx_mdb/src/ui.h | 53 +++++++++++++++++++++++++++++++ 15 files changed, 166 insertions(+), 98 deletions(-) delete mode 100644 plugins/Dbx_mdb/db3x_lmdb.vcxproj delete mode 100644 plugins/Dbx_mdb/db3x_lmdb.vcxproj.filters create mode 100644 plugins/Dbx_mdb/dbx_lmdb.vcxproj create mode 100644 plugins/Dbx_mdb/dbx_lmdb.vcxproj.filters create mode 100644 plugins/Dbx_mdb/src/ui.h (limited to 'plugins/Dbx_mdb') diff --git a/plugins/Dbx_mdb/db3x_lmdb.vcxproj b/plugins/Dbx_mdb/db3x_lmdb.vcxproj deleted file mode 100644 index 032e3f1b98..0000000000 --- a/plugins/Dbx_mdb/db3x_lmdb.vcxproj +++ /dev/null @@ -1,33 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - Dbx_lmdb - {E0ACDEA0-0AC9-4431-8CA3-6B0CCACB2E18} - - - - - - - NotUsing - - - \ No newline at end of file diff --git a/plugins/Dbx_mdb/db3x_lmdb.vcxproj.filters b/plugins/Dbx_mdb/db3x_lmdb.vcxproj.filters deleted file mode 100644 index de5ad9f66c..0000000000 --- a/plugins/Dbx_mdb/db3x_lmdb.vcxproj.filters +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/plugins/Dbx_mdb/dbx_lmdb.vcxproj b/plugins/Dbx_mdb/dbx_lmdb.vcxproj new file mode 100644 index 0000000000..032e3f1b98 --- /dev/null +++ b/plugins/Dbx_mdb/dbx_lmdb.vcxproj @@ -0,0 +1,33 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + Dbx_lmdb + {E0ACDEA0-0AC9-4431-8CA3-6B0CCACB2E18} + + + + + + + NotUsing + + + \ No newline at end of file diff --git a/plugins/Dbx_mdb/dbx_lmdb.vcxproj.filters b/plugins/Dbx_mdb/dbx_lmdb.vcxproj.filters new file mode 100644 index 0000000000..de5ad9f66c --- /dev/null +++ b/plugins/Dbx_mdb/dbx_lmdb.vcxproj.filters @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/plugins/Dbx_mdb/res/dbx_mdb.rc b/plugins/Dbx_mdb/res/dbx_mdb.rc index 3f12bcfe98..0dc89c67f3 100644 --- a/plugins/Dbx_mdb/res/dbx_mdb.rc +++ b/plugins/Dbx_mdb/res/dbx_mdb.rc @@ -23,6 +23,17 @@ 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,14,199,30,CBS_DROPDOWN | CBS_SORT | WS_TABSTOP + LTEXT "",IDC_CRYPTOPROVIDER_DESCR,18,34,197,14,NOT WS_GROUP +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_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp index 554df02d9a..c9e549da8e 100644 --- a/plugins/Dbx_mdb/src/dbcontacts.cpp +++ b/plugins/Dbx_mdb/src/dbcontacts.cpp @@ -258,6 +258,17 @@ void DBCachedContact::Advance(DWORD id, DBEvent &dbe) } } +void DBCachedContact::Snapshot() +{ + memcpy(&tmp_dbc, &dbc, sizeof(dbc)); +} + +void DBCachedContact::Revert() +{ + memcpy(&dbc, &tmp_dbc, sizeof(dbc)); + memset(&tmp_dbc, 0, sizeof(dbc)); +} + ///////////////////////////////////////////////////////////////////////////////////////// // initial cycle to fill the contacts' cache @@ -266,7 +277,7 @@ void CDbxMdb::FillContacts() LIST arContacts(10); txn_ptr trnlck(m_pMdbEnv); - mdb_open(trnlck, "contacts", MDB_INTEGERKEY, &m_dbContacts); + //mdb_open(trnlck, "contacts", MDB_INTEGERKEY, &m_dbContacts); { cursor_ptr cursor(trnlck, m_dbContacts); diff --git a/plugins/Dbx_mdb/src/dbcrypt.cpp b/plugins/Dbx_mdb/src/dbcrypt.cpp index 2cf2613c45..f13e74aa81 100644 --- a/plugins/Dbx_mdb/src/dbcrypt.cpp +++ b/plugins/Dbx_mdb/src/dbcrypt.cpp @@ -141,7 +141,13 @@ int CDbxMdb::InitCrypt() if (iNumProvs == 0) return 1; - pProvider = ppProvs[0]; //!!!!!!!!!!!!!!!!!! + if (iNumProvs > 1) + { + CSelectCryptoDialog dlg(ppProvs, iNumProvs); + dlg.DoModal(); + pProvider = dlg.GetSelected(); + } + else pProvider = ppProvs[0]; DBCONTACTWRITESETTING dbcws = { "CryptoEngine", "Provider" }; dbcws.value.type = DBVT_BLOB; @@ -149,7 +155,8 @@ int CDbxMdb::InitCrypt() dbcws.value.cpbVal = (int)strlen(pProvider->pszName) + 1; WriteContactSetting(NULL, &dbcws); } - else { + else + { if (dbv.type != DBVT_BLOB) { // old version, clean it up bMissingKey = true; goto LBL_CreateProvider; diff --git a/plugins/Dbx_mdb/src/dbevents.cpp b/plugins/Dbx_mdb/src/dbevents.cpp index d8c5a37d6d..39ec4d4afb 100644 --- a/plugins/Dbx_mdb/src/dbevents.cpp +++ b/plugins/Dbx_mdb/src/dbevents.cpp @@ -84,7 +84,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) mir_cslockfull lck(m_csDbAccess); DWORD dwEventId = ++m_dwMaxEventId; - for (bool bContactIncremented = false; ;[=](){ if (bContactIncremented) cc->dbc.dwEventCount--; }(), Remap()) { + for (bool bContactIncremented = false; ;[=](){ if (bContactIncremented) cc->Revert(); }(), Remap()) { txn_ptr txn(m_pMdbEnv); MDB_val key = { sizeof(int), &dwEventId }, data = { sizeof(DBEvent) + dbe.cbBlob, NULL }; @@ -100,6 +100,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) data.mv_size = 1; data.mv_data = ""; MDB_CHECK(mdb_put(txn, m_dbEventsSort, &key, &data, 0), 0); + cc->Snapshot(); cc->Advance(dwEventId, dbe); bContactIncremented = true; MDB_val keyc = { sizeof(int), &contactID }, datac = { sizeof(DBContact), &cc->dbc }; @@ -137,7 +138,7 @@ STDMETHODIMP_(BOOL) CDbxMdb::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) mir_cslockfull lck(m_csDbAccess); - for (bool bContactDecremented = false; ;[=](){ if (bContactDecremented) cc->dbc.dwEventCount++; }(), Remap()) + for (bool bContactDecremented = false; ; [=](){ if (bContactDecremented) cc->Revert(); }(), Remap()) { txn_ptr txn(m_pMdbEnv); MDB_val key = { sizeof(MEVENT), &hDbEvent }, data; @@ -163,6 +164,8 @@ STDMETHODIMP_(BOOL) CDbxMdb::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) // update a contact key.mv_size = sizeof(int); key.mv_data = &contactID; + + cc->Snapshot(); cc->dbc.dwEventCount--; bContactDecremented = true; if (cc->dbc.dwFirstUnread == hDbEvent) @@ -170,7 +173,7 @@ STDMETHODIMP_(BOOL) CDbxMdb::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) data = { sizeof(DBContact), &cc->dbc }; - MDB_CHECK(mdb_put(txn, m_dbContacts, &key, &data, 0), 0); + MDB_CHECK(mdb_put(txn, m_dbContacts, &key, &data, 0), 1); if (txn.commit()) break; diff --git a/plugins/Dbx_mdb/src/dbintf.cpp b/plugins/Dbx_mdb/src/dbintf.cpp index b7c0c81572..cb044d622f 100644 --- a/plugins/Dbx_mdb/src/dbintf.cpp +++ b/plugins/Dbx_mdb/src/dbintf.cpp @@ -23,18 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -#define CMP_UINT32(A,B) if (A != B) return (A < B) ? -1 : 1; - -static int MDB_CompareEvents(const MDB_val *v1, const MDB_val *v2) -{ - DBEventSortingKey *k1 = static_cast(v1->mv_data); - DBEventSortingKey *k2 = static_cast(v2->mv_data); - CMP_UINT32(k1->dwContactId, k2->dwContactId); - CMP_UINT32(k1->ts, k2->ts); - CMP_UINT32(k1->dwEventId, k2->dwEventId); - return 0; -} - static int ModCompare(const ModuleName *mn1, const ModuleName *mn2) { return strcmp(mn1->name, mn2->name); @@ -110,7 +98,6 @@ int CDbxMdb::Load(bool bSkipInit) mdb_open(trnlck, "eventsrt", MDB_CREATE | MDB_INTEGERKEY, &m_dbEventsSort); mdb_open(trnlck, "settings", MDB_CREATE, &m_dbSettings); - //mdb_set_compare(trnlck, m_dbEventsSort, MDB_CompareEvents); DWORD keyVal = 1; MDB_val key = { sizeof(DWORD), &keyVal }, data; diff --git a/plugins/Dbx_mdb/src/dbintf.h b/plugins/Dbx_mdb/src/dbintf.h index 866b637786..d6751960b2 100644 --- a/plugins/Dbx_mdb/src/dbintf.h +++ b/plugins/Dbx_mdb/src/dbintf.h @@ -103,18 +103,27 @@ struct DBEvent } }; -#include - struct DBEventSortingKey { DWORD dwEventId, ts, dwContactId; }; +struct DBSettingKey +{ + DWORD dwContactID; + DWORD dwOfsModule; + char szSettingName[100]; +}; + + +#include + struct DBCachedContact : public DBCachedContactBase { void Advance(DWORD id, DBEvent &dbe); - - DBContact dbc; + void Snapshot(); + void Revert(); + DBContact dbc, tmp_dbc; }; struct EventItem diff --git a/plugins/Dbx_mdb/src/dbmodulechain.cpp b/plugins/Dbx_mdb/src/dbmodulechain.cpp index a91ccc576c..faff9df351 100644 --- a/plugins/Dbx_mdb/src/dbmodulechain.cpp +++ b/plugins/Dbx_mdb/src/dbmodulechain.cpp @@ -119,7 +119,7 @@ DWORD CDbxMdb::GetModuleNameOfs(const char *szName) AddToList(mod, newIdx); // quit - return -1; + return newIdx; } char* CDbxMdb::GetModuleNameByOfs(DWORD ofs) diff --git a/plugins/Dbx_mdb/src/dbsettings.cpp b/plugins/Dbx_mdb/src/dbsettings.cpp index ebfe1970b4..d5ff44266b 100644 --- a/plugins/Dbx_mdb/src/dbsettings.cpp +++ b/plugins/Dbx_mdb/src/dbsettings.cpp @@ -23,13 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -struct DBSettingKey -{ - DWORD dwContactID; - DWORD dwOfsModule; - char szSettingName[100]; -}; - #define VLT(n) ((n == DBVT_UTF8 || n == DBVT_ENCRYPTED)?DBVT_ASCIIZ:n) BOOL CDbxMdb::IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting) @@ -372,23 +365,13 @@ STDMETHODIMP_(BOOL) CDbxMdb::WriteContactSetting(MCONTACT contactID, DBCONTACTWR // the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name int settingNameLen = (int)strlen(dbcws->szSetting); int moduleNameLen = (int)strlen(dbcws->szModule); - if (settingNameLen > 0xFE) { -#ifdef _DEBUG - OutputDebugStringA("WriteContactSetting() got a > 255 setting name length. \n"); -#endif - return 1; - } - if (moduleNameLen > 0xFE) { -#ifdef _DEBUG - OutputDebugStringA("WriteContactSetting() got a > 255 module name length. \n"); -#endif - return 1; - } // used for notifications DBCONTACTWRITESETTING dbcwNotif = *dbcws; - if (dbcwNotif.value.type == DBVT_WCHAR) { - if (dbcwNotif.value.pszVal != NULL) { + if (dbcwNotif.value.type == DBVT_WCHAR) + { + if (dbcwNotif.value.pszVal != NULL) + { char* val = mir_utf8encodeW(dbcwNotif.value.pwszVal); if (val == NULL) return 1; @@ -418,10 +401,12 @@ STDMETHODIMP_(BOOL) CDbxMdb::WriteContactSetting(MCONTACT contactID, DBCONTACTWR if (dbcwWork.value.pszVal == NULL) return 1; dbcwWork.value.cchVal = (WORD)strlen(dbcwWork.value.pszVal); - if (bIsEncrypted) { + if (bIsEncrypted) + { size_t len; BYTE *pResult = m_crypto->encodeString(dbcwWork.value.pszVal, &len); - if (pResult != NULL) { + if (pResult != NULL) + { pEncoded = dbcwWork.value.pbVal = pResult; dbcwWork.value.cpbVal = (WORD)len; dbcwWork.value.type = DBVT_ENCRYPTED; @@ -446,11 +431,14 @@ STDMETHODIMP_(BOOL) CDbxMdb::WriteContactSetting(MCONTACT contactID, DBCONTACTWR char *szCachedSettingName = m_cache->GetCachedSetting(dbcwWork.szModule, dbcwWork.szSetting, moduleNameLen, settingNameLen); // we don't cache blobs and passwords - if (dbcwWork.value.type != DBVT_BLOB && dbcwWork.value.type != DBVT_ENCRYPTED && !bIsEncrypted) { + if (dbcwWork.value.type != DBVT_BLOB && dbcwWork.value.type != DBVT_ENCRYPTED && !bIsEncrypted) + { DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, 1); - if (pCachedValue != NULL) { + if (pCachedValue != NULL) + { bool bIsIdentical = false; - if (pCachedValue->type == dbcwWork.value.type) { + if (pCachedValue->type == dbcwWork.value.type) + { switch (dbcwWork.value.type) { case DBVT_BYTE: bIsIdentical = pCachedValue->bVal == dbcwWork.value.bVal; break; case DBVT_WORD: bIsIdentical = pCachedValue->wVal == dbcwWork.value.wVal; break; @@ -463,7 +451,8 @@ STDMETHODIMP_(BOOL) CDbxMdb::WriteContactSetting(MCONTACT contactID, DBCONTACTWR } m_cache->SetCachedVariant(&dbcwWork.value, pCachedValue); } - if (szCachedSettingName[-1] != 0) { + if (szCachedSettingName[-1] != 0) + { lck.unlock(); NotifyEventHooks(hSettingChangeEvent, contactID, (LPARAM)&dbcwWork); return 0; diff --git a/plugins/Dbx_mdb/src/resource.h b/plugins/Dbx_mdb/src/resource.h index be74c3e5e8..cd5530394c 100644 --- a/plugins/Dbx_mdb/src/resource.h +++ b/plugins/Dbx_mdb/src/resource.h @@ -11,6 +11,7 @@ #define IDD_NEWPASS 103 #define IDD_CHANGEPASS 104 #define IDD_OPTIONS 105 +#define IDD_SELECT_CRYPTOPROVIDER 106 #define IDC_HEADERBAR 1001 #define IDC_LANG 1002 #define IDC_USERPASS 1003 @@ -19,14 +20,15 @@ #define IDC_OLDPASS 1006 #define IDC_STANDARD 1007 #define IDC_TOTAL 1008 - +#define IDC_SELECTCRYPT_COMBO 1010 +#define IDC_CRYPTOPROVIDER_DESCR 1011 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 106 +#define _APS_NEXT_RESOURCE_VALUE 107 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1009 +#define _APS_NEXT_CONTROL_VALUE 1012 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/plugins/Dbx_mdb/src/stdafx.h b/plugins/Dbx_mdb/src/stdafx.h index ee324a69ee..0a777f5e5b 100644 --- a/plugins/Dbx_mdb/src/stdafx.h +++ b/plugins/Dbx_mdb/src/stdafx.h @@ -38,6 +38,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include extern "C" { @@ -91,8 +92,7 @@ public: __forceinline ~txn_ptr_ro() { - if (m_txn) - mdb_txn_reset(m_txn); + mdb_txn_reset(m_txn); } __forceinline operator MDB_txn*() const { return m_txn; } @@ -131,8 +131,4 @@ public: extern HINSTANCE g_hInst; extern LIST g_Dbs; -#ifdef __GNUC__ -#define mir_i64(x) (x##LL) -#else -#define mir_i64(x) (x##i64) -#endif +#include "ui.h" diff --git a/plugins/Dbx_mdb/src/ui.h b/plugins/Dbx_mdb/src/ui.h new file mode 100644 index 0000000000..d723e684c0 --- /dev/null +++ b/plugins/Dbx_mdb/src/ui.h @@ -0,0 +1,53 @@ + + +class CSelectCryptoDialog : public CDlgBase +{ + CCtrlCombo m_combo; + CCtrlData m_descr; + //CCtrlCustom m_descr; + CRYPTO_PROVIDER **m_provs; + size_t m_provscount; + CRYPTO_PROVIDER *m_selected; +public: + CSelectCryptoDialog(CRYPTO_PROVIDER **provs, size_t count) : + CDlgBase(g_hInst, IDD_SELECT_CRYPTOPROVIDER), + m_combo(this, IDC_SELECTCRYPT_COMBO), + m_descr(this, IDC_CRYPTOPROVIDER_DESCR), + m_provs(provs), + m_provscount(count), + m_selected(nullptr) + { + m_combo.OnChange = Callback(this, &CSelectCryptoDialog::OnComboChanged); + } + + void OnInitDialog() + { + 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); + SetDescr(m_provs[0]); + } + + void OnClose() + { + m_selected = m_provs[ m_combo.GetItemData(m_combo.GetCurSel()) ]; + } + + void OnComboChanged(CCtrlCombo*) + { + SetDescr(m_provs[m_combo.GetItemData(m_combo.GetCurSel())]); + } + + void SetDescr(CRYPTO_PROVIDER *prov) + { + m_descr.SetText(prov->ptszDescr); + } + + inline CRYPTO_PROVIDER* GetSelected() + { + return m_selected; + } +}; \ No newline at end of file -- cgit v1.2.3