From 4d9fce6f544f0c6782a7ade4900afd3e1c6c9c52 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 29 Jan 2011 15:17:51 +0300 Subject: Better metacontacts handling\nFixed subkey length in keygen --- clist.cpp | 82 +- commonheaders.h | 8 +- constants.h | 10 +- globals.h | 44 +- gpg_wrapper.cpp | 2 +- gpg_wrapper.h | 60 +- icons.cpp | 288 +++--- init.cpp | 536 ++++++------ jabber_account.cpp | 148 ++-- jabber_account.h | 80 +- log.cpp | 182 ++-- log.h | 2 +- m_extraicons.h | 316 +++---- m_metacontacts.h | 332 +++---- main.cpp | 51 +- main.h | 62 +- messages.cpp | 285 +++--- metacontacts.cpp | 200 ++--- metacontacts.h | 48 +- options.cpp | 2484 ++++++++++++++++++++++++++-------------------------- resource.h | 170 ++-- srmm.cpp | 160 ++-- utilities.cpp | 388 ++++---- utilities.h | 80 +- 24 files changed, 3010 insertions(+), 3008 deletions(-) diff --git a/clist.cpp b/clist.cpp index c6634c8..25c5a24 100644 --- a/clist.cpp +++ b/clist.cpp @@ -1,41 +1,41 @@ -// Copyright © 2010 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; -} +// Copyright © 2010 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 index 990497b..1b7d8f1 100644 --- a/commonheaders.h +++ b/commonheaders.h @@ -44,10 +44,10 @@ using std::fstream; //boost #include #include -#include -#include -#include -#include +#include +#include +#include +#include //utf8cpp diff --git a/constants.h b/constants.h index be76946..2982f31 100644 --- a/constants.h +++ b/constants.h @@ -1,5 +1,5 @@ -#ifndef CONSTANTS_H -#define CONSTANTS_H -#define szGPGModuleName "GPG" -#define PREF_METANODB 0x2000 -#endif +#ifndef CONSTANTS_H +#define CONSTANTS_H +#define szGPGModuleName "GPG" +#define PREF_METANODB 0x2000 +#endif diff --git a/globals.h b/globals.h index 0aeac02..cafedab 100644 --- a/globals.h +++ b/globals.h @@ -1,22 +1,22 @@ -// Copyright © 2010 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, gpg_configured; -extern TCHAR *inopentag, *inclosetag, *outopentag, *outclosetag; -extern logtofile debuglog; -#endif +// Copyright © 2010 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, gpg_configured; +extern TCHAR *inopentag, *inclosetag, *outopentag, *outclosetag; +extern logtofile debuglog; +#endif diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp index de44233..3091566 100644 --- a/gpg_wrapper.cpp +++ b/gpg_wrapper.cpp @@ -159,4 +159,4 @@ void pxEexcute_thread(void *param) { debuglog< Accounts; - -HINSTANCE hInst; -HANDLE hLoadPubKey = NULL, hToggleEncryption = NULL, hOnPreBuildContactMenu = NULL, hSendKey = NULL, g_hCLIcon = NULL; -PLUGINLINK *pluginLink; -IconExtraColumn g_IEC = {0}; -static int OnModulesLoaded(WPARAM wParam,LPARAM lParam); -extern char *date(); -MM_INTERFACE mmi = {0}; -UTF8_INTERFACE utfi = {0}; -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}; -logtofile debuglog; -bool gpg_configured = 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,9), - "new GPG encryption support plugin, used code from http://addons.miranda-im.org/details.php?action=viewfile&id=3485", - "sss", - "sss123next@list.ru", - "© 2010 sss", - "http://sss.chaoslab.ru/tracker/mim_plugs/", - 1, //unicode - 0, //doesn't replace anything built-in - 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); - -void init_vars() -{ - bAppendTags = DBGetContactSettingByte(NULL, szGPGModuleName, "bAppendTags", 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); - debuglog.init(); - bJabberAPI = DBGetContactSettingByte(NULL, szGPGModuleName, "bJabberAPI", bIsMiranda09?1:0); - bFileTransfers = DBGetContactSettingByte(NULL, szGPGModuleName, "bFileTransfers", 1); - 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); -} - -extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) -{ - pluginLink=link; - init_vars(); - HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); - mir_getMMI(&mmi); - mir_getUTFI(&utfi); - mir_getXI(&xi); //TODO: check if we have access to api - CreateServiceFunction("/LoadPubKey",(MIRANDASERVICE)LoadKey); - CreateServiceFunction("/ToggleEncryption",(MIRANDASERVICE)ToggleEncryption); - CreateServiceFunction("/SendKey",(MIRANDASERVICE)SendKey); - 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 = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&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 = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&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 = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&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; -} +// Copyright © 2010 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, bIsMiranda09 = false, bMetaContacts = false, bFileTransfers = false, bAutoExchange = 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; +PLUGINLINK *pluginLink; +IconExtraColumn g_IEC = {0}; +static int OnModulesLoaded(WPARAM wParam,LPARAM lParam); +extern char *date(); +MM_INTERFACE mmi = {0}; +UTF8_INTERFACE utfi = {0}; +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}; +logtofile debuglog; +bool gpg_configured = 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,9), + "new GPG encryption support plugin, used code from http://addons.miranda-im.org/details.php?action=viewfile&id=3485", + "sss", + "sss123next@list.ru", + "© 2010 sss", + "http://sss.chaoslab.ru/tracker/mim_plugs/", + 1, //unicode + 0, //doesn't replace anything built-in + 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); + +void init_vars() +{ + bAppendTags = DBGetContactSettingByte(NULL, szGPGModuleName, "bAppendTags", 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); + debuglog.init(); + bJabberAPI = DBGetContactSettingByte(NULL, szGPGModuleName, "bJabberAPI", bIsMiranda09?1:0); + bFileTransfers = DBGetContactSettingByte(NULL, szGPGModuleName, "bFileTransfers", 1); + 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); +} + +extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) +{ + pluginLink=link; + init_vars(); + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + mir_getMMI(&mmi); + mir_getUTFI(&utfi); + mir_getXI(&xi); //TODO: check if we have access to api + CreateServiceFunction("/LoadPubKey",(MIRANDASERVICE)LoadKey); + CreateServiceFunction("/ToggleEncryption",(MIRANDASERVICE)ToggleEncryption); + CreateServiceFunction("/SendKey",(MIRANDASERVICE)SendKey); + 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 = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&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 = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&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 = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&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 index 636815b..ac5ce24 100644 --- a/jabber_account.cpp +++ b/jabber_account.cpp @@ -1,75 +1,75 @@ -// Copyright © 2010 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; -} - - -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; -} - - -JabberAccount::JabberAccount() -{ - AccountName = NULL; - hSendHandler = INVALID_HANDLE_VALUE; - hPrescenseHandler = INVALID_HANDLE_VALUE; - AccountNumber = -1; - JabberInterface = NULL; -} -JabberAccount::~JabberAccount() -{ - if(AccountName) - mir_free(AccountName); +// Copyright © 2010 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; +} + + +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; +} + + +JabberAccount::JabberAccount() +{ + AccountName = NULL; + hSendHandler = INVALID_HANDLE_VALUE; + hPrescenseHandler = 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 index 490ea63..66a8bc1 100644 --- a/jabber_account.h +++ b/jabber_account.h @@ -1,41 +1,41 @@ -// Copyright © 2010 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); - - TCHAR *getAccountName(); - int getAccountNumber(); - IJabberInterface *getJabberInterface(); - HJHANDLER getSendHandler(); - HJHANDLER getPrescenseHandler(); - ~JabberAccount(); - JabberAccount(); -private: - TCHAR *AccountName; - int AccountNumber; - IJabberInterface *JabberInterface; - HJHANDLER hSendHandler, hPrescenseHandler; -}; - +// Copyright © 2010 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); + + TCHAR *getAccountName(); + int getAccountNumber(); + IJabberInterface *getJabberInterface(); + HJHANDLER getSendHandler(); + HJHANDLER getPrescenseHandler(); + ~JabberAccount(); + JabberAccount(); +private: + TCHAR *AccountName; + int AccountNumber; + IJabberInterface *JabberInterface; + HJHANDLER hSendHandler, hPrescenseHandler; +}; + #endif \ No newline at end of file diff --git a/log.cpp b/log.cpp index d2e360d..39fa89d 100644 --- a/log.cpp +++ b/log.cpp @@ -1,91 +1,91 @@ -// Copyright © 2010 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< msgs_to_tag, msgs_to_ignore, msgs_to_send; - 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 - - +// Copyright © 2010 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_tag, msgs_to_ignore, msgs_to_send; + 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 index e8954e1..0289685 100644 --- a/messages.cpp +++ b/messages.cpp @@ -36,7 +36,6 @@ int RecvMsgSvc(WPARAM w, LPARAM l) return CallService(MS_PROTO_CHAINRECV, w, l); HANDLE hContact = ccs->hContact; - { //check for gpg related data wstring str = toUTF16(msg); wstring::size_type s1 = wstring::npos, s2 = wstring::npos; @@ -49,98 +48,98 @@ int RecvMsgSvc(WPARAM w, LPARAM l) { s2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")); DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", str.substr(s1,s2-s1).c_str()); - DBWriteContactSettingByte(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); - ptmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); - wstring new_key = ptmp; - mir_free(ptmp); - f< 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); - } + DBWriteContactSettingByte(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); + ptmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); + wstring new_key = ptmp; + mir_free(ptmp); + f< 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); + } DBWriteContactSettingByte(hContact, szGPGModuleName, "bAlwatsTrust", 1); void setSrmmIcon(HANDLE); void setClistIcon(HANDLE); @@ -227,26 +226,26 @@ int RecvMsgSvc(WPARAM w, LPARAM l) else { TCHAR *jid = UniGetContactSettingUtf(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(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); + 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(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); } } } @@ -496,21 +495,21 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } else { - mir_free((void**)pre->szMessage); if(bAppendTags) { str.insert(0, inopentag); str.append(inclosetag); } - pre->szMessage = mir_strdup(toUTF8(str).c_str()); if(metaIsSubcontact(hContact)) { char *msg = mir_strdup(toUTF8(str).c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, DBEF_UTF); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, DBEF_UTF|DBEF_READ); HistoryLog(metaGetContact(hContact), msg, EVENTTYPE_MESSAGE, DBEF_UTF); mir_free(msg); return 1; } + mir_free((void**)pre->szMessage); + pre->szMessage = mir_strdup(toUTF8(str).c_str()); return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); } } @@ -578,32 +577,32 @@ int SendMsgSvc(WPARAM w, LPARAM l) TCHAR *jid = UniGetContactSettingUtf(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(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); - hcontact_data[hContact].msgs_to_ignore.push_back(msg); - hcontact_data[hContact].msgs_to_send.push_back(msg); - boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, hContact)); - return returnNoError(hContact); - } - } - } + 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(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); + hcontact_data[hContact].msgs_to_ignore.push_back(msg); + hcontact_data[hContact].msgs_to_send.push_back(msg); + boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, hContact)); + return returnNoError(hContact); + } + } + } } } } @@ -738,7 +737,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) str_event.append(toUTF8(outclosetag)); } HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT); - HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT); + HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT); hcontact_data[hContact].msgs_to_ignore.push_back((char*)ccs->lParam); hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back((char*)ccs->lParam); //hmm, twice ? metacontacts !! %) CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)toUTF8(str).c_str()); diff --git a/metacontacts.cpp b/metacontacts.cpp index d1e959c..30d3a75 100644 --- a/metacontacts.cpp +++ b/metacontacts.cpp @@ -1,100 +1,100 @@ -// Copyright © 2010 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) - return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0); - return 0; -} -bool metaIsSubcontact(HANDLE hContact) -{ - if(bMetaContacts) - return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0); - return false; -} - - -HANDLE metaGetMostOnline(HANDLE hContact) -{ - - if(bMetaContacts) - return (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT,(WPARAM)hContact,0); - return 0; -} -HANDLE metaGetDefault(HANDLE hContact) -{ - - if(bMetaContacts) - return (HANDLE)CallService(MS_MC_GETDEFAULTCONTACT,(WPARAM)hContact,0); - return 0; -} - -HANDLE metaGetCurrent(HANDLE hContact) -{ - bool IsOnline(HANDLE hContact); - if(bMetaContacts) - { - if(!metaIsProtoMetaContacts(hContact)) - return hContact; - HANDLE hcnt = metaGetMostOnline (hContact); - if(!hcnt) - hcnt = metaGetDefault(hContact); - return hcnt; - } - return hContact; -} - - -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; -} - - +// Copyright © 2010 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) + return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0); + return 0; +} +bool metaIsSubcontact(HANDLE hContact) +{ + if(bMetaContacts) + return (HANDLE)CallService(MS_MC_GETMETACONTACT,(WPARAM)hContact,0); + return false; +} + + +HANDLE metaGetMostOnline(HANDLE hContact) +{ + + if(bMetaContacts) + return (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT,(WPARAM)hContact,0); + return 0; +} +HANDLE metaGetDefault(HANDLE hContact) +{ + + if(bMetaContacts) + return (HANDLE)CallService(MS_MC_GETDEFAULTCONTACT,(WPARAM)hContact,0); + return 0; +} + +HANDLE metaGetCurrent(HANDLE hContact) +{ + bool IsOnline(HANDLE hContact); + if(bMetaContacts) + { + if(!metaIsProtoMetaContacts(hContact)) + return hContact; + HANDLE hcnt = metaGetMostOnline (hContact); + if(!hcnt) + hcnt = metaGetDefault(hContact); + return hcnt; + } + return hContact; +} + + +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 index 0ac825e..b7928a9 100644 --- a/metacontacts.h +++ b/metacontacts.h @@ -1,25 +1,25 @@ -// Copyright © 2010 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); -HANDLE metaGetCurrent(HANDLE hContact); -DWORD metaGetContactsNum(HANDLE hContact); +// Copyright © 2010 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); +HANDLE metaGetCurrent(HANDLE hContact); +DWORD metaGetContactsNum(HANDLE hContact); HANDLE metaGetSubcontact(HANDLE hContact, int num); \ No newline at end of file diff --git a/options.cpp b/options.cpp index 3ac57b9..6b773d3 100644 --- a/options.cpp +++ b/options.cpp @@ -1,1242 +1,1242 @@ -// Copyright © 2010 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); - -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; - CallService(MS_OPT_ADDPAGE,wParam,(LPARAM)&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; - CallService(MS_OPT_ADDPAGE,wParam,(LPARAM)&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; - CallService(MS_OPT_ADDPAGE,wParam,(LPARAM)&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 = _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 = _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 = _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 = _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 = _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); - tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainName", ""); - tmp = mir_a2t(tmp2); - mir_free(tmp2); - ListView_SetItemText(hwndList, iRow, 2, (_tcslen(tmp) > 1)?tmp:_T("not set")); - mir_free(tmp); - tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainEmail", ""); - tmp = mir_a2t(tmp2); - 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 = "Current private key id: "; - char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); - keyinfo += (strlen(keyid) > 0)?keyid:"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", 1); - 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(); - 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(); - 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, _T("This is not gnupg binary !\nrecommended to use GnuPG v1.x.x with this plugn."), _T("Warning"), MB_OK); - } - if(bad_version) - MessageBox(0, _T("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); - { - 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"); - { - 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; -} - -HWND hPubKeyEdit = NULL; - - -static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) -{ - 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: - { - SetWindowPos(hwndDlg, 0, load_key_rect.left, load_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); - HANDLE hcnt = hContact; - if(metaIsProtoMetaContacts(hcnt)) - hcnt = metaGetMostOnline(hcnt); - TranslateDialogDefault(hwndDlg); - 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, _T("Turn off encryption")); - else - SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, _T("Turn on encryption")); - 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(); - 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 (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(); - 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); -} +// Copyright © 2010 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); + +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; + CallService(MS_OPT_ADDPAGE,wParam,(LPARAM)&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; + CallService(MS_OPT_ADDPAGE,wParam,(LPARAM)&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; + CallService(MS_OPT_ADDPAGE,wParam,(LPARAM)&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 = _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 = _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 = _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 = _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 = _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); + tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainName", ""); + tmp = mir_a2t(tmp2); + mir_free(tmp2); + ListView_SetItemText(hwndList, iRow, 2, (_tcslen(tmp) > 1)?tmp:_T("not set")); + mir_free(tmp); + tmp2 = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyMainEmail", ""); + tmp = mir_a2t(tmp2); + 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 = "Current private key id: "; + char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); + keyinfo += (strlen(keyid) > 0)?keyid:"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", 1); + 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(); + 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(); + 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, _T("This is not gnupg binary !\nrecommended to use GnuPG v1.x.x with this plugn."), _T("Warning"), MB_OK); + } + if(bad_version) + MessageBox(0, _T("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); + { + 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"); + { + 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; +} + +HWND hPubKeyEdit = NULL; + + +static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + 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: + { + SetWindowPos(hwndDlg, 0, load_key_rect.left, load_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); + HANDLE hcnt = hContact; + if(metaIsProtoMetaContacts(hcnt)) + hcnt = metaGetMostOnline(hcnt); + TranslateDialogDefault(hwndDlg); + 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, _T("Turn off encryption")); + else + SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, _T("Turn on encryption")); + 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(); + 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 (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(); + 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/resource.h b/resource.h index f292c2b..9043ac1 100644 --- a/resource.h +++ b/resource.h @@ -1,85 +1,85 @@ -//{{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 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 - -// 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 1066 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by new_gpg.rc +// +#define IDD_LOAD_PUBLIC_KEY 102 +#define IDD_FIRST_RUN 103 +#define IDD_OPT_GPG 104 +#define IDD_OPT_GPG_BIN 105 +#define IDD_BIN_PATH 106 +#define IDD_OPT_GPG_MESSAGES 107 +#define IDD_NEW_KEY 108 +#define IDD_KEY_GEN 109 +#define IDD_LOAD_EXISTING_KEY 110 +#define IDD_KEY_PASSWD 111 +#define IDI_SECURED 112 +#define IDD_IMPORT_KEY 112 +#define IDI_UNSECURED 113 +#define 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 + +// 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 1066 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/srmm.cpp b/srmm.cpp index 48c8b65..de86611 100644 --- a/srmm.cpp +++ b/srmm.cpp @@ -1,80 +1,80 @@ -// Copyright © 2010 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; - if(metaIsProtoMetaContacts(hContact)) - hContact = metaGetMostOnline(hContact); // возьмем тот, через который пойдет сообщение - - StatusIconClickData *sicd = (StatusIconClickData *)lParam; - if(strcmp(sicd->szModule, szGPGModuleName) != 0) - 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); - 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); - setSrmmIcon(hContact); - setClistIcon(hContact); - return 0; - } - if(isContactHaveKey(hContact)) - { - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); - setSrmmIcon(hContact); - setClistIcon(hContact); - } - } - return 0; -} +// Copyright © 2010 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; + if(metaIsProtoMetaContacts(hContact)) + hContact = metaGetMostOnline(hContact); // возьмем тот, через который пойдет сообщение + + StatusIconClickData *sicd = (StatusIconClickData *)lParam; + if(strcmp(sicd->szModule, szGPGModuleName) != 0) + 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); + 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); + setSrmmIcon(hContact); + setClistIcon(hContact); + return 0; + } + if(isContactHaveKey(hContact)) + { + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); + setSrmmIcon(hContact); + setClistIcon(hContact); + } + } + return 0; +} diff --git a/utilities.cpp b/utilities.cpp index b0f72c0..0b49e61 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -275,37 +275,37 @@ list transfers; int onProtoAck(WPARAM w, LPARAM l) { - ACKDATA *ack=(ACKDATA*)l; - CCSDATA *ccs=(CCSDATA*)ack->lParam; - if (ack->type!=ACKTYPE_FILE) - return 0; - PROTOFILETRANSFERSTATUS *f = (PROTOFILETRANSFERSTATUS*) ack->lParam; -// if(!f) -// f = (PROTOFILETRANSFERSTATUS*) ack->hProcess; - if(!f) - return 0; - - switch(ack->result) - { - case ACKRESULT_DENIED: case ACKRESULT_FAILED: - break; - case ACKRESULT_SUCCESS: - { - TCHAR *filename = NULL; -// if(f->szCurrentFile && f->szCurrentFile[0]) -// filename = mir_utf8decodeW(f->szCurrentFile); - if(f->tszCurrentFile && f->tszCurrentFile[0]) - filename = mir_wstrdup(f->tszCurrentFile); - if(!filename) - break; - TCHAR *temp = _wgetenv(_T("TEMP")); - if(_tcsstr(filename, temp)) - { - mir_free(filename); - break; - } - else if(_tcsstr(filename, _T(".gpg"))) //decrypt it - { //process encrypted file + ACKDATA *ack=(ACKDATA*)l; + CCSDATA *ccs=(CCSDATA*)ack->lParam; + if (ack->type!=ACKTYPE_FILE) + return 0; + PROTOFILETRANSFERSTATUS *f = (PROTOFILETRANSFERSTATUS*) ack->lParam; +// if(!f) +// f = (PROTOFILETRANSFERSTATUS*) ack->hProcess; + if(!f) + return 0; + + switch(ack->result) + { + case ACKRESULT_DENIED: case ACKRESULT_FAILED: + break; + case ACKRESULT_SUCCESS: + { + TCHAR *filename = NULL; +// if(f->szCurrentFile && f->szCurrentFile[0]) +// filename = mir_utf8decodeW(f->szCurrentFile); + if(f->tszCurrentFile && f->tszCurrentFile[0]) + filename = mir_wstrdup(f->tszCurrentFile); + if(!filename) + break; + TCHAR *temp = _wgetenv(_T("TEMP")); + if(_tcsstr(filename, temp)) + { + mir_free(filename); + break; + } + else if(_tcsstr(filename, _T(".gpg"))) //decrypt it + { //process encrypted file if(_waccess(f->tszCurrentFile, 0) == -1) { if(errno == ENOENT) @@ -342,13 +342,13 @@ int onProtoAck(WPARAM w, LPARAM l) delete gpg_thread; 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; -} - -string toUTF8(wstring str) -{ - string ustr; - wstring tmpstr; - utf8::replace_invalid(str.begin(), str.end(), back_inserter(tmpstr)); - utf8::utf16to8(tmpstr.begin(), tmpstr.end(), back_inserter(ustr)); - return ustr; -} - -string toUTF8(string str) -{ - string ustr; - wstring tmpstr; - utf8::replace_invalid(str.begin(), str.end(), back_inserter(tmpstr)); - utf8::utf16to8(tmpstr.begin(), tmpstr.end(), back_inserter(ustr)); - return ustr; -} - - -wstring toUTF16(string str) //convert as much as possible -{ - wstring ustr; - string tmpstr; - utf8::replace_invalid(str.begin(), str.end(), back_inserter(tmpstr)); - utf8::utf8to16(tmpstr.begin(), tmpstr.end(), back_inserter(ustr)); - return ustr; -} - -string get_random(int length) -{ - string chars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"); - string data; - boost::random_device rng; - boost::variate_generator> 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(); - for(list::iterator p = hcontact_data[hContact].msgs_to_send.begin(); p != end; ++p) - { - CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)p->c_str()); - HistoryLog(hContact, (char*)p->c_str(), EVENTTYPE_MESSAGE, DBEF_SENT); - boost::this_thread::sleep(boost::posix_time::seconds(1)); - } - return; - } - else - return; - } -} - +#define NEWTSTR_MALLOC(A) (A==NULL)?NULL:strcpy((char*)mir_alloc(sizeof(char)*(strlen(A)+1)),A) + +const bool StriStr(const char *str, const char *substr) +{ + bool i = false; + char *str_up = NEWTSTR_MALLOC(str); + char *substr_up = NEWTSTR_MALLOC(substr); + + CharUpperBuffA(str_up, strlen(str_up)); + CharUpperBuffA(substr_up, strlen(substr_up)); + + if(strstr (str_up, substr_up)) + i = true; + + mir_free(str_up); + mir_free(substr_up); + + return i; +} + +bool IsOnline(HANDLE hContact) +{ + if(DBGetContactSettingByte(hContact, szGPGModuleName, "Status", 0) == ID_STATUS_OFFLINE) + return false; + return true; +} + +//from secureim +#include + +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; +} + +string toUTF8(wstring str) +{ + string ustr; + wstring tmpstr; + utf8::replace_invalid(str.begin(), str.end(), back_inserter(tmpstr)); + utf8::utf16to8(tmpstr.begin(), tmpstr.end(), back_inserter(ustr)); + return ustr; +} + +string toUTF8(string str) +{ + string ustr; + wstring tmpstr; + utf8::replace_invalid(str.begin(), str.end(), back_inserter(tmpstr)); + utf8::utf16to8(tmpstr.begin(), tmpstr.end(), back_inserter(ustr)); + return ustr; +} + + +wstring toUTF16(string str) //convert as much as possible +{ + wstring ustr; + string tmpstr; + utf8::replace_invalid(str.begin(), str.end(), back_inserter(tmpstr)); + utf8::utf8to16(tmpstr.begin(), tmpstr.end(), back_inserter(ustr)); + return ustr; +} + +string get_random(int length) +{ + string chars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"); + string data; + boost::random_device rng; + boost::variate_generator> 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(); + for(list::iterator p = hcontact_data[hContact].msgs_to_send.begin(); p != end; ++p) + { + CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)p->c_str()); + HistoryLog(hContact, (char*)p->c_str(), EVENTTYPE_MESSAGE, DBEF_SENT); + boost::this_thread::sleep(boost::posix_time::seconds(1)); + } + return; + } + else + return; + } +} + string time_str() -{ - boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); +{ + boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); return (string)boost::posix_time::to_simple_string(now); } diff --git a/utilities.h b/utilities.h index 3871f67..58a23b9 100644 --- a/utilities.h +++ b/utilities.h @@ -1,40 +1,40 @@ -// Copyright © 2010 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); - - -void HistoryLog(HANDLE hContact, char *data, int event_type, int flags); -int ComboBoxAddStringUtf(HWND hCombo, const TCHAR *szString, DWORD data); -bool isContactSecured(HANDLE hContact); -bool isContactHaveKey(HANDLE hContact); -bool isGPGConfigured(); -const bool StriStr(const char *str, const char *substr); -string toUTF8(wstring str); -string toUTF8(string str); -wstring toUTF16(string str); -string get_random(int length); -string time_str(); - -#endif +// Copyright © 2010 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); + + +void HistoryLog(HANDLE hContact, char *data, int event_type, int flags); +int ComboBoxAddStringUtf(HWND hCombo, const TCHAR *szString, DWORD data); +bool isContactSecured(HANDLE hContact); +bool isContactHaveKey(HANDLE hContact); +bool isGPGConfigured(); +const bool StriStr(const char *str, const char *substr); +string toUTF8(wstring str); +string toUTF8(string str); +wstring toUTF16(string str); +string get_random(int length); +string time_str(); + +#endif -- cgit v1.2.3 From 094d38a1686a807bf6b3a2cea3ef027bd70bb05b Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 29 Jan 2011 17:28:12 +0300 Subject: Metacontacts encodings fix --- init.cpp | 8 ++++---- messages.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/init.cpp b/init.cpp index 7983659..8af16e6 100644 --- a/init.cpp +++ b/init.cpp @@ -1,4 +1,4 @@ -// Copyright © 2010 sss +// Copyright © 2010-2011 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -42,11 +42,11 @@ std::map hcontact_data; PLUGININFOEX pluginInfo={ sizeof(PLUGININFOEX), 0, - PLUGIN_MAKE_VERSION(0,0,0,9), - "new GPG encryption support plugin, used code from http://addons.miranda-im.org/details.php?action=viewfile&id=3485", + PLUGIN_MAKE_VERSION(0,0,0,10), + "new GPG encryption support plugin, based on code from old gpg plugin and secureim", "sss", "sss123next@list.ru", - "© 2010 sss", + "© 2010-2011 sss", "http://sss.chaoslab.ru/tracker/mim_plugs/", 1, //unicode 0, //doesn't replace anything built-in diff --git a/messages.cpp b/messages.cpp index 0289685..c597ee3 100644 --- a/messages.cpp +++ b/messages.cpp @@ -1,4 +1,4 @@ -// Copyright © 2010 sss +// Copyright © 2010-2011 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -619,7 +619,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) str.append(tmp); mir_free(tmp); } - { //not xmpp, just replace whole message + { string out; DWORD code; wstring cmd; @@ -736,11 +736,11 @@ int SendMsgSvc(WPARAM w, LPARAM l) str_event.insert(0, toUTF8(outopentag)); str_event.append(toUTF8(outclosetag)); } - HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT); - HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT); + HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | DBEF_UTF); + HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT |DBEF_UTF); hcontact_data[hContact].msgs_to_ignore.push_back((char*)ccs->lParam); hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back((char*)ccs->lParam); //hmm, twice ? metacontacts !! %) - CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)toUTF8(str).c_str()); + CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UNICODE, (LPARAM)str.c_str()); return returnNoError(hContact); } if(bAppendTags) -- cgit v1.2.3 From 86da56a08b722b906f5e660ab965a995a3ba1ff4 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 29 Jan 2011 17:29:36 +0300 Subject: Additional encoding conversion --- messages.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/messages.cpp b/messages.cpp index c597ee3..36434ea 100644 --- a/messages.cpp +++ b/messages.cpp @@ -738,8 +738,8 @@ int SendMsgSvc(WPARAM w, LPARAM l) } HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | DBEF_UTF); HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT |DBEF_UTF); - hcontact_data[hContact].msgs_to_ignore.push_back((char*)ccs->lParam); - hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back((char*)ccs->lParam); //hmm, twice ? metacontacts !! %) + hcontact_data[hContact].msgs_to_ignore.push_back(toUTF8(toUTF16((char*)ccs->lParam))); + hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back(toUTF8(toUTF16((char*)ccs->lParam))); //hmm, twice ? metacontacts !! %) CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UNICODE, (LPARAM)str.c_str()); return returnNoError(hContact); } -- cgit v1.2.3 From 1bfecda76700e3ed89a1e381789a77ab26e262a8 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 1 Feb 2011 03:48:36 +0300 Subject: metacontacts fixes --- messages.cpp | 35 ++++++++++++++++++++++++----------- new_gpg.rc | 37 +++++++++++-------------------------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/messages.cpp b/messages.cpp index 36434ea..952d9e5 100644 --- a/messages.cpp +++ b/messages.cpp @@ -520,7 +520,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) { if(metaIsSubcontact(hContact)) { - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, DBEF_UTF); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, DBEF_UTF| DBEF_READ); HistoryLog(metaGetContact(hContact), msg, EVENTTYPE_MESSAGE, DBEF_UTF); mir_free(msg); return 1; @@ -551,7 +551,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) hcontact_data[ccs->hContact].msgs_to_ignore.push_back((char*)ccs->lParam); return CallService(MS_PROTO_CHAINSEND, w, l); } - if(!isContactHaveKey(hContact) && bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && isGPGConfigured()) //TODO: add all mesages to list, and send after key exchange done, encrypted + if(!isContactHaveKey(hContact) && bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && isGPGConfigured()) { void send_encrypted_msgs_thread(HANDLE hContact); LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); @@ -611,11 +611,17 @@ int SendMsgSvc(WPARAM w, LPARAM l) { //encrypt data here wstring str; + bool isansi = false; if(!metaIsSubcontact(hContact)) str = toUTF16(msg); else {//workaround ... - wchar_t *tmp = mir_a2t(msg); + wchar_t *tmp = mir_utf8decodeW(msg); + if(!tmp) + { + tmp = mir_a2t(msg); + isansi = true; + } str.append(tmp); mir_free(tmp); } @@ -702,7 +708,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) } if(out.find("usage: ") != string::npos) { - MessageBox(0, _T("Something wrong, gpg does not understand us, aborting encrypting."), _T("Warning"), MB_OK); + MessageBox(0, _T("Something wrong, gpg does not understand us, aborting encryption."), _T("Warning"), MB_OK); DeleteFile(path.c_str()); return CallService(MS_PROTO_CHAINSEND, w, l); } @@ -732,15 +738,22 @@ int SendMsgSvc(WPARAM w, LPARAM l) { //dirty hack to avoid metacontacts problem ..., this also broke filters chain string str_event = (char*)ccs->lParam; if(bAppendTags) - { + { //utf8 tag will cause problems here str_event.insert(0, toUTF8(outopentag)); str_event.append(toUTF8(outclosetag)); } - HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | DBEF_UTF); - HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT |DBEF_UTF); - hcontact_data[hContact].msgs_to_ignore.push_back(toUTF8(toUTF16((char*)ccs->lParam))); - hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back(toUTF8(toUTF16((char*)ccs->lParam))); //hmm, twice ? metacontacts !! %) - CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UNICODE, (LPARAM)str.c_str()); + DWORD flags = 0, flags2 = 0; + if(!isansi) //message from metacontact itself, yet another metacontacts workaround... + flags |= DBEF_UTF; + else + flags2 |= DBEF_READ; + HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | flags2 | flags); + HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | flags); + hcontact_data[hContact].msgs_to_ignore.push_back(msg); + if(isansi) + hcontact_data[hContact].msgs_to_ignore.push_back(msg); + hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back(msg); + CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)toUTF8(str).c_str()); return returnNoError(hContact); } if(bAppendTags) @@ -758,7 +771,7 @@ int HookSendMsg(WPARAM w, LPARAM l) DBEVENTINFO * dbei = (DBEVENTINFO*)l; if((dbei->eventType == EVENTTYPE_MESSAGE) && (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-----")) //grrrr! + 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 = NULL; if(!hcontact_data[(HANDLE)w].msgs_to_ignore.empty()) diff --git a/new_gpg.rc b/new_gpg.rc index a0535cc..b6deae4 100644 --- a/new_gpg.rc +++ b/new_gpg.rc @@ -13,11 +13,13 @@ #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// -// Russian (Russia) resources +// русский resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) +#ifdef _WIN32 LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT #pragma code_page(1251) +#endif //_WIN32 #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// @@ -175,7 +177,7 @@ END // #ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO +GUIDELINES DESIGNINFO BEGIN IDD_LOAD_PUBLIC_KEY, DIALOG BEGIN @@ -261,7 +263,7 @@ IDI_UNSECURED ICON "icons\\unsecured.ico" // VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,0,0,9 + FILEVERSION 0,0,0,10 PRODUCTVERSION 0,9,0,0 FILEFLAGSMASK 0x17L #ifdef _DEBUG @@ -278,7 +280,7 @@ BEGIN BLOCK "041904b0" BEGIN VALUE "FileDescription", "new_gpg" - VALUE "FileVersion", "0.0.0.9" + VALUE "FileVersion", "0.0.0.10" VALUE "InternalName", "new_gpg" VALUE "LegalCopyright", "Copyright (C) 2010 sss" VALUE "OriginalFilename", "new_gpg" @@ -292,16 +294,18 @@ BEGIN END END -#endif // Russian (Russia) resources +#endif // русский resources ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// -// English (United States) resources +// английский (США) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) +#endif //_WIN32 ///////////////////////////////////////////////////////////////////////////// // @@ -357,26 +361,7 @@ BEGIN RTEXT "Close:",IDC_STATIC,127,49,23,8 END - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_OPT_GPG, DIALOG - BEGIN - END - - IDD_OPT_GPG_BIN, DIALOG - BEGIN - END -END -#endif // APSTUDIO_INVOKED - -#endif // English (United States) resources +#endif // английский (США) resources ///////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 02fa894d6d4ecada2f3c79a2fd3fb84c0d4425ad Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 1 Feb 2011 04:11:54 +0300 Subject: hm... --- messages.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/messages.cpp b/messages.cpp index 952d9e5..a0389a7 100644 --- a/messages.cpp +++ b/messages.cpp @@ -750,8 +750,6 @@ int SendMsgSvc(WPARAM w, LPARAM l) HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | flags2 | flags); HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | flags); hcontact_data[hContact].msgs_to_ignore.push_back(msg); - if(isansi) - hcontact_data[hContact].msgs_to_ignore.push_back(msg); hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back(msg); CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)toUTF8(str).c_str()); return returnNoError(hContact); -- cgit v1.2.3 From 9704417a4866a6b1758123bef6e90b14fb154bbe Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Thu, 3 Feb 2011 02:35:33 +0300 Subject: "Select existing key list fixes" --- main.cpp | 52 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/main.cpp b/main.cpp index 9af1f5d..1287be5 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,4 @@ -// Copyright © 2010 sss +// Copyright © 2010-2011 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -1376,11 +1376,17 @@ static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam, col.cx = 30; ListView_InsertColumn(hwndList, 3, &col); ZeroMemory(&col,sizeof(col)); - col.pszText = _T("Key length"); + 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; { @@ -1423,30 +1429,49 @@ static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam, TCHAR *tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); item.pszText = tmp; iRow = ListView_InsertItem(hwndList, &item); - ListView_SetItemText(hwndList, iRow, 4, tmp); + ListView_SetItemText(hwndList, iRow, 5, tmp); mir_free(tmp); p2+=2; p = out.find(" ", p2); tmp = mir_wstrdup(toUTF16(out.substr(p2,p-p2)).c_str()); ListView_SetItemText(hwndList, iRow, 0, tmp); mir_free(tmp); - p++; p2 = out.find("\n", p); + string::size_type p3 = out.substr(p, p2-p).find("["); + if(p3 != string::npos) + { + p3+=p; + p2 = p3; + p2--; + p3++; + p3+=strlen("expires: "); + string::size_type p4 = out.find("]", p3); + tmp = mir_wstrdup(toUTF16(out.substr(p3,p4-p3)).c_str()); + ListView_SetItemText(hwndList, iRow, 4, tmp); + mir_free(tmp); + } tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); ListView_SetItemText(hwndList, iRow, 3, tmp); mir_free(tmp); - p = out.find("uid ", p); - p2 = out.find_first_not_of(" ", p+5); - p = out.find("<", p2); - tmp = mir_wstrdup(toUTF16(out.substr(p2,p-p2)).c_str()); - ListView_SetItemText(hwndList, iRow, 2, tmp); - mir_free(tmp); - p++; - p2 = out.find(">", p); + p+= strlen("uid "); + p2 = out.find("\n", p); + p3 = out.substr(p, p2-p).find("<"); + if(p3 != string::npos) + { + p3+=p; + p2=p3; + p2--; + p3++; + string::size_type p4 = out.find(">", p3); + tmp = mir_wstrdup(toUTF16(out.substr(p3,p4-p3)).c_str()); + ListView_SetItemText(hwndList, iRow, 1, tmp); + mir_free(tmp); + } + p = out.find_first_not_of(" ", p); tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); - ListView_SetItemText(hwndList, iRow, 1, tmp); + ListView_SetItemText(hwndList, iRow, 2, tmp); mir_free(tmp); // p = out.find("sub ", p2) + 6; // p = out.find(" ", p) + 1; @@ -1459,6 +1484,7 @@ static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam, 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++; } } -- cgit v1.2.3 From 816241e9a436ba0992d6306a0b739862d6e2fa47 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 5 Feb 2011 01:01:39 +0300 Subject: keylist fix --- main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.cpp b/main.cpp index 1287be5..f35ff70 100644 --- a/main.cpp +++ b/main.cpp @@ -1451,6 +1451,8 @@ static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam, ListView_SetItemText(hwndList, iRow, 4, tmp); mir_free(tmp); } + else + p2--; tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); ListView_SetItemText(hwndList, iRow, 3, tmp); mir_free(tmp); @@ -1469,6 +1471,8 @@ static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam, 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); -- cgit v1.2.3 From b5eba0e25f83526ad457252c4b860300393bb3c6 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Fri, 11 Mar 2011 18:46:55 +0200 Subject: modified: new_gpg.rc --- new_gpg.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new_gpg.rc b/new_gpg.rc index a0535cc..d493f87 100644 --- a/new_gpg.rc +++ b/new_gpg.rc @@ -280,7 +280,7 @@ BEGIN VALUE "FileDescription", "new_gpg" VALUE "FileVersion", "0.0.0.9" VALUE "InternalName", "new_gpg" - VALUE "LegalCopyright", "Copyright (C) 2010 sss" + VALUE "LegalCopyright", "Copyright (C) 2010-2011 sss" VALUE "OriginalFilename", "new_gpg" VALUE "ProductName", "new_gpg" VALUE "ProductVersion", "0.9.0.0" -- cgit v1.2.3 From 2c8627c6f7c0762c36995028b9d7af346209e2be Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 12 Mar 2011 00:22:51 +0200 Subject: small ui inprovements --- options.cpp | 12 +++++++++++- utilities.cpp | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/options.cpp b/options.cpp index 6b773d3..f2b658a 100644 --- a/options.cpp +++ b/options.cpp @@ -644,6 +644,11 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP if(metaIsProtoMetaContacts(hcnt)) hcnt = metaGetMostOnline(hcnt); TranslateDialogDefault(hwndDlg); + { + string msg = "Load Public GPG Key for "; + msg += (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hcnt, 0); + SetWindowTextA(hwndDlg, msg.c_str()); + } bool isContactSecured(HANDLE); if(!hcnt) { @@ -653,7 +658,10 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP if(isContactSecured(hcnt)) SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, _T("Turn off encryption")); else + { SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, _T("Turn on encryption")); + CheckDlgButton(hwndDlg, IDC_ENABLE_ENCRYPTION, 1); + } if(hcnt) { tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", _T("")); @@ -720,7 +728,9 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP TCHAR *tmp3 = mir_a2t(out.c_str()); str.clear(); str.append(tmp3); - string msg = "Load Public GPG Key (Key ID: "; + 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()); diff --git a/utilities.cpp b/utilities.cpp index 0b49e61..cf64422 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -930,6 +930,8 @@ int returnNoError(HANDLE hContact) { SetEvent( hEvent ); return 777; } +// end from secureim + string toUTF8(wstring str) { -- cgit v1.2.3 From 68b8f4ead3b2005856427392bd1a7fd8830ee3a9 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 16 Mar 2011 03:24:16 +0200 Subject: modified: jabber_account.cpp modified: jabber_account.h modified: utilities.cpp --- jabber_account.cpp | 10 ++++++++++ jabber_account.h | 4 +++- utilities.cpp | 13 +++++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/jabber_account.cpp b/jabber_account.cpp index ac5ce24..9dedd56 100644 --- a/jabber_account.cpp +++ b/jabber_account.cpp @@ -36,6 +36,10 @@ void JabberAccount::setPrescenseHandler(HJHANDLER hHandler) { hPrescenseHandler = hHandler; } +void JabberAccount::setMessageHandler(HJHANDLER hHandler) +{ + hMessageHandler = hHandler; +} TCHAR *JabberAccount::getAccountName() @@ -59,12 +63,18 @@ 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; } diff --git a/jabber_account.h b/jabber_account.h index 66a8bc1..766f571 100644 --- a/jabber_account.h +++ b/jabber_account.h @@ -23,19 +23,21 @@ public: 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; + HJHANDLER hSendHandler, hPrescenseHandler, hMessageHandler; }; #endif \ No newline at end of file diff --git a/utilities.cpp b/utilities.cpp index cf64422..d59a7cb 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -782,6 +782,13 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi return FALSE; } +static JABBER_HANDLER_FUNC MessageHandler(IJabberInterface *ji, HXML node, void *pUserData) +{ + return FALSE; +} + + + void AddHandlers() { @@ -792,13 +799,11 @@ void AddHandlers() 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_ERROR,0 ,0)); 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)")); -- cgit v1.2.3 From e344eae02ec47553fb1eec9fb2e9e6f975c72bc7 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 16 Mar 2011 16:23:30 +0200 Subject: fixing outgoung encrypted filetransfer... --- new_gpg.vcxproj | 10 +++++----- utilities.cpp | 31 +++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/new_gpg.vcxproj b/new_gpg.vcxproj index 39bdf92..21ee00c 100644 --- a/new_gpg.vcxproj +++ b/new_gpg.vcxproj @@ -477,7 +477,7 @@ Disabled - 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) + x:\temp\windows\libs\utf8cpp\include;C:\Boost\include\boost-1_46;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 @@ -499,7 +499,7 @@ 0x0809 - shlwapi.lib;%(AdditionalDependencies) libboost_thread-vc100-mt-sgd-1_45.lib + shlwapi.lib;%(AdditionalDependencies) libboost_thread-vc100-mt-sgd-1_46_1.lib true C:\Boost\lib-debug;%(AdditionalLibraryDirectories) true @@ -527,7 +527,7 @@ Disabled - 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) + x:\temp\windows\libs\utf8cpp\include;C:\Boost\include\boost-1_46;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 @@ -685,7 +685,7 @@ 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 + x:\temp\windows\libs\utf8cpp\include;C:\Boost\include\boost-1_46;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 @@ -739,7 +739,7 @@ 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) + x:\temp\windows\libs\utf8cpp\include;C:\Boost\include\boost-1_46;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 diff --git a/utilities.cpp b/utilities.cpp index d59a7cb..28bb51e 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -375,7 +375,9 @@ int onSendFile(WPARAM w, LPARAM l) DWORD code; pxResult result; char *keyid = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "KeyID", ""); - wstring cmd = _T("-r "); + wstring cmd = _T("--batch --yes -r "); + if(DBGetContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwaysTrust", 0)) + cmd += _T("--trust-model always "); TCHAR *szKeyid = mir_a2t(keyid); cmd += szKeyid; mir_free(szKeyid); @@ -401,19 +403,40 @@ int onSendFile(WPARAM w, LPARAM l) 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(10))) + if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) { delete gpg_thread; debuglog<hContact, szGPGModuleName, "bAlwaysTrust", 1); + cmd.insert(0, _T("--trust-model always ")); + 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(180))) + { + gpg_thread.~thread(); + debuglog<szProtoService, w, l); } void storeOutput(HANDLE ahandle, string *output) -- cgit v1.2.3 From d116d404808e9ae9a7860c1eecf0b5974b91c994 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Wed, 16 Mar 2011 17:39:39 +0200 Subject: modified: utilities.cpp --- utilities.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utilities.cpp b/utilities.cpp index 28bb51e..115c2bf 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -369,7 +369,7 @@ int onSendFile(WPARAM w, LPARAM l) name = file[i]; else name++; - TCHAR *file_out = (TCHAR*) mir_alloc(_tcslen(name)+20); + TCHAR *file_out = new TCHAR [_tcslen(file[i])+4]; mir_sntprintf(file_out, _tcslen(name)+7, _T("%s.gpg"), name); string out; DWORD code; @@ -432,7 +432,7 @@ int onSendFile(WPARAM w, LPARAM l) } mir_free(file[i]); file[i]=mir_wstrdup(path_out.c_str()); - mir_free(file_out); + delete [] file_out; transfers.push_back(path_out); } } -- cgit v1.2.3