diff options
author | George Hazan <ghazan@miranda.im> | 2021-01-08 14:54:51 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-01-08 14:54:51 +0300 |
commit | 64579d553e4089d55c136140bd0058696d2cf526 (patch) | |
tree | 7b7e6c5cd03b9060bd7080b5981938005436b432 /src/mir_app | |
parent | dae0d079ad629d499034ff911e0b1a807c19fce0 (diff) |
another bunch of duplicate code moved to the core
Diffstat (limited to 'src/mir_app')
-rw-r--r-- | src/mir_app/mir_app.vcxproj | 2 | ||||
-rw-r--r-- | src/mir_app/mir_app.vcxproj.filters | 6 | ||||
-rw-r--r-- | src/mir_app/res/resource.rc | 10 | ||||
-rw-r--r-- | src/mir_app/src/MDatabaseCommon.cpp | 18 | ||||
-rw-r--r-- | src/mir_app/src/MDatabaseCommonCrypt.cpp | 113 | ||||
-rw-r--r-- | src/mir_app/src/MDatabaseReadonly.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/encrypt.cpp | 62 | ||||
-rw-r--r-- | src/mir_app/src/encrypt.h | 45 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 5 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 5 | ||||
-rw-r--r-- | src/mir_app/src/modules.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/resource.h | 3 | ||||
-rw-r--r-- | src/mir_app/src/utils.cpp | 16 |
13 files changed, 208 insertions, 81 deletions
diff --git a/src/mir_app/mir_app.vcxproj b/src/mir_app/mir_app.vcxproj index 3241cf4fc9..e1281e19e6 100644 --- a/src/mir_app/mir_app.vcxproj +++ b/src/mir_app/mir_app.vcxproj @@ -92,6 +92,7 @@ <ClCompile Include="src\lpopts.cpp" />
<ClCompile Include="src\mdatabasecache.cpp" />
<ClCompile Include="src\MDatabaseCommon.cpp" />
+ <ClCompile Include="src\MDatabaseCommonCrypt.cpp" />
<ClCompile Include="src\MDatabaseReadonly.cpp" />
<ClCompile Include="src\menu_clist.cpp" />
<ClCompile Include="src\menu_frames.cpp" />
@@ -160,6 +161,7 @@ <ClInclude Include="src\chat.h" />
<ClInclude Include="src\clc.h" />
<ClInclude Include="src\database.h" />
+ <ClInclude Include="src\encrypt.h" />
<ClInclude Include="src\extraicons.h" />
<ClInclude Include="src\filter.h" />
<ClInclude Include="src\findadd.h" />
diff --git a/src/mir_app/mir_app.vcxproj.filters b/src/mir_app/mir_app.vcxproj.filters index 927addb7c9..49ad63544f 100644 --- a/src/mir_app/mir_app.vcxproj.filters +++ b/src/mir_app/mir_app.vcxproj.filters @@ -389,6 +389,9 @@ <ClCompile Include="src\pu_utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\MDatabaseCommonCrypt.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\chat.h">
@@ -451,6 +454,9 @@ <ClInclude Include="src\usedIcons.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="src\encrypt.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\resource.rc">
diff --git a/src/mir_app/res/resource.rc b/src/mir_app/res/resource.rc index 8e88a2c601..30b353082e 100644 --- a/src/mir_app/res/resource.rc +++ b/src/mir_app/res/resource.rc @@ -879,6 +879,16 @@ CAPTION "Hidden window" BEGIN
END
+IDD_SELECT_CRYPTOPROVIDER DIALOGEX 0, 0, 229, 45
+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
+END
/////////////////////////////////////////////////////////////////////////////
//
diff --git a/src/mir_app/src/MDatabaseCommon.cpp b/src/mir_app/src/MDatabaseCommon.cpp index a7240dc764..787c6609bd 100644 --- a/src/mir_app/src/MDatabaseCommon.cpp +++ b/src/mir_app/src/MDatabaseCommon.cpp @@ -183,24 +183,6 @@ STDMETHODIMP_(MCONTACT) MDatabaseCommon::FindNextContact(MCONTACT contactID, con } ///////////////////////////////////////////////////////////////////////////////////////// -// Encryption support - -BOOL MDatabaseCommon::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; -} - -///////////////////////////////////////////////////////////////////////////////////////// // Meta-contacts support BOOL MDatabaseCommon::MetaDetouchSub(DBCachedContact *cc, int nSub) diff --git a/src/mir_app/src/MDatabaseCommonCrypt.cpp b/src/mir_app/src/MDatabaseCommonCrypt.cpp new file mode 100644 index 0000000000..0b3a135e46 --- /dev/null +++ b/src/mir_app/src/MDatabaseCommonCrypt.cpp @@ -0,0 +1,113 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (C) 2012-20 Miranda NG team, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" +#include "database.h" +#include "encrypt.h" + +///////////////////////////////////////////////////////////////////////////////////////// +// Provider selection dialog + +class CSelectCryptoDialog : public CDlgBase +{ + CCtrlCombo m_combo; + CCtrlData m_descr; + CRYPTO_PROVIDER *m_selected = nullptr; + + CRYPTO_PROVIDER *getCurrent() + { + return (CRYPTO_PROVIDER*)m_combo.GetItemData(m_combo.GetCurSel()); + } + + bool OnInitDialog() override + { + for (auto &p : arCryptoProviders) + m_combo.AddStringA(p->pszName, LPARAM(p)); + + m_combo.SetCurSel(0); + m_descr.SetText(arCryptoProviders[0].szDescr.w); + return true; + } + + bool OnApply() override + { + m_selected = getCurrent(); + return true; + } + + void OnComboChanged(CCtrlCombo*) + { + m_descr.SetText(getCurrent()->szDescr.w); + } + +public: + CSelectCryptoDialog() : + CDlgBase(g_plugin, IDD_SELECT_CRYPTOPROVIDER), + m_combo(this, IDC_SELECTCRYPT_COMBO), + m_descr(this, IDC_CRYPTOPROVIDER_DESCR) + { + m_combo.OnChange = Callback(this, &CSelectCryptoDialog::OnComboChanged); + } + + inline CRYPTO_PROVIDER* GetSelected() + { return m_selected; + } +}; + +CRYPTO_PROVIDER* MDatabaseCommon::SelectProvider() +{ + if (arCryptoProviders.getCount() == 0) + return nullptr; + + CRYPTO_PROVIDER *pProv; + if (arCryptoProviders.getCount() > 1) { + CSelectCryptoDialog dlg; + dlg.DoModal(); + pProv = dlg.GetSelected(); + } + else pProv = &arCryptoProviders[0]; + + return (StoreProvider(pProv)) ? pProv : nullptr; +} + +STDMETHODIMP_(BOOL) MDatabaseCommon::StoreProvider(CRYPTO_PROVIDER *) +{ + return FALSE; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +BOOL MDatabaseCommon::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; +} diff --git a/src/mir_app/src/MDatabaseReadonly.cpp b/src/mir_app/src/MDatabaseReadonly.cpp index 0f006160eb..7490eff643 100644 --- a/src/mir_app/src/MDatabaseReadonly.cpp +++ b/src/mir_app/src/MDatabaseReadonly.cpp @@ -39,7 +39,7 @@ void MDatabaseReadonly::SetCacheSafetyMode(BOOL) BOOL MDatabaseReadonly::EnumModuleNames(DBMODULEENUMPROC, void*) { - return 0; + return FALSE; } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/mir_app/src/encrypt.cpp b/src/mir_app/src/encrypt.cpp index 3f1a9c9cde..53fdb9bb46 100644 --- a/src/mir_app/src/encrypt.cpp +++ b/src/mir_app/src/encrypt.cpp @@ -22,66 +22,40 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "stdafx.h"
+#include "encrypt.h"
/////////////////////////////////////////////////////////////////////////////////////////
-static int CompareFunc(const CRYPTO_PROVIDER *p1, const CRYPTO_PROVIDER *p2)
+static int CompareFunc(const MCryptoProvider *p1, const MCryptoProvider *p2)
{
return mir_strcmp(p1->pszName, p2->pszName);
}
-static LIST<CRYPTO_PROVIDER> arProviders(5, CompareFunc);
+OBJLIST<MCryptoProvider> arCryptoProviders(5, CompareFunc);
-static INT_PTR srvRegister(WPARAM, LPARAM lParam)
-{
- CRYPTO_PROVIDER *p = (CRYPTO_PROVIDER*)lParam;
- if (p == nullptr || p->dwSize != sizeof(CRYPTO_PROVIDER))
- return 1;
-
- CRYPTO_PROVIDER *pNew = new CRYPTO_PROVIDER(*p);
- pNew->pszName = mir_strdup(p->pszName);
- if (pNew->dwFlags & CPF_UNICODE)
- pNew->szDescr.w = mir_wstrdup(TranslateW_LP(p->szDescr.w, p->pPlugin));
- else
- pNew->szDescr.w = mir_a2u(TranslateA_LP(p->szDescr.a, p->pPlugin));
- arProviders.insert(pNew);
- return 0;
-}
+/////////////////////////////////////////////////////////////////////////////////////////
-static INT_PTR srvEnumProviders(WPARAM wParam, LPARAM lParam)
+MIR_APP_DLL(void) Crypto_RegisterEngine(const CRYPTO_PROVIDER *pProvider)
{
- if (wParam && lParam) {
- *(int*)wParam = arProviders.getCount();
- *(CRYPTO_PROVIDER***)lParam = arProviders.getArray();
- }
- return 0;
+ if (pProvider && pProvider->dwSize == sizeof(CRYPTO_PROVIDER))
+ arCryptoProviders.insert(new MCryptoProvider(pProvider));
}
-static INT_PTR srvGetProvider(WPARAM, LPARAM lParam)
+MIR_APP_DLL(void) Crypto_ListProviders(int *pCount, CRYPTO_PROVIDER ***pList)
{
- if (lParam == 0)
- return 0;
+ if (pCount)
+ *pCount = arCryptoProviders.getCount();
- CRYPTO_PROVIDER tmp;
- tmp.pszName = (LPSTR)lParam;
- return (INT_PTR)arProviders.find(&tmp);
+ if (pList)
+ *pList = (CRYPTO_PROVIDER**)arCryptoProviders.getArray();
}
-/////////////////////////////////////////////////////////////////////////////////////////
-
-int InitCrypt(void)
+MIR_APP_DLL(CRYPTO_PROVIDER*) Crypto_GetProvider(const char *pszName)
{
- CreateServiceFunction(MS_CRYPTO_REGISTER_ENGINE, srvRegister);
- CreateServiceFunction(MS_CRYPTO_ENUM_PROVIDERS, srvEnumProviders);
- CreateServiceFunction(MS_CRYPTO_GET_PROVIDER, srvGetProvider);
- return 0;
-}
+ if (pszName == 0)
+ return nullptr;
-void UninitCrypt(void)
-{
- for (auto &p : arProviders) {
- mir_free(p->pszName);
- mir_free(p->szDescr.w);
- delete p;
- }
+ auto *tmp = (MCryptoProvider *)_alloca(sizeof(MCryptoProvider));
+ tmp->pszName = (LPSTR)pszName;
+ return arCryptoProviders.find(tmp);
}
diff --git a/src/mir_app/src/encrypt.h b/src/mir_app/src/encrypt.h new file mode 100644 index 0000000000..cd709b9122 --- /dev/null +++ b/src/mir_app/src/encrypt.h @@ -0,0 +1,45 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright 2012-20 Miranda NG team, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#pragma once + +struct MCryptoProvider : public CRYPTO_PROVIDER +{ + MCryptoProvider(const CRYPTO_PROVIDER *pProvider) + { + memcpy(this, pProvider, sizeof(*pProvider)); + pszName = mir_strdup(pszName); + if (dwFlags & CPF_UNICODE) + szDescr.w = mir_wstrdup(TranslateW_LP(pProvider->szDescr.w, pProvider->pPlugin)); + else + szDescr.w = mir_a2u(TranslateA_LP(pProvider->szDescr.a, pProvider->pPlugin)); + } + + ~MCryptoProvider() + { + mir_free(pszName); + mir_free(szDescr.w); + } +}; + +extern OBJLIST<MCryptoProvider> arCryptoProviders; diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 07ad4cb79b..70dc5372b8 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -756,3 +756,8 @@ _Netlib_GetTlsUnique@8 @831 NONAME ?WriteContactSetting@MDatabaseCommon@@UAGHIPAUDBCONTACTWRITESETTING@@@Z @844 NONAME
?getCrypt@MDatabaseCommon@@QBEPAUMICryptoEngine@@XZ @845 NONAME
?isEncrypted@MDatabaseCommon@@QBE_NXZ @846 NONAME
+?SelectProvider@MDatabaseCommon@@IAEPAUCRYPTO_PROVIDER@@XZ @847 NONAME
+?StoreProvider@MDatabaseCommon@@MAGHPAUCRYPTO_PROVIDER@@@Z @848 NONAME
+?Crypto_GetProvider@@YGPAUCRYPTO_PROVIDER@@PBD@Z @849 NONAME
+?Crypto_ListProviders@@YGXPAHPAPAPAUCRYPTO_PROVIDER@@@Z @850 NONAME
+?Crypto_RegisterEngine@@YGXPBUCRYPTO_PROVIDER@@@Z @851 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 542d44b8f6..804cbf7c55 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -756,3 +756,8 @@ Netlib_GetTlsUnique @831 NONAME ?WriteContactSetting@MDatabaseCommon@@UEAAHIPEAUDBCONTACTWRITESETTING@@@Z @844 NONAME
?getCrypt@MDatabaseCommon@@QEBAPEAUMICryptoEngine@@XZ @845 NONAME
?isEncrypted@MDatabaseCommon@@QEBA_NXZ @846 NONAME
+?SelectProvider@MDatabaseCommon@@IEAAPEAUCRYPTO_PROVIDER@@XZ @847 NONAME
+?StoreProvider@MDatabaseCommon@@MEAAHPEAUCRYPTO_PROVIDER@@@Z @848 NONAME
+?Crypto_GetProvider@@YAPEAUCRYPTO_PROVIDER@@PEBD@Z @849 NONAME
+?Crypto_ListProviders@@YAXPEAHPEAPEAPEAUCRYPTO_PROVIDER@@@Z @850 NONAME
+?Crypto_RegisterEngine@@YAXPEBUCRYPTO_PROVIDER@@@Z @851 NONAME
diff --git a/src/mir_app/src/modules.cpp b/src/mir_app/src/modules.cpp index 2af9ae6b30..82399caca9 100644 --- a/src/mir_app/src/modules.cpp +++ b/src/mir_app/src/modules.cpp @@ -74,7 +74,6 @@ void UnloadProtocolsModule(void); void UnloadSkinSounds(void);
void UnloadSkinHotkeys(void);
void UnloadSrmmModule(void);
-void UnloadUtilsModule(void);
int LoadHeaderbarModule();
int LoadDescButtonModule();
@@ -171,7 +170,6 @@ void UnloadDefaultModules(void) UnloadSkinHotkeys();
UnloadSrmmModule();
UnloadIcoLibModule();
- UnloadUtilsModule();
UnloadExtraIconsModule();
UnloadClcModule();
UnloadContactListModule();
diff --git a/src/mir_app/src/resource.h b/src/mir_app/src/resource.h index 3879595446..9784e98b46 100644 --- a/src/mir_app/src/resource.h +++ b/src/mir_app/src/resource.h @@ -28,6 +28,7 @@ #define IDD_OPT_CLIST 119
#define IDD_OPT_CHAT_EVENTS 120
#define IDD_AUTHREQ 121
+#define IDD_SELECT_CRYPTOPROVIDER 122
#define IDD_DETAILS 125
#define IDD_HISTORY 127
#define IDI_AWAY 128
@@ -302,6 +303,8 @@ #define IDC_EDIT1 1105
#define IDC_BUILDTIME 1108
#define IDC_CREDITSFILE 1109
+#define IDC_SELECTCRYPT_COMBO 1110
+#define IDC_CRYPTOPROVIDER_DESCR 1111
#define IDC_NUMBER 1113
#define IDC_FINDWHAT 1131
#define IDC_FIND 1132
diff --git a/src/mir_app/src/utils.cpp b/src/mir_app/src/utils.cpp index ce1260ea37..42f0d9ba07 100644 --- a/src/mir_app/src/utils.cpp +++ b/src/mir_app/src/utils.cpp @@ -26,13 +26,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MS_SYSTEM_GET_MD5I "Miranda/System/GetMD5I"
-int InitCrypt(void);
-void UninitCrypt(void);
-
void InitClistCore(void);
-static BOOL bModuleInitialized = FALSE;
-
static CountryListEntry countries[] = {
{ 0, "", LPGEN("Unspecified") },
{ 9999, "", LPGEN("Other") },
@@ -379,21 +374,10 @@ bool ProcessFileDrop(HDROP hDrop, MCONTACT hContact) int LoadUtilsModule(void)
{
- bModuleInitialized = TRUE;
-
CreateServiceFunction(MS_UTILS_GETCOUNTRYBYNUMBER, GetCountryByNumber);
CreateServiceFunction(MS_UTILS_GETCOUNTRYBYISOCODE, GetCountryByISOCode);
CreateServiceFunction(MS_UTILS_GETCOUNTRYLIST, GetCountryList);
- InitCrypt();
InitClistCore();
return 0;
}
-
-void UnloadUtilsModule(void)
-{
- if (!bModuleInitialized)
- return;
-
- UninitCrypt();
-}
|