diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2017-12-02 00:43:02 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2017-12-02 00:43:02 +0300 |
commit | 8ad91f63bd6671b8ec95ab68c1740b63235cf2be (patch) | |
tree | 93e3d207a0ef3d1e276fbcdca0963b00b78ff028 /plugins | |
parent | 457b95fe98b0c515b973958f4d45585e2590915f (diff) |
new_gpg: dos2unix //deal with it.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/New_GPG/src/clist.cpp | 62 | ||||
-rw-r--r-- | plugins/New_GPG/src/constants.h | 10 | ||||
-rw-r--r-- | plugins/New_GPG/src/globals.h | 60 | ||||
-rw-r--r-- | plugins/New_GPG/src/icons.cpp | 154 | ||||
-rw-r--r-- | plugins/New_GPG/src/init.cpp | 486 | ||||
-rw-r--r-- | plugins/New_GPG/src/jabber_account.cpp | 168 | ||||
-rw-r--r-- | plugins/New_GPG/src/jabber_account.h | 84 | ||||
-rw-r--r-- | plugins/New_GPG/src/log.cpp | 174 | ||||
-rwxr-xr-x | plugins/New_GPG/src/main.cpp | 10 | ||||
-rw-r--r-- | plugins/New_GPG/src/main.h | 62 | ||||
-rwxr-xr-x | plugins/New_GPG/src/messages.cpp | 16 | ||||
-rw-r--r-- | plugins/New_GPG/src/metacontacts.cpp | 58 | ||||
-rw-r--r-- | plugins/New_GPG/src/metacontacts.h | 38 | ||||
-rwxr-xr-x | plugins/New_GPG/src/options.cpp | 2188 | ||||
-rw-r--r-- | plugins/New_GPG/src/resource.h | 232 | ||||
-rwxr-xr-x | plugins/New_GPG/src/srmm.cpp | 164 | ||||
-rwxr-xr-x | plugins/New_GPG/src/utilities.cpp | 42 | ||||
-rw-r--r-- | plugins/New_GPG/src/utilities.h | 222 |
18 files changed, 2115 insertions, 2115 deletions
diff --git a/plugins/New_GPG/src/clist.cpp b/plugins/New_GPG/src/clist.cpp index 4dba48a024..317171f87c 100644 --- a/plugins/New_GPG/src/clist.cpp +++ b/plugins/New_GPG/src/clist.cpp @@ -1,31 +1,31 @@ -// Copyright © 2010-2012 SecureIM developers (baloo and others), sss
-//
-// 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"
-
-void RefreshContactListIcons(void);
-
-int onExtraImageListRebuilding(WPARAM, LPARAM)
-{
- RefreshContactListIcons();
- return 0;
-}
-
-int onExtraImageApplying(WPARAM wParam, LPARAM)
-{
- setClistIcon(wParam);
- return 0;
-}
+// Copyright © 2010-2012 SecureIM developers (baloo and others), sss +// +// 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" + +void RefreshContactListIcons(void); + +int onExtraImageListRebuilding(WPARAM, LPARAM) +{ + RefreshContactListIcons(); + return 0; +} + +int onExtraImageApplying(WPARAM wParam, LPARAM) +{ + setClistIcon(wParam); + return 0; +} diff --git a/plugins/New_GPG/src/constants.h b/plugins/New_GPG/src/constants.h index 2982f31489..be769466c9 100644 --- a/plugins/New_GPG/src/constants.h +++ b/plugins/New_GPG/src/constants.h @@ -1,5 +1,5 @@ -#ifndef CONSTANTS_H
-#define CONSTANTS_H
-#define szGPGModuleName "GPG"
-#define PREF_METANODB 0x2000
-#endif
+#ifndef CONSTANTS_H +#define CONSTANTS_H +#define szGPGModuleName "GPG" +#define PREF_METANODB 0x2000 +#endif diff --git a/plugins/New_GPG/src/globals.h b/plugins/New_GPG/src/globals.h index e289fa8f0b..ef3ea72445 100644 --- a/plugins/New_GPG/src/globals.h +++ b/plugins/New_GPG/src/globals.h @@ -1,30 +1,30 @@ -// Copyright © 2010-2012 sss
-//
-// 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.
-
-#ifndef GLOBALS_H
-#define GLOBALS_H
-extern bool bAppendTags, bPresenceSigning, bStripTags, gpg_valid, gpg_keyexist, tabsrmm_used, bSameAction, bFileTransfers, bDebugLog;
-extern wchar_t *inopentag, *inclosetag, *outopentag, *outclosetag;
-extern logtofile debuglog;
-
-extern map<int, MCONTACT> user_data;
-extern int item_num;
-
-extern bool _terminate;
-extern wstring new_key;
-extern MCONTACT new_key_hcnt;
-extern boost::mutex new_key_hcnt_mutex;
-#endif
+// Copyright © 2010-2012 sss +// +// 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. + +#ifndef GLOBALS_H +#define GLOBALS_H +extern bool bAppendTags, bPresenceSigning, bStripTags, gpg_valid, gpg_keyexist, tabsrmm_used, bSameAction, bFileTransfers, bDebugLog; +extern wchar_t *inopentag, *inclosetag, *outopentag, *outclosetag; +extern logtofile debuglog; + +extern map<int, MCONTACT> user_data; +extern int item_num; + +extern bool _terminate; +extern wstring new_key; +extern MCONTACT new_key_hcnt; +extern boost::mutex new_key_hcnt_mutex; +#endif diff --git a/plugins/New_GPG/src/icons.cpp b/plugins/New_GPG/src/icons.cpp index bb680e34cb..dc6668e2a6 100644 --- a/plugins/New_GPG/src/icons.cpp +++ b/plugins/New_GPG/src/icons.cpp @@ -1,77 +1,77 @@ -// Copyright © 2010-2012 SecureIM developers (baloo and others), sss
-//
-// 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"
-
-extern HINSTANCE hInst;
-
-static IconItem iconList[] =
-{
- { "Secured", "secured", IDI_SECURED },
- { "Unsecured", "unsecured", IDI_UNSECURED }
-};
-
-void InitIconLib()
-{
- Icon_Register(hInst, szGPGModuleName, iconList, _countof(iconList));
-}
-
-HANDLE IconLibHookIconsChanged(MIRANDAHOOK hook)
-{
- return HookEvent(ME_SKIN2_ICONSCHANGED, hook);
-}
-
-void setClistIcon(MCONTACT hContact)
-{
- bool enabled = isContactSecured(hContact);
- extern HANDLE g_hCLIcon;
- MCONTACT hMC = db_mc_tryMeta(hContact);
- const char *szIconId = (enabled) ? "secured" : nullptr;
- ExtraIcon_SetIconByName(g_hCLIcon, hContact, szIconId);
- if(hMC != hContact)
- ExtraIcon_SetIconByName(g_hCLIcon, hMC, szIconId);
-}
-
-void setSrmmIcon(MCONTACT h)
-{
- MCONTACT hContact = db_mc_isMeta(h) ? metaGetMostOnline(h) : h;
- bool enabled = isContactSecured(hContact);
- MCONTACT hMC = db_mc_tryMeta(hContact);
-
- StatusIconData sid = {};
- sid.szModule = szGPGModuleName;
- sid.hIcon = IcoLib_GetIcon("secured");
- sid.dwId = 1;
- sid.flags = enabled ? 0 : MBF_HIDDEN;
- Srmm_ModifyIcon(hContact, &sid);
- if(hMC != hContact)
- Srmm_ModifyIcon(hMC, &sid);
-
- sid.hIcon = IcoLib_GetIcon("unsecured");
- sid.dwId = 2;
- sid.flags = enabled ? MBF_HIDDEN : 0;
- Srmm_ModifyIcon(hContact, &sid);
- if(hMC != hContact)
- Srmm_ModifyIcon(hMC, &sid);
-}
-
-void RefreshContactListIcons()
-{
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
- setClistIcon(hContact);
-
- Clist_EndRebuild();
-}
+// Copyright © 2010-2012 SecureIM developers (baloo and others), sss +// +// 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" + +extern HINSTANCE hInst; + +static IconItem iconList[] = +{ + { "Secured", "secured", IDI_SECURED }, + { "Unsecured", "unsecured", IDI_UNSECURED } +}; + +void InitIconLib() +{ + Icon_Register(hInst, szGPGModuleName, iconList, _countof(iconList)); +} + +HANDLE IconLibHookIconsChanged(MIRANDAHOOK hook) +{ + return HookEvent(ME_SKIN2_ICONSCHANGED, hook); +} + +void setClistIcon(MCONTACT hContact) +{ + bool enabled = isContactSecured(hContact); + extern HANDLE g_hCLIcon; + MCONTACT hMC = db_mc_tryMeta(hContact); + const char *szIconId = (enabled) ? "secured" : nullptr; + ExtraIcon_SetIconByName(g_hCLIcon, hContact, szIconId); + if(hMC != hContact) + ExtraIcon_SetIconByName(g_hCLIcon, hMC, szIconId); +} + +void setSrmmIcon(MCONTACT h) +{ + MCONTACT hContact = db_mc_isMeta(h) ? metaGetMostOnline(h) : h; + bool enabled = isContactSecured(hContact); + MCONTACT hMC = db_mc_tryMeta(hContact); + + StatusIconData sid = {}; + sid.szModule = szGPGModuleName; + sid.hIcon = IcoLib_GetIcon("secured"); + sid.dwId = 1; + sid.flags = enabled ? 0 : MBF_HIDDEN; + Srmm_ModifyIcon(hContact, &sid); + if(hMC != hContact) + Srmm_ModifyIcon(hMC, &sid); + + sid.hIcon = IcoLib_GetIcon("unsecured"); + sid.dwId = 2; + sid.flags = enabled ? MBF_HIDDEN : 0; + Srmm_ModifyIcon(hContact, &sid); + if(hMC != hContact) + Srmm_ModifyIcon(hMC, &sid); +} + +void RefreshContactListIcons() +{ + for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + setClistIcon(hContact); + + Clist_EndRebuild(); +} diff --git a/plugins/New_GPG/src/init.cpp b/plugins/New_GPG/src/init.cpp index f46c266d09..9ad51625f4 100644 --- a/plugins/New_GPG/src/init.cpp +++ b/plugins/New_GPG/src/init.cpp @@ -1,243 +1,243 @@ -// Copyright © 2010-2012 sss
-//
-// 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"
-
-//global variables
-bool bAppendTags = false, bDebugLog = false, bJabberAPI = false, bPresenceSigning = false, bFileTransfers = false, bSameAction = false, bAutoExchange = false, bStripTags = false, tabsrmm_used = false;
-wchar_t *inopentag = nullptr, *inclosetag = nullptr, *outopentag = nullptr, *outclosetag = nullptr, *password = nullptr;
-
-list <JabberAccount*> Accounts;
-
-CLIST_INTERFACE *pcli;
-HINSTANCE hInst;
-HFONT bold_font = nullptr;
-HANDLE hLoadPubKey = nullptr, g_hCLIcon = nullptr, hExportGpgKeys = nullptr, hImportGpgKeys = nullptr;
-HGENMENU hSendKey = nullptr, hToggleEncryption = nullptr;
-RECT key_from_keyserver_rect = {0}, firstrun_rect = {0}, new_key_rect = {0}, key_gen_rect = {0}, load_key_rect = {0}, import_key_rect = {0}, key_password_rect = {0}, load_existing_key_rect = {0};
-
-int hLangpack = 0;
-logtofile debuglog;
-bool gpg_valid = false, gpg_keyexist = false;
-std::map<MCONTACT, contact_data> hcontact_data;
-
-PLUGININFOEX pluginInfo={
- sizeof(PLUGININFOEX),
- __PLUGIN_NAME,
- PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
- __DESCRIPTION,
- __AUTHOR,
- __AUTHOREMAIL,
- __COPYRIGHT,
- __AUTHORWEB,
- UNICODE_AWARE,
- // {4227c050-8d97-48d2-91ec-6a952b3dab94}
- { 0x4227c050, 0x8d97, 0x48d2, { 0x91, 0xec, 0x6a, 0x95, 0x2b, 0x3d, 0xab, 0x94 } }
-};
-
-BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID)
-{
- hInst = hinstDLL;
- return TRUE;
-}
-
-
-extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
-{
- return &pluginInfo;
-}
-
-
-INT_PTR LoadKey(WPARAM w, LPARAM l);
-INT_PTR ToggleEncryption(WPARAM w, LPARAM l);
-INT_PTR SendKey(WPARAM w, LPARAM l);
-INT_PTR ExportGpGKeys(WPARAM w, LPARAM l);
-INT_PTR ImportGpGKeys(WPARAM w, LPARAM l);
-int onExtraImageListRebuilding(WPARAM, LPARAM);
-int onExtraImageApplying(WPARAM wParam, LPARAM);
-void InitIconLib();
-
-void init_vars()
-{
- bAppendTags = db_get_b(NULL, szGPGModuleName, "bAppendTags", 0) != 0;
- bStripTags = db_get_b(NULL, szGPGModuleName, "bStripTags", 0) != 0;
- inopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", L"<GPGdec>");
- inclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", L"</GPGdec>");
- outopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", L"<GPGenc>");
- outclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", L"</GPGenc>");
- bDebugLog = db_get_b(NULL, szGPGModuleName, "bDebugLog", 0) != 0;
- bAutoExchange = db_get_b(NULL, szGPGModuleName, "bAutoExchange", 0) != 0;
- bSameAction = db_get_b(NULL, szGPGModuleName, "bSameAction", 0) != 0;
- password = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", L"");
- debuglog.init();
- bJabberAPI = db_get_b(NULL, szGPGModuleName, "bJabberAPI", true) != 0;
- bPresenceSigning = db_get_b(NULL, szGPGModuleName, "bPresenceSigning", 0) != 0;
- bFileTransfers = db_get_b(NULL, szGPGModuleName, "bFileTransfers", 0) != 0;
- firstrun_rect.left = db_get_dw(NULL, szGPGModuleName, "FirstrunWindowX", 0);
- firstrun_rect.top = db_get_dw(NULL, szGPGModuleName, "FirstrunWindowY", 0);
- key_password_rect.left = db_get_dw(NULL, szGPGModuleName, "PasswordWindowX", 0);
- key_password_rect.top = db_get_dw(NULL, szGPGModuleName, "PasswordWindowY", 0);
- key_gen_rect.left = db_get_dw(NULL, szGPGModuleName, "KeyGenWindowX", 0);
- key_gen_rect.top = db_get_dw(NULL, szGPGModuleName, "KeyGenWindowY", 0);
- load_key_rect.left = db_get_dw(NULL, szGPGModuleName, "LoadKeyWindowX", 0);
- load_key_rect.top = db_get_dw(NULL, szGPGModuleName, "LoadKeyWindowY", 0);
- import_key_rect.left = db_get_dw(NULL, szGPGModuleName, "ImportKeyWindowX", 0);
- import_key_rect.top = db_get_dw(NULL, szGPGModuleName, "ImportKeyWindowY", 0);
- new_key_rect.left = db_get_dw(NULL, szGPGModuleName, "NewKeyWindowX", 0);
- new_key_rect.top = db_get_dw(NULL, szGPGModuleName, "NewKeyWindowY", 0);
- load_existing_key_rect.left = db_get_dw(NULL, szGPGModuleName, "LoadExistingKeyWindowX", 0);
- load_existing_key_rect.top = db_get_dw(NULL, szGPGModuleName, "LoadExistingKeyWindowY", 0);
- tabsrmm_used = isTabsrmmUsed();
- bold_font = CreateFont(14, 0, 0, 0, 600, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, L"Arial");
-}
-
-static int OnModulesLoaded(WPARAM, LPARAM)
-{
- int GpgOptInit(WPARAM wParam,LPARAM lParam);
- int OnPreBuildContactMenu(WPARAM w, LPARAM l);
- INT_PTR RecvMsgSvc(WPARAM w, LPARAM l);
- INT_PTR SendMsgSvc(WPARAM w, LPARAM l);
- int HookSendMsg(WPARAM w, LPARAM l);
-// int TestHook(WPARAM w, LPARAM l);
- int GetJabberInterface(WPARAM w, LPARAM l);
- int onWindowEvent(WPARAM wParam, LPARAM lParam);
- int onIconPressed(WPARAM wParam, LPARAM lParam);
- int onProtoAck(WPARAM, LPARAM);
- INT_PTR onSendFile(WPARAM, LPARAM);
-
- void InitCheck();
- void FirstRun();
- FirstRun();
- if(!db_get_b(NULL, szGPGModuleName, "FirstRun", 1))
- InitCheck();
-
- StatusIconData sid = {};
- sid.szModule = szGPGModuleName;
- sid.flags = MBF_HIDDEN;
- sid.dwId = 0x00000001;
- sid.hIcon = IcoLib_GetIcon("secured");
- sid.szTooltip = LPGEN("GPG Turn off encryption");
- Srmm_AddIcon(&sid);
-
- sid.dwId = 0x00000002;
- sid.hIcon = IcoLib_GetIcon("unsecured");
- sid.szTooltip = LPGEN("GPG Turn on encryption");
- Srmm_AddIcon(&sid);
-
- if(bJabberAPI)
- GetJabberInterface(0,0);
-
- HookEvent(ME_OPT_INITIALISE, GpgOptInit);
- HookEvent(ME_DB_EVENT_FILTER_ADD, HookSendMsg);
- if(bJabberAPI)
- HookEvent(ME_PROTO_ACCLISTCHANGED, GetJabberInterface);
-
- HookEvent(ME_PROTO_ACK, onProtoAck);
-
- HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPreBuildContactMenu);
-
- HookEvent(ME_MSG_WINDOWEVENT, onWindowEvent);
- HookEvent(ME_MSG_ICONPRESSED, onIconPressed);
-
- PROTOCOLDESCRIPTOR pd = { 0 };
- pd.cbSize = sizeof(pd);
- pd.szName = szGPGModuleName;
- pd.type = PROTOTYPE_ENCRYPTION;
- Proto_RegisterModule(&pd);
-
- CreateProtoServiceFunction(szGPGModuleName, PSR_MESSAGE, RecvMsgSvc);
- CreateProtoServiceFunction(szGPGModuleName, PSS_MESSAGE, SendMsgSvc);
- CreateProtoServiceFunction(szGPGModuleName, PSS_FILE, onSendFile);
- clean_temp_dir();
- return 0;
-}
-
-extern "C" int __declspec(dllexport) Load()
-{
- mir_getLP(&pluginInfo);
- pcli = Clist_GetInterface();
-
- HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
-
- init_vars();
- CreateServiceFunction("/LoadPubKey",LoadKey);
- CreateServiceFunction("/ToggleEncryption",ToggleEncryption);
- CreateServiceFunction("/SendKey",SendKey);
- CreateServiceFunction("/ExportGPGKeys",ExportGpGKeys);
- CreateServiceFunction("/ImportGPGKeys",ImportGpGKeys);
-
- CMenuItem mi;
-
- SET_UID(mi, 0xbd22e3f8, 0xc19c, 0x45a8, 0xb7, 0x37, 0x6b, 0x3b, 0x27, 0xf0, 0x8c, 0xbb);
- mi.position = -0x7FFFFFFF;
- mi.flags = CMIF_UNICODE;
- mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
- mi.name.w = LPGENW("Load public GPG key");
- mi.pszService = "/LoadPubKey";
- hLoadPubKey = Menu_AddContactMenuItem(&mi);
-
- SET_UID(mi, 0xc8008193, 0x56a9, 0x414a, 0x82, 0x98, 0x78, 0xe8, 0xa8, 0x84, 0x20, 0x67);
- mi.position = -0x7FFFFFFe;
- mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
- mi.name.w = LPGENW("Toggle GPG encryption");
- mi.pszService = "/ToggleEncryption";
- hToggleEncryption = Menu_AddContactMenuItem(&mi);
-
- SET_UID(mi, 0x42bb535f, 0xd58e, 0x4edb, 0xbf, 0x2c, 0xfa, 0x9a, 0xbf, 0x1e, 0xb8, 0x69);
- mi.position = -0x7FFFFFFd;
- mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
- mi.name.w = LPGENW("Send public key");
- mi.pszService = "/SendKey";
- hSendKey = Menu_AddContactMenuItem(&mi);
-
- SET_UID(mi, 0x33a204b2, 0xe3c0, 0x413b, 0xbf, 0xd8, 0x8b, 0x2e, 0x3d, 0xa0, 0xef, 0xa4);
- mi.position = -0x7FFFFFFe;
- mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
- mi.name.w = LPGENW("Export GPG Public keys");
- mi.pszService = "/ExportGPGKeys";
- hExportGpgKeys = Menu_AddMainMenuItem(&mi);
-
- SET_UID(mi, 0x627fcfc1, 0x4e60, 0x4428, 0xaf, 0x96, 0x11, 0x42, 0x24, 0xeb, 0x7, 0xea);
- mi.position = -0x7FFFFFFF;
- mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
- mi.name.w = LPGENW("Import GPG Public keys");
- mi.pszService = "/ImportGPGKeys";
- hImportGpgKeys = Menu_AddMainMenuItem(&mi);
-
- InitIconLib();
-
- g_hCLIcon = ExtraIcon_RegisterCallback(szGPGModuleName, Translate("GPG encryption status"), "secured", onExtraImageListRebuilding, onExtraImageApplying);
- return 0;
-}
-
-extern list<wstring> transfers;
-extern "C" int __declspec(dllexport) Unload(void)
-{
- if(!transfers.empty())
- {
- for(list<wstring>::iterator p = transfers.begin(); p != transfers.end(); p++)
- if(!(*p).empty())
- boost::filesystem::remove((*p));
- }
- mir_free(inopentag);
- mir_free(inclosetag);
- mir_free(outopentag);
- mir_free(outclosetag);
- if(password)
- mir_free(password);
- clean_temp_dir();
- return 0;
-}
+// Copyright © 2010-2012 sss +// +// 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" + +//global variables +bool bAppendTags = false, bDebugLog = false, bJabberAPI = false, bPresenceSigning = false, bFileTransfers = false, bSameAction = false, bAutoExchange = false, bStripTags = false, tabsrmm_used = false; +wchar_t *inopentag = nullptr, *inclosetag = nullptr, *outopentag = nullptr, *outclosetag = nullptr, *password = nullptr; + +list <JabberAccount*> Accounts; + +CLIST_INTERFACE *pcli; +HINSTANCE hInst; +HFONT bold_font = nullptr; +HANDLE hLoadPubKey = nullptr, g_hCLIcon = nullptr, hExportGpgKeys = nullptr, hImportGpgKeys = nullptr; +HGENMENU hSendKey = nullptr, hToggleEncryption = nullptr; +RECT key_from_keyserver_rect = {0}, firstrun_rect = {0}, new_key_rect = {0}, key_gen_rect = {0}, load_key_rect = {0}, import_key_rect = {0}, key_password_rect = {0}, load_existing_key_rect = {0}; + +int hLangpack = 0; +logtofile debuglog; +bool gpg_valid = false, gpg_keyexist = false; +std::map<MCONTACT, contact_data> hcontact_data; + +PLUGININFOEX pluginInfo={ + sizeof(PLUGININFOEX), + __PLUGIN_NAME, + PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), + __DESCRIPTION, + __AUTHOR, + __AUTHOREMAIL, + __COPYRIGHT, + __AUTHORWEB, + UNICODE_AWARE, + // {4227c050-8d97-48d2-91ec-6a952b3dab94} + { 0x4227c050, 0x8d97, 0x48d2, { 0x91, 0xec, 0x6a, 0x95, 0x2b, 0x3d, 0xab, 0x94 } } +}; + +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) +{ + hInst = hinstDLL; + return TRUE; +} + + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) +{ + return &pluginInfo; +} + + +INT_PTR LoadKey(WPARAM w, LPARAM l); +INT_PTR ToggleEncryption(WPARAM w, LPARAM l); +INT_PTR SendKey(WPARAM w, LPARAM l); +INT_PTR ExportGpGKeys(WPARAM w, LPARAM l); +INT_PTR ImportGpGKeys(WPARAM w, LPARAM l); +int onExtraImageListRebuilding(WPARAM, LPARAM); +int onExtraImageApplying(WPARAM wParam, LPARAM); +void InitIconLib(); + +void init_vars() +{ + bAppendTags = db_get_b(NULL, szGPGModuleName, "bAppendTags", 0) != 0; + bStripTags = db_get_b(NULL, szGPGModuleName, "bStripTags", 0) != 0; + inopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", L"<GPGdec>"); + inclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", L"</GPGdec>"); + outopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", L"<GPGenc>"); + outclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", L"</GPGenc>"); + bDebugLog = db_get_b(NULL, szGPGModuleName, "bDebugLog", 0) != 0; + bAutoExchange = db_get_b(NULL, szGPGModuleName, "bAutoExchange", 0) != 0; + bSameAction = db_get_b(NULL, szGPGModuleName, "bSameAction", 0) != 0; + password = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", L""); + debuglog.init(); + bJabberAPI = db_get_b(NULL, szGPGModuleName, "bJabberAPI", true) != 0; + bPresenceSigning = db_get_b(NULL, szGPGModuleName, "bPresenceSigning", 0) != 0; + bFileTransfers = db_get_b(NULL, szGPGModuleName, "bFileTransfers", 0) != 0; + firstrun_rect.left = db_get_dw(NULL, szGPGModuleName, "FirstrunWindowX", 0); + firstrun_rect.top = db_get_dw(NULL, szGPGModuleName, "FirstrunWindowY", 0); + key_password_rect.left = db_get_dw(NULL, szGPGModuleName, "PasswordWindowX", 0); + key_password_rect.top = db_get_dw(NULL, szGPGModuleName, "PasswordWindowY", 0); + key_gen_rect.left = db_get_dw(NULL, szGPGModuleName, "KeyGenWindowX", 0); + key_gen_rect.top = db_get_dw(NULL, szGPGModuleName, "KeyGenWindowY", 0); + load_key_rect.left = db_get_dw(NULL, szGPGModuleName, "LoadKeyWindowX", 0); + load_key_rect.top = db_get_dw(NULL, szGPGModuleName, "LoadKeyWindowY", 0); + import_key_rect.left = db_get_dw(NULL, szGPGModuleName, "ImportKeyWindowX", 0); + import_key_rect.top = db_get_dw(NULL, szGPGModuleName, "ImportKeyWindowY", 0); + new_key_rect.left = db_get_dw(NULL, szGPGModuleName, "NewKeyWindowX", 0); + new_key_rect.top = db_get_dw(NULL, szGPGModuleName, "NewKeyWindowY", 0); + load_existing_key_rect.left = db_get_dw(NULL, szGPGModuleName, "LoadExistingKeyWindowX", 0); + load_existing_key_rect.top = db_get_dw(NULL, szGPGModuleName, "LoadExistingKeyWindowY", 0); + tabsrmm_used = isTabsrmmUsed(); + bold_font = CreateFont(14, 0, 0, 0, 600, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, L"Arial"); +} + +static int OnModulesLoaded(WPARAM, LPARAM) +{ + int GpgOptInit(WPARAM wParam,LPARAM lParam); + int OnPreBuildContactMenu(WPARAM w, LPARAM l); + INT_PTR RecvMsgSvc(WPARAM w, LPARAM l); + INT_PTR SendMsgSvc(WPARAM w, LPARAM l); + int HookSendMsg(WPARAM w, LPARAM l); +// int TestHook(WPARAM w, LPARAM l); + int GetJabberInterface(WPARAM w, LPARAM l); + int onWindowEvent(WPARAM wParam, LPARAM lParam); + int onIconPressed(WPARAM wParam, LPARAM lParam); + int onProtoAck(WPARAM, LPARAM); + INT_PTR onSendFile(WPARAM, LPARAM); + + void InitCheck(); + void FirstRun(); + FirstRun(); + if(!db_get_b(NULL, szGPGModuleName, "FirstRun", 1)) + InitCheck(); + + StatusIconData sid = {}; + sid.szModule = szGPGModuleName; + sid.flags = MBF_HIDDEN; + sid.dwId = 0x00000001; + sid.hIcon = IcoLib_GetIcon("secured"); + sid.szTooltip = LPGEN("GPG Turn off encryption"); + Srmm_AddIcon(&sid); + + sid.dwId = 0x00000002; + sid.hIcon = IcoLib_GetIcon("unsecured"); + sid.szTooltip = LPGEN("GPG Turn on encryption"); + Srmm_AddIcon(&sid); + + if(bJabberAPI) + GetJabberInterface(0,0); + + HookEvent(ME_OPT_INITIALISE, GpgOptInit); + HookEvent(ME_DB_EVENT_FILTER_ADD, HookSendMsg); + if(bJabberAPI) + HookEvent(ME_PROTO_ACCLISTCHANGED, GetJabberInterface); + + HookEvent(ME_PROTO_ACK, onProtoAck); + + HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPreBuildContactMenu); + + HookEvent(ME_MSG_WINDOWEVENT, onWindowEvent); + HookEvent(ME_MSG_ICONPRESSED, onIconPressed); + + PROTOCOLDESCRIPTOR pd = { 0 }; + pd.cbSize = sizeof(pd); + pd.szName = szGPGModuleName; + pd.type = PROTOTYPE_ENCRYPTION; + Proto_RegisterModule(&pd); + + CreateProtoServiceFunction(szGPGModuleName, PSR_MESSAGE, RecvMsgSvc); + CreateProtoServiceFunction(szGPGModuleName, PSS_MESSAGE, SendMsgSvc); + CreateProtoServiceFunction(szGPGModuleName, PSS_FILE, onSendFile); + clean_temp_dir(); + return 0; +} + +extern "C" int __declspec(dllexport) Load() +{ + mir_getLP(&pluginInfo); + pcli = Clist_GetInterface(); + + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + + init_vars(); + CreateServiceFunction("/LoadPubKey",LoadKey); + CreateServiceFunction("/ToggleEncryption",ToggleEncryption); + CreateServiceFunction("/SendKey",SendKey); + CreateServiceFunction("/ExportGPGKeys",ExportGpGKeys); + CreateServiceFunction("/ImportGPGKeys",ImportGpGKeys); + + CMenuItem mi; + + SET_UID(mi, 0xbd22e3f8, 0xc19c, 0x45a8, 0xb7, 0x37, 0x6b, 0x3b, 0x27, 0xf0, 0x8c, 0xbb); + mi.position = -0x7FFFFFFF; + mi.flags = CMIF_UNICODE; + mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA); + mi.name.w = LPGENW("Load public GPG key"); + mi.pszService = "/LoadPubKey"; + hLoadPubKey = Menu_AddContactMenuItem(&mi); + + SET_UID(mi, 0xc8008193, 0x56a9, 0x414a, 0x82, 0x98, 0x78, 0xe8, 0xa8, 0x84, 0x20, 0x67); + mi.position = -0x7FFFFFFe; + mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA); + mi.name.w = LPGENW("Toggle GPG encryption"); + mi.pszService = "/ToggleEncryption"; + hToggleEncryption = Menu_AddContactMenuItem(&mi); + + SET_UID(mi, 0x42bb535f, 0xd58e, 0x4edb, 0xbf, 0x2c, 0xfa, 0x9a, 0xbf, 0x1e, 0xb8, 0x69); + mi.position = -0x7FFFFFFd; + mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA); + mi.name.w = LPGENW("Send public key"); + mi.pszService = "/SendKey"; + hSendKey = Menu_AddContactMenuItem(&mi); + + SET_UID(mi, 0x33a204b2, 0xe3c0, 0x413b, 0xbf, 0xd8, 0x8b, 0x2e, 0x3d, 0xa0, 0xef, 0xa4); + mi.position = -0x7FFFFFFe; + mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA); + mi.name.w = LPGENW("Export GPG Public keys"); + mi.pszService = "/ExportGPGKeys"; + hExportGpgKeys = Menu_AddMainMenuItem(&mi); + + SET_UID(mi, 0x627fcfc1, 0x4e60, 0x4428, 0xaf, 0x96, 0x11, 0x42, 0x24, 0xeb, 0x7, 0xea); + mi.position = -0x7FFFFFFF; + mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA); + mi.name.w = LPGENW("Import GPG Public keys"); + mi.pszService = "/ImportGPGKeys"; + hImportGpgKeys = Menu_AddMainMenuItem(&mi); + + InitIconLib(); + + g_hCLIcon = ExtraIcon_RegisterCallback(szGPGModuleName, Translate("GPG encryption status"), "secured", onExtraImageListRebuilding, onExtraImageApplying); + return 0; +} + +extern list<wstring> transfers; +extern "C" int __declspec(dllexport) Unload(void) +{ + if(!transfers.empty()) + { + for(list<wstring>::iterator p = transfers.begin(); p != transfers.end(); p++) + if(!(*p).empty()) + boost::filesystem::remove((*p)); + } + mir_free(inopentag); + mir_free(inclosetag); + mir_free(outopentag); + mir_free(outclosetag); + if(password) + mir_free(password); + clean_temp_dir(); + return 0; +} diff --git a/plugins/New_GPG/src/jabber_account.cpp b/plugins/New_GPG/src/jabber_account.cpp index 7aaf562bdf..3a939c6c8e 100644 --- a/plugins/New_GPG/src/jabber_account.cpp +++ b/plugins/New_GPG/src/jabber_account.cpp @@ -1,85 +1,85 @@ -// Copyright © 2010-2012 sss
-//
-// 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"
-
-void JabberAccount::setAccountName(wchar_t *Name)
-{
- AccountName = Name;
-}
-void JabberAccount::setAccountNumber(int Number)
-{
- AccountNumber = Number;
-}
-void JabberAccount::setJabberInterface(IJabberInterface *JIf)
-{
- JabberInterface = JIf;
-}
-void JabberAccount::setSendHandler(HJHANDLER hHandler)
-{
- hSendHandler = hHandler;
-}
-void JabberAccount::setPrescenseHandler(HJHANDLER hHandler)
-{
- hPrescenseHandler = hHandler;
-}
-void JabberAccount::setMessageHandler(HJHANDLER hHandler)
-{
- hMessageHandler = hHandler;
-}
-
-
-wchar_t *JabberAccount::getAccountName()
-{
- return AccountName;
-}
-int JabberAccount::getAccountNumber()
-{
- return AccountNumber;
-}
-IJabberInterface *JabberAccount::getJabberInterface()
-{
- return JabberInterface;
-}
-HJHANDLER JabberAccount::getSendHandler()
-{
- return hSendHandler;
-}
-HJHANDLER JabberAccount::getPrescenseHandler()
-{
- return hPrescenseHandler;
-}
-
-HJHANDLER JabberAccount::getMessageHandler()
-{
- return hMessageHandler;
-}
-
-
-JabberAccount::JabberAccount()
-{
- AccountName = nullptr;
- hSendHandler = INVALID_HANDLE_VALUE;
- hPrescenseHandler = INVALID_HANDLE_VALUE;
- hMessageHandler = INVALID_HANDLE_VALUE;
- AccountNumber = -1;
- JabberInterface = nullptr;
-}
-JabberAccount::~JabberAccount()
-{
- if(AccountName)
- mir_free(AccountName);
+// Copyright © 2010-2012 sss +// +// 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" + +void JabberAccount::setAccountName(wchar_t *Name) +{ + AccountName = Name; +} +void JabberAccount::setAccountNumber(int Number) +{ + AccountNumber = Number; +} +void JabberAccount::setJabberInterface(IJabberInterface *JIf) +{ + JabberInterface = JIf; +} +void JabberAccount::setSendHandler(HJHANDLER hHandler) +{ + hSendHandler = hHandler; +} +void JabberAccount::setPrescenseHandler(HJHANDLER hHandler) +{ + hPrescenseHandler = hHandler; +} +void JabberAccount::setMessageHandler(HJHANDLER hHandler) +{ + hMessageHandler = hHandler; +} + + +wchar_t *JabberAccount::getAccountName() +{ + return AccountName; +} +int JabberAccount::getAccountNumber() +{ + return AccountNumber; +} +IJabberInterface *JabberAccount::getJabberInterface() +{ + return JabberInterface; +} +HJHANDLER JabberAccount::getSendHandler() +{ + return hSendHandler; +} +HJHANDLER JabberAccount::getPrescenseHandler() +{ + return hPrescenseHandler; +} + +HJHANDLER JabberAccount::getMessageHandler() +{ + return hMessageHandler; +} + + +JabberAccount::JabberAccount() +{ + AccountName = nullptr; + hSendHandler = INVALID_HANDLE_VALUE; + hPrescenseHandler = INVALID_HANDLE_VALUE; + hMessageHandler = INVALID_HANDLE_VALUE; + AccountNumber = -1; + JabberInterface = nullptr; +} +JabberAccount::~JabberAccount() +{ + if(AccountName) + mir_free(AccountName); }
\ No newline at end of file diff --git a/plugins/New_GPG/src/jabber_account.h b/plugins/New_GPG/src/jabber_account.h index c29003d612..fe336bd4a1 100644 --- a/plugins/New_GPG/src/jabber_account.h +++ b/plugins/New_GPG/src/jabber_account.h @@ -1,43 +1,43 @@ -// Copyright © 2010-2012 sss
-//
-// 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.
-#ifndef JABBER_ACCOUNT_H
-#define JABBER_ACCOUNT_H
-class JabberAccount
-{
-public:
- void setAccountName(wchar_t *Name);
- void setAccountNumber(int Number);
- void setJabberInterface(IJabberInterface *JIf);
- void setSendHandler(HJHANDLER hHandler);
- void setPrescenseHandler(HJHANDLER hHandler);
- void setMessageHandler(HJHANDLER hHandler);
-
- wchar_t *getAccountName();
- int getAccountNumber();
- IJabberInterface *getJabberInterface();
- HJHANDLER getSendHandler();
- HJHANDLER getPrescenseHandler();
- HJHANDLER getMessageHandler();
- ~JabberAccount();
- JabberAccount();
-private:
- wchar_t *AccountName;
- int AccountNumber;
- IJabberInterface *JabberInterface;
- HJHANDLER hSendHandler, hPrescenseHandler, hMessageHandler;
-};
-
+// Copyright © 2010-2012 sss +// +// 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. +#ifndef JABBER_ACCOUNT_H +#define JABBER_ACCOUNT_H +class JabberAccount +{ +public: + void setAccountName(wchar_t *Name); + void setAccountNumber(int Number); + void setJabberInterface(IJabberInterface *JIf); + void setSendHandler(HJHANDLER hHandler); + void setPrescenseHandler(HJHANDLER hHandler); + void setMessageHandler(HJHANDLER hHandler); + + wchar_t *getAccountName(); + int getAccountNumber(); + IJabberInterface *getJabberInterface(); + HJHANDLER getSendHandler(); + HJHANDLER getPrescenseHandler(); + HJHANDLER getMessageHandler(); + ~JabberAccount(); + JabberAccount(); +private: + wchar_t *AccountName; + int AccountNumber; + IJabberInterface *JabberInterface; + HJHANDLER hSendHandler, hPrescenseHandler, hMessageHandler; +}; + #endif
\ No newline at end of file diff --git a/plugins/New_GPG/src/log.cpp b/plugins/New_GPG/src/log.cpp index a1927e4274..1737f3853e 100644 --- a/plugins/New_GPG/src/log.cpp +++ b/plugins/New_GPG/src/log.cpp @@ -1,87 +1,87 @@ -// Copyright © 2010-2012 sss
-//
-// 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"
-
-
-logtofile& logtofile::operator<<(wchar_t *buf)
-{
- if(_bDebugLog != bDebugLog)
- init();
- log_mutex.lock();
- log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate);
- log<<toUTF8(buf);
- log<<"\n";
- log.close();
- log_mutex.unlock();
- return *this;
-}
-logtofile& logtofile::operator<<(char *buf)
-{
- if(_bDebugLog != bDebugLog)
- init();
- log_mutex.lock();
- log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate);
- log<<buf;
- log<<"\n";
- log.close();
- log_mutex.unlock();
- return *this;
-}
-logtofile& logtofile::operator<<(string buf)
-{
- if(_bDebugLog != bDebugLog)
- init();
- log_mutex.lock();
- char *tmp = mir_utf8encode(buf.c_str());
- log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate);
- log<<tmp;
- log<<"\n";
- log.close();
- log_mutex.unlock();
- mir_free(tmp);
- return *this;
-}
-logtofile& logtofile::operator<<(wstring buf)
-{
- if(_bDebugLog != bDebugLog)
- init();
- log_mutex.lock();
- log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate);
- log<<toUTF8(buf);
- log<<"\n";
- log.close();
- log_mutex.unlock();
- return *this;
-}
-void logtofile::init()
-{
- if(bDebugLog)
- {
- if(path)
- mir_free(path);
- path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", L"C:\\GPGdebug.log");
- }
- _bDebugLog = bDebugLog;
-}
-logtofile::logtofile()
-{
- path = nullptr;
-}
-logtofile::~logtofile()
-{
- mir_free(path);
-}
+// Copyright © 2010-2012 sss +// +// 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" + + +logtofile& logtofile::operator<<(wchar_t *buf) +{ + if(_bDebugLog != bDebugLog) + init(); + log_mutex.lock(); + log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate); + log<<toUTF8(buf); + log<<"\n"; + log.close(); + log_mutex.unlock(); + return *this; +} +logtofile& logtofile::operator<<(char *buf) +{ + if(_bDebugLog != bDebugLog) + init(); + log_mutex.lock(); + log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate); + log<<buf; + log<<"\n"; + log.close(); + log_mutex.unlock(); + return *this; +} +logtofile& logtofile::operator<<(string buf) +{ + if(_bDebugLog != bDebugLog) + init(); + log_mutex.lock(); + char *tmp = mir_utf8encode(buf.c_str()); + log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate); + log<<tmp; + log<<"\n"; + log.close(); + log_mutex.unlock(); + mir_free(tmp); + return *this; +} +logtofile& logtofile::operator<<(wstring buf) +{ + if(_bDebugLog != bDebugLog) + init(); + log_mutex.lock(); + log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate); + log<<toUTF8(buf); + log<<"\n"; + log.close(); + log_mutex.unlock(); + return *this; +} +void logtofile::init() +{ + if(bDebugLog) + { + if(path) + mir_free(path); + path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", L"C:\\GPGdebug.log"); + } + _bDebugLog = bDebugLog; +} +logtofile::logtofile() +{ + path = nullptr; +} +logtofile::~logtofile() +{ + mir_free(path); +} diff --git a/plugins/New_GPG/src/main.cpp b/plugins/New_GPG/src/main.cpp index 874418587e..830d853ea9 100755 --- a/plugins/New_GPG/src/main.cpp +++ b/plugins/New_GPG/src/main.cpp @@ -28,11 +28,11 @@ HWND hwndFirstRun = nullptr, hwndSetDirs = nullptr, hwndNewKey = nullptr, hwndKe int itemnum = 0; HWND hwndList_g = nullptr; -BOOL CheckStateStoreDB(HWND hwndDlg, int idCtrl, const char* szSetting)
-{
- BOOL state = IsDlgButtonChecked(hwndDlg, idCtrl);
- db_set_b(NULL, szGPGModuleName, szSetting, (BYTE)state);
- return state;
+BOOL CheckStateStoreDB(HWND hwndDlg, int idCtrl, const char* szSetting) +{ + BOOL state = IsDlgButtonChecked(hwndDlg, idCtrl); + db_set_b(NULL, szGPGModuleName, szSetting, (BYTE)state); + return state; } wchar_t key_id_global[17] = { 0 }; diff --git a/plugins/New_GPG/src/main.h b/plugins/New_GPG/src/main.h index d5c9a6c0a8..745f5e2a77 100644 --- a/plugins/New_GPG/src/main.h +++ b/plugins/New_GPG/src/main.h @@ -1,31 +1,31 @@ -// Copyright © 2010-2012 sss
-//
-// 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.
-#ifndef MAIN_H
-#define MAIN_H
-
-struct contact_data
-{
- list<string> msgs_to_send;// msgs_to_pass;
- string key_in_prescense;
-};
-
-extern std::map<MCONTACT, contact_data> hcontact_data;
-extern bool bAutoExchange;
-extern RECT key_from_keyserver_rect, firstrun_rect, new_key_rect, key_gen_rect, load_key_rect, import_key_rect, key_password_rect, load_existing_key_rect;
-
-#endif
-
-
+// Copyright © 2010-2012 sss +// +// 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. +#ifndef MAIN_H +#define MAIN_H + +struct contact_data +{ + list<string> msgs_to_send;// msgs_to_pass; + string key_in_prescense; +}; + +extern std::map<MCONTACT, contact_data> hcontact_data; +extern bool bAutoExchange; +extern RECT key_from_keyserver_rect, firstrun_rect, new_key_rect, key_gen_rect, load_key_rect, import_key_rect, key_password_rect, load_existing_key_rect; + +#endif + + diff --git a/plugins/New_GPG/src/messages.cpp b/plugins/New_GPG/src/messages.cpp index 4c30f3668b..ab44c30e01 100755 --- a/plugins/New_GPG/src/messages.cpp +++ b/plugins/New_GPG/src/messages.cpp @@ -1028,17 +1028,17 @@ public: chk_DEFAULT_PASSWORD.Disable(); } } - virtual void OnClose() override
- {
- DestroyWindow(m_hwnd);
- }
- virtual void OnDestroy() override
- {
- mir_free(inkeyid);
+ virtual void OnClose() override + { + DestroyWindow(m_hwnd); + } + virtual void OnDestroy() override + { + mir_free(inkeyid); GetWindowRect(m_hwnd, &key_password_rect); db_set_dw(NULL, szGPGModuleName, "PasswordWindowX", key_password_rect.left); db_set_dw(NULL, szGPGModuleName, "PasswordWindowY", key_password_rect.top); - delete this;
+ delete this; } void onClick_OK(CCtrlButton*) { diff --git a/plugins/New_GPG/src/metacontacts.cpp b/plugins/New_GPG/src/metacontacts.cpp index 8d433e6e6b..73225bdbb4 100644 --- a/plugins/New_GPG/src/metacontacts.cpp +++ b/plugins/New_GPG/src/metacontacts.cpp @@ -1,29 +1,29 @@ -// Copyright © 2010-2012 SecureIM developers (baloo and others), sss
-//
-// 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"
-
-bool metaIsDefaultSubContact(MCONTACT hContact)
-{
- return db_mc_getDefault(db_mc_getMeta(hContact)) == hContact;
-}
-
-MCONTACT metaGetMostOnline(MCONTACT hContact)
-{
- if(db_mc_isMeta(hContact))
- return db_mc_getMostOnline(hContact);
- return NULL;
-}
+// Copyright © 2010-2012 SecureIM developers (baloo and others), sss +// +// 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" + +bool metaIsDefaultSubContact(MCONTACT hContact) +{ + return db_mc_getDefault(db_mc_getMeta(hContact)) == hContact; +} + +MCONTACT metaGetMostOnline(MCONTACT hContact) +{ + if(db_mc_isMeta(hContact)) + return db_mc_getMostOnline(hContact); + return NULL; +} diff --git a/plugins/New_GPG/src/metacontacts.h b/plugins/New_GPG/src/metacontacts.h index 30953dda5b..23a56d4ef7 100644 --- a/plugins/New_GPG/src/metacontacts.h +++ b/plugins/New_GPG/src/metacontacts.h @@ -1,19 +1,19 @@ -// Copyright © 2010-2012 sss
-//
-// 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.
-
-bool metaIsDefaultSubContact(MCONTACT hContact) ;
-MCONTACT metaGetMostOnline(MCONTACT hContact);
-
+// Copyright © 2010-2012 sss +// +// 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. + +bool metaIsDefaultSubContact(MCONTACT hContact) ; +MCONTACT metaGetMostOnline(MCONTACT hContact); + diff --git a/plugins/New_GPG/src/options.cpp b/plugins/New_GPG/src/options.cpp index 24c6505ad8..a59a0d54fa 100755 --- a/plugins/New_GPG/src/options.cpp +++ b/plugins/New_GPG/src/options.cpp @@ -1,1094 +1,1094 @@ -// Copyright � 2010-2012 sss
-//
-// 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"
-
-extern HINSTANCE hInst;
-extern bool bJabberAPI, bFileTransfers;
-
-
-map<int, MCONTACT> user_data;
-
-int item_num = 0;
-HWND hwndList_p = nullptr;
-HWND hwndCurKey_p = nullptr;
-
-void ShowLoadPublicKeyDialog(bool = false);
-
-class COptGpgMainDlg : public CDlgBase
-{
- CCtrlListView list_USERLIST;
- CCtrlData lbl_CURRENT_KEY;
- CCtrlEdit edit_LOG_FILE_EDIT;
- CCtrlCheck check_DEBUG_LOG, check_JABBER_API, check_AUTO_EXCHANGE, check_FILE_TRANSFERS;
- CCtrlButton btn_DELETE_KEY_BUTTON, btn_SELECT_KEY, btn_SAVE_KEY_BUTTON, btn_COPY_KEY, btn_LOG_FILE_SET;
-
-public:
- COptGpgMainDlg() : CDlgBase(hInst, IDD_OPT_GPG),
- list_USERLIST(this, IDC_USERLIST), lbl_CURRENT_KEY(this, IDC_CURRENT_KEY), edit_LOG_FILE_EDIT(this, IDC_LOG_FILE_EDIT),
- check_DEBUG_LOG(this, IDC_DEBUG_LOG), check_JABBER_API(this, IDC_JABBER_API), check_AUTO_EXCHANGE(this, IDC_AUTO_EXCHANGE), check_FILE_TRANSFERS(this, IDC_FILE_TRANSFERS),
- btn_DELETE_KEY_BUTTON(this, IDC_DELETE_KEY_BUTTON), btn_SELECT_KEY(this, IDC_SELECT_KEY), btn_SAVE_KEY_BUTTON(this, IDC_SAVE_KEY_BUTTON), btn_COPY_KEY(this, IDC_COPY_KEY), btn_LOG_FILE_SET(this, IDC_LOG_FILE_SET)
- {
- btn_DELETE_KEY_BUTTON.OnClick = Callback(this, &COptGpgMainDlg::onClick_DELETE_KEY_BUTTON);
- btn_SELECT_KEY.OnClick = Callback(this, &COptGpgMainDlg::onClick_SELECT_KEY);
- btn_SAVE_KEY_BUTTON.OnClick = Callback(this, &COptGpgMainDlg::onClick_SAVE_KEY_BUTTON);
- btn_COPY_KEY.OnClick = Callback(this, &COptGpgMainDlg::onClick_COPY_KEY);
- btn_LOG_FILE_SET.OnClick = Callback(this, &COptGpgMainDlg::onClick_LOG_FILE_SET);
-
- check_JABBER_API.OnChange = Callback(this, &COptGpgMainDlg::onChange_JABBER_API);
-
- list_USERLIST.OnItemActivate;
- list_USERLIST.OnColumnClick;
- list_USERLIST.OnDoubleClick;
- }
-
- virtual void OnInitDialog() override
- {
- list_USERLIST.AddColumn(0, TranslateT("Contact"), 60);
- list_USERLIST.AddColumn(1, TranslateT("Key ID"), 50);
- list_USERLIST.AddColumn(2, TranslateT("Name"), 50);
- list_USERLIST.AddColumn(3, TranslateT("Email"), 50);
- list_USERLIST.AddColumn(4, TranslateT("Protocol"), 60);
- list_USERLIST.SetExtendedListViewStyle(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);
- int i = 1;
- for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact))
- {
- if (isContactHaveKey(hContact))
- {
- wchar_t *name = pcli->pfnGetContactDisplayName(hContact, 0);
-
- int row = list_USERLIST.AddItem(L"", 0);
- list_USERLIST.SetItemText(row, 0, name);
-
- wchar_t *tmp = mir_a2u(GetContactProto(hContact));
- list_USERLIST.SetItemText(row, 4, tmp);
- mir_free(tmp);
-
- char *tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", "");
- tmp = mir_a2u(tmp2);
- mir_free(tmp2);
- list_USERLIST.SetItemText(row, 1, (mir_wstrlen(tmp) > 1) ? tmp : L"not set");
- mir_free(tmp);
-
- tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainName", "");
- if (!toUTF16(tmp2).empty())
- tmp = mir_wstrdup(toUTF16(tmp2).c_str());
- else
- tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainName", L"");
- mir_free(tmp2);
- list_USERLIST.SetItemText(row, 2, (mir_wstrlen(tmp) > 1) ? tmp : L"not set");
- mir_free(tmp);
-
- tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainEmail", "");
- if (!toUTF16(tmp2).empty())
- tmp = mir_wstrdup(toUTF16(tmp2).c_str());
- else
- tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainEmail", L"");
- mir_free(tmp2);
- list_USERLIST.SetItemText(row, 3, (mir_wstrlen(tmp) > 1) ? tmp : L"not set");
- mir_free(tmp);
-
-
- if (db_get_b(hContact, szGPGModuleName, "GPGEncryption", 0))
- list_USERLIST.SetCheckState(row, 1);
- user_data[i] = hContact;
- list_USERLIST.SetColumnWidth(0, LVSCW_AUTOSIZE);
- list_USERLIST.SetColumnWidth(1, LVSCW_AUTOSIZE);
- list_USERLIST.SetColumnWidth(2, LVSCW_AUTOSIZE);
- list_USERLIST.SetColumnWidth(3, LVSCW_AUTOSIZE);
- list_USERLIST.SetColumnWidth(4, LVSCW_AUTOSIZE);
- i++;
- }
- }
- edit_LOG_FILE_EDIT.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", L"")));
-
- check_DEBUG_LOG.SetState(db_get_b(NULL, szGPGModuleName, "bDebugLog", 0));
- check_JABBER_API.Enable();
- check_AUTO_EXCHANGE.Enable(bJabberAPI);
-
- {
- string keyinfo = Translate("Default private key ID");
- keyinfo += ": ";
- char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", "");
- keyinfo += (mir_strlen(keyid) > 0) ? keyid : Translate("not set");
- mir_free(keyid);
- lbl_CURRENT_KEY.SetTextA(keyinfo.c_str());
- }
- check_JABBER_API.SetState(db_get_b(NULL, szGPGModuleName, "bJabberAPI", 1));
- check_FILE_TRANSFERS.SetState(db_get_b(NULL, szGPGModuleName, "bFileTransfers", 0));
- check_AUTO_EXCHANGE.SetState(db_get_b(NULL, szGPGModuleName, "bAutoExchange", 0));
-
- //TODO: get rid of following s..t
- ////////////////
- hwndList_p = list_USERLIST.GetHwnd();
- hwndCurKey_p = lbl_CURRENT_KEY.GetHwnd();
- ////////////////
-
- list_USERLIST.OnItemChanged = Callback(this, &COptGpgMainDlg::onItemChanged_USERLIST);
- }
-
- virtual void OnApply() override
- {
- db_set_b(NULL, szGPGModuleName, "bDebugLog", bDebugLog = check_DEBUG_LOG.GetState());
-
- if (bDebugLog)
- debuglog.init();
- db_set_b(NULL, szGPGModuleName, "bJabberAPI", bJabberAPI = check_JABBER_API.GetState());
- bool old_bFileTransfers = db_get_b(NULL, szGPGModuleName, "bFileTransfers", 0) != 0;
- db_set_b(NULL, szGPGModuleName, "bFileTransfers", bFileTransfers = check_JABBER_API.GetState());
- if (bFileTransfers != old_bFileTransfers) {
- db_set_b(NULL, szGPGModuleName, "bSameAction", 0);
- bSameAction = false;
- }
- db_set_b(NULL, szGPGModuleName, "bAutoExchange", bAutoExchange = check_JABBER_API.GetState());
- db_set_ws(NULL, szGPGModuleName, "szLogFilePath", ptrW(edit_LOG_FILE_EDIT.GetText()));
- }
-
- void onClick_DELETE_KEY_BUTTON(CCtrlButton*)
- {
- void setClistIcon(MCONTACT hContact);
- void setSrmmIcon(MCONTACT hContact);
- { //gpg execute block
- wchar_t *ptmp;
- char *tmp;
- bool keep = false;
- bool ismetacontact = false;
- MCONTACT meta = NULL;
- MCONTACT hContact = user_data[item_num + 1];
- if (db_mc_isMeta(hContact)) {
- meta = hContact;
- hContact = metaGetMostOnline(hContact);
- ismetacontact = true;
- }
- else if ((meta = db_mc_getMeta(user_data[item_num + 1])) != NULL) {
- hContact = metaGetMostOnline(meta);
- ismetacontact = true;
- }
- tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", "");
- for (MCONTACT hcnttmp = db_find_first(); hcnttmp != NULL; hcnttmp = db_find_next(hcnttmp)) {
- if (hcnttmp != hContact) {
- char *tmp2 = UniGetContactSettingUtf(hcnttmp, szGPGModuleName, "KeyID", "");
- if (!mir_strcmp(tmp, tmp2)) {
- mir_free(tmp2);
- keep = true;
- break;
- }
- mir_free(tmp2);
- }
- }
- if (!keep)
- if (MessageBox(nullptr, TranslateT("This key is not used by any contact. Do you want to remove it from public keyring?"), TranslateT("Key info"), MB_YESNO) == IDYES) {
- std::vector<wstring> cmd;
- string output;
- DWORD exitcode;
- cmd.push_back(L"--batch");
- cmd.push_back(L"--yes");
- cmd.push_back(L"--delete-key");
- ptmp = mir_a2u(tmp);
- cmd.push_back(ptmp);
- mir_free(ptmp);
- gpg_execution_params params(cmd);
- pxResult result;
- params.out = &output;
- params.code = &exitcode;
- params.result = &result;
- if (!gpg_launcher(params)) {
- mir_free(tmp);
- return;
- }
- if (result == pxNotFound) {
- mir_free(tmp);
- return;
- }
- if (output.find("--delete-secret-keys") != string::npos)
- MessageBox(nullptr, TranslateT("we have secret key for this public key, do not removing from GPG keyring"), TranslateT("info"), MB_OK);
- else
- MessageBox(nullptr, TranslateT("Key removed from GPG keyring"), TranslateT("info"), MB_OK);
- }
- mir_free(tmp);
- if (ismetacontact) {
- if (MessageBox(nullptr, TranslateT("Do you want to remove key from entire metacontact (all subcontacts)?"), TranslateT("Metacontact detected"), MB_YESNO) == IDYES) {
- MCONTACT hcnt = NULL;
- int count = db_mc_getSubCount(meta);
- for (int i = 0; i < count; i++) {
- hcnt = db_mc_getSub(meta, i);
- if (hcnt) {
- db_unset(hcnt, szGPGModuleName, "KeyID");
- db_unset(hcnt, szGPGModuleName, "GPGPubKey");
- db_unset(hcnt, szGPGModuleName, "KeyMainName");
- db_unset(hcnt, szGPGModuleName, "KeyType");
- db_unset(hcnt, szGPGModuleName, "KeyMainEmail");
- db_unset(hcnt, szGPGModuleName, "KeyComment");
- setClistIcon(hcnt);
- setSrmmIcon(hcnt);
- }
- }
- }
- else {
- db_unset(hContact, szGPGModuleName, "KeyID");
- db_unset(hContact, szGPGModuleName, "GPGPubKey");
- db_unset(hContact, szGPGModuleName, "KeyMainName");
- db_unset(hContact, szGPGModuleName, "KeyType");
- db_unset(hContact, szGPGModuleName, "KeyMainEmail");
- db_unset(hContact, szGPGModuleName, "KeyComment");
- setClistIcon(hContact);
- setSrmmIcon(hContact);
- }
- }
- else {
- db_unset(user_data[item_num + 1], szGPGModuleName, "KeyID");
- db_unset(user_data[item_num + 1], szGPGModuleName, "GPGPubKey");
- db_unset(user_data[item_num + 1], szGPGModuleName, "KeyMainName");
- db_unset(user_data[item_num + 1], szGPGModuleName, "KeyType");
- db_unset(user_data[item_num + 1], szGPGModuleName, "KeyMainEmail");
- db_unset(user_data[item_num + 1], szGPGModuleName, "KeyComment");
- setClistIcon(user_data[item_num + 1]);
- setSrmmIcon(user_data[item_num + 1]);
- }
- }
- list_USERLIST.SetItemText(item_num, 3, TranslateT("not set"));
- list_USERLIST.SetItemText(item_num, 2, TranslateT("not set"));
- list_USERLIST.SetItemText(item_num, 1, TranslateT("not set"));
- }
-
- void onClick_SELECT_KEY(CCtrlButton*)
- {
- void ShowFirstRunDialog();
- ShowFirstRunDialog();
- }
-
- void onClick_SAVE_KEY_BUTTON(CCtrlButton*)
- {
- wchar_t *tmp = GetFilePath(TranslateT("Export public key"), L"*", TranslateT(".asc pubkey file"), true);
- if (tmp) {
- wstring str(ptrW(UniGetContactSettingUtf(user_data[item_num + 1], szGPGModuleName, "GPGPubKey", L"")));
- wstring::size_type s = 0;
- while ((s = str.find(L"\r", s)) != wstring::npos)
- str.erase(s, 1);
-
- wfstream f(tmp, std::ios::out);
- delete[] tmp;
- f << str.c_str();
- f.close();
- }
- }
-
- void onClick_COPY_KEY(CCtrlButton*)
- {
- if (OpenClipboard(m_hwnd)) {
- char *szKey = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", "");
- std::string str = szKey;
- mir_free(szKey);
- boost::algorithm::replace_all(str, "\n", "\r\n");
- HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, str.size() + 1);
- if (!hMem) {
- MessageBox(nullptr, TranslateT("Failed to allocate memory"), TranslateT("Error"), MB_OK);
- return;
- }
- szKey = (char*)GlobalLock(hMem);
- if (!szKey) {
- wchar_t msg[64];
- mir_snwprintf(msg, TranslateT("Failed to lock memory with error %d"), GetLastError());
- MessageBox(nullptr, msg, TranslateT("Error"), MB_OK);
- GlobalFree(hMem);
- }
- else {
- memcpy(szKey, str.c_str(), str.size());
- szKey[str.size()] = '\0';
- str.clear();
- EmptyClipboard();
- GlobalUnlock(hMem);
- if (!SetClipboardData(CF_OEMTEXT, hMem)) {
- GlobalFree(hMem);
- wchar_t msg[64];
- mir_snwprintf(msg, TranslateT("Failed write to clipboard with error %d"), GetLastError());
- MessageBox(nullptr, msg, TranslateT("Error"), MB_OK);
- }
- CloseClipboard();
- }
- }
- else {
- wchar_t msg[64];
- mir_snwprintf(msg, TranslateT("Failed to open clipboard with error %d"), GetLastError());
- MessageBox(nullptr, msg, TranslateT("Error"), MB_OK);
- }
- }
-
- void onClick_LOG_FILE_SET(CCtrlButton*)
- {
- edit_LOG_FILE_EDIT.SetText(ptrW(GetFilePath(TranslateT("Set log file"), L"*", TranslateT("LOG files"), 1)));
- }
-
- void onChange_JABBER_API(CCtrlCheck *chk)
- {
- check_AUTO_EXCHANGE.Enable(chk->GetState());
- }
-
- void onItemChanged_USERLIST(CCtrlListView::TEventInfo *ev)
- {
- //TODO: get rid of "item_num"
- if (ev->nmlv)
- {
- NMLISTVIEW *hdr = ev->nmlv;
-
- if (hdr->iItem == -1)
- return;
- void setClistIcon(MCONTACT hContact);
- void setSrmmIcon(MCONTACT hContact);
- item_num = hdr->iItem;
- if (list_USERLIST.GetCheckState(hdr->iItem))
- db_set_b(user_data[item_num + 1], szGPGModuleName, "GPGEncryption", 1);
- else
- db_set_b(user_data[item_num + 1], szGPGModuleName, "GPGEncryption", 0);
- setClistIcon(user_data[item_num + 1]);
- setSrmmIcon(user_data[item_num + 1]);
- }
- }
-
- void onClick_USERLIST(CCtrlListView::TEventInfo *ev)
- {
- //TODO: get rid of "item_num"
- if (ev->nmlv)
- {
- NMLISTVIEW *hdr = ev->nmlv;
-
- if (hdr->iItem == -1)
- return;
-
- item_num = hdr->iItem;
- }
- }
-};
-
-
-class COptGpgBinDlg : public CDlgBase
-{
- CCtrlEdit edit_BIN_PATH, edit_HOME_DIR;
- CCtrlButton btn_SET_BIN_PATH, btn_SET_HOME_DIR;
-
-public:
- COptGpgBinDlg() : CDlgBase(hInst, IDD_OPT_GPG_BIN),
- edit_BIN_PATH(this, IDC_BIN_PATH), edit_HOME_DIR(this, IDC_HOME_DIR),
- btn_SET_BIN_PATH(this, IDC_SET_BIN_PATH), btn_SET_HOME_DIR(this, IDC_SET_HOME_DIR)
- {
- btn_SET_BIN_PATH.OnClick = Callback(this, &COptGpgBinDlg::onClick_SET_BIN_PATH);
- btn_SET_HOME_DIR.OnClick = Callback(this, &COptGpgBinDlg::onClick_SET_HOME_DIR);
-
- }
-
- virtual void OnInitDialog() override
- {
- edit_BIN_PATH.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", L"gpg.exe")));
- edit_HOME_DIR.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", L"gpg")));
- }
-
- virtual void OnApply() override
- {
- wchar_t tmp[8192];
- db_set_ws(NULL, szGPGModuleName, "szGpgBinPath", edit_BIN_PATH.GetText());
- mir_wstrncpy(tmp, edit_HOME_DIR.GetText(), 8191);
- while (tmp[mir_wstrlen(tmp) - 1] == '\\')
- tmp[mir_wstrlen(tmp) - 1] = '\0';
- db_set_ws(NULL, szGPGModuleName, "szHomePath", tmp);
- }
-
- void onClick_SET_BIN_PATH(CCtrlButton*)
- {
- GetFilePath(TranslateT("Choose gpg.exe"), "szGpgBinPath", L"*.exe", TranslateT("EXE Executables"));
- CMStringW tmp(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", L"gpg.exe")));
- edit_BIN_PATH.SetText(tmp);
- bool gpg_exists = false;
- {
- if (_waccess(tmp, 0) != -1)
- gpg_exists = true;
- if (gpg_exists) {
- bool bad_version = false;
- wchar_t *tmp_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", L"");
- db_set_ws(NULL, szGPGModuleName, "szGpgBinPath", tmp);
- string out;
- DWORD code;
- std::vector<wstring> cmd;
- cmd.push_back(L"--version");
- gpg_execution_params params(cmd);
- pxResult result;
- params.out = &out;
- params.code = &code;
- params.result = &result;
- auto old_gpg_state = gpg_valid;
- gpg_valid = true;
- gpg_launcher(params);
- gpg_valid = old_gpg_state;
- db_set_ws(NULL, szGPGModuleName, "szGpgBinPath", tmp_path);
- mir_free(tmp_path);
- string::size_type p1 = out.find("(GnuPG) ");
- if (p1 != string::npos) {
- p1 += mir_strlen("(GnuPG) ");
- if (out[p1] != '1')
- bad_version = true;
- }
- else {
- bad_version = false;
- MessageBox(nullptr, TranslateT("This is not GnuPG binary!\nIt is recommended that you use GnuPG v1.x.x with this plugin."), TranslateT("Warning"), MB_OK);
- }
- /* if(bad_version) //looks like working fine with gpg2
- MessageBox(0, TranslateT("Unsupported GnuPG version found, use at you own risk!\nIt is recommended that you use GnuPG v1.x.x with this plugin."), L"Warning", MB_OK); */
- }
- }
- wchar_t mir_path[MAX_PATH];
- PathToAbsoluteW(L"\\", mir_path);
- if (tmp.Find(mir_path, 0) == 0) {
- CMStringW path = tmp.Mid(mir_wstrlen(mir_path));
- edit_BIN_PATH.SetText(path);
- }
- }
-
- void onClick_SET_HOME_DIR(CCtrlButton*)
- {
- GetFolderPath(TranslateT("Set home directory"), "szHomePath");
- CMStringW tmp(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", L"")));
- edit_HOME_DIR.SetText(tmp);
- wchar_t mir_path[MAX_PATH];
- PathToAbsoluteW(L"\\", mir_path);
- if (tmp.Find(mir_path, 0) == 0) {
- CMStringW path = tmp.Mid(mir_wstrlen(mir_path));
- edit_HOME_DIR.SetText(tmp);
- }
- }
-};
-
-class COptGpgMsgDlg : public CDlgBase
-{
- CCtrlCheck check_APPEND_TAGS, check_STRIP_TAGS;
- CCtrlEdit edit_IN_OPEN_TAG, edit_IN_CLOSE_TAG, edit_OUT_OPEN_TAG, edit_OUT_CLOSE_TAG;
-
-public:
- COptGpgMsgDlg() : CDlgBase(hInst, IDD_OPT_GPG_MESSAGES),
- check_APPEND_TAGS(this, IDC_APPEND_TAGS), check_STRIP_TAGS(this, IDC_STRIP_TAGS),
- edit_IN_OPEN_TAG(this, IDC_IN_OPEN_TAG), edit_IN_CLOSE_TAG(this, IDC_IN_CLOSE_TAG), edit_OUT_OPEN_TAG(this, IDC_OUT_OPEN_TAG), edit_OUT_CLOSE_TAG(this, IDC_OUT_CLOSE_TAG)
- {}
-
- virtual void OnInitDialog() override
- {
- check_APPEND_TAGS.SetState(db_get_b(NULL, szGPGModuleName, "bAppendTags", 0));
- check_STRIP_TAGS.SetState(db_get_b(NULL, szGPGModuleName, "bStripTags", 0));
- edit_IN_OPEN_TAG.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", L"<GPGdec>")));
- edit_IN_CLOSE_TAG.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", L"</GPGdec>")));
- edit_OUT_OPEN_TAG.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", L"<GPGenc>")));
- edit_OUT_CLOSE_TAG.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", L"</GPGenc>")));
- }
-
- virtual void OnApply() override
- {
- db_set_b(NULL, szGPGModuleName, "bAppendTags", bAppendTags = check_APPEND_TAGS.GetState());
- db_set_b(NULL, szGPGModuleName, "bStripTags", bStripTags = check_STRIP_TAGS.GetState());
- {
- wchar_t *tmp = mir_wstrdup(edit_IN_OPEN_TAG.GetText());
- db_set_ws(NULL, szGPGModuleName, "szInOpenTag", tmp);
- mir_free(inopentag);
- inopentag = tmp;
- tmp = mir_wstrdup(edit_IN_CLOSE_TAG.GetText());
- db_set_ws(NULL, szGPGModuleName, "szInCloseTag", tmp);
- mir_free(inclosetag);
- inclosetag = tmp;
- tmp = mir_wstrdup(edit_OUT_OPEN_TAG.GetText());
- db_set_ws(NULL, szGPGModuleName, "szOutOpenTag", tmp);
- mir_free(outopentag);
- outopentag = tmp;
- tmp = mir_wstrdup(edit_OUT_CLOSE_TAG.GetText());
- db_set_ws(NULL, szGPGModuleName, "szOutCloseTag", tmp);
- mir_free(outclosetag);
- outclosetag = tmp;
- }
- }
-};
-
-class COptGpgAdvDlg : public CDlgBase
-{
- CCtrlButton btn_EXPORT, btn_IMPORT;
- CCtrlCheck check_PRESCENSE_SUBSCRIPTION;
-
-public:
- COptGpgAdvDlg() : CDlgBase(hInst, IDD_OPT_GPG_ADVANCED),
- btn_EXPORT(this, IDC_EXPORT), btn_IMPORT(this, IDC_IMPORT),
- check_PRESCENSE_SUBSCRIPTION(this, IDC_PRESCENSE_SUBSCRIPTION)
- {
- btn_EXPORT.OnClick = Callback(this, &COptGpgAdvDlg::onClick_EXPORT);
- btn_IMPORT.OnClick = Callback(this, &COptGpgAdvDlg::onClick_IMPORT);
- }
-
- virtual void OnInitDialog() override
- {
- check_PRESCENSE_SUBSCRIPTION.SetState(db_get_b(NULL, szGPGModuleName, "bPresenceSigning", 0));
- check_PRESCENSE_SUBSCRIPTION.Enable(bJabberAPI);
- }
-
- virtual void OnApply() override
- {
- db_set_b(NULL, szGPGModuleName, "bPresenceSigning", bPresenceSigning = check_PRESCENSE_SUBSCRIPTION.GetState());
- }
-
- void onClick_EXPORT(CCtrlButton*)
- {
- INT_PTR ExportGpGKeys(WPARAM w, LPARAM l);
- ExportGpGKeys(NULL, NULL);
- }
-
- void onClick_IMPORT(CCtrlButton*)
- {
- INT_PTR ImportGpGKeys(WPARAM w, LPARAM l);
- ImportGpGKeys(NULL, NULL);
- }
-};
-
-
-HWND hPubKeyEdit = nullptr;
-
-static LRESULT CALLBACK editctrl_ctrl_a(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg) {
- case WM_KEYDOWN:
- if (wParam == 0x41 && GetKeyState(VK_CONTROL) < 0)
- SendMessage(hwndDlg, EM_SETSEL, 0, -1);
- return 0;
- }
- return mir_callNextSubclass(hwndDlg, editctrl_ctrl_a, msg, wParam, lParam);
-}
-
-class CDlgLoadPubKeyDlg : public CDlgBase
-{
- MCONTACT hContact;
- wstring key_buf;
- wstring::size_type ws1 = 0, ws2 = 0;
- CCtrlCheck chk_ENABLE_ENCRYPTION;
- CCtrlButton btn_SELECT_EXISTING, btn_OK, btn_LOAD_FROM_FILE, btn_IMPORT;
- CCtrlEdit edit_PUBLIC_KEY_EDIT;
-
-public:
- CDlgLoadPubKeyDlg() : CDlgBase(hInst, IDD_LOAD_PUBLIC_KEY),
- chk_ENABLE_ENCRYPTION(this, IDC_ENABLE_ENCRYPTION),
- btn_SELECT_EXISTING(this, IDC_SELECT_EXISTING), btn_OK(this, ID_OK), btn_LOAD_FROM_FILE(this, ID_LOAD_FROM_FILE), btn_IMPORT(this, IDC_IMPORT),
- edit_PUBLIC_KEY_EDIT(this, IDC_PUBLIC_KEY_EDIT)
- {
- btn_SELECT_EXISTING.OnClick = Callback(this, &CDlgLoadPubKeyDlg::onClick_SELECT_EXISTING);
- btn_OK.OnClick = Callback(this, &CDlgLoadPubKeyDlg::onClick_OK);
- btn_LOAD_FROM_FILE.OnClick = Callback(this, &CDlgLoadPubKeyDlg::onClick_LOAD_FROM_FILE);
- btn_IMPORT.OnClick = Callback(this, &CDlgLoadPubKeyDlg::onClick_IMPORT);
- }
-
- virtual void OnInitDialog() override
- {
- hContact = user_data[1];
- SetWindowPos(m_hwnd, nullptr, load_key_rect.left, load_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
- mir_subclassWindow(GetDlgItem(m_hwnd, IDC_PUBLIC_KEY_EDIT), editctrl_ctrl_a);
- MCONTACT hcnt = db_mc_tryMeta(hContact);
- {
- wstring msg = TranslateT("Load Public GPG Key for ");
- msg += pcli->pfnGetContactDisplayName(hcnt, 0);
- this->SetCaption(msg.c_str());
- }
- if (!hcnt) {
- btn_SELECT_EXISTING.Disable();
- chk_ENABLE_ENCRYPTION.Disable();
- }
- if (isContactSecured(hcnt))
- chk_ENABLE_ENCRYPTION.SetText(TranslateT("Turn off encryption"));
- else {
- chk_ENABLE_ENCRYPTION.SetText(TranslateT("Turn on encryption"));
- chk_ENABLE_ENCRYPTION.SetState(1);
- }
- if (hcnt) {
- wchar_t *tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", L"");
- wstring str = tmp;
- mir_free(tmp); tmp = nullptr;
- if (!str.empty()) {
- wstring::size_type p = 0, stop = 0;
- for (;;) {
- if ((p = str.find(L"\n", p + 2)) != wstring::npos) {
- if (p > stop) {
- stop = p;
- str.insert(p, L"\r");
- }
- else break;
- }
- }
- }
- // char *tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID_Prescense", "");
- if (!hcontact_data[hcnt].key_in_prescense.empty()) {
- char *tmp2 = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID", "");
- if (!tmp2[0]) {
- string out;
- DWORD code;
- std::vector<wstring> cmd;
- cmd.push_back(L"--export");
- cmd.push_back(L"-a");
- cmd.push_back(toUTF16(hcontact_data[hcnt].key_in_prescense));
- gpg_execution_params params(cmd);
- pxResult result;
- params.out = &out;
- params.code = &code;
- params.result = &result;
- gpg_launcher(params); //TODO: handle errors
- if ((out.find("-----BEGIN PGP PUBLIC KEY BLOCK-----") != string::npos) && (out.find("-----END PGP PUBLIC KEY BLOCK-----") != string::npos)) {
- boost::algorithm::replace_all(out, "\n", "\r\n");
-
- wchar_t *tmp3 = mir_a2u(out.c_str());
- str.clear();
- str.append(tmp3);
- mir_free(tmp3);
- string msg = Translate("Load Public GPG Key for ");
- msg += _T2A(pcli->pfnGetContactDisplayName(hcnt, 0));
- msg += " (Key ID: ";
- msg += hcontact_data[hcnt].key_in_prescense;
- msg += Translate(" found in presence, and exists in keyring.)");
- SetCaption(toUTF16(msg).c_str());
- }
- else {
- string msg = Translate("Load Public GPG Key (Key ID: ");
- msg += hcontact_data[hcnt].key_in_prescense;
- msg += Translate(" found in presence.)");
- SetCaption(toUTF16(msg).c_str());
- btn_IMPORT.Enable();
- }
- }
- mir_free(tmp2);
- }
- if (tmp)
- mir_free(tmp);
- edit_PUBLIC_KEY_EDIT.SetText(!str.empty() ? str.c_str() : L"");
- }
- hPubKeyEdit = edit_PUBLIC_KEY_EDIT.GetHwnd();
- }
-
- virtual void OnDestroy() override
- {
- GetWindowRect(m_hwnd, &load_key_rect);
- db_set_dw(NULL, szGPGModuleName, "LoadKeyWindowX", load_key_rect.left);
- db_set_dw(NULL, szGPGModuleName, "LoadKeyWindowY", load_key_rect.top);
- delete this;
- }
-
- void onClick_SELECT_EXISTING(CCtrlButton*)
- {
- void ShowSelectExistingKeyDialog();
- ShowSelectExistingKeyDialog();
- }
-
- void onClick_OK(CCtrlButton*)
- {
- wchar_t *tmp = mir_wstrdup(edit_PUBLIC_KEY_EDIT.GetText());
- wchar_t *begin, *end;
- key_buf.append(tmp);
- key_buf.append(L"\n"); //no new line at end of file )
- mir_free(tmp);
- while ((ws1 = key_buf.find(L"\r", ws1)) != wstring::npos) {
- key_buf.erase(ws1, 1); //remove windows specific trash
- }
- ws1 = 0;
- if (((ws2 = key_buf.find(L"-----END PGP PUBLIC KEY BLOCK-----")) != wstring::npos) && ((ws1 = key_buf.find(L"-----BEGIN PGP PUBLIC KEY BLOCK-----")) != wstring::npos)) {
- begin = (wchar_t*)mir_alloc(sizeof(wchar_t) * (mir_wstrlen(L"-----BEGIN PGP PUBLIC KEY BLOCK-----") + 1));
- mir_wstrcpy(begin, L"-----BEGIN PGP PUBLIC KEY BLOCK-----");
- end = (wchar_t*)mir_alloc(sizeof(wchar_t) * (mir_wstrlen(L"-----END PGP PUBLIC KEY BLOCK-----") + 1));
- mir_wstrcpy(end, L"-----END PGP PUBLIC KEY BLOCK-----");
- }
- else if (((ws2 = key_buf.find(L"-----END PGP PRIVATE KEY BLOCK-----")) != wstring::npos) && ((ws1 = key_buf.find(L"-----BEGIN PGP PRIVATE KEY BLOCK-----")) != wstring::npos)) {
- begin = (wchar_t*)mir_alloc(sizeof(wchar_t) * (mir_wstrlen(L"-----BEGIN PGP PRIVATE KEY BLOCK-----") + 1));
- mir_wstrcpy(begin, L"-----BEGIN PGP PRIVATE KEY BLOCK-----");
- end = (wchar_t*)mir_alloc(sizeof(wchar_t) * (mir_wstrlen(L"-----END PGP PRIVATE KEY BLOCK-----") + 1));
- mir_wstrcpy(end, L"-----END PGP PRIVATE KEY BLOCK-----");
- }
- else {
- MessageBox(nullptr, TranslateT("This is not public or private key"), L"INFO", MB_OK);
- return;
- }
- ws2 += mir_wstrlen(end);
- bool allsubcontacts = false;
- {
- if (db_mc_isMeta(hContact)) {
- if (MessageBox(nullptr, TranslateT("Do you want to load key for all subcontacts?"), TranslateT("Metacontact detected"), MB_YESNO) == IDYES) {
- allsubcontacts = true;
- int count = db_mc_getSubCount(hContact);
- for (int i = 0; i < count; i++) {
- MCONTACT hcnt = db_mc_getSub(hContact, i);
- if (hcnt)
- db_set_ws(hcnt, szGPGModuleName, "GPGPubKey", key_buf.substr(ws1, ws2 - ws1).c_str());
- }
- }
- else db_set_ws(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", key_buf.substr(ws1, ws2 - ws1).c_str());
- }
- else db_set_ws(hContact, szGPGModuleName, "GPGPubKey", key_buf.substr(ws1, ws2 - ws1).c_str());
- }
- tmp = (wchar_t*)mir_alloc(sizeof(wchar_t) * (key_buf.length() + 1));
- mir_wstrcpy(tmp, key_buf.substr(ws1, ws2 - ws1).c_str());
- { //gpg execute block
- std::vector<wstring> cmd;
- wchar_t tmp2[MAX_PATH] = { 0 };
- wchar_t *ptmp;
- string output;
- DWORD exitcode;
- {
- MCONTACT hcnt = db_mc_tryMeta(hContact);
- ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", L"");
- wcsncpy(tmp2, ptmp, MAX_PATH - 1);
- mir_free(ptmp);
- mir_wstrncat(tmp2, L"\\", _countof(tmp2) - mir_wstrlen(tmp2));
- mir_wstrncat(tmp2, L"temporary_exported.asc", _countof(tmp2) - mir_wstrlen(tmp2));
- boost::filesystem::remove(tmp2);
- wfstream f(tmp2, std::ios::out);
- ptmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", L"");
- wstring str = ptmp;
- mir_free(ptmp);
- wstring::size_type s = 0;
- while ((s = str.find(L"\r", s)) != wstring::npos) {
- str.erase(s, 1);
- }
- f << str.c_str();
- f.close();
- cmd.push_back(L"--batch");
- cmd.push_back(L"--import");
- cmd.push_back(tmp2);
- }
- gpg_execution_params params(cmd);
- pxResult result;
- params.out = &output;
- params.code = &exitcode;
- params.result = &result;
- if (!gpg_launcher(params))
- return;
- if (result == pxNotFound)
- return;
- mir_free(begin);
- mir_free(end);
- if (hContact) {
- if (db_mc_isMeta(hContact)) {
- if (allsubcontacts) {
- int count = db_mc_getSubCount(hContact);
- for (int i = 0; i < count; i++) {
- MCONTACT hcnt = db_mc_getSub(hContact, i);
- if (hcnt)
- db_unset(hcnt, szGPGModuleName, "bAlwatsTrust");
- }
- }
- else db_unset(metaGetMostOnline(hContact), szGPGModuleName, "bAlwatsTrust");
- }
- else db_unset(hContact, szGPGModuleName, "bAlwatsTrust");
- }
- {
- if (output.find("already in secret keyring") != string::npos) {
- MessageBox(nullptr, TranslateT("Key already in secret keyring."), TranslateT("Info"), MB_OK);
- boost::filesystem::remove(tmp2);
- return;
- }
- string::size_type s = output.find("gpg: key ") + mir_strlen("gpg: key ");
- string::size_type s2 = output.find(":", s);
- {
- char *tmp3 = (char*)mir_alloc((output.substr(s, s2 - s).length() + 1) * sizeof(char));
- mir_strcpy(tmp3, output.substr(s, s2 - s).c_str());
- mir_utf8decode(tmp3, nullptr);
- {
- if (db_mc_isMeta(hContact)) {
- if (allsubcontacts) {
- int count = db_mc_getSubCount(hContact);
- for (int i = 0; i < count; i++) {
- MCONTACT hcnt = db_mc_getSub(hContact, i);
- if (hcnt)
- db_set_s(hcnt, szGPGModuleName, "KeyID", tmp3);
- }
- }
- else
- db_set_s(metaGetMostOnline(hContact), szGPGModuleName, "KeyID", tmp3);
- }
- else
- db_set_s(hContact, szGPGModuleName, "KeyID", tmp3);
- }
- mir_free(tmp3);
- }
- tmp = mir_wstrdup(toUTF16(output.substr(s, s2 - s)).c_str());
- if (hContact && hwndList_p)
- ListView_SetItemText(hwndList_p, item_num, 1, tmp);
- mir_free(tmp);
- s = output.find("“", s2);
- if (s == string::npos) {
- s = output.find("\"", s2);
- s += 1;
- }
- else
- s += 3;
- bool uncommon = false;
- if ((s2 = output.find("(", s)) == string::npos) {
- if ((s2 = output.find("<", s)) == string::npos) {
- s2 = output.find("”", s);
- uncommon = true;
- }
- }
- else if (s2 > output.find("<", s))
- s2 = output.find("<", s);
- if (s2 != string::npos && s != string::npos) {
- {
- char *tmp3 = (char*)mir_alloc(sizeof(char)*(output.substr(s, s2 - s - (uncommon ? 1 : 0)).length() + 1));
- mir_strcpy(tmp3, output.substr(s, s2 - s - (uncommon ? 1 : 0)).c_str());
- mir_utf8decode(tmp3, nullptr);
- if (hContact) {
- if (db_mc_isMeta(hContact)) {
- if (allsubcontacts) {
- int count = db_mc_getSubCount(hContact);
- for (int i = 0; i < count; i++) {
- MCONTACT hcnt = db_mc_getSub(hContact, i);
- if (hcnt)
- db_set_s(hcnt, szGPGModuleName, "KeyMainName", output.substr(s, s2 - s - 1).c_str());
- }
- }
- else db_set_s(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainName", output.substr(s, s2 - s - 1).c_str());
- }
- else db_set_s(hContact, szGPGModuleName, "KeyMainName", output.substr(s, s2 - s - 1).c_str());
- }
- mir_free(tmp3);
- }
- tmp = mir_wstrdup(toUTF16(output.substr(s, s2 - s - 1)).c_str());
- if (hContact && hwndList_p)
- ListView_SetItemText(hwndList_p, item_num, 2, tmp); //TODO: do something with this
- mir_free(tmp);
- if ((s = output.find(")", s2)) == string::npos)
- s = output.find(">", s2);
- else if (s > output.find(">", s2))
- s = output.find(">", s2);
- s2++;
- if (s != string::npos && s2 != string::npos) {
- if (output[s] == ')') {
- char *tmp3 = (char*)mir_alloc((output.substr(s2, s - s2).length() + 1) * sizeof(char));
- mir_strcpy(tmp3, output.substr(s2, s - s2).c_str());
- mir_utf8decode(tmp3, nullptr);
- if (hContact) {
- if (db_mc_isMeta(hContact)) {
- if (allsubcontacts) {
- int count = db_mc_getSubCount(hContact);
- for (int i = 0; i < count; i++) {
- MCONTACT hcnt = db_mc_getSub(hContact, i);
- if (hcnt)
- db_set_s(hcnt, szGPGModuleName, "KeyComment", output.substr(s2, s - s2).c_str());
- }
- }
- else db_set_s(metaGetMostOnline(hContact), szGPGModuleName, "KeyComment", output.substr(s2, s - s2).c_str());
- }
- else db_set_s(hContact, szGPGModuleName, "KeyComment", output.substr(s2, s - s2).c_str());
- }
- mir_free(tmp3);
- s += 3;
- s2 = output.find(">", s);
- tmp3 = (char*)mir_alloc((output.substr(s, s2 - s).length() + 1) * sizeof(char));
- mir_strcpy(tmp3, output.substr(s, s2 - s).c_str());
- mir_utf8decode(tmp3, nullptr);
- if (hContact) {
- if (db_mc_isMeta(hContact)) {
- if (allsubcontacts) {
- int count = db_mc_getSubCount(hContact);
- for (int i = 0; i < count; i++) {
- MCONTACT hcnt = db_mc_getSub(hContact, i);
- if (hcnt)
- db_set_s(hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s, s2 - s).c_str());
- }
- }
- else db_set_s(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s, s2 - s).c_str());
- }
- else db_set_s(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s, s2 - s).c_str());
- }
- mir_free(tmp3);
- tmp = mir_wstrdup(toUTF16(output.substr(s, s2 - s)).c_str());
- if (hContact && hwndList_p)
- ListView_SetItemText(hwndList_p, item_num, 3, tmp);
- mir_free(tmp);
- }
- else {
- char *tmp3 = (char*)mir_alloc(output.substr(s2, s - s2).length() + 1);
- mir_strcpy(tmp3, output.substr(s2, s - s2).c_str());
- mir_utf8decode(tmp3, nullptr);
- if (hContact) {
- if (db_mc_isMeta(hContact)) {
- if (allsubcontacts) {
- int count = db_mc_getSubCount(hContact);
- for (int i = 0; i < count; i++) {
- MCONTACT hcnt = db_mc_getSub(hContact, i);
- if (hcnt)
- db_set_s(hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s2, s - s2).c_str());
- }
- }
- else db_set_s(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s2, s - s2).c_str());
- }
- else db_set_s(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2, s - s2).c_str());
- }
- mir_free(tmp3);
- tmp = mir_wstrdup(toUTF16(output.substr(s2, s - s2)).c_str());
- if (hContact && hwndList_p)
- ListView_SetItemText(hwndList_p, item_num, 3, tmp); //TODO: do something with this
- mir_free(tmp);
- }
- }
- }
- if (hContact && hwndList_p) //TODO: do something with this
- {
- ListView_SetColumnWidth(hwndList_p, 0, LVSCW_AUTOSIZE);
- ListView_SetColumnWidth(hwndList_p, 1, LVSCW_AUTOSIZE);
- ListView_SetColumnWidth(hwndList_p, 2, LVSCW_AUTOSIZE);
- ListView_SetColumnWidth(hwndList_p, 3, LVSCW_AUTOSIZE);
- }
- }
- if (!hContact) {
- wchar_t *fp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", L"");
- {
- string out;
- DWORD code;
- std::vector<wstring> cmds;
- cmds.push_back(L"--batch");
- cmds.push_back(L"-a");
- cmds.push_back(L"--export");
- cmds.push_back(fp);
- mir_free(fp);
- gpg_execution_params params2(cmds);
- pxResult result2;
- params2.out = &out;
- params2.code = &code;
- params2.result = &result2;
- if (!gpg_launcher(params2))
- return;
- if (result2 == pxNotFound)
- return;
- string::size_type s = 0;
- while ((s = out.find("\r", s)) != string::npos) {
- out.erase(s, 1);
- }
- db_set_s(hContact, szGPGModuleName, "GPGPubKey", out.c_str());
- }
- }
- tmp = mir_wstrdup(toUTF16(output).c_str());
- MessageBox(nullptr, tmp, L"", MB_OK);
- mir_free(tmp);
- boost::filesystem::remove(tmp2);
- }
- key_buf.clear();
- if (chk_ENABLE_ENCRYPTION.GetState()) {
- if (hContact) {
- if (db_mc_isMeta(hContact)) {
- if (allsubcontacts) {
- int count = db_mc_getSubCount(hContact);
- for (int i = 0; i < count; i++) {
- MCONTACT hcnt = db_mc_getSub(hContact, i);
- if (hcnt) {
- if (!isContactSecured(hcnt))
- db_set_b(hcnt, szGPGModuleName, "GPGEncryption", 1);
- else
- db_set_b(hcnt, szGPGModuleName, "GPGEncryption", 0);
- setSrmmIcon(hContact);
- setClistIcon(hContact);
- }
- }
- }
- else if (!isContactSecured(hContact))
- db_set_b(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 1);
- else
- db_set_b(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0);
- }
- else if (!isContactSecured(hContact))
- db_set_b(hContact, szGPGModuleName, "GPGEncryption", 1);
- else
- db_set_b(hContact, szGPGModuleName, "GPGEncryption", 0);
- }
- }
- DestroyWindow(m_hwnd);
- }
-
- void onClick_LOAD_FROM_FILE(CCtrlButton*)
- {
- wchar_t *tmp = GetFilePath(TranslateT("Set file containing GPG public key"), L"*", TranslateT("GPG public key file"));
- if (!tmp)
- return;
-
- wfstream f(tmp, std::ios::in | std::ios::ate | std::ios::binary);
- delete[] tmp;
- if (!f.is_open()) {
- MessageBox(nullptr, TranslateT("Failed to open file"), TranslateT("Error"), MB_OK);
- return;
- }
- if (f.is_open()) {
- std::wifstream::pos_type size = f.tellg();
- wchar_t *temp = new wchar_t[(std::ifstream::pos_type)size + (std::ifstream::pos_type)1];
- f.seekg(0, std::ios::beg);
- f.read(temp, size);
- temp[size] = '\0';
- key_buf.append(temp);
- delete[] temp;
- f.close();
- }
- if (key_buf.empty()) {
- key_buf.clear();
- if (bDebugLog)
- debuglog << std::string(time_str() + ": info: Failed to read key file");
- return;
- }
- ws2 = key_buf.find(L"-----END PGP PUBLIC KEY BLOCK-----");
- ws1 = key_buf.find(L"-----BEGIN PGP PUBLIC KEY BLOCK-----");
- if (ws2 == wstring::npos || ws1 == wstring::npos) {
- ws2 = key_buf.find(L"-----END PGP PRIVATE KEY BLOCK-----");
- ws1 = key_buf.find(L"-----BEGIN PGP PRIVATE KEY BLOCK-----");
- }
- if (ws2 == wstring::npos || ws1 == wstring::npos) {
- MessageBox(nullptr, TranslateT("There is no public or private key."), TranslateT("Info"), MB_OK);
- return;
- }
- ws2 += mir_wstrlen(L"-----END PGP PUBLIC KEY BLOCK-----");
- edit_PUBLIC_KEY_EDIT.SetText(key_buf.substr(ws1, ws2 - ws1).c_str());
- key_buf.clear();
- }
- void onClick_IMPORT(CCtrlButton*)
- {
- new_key_hcnt_mutex.lock();
- new_key_hcnt = hContact;
- void ShowImportKeyDialog();
- ShowImportKeyDialog();
- }
-};
-
-
-void ShowLoadPublicKeyDialog(bool modal)
-{
- CDlgLoadPubKeyDlg *d = new CDlgLoadPubKeyDlg();
- if (modal)
- d->DoModal();
- d->Show();
-}
-
-int GpgOptInit(WPARAM wParam, LPARAM)
-{
- OPTIONSDIALOGPAGE odp = {};
- odp.szGroup.w = LPGENW("Services");
- odp.szTitle.w = _T(szGPGModuleName);
-
- odp.szTab.w = LPGENW("Main");
- odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE;
- odp.pDialog = new COptGpgMainDlg();
- Options_AddPage(wParam, &odp);
-
- odp.szTab.w = LPGENW("GnuPG Variables");
- odp.pDialog = new COptGpgBinDlg();
- Options_AddPage(wParam, &odp);
-
- odp.szTab.w = LPGENW("Messages");
- odp.pDialog = new COptGpgMsgDlg();
- Options_AddPage(wParam, &odp);
-
- odp.szTab.w = LPGENW("Advanced");
- odp.pDialog = new COptGpgAdvDlg();
- Options_AddPage(wParam, &odp);
- return 0;
-}
+// Copyright � 2010-2012 sss +// +// 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" + +extern HINSTANCE hInst; +extern bool bJabberAPI, bFileTransfers; + + +map<int, MCONTACT> user_data; + +int item_num = 0; +HWND hwndList_p = nullptr; +HWND hwndCurKey_p = nullptr; + +void ShowLoadPublicKeyDialog(bool = false); + +class COptGpgMainDlg : public CDlgBase +{ + CCtrlListView list_USERLIST; + CCtrlData lbl_CURRENT_KEY; + CCtrlEdit edit_LOG_FILE_EDIT; + CCtrlCheck check_DEBUG_LOG, check_JABBER_API, check_AUTO_EXCHANGE, check_FILE_TRANSFERS; + CCtrlButton btn_DELETE_KEY_BUTTON, btn_SELECT_KEY, btn_SAVE_KEY_BUTTON, btn_COPY_KEY, btn_LOG_FILE_SET; + +public: + COptGpgMainDlg() : CDlgBase(hInst, IDD_OPT_GPG), + list_USERLIST(this, IDC_USERLIST), lbl_CURRENT_KEY(this, IDC_CURRENT_KEY), edit_LOG_FILE_EDIT(this, IDC_LOG_FILE_EDIT), + check_DEBUG_LOG(this, IDC_DEBUG_LOG), check_JABBER_API(this, IDC_JABBER_API), check_AUTO_EXCHANGE(this, IDC_AUTO_EXCHANGE), check_FILE_TRANSFERS(this, IDC_FILE_TRANSFERS), + btn_DELETE_KEY_BUTTON(this, IDC_DELETE_KEY_BUTTON), btn_SELECT_KEY(this, IDC_SELECT_KEY), btn_SAVE_KEY_BUTTON(this, IDC_SAVE_KEY_BUTTON), btn_COPY_KEY(this, IDC_COPY_KEY), btn_LOG_FILE_SET(this, IDC_LOG_FILE_SET) + { + btn_DELETE_KEY_BUTTON.OnClick = Callback(this, &COptGpgMainDlg::onClick_DELETE_KEY_BUTTON); + btn_SELECT_KEY.OnClick = Callback(this, &COptGpgMainDlg::onClick_SELECT_KEY); + btn_SAVE_KEY_BUTTON.OnClick = Callback(this, &COptGpgMainDlg::onClick_SAVE_KEY_BUTTON); + btn_COPY_KEY.OnClick = Callback(this, &COptGpgMainDlg::onClick_COPY_KEY); + btn_LOG_FILE_SET.OnClick = Callback(this, &COptGpgMainDlg::onClick_LOG_FILE_SET); + + check_JABBER_API.OnChange = Callback(this, &COptGpgMainDlg::onChange_JABBER_API); + + list_USERLIST.OnItemActivate; + list_USERLIST.OnColumnClick; + list_USERLIST.OnDoubleClick; + } + + virtual void OnInitDialog() override + { + list_USERLIST.AddColumn(0, TranslateT("Contact"), 60); + list_USERLIST.AddColumn(1, TranslateT("Key ID"), 50); + list_USERLIST.AddColumn(2, TranslateT("Name"), 50); + list_USERLIST.AddColumn(3, TranslateT("Email"), 50); + list_USERLIST.AddColumn(4, TranslateT("Protocol"), 60); + list_USERLIST.SetExtendedListViewStyle(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT); + int i = 1; + for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) + { + if (isContactHaveKey(hContact)) + { + wchar_t *name = pcli->pfnGetContactDisplayName(hContact, 0); + + int row = list_USERLIST.AddItem(L"", 0); + list_USERLIST.SetItemText(row, 0, name); + + wchar_t *tmp = mir_a2u(GetContactProto(hContact)); + list_USERLIST.SetItemText(row, 4, tmp); + mir_free(tmp); + + char *tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); + tmp = mir_a2u(tmp2); + mir_free(tmp2); + list_USERLIST.SetItemText(row, 1, (mir_wstrlen(tmp) > 1) ? tmp : L"not set"); + mir_free(tmp); + + tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainName", ""); + if (!toUTF16(tmp2).empty()) + tmp = mir_wstrdup(toUTF16(tmp2).c_str()); + else + tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainName", L""); + mir_free(tmp2); + list_USERLIST.SetItemText(row, 2, (mir_wstrlen(tmp) > 1) ? tmp : L"not set"); + mir_free(tmp); + + tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainEmail", ""); + if (!toUTF16(tmp2).empty()) + tmp = mir_wstrdup(toUTF16(tmp2).c_str()); + else + tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainEmail", L""); + mir_free(tmp2); + list_USERLIST.SetItemText(row, 3, (mir_wstrlen(tmp) > 1) ? tmp : L"not set"); + mir_free(tmp); + + + if (db_get_b(hContact, szGPGModuleName, "GPGEncryption", 0)) + list_USERLIST.SetCheckState(row, 1); + user_data[i] = hContact; + list_USERLIST.SetColumnWidth(0, LVSCW_AUTOSIZE); + list_USERLIST.SetColumnWidth(1, LVSCW_AUTOSIZE); + list_USERLIST.SetColumnWidth(2, LVSCW_AUTOSIZE); + list_USERLIST.SetColumnWidth(3, LVSCW_AUTOSIZE); + list_USERLIST.SetColumnWidth(4, LVSCW_AUTOSIZE); + i++; + } + } + edit_LOG_FILE_EDIT.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", L""))); + + check_DEBUG_LOG.SetState(db_get_b(NULL, szGPGModuleName, "bDebugLog", 0)); + check_JABBER_API.Enable(); + check_AUTO_EXCHANGE.Enable(bJabberAPI); + + { + string keyinfo = Translate("Default private key ID"); + keyinfo += ": "; + char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); + keyinfo += (mir_strlen(keyid) > 0) ? keyid : Translate("not set"); + mir_free(keyid); + lbl_CURRENT_KEY.SetTextA(keyinfo.c_str()); + } + check_JABBER_API.SetState(db_get_b(NULL, szGPGModuleName, "bJabberAPI", 1)); + check_FILE_TRANSFERS.SetState(db_get_b(NULL, szGPGModuleName, "bFileTransfers", 0)); + check_AUTO_EXCHANGE.SetState(db_get_b(NULL, szGPGModuleName, "bAutoExchange", 0)); + + //TODO: get rid of following s..t + //////////////// + hwndList_p = list_USERLIST.GetHwnd(); + hwndCurKey_p = lbl_CURRENT_KEY.GetHwnd(); + //////////////// + + list_USERLIST.OnItemChanged = Callback(this, &COptGpgMainDlg::onItemChanged_USERLIST); + } + + virtual void OnApply() override + { + db_set_b(NULL, szGPGModuleName, "bDebugLog", bDebugLog = check_DEBUG_LOG.GetState()); + + if (bDebugLog) + debuglog.init(); + db_set_b(NULL, szGPGModuleName, "bJabberAPI", bJabberAPI = check_JABBER_API.GetState()); + bool old_bFileTransfers = db_get_b(NULL, szGPGModuleName, "bFileTransfers", 0) != 0; + db_set_b(NULL, szGPGModuleName, "bFileTransfers", bFileTransfers = check_JABBER_API.GetState()); + if (bFileTransfers != old_bFileTransfers) { + db_set_b(NULL, szGPGModuleName, "bSameAction", 0); + bSameAction = false; + } + db_set_b(NULL, szGPGModuleName, "bAutoExchange", bAutoExchange = check_JABBER_API.GetState()); + db_set_ws(NULL, szGPGModuleName, "szLogFilePath", ptrW(edit_LOG_FILE_EDIT.GetText())); + } + + void onClick_DELETE_KEY_BUTTON(CCtrlButton*) + { + void setClistIcon(MCONTACT hContact); + void setSrmmIcon(MCONTACT hContact); + { //gpg execute block + wchar_t *ptmp; + char *tmp; + bool keep = false; + bool ismetacontact = false; + MCONTACT meta = NULL; + MCONTACT hContact = user_data[item_num + 1]; + if (db_mc_isMeta(hContact)) { + meta = hContact; + hContact = metaGetMostOnline(hContact); + ismetacontact = true; + } + else if ((meta = db_mc_getMeta(user_data[item_num + 1])) != NULL) { + hContact = metaGetMostOnline(meta); + ismetacontact = true; + } + tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); + for (MCONTACT hcnttmp = db_find_first(); hcnttmp != NULL; hcnttmp = db_find_next(hcnttmp)) { + if (hcnttmp != hContact) { + char *tmp2 = UniGetContactSettingUtf(hcnttmp, szGPGModuleName, "KeyID", ""); + if (!mir_strcmp(tmp, tmp2)) { + mir_free(tmp2); + keep = true; + break; + } + mir_free(tmp2); + } + } + if (!keep) + if (MessageBox(nullptr, TranslateT("This key is not used by any contact. Do you want to remove it from public keyring?"), TranslateT("Key info"), MB_YESNO) == IDYES) { + std::vector<wstring> cmd; + string output; + DWORD exitcode; + cmd.push_back(L"--batch"); + cmd.push_back(L"--yes"); + cmd.push_back(L"--delete-key"); + ptmp = mir_a2u(tmp); + cmd.push_back(ptmp); + mir_free(ptmp); + gpg_execution_params params(cmd); + pxResult result; + params.out = &output; + params.code = &exitcode; + params.result = &result; + if (!gpg_launcher(params)) { + mir_free(tmp); + return; + } + if (result == pxNotFound) { + mir_free(tmp); + return; + } + if (output.find("--delete-secret-keys") != string::npos) + MessageBox(nullptr, TranslateT("we have secret key for this public key, do not removing from GPG keyring"), TranslateT("info"), MB_OK); + else + MessageBox(nullptr, TranslateT("Key removed from GPG keyring"), TranslateT("info"), MB_OK); + } + mir_free(tmp); + if (ismetacontact) { + if (MessageBox(nullptr, TranslateT("Do you want to remove key from entire metacontact (all subcontacts)?"), TranslateT("Metacontact detected"), MB_YESNO) == IDYES) { + MCONTACT hcnt = NULL; + int count = db_mc_getSubCount(meta); + for (int i = 0; i < count; i++) { + hcnt = db_mc_getSub(meta, i); + if (hcnt) { + db_unset(hcnt, szGPGModuleName, "KeyID"); + db_unset(hcnt, szGPGModuleName, "GPGPubKey"); + db_unset(hcnt, szGPGModuleName, "KeyMainName"); + db_unset(hcnt, szGPGModuleName, "KeyType"); + db_unset(hcnt, szGPGModuleName, "KeyMainEmail"); + db_unset(hcnt, szGPGModuleName, "KeyComment"); + setClistIcon(hcnt); + setSrmmIcon(hcnt); + } + } + } + else { + db_unset(hContact, szGPGModuleName, "KeyID"); + db_unset(hContact, szGPGModuleName, "GPGPubKey"); + db_unset(hContact, szGPGModuleName, "KeyMainName"); + db_unset(hContact, szGPGModuleName, "KeyType"); + db_unset(hContact, szGPGModuleName, "KeyMainEmail"); + db_unset(hContact, szGPGModuleName, "KeyComment"); + setClistIcon(hContact); + setSrmmIcon(hContact); + } + } + else { + db_unset(user_data[item_num + 1], szGPGModuleName, "KeyID"); + db_unset(user_data[item_num + 1], szGPGModuleName, "GPGPubKey"); + db_unset(user_data[item_num + 1], szGPGModuleName, "KeyMainName"); + db_unset(user_data[item_num + 1], szGPGModuleName, "KeyType"); + db_unset(user_data[item_num + 1], szGPGModuleName, "KeyMainEmail"); + db_unset(user_data[item_num + 1], szGPGModuleName, "KeyComment"); + setClistIcon(user_data[item_num + 1]); + setSrmmIcon(user_data[item_num + 1]); + } + } + list_USERLIST.SetItemText(item_num, 3, TranslateT("not set")); + list_USERLIST.SetItemText(item_num, 2, TranslateT("not set")); + list_USERLIST.SetItemText(item_num, 1, TranslateT("not set")); + } + + void onClick_SELECT_KEY(CCtrlButton*) + { + void ShowFirstRunDialog(); + ShowFirstRunDialog(); + } + + void onClick_SAVE_KEY_BUTTON(CCtrlButton*) + { + wchar_t *tmp = GetFilePath(TranslateT("Export public key"), L"*", TranslateT(".asc pubkey file"), true); + if (tmp) { + wstring str(ptrW(UniGetContactSettingUtf(user_data[item_num + 1], szGPGModuleName, "GPGPubKey", L""))); + wstring::size_type s = 0; + while ((s = str.find(L"\r", s)) != wstring::npos) + str.erase(s, 1); + + wfstream f(tmp, std::ios::out); + delete[] tmp; + f << str.c_str(); + f.close(); + } + } + + void onClick_COPY_KEY(CCtrlButton*) + { + if (OpenClipboard(m_hwnd)) { + char *szKey = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); + std::string str = szKey; + mir_free(szKey); + boost::algorithm::replace_all(str, "\n", "\r\n"); + HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, str.size() + 1); + if (!hMem) { + MessageBox(nullptr, TranslateT("Failed to allocate memory"), TranslateT("Error"), MB_OK); + return; + } + szKey = (char*)GlobalLock(hMem); + if (!szKey) { + wchar_t msg[64]; + mir_snwprintf(msg, TranslateT("Failed to lock memory with error %d"), GetLastError()); + MessageBox(nullptr, msg, TranslateT("Error"), MB_OK); + GlobalFree(hMem); + } + else { + memcpy(szKey, str.c_str(), str.size()); + szKey[str.size()] = '\0'; + str.clear(); + EmptyClipboard(); + GlobalUnlock(hMem); + if (!SetClipboardData(CF_OEMTEXT, hMem)) { + GlobalFree(hMem); + wchar_t msg[64]; + mir_snwprintf(msg, TranslateT("Failed write to clipboard with error %d"), GetLastError()); + MessageBox(nullptr, msg, TranslateT("Error"), MB_OK); + } + CloseClipboard(); + } + } + else { + wchar_t msg[64]; + mir_snwprintf(msg, TranslateT("Failed to open clipboard with error %d"), GetLastError()); + MessageBox(nullptr, msg, TranslateT("Error"), MB_OK); + } + } + + void onClick_LOG_FILE_SET(CCtrlButton*) + { + edit_LOG_FILE_EDIT.SetText(ptrW(GetFilePath(TranslateT("Set log file"), L"*", TranslateT("LOG files"), 1))); + } + + void onChange_JABBER_API(CCtrlCheck *chk) + { + check_AUTO_EXCHANGE.Enable(chk->GetState()); + } + + void onItemChanged_USERLIST(CCtrlListView::TEventInfo *ev) + { + //TODO: get rid of "item_num" + if (ev->nmlv) + { + NMLISTVIEW *hdr = ev->nmlv; + + if (hdr->iItem == -1) + return; + void setClistIcon(MCONTACT hContact); + void setSrmmIcon(MCONTACT hContact); + item_num = hdr->iItem; + if (list_USERLIST.GetCheckState(hdr->iItem)) + db_set_b(user_data[item_num + 1], szGPGModuleName, "GPGEncryption", 1); + else + db_set_b(user_data[item_num + 1], szGPGModuleName, "GPGEncryption", 0); + setClistIcon(user_data[item_num + 1]); + setSrmmIcon(user_data[item_num + 1]); + } + } + + void onClick_USERLIST(CCtrlListView::TEventInfo *ev) + { + //TODO: get rid of "item_num" + if (ev->nmlv) + { + NMLISTVIEW *hdr = ev->nmlv; + + if (hdr->iItem == -1) + return; + + item_num = hdr->iItem; + } + } +}; + + +class COptGpgBinDlg : public CDlgBase +{ + CCtrlEdit edit_BIN_PATH, edit_HOME_DIR; + CCtrlButton btn_SET_BIN_PATH, btn_SET_HOME_DIR; + +public: + COptGpgBinDlg() : CDlgBase(hInst, IDD_OPT_GPG_BIN), + edit_BIN_PATH(this, IDC_BIN_PATH), edit_HOME_DIR(this, IDC_HOME_DIR), + btn_SET_BIN_PATH(this, IDC_SET_BIN_PATH), btn_SET_HOME_DIR(this, IDC_SET_HOME_DIR) + { + btn_SET_BIN_PATH.OnClick = Callback(this, &COptGpgBinDlg::onClick_SET_BIN_PATH); + btn_SET_HOME_DIR.OnClick = Callback(this, &COptGpgBinDlg::onClick_SET_HOME_DIR); + + } + + virtual void OnInitDialog() override + { + edit_BIN_PATH.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", L"gpg.exe"))); + edit_HOME_DIR.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", L"gpg"))); + } + + virtual void OnApply() override + { + wchar_t tmp[8192]; + db_set_ws(NULL, szGPGModuleName, "szGpgBinPath", edit_BIN_PATH.GetText()); + mir_wstrncpy(tmp, edit_HOME_DIR.GetText(), 8191); + while (tmp[mir_wstrlen(tmp) - 1] == '\\') + tmp[mir_wstrlen(tmp) - 1] = '\0'; + db_set_ws(NULL, szGPGModuleName, "szHomePath", tmp); + } + + void onClick_SET_BIN_PATH(CCtrlButton*) + { + GetFilePath(TranslateT("Choose gpg.exe"), "szGpgBinPath", L"*.exe", TranslateT("EXE Executables")); + CMStringW tmp(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", L"gpg.exe"))); + edit_BIN_PATH.SetText(tmp); + bool gpg_exists = false; + { + if (_waccess(tmp, 0) != -1) + gpg_exists = true; + if (gpg_exists) { + bool bad_version = false; + wchar_t *tmp_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", L""); + db_set_ws(NULL, szGPGModuleName, "szGpgBinPath", tmp); + string out; + DWORD code; + std::vector<wstring> cmd; + cmd.push_back(L"--version"); + gpg_execution_params params(cmd); + pxResult result; + params.out = &out; + params.code = &code; + params.result = &result; + auto old_gpg_state = gpg_valid; + gpg_valid = true; + gpg_launcher(params); + gpg_valid = old_gpg_state; + db_set_ws(NULL, szGPGModuleName, "szGpgBinPath", tmp_path); + mir_free(tmp_path); + string::size_type p1 = out.find("(GnuPG) "); + if (p1 != string::npos) { + p1 += mir_strlen("(GnuPG) "); + if (out[p1] != '1') + bad_version = true; + } + else { + bad_version = false; + MessageBox(nullptr, TranslateT("This is not GnuPG binary!\nIt is recommended that you use GnuPG v1.x.x with this plugin."), TranslateT("Warning"), MB_OK); + } + /* if(bad_version) //looks like working fine with gpg2 + MessageBox(0, TranslateT("Unsupported GnuPG version found, use at you own risk!\nIt is recommended that you use GnuPG v1.x.x with this plugin."), L"Warning", MB_OK); */ + } + } + wchar_t mir_path[MAX_PATH]; + PathToAbsoluteW(L"\\", mir_path); + if (tmp.Find(mir_path, 0) == 0) { + CMStringW path = tmp.Mid(mir_wstrlen(mir_path)); + edit_BIN_PATH.SetText(path); + } + } + + void onClick_SET_HOME_DIR(CCtrlButton*) + { + GetFolderPath(TranslateT("Set home directory"), "szHomePath"); + CMStringW tmp(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", L""))); + edit_HOME_DIR.SetText(tmp); + wchar_t mir_path[MAX_PATH]; + PathToAbsoluteW(L"\\", mir_path); + if (tmp.Find(mir_path, 0) == 0) { + CMStringW path = tmp.Mid(mir_wstrlen(mir_path)); + edit_HOME_DIR.SetText(tmp); + } + } +}; + +class COptGpgMsgDlg : public CDlgBase +{ + CCtrlCheck check_APPEND_TAGS, check_STRIP_TAGS; + CCtrlEdit edit_IN_OPEN_TAG, edit_IN_CLOSE_TAG, edit_OUT_OPEN_TAG, edit_OUT_CLOSE_TAG; + +public: + COptGpgMsgDlg() : CDlgBase(hInst, IDD_OPT_GPG_MESSAGES), + check_APPEND_TAGS(this, IDC_APPEND_TAGS), check_STRIP_TAGS(this, IDC_STRIP_TAGS), + edit_IN_OPEN_TAG(this, IDC_IN_OPEN_TAG), edit_IN_CLOSE_TAG(this, IDC_IN_CLOSE_TAG), edit_OUT_OPEN_TAG(this, IDC_OUT_OPEN_TAG), edit_OUT_CLOSE_TAG(this, IDC_OUT_CLOSE_TAG) + {} + + virtual void OnInitDialog() override + { + check_APPEND_TAGS.SetState(db_get_b(NULL, szGPGModuleName, "bAppendTags", 0)); + check_STRIP_TAGS.SetState(db_get_b(NULL, szGPGModuleName, "bStripTags", 0)); + edit_IN_OPEN_TAG.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", L"<GPGdec>"))); + edit_IN_CLOSE_TAG.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", L"</GPGdec>"))); + edit_OUT_OPEN_TAG.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", L"<GPGenc>"))); + edit_OUT_CLOSE_TAG.SetText(ptrW(UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", L"</GPGenc>"))); + } + + virtual void OnApply() override + { + db_set_b(NULL, szGPGModuleName, "bAppendTags", bAppendTags = check_APPEND_TAGS.GetState()); + db_set_b(NULL, szGPGModuleName, "bStripTags", bStripTags = check_STRIP_TAGS.GetState()); + { + wchar_t *tmp = mir_wstrdup(edit_IN_OPEN_TAG.GetText()); + db_set_ws(NULL, szGPGModuleName, "szInOpenTag", tmp); + mir_free(inopentag); + inopentag = tmp; + tmp = mir_wstrdup(edit_IN_CLOSE_TAG.GetText()); + db_set_ws(NULL, szGPGModuleName, "szInCloseTag", tmp); + mir_free(inclosetag); + inclosetag = tmp; + tmp = mir_wstrdup(edit_OUT_OPEN_TAG.GetText()); + db_set_ws(NULL, szGPGModuleName, "szOutOpenTag", tmp); + mir_free(outopentag); + outopentag = tmp; + tmp = mir_wstrdup(edit_OUT_CLOSE_TAG.GetText()); + db_set_ws(NULL, szGPGModuleName, "szOutCloseTag", tmp); + mir_free(outclosetag); + outclosetag = tmp; + } + } +}; + +class COptGpgAdvDlg : public CDlgBase +{ + CCtrlButton btn_EXPORT, btn_IMPORT; + CCtrlCheck check_PRESCENSE_SUBSCRIPTION; + +public: + COptGpgAdvDlg() : CDlgBase(hInst, IDD_OPT_GPG_ADVANCED), + btn_EXPORT(this, IDC_EXPORT), btn_IMPORT(this, IDC_IMPORT), + check_PRESCENSE_SUBSCRIPTION(this, IDC_PRESCENSE_SUBSCRIPTION) + { + btn_EXPORT.OnClick = Callback(this, &COptGpgAdvDlg::onClick_EXPORT); + btn_IMPORT.OnClick = Callback(this, &COptGpgAdvDlg::onClick_IMPORT); + } + + virtual void OnInitDialog() override + { + check_PRESCENSE_SUBSCRIPTION.SetState(db_get_b(NULL, szGPGModuleName, "bPresenceSigning", 0)); + check_PRESCENSE_SUBSCRIPTION.Enable(bJabberAPI); + } + + virtual void OnApply() override + { + db_set_b(NULL, szGPGModuleName, "bPresenceSigning", bPresenceSigning = check_PRESCENSE_SUBSCRIPTION.GetState()); + } + + void onClick_EXPORT(CCtrlButton*) + { + INT_PTR ExportGpGKeys(WPARAM w, LPARAM l); + ExportGpGKeys(NULL, NULL); + } + + void onClick_IMPORT(CCtrlButton*) + { + INT_PTR ImportGpGKeys(WPARAM w, LPARAM l); + ImportGpGKeys(NULL, NULL); + } +}; + + +HWND hPubKeyEdit = nullptr; + +static LRESULT CALLBACK editctrl_ctrl_a(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) { + case WM_KEYDOWN: + if (wParam == 0x41 && GetKeyState(VK_CONTROL) < 0) + SendMessage(hwndDlg, EM_SETSEL, 0, -1); + return 0; + } + return mir_callNextSubclass(hwndDlg, editctrl_ctrl_a, msg, wParam, lParam); +} + +class CDlgLoadPubKeyDlg : public CDlgBase +{ + MCONTACT hContact; + wstring key_buf; + wstring::size_type ws1 = 0, ws2 = 0; + CCtrlCheck chk_ENABLE_ENCRYPTION; + CCtrlButton btn_SELECT_EXISTING, btn_OK, btn_LOAD_FROM_FILE, btn_IMPORT; + CCtrlEdit edit_PUBLIC_KEY_EDIT; + +public: + CDlgLoadPubKeyDlg() : CDlgBase(hInst, IDD_LOAD_PUBLIC_KEY), + chk_ENABLE_ENCRYPTION(this, IDC_ENABLE_ENCRYPTION), + btn_SELECT_EXISTING(this, IDC_SELECT_EXISTING), btn_OK(this, ID_OK), btn_LOAD_FROM_FILE(this, ID_LOAD_FROM_FILE), btn_IMPORT(this, IDC_IMPORT), + edit_PUBLIC_KEY_EDIT(this, IDC_PUBLIC_KEY_EDIT) + { + btn_SELECT_EXISTING.OnClick = Callback(this, &CDlgLoadPubKeyDlg::onClick_SELECT_EXISTING); + btn_OK.OnClick = Callback(this, &CDlgLoadPubKeyDlg::onClick_OK); + btn_LOAD_FROM_FILE.OnClick = Callback(this, &CDlgLoadPubKeyDlg::onClick_LOAD_FROM_FILE); + btn_IMPORT.OnClick = Callback(this, &CDlgLoadPubKeyDlg::onClick_IMPORT); + } + + virtual void OnInitDialog() override + { + hContact = user_data[1]; + SetWindowPos(m_hwnd, nullptr, load_key_rect.left, load_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); + mir_subclassWindow(GetDlgItem(m_hwnd, IDC_PUBLIC_KEY_EDIT), editctrl_ctrl_a); + MCONTACT hcnt = db_mc_tryMeta(hContact); + { + wstring msg = TranslateT("Load Public GPG Key for "); + msg += pcli->pfnGetContactDisplayName(hcnt, 0); + this->SetCaption(msg.c_str()); + } + if (!hcnt) { + btn_SELECT_EXISTING.Disable(); + chk_ENABLE_ENCRYPTION.Disable(); + } + if (isContactSecured(hcnt)) + chk_ENABLE_ENCRYPTION.SetText(TranslateT("Turn off encryption")); + else { + chk_ENABLE_ENCRYPTION.SetText(TranslateT("Turn on encryption")); + chk_ENABLE_ENCRYPTION.SetState(1); + } + if (hcnt) { + wchar_t *tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", L""); + wstring str = tmp; + mir_free(tmp); tmp = nullptr; + if (!str.empty()) { + wstring::size_type p = 0, stop = 0; + for (;;) { + if ((p = str.find(L"\n", p + 2)) != wstring::npos) { + if (p > stop) { + stop = p; + str.insert(p, L"\r"); + } + else break; + } + } + } + // char *tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID_Prescense", ""); + if (!hcontact_data[hcnt].key_in_prescense.empty()) { + char *tmp2 = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID", ""); + if (!tmp2[0]) { + string out; + DWORD code; + std::vector<wstring> cmd; + cmd.push_back(L"--export"); + cmd.push_back(L"-a"); + cmd.push_back(toUTF16(hcontact_data[hcnt].key_in_prescense)); + gpg_execution_params params(cmd); + pxResult result; + params.out = &out; + params.code = &code; + params.result = &result; + gpg_launcher(params); //TODO: handle errors + if ((out.find("-----BEGIN PGP PUBLIC KEY BLOCK-----") != string::npos) && (out.find("-----END PGP PUBLIC KEY BLOCK-----") != string::npos)) { + boost::algorithm::replace_all(out, "\n", "\r\n"); + + wchar_t *tmp3 = mir_a2u(out.c_str()); + str.clear(); + str.append(tmp3); + mir_free(tmp3); + string msg = Translate("Load Public GPG Key for "); + msg += _T2A(pcli->pfnGetContactDisplayName(hcnt, 0)); + msg += " (Key ID: "; + msg += hcontact_data[hcnt].key_in_prescense; + msg += Translate(" found in presence, and exists in keyring.)"); + SetCaption(toUTF16(msg).c_str()); + } + else { + string msg = Translate("Load Public GPG Key (Key ID: "); + msg += hcontact_data[hcnt].key_in_prescense; + msg += Translate(" found in presence.)"); + SetCaption(toUTF16(msg).c_str()); + btn_IMPORT.Enable(); + } + } + mir_free(tmp2); + } + if (tmp) + mir_free(tmp); + edit_PUBLIC_KEY_EDIT.SetText(!str.empty() ? str.c_str() : L""); + } + hPubKeyEdit = edit_PUBLIC_KEY_EDIT.GetHwnd(); + } + + virtual void OnDestroy() override + { + GetWindowRect(m_hwnd, &load_key_rect); + db_set_dw(NULL, szGPGModuleName, "LoadKeyWindowX", load_key_rect.left); + db_set_dw(NULL, szGPGModuleName, "LoadKeyWindowY", load_key_rect.top); + delete this; + } + + void onClick_SELECT_EXISTING(CCtrlButton*) + { + void ShowSelectExistingKeyDialog(); + ShowSelectExistingKeyDialog(); + } + + void onClick_OK(CCtrlButton*) + { + wchar_t *tmp = mir_wstrdup(edit_PUBLIC_KEY_EDIT.GetText()); + wchar_t *begin, *end; + key_buf.append(tmp); + key_buf.append(L"\n"); //no new line at end of file ) + mir_free(tmp); + while ((ws1 = key_buf.find(L"\r", ws1)) != wstring::npos) { + key_buf.erase(ws1, 1); //remove windows specific trash + } + ws1 = 0; + if (((ws2 = key_buf.find(L"-----END PGP PUBLIC KEY BLOCK-----")) != wstring::npos) && ((ws1 = key_buf.find(L"-----BEGIN PGP PUBLIC KEY BLOCK-----")) != wstring::npos)) { + begin = (wchar_t*)mir_alloc(sizeof(wchar_t) * (mir_wstrlen(L"-----BEGIN PGP PUBLIC KEY BLOCK-----") + 1)); + mir_wstrcpy(begin, L"-----BEGIN PGP PUBLIC KEY BLOCK-----"); + end = (wchar_t*)mir_alloc(sizeof(wchar_t) * (mir_wstrlen(L"-----END PGP PUBLIC KEY BLOCK-----") + 1)); + mir_wstrcpy(end, L"-----END PGP PUBLIC KEY BLOCK-----"); + } + else if (((ws2 = key_buf.find(L"-----END PGP PRIVATE KEY BLOCK-----")) != wstring::npos) && ((ws1 = key_buf.find(L"-----BEGIN PGP PRIVATE KEY BLOCK-----")) != wstring::npos)) { + begin = (wchar_t*)mir_alloc(sizeof(wchar_t) * (mir_wstrlen(L"-----BEGIN PGP PRIVATE KEY BLOCK-----") + 1)); + mir_wstrcpy(begin, L"-----BEGIN PGP PRIVATE KEY BLOCK-----"); + end = (wchar_t*)mir_alloc(sizeof(wchar_t) * (mir_wstrlen(L"-----END PGP PRIVATE KEY BLOCK-----") + 1)); + mir_wstrcpy(end, L"-----END PGP PRIVATE KEY BLOCK-----"); + } + else { + MessageBox(nullptr, TranslateT("This is not public or private key"), L"INFO", MB_OK); + return; + } + ws2 += mir_wstrlen(end); + bool allsubcontacts = false; + { + if (db_mc_isMeta(hContact)) { + if (MessageBox(nullptr, TranslateT("Do you want to load key for all subcontacts?"), TranslateT("Metacontact detected"), MB_YESNO) == IDYES) { + allsubcontacts = true; + int count = db_mc_getSubCount(hContact); + for (int i = 0; i < count; i++) { + MCONTACT hcnt = db_mc_getSub(hContact, i); + if (hcnt) + db_set_ws(hcnt, szGPGModuleName, "GPGPubKey", key_buf.substr(ws1, ws2 - ws1).c_str()); + } + } + else db_set_ws(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", key_buf.substr(ws1, ws2 - ws1).c_str()); + } + else db_set_ws(hContact, szGPGModuleName, "GPGPubKey", key_buf.substr(ws1, ws2 - ws1).c_str()); + } + tmp = (wchar_t*)mir_alloc(sizeof(wchar_t) * (key_buf.length() + 1)); + mir_wstrcpy(tmp, key_buf.substr(ws1, ws2 - ws1).c_str()); + { //gpg execute block + std::vector<wstring> cmd; + wchar_t tmp2[MAX_PATH] = { 0 }; + wchar_t *ptmp; + string output; + DWORD exitcode; + { + MCONTACT hcnt = db_mc_tryMeta(hContact); + ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", L""); + wcsncpy(tmp2, ptmp, MAX_PATH - 1); + mir_free(ptmp); + mir_wstrncat(tmp2, L"\\", _countof(tmp2) - mir_wstrlen(tmp2)); + mir_wstrncat(tmp2, L"temporary_exported.asc", _countof(tmp2) - mir_wstrlen(tmp2)); + boost::filesystem::remove(tmp2); + wfstream f(tmp2, std::ios::out); + ptmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", L""); + wstring str = ptmp; + mir_free(ptmp); + wstring::size_type s = 0; + while ((s = str.find(L"\r", s)) != wstring::npos) { + str.erase(s, 1); + } + f << str.c_str(); + f.close(); + cmd.push_back(L"--batch"); + cmd.push_back(L"--import"); + cmd.push_back(tmp2); + } + gpg_execution_params params(cmd); + pxResult result; + params.out = &output; + params.code = &exitcode; + params.result = &result; + if (!gpg_launcher(params)) + return; + if (result == pxNotFound) + return; + mir_free(begin); + mir_free(end); + if (hContact) { + if (db_mc_isMeta(hContact)) { + if (allsubcontacts) { + int count = db_mc_getSubCount(hContact); + for (int i = 0; i < count; i++) { + MCONTACT hcnt = db_mc_getSub(hContact, i); + if (hcnt) + db_unset(hcnt, szGPGModuleName, "bAlwatsTrust"); + } + } + else db_unset(metaGetMostOnline(hContact), szGPGModuleName, "bAlwatsTrust"); + } + else db_unset(hContact, szGPGModuleName, "bAlwatsTrust"); + } + { + if (output.find("already in secret keyring") != string::npos) { + MessageBox(nullptr, TranslateT("Key already in secret keyring."), TranslateT("Info"), MB_OK); + boost::filesystem::remove(tmp2); + return; + } + string::size_type s = output.find("gpg: key ") + mir_strlen("gpg: key "); + string::size_type s2 = output.find(":", s); + { + char *tmp3 = (char*)mir_alloc((output.substr(s, s2 - s).length() + 1) * sizeof(char)); + mir_strcpy(tmp3, output.substr(s, s2 - s).c_str()); + mir_utf8decode(tmp3, nullptr); + { + if (db_mc_isMeta(hContact)) { + if (allsubcontacts) { + int count = db_mc_getSubCount(hContact); + for (int i = 0; i < count; i++) { + MCONTACT hcnt = db_mc_getSub(hContact, i); + if (hcnt) + db_set_s(hcnt, szGPGModuleName, "KeyID", tmp3); + } + } + else + db_set_s(metaGetMostOnline(hContact), szGPGModuleName, "KeyID", tmp3); + } + else + db_set_s(hContact, szGPGModuleName, "KeyID", tmp3); + } + mir_free(tmp3); + } + tmp = mir_wstrdup(toUTF16(output.substr(s, s2 - s)).c_str()); + if (hContact && hwndList_p) + ListView_SetItemText(hwndList_p, item_num, 1, tmp); + mir_free(tmp); + s = output.find("“", s2); + if (s == string::npos) { + s = output.find("\"", s2); + s += 1; + } + else + s += 3; + bool uncommon = false; + if ((s2 = output.find("(", s)) == string::npos) { + if ((s2 = output.find("<", s)) == string::npos) { + s2 = output.find("”", s); + uncommon = true; + } + } + else if (s2 > output.find("<", s)) + s2 = output.find("<", s); + if (s2 != string::npos && s != string::npos) { + { + char *tmp3 = (char*)mir_alloc(sizeof(char)*(output.substr(s, s2 - s - (uncommon ? 1 : 0)).length() + 1)); + mir_strcpy(tmp3, output.substr(s, s2 - s - (uncommon ? 1 : 0)).c_str()); + mir_utf8decode(tmp3, nullptr); + if (hContact) { + if (db_mc_isMeta(hContact)) { + if (allsubcontacts) { + int count = db_mc_getSubCount(hContact); + for (int i = 0; i < count; i++) { + MCONTACT hcnt = db_mc_getSub(hContact, i); + if (hcnt) + db_set_s(hcnt, szGPGModuleName, "KeyMainName", output.substr(s, s2 - s - 1).c_str()); + } + } + else db_set_s(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainName", output.substr(s, s2 - s - 1).c_str()); + } + else db_set_s(hContact, szGPGModuleName, "KeyMainName", output.substr(s, s2 - s - 1).c_str()); + } + mir_free(tmp3); + } + tmp = mir_wstrdup(toUTF16(output.substr(s, s2 - s - 1)).c_str()); + if (hContact && hwndList_p) + ListView_SetItemText(hwndList_p, item_num, 2, tmp); //TODO: do something with this + mir_free(tmp); + if ((s = output.find(")", s2)) == string::npos) + s = output.find(">", s2); + else if (s > output.find(">", s2)) + s = output.find(">", s2); + s2++; + if (s != string::npos && s2 != string::npos) { + if (output[s] == ')') { + char *tmp3 = (char*)mir_alloc((output.substr(s2, s - s2).length() + 1) * sizeof(char)); + mir_strcpy(tmp3, output.substr(s2, s - s2).c_str()); + mir_utf8decode(tmp3, nullptr); + if (hContact) { + if (db_mc_isMeta(hContact)) { + if (allsubcontacts) { + int count = db_mc_getSubCount(hContact); + for (int i = 0; i < count; i++) { + MCONTACT hcnt = db_mc_getSub(hContact, i); + if (hcnt) + db_set_s(hcnt, szGPGModuleName, "KeyComment", output.substr(s2, s - s2).c_str()); + } + } + else db_set_s(metaGetMostOnline(hContact), szGPGModuleName, "KeyComment", output.substr(s2, s - s2).c_str()); + } + else db_set_s(hContact, szGPGModuleName, "KeyComment", output.substr(s2, s - s2).c_str()); + } + mir_free(tmp3); + s += 3; + s2 = output.find(">", s); + tmp3 = (char*)mir_alloc((output.substr(s, s2 - s).length() + 1) * sizeof(char)); + mir_strcpy(tmp3, output.substr(s, s2 - s).c_str()); + mir_utf8decode(tmp3, nullptr); + if (hContact) { + if (db_mc_isMeta(hContact)) { + if (allsubcontacts) { + int count = db_mc_getSubCount(hContact); + for (int i = 0; i < count; i++) { + MCONTACT hcnt = db_mc_getSub(hContact, i); + if (hcnt) + db_set_s(hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s, s2 - s).c_str()); + } + } + else db_set_s(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s, s2 - s).c_str()); + } + else db_set_s(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s, s2 - s).c_str()); + } + mir_free(tmp3); + tmp = mir_wstrdup(toUTF16(output.substr(s, s2 - s)).c_str()); + if (hContact && hwndList_p) + ListView_SetItemText(hwndList_p, item_num, 3, tmp); + mir_free(tmp); + } + else { + char *tmp3 = (char*)mir_alloc(output.substr(s2, s - s2).length() + 1); + mir_strcpy(tmp3, output.substr(s2, s - s2).c_str()); + mir_utf8decode(tmp3, nullptr); + if (hContact) { + if (db_mc_isMeta(hContact)) { + if (allsubcontacts) { + int count = db_mc_getSubCount(hContact); + for (int i = 0; i < count; i++) { + MCONTACT hcnt = db_mc_getSub(hContact, i); + if (hcnt) + db_set_s(hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s2, s - s2).c_str()); + } + } + else db_set_s(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s2, s - s2).c_str()); + } + else db_set_s(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2, s - s2).c_str()); + } + mir_free(tmp3); + tmp = mir_wstrdup(toUTF16(output.substr(s2, s - s2)).c_str()); + if (hContact && hwndList_p) + ListView_SetItemText(hwndList_p, item_num, 3, tmp); //TODO: do something with this + mir_free(tmp); + } + } + } + if (hContact && hwndList_p) //TODO: do something with this + { + ListView_SetColumnWidth(hwndList_p, 0, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList_p, 1, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList_p, 2, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList_p, 3, LVSCW_AUTOSIZE); + } + } + if (!hContact) { + wchar_t *fp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", L""); + { + string out; + DWORD code; + std::vector<wstring> cmds; + cmds.push_back(L"--batch"); + cmds.push_back(L"-a"); + cmds.push_back(L"--export"); + cmds.push_back(fp); + mir_free(fp); + gpg_execution_params params2(cmds); + pxResult result2; + params2.out = &out; + params2.code = &code; + params2.result = &result2; + if (!gpg_launcher(params2)) + return; + if (result2 == pxNotFound) + return; + string::size_type s = 0; + while ((s = out.find("\r", s)) != string::npos) { + out.erase(s, 1); + } + db_set_s(hContact, szGPGModuleName, "GPGPubKey", out.c_str()); + } + } + tmp = mir_wstrdup(toUTF16(output).c_str()); + MessageBox(nullptr, tmp, L"", MB_OK); + mir_free(tmp); + boost::filesystem::remove(tmp2); + } + key_buf.clear(); + if (chk_ENABLE_ENCRYPTION.GetState()) { + if (hContact) { + if (db_mc_isMeta(hContact)) { + if (allsubcontacts) { + int count = db_mc_getSubCount(hContact); + for (int i = 0; i < count; i++) { + MCONTACT hcnt = db_mc_getSub(hContact, i); + if (hcnt) { + if (!isContactSecured(hcnt)) + db_set_b(hcnt, szGPGModuleName, "GPGEncryption", 1); + else + db_set_b(hcnt, szGPGModuleName, "GPGEncryption", 0); + setSrmmIcon(hContact); + setClistIcon(hContact); + } + } + } + else if (!isContactSecured(hContact)) + db_set_b(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 1); + else + db_set_b(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0); + } + else if (!isContactSecured(hContact)) + db_set_b(hContact, szGPGModuleName, "GPGEncryption", 1); + else + db_set_b(hContact, szGPGModuleName, "GPGEncryption", 0); + } + } + DestroyWindow(m_hwnd); + } + + void onClick_LOAD_FROM_FILE(CCtrlButton*) + { + wchar_t *tmp = GetFilePath(TranslateT("Set file containing GPG public key"), L"*", TranslateT("GPG public key file")); + if (!tmp) + return; + + wfstream f(tmp, std::ios::in | std::ios::ate | std::ios::binary); + delete[] tmp; + if (!f.is_open()) { + MessageBox(nullptr, TranslateT("Failed to open file"), TranslateT("Error"), MB_OK); + return; + } + if (f.is_open()) { + std::wifstream::pos_type size = f.tellg(); + wchar_t *temp = new wchar_t[(std::ifstream::pos_type)size + (std::ifstream::pos_type)1]; + f.seekg(0, std::ios::beg); + f.read(temp, size); + temp[size] = '\0'; + key_buf.append(temp); + delete[] temp; + f.close(); + } + if (key_buf.empty()) { + key_buf.clear(); + if (bDebugLog) + debuglog << std::string(time_str() + ": info: Failed to read key file"); + return; + } + ws2 = key_buf.find(L"-----END PGP PUBLIC KEY BLOCK-----"); + ws1 = key_buf.find(L"-----BEGIN PGP PUBLIC KEY BLOCK-----"); + if (ws2 == wstring::npos || ws1 == wstring::npos) { + ws2 = key_buf.find(L"-----END PGP PRIVATE KEY BLOCK-----"); + ws1 = key_buf.find(L"-----BEGIN PGP PRIVATE KEY BLOCK-----"); + } + if (ws2 == wstring::npos || ws1 == wstring::npos) { + MessageBox(nullptr, TranslateT("There is no public or private key."), TranslateT("Info"), MB_OK); + return; + } + ws2 += mir_wstrlen(L"-----END PGP PUBLIC KEY BLOCK-----"); + edit_PUBLIC_KEY_EDIT.SetText(key_buf.substr(ws1, ws2 - ws1).c_str()); + key_buf.clear(); + } + void onClick_IMPORT(CCtrlButton*) + { + new_key_hcnt_mutex.lock(); + new_key_hcnt = hContact; + void ShowImportKeyDialog(); + ShowImportKeyDialog(); + } +}; + + +void ShowLoadPublicKeyDialog(bool modal) +{ + CDlgLoadPubKeyDlg *d = new CDlgLoadPubKeyDlg(); + if (modal) + d->DoModal(); + d->Show(); +} + +int GpgOptInit(WPARAM wParam, LPARAM) +{ + OPTIONSDIALOGPAGE odp = {}; + odp.szGroup.w = LPGENW("Services"); + odp.szTitle.w = _T(szGPGModuleName); + + odp.szTab.w = LPGENW("Main"); + odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE; + odp.pDialog = new COptGpgMainDlg(); + Options_AddPage(wParam, &odp); + + odp.szTab.w = LPGENW("GnuPG Variables"); + odp.pDialog = new COptGpgBinDlg(); + Options_AddPage(wParam, &odp); + + odp.szTab.w = LPGENW("Messages"); + odp.pDialog = new COptGpgMsgDlg(); + Options_AddPage(wParam, &odp); + + odp.szTab.w = LPGENW("Advanced"); + odp.pDialog = new COptGpgAdvDlg(); + Options_AddPage(wParam, &odp); + return 0; +} diff --git a/plugins/New_GPG/src/resource.h b/plugins/New_GPG/src/resource.h index cd607fb27a..b57e346c05 100644 --- a/plugins/New_GPG/src/resource.h +++ b/plugins/New_GPG/src/resource.h @@ -1,116 +1,116 @@ -//{{NO_DEPENDENCIES}}
-// Microsoft Visual C++ generated include file.
-// Used by new_gpg.rc
-//
-#define IDD_LOAD_PUBLIC_KEY 102
-#define IDD_FIRST_RUN 103
-#define IDD_OPT_GPG 104
-#define IDD_OPT_GPG_BIN 105
-#define IDD_BIN_PATH 106
-#define IDD_OPT_GPG_MESSAGES 107
-#define IDD_NEW_KEY 108
-#define IDD_KEY_GEN 109
-#define IDD_LOAD_EXISTING_KEY 110
-#define IDD_KEY_PASSWD 111
-#define IDI_SECURED 112
-#define IDD_IMPORT_KEY 112
-#define IDI_UNSECURED 113
-#define IDD_OPT_GPG_ADVANCED 113
-#define IDD_ENCRYPTED_FILE_MSG_BOX 114
-#define IDD_EXPORT_TYPE 115
-#define IDD_CHANGE_PASSWD 116
-#define IDC_SET_BIN_PATH 1016
-#define IDC_SET_HOME_DIR 1017
-#define IDC_BIN_PATH 1018
-#define IDC_HOME_DIR 1019
-#define IDC_USERLIST 1020
-#define IDC_LOAD_KEY_BUTTON 1022
-#define ID_OK 1023
-#define ID_LOD_FROM_FILE 1024
-#define ID_LOAD_FROM_FILE 1024
-#define IDC_EDIT1 1025
-#define IDC_PUBLIC_KEY_EDIT 1025
-#define IDC_KEY_PASSWORD 1025
-#define IDC_IN_OPEN_TAG 1025
-#define IDC_KEY_PASSWD 1025
-#define IDC_PASSWORD 1025
-#define IDC_LOG_FILE_EDIT 1025
-#define IDC_BUTTON1 1026
-#define IDC_SAVE_KEY_BUTTON 1026
-#define IDC_GENERATE_KEY 1026
-#define IDC_IGNORE_KEY 1026
-#define IDC_SELECT_EXISTING 1026
-#define IDC_KEY_EMAIL 1026
-#define IDC_IGNORE 1026
-#define IDC_OK 1026
-#define IDC_EXPORT 1026
-#define IDC_DELETE_KEY_BUTTON 1027
-#define IDC_IN_CLOSE_TAG 1027
-#define IDC_KEY_REAL_NAME 1027
-#define IDC_KEY_LIST 1028
-#define IDC_KEY_COMMENT 1028
-#define IDC_OUT_OPEN_TAG 1029
-#define IDC_APPEND_TAGS 1030
-#define IDC_OUT_CLOSE_TAG 1031
-#define IDC_SELECT_KEY 1033
-#define IDC_MESSAGE 1034
-#define ID_IMPORT 1035
-#define IDC_IMPORT_AND_USE 1036
-#define IDC_KEY_TYPE 1039
-#define IDC_KEY_LENGTH 1040
-#define IDC_KEY_EXPIRE_DATE 1043
-#define IDC_EXISTING_KEY_LIST 1045
-#define IDC_BUTTON2 1046
-#define IDC_OTHER 1046
-#define IDC_LOG_FILE_SET 1046
-#define IDC_IMPORT 1046
-#define IDC_DECRYPT 1046
-#define IDC_CANCEL 1046
-#define IDC_SAVE_PASSWORD 1047
-#define IDC_DEBUG_LOG 1048
-#define IDC_JABBER_API 1049
-#define IDC_ENABLE_ENCRYPTION 1050
-#define IDC_KEY_FROM 1051
-#define IDC_DELETE_KEY 1052
-#define IDC_KEYID 1053
-#define IDC_CURRENT_KEY 1054
-#define IDC_DEFAULT_PASSWORD 1055
-#define IDC_KEYSERVER 1058
-#define IDC_FILE_TRANSFERS 1061
-#define IDC_REMOVE_FILTERS 1062
-#define IDC_GENERATE_RANDOM 1063
-#define IDC_AUTO_EXCHANGE 1064
-#define IDC_AUT_EXCHANGE 1065
-#define IDC_BUTTON3 1066
-#define IDC_COPY_KEY 1066
-#define IDC_COPY_PUBKEY 1066
-#define IDC_STRIP_TAGS 1067
-#define IDC_CHECK1 1068
-#define IDC_PRESCENSE_SUBSCRIPTION 1068
-#define IDC_REMEMBRE 1068
-#define IDC_REMEMBER 1068
-#define IDC_GENERATING_KEY 1069
-#define IDC_GENERATING_TEXT 1070
-#define IDC_KEY_ID 1071
-#define IDC_COMBO1 1072
-#define IDC_ACCOUNT 1072
-#define IDC_PUBLIC 1073
-#define IDC_PRIVATE 1074
-#define IDC_ALL 1075
-#define IDC_EXPORT_PRIVATE 1076
-#define IDC_CHANGE_PASSWD 1077
-#define IDC_OLD_PASSWD 1078
-#define IDC_NEW_PASSWD1 1079
-#define IDC_NEW_PASSWD2 1080
-
-
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 117
-#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1081
-#define _APS_NEXT_SYMED_VALUE 101
-#endif
-#endif
+//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by new_gpg.rc +// +#define IDD_LOAD_PUBLIC_KEY 102 +#define IDD_FIRST_RUN 103 +#define IDD_OPT_GPG 104 +#define IDD_OPT_GPG_BIN 105 +#define IDD_BIN_PATH 106 +#define IDD_OPT_GPG_MESSAGES 107 +#define IDD_NEW_KEY 108 +#define IDD_KEY_GEN 109 +#define IDD_LOAD_EXISTING_KEY 110 +#define IDD_KEY_PASSWD 111 +#define IDI_SECURED 112 +#define IDD_IMPORT_KEY 112 +#define IDI_UNSECURED 113 +#define IDD_OPT_GPG_ADVANCED 113 +#define IDD_ENCRYPTED_FILE_MSG_BOX 114 +#define IDD_EXPORT_TYPE 115 +#define IDD_CHANGE_PASSWD 116 +#define IDC_SET_BIN_PATH 1016 +#define IDC_SET_HOME_DIR 1017 +#define IDC_BIN_PATH 1018 +#define IDC_HOME_DIR 1019 +#define IDC_USERLIST 1020 +#define IDC_LOAD_KEY_BUTTON 1022 +#define ID_OK 1023 +#define ID_LOD_FROM_FILE 1024 +#define ID_LOAD_FROM_FILE 1024 +#define IDC_EDIT1 1025 +#define IDC_PUBLIC_KEY_EDIT 1025 +#define IDC_KEY_PASSWORD 1025 +#define IDC_IN_OPEN_TAG 1025 +#define IDC_KEY_PASSWD 1025 +#define IDC_PASSWORD 1025 +#define IDC_LOG_FILE_EDIT 1025 +#define IDC_BUTTON1 1026 +#define IDC_SAVE_KEY_BUTTON 1026 +#define IDC_GENERATE_KEY 1026 +#define IDC_IGNORE_KEY 1026 +#define IDC_SELECT_EXISTING 1026 +#define IDC_KEY_EMAIL 1026 +#define IDC_IGNORE 1026 +#define IDC_OK 1026 +#define IDC_EXPORT 1026 +#define IDC_DELETE_KEY_BUTTON 1027 +#define IDC_IN_CLOSE_TAG 1027 +#define IDC_KEY_REAL_NAME 1027 +#define IDC_KEY_LIST 1028 +#define IDC_KEY_COMMENT 1028 +#define IDC_OUT_OPEN_TAG 1029 +#define IDC_APPEND_TAGS 1030 +#define IDC_OUT_CLOSE_TAG 1031 +#define IDC_SELECT_KEY 1033 +#define IDC_MESSAGE 1034 +#define ID_IMPORT 1035 +#define IDC_IMPORT_AND_USE 1036 +#define IDC_KEY_TYPE 1039 +#define IDC_KEY_LENGTH 1040 +#define IDC_KEY_EXPIRE_DATE 1043 +#define IDC_EXISTING_KEY_LIST 1045 +#define IDC_BUTTON2 1046 +#define IDC_OTHER 1046 +#define IDC_LOG_FILE_SET 1046 +#define IDC_IMPORT 1046 +#define IDC_DECRYPT 1046 +#define IDC_CANCEL 1046 +#define IDC_SAVE_PASSWORD 1047 +#define IDC_DEBUG_LOG 1048 +#define IDC_JABBER_API 1049 +#define IDC_ENABLE_ENCRYPTION 1050 +#define IDC_KEY_FROM 1051 +#define IDC_DELETE_KEY 1052 +#define IDC_KEYID 1053 +#define IDC_CURRENT_KEY 1054 +#define IDC_DEFAULT_PASSWORD 1055 +#define IDC_KEYSERVER 1058 +#define IDC_FILE_TRANSFERS 1061 +#define IDC_REMOVE_FILTERS 1062 +#define IDC_GENERATE_RANDOM 1063 +#define IDC_AUTO_EXCHANGE 1064 +#define IDC_AUT_EXCHANGE 1065 +#define IDC_BUTTON3 1066 +#define IDC_COPY_KEY 1066 +#define IDC_COPY_PUBKEY 1066 +#define IDC_STRIP_TAGS 1067 +#define IDC_CHECK1 1068 +#define IDC_PRESCENSE_SUBSCRIPTION 1068 +#define IDC_REMEMBRE 1068 +#define IDC_REMEMBER 1068 +#define IDC_GENERATING_KEY 1069 +#define IDC_GENERATING_TEXT 1070 +#define IDC_KEY_ID 1071 +#define IDC_COMBO1 1072 +#define IDC_ACCOUNT 1072 +#define IDC_PUBLIC 1073 +#define IDC_PRIVATE 1074 +#define IDC_ALL 1075 +#define IDC_EXPORT_PRIVATE 1076 +#define IDC_CHANGE_PASSWD 1077 +#define IDC_OLD_PASSWD 1078 +#define IDC_NEW_PASSWD1 1079 +#define IDC_NEW_PASSWD2 1080 + + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 117 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1081 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/plugins/New_GPG/src/srmm.cpp b/plugins/New_GPG/src/srmm.cpp index 4365ca076c..edcd6ae51e 100755 --- a/plugins/New_GPG/src/srmm.cpp +++ b/plugins/New_GPG/src/srmm.cpp @@ -1,82 +1,82 @@ -// Copyright © 2010-2012 SecureIM developers (baloo and others), sss
-//
-// 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"
-
-void ShowStatusIcon(MCONTACT hContact);
-void setSrmmIcon(MCONTACT hContact);
-
-int __cdecl onWindowEvent(WPARAM, LPARAM lParam)
-{
- MessageWindowEventData *mwd = (MessageWindowEventData *)lParam;
- if(mwd->uType == MSG_WINDOW_EVT_OPEN || mwd->uType == MSG_WINDOW_EVT_OPENING)
- setSrmmIcon(mwd->hContact);
- return 0;
-}
-
-
-int __cdecl onIconPressed(WPARAM wParam, LPARAM lParam)
-{
- MCONTACT hContact = wParam;
- MCONTACT hMeta = NULL;
- if(db_mc_isMeta(hContact))
- {
- hMeta = hContact;
- hContact = metaGetMostOnline(hContact); // возьмем тот, через который пойдет сообщение
- }
- else if(db_mc_isSub(hContact))
- hMeta = db_mc_getMeta(hContact);
- StatusIconClickData *sicd = (StatusIconClickData *)lParam;
- if(mir_strcmp(sicd->szModule, szGPGModuleName))
- return 0; // not our event
-
- BYTE enc = db_get_b(hContact, szGPGModuleName, "GPGEncryption", 0);
- if(enc)
- {
- db_set_b(hContact, szGPGModuleName, "GPGEncryption", 0);
- hMeta?db_set_b(hMeta, szGPGModuleName, "GPGEncryption", 0):0;
- setSrmmIcon(hContact);
- setClistIcon(hContact);
- }
- else if(!enc)
- {
- if(!isContactHaveKey(hContact))
- {
- void ShowLoadPublicKeyDialog(bool = false);
- item_num = 0; //black magic here
- user_data[1] = hContact;
- ShowLoadPublicKeyDialog();
- }
- else
- {
- db_set_b(hContact, szGPGModuleName, "GPGEncryption", 1);
- hMeta?db_set_b(hMeta, szGPGModuleName, "GPGEncryption", 1):0;
- setSrmmIcon(hContact);
- setClistIcon(hContact);
- return 0;
- }
- if(isContactHaveKey(hContact))
- {
- db_set_b(hContact, szGPGModuleName, "GPGEncryption", 1);
- hMeta?db_set_b(hMeta, szGPGModuleName, "GPGEncryption", 1):0;
- setSrmmIcon(hContact);
- setClistIcon(hContact);
- }
- }
- return 0;
-}
+// Copyright © 2010-2012 SecureIM developers (baloo and others), sss +// +// 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" + +void ShowStatusIcon(MCONTACT hContact); +void setSrmmIcon(MCONTACT hContact); + +int __cdecl onWindowEvent(WPARAM, LPARAM lParam) +{ + MessageWindowEventData *mwd = (MessageWindowEventData *)lParam; + if(mwd->uType == MSG_WINDOW_EVT_OPEN || mwd->uType == MSG_WINDOW_EVT_OPENING) + setSrmmIcon(mwd->hContact); + return 0; +} + + +int __cdecl onIconPressed(WPARAM wParam, LPARAM lParam) +{ + MCONTACT hContact = wParam; + MCONTACT hMeta = NULL; + if(db_mc_isMeta(hContact)) + { + hMeta = hContact; + hContact = metaGetMostOnline(hContact); // возьмем тот, через который пойдет сообщение + } + else if(db_mc_isSub(hContact)) + hMeta = db_mc_getMeta(hContact); + StatusIconClickData *sicd = (StatusIconClickData *)lParam; + if(mir_strcmp(sicd->szModule, szGPGModuleName)) + return 0; // not our event + + BYTE enc = db_get_b(hContact, szGPGModuleName, "GPGEncryption", 0); + if(enc) + { + db_set_b(hContact, szGPGModuleName, "GPGEncryption", 0); + hMeta?db_set_b(hMeta, szGPGModuleName, "GPGEncryption", 0):0; + setSrmmIcon(hContact); + setClistIcon(hContact); + } + else if(!enc) + { + if(!isContactHaveKey(hContact)) + { + void ShowLoadPublicKeyDialog(bool = false); + item_num = 0; //black magic here + user_data[1] = hContact; + ShowLoadPublicKeyDialog(); + } + else + { + db_set_b(hContact, szGPGModuleName, "GPGEncryption", 1); + hMeta?db_set_b(hMeta, szGPGModuleName, "GPGEncryption", 1):0; + setSrmmIcon(hContact); + setClistIcon(hContact); + return 0; + } + if(isContactHaveKey(hContact)) + { + db_set_b(hContact, szGPGModuleName, "GPGEncryption", 1); + hMeta?db_set_b(hMeta, szGPGModuleName, "GPGEncryption", 1):0; + setSrmmIcon(hContact); + setClistIcon(hContact); + } + } + return 0; +} diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp index 3372f79e20..291ba4ec3c 100755 --- a/plugins/New_GPG/src/utilities.cpp +++ b/plugins/New_GPG/src/utilities.cpp @@ -1810,13 +1810,13 @@ public: { file_msg_state = -1; } - virtual void OnClose() override
- {
- DestroyWindow(m_hwnd);
- }
- virtual void OnDestroy() override
- {
- delete this;
+ virtual void OnClose() override + { + DestroyWindow(m_hwnd); + } + virtual void OnDestroy() override + { + delete this; } void onClick_IGNORE(CCtrlButton*) { @@ -1867,13 +1867,13 @@ public: { chk_PUBLIC.SetState(1); } - virtual void OnClose() override
- {
- DestroyWindow(m_hwnd);
- }
- virtual void OnDestroy() override
- {
- delete this;
+ virtual void OnClose() override + { + DestroyWindow(m_hwnd); + } + virtual void OnDestroy() override + { + delete this; } void onClick_OK(CCtrlButton*) { @@ -1911,13 +1911,13 @@ public: { btn_OK.OnClick = Callback(this, &CDlgChangePasswdMsgBox::onClick_OK); } - virtual void OnClose() override
- {
- DestroyWindow(m_hwnd);
- }
- virtual void OnDestroy() override
- {
- delete this;
+ virtual void OnClose() override + { + DestroyWindow(m_hwnd); + } + virtual void OnDestroy() override + { + delete this; } void onClick_OK(CCtrlButton*) { diff --git a/plugins/New_GPG/src/utilities.h b/plugins/New_GPG/src/utilities.h index a27f6215c4..753342d86d 100644 --- a/plugins/New_GPG/src/utilities.h +++ b/plugins/New_GPG/src/utilities.h @@ -1,111 +1,111 @@ -// Copyright © 2010-2012 sss
-//
-// 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.
-
-#ifndef UTILITIES_H
-#define UTILITIES_H
-wchar_t* __stdcall UniGetContactSettingUtf(MCONTACT hContact, const char *szModule,const char* szSetting, wchar_t* szDef);
-char* __stdcall UniGetContactSettingUtf(MCONTACT hContact, const char *szModule,const char* szSetting, char* szDef);
-void GetFilePath(wchar_t *WindowTittle, char *szSetting, wchar_t *szExt, wchar_t *szExtDesc);
-wchar_t *GetFilePath(wchar_t *WindowTittle, wchar_t *szExt, wchar_t *szExtDesc, bool save_file = false);
-void GetFolderPath(wchar_t *WindowTittle, char *szSetting);
-
-void storeOutput(HANDLE ahandle, string *output);
-
-void setSrmmIcon(MCONTACT);
-void setClistIcon(MCONTACT);
-
-void send_encrypted_msgs_thread(void*);
-
-int ComboBoxAddStringUtf(HWND hCombo, const wchar_t *szString, DWORD data);
-bool isContactSecured(MCONTACT hContact);
-bool isContactHaveKey(MCONTACT hContact);
-bool isTabsrmmUsed();
-bool isGPGKeyExist();
-bool isGPGValid();
-const bool StriStr(const char *str, const char *substr);
-string toUTF8(wstring str);
-wstring toUTF16(string str);
-string get_random(int length);
-string time_str();
-
-struct db_event : public DBEVENTINFO
-{
-public:
- db_event(char* msg)
- {
- eventType = EVENTTYPE_MESSAGE;
- flags = 0;
- timestamp = time(0);
- szModule = 0;
- cbBlob = DWORD(mir_strlen(msg)+1);
- pBlob = (PBYTE)msg;
- }
- db_event(char* msg, DWORD time)
- {
- cbBlob = DWORD(mir_strlen(msg)+1);
- pBlob = (PBYTE)msg;
- eventType = EVENTTYPE_MESSAGE;
- flags = 0;
- timestamp = time;
- szModule = 0;
- }
- db_event(char* msg, DWORD time, int type)
- {
- cbBlob = DWORD(mir_strlen(msg)+1);
- pBlob = (PBYTE)msg;
- if(type)
- eventType = type;
- else
- eventType = EVENTTYPE_MESSAGE;
- flags = 0;
- timestamp = time;
- szModule = 0;
- }
- db_event(char* msg, int type)
- {
- cbBlob = DWORD(mir_strlen(msg)+1);
- pBlob = (PBYTE)msg;
- flags = 0;
- if(type)
- eventType = type;
- else
- eventType = EVENTTYPE_MESSAGE;
- timestamp = time(0);
- szModule = 0;
- }
- db_event(char* msg, DWORD time, int type, DWORD _flags)
- {
- cbBlob = DWORD(mir_strlen(msg)+1);
- pBlob = (PBYTE)msg;
- if(type)
- eventType = type;
- else
- eventType = EVENTTYPE_MESSAGE;
- flags = _flags;
- timestamp = time;
- szModule = 0;
- }
-};
-
-void HistoryLog(MCONTACT, db_event);
-void fix_line_term(std::string &s);
-void fix_line_term(std::wstring &s);
-void strip_line_term(std::wstring &s);
-void strip_line_term(std::string &s);
-void strip_tags(std::wstring &s);
-void clean_temp_dir();
-
-#endif
+// Copyright © 2010-2012 sss +// +// 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. + +#ifndef UTILITIES_H +#define UTILITIES_H +wchar_t* __stdcall UniGetContactSettingUtf(MCONTACT hContact, const char *szModule,const char* szSetting, wchar_t* szDef); +char* __stdcall UniGetContactSettingUtf(MCONTACT hContact, const char *szModule,const char* szSetting, char* szDef); +void GetFilePath(wchar_t *WindowTittle, char *szSetting, wchar_t *szExt, wchar_t *szExtDesc); +wchar_t *GetFilePath(wchar_t *WindowTittle, wchar_t *szExt, wchar_t *szExtDesc, bool save_file = false); +void GetFolderPath(wchar_t *WindowTittle, char *szSetting); + +void storeOutput(HANDLE ahandle, string *output); + +void setSrmmIcon(MCONTACT); +void setClistIcon(MCONTACT); + +void send_encrypted_msgs_thread(void*); + +int ComboBoxAddStringUtf(HWND hCombo, const wchar_t *szString, DWORD data); +bool isContactSecured(MCONTACT hContact); +bool isContactHaveKey(MCONTACT hContact); +bool isTabsrmmUsed(); +bool isGPGKeyExist(); +bool isGPGValid(); +const bool StriStr(const char *str, const char *substr); +string toUTF8(wstring str); +wstring toUTF16(string str); +string get_random(int length); +string time_str(); + +struct db_event : public DBEVENTINFO +{ +public: + db_event(char* msg) + { + eventType = EVENTTYPE_MESSAGE; + flags = 0; + timestamp = time(0); + szModule = 0; + cbBlob = DWORD(mir_strlen(msg)+1); + pBlob = (PBYTE)msg; + } + db_event(char* msg, DWORD time) + { + cbBlob = DWORD(mir_strlen(msg)+1); + pBlob = (PBYTE)msg; + eventType = EVENTTYPE_MESSAGE; + flags = 0; + timestamp = time; + szModule = 0; + } + db_event(char* msg, DWORD time, int type) + { + cbBlob = DWORD(mir_strlen(msg)+1); + pBlob = (PBYTE)msg; + if(type) + eventType = type; + else + eventType = EVENTTYPE_MESSAGE; + flags = 0; + timestamp = time; + szModule = 0; + } + db_event(char* msg, int type) + { + cbBlob = DWORD(mir_strlen(msg)+1); + pBlob = (PBYTE)msg; + flags = 0; + if(type) + eventType = type; + else + eventType = EVENTTYPE_MESSAGE; + timestamp = time(0); + szModule = 0; + } + db_event(char* msg, DWORD time, int type, DWORD _flags) + { + cbBlob = DWORD(mir_strlen(msg)+1); + pBlob = (PBYTE)msg; + if(type) + eventType = type; + else + eventType = EVENTTYPE_MESSAGE; + flags = _flags; + timestamp = time; + szModule = 0; + } +}; + +void HistoryLog(MCONTACT, db_event); +void fix_line_term(std::string &s); +void fix_line_term(std::wstring &s); +void strip_line_term(std::wstring &s); +void strip_line_term(std::string &s); +void strip_tags(std::wstring &s); +void clean_temp_dir(); + +#endif |