From 4b918c8f61749cfc0cfc9a8abd0c3b06af042faf Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sun, 29 Jul 2012 00:59:39 +0300 Subject: following miranda ng plugin rules --- Makefile | 0 README | 2 +- clist.cpp | 41 - commonheaders.h | 88 -- constants.h | 5 - globals.h | 22 - gpg_wrapper.cpp | 163 ---- gpg_wrapper.h | 50 - icons.cpp | 152 --- icons/secured.ico | Bin 2550 -> 0 bytes icons/unsecured.ico | Bin 2550 -> 0 bytes init.cpp | 288 ------ jabber_account.cpp | 85 -- jabber_account.h | 43 - log.cpp | 91 -- log.h | 35 - m_extraicons.h | 158 --- m_metacontacts.h | 166 ---- main.cpp | 2293 -------------------------------------------- main.h | 31 - messages.cpp | 1043 -------------------- metacontacts.cpp | 88 -- metacontacts.h | 24 - new_gpg.icproj | 28 - new_gpg.rc | 419 -------- new_gpg.sln | 54 -- new_gpg.vcproj | 941 ------------------ new_gpg.vcxproj | 1352 -------------------------- new_gpg_10.sln | 20 + new_gpg_10.vcxproj | 842 ++++++++++++++++ new_gpg_10.vcxproj.filters | 103 ++ new_gpg_lang_ru.txt | 0 options.cpp | 1386 -------------------------- res/icons/secured.ico | Bin 0 -> 2550 bytes res/icons/unsecured.ico | Bin 0 -> 2550 bytes res/new_gpg.rc | 419 ++++++++ resource.h | 96 -- src/clist.cpp | 41 + src/commonheaders.h | 88 ++ src/constants.h | 5 + src/globals.h | 22 + src/gpg_wrapper.cpp | 163 ++++ src/gpg_wrapper.h | 50 + src/icons.cpp | 152 +++ src/init.cpp | 288 ++++++ src/jabber_account.cpp | 85 ++ src/jabber_account.h | 43 + src/log.cpp | 91 ++ src/log.h | 35 + src/m_extraicons.h | 158 +++ src/m_metacontacts.h | 166 ++++ src/main.cpp | 2293 ++++++++++++++++++++++++++++++++++++++++++++ src/main.h | 31 + src/messages.cpp | 1043 ++++++++++++++++++++ src/metacontacts.cpp | 88 ++ src/metacontacts.h | 24 + src/options.cpp | 1386 ++++++++++++++++++++++++++ src/resource.h | 96 ++ src/srmm.cpp | 88 ++ src/utilities.cpp | 1823 +++++++++++++++++++++++++++++++++++ src/utilities.h | 104 ++ srmm.cpp | 88 -- utilities.cpp | 1823 ----------------------------------- utilities.h | 104 -- 64 files changed, 9748 insertions(+), 11158 deletions(-) mode change 100644 => 100755 Makefile mode change 100644 => 100755 README delete mode 100755 clist.cpp delete mode 100755 commonheaders.h delete mode 100644 constants.h delete mode 100755 globals.h delete mode 100755 gpg_wrapper.cpp delete mode 100755 gpg_wrapper.h delete mode 100755 icons.cpp delete mode 100644 icons/secured.ico delete mode 100644 icons/unsecured.ico delete mode 100755 init.cpp delete mode 100755 jabber_account.cpp delete mode 100755 jabber_account.h delete mode 100755 log.cpp delete mode 100755 log.h delete mode 100644 m_extraicons.h delete mode 100644 m_metacontacts.h delete mode 100755 main.cpp delete mode 100755 main.h delete mode 100755 messages.cpp delete mode 100755 metacontacts.cpp delete mode 100755 metacontacts.h delete mode 100644 new_gpg.icproj delete mode 100755 new_gpg.rc delete mode 100755 new_gpg.sln delete mode 100644 new_gpg.vcproj delete mode 100755 new_gpg.vcxproj create mode 100755 new_gpg_10.sln create mode 100755 new_gpg_10.vcxproj create mode 100755 new_gpg_10.vcxproj.filters mode change 100644 => 100755 new_gpg_lang_ru.txt delete mode 100755 options.cpp create mode 100755 res/icons/secured.ico create mode 100755 res/icons/unsecured.ico create mode 100755 res/new_gpg.rc delete mode 100755 resource.h create mode 100755 src/clist.cpp create mode 100755 src/commonheaders.h create mode 100755 src/constants.h create mode 100755 src/globals.h create mode 100755 src/gpg_wrapper.cpp create mode 100755 src/gpg_wrapper.h create mode 100755 src/icons.cpp create mode 100755 src/init.cpp create mode 100755 src/jabber_account.cpp create mode 100755 src/jabber_account.h create mode 100755 src/log.cpp create mode 100755 src/log.h create mode 100755 src/m_extraicons.h create mode 100755 src/m_metacontacts.h create mode 100755 src/main.cpp create mode 100755 src/main.h create mode 100755 src/messages.cpp create mode 100755 src/metacontacts.cpp create mode 100755 src/metacontacts.h create mode 100755 src/options.cpp create mode 100755 src/resource.h create mode 100755 src/srmm.cpp create mode 100755 src/utilities.cpp create mode 100755 src/utilities.h delete mode 100755 srmm.cpp delete mode 100755 utilities.cpp delete mode 100755 utilities.h diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 diff --git a/README b/README old mode 100644 new mode 100755 index 7c47ae7..be5551c --- a/README +++ b/README @@ -3,4 +3,4 @@ 2. utf8cpp (http://utfcpp.sourceforge.net/) 3. c++ compiller (because of miranda have compiled with MSVC, only msvc compiled builds working fine (i have no success with mingw, please report your result :) )) * Runtime Dependencies - 1. MIranda IM at least 0.8 (0.9 recommended for extended jabber integration) + 1. MIranda NG diff --git a/clist.cpp b/clist.cpp deleted file mode 100755 index c64fb17..0000000 --- a/clist.cpp +++ /dev/null @@ -1,41 +0,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 "commonheaders.h" - -extern HANDLE g_hCLIcon; -void RefreshContactListIcons(void); - -int onExtraImageListRebuilding(WPARAM, LPARAM) -{ - if(g_hCLIcon && ServiceExists(MS_CLIST_EXTRA_ADD_ICON) ) - RefreshContactListIcons(); - return 0; -} - - -int onExtraImageApplying(WPARAM wParam, LPARAM) -{ - void setClistIcon(HANDLE); - if(g_hCLIcon && ServiceExists(MS_CLIST_EXTRA_SET_ICON)) - { -// IconExtraColumn iec = {0}; //need to init this - if( g_hCLIcon ) - setClistIcon((HANDLE)wParam); -// ExtraIcon_SetIcon(g_hCLIcon, (HANDLE)wParam, iec.hImage); - } - return 0; -} diff --git a/commonheaders.h b/commonheaders.h deleted file mode 100755 index 459d76e..0000000 --- a/commonheaders.h +++ /dev/null @@ -1,88 +0,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. -#ifndef COMMONHEADERS_H -#define COMMONHEADERS_H -#define MIRANDA_VER 0x0901 -//windows -#include -#include -#include -#include -#include -#include -//c -#include -#include -#include -//c++ -#include -#include -using std::map; -#include -using std::list; -#include -using std::vector; -#include -using std::string; -using std::wstring; -#include -using std::wfstream; -using std::fstream; - -//boost -#include -#include -#include -#include -#include -#include - - -//utf8cpp -#include - -//miranda -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "m_extraicons.h" -#include "m_metacontacts.h" -#include "resource.h" - - -//internal -#include "constants.h" -#include "log.h" -#include "globals.h" -#include "utilities.h" -#include "main.h" -#include "gpg_wrapper.h" -#include "jabber_account.h" -#include "metacontacts.h" -#endif diff --git a/constants.h b/constants.h deleted file mode 100644 index 2982f31..0000000 --- a/constants.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef CONSTANTS_H -#define CONSTANTS_H -#define szGPGModuleName "GPG" -#define PREF_METANODB 0x2000 -#endif diff --git a/globals.h b/globals.h deleted file mode 100755 index e84ae1e..0000000 --- a/globals.h +++ /dev/null @@ -1,22 +0,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. - -#ifndef GLOBALS_H -#define GLOBALS_H -extern bool bAppendTags, bPresenceSigning, bStripTags, gpg_valid, gpg_keyexist, tabsrmm_used; -extern TCHAR *inopentag, *inclosetag, *outopentag, *outclosetag; -extern logtofile debuglog; -#endif diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp deleted file mode 100755 index 410a0d5..0000000 --- a/gpg_wrapper.cpp +++ /dev/null @@ -1,163 +0,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 "commonheaders.h" - -//thx gpg module from Harald Treder, Zakhar V. Bardymov - -//boost::mutex gpg_mutex; - - -pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result, HANDLE hProcess, PROCESS_INFORMATION *pr) -{ -// gpg_mutex.lock(); - if(!gpg_valid) - return pxNotConfigured; - extern logtofile debuglog; - BOOL success; - STARTUPINFO sinfo = {0}; - SECURITY_ATTRIBUTES sattrs = {0}; - SECURITY_DESCRIPTOR sdesc = {0}; - PROCESS_INFORMATION pri = {0}; - HANDLE newstdin, newstdout, readstdout, writestdin; - char *inputpos; - unsigned long transfered; - int size; - - wstring commandline; - - sattrs.nLength=sizeof(SECURITY_ATTRIBUTES); - sattrs.bInheritHandle=TRUE; - InitializeSecurityDescriptor(&sdesc,SECURITY_DESCRIPTOR_REVISION); - SetSecurityDescriptorDacl(&sdesc,TRUE,NULL,FALSE); - sattrs.lpSecurityDescriptor=&sdesc; - - success=CreatePipe(&newstdin,&writestdin,&sattrs,0); - if (!success) - { - *result = pxCreatePipeFailed; - return pxCreatePipeFailed; - } - - success=CreatePipe(&readstdout,&newstdout,&sattrs,0); - if (!success) - { - CloseHandle(newstdin); - CloseHandle(writestdin); - *result = pxCreatePipeFailed; - return pxCreatePipeFailed; - } - - GetStartupInfo(&sinfo); - sinfo.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; - sinfo.wShowWindow=SW_HIDE; - sinfo.hStdOutput=newstdout; - sinfo.hStdError=newstdout; - sinfo.hStdInput=newstdin; - - char *mir_path = new char [MAX_PATH]; - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); - SetCurrentDirectoryA(mir_path); - delete [] mir_path; - - TCHAR *bin_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("")); - { - if(_waccess(bin_path, 0) == -1) - { - if(errno == ENOENT) - { - mir_free(bin_path); - debuglog<c_str(); - - WaitForSingleObject(pri.hProcess,INFINITE); - - CloseHandle(pri.hThread); - CloseHandle(pri.hProcess); - CloseHandle(newstdin); - CloseHandle(newstdout); - CloseHandle(readstdout); - CloseHandle(writestdin); - - *result = pxSuccess; -// gpg_mutex.unlock(); - return pxSuccess; -} - -void pxEexcute_thread(void *param) -{ - gpg_execution_params *params = (gpg_execution_params*)param; - pxResult result = pxExecute(params->cmd, params->useless, params->out, params->code, params->result, params->hProcess, params->proc); -} diff --git a/gpg_wrapper.h b/gpg_wrapper.h deleted file mode 100755 index 5501297..0000000 --- a/gpg_wrapper.h +++ /dev/null @@ -1,50 +0,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. - - -#ifndef GPG_WRAPPER_H -#define GPG_WRAPPER_H -typedef enum { - pxSuccess, - pxSuccessExitCodeInvalid, - pxCreatePipeFailed, - pxDuplicateHandleFailed, - pxCloseHandleFailed, - pxCreateProcessFailed, - pxThreadWaitFailed, - pxReadFileFailed, - pxBufferOverflow, - pxNotFound, - pxNotConfigured -} -pxResult; - -pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result); - -struct gpg_execution_params -{ - wstring *cmd; - char *useless; - string *out; - LPDWORD code; - pxResult *result; - HANDLE hProcess; - PROCESS_INFORMATION *proc; -}; - -void pxEexcute_thread(void *param); - -#endif \ No newline at end of file diff --git a/icons.cpp b/icons.cpp deleted file mode 100755 index c981eea..0000000 --- a/icons.cpp +++ /dev/null @@ -1,152 +0,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 "commonheaders.h" - -HANDLE IconLibDefine(TCHAR* desc, TCHAR* section, char* ident, HICON icon, char* def_file, int def_idx, int size) -{ - SKINICONDESC sid = {0}; - HANDLE hIcon; - - if(!size) - size = 16; - - sid.cbSize = sizeof( SKINICONDESC ); - sid.ptszSection = section; - sid.ptszDescription = desc; - sid.flags = SIDF_TCHAR; - - sid.pszName = ident; - sid.pszDefaultFile = def_file; - sid.iDefaultIndex = def_idx; - sid.hDefaultIcon = icon; - sid.cx = sid.cy = size; - - hIcon = Skin_AddIcon(&sid); - - return hIcon; -} - - -void InitIconLib() -{ - extern HINSTANCE hInst; - char lib[MAX_PATH]; - GetModuleFileNameA(hInst, lib, MAX_PATH); - TCHAR *module = mir_a2t(szGPGModuleName); - - IconLibDefine(_T("Secured"), module, "secured", NULL, lib, -IDI_SECURED,0); - IconLibDefine(_T("Unsecured"), module, "unsecured", NULL, lib, -IDI_UNSECURED,0); - mir_free(module); -} - - - - - -HICON IconLibGetIcon(const char* ident) -{ - return (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)ident); -} - - - -void IconLibReleaseIcon(const char* ident) -{ - CallService(MS_SKIN2_RELEASEICON, 0, (LPARAM)ident); -} - - - -HANDLE IconLibHookIconsChanged(MIRANDAHOOK hook) -{ - return HookEvent(ME_SKIN2_ICONSCHANGED, hook); -} - - -void setClistIcon(HANDLE hContact) -{ - bool enabled = isContactSecured(hContact); - extern HANDLE g_hCLIcon; - HANDLE hMC = hContact; - if(metaIsSubcontact(hContact)) - hMC = metaGetContact(hContact); - else if(metaIsProtoMetaContacts(hContact)) - hMC = metaGetContact(hContact); - if(g_hCLIcon && enabled) - { - HICON icon = IconLibGetIcon("secured"); - IconExtraColumn iec = {0}; - iec.cbSize = sizeof(iec); - iec.hImage = (HANDLE)CallService(MS_CLIST_EXTRA_ADD_ICON, (WPARAM)icon, (LPARAM)0); - ExtraIcon_SetIcon(g_hCLIcon, hContact, iec.hImage); - if(hMC) - ExtraIcon_SetIcon(g_hCLIcon, hMC, iec.hImage); - } - else - { - ExtraIcon_SetIcon(g_hCLIcon, hContact, (HANDLE)0); // is it right ? hmm.., at least working.... - if(hMC) - ExtraIcon_SetIcon(g_hCLIcon, hMC, (HANDLE)0); - } -} - -void setSrmmIcon(HANDLE h) -{ - HANDLE hContact = metaIsProtoMetaContacts(h)?metaGetMostOnline(h):h; - bool enabled = isContactSecured(hContact); - HANDLE hMC = hContact; - if(metaIsSubcontact(hContact)) - hMC = metaGetContact(hContact); - else if(metaIsProtoMetaContacts(hContact)) - hMC = metaGetContact(hContact); - if(ServiceExists(MS_MSG_MODIFYICON)) - { - StatusIconData sid = {0}; - sid.cbSize = sizeof(sid); - sid.szModule = szGPGModuleName; - sid.hIcon = IconLibGetIcon("secured"); - sid.dwId = 0x00000001; - sid.flags = enabled?0:MBF_HIDDEN; - CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid); - if( hMC ) - CallService(MS_MSG_MODIFYICON, (WPARAM)hMC, (LPARAM)&sid); - ZeroMemory(&sid, sizeof(sid)); - sid.cbSize = sizeof(sid); - sid.szModule = szGPGModuleName; - sid.hIcon = IconLibGetIcon("unsecured"); - sid.dwId = 0x00000002; - sid.flags = enabled?MBF_HIDDEN:0; - CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid); - if( hMC ) - CallService(MS_MSG_MODIFYICON, (WPARAM)hMC, (LPARAM)&sid); - } -} - - -void RefreshContactListIcons() -{ - HANDLE hContact; - extern HANDLE g_hCLIcon; - CallService(MS_CLUI_LISTBEGINREBUILD,0,0); - hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); - while (hContact) - { - setClistIcon(hContact); - hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0); - } - CallService(MS_CLUI_LISTENDREBUILD,0,0); -} diff --git a/icons/secured.ico b/icons/secured.ico deleted file mode 100644 index 8d84167..0000000 Binary files a/icons/secured.ico and /dev/null differ diff --git a/icons/unsecured.ico b/icons/unsecured.ico deleted file mode 100644 index 567367b..0000000 Binary files a/icons/unsecured.ico and /dev/null differ diff --git a/init.cpp b/init.cpp deleted file mode 100755 index b87e76f..0000000 --- a/init.cpp +++ /dev/null @@ -1,288 +0,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 "commonheaders.h" - -//global variables -bool bAppendTags = false, bDebugLog = false, bJabberAPI = false, bPresenceSigning = false, bIsMiranda09 = false, bMetaContacts = false, bFileTransfers = false, bAutoExchange = false, bStripTags = false, tabsrmm_used = false; -TCHAR *inopentag = NULL, *inclosetag = NULL, *outopentag = NULL, *outclosetag = NULL, *password = NULL; - -list Accounts; - -HINSTANCE hInst; -HANDLE hLoadPubKey = NULL, hToggleEncryption = NULL, hOnPreBuildContactMenu = NULL, hSendKey = NULL, g_hCLIcon = NULL, hExportGpgKeys = NULL, hImportGpgKeys = NULL; -IconExtraColumn g_IEC = {0}; -static int OnModulesLoaded(WPARAM wParam,LPARAM lParam); -extern char *date(); -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}; -XML_API xi = {0}; -int hLangpack = 0; -logtofile debuglog; -bool gpg_valid = false, gpg_keyexist = false; -std::map hcontact_data; - - -#define MIID_GPG { 0x4227c050, 0x8d97, 0x48d2, { 0x91, 0xec, 0x6a, 0x95, 0x2b, 0x3d, 0xab, 0x94 } } - -PLUGININFOEX pluginInfo={ - sizeof(PLUGININFOEX), - 0, - PLUGIN_MAKE_VERSION(0,0,0,11), - "new GPG encryption support plugin, based on code from old gpg plugin and secureim", - "sss", - "sss123next@list.ru", - "© 2010-2012 sss", - "http://sss.chaoslab.ru/tracker/mim_plugs/", - 1, //unicode - MIID_GPG -}; - -BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) -{ - hInst=hinstDLL; - return TRUE; -} - - -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) -{ - static char plugname[52]; - strcpy(plugname, szGPGModuleName" ["); - strcat(plugname, date()); - strcat(plugname, " "); - strcat(plugname, __TIME__); - strcat(plugname, "]"); - pluginInfo.shortName = plugname; - return &pluginInfo; -} - -static const MUUID interfaces[] = {MIID_GPG, MIID_LAST}; -extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void) -{ - return interfaces; -} - -int LoadKey(WPARAM w, LPARAM l); -int ToggleEncryption(WPARAM w, LPARAM l); -int SendKey(WPARAM w, LPARAM l); -int ExportGpGKeys(WPARAM w, LPARAM l); -int ImportGpGKeys(WPARAM w, LPARAM l); - -void init_vars() -{ - bAppendTags = DBGetContactSettingByte(NULL, szGPGModuleName, "bAppendTags", 0); - bStripTags = DBGetContactSettingByte(NULL, szGPGModuleName, "bStripTags", 0); - inopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", _T("")); - inclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", _T("")); - outopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", _T("")); - outclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", _T("")); - bDebugLog = DBGetContactSettingByte(NULL, szGPGModuleName, "bDebugLog", 0); - bAutoExchange = DBGetContactSettingByte(NULL, szGPGModuleName, "bAutoExchange", 0); - password = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); - debuglog.init(); - bJabberAPI = DBGetContactSettingByte(NULL, szGPGModuleName, "bJabberAPI", bIsMiranda09?1:0); - bPresenceSigning = DBGetContactSettingByte(NULL, szGPGModuleName, "bPresenceSigning", 0); - bFileTransfers = DBGetContactSettingByte(NULL, szGPGModuleName, "bFileTransfers", 0); - firstrun_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "FirstrunWindowX", 0); - firstrun_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "FirstrunWindowY", 0); - key_password_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "PasswordWindowX", 0); - key_password_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "PasswordWindowY", 0); - key_gen_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "KeyGenWindowX", 0); - key_gen_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "KeyGenWindowY", 0); - load_key_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "LoadKeyWindowX", 0); - load_key_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "LoadKeyWindowY", 0); - import_key_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "ImportKeyWindowX", 0); - import_key_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "ImportKeyWindowY", 0); - new_key_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "NewKeyWindowX", 0); - new_key_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "NewKeyWindowY", 0); - load_existing_key_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "LoadExistingKeyWindowX", 0); - load_existing_key_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "LoadExistingKeyWindowY", 0); - tabsrmm_used = isTabsrmmUsed(); -} - -extern "C" int __declspec(dllexport) Load() -{ - HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); - mir_getXI(&xi); //TODO: check if we have access to api - mir_getLP(&pluginInfo); - init_vars(); - CreateServiceFunction("/LoadPubKey",(MIRANDASERVICE)LoadKey); - CreateServiceFunction("/ToggleEncryption",(MIRANDASERVICE)ToggleEncryption); - CreateServiceFunction("/SendKey",(MIRANDASERVICE)SendKey); - CreateServiceFunction("/ExportGPGKeys",(MIRANDASERVICE)ExportGpGKeys); - CreateServiceFunction("/ImportGPGKeys",(MIRANDASERVICE)ImportGpGKeys); - CLISTMENUITEM mi = {0}; - mi.cbSize=sizeof(mi); - mi.position=-0x7FFFFFFF; - mi.flags=0; - mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); - mi.pszName="Load GPG public key"; - mi.pszService="/LoadPubKey"; - hLoadPubKey = Menu_AddContactMenuItem(&mi); - ZeroMemory(&mi,sizeof(mi)); - mi.cbSize=sizeof(mi); - mi.position=-0x7FFFFFFe; - mi.flags=0; - mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); - mi.pszName="Toggle GPG encryption"; - mi.pszService="/ToggleEncryption"; - hToggleEncryption = Menu_AddContactMenuItem(&mi); - ZeroMemory(&mi,sizeof(mi)); - mi.cbSize=sizeof(mi); - mi.position=-0x7FFFFFFe; - mi.flags=0; - mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); - mi.pszName="Send public key"; - mi.pszService="/SendKey"; - hSendKey = Menu_AddContactMenuItem(&mi); - ZeroMemory(&mi,sizeof(mi)); - mi.cbSize=sizeof(mi); - mi.position=-0x7FFFFFFF; - mi.flags=0; - mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); - mi.pszName="Export GPG Public keys from all users"; - mi.pszService="/ExportGPGKeys"; - hExportGpgKeys = Menu_AddMainMenuItem(&mi); - ZeroMemory(&mi,sizeof(mi)); - mi.cbSize=sizeof(mi); - mi.position=-0x7FFFFFFF; - mi.flags=0; - mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); - mi.pszName="Import GPG Public keys from all users"; - mi.pszService="/ImportGPGKeys"; - hImportGpgKeys = Menu_AddMainMenuItem(&mi); - - return 0; -} - -int AddContact(WPARAM w, LPARAM l) -{ - CallService(MS_PROTO_ADDTOCONTACT,w,(LPARAM)szGPGModuleName); - return 0; -} - - -static int OnModulesLoaded(WPARAM wParam,LPARAM lParam) -{ - - int GpgOptInit(WPARAM wParam,LPARAM lParam); - int OnPreBuildContactMenu(WPARAM w, LPARAM l); - int RecvMsgSvc(WPARAM w, LPARAM l); - int 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 onExtraImageListRebuilding(WPARAM, LPARAM); - int onExtraImageApplying(WPARAM wParam, LPARAM); - int onProtoAck(WPARAM, LPARAM); - int onSendFile(WPARAM, LPARAM); - void InitIconLib(); - - void InitCheck(); - void FirstRun(); - bIsMiranda09 = (DWORD)CallService(MS_SYSTEM_GETVERSION, 0, 0) >= 0x00090001?true:false; - FirstRun(); - InitCheck(); - InitIconLib(); - if(ServiceExists(MS_MSG_ADDICON)) - { - HICON IconLibGetIcon(const char* ident); - StatusIconData sid = {0}; - sid.cbSize = sizeof(sid); - sid.szModule = szGPGModuleName; - sid.flags = MBF_HIDDEN; - sid.dwId = 0x00000001; - sid.hIcon = IconLibGetIcon("secured"); - sid.szTooltip = Translate("GPG Turn off encryption"); - CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); - ZeroMemory(&sid, sizeof(sid)); - sid.cbSize = sizeof(sid); - sid.szModule = szGPGModuleName; - sid.flags = MBF_HIDDEN; - sid.dwId = 0x00000002; - sid.hIcon = IconLibGetIcon("unsecured"); - sid.szTooltip = Translate("GPG Turn on encryption"); - CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); - } - - - bMetaContacts = ServiceExists(MS_MC_GETMETACONTACT); - - if(bJabberAPI && bIsMiranda09) - GetJabberInterface(0,0); - - HookEvent(ME_OPT_INITIALISE, GpgOptInit); - HookEvent(ME_DB_EVENT_FILTER_ADD, HookSendMsg); - if(bJabberAPI && bIsMiranda09) - HookEvent(ME_PROTO_ACCLISTCHANGED, GetJabberInterface); - - HookEvent(ME_PROTO_ACK, onProtoAck); //filetransfer unimplemented now - - HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPreBuildContactMenu); - - HookEvent(ME_MSG_WINDOWEVENT, onWindowEvent); - HookEvent(ME_MSG_ICONPRESSED, onIconPressed); - - if(ServiceExists(MS_EXTRAICON_REGISTER)) - g_hCLIcon = ExtraIcon_Register(szGPGModuleName, Translate("GPG encryption status"), "secured", (MIRANDAHOOK)onExtraImageListRebuilding, (MIRANDAHOOK)onExtraImageApplying); - - - - PROTOCOLDESCRIPTOR pd = {0}; - pd.cbSize=sizeof(PROTOCOLDESCRIPTOR); - pd.szName=szGPGModuleName; - pd.type=PROTOTYPE_ENCRYPTION; - CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd); - - CreateProtoServiceFunction(szGPGModuleName, PSR_MESSAGE, (MIRANDASERVICE)RecvMsgSvc); - CreateProtoServiceFunction(szGPGModuleName, PSS_MESSAGE, (MIRANDASERVICE)SendMsgSvc); - CreateProtoServiceFunction(szGPGModuleName, PSR_MESSAGE"W", (MIRANDASERVICE)RecvMsgSvc); - CreateProtoServiceFunction(szGPGModuleName, PSS_MESSAGE"W", (MIRANDASERVICE)SendMsgSvc); - - CreateProtoServiceFunction(szGPGModuleName, PSS_FILE, (MIRANDASERVICE)onSendFile); - CreateProtoServiceFunction(szGPGModuleName, PSS_FILE"W", (MIRANDASERVICE)onSendFile); - - for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) - if (!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)szGPGModuleName)) - CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)szGPGModuleName); - - HookEvent(ME_DB_CONTACT_ADDED,AddContact); - - - return 0; -} - -extern list transfers; -extern "C" int __declspec(dllexport) Unload(void) -{ -// for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) -// DBDeleteContactSetting(hContact, szGPGModuleName, "KeyID_Prescense"); - if(!transfers.empty()) - { - for(list::iterator p = transfers.begin(); p != transfers.end(); p++) - if(!(*p).empty()) - DeleteFile((*p).c_str()); - } - mir_free(inopentag); - mir_free(inclosetag); - mir_free(outopentag); - mir_free(outclosetag); - if(password) - delete [] password; - return 0; -} diff --git a/jabber_account.cpp b/jabber_account.cpp deleted file mode 100755 index 6a264a4..0000000 --- a/jabber_account.cpp +++ /dev/null @@ -1,85 +0,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 "commonheaders.h" - -void JabberAccount::setAccountName(TCHAR *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; -} - - -TCHAR *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 = NULL; - hSendHandler = INVALID_HANDLE_VALUE; - hPrescenseHandler = INVALID_HANDLE_VALUE; - hMessageHandler = INVALID_HANDLE_VALUE; - AccountNumber = -1; - JabberInterface = NULL; -} -JabberAccount::~JabberAccount() -{ - if(AccountName) - mir_free(AccountName); -} \ No newline at end of file diff --git a/jabber_account.h b/jabber_account.h deleted file mode 100755 index b643ed1..0000000 --- a/jabber_account.h +++ /dev/null @@ -1,43 +0,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. -#ifndef JABBER_ACCOUNT_H -#define JABBER_ACCOUNT_H -class JabberAccount -{ -public: - void setAccountName(TCHAR *Name); - void setAccountNumber(int Number); - void setJabberInterface(IJabberInterface *JIf); - void setSendHandler(HJHANDLER hHandler); - void setPrescenseHandler(HJHANDLER hHandler); - void setMessageHandler(HJHANDLER hHandler); - - TCHAR *getAccountName(); - int getAccountNumber(); - IJabberInterface *getJabberInterface(); - HJHANDLER getSendHandler(); - HJHANDLER getPrescenseHandler(); - HJHANDLER getMessageHandler(); - ~JabberAccount(); - JabberAccount(); -private: - TCHAR *AccountName; - int AccountNumber; - IJabberInterface *JabberInterface; - HJHANDLER hSendHandler, hPrescenseHandler, hMessageHandler; -}; - -#endif \ No newline at end of file diff --git a/log.cpp b/log.cpp deleted file mode 100755 index 7618914..0000000 --- a/log.cpp +++ /dev/null @@ -1,91 +0,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 "commonheaders.h" - - -logtofile& logtofile::operator<<(TCHAR *buf) -{ - extern bool bDebugLog; - if(bDebugLog) - { - log_mutex.lock(); - log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate); - log<", p); - tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); - ListView_SetItemText(hwndList, iRow, 1, tmp); - mir_free(tmp); - p = out.find("ssb ", p2) + 6; - p = out.find(" ", p) + 1; - p2 = out.find("\n", p); - tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p-1)).c_str()); - ListView_SetItemText(hwndList, iRow, 3, tmp); - mir_free(tmp); - ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this - ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); - i++; - } - } - } - { - SendMessageA(GetDlgItem(hwndDlg, IDC_ACCOUNT), CB_ADDSTRING, 0, (LPARAM)Translate("Default")); - int count = 0; - PROTOACCOUNT **accounts; - ProtoEnumAccounts(&count, &accounts); - for(int i = 0; i < count; i++) - { - if(StriStr(accounts[i]->szModuleName, "metacontacts")) - continue; - if(StriStr(accounts[i]->szModuleName, "weather")) - continue; - SendMessageA(GetDlgItem(hwndDlg, IDC_ACCOUNT), CB_ADDSTRING, 0, (LPARAM)accounts[i]->szModuleName); - } - SendMessageA(GetDlgItem(hwndDlg, IDC_ACCOUNT), CB_SELECTSTRING, 0, (LPARAM)Translate("Default")); - string keyinfo = Translate("key id"); - keyinfo += ": "; - char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); - keyinfo += (strlen(keyid) > 0)?keyid:Translate("not set"); - mir_free(keyid); - SetDlgItemTextA(hwndDlg, IDC_KEY_ID, keyinfo.c_str()); - } - return TRUE; - } - - - case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDC_GENERATE_KEY: - void ShowKeyGenDialog(); - ShowKeyGenDialog(); - break; - case ID_OK: - { - ListView_GetItemText(hwndList, itemnum, 0, fp, 16); - TCHAR *name = new TCHAR [64]; - ListView_GetItemText(hwndList, itemnum, 2, name, 64); - { - if(_tcschr(name, _T('('))) - { - wstring str = name; - wstring::size_type p = str.find(_T("("))-1; - _tcscpy(name, str.substr(0, p).c_str()); - } - } - string out; - DWORD code; - wstring cmd = _T("--batch -a --export "); - cmd += fp; -// cmd += _T("\""); - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog< user_data; - extern int item_num; - item_num = 0; //black magic here - user_data[1] = 0; - ShowLoadPublicKeyDialog(); - ListView_DeleteAllItems(hwndList); - { - int i = 1, iRow = 0; - item.mask = LVIF_TEXT; - item.iItem = i; - item.iSubItem = 0; - item.pszText = _T(""); - {//parse gpg output - string out; - DWORD code; - wstring::size_type p = 0, p2 = 0, stop = 0; - { - wstring cmd = _T("--batch --list-secret-keys"); - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<", p); - tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); - ListView_SetItemText(hwndList, iRow, 1, tmp); - mir_free(tmp); - p = out.find("ssb ", p2) + 6; - p = out.find(" ", p) + 1; - p2 = out.find("\n", p); - tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p-1)).c_str()); - ListView_SetItemText(hwndList, iRow, 3, tmp); - mir_free(tmp); - ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this - ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); - i++; - } - } - } - } - break; - case IDC_DELETE_KEY: - ListView_GetItemText(hwndList, itemnum, 0, fp, 16); - { - string out; - DWORD code; - wstring cmd = _T("--batch --fingerprint "); - cmd += fp; - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::seconds(10))) - { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<timed_join(boost::posix_time::seconds(10))) - { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog< 0)?keyid:Translate("not set"); - mir_free(keyid); - SetDlgItemTextA(hwndDlg, IDC_KEY_ID, keyinfo.c_str()); - } - else - { - string keyinfo = Translate("key id"); - keyinfo += ": "; - char setting[64]; - strcpy(setting, buf); - strcat(setting, "_KeyID"); - char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, setting, ""); - keyinfo += (strlen(keyid) > 0)?keyid:Translate("not set"); - mir_free(keyid); - SetDlgItemTextA(hwndDlg, IDC_KEY_ID, keyinfo.c_str()); - } - } - break; - - } - break; - } - - case WM_NOTIFY: - { - if(hdr && IsWindowVisible(hdr->hdr.hwndFrom) && hdr->iItem != (-1)) - { - if(hdr->hdr.code == NM_CLICK) - { - EnableWindow(GetDlgItem(hwndDlg, ID_OK), 1); - itemnum = hdr->iItem; - } - } -/* switch(LOWORD(wParam)) - { - default: - break; - }; */ -/* switch (((LPNMHDR)lParam)->code) - { - default: - break; - } */ - } - break; - case WM_CLOSE: - DestroyWindow(hwndDlg); - break; - case WM_DESTROY: - { - GetWindowRect(hwndDlg, &firstrun_rect); - DBWriteContactSettingDword(NULL, szGPGModuleName, "FirstrunWindowX", firstrun_rect.left); - DBWriteContactSettingDword(NULL, szGPGModuleName, "FirstrunWindowY", firstrun_rect.top); - } - hwndFirstRun = NULL; - break; - - } - - return FALSE; -} - -void ShowFirstRunDialog(); - -static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - TCHAR *tmp = NULL; - switch (msg) - { - case WM_INITDIALOG: - { - TranslateDialogDefault(hwndDlg); - TCHAR *path = new TCHAR [MAX_PATH]; - bool gpg_exists = false, lang_exists = false; - { - char *mir_path = new char [MAX_PATH]; - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); - SetCurrentDirectoryA(mir_path); - tmp = mir_a2t(mir_path); - mir_free(mir_path); - mir_realloc(path, (_tcslen(path)+128)*sizeof(TCHAR)); - TCHAR *gpg_path = new TCHAR [MAX_PATH], *gpg_lang_path = new TCHAR [MAX_PATH]; - _tcscpy(gpg_path, tmp); - _tcscat(gpg_path, _T("\\GnuPG\\gpg.exe")); - _tcscpy(gpg_lang_path, tmp); - _tcscat(gpg_lang_path, _T("\\GnuPG\\gnupg.nls\\en@quot.mo")); - mir_free(tmp); - if(_waccess(gpg_path, 0) != -1) - { - gpg_exists = true; - _tcscpy(path, _T("GnuPG\\gpg.exe")); - } - if(_waccess(gpg_lang_path, 0) != -1) - lang_exists = true; - if(gpg_exists && !lang_exists) //TODO: check gpg version - MessageBox(0, TranslateT("gpg binary found in miranda folder, but english locale does not exists.\nit's highly recommended to place \\gnupg.nls\\en@quot.mo in gnupg folder under miranda root.\nwithout this file you may expirense many problem with gpg output on non english systems.\nand plugin may completely do not work.\nyou have beed warned."), TranslateT("Warning"), MB_OK); - mir_free(gpg_path); - mir_free(gpg_lang_path); - } - DWORD len = MAX_PATH; - if(!gpg_exists) - { - tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", (SHGetValue(HKEY_CURRENT_USER, _T("Software\\GNU\\GnuPG"), _T("gpgProgram"), 0, path, &len) == ERROR_SUCCESS)?path:_T("")); - if(tmp[0]) - { - char *mir_path = new char [MAX_PATH]; - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); - SetCurrentDirectoryA(mir_path); - delete [] mir_path; - if(_waccess(tmp, 0) == -1) - { - if(errno == ENOENT) - MessageBox(0, TranslateT("wrong gpg binary location found in system.\nplease choose another location"), TranslateT("Warning"), MB_OK); - } - } - } - else - tmp = mir_wstrdup(path); - delete [] path; - SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp); - bool bad_version = false; - if(gpg_exists && lang_exists) - { - DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); - string out; - DWORD code; - wstring cmd = _T("--version"); - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - gpg_valid = true; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<code) - { - default: - break; - }*/ - } - break; - case WM_CLOSE: - DestroyWindow(hwndDlg); - break; - case WM_DESTROY: - hwndSetDirs = NULL; - break; - - } - return FALSE; -} - -static BOOL CALLBACK DlgProcNewKeyDialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - extern HANDLE new_key_hcnt; - extern boost::mutex new_key_hcnt_mutex; - static HANDLE hContact = INVALID_HANDLE_VALUE; - void ImportKey(); - TCHAR *tmp = NULL; - switch (msg) - { - case WM_INITDIALOG: - { - hContact = new_key_hcnt; - new_key_hcnt_mutex.unlock(); - SetWindowPos(hwndDlg, 0, new_key_rect.left, new_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); - TranslateDialogDefault(hwndDlg); - TCHAR *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); - SetDlgItemText(hwndDlg, IDC_MESSAGE, tmp[0]?TranslateT("There is existing key for contact, would you like to replace with new key ?"):TranslateT("New public key was received, do you want to import it?")); - EnableWindow(GetDlgItem(hwndDlg, IDC_IMPORT_AND_USE), DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)?0:1); - SetDlgItemText(hwndDlg, ID_IMPORT, tmp[0]?TranslateT("Replace"):TranslateT("Accept")); - mir_free(tmp); - tmp = new TCHAR [256]; - _tcscpy(tmp, TranslateT("Received key from ")); - _tcscat(tmp, (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, (LPARAM)GCDNF_TCHAR)); - SetDlgItemText(hwndDlg, IDC_KEY_FROM, tmp); - delete [] tmp; - return TRUE; - } - - - case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case ID_IMPORT: - ImportKey(); - DestroyWindow(hwndDlg); - break; - case IDC_IMPORT_AND_USE: - ImportKey(); - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); - void setSrmmIcon(HANDLE hContact); - void setClistIcon(HANDLE hContact); - setSrmmIcon(hContact); - setClistIcon(hContact); - DestroyWindow(hwndDlg); - break; - case IDC_IGNORE_KEY: - DestroyWindow(hwndDlg); - break; - default: - break; - } - - break; - } - - case WM_NOTIFY: - { -/* switch (((LPNMHDR)lParam)->code) - { - default: - break; - }*/ - } - break; - case WM_CLOSE: - DestroyWindow(hwndDlg); - break; - case WM_DESTROY: - { - GetWindowRect(hwndDlg, &new_key_rect); - DBWriteContactSettingDword(NULL, szGPGModuleName, "NewKeyWindowX", new_key_rect.left); - DBWriteContactSettingDword(NULL, szGPGModuleName, "NewKeyWindowY", new_key_rect.top); - } - hwndNewKey = NULL; - break; - - } - return FALSE; -} -static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch (msg) - { - case WM_INITDIALOG: - { - SetWindowPos(hwndDlg, 0, key_gen_rect.left, key_gen_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); - TranslateDialogDefault(hwndDlg); - SetWindowText(hwndDlg, TranslateT("Key Generation dialog")); - ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEY_TYPE), _T("RSA"), 0); - ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEY_TYPE), _T("DSA"), 1); - SendDlgItemMessage(hwndDlg, IDC_KEY_TYPE, CB_SETCURSEL, (WPARAM)1, 0); - SetDlgItemInt(hwndDlg, IDC_KEY_EXPIRE_DATE, 0, 0); - SetDlgItemInt(hwndDlg, IDC_KEY_LENGTH, 4096, 0); - return TRUE; - } - - - case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDCANCEL: - DestroyWindow(hwndDlg); - break; - case IDOK: - { - wstring path; - { //data sanity checks - TCHAR *tmp = new TCHAR [5]; - GetDlgItemText(hwndDlg, IDC_KEY_TYPE, tmp, 5); - if(_tcslen(tmp) < 3) - { - mir_free(tmp); - MessageBox(0, TranslateT("You must set encryption algorythm first"), TranslateT("Error"), MB_OK); - break; - } - mir_free(tmp); - tmp = new TCHAR [5]; - GetDlgItemText(hwndDlg, IDC_KEY_LENGTH, tmp, 5); - int length = _ttoi(tmp); - mir_free(tmp); - if(length < 1024 || length > 4096) - { - MessageBox(0, TranslateT("Key length must be of length from 1024 to 4096 bits"), TranslateT("Error"), MB_OK); - break; - } - tmp = new TCHAR [12]; - GetDlgItemText(hwndDlg, IDC_KEY_EXPIRE_DATE, tmp, 12); - if(_tcslen(tmp) != 10 && tmp[0] != '0') - { - MessageBox(0, TranslateT("Invalid date"), TranslateT("Error"), MB_OK); - delete [] tmp; - break; - } - delete [] tmp; - tmp = new TCHAR [128]; - GetDlgItemText(hwndDlg, IDC_KEY_REAL_NAME, tmp, 128); - if(_tcslen(tmp) < 5) - { - MessageBox(0, TranslateT("Name must contain at least 5 characters"), TranslateT("Error"), MB_OK); - delete [] tmp; - break; - } - else if (_tcschr(tmp, _T('(')) || _tcschr(tmp, _T(')'))) - { - MessageBox(0, TranslateT("Name cannot contain '(' or ')'"), TranslateT("Error"), MB_OK); - delete [] tmp; - break; - } - delete [] tmp; - tmp = new TCHAR [128]; - GetDlgItemText(hwndDlg, IDC_KEY_EMAIL, tmp, 128); - if((_tcslen(tmp)) < 5 || (!_tcschr(tmp, _T('@'))) || (!_tcschr(tmp, _T('.')))) - { - MessageBox(0, TranslateT("Invalid Email"), TranslateT("Error"), MB_OK); - delete [] tmp; - break; - } - delete [] tmp; - } - { //generating key file - TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - char *tmp2;// = mir_t2a(tmp); - path = tmp; - mir_free(tmp); - // mir_free(tmp2); - path.append(_T("\\new_key")); - wfstream f(path.c_str(), std::ios::out); - if(!f.is_open()) - { - MessageBox(0, TranslateT("Failed to open file"), TranslateT("Error"), MB_OK); - break; - } - f<<"Key-Type: "; - tmp = new TCHAR [5]; - GetDlgItemText(hwndDlg, IDC_KEY_TYPE, tmp, 5); - tmp2 = mir_t2a(tmp); - delete [] tmp; - char *subkeytype = new char [6]; - if(strstr(tmp2, "RSA")) - strcpy(subkeytype, "RSA"); - else if(strstr(tmp2, "DSA")) //this is useless check for now, but it will be required if someone add another key types support - strcpy(subkeytype, "ELG-E"); - f<", p); - tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); - ListView_SetItemText(hwndList_g, iRow, 1, tmp); - mir_free(tmp); - p = out.find("ssb ", p2) + 6; - p = out.find(" ", p) + 1; - p2 = out.find("\n", p); - tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p-1)).c_str()); - ListView_SetItemText(hwndList_g, iRow, 3, tmp); - mir_free(tmp); - ListView_SetColumnWidth(hwndList_g, 0, LVSCW_AUTOSIZE);// not sure about this - ListView_SetColumnWidth(hwndList_g, 1, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList_g, 2, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList_g, 3, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList_g, 4, LVSCW_AUTOSIZE); - i++; - } - } - } - break; - default: - break; - } - - break; - } - - case WM_NOTIFY: - { -/* switch (((LPNMHDR)lParam)->code) - { - default: - break; - } */ - } - break; - case WM_CLOSE: - DestroyWindow(hwndDlg); - break; - case WM_DESTROY: - { - GetWindowRect(hwndDlg, &key_gen_rect); - DBWriteContactSettingDword(NULL, szGPGModuleName, "KeyGenWindowX", key_gen_rect.left); - DBWriteContactSettingDword(NULL, szGPGModuleName, "KeyGenWindowY", key_gen_rect.top); - } - hwndKeyGen = NULL; - break; - - } - return FALSE; -} - -int itemnum2 = 0; - -static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) -{ - HWND hwndList=GetDlgItem(hwndDlg, IDC_EXISTING_KEY_LIST); - hwndList_g = hwndList; - LVCOLUMN col = {0}; - LVITEM item = {0}; - NMLISTVIEW * hdr = (NMLISTVIEW *) lParam; - TCHAR id[16] = {0}; - switch (msg) - { - case WM_INITDIALOG: - { - SetWindowPos(hwndDlg, 0, load_existing_key_rect.left, load_existing_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); - TranslateDialogDefault(hwndDlg); - col.pszText = _T("Key ID"); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 50; - ListView_InsertColumn(hwndList, 0, &col); - ZeroMemory(&col,sizeof(col)); - col.pszText = _T("Email"); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 30; - ListView_InsertColumn(hwndList, 1, &col); - ZeroMemory(&col,sizeof(col)); - col.pszText = _T("Name"); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 250; - ListView_InsertColumn(hwndList, 2, &col); - ZeroMemory(&col,sizeof(col)); - col.pszText = _T("Creation date"); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 30; - ListView_InsertColumn(hwndList, 3, &col); - ZeroMemory(&col,sizeof(col)); - col.pszText = _T("Expiration date"); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 30; - ListView_InsertColumn(hwndList, 4, &col); - ZeroMemory(&col,sizeof(col)); - col.pszText = _T("Key length"); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 30; - ListView_InsertColumn(hwndList, 5, &col); - ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_FULLROWSELECT); - int i = 1, iRow = 0; - { - item.mask = LVIF_TEXT; - item.iItem = i; - item.iSubItem = 0; - item.pszText = _T(""); - {//parse gpg output - string out; - DWORD code; - string::size_type p = 0, p2 = 0, stop = 0; - { - wstring cmd = _T("--batch --list-keys"); - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<", p3); - tmp = mir_wstrdup(toUTF16(out.substr(p3,p4-p3)).c_str()); - ListView_SetItemText(hwndList, iRow, 1, tmp); - mir_free(tmp); - } - else - p2--; - p = out.find_first_not_of(" ", p); - tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); - ListView_SetItemText(hwndList, iRow, 2, tmp); - mir_free(tmp); -// p = out.find("sub ", p2) + 6; -// p = out.find(" ", p) + 1; -// p2 = out.find("\n", p); -// tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p-1)).c_str()); -// ListView_SetItemText(hwndList, iRow, 3, tmp); -// mir_free(tmp); - ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this - ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 5, LVSCW_AUTOSIZE); - i++; - } - } - } - return TRUE; - } - case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDOK: - { - ListView_GetItemText(hwndList, itemnum2, 0, id, 16); - extern HWND hPubKeyEdit; - string out; - DWORD code; - wstring cmd = _T("--batch -a --export "); - cmd += id; - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<hdr.hwndFrom) && hdr->iItem != (-1)) - { - if(hdr->hdr.code == NM_CLICK) - { - EnableWindow(GetDlgItem(hwndDlg, IDOK), 1); - itemnum2 = hdr->iItem; - } - } - - switch (((LPNMHDR)lParam)->code) - { - - case PSN_APPLY: - { - return TRUE; - } - } - } - break; - case WM_CLOSE: - DestroyWindow(hwndDlg); - break; - case WM_DESTROY: - { - GetWindowRect(hwndDlg, &load_existing_key_rect); - DBWriteContactSettingDword(NULL, szGPGModuleName, "LoadExistingKeyWindowX", load_existing_key_rect.left); - DBWriteContactSettingDword(NULL, szGPGModuleName, "LoadExistingKeyWindowY", load_existing_key_rect.top); - } - hwndSelectExistingKey = NULL; - break; - - } - - return FALSE; -} -static BOOL CALLBACK DlgProcImportKeyDialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - extern HANDLE new_key_hcnt; - extern boost::mutex new_key_hcnt_mutex; - HANDLE hContact = INVALID_HANDLE_VALUE; - switch (msg) - { - case WM_INITDIALOG: - { - hContact = new_key_hcnt; - new_key_hcnt_mutex.unlock(); - SetWindowPos(hwndDlg, 0 , import_key_rect.left, import_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); - TranslateDialogDefault(hwndDlg); - ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEYSERVER), _T("subkeys.pgp.net"), 0); - ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEYSERVER), _T("keys.gnupg.net"), 0); - return TRUE; - } - - - case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDC_IMPORT: - { - string out; - DWORD code; - wstring cmd = _T(" --keyserver \""); - TCHAR *server= new TCHAR [128]; - GetDlgItemText(hwndDlg, IDC_KEYSERVER, server, 128); - cmd += server; - delete [] server; - cmd += _T("\" --recv-keys "); -// char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID_Prescense", ""); -// TCHAR *tmp2 = mir_a2t(tmp); -// mir_free(tmp); - cmd += toUTF16(hcontact_data[hContact].key_in_prescense); -// mir_free(tmp2); - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<code) - { - default: - break; - } */ - } - break; - case WM_CLOSE: - DestroyWindow(hwndDlg); - break; - case WM_DESTROY: - { - GetWindowRect(hwndDlg, &import_key_rect); - DBWriteContactSettingDword(NULL, szGPGModuleName, "ImportKeyWindowX", import_key_rect.left); - DBWriteContactSettingDword(NULL, szGPGModuleName, "ImportKeyWindowY", import_key_rect.top); - } - break; - - } - return FALSE; -} - - -extern HINSTANCE hInst; - - -void ShowFirstRunDialog() -{ - if (hwndFirstRun == NULL) - { - hwndFirstRun = CreateDialog(hInst, MAKEINTRESOURCE(IDD_FIRST_RUN), NULL, (DLGPROC)DlgProcFirstRun); - } - SetForegroundWindow(hwndFirstRun); -} - - -void ShowSetDirsDialog() -{ - if (hwndSetDirs == NULL) - { - hwndSetDirs = CreateDialog(hInst, MAKEINTRESOURCE(IDD_BIN_PATH), NULL, (DLGPROC)DlgProcGpgBinOpts); - } - SetForegroundWindow(hwndSetDirs); -} - -void ShowNewKeyDialog() -{ - hwndNewKey = CreateDialog(hInst, MAKEINTRESOURCE(IDD_NEW_KEY), NULL, (DLGPROC)DlgProcNewKeyDialog); - SetForegroundWindow(hwndNewKey); -} - -void ShowKeyGenDialog() -{ - if (hwndKeyGen == NULL) - { - hwndKeyGen = CreateDialog(hInst, MAKEINTRESOURCE(IDD_KEY_GEN), NULL, (DLGPROC)DlgProcKeyGenDialog); - } - SetForegroundWindow(hwndKeyGen); -} - -void ShowSelectExistingKeyDialog() -{ - if (hwndSelectExistingKey == NULL) - { - hwndSelectExistingKey = CreateDialog(hInst, MAKEINTRESOURCE(IDD_LOAD_EXISTING_KEY), NULL, (DLGPROC)DlgProcLoadExistingKey); - } - SetForegroundWindow(hwndSelectExistingKey); -} - -void ShowImportKeyDialog() -{ - CreateDialog(hInst, MAKEINTRESOURCE(IDD_IMPORT_KEY), NULL, (DLGPROC)DlgProcImportKeyDialog); -} - - - - -void FirstRun() -{ - DWORD pid = 0; - if(!DBGetContactSettingByte(NULL, szGPGModuleName, "FirstRun", 1)) - return; - ShowSetDirsDialog(); -} - -void InitCheck() -{ - {//parse gpg output - gpg_valid = isGPGValid(); - bool home_dir_access = false, temp_access = false; - TCHAR *home_dir = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - std::wstring test_path = home_dir; - mir_free(home_dir); - test_path += _T("/"); - test_path += toUTF16(get_random(13)); - wfstream test_file; - test_file.open(test_path, std::ios::trunc | std::ios::out); - if(test_file.is_open() && test_file.good()) - { - test_file<<_T("access_test\n"); - if(test_file.good()) - home_dir_access = true; - test_file.close(); - DeleteFile(test_path.c_str()); - } - home_dir = _tgetenv(_T("TEMP")); - test_path = home_dir; - test_path += _T("/"); - test_path += toUTF16(get_random(13)); - test_file.open(test_path, std::ios::trunc | std::ios::out); - if(test_file.is_open() && test_file.good()) - { - test_file<<_T("access_test\n"); - if(test_file.good()) - temp_access = true; - test_file.close(); - DeleteFile(test_path.c_str()); - } - if(!home_dir_access || !temp_access || !gpg_valid) - { - char buf[4096]; - strcpy(buf, gpg_valid?Translate("GPG binary is set and valid (this is good).\n"):Translate("GPG binary unset or invalid (plugin will not work).\n")); - strcat(buf, home_dir_access?Translate("Home dir write access granted (this is good).\n"):Translate("Home dir have not write access (plugin most probably will not work).\n")); - strcat(buf, temp_access?Translate("Temp dir write access granted (this is good).\n"):Translate("Temp dir have not write access (plugin should work, but may have some problems, filetransfers will not work).")); - if(!gpg_valid) - strcat(buf, Translate("\nGPG will be disabled until you solve this problems")); - MessageBoxA(0, buf, Translate("GPG plugin problems"), MB_OK); - } - if(!gpg_valid) - return; - gpg_keyexist = isGPGKeyExist(); - string out; - DWORD code; - pxResult result; - wstring::size_type p = 0, p2 = 0, stop = 0; - { - gpg_execution_params params; - wstring cmd = _T("--batch --list-secret-keys"); - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog< output.find("<", s)) - s2 = output.find("<", s); - tmp = new char [output.substr(s,s2-s-1).length()+1]; - strcpy(tmp, output.substr(s,s2-s-1).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainName", tmp); - 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(output[s] == ')') - { - tmp = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyComment", tmp); - mir_free(tmp); - s+=3; - s2 = output.find(">", s); - tmp = new char [output.substr(s,s2-s).length()+1]; - strcpy(tmp, output.substr(s,s2-s).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainEmail", tmp); - mir_free(tmp); - } - else - { - tmp = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); - mir_free(tmp); - } - DBDeleteContactSetting(hcnt, szGPGModuleName, "bAlwatsTrust"); - } - } - } - else - { - char *tmp = NULL; - string::size_type s = output.find("gpg: key ") + strlen("gpg: key "); - string::size_type s2 = output.find(":", s); - DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str()); - s2+=2; - s = output.find("“", s2); - if(s == string::npos) - { - s = output.find("\"", s2); - s += 1; - } - else - s += 3; - if((s2 = output.find("(", s)) == string::npos) - s2 = output.find("<", s); - else if(s2 > output.find("<", s)) - s2 = output.find("<", s); - tmp = new char [output.substr(s,s2-s-1).length()+1]; - strcpy(tmp, output.substr(s,s2-s-1).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainName", tmp); - 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(output[s] == ')') - { - tmp = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyComment", tmp); - mir_free(tmp); - s+=3; - s2 = output.find(">", s); - tmp = new char [output.substr(s,s2-s).length()+1]; - strcpy(tmp, output.substr(s,s2-s).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", tmp); - mir_free(tmp); - } - else - { - tmp = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); - mir_free(tmp); - } - DBDeleteContactSetting(metaGetMostOnline(hContact), szGPGModuleName, "bAlwatsTrust"); - } - } - else - { - char *tmp = NULL; - string::size_type s = output.find("gpg: key ") + strlen("gpg: key "); - string::size_type s2 = output.find(":", s); - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str()); - s2+=2; - s = output.find("“", s2); - if(s == string::npos) - { - s = output.find("\"", s2); - s += 1; - } - else - s += 3; - if((s2 = output.find("(", s)) == string::npos) - s2 = output.find("<", s); - else if(s2 > output.find("<", s)) - s2 = output.find("<", s); - tmp = new char [output.substr(s,s2-s-1).length()+1]; - strcpy(tmp, output.substr(s,s2-s-1).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", tmp); - 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(output[s] == ')') - { - tmp = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", tmp); - mir_free(tmp); - s+=3; - s2 = output.find(">", s); - tmp = new char [output.substr(s,s2-s).length()+1]; - strcpy(tmp, output.substr(s,s2-s).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", tmp); - mir_free(tmp); - } - else - { - tmp = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); - mir_free(tmp); - } - DBDeleteContactSetting(hContact, szGPGModuleName, "bAlwatsTrust"); - } - } - ptmp = mir_wstrdup(toUTF16(output).c_str()); - MessageBox(0, ptmp, _T(""), MB_OK); - mir_free(ptmp); - DeleteFile(tmp2); - } -} \ No newline at end of file diff --git a/main.h b/main.h deleted file mode 100755 index 23627a4..0000000 --- a/main.h +++ /dev/null @@ -1,31 +0,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. -#ifndef MAIN_H -#define MAIN_H - -struct contact_data -{ - list msgs_to_send, msgs_to_pass; - string key_in_prescense; -}; - -extern std::map 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/messages.cpp b/messages.cpp deleted file mode 100755 index f2e3c35..0000000 --- a/messages.cpp +++ /dev/null @@ -1,1043 +0,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 "commonheaders.h" - - -wstring new_key; -HANDLE new_key_hcnt = NULL; -boost::mutex new_key_hcnt_mutex; -bool _terminate = false; -int returnNoError(HANDLE hContact); - -std::list sent_msgs; - -int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, DWORD timestamp) -{ - DWORD dbflags = DBEF_UTF; - { //check for gpg related data - wstring::size_type s1 = wstring::npos, s2 = wstring::npos; - - s1 = str.find(_T("-----BEGIN PGP MESSAGE-----")); - s2 = str.find(_T("-----END PGP MESSAGE-----")); - if((s2 != wstring::npos) && (s1 != wstring::npos)) - { //this is generic encrypted data block - void setSrmmIcon(HANDLE); - void setClistIcon(HANDLE); - bool isContactHaveKey(HANDLE hContact); - if(!isContactSecured(hContact)) - { - debuglog< user_data; - extern int item_num; - item_num = 0; //black magic here - user_data[1] = hContact; - ShowLoadPublicKeyDialog(); - } - else - { - DBWriteContactSettingByte(metaIsProtoMetaContacts(hContact)?metaGetMostOnline(hContact):hContact, szGPGModuleName, "GPGEncryption", 1); - setSrmmIcon(hContact); - setClistIcon(hContact); - } - if(isContactHaveKey(hContact)) - { - DBWriteContactSettingByte(metaIsProtoMetaContacts(hContact)?metaGetMostOnline(hContact):hContact, szGPGModuleName, "GPGEncryption", 1); - setSrmmIcon(hContact); - setClistIcon(hContact); - } - } - else if(MessageBox(0, _T("Do you want try to decrypt encrypted message ?"), _T("Warning"), MB_YESNO) == IDNO) - { - - HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); - return 0; - } - } - { - wstring::size_type p = 0; - while((p = str.find(_T("\r"), p)) != wstring::npos) - str.erase(p, 1); - } - s2 += _tcslen(_T("-----END PGP MESSAGE-----")); - char *tmp = mir_t2a(str.substr(s1,s2-s1).c_str()); - TCHAR *tmp2 = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - wstring path = tmp2; - wstring encfile = toUTF16(get_random(10)); - wstring decfile = toUTF16(get_random(10)); - path.append(_T("\\tmp\\")); - path.append(encfile); - DeleteFile(path.c_str()); - fstream f(path.c_str(), std::ios::out); - while(!f.is_open()) - f.open(path.c_str(), std::ios::out); - f<timed_join(boost::posix_time::seconds(10))) - { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<timed_join(boost::posix_time::seconds(10))) - { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<timed_join(boost::posix_time::seconds(10))) - { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<lParam); - if (!pre) - return CallService(MS_PROTO_CHAINRECV, w, l); - char *msg = pre->szMessage; - if (!msg) - return CallService(MS_PROTO_CHAINRECV, w, l); - wstring str = toUTF16(msg); - wstring::size_type s1 = wstring::npos, s2 = wstring::npos; - DWORD dbflags = DBEF_UTF; - if((str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos) && !metaIsProtoMetaContacts(ccs->hContact)) - { - s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); - s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); - if(s1 != wstring::npos && s2 != wstring::npos) - { - s2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")); - DBWriteContactSettingTString(ccs->hContact, szGPGModuleName, "GPGPubKey", str.substr(s1,s2-s1).c_str()); - DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 1); - { //gpg execute block - wstring cmd; - TCHAR tmp2[MAX_PATH] = {0}; - TCHAR *ptmp; - string output; - DWORD exitcode; - { - ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - _tcscpy(tmp2, ptmp); - mir_free(ptmp); - _tcscat(tmp2, _T("\\")); - _tcscat(tmp2, _T("temporary_exported.asc")); - DeleteFile(tmp2); - wfstream f(tmp2, std::ios::out); - while(!f.is_open()) - f.open(tmp2, std::ios::out); - ptmp = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "GPGPubKey", _T("")); - wstring new_key = ptmp; - mir_free(ptmp); - f<hContact, szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str()); - s2+=2; - s = output.find("“", s2); - if(s == string::npos) - { - s = output.find("\"", s2); - s += 1; - } - else - s += 3; - if((s2 = output.find("(", s)) == string::npos) - s2 = output.find("<", s); - else if(s2 > output.find("<", s)) - s2 = output.find("<", s); - tmp = new char [output.substr(s,s2-s-1).length()+1]; - strcpy(tmp, output.substr(s,s2-s-1).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(ccs->hContact, szGPGModuleName, "KeyMainName", tmp); - 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(output[s] == ')') - { - tmp = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(ccs->hContact, szGPGModuleName, "KeyComment", tmp); - mir_free(tmp); - s+=3; - s2 = output.find(">", s); - tmp = new char [output.substr(s,s2-s).length()+1]; - strcpy(tmp, output.substr(s,s2-s).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(ccs->hContact, szGPGModuleName, "KeyMainEmail", tmp); - mir_free(tmp); - } - else - { - tmp = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp, 0); - DBWriteContactSettingString(ccs->hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); - mir_free(tmp); - } - DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwatsTrust", 1); - void setSrmmIcon(HANDLE); - void setClistIcon(HANDLE); - setSrmmIcon(ccs->hContact); - setClistIcon(ccs->hContact); - if(metaIsSubcontact(ccs->hContact)) - { - setSrmmIcon(metaGetContact(ccs->hContact)); - setClistIcon(metaGetContact(ccs->hContact)); - HistoryLog(metaGetContact(ccs->hContact), "PGP Encryption turned on by key autoexchange feature"); - } - HistoryLog(ccs->hContact, "PGP Encryption turned on by key autoexchange feature"); - } - } - return 1; - } - } - if((str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) != wstring::npos)) - { - s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); - s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); - } - else if((str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")) != wstring::npos)) - { - s2 = str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")); - s1 = str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); - } - if((s2 != wstring::npos) && (s1 != wstring::npos)) - { //this is public key - if(metaIsProtoMetaContacts(ccs->hContact)) - { - HistoryLog(ccs->hContact, db_event(msg, 0, 0, dbflags)); - return 0; - } - debuglog<hContact, GCDNF_TCHAR)<<"\n"; - s1 = 0; - while((s1 = str.find(_T("\r"), s1)) != wstring::npos) - { - str.erase(s1, 1); - } - void ShowNewKeyDialog(); - if((str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) != wstring::npos)) - { - s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); - s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); - s2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")); - } - else if((str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")) != wstring::npos)) - { - s2 = str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")); - s1 = str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); - s2 += _tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----")); - } - new_key.append(str.substr(s1,s2-s1)); - new_key_hcnt_mutex.lock(); - new_key_hcnt = ccs->hContact; - ShowNewKeyDialog(); - HistoryLog(ccs->hContact, db_event(msg, 0, 0, dbflags)); - return 0; - } - if(bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && gpg_valid && gpg_keyexist) - { - char *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); - if(tmp[0]) - { - DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 0); - string str = "-----PGP KEY RESPONSE-----"; - str.append(tmp); - CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)str.c_str()); - DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 1); - } - mir_free(tmp); - if(!isContactHaveKey(ccs->hContact) && bAutoExchange && gpg_valid && gpg_keyexist) - { - LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); - DWORD uin = DBGetContactSettingDword(ccs->hContact, proto, "UIN", 0); - if(uin) - { - if(ServiceExists("ICQ"PS_ICQ_CHECKCAPABILITY)) - { - ICQ_CUSTOMCAP cap = {0}; - strcpy(cap.caps, "GPG AutoExchange"); - if(CallService("ICQ"PS_ICQ_CHECKCAPABILITY, (WPARAM)ccs->hContact, (LPARAM)&cap)) - CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); - } - } - else - { - TCHAR *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", _T("")); - if(jid[0]) - { - extern list Accounts; - list::iterator end = Accounts.end(); - for(list::iterator p = Accounts.begin(); p != end; p++) - { - TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid); - if(caps) - { - wstring str; - for(int i =0;;i++) - { - str.push_back(caps[i]); - if(caps[i] == '\0') - if(caps[i+1] == '\0') - break; - } - mir_free(caps); - if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) - CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)0, (LPARAM)"-----PGP KEY REQUEST-----"); - } - } - } - } - } - return 1; - } - if(!(strstr(msg, "-----BEGIN PGP MESSAGE-----") && strstr(msg, "-----END PGP MESSAGE-----"))) - return CallService(MS_PROTO_CHAINRECV, w, l); - boost::thread *thr = new boost::thread(boost::bind(RecvMsgSvc_func, ccs->hContact, str, msg, ccs->wParam, pre->timestamp)); - return returnNoError(ccs->hContact); -} - -int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) -{ - wstring str; - bool isansi = false; - DWORD dbflags = 0; - if(flags & PREF_UTF) - dbflags |= DBEF_UTF; - if(!metaIsSubcontact(hContact)) - str = toUTF16(msg); - else - {//workaround ... - wchar_t *tmp = mir_utf8decodeW(msg); - if(!tmp) - { - tmp = mir_a2t(msg); - isansi = true; - } - str.append(tmp); - mir_free(tmp); - } - if(bStripTags && bAppendTags) - { - std::wstring::size_type p; - for(p = str.find(inopentag); p != std::wstring::npos; p = str.find(inopentag)) - str.erase(p, _tcslen(inopentag)); - for(p = str.find(inclosetag); p != std::wstring::npos; p = str.find(inclosetag)) - str.erase(p, _tcslen(inclosetag)); - for(p = str.find(outopentag); p != std::wstring::npos; p = str.find(outopentag)) - str.erase(p, _tcslen(outopentag)); - for(p = str.find(outclosetag); p != std::wstring::npos; p = str.find(outclosetag)) - str.erase(p, _tcslen(outclosetag)); - } -/* for(std::wstring::size_type i = str.find(_T("\r\n")); i != std::wstring::npos; i = str.find(_T("\r\n"), i+1)) - str.replace(i, 2, _T("\n")); */ - string out; - DWORD code; - wstring cmd; - wstring file = toUTF16(get_random(10)); - wstring path; - extern bool bJabberAPI, bIsMiranda09; - char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); - if(!tmp[0]) - { - mir_free(tmp); - HistoryLog(hContact, db_event("Failed to encrypt message with GPG", 0,0, DBEF_SENT)); - hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG"); - mir_free(msg); - return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); - } - if(!bJabberAPI || !bIsMiranda09) //force jabber to handle encrypted message by itself - cmd += _T("--comment \"\" --no-version "); - if(DBGetContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 0)) - cmd += _T("--trust-model always "); - cmd += _T("--batch --yes -e -a -t -r "); - TCHAR *tmp2 = mir_a2t(tmp); - mir_free(tmp); - cmd += tmp2; - mir_free(tmp2); - cmd += _T(" \""); - tmp2 = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - path.append(tmp2); - cmd += tmp2; - mir_free(tmp2); - cmd += _T("\\tmp\\"); - cmd += file; - path.append(_T("\\tmp\\")); - path += file; - cmd += _T("\""); - { - char *tmp; - tmp = mir_strdup(toUTF8(str).c_str()); - fstream f(path.c_str(), std::ios::out); - while(!f.is_open()) - f.open(path.c_str(), std::ios::out); - f<lParam)); - if (!msg) - { - mir_free(msg); - return CallService(MS_PROTO_CHAINSEND, w, l); - } - if(strstr(msg,"-----BEGIN PGP MESSAGE-----")) - return CallService(MS_PROTO_CHAINSEND, w, l); - if(!isContactHaveKey(ccs->hContact)) - { - if(bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && gpg_valid) - { - void send_encrypted_msgs_thread(HANDLE hContact); - LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); - DWORD uin = DBGetContactSettingDword(ccs->hContact, proto, "UIN", 0); - if(uin) - { - if(ServiceExists("ICQ"PS_ICQ_CHECKCAPABILITY)) - { - ICQ_CUSTOMCAP cap = {0}; - strcpy(cap.caps, "GPG AutoExchange"); - if(CallService("ICQ"PS_ICQ_CHECKCAPABILITY, (WPARAM)ccs->hContact, (LPARAM)&cap)) - { - CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)ccs->wParam, (LPARAM)"-----PGP KEY REQUEST-----"); - hcontact_data[ccs->hContact].msgs_to_send.push_back(msg); - boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, ccs->hContact)); - mir_free(msg); - return returnNoError(ccs->hContact); - } - } - } - else - { - TCHAR *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", _T("")); - if(jid[0]) - { - extern list Accounts; - list::iterator end = Accounts.end(); - for(list::iterator p = Accounts.begin(); p != end; p++) - { - TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid); - if(caps) - { - wstring str; - for(int i =0;;i++) - { - str.push_back(caps[i]); - if(caps[i] == '\0') - if(caps[i+1] == '\0') - break; - } - mir_free(caps); - if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) - { - CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)ccs->wParam, (LPARAM)"-----PGP KEY REQUEST-----"); - hcontact_data[ccs->hContact].msgs_to_send.push_back(msg); - boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, ccs->hContact)); - mir_free(msg); - return returnNoError(ccs->hContact); - } - } - } - } - } - } - else - { - mir_free(msg); - return CallService(MS_PROTO_CHAINSEND, w, l); - } - } - if(!isContactSecured(ccs->hContact) || metaIsProtoMetaContacts(ccs->hContact)) - { - mir_free(msg); - return CallService(MS_PROTO_CHAINSEND, w, l); - } - boost::thread *thr = new boost::thread(boost::bind(SendMsgSvc_func, ccs->hContact, msg, (DWORD)ccs->wParam)); - return returnNoError(ccs->hContact); -} - -boost::mutex event_processing_mutex; - -int HookSendMsg(WPARAM w, LPARAM l) -{ - if(!l) - return 0; - DBEVENTINFO * dbei = (DBEVENTINFO*)l; - if(dbei->eventType != EVENTTYPE_MESSAGE) - return 0; - if(dbei->flags & DBEF_SENT) - { - if(strstr((char*)dbei->pBlob, "-----BEGIN PGP MESSAGE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY RESPONSE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----") || strstr((char*)dbei->pBlob, "-----PGP KEY RESPONSE-----")) //our service data, can be double added by metacontacts e.t.c. - return 1; - } - HANDLE hContact = (HANDLE)w; - if(isContactSecured(hContact) && (dbei->flags & DBEF_SENT)) //aggressive outgoing events filtering - { - if(!hcontact_data[hContact].msgs_to_pass.empty()) - { - event_processing_mutex.lock(); - std::list::iterator end = hcontact_data[hContact].msgs_to_pass.end(); - for(std::list::iterator i = hcontact_data[hContact].msgs_to_pass.begin(); i != end; ++i) - { - if(!strcmp((*i).c_str(), (char*)dbei->pBlob)) - { - hcontact_data[hContact].msgs_to_pass.erase(i); - debuglog<pBlob<<"\" passed event filter, contact "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<", message is in allowed list\n"; - event_processing_mutex.unlock(); - return 0; - } - } - event_processing_mutex.unlock(); - } - if(metaIsProtoMetaContacts(hContact) && !isContactSecured(metaGetMostOnline(hContact))) - return 0; - return 1; - } - if(!isContactSecured(hContact)) - { - debuglog<pBlob<<"\" passed event filter, contact "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" is unsecured\n"; - return 0; - } - if(!(dbei->flags & DBEF_SENT) && metaIsProtoMetaContacts((HANDLE)w)) - { - char tmp[29]; - strncpy(tmp, (char*)dbei->pBlob, 27); - tmp[28] = '\0'; - if(strstr(tmp, "-----BEGIN PGP MESSAGE-----")) - return 1; - } - return 0; -} - - -static BOOL CALLBACK DlgProcKeyPassword(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - char *inkeyid = NULL; - switch (msg) - { - case WM_INITDIALOG: - { - inkeyid = UniGetContactSettingUtf(new_key_hcnt, szGPGModuleName, "InKeyID", ""); - new_key_hcnt_mutex.unlock(); - TCHAR *tmp = NULL; - - SetWindowPos(hwndDlg, 0, key_password_rect.left, key_password_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); - TranslateDialogDefault(hwndDlg); - string questionstr = "Please enter password for key with ID: "; - questionstr += inkeyid; - SetDlgItemTextA(hwndDlg, IDC_KEYID, questionstr.c_str()); - EnableWindow(GetDlgItem(hwndDlg, IDC_DEFAULT_PASSWORD), 0); - return TRUE; - } - - - case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDOK: - { - TCHAR tmp[64]; - GetDlgItemText(hwndDlg, IDC_KEY_PASSWORD, tmp, 64); - if(tmp[0]) - { - extern TCHAR *password; - if(IsDlgButtonChecked(hwndDlg, IDC_SAVE_PASSWORD)) - { - if(inkeyid && inkeyid[0] && !IsDlgButtonChecked(hwndDlg, IDC_DEFAULT_PASSWORD)) - { - string dbsetting = "szKey_"; - dbsetting += inkeyid; - dbsetting += "_Password"; - DBWriteContactSettingTString(NULL, szGPGModuleName, dbsetting.c_str(), tmp); - } - else - DBWriteContactSettingTString(NULL, szGPGModuleName, "szKeyPassword", tmp); - } - if(password) - delete [] password; - password = new TCHAR [_tcslen(tmp)+1]; - _tcscpy(password, tmp); - } - mir_free(tmp); - mir_free(inkeyid); - DestroyWindow(hwndDlg); - break; - } - case IDCANCEL: - mir_free(inkeyid); - _terminate = true; - DestroyWindow(hwndDlg); - break; - default: - break; - } - - break; - } - - case WM_NOTIFY: - { -/* switch (((LPNMHDR)lParam)->code) - { - default: - EnableWindow(GetDlgItem(hwndDlg, IDC_DEFAULT_PASSWORD), IsDlgButtonChecked(hwndDlg, IDC_SAVE_PASSWORD)?1:0); - break; - }*/ - } - break; - case WM_CLOSE: - mir_free(inkeyid); - DestroyWindow(hwndDlg); - break; - case WM_DESTROY: - { - GetWindowRect(hwndDlg, &key_password_rect); - DBWriteContactSettingDword(NULL, szGPGModuleName, "PasswordWindowX", key_password_rect.left); - DBWriteContactSettingDword(NULL, szGPGModuleName, "PasswordWindowY", key_password_rect.top); - } - break; - - } - return FALSE; -} - -void ShowLoadKeyPasswordWindow() -{ - extern HINSTANCE hInst; - DialogBox(hInst, MAKEINTRESOURCE(IDD_KEY_PASSWD), NULL, (DLGPROC)DlgProcKeyPassword); -} diff --git a/metacontacts.cpp b/metacontacts.cpp deleted file mode 100755 index 1abc2aa..0000000 --- a/metacontacts.cpp +++ /dev/null @@ -1,88 +0,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 "commonheaders.h" - -extern bool bMetaContacts; - -bool metaIsProtoMetaContacts(HANDLE hContact) -{ - if(bMetaContacts) { - LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - if( proto && strcmp(proto,"MetaContacts")==0 ) { - return true; - } - } - return false; -} - - -bool metaIsDefaultSubContact(HANDLE hContact) -{ - - if(bMetaContacts) - return (HANDLE)CallService(MS_MC_GETDEFAULTCONTACT,(WPARAM)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0),0)==hContact; - return false; -} - - -HANDLE metaGetContact(HANDLE hContact) -{ - if(bMetaContacts) - if(metaIsSubcontact(hContact)) - return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0); - return NULL; -} -bool metaIsSubcontact(HANDLE hContact) -{ - if(bMetaContacts) - return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0); - return false; -} - - -HANDLE metaGetMostOnline(HANDLE hContact) -{ - - if(bMetaContacts) - if(metaIsProtoMetaContacts(hContact)) - return (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT,(WPARAM)hContact,0); - return NULL; -} -HANDLE metaGetDefault(HANDLE hContact) -{ - - if(bMetaContacts) - if(metaIsProtoMetaContacts(hContact)) - return (HANDLE)CallService(MS_MC_GETDEFAULTCONTACT,(WPARAM)hContact,0); - return NULL; -} - - -DWORD metaGetContactsNum(HANDLE hContact) -{ - if(bMetaContacts) - return CallService(MS_MC_GETNUMCONTACTS, (WPARAM)hContact, 0); - return 0; -} -HANDLE metaGetSubcontact(HANDLE hContact, int num) -{ - if(bMetaContacts) - return (HANDLE)CallService(MS_MC_GETSUBCONTACT, (WPARAM)hContact, (LPARAM)num); - return 0; -} - - diff --git a/metacontacts.h b/metacontacts.h deleted file mode 100755 index 8b8873e..0000000 --- a/metacontacts.h +++ /dev/null @@ -1,24 +0,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. - -bool metaIsProtoMetaContacts(HANDLE hContact); -bool metaIsDefaultSubContact(HANDLE hContact) ; -HANDLE metaGetContact(HANDLE hContact); -bool metaIsSubcontact(HANDLE hContact); -HANDLE metaGetMostOnline(HANDLE hContact); -HANDLE metaGetDefault(HANDLE hContact); -DWORD metaGetContactsNum(HANDLE hContact); -HANDLE metaGetSubcontact(HANDLE hContact, int num); \ No newline at end of file diff --git a/new_gpg.icproj b/new_gpg.icproj deleted file mode 100644 index f084bca..0000000 --- a/new_gpg.icproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - diff --git a/new_gpg.rc b/new_gpg.rc deleted file mode 100755 index fadafdc..0000000 --- a/new_gpg.rc +++ /dev/null @@ -1,419 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// Ðóññêèé (Ðîññèÿ) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) -LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT -#pragma code_page(1251) - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_LOAD_PUBLIC_KEY DIALOGEX 0, 0, 338, 190 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -CAPTION "Load Public GPG key" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - DEFPUSHBUTTON "ÎÊ",ID_OK,7,169,50,14 - PUSHBUTTON "Load from file",ID_LOAD_FROM_FILE,273,169,58,14 - EDITTEXT IDC_PUBLIC_KEY_EDIT,7,7,324,134,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | WS_VSCROLL,WS_EX_STATICEDGE - PUSHBUTTON "Select existing",IDC_SELECT_EXISTING,113,169,97,14 - CONTROL "Turn on encryption",IDC_ENABLE_ENCRYPTION,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,143,196,10 - PUSHBUTTON "Import key from keyserver",IDC_IMPORT,140,152,188,14,WS_DISABLED -END - -IDD_FIRST_RUN DIALOGEX 0, 0, 291, 230 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -CAPTION "Set own key" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - DEFPUSHBUTTON "ÎÊ",ID_OK,12,209,50,14,WS_DISABLED - CONTROL "",IDC_KEY_LIST,"SysListView32",LVS_REPORT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,44,277,105 - PUSHBUTTON "Generate key",IDC_GENERATE_KEY,8,152,74,14 - LTEXT "Select key for use",IDC_STATIC,16,33,186,8 - EDITTEXT IDC_KEY_PASSWORD,94,168,77,14,ES_PASSWORD | ES_AUTOHSCROLL - RTEXT "Key password:",IDC_STATIC,12,170,76,8 - PUSHBUTTON "Load other",IDC_OTHER,83,152,64,14 - PUSHBUTTON "Delete key",IDC_DELETE_KEY,149,152,70,14 - PUSHBUTTON "Generate and use random key",IDC_GENERATE_RANDOM,99,184,118,14 - LTEXT "",IDC_GENERATING_KEY,82,207,174,8 - LTEXT "Account:",IDC_STATIC,15,12,42,8 - LTEXT "key id: ",IDC_KEY_ID,178,12,99,8 - COMBOBOX IDC_ACCOUNT,66,9,104,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP -END - -IDD_BIN_PATH DIALOGEX 0, 0, 354, 108 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -CAPTION "Set GPG bin path and keyring home dir." -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - DEFPUSHBUTTON "Continue",ID_OK,7,87,50,14 - LTEXT "Home directory:",IDC_STATIC,9,34,325,8 - LTEXT "GnuPG binary:",IDC_STATIC,10,7,147,8 - PUSHBUTTON "Browse",IDC_SET_BIN_PATH,293,18,54,14 - PUSHBUTTON "Browse",IDC_SET_HOME_DIR,293,44,54,14 - EDITTEXT IDC_HOME_DIR,7,44,277,14,ES_AUTOHSCROLL - EDITTEXT IDC_BIN_PATH,7,17,277,14,ES_AUTOHSCROLL - PUSHBUTTON "Generate and use random key",IDC_GENERATE_RANDOM,166,87,118,14 - CONTROL "Turn on key autoexchange",IDC_AUTO_EXCHANGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,64,277,10 -END - -IDD_NEW_KEY DIALOGEX 0, 0, 427, 68 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -CAPTION "The new public key was recieved" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - DEFPUSHBUTTON "Import key",ID_IMPORT,9,47,46,14 - PUSHBUTTON "Accept and enable encryption",IDC_IMPORT_AND_USE,156,47,119,14 - PUSHBUTTON "Ignore",IDC_IGNORE_KEY,368,47,52,14 - CTEXT "Ñòàòè÷åñêèé",IDC_MESSAGE,18,25,392,8 - CTEXT "Ñòàòè÷åñêèé",IDC_KEY_FROM,16,12,395,8 -END - -IDD_KEY_GEN DIALOGEX 0, 0, 284, 169 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -CAPTION "Key Generation dialog" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - DEFPUSHBUTTON "OK",IDOK,7,148,50,14 - PUSHBUTTON "Cancel",IDCANCEL,227,148,50,14 - COMBOBOX IDC_KEY_TYPE,120,14,48,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_GROUP | WS_TABSTOP - EDITTEXT IDC_KEY_LENGTH,120,30,40,14,ES_AUTOHSCROLL | ES_NUMBER | WS_GROUP - EDITTEXT IDC_KEY_PASSWD,120,46,55,14,ES_AUTOHSCROLL | WS_GROUP - EDITTEXT IDC_KEY_REAL_NAME,120,61,55,14,ES_AUTOHSCROLL | WS_GROUP - EDITTEXT IDC_KEY_EMAIL,120,76,55,14,ES_AUTOHSCROLL | WS_GROUP - EDITTEXT IDC_KEY_COMMENT,120,91,55,14,ES_AUTOHSCROLL | WS_GROUP - EDITTEXT IDC_KEY_EXPIRE_DATE,120,106,55,14,ES_AUTOHSCROLL | WS_GROUP - LTEXT "Key type:",IDC_STATIC,8,16,96,8 - LTEXT "Key length:",IDC_STATIC,7,32,106,8 - LTEXT "Key password:",IDC_STATIC,7,49,105,8 - LTEXT "Real name:",IDC_STATIC,7,63,105,8 - LTEXT "Email:",IDC_STATIC,7,79,108,8 - LTEXT "Comment:",IDC_STATIC,7,92,107,8 - LTEXT "Expire date:",IDC_STATIC,7,109,111,8 - LTEXT "ex.: 2010-08-15",IDC_STATIC,182,108,75,8 - LTEXT "From 1024 to 4096",IDC_STATIC,168,33,89,8 - LTEXT "It can take a long time, be patient",IDC_GENERATING_TEXT,15,132,246,8 - LTEXT "0 - does not expire",IDC_STATIC,122,122,141,8 -END - -IDD_LOAD_EXISTING_KEY DIALOGEX 0, 0, 370, 257 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -CAPTION "Select existing public key from list" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - DEFPUSHBUTTON "ÎÊ",IDOK,7,236,50,14,WS_DISABLED - PUSHBUTTON "Cancel",IDCANCEL,313,236,50,14 - CONTROL "",IDC_EXISTING_KEY_LIST,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,14,356,217 -END - -IDD_KEY_PASSWD DIALOGEX 0, 0, 207, 108 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -CAPTION "Enter password for your secret key" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - DEFPUSHBUTTON "ÎÊ",IDOK,7,87,50,14 - PUSHBUTTON "Cancel",IDCANCEL,150,87,50,14 - EDITTEXT IDC_PASSWORD,13,38,179,14,ES_PASSWORD | ES_AUTOHSCROLL - LTEXT "Password:",IDC_STATIC,14,28,34,8 - CONTROL "Save password to database",IDC_SAVE_PASSWORD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,56,124,10 - LTEXT "",IDC_KEYID,14,14,179,8 - CONTROL "Default password",IDC_DEFAULT_PASSWORD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,67,151,10 -END - -IDD_IMPORT_KEY DIALOGEX 0, 0, 161, 81 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -CAPTION "Set GPG bin path and keyring home dir." -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - PUSHBUTTON "Import",IDC_IMPORT,15,56,50,14 - LTEXT "Select keyserver for key search:",IDC_STATIC,16,20,122,8 - COMBOBOX IDC_KEYSERVER,15,34,125,30,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_LOAD_PUBLIC_KEY, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 331 - TOPMARGIN, 7 - BOTTOMMARGIN, 183 - END - - IDD_FIRST_RUN, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 284 - VERTGUIDE, 15 - TOPMARGIN, 7 - BOTTOMMARGIN, 223 - HORZGUIDE, 20 - END - - IDD_BIN_PATH, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 347 - VERTGUIDE, 284 - TOPMARGIN, 7 - BOTTOMMARGIN, 101 - END - - IDD_NEW_KEY, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 420 - TOPMARGIN, 6 - BOTTOMMARGIN, 61 - END - - IDD_KEY_GEN, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 277 - TOPMARGIN, 7 - BOTTOMMARGIN, 162 - END - - IDD_LOAD_EXISTING_KEY, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 363 - TOPMARGIN, 7 - BOTTOMMARGIN, 250 - END - - IDD_KEY_PASSWD, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 200 - TOPMARGIN, 7 - BOTTOMMARGIN, 101 - END - - IDD_IMPORT_KEY, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 154 - TOPMARGIN, 7 - BOTTOMMARGIN, 74 - END -END -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_SECURED ICON "icons\\secured.ico" -IDI_UNSECURED ICON "icons\\unsecured.ico" - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,0,0,11 - PRODUCTVERSION 0,9,0,0 - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x0L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "041904b0" - BEGIN - VALUE "FileDescription", "new_gpg" - VALUE "FileVersion", "0.0.0.11" - VALUE "InternalName", "new_gpg" - VALUE "LegalCopyright", "Copyright (C) 2010-2011 sss" - VALUE "OriginalFilename", "new_gpg" - VALUE "ProductName", "new_gpg" - VALUE "ProductVersion", "0.9.0.0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x419, 1200 - END -END - -#endif // Ðóññêèé (Ðîññèÿ) resources -///////////////////////////////////////////////////////////////////////////// - - -///////////////////////////////////////////////////////////////////////////// -// Àíãëèéñêèé (ÑØÀ) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_OPT_GPG DIALOGEX 0, 0, 286, 214 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -FONT 8, "MS Shell Dlg", 400, 0, 0x0 -BEGIN - CONTROL "",IDC_USERLIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,17,272,112 - CTEXT "Userlist:",IDC_STATIC,25,7,201,8 - PUSHBUTTON "Export PubKey",IDC_SAVE_KEY_BUTTON,8,135,75,14 - PUSHBUTTON "Delete key",IDC_DELETE_KEY_BUTTON,90,135,70,14 - PUSHBUTTON "Select own key",IDC_SELECT_KEY,205,193,74,14 - CONTROL "Turn on debug log",IDC_DEBUG_LOG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,181,159,89,10 - EDITTEXT IDC_LOG_FILE_EDIT,11,157,98,14,ES_AUTOHSCROLL - PUSHBUTTON "Browse",IDC_LOG_FILE_SET,119,156,50,14 - CONTROL "Use jabber api on Miranda IM >= 0.9 (recomended)",IDC_JABBER_API, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,175,251,10 - LTEXT "Default key",IDC_CURRENT_KEY,12,196,110,8 - CONTROL "Encrypt file transfers",IDC_FILE_TRANSFERS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,185,137,10 - CONTROL "Automatic key exchange",IDC_AUTO_EXCHANGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,163,137,111,10 - PUSHBUTTON "Copy own key",IDC_COPY_KEY,127,193,74,14 -END - -IDD_OPT_GPG_BIN DIALOGEX 0, 0, 282, 214 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -FONT 8, "MS Shell Dlg", 400, 0, 0x0 -BEGIN - PUSHBUTTON "Browse",IDC_SET_BIN_PATH,216,17,60,14 - PUSHBUTTON "Browse",IDC_SET_HOME_DIR,217,44,57,14 - EDITTEXT IDC_BIN_PATH,7,17,195,14,ES_AUTOHSCROLL - EDITTEXT IDC_HOME_DIR,7,44,195,14,ES_AUTOHSCROLL - LTEXT "GnuPG binary:",IDC_STATIC,10,7,147,8 - LTEXT "Home directory:",IDC_STATIC,9,34,144,8 -END - -IDD_OPT_GPG_MESSAGES DIALOGEX 0, 0, 302, 241 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -FONT 8, "MS Shell Dlg", 400, 0, 0x0 -BEGIN - CONTROL "Add tags to encoded and decoded messages",IDC_APPEND_TAGS, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,3,65,243,10 - EDITTEXT IDC_IN_OPEN_TAG,39,20,88,14,ES_AUTOHSCROLL - EDITTEXT IDC_IN_CLOSE_TAG,151,20,90,14,ES_AUTOHSCROLL - LTEXT "Incomming message tags:",IDC_STATIC,15,10,84,8 - LTEXT "Outgoing message tags:",IDC_STATIC,13,36,79,8 - RTEXT "Open:",IDC_STATIC,13,23,26,8 - RTEXT "Close:",IDC_STATIC,127,23,23,8 - EDITTEXT IDC_OUT_OPEN_TAG,39,46,88,14,ES_AUTOHSCROLL - EDITTEXT IDC_OUT_CLOSE_TAG,151,46,90,14,ES_AUTOHSCROLL - RTEXT "Open:",IDC_STATIC,13,49,26,8 - RTEXT "Close:",IDC_STATIC,127,49,23,8 - CONTROL "Strip all tags in outgoing messages",IDC_STRIP_TAGS, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,3,76,233,10 -END - -IDD_OPT_GPG_ADVANCED DIALOGEX 0, 0, 286, 214 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -FONT 8, "MS Shell Dlg", 400, 0, 0x0 -BEGIN - CONTROL "Turn on presence signing (Jabber)",IDC_PRESCENSE_SUBSCRIPTION, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,9,190,10 -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_OPT_GPG, DIALOG - BEGIN - END - - IDD_OPT_GPG_BIN, DIALOG - BEGIN - END - - IDD_OPT_GPG_MESSAGES, DIALOG - BEGIN - END - - IDD_OPT_GPG_ADVANCED, DIALOG - BEGIN - VERTGUIDE, 12 - END -END -#endif // APSTUDIO_INVOKED - -#endif // Àíãëèéñêèé (ÑØÀ) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/new_gpg.sln b/new_gpg.sln deleted file mode 100755 index 6a74e17..0000000 --- a/new_gpg.sln +++ /dev/null @@ -1,54 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "new_gpg", "new_gpg.vcxproj", "{F29D0C8D-141A-43CF-86B2-34A04653F8D4}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug x64|Win32 = Debug x64|Win32 - Debug x64|x64 = Debug x64|x64 - Debug(service)|Win32 = Debug(service)|Win32 - Debug(service)|x64 = Debug(service)|x64 - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release Unicode (service only)(static)|Win32 = Release Unicode (service only)(static)|Win32 - Release Unicode (service only)(static)|x64 = Release Unicode (service only)(static)|x64 - Release Unicode (service only)|Win32 = Release Unicode (service only)|Win32 - Release Unicode (service only)|x64 = Release Unicode (service only)|x64 - Release Unicode (static) x64|Win32 = Release Unicode (static) x64|Win32 - Release Unicode (static) x64|x64 = Release Unicode (static) x64|x64 - Release Unicode (static)|Win32 = Release Unicode (static)|Win32 - Release Unicode (static)|x64 = Release Unicode (static)|x64 - Release Unicode|Win32 = Release Unicode|Win32 - Release Unicode|x64 = Release Unicode|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Debug x64|Win32.ActiveCfg = Debug x64|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Debug x64|x64.ActiveCfg = Debug x64|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Debug x64|x64.Build.0 = Debug x64|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Debug(service)|Win32.ActiveCfg = Debug(service)|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Debug(service)|x64.ActiveCfg = Debug(service)|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Debug(service)|x64.Build.0 = Debug(service)|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Debug|Win32.ActiveCfg = Debug|Win32 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Debug|x64.ActiveCfg = Debug|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Debug|x64.Build.0 = Debug|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode (service only)(static)|Win32.ActiveCfg = Release Unicode (service only)(static)|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode (service only)(static)|x64.ActiveCfg = Release Unicode (service only)(static)|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode (service only)(static)|x64.Build.0 = Release Unicode (service only)(static)|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode (service only)|Win32.ActiveCfg = Release Unicode (service only)|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode (service only)|x64.ActiveCfg = Release Unicode (service only)|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode (service only)|x64.Build.0 = Release Unicode (service only)|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode (static) x64|Win32.ActiveCfg = Release Unicode (static) x64|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode (static) x64|x64.ActiveCfg = Release Unicode (static) x64|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode (static) x64|x64.Build.0 = Release Unicode (static) x64|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode (static)|Win32.ActiveCfg = Release Unicode (static)|Win32 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode (static)|x64.ActiveCfg = Release Unicode (static)|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode (static)|x64.Build.0 = Release Unicode (static)|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode|Win32.ActiveCfg = Release Unicode|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode|x64.ActiveCfg = Release Unicode|x64 - {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release Unicode|x64.Build.0 = Release Unicode|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/new_gpg.vcproj b/new_gpg.vcproj deleted file mode 100644 index 033d60a..0000000 --- a/new_gpg.vcproj +++ /dev/null @@ -1,941 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/new_gpg.vcxproj b/new_gpg.vcxproj deleted file mode 100755 index 17f84a7..0000000 --- a/new_gpg.vcxproj +++ /dev/null @@ -1,1352 +0,0 @@ - - - - - Debug x64 - Win32 - - - Debug x64 - x64 - - - Debug(service) - Win32 - - - Debug(service) - x64 - - - Debug - Win32 - - - Debug - x64 - - - Release Unicode (service only)(static) - Win32 - - - Release Unicode (service only)(static) - x64 - - - Release Unicode (service only) - Win32 - - - Release Unicode (service only) - x64 - - - Release Unicode (static) x64 - Win32 - - - Release Unicode (static) x64 - x64 - - - Release Unicode (static) - Win32 - - - Release Unicode (static) - x64 - - - Release Unicode - Win32 - - - Release Unicode - x64 - - - - {F29D0C8D-141A-43CF-86B2-34A04653F8D4} - new_gpg - - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - DynamicLibrary - false - Unicode - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(SolutionDir)$(Configuration)\ - $(SolutionDir)$(Configuration)\ - $(Configuration)\ - $(Configuration)\ - false - false - .\Debug\ - .\Debug\ - .\Debug\ - .\Debug\ - true - true - true - true - $(SolutionDir)$(Configuration)\ - $(SolutionDir)$(Configuration)\ - $(SolutionDir)$(Configuration)\ - $(SolutionDir)$(Configuration)\ - $(Configuration)\ - $(Configuration)\ - $(Configuration)\ - $(Configuration)\ - false - false - false - false - $(SolutionDir)$(Configuration)\ - $(SolutionDir)$(Configuration)\ - $(Configuration)\ - $(Configuration)\ - false - false - $(SolutionDir)$(Configuration)\ - $(SolutionDir)$(Configuration)\ - $(Configuration)\ - $(Configuration)\ - false - false - $(Configuration)\ - $(Configuration)\ - $(Configuration)\ - $(Configuration)\ - true - true - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - AllRules.ruleset - AllRules.ruleset - - - - - - - - - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - AllRules.ruleset - AllRules.ruleset - - - - - - - - - AllRules.ruleset - AllRules.ruleset - - - - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - .\Release Unicode/testplug.tlb - - - - - Full - OnlyExplicitInline - Size - true - true - X:\install\git\miranda\mim_plugs;X:\install\git\miranda\miranda-im\miranda\include;../../include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - StreamingSIMDExtensions - Precise - .\Release Unicode/testplug.pch - .\Release Unicode/ - .\Release Unicode/ - .\Release Unicode/ - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0809 - - - libgpgme-11.lib;libgcrypt-11.lib;libksba-8.lib;%(AdditionalDependencies) - true - X:\install\git\miranda\mim_plugs\lib;%(AdditionalLibraryDirectories) - true - true - true - UseLinkTimeCodeGeneration - false - - - .\Release Unicode/testplug.lib - - - true - .\Release Unicode/testplug.bsc - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - .\Release Unicode/testplug.tlb - - - - - Full - OnlyExplicitInline - Size - true - true - X:\install\git\miranda\mim_plugs;X:\install\git\miranda\miranda-im\miranda\include;../../include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - StreamingSIMDExtensions - Precise - .\Release Unicode/testplug.pch - .\Release Unicode/ - .\Release Unicode/ - .\Release Unicode/ - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0809 - - - libgpgme-11.lib;libgcrypt-11.lib;libksba-8.lib;%(AdditionalDependencies) - true - X:\install\git\miranda\mim_plugs\lib;%(AdditionalLibraryDirectories) - true - true - true - UseLinkTimeCodeGeneration - false - - - .\Release Unicode/testplug.lib - - - true - .\Release Unicode/testplug.bsc - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - .\Debug/testplug.tlb - - - - - Disabled - x:\temp\windows\libs\utf8cpp\include;x:\temp\windows\libs\boost;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - Use - commonheaders.h - c:\temp\new_gpg.pch - - - .\Debug/ - .\Debug/ - .\Debug/ - true - Level3 - true - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x0809 - - - shlwapi.lib;%(AdditionalDependencies) - true - x:\temp\windows\libs\boost\lib;%(AdditionalLibraryDirectories) - true - true - false - false - false - - - .\Debug/testplug.lib - - - true - .\Debug/testplug.bsc - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - .\Debug/testplug.tlb - - - - - Disabled - x:\temp\windows\libs\utf8cpp\include;x:\temp\windows\libs\Boost\include;X:\install\git\miranda\miranda_ng_svn\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - Use - commonheaders.h - c:\temp\new_gpg.pch - All - .\Debug/ - .\Debug/ - .\Debug/ - true - Level3 - true - ProgramDatabase - true - true - CompileAsCpp - true - - - _DEBUG;%(PreprocessorDefinitions) - 0x0809 - - - shlwapi.lib;%(AdditionalDependencies) libboost_thread-vc100-mt-sgd-1_51.lib - true - X:\install\git\miranda\miranda_ng_svn\bin10\lib;x:\temp\windows\libs\Boost\lib;%(AdditionalLibraryDirectories) - true - true - true - false - false - - - .\Debug/testplug.lib - c:\debug\$(TargetName).pdb - - - true - .\Debug/testplug.bsc - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - .\Debug/testplug.tlb - - - - - Disabled - x:\temp\windows\libs\utf8cpp\include;X:\temp\windows\libs\Boost\include;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - Use - commonheaders.h - c:\temp\new_gpg.pch - - - .\Debug/ - .\Debug/ - .\Debug/ - true - Level3 - true - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x0809 - - - shlwapi.lib;%(AdditionalDependencies) - true - X:\temp\windows\libs\Boost\lib64;%(AdditionalLibraryDirectories) - true - true - false - false - false - - - .\Debug/testplug.lib - c:\debug\$(TargetName).pdb - - - true - .\Debug/testplug.bsc - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - .\Debug/testplug.tlb - - - - - Disabled - x:\temp\windows\libs\utf8cpp\include;x:\temp\windows\libs\boost;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - Use - commonheaders.h - c:\temp\new_gpg.pch - - - .\Debug/ - .\Debug/ - .\Debug/ - true - Level3 - true - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x0809 - - - shlwapi.lib;%(AdditionalDependencies) libboost_thread-vc100-mt-sgd-1_45-64.lib - true - x:\temp\windows\libs\boost\lib;%(AdditionalLibraryDirectories) - true - true - false - false - false - - - .\Debug/testplug.lib - - - true - .\Debug/testplug.bsc - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - .\Release Unicode (static)/testplug.tlb - - - - - MinSpace - OnlyExplicitInline - Size - true - true - x:\temp\windows\libs\utf8cpp\include;C:\Boost\include\boost-1_45;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions) - true - MultiThreaded - true - StreamingSIMDExtensions - Precise - Use - commonheaders.h - c:\temp\new_gpg.pch - .\Release Unicode (static)/ - .\Release Unicode (static)/ - .\Release Unicode (static)/ - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0809 - - - shlwapi.lib;%(AdditionalDependencies) - true - x:\temp\windows\libs\boost\lib;%(AdditionalLibraryDirectories) - false - NotSet - true - true - UseLinkTimeCodeGeneration - false - - - .\Release Unicode (static)/testplug.lib - - - true - .\Release Unicode (static)/testplug.bsc - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - .\Release Unicode (static)/testplug.tlb - - - - - MinSpace - OnlyExplicitInline - Size - true - true - x:\temp\windows\libs\utf8cpp\include;X:\temp\windows\libs\Boost\include;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include - WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions) - true - MultiThreaded - true - StreamingSIMDExtensions - Precise - Use - commonheaders.h - c:\temp\new_gpg.pch - .\Release Unicode (static)/ - .\Release Unicode (static)/ - .\Release Unicode (static)/ - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0809 - - - shlwapi.lib;%(AdditionalDependencies) - true - X:\temp\windows\libs\Boost\lib;%(AdditionalLibraryDirectories) - true - NotSet - true - true - UseLinkTimeCodeGeneration - false - - - .\Release Unicode (static)/testplug.lib - c:\debug\$(TargetName).pdb - - - true - .\Release Unicode (static)/testplug.bsc - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - .\Release Unicode (static)/testplug.tlb - - - - - MinSpace - OnlyExplicitInline - Size - true - true - x:\temp\windows\libs\utf8cpp\include;x:\temp\windows\libs\Boost\include;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions) - true - MultiThreaded - true - StreamingSIMDExtensions - Precise - Use - commonheaders.h - c:\temp\new_gpg.pch - .\Release Unicode (static)/ - .\Release Unicode (static)/ - .\Release Unicode (static)/ - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0809 - - - shlwapi.lib;%(AdditionalDependencies) - true - x:\temp\windows\libs\Boost\lib64;%(AdditionalLibraryDirectories) - true - NotSet - true - true - UseLinkTimeCodeGeneration - false - - - .\Release Unicode (static)/testplug.lib - c:\debug\$(TargetName).pdb - - - true - .\Release Unicode (static)/testplug.bsc - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - .\Release Unicode (static)/testplug.tlb - - - - - MinSpace - OnlyExplicitInline - Size - true - true - x:\temp\windows\libs\utf8cpp\include;x:\temp\windows\libs\boost;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions) - true - MultiThreaded - true - StreamingSIMDExtensions - Precise - Use - commonheaders.h - c:\temp\new_gpg.pch - .\Release Unicode (static)/ - .\Release Unicode (static)/ - .\Release Unicode (static)/ - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0809 - - - shlwapi.lib;%(AdditionalDependencies) - true - x:\temp\windows\libs\boost\lib;%(AdditionalLibraryDirectories) - false - NotSet - true - true - UseLinkTimeCodeGeneration - false - - - .\Release Unicode (static)/testplug.lib - - - true - .\Release Unicode (static)/testplug.bsc - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - .\Release Unicode (static)/testplug.tlb - - - - - Full - OnlyExplicitInline - Size - true - true - ../../include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - true - MultiThreaded - true - StreamingSIMDExtensions - Precise - .\Release Unicode (static)/testplug.pch - .\Release Unicode (static)/ - .\Release Unicode (static)/ - .\Release Unicode (static)/ - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0809 - - - true - true - true - true - UseLinkTimeCodeGeneration - false - - - .\Release Unicode (static)/testplug.lib - - - true - .\Release Unicode (static)/testplug.bsc - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - .\Release Unicode (static)/testplug.tlb - - - - - Full - OnlyExplicitInline - Size - true - true - ../../include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - true - MultiThreaded - true - StreamingSIMDExtensions - Precise - .\Release Unicode (static)/testplug.pch - .\Release Unicode (static)/ - .\Release Unicode (static)/ - .\Release Unicode (static)/ - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0809 - - - true - true - true - true - UseLinkTimeCodeGeneration - false - - - .\Release Unicode (static)/testplug.lib - - - true - .\Release Unicode (static)/testplug.bsc - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - .\Release Unicode (static)/testplug.tlb - - - - - Full - OnlyExplicitInline - Size - true - true - ../../include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - StreamingSIMDExtensions - Precise - .\Release Unicode (static)/testplug.pch - .\Release Unicode (static)/ - .\Release Unicode (static)/ - .\Release Unicode (static)/ - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0809 - - - true - true - true - true - UseLinkTimeCodeGeneration - false - - - .\Release Unicode (static)/testplug.lib - - - true - .\Release Unicode (static)/testplug.bsc - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - .\Release Unicode (static)/testplug.tlb - - - - - Full - OnlyExplicitInline - Size - true - true - ../../include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - StreamingSIMDExtensions - Precise - .\Release Unicode (static)/testplug.pch - .\Release Unicode (static)/ - .\Release Unicode (static)/ - .\Release Unicode (static)/ - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0809 - - - true - true - true - true - UseLinkTimeCodeGeneration - false - - - .\Release Unicode (static)/testplug.lib - - - true - .\Release Unicode (static)/testplug.bsc - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - .\Debug/testplug.tlb - - - - - Disabled - ../../include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - .\Debug/testplug.pch - .\Debug/ - .\Debug/ - .\Debug/ - Level3 - true - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x0809 - - - true - true - false - - - .\Debug/testplug.lib - - - true - .\Debug/testplug.bsc - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - .\Debug/testplug.tlb - - - - - Disabled - ../../include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - .\Debug/testplug.pch - .\Debug/ - .\Debug/ - .\Debug/ - Level3 - true - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x0809 - - - true - true - false - - - .\Debug/testplug.lib - - - true - .\Debug/testplug.bsc - - - - - Use - NotUsing - Use - Use - Use - Use - Use - Use - commonheaders.h - commonheaders.h - commonheaders.h - commonheaders.h - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - - - Use - NotUsing - Use - Use - Use - Use - Use - Use - commonheaders.h - commonheaders.h - commonheaders.h - commonheaders.h - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - - - Use - NotUsing - Use - Use - Use - Use - Use - Use - commonheaders.h - commonheaders.h - commonheaders.h - commonheaders.h - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - - - Create - NotUsing - Create - Create - commonheaders.h - commonheaders.h - commonheaders.h - commonheaders.h - Create - Create - Create - Create - commonheaders.h - commonheaders.h - commonheaders.h - commonheaders.h - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - - - Use - NotUsing - Use - Use - Use - Use - Use - Use - commonheaders.h - commonheaders.h - commonheaders.h - commonheaders.h - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - - - NotUsing - - - Use - NotUsing - Use - Use - Use - Use - Use - Use - commonheaders.h - commonheaders.h - commonheaders.h - commonheaders.h - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - - - Use - NotUsing - Use - Use - Use - Use - Use - Use - commonheaders.h - commonheaders.h - commonheaders.h - commonheaders.h - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - - - Use - NotUsing - Use - Use - Use - Use - Use - Use - commonheaders.h - commonheaders.h - commonheaders.h - commonheaders.h - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - - - Use - NotUsing - Use - Use - Use - Use - Use - Use - commonheaders.h - commonheaders.h - commonheaders.h - commonheaders.h - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - - - Use - NotUsing - Use - Use - Use - Use - Use - Use - commonheaders.h - commonheaders.h - commonheaders.h - commonheaders.h - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - - - Use - NotUsing - Use - Use - Use - Use - Use - Use - commonheaders.h - commonheaders.h - commonheaders.h - commonheaders.h - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - c:\temp\new_gpg.pch - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/new_gpg_10.sln b/new_gpg_10.sln new file mode 100755 index 0000000..293170a --- /dev/null +++ b/new_gpg_10.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "new_gpg", "new_gpg_10.vcxproj", "{F29D0C8D-141A-43CF-86B2-34A04653F8D4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Debug|Win32.ActiveCfg = Debug|Win32 + {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Debug|Win32.Build.0 = Debug|Win32 + {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release|Win32.ActiveCfg = Release|Win32 + {F29D0C8D-141A-43CF-86B2-34A04653F8D4}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/new_gpg_10.vcxproj b/new_gpg_10.vcxproj new file mode 100755 index 0000000..0adc022 --- /dev/null +++ b/new_gpg_10.vcxproj @@ -0,0 +1,842 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + + + + + + + + NotUsing + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {F29D0C8D-141A-43CF-86B2-34A04653F8D4} + new_gpg + new_gpg + + + + DynamicLibrary + false + Unicode + + + DynamicLibrary + false + Unicode + + + DynamicLibrary + false + Unicode + + + DynamicLibrary + false + Unicode + + + DynamicLibrary + false + Unicode + + + DynamicLibrary + false + Unicode + + + DynamicLibrary + false + Unicode + + + DynamicLibrary + false + Unicode + + + DynamicLibrary + false + Unicode + + + DynamicLibrary + false + Unicode + + + DynamicLibrary + false + Unicode + + + DynamicLibrary + false + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)$(Configuration)\ + $(SolutionDir)$(Configuration)\Plugins\ + $(Configuration)\ + $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ + false + false + .\Debug\ + $(SolutionDir)$(Configuration)\Plugins\ + .\Debug\ + $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ + true + true + true + $(SolutionDir)$(Configuration)\ + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + $(Configuration)\ + false + false + $(SolutionDir)$(Configuration)\ + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + $(Configuration)\ + false + false + $(SolutionDir)$(Configuration)\ + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + $(Configuration)\ + false + false + $(Configuration)\ + $(Configuration)\ + true + AllRules.ruleset + + + AllRules.ruleset + AllRules.ruleset + AllRules.ruleset + + + + + + + AllRules.ruleset + AllRules.ruleset + + + + + AllRules.ruleset + AllRules.ruleset + + + + + AllRules.ruleset + AllRules.ruleset + + + + + AllRules.ruleset + AllRules.ruleset + + + + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + .\Release Unicode/testplug.tlb + + + + + Full + OnlyExplicitInline + Size + true + true + X:\install\git\miranda\mim_plugs;X:\install\git\miranda\miranda-im\miranda\include;../../include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions) + true + MultiThreadedDLL + true + StreamingSIMDExtensions + Precise + .\Release Unicode/testplug.pch + .\Release Unicode/ + .\Release Unicode/ + .\Release Unicode/ + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0809 + + + libgpgme-11.lib;libgcrypt-11.lib;libksba-8.lib;%(AdditionalDependencies) + true + X:\install\git\miranda\mim_plugs\lib;%(AdditionalLibraryDirectories) + true + true + true + UseLinkTimeCodeGeneration + false + + + .\Release Unicode/testplug.lib + + + true + .\Release Unicode/testplug.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + .\Release Unicode/testplug.tlb + + + + + Full + OnlyExplicitInline + Size + true + true + X:\temp\windows\libs\utf8cpp\include;x:\temp\windows\libs\Boost\include;X:\install\git\miranda\miranda_ng_svn\include + WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions) + true + MultiThreadedDLL + true + StreamingSIMDExtensions + Fast + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0809 + + + shlwapi.lib;%(AdditionalDependencies) + true + X:\temp\windows\libs\Boost\lib32;X:\install\git\miranda\miranda_ng_svn\bin10\lib;%(AdditionalLibraryDirectories) + true + true + true + UseLinkTimeCodeGeneration + false + + + .\Release Unicode/testplug.lib + + + true + .\Release Unicode/testplug.bsc + + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + .\Debug/testplug.tlb + + + + + Disabled + x:\temp\windows\libs\utf8cpp\include;x:\temp\windows\libs\boost;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + Use + commonheaders.h + c:\temp\new_gpg.pch + + + .\Debug/ + .\Debug/ + .\Debug/ + true + Level3 + true + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x0809 + + + shlwapi.lib;%(AdditionalDependencies) + true + x:\temp\windows\libs\boost\lib;%(AdditionalLibraryDirectories) + true + true + false + false + false + + + .\Debug/testplug.lib + + + true + .\Debug/testplug.bsc + + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + .\Debug/testplug.tlb + + + + + Disabled + X:\temp\windows\libs\utf8cpp\include;x:\temp\windows\libs\Boost\include;X:\install\git\miranda\miranda_ng_svn\include + WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebugDLL + NotUsing + commonheaders.h + All + true + Level3 + true + true + true + CompileAsCpp + true + + + _DEBUG;%(PreprocessorDefinitions) + 0x0809 + + + shlwapi.lib;%(AdditionalDependencies) + true + X:\temp\windows\libs\Boost\lib32;X:\install\git\miranda\miranda_ng_svn\bin10\lib;%(AdditionalLibraryDirectories) + true + true + true + false + false + + + $(IntDir)$(TargetName).lib + $(TargetDir)$(TargetName).pdb + + + true + .\Debug/testplug.bsc + + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + .\Debug/testplug.tlb + + + + + Disabled + x:\temp\windows\libs\utf8cpp\include;X:\temp\windows\libs\Boost\include;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + Use + commonheaders.h + c:\temp\new_gpg.pch + + + .\Debug/ + .\Debug/ + .\Debug/ + true + Level3 + true + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x0809 + + + shlwapi.lib;%(AdditionalDependencies) + true + X:\temp\windows\libs\Boost\lib64;%(AdditionalLibraryDirectories) + true + true + false + false + false + + + .\Debug/testplug.lib + c:\debug\$(TargetName).pdb + + + true + .\Debug/testplug.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + .\Release Unicode (static)/testplug.tlb + + + + + MinSpace + OnlyExplicitInline + Size + true + true + x:\temp\windows\libs\utf8cpp\include;C:\Boost\include\boost-1_45;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions) + true + MultiThreaded + true + StreamingSIMDExtensions + Precise + Use + commonheaders.h + c:\temp\new_gpg.pch + .\Release Unicode (static)/ + .\Release Unicode (static)/ + .\Release Unicode (static)/ + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0809 + + + shlwapi.lib;%(AdditionalDependencies) + true + x:\temp\windows\libs\boost\lib;%(AdditionalLibraryDirectories) + false + NotSet + true + true + UseLinkTimeCodeGeneration + false + + + .\Release Unicode (static)/testplug.lib + + + true + .\Release Unicode (static)/testplug.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + .\Release Unicode (static)/testplug.tlb + + + + + MinSpace + OnlyExplicitInline + Size + true + true + x:\temp\windows\libs\utf8cpp\include;x:\temp\windows\libs\Boost\include;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions) + true + MultiThreaded + true + StreamingSIMDExtensions + Precise + Use + commonheaders.h + c:\temp\new_gpg.pch + .\Release Unicode (static)/ + .\Release Unicode (static)/ + .\Release Unicode (static)/ + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0809 + + + shlwapi.lib;%(AdditionalDependencies) + true + x:\temp\windows\libs\Boost\lib64;%(AdditionalLibraryDirectories) + true + NotSet + true + true + UseLinkTimeCodeGeneration + false + + + .\Release Unicode (static)/testplug.lib + c:\debug\$(TargetName).pdb + + + true + .\Release Unicode (static)/testplug.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + .\Release Unicode (static)/testplug.tlb + + + + + Full + OnlyExplicitInline + Size + true + true + ../../include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + StreamingSIMDExtensions + Precise + .\Release Unicode (static)/testplug.pch + .\Release Unicode (static)/ + .\Release Unicode (static)/ + .\Release Unicode (static)/ + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0809 + + + true + true + true + true + UseLinkTimeCodeGeneration + false + + + .\Release Unicode (static)/testplug.lib + + + true + .\Release Unicode (static)/testplug.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + .\Release Unicode (static)/testplug.tlb + + + + + Full + OnlyExplicitInline + Size + true + true + ../../include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + StreamingSIMDExtensions + Precise + .\Release Unicode (static)/testplug.pch + .\Release Unicode (static)/ + .\Release Unicode (static)/ + .\Release Unicode (static)/ + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0809 + + + true + true + true + true + UseLinkTimeCodeGeneration + false + + + .\Release Unicode (static)/testplug.lib + + + true + .\Release Unicode (static)/testplug.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + .\Release Unicode (static)/testplug.tlb + + + + + Full + OnlyExplicitInline + Size + true + true + ../../include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreadedDLL + true + StreamingSIMDExtensions + Precise + .\Release Unicode (static)/testplug.pch + .\Release Unicode (static)/ + .\Release Unicode (static)/ + .\Release Unicode (static)/ + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0809 + + + true + true + true + true + UseLinkTimeCodeGeneration + false + + + .\Release Unicode (static)/testplug.lib + + + true + .\Release Unicode (static)/testplug.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + .\Release Unicode (static)/testplug.tlb + + + + + Full + OnlyExplicitInline + Size + true + true + ../../include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreadedDLL + true + StreamingSIMDExtensions + Precise + .\Release Unicode (static)/testplug.pch + .\Release Unicode (static)/ + .\Release Unicode (static)/ + .\Release Unicode (static)/ + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0809 + + + true + true + true + true + UseLinkTimeCodeGeneration + false + + + .\Release Unicode (static)/testplug.lib + + + true + .\Release Unicode (static)/testplug.bsc + + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + .\Debug/testplug.tlb + + + + + Disabled + ../../include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + .\Debug/testplug.pch + .\Debug/ + .\Debug/ + .\Debug/ + Level3 + true + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x0809 + + + true + true + false + + + .\Debug/testplug.lib + + + true + .\Debug/testplug.bsc + + + + + + + + + + + \ No newline at end of file diff --git a/new_gpg_10.vcxproj.filters b/new_gpg_10.vcxproj.filters new file mode 100755 index 0000000..37e663c --- /dev/null +++ b/new_gpg_10.vcxproj.filters @@ -0,0 +1,103 @@ + + + + + {56a6d5fd-c491-4d42-95e0-d0e98979acff} + + + {8159144c-7020-4568-8bb4-53f4699faac6} + + + {65abe24a-f835-47f5-9ebf-fbd3f55f993c} + + + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + + + Resources + + + + + Resources + + + Resources + + + \ No newline at end of file diff --git a/new_gpg_lang_ru.txt b/new_gpg_lang_ru.txt old mode 100644 new mode 100755 diff --git a/options.cpp b/options.cpp deleted file mode 100755 index a990003..0000000 --- a/options.cpp +++ /dev/null @@ -1,1386 +0,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 "commonheaders.h" - -extern HINSTANCE hInst; - -static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -static BOOL CALLBACK DlgProcGpgMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -static BOOL CALLBACK DlgProcGpgAdvOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); - -BOOL CheckStateLoadDB(HWND hwndDlg, int idCtrl, const char* szSetting, BYTE bDef) -{ - BOOL state = DBGetContactSettingByte(NULL, szGPGModuleName, szSetting, bDef); - CheckDlgButton(hwndDlg, idCtrl, state); - return state; -} - -BOOL CheckStateStoreDB(HWND hwndDlg, int idCtrl, const char* szSetting) -{ - BOOL state = IsDlgButtonChecked(hwndDlg, idCtrl); - DBWriteContactSettingByte(NULL, szGPGModuleName, szSetting, (BYTE)state); - return state; -} - - -int GpgOptInit(WPARAM wParam,LPARAM lParam) -{ - OPTIONSDIALOGPAGE odp = { 0 }; - odp.cbSize = sizeof(odp); - odp.hInstance = hInst; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_GPG); - odp.pszTitle = szGPGModuleName; - odp.pszGroup = "Services"; - odp.pszTab = "Main"; - odp.flags=ODPF_BOLDGROUPS; - odp.pfnDlgProc = (DLGPROC)DlgProcGpgOpts; - Options_AddPage(wParam, &odp); - - ZeroMemory(&odp, sizeof(odp)); - - odp.cbSize = sizeof(odp); - odp.hInstance = hInst; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_GPG_BIN); - odp.pszTitle = szGPGModuleName; - odp.pszGroup = "Services"; - odp.pszTab = "GnuPG Variables"; - odp.flags=ODPF_BOLDGROUPS; - odp.pfnDlgProc = (DLGPROC)DlgProcGpgBinOpts; - Options_AddPage(wParam, &odp); - - ZeroMemory(&odp, sizeof(odp)); - - odp.cbSize = sizeof(odp); - odp.hInstance = hInst; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_GPG_MESSAGES); - odp.pszTitle = szGPGModuleName; - odp.pszGroup = "Services"; - odp.pszTab = "Messages"; - odp.flags=ODPF_BOLDGROUPS; - odp.pfnDlgProc = (DLGPROC)DlgProcGpgMsgOpts; - Options_AddPage(wParam, &odp); - - ZeroMemory(&odp, sizeof(odp)); - - odp.cbSize = sizeof(odp); - odp.hInstance = hInst; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_GPG_ADVANCED); - odp.pszTitle = szGPGModuleName; - odp.pszGroup = "Services"; - odp.pszTab = "Advanced"; - odp.flags=ODPF_BOLDGROUPS | ODPF_EXPERTONLY; - odp.pfnDlgProc = (DLGPROC)DlgProcGpgAdvOpts; - Options_AddPage(wParam, &odp); - - return 0; -} - -map user_data; - -int item_num = 0; -HWND hwndList_p = NULL; -HWND hwndCurKey_p = NULL; - -void ShowLoadPublicKeyDialog(); -static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - HWND hwndList=GetDlgItem(hwndDlg, IDC_USERLIST); - hwndList_p = hwndList; - hwndCurKey_p = GetDlgItem(hwndDlg, IDC_CURRENT_KEY); - LVCOLUMN col = {0}; - LVITEM item = {0}; - TCHAR *tmp = NULL; - char *tmp2 = NULL; - extern bool bIsMiranda09, bJabberAPI; - NMLISTVIEW * hdr = (NMLISTVIEW *) lParam; - switch (msg) - { - case WM_INITDIALOG: - { - TranslateDialogDefault(hwndDlg); - col.pszText = TranslateW(_T("Contact")); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 60; - ListView_InsertColumn(hwndList, 0, &col); - ZeroMemory(&col,sizeof(col)); - col.pszText = TranslateW(_T("Key ID")); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 50; - ListView_InsertColumn(hwndList, 1, &col); - ZeroMemory(&col,sizeof(col)); - col.pszText = TranslateW(_T("Name")); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 50; - ListView_InsertColumn(hwndList, 2, &col); - ZeroMemory(&col,sizeof(col)); - col.pszText = TranslateW(_T("Email")); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 50; - ListView_InsertColumn(hwndList, 3, &col); - ZeroMemory(&col,sizeof(col)); - col.pszText = TranslateW(_T("Protocol")); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 60; - ListView_InsertColumn(hwndList, 4, &col); - ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT); - int i = 1, iRow = 0; - bool isContactHaveKey(HANDLE); - for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact != NULL; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) - { - if(isContactHaveKey(hContact)) - { - TCHAR *name = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR); - item.mask = LVIF_TEXT; - item.iItem = i; - item.iSubItem = 0; - item.pszText = name; - iRow = ListView_InsertItem(hwndList, &item); - ListView_SetItemText(hwndList, iRow, 0, name); - TCHAR *tmp = mir_a2t((char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0)); - ListView_SetItemText(hwndList, iRow, 4, tmp); - mir_free(tmp); - tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); - tmp = mir_a2t(tmp2); - mir_free(tmp2); - ListView_SetItemText(hwndList, iRow, 1, (_tcslen(tmp) > 1)?tmp:_T("not set")); - mir_free(tmp); - char *tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainName", ""); - if(!toUTF16(tmp2).empty()) - tmp = mir_wstrdup(toUTF16(tmp2).c_str()); - else - tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainName", _T("")); - mir_free(tmp2); - ListView_SetItemText(hwndList, iRow, 2, (_tcslen(tmp) > 1)?tmp:_T("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", _T("")); - mir_free(tmp2); - ListView_SetItemText(hwndList, iRow, 3, (_tcslen(tmp) > 1)?tmp:_T("not set")); - mir_free(tmp); - if(DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)) - ListView_SetCheckState(hwndList, iRow, 1); - user_data[i] = hContact; - ZeroMemory(&item,sizeof(item)); - ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this - ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); - i++; - } - } - tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", _T("")); - SetDlgItemText(hwndDlg, IDC_LOG_FILE_EDIT, (_tcslen(tmp) > 1)?tmp:_T("c:\\GPGdebug.log")); - mir_free(tmp); - CheckStateLoadDB(hwndDlg, IDC_DEBUG_LOG, "bDebugLog", 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_JABBER_API), bIsMiranda09); - EnableWindow(GetDlgItem(hwndDlg, IDC_AUTO_EXCHANGE), (bIsMiranda09 && bJabberAPI)); - { - string keyinfo = Translate("Default private key id"); - keyinfo += ": "; - char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); - keyinfo += (strlen(keyid) > 0)?keyid:Translate("not set"); - mir_free(keyid); - SetDlgItemTextA(hwndDlg, IDC_CURRENT_KEY, keyinfo.c_str()); - } - if(bIsMiranda09) - CheckStateLoadDB(hwndDlg, IDC_JABBER_API, "bJabberAPI", 1); - CheckStateLoadDB(hwndDlg, IDC_FILE_TRANSFERS, "bFileTransfers", 0); - CheckStateLoadDB(hwndDlg, IDC_AUTO_EXCHANGE, "bAutoExchange", 0); - return TRUE; - } - - - case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDC_DELETE_KEY_BUTTON: - void setClistIcon(HANDLE hContact); - void setSrmmIcon(HANDLE hContact); - { //gpg execute block - TCHAR tmp2[MAX_PATH] = {0}; - TCHAR *ptmp; - char *tmp; - bool keep = false; - bool ismetacontact = false; - HANDLE meta = NULL; - HANDLE hContact = user_data[item_num+1]; - if(metaIsProtoMetaContacts(hContact)) - { - meta = hContact; - hContact = metaGetMostOnline(hContact); - ismetacontact = true; - } - else if((meta = metaGetContact(user_data[item_num+1])) != NULL) - { - hContact = metaGetMostOnline(meta); - ismetacontact = true; - } - tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); - for(HANDLE hcnttmp = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hcnttmp != NULL; hcnttmp = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hcnttmp, 0)) - { - if(hcnttmp != hContact) - { - char *tmp2 = UniGetContactSettingUtf(hcnttmp, szGPGModuleName, "KeyID", ""); - if(!strcmp(tmp, tmp2)) - { - mir_free(tmp2); - keep = true; - break; - } - mir_free(tmp2); - } - } - if(!keep) - if(MessageBox(0, _T("This key not used by any contact, do you want to remove it from public keyring ?"), _T("Key info"), MB_YESNO) == IDYES) - { - wstring cmd; - string output; - DWORD exitcode; - cmd += _T(" --batch --yes --delete-key "); - ptmp = mir_a2t(tmp); - cmd += ptmp; - mir_free(ptmp); - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &output; - params.code = &exitcode; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<hdr.hwndFrom) && hdr->iItem != (-1)) - { - if(hdr->hdr.code == NM_CLICK) - { - item_num = hdr->iItem; - } - else if(hdr->hdr.code == LVN_ITEMCHANGED) - { - void setClistIcon(HANDLE hContact); - void setSrmmIcon(HANDLE hContact); - if(ListView_GetCheckState(hwndList, item_num)) - DBWriteContactSettingByte(user_data[item_num+1], szGPGModuleName, "GPGEncryption", 1); - else - DBWriteContactSettingByte(user_data[item_num+1], szGPGModuleName, "GPGEncryption", 0); - setClistIcon(user_data[item_num+1]); - setSrmmIcon(user_data[item_num+1]); - } - } - switch (((LPNMHDR)lParam)->code) - { - - case PSN_APPLY: - { - extern bool bDebugLog, bJabberAPI, bFileTransfers; - bDebugLog = CheckStateStoreDB(hwndDlg, IDC_DEBUG_LOG, "bDebugLog"); - if(bDebugLog) - debuglog.init(); - bJabberAPI = CheckStateStoreDB(hwndDlg, IDC_JABBER_API, "bJabberAPI"); - bFileTransfers = CheckStateStoreDB(hwndDlg, IDC_FILE_TRANSFERS, "bFileTransfers"); - bAutoExchange = CheckStateStoreDB(hwndDlg, IDC_AUTO_EXCHANGE, "bAutoExchange"); - { - TCHAR tmp[512]; - GetDlgItemText(hwndDlg, IDC_LOG_FILE_EDIT, tmp, 512); - DBWriteContactSettingTString(NULL, szGPGModuleName, "szLogFilePath", tmp); - } - return TRUE; - } - } - } - break; - } - - return FALSE; -} - - -static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - TCHAR *tmp = NULL; - switch (msg) - { - case WM_INITDIALOG: - { - TranslateDialogDefault(hwndDlg); - tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("gpg.exe")); - SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp); - mir_free(tmp); - tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("gpg")); - SetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp); - mir_free(tmp); - return TRUE; - } - - - case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDC_SET_BIN_PATH: - { - GetFilePath(_T("Choose gpg.exe"), "szGpgBinPath", _T("*.exe"), _T("EXE Executables")); - tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("gpg.exe")); - SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp); - bool gpg_exists = false; - { - if(_waccess(tmp, 0) != -1) - gpg_exists = true; - if(gpg_exists) - { - bool bad_version = false; - TCHAR *tmp_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("")); - DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); - string out; - DWORD code; - wstring cmd = _T("--version"); - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - } - DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp_path); - mir_free(tmp_path); - string::size_type p1 = out.find("(GnuPG) "); - if(p1 != string::npos) - { - p1 += strlen("(GnuPG) "); - if(out[p1] != '1') - bad_version = true; - } - else - { - bad_version = false; - MessageBox(0, TranslateT("This is not gnupg binary !\nrecommended to use GnuPG v1.x.x with this plugn."), _T("Warning"), MB_OK); - } -/* if(bad_version) //looks like working fine with gpg2 - MessageBox(0, TranslateT("Unsupported gnupg version found, use at you own risk!\nrecommended to use GnuPG v1.x.x with this plugn."), _T("Warning"), MB_OK); */ - } - } - char mir_path[MAX_PATH]; - char *atmp = mir_t2a(tmp); - mir_free(tmp); - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); - char* p_path = NULL; - if(StriStr(atmp, mir_path)) - { - p_path = atmp + strlen(mir_path); - tmp = mir_a2t(p_path); - SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp); - } - } - break; - case IDC_SET_HOME_DIR: - { - GetFolderPath(_T("Set home diractory"), "szHomePath"); - tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - SetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp); - char mir_path[MAX_PATH]; - char *atmp = mir_t2a(tmp); - mir_free(tmp); - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); - char* p_path = NULL; - if(StriStr(atmp, mir_path)) - { - p_path = atmp + strlen(mir_path); - tmp = mir_a2t(p_path); - SetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp); - } - } - break; - default: - break; - } - - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - } - - case WM_NOTIFY: - { - switch (((LPNMHDR)lParam)->code) - { - - case PSN_APPLY: - { - TCHAR tmp[512]; - GetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp, 512); - DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); - GetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp, 512); - while(tmp[_tcslen(tmp)-1] == '\\') - tmp[_tcslen(tmp)-1] = '\0'; - DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", tmp); - return TRUE; - } - } - } - break; - } - return FALSE; -} - -static BOOL CALLBACK DlgProcGpgMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch (msg) - { - case WM_INITDIALOG: - { - TranslateDialogDefault(hwndDlg); - CheckStateLoadDB(hwndDlg, IDC_APPEND_TAGS, "bAppendTags", 0); - CheckStateLoadDB(hwndDlg, IDC_STRIP_TAGS, "bStripTags", 0); - { - TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", _T("")); - SetDlgItemText(hwndDlg, IDC_IN_OPEN_TAG, tmp); - mir_free(tmp); - tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", _T("")); - SetDlgItemText(hwndDlg, IDC_IN_CLOSE_TAG, tmp); - mir_free(tmp); - tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", _T("")); - SetDlgItemText(hwndDlg, IDC_OUT_OPEN_TAG, tmp); - mir_free(tmp); - tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", _T("")); - SetDlgItemText(hwndDlg, IDC_OUT_CLOSE_TAG, tmp); - mir_free(tmp); - } - return TRUE; - } - - - case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDC_APPEND_TAGS: - break; - default: - break; - } - - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - } - - case WM_NOTIFY: - { - switch (((LPNMHDR)lParam)->code) - { - - case PSN_APPLY: - { - bAppendTags = CheckStateStoreDB(hwndDlg, IDC_APPEND_TAGS, "bAppendTags"); - bStripTags = CheckStateStoreDB(hwndDlg, IDC_STRIP_TAGS, "bStripTags"); - { - TCHAR tmp[128]; - GetDlgItemText(hwndDlg, IDC_IN_OPEN_TAG, tmp, 128); - DBWriteContactSettingTString(NULL, szGPGModuleName, "szInOpenTag", tmp); - mir_free(inopentag); - inopentag = new TCHAR [_tcslen(tmp)+1]; - _tcscpy(inopentag, tmp); - GetDlgItemText(hwndDlg, IDC_IN_CLOSE_TAG, tmp, 128); - DBWriteContactSettingTString(NULL, szGPGModuleName, "szInCloseTag", tmp); - mir_free(inclosetag); - inclosetag = new TCHAR [_tcslen(tmp)+1]; - _tcscpy(inclosetag, tmp); - GetDlgItemText(hwndDlg, IDC_OUT_OPEN_TAG, tmp, 128); - DBWriteContactSettingTString(NULL, szGPGModuleName, "szOutOpenTag", tmp); - mir_free(outopentag); - outopentag = new TCHAR [_tcslen(tmp)+1]; - _tcscpy(outopentag, tmp); - GetDlgItemText(hwndDlg, IDC_OUT_CLOSE_TAG, tmp, 128); - DBWriteContactSettingTString(NULL, szGPGModuleName, "szOutCloseTag", tmp); - mir_free(outclosetag); - outclosetag = new TCHAR [_tcslen(tmp)+1]; - _tcscpy(outclosetag, tmp); - } - return TRUE; - } - } - } - break; - } - return FALSE; -} - -static BOOL CALLBACK DlgProcGpgAdvOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch (msg) - { - case WM_INITDIALOG: - { - extern bool bJabberAPI; - TranslateDialogDefault(hwndDlg); - CheckStateLoadDB(hwndDlg, IDC_PRESCENSE_SUBSCRIPTION, "bPresenceSigning", 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_PRESCENSE_SUBSCRIPTION), bJabberAPI); - - return TRUE; - } - - - case WM_COMMAND: - { - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - } - - case WM_NOTIFY: - { - switch (((LPNMHDR)lParam)->code) - { - - case PSN_APPLY: - { - bPresenceSigning = CheckStateStoreDB(hwndDlg, IDC_PRESCENSE_SUBSCRIPTION, "bPresenceSigning"); - return TRUE; - } - } - } - break; - } - return FALSE; -} - -HWND hPubKeyEdit = NULL; - -LONG_PTR default_edit_proc = NULL; - -static BOOL CALLBACK editctrl_ctrl_a(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) -{ - LRESULT ret = 0; - switch(msg) - { - case WM_KEYDOWN: - if(wParam == 0x41 && GetKeyState(VK_CONTROL)< 0 ) - SendMessage(hwndDlg, EM_SETSEL, 0, -1); - break; - default: - ret = CallWindowProc((WNDPROC)default_edit_proc, hwndDlg, msg, wParam, lParam); - break; - } - return ret; -} - -static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) -{ - static HANDLE hContact = user_data[item_num+1]; - - - TCHAR *tmp = NULL; - - wstring key_buf; - wstring::size_type ws1 = 0, ws2 = 0; - switch (msg) - { - case WM_INITDIALOG: - { - default_edit_proc = GetWindowLong(GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT), GWLP_WNDPROC); - SetWindowPos(hwndDlg, 0, load_key_rect.left, load_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); - SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT), GWLP_WNDPROC, (LONG_PTR)editctrl_ctrl_a); - HANDLE hcnt = hContact; - if(metaIsProtoMetaContacts(hcnt)) - hcnt = metaGetMostOnline(hcnt); - TranslateDialogDefault(hwndDlg); - { - string msg = Translate("Load Public GPG Key for "); - msg += (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hcnt, 0); - SetWindowTextA(hwndDlg, msg.c_str()); - } - bool isContactSecured(HANDLE); - if(!hcnt) - { - EnableWindow(GetDlgItem(hwndDlg, IDC_SELECT_EXISTING), 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLE_ENCRYPTION), 0); - } - if(isContactSecured(hcnt)) - SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, TranslateW(_T("Turn off encryption"))); - else - { - SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, TranslateW(_T("Turn on encryption"))); - CheckDlgButton(hwndDlg, IDC_ENABLE_ENCRYPTION, 1); - } - if(hcnt) - { - tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", _T("")); - wstring str = tmp; - mir_free(tmp); - wstring::size_type p = 0, stop = 0; - if(!str.empty()) - { - for(;;) - { - if((p = str.find(_T("\n"), p+2)) != wstring::npos) - { - if(p > stop) - { - stop = p; - str.insert(p, _T("\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; - wstring cmd = _T(" --export -a "); -// TCHAR *tmp3 = mir_a2t(tmp); - cmd += toUTF16(hcontact_data[hcnt].key_in_prescense); -// mir_free(tmp3); - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog< stop) - { - stop = p; - out.insert(p, "\r"); - } - else - break; - } - } - TCHAR *tmp3 = mir_a2t(out.c_str()); - str.clear(); - str.append(tmp3); - string msg = "Load Public GPG Key for "; - msg += (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hcnt, 0); - msg += " (Key ID: "; - msg += hcontact_data[hcnt].key_in_prescense; - msg += " found in prescense, and exists in keyring.)"; - SetWindowTextA(hwndDlg, msg.c_str()); - } - else - { - string msg = "Load Public GPG Key (Key ID: "; - msg += hcontact_data[hcnt].key_in_prescense; - msg += " found in prescense.)"; - SetWindowTextA(hwndDlg, msg.c_str()); - EnableWindow(GetDlgItem(hwndDlg, IDC_IMPORT), 1); - } - } - mir_free(tmp2); - } - mir_free(tmp); - SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, !str.empty()?str.c_str():_T("")); - } - hPubKeyEdit = GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT); - return TRUE; - } - - case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case ID_OK: - { - tmp = new TCHAR [40960]; - TCHAR *begin, *end; - GetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, tmp, 40960); - key_buf.append(tmp); - key_buf.append(_T("\n")); //no new line at end of file ) - delete [] tmp; - while((ws1 = key_buf.find(_T("\r"), ws1)) != wstring::npos) - { - key_buf.erase(ws1, 1); //remove windows specific trash - } - ws1 = 0; - if(((ws2 = key_buf.find(_T("-----END PGP PUBLIC KEY BLOCK-----"))) != wstring::npos) && ((ws1 = key_buf.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"))) != wstring::npos)) - { - begin = new TCHAR [_tcslen(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) + 1]; - _tcscpy(begin, _T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); - end = new TCHAR [_tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")) + 1]; - _tcscpy(end, _T("-----END PGP PUBLIC KEY BLOCK-----")); - } - else if(((ws2 = key_buf.find(_T("-----END PGP PRIVATE KEY BLOCK-----"))) != wstring::npos) && ((ws1 = key_buf.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----"))) != wstring::npos)) - { - begin = new TCHAR [_tcslen(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) + 1]; - _tcscpy(begin, _T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); - end = new TCHAR [_tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----")) + 1]; - _tcscpy(end, _T("-----END PGP PRIVATE KEY BLOCK-----")); - } - else - { - MessageBox(0, _T("This is not public or private key"), _T("INFO"), MB_OK); - break; - } - ws2 += _tcslen(end); - bool allsubcontacts = false; - { - if(metaIsProtoMetaContacts(hContact)) - { - HANDLE hcnt = NULL; - if(MessageBox(0, _T("Do you want load key for all subcontacts ?"), _T("Metacontact detected"), MB_YESNO) == IDYES) - { - allsubcontacts = true; - int count = metaGetContactsNum(hContact); - for(int i = 0; i < count; i++) - { - hcnt = metaGetSubcontact(hContact, i); - if(hcnt) - DBWriteContactSettingTString(hcnt, szGPGModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str()); - } - } - else - DBWriteContactSettingTString(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str()); - } - else - DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str()); - } - tmp = new TCHAR [key_buf.length()+1]; - _tcscpy(tmp, key_buf.substr(ws1,ws2-ws1).c_str()); - { //gpg execute block - wstring cmd; - TCHAR tmp2[MAX_PATH] = {0}; - TCHAR *ptmp; - string output; - DWORD exitcode; - { - HANDLE hcnt = hContact; - if(metaIsProtoMetaContacts(hcnt)) - hcnt = metaGetMostOnline(hcnt); - ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - _tcscpy(tmp2, ptmp); - mir_free(ptmp); - _tcscat(tmp2, _T("\\")); - _tcscat(tmp2, _T("temporary_exported.asc")); - DeleteFile(tmp2); - wfstream f(tmp2, std::ios::out); - ptmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", _T("")); - wstring str = ptmp; - mir_free(ptmp); - wstring::size_type s = 0; - while((s = str.find(_T("\r"), s)) != wstring::npos) - { - str.erase(s, 1); - } - f< output.find("<", s)) - s2 = output.find("<", s); - if(s2 != string::npos) - { - tmp2 = new char [output.substr(s,s2-s-1).length()+1]; - strcpy(tmp2, output.substr(s,s2-s-1).c_str()); - mir_utf8decode(tmp2, 0); - if(hContact) - { - if(metaIsProtoMetaContacts(hContact)) - { - HANDLE hcnt = NULL; - if(allsubcontacts) - { - int count = metaGetContactsNum(hContact); - for(int i = 0; i < count; i++) - { - hcnt = metaGetSubcontact(hContact, i); - if(hcnt) - DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); - } - } - else - DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); - } - else - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); - } - mir_free(tmp2); - tmp = mir_wstrdup(toUTF16(output.substr(s,s2-s-1)).c_str()); - if(hContact && hwndList_p) - ListView_SetItemText(hwndList_p, item_num, 2, tmp); - 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(output[s] == ')') - { - tmp2 = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp2, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp2, 0); - if(hContact) - { - if(metaIsProtoMetaContacts(hContact)) - { - HANDLE hcnt = NULL; - if(allsubcontacts) - { - int count = metaGetContactsNum(hContact); - for(int i = 0; i < count; i++) - { - hcnt = metaGetSubcontact(hContact, i); - if(hcnt) - DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); - } - } - else - DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); - } - else - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); - } - mir_free(tmp2); - s+=3; - s2 = output.find(">", s); - tmp2 = new char [output.substr(s,s2-s).length()+1]; - strcpy(tmp2, output.substr(s,s2-s).c_str()); - mir_utf8decode(tmp2, 0); - if(hContact) - { - if(metaIsProtoMetaContacts(hContact)) - { - HANDLE hcnt = NULL; - if(allsubcontacts) - { - int count = metaGetContactsNum(hContact); - for(int i = 0; i < count; i++) - { - hcnt = metaGetSubcontact(hContact, i); - if(hcnt) - DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); - } - } - else - DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); - } - else - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); - } - mir_free(tmp2); - 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 - { - tmp2 = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp2, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp2, 0); - if(hContact) - { - if(metaIsProtoMetaContacts(hContact)) - { - HANDLE hcnt = NULL; - if(allsubcontacts) - { - int count = metaGetContactsNum(hContact); - for(int i = 0; i < count; i++) - { - hcnt = metaGetSubcontact(hContact, i); - if(hcnt) - DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); - } - } - else - DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); - } - else - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); - } - mir_free(tmp2); - tmp = mir_wstrdup(toUTF16(output.substr(s2,s-s2)).c_str()); - if(hContact && hwndList_p) - ListView_SetItemText(hwndList_p, item_num, 3, tmp); - mir_free(tmp); - } - } - if(hContact && hwndList_p) - { - 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) - { - TCHAR *fp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", _T("")); - { - string out; - DWORD code; - wstring cmd = _T("--batch -a --export "); - cmd += fp; - mir_free(fp); - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<code) - { - - case PSN_APPLY: - { - return TRUE; - } - } - } - break; - case WM_CLOSE: - DestroyWindow(hwndDlg); - break; - case WM_DESTROY: - { - GetWindowRect(hwndDlg, &load_key_rect); - DBWriteContactSettingDword(NULL, szGPGModuleName, "LoadKeyWindowX", load_key_rect.left); - DBWriteContactSettingDword(NULL, szGPGModuleName, "LoadKeyWindowY", load_key_rect.top); - } - break; - } - - return FALSE; -} - - - -void ShowLoadPublicKeyDialog() -{ - DialogBox(hInst, MAKEINTRESOURCE(IDD_LOAD_PUBLIC_KEY), NULL, (DLGPROC)DlgProcLoadPublicKey); -} diff --git a/res/icons/secured.ico b/res/icons/secured.ico new file mode 100755 index 0000000..8d84167 Binary files /dev/null and b/res/icons/secured.ico differ diff --git a/res/icons/unsecured.ico b/res/icons/unsecured.ico new file mode 100755 index 0000000..567367b Binary files /dev/null and b/res/icons/unsecured.ico differ diff --git a/res/new_gpg.rc b/res/new_gpg.rc new file mode 100755 index 0000000..f72f9ea --- /dev/null +++ b/res/new_gpg.rc @@ -0,0 +1,419 @@ +// Microsoft Visual C++ generated resource script. +// +#include "src/resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// Ðóññêèé (Ðîññèÿ) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) +LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT +#pragma code_page(1251) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_LOAD_PUBLIC_KEY DIALOGEX 0, 0, 338, 190 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Load Public GPG key" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "ÎÊ",ID_OK,7,169,50,14 + PUSHBUTTON "Load from file",ID_LOAD_FROM_FILE,273,169,58,14 + EDITTEXT IDC_PUBLIC_KEY_EDIT,7,7,324,134,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | WS_VSCROLL,WS_EX_STATICEDGE + PUSHBUTTON "Select existing",IDC_SELECT_EXISTING,113,169,97,14 + CONTROL "Turn on encryption",IDC_ENABLE_ENCRYPTION,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,143,196,10 + PUSHBUTTON "Import key from keyserver",IDC_IMPORT,140,152,188,14,WS_DISABLED +END + +IDD_FIRST_RUN DIALOGEX 0, 0, 291, 230 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Set own key" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "ÎÊ",ID_OK,12,209,50,14,WS_DISABLED + CONTROL "",IDC_KEY_LIST,"SysListView32",LVS_REPORT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,44,277,105 + PUSHBUTTON "Generate key",IDC_GENERATE_KEY,8,152,74,14 + LTEXT "Select key for use",IDC_STATIC,16,33,186,8 + EDITTEXT IDC_KEY_PASSWORD,94,168,77,14,ES_PASSWORD | ES_AUTOHSCROLL + RTEXT "Key password:",IDC_STATIC,12,170,76,8 + PUSHBUTTON "Load other",IDC_OTHER,83,152,64,14 + PUSHBUTTON "Delete key",IDC_DELETE_KEY,149,152,70,14 + PUSHBUTTON "Generate and use random key",IDC_GENERATE_RANDOM,99,184,118,14 + LTEXT "",IDC_GENERATING_KEY,82,207,174,8 + LTEXT "Account:",IDC_STATIC,15,12,42,8 + LTEXT "key id: ",IDC_KEY_ID,178,12,99,8 + COMBOBOX IDC_ACCOUNT,66,9,104,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP +END + +IDD_BIN_PATH DIALOGEX 0, 0, 354, 108 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Set GPG bin path and keyring home dir." +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "Continue",ID_OK,7,87,50,14 + LTEXT "Home directory:",IDC_STATIC,9,34,325,8 + LTEXT "GnuPG binary:",IDC_STATIC,10,7,147,8 + PUSHBUTTON "Browse",IDC_SET_BIN_PATH,293,18,54,14 + PUSHBUTTON "Browse",IDC_SET_HOME_DIR,293,44,54,14 + EDITTEXT IDC_HOME_DIR,7,44,277,14,ES_AUTOHSCROLL + EDITTEXT IDC_BIN_PATH,7,17,277,14,ES_AUTOHSCROLL + PUSHBUTTON "Generate and use random key",IDC_GENERATE_RANDOM,166,87,118,14 + CONTROL "Turn on key autoexchange",IDC_AUTO_EXCHANGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,64,277,10 +END + +IDD_NEW_KEY DIALOGEX 0, 0, 427, 68 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "The new public key was recieved" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "Import key",ID_IMPORT,9,47,46,14 + PUSHBUTTON "Accept and enable encryption",IDC_IMPORT_AND_USE,156,47,119,14 + PUSHBUTTON "Ignore",IDC_IGNORE_KEY,368,47,52,14 + CTEXT "Ñòàòè÷åñêèé",IDC_MESSAGE,18,25,392,8 + CTEXT "Ñòàòè÷åñêèé",IDC_KEY_FROM,16,12,395,8 +END + +IDD_KEY_GEN DIALOGEX 0, 0, 284, 169 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Key Generation dialog" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "OK",IDOK,7,148,50,14 + PUSHBUTTON "Cancel",IDCANCEL,227,148,50,14 + COMBOBOX IDC_KEY_TYPE,120,14,48,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_GROUP | WS_TABSTOP + EDITTEXT IDC_KEY_LENGTH,120,30,40,14,ES_AUTOHSCROLL | ES_NUMBER | WS_GROUP + EDITTEXT IDC_KEY_PASSWD,120,46,55,14,ES_AUTOHSCROLL | WS_GROUP + EDITTEXT IDC_KEY_REAL_NAME,120,61,55,14,ES_AUTOHSCROLL | WS_GROUP + EDITTEXT IDC_KEY_EMAIL,120,76,55,14,ES_AUTOHSCROLL | WS_GROUP + EDITTEXT IDC_KEY_COMMENT,120,91,55,14,ES_AUTOHSCROLL | WS_GROUP + EDITTEXT IDC_KEY_EXPIRE_DATE,120,106,55,14,ES_AUTOHSCROLL | WS_GROUP + LTEXT "Key type:",IDC_STATIC,8,16,96,8 + LTEXT "Key length:",IDC_STATIC,7,32,106,8 + LTEXT "Key password:",IDC_STATIC,7,49,105,8 + LTEXT "Real name:",IDC_STATIC,7,63,105,8 + LTEXT "Email:",IDC_STATIC,7,79,108,8 + LTEXT "Comment:",IDC_STATIC,7,92,107,8 + LTEXT "Expire date:",IDC_STATIC,7,109,111,8 + LTEXT "ex.: 2010-08-15",IDC_STATIC,182,108,75,8 + LTEXT "From 1024 to 4096",IDC_STATIC,168,33,89,8 + LTEXT "It can take a long time, be patient",IDC_GENERATING_TEXT,15,132,246,8 + LTEXT "0 - does not expire",IDC_STATIC,122,122,141,8 +END + +IDD_LOAD_EXISTING_KEY DIALOGEX 0, 0, 370, 257 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Select existing public key from list" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "ÎÊ",IDOK,7,236,50,14,WS_DISABLED + PUSHBUTTON "Cancel",IDCANCEL,313,236,50,14 + CONTROL "",IDC_EXISTING_KEY_LIST,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,14,356,217 +END + +IDD_KEY_PASSWD DIALOGEX 0, 0, 207, 108 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Enter password for your secret key" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "ÎÊ",IDOK,7,87,50,14 + PUSHBUTTON "Cancel",IDCANCEL,150,87,50,14 + EDITTEXT IDC_PASSWORD,13,38,179,14,ES_PASSWORD | ES_AUTOHSCROLL + LTEXT "Password:",IDC_STATIC,14,28,34,8 + CONTROL "Save password to database",IDC_SAVE_PASSWORD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,56,124,10 + LTEXT "",IDC_KEYID,14,14,179,8 + CONTROL "Default password",IDC_DEFAULT_PASSWORD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,67,151,10 +END + +IDD_IMPORT_KEY DIALOGEX 0, 0, 161, 81 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Set GPG bin path and keyring home dir." +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + PUSHBUTTON "Import",IDC_IMPORT,15,56,50,14 + LTEXT "Select keyserver for key search:",IDC_STATIC,16,20,122,8 + COMBOBOX IDC_KEYSERVER,15,34,125,30,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_LOAD_PUBLIC_KEY, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 331 + TOPMARGIN, 7 + BOTTOMMARGIN, 183 + END + + IDD_FIRST_RUN, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 284 + VERTGUIDE, 15 + TOPMARGIN, 7 + BOTTOMMARGIN, 223 + HORZGUIDE, 20 + END + + IDD_BIN_PATH, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 347 + VERTGUIDE, 284 + TOPMARGIN, 7 + BOTTOMMARGIN, 101 + END + + IDD_NEW_KEY, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 420 + TOPMARGIN, 6 + BOTTOMMARGIN, 61 + END + + IDD_KEY_GEN, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 277 + TOPMARGIN, 7 + BOTTOMMARGIN, 162 + END + + IDD_LOAD_EXISTING_KEY, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 363 + TOPMARGIN, 7 + BOTTOMMARGIN, 250 + END + + IDD_KEY_PASSWD, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 200 + TOPMARGIN, 7 + BOTTOMMARGIN, 101 + END + + IDD_IMPORT_KEY, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 154 + TOPMARGIN, 7 + BOTTOMMARGIN, 74 + END +END +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_SECURED ICON "icons\\secured.ico" +IDI_UNSECURED ICON "icons\\unsecured.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 0,0,0,11 + PRODUCTVERSION 0,9,0,0 + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "041904b0" + BEGIN + VALUE "FileDescription", "new_gpg" + VALUE "FileVersion", "0.0.0.11" + VALUE "InternalName", "new_gpg" + VALUE "LegalCopyright", "Copyright (C) 2010-2011 sss" + VALUE "OriginalFilename", "new_gpg" + VALUE "ProductName", "new_gpg" + VALUE "ProductVersion", "0.9.0.0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x419, 1200 + END +END + +#endif // Ðóññêèé (Ðîññèÿ) resources +///////////////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////////////////// +// Àíãëèéñêèé (ÑØÀ) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_OPT_GPG DIALOGEX 0, 0, 286, 214 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, "MS Shell Dlg", 400, 0, 0x0 +BEGIN + CONTROL "",IDC_USERLIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,17,272,112 + CTEXT "Userlist:",IDC_STATIC,25,7,201,8 + PUSHBUTTON "Export PubKey",IDC_SAVE_KEY_BUTTON,8,135,75,14 + PUSHBUTTON "Delete key",IDC_DELETE_KEY_BUTTON,90,135,70,14 + PUSHBUTTON "Select own key",IDC_SELECT_KEY,205,193,74,14 + CONTROL "Turn on debug log",IDC_DEBUG_LOG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,181,159,89,10 + EDITTEXT IDC_LOG_FILE_EDIT,11,157,98,14,ES_AUTOHSCROLL + PUSHBUTTON "Browse",IDC_LOG_FILE_SET,119,156,50,14 + CONTROL "Use jabber api on Miranda IM >= 0.9 (recomended)",IDC_JABBER_API, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,175,251,10 + LTEXT "Default key",IDC_CURRENT_KEY,12,196,110,8 + CONTROL "Encrypt file transfers",IDC_FILE_TRANSFERS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,185,137,10 + CONTROL "Automatic key exchange",IDC_AUTO_EXCHANGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,163,137,111,10 + PUSHBUTTON "Copy own key",IDC_COPY_KEY,127,193,74,14 +END + +IDD_OPT_GPG_BIN DIALOGEX 0, 0, 282, 214 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, "MS Shell Dlg", 400, 0, 0x0 +BEGIN + PUSHBUTTON "Browse",IDC_SET_BIN_PATH,216,17,60,14 + PUSHBUTTON "Browse",IDC_SET_HOME_DIR,217,44,57,14 + EDITTEXT IDC_BIN_PATH,7,17,195,14,ES_AUTOHSCROLL + EDITTEXT IDC_HOME_DIR,7,44,195,14,ES_AUTOHSCROLL + LTEXT "GnuPG binary:",IDC_STATIC,10,7,147,8 + LTEXT "Home directory:",IDC_STATIC,9,34,144,8 +END + +IDD_OPT_GPG_MESSAGES DIALOGEX 0, 0, 302, 241 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, "MS Shell Dlg", 400, 0, 0x0 +BEGIN + CONTROL "Add tags to encoded and decoded messages",IDC_APPEND_TAGS, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,3,65,243,10 + EDITTEXT IDC_IN_OPEN_TAG,39,20,88,14,ES_AUTOHSCROLL + EDITTEXT IDC_IN_CLOSE_TAG,151,20,90,14,ES_AUTOHSCROLL + LTEXT "Incomming message tags:",IDC_STATIC,15,10,84,8 + LTEXT "Outgoing message tags:",IDC_STATIC,13,36,79,8 + RTEXT "Open:",IDC_STATIC,13,23,26,8 + RTEXT "Close:",IDC_STATIC,127,23,23,8 + EDITTEXT IDC_OUT_OPEN_TAG,39,46,88,14,ES_AUTOHSCROLL + EDITTEXT IDC_OUT_CLOSE_TAG,151,46,90,14,ES_AUTOHSCROLL + RTEXT "Open:",IDC_STATIC,13,49,26,8 + RTEXT "Close:",IDC_STATIC,127,49,23,8 + CONTROL "Strip all tags in outgoing messages",IDC_STRIP_TAGS, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,3,76,233,10 +END + +IDD_OPT_GPG_ADVANCED DIALOGEX 0, 0, 286, 214 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, "MS Shell Dlg", 400, 0, 0x0 +BEGIN + CONTROL "Turn on presence signing (Jabber)",IDC_PRESCENSE_SUBSCRIPTION, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,9,190,10 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_OPT_GPG, DIALOG + BEGIN + END + + IDD_OPT_GPG_BIN, DIALOG + BEGIN + END + + IDD_OPT_GPG_MESSAGES, DIALOG + BEGIN + END + + IDD_OPT_GPG_ADVANCED, DIALOG + BEGIN + VERTGUIDE, 12 + END +END +#endif // APSTUDIO_INVOKED + +#endif // Àíãëèéñêèé (ÑØÀ) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/resource.h b/resource.h deleted file mode 100755 index 027e279..0000000 --- a/resource.h +++ /dev/null @@ -1,96 +0,0 @@ -//{{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 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_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_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_STRIP_TAGS 1067 -#define IDC_CHECK1 1068 -#define IDC_PRESCENSE_SUBSCRIPTION 1068 -#define IDC_GENERATING_KEY 1069 -#define IDC_GENERATING_TEXT 1070 -#define IDC_KEY_ID 1071 -#define IDC_COMBO1 1072 -#define IDC_ACCOUNT 1072 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 114 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1073 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/src/clist.cpp b/src/clist.cpp new file mode 100755 index 0000000..c64fb17 --- /dev/null +++ b/src/clist.cpp @@ -0,0 +1,41 @@ +// 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 "commonheaders.h" + +extern HANDLE g_hCLIcon; +void RefreshContactListIcons(void); + +int onExtraImageListRebuilding(WPARAM, LPARAM) +{ + if(g_hCLIcon && ServiceExists(MS_CLIST_EXTRA_ADD_ICON) ) + RefreshContactListIcons(); + return 0; +} + + +int onExtraImageApplying(WPARAM wParam, LPARAM) +{ + void setClistIcon(HANDLE); + if(g_hCLIcon && ServiceExists(MS_CLIST_EXTRA_SET_ICON)) + { +// IconExtraColumn iec = {0}; //need to init this + if( g_hCLIcon ) + setClistIcon((HANDLE)wParam); +// ExtraIcon_SetIcon(g_hCLIcon, (HANDLE)wParam, iec.hImage); + } + return 0; +} diff --git a/src/commonheaders.h b/src/commonheaders.h new file mode 100755 index 0000000..459d76e --- /dev/null +++ b/src/commonheaders.h @@ -0,0 +1,88 @@ +// 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 COMMONHEADERS_H +#define COMMONHEADERS_H +#define MIRANDA_VER 0x0901 +//windows +#include +#include +#include +#include +#include +#include +//c +#include +#include +#include +//c++ +#include +#include +using std::map; +#include +using std::list; +#include +using std::vector; +#include +using std::string; +using std::wstring; +#include +using std::wfstream; +using std::fstream; + +//boost +#include +#include +#include +#include +#include +#include + + +//utf8cpp +#include + +//miranda +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "m_extraicons.h" +#include "m_metacontacts.h" +#include "resource.h" + + +//internal +#include "constants.h" +#include "log.h" +#include "globals.h" +#include "utilities.h" +#include "main.h" +#include "gpg_wrapper.h" +#include "jabber_account.h" +#include "metacontacts.h" +#endif diff --git a/src/constants.h b/src/constants.h new file mode 100755 index 0000000..2982f31 --- /dev/null +++ b/src/constants.h @@ -0,0 +1,5 @@ +#ifndef CONSTANTS_H +#define CONSTANTS_H +#define szGPGModuleName "GPG" +#define PREF_METANODB 0x2000 +#endif diff --git a/src/globals.h b/src/globals.h new file mode 100755 index 0000000..e84ae1e --- /dev/null +++ b/src/globals.h @@ -0,0 +1,22 @@ +// 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; +extern TCHAR *inopentag, *inclosetag, *outopentag, *outclosetag; +extern logtofile debuglog; +#endif diff --git a/src/gpg_wrapper.cpp b/src/gpg_wrapper.cpp new file mode 100755 index 0000000..410a0d5 --- /dev/null +++ b/src/gpg_wrapper.cpp @@ -0,0 +1,163 @@ +// 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 "commonheaders.h" + +//thx gpg module from Harald Treder, Zakhar V. Bardymov + +//boost::mutex gpg_mutex; + + +pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result, HANDLE hProcess, PROCESS_INFORMATION *pr) +{ +// gpg_mutex.lock(); + if(!gpg_valid) + return pxNotConfigured; + extern logtofile debuglog; + BOOL success; + STARTUPINFO sinfo = {0}; + SECURITY_ATTRIBUTES sattrs = {0}; + SECURITY_DESCRIPTOR sdesc = {0}; + PROCESS_INFORMATION pri = {0}; + HANDLE newstdin, newstdout, readstdout, writestdin; + char *inputpos; + unsigned long transfered; + int size; + + wstring commandline; + + sattrs.nLength=sizeof(SECURITY_ATTRIBUTES); + sattrs.bInheritHandle=TRUE; + InitializeSecurityDescriptor(&sdesc,SECURITY_DESCRIPTOR_REVISION); + SetSecurityDescriptorDacl(&sdesc,TRUE,NULL,FALSE); + sattrs.lpSecurityDescriptor=&sdesc; + + success=CreatePipe(&newstdin,&writestdin,&sattrs,0); + if (!success) + { + *result = pxCreatePipeFailed; + return pxCreatePipeFailed; + } + + success=CreatePipe(&readstdout,&newstdout,&sattrs,0); + if (!success) + { + CloseHandle(newstdin); + CloseHandle(writestdin); + *result = pxCreatePipeFailed; + return pxCreatePipeFailed; + } + + GetStartupInfo(&sinfo); + sinfo.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; + sinfo.wShowWindow=SW_HIDE; + sinfo.hStdOutput=newstdout; + sinfo.hStdError=newstdout; + sinfo.hStdInput=newstdin; + + char *mir_path = new char [MAX_PATH]; + CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + SetCurrentDirectoryA(mir_path); + delete [] mir_path; + + TCHAR *bin_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("")); + { + if(_waccess(bin_path, 0) == -1) + { + if(errno == ENOENT) + { + mir_free(bin_path); + debuglog<c_str(); + + WaitForSingleObject(pri.hProcess,INFINITE); + + CloseHandle(pri.hThread); + CloseHandle(pri.hProcess); + CloseHandle(newstdin); + CloseHandle(newstdout); + CloseHandle(readstdout); + CloseHandle(writestdin); + + *result = pxSuccess; +// gpg_mutex.unlock(); + return pxSuccess; +} + +void pxEexcute_thread(void *param) +{ + gpg_execution_params *params = (gpg_execution_params*)param; + pxResult result = pxExecute(params->cmd, params->useless, params->out, params->code, params->result, params->hProcess, params->proc); +} diff --git a/src/gpg_wrapper.h b/src/gpg_wrapper.h new file mode 100755 index 0000000..5501297 --- /dev/null +++ b/src/gpg_wrapper.h @@ -0,0 +1,50 @@ +// 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 GPG_WRAPPER_H +#define GPG_WRAPPER_H +typedef enum { + pxSuccess, + pxSuccessExitCodeInvalid, + pxCreatePipeFailed, + pxDuplicateHandleFailed, + pxCloseHandleFailed, + pxCreateProcessFailed, + pxThreadWaitFailed, + pxReadFileFailed, + pxBufferOverflow, + pxNotFound, + pxNotConfigured +} +pxResult; + +pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result); + +struct gpg_execution_params +{ + wstring *cmd; + char *useless; + string *out; + LPDWORD code; + pxResult *result; + HANDLE hProcess; + PROCESS_INFORMATION *proc; +}; + +void pxEexcute_thread(void *param); + +#endif \ No newline at end of file diff --git a/src/icons.cpp b/src/icons.cpp new file mode 100755 index 0000000..c981eea --- /dev/null +++ b/src/icons.cpp @@ -0,0 +1,152 @@ +// 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 "commonheaders.h" + +HANDLE IconLibDefine(TCHAR* desc, TCHAR* section, char* ident, HICON icon, char* def_file, int def_idx, int size) +{ + SKINICONDESC sid = {0}; + HANDLE hIcon; + + if(!size) + size = 16; + + sid.cbSize = sizeof( SKINICONDESC ); + sid.ptszSection = section; + sid.ptszDescription = desc; + sid.flags = SIDF_TCHAR; + + sid.pszName = ident; + sid.pszDefaultFile = def_file; + sid.iDefaultIndex = def_idx; + sid.hDefaultIcon = icon; + sid.cx = sid.cy = size; + + hIcon = Skin_AddIcon(&sid); + + return hIcon; +} + + +void InitIconLib() +{ + extern HINSTANCE hInst; + char lib[MAX_PATH]; + GetModuleFileNameA(hInst, lib, MAX_PATH); + TCHAR *module = mir_a2t(szGPGModuleName); + + IconLibDefine(_T("Secured"), module, "secured", NULL, lib, -IDI_SECURED,0); + IconLibDefine(_T("Unsecured"), module, "unsecured", NULL, lib, -IDI_UNSECURED,0); + mir_free(module); +} + + + + + +HICON IconLibGetIcon(const char* ident) +{ + return (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)ident); +} + + + +void IconLibReleaseIcon(const char* ident) +{ + CallService(MS_SKIN2_RELEASEICON, 0, (LPARAM)ident); +} + + + +HANDLE IconLibHookIconsChanged(MIRANDAHOOK hook) +{ + return HookEvent(ME_SKIN2_ICONSCHANGED, hook); +} + + +void setClistIcon(HANDLE hContact) +{ + bool enabled = isContactSecured(hContact); + extern HANDLE g_hCLIcon; + HANDLE hMC = hContact; + if(metaIsSubcontact(hContact)) + hMC = metaGetContact(hContact); + else if(metaIsProtoMetaContacts(hContact)) + hMC = metaGetContact(hContact); + if(g_hCLIcon && enabled) + { + HICON icon = IconLibGetIcon("secured"); + IconExtraColumn iec = {0}; + iec.cbSize = sizeof(iec); + iec.hImage = (HANDLE)CallService(MS_CLIST_EXTRA_ADD_ICON, (WPARAM)icon, (LPARAM)0); + ExtraIcon_SetIcon(g_hCLIcon, hContact, iec.hImage); + if(hMC) + ExtraIcon_SetIcon(g_hCLIcon, hMC, iec.hImage); + } + else + { + ExtraIcon_SetIcon(g_hCLIcon, hContact, (HANDLE)0); // is it right ? hmm.., at least working.... + if(hMC) + ExtraIcon_SetIcon(g_hCLIcon, hMC, (HANDLE)0); + } +} + +void setSrmmIcon(HANDLE h) +{ + HANDLE hContact = metaIsProtoMetaContacts(h)?metaGetMostOnline(h):h; + bool enabled = isContactSecured(hContact); + HANDLE hMC = hContact; + if(metaIsSubcontact(hContact)) + hMC = metaGetContact(hContact); + else if(metaIsProtoMetaContacts(hContact)) + hMC = metaGetContact(hContact); + if(ServiceExists(MS_MSG_MODIFYICON)) + { + StatusIconData sid = {0}; + sid.cbSize = sizeof(sid); + sid.szModule = szGPGModuleName; + sid.hIcon = IconLibGetIcon("secured"); + sid.dwId = 0x00000001; + sid.flags = enabled?0:MBF_HIDDEN; + CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid); + if( hMC ) + CallService(MS_MSG_MODIFYICON, (WPARAM)hMC, (LPARAM)&sid); + ZeroMemory(&sid, sizeof(sid)); + sid.cbSize = sizeof(sid); + sid.szModule = szGPGModuleName; + sid.hIcon = IconLibGetIcon("unsecured"); + sid.dwId = 0x00000002; + sid.flags = enabled?MBF_HIDDEN:0; + CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid); + if( hMC ) + CallService(MS_MSG_MODIFYICON, (WPARAM)hMC, (LPARAM)&sid); + } +} + + +void RefreshContactListIcons() +{ + HANDLE hContact; + extern HANDLE g_hCLIcon; + CallService(MS_CLUI_LISTBEGINREBUILD,0,0); + hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + while (hContact) + { + setClistIcon(hContact); + hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0); + } + CallService(MS_CLUI_LISTENDREBUILD,0,0); +} diff --git a/src/init.cpp b/src/init.cpp new file mode 100755 index 0000000..b87e76f --- /dev/null +++ b/src/init.cpp @@ -0,0 +1,288 @@ +// 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 "commonheaders.h" + +//global variables +bool bAppendTags = false, bDebugLog = false, bJabberAPI = false, bPresenceSigning = false, bIsMiranda09 = false, bMetaContacts = false, bFileTransfers = false, bAutoExchange = false, bStripTags = false, tabsrmm_used = false; +TCHAR *inopentag = NULL, *inclosetag = NULL, *outopentag = NULL, *outclosetag = NULL, *password = NULL; + +list Accounts; + +HINSTANCE hInst; +HANDLE hLoadPubKey = NULL, hToggleEncryption = NULL, hOnPreBuildContactMenu = NULL, hSendKey = NULL, g_hCLIcon = NULL, hExportGpgKeys = NULL, hImportGpgKeys = NULL; +IconExtraColumn g_IEC = {0}; +static int OnModulesLoaded(WPARAM wParam,LPARAM lParam); +extern char *date(); +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}; +XML_API xi = {0}; +int hLangpack = 0; +logtofile debuglog; +bool gpg_valid = false, gpg_keyexist = false; +std::map hcontact_data; + + +#define MIID_GPG { 0x4227c050, 0x8d97, 0x48d2, { 0x91, 0xec, 0x6a, 0x95, 0x2b, 0x3d, 0xab, 0x94 } } + +PLUGININFOEX pluginInfo={ + sizeof(PLUGININFOEX), + 0, + PLUGIN_MAKE_VERSION(0,0,0,11), + "new GPG encryption support plugin, based on code from old gpg plugin and secureim", + "sss", + "sss123next@list.ru", + "© 2010-2012 sss", + "http://sss.chaoslab.ru/tracker/mim_plugs/", + 1, //unicode + MIID_GPG +}; + +BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) +{ + hInst=hinstDLL; + return TRUE; +} + + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + static char plugname[52]; + strcpy(plugname, szGPGModuleName" ["); + strcat(plugname, date()); + strcat(plugname, " "); + strcat(plugname, __TIME__); + strcat(plugname, "]"); + pluginInfo.shortName = plugname; + return &pluginInfo; +} + +static const MUUID interfaces[] = {MIID_GPG, MIID_LAST}; +extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void) +{ + return interfaces; +} + +int LoadKey(WPARAM w, LPARAM l); +int ToggleEncryption(WPARAM w, LPARAM l); +int SendKey(WPARAM w, LPARAM l); +int ExportGpGKeys(WPARAM w, LPARAM l); +int ImportGpGKeys(WPARAM w, LPARAM l); + +void init_vars() +{ + bAppendTags = DBGetContactSettingByte(NULL, szGPGModuleName, "bAppendTags", 0); + bStripTags = DBGetContactSettingByte(NULL, szGPGModuleName, "bStripTags", 0); + inopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", _T("")); + inclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", _T("")); + outopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", _T("")); + outclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", _T("")); + bDebugLog = DBGetContactSettingByte(NULL, szGPGModuleName, "bDebugLog", 0); + bAutoExchange = DBGetContactSettingByte(NULL, szGPGModuleName, "bAutoExchange", 0); + password = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); + debuglog.init(); + bJabberAPI = DBGetContactSettingByte(NULL, szGPGModuleName, "bJabberAPI", bIsMiranda09?1:0); + bPresenceSigning = DBGetContactSettingByte(NULL, szGPGModuleName, "bPresenceSigning", 0); + bFileTransfers = DBGetContactSettingByte(NULL, szGPGModuleName, "bFileTransfers", 0); + firstrun_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "FirstrunWindowX", 0); + firstrun_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "FirstrunWindowY", 0); + key_password_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "PasswordWindowX", 0); + key_password_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "PasswordWindowY", 0); + key_gen_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "KeyGenWindowX", 0); + key_gen_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "KeyGenWindowY", 0); + load_key_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "LoadKeyWindowX", 0); + load_key_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "LoadKeyWindowY", 0); + import_key_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "ImportKeyWindowX", 0); + import_key_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "ImportKeyWindowY", 0); + new_key_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "NewKeyWindowX", 0); + new_key_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "NewKeyWindowY", 0); + load_existing_key_rect.left = DBGetContactSettingDword(NULL, szGPGModuleName, "LoadExistingKeyWindowX", 0); + load_existing_key_rect.top = DBGetContactSettingDword(NULL, szGPGModuleName, "LoadExistingKeyWindowY", 0); + tabsrmm_used = isTabsrmmUsed(); +} + +extern "C" int __declspec(dllexport) Load() +{ + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + mir_getXI(&xi); //TODO: check if we have access to api + mir_getLP(&pluginInfo); + init_vars(); + CreateServiceFunction("/LoadPubKey",(MIRANDASERVICE)LoadKey); + CreateServiceFunction("/ToggleEncryption",(MIRANDASERVICE)ToggleEncryption); + CreateServiceFunction("/SendKey",(MIRANDASERVICE)SendKey); + CreateServiceFunction("/ExportGPGKeys",(MIRANDASERVICE)ExportGpGKeys); + CreateServiceFunction("/ImportGPGKeys",(MIRANDASERVICE)ImportGpGKeys); + CLISTMENUITEM mi = {0}; + mi.cbSize=sizeof(mi); + mi.position=-0x7FFFFFFF; + mi.flags=0; + mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); + mi.pszName="Load GPG public key"; + mi.pszService="/LoadPubKey"; + hLoadPubKey = Menu_AddContactMenuItem(&mi); + ZeroMemory(&mi,sizeof(mi)); + mi.cbSize=sizeof(mi); + mi.position=-0x7FFFFFFe; + mi.flags=0; + mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); + mi.pszName="Toggle GPG encryption"; + mi.pszService="/ToggleEncryption"; + hToggleEncryption = Menu_AddContactMenuItem(&mi); + ZeroMemory(&mi,sizeof(mi)); + mi.cbSize=sizeof(mi); + mi.position=-0x7FFFFFFe; + mi.flags=0; + mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); + mi.pszName="Send public key"; + mi.pszService="/SendKey"; + hSendKey = Menu_AddContactMenuItem(&mi); + ZeroMemory(&mi,sizeof(mi)); + mi.cbSize=sizeof(mi); + mi.position=-0x7FFFFFFF; + mi.flags=0; + mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); + mi.pszName="Export GPG Public keys from all users"; + mi.pszService="/ExportGPGKeys"; + hExportGpgKeys = Menu_AddMainMenuItem(&mi); + ZeroMemory(&mi,sizeof(mi)); + mi.cbSize=sizeof(mi); + mi.position=-0x7FFFFFFF; + mi.flags=0; + mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); + mi.pszName="Import GPG Public keys from all users"; + mi.pszService="/ImportGPGKeys"; + hImportGpgKeys = Menu_AddMainMenuItem(&mi); + + return 0; +} + +int AddContact(WPARAM w, LPARAM l) +{ + CallService(MS_PROTO_ADDTOCONTACT,w,(LPARAM)szGPGModuleName); + return 0; +} + + +static int OnModulesLoaded(WPARAM wParam,LPARAM lParam) +{ + + int GpgOptInit(WPARAM wParam,LPARAM lParam); + int OnPreBuildContactMenu(WPARAM w, LPARAM l); + int RecvMsgSvc(WPARAM w, LPARAM l); + int 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 onExtraImageListRebuilding(WPARAM, LPARAM); + int onExtraImageApplying(WPARAM wParam, LPARAM); + int onProtoAck(WPARAM, LPARAM); + int onSendFile(WPARAM, LPARAM); + void InitIconLib(); + + void InitCheck(); + void FirstRun(); + bIsMiranda09 = (DWORD)CallService(MS_SYSTEM_GETVERSION, 0, 0) >= 0x00090001?true:false; + FirstRun(); + InitCheck(); + InitIconLib(); + if(ServiceExists(MS_MSG_ADDICON)) + { + HICON IconLibGetIcon(const char* ident); + StatusIconData sid = {0}; + sid.cbSize = sizeof(sid); + sid.szModule = szGPGModuleName; + sid.flags = MBF_HIDDEN; + sid.dwId = 0x00000001; + sid.hIcon = IconLibGetIcon("secured"); + sid.szTooltip = Translate("GPG Turn off encryption"); + CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); + ZeroMemory(&sid, sizeof(sid)); + sid.cbSize = sizeof(sid); + sid.szModule = szGPGModuleName; + sid.flags = MBF_HIDDEN; + sid.dwId = 0x00000002; + sid.hIcon = IconLibGetIcon("unsecured"); + sid.szTooltip = Translate("GPG Turn on encryption"); + CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); + } + + + bMetaContacts = ServiceExists(MS_MC_GETMETACONTACT); + + if(bJabberAPI && bIsMiranda09) + GetJabberInterface(0,0); + + HookEvent(ME_OPT_INITIALISE, GpgOptInit); + HookEvent(ME_DB_EVENT_FILTER_ADD, HookSendMsg); + if(bJabberAPI && bIsMiranda09) + HookEvent(ME_PROTO_ACCLISTCHANGED, GetJabberInterface); + + HookEvent(ME_PROTO_ACK, onProtoAck); //filetransfer unimplemented now + + HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPreBuildContactMenu); + + HookEvent(ME_MSG_WINDOWEVENT, onWindowEvent); + HookEvent(ME_MSG_ICONPRESSED, onIconPressed); + + if(ServiceExists(MS_EXTRAICON_REGISTER)) + g_hCLIcon = ExtraIcon_Register(szGPGModuleName, Translate("GPG encryption status"), "secured", (MIRANDAHOOK)onExtraImageListRebuilding, (MIRANDAHOOK)onExtraImageApplying); + + + + PROTOCOLDESCRIPTOR pd = {0}; + pd.cbSize=sizeof(PROTOCOLDESCRIPTOR); + pd.szName=szGPGModuleName; + pd.type=PROTOTYPE_ENCRYPTION; + CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd); + + CreateProtoServiceFunction(szGPGModuleName, PSR_MESSAGE, (MIRANDASERVICE)RecvMsgSvc); + CreateProtoServiceFunction(szGPGModuleName, PSS_MESSAGE, (MIRANDASERVICE)SendMsgSvc); + CreateProtoServiceFunction(szGPGModuleName, PSR_MESSAGE"W", (MIRANDASERVICE)RecvMsgSvc); + CreateProtoServiceFunction(szGPGModuleName, PSS_MESSAGE"W", (MIRANDASERVICE)SendMsgSvc); + + CreateProtoServiceFunction(szGPGModuleName, PSS_FILE, (MIRANDASERVICE)onSendFile); + CreateProtoServiceFunction(szGPGModuleName, PSS_FILE"W", (MIRANDASERVICE)onSendFile); + + for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) + if (!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)szGPGModuleName)) + CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)szGPGModuleName); + + HookEvent(ME_DB_CONTACT_ADDED,AddContact); + + + return 0; +} + +extern list transfers; +extern "C" int __declspec(dllexport) Unload(void) +{ +// for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) +// DBDeleteContactSetting(hContact, szGPGModuleName, "KeyID_Prescense"); + if(!transfers.empty()) + { + for(list::iterator p = transfers.begin(); p != transfers.end(); p++) + if(!(*p).empty()) + DeleteFile((*p).c_str()); + } + mir_free(inopentag); + mir_free(inclosetag); + mir_free(outopentag); + mir_free(outclosetag); + if(password) + delete [] password; + return 0; +} diff --git a/src/jabber_account.cpp b/src/jabber_account.cpp new file mode 100755 index 0000000..6a264a4 --- /dev/null +++ b/src/jabber_account.cpp @@ -0,0 +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 "commonheaders.h" + +void JabberAccount::setAccountName(TCHAR *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; +} + + +TCHAR *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 = NULL; + hSendHandler = INVALID_HANDLE_VALUE; + hPrescenseHandler = INVALID_HANDLE_VALUE; + hMessageHandler = INVALID_HANDLE_VALUE; + AccountNumber = -1; + JabberInterface = NULL; +} +JabberAccount::~JabberAccount() +{ + if(AccountName) + mir_free(AccountName); +} \ No newline at end of file diff --git a/src/jabber_account.h b/src/jabber_account.h new file mode 100755 index 0000000..b643ed1 --- /dev/null +++ b/src/jabber_account.h @@ -0,0 +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(TCHAR *Name); + void setAccountNumber(int Number); + void setJabberInterface(IJabberInterface *JIf); + void setSendHandler(HJHANDLER hHandler); + void setPrescenseHandler(HJHANDLER hHandler); + void setMessageHandler(HJHANDLER hHandler); + + TCHAR *getAccountName(); + int getAccountNumber(); + IJabberInterface *getJabberInterface(); + HJHANDLER getSendHandler(); + HJHANDLER getPrescenseHandler(); + HJHANDLER getMessageHandler(); + ~JabberAccount(); + JabberAccount(); +private: + TCHAR *AccountName; + int AccountNumber; + IJabberInterface *JabberInterface; + HJHANDLER hSendHandler, hPrescenseHandler, hMessageHandler; +}; + +#endif \ No newline at end of file diff --git a/src/log.cpp b/src/log.cpp new file mode 100755 index 0000000..7618914 --- /dev/null +++ b/src/log.cpp @@ -0,0 +1,91 @@ +// 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 "commonheaders.h" + + +logtofile& logtofile::operator<<(TCHAR *buf) +{ + extern bool bDebugLog; + if(bDebugLog) + { + log_mutex.lock(); + log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate); + log<", p); + tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); + ListView_SetItemText(hwndList, iRow, 1, tmp); + mir_free(tmp); + p = out.find("ssb ", p2) + 6; + p = out.find(" ", p) + 1; + p2 = out.find("\n", p); + tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p-1)).c_str()); + ListView_SetItemText(hwndList, iRow, 3, tmp); + mir_free(tmp); + ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this + ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); + i++; + } + } + } + { + SendMessageA(GetDlgItem(hwndDlg, IDC_ACCOUNT), CB_ADDSTRING, 0, (LPARAM)Translate("Default")); + int count = 0; + PROTOACCOUNT **accounts; + ProtoEnumAccounts(&count, &accounts); + for(int i = 0; i < count; i++) + { + if(StriStr(accounts[i]->szModuleName, "metacontacts")) + continue; + if(StriStr(accounts[i]->szModuleName, "weather")) + continue; + SendMessageA(GetDlgItem(hwndDlg, IDC_ACCOUNT), CB_ADDSTRING, 0, (LPARAM)accounts[i]->szModuleName); + } + SendMessageA(GetDlgItem(hwndDlg, IDC_ACCOUNT), CB_SELECTSTRING, 0, (LPARAM)Translate("Default")); + string keyinfo = Translate("key id"); + keyinfo += ": "; + char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); + keyinfo += (strlen(keyid) > 0)?keyid:Translate("not set"); + mir_free(keyid); + SetDlgItemTextA(hwndDlg, IDC_KEY_ID, keyinfo.c_str()); + } + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDC_GENERATE_KEY: + void ShowKeyGenDialog(); + ShowKeyGenDialog(); + break; + case ID_OK: + { + ListView_GetItemText(hwndList, itemnum, 0, fp, 16); + TCHAR *name = new TCHAR [64]; + ListView_GetItemText(hwndList, itemnum, 2, name, 64); + { + if(_tcschr(name, _T('('))) + { + wstring str = name; + wstring::size_type p = str.find(_T("("))-1; + _tcscpy(name, str.substr(0, p).c_str()); + } + } + string out; + DWORD code; + wstring cmd = _T("--batch -a --export "); + cmd += fp; +// cmd += _T("\""); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog< user_data; + extern int item_num; + item_num = 0; //black magic here + user_data[1] = 0; + ShowLoadPublicKeyDialog(); + ListView_DeleteAllItems(hwndList); + { + int i = 1, iRow = 0; + item.mask = LVIF_TEXT; + item.iItem = i; + item.iSubItem = 0; + item.pszText = _T(""); + {//parse gpg output + string out; + DWORD code; + wstring::size_type p = 0, p2 = 0, stop = 0; + { + wstring cmd = _T("--batch --list-secret-keys"); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<", p); + tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); + ListView_SetItemText(hwndList, iRow, 1, tmp); + mir_free(tmp); + p = out.find("ssb ", p2) + 6; + p = out.find(" ", p) + 1; + p2 = out.find("\n", p); + tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p-1)).c_str()); + ListView_SetItemText(hwndList, iRow, 3, tmp); + mir_free(tmp); + ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this + ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); + i++; + } + } + } + } + break; + case IDC_DELETE_KEY: + ListView_GetItemText(hwndList, itemnum, 0, fp, 16); + { + string out; + DWORD code; + wstring cmd = _T("--batch --fingerprint "); + cmd += fp; + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread->timed_join(boost::posix_time::seconds(10))) + { + delete gpg_thread; + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<timed_join(boost::posix_time::seconds(10))) + { + delete gpg_thread; + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog< 0)?keyid:Translate("not set"); + mir_free(keyid); + SetDlgItemTextA(hwndDlg, IDC_KEY_ID, keyinfo.c_str()); + } + else + { + string keyinfo = Translate("key id"); + keyinfo += ": "; + char setting[64]; + strcpy(setting, buf); + strcat(setting, "_KeyID"); + char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, setting, ""); + keyinfo += (strlen(keyid) > 0)?keyid:Translate("not set"); + mir_free(keyid); + SetDlgItemTextA(hwndDlg, IDC_KEY_ID, keyinfo.c_str()); + } + } + break; + + } + break; + } + + case WM_NOTIFY: + { + if(hdr && IsWindowVisible(hdr->hdr.hwndFrom) && hdr->iItem != (-1)) + { + if(hdr->hdr.code == NM_CLICK) + { + EnableWindow(GetDlgItem(hwndDlg, ID_OK), 1); + itemnum = hdr->iItem; + } + } +/* switch(LOWORD(wParam)) + { + default: + break; + }; */ +/* switch (((LPNMHDR)lParam)->code) + { + default: + break; + } */ + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + { + GetWindowRect(hwndDlg, &firstrun_rect); + DBWriteContactSettingDword(NULL, szGPGModuleName, "FirstrunWindowX", firstrun_rect.left); + DBWriteContactSettingDword(NULL, szGPGModuleName, "FirstrunWindowY", firstrun_rect.top); + } + hwndFirstRun = NULL; + break; + + } + + return FALSE; +} + +void ShowFirstRunDialog(); + +static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + TCHAR *tmp = NULL; + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + TCHAR *path = new TCHAR [MAX_PATH]; + bool gpg_exists = false, lang_exists = false; + { + char *mir_path = new char [MAX_PATH]; + CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + SetCurrentDirectoryA(mir_path); + tmp = mir_a2t(mir_path); + mir_free(mir_path); + mir_realloc(path, (_tcslen(path)+128)*sizeof(TCHAR)); + TCHAR *gpg_path = new TCHAR [MAX_PATH], *gpg_lang_path = new TCHAR [MAX_PATH]; + _tcscpy(gpg_path, tmp); + _tcscat(gpg_path, _T("\\GnuPG\\gpg.exe")); + _tcscpy(gpg_lang_path, tmp); + _tcscat(gpg_lang_path, _T("\\GnuPG\\gnupg.nls\\en@quot.mo")); + mir_free(tmp); + if(_waccess(gpg_path, 0) != -1) + { + gpg_exists = true; + _tcscpy(path, _T("GnuPG\\gpg.exe")); + } + if(_waccess(gpg_lang_path, 0) != -1) + lang_exists = true; + if(gpg_exists && !lang_exists) //TODO: check gpg version + MessageBox(0, TranslateT("gpg binary found in miranda folder, but english locale does not exists.\nit's highly recommended to place \\gnupg.nls\\en@quot.mo in gnupg folder under miranda root.\nwithout this file you may expirense many problem with gpg output on non english systems.\nand plugin may completely do not work.\nyou have beed warned."), TranslateT("Warning"), MB_OK); + mir_free(gpg_path); + mir_free(gpg_lang_path); + } + DWORD len = MAX_PATH; + if(!gpg_exists) + { + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", (SHGetValue(HKEY_CURRENT_USER, _T("Software\\GNU\\GnuPG"), _T("gpgProgram"), 0, path, &len) == ERROR_SUCCESS)?path:_T("")); + if(tmp[0]) + { + char *mir_path = new char [MAX_PATH]; + CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + SetCurrentDirectoryA(mir_path); + delete [] mir_path; + if(_waccess(tmp, 0) == -1) + { + if(errno == ENOENT) + MessageBox(0, TranslateT("wrong gpg binary location found in system.\nplease choose another location"), TranslateT("Warning"), MB_OK); + } + } + } + else + tmp = mir_wstrdup(path); + delete [] path; + SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp); + bool bad_version = false; + if(gpg_exists && lang_exists) + { + DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); + string out; + DWORD code; + wstring cmd = _T("--version"); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + gpg_valid = true; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<code) + { + default: + break; + }*/ + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + hwndSetDirs = NULL; + break; + + } + return FALSE; +} + +static BOOL CALLBACK DlgProcNewKeyDialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + extern HANDLE new_key_hcnt; + extern boost::mutex new_key_hcnt_mutex; + static HANDLE hContact = INVALID_HANDLE_VALUE; + void ImportKey(); + TCHAR *tmp = NULL; + switch (msg) + { + case WM_INITDIALOG: + { + hContact = new_key_hcnt; + new_key_hcnt_mutex.unlock(); + SetWindowPos(hwndDlg, 0, new_key_rect.left, new_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); + TranslateDialogDefault(hwndDlg); + TCHAR *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); + SetDlgItemText(hwndDlg, IDC_MESSAGE, tmp[0]?TranslateT("There is existing key for contact, would you like to replace with new key ?"):TranslateT("New public key was received, do you want to import it?")); + EnableWindow(GetDlgItem(hwndDlg, IDC_IMPORT_AND_USE), DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)?0:1); + SetDlgItemText(hwndDlg, ID_IMPORT, tmp[0]?TranslateT("Replace"):TranslateT("Accept")); + mir_free(tmp); + tmp = new TCHAR [256]; + _tcscpy(tmp, TranslateT("Received key from ")); + _tcscat(tmp, (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, (LPARAM)GCDNF_TCHAR)); + SetDlgItemText(hwndDlg, IDC_KEY_FROM, tmp); + delete [] tmp; + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case ID_IMPORT: + ImportKey(); + DestroyWindow(hwndDlg); + break; + case IDC_IMPORT_AND_USE: + ImportKey(); + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); + void setSrmmIcon(HANDLE hContact); + void setClistIcon(HANDLE hContact); + setSrmmIcon(hContact); + setClistIcon(hContact); + DestroyWindow(hwndDlg); + break; + case IDC_IGNORE_KEY: + DestroyWindow(hwndDlg); + break; + default: + break; + } + + break; + } + + case WM_NOTIFY: + { +/* switch (((LPNMHDR)lParam)->code) + { + default: + break; + }*/ + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + { + GetWindowRect(hwndDlg, &new_key_rect); + DBWriteContactSettingDword(NULL, szGPGModuleName, "NewKeyWindowX", new_key_rect.left); + DBWriteContactSettingDword(NULL, szGPGModuleName, "NewKeyWindowY", new_key_rect.top); + } + hwndNewKey = NULL; + break; + + } + return FALSE; +} +static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_INITDIALOG: + { + SetWindowPos(hwndDlg, 0, key_gen_rect.left, key_gen_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); + TranslateDialogDefault(hwndDlg); + SetWindowText(hwndDlg, TranslateT("Key Generation dialog")); + ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEY_TYPE), _T("RSA"), 0); + ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEY_TYPE), _T("DSA"), 1); + SendDlgItemMessage(hwndDlg, IDC_KEY_TYPE, CB_SETCURSEL, (WPARAM)1, 0); + SetDlgItemInt(hwndDlg, IDC_KEY_EXPIRE_DATE, 0, 0); + SetDlgItemInt(hwndDlg, IDC_KEY_LENGTH, 4096, 0); + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDCANCEL: + DestroyWindow(hwndDlg); + break; + case IDOK: + { + wstring path; + { //data sanity checks + TCHAR *tmp = new TCHAR [5]; + GetDlgItemText(hwndDlg, IDC_KEY_TYPE, tmp, 5); + if(_tcslen(tmp) < 3) + { + mir_free(tmp); + MessageBox(0, TranslateT("You must set encryption algorythm first"), TranslateT("Error"), MB_OK); + break; + } + mir_free(tmp); + tmp = new TCHAR [5]; + GetDlgItemText(hwndDlg, IDC_KEY_LENGTH, tmp, 5); + int length = _ttoi(tmp); + mir_free(tmp); + if(length < 1024 || length > 4096) + { + MessageBox(0, TranslateT("Key length must be of length from 1024 to 4096 bits"), TranslateT("Error"), MB_OK); + break; + } + tmp = new TCHAR [12]; + GetDlgItemText(hwndDlg, IDC_KEY_EXPIRE_DATE, tmp, 12); + if(_tcslen(tmp) != 10 && tmp[0] != '0') + { + MessageBox(0, TranslateT("Invalid date"), TranslateT("Error"), MB_OK); + delete [] tmp; + break; + } + delete [] tmp; + tmp = new TCHAR [128]; + GetDlgItemText(hwndDlg, IDC_KEY_REAL_NAME, tmp, 128); + if(_tcslen(tmp) < 5) + { + MessageBox(0, TranslateT("Name must contain at least 5 characters"), TranslateT("Error"), MB_OK); + delete [] tmp; + break; + } + else if (_tcschr(tmp, _T('(')) || _tcschr(tmp, _T(')'))) + { + MessageBox(0, TranslateT("Name cannot contain '(' or ')'"), TranslateT("Error"), MB_OK); + delete [] tmp; + break; + } + delete [] tmp; + tmp = new TCHAR [128]; + GetDlgItemText(hwndDlg, IDC_KEY_EMAIL, tmp, 128); + if((_tcslen(tmp)) < 5 || (!_tcschr(tmp, _T('@'))) || (!_tcschr(tmp, _T('.')))) + { + MessageBox(0, TranslateT("Invalid Email"), TranslateT("Error"), MB_OK); + delete [] tmp; + break; + } + delete [] tmp; + } + { //generating key file + TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + char *tmp2;// = mir_t2a(tmp); + path = tmp; + mir_free(tmp); + // mir_free(tmp2); + path.append(_T("\\new_key")); + wfstream f(path.c_str(), std::ios::out); + if(!f.is_open()) + { + MessageBox(0, TranslateT("Failed to open file"), TranslateT("Error"), MB_OK); + break; + } + f<<"Key-Type: "; + tmp = new TCHAR [5]; + GetDlgItemText(hwndDlg, IDC_KEY_TYPE, tmp, 5); + tmp2 = mir_t2a(tmp); + delete [] tmp; + char *subkeytype = new char [6]; + if(strstr(tmp2, "RSA")) + strcpy(subkeytype, "RSA"); + else if(strstr(tmp2, "DSA")) //this is useless check for now, but it will be required if someone add another key types support + strcpy(subkeytype, "ELG-E"); + f<", p); + tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); + ListView_SetItemText(hwndList_g, iRow, 1, tmp); + mir_free(tmp); + p = out.find("ssb ", p2) + 6; + p = out.find(" ", p) + 1; + p2 = out.find("\n", p); + tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p-1)).c_str()); + ListView_SetItemText(hwndList_g, iRow, 3, tmp); + mir_free(tmp); + ListView_SetColumnWidth(hwndList_g, 0, LVSCW_AUTOSIZE);// not sure about this + ListView_SetColumnWidth(hwndList_g, 1, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList_g, 2, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList_g, 3, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList_g, 4, LVSCW_AUTOSIZE); + i++; + } + } + } + break; + default: + break; + } + + break; + } + + case WM_NOTIFY: + { +/* switch (((LPNMHDR)lParam)->code) + { + default: + break; + } */ + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + { + GetWindowRect(hwndDlg, &key_gen_rect); + DBWriteContactSettingDword(NULL, szGPGModuleName, "KeyGenWindowX", key_gen_rect.left); + DBWriteContactSettingDword(NULL, szGPGModuleName, "KeyGenWindowY", key_gen_rect.top); + } + hwndKeyGen = NULL; + break; + + } + return FALSE; +} + +int itemnum2 = 0; + +static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + HWND hwndList=GetDlgItem(hwndDlg, IDC_EXISTING_KEY_LIST); + hwndList_g = hwndList; + LVCOLUMN col = {0}; + LVITEM item = {0}; + NMLISTVIEW * hdr = (NMLISTVIEW *) lParam; + TCHAR id[16] = {0}; + switch (msg) + { + case WM_INITDIALOG: + { + SetWindowPos(hwndDlg, 0, load_existing_key_rect.left, load_existing_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); + TranslateDialogDefault(hwndDlg); + col.pszText = _T("Key ID"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 50; + ListView_InsertColumn(hwndList, 0, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Email"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 1, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Name"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 250; + ListView_InsertColumn(hwndList, 2, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Creation date"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 3, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Expiration date"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 4, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Key length"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 5, &col); + ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_FULLROWSELECT); + int i = 1, iRow = 0; + { + item.mask = LVIF_TEXT; + item.iItem = i; + item.iSubItem = 0; + item.pszText = _T(""); + {//parse gpg output + string out; + DWORD code; + string::size_type p = 0, p2 = 0, stop = 0; + { + wstring cmd = _T("--batch --list-keys"); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<", p3); + tmp = mir_wstrdup(toUTF16(out.substr(p3,p4-p3)).c_str()); + ListView_SetItemText(hwndList, iRow, 1, tmp); + mir_free(tmp); + } + else + p2--; + p = out.find_first_not_of(" ", p); + tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); + ListView_SetItemText(hwndList, iRow, 2, tmp); + mir_free(tmp); +// p = out.find("sub ", p2) + 6; +// p = out.find(" ", p) + 1; +// p2 = out.find("\n", p); +// tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p-1)).c_str()); +// ListView_SetItemText(hwndList, iRow, 3, tmp); +// mir_free(tmp); + ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this + ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 5, LVSCW_AUTOSIZE); + i++; + } + } + } + return TRUE; + } + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDOK: + { + ListView_GetItemText(hwndList, itemnum2, 0, id, 16); + extern HWND hPubKeyEdit; + string out; + DWORD code; + wstring cmd = _T("--batch -a --export "); + cmd += id; + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<hdr.hwndFrom) && hdr->iItem != (-1)) + { + if(hdr->hdr.code == NM_CLICK) + { + EnableWindow(GetDlgItem(hwndDlg, IDOK), 1); + itemnum2 = hdr->iItem; + } + } + + switch (((LPNMHDR)lParam)->code) + { + + case PSN_APPLY: + { + return TRUE; + } + } + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + { + GetWindowRect(hwndDlg, &load_existing_key_rect); + DBWriteContactSettingDword(NULL, szGPGModuleName, "LoadExistingKeyWindowX", load_existing_key_rect.left); + DBWriteContactSettingDword(NULL, szGPGModuleName, "LoadExistingKeyWindowY", load_existing_key_rect.top); + } + hwndSelectExistingKey = NULL; + break; + + } + + return FALSE; +} +static BOOL CALLBACK DlgProcImportKeyDialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + extern HANDLE new_key_hcnt; + extern boost::mutex new_key_hcnt_mutex; + HANDLE hContact = INVALID_HANDLE_VALUE; + switch (msg) + { + case WM_INITDIALOG: + { + hContact = new_key_hcnt; + new_key_hcnt_mutex.unlock(); + SetWindowPos(hwndDlg, 0 , import_key_rect.left, import_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); + TranslateDialogDefault(hwndDlg); + ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEYSERVER), _T("subkeys.pgp.net"), 0); + ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEYSERVER), _T("keys.gnupg.net"), 0); + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDC_IMPORT: + { + string out; + DWORD code; + wstring cmd = _T(" --keyserver \""); + TCHAR *server= new TCHAR [128]; + GetDlgItemText(hwndDlg, IDC_KEYSERVER, server, 128); + cmd += server; + delete [] server; + cmd += _T("\" --recv-keys "); +// char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID_Prescense", ""); +// TCHAR *tmp2 = mir_a2t(tmp); +// mir_free(tmp); + cmd += toUTF16(hcontact_data[hContact].key_in_prescense); +// mir_free(tmp2); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<code) + { + default: + break; + } */ + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + { + GetWindowRect(hwndDlg, &import_key_rect); + DBWriteContactSettingDword(NULL, szGPGModuleName, "ImportKeyWindowX", import_key_rect.left); + DBWriteContactSettingDword(NULL, szGPGModuleName, "ImportKeyWindowY", import_key_rect.top); + } + break; + + } + return FALSE; +} + + +extern HINSTANCE hInst; + + +void ShowFirstRunDialog() +{ + if (hwndFirstRun == NULL) + { + hwndFirstRun = CreateDialog(hInst, MAKEINTRESOURCE(IDD_FIRST_RUN), NULL, (DLGPROC)DlgProcFirstRun); + } + SetForegroundWindow(hwndFirstRun); +} + + +void ShowSetDirsDialog() +{ + if (hwndSetDirs == NULL) + { + hwndSetDirs = CreateDialog(hInst, MAKEINTRESOURCE(IDD_BIN_PATH), NULL, (DLGPROC)DlgProcGpgBinOpts); + } + SetForegroundWindow(hwndSetDirs); +} + +void ShowNewKeyDialog() +{ + hwndNewKey = CreateDialog(hInst, MAKEINTRESOURCE(IDD_NEW_KEY), NULL, (DLGPROC)DlgProcNewKeyDialog); + SetForegroundWindow(hwndNewKey); +} + +void ShowKeyGenDialog() +{ + if (hwndKeyGen == NULL) + { + hwndKeyGen = CreateDialog(hInst, MAKEINTRESOURCE(IDD_KEY_GEN), NULL, (DLGPROC)DlgProcKeyGenDialog); + } + SetForegroundWindow(hwndKeyGen); +} + +void ShowSelectExistingKeyDialog() +{ + if (hwndSelectExistingKey == NULL) + { + hwndSelectExistingKey = CreateDialog(hInst, MAKEINTRESOURCE(IDD_LOAD_EXISTING_KEY), NULL, (DLGPROC)DlgProcLoadExistingKey); + } + SetForegroundWindow(hwndSelectExistingKey); +} + +void ShowImportKeyDialog() +{ + CreateDialog(hInst, MAKEINTRESOURCE(IDD_IMPORT_KEY), NULL, (DLGPROC)DlgProcImportKeyDialog); +} + + + + +void FirstRun() +{ + DWORD pid = 0; + if(!DBGetContactSettingByte(NULL, szGPGModuleName, "FirstRun", 1)) + return; + ShowSetDirsDialog(); +} + +void InitCheck() +{ + {//parse gpg output + gpg_valid = isGPGValid(); + bool home_dir_access = false, temp_access = false; + TCHAR *home_dir = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + std::wstring test_path = home_dir; + mir_free(home_dir); + test_path += _T("/"); + test_path += toUTF16(get_random(13)); + wfstream test_file; + test_file.open(test_path, std::ios::trunc | std::ios::out); + if(test_file.is_open() && test_file.good()) + { + test_file<<_T("access_test\n"); + if(test_file.good()) + home_dir_access = true; + test_file.close(); + DeleteFile(test_path.c_str()); + } + home_dir = _tgetenv(_T("TEMP")); + test_path = home_dir; + test_path += _T("/"); + test_path += toUTF16(get_random(13)); + test_file.open(test_path, std::ios::trunc | std::ios::out); + if(test_file.is_open() && test_file.good()) + { + test_file<<_T("access_test\n"); + if(test_file.good()) + temp_access = true; + test_file.close(); + DeleteFile(test_path.c_str()); + } + if(!home_dir_access || !temp_access || !gpg_valid) + { + char buf[4096]; + strcpy(buf, gpg_valid?Translate("GPG binary is set and valid (this is good).\n"):Translate("GPG binary unset or invalid (plugin will not work).\n")); + strcat(buf, home_dir_access?Translate("Home dir write access granted (this is good).\n"):Translate("Home dir have not write access (plugin most probably will not work).\n")); + strcat(buf, temp_access?Translate("Temp dir write access granted (this is good).\n"):Translate("Temp dir have not write access (plugin should work, but may have some problems, filetransfers will not work).")); + if(!gpg_valid) + strcat(buf, Translate("\nGPG will be disabled until you solve this problems")); + MessageBoxA(0, buf, Translate("GPG plugin problems"), MB_OK); + } + if(!gpg_valid) + return; + gpg_keyexist = isGPGKeyExist(); + string out; + DWORD code; + pxResult result; + wstring::size_type p = 0, p2 = 0, stop = 0; + { + gpg_execution_params params; + wstring cmd = _T("--batch --list-secret-keys"); + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog< output.find("<", s)) + s2 = output.find("<", s); + tmp = new char [output.substr(s,s2-s-1).length()+1]; + strcpy(tmp, output.substr(s,s2-s-1).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainName", tmp); + 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(output[s] == ')') + { + tmp = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyComment", tmp); + mir_free(tmp); + s+=3; + s2 = output.find(">", s); + tmp = new char [output.substr(s,s2-s).length()+1]; + strcpy(tmp, output.substr(s,s2-s).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainEmail", tmp); + mir_free(tmp); + } + else + { + tmp = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + mir_free(tmp); + } + DBDeleteContactSetting(hcnt, szGPGModuleName, "bAlwatsTrust"); + } + } + } + else + { + char *tmp = NULL; + string::size_type s = output.find("gpg: key ") + strlen("gpg: key "); + string::size_type s2 = output.find(":", s); + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str()); + s2+=2; + s = output.find("“", s2); + if(s == string::npos) + { + s = output.find("\"", s2); + s += 1; + } + else + s += 3; + if((s2 = output.find("(", s)) == string::npos) + s2 = output.find("<", s); + else if(s2 > output.find("<", s)) + s2 = output.find("<", s); + tmp = new char [output.substr(s,s2-s-1).length()+1]; + strcpy(tmp, output.substr(s,s2-s-1).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainName", tmp); + 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(output[s] == ')') + { + tmp = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyComment", tmp); + mir_free(tmp); + s+=3; + s2 = output.find(">", s); + tmp = new char [output.substr(s,s2-s).length()+1]; + strcpy(tmp, output.substr(s,s2-s).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", tmp); + mir_free(tmp); + } + else + { + tmp = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + mir_free(tmp); + } + DBDeleteContactSetting(metaGetMostOnline(hContact), szGPGModuleName, "bAlwatsTrust"); + } + } + else + { + char *tmp = NULL; + string::size_type s = output.find("gpg: key ") + strlen("gpg: key "); + string::size_type s2 = output.find(":", s); + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str()); + s2+=2; + s = output.find("“", s2); + if(s == string::npos) + { + s = output.find("\"", s2); + s += 1; + } + else + s += 3; + if((s2 = output.find("(", s)) == string::npos) + s2 = output.find("<", s); + else if(s2 > output.find("<", s)) + s2 = output.find("<", s); + tmp = new char [output.substr(s,s2-s-1).length()+1]; + strcpy(tmp, output.substr(s,s2-s-1).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", tmp); + 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(output[s] == ')') + { + tmp = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", tmp); + mir_free(tmp); + s+=3; + s2 = output.find(">", s); + tmp = new char [output.substr(s,s2-s).length()+1]; + strcpy(tmp, output.substr(s,s2-s).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", tmp); + mir_free(tmp); + } + else + { + tmp = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + mir_free(tmp); + } + DBDeleteContactSetting(hContact, szGPGModuleName, "bAlwatsTrust"); + } + } + ptmp = mir_wstrdup(toUTF16(output).c_str()); + MessageBox(0, ptmp, _T(""), MB_OK); + mir_free(ptmp); + DeleteFile(tmp2); + } +} \ No newline at end of file diff --git a/src/main.h b/src/main.h new file mode 100755 index 0000000..23627a4 --- /dev/null +++ b/src/main.h @@ -0,0 +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 msgs_to_send, msgs_to_pass; + string key_in_prescense; +}; + +extern std::map 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/src/messages.cpp b/src/messages.cpp new file mode 100755 index 0000000..f2e3c35 --- /dev/null +++ b/src/messages.cpp @@ -0,0 +1,1043 @@ +// 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 "commonheaders.h" + + +wstring new_key; +HANDLE new_key_hcnt = NULL; +boost::mutex new_key_hcnt_mutex; +bool _terminate = false; +int returnNoError(HANDLE hContact); + +std::list sent_msgs; + +int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, DWORD timestamp) +{ + DWORD dbflags = DBEF_UTF; + { //check for gpg related data + wstring::size_type s1 = wstring::npos, s2 = wstring::npos; + + s1 = str.find(_T("-----BEGIN PGP MESSAGE-----")); + s2 = str.find(_T("-----END PGP MESSAGE-----")); + if((s2 != wstring::npos) && (s1 != wstring::npos)) + { //this is generic encrypted data block + void setSrmmIcon(HANDLE); + void setClistIcon(HANDLE); + bool isContactHaveKey(HANDLE hContact); + if(!isContactSecured(hContact)) + { + debuglog< user_data; + extern int item_num; + item_num = 0; //black magic here + user_data[1] = hContact; + ShowLoadPublicKeyDialog(); + } + else + { + DBWriteContactSettingByte(metaIsProtoMetaContacts(hContact)?metaGetMostOnline(hContact):hContact, szGPGModuleName, "GPGEncryption", 1); + setSrmmIcon(hContact); + setClistIcon(hContact); + } + if(isContactHaveKey(hContact)) + { + DBWriteContactSettingByte(metaIsProtoMetaContacts(hContact)?metaGetMostOnline(hContact):hContact, szGPGModuleName, "GPGEncryption", 1); + setSrmmIcon(hContact); + setClistIcon(hContact); + } + } + else if(MessageBox(0, _T("Do you want try to decrypt encrypted message ?"), _T("Warning"), MB_YESNO) == IDNO) + { + + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); + return 0; + } + } + { + wstring::size_type p = 0; + while((p = str.find(_T("\r"), p)) != wstring::npos) + str.erase(p, 1); + } + s2 += _tcslen(_T("-----END PGP MESSAGE-----")); + char *tmp = mir_t2a(str.substr(s1,s2-s1).c_str()); + TCHAR *tmp2 = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + wstring path = tmp2; + wstring encfile = toUTF16(get_random(10)); + wstring decfile = toUTF16(get_random(10)); + path.append(_T("\\tmp\\")); + path.append(encfile); + DeleteFile(path.c_str()); + fstream f(path.c_str(), std::ios::out); + while(!f.is_open()) + f.open(path.c_str(), std::ios::out); + f<timed_join(boost::posix_time::seconds(10))) + { + delete gpg_thread; + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<timed_join(boost::posix_time::seconds(10))) + { + delete gpg_thread; + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<timed_join(boost::posix_time::seconds(10))) + { + delete gpg_thread; + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<lParam); + if (!pre) + return CallService(MS_PROTO_CHAINRECV, w, l); + char *msg = pre->szMessage; + if (!msg) + return CallService(MS_PROTO_CHAINRECV, w, l); + wstring str = toUTF16(msg); + wstring::size_type s1 = wstring::npos, s2 = wstring::npos; + DWORD dbflags = DBEF_UTF; + if((str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos) && !metaIsProtoMetaContacts(ccs->hContact)) + { + s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); + s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); + if(s1 != wstring::npos && s2 != wstring::npos) + { + s2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")); + DBWriteContactSettingTString(ccs->hContact, szGPGModuleName, "GPGPubKey", str.substr(s1,s2-s1).c_str()); + DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 1); + { //gpg execute block + wstring cmd; + TCHAR tmp2[MAX_PATH] = {0}; + TCHAR *ptmp; + string output; + DWORD exitcode; + { + ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + _tcscpy(tmp2, ptmp); + mir_free(ptmp); + _tcscat(tmp2, _T("\\")); + _tcscat(tmp2, _T("temporary_exported.asc")); + DeleteFile(tmp2); + wfstream f(tmp2, std::ios::out); + while(!f.is_open()) + f.open(tmp2, std::ios::out); + ptmp = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "GPGPubKey", _T("")); + wstring new_key = ptmp; + mir_free(ptmp); + f<hContact, szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str()); + s2+=2; + s = output.find("“", s2); + if(s == string::npos) + { + s = output.find("\"", s2); + s += 1; + } + else + s += 3; + if((s2 = output.find("(", s)) == string::npos) + s2 = output.find("<", s); + else if(s2 > output.find("<", s)) + s2 = output.find("<", s); + tmp = new char [output.substr(s,s2-s-1).length()+1]; + strcpy(tmp, output.substr(s,s2-s-1).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(ccs->hContact, szGPGModuleName, "KeyMainName", tmp); + 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(output[s] == ')') + { + tmp = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(ccs->hContact, szGPGModuleName, "KeyComment", tmp); + mir_free(tmp); + s+=3; + s2 = output.find(">", s); + tmp = new char [output.substr(s,s2-s).length()+1]; + strcpy(tmp, output.substr(s,s2-s).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(ccs->hContact, szGPGModuleName, "KeyMainEmail", tmp); + mir_free(tmp); + } + else + { + tmp = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp, 0); + DBWriteContactSettingString(ccs->hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + mir_free(tmp); + } + DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwatsTrust", 1); + void setSrmmIcon(HANDLE); + void setClistIcon(HANDLE); + setSrmmIcon(ccs->hContact); + setClistIcon(ccs->hContact); + if(metaIsSubcontact(ccs->hContact)) + { + setSrmmIcon(metaGetContact(ccs->hContact)); + setClistIcon(metaGetContact(ccs->hContact)); + HistoryLog(metaGetContact(ccs->hContact), "PGP Encryption turned on by key autoexchange feature"); + } + HistoryLog(ccs->hContact, "PGP Encryption turned on by key autoexchange feature"); + } + } + return 1; + } + } + if((str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) != wstring::npos)) + { + s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); + s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); + } + else if((str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")) != wstring::npos)) + { + s2 = str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")); + s1 = str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); + } + if((s2 != wstring::npos) && (s1 != wstring::npos)) + { //this is public key + if(metaIsProtoMetaContacts(ccs->hContact)) + { + HistoryLog(ccs->hContact, db_event(msg, 0, 0, dbflags)); + return 0; + } + debuglog<hContact, GCDNF_TCHAR)<<"\n"; + s1 = 0; + while((s1 = str.find(_T("\r"), s1)) != wstring::npos) + { + str.erase(s1, 1); + } + void ShowNewKeyDialog(); + if((str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) != wstring::npos)) + { + s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); + s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); + s2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")); + } + else if((str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")) != wstring::npos)) + { + s2 = str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")); + s1 = str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); + s2 += _tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----")); + } + new_key.append(str.substr(s1,s2-s1)); + new_key_hcnt_mutex.lock(); + new_key_hcnt = ccs->hContact; + ShowNewKeyDialog(); + HistoryLog(ccs->hContact, db_event(msg, 0, 0, dbflags)); + return 0; + } + if(bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && gpg_valid && gpg_keyexist) + { + char *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); + if(tmp[0]) + { + DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 0); + string str = "-----PGP KEY RESPONSE-----"; + str.append(tmp); + CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)str.c_str()); + DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 1); + } + mir_free(tmp); + if(!isContactHaveKey(ccs->hContact) && bAutoExchange && gpg_valid && gpg_keyexist) + { + LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); + DWORD uin = DBGetContactSettingDword(ccs->hContact, proto, "UIN", 0); + if(uin) + { + if(ServiceExists("ICQ"PS_ICQ_CHECKCAPABILITY)) + { + ICQ_CUSTOMCAP cap = {0}; + strcpy(cap.caps, "GPG AutoExchange"); + if(CallService("ICQ"PS_ICQ_CHECKCAPABILITY, (WPARAM)ccs->hContact, (LPARAM)&cap)) + CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); + } + } + else + { + TCHAR *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", _T("")); + if(jid[0]) + { + extern list Accounts; + list::iterator end = Accounts.end(); + for(list::iterator p = Accounts.begin(); p != end; p++) + { + TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid); + if(caps) + { + wstring str; + for(int i =0;;i++) + { + str.push_back(caps[i]); + if(caps[i] == '\0') + if(caps[i+1] == '\0') + break; + } + mir_free(caps); + if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) + CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)0, (LPARAM)"-----PGP KEY REQUEST-----"); + } + } + } + } + } + return 1; + } + if(!(strstr(msg, "-----BEGIN PGP MESSAGE-----") && strstr(msg, "-----END PGP MESSAGE-----"))) + return CallService(MS_PROTO_CHAINRECV, w, l); + boost::thread *thr = new boost::thread(boost::bind(RecvMsgSvc_func, ccs->hContact, str, msg, ccs->wParam, pre->timestamp)); + return returnNoError(ccs->hContact); +} + +int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) +{ + wstring str; + bool isansi = false; + DWORD dbflags = 0; + if(flags & PREF_UTF) + dbflags |= DBEF_UTF; + if(!metaIsSubcontact(hContact)) + str = toUTF16(msg); + else + {//workaround ... + wchar_t *tmp = mir_utf8decodeW(msg); + if(!tmp) + { + tmp = mir_a2t(msg); + isansi = true; + } + str.append(tmp); + mir_free(tmp); + } + if(bStripTags && bAppendTags) + { + std::wstring::size_type p; + for(p = str.find(inopentag); p != std::wstring::npos; p = str.find(inopentag)) + str.erase(p, _tcslen(inopentag)); + for(p = str.find(inclosetag); p != std::wstring::npos; p = str.find(inclosetag)) + str.erase(p, _tcslen(inclosetag)); + for(p = str.find(outopentag); p != std::wstring::npos; p = str.find(outopentag)) + str.erase(p, _tcslen(outopentag)); + for(p = str.find(outclosetag); p != std::wstring::npos; p = str.find(outclosetag)) + str.erase(p, _tcslen(outclosetag)); + } +/* for(std::wstring::size_type i = str.find(_T("\r\n")); i != std::wstring::npos; i = str.find(_T("\r\n"), i+1)) + str.replace(i, 2, _T("\n")); */ + string out; + DWORD code; + wstring cmd; + wstring file = toUTF16(get_random(10)); + wstring path; + extern bool bJabberAPI, bIsMiranda09; + char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); + if(!tmp[0]) + { + mir_free(tmp); + HistoryLog(hContact, db_event("Failed to encrypt message with GPG", 0,0, DBEF_SENT)); + hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG"); + mir_free(msg); + return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); + } + if(!bJabberAPI || !bIsMiranda09) //force jabber to handle encrypted message by itself + cmd += _T("--comment \"\" --no-version "); + if(DBGetContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 0)) + cmd += _T("--trust-model always "); + cmd += _T("--batch --yes -e -a -t -r "); + TCHAR *tmp2 = mir_a2t(tmp); + mir_free(tmp); + cmd += tmp2; + mir_free(tmp2); + cmd += _T(" \""); + tmp2 = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + path.append(tmp2); + cmd += tmp2; + mir_free(tmp2); + cmd += _T("\\tmp\\"); + cmd += file; + path.append(_T("\\tmp\\")); + path += file; + cmd += _T("\""); + { + char *tmp; + tmp = mir_strdup(toUTF8(str).c_str()); + fstream f(path.c_str(), std::ios::out); + while(!f.is_open()) + f.open(path.c_str(), std::ios::out); + f<lParam)); + if (!msg) + { + mir_free(msg); + return CallService(MS_PROTO_CHAINSEND, w, l); + } + if(strstr(msg,"-----BEGIN PGP MESSAGE-----")) + return CallService(MS_PROTO_CHAINSEND, w, l); + if(!isContactHaveKey(ccs->hContact)) + { + if(bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && gpg_valid) + { + void send_encrypted_msgs_thread(HANDLE hContact); + LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); + DWORD uin = DBGetContactSettingDword(ccs->hContact, proto, "UIN", 0); + if(uin) + { + if(ServiceExists("ICQ"PS_ICQ_CHECKCAPABILITY)) + { + ICQ_CUSTOMCAP cap = {0}; + strcpy(cap.caps, "GPG AutoExchange"); + if(CallService("ICQ"PS_ICQ_CHECKCAPABILITY, (WPARAM)ccs->hContact, (LPARAM)&cap)) + { + CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)ccs->wParam, (LPARAM)"-----PGP KEY REQUEST-----"); + hcontact_data[ccs->hContact].msgs_to_send.push_back(msg); + boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, ccs->hContact)); + mir_free(msg); + return returnNoError(ccs->hContact); + } + } + } + else + { + TCHAR *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", _T("")); + if(jid[0]) + { + extern list Accounts; + list::iterator end = Accounts.end(); + for(list::iterator p = Accounts.begin(); p != end; p++) + { + TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid); + if(caps) + { + wstring str; + for(int i =0;;i++) + { + str.push_back(caps[i]); + if(caps[i] == '\0') + if(caps[i+1] == '\0') + break; + } + mir_free(caps); + if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) + { + CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)ccs->wParam, (LPARAM)"-----PGP KEY REQUEST-----"); + hcontact_data[ccs->hContact].msgs_to_send.push_back(msg); + boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, ccs->hContact)); + mir_free(msg); + return returnNoError(ccs->hContact); + } + } + } + } + } + } + else + { + mir_free(msg); + return CallService(MS_PROTO_CHAINSEND, w, l); + } + } + if(!isContactSecured(ccs->hContact) || metaIsProtoMetaContacts(ccs->hContact)) + { + mir_free(msg); + return CallService(MS_PROTO_CHAINSEND, w, l); + } + boost::thread *thr = new boost::thread(boost::bind(SendMsgSvc_func, ccs->hContact, msg, (DWORD)ccs->wParam)); + return returnNoError(ccs->hContact); +} + +boost::mutex event_processing_mutex; + +int HookSendMsg(WPARAM w, LPARAM l) +{ + if(!l) + return 0; + DBEVENTINFO * dbei = (DBEVENTINFO*)l; + if(dbei->eventType != EVENTTYPE_MESSAGE) + return 0; + if(dbei->flags & DBEF_SENT) + { + if(strstr((char*)dbei->pBlob, "-----BEGIN PGP MESSAGE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY RESPONSE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----") || strstr((char*)dbei->pBlob, "-----PGP KEY RESPONSE-----")) //our service data, can be double added by metacontacts e.t.c. + return 1; + } + HANDLE hContact = (HANDLE)w; + if(isContactSecured(hContact) && (dbei->flags & DBEF_SENT)) //aggressive outgoing events filtering + { + if(!hcontact_data[hContact].msgs_to_pass.empty()) + { + event_processing_mutex.lock(); + std::list::iterator end = hcontact_data[hContact].msgs_to_pass.end(); + for(std::list::iterator i = hcontact_data[hContact].msgs_to_pass.begin(); i != end; ++i) + { + if(!strcmp((*i).c_str(), (char*)dbei->pBlob)) + { + hcontact_data[hContact].msgs_to_pass.erase(i); + debuglog<pBlob<<"\" passed event filter, contact "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<", message is in allowed list\n"; + event_processing_mutex.unlock(); + return 0; + } + } + event_processing_mutex.unlock(); + } + if(metaIsProtoMetaContacts(hContact) && !isContactSecured(metaGetMostOnline(hContact))) + return 0; + return 1; + } + if(!isContactSecured(hContact)) + { + debuglog<pBlob<<"\" passed event filter, contact "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" is unsecured\n"; + return 0; + } + if(!(dbei->flags & DBEF_SENT) && metaIsProtoMetaContacts((HANDLE)w)) + { + char tmp[29]; + strncpy(tmp, (char*)dbei->pBlob, 27); + tmp[28] = '\0'; + if(strstr(tmp, "-----BEGIN PGP MESSAGE-----")) + return 1; + } + return 0; +} + + +static BOOL CALLBACK DlgProcKeyPassword(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + char *inkeyid = NULL; + switch (msg) + { + case WM_INITDIALOG: + { + inkeyid = UniGetContactSettingUtf(new_key_hcnt, szGPGModuleName, "InKeyID", ""); + new_key_hcnt_mutex.unlock(); + TCHAR *tmp = NULL; + + SetWindowPos(hwndDlg, 0, key_password_rect.left, key_password_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); + TranslateDialogDefault(hwndDlg); + string questionstr = "Please enter password for key with ID: "; + questionstr += inkeyid; + SetDlgItemTextA(hwndDlg, IDC_KEYID, questionstr.c_str()); + EnableWindow(GetDlgItem(hwndDlg, IDC_DEFAULT_PASSWORD), 0); + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDOK: + { + TCHAR tmp[64]; + GetDlgItemText(hwndDlg, IDC_KEY_PASSWORD, tmp, 64); + if(tmp[0]) + { + extern TCHAR *password; + if(IsDlgButtonChecked(hwndDlg, IDC_SAVE_PASSWORD)) + { + if(inkeyid && inkeyid[0] && !IsDlgButtonChecked(hwndDlg, IDC_DEFAULT_PASSWORD)) + { + string dbsetting = "szKey_"; + dbsetting += inkeyid; + dbsetting += "_Password"; + DBWriteContactSettingTString(NULL, szGPGModuleName, dbsetting.c_str(), tmp); + } + else + DBWriteContactSettingTString(NULL, szGPGModuleName, "szKeyPassword", tmp); + } + if(password) + delete [] password; + password = new TCHAR [_tcslen(tmp)+1]; + _tcscpy(password, tmp); + } + mir_free(tmp); + mir_free(inkeyid); + DestroyWindow(hwndDlg); + break; + } + case IDCANCEL: + mir_free(inkeyid); + _terminate = true; + DestroyWindow(hwndDlg); + break; + default: + break; + } + + break; + } + + case WM_NOTIFY: + { +/* switch (((LPNMHDR)lParam)->code) + { + default: + EnableWindow(GetDlgItem(hwndDlg, IDC_DEFAULT_PASSWORD), IsDlgButtonChecked(hwndDlg, IDC_SAVE_PASSWORD)?1:0); + break; + }*/ + } + break; + case WM_CLOSE: + mir_free(inkeyid); + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + { + GetWindowRect(hwndDlg, &key_password_rect); + DBWriteContactSettingDword(NULL, szGPGModuleName, "PasswordWindowX", key_password_rect.left); + DBWriteContactSettingDword(NULL, szGPGModuleName, "PasswordWindowY", key_password_rect.top); + } + break; + + } + return FALSE; +} + +void ShowLoadKeyPasswordWindow() +{ + extern HINSTANCE hInst; + DialogBox(hInst, MAKEINTRESOURCE(IDD_KEY_PASSWD), NULL, (DLGPROC)DlgProcKeyPassword); +} diff --git a/src/metacontacts.cpp b/src/metacontacts.cpp new file mode 100755 index 0000000..1abc2aa --- /dev/null +++ b/src/metacontacts.cpp @@ -0,0 +1,88 @@ +// 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 "commonheaders.h" + +extern bool bMetaContacts; + +bool metaIsProtoMetaContacts(HANDLE hContact) +{ + if(bMetaContacts) { + LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + if( proto && strcmp(proto,"MetaContacts")==0 ) { + return true; + } + } + return false; +} + + +bool metaIsDefaultSubContact(HANDLE hContact) +{ + + if(bMetaContacts) + return (HANDLE)CallService(MS_MC_GETDEFAULTCONTACT,(WPARAM)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0),0)==hContact; + return false; +} + + +HANDLE metaGetContact(HANDLE hContact) +{ + if(bMetaContacts) + if(metaIsSubcontact(hContact)) + return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0); + return NULL; +} +bool metaIsSubcontact(HANDLE hContact) +{ + if(bMetaContacts) + return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0); + return false; +} + + +HANDLE metaGetMostOnline(HANDLE hContact) +{ + + if(bMetaContacts) + if(metaIsProtoMetaContacts(hContact)) + return (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT,(WPARAM)hContact,0); + return NULL; +} +HANDLE metaGetDefault(HANDLE hContact) +{ + + if(bMetaContacts) + if(metaIsProtoMetaContacts(hContact)) + return (HANDLE)CallService(MS_MC_GETDEFAULTCONTACT,(WPARAM)hContact,0); + return NULL; +} + + +DWORD metaGetContactsNum(HANDLE hContact) +{ + if(bMetaContacts) + return CallService(MS_MC_GETNUMCONTACTS, (WPARAM)hContact, 0); + return 0; +} +HANDLE metaGetSubcontact(HANDLE hContact, int num) +{ + if(bMetaContacts) + return (HANDLE)CallService(MS_MC_GETSUBCONTACT, (WPARAM)hContact, (LPARAM)num); + return 0; +} + + diff --git a/src/metacontacts.h b/src/metacontacts.h new file mode 100755 index 0000000..8b8873e --- /dev/null +++ b/src/metacontacts.h @@ -0,0 +1,24 @@ +// 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 metaIsProtoMetaContacts(HANDLE hContact); +bool metaIsDefaultSubContact(HANDLE hContact) ; +HANDLE metaGetContact(HANDLE hContact); +bool metaIsSubcontact(HANDLE hContact); +HANDLE metaGetMostOnline(HANDLE hContact); +HANDLE metaGetDefault(HANDLE hContact); +DWORD metaGetContactsNum(HANDLE hContact); +HANDLE metaGetSubcontact(HANDLE hContact, int num); \ No newline at end of file diff --git a/src/options.cpp b/src/options.cpp new file mode 100755 index 0000000..a990003 --- /dev/null +++ b/src/options.cpp @@ -0,0 +1,1386 @@ +// 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 "commonheaders.h" + +extern HINSTANCE hInst; + +static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +static BOOL CALLBACK DlgProcGpgMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +static BOOL CALLBACK DlgProcGpgAdvOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); + +BOOL CheckStateLoadDB(HWND hwndDlg, int idCtrl, const char* szSetting, BYTE bDef) +{ + BOOL state = DBGetContactSettingByte(NULL, szGPGModuleName, szSetting, bDef); + CheckDlgButton(hwndDlg, idCtrl, state); + return state; +} + +BOOL CheckStateStoreDB(HWND hwndDlg, int idCtrl, const char* szSetting) +{ + BOOL state = IsDlgButtonChecked(hwndDlg, idCtrl); + DBWriteContactSettingByte(NULL, szGPGModuleName, szSetting, (BYTE)state); + return state; +} + + +int GpgOptInit(WPARAM wParam,LPARAM lParam) +{ + OPTIONSDIALOGPAGE odp = { 0 }; + odp.cbSize = sizeof(odp); + odp.hInstance = hInst; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_GPG); + odp.pszTitle = szGPGModuleName; + odp.pszGroup = "Services"; + odp.pszTab = "Main"; + odp.flags=ODPF_BOLDGROUPS; + odp.pfnDlgProc = (DLGPROC)DlgProcGpgOpts; + Options_AddPage(wParam, &odp); + + ZeroMemory(&odp, sizeof(odp)); + + odp.cbSize = sizeof(odp); + odp.hInstance = hInst; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_GPG_BIN); + odp.pszTitle = szGPGModuleName; + odp.pszGroup = "Services"; + odp.pszTab = "GnuPG Variables"; + odp.flags=ODPF_BOLDGROUPS; + odp.pfnDlgProc = (DLGPROC)DlgProcGpgBinOpts; + Options_AddPage(wParam, &odp); + + ZeroMemory(&odp, sizeof(odp)); + + odp.cbSize = sizeof(odp); + odp.hInstance = hInst; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_GPG_MESSAGES); + odp.pszTitle = szGPGModuleName; + odp.pszGroup = "Services"; + odp.pszTab = "Messages"; + odp.flags=ODPF_BOLDGROUPS; + odp.pfnDlgProc = (DLGPROC)DlgProcGpgMsgOpts; + Options_AddPage(wParam, &odp); + + ZeroMemory(&odp, sizeof(odp)); + + odp.cbSize = sizeof(odp); + odp.hInstance = hInst; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_GPG_ADVANCED); + odp.pszTitle = szGPGModuleName; + odp.pszGroup = "Services"; + odp.pszTab = "Advanced"; + odp.flags=ODPF_BOLDGROUPS | ODPF_EXPERTONLY; + odp.pfnDlgProc = (DLGPROC)DlgProcGpgAdvOpts; + Options_AddPage(wParam, &odp); + + return 0; +} + +map user_data; + +int item_num = 0; +HWND hwndList_p = NULL; +HWND hwndCurKey_p = NULL; + +void ShowLoadPublicKeyDialog(); +static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + HWND hwndList=GetDlgItem(hwndDlg, IDC_USERLIST); + hwndList_p = hwndList; + hwndCurKey_p = GetDlgItem(hwndDlg, IDC_CURRENT_KEY); + LVCOLUMN col = {0}; + LVITEM item = {0}; + TCHAR *tmp = NULL; + char *tmp2 = NULL; + extern bool bIsMiranda09, bJabberAPI; + NMLISTVIEW * hdr = (NMLISTVIEW *) lParam; + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + col.pszText = TranslateW(_T("Contact")); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 60; + ListView_InsertColumn(hwndList, 0, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = TranslateW(_T("Key ID")); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 50; + ListView_InsertColumn(hwndList, 1, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = TranslateW(_T("Name")); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 50; + ListView_InsertColumn(hwndList, 2, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = TranslateW(_T("Email")); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 50; + ListView_InsertColumn(hwndList, 3, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = TranslateW(_T("Protocol")); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 60; + ListView_InsertColumn(hwndList, 4, &col); + ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT); + int i = 1, iRow = 0; + bool isContactHaveKey(HANDLE); + for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact != NULL; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) + { + if(isContactHaveKey(hContact)) + { + TCHAR *name = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR); + item.mask = LVIF_TEXT; + item.iItem = i; + item.iSubItem = 0; + item.pszText = name; + iRow = ListView_InsertItem(hwndList, &item); + ListView_SetItemText(hwndList, iRow, 0, name); + TCHAR *tmp = mir_a2t((char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0)); + ListView_SetItemText(hwndList, iRow, 4, tmp); + mir_free(tmp); + tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); + tmp = mir_a2t(tmp2); + mir_free(tmp2); + ListView_SetItemText(hwndList, iRow, 1, (_tcslen(tmp) > 1)?tmp:_T("not set")); + mir_free(tmp); + char *tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainName", ""); + if(!toUTF16(tmp2).empty()) + tmp = mir_wstrdup(toUTF16(tmp2).c_str()); + else + tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainName", _T("")); + mir_free(tmp2); + ListView_SetItemText(hwndList, iRow, 2, (_tcslen(tmp) > 1)?tmp:_T("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", _T("")); + mir_free(tmp2); + ListView_SetItemText(hwndList, iRow, 3, (_tcslen(tmp) > 1)?tmp:_T("not set")); + mir_free(tmp); + if(DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)) + ListView_SetCheckState(hwndList, iRow, 1); + user_data[i] = hContact; + ZeroMemory(&item,sizeof(item)); + ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this + ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); + i++; + } + } + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", _T("")); + SetDlgItemText(hwndDlg, IDC_LOG_FILE_EDIT, (_tcslen(tmp) > 1)?tmp:_T("c:\\GPGdebug.log")); + mir_free(tmp); + CheckStateLoadDB(hwndDlg, IDC_DEBUG_LOG, "bDebugLog", 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_JABBER_API), bIsMiranda09); + EnableWindow(GetDlgItem(hwndDlg, IDC_AUTO_EXCHANGE), (bIsMiranda09 && bJabberAPI)); + { + string keyinfo = Translate("Default private key id"); + keyinfo += ": "; + char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); + keyinfo += (strlen(keyid) > 0)?keyid:Translate("not set"); + mir_free(keyid); + SetDlgItemTextA(hwndDlg, IDC_CURRENT_KEY, keyinfo.c_str()); + } + if(bIsMiranda09) + CheckStateLoadDB(hwndDlg, IDC_JABBER_API, "bJabberAPI", 1); + CheckStateLoadDB(hwndDlg, IDC_FILE_TRANSFERS, "bFileTransfers", 0); + CheckStateLoadDB(hwndDlg, IDC_AUTO_EXCHANGE, "bAutoExchange", 0); + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDC_DELETE_KEY_BUTTON: + void setClistIcon(HANDLE hContact); + void setSrmmIcon(HANDLE hContact); + { //gpg execute block + TCHAR tmp2[MAX_PATH] = {0}; + TCHAR *ptmp; + char *tmp; + bool keep = false; + bool ismetacontact = false; + HANDLE meta = NULL; + HANDLE hContact = user_data[item_num+1]; + if(metaIsProtoMetaContacts(hContact)) + { + meta = hContact; + hContact = metaGetMostOnline(hContact); + ismetacontact = true; + } + else if((meta = metaGetContact(user_data[item_num+1])) != NULL) + { + hContact = metaGetMostOnline(meta); + ismetacontact = true; + } + tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); + for(HANDLE hcnttmp = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hcnttmp != NULL; hcnttmp = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hcnttmp, 0)) + { + if(hcnttmp != hContact) + { + char *tmp2 = UniGetContactSettingUtf(hcnttmp, szGPGModuleName, "KeyID", ""); + if(!strcmp(tmp, tmp2)) + { + mir_free(tmp2); + keep = true; + break; + } + mir_free(tmp2); + } + } + if(!keep) + if(MessageBox(0, _T("This key not used by any contact, do you want to remove it from public keyring ?"), _T("Key info"), MB_YESNO) == IDYES) + { + wstring cmd; + string output; + DWORD exitcode; + cmd += _T(" --batch --yes --delete-key "); + ptmp = mir_a2t(tmp); + cmd += ptmp; + mir_free(ptmp); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &output; + params.code = &exitcode; + params.result = &result; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<hdr.hwndFrom) && hdr->iItem != (-1)) + { + if(hdr->hdr.code == NM_CLICK) + { + item_num = hdr->iItem; + } + else if(hdr->hdr.code == LVN_ITEMCHANGED) + { + void setClistIcon(HANDLE hContact); + void setSrmmIcon(HANDLE hContact); + if(ListView_GetCheckState(hwndList, item_num)) + DBWriteContactSettingByte(user_data[item_num+1], szGPGModuleName, "GPGEncryption", 1); + else + DBWriteContactSettingByte(user_data[item_num+1], szGPGModuleName, "GPGEncryption", 0); + setClistIcon(user_data[item_num+1]); + setSrmmIcon(user_data[item_num+1]); + } + } + switch (((LPNMHDR)lParam)->code) + { + + case PSN_APPLY: + { + extern bool bDebugLog, bJabberAPI, bFileTransfers; + bDebugLog = CheckStateStoreDB(hwndDlg, IDC_DEBUG_LOG, "bDebugLog"); + if(bDebugLog) + debuglog.init(); + bJabberAPI = CheckStateStoreDB(hwndDlg, IDC_JABBER_API, "bJabberAPI"); + bFileTransfers = CheckStateStoreDB(hwndDlg, IDC_FILE_TRANSFERS, "bFileTransfers"); + bAutoExchange = CheckStateStoreDB(hwndDlg, IDC_AUTO_EXCHANGE, "bAutoExchange"); + { + TCHAR tmp[512]; + GetDlgItemText(hwndDlg, IDC_LOG_FILE_EDIT, tmp, 512); + DBWriteContactSettingTString(NULL, szGPGModuleName, "szLogFilePath", tmp); + } + return TRUE; + } + } + } + break; + } + + return FALSE; +} + + +static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + TCHAR *tmp = NULL; + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("gpg.exe")); + SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp); + mir_free(tmp); + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("gpg")); + SetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp); + mir_free(tmp); + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDC_SET_BIN_PATH: + { + GetFilePath(_T("Choose gpg.exe"), "szGpgBinPath", _T("*.exe"), _T("EXE Executables")); + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("gpg.exe")); + SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp); + bool gpg_exists = false; + { + if(_waccess(tmp, 0) != -1) + gpg_exists = true; + if(gpg_exists) + { + bool bad_version = false; + TCHAR *tmp_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("")); + DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); + string out; + DWORD code; + wstring cmd = _T("--version"); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + } + DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp_path); + mir_free(tmp_path); + string::size_type p1 = out.find("(GnuPG) "); + if(p1 != string::npos) + { + p1 += strlen("(GnuPG) "); + if(out[p1] != '1') + bad_version = true; + } + else + { + bad_version = false; + MessageBox(0, TranslateT("This is not gnupg binary !\nrecommended to use GnuPG v1.x.x with this plugn."), _T("Warning"), MB_OK); + } +/* if(bad_version) //looks like working fine with gpg2 + MessageBox(0, TranslateT("Unsupported gnupg version found, use at you own risk!\nrecommended to use GnuPG v1.x.x with this plugn."), _T("Warning"), MB_OK); */ + } + } + char mir_path[MAX_PATH]; + char *atmp = mir_t2a(tmp); + mir_free(tmp); + CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + char* p_path = NULL; + if(StriStr(atmp, mir_path)) + { + p_path = atmp + strlen(mir_path); + tmp = mir_a2t(p_path); + SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp); + } + } + break; + case IDC_SET_HOME_DIR: + { + GetFolderPath(_T("Set home diractory"), "szHomePath"); + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + SetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp); + char mir_path[MAX_PATH]; + char *atmp = mir_t2a(tmp); + mir_free(tmp); + CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + char* p_path = NULL; + if(StriStr(atmp, mir_path)) + { + p_path = atmp + strlen(mir_path); + tmp = mir_a2t(p_path); + SetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp); + } + } + break; + default: + break; + } + + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + } + + case WM_NOTIFY: + { + switch (((LPNMHDR)lParam)->code) + { + + case PSN_APPLY: + { + TCHAR tmp[512]; + GetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp, 512); + DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); + GetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp, 512); + while(tmp[_tcslen(tmp)-1] == '\\') + tmp[_tcslen(tmp)-1] = '\0'; + DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", tmp); + return TRUE; + } + } + } + break; + } + return FALSE; +} + +static BOOL CALLBACK DlgProcGpgMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + CheckStateLoadDB(hwndDlg, IDC_APPEND_TAGS, "bAppendTags", 0); + CheckStateLoadDB(hwndDlg, IDC_STRIP_TAGS, "bStripTags", 0); + { + TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", _T("")); + SetDlgItemText(hwndDlg, IDC_IN_OPEN_TAG, tmp); + mir_free(tmp); + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", _T("")); + SetDlgItemText(hwndDlg, IDC_IN_CLOSE_TAG, tmp); + mir_free(tmp); + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", _T("")); + SetDlgItemText(hwndDlg, IDC_OUT_OPEN_TAG, tmp); + mir_free(tmp); + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", _T("")); + SetDlgItemText(hwndDlg, IDC_OUT_CLOSE_TAG, tmp); + mir_free(tmp); + } + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDC_APPEND_TAGS: + break; + default: + break; + } + + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + } + + case WM_NOTIFY: + { + switch (((LPNMHDR)lParam)->code) + { + + case PSN_APPLY: + { + bAppendTags = CheckStateStoreDB(hwndDlg, IDC_APPEND_TAGS, "bAppendTags"); + bStripTags = CheckStateStoreDB(hwndDlg, IDC_STRIP_TAGS, "bStripTags"); + { + TCHAR tmp[128]; + GetDlgItemText(hwndDlg, IDC_IN_OPEN_TAG, tmp, 128); + DBWriteContactSettingTString(NULL, szGPGModuleName, "szInOpenTag", tmp); + mir_free(inopentag); + inopentag = new TCHAR [_tcslen(tmp)+1]; + _tcscpy(inopentag, tmp); + GetDlgItemText(hwndDlg, IDC_IN_CLOSE_TAG, tmp, 128); + DBWriteContactSettingTString(NULL, szGPGModuleName, "szInCloseTag", tmp); + mir_free(inclosetag); + inclosetag = new TCHAR [_tcslen(tmp)+1]; + _tcscpy(inclosetag, tmp); + GetDlgItemText(hwndDlg, IDC_OUT_OPEN_TAG, tmp, 128); + DBWriteContactSettingTString(NULL, szGPGModuleName, "szOutOpenTag", tmp); + mir_free(outopentag); + outopentag = new TCHAR [_tcslen(tmp)+1]; + _tcscpy(outopentag, tmp); + GetDlgItemText(hwndDlg, IDC_OUT_CLOSE_TAG, tmp, 128); + DBWriteContactSettingTString(NULL, szGPGModuleName, "szOutCloseTag", tmp); + mir_free(outclosetag); + outclosetag = new TCHAR [_tcslen(tmp)+1]; + _tcscpy(outclosetag, tmp); + } + return TRUE; + } + } + } + break; + } + return FALSE; +} + +static BOOL CALLBACK DlgProcGpgAdvOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_INITDIALOG: + { + extern bool bJabberAPI; + TranslateDialogDefault(hwndDlg); + CheckStateLoadDB(hwndDlg, IDC_PRESCENSE_SUBSCRIPTION, "bPresenceSigning", 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_PRESCENSE_SUBSCRIPTION), bJabberAPI); + + return TRUE; + } + + + case WM_COMMAND: + { + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + } + + case WM_NOTIFY: + { + switch (((LPNMHDR)lParam)->code) + { + + case PSN_APPLY: + { + bPresenceSigning = CheckStateStoreDB(hwndDlg, IDC_PRESCENSE_SUBSCRIPTION, "bPresenceSigning"); + return TRUE; + } + } + } + break; + } + return FALSE; +} + +HWND hPubKeyEdit = NULL; + +LONG_PTR default_edit_proc = NULL; + +static BOOL CALLBACK editctrl_ctrl_a(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + LRESULT ret = 0; + switch(msg) + { + case WM_KEYDOWN: + if(wParam == 0x41 && GetKeyState(VK_CONTROL)< 0 ) + SendMessage(hwndDlg, EM_SETSEL, 0, -1); + break; + default: + ret = CallWindowProc((WNDPROC)default_edit_proc, hwndDlg, msg, wParam, lParam); + break; + } + return ret; +} + +static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + static HANDLE hContact = user_data[item_num+1]; + + + TCHAR *tmp = NULL; + + wstring key_buf; + wstring::size_type ws1 = 0, ws2 = 0; + switch (msg) + { + case WM_INITDIALOG: + { + default_edit_proc = GetWindowLong(GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT), GWLP_WNDPROC); + SetWindowPos(hwndDlg, 0, load_key_rect.left, load_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); + SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT), GWLP_WNDPROC, (LONG_PTR)editctrl_ctrl_a); + HANDLE hcnt = hContact; + if(metaIsProtoMetaContacts(hcnt)) + hcnt = metaGetMostOnline(hcnt); + TranslateDialogDefault(hwndDlg); + { + string msg = Translate("Load Public GPG Key for "); + msg += (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hcnt, 0); + SetWindowTextA(hwndDlg, msg.c_str()); + } + bool isContactSecured(HANDLE); + if(!hcnt) + { + EnableWindow(GetDlgItem(hwndDlg, IDC_SELECT_EXISTING), 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLE_ENCRYPTION), 0); + } + if(isContactSecured(hcnt)) + SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, TranslateW(_T("Turn off encryption"))); + else + { + SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, TranslateW(_T("Turn on encryption"))); + CheckDlgButton(hwndDlg, IDC_ENABLE_ENCRYPTION, 1); + } + if(hcnt) + { + tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", _T("")); + wstring str = tmp; + mir_free(tmp); + wstring::size_type p = 0, stop = 0; + if(!str.empty()) + { + for(;;) + { + if((p = str.find(_T("\n"), p+2)) != wstring::npos) + { + if(p > stop) + { + stop = p; + str.insert(p, _T("\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; + wstring cmd = _T(" --export -a "); +// TCHAR *tmp3 = mir_a2t(tmp); + cmd += toUTF16(hcontact_data[hcnt].key_in_prescense); +// mir_free(tmp3); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog< stop) + { + stop = p; + out.insert(p, "\r"); + } + else + break; + } + } + TCHAR *tmp3 = mir_a2t(out.c_str()); + str.clear(); + str.append(tmp3); + string msg = "Load Public GPG Key for "; + msg += (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hcnt, 0); + msg += " (Key ID: "; + msg += hcontact_data[hcnt].key_in_prescense; + msg += " found in prescense, and exists in keyring.)"; + SetWindowTextA(hwndDlg, msg.c_str()); + } + else + { + string msg = "Load Public GPG Key (Key ID: "; + msg += hcontact_data[hcnt].key_in_prescense; + msg += " found in prescense.)"; + SetWindowTextA(hwndDlg, msg.c_str()); + EnableWindow(GetDlgItem(hwndDlg, IDC_IMPORT), 1); + } + } + mir_free(tmp2); + } + mir_free(tmp); + SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, !str.empty()?str.c_str():_T("")); + } + hPubKeyEdit = GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT); + return TRUE; + } + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case ID_OK: + { + tmp = new TCHAR [40960]; + TCHAR *begin, *end; + GetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, tmp, 40960); + key_buf.append(tmp); + key_buf.append(_T("\n")); //no new line at end of file ) + delete [] tmp; + while((ws1 = key_buf.find(_T("\r"), ws1)) != wstring::npos) + { + key_buf.erase(ws1, 1); //remove windows specific trash + } + ws1 = 0; + if(((ws2 = key_buf.find(_T("-----END PGP PUBLIC KEY BLOCK-----"))) != wstring::npos) && ((ws1 = key_buf.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"))) != wstring::npos)) + { + begin = new TCHAR [_tcslen(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) + 1]; + _tcscpy(begin, _T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); + end = new TCHAR [_tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")) + 1]; + _tcscpy(end, _T("-----END PGP PUBLIC KEY BLOCK-----")); + } + else if(((ws2 = key_buf.find(_T("-----END PGP PRIVATE KEY BLOCK-----"))) != wstring::npos) && ((ws1 = key_buf.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----"))) != wstring::npos)) + { + begin = new TCHAR [_tcslen(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) + 1]; + _tcscpy(begin, _T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); + end = new TCHAR [_tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----")) + 1]; + _tcscpy(end, _T("-----END PGP PRIVATE KEY BLOCK-----")); + } + else + { + MessageBox(0, _T("This is not public or private key"), _T("INFO"), MB_OK); + break; + } + ws2 += _tcslen(end); + bool allsubcontacts = false; + { + if(metaIsProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(MessageBox(0, _T("Do you want load key for all subcontacts ?"), _T("Metacontact detected"), MB_YESNO) == IDYES) + { + allsubcontacts = true; + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBWriteContactSettingTString(hcnt, szGPGModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str()); + } + } + else + DBWriteContactSettingTString(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str()); + } + else + DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str()); + } + tmp = new TCHAR [key_buf.length()+1]; + _tcscpy(tmp, key_buf.substr(ws1,ws2-ws1).c_str()); + { //gpg execute block + wstring cmd; + TCHAR tmp2[MAX_PATH] = {0}; + TCHAR *ptmp; + string output; + DWORD exitcode; + { + HANDLE hcnt = hContact; + if(metaIsProtoMetaContacts(hcnt)) + hcnt = metaGetMostOnline(hcnt); + ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + _tcscpy(tmp2, ptmp); + mir_free(ptmp); + _tcscat(tmp2, _T("\\")); + _tcscat(tmp2, _T("temporary_exported.asc")); + DeleteFile(tmp2); + wfstream f(tmp2, std::ios::out); + ptmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", _T("")); + wstring str = ptmp; + mir_free(ptmp); + wstring::size_type s = 0; + while((s = str.find(_T("\r"), s)) != wstring::npos) + { + str.erase(s, 1); + } + f< output.find("<", s)) + s2 = output.find("<", s); + if(s2 != string::npos) + { + tmp2 = new char [output.substr(s,s2-s-1).length()+1]; + strcpy(tmp2, output.substr(s,s2-s-1).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + { + if(metaIsProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(allsubcontacts) + { + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); + } + } + else + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); + } + else + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); + } + mir_free(tmp2); + tmp = mir_wstrdup(toUTF16(output.substr(s,s2-s-1)).c_str()); + if(hContact && hwndList_p) + ListView_SetItemText(hwndList_p, item_num, 2, tmp); + 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(output[s] == ')') + { + tmp2 = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp2, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + { + if(metaIsProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(allsubcontacts) + { + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); + } + } + else + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); + } + else + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); + } + mir_free(tmp2); + s+=3; + s2 = output.find(">", s); + tmp2 = new char [output.substr(s,s2-s).length()+1]; + strcpy(tmp2, output.substr(s,s2-s).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + { + if(metaIsProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(allsubcontacts) + { + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); + } + } + else + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); + } + else + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); + } + mir_free(tmp2); + 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 + { + tmp2 = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp2, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + { + if(metaIsProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(allsubcontacts) + { + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + } + } + else + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + } + else + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + } + mir_free(tmp2); + tmp = mir_wstrdup(toUTF16(output.substr(s2,s-s2)).c_str()); + if(hContact && hwndList_p) + ListView_SetItemText(hwndList_p, item_num, 3, tmp); + mir_free(tmp); + } + } + if(hContact && hwndList_p) + { + 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) + { + TCHAR *fp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", _T("")); + { + string out; + DWORD code; + wstring cmd = _T("--batch -a --export "); + cmd += fp; + mir_free(fp); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<code) + { + + case PSN_APPLY: + { + return TRUE; + } + } + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + { + GetWindowRect(hwndDlg, &load_key_rect); + DBWriteContactSettingDword(NULL, szGPGModuleName, "LoadKeyWindowX", load_key_rect.left); + DBWriteContactSettingDword(NULL, szGPGModuleName, "LoadKeyWindowY", load_key_rect.top); + } + break; + } + + return FALSE; +} + + + +void ShowLoadPublicKeyDialog() +{ + DialogBox(hInst, MAKEINTRESOURCE(IDD_LOAD_PUBLIC_KEY), NULL, (DLGPROC)DlgProcLoadPublicKey); +} diff --git a/src/resource.h b/src/resource.h new file mode 100755 index 0000000..027e279 --- /dev/null +++ b/src/resource.h @@ -0,0 +1,96 @@ +//{{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 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_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_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_STRIP_TAGS 1067 +#define IDC_CHECK1 1068 +#define IDC_PRESCENSE_SUBSCRIPTION 1068 +#define IDC_GENERATING_KEY 1069 +#define IDC_GENERATING_TEXT 1070 +#define IDC_KEY_ID 1071 +#define IDC_COMBO1 1072 +#define IDC_ACCOUNT 1072 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 114 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1073 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/src/srmm.cpp b/src/srmm.cpp new file mode 100755 index 0000000..6fc204a --- /dev/null +++ b/src/srmm.cpp @@ -0,0 +1,88 @@ +// 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 "commonheaders.h" + +void ShowStatusIcon(HANDLE hContact); +void setSrmmIcon(HANDLE hContact); + +int __cdecl onWindowEvent(WPARAM 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) { + HANDLE hContact = (HANDLE)wParam; + HANDLE hMeta = NULL; + if(metaIsProtoMetaContacts(hContact)) + { + hMeta = hContact; + hContact = metaGetMostOnline(hContact); // âîçüìåì òîò, ÷åðåç êîòîðûé ïîéäåò ñîîáùåíèå + } + else if(metaIsSubcontact(hContact)) + hMeta = metaGetContact(hContact); + StatusIconClickData *sicd = (StatusIconClickData *)lParam; + if(strcmp(sicd->szModule, szGPGModuleName)) + return 0; // not our event + + void setSrmmIcon(HANDLE); + void setClistIcon(HANDLE); + bool isContactHaveKey(HANDLE hContact); + BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + if(enc) + { + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + hMeta?DBWriteContactSettingByte(hMeta, szGPGModuleName, "GPGEncryption", 0):0; + setSrmmIcon(hContact); + setClistIcon(hContact); + } + else if(!enc) + { + if(!isContactHaveKey(hContact)) + { + void ShowLoadPublicKeyDialog(); + extern map user_data; + extern int item_num; + item_num = 0; //black magic here + user_data[1] = hContact; + ShowLoadPublicKeyDialog(); + } + else + { + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); + hMeta?DBWriteContactSettingByte(hMeta, szGPGModuleName, "GPGEncryption", 1):0; + setSrmmIcon(hContact); + setClistIcon(hContact); + return 0; + } + if(isContactHaveKey(hContact)) + { + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); + hMeta?DBWriteContactSettingByte(hMeta, szGPGModuleName, "GPGEncryption", 1):0; + setSrmmIcon(hContact); + setClistIcon(hContact); + } + } + return 0; +} diff --git a/src/utilities.cpp b/src/utilities.cpp new file mode 100755 index 0000000..2207213 --- /dev/null +++ b/src/utilities.cpp @@ -0,0 +1,1823 @@ +// 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 "commonheaders.h" + + +TCHAR* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, TCHAR* szDef) +{ + DBVARIANT dbv = {DBVT_DELETED}; + TCHAR* szRes; + if (DBGetContactSettingTString(hContact, szModule, szSetting, &dbv)) + return _tcsdup(szDef); + if(dbv.pszVal) + szRes = _tcsdup(dbv.ptszVal); + DBFreeVariant(&dbv); + return szRes; +} + +char* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, char* szDef) +{ + DBVARIANT dbv = {DBVT_DELETED}; + char* szRes; + if (DBGetContactSettingString(hContact, szModule, szSetting, &dbv)) + return _strdup(szDef); + if(dbv.pszVal) + szRes = _strdup(dbv.pszVal); + DBFreeVariant(&dbv); + return szRes; +} + + +char *date() +{ + setlocale( LC_ALL, "C" ); + static char d[11]; + char *tmp = __DATE__, m[4], mn[3] = "01"; + m[0]=tmp[0]; + m[1]=tmp[1]; + m[2]=tmp[2]; + if(strstr(m,"Jan")) + strcpy(mn,"01"); + else if(strstr(m,"Feb")) + strcpy(mn,"02"); + else if(strstr(m,"Mar")) + strcpy(mn,"03"); + else if(strstr(m,"Apr")) + strcpy(mn,"04"); + else if(strstr(m,"May")) + strcpy(mn,"05"); + else if(strstr(m,"Jun")) + strcpy(mn,"06"); + else if(strstr(m,"Jul")) + strcpy(mn,"07"); + else if(strstr(m,"Aug")) + strcpy(mn,"08"); + else if(strstr(m,"Sep")) + strcpy(mn,"09"); + else if(strstr(m,"Oct")) + strcpy(mn,"10"); + else if(strstr(m,"Nov")) + strcpy(mn,"11"); + else if(strstr(m,"Dec")) + strcpy(mn,"12"); + d[0]=tmp[7]; + d[1]=tmp[8]; + d[2]=tmp[9]; + d[3]=tmp[10]; + d[4]='.'; + d[5]=mn[0]; + d[6]=mn[1]; + d[7]='.'; + if (tmp[4] == ' ') + d[8] = '0'; + else + d[8]=tmp[4]; + d[9]=tmp[5]; + return d; +} + +void GetFilePath(TCHAR *WindowTittle, char *szSetting, TCHAR *szExt, TCHAR *szExtDesc) +{ + TCHAR str[MAX_PATH+2] = {0}, *tmp; + OPENFILENAME ofn={0}; + TCHAR filter[512], *pfilter; + ofn.lStructSize=CDSIZEOF_STRUCT(OPENFILENAME,lpTemplateName); + ofn.Flags=OFN_EXPLORER; + ofn.lpstrTitle=TranslateW(WindowTittle); + _tcscpy(filter,TranslateW(szExtDesc)); + pfilter=filter+_tcslen(filter)+1; + _tcscpy(pfilter, szExt); + pfilter[_tcslen(pfilter)+1] = '\0'; + pfilter[_tcslen(pfilter)+2] = '\0'; + ofn.lpstrFilter=filter; + tmp = UniGetContactSettingUtf(0, szGPGModuleName, szSetting, _T("")); + _tcscpy(str, tmp); + mir_free(tmp); + if(_tcslen(str)< 2) + str[0] = '\0'; + ofn.lpstrFile=str; + ofn.nMaxFile=_MAX_PATH; + ofn.nMaxFileTitle=MAX_PATH; + if(!GetOpenFileName(&ofn)) + return; + DBWriteContactSettingTString(0, szGPGModuleName, szSetting, str); +} + +TCHAR *GetFilePath(TCHAR *WindowTittle, TCHAR *szExt, TCHAR *szExtDesc, bool save_file) +{ + TCHAR *str = new TCHAR [MAX_PATH+2]; + OPENFILENAME ofn={0}; + TCHAR filter[512], *pfilter; + ofn.lStructSize=CDSIZEOF_STRUCT(OPENFILENAME,lpTemplateName); + ofn.Flags=OFN_EXPLORER; + ofn.lpstrTitle=TranslateW(WindowTittle); + _tcscpy(filter,TranslateW(szExtDesc)); + pfilter=filter+_tcslen(filter)+1; + _tcscpy(pfilter, szExt); + pfilter[_tcslen(pfilter)+1] = '\0'; + pfilter[_tcslen(pfilter)+2] = '\0'; + ofn.lpstrFilter=filter; + _tcscpy(str, _T("")); + if(_tcslen(str)< 2) + str[0] = '\0'; + ofn.lpstrFile=str; + ofn.nMaxFile=_MAX_PATH; + ofn.nMaxFileTitle=MAX_PATH; + if(!save_file) + { + if(!GetOpenFileName(&ofn)) + { + delete [] str; + return NULL; + } + } + else + { + if(!GetSaveFileName(&ofn)) + { + delete [] str; + return NULL; + } + } + return str; +} + +void GetFolderPath(TCHAR *WindowTittle, char *szSetting) +{ + BROWSEINFO pbi = {0}; + pbi.lpszTitle = WindowTittle; + pbi.ulFlags = BIF_EDITBOX|BIF_NEWDIALOGSTYLE|BIF_SHAREABLE; + LPITEMIDLIST pidl = SHBrowseForFolder(&pbi); + if (pidl != 0) + { + TCHAR path[MAX_PATH]; + if (SHGetPathFromIDList(pidl, path)) + { + DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", path); + } + IMalloc * imalloc = 0; + if (SUCCEEDED(SHGetMalloc(&imalloc))) + { + imalloc->Free(pidl); + imalloc->Release(); + } + } +} + +int LoadKey(WPARAM w, LPARAM l) +{ + void ShowLoadPublicKeyDialog(); + extern map user_data; + extern int item_num; + item_num = 0; //black magic here + user_data[1] = (HANDLE)w; + ShowLoadPublicKeyDialog(); + return 0; +} + +int SendKey(WPARAM w, LPARAM l) +{ + HANDLE hContact = (HANDLE)w; + if(metaIsProtoMetaContacts(hContact)) + hContact = metaGetMostOnline(hContact); + char *szMessage; + { + char *proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + char setting[64]; + if(proto) + { + strcpy(setting, proto); + strcat(setting, "_GPGPubKey"); + szMessage = UniGetContactSettingUtf(NULL, szGPGModuleName, setting, ""); + } + if(!szMessage[0]) + { + mir_free(szMessage); + szMessage = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); + } + } + if(szMessage[0]) + { + BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)szMessage); + HistoryLog(hContact, db_event("Public key sent", 0, 0, DBEF_SENT)); + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); + } + mir_free(szMessage); + return 0; +} + +extern HANDLE hLoadPublicKey, hToggleEncryption; + +int ToggleEncryption(WPARAM w, LPARAM l) +{ + HANDLE hContact = (HANDLE)w; + BYTE enc = 0; + if(metaIsProtoMetaContacts(hContact)) + enc = DBGetContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0); + else + enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + if(metaIsProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(MessageBox(0, _T("Do you want to toggle encryption for all subcontacts ?"), _T("Metacontact detected"), MB_YESNO) == IDYES) + { + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBWriteContactSettingByte(hcnt, szGPGModuleName, "GPGEncryption", enc?0:1); + } + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc?0:1); + } + } + else + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc?0:1); + void setSrmmIcon(HANDLE hContact); + void setClistIcon(HANDLE hContact); + setSrmmIcon(hContact); + setClistIcon(hContact); + enc = enc?0:1; + CLISTMENUITEM mi = {0}; + mi.cbSize=sizeof(mi); + mi.flags = CMIM_NAME; + enc?mi.pszName="Turn off GPG encryption":mi.pszName="Turn on GPG encryption"; + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hToggleEncryption, (LPARAM)&mi); + return 0; +} + +int OnPreBuildContactMenu(WPARAM w, LPARAM l) +{ + HANDLE hContact = (HANDLE)w; + if(metaIsProtoMetaContacts(hContact)) + hContact = metaGetMostOnline(hContact); + CLISTMENUITEM mi = {0}; + mi.cbSize=sizeof(mi); + mi.flags = CMIM_NAME; + TCHAR *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); + if(_tcslen(tmp) < 1) + { + DBDeleteContactSetting(hContact, szGPGModuleName, "GPGEncryption"); + mi.flags += CMIM_FLAGS | CMIF_GRAYED; + } + else + mi.flags = CMIM_NAME | CMIM_FLAGS; + mi.pszName = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)?"Turn off GPG encryption":"Turn on GPG encryption"; + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hToggleEncryption, (LPARAM)&mi); + return 0; +} + + +list transfers; +extern bool bFileTransfers; + +int onProtoAck(WPARAM w, LPARAM l) +{ + ACKDATA *ack=(ACKDATA*)l; + CCSDATA *ccs=(CCSDATA*)ack->lParam; + + if(ack->type == ACKTYPE_FILE && bFileTransfers) + { + switch(ack->result) + { + case ACKRESULT_DENIED: case ACKRESULT_FAILED: + break; + case ACKRESULT_SUCCESS: + { + PROTOFILETRANSFERSTATUS *f = (PROTOFILETRANSFERSTATUS*) ack->hProcess; + TCHAR *filename = NULL; + if(f->flags & PFTS_UNICODE) + { + if(f->tszCurrentFile && f->tszCurrentFile[0]) + filename = mir_wstrdup(f->tszCurrentFile); + if(!filename) + return 0; + } + else + { + if(f->szCurrentFile && f->szCurrentFile[0]) + filename = mir_utf8decodeT(f->szCurrentFile); + if(!filename) + return 0; + } + if(_tcsstr(filename, _T(".gpg"))) //decrypt it + { //process encrypted file + if(_waccess(f->tszCurrentFile, 0) == -1) + { + if(errno == ENOENT) + return 0; + } + string out; + DWORD code; + pxResult result; + wstring cmd = _T(" -o "); + wstring file = filename; + wstring::size_type p1 = file.rfind(_T(".gpg")); + file.erase(p1, _tcslen(_T(".gpg"))); + if(_waccess(file.c_str(), 0) != -1) + { + if(MessageBox(0, _T("Target file exists, do you want to replace it ?"), _T("Warning"), MB_YESNO) == IDNO) + return 0; + } + DeleteFile(file.c_str()); + file.insert(0, _T("\"")); + file.insert(file.length(), _T("\" ")); + cmd += file; + extern TCHAR *password; + { // password + TCHAR *pass = NULL; + char *keyid = UniGetContactSettingUtf(ack->hContact, szGPGModuleName, "KeyID", ""); + if(strlen(keyid) > 0) + { + string dbsetting = "szKey_"; + dbsetting += keyid; + dbsetting += "_Password"; + pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T("")); + if(_tcslen(pass) > 0) + debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; + } + else + { + pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); + if(_tcslen(pass) > 0) + debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; + } + if(_tcslen(pass) > 0) + { + cmd += _T("--passphrase \""); + cmd += pass; + cmd += _T("\" "); + } + else if(password) + { + debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; + cmd += _T("--passphrase \""); + cmd += password; + cmd += _T("\" "); + } + else + debuglog<hContact, GCDNF_TCHAR)<<" with out password\n"; + mir_free(pass); + mir_free(keyid); + } + cmd += _T(" -d \""); + cmd += filename; + cmd += _T("\""); + gpg_execution_params params; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread->timed_join(boost::posix_time::minutes(15))) + { + delete gpg_thread; + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<hContact, GCDNF_TCHAR)<<" password needed, trying to get one\n"; + if(_terminate) + break; + { //save inkey id + string::size_type s = out.find(" encrypted with "); + s = out.find(" ID ", s); + s += strlen(" ID "); + string::size_type s2 = out.find(",",s); + if(metaIsProtoMetaContacts(ack->hContact)) + DBWriteContactSettingString(metaGetMostOnline(ack->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); + else + DBWriteContactSettingString(ack->hContact, szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); + } + void ShowLoadKeyPasswordWindow(); + new_key_hcnt_mutex.lock(); + new_key_hcnt = ack->hContact; + ShowLoadKeyPasswordWindow(); + wstring cmd2 = cmd; + if(password) + { + debuglog<hContact, GCDNF_TCHAR)<<"\n"; + wstring tmp = _T("--passphrase \""); + tmp += password; + tmp += _T("\" "); + cmd2.insert(0, tmp); + } + out.clear(); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd2; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + gpg_thread = gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread->timed_join(boost::posix_time::seconds(15))) + { + delete gpg_thread; + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<type == ACKTYPE_MESSAGE) + { + extern std::list sent_msgs; + if(!sent_msgs.empty()) + { + if(ack->result == ACKRESULT_FAILED) + { + std::list::iterator it = std::find(sent_msgs.begin(), sent_msgs.end(), ack->hProcess); + if(it != sent_msgs.end()) + { + HistoryLog(ack->hContact, db_event("Failed to send encrypted message", 0,0, 0)); + + } + } + else if(ack->result == ACKRESULT_SUCCESS) + { + std::list::iterator it = std::find(sent_msgs.begin(), sent_msgs.end(), ack->hProcess); + if(it != sent_msgs.end()) + sent_msgs.erase(it); + } + } + } + return 0; +} + +std::wstring encrypt_file(HANDLE hContact, TCHAR *filename) +{ + string out; + DWORD code; + pxResult result; + HANDLE hcnt = metaIsProtoMetaContacts(hContact)?metaGetMostOnline(hContact):hContact; + wstring cmd = _T("--batch --yes -r "); + char *keyid = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID", ""); + TCHAR *szKeyid = mir_a2t(keyid); + TCHAR *name = _tcsrchr(filename,_T('\\')); + if( !name ) + name = filename; + else + name++; + TCHAR *file_out = new TCHAR [_tcslen(filename)+4]; + mir_sntprintf(file_out, _tcslen(name)+7, _T("%s.gpg"), name); + cmd += szKeyid; + if(DBGetContactSettingByte(hcnt, szGPGModuleName, "bAlwaysTrust", 0)) + cmd += _T(" --trust-model always "); + mir_free(szKeyid); + mir_free(keyid); + cmd += _T(" -o \""); + TCHAR *temp = _tgetenv(_T("TEMP")); + cmd += temp; + cmd += _T("\\"); + cmd += file_out; + wstring path_out = temp; + path_out += _T("\\"); + path_out += file_out; + DeleteFile(path_out.c_str()); + cmd += _T("\" "); + mir_free(temp); + cmd += _T(" -e \""); + cmd += filename; + cmd += _T("\" "); + gpg_execution_params params; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + mir_free(keyid); + delete [] file_out; + boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) + { + delete gpg_thread; + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<timed_join(boost::posix_time::seconds(180))) + { + delete gpg_thread; + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog<hContact)) + { + + DWORD flags = (DWORD)ccs->wParam; //check for PFTS_UNICODE here + int i; +// if(flags & PFTS_UNICODE) //this does not work .... + if(StriStr(ccs->szProtoService, "/sendfilew")) + { + TCHAR **file=(TCHAR **)ccs->lParam; + for(i = 0; file[i]; i++) + { + if(_waccess(file[i], 0) == -1) + if(errno == ENOENT) + return 0; //we do not want to send file unencrypted (sometimes ack have wrong info) + if (_tcsstr(file[i],_T(".gpg"))) + continue; + std::wstring path_out = encrypt_file(ccs->hContact, file[i]); + mir_free(file[i]); + file[i] = mir_tstrdup(path_out.c_str()); + transfers.push_back(path_out); + } + } + else + { + char **file = (char**) ccs->lParam; + for(i = 0; file[i]; i++) + { + if(_access(file[i], 0) == -1) + if(errno == ENOENT) + return 0; //we do not want to send file unencrypted (sometimes ack have wrong info) + if (strstr(file[i],".gpg")) + continue; + TCHAR *tmp = mir_utf8decodeT(file[i]); + std::wstring path_out = encrypt_file(ccs->hContact, tmp); + mir_free(tmp); + char* tmp2 = mir_utf8encodeW(path_out.c_str()); + mir_free(file[i]); + file[i] = tmp2; + transfers.push_back(path_out); + + } + } + } + return CallService(MS_PROTO_CHAINSEND, w, l); +} + +void storeOutput(HANDLE ahandle, string *output) +{ + BOOL success; + char readbuffer[4096] = {0}; + unsigned long transfered, available; + + do { + PeekNamedPipe(ahandle,NULL,0,NULL,&available,NULL); + if (!available) + continue; + success=ReadFile(ahandle,readbuffer,sizeof(readbuffer),&transfered,NULL); + if (success && transfered) + output->append(readbuffer, 4096); + } while (available>0); +} + +void HistoryLog(HANDLE hContact, db_event evt) +{ + DBEVENTINFO Event = {0}; + Event.cbSize = sizeof(Event); + Event.szModule = szGPGModuleName; + Event.eventType = evt.eventType; + Event.flags = evt.flags; + if(!evt.timestamp) + Event.timestamp = (DWORD)time(NULL); + else + Event.timestamp = evt.timestamp; + Event.cbBlob = strlen((char*)evt.pBlob)+1; + Event.pBlob = (PBYTE)_strdup((char*)evt.pBlob); + CallService(MS_DB_EVENT_ADD, (WPARAM)(HANDLE)hContact,(LPARAM)&Event); +} + +static int ControlAddStringUtf(HWND ctrl, DWORD msg, const TCHAR *szString) +{ + int item = -1; + item = SendMessage(ctrl, msg, 0, (LPARAM)szString); + return item; +} + +int ComboBoxAddStringUtf(HWND hCombo, const TCHAR *szString, DWORD data) +{ + int item = ControlAddStringUtf(hCombo, CB_ADDSTRING, szString); + SendMessage(hCombo, CB_SETITEMDATA, item, data); + + return item; +} + + +int GetJabberInterface(WPARAM w, LPARAM l) //get interface for all jabber accounts, options later +{ + extern list Accounts; + void AddHandlers(); + int count = 0; + PROTOACCOUNT **accounts; + ProtoEnumAccounts(&count, &accounts); + list ::iterator p; + Accounts.clear(); + Accounts.push_back(new JabberAccount); + p = Accounts.begin(); + (*p)->setAccountNumber(0); + for(int i = 0; i < count; i++) //get only jabber accounts from all accounts + { + IJabberInterface *JIftmp = getJabberApi(accounts[i]->szModuleName); + int a = 0; + if(JIftmp) + { + (*p)->setJabberInterface(JIftmp); + if(accounts[i]->tszAccountName) + { + TCHAR* tmp = mir_tstrdup(accounts[i]->tszAccountName); + (*p)->setAccountName(tmp); + } + else + { + TCHAR *tmp = mir_a2t(accounts[i]->szModuleName); + (*p)->setAccountName(tmp); + } + (*p)->setAccountNumber(a); + a++; + Accounts.push_back(new JabberAccount); + p++; + } + } + Accounts.pop_back(); + AddHandlers(); + return 0; +} + +static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pUserData) +{ + HXML local_node = node; + for(int n = 0; n <= xi.getChildCount(node); n++) + { + LPCTSTR str = xi.getText(local_node); + LPCTSTR nodename = xi.getName(local_node); + if(str) + { + if(_tcsstr(str, _T("-----BEGIN PGP MESSAGE-----")) && _tcsstr(str, _T("-----END PGP MESSAGE-----"))) + { + wstring data = str; + xi.setText(local_node, _T("This message is encrypted.")); + wstring::size_type p1 = data.find(_T("-----BEGIN PGP MESSAGE-----")) + _tcslen(_T("-----BEGIN PGP MESSAGE-----")); + while(data.find(_T("Version: "), p1) != wstring::npos) + { + p1 = data.find(_T("Version: "), p1); + p1 = data.find(_T("\n"), p1); + } + while(data.find(_T("Comment: "), p1) != wstring::npos) + { + p1 = data.find(_T("Comment: "), p1); + p1 = data.find(_T("\n"), p1); + } + while(data.find(_T("Encoding: "), p1) != wstring::npos) + { + p1 = data.find(_T("Encoding: "), p1); + p1 = data.find(_T("\n"), p1); + } + p1+=2; + wstring::size_type p2 = data.find(_T("-----END PGP MESSAGE-----")); + HXML encrypted_data = xi.addChild(node, _T("x"), data.substr(p1, p2-p1).c_str()); + xi.addAttr(encrypted_data, _T("xmlns"), _T("jabber:x:encrypted")); + return FALSE; + } + } + if(bPresenceSigning && nodename) + { + if(_tcsstr(nodename, _T("status"))) + { + TCHAR *path_c = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + wstring path_out = path_c; + wstring file = toUTF16(get_random(10)); + mir_free(path_c); + path_out += _T("\\tmp\\"); + path_out += file; + DeleteFile(path_out.c_str()); + wfstream f(path_out.c_str(), std::ios::out); + f<Sys()->GetModuleName(); + char setting[64]; + strcpy(setting, proto); + strcat(setting, "_KeyID"); + inkeyid = UniGetContactSettingUtf(NULL, szGPGModuleName, setting, ""); + if(!inkeyid[0]) + { + mir_free(inkeyid); + inkeyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); + } + } + TCHAR *pass = NULL; + if(inkeyid[0]) + { + string dbsetting = "szKey_"; + dbsetting += inkeyid; + dbsetting += "_Password"; + pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T("")); + if(pass[0]) + debuglog< Accounts; + list ::iterator p = Accounts.begin(); + for(unsigned int i = 0; i < Accounts.size(); i++, p++) + { + if(!(*p)) + break; + hContact = (*p)->getJabberInterface()->Sys()->ContactFromJID(xi.getAttrValue(node, _T("from"))); + if(hContact) + hcontact_data[hContact].key_in_prescense = out.substr(p1, p2-p1-1).c_str(); + } + } + } + } + } + return FALSE; + } + } + } + } + local_node = xi.getChild(node, n); + } + return FALSE; +} + +static JABBER_HANDLER_FUNC MessageHandler(IJabberInterface *ji, HXML node, void *pUserData) +{ + return FALSE; +} + + + + +void AddHandlers() +{ + extern list Accounts; + list::iterator end = Accounts.end(); + for(list::iterator p = Accounts.begin(); p != end; p++) + { + if(!(*p)) + break; + if((*p)->getSendHandler() == INVALID_HANDLE_VALUE) + (*p)->setSendHandler((*p)->getJabberInterface()->Net()->AddSendHandler((JABBER_HANDLER_FUNC)SendHandler)); + if((*p)->getPrescenseHandler() == INVALID_HANDLE_VALUE) + (*p)->setPrescenseHandler((*p)->getJabberInterface()->Net()->AddPresenceHandler((JABBER_HANDLER_FUNC)PrescenseHandler)); +// if((*p)->getMessageHandler() == INVALID_HANDLE_VALUE) +// (*p)->setMessageHandler((*p)->getJabberInterface()->Net()->AddMessageHandler((JABBER_HANDLER_FUNC)MessageHandler, JABBER_MESSAGE_TYPE_ANY ,NULL,NULL)); + if(bAutoExchange) + { + (*p)->getJabberInterface()->Net()->RegisterFeature(_T("GPG_Key_Auto_Exchange:0"), _T("Indicates that gpg installed and configured to public key auto exchange (currently implemented in new_gpg Miranda IM plugin)")); + (*p)->getJabberInterface()->Net()->AddFeatures(_T("GPG_Key_Auto_Exchange:0\0\0")); + } + } +} + +bool isContactSecured(HANDLE hContact) +{ + BYTE gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + if(!gpg_enc) + { + debuglog< 0) + { + mir_free(key); + return true; + } + mir_free(key); + return false; +} + +bool isGPGKeyExist() +{ + TCHAR *id = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", _T("")); + char *key = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); + if(id[0] && key[0]) + { + mir_free(id); + mir_free(key); + return true; + } + mir_free(id); + mir_free(key); + return false; +} +bool isGPGValid() +{ + TCHAR *tmp; + bool gpg_exists = false, is_valid = true; + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("")); + if(_waccess(tmp, 0) != -1) + gpg_exists = true; + else + { + mir_free(tmp); + TCHAR *path = new TCHAR [MAX_PATH]; + char *mir_path = new char [MAX_PATH]; + CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + SetCurrentDirectoryA(mir_path); + tmp = mir_a2t(mir_path); + mir_free(mir_path); + mir_realloc(path, (_tcslen(path)+128)*sizeof(TCHAR)); + TCHAR *gpg_path = new TCHAR [MAX_PATH]; + _tcscpy(gpg_path, tmp); + _tcscat(gpg_path, _T("\\GnuPG\\gpg.exe")); + mir_free(tmp); + if(_waccess(gpg_path, 0) != -1) + { + gpg_exists = true; + _tcscpy(path, _T("GnuPG\\gpg.exe")); + } + mir_free(gpg_path); + tmp = mir_wstrdup(path); + delete [] path; + } + DWORD len = MAX_PATH; + if(gpg_exists) + { + DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); + string out; + DWORD code; + wstring cmd = _T("--version"); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + gpg_valid = true; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; + debuglog< + +struct TFakeAckParams { + inline TFakeAckParams( HANDLE p1, HANDLE p2, LONG p3, LPCSTR p4 ) : + hEvent( p1 ), + hContact( p2 ), + id( p3 ), + msg( p4 ) + {} + + HANDLE hEvent; + HANDLE hContact; + LONG id; + LPCSTR msg; +}; + +int SendBroadcast( HANDLE hContact, int type, int result, HANDLE hProcess, LPARAM lParam ) { + ACKDATA ack; + memset(&ack,0,sizeof(ack)); + ack.cbSize = sizeof( ACKDATA ); + ack.szModule = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + ack.hContact = hContact; + ack.type = type; + ack.result = result; + ack.hProcess = hProcess; + ack.lParam = lParam; + return CallService( MS_PROTO_BROADCASTACK, 0, ( LPARAM )&ack ); +} + + + +unsigned __stdcall sttFakeAck( LPVOID param ) { + + TFakeAckParams* tParam = ( TFakeAckParams* )param; + WaitForSingleObject( tParam->hEvent, INFINITE ); + + Sleep( 100 ); + if ( tParam->msg == NULL ) + SendBroadcast( tParam->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, ( HANDLE )tParam->id, 0 ); + else + SendBroadcast( tParam->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, ( HANDLE )tParam->id, LPARAM( tParam->msg )); + + CloseHandle( tParam->hEvent ); + delete tParam; + + return 0; +} + + +int returnNoError(HANDLE hContact) { + HANDLE hEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); + unsigned int tID; + CloseHandle( (HANDLE) _beginthreadex(NULL, 0, sttFakeAck, new TFakeAckParams(hEvent,hContact,777,0), 0, &tID) ); + SetEvent( hEvent ); + return 777; +} +// end from secureim + + +string toUTF8(wstring str) +{ + string ustr; + try{ + utf8::utf16to8(str.begin(), str.end(), back_inserter(ustr)); + } + catch(const utf8::exception& e) + { + debuglog<> gen(rng, boost::uniform_int<>(0, chars.length()-1)); + for(int i = 0; i < length; ++i) + data += chars[gen()]; + return data; +} + +void send_encrypted_msgs_thread(HANDLE hContact) +{ + while(true) + { + char *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", ""); + while(!isContactSecured(hContact)) + boost::this_thread::sleep(boost::posix_time::seconds(1)); + if(!hcontact_data[hContact].msgs_to_send.empty()) + { + boost::this_thread::sleep(boost::posix_time::seconds(1)); + list::iterator end = hcontact_data[hContact].msgs_to_send.end(); + extern std::list sent_msgs; + for(list::iterator p = hcontact_data[hContact].msgs_to_send.begin(); p != end; ++p) + { + sent_msgs.push_back((HANDLE)CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)p->c_str())); + HistoryLog(hContact, db_event((char*)p->c_str(),0,0, DBEF_SENT)); + boost::this_thread::sleep(boost::posix_time::seconds(1)); + } + hcontact_data[hContact].msgs_to_send.clear(); + return; + } + else + return; + } +} + +string time_str() +{ + boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); + return (string)boost::posix_time::to_simple_string(now); +} + +int handleEnum(const char *szSetting, LPARAM lParam) +{ + if(!*(bool*)lParam && szSetting[0] && StriStr(szSetting, "tabsrmm")) + { + bool f = false, *found = (bool*)lParam; + f = !DBGetContactSettingByte(NULL, "PluginDisable", szSetting, 0); + if(f) + *found = f; + } + return 0; +} + +bool isTabsrmmUsed() +{ + DBCONTACTENUMSETTINGS enm = {0}; + bool found = false; + enm.lParam = (LPARAM)&found; + enm.pfnEnumProc = (DBSETTINGENUMPROC)&handleEnum; + enm.szModule = "PluginDisable"; + if(CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)NULL, (LPARAM)&enm) == -1) + return false; + + return found; +} + + +int ExportGpGKeys(WPARAM w, LPARAM l) +{ + TCHAR *p = GetFilePath(_T("Choose file to export public keys"), _T("*"), _T("Any file"), true); + if(!p || !p[0]) + { + delete [] p; + //TODO: handle error + return 1; + } + char *path = mir_t2a(p); + delete [] p; + std::ofstream file; + file.open(path, std::ios::trunc | std::ios::out); + mir_free(path); + int exported_keys = 0; + if(!file.is_open()) + return 1; //TODO: handle error + for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) + { + char *k = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", ""); + if(!k[0]) + { + mir_free(k); + continue; + } + std::string key = k; + mir_free(k); + + const char* proto = (const char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + std::string id = "Comment: login "; + const char * uid = (const char*)CallProtoService(proto, PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDSETTING, 0); + DBVARIANT dbv = {0}; + DBCONTACTGETSETTING dbcgs = {0}; + dbcgs.pValue = &dbv; + dbcgs.szModule = proto; + dbcgs.szSetting = uid; + CallService(MS_DB_CONTACT_GETSETTING, 0, (LPARAM)&dbcgs); + switch(dbcgs.pValue->type) + { + case DBVT_DELETED: + continue; + break; + case DBVT_BYTE: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal); + id += _id; + } + break; + case DBVT_WORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal); + id += _id; + } + break; + case DBVT_DWORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal); + id += _id; + } + break; + case DBVT_ASCIIZ: + { + id += dbcgs.pValue->pszVal; + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + } + break; + case DBVT_UTF8: + { + char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal); + if(tmp[0]) + id += tmp; + mir_free(tmp); + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + } + break; + case DBVT_BLOB: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + case DBVT_WCHAR: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + } + id += " contact_id "; + ZeroMemory(&dbv, sizeof(dbv)); + ZeroMemory(&dbcgs, sizeof(dbcgs)); + dbcgs.pValue = &dbv; + dbcgs.szModule = proto; + dbcgs.szSetting = uid; + CallService(MS_DB_CONTACT_GETSETTING, (WPARAM)hContact, (LPARAM)&dbcgs); + switch(dbcgs.pValue->type) + { + case DBVT_DELETED: + continue; + break; + case DBVT_BYTE: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal); + id += _id; + } + break; + case DBVT_WORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal); + id += _id; + } + break; + case DBVT_DWORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal); + id += _id; + } + break; + case DBVT_ASCIIZ: + { + id += dbcgs.pValue->pszVal; + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + } + break; + case DBVT_UTF8: + { + char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal); + if(tmp[0]) + id += tmp; + mir_free(tmp); + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + } + break; + case DBVT_BLOB: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + case DBVT_WCHAR: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + } + std::string::size_type p1 = key.find("-----BEGIN PGP PUBLIC KEY BLOCK-----"); + if(p1 == std::string::npos) + continue; + p1 += strlen("-----BEGIN PGP PUBLIC KEY BLOCK-----"); + p1 ++; + id += '\n'; + key.insert(p1, id); + file<szModuleName, PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDSETTING, 0); + DBVARIANT dbv = {0}; + DBCONTACTGETSETTING dbcgs = {0}; + dbcgs.pValue = &dbv; + dbcgs.szModule = accs[i]->szModuleName; + dbcgs.szSetting = uid; + CallService(MS_DB_CONTACT_GETSETTING, 0, (LPARAM)&dbcgs); + std::string id; + switch(dbcgs.pValue->type) + { + case DBVT_DELETED: + continue; + break; + case DBVT_BYTE: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal); + id += _id; + if(id == login) + acc = accs[i]->szModuleName; + } + break; + case DBVT_WORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal); + id += _id; + if(id == login) + acc = accs[i]->szModuleName; + } + break; + case DBVT_DWORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal); + id += _id; + if(id == login) + acc = accs[i]->szModuleName; + } + break; + case DBVT_ASCIIZ: + { + id += dbcgs.pValue->pszVal; + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + if(id == login) + acc = accs[i]->szModuleName; + } + break; + case DBVT_UTF8: + { + char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal); + if(tmp[0]) + id += tmp; + mir_free(tmp); + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + if(id == login) + acc = accs[i]->szModuleName; + } + break; + case DBVT_BLOB: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + case DBVT_WCHAR: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + } + } + if(acc.length()) + { + const char * uid = (const char*)CallProtoService(acc.c_str(), PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDSETTING, 0); + for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, (LPARAM)acc.c_str()); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, (LPARAM)acc.c_str())) + { + DBVARIANT dbv = {0}; + DBCONTACTGETSETTING dbcgs = {0}; + dbcgs.pValue = &dbv; + dbcgs.szModule = acc.c_str(); + dbcgs.szSetting = uid; + CallService(MS_DB_CONTACT_GETSETTING, (WPARAM)hContact, (LPARAM)&dbcgs); + std::string id; + bool found = false; + switch(dbcgs.pValue->type) + { + case DBVT_DELETED: + continue; + break; + case DBVT_BYTE: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal); + id += _id; + if(id == contact_id) + found = true; + } + break; + case DBVT_WORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal); + id += _id; + if(id == contact_id) + found = true; + } + break; + case DBVT_DWORD: + { + char _id[64]; + mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal); + id += _id; + if(id == contact_id) + found = true; + } + break; + case DBVT_ASCIIZ: + { + id += dbcgs.pValue->pszVal; + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + if(id == contact_id) + found = true; + } + break; + case DBVT_UTF8: + { + char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal); + if(tmp[0]) + id += tmp; + mir_free(tmp); + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + if(id == contact_id) + found = true; + } + break; + case DBVT_BLOB: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + case DBVT_WCHAR: + //TODO + CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); + break; + } + if(found) + { + wstring cmd; + TCHAR tmp2[MAX_PATH] = {0}; + TCHAR *ptmp; + string output; + DWORD exitcode; + { + HANDLE hcnt = hContact; + ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + _tcscpy(tmp2, ptmp); + mir_free(ptmp); + _tcscat(tmp2, _T("\\")); + _tcscat(tmp2, _T("temporary_exported.asc")); + DeleteFile(tmp2); + wfstream f(tmp2, std::ios::out); + f< output.find("<", s)) + s2 = output.find("<", s); + if(s2 != string::npos) + { + tmp2 = new char [output.substr(s,s2-s-1).length()+1]; + strcpy(tmp2, output.substr(s,s2-s-1).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + { + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); + } + mir_free(tmp2); + if((s = output.find(")", s2)) == string::npos) + s = output.find(">", s2); + else if(s > output.find(">", s2)) + s = output.find(">", s2); + s2++; + if(output[s] == ')') + { + tmp2 = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp2, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); + mir_free(tmp2); + s+=3; + s2 = output.find(">", s); + tmp2 = new char [output.substr(s,s2-s).length()+1]; + strcpy(tmp2, output.substr(s,s2-s).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); + mir_free(tmp2); + } + else + { + tmp2 = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp2, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + mir_free(tmp2); + } + } + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); + DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", toUTF16(key).c_str()); + } + DeleteFile(tmp2); + break; + } + } + } + key.clear(); + } + } + if(file.is_open()) + file.close(); + char msg[512]; + mir_snprintf(msg, 511, "we have succesfully processed %d keys", processed_keys); + MessageBoxA(NULL, msg, Translate("Keys import result"), MB_OK); + return 0; +} \ No newline at end of file diff --git a/src/utilities.h b/src/utilities.h new file mode 100755 index 0000000..30e9f68 --- /dev/null +++ b/src/utilities.h @@ -0,0 +1,104 @@ +// 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 +TCHAR* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, TCHAR* szDef); +char* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, char* szDef); +void GetFilePath(TCHAR *WindowTittle, char *szSetting, TCHAR *szExt, TCHAR *szExtDesc); +TCHAR *GetFilePath(TCHAR *WindowTittle, TCHAR *szExt, TCHAR *szExtDesc, bool save_file = false); +void GetFolderPath(TCHAR *WindowTittle, char *szSetting); + +void storeOutput(HANDLE ahandle, string *output); + +int ComboBoxAddStringUtf(HWND hCombo, const TCHAR *szString, DWORD data); +bool isContactSecured(HANDLE hContact); +bool isContactHaveKey(HANDLE 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 = 0; + szModule = 0; + cbSize = 0; + cbBlob = strlen(msg)+1; + pBlob = (PBYTE)msg; + } + db_event(char* msg, DWORD time) + { + cbBlob = strlen(msg)+1; + pBlob = (PBYTE)msg; + eventType = EVENTTYPE_MESSAGE; + flags = 0; + timestamp = time; + szModule = 0; + cbSize = 0; + } + db_event(char* msg, DWORD time, int type) + { + cbBlob = strlen(msg)+1; + pBlob = (PBYTE)msg; + if(type) + eventType = type; + else + eventType = EVENTTYPE_MESSAGE; + flags = 0; + timestamp = time; + szModule = 0; + cbSize = 0; + } + db_event(char* msg, int type) + { + cbBlob = strlen(msg)+1; + pBlob = (PBYTE)msg; + flags = 0; + if(type) + eventType = type; + else + eventType = EVENTTYPE_MESSAGE; + timestamp = 0; + szModule = 0; + cbSize = 0; + } + db_event(char* msg, DWORD time, int type, DWORD _flags) + { + cbBlob = strlen(msg)+1; + pBlob = (PBYTE)msg; + if(type) + eventType = type; + else + eventType = EVENTTYPE_MESSAGE; + flags = _flags; + timestamp = time; + szModule = 0; + cbSize = 0; + } +}; +void HistoryLog(HANDLE, db_event); + +#endif diff --git a/srmm.cpp b/srmm.cpp deleted file mode 100755 index 6fc204a..0000000 --- a/srmm.cpp +++ /dev/null @@ -1,88 +0,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 "commonheaders.h" - -void ShowStatusIcon(HANDLE hContact); -void setSrmmIcon(HANDLE hContact); - -int __cdecl onWindowEvent(WPARAM 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) { - HANDLE hContact = (HANDLE)wParam; - HANDLE hMeta = NULL; - if(metaIsProtoMetaContacts(hContact)) - { - hMeta = hContact; - hContact = metaGetMostOnline(hContact); // âîçüìåì òîò, ÷åðåç êîòîðûé ïîéäåò ñîîáùåíèå - } - else if(metaIsSubcontact(hContact)) - hMeta = metaGetContact(hContact); - StatusIconClickData *sicd = (StatusIconClickData *)lParam; - if(strcmp(sicd->szModule, szGPGModuleName)) - return 0; // not our event - - void setSrmmIcon(HANDLE); - void setClistIcon(HANDLE); - bool isContactHaveKey(HANDLE hContact); - BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); - if(enc) - { - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); - hMeta?DBWriteContactSettingByte(hMeta, szGPGModuleName, "GPGEncryption", 0):0; - setSrmmIcon(hContact); - setClistIcon(hContact); - } - else if(!enc) - { - if(!isContactHaveKey(hContact)) - { - void ShowLoadPublicKeyDialog(); - extern map user_data; - extern int item_num; - item_num = 0; //black magic here - user_data[1] = hContact; - ShowLoadPublicKeyDialog(); - } - else - { - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); - hMeta?DBWriteContactSettingByte(hMeta, szGPGModuleName, "GPGEncryption", 1):0; - setSrmmIcon(hContact); - setClistIcon(hContact); - return 0; - } - if(isContactHaveKey(hContact)) - { - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); - hMeta?DBWriteContactSettingByte(hMeta, szGPGModuleName, "GPGEncryption", 1):0; - setSrmmIcon(hContact); - setClistIcon(hContact); - } - } - return 0; -} diff --git a/utilities.cpp b/utilities.cpp deleted file mode 100755 index 2207213..0000000 --- a/utilities.cpp +++ /dev/null @@ -1,1823 +0,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 "commonheaders.h" - - -TCHAR* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, TCHAR* szDef) -{ - DBVARIANT dbv = {DBVT_DELETED}; - TCHAR* szRes; - if (DBGetContactSettingTString(hContact, szModule, szSetting, &dbv)) - return _tcsdup(szDef); - if(dbv.pszVal) - szRes = _tcsdup(dbv.ptszVal); - DBFreeVariant(&dbv); - return szRes; -} - -char* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, char* szDef) -{ - DBVARIANT dbv = {DBVT_DELETED}; - char* szRes; - if (DBGetContactSettingString(hContact, szModule, szSetting, &dbv)) - return _strdup(szDef); - if(dbv.pszVal) - szRes = _strdup(dbv.pszVal); - DBFreeVariant(&dbv); - return szRes; -} - - -char *date() -{ - setlocale( LC_ALL, "C" ); - static char d[11]; - char *tmp = __DATE__, m[4], mn[3] = "01"; - m[0]=tmp[0]; - m[1]=tmp[1]; - m[2]=tmp[2]; - if(strstr(m,"Jan")) - strcpy(mn,"01"); - else if(strstr(m,"Feb")) - strcpy(mn,"02"); - else if(strstr(m,"Mar")) - strcpy(mn,"03"); - else if(strstr(m,"Apr")) - strcpy(mn,"04"); - else if(strstr(m,"May")) - strcpy(mn,"05"); - else if(strstr(m,"Jun")) - strcpy(mn,"06"); - else if(strstr(m,"Jul")) - strcpy(mn,"07"); - else if(strstr(m,"Aug")) - strcpy(mn,"08"); - else if(strstr(m,"Sep")) - strcpy(mn,"09"); - else if(strstr(m,"Oct")) - strcpy(mn,"10"); - else if(strstr(m,"Nov")) - strcpy(mn,"11"); - else if(strstr(m,"Dec")) - strcpy(mn,"12"); - d[0]=tmp[7]; - d[1]=tmp[8]; - d[2]=tmp[9]; - d[3]=tmp[10]; - d[4]='.'; - d[5]=mn[0]; - d[6]=mn[1]; - d[7]='.'; - if (tmp[4] == ' ') - d[8] = '0'; - else - d[8]=tmp[4]; - d[9]=tmp[5]; - return d; -} - -void GetFilePath(TCHAR *WindowTittle, char *szSetting, TCHAR *szExt, TCHAR *szExtDesc) -{ - TCHAR str[MAX_PATH+2] = {0}, *tmp; - OPENFILENAME ofn={0}; - TCHAR filter[512], *pfilter; - ofn.lStructSize=CDSIZEOF_STRUCT(OPENFILENAME,lpTemplateName); - ofn.Flags=OFN_EXPLORER; - ofn.lpstrTitle=TranslateW(WindowTittle); - _tcscpy(filter,TranslateW(szExtDesc)); - pfilter=filter+_tcslen(filter)+1; - _tcscpy(pfilter, szExt); - pfilter[_tcslen(pfilter)+1] = '\0'; - pfilter[_tcslen(pfilter)+2] = '\0'; - ofn.lpstrFilter=filter; - tmp = UniGetContactSettingUtf(0, szGPGModuleName, szSetting, _T("")); - _tcscpy(str, tmp); - mir_free(tmp); - if(_tcslen(str)< 2) - str[0] = '\0'; - ofn.lpstrFile=str; - ofn.nMaxFile=_MAX_PATH; - ofn.nMaxFileTitle=MAX_PATH; - if(!GetOpenFileName(&ofn)) - return; - DBWriteContactSettingTString(0, szGPGModuleName, szSetting, str); -} - -TCHAR *GetFilePath(TCHAR *WindowTittle, TCHAR *szExt, TCHAR *szExtDesc, bool save_file) -{ - TCHAR *str = new TCHAR [MAX_PATH+2]; - OPENFILENAME ofn={0}; - TCHAR filter[512], *pfilter; - ofn.lStructSize=CDSIZEOF_STRUCT(OPENFILENAME,lpTemplateName); - ofn.Flags=OFN_EXPLORER; - ofn.lpstrTitle=TranslateW(WindowTittle); - _tcscpy(filter,TranslateW(szExtDesc)); - pfilter=filter+_tcslen(filter)+1; - _tcscpy(pfilter, szExt); - pfilter[_tcslen(pfilter)+1] = '\0'; - pfilter[_tcslen(pfilter)+2] = '\0'; - ofn.lpstrFilter=filter; - _tcscpy(str, _T("")); - if(_tcslen(str)< 2) - str[0] = '\0'; - ofn.lpstrFile=str; - ofn.nMaxFile=_MAX_PATH; - ofn.nMaxFileTitle=MAX_PATH; - if(!save_file) - { - if(!GetOpenFileName(&ofn)) - { - delete [] str; - return NULL; - } - } - else - { - if(!GetSaveFileName(&ofn)) - { - delete [] str; - return NULL; - } - } - return str; -} - -void GetFolderPath(TCHAR *WindowTittle, char *szSetting) -{ - BROWSEINFO pbi = {0}; - pbi.lpszTitle = WindowTittle; - pbi.ulFlags = BIF_EDITBOX|BIF_NEWDIALOGSTYLE|BIF_SHAREABLE; - LPITEMIDLIST pidl = SHBrowseForFolder(&pbi); - if (pidl != 0) - { - TCHAR path[MAX_PATH]; - if (SHGetPathFromIDList(pidl, path)) - { - DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", path); - } - IMalloc * imalloc = 0; - if (SUCCEEDED(SHGetMalloc(&imalloc))) - { - imalloc->Free(pidl); - imalloc->Release(); - } - } -} - -int LoadKey(WPARAM w, LPARAM l) -{ - void ShowLoadPublicKeyDialog(); - extern map user_data; - extern int item_num; - item_num = 0; //black magic here - user_data[1] = (HANDLE)w; - ShowLoadPublicKeyDialog(); - return 0; -} - -int SendKey(WPARAM w, LPARAM l) -{ - HANDLE hContact = (HANDLE)w; - if(metaIsProtoMetaContacts(hContact)) - hContact = metaGetMostOnline(hContact); - char *szMessage; - { - char *proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - char setting[64]; - if(proto) - { - strcpy(setting, proto); - strcat(setting, "_GPGPubKey"); - szMessage = UniGetContactSettingUtf(NULL, szGPGModuleName, setting, ""); - } - if(!szMessage[0]) - { - mir_free(szMessage); - szMessage = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); - } - } - if(szMessage[0]) - { - BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); - CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)szMessage); - HistoryLog(hContact, db_event("Public key sent", 0, 0, DBEF_SENT)); - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); - } - mir_free(szMessage); - return 0; -} - -extern HANDLE hLoadPublicKey, hToggleEncryption; - -int ToggleEncryption(WPARAM w, LPARAM l) -{ - HANDLE hContact = (HANDLE)w; - BYTE enc = 0; - if(metaIsProtoMetaContacts(hContact)) - enc = DBGetContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0); - else - enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); - if(metaIsProtoMetaContacts(hContact)) - { - HANDLE hcnt = NULL; - if(MessageBox(0, _T("Do you want to toggle encryption for all subcontacts ?"), _T("Metacontact detected"), MB_YESNO) == IDYES) - { - int count = metaGetContactsNum(hContact); - for(int i = 0; i < count; i++) - { - hcnt = metaGetSubcontact(hContact, i); - if(hcnt) - DBWriteContactSettingByte(hcnt, szGPGModuleName, "GPGEncryption", enc?0:1); - } - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc?0:1); - } - } - else - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc?0:1); - void setSrmmIcon(HANDLE hContact); - void setClistIcon(HANDLE hContact); - setSrmmIcon(hContact); - setClistIcon(hContact); - enc = enc?0:1; - CLISTMENUITEM mi = {0}; - mi.cbSize=sizeof(mi); - mi.flags = CMIM_NAME; - enc?mi.pszName="Turn off GPG encryption":mi.pszName="Turn on GPG encryption"; - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hToggleEncryption, (LPARAM)&mi); - return 0; -} - -int OnPreBuildContactMenu(WPARAM w, LPARAM l) -{ - HANDLE hContact = (HANDLE)w; - if(metaIsProtoMetaContacts(hContact)) - hContact = metaGetMostOnline(hContact); - CLISTMENUITEM mi = {0}; - mi.cbSize=sizeof(mi); - mi.flags = CMIM_NAME; - TCHAR *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); - if(_tcslen(tmp) < 1) - { - DBDeleteContactSetting(hContact, szGPGModuleName, "GPGEncryption"); - mi.flags += CMIM_FLAGS | CMIF_GRAYED; - } - else - mi.flags = CMIM_NAME | CMIM_FLAGS; - mi.pszName = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)?"Turn off GPG encryption":"Turn on GPG encryption"; - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hToggleEncryption, (LPARAM)&mi); - return 0; -} - - -list transfers; -extern bool bFileTransfers; - -int onProtoAck(WPARAM w, LPARAM l) -{ - ACKDATA *ack=(ACKDATA*)l; - CCSDATA *ccs=(CCSDATA*)ack->lParam; - - if(ack->type == ACKTYPE_FILE && bFileTransfers) - { - switch(ack->result) - { - case ACKRESULT_DENIED: case ACKRESULT_FAILED: - break; - case ACKRESULT_SUCCESS: - { - PROTOFILETRANSFERSTATUS *f = (PROTOFILETRANSFERSTATUS*) ack->hProcess; - TCHAR *filename = NULL; - if(f->flags & PFTS_UNICODE) - { - if(f->tszCurrentFile && f->tszCurrentFile[0]) - filename = mir_wstrdup(f->tszCurrentFile); - if(!filename) - return 0; - } - else - { - if(f->szCurrentFile && f->szCurrentFile[0]) - filename = mir_utf8decodeT(f->szCurrentFile); - if(!filename) - return 0; - } - if(_tcsstr(filename, _T(".gpg"))) //decrypt it - { //process encrypted file - if(_waccess(f->tszCurrentFile, 0) == -1) - { - if(errno == ENOENT) - return 0; - } - string out; - DWORD code; - pxResult result; - wstring cmd = _T(" -o "); - wstring file = filename; - wstring::size_type p1 = file.rfind(_T(".gpg")); - file.erase(p1, _tcslen(_T(".gpg"))); - if(_waccess(file.c_str(), 0) != -1) - { - if(MessageBox(0, _T("Target file exists, do you want to replace it ?"), _T("Warning"), MB_YESNO) == IDNO) - return 0; - } - DeleteFile(file.c_str()); - file.insert(0, _T("\"")); - file.insert(file.length(), _T("\" ")); - cmd += file; - extern TCHAR *password; - { // password - TCHAR *pass = NULL; - char *keyid = UniGetContactSettingUtf(ack->hContact, szGPGModuleName, "KeyID", ""); - if(strlen(keyid) > 0) - { - string dbsetting = "szKey_"; - dbsetting += keyid; - dbsetting += "_Password"; - pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T("")); - if(_tcslen(pass) > 0) - debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; - } - else - { - pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); - if(_tcslen(pass) > 0) - debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; - } - if(_tcslen(pass) > 0) - { - cmd += _T("--passphrase \""); - cmd += pass; - cmd += _T("\" "); - } - else if(password) - { - debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; - cmd += _T("--passphrase \""); - cmd += password; - cmd += _T("\" "); - } - else - debuglog<hContact, GCDNF_TCHAR)<<" with out password\n"; - mir_free(pass); - mir_free(keyid); - } - cmd += _T(" -d \""); - cmd += filename; - cmd += _T("\""); - gpg_execution_params params; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::minutes(15))) - { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<hContact, GCDNF_TCHAR)<<" password needed, trying to get one\n"; - if(_terminate) - break; - { //save inkey id - string::size_type s = out.find(" encrypted with "); - s = out.find(" ID ", s); - s += strlen(" ID "); - string::size_type s2 = out.find(",",s); - if(metaIsProtoMetaContacts(ack->hContact)) - DBWriteContactSettingString(metaGetMostOnline(ack->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); - else - DBWriteContactSettingString(ack->hContact, szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str()); - } - void ShowLoadKeyPasswordWindow(); - new_key_hcnt_mutex.lock(); - new_key_hcnt = ack->hContact; - ShowLoadKeyPasswordWindow(); - wstring cmd2 = cmd; - if(password) - { - debuglog<hContact, GCDNF_TCHAR)<<"\n"; - wstring tmp = _T("--passphrase \""); - tmp += password; - tmp += _T("\" "); - cmd2.insert(0, tmp); - } - out.clear(); - gpg_execution_params params; - pxResult result; - params.cmd = &cmd2; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - gpg_thread = gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::seconds(15))) - { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<type == ACKTYPE_MESSAGE) - { - extern std::list sent_msgs; - if(!sent_msgs.empty()) - { - if(ack->result == ACKRESULT_FAILED) - { - std::list::iterator it = std::find(sent_msgs.begin(), sent_msgs.end(), ack->hProcess); - if(it != sent_msgs.end()) - { - HistoryLog(ack->hContact, db_event("Failed to send encrypted message", 0,0, 0)); - - } - } - else if(ack->result == ACKRESULT_SUCCESS) - { - std::list::iterator it = std::find(sent_msgs.begin(), sent_msgs.end(), ack->hProcess); - if(it != sent_msgs.end()) - sent_msgs.erase(it); - } - } - } - return 0; -} - -std::wstring encrypt_file(HANDLE hContact, TCHAR *filename) -{ - string out; - DWORD code; - pxResult result; - HANDLE hcnt = metaIsProtoMetaContacts(hContact)?metaGetMostOnline(hContact):hContact; - wstring cmd = _T("--batch --yes -r "); - char *keyid = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID", ""); - TCHAR *szKeyid = mir_a2t(keyid); - TCHAR *name = _tcsrchr(filename,_T('\\')); - if( !name ) - name = filename; - else - name++; - TCHAR *file_out = new TCHAR [_tcslen(filename)+4]; - mir_sntprintf(file_out, _tcslen(name)+7, _T("%s.gpg"), name); - cmd += szKeyid; - if(DBGetContactSettingByte(hcnt, szGPGModuleName, "bAlwaysTrust", 0)) - cmd += _T(" --trust-model always "); - mir_free(szKeyid); - mir_free(keyid); - cmd += _T(" -o \""); - TCHAR *temp = _tgetenv(_T("TEMP")); - cmd += temp; - cmd += _T("\\"); - cmd += file_out; - wstring path_out = temp; - path_out += _T("\\"); - path_out += file_out; - DeleteFile(path_out.c_str()); - cmd += _T("\" "); - mir_free(temp); - cmd += _T(" -e \""); - cmd += filename; - cmd += _T("\" "); - gpg_execution_params params; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - mir_free(keyid); - delete [] file_out; - boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) - { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<timed_join(boost::posix_time::seconds(180))) - { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog<hContact)) - { - - DWORD flags = (DWORD)ccs->wParam; //check for PFTS_UNICODE here - int i; -// if(flags & PFTS_UNICODE) //this does not work .... - if(StriStr(ccs->szProtoService, "/sendfilew")) - { - TCHAR **file=(TCHAR **)ccs->lParam; - for(i = 0; file[i]; i++) - { - if(_waccess(file[i], 0) == -1) - if(errno == ENOENT) - return 0; //we do not want to send file unencrypted (sometimes ack have wrong info) - if (_tcsstr(file[i],_T(".gpg"))) - continue; - std::wstring path_out = encrypt_file(ccs->hContact, file[i]); - mir_free(file[i]); - file[i] = mir_tstrdup(path_out.c_str()); - transfers.push_back(path_out); - } - } - else - { - char **file = (char**) ccs->lParam; - for(i = 0; file[i]; i++) - { - if(_access(file[i], 0) == -1) - if(errno == ENOENT) - return 0; //we do not want to send file unencrypted (sometimes ack have wrong info) - if (strstr(file[i],".gpg")) - continue; - TCHAR *tmp = mir_utf8decodeT(file[i]); - std::wstring path_out = encrypt_file(ccs->hContact, tmp); - mir_free(tmp); - char* tmp2 = mir_utf8encodeW(path_out.c_str()); - mir_free(file[i]); - file[i] = tmp2; - transfers.push_back(path_out); - - } - } - } - return CallService(MS_PROTO_CHAINSEND, w, l); -} - -void storeOutput(HANDLE ahandle, string *output) -{ - BOOL success; - char readbuffer[4096] = {0}; - unsigned long transfered, available; - - do { - PeekNamedPipe(ahandle,NULL,0,NULL,&available,NULL); - if (!available) - continue; - success=ReadFile(ahandle,readbuffer,sizeof(readbuffer),&transfered,NULL); - if (success && transfered) - output->append(readbuffer, 4096); - } while (available>0); -} - -void HistoryLog(HANDLE hContact, db_event evt) -{ - DBEVENTINFO Event = {0}; - Event.cbSize = sizeof(Event); - Event.szModule = szGPGModuleName; - Event.eventType = evt.eventType; - Event.flags = evt.flags; - if(!evt.timestamp) - Event.timestamp = (DWORD)time(NULL); - else - Event.timestamp = evt.timestamp; - Event.cbBlob = strlen((char*)evt.pBlob)+1; - Event.pBlob = (PBYTE)_strdup((char*)evt.pBlob); - CallService(MS_DB_EVENT_ADD, (WPARAM)(HANDLE)hContact,(LPARAM)&Event); -} - -static int ControlAddStringUtf(HWND ctrl, DWORD msg, const TCHAR *szString) -{ - int item = -1; - item = SendMessage(ctrl, msg, 0, (LPARAM)szString); - return item; -} - -int ComboBoxAddStringUtf(HWND hCombo, const TCHAR *szString, DWORD data) -{ - int item = ControlAddStringUtf(hCombo, CB_ADDSTRING, szString); - SendMessage(hCombo, CB_SETITEMDATA, item, data); - - return item; -} - - -int GetJabberInterface(WPARAM w, LPARAM l) //get interface for all jabber accounts, options later -{ - extern list Accounts; - void AddHandlers(); - int count = 0; - PROTOACCOUNT **accounts; - ProtoEnumAccounts(&count, &accounts); - list ::iterator p; - Accounts.clear(); - Accounts.push_back(new JabberAccount); - p = Accounts.begin(); - (*p)->setAccountNumber(0); - for(int i = 0; i < count; i++) //get only jabber accounts from all accounts - { - IJabberInterface *JIftmp = getJabberApi(accounts[i]->szModuleName); - int a = 0; - if(JIftmp) - { - (*p)->setJabberInterface(JIftmp); - if(accounts[i]->tszAccountName) - { - TCHAR* tmp = mir_tstrdup(accounts[i]->tszAccountName); - (*p)->setAccountName(tmp); - } - else - { - TCHAR *tmp = mir_a2t(accounts[i]->szModuleName); - (*p)->setAccountName(tmp); - } - (*p)->setAccountNumber(a); - a++; - Accounts.push_back(new JabberAccount); - p++; - } - } - Accounts.pop_back(); - AddHandlers(); - return 0; -} - -static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pUserData) -{ - HXML local_node = node; - for(int n = 0; n <= xi.getChildCount(node); n++) - { - LPCTSTR str = xi.getText(local_node); - LPCTSTR nodename = xi.getName(local_node); - if(str) - { - if(_tcsstr(str, _T("-----BEGIN PGP MESSAGE-----")) && _tcsstr(str, _T("-----END PGP MESSAGE-----"))) - { - wstring data = str; - xi.setText(local_node, _T("This message is encrypted.")); - wstring::size_type p1 = data.find(_T("-----BEGIN PGP MESSAGE-----")) + _tcslen(_T("-----BEGIN PGP MESSAGE-----")); - while(data.find(_T("Version: "), p1) != wstring::npos) - { - p1 = data.find(_T("Version: "), p1); - p1 = data.find(_T("\n"), p1); - } - while(data.find(_T("Comment: "), p1) != wstring::npos) - { - p1 = data.find(_T("Comment: "), p1); - p1 = data.find(_T("\n"), p1); - } - while(data.find(_T("Encoding: "), p1) != wstring::npos) - { - p1 = data.find(_T("Encoding: "), p1); - p1 = data.find(_T("\n"), p1); - } - p1+=2; - wstring::size_type p2 = data.find(_T("-----END PGP MESSAGE-----")); - HXML encrypted_data = xi.addChild(node, _T("x"), data.substr(p1, p2-p1).c_str()); - xi.addAttr(encrypted_data, _T("xmlns"), _T("jabber:x:encrypted")); - return FALSE; - } - } - if(bPresenceSigning && nodename) - { - if(_tcsstr(nodename, _T("status"))) - { - TCHAR *path_c = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - wstring path_out = path_c; - wstring file = toUTF16(get_random(10)); - mir_free(path_c); - path_out += _T("\\tmp\\"); - path_out += file; - DeleteFile(path_out.c_str()); - wfstream f(path_out.c_str(), std::ios::out); - f<Sys()->GetModuleName(); - char setting[64]; - strcpy(setting, proto); - strcat(setting, "_KeyID"); - inkeyid = UniGetContactSettingUtf(NULL, szGPGModuleName, setting, ""); - if(!inkeyid[0]) - { - mir_free(inkeyid); - inkeyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); - } - } - TCHAR *pass = NULL; - if(inkeyid[0]) - { - string dbsetting = "szKey_"; - dbsetting += inkeyid; - dbsetting += "_Password"; - pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T("")); - if(pass[0]) - debuglog< Accounts; - list ::iterator p = Accounts.begin(); - for(unsigned int i = 0; i < Accounts.size(); i++, p++) - { - if(!(*p)) - break; - hContact = (*p)->getJabberInterface()->Sys()->ContactFromJID(xi.getAttrValue(node, _T("from"))); - if(hContact) - hcontact_data[hContact].key_in_prescense = out.substr(p1, p2-p1-1).c_str(); - } - } - } - } - } - return FALSE; - } - } - } - } - local_node = xi.getChild(node, n); - } - return FALSE; -} - -static JABBER_HANDLER_FUNC MessageHandler(IJabberInterface *ji, HXML node, void *pUserData) -{ - return FALSE; -} - - - - -void AddHandlers() -{ - extern list Accounts; - list::iterator end = Accounts.end(); - for(list::iterator p = Accounts.begin(); p != end; p++) - { - if(!(*p)) - break; - if((*p)->getSendHandler() == INVALID_HANDLE_VALUE) - (*p)->setSendHandler((*p)->getJabberInterface()->Net()->AddSendHandler((JABBER_HANDLER_FUNC)SendHandler)); - if((*p)->getPrescenseHandler() == INVALID_HANDLE_VALUE) - (*p)->setPrescenseHandler((*p)->getJabberInterface()->Net()->AddPresenceHandler((JABBER_HANDLER_FUNC)PrescenseHandler)); -// if((*p)->getMessageHandler() == INVALID_HANDLE_VALUE) -// (*p)->setMessageHandler((*p)->getJabberInterface()->Net()->AddMessageHandler((JABBER_HANDLER_FUNC)MessageHandler, JABBER_MESSAGE_TYPE_ANY ,NULL,NULL)); - if(bAutoExchange) - { - (*p)->getJabberInterface()->Net()->RegisterFeature(_T("GPG_Key_Auto_Exchange:0"), _T("Indicates that gpg installed and configured to public key auto exchange (currently implemented in new_gpg Miranda IM plugin)")); - (*p)->getJabberInterface()->Net()->AddFeatures(_T("GPG_Key_Auto_Exchange:0\0\0")); - } - } -} - -bool isContactSecured(HANDLE hContact) -{ - BYTE gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); - if(!gpg_enc) - { - debuglog< 0) - { - mir_free(key); - return true; - } - mir_free(key); - return false; -} - -bool isGPGKeyExist() -{ - TCHAR *id = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", _T("")); - char *key = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); - if(id[0] && key[0]) - { - mir_free(id); - mir_free(key); - return true; - } - mir_free(id); - mir_free(key); - return false; -} -bool isGPGValid() -{ - TCHAR *tmp; - bool gpg_exists = false, is_valid = true; - tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("")); - if(_waccess(tmp, 0) != -1) - gpg_exists = true; - else - { - mir_free(tmp); - TCHAR *path = new TCHAR [MAX_PATH]; - char *mir_path = new char [MAX_PATH]; - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); - SetCurrentDirectoryA(mir_path); - tmp = mir_a2t(mir_path); - mir_free(mir_path); - mir_realloc(path, (_tcslen(path)+128)*sizeof(TCHAR)); - TCHAR *gpg_path = new TCHAR [MAX_PATH]; - _tcscpy(gpg_path, tmp); - _tcscat(gpg_path, _T("\\GnuPG\\gpg.exe")); - mir_free(tmp); - if(_waccess(gpg_path, 0) != -1) - { - gpg_exists = true; - _tcscpy(path, _T("GnuPG\\gpg.exe")); - } - mir_free(gpg_path); - tmp = mir_wstrdup(path); - delete [] path; - } - DWORD len = MAX_PATH; - if(gpg_exists) - { - DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); - string out; - DWORD code; - wstring cmd = _T("--version"); - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - gpg_valid = true; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - debuglog< - -struct TFakeAckParams { - inline TFakeAckParams( HANDLE p1, HANDLE p2, LONG p3, LPCSTR p4 ) : - hEvent( p1 ), - hContact( p2 ), - id( p3 ), - msg( p4 ) - {} - - HANDLE hEvent; - HANDLE hContact; - LONG id; - LPCSTR msg; -}; - -int SendBroadcast( HANDLE hContact, int type, int result, HANDLE hProcess, LPARAM lParam ) { - ACKDATA ack; - memset(&ack,0,sizeof(ack)); - ack.cbSize = sizeof( ACKDATA ); - ack.szModule = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - ack.hContact = hContact; - ack.type = type; - ack.result = result; - ack.hProcess = hProcess; - ack.lParam = lParam; - return CallService( MS_PROTO_BROADCASTACK, 0, ( LPARAM )&ack ); -} - - - -unsigned __stdcall sttFakeAck( LPVOID param ) { - - TFakeAckParams* tParam = ( TFakeAckParams* )param; - WaitForSingleObject( tParam->hEvent, INFINITE ); - - Sleep( 100 ); - if ( tParam->msg == NULL ) - SendBroadcast( tParam->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, ( HANDLE )tParam->id, 0 ); - else - SendBroadcast( tParam->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, ( HANDLE )tParam->id, LPARAM( tParam->msg )); - - CloseHandle( tParam->hEvent ); - delete tParam; - - return 0; -} - - -int returnNoError(HANDLE hContact) { - HANDLE hEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); - unsigned int tID; - CloseHandle( (HANDLE) _beginthreadex(NULL, 0, sttFakeAck, new TFakeAckParams(hEvent,hContact,777,0), 0, &tID) ); - SetEvent( hEvent ); - return 777; -} -// end from secureim - - -string toUTF8(wstring str) -{ - string ustr; - try{ - utf8::utf16to8(str.begin(), str.end(), back_inserter(ustr)); - } - catch(const utf8::exception& e) - { - debuglog<> gen(rng, boost::uniform_int<>(0, chars.length()-1)); - for(int i = 0; i < length; ++i) - data += chars[gen()]; - return data; -} - -void send_encrypted_msgs_thread(HANDLE hContact) -{ - while(true) - { - char *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", ""); - while(!isContactSecured(hContact)) - boost::this_thread::sleep(boost::posix_time::seconds(1)); - if(!hcontact_data[hContact].msgs_to_send.empty()) - { - boost::this_thread::sleep(boost::posix_time::seconds(1)); - list::iterator end = hcontact_data[hContact].msgs_to_send.end(); - extern std::list sent_msgs; - for(list::iterator p = hcontact_data[hContact].msgs_to_send.begin(); p != end; ++p) - { - sent_msgs.push_back((HANDLE)CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)p->c_str())); - HistoryLog(hContact, db_event((char*)p->c_str(),0,0, DBEF_SENT)); - boost::this_thread::sleep(boost::posix_time::seconds(1)); - } - hcontact_data[hContact].msgs_to_send.clear(); - return; - } - else - return; - } -} - -string time_str() -{ - boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); - return (string)boost::posix_time::to_simple_string(now); -} - -int handleEnum(const char *szSetting, LPARAM lParam) -{ - if(!*(bool*)lParam && szSetting[0] && StriStr(szSetting, "tabsrmm")) - { - bool f = false, *found = (bool*)lParam; - f = !DBGetContactSettingByte(NULL, "PluginDisable", szSetting, 0); - if(f) - *found = f; - } - return 0; -} - -bool isTabsrmmUsed() -{ - DBCONTACTENUMSETTINGS enm = {0}; - bool found = false; - enm.lParam = (LPARAM)&found; - enm.pfnEnumProc = (DBSETTINGENUMPROC)&handleEnum; - enm.szModule = "PluginDisable"; - if(CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)NULL, (LPARAM)&enm) == -1) - return false; - - return found; -} - - -int ExportGpGKeys(WPARAM w, LPARAM l) -{ - TCHAR *p = GetFilePath(_T("Choose file to export public keys"), _T("*"), _T("Any file"), true); - if(!p || !p[0]) - { - delete [] p; - //TODO: handle error - return 1; - } - char *path = mir_t2a(p); - delete [] p; - std::ofstream file; - file.open(path, std::ios::trunc | std::ios::out); - mir_free(path); - int exported_keys = 0; - if(!file.is_open()) - return 1; //TODO: handle error - for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) - { - char *k = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", ""); - if(!k[0]) - { - mir_free(k); - continue; - } - std::string key = k; - mir_free(k); - - const char* proto = (const char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - std::string id = "Comment: login "; - const char * uid = (const char*)CallProtoService(proto, PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDSETTING, 0); - DBVARIANT dbv = {0}; - DBCONTACTGETSETTING dbcgs = {0}; - dbcgs.pValue = &dbv; - dbcgs.szModule = proto; - dbcgs.szSetting = uid; - CallService(MS_DB_CONTACT_GETSETTING, 0, (LPARAM)&dbcgs); - switch(dbcgs.pValue->type) - { - case DBVT_DELETED: - continue; - break; - case DBVT_BYTE: - { - char _id[64]; - mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal); - id += _id; - } - break; - case DBVT_WORD: - { - char _id[64]; - mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal); - id += _id; - } - break; - case DBVT_DWORD: - { - char _id[64]; - mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal); - id += _id; - } - break; - case DBVT_ASCIIZ: - { - id += dbcgs.pValue->pszVal; - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - } - break; - case DBVT_UTF8: - { - char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal); - if(tmp[0]) - id += tmp; - mir_free(tmp); - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - } - break; - case DBVT_BLOB: - //TODO - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - break; - case DBVT_WCHAR: - //TODO - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - break; - } - id += " contact_id "; - ZeroMemory(&dbv, sizeof(dbv)); - ZeroMemory(&dbcgs, sizeof(dbcgs)); - dbcgs.pValue = &dbv; - dbcgs.szModule = proto; - dbcgs.szSetting = uid; - CallService(MS_DB_CONTACT_GETSETTING, (WPARAM)hContact, (LPARAM)&dbcgs); - switch(dbcgs.pValue->type) - { - case DBVT_DELETED: - continue; - break; - case DBVT_BYTE: - { - char _id[64]; - mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal); - id += _id; - } - break; - case DBVT_WORD: - { - char _id[64]; - mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal); - id += _id; - } - break; - case DBVT_DWORD: - { - char _id[64]; - mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal); - id += _id; - } - break; - case DBVT_ASCIIZ: - { - id += dbcgs.pValue->pszVal; - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - } - break; - case DBVT_UTF8: - { - char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal); - if(tmp[0]) - id += tmp; - mir_free(tmp); - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - } - break; - case DBVT_BLOB: - //TODO - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - break; - case DBVT_WCHAR: - //TODO - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - break; - } - std::string::size_type p1 = key.find("-----BEGIN PGP PUBLIC KEY BLOCK-----"); - if(p1 == std::string::npos) - continue; - p1 += strlen("-----BEGIN PGP PUBLIC KEY BLOCK-----"); - p1 ++; - id += '\n'; - key.insert(p1, id); - file<szModuleName, PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDSETTING, 0); - DBVARIANT dbv = {0}; - DBCONTACTGETSETTING dbcgs = {0}; - dbcgs.pValue = &dbv; - dbcgs.szModule = accs[i]->szModuleName; - dbcgs.szSetting = uid; - CallService(MS_DB_CONTACT_GETSETTING, 0, (LPARAM)&dbcgs); - std::string id; - switch(dbcgs.pValue->type) - { - case DBVT_DELETED: - continue; - break; - case DBVT_BYTE: - { - char _id[64]; - mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal); - id += _id; - if(id == login) - acc = accs[i]->szModuleName; - } - break; - case DBVT_WORD: - { - char _id[64]; - mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal); - id += _id; - if(id == login) - acc = accs[i]->szModuleName; - } - break; - case DBVT_DWORD: - { - char _id[64]; - mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal); - id += _id; - if(id == login) - acc = accs[i]->szModuleName; - } - break; - case DBVT_ASCIIZ: - { - id += dbcgs.pValue->pszVal; - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - if(id == login) - acc = accs[i]->szModuleName; - } - break; - case DBVT_UTF8: - { - char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal); - if(tmp[0]) - id += tmp; - mir_free(tmp); - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - if(id == login) - acc = accs[i]->szModuleName; - } - break; - case DBVT_BLOB: - //TODO - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - break; - case DBVT_WCHAR: - //TODO - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - break; - } - } - if(acc.length()) - { - const char * uid = (const char*)CallProtoService(acc.c_str(), PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDSETTING, 0); - for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, (LPARAM)acc.c_str()); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, (LPARAM)acc.c_str())) - { - DBVARIANT dbv = {0}; - DBCONTACTGETSETTING dbcgs = {0}; - dbcgs.pValue = &dbv; - dbcgs.szModule = acc.c_str(); - dbcgs.szSetting = uid; - CallService(MS_DB_CONTACT_GETSETTING, (WPARAM)hContact, (LPARAM)&dbcgs); - std::string id; - bool found = false; - switch(dbcgs.pValue->type) - { - case DBVT_DELETED: - continue; - break; - case DBVT_BYTE: - { - char _id[64]; - mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal); - id += _id; - if(id == contact_id) - found = true; - } - break; - case DBVT_WORD: - { - char _id[64]; - mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal); - id += _id; - if(id == contact_id) - found = true; - } - break; - case DBVT_DWORD: - { - char _id[64]; - mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal); - id += _id; - if(id == contact_id) - found = true; - } - break; - case DBVT_ASCIIZ: - { - id += dbcgs.pValue->pszVal; - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - if(id == contact_id) - found = true; - } - break; - case DBVT_UTF8: - { - char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal); - if(tmp[0]) - id += tmp; - mir_free(tmp); - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - if(id == contact_id) - found = true; - } - break; - case DBVT_BLOB: - //TODO - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - break; - case DBVT_WCHAR: - //TODO - CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv); - break; - } - if(found) - { - wstring cmd; - TCHAR tmp2[MAX_PATH] = {0}; - TCHAR *ptmp; - string output; - DWORD exitcode; - { - HANDLE hcnt = hContact; - ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - _tcscpy(tmp2, ptmp); - mir_free(ptmp); - _tcscat(tmp2, _T("\\")); - _tcscat(tmp2, _T("temporary_exported.asc")); - DeleteFile(tmp2); - wfstream f(tmp2, std::ios::out); - f< output.find("<", s)) - s2 = output.find("<", s); - if(s2 != string::npos) - { - tmp2 = new char [output.substr(s,s2-s-1).length()+1]; - strcpy(tmp2, output.substr(s,s2-s-1).c_str()); - mir_utf8decode(tmp2, 0); - if(hContact) - { - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); - } - mir_free(tmp2); - if((s = output.find(")", s2)) == string::npos) - s = output.find(">", s2); - else if(s > output.find(">", s2)) - s = output.find(">", s2); - s2++; - if(output[s] == ')') - { - tmp2 = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp2, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp2, 0); - if(hContact) - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); - mir_free(tmp2); - s+=3; - s2 = output.find(">", s); - tmp2 = new char [output.substr(s,s2-s).length()+1]; - strcpy(tmp2, output.substr(s,s2-s).c_str()); - mir_utf8decode(tmp2, 0); - if(hContact) - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); - mir_free(tmp2); - } - else - { - tmp2 = new char [output.substr(s2,s-s2).length()+1]; - strcpy(tmp2, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp2, 0); - if(hContact) - DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); - mir_free(tmp2); - } - } - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); - DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", toUTF16(key).c_str()); - } - DeleteFile(tmp2); - break; - } - } - } - key.clear(); - } - } - if(file.is_open()) - file.close(); - char msg[512]; - mir_snprintf(msg, 511, "we have succesfully processed %d keys", processed_keys); - MessageBoxA(NULL, msg, Translate("Keys import result"), MB_OK); - return 0; -} \ No newline at end of file diff --git a/utilities.h b/utilities.h deleted file mode 100755 index 30e9f68..0000000 --- a/utilities.h +++ /dev/null @@ -1,104 +0,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. - -#ifndef UTILITIES_H -#define UTILITIES_H -TCHAR* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, TCHAR* szDef); -char* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, char* szDef); -void GetFilePath(TCHAR *WindowTittle, char *szSetting, TCHAR *szExt, TCHAR *szExtDesc); -TCHAR *GetFilePath(TCHAR *WindowTittle, TCHAR *szExt, TCHAR *szExtDesc, bool save_file = false); -void GetFolderPath(TCHAR *WindowTittle, char *szSetting); - -void storeOutput(HANDLE ahandle, string *output); - -int ComboBoxAddStringUtf(HWND hCombo, const TCHAR *szString, DWORD data); -bool isContactSecured(HANDLE hContact); -bool isContactHaveKey(HANDLE 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 = 0; - szModule = 0; - cbSize = 0; - cbBlob = strlen(msg)+1; - pBlob = (PBYTE)msg; - } - db_event(char* msg, DWORD time) - { - cbBlob = strlen(msg)+1; - pBlob = (PBYTE)msg; - eventType = EVENTTYPE_MESSAGE; - flags = 0; - timestamp = time; - szModule = 0; - cbSize = 0; - } - db_event(char* msg, DWORD time, int type) - { - cbBlob = strlen(msg)+1; - pBlob = (PBYTE)msg; - if(type) - eventType = type; - else - eventType = EVENTTYPE_MESSAGE; - flags = 0; - timestamp = time; - szModule = 0; - cbSize = 0; - } - db_event(char* msg, int type) - { - cbBlob = strlen(msg)+1; - pBlob = (PBYTE)msg; - flags = 0; - if(type) - eventType = type; - else - eventType = EVENTTYPE_MESSAGE; - timestamp = 0; - szModule = 0; - cbSize = 0; - } - db_event(char* msg, DWORD time, int type, DWORD _flags) - { - cbBlob = strlen(msg)+1; - pBlob = (PBYTE)msg; - if(type) - eventType = type; - else - eventType = EVENTTYPE_MESSAGE; - flags = _flags; - timestamp = time; - szModule = 0; - cbSize = 0; - } -}; -void HistoryLog(HANDLE, db_event); - -#endif -- cgit v1.2.3