summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2011-01-29 15:17:51 +0300
committerGluzskiy Alexandr <sss123next@list.ru>2011-01-29 15:17:51 +0300
commit4d9fce6f544f0c6782a7ade4900afd3e1c6c9c52 (patch)
tree286cf4e530cec23e62e1a629857b4366ddd9862f
parent8142cedd8b857edd99a92f328e8b692b32bfeba6 (diff)
Better metacontacts handling\nFixed subkey length in keygen
-rw-r--r--clist.cpp82
-rw-r--r--commonheaders.h8
-rw-r--r--constants.h10
-rw-r--r--globals.h44
-rw-r--r--gpg_wrapper.cpp2
-rw-r--r--gpg_wrapper.h60
-rw-r--r--icons.cpp288
-rw-r--r--init.cpp536
-rw-r--r--jabber_account.cpp148
-rw-r--r--jabber_account.h80
-rw-r--r--log.cpp182
-rw-r--r--log.h2
-rw-r--r--m_extraicons.h316
-rw-r--r--m_metacontacts.h332
-rw-r--r--main.cpp51
-rw-r--r--main.h62
-rw-r--r--messages.cpp285
-rw-r--r--metacontacts.cpp200
-rw-r--r--metacontacts.h48
-rw-r--r--options.cpp2484
-rw-r--r--resource.h170
-rw-r--r--srmm.cpp160
-rw-r--r--utilities.cpp388
-rw-r--r--utilities.h80
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 <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
-#include <boost/nondet_random.hpp>
-#include <boost/random/variate_generator.hpp>
-#include <boost/random/uniform_int.hpp>
-#include <boost/date_time.hpp>
+#include <boost/nondet_random.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/uniform_int.hpp>
+#include <boost/date_time.hpp>
//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<<time_str()<<": Gpg binary not found";
}
-}
+}
diff --git a/gpg_wrapper.h b/gpg_wrapper.h
index 52b3c1c..d9a02c9 100644
--- a/gpg_wrapper.h
+++ b/gpg_wrapper.h
@@ -1,31 +1,31 @@
-#ifndef GPG_WRAPPER_H
-#define GPG_WRAPPER_H
-typedef enum {
- pxSuccess,
- pxSuccessExitCodeInvalid,
- pxCreatePipeFailed,
- pxDuplicateHandleFailed,
- pxCloseHandleFailed,
- pxCreateProcessFailed,
- pxThreadWaitFailed,
- pxReadFileFailed,
- pxBufferOverflow,
- pxNotFound,
- pxNotConfigured
-}
-pxResult;
-
-pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result);
-
-struct gpg_execution_params
-{
- wstring *cmd;
- char *useless;
- string *out;
- LPDWORD code;
- pxResult *result;
-};
-
-void pxEexcute_thread(void *param);
-
+#ifndef GPG_WRAPPER_H
+#define GPG_WRAPPER_H
+typedef enum {
+ pxSuccess,
+ pxSuccessExitCodeInvalid,
+ pxCreatePipeFailed,
+ pxDuplicateHandleFailed,
+ pxCloseHandleFailed,
+ pxCreateProcessFailed,
+ pxThreadWaitFailed,
+ pxReadFileFailed,
+ pxBufferOverflow,
+ pxNotFound,
+ pxNotConfigured
+}
+pxResult;
+
+pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result);
+
+struct gpg_execution_params
+{
+ wstring *cmd;
+ char *useless;
+ string *out;
+ LPDWORD code;
+ pxResult *result;
+};
+
+void pxEexcute_thread(void *param);
+
#endif \ No newline at end of file
diff --git a/icons.cpp b/icons.cpp
index 96c4f50..1f4d353 100644
--- a/icons.cpp
+++ b/icons.cpp
@@ -1,144 +1,144 @@
-// 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"
-
-HANDLE IconLibDefine(TCHAR* desc, TCHAR* section, char* ident, HICON icon, char* def_file, int def_idx, int size)
-{
- SKINICONDESC sid = {0};
- HANDLE hIcon;
-
- if(!size)
- size = 16;
-
- sid.cbSize = SKINICONDESC_SIZE;
- sid.ptszSection = section;
- sid.ptszDescription = desc;
- sid.flags = SIDF_TCHAR;
-
- sid.pszName = ident;
- sid.pszDefaultFile = def_file;
- sid.iDefaultIndex = def_idx;
- sid.hDefaultIcon = icon;
- sid.cx = sid.cy = size;
-
- hIcon = (HANDLE)CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid);
-
- return hIcon;
-}
-
-
-void InitIconLib()
-{
- extern HINSTANCE hInst;
- char lib[MAX_PATH];
- GetModuleFileNameA(hInst, lib, MAX_PATH);
- TCHAR *module = mir_a2t(szGPGModuleName);
-
- IconLibDefine(_T("Secured"), module, "secured", NULL, lib, -IDI_SECURED,0);
- IconLibDefine(_T("Unsecured"), module, "unsecured", NULL, lib, -IDI_UNSECURED,0);
- mir_free(module);
-}
-
-
-
-
-
-HICON IconLibGetIcon(const char* ident)
-{
- return (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)ident);
-}
-
-
-
-void IconLibReleaseIcon(const char* ident)
-{
- CallService(MS_SKIN2_RELEASEICON, 0, (LPARAM)ident);
-}
-
-
-
-HANDLE IconLibHookIconsChanged(MIRANDAHOOK hook)
-{
- return HookEvent(ME_SKIN2_ICONSCHANGED, hook);
-}
-
-
-void setClistIcon(HANDLE hContact)
-{
- bool enabled = isContactSecured(hContact);
- extern HANDLE g_hCLIcon;
- HANDLE hMC = metaGetContact(hContact);
- if(g_hCLIcon && enabled)
- { // обновить иконки в clist
- HICON icon = IconLibGetIcon("secured");
- IconExtraColumn iec = {0};
- iec.cbSize = sizeof(iec);
- iec.hImage = (HANDLE)CallService(MS_CLIST_EXTRA_ADD_ICON, (WPARAM)icon, (LPARAM)0);
- ExtraIcon_SetIcon(g_hCLIcon, hContact, iec.hImage);
- if(hMC)
- ExtraIcon_SetIcon(g_hCLIcon, hMC, iec.hImage);
- }
- else
- {
- ExtraIcon_SetIcon(g_hCLIcon, hContact, (HANDLE)0); // is it right ? hmm.., at least working....
- if(hMC)
- ExtraIcon_SetIcon(g_hCLIcon, hMC, (HANDLE)0);
- }
-}
-
-void setSrmmIcon(HANDLE hContact)
-{
- hContact = metaGetCurrent(hContact);
- bool enabled = isContactSecured(hContact);
- HANDLE hMC = metaGetContact(hContact);
- if(ServiceExists(MS_MSG_MODIFYICON))
- { // обновить иконки в srmm
- StatusIconData sid = {0};
- sid.cbSize = sizeof(sid);
- sid.szModule = szGPGModuleName;
- sid.hIcon = IconLibGetIcon("secured");
- sid.dwId = 0x00000001;
- sid.flags = enabled?0:MBF_HIDDEN;
- CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid);
- if( hMC )
- CallService(MS_MSG_MODIFYICON, (WPARAM)hMC, (LPARAM)&sid);
- ZeroMemory(&sid, sizeof(sid));
- sid.cbSize = sizeof(sid);
- sid.szModule = szGPGModuleName;
- sid.hIcon = IconLibGetIcon("unsecured");
- sid.dwId = 0x00000002;
- sid.flags = enabled?MBF_HIDDEN:0;
- CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid);
- if( hMC )
- CallService(MS_MSG_MODIFYICON, (WPARAM)hMC, (LPARAM)&sid);
- }
-}
-
-
-void RefreshContactListIcons()
-{
- HANDLE hContact;
- extern HANDLE g_hCLIcon;
- CallService(MS_CLUI_LISTBEGINREBUILD,0,0);
- hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
- while (hContact)
- {
- setClistIcon(hContact);
- hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0);
- }
- CallService(MS_CLUI_LISTENDREBUILD,0,0);
-}
+// 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"
+
+HANDLE IconLibDefine(TCHAR* desc, TCHAR* section, char* ident, HICON icon, char* def_file, int def_idx, int size)
+{
+ SKINICONDESC sid = {0};
+ HANDLE hIcon;
+
+ if(!size)
+ size = 16;
+
+ sid.cbSize = SKINICONDESC_SIZE;
+ sid.ptszSection = section;
+ sid.ptszDescription = desc;
+ sid.flags = SIDF_TCHAR;
+
+ sid.pszName = ident;
+ sid.pszDefaultFile = def_file;
+ sid.iDefaultIndex = def_idx;
+ sid.hDefaultIcon = icon;
+ sid.cx = sid.cy = size;
+
+ hIcon = (HANDLE)CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid);
+
+ return hIcon;
+}
+
+
+void InitIconLib()
+{
+ extern HINSTANCE hInst;
+ char lib[MAX_PATH];
+ GetModuleFileNameA(hInst, lib, MAX_PATH);
+ TCHAR *module = mir_a2t(szGPGModuleName);
+
+ IconLibDefine(_T("Secured"), module, "secured", NULL, lib, -IDI_SECURED,0);
+ IconLibDefine(_T("Unsecured"), module, "unsecured", NULL, lib, -IDI_UNSECURED,0);
+ mir_free(module);
+}
+
+
+
+
+
+HICON IconLibGetIcon(const char* ident)
+{
+ return (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)ident);
+}
+
+
+
+void IconLibReleaseIcon(const char* ident)
+{
+ CallService(MS_SKIN2_RELEASEICON, 0, (LPARAM)ident);
+}
+
+
+
+HANDLE IconLibHookIconsChanged(MIRANDAHOOK hook)
+{
+ return HookEvent(ME_SKIN2_ICONSCHANGED, hook);
+}
+
+
+void setClistIcon(HANDLE hContact)
+{
+ bool enabled = isContactSecured(hContact);
+ extern HANDLE g_hCLIcon;
+ HANDLE hMC = metaGetContact(hContact);
+ if(g_hCLIcon && enabled)
+ { // обновить иконки в clist
+ HICON icon = IconLibGetIcon("secured");
+ IconExtraColumn iec = {0};
+ iec.cbSize = sizeof(iec);
+ iec.hImage = (HANDLE)CallService(MS_CLIST_EXTRA_ADD_ICON, (WPARAM)icon, (LPARAM)0);
+ ExtraIcon_SetIcon(g_hCLIcon, hContact, iec.hImage);
+ if(hMC)
+ ExtraIcon_SetIcon(g_hCLIcon, hMC, iec.hImage);
+ }
+ else
+ {
+ ExtraIcon_SetIcon(g_hCLIcon, hContact, (HANDLE)0); // is it right ? hmm.., at least working....
+ if(hMC)
+ ExtraIcon_SetIcon(g_hCLIcon, hMC, (HANDLE)0);
+ }
+}
+
+void setSrmmIcon(HANDLE hContact)
+{
+ hContact = metaGetCurrent(hContact);
+ bool enabled = isContactSecured(hContact);
+ HANDLE hMC = metaGetContact(hContact);
+ if(ServiceExists(MS_MSG_MODIFYICON))
+ { // обновить иконки в srmm
+ StatusIconData sid = {0};
+ sid.cbSize = sizeof(sid);
+ sid.szModule = szGPGModuleName;
+ sid.hIcon = IconLibGetIcon("secured");
+ sid.dwId = 0x00000001;
+ sid.flags = enabled?0:MBF_HIDDEN;
+ CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid);
+ if( hMC )
+ CallService(MS_MSG_MODIFYICON, (WPARAM)hMC, (LPARAM)&sid);
+ ZeroMemory(&sid, sizeof(sid));
+ sid.cbSize = sizeof(sid);
+ sid.szModule = szGPGModuleName;
+ sid.hIcon = IconLibGetIcon("unsecured");
+ sid.dwId = 0x00000002;
+ sid.flags = enabled?MBF_HIDDEN:0;
+ CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid);
+ if( hMC )
+ CallService(MS_MSG_MODIFYICON, (WPARAM)hMC, (LPARAM)&sid);
+ }
+}
+
+
+void RefreshContactListIcons()
+{
+ HANDLE hContact;
+ extern HANDLE g_hCLIcon;
+ CallService(MS_CLUI_LISTBEGINREBUILD,0,0);
+ hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
+ while (hContact)
+ {
+ setClistIcon(hContact);
+ hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0);
+ }
+ CallService(MS_CLUI_LISTENDREBUILD,0,0);
+}
diff --git a/init.cpp b/init.cpp
index 3497f4b..7983659 100644
--- a/init.cpp
+++ b/init.cpp
@@ -1,268 +1,268 @@
-// 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 <JabberAccount*> 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<HANDLE, contact_data> 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("<GPGdec>"));
- inclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", _T("</GPGdec>"));
- outopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", _T("<GPGenc>"));
- outclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", _T("</GPGenc>"));
- 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<wstring> 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<wstring>::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 <JabberAccount*> 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<HANDLE, contact_data> 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("<GPGdec>"));
+ inclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", _T("</GPGdec>"));
+ outopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", _T("<GPGenc>"));
+ outclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", _T("</GPGenc>"));
+ 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<wstring> 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<wstring>::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<<toUTF8(buf);
- log.close();
- log_mutex.unlock();
- }
- return *this;
-}
-logtofile& logtofile::operator<<(char *buf)
-{
- extern bool bDebugLog;
- if(bDebugLog)
- {
- log_mutex.lock();
- log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate);
- log<<buf;
- log.close();
- log_mutex.unlock();
- }
- return *this;
-}
-logtofile& logtofile::operator<<(string buf)
-{
- extern bool bDebugLog;
- if(bDebugLog)
- {
- log_mutex.lock();
- char *tmp = mir_utf8encode(buf.c_str());
- log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate);
- log<<tmp;
- log.close();
- log_mutex.unlock();
- mir_free(tmp);
- }
- return *this;
-}
-logtofile& logtofile::operator<<(wstring buf)
-{
- extern bool bDebugLog;
- if(bDebugLog)
- {
- log_mutex.lock();
- log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate);
- log<<toUTF8(buf);
- log.close();
- log_mutex.unlock();
- }
- return *this;
-}
-void logtofile::init()
-{
- extern bool bDebugLog;
- if(bDebugLog)
- {
- if(path)
- mir_free(path);
- path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", _T("C:\\GPGdebug.log"));
- }
-}
-logtofile::logtofile()
-{
- path = NULL;
-}
-logtofile::~logtofile()
-{
- mir_free(path);
-}
+// 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<<toUTF8(buf);
+ log.close();
+ log_mutex.unlock();
+ }
+ return *this;
+}
+logtofile& logtofile::operator<<(char *buf)
+{
+ extern bool bDebugLog;
+ if(bDebugLog)
+ {
+ log_mutex.lock();
+ log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate);
+ log<<buf;
+ log.close();
+ log_mutex.unlock();
+ }
+ return *this;
+}
+logtofile& logtofile::operator<<(string buf)
+{
+ extern bool bDebugLog;
+ if(bDebugLog)
+ {
+ log_mutex.lock();
+ char *tmp = mir_utf8encode(buf.c_str());
+ log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate);
+ log<<tmp;
+ log.close();
+ log_mutex.unlock();
+ mir_free(tmp);
+ }
+ return *this;
+}
+logtofile& logtofile::operator<<(wstring buf)
+{
+ extern bool bDebugLog;
+ if(bDebugLog)
+ {
+ log_mutex.lock();
+ log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate);
+ log<<toUTF8(buf);
+ log.close();
+ log_mutex.unlock();
+ }
+ return *this;
+}
+void logtofile::init()
+{
+ extern bool bDebugLog;
+ if(bDebugLog)
+ {
+ if(path)
+ mir_free(path);
+ path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", _T("C:\\GPGdebug.log"));
+ }
+}
+logtofile::logtofile()
+{
+ path = NULL;
+}
+logtofile::~logtofile()
+{
+ mir_free(path);
+}
diff --git a/log.h b/log.h
index 64a8ad4..2acf09d 100644
--- a/log.h
+++ b/log.h
@@ -32,4 +32,4 @@ private:
boost::mutex log_mutex;
};
-#endif
+#endif
diff --git a/m_extraicons.h b/m_extraicons.h
index 54270fe..589d040 100644
--- a/m_extraicons.h
+++ b/m_extraicons.h
@@ -1,158 +1,158 @@
-/*
- Copyright (C) 2009 Ricardo Pescuma Domenecci
-
- This is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this file; see the file license.txt. If
- not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-#ifndef __M_EXTRAICONS_H__
-#define __M_EXTRAICONS_H__
-
-#define MIID_EXTRAICONSSERVICE { 0x62d80749, 0xf169, 0x4592, { 0xb4, 0x4d, 0x3d, 0xd6, 0xde, 0x9d, 0x50, 0xc5 } }
-
-
-#define EXTRAICON_TYPE_CALLBACK 0 // Similar to old clist callbacks, it fires 2 notifications
-#define EXTRAICON_TYPE_ICOLIB 1 // This extra icon will use only icons registered with icolib. No callbacks
- // needed. Just call MS_EXTRAICON_SET_ICON passing the name of the extraicon to set one.
-
-
-typedef struct {
- int cbSize;
- int type; // One of EXTRAICON_TYPE_*
- const char *name; // Internal name. More than one plugin can register extra icons with the same name
- // if both have the same type. In this case, both will be handled as one.
- // This is usefull for ex for extra status, where icq and jabber can share the same slot.
- // If the types are different the second one will be denied.
- const char *description; // [Translated by plugin] Description to be used in GUI
- const char *descIcon; // [Optional] Name of an icon registered with icolib to be used in GUI.
-
- // If type == EXTRAICON_TYPE_CALLBACK this two must be set
-
- // Callback to add icons to clist, calling MS_CLIST_EXTRA_ADD_ICON
- // wParam=lParam=0
- MIRANDAHOOK RebuildIcons;
-
- // Callback to set the icon to clist, calling MS_CLIST_EXTRA_SET_ICON or MS_EXTRAICON_SET_ICON
- // wParam = HANDLE hContact
- // lParam = int slot
- MIRANDAHOOK ApplyIcon;
-
- // Other optional callbacks
-
- // [Optional] Callback called when extra icon was clicked
- // wParam = HANDLE hContact
- // lParam = int slot
- // param = onClickParam
- MIRANDAHOOKPARAM OnClick;
-
- LPARAM onClickParam;
-
-} EXTRAICON_INFO;
-
-
-// Register an extra icon
-// wParam = (EXTRAICON_INFO *) Extra icon info
-// lParam = 0
-// Return: (HANDLE) id of extra icon on success, 0 on error
-#define MS_EXTRAICON_REGISTER "ExtraIcon/Register"
-
-
-typedef struct {
- int cbSize;
- HANDLE hExtraIcon; // Value returned by MS_EXTRAICON_REGISTER
- HANDLE hContact; // Contact to set the extra icon
- union { // The icon to be set. This depends on the type of the extra icon:
- HANDLE hImage; // Value returned by MS_CLIST_EXTRA_ADD_ICON (if EXTRAICON_TYPE_CALLBACK)
- const char *icoName; // Name of the icon registered with icolib (if EXTRAICON_TYPE_ICOLIB)
- };
-} EXTRAICON;
-
-// Set an extra icon icon
-// wParam = (EXTRAICON *) Extra icon
-// Return: 0 on success
-#define MS_EXTRAICON_SET_ICON "ExtraIcon/SetIcon"
-
-
-
-#ifndef _NO_WRAPPERS
-#ifdef __cplusplus
-
-static HANDLE ExtraIcon_Register(const char *name, const char *description, const char *descIcon,
- MIRANDAHOOK RebuildIcons,
- MIRANDAHOOK ApplyIcon,
- MIRANDAHOOKPARAM OnClick = NULL, LPARAM onClickParam = NULL)
-{
- if (!ServiceExists(MS_EXTRAICON_REGISTER))
- return NULL;
-
- EXTRAICON_INFO ei = {0};
- ei.cbSize = sizeof(ei);
- ei.type = EXTRAICON_TYPE_CALLBACK;
- ei.name = name;
- ei.description = description;
- ei.descIcon = descIcon;
- ei.RebuildIcons = RebuildIcons;
- ei.ApplyIcon = ApplyIcon;
- ei.OnClick = OnClick;
- ei.onClickParam = onClickParam;
-
- return (HANDLE) CallService(MS_EXTRAICON_REGISTER, (WPARAM) &ei, 0);
-}
-
-static HANDLE ExtraIcon_Register(const char *name, const char *description, const char *descIcon = NULL,
- MIRANDAHOOKPARAM OnClick = NULL, LPARAM onClickParam = NULL)
-{
- if (!ServiceExists(MS_EXTRAICON_REGISTER))
- return NULL;
-
- EXTRAICON_INFO ei = {0};
- ei.cbSize = sizeof(ei);
- ei.type = EXTRAICON_TYPE_ICOLIB;
- ei.name = name;
- ei.description = description;
- ei.descIcon = descIcon;
- ei.OnClick = OnClick;
- ei.onClickParam = onClickParam;
-
- return (HANDLE) CallService(MS_EXTRAICON_REGISTER, (WPARAM) &ei, 0);
-}
-
-static int ExtraIcon_SetIcon(HANDLE hExtraIcon, HANDLE hContact, HANDLE hImage)
-{
- EXTRAICON ei = {0};
- ei.cbSize = sizeof(ei);
- ei.hExtraIcon = hExtraIcon;
- ei.hContact = hContact;
- ei.hImage = hImage;
-
- return CallService(MS_EXTRAICON_SET_ICON, (WPARAM) &ei, 0);
-}
-
-static int ExtraIcon_SetIcon(HANDLE hExtraIcon, HANDLE hContact, const char *icoName)
-{
- EXTRAICON ei = {0};
- ei.cbSize = sizeof(ei);
- ei.hExtraIcon = hExtraIcon;
- ei.hContact = hContact;
- ei.icoName = icoName;
-
- return CallService(MS_EXTRAICON_SET_ICON, (WPARAM) &ei, 0);
-}
-
-#endif
-#endif
-
-
-#endif // __M_EXTRAICONS_H__
+/*
+ Copyright (C) 2009 Ricardo Pescuma Domenecci
+
+ This is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this file; see the file license.txt. If
+ not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __M_EXTRAICONS_H__
+#define __M_EXTRAICONS_H__
+
+#define MIID_EXTRAICONSSERVICE { 0x62d80749, 0xf169, 0x4592, { 0xb4, 0x4d, 0x3d, 0xd6, 0xde, 0x9d, 0x50, 0xc5 } }
+
+
+#define EXTRAICON_TYPE_CALLBACK 0 // Similar to old clist callbacks, it fires 2 notifications
+#define EXTRAICON_TYPE_ICOLIB 1 // This extra icon will use only icons registered with icolib. No callbacks
+ // needed. Just call MS_EXTRAICON_SET_ICON passing the name of the extraicon to set one.
+
+
+typedef struct {
+ int cbSize;
+ int type; // One of EXTRAICON_TYPE_*
+ const char *name; // Internal name. More than one plugin can register extra icons with the same name
+ // if both have the same type. In this case, both will be handled as one.
+ // This is usefull for ex for extra status, where icq and jabber can share the same slot.
+ // If the types are different the second one will be denied.
+ const char *description; // [Translated by plugin] Description to be used in GUI
+ const char *descIcon; // [Optional] Name of an icon registered with icolib to be used in GUI.
+
+ // If type == EXTRAICON_TYPE_CALLBACK this two must be set
+
+ // Callback to add icons to clist, calling MS_CLIST_EXTRA_ADD_ICON
+ // wParam=lParam=0
+ MIRANDAHOOK RebuildIcons;
+
+ // Callback to set the icon to clist, calling MS_CLIST_EXTRA_SET_ICON or MS_EXTRAICON_SET_ICON
+ // wParam = HANDLE hContact
+ // lParam = int slot
+ MIRANDAHOOK ApplyIcon;
+
+ // Other optional callbacks
+
+ // [Optional] Callback called when extra icon was clicked
+ // wParam = HANDLE hContact
+ // lParam = int slot
+ // param = onClickParam
+ MIRANDAHOOKPARAM OnClick;
+
+ LPARAM onClickParam;
+
+} EXTRAICON_INFO;
+
+
+// Register an extra icon
+// wParam = (EXTRAICON_INFO *) Extra icon info
+// lParam = 0
+// Return: (HANDLE) id of extra icon on success, 0 on error
+#define MS_EXTRAICON_REGISTER "ExtraIcon/Register"
+
+
+typedef struct {
+ int cbSize;
+ HANDLE hExtraIcon; // Value returned by MS_EXTRAICON_REGISTER
+ HANDLE hContact; // Contact to set the extra icon
+ union { // The icon to be set. This depends on the type of the extra icon:
+ HANDLE hImage; // Value returned by MS_CLIST_EXTRA_ADD_ICON (if EXTRAICON_TYPE_CALLBACK)
+ const char *icoName; // Name of the icon registered with icolib (if EXTRAICON_TYPE_ICOLIB)
+ };
+} EXTRAICON;
+
+// Set an extra icon icon
+// wParam = (EXTRAICON *) Extra icon
+// Return: 0 on success
+#define MS_EXTRAICON_SET_ICON "ExtraIcon/SetIcon"
+
+
+
+#ifndef _NO_WRAPPERS
+#ifdef __cplusplus
+
+static HANDLE ExtraIcon_Register(const char *name, const char *description, const char *descIcon,
+ MIRANDAHOOK RebuildIcons,
+ MIRANDAHOOK ApplyIcon,
+ MIRANDAHOOKPARAM OnClick = NULL, LPARAM onClickParam = NULL)
+{
+ if (!ServiceExists(MS_EXTRAICON_REGISTER))
+ return NULL;
+
+ EXTRAICON_INFO ei = {0};
+ ei.cbSize = sizeof(ei);
+ ei.type = EXTRAICON_TYPE_CALLBACK;
+ ei.name = name;
+ ei.description = description;
+ ei.descIcon = descIcon;
+ ei.RebuildIcons = RebuildIcons;
+ ei.ApplyIcon = ApplyIcon;
+ ei.OnClick = OnClick;
+ ei.onClickParam = onClickParam;
+
+ return (HANDLE) CallService(MS_EXTRAICON_REGISTER, (WPARAM) &ei, 0);
+}
+
+static HANDLE ExtraIcon_Register(const char *name, const char *description, const char *descIcon = NULL,
+ MIRANDAHOOKPARAM OnClick = NULL, LPARAM onClickParam = NULL)
+{
+ if (!ServiceExists(MS_EXTRAICON_REGISTER))
+ return NULL;
+
+ EXTRAICON_INFO ei = {0};
+ ei.cbSize = sizeof(ei);
+ ei.type = EXTRAICON_TYPE_ICOLIB;
+ ei.name = name;
+ ei.description = description;
+ ei.descIcon = descIcon;
+ ei.OnClick = OnClick;
+ ei.onClickParam = onClickParam;
+
+ return (HANDLE) CallService(MS_EXTRAICON_REGISTER, (WPARAM) &ei, 0);
+}
+
+static int ExtraIcon_SetIcon(HANDLE hExtraIcon, HANDLE hContact, HANDLE hImage)
+{
+ EXTRAICON ei = {0};
+ ei.cbSize = sizeof(ei);
+ ei.hExtraIcon = hExtraIcon;
+ ei.hContact = hContact;
+ ei.hImage = hImage;
+
+ return CallService(MS_EXTRAICON_SET_ICON, (WPARAM) &ei, 0);
+}
+
+static int ExtraIcon_SetIcon(HANDLE hExtraIcon, HANDLE hContact, const char *icoName)
+{
+ EXTRAICON ei = {0};
+ ei.cbSize = sizeof(ei);
+ ei.hExtraIcon = hExtraIcon;
+ ei.hContact = hContact;
+ ei.icoName = icoName;
+
+ return CallService(MS_EXTRAICON_SET_ICON, (WPARAM) &ei, 0);
+}
+
+#endif
+#endif
+
+
+#endif // __M_EXTRAICONS_H__
diff --git a/m_metacontacts.h b/m_metacontacts.h
index b4f63ea..9f348bd 100644
--- a/m_metacontacts.h
+++ b/m_metacontacts.h
@@ -1,166 +1,166 @@
-/*
-
-Miranda IM: the free IM client for Microsoft* Windows*
-
-Copyright © 2004 Universite Louis PASTEUR, STRASBOURG.
-Copyright © 2004 Scott Ellis (www.scottellis.com.au mail@scottellis.com.au)
-
-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 M_METACONTACTS_H__
-#define M_METACONTACTS_H__ 1
-
-#ifndef MIID_METACONTACTS
-#define MIID_METACONTACTS {0xc0325019, 0xc1a7, 0x40f5, { 0x83, 0x65, 0x4f, 0x46, 0xbe, 0x21, 0x86, 0x3e}}
-#endif
-
-//get the handle for a contact's parent metacontact
-//wParam=(HANDLE)hSubContact
-//lParam=0
-//returns a handle to the parent metacontact, or null if this contact is not a subcontact
-#define MS_MC_GETMETACONTACT "MetaContacts/GetMeta"
-
-//gets the handle for the default contact
-//wParam=(HANDLE)hMetaContact
-//lParam=0
-//returns a handle to the default contact, or null on failure
-#define MS_MC_GETDEFAULTCONTACT "MetaContacts/GetDefault"
-
-//gets the contact number for the default contact
-//wParam=(HANDLE)hMetaContact
-//lParam=0
-//returns a DWORD contact number, or -1 on failure
-#define MS_MC_GETDEFAULTCONTACTNUM "MetaContacts/GetDefaultNum"
-
-//gets the handle for the 'most online' contact
-//wParam=(HANDLE)hMetaContact
-//lParam=0
-//returns a handle to the 'most online' contact
-#define MS_MC_GETMOSTONLINECONTACT "MetaContacts/GetMostOnline"
-
-//gets the number of subcontacts for a metacontact
-//wParam=(HANDLE)hMetaContact
-//lParam=0
-//returns a DWORD representing the number of subcontacts for the given metacontact
-#define MS_MC_GETNUMCONTACTS "MetaContacts/GetNumContacts"
-
-//gets the handle of a subcontact, using the subcontact's number
-//wParam=(HANDLE)hMetaContact
-//lParam=(DWORD)contact number
-//returns a handle to the specified subcontact
-#define MS_MC_GETSUBCONTACT "MetaContacts/GetSubContact"
-
-//sets the default contact, using the subcontact's contact number
-//wParam=(HANDLE)hMetaContact
-//lParam=(DWORD)contact number
-//returns 0 on success
-#define MS_MC_SETDEFAULTCONTACTNUM "MetaContacts/SetDefault"
-
-//sets the default contact, using the subcontact's handle
-//wParam=(HANDLE)hMetaContact
-//lParam=(HANDLE)hSubcontact
-//returns 0 on success
-#define MS_MC_SETDEFAULTCONTACT "MetaContacts/SetDefaultByHandle"
-
-//forces the metacontact to send using a specific subcontact, using the subcontact's contact number
-//wParam=(HANDLE)hMetaContact
-//lParam=(DWORD)contact number
-//returns 0 on success
-#define MS_MC_FORCESENDCONTACTNUM "MetaContacts/ForceSendContact"
-
-//forces the metacontact to send using a specific subcontact, using the subcontact's handle
-//wParam=(HANDLE)hMetaContact
-//lParam=(HANDLE)hSubcontact
-//returns 0 on success (will fail if 'force default' is in effect)
-#define MS_MC_FORCESENDCONTACT "MetaContacts/ForceSendContactByHandle"
-
-//'unforces' the metacontact to send using a specific subcontact
-//wParam=(HANDLE)hMetaContact
-//lParam=0
-//returns 0 on success (will fail if 'force default' is in effect)
-#define MS_MC_UNFORCESENDCONTACT "MetaContacts/UnforceSendContact"
-
-//'forces' or 'unforces' (i.e. toggles) the metacontact to send using it's default contact
-// overrides (and clears) 'force send' above, and will even force use of offline contacts
-// will send ME_MC_FORCESEND or ME_MC_UNFORCESEND event
-//wParam=(HANDLE)hMetaContact
-//lParam=0
-//returns 1(true) or 0(false) representing new state of 'force default'
-#define MS_MC_FORCEDEFAULT "MetaContacts/ForceSendDefault"
-
-// method to get state of 'force' for a metacontact
-// wParam=(HANDLE)hMetaContact
-// lParam= (DWORD)&contact_number or NULL
-//
-// if lparam supplied, the contact_number of the contatct 'in force' will be copied to the address it points to,
-// or if none is in force, the value (DWORD)-1 will be copied
-// (v0.8.0.8+ returns 1 if 'force default' is true with *lParam == default contact number, else returns 0 with *lParam as above)
-#define MS_MC_GETFORCESTATE "MetaContacts/GetForceState"
-
-// fired when a metacontact's default contact changes (fired upon creation of metacontact also, when default is initially set)
-// wParam=(HANDLE)hMetaContact
-// lParam=(HANDLE)hDefaultContact
-#define ME_MC_DEFAULTTCHANGED "MetaContacts/DefaultChanged"
-
-// fired when a metacontact's subcontacts change (fired upon creation of metacontact, when contacts are added or removed, and when
-// contacts are reordered) - a signal to re-read metacontact data
-// wParam=(HANDLE)hMetaContact
-// lParam=0
-#define ME_MC_SUBCONTACTSCHANGED "MetaContacts/SubcontactsChanged"
-
-// fired when a metacontact is forced to send using a specific subcontact
-// wParam=(HANDLE)hMetaContact
-// lParam=(HANDLE)hForceContact
-#define ME_MC_FORCESEND "MetaContacts/ForceSend"
-
-// fired when a metacontact is 'unforced' to send using a specific subcontact
-// wParam=(HANDLE)hMetaContact
-// lParam=0
-#define ME_MC_UNFORCESEND "MetaContacts/UnforceSend"
-
-// method to get protocol name - used to be sure you're dealing with a "real" metacontacts plugin :)
-// wParam=lParam=0
-#define MS_MC_GETPROTOCOLNAME "MetaContacts/GetProtoName"
-
-
-// added 0.9.5.0 (22/3/05)
-// wParam=(HANDLE)hContact
-// lParam=0
-// convert a given contact into a metacontact
-#define MS_MC_CONVERTTOMETA "MetaContacts/ConvertToMetacontact"
-
-// added 0.9.5.0 (22/3/05)
-// wParam=(HANDLE)hContact
-// lParam=(HANDLE)hMeta
-// add an existing contact to a metacontact
-#define MS_MC_ADDTOMETA "MetaContacts/AddToMetacontact"
-
-// added 0.9.5.0 (22/3/05)
-// wParam=0
-// lParam=(HANDLE)hContact
-// remove a contact from a metacontact
-#define MS_MC_REMOVEFROMMETA "MetaContacts/RemoveFromMetacontact"
-
-
-// added 0.9.13.2 (6/10/05)
-// wParam=(BOOL)disable
-// lParam=0
-// enable/disable the 'hidden group hack' - for clists that support subcontact hiding using 'IsSubcontact' setting
-// should be called once in the clist 'onmodulesloaded' event handler (which, since it's loaded after the db, will be called
-// before the metacontact onmodulesloaded handler where the subcontact hiding is usually done)
-#define MS_MC_DISABLEHIDDENGROUP "MetaContacts/DisableHiddenGroup"
-
-#endif
+/*
+
+Miranda IM: the free IM client for Microsoft* Windows*
+
+Copyright © 2004 Universite Louis PASTEUR, STRASBOURG.
+Copyright © 2004 Scott Ellis (www.scottellis.com.au mail@scottellis.com.au)
+
+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 M_METACONTACTS_H__
+#define M_METACONTACTS_H__ 1
+
+#ifndef MIID_METACONTACTS
+#define MIID_METACONTACTS {0xc0325019, 0xc1a7, 0x40f5, { 0x83, 0x65, 0x4f, 0x46, 0xbe, 0x21, 0x86, 0x3e}}
+#endif
+
+//get the handle for a contact's parent metacontact
+//wParam=(HANDLE)hSubContact
+//lParam=0
+//returns a handle to the parent metacontact, or null if this contact is not a subcontact
+#define MS_MC_GETMETACONTACT "MetaContacts/GetMeta"
+
+//gets the handle for the default contact
+//wParam=(HANDLE)hMetaContact
+//lParam=0
+//returns a handle to the default contact, or null on failure
+#define MS_MC_GETDEFAULTCONTACT "MetaContacts/GetDefault"
+
+//gets the contact number for the default contact
+//wParam=(HANDLE)hMetaContact
+//lParam=0
+//returns a DWORD contact number, or -1 on failure
+#define MS_MC_GETDEFAULTCONTACTNUM "MetaContacts/GetDefaultNum"
+
+//gets the handle for the 'most online' contact
+//wParam=(HANDLE)hMetaContact
+//lParam=0
+//returns a handle to the 'most online' contact
+#define MS_MC_GETMOSTONLINECONTACT "MetaContacts/GetMostOnline"
+
+//gets the number of subcontacts for a metacontact
+//wParam=(HANDLE)hMetaContact
+//lParam=0
+//returns a DWORD representing the number of subcontacts for the given metacontact
+#define MS_MC_GETNUMCONTACTS "MetaContacts/GetNumContacts"
+
+//gets the handle of a subcontact, using the subcontact's number
+//wParam=(HANDLE)hMetaContact
+//lParam=(DWORD)contact number
+//returns a handle to the specified subcontact
+#define MS_MC_GETSUBCONTACT "MetaContacts/GetSubContact"
+
+//sets the default contact, using the subcontact's contact number
+//wParam=(HANDLE)hMetaContact
+//lParam=(DWORD)contact number
+//returns 0 on success
+#define MS_MC_SETDEFAULTCONTACTNUM "MetaContacts/SetDefault"
+
+//sets the default contact, using the subcontact's handle
+//wParam=(HANDLE)hMetaContact
+//lParam=(HANDLE)hSubcontact
+//returns 0 on success
+#define MS_MC_SETDEFAULTCONTACT "MetaContacts/SetDefaultByHandle"
+
+//forces the metacontact to send using a specific subcontact, using the subcontact's contact number
+//wParam=(HANDLE)hMetaContact
+//lParam=(DWORD)contact number
+//returns 0 on success
+#define MS_MC_FORCESENDCONTACTNUM "MetaContacts/ForceSendContact"
+
+//forces the metacontact to send using a specific subcontact, using the subcontact's handle
+//wParam=(HANDLE)hMetaContact
+//lParam=(HANDLE)hSubcontact
+//returns 0 on success (will fail if 'force default' is in effect)
+#define MS_MC_FORCESENDCONTACT "MetaContacts/ForceSendContactByHandle"
+
+//'unforces' the metacontact to send using a specific subcontact
+//wParam=(HANDLE)hMetaContact
+//lParam=0
+//returns 0 on success (will fail if 'force default' is in effect)
+#define MS_MC_UNFORCESENDCONTACT "MetaContacts/UnforceSendContact"
+
+//'forces' or 'unforces' (i.e. toggles) the metacontact to send using it's default contact
+// overrides (and clears) 'force send' above, and will even force use of offline contacts
+// will send ME_MC_FORCESEND or ME_MC_UNFORCESEND event
+//wParam=(HANDLE)hMetaContact
+//lParam=0
+//returns 1(true) or 0(false) representing new state of 'force default'
+#define MS_MC_FORCEDEFAULT "MetaContacts/ForceSendDefault"
+
+// method to get state of 'force' for a metacontact
+// wParam=(HANDLE)hMetaContact
+// lParam= (DWORD)&contact_number or NULL
+//
+// if lparam supplied, the contact_number of the contatct 'in force' will be copied to the address it points to,
+// or if none is in force, the value (DWORD)-1 will be copied
+// (v0.8.0.8+ returns 1 if 'force default' is true with *lParam == default contact number, else returns 0 with *lParam as above)
+#define MS_MC_GETFORCESTATE "MetaContacts/GetForceState"
+
+// fired when a metacontact's default contact changes (fired upon creation of metacontact also, when default is initially set)
+// wParam=(HANDLE)hMetaContact
+// lParam=(HANDLE)hDefaultContact
+#define ME_MC_DEFAULTTCHANGED "MetaContacts/DefaultChanged"
+
+// fired when a metacontact's subcontacts change (fired upon creation of metacontact, when contacts are added or removed, and when
+// contacts are reordered) - a signal to re-read metacontact data
+// wParam=(HANDLE)hMetaContact
+// lParam=0
+#define ME_MC_SUBCONTACTSCHANGED "MetaContacts/SubcontactsChanged"
+
+// fired when a metacontact is forced to send using a specific subcontact
+// wParam=(HANDLE)hMetaContact
+// lParam=(HANDLE)hForceContact
+#define ME_MC_FORCESEND "MetaContacts/ForceSend"
+
+// fired when a metacontact is 'unforced' to send using a specific subcontact
+// wParam=(HANDLE)hMetaContact
+// lParam=0
+#define ME_MC_UNFORCESEND "MetaContacts/UnforceSend"
+
+// method to get protocol name - used to be sure you're dealing with a "real" metacontacts plugin :)
+// wParam=lParam=0
+#define MS_MC_GETPROTOCOLNAME "MetaContacts/GetProtoName"
+
+
+// added 0.9.5.0 (22/3/05)
+// wParam=(HANDLE)hContact
+// lParam=0
+// convert a given contact into a metacontact
+#define MS_MC_CONVERTTOMETA "MetaContacts/ConvertToMetacontact"
+
+// added 0.9.5.0 (22/3/05)
+// wParam=(HANDLE)hContact
+// lParam=(HANDLE)hMeta
+// add an existing contact to a metacontact
+#define MS_MC_ADDTOMETA "MetaContacts/AddToMetacontact"
+
+// added 0.9.5.0 (22/3/05)
+// wParam=0
+// lParam=(HANDLE)hContact
+// remove a contact from a metacontact
+#define MS_MC_REMOVEFROMMETA "MetaContacts/RemoveFromMetacontact"
+
+
+// added 0.9.13.2 (6/10/05)
+// wParam=(BOOL)disable
+// lParam=0
+// enable/disable the 'hidden group hack' - for clists that support subcontact hiding using 'IsSubcontact' setting
+// should be called once in the clist 'onmodulesloaded' event handler (which, since it's loaded after the db, will be called
+// before the metacontact onmodulesloaded handler where the subcontact hiding is usually done)
+#define MS_MC_DISABLEHIDDENGROUP "MetaContacts/DisableHiddenGroup"
+
+#endif
diff --git a/main.cpp b/main.cpp
index eca2698..9af1f5d 100644
--- a/main.cpp
+++ b/main.cpp
@@ -723,15 +723,15 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
MessageBox(0, _T("please set keyring's home directory"), _T("Warning"), MB_OK);
break;
}
- DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", tmp);
- {
- TCHAR *path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
- DWORD dwFileAttr = GetFileAttributes(path);
- if (dwFileAttr != INVALID_FILE_ATTRIBUTES)
- {
- dwFileAttr &=~ FILE_ATTRIBUTE_READONLY;
- SetFileAttributes(path, dwFileAttr);
- }
+ DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", tmp);
+ {
+ TCHAR *path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
+ DWORD dwFileAttr = GetFileAttributes(path);
+ if (dwFileAttr != INVALID_FILE_ATTRIBUTES)
+ {
+ dwFileAttr &=~ FILE_ATTRIBUTE_READONLY;
+ SetFileAttributes(path, dwFileAttr);
+ }
mir_free(path);
}
gpg_configured = true;
@@ -806,15 +806,15 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
{
MessageBox(0, _T("please set keyring's home directory"), _T("Warning"), MB_OK);
break;
- }
- DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", tmp);
- {
- TCHAR *path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
- DWORD dwFileAttr = GetFileAttributes(path);
- if (dwFileAttr != INVALID_FILE_ATTRIBUTES)
- {
- dwFileAttr &=~ FILE_ATTRIBUTE_READONLY;
- SetFileAttributes(path, dwFileAttr);
+ }
+ DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", tmp);
+ {
+ TCHAR *path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
+ DWORD dwFileAttr = GetFileAttributes(path);
+ if (dwFileAttr != INVALID_FILE_ATTRIBUTES)
+ {
+ dwFileAttr &=~ FILE_ATTRIBUTE_READONLY;
+ SetFileAttributes(path, dwFileAttr);
}
mir_free(path);
}
@@ -1144,6 +1144,9 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam,
delete [] tmp;
f<<length;
f<<"\n";
+ f<<"Subkey-Length: ";
+ f<<length;
+ f<<"\n";
f<<"Subkey-Type: ";
f<<subkeytype;
delete [] subkeytype;
@@ -1730,12 +1733,12 @@ void InitCheck()
if(MessageBoxA(0, question.c_str(), "Own secret key warning", MB_YESNO) == IDYES)
ShowFirstRunDialog();
}
- {
- TCHAR *path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
- DWORD dwFileAttr = GetFileAttributes(path);
- if (dwFileAttr != INVALID_FILE_ATTRIBUTES)
- {
- dwFileAttr &=~ FILE_ATTRIBUTE_READONLY;
+ {
+ TCHAR *path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
+ DWORD dwFileAttr = GetFileAttributes(path);
+ if (dwFileAttr != INVALID_FILE_ATTRIBUTES)
+ {
+ dwFileAttr &=~ FILE_ATTRIBUTE_READONLY;
SetFileAttributes(path, dwFileAttr);
}
mir_free(path);
diff --git a/main.h b/main.h
index 5b98750..102821c 100644
--- a/main.h
+++ b/main.h
@@ -1,31 +1,31 @@
-// 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<string> msgs_to_tag, msgs_to_ignore, msgs_to_send;
- string key_in_prescense;
-};
-
-extern std::map<HANDLE, contact_data> hcontact_data;
-extern bool bAutoExchange;
-extern RECT key_from_keyserver_rect, firstrun_rect, new_key_rect, key_gen_rect, load_key_rect, import_key_rect, key_password_rect, load_existing_key_rect;
-
-#endif
-
-
+// Copyright © 2010 sss
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#ifndef MAIN_H
+#define MAIN_H
+
+struct contact_data
+{
+ list<string> msgs_to_tag, msgs_to_ignore, msgs_to_send;
+ string key_in_prescense;
+};
+
+extern std::map<HANDLE, contact_data> hcontact_data;
+extern bool bAutoExchange;
+extern RECT key_from_keyserver_rect, firstrun_rect, new_key_rect, key_gen_rect, load_key_rect, import_key_rect, key_password_rect, load_existing_key_rect;
+
+#endif
+
+
diff --git a/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<<new_key.c_str();
- f.close();
- cmd += _T(" --batch ");
- cmd += _T(" --import \"");
- cmd += tmp2;
- cmd += _T("\"");
- }
- 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, &params));
- if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
- {
- gpg_thread.~thread();
- debuglog<<time_str()<<": GPG execution timed out, aborted\n";
- return 1;
- }
- if(result == pxNotFound)
- return 1;
- {
- char *tmp = NULL;
- string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
- string::size_type s2 = output.find(":", s);
- DBWriteContactSettingString(hContact, szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str());
- s2+=2;
- s = output.find("“", s2);
- if(s == string::npos)
- {
- s = output.find("\"", s2);
- s += 1;
- }
- else
- s += 3;
- if((s2 = output.find("(", s)) == string::npos)
- s2 = output.find("<", s);
- else if(s2 > output.find("<", s))
- s2 = output.find("<", s);
- tmp = new char [output.substr(s,s2-s-1).length()+1];
- strcpy(tmp, output.substr(s,s2-s-1).c_str());
- mir_utf8decode(tmp, 0);
- DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", tmp);
- mir_free(tmp);
- if((s = output.find(")", s2)) == string::npos)
- s = output.find(">", s2);
- else if(s > output.find(">", s2))
- s = output.find(">", s2);
- s2++;
- if(output[s] == ')')
- {
- tmp = new char [output.substr(s2,s-s2).length()+1];
- strcpy(tmp, output.substr(s2,s-s2).c_str());
- mir_utf8decode(tmp, 0);
- DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", tmp);
- mir_free(tmp);
- s+=3;
- s2 = output.find(">", s);
- tmp = new char [output.substr(s,s2-s).length()+1];
- strcpy(tmp, output.substr(s,s2-s).c_str());
- mir_utf8decode(tmp, 0);
- DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", tmp);
- mir_free(tmp);
- }
- else
- {
- tmp = new char [output.substr(s2,s-s2).length()+1];
- strcpy(tmp, output.substr(s2,s-s2).c_str());
- mir_utf8decode(tmp, 0);
- DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str());
- mir_free(tmp);
- }
+ 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<<new_key.c_str();
+ f.close();
+ cmd += _T(" --batch ");
+ cmd += _T(" --import \"");
+ cmd += tmp2;
+ cmd += _T("\"");
+ }
+ 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, &params));
+ if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
+ {
+ gpg_thread.~thread();
+ debuglog<<time_str()<<": GPG execution timed out, aborted\n";
+ return 1;
+ }
+ if(result == pxNotFound)
+ return 1;
+ {
+ char *tmp = NULL;
+ string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
+ string::size_type s2 = output.find(":", s);
+ DBWriteContactSettingString(hContact, szGPGModuleName, "KeyID", output.substr(s,s2-s).c_str());
+ s2+=2;
+ s = output.find("“", s2);
+ if(s == string::npos)
+ {
+ s = output.find("\"", s2);
+ s += 1;
+ }
+ else
+ s += 3;
+ if((s2 = output.find("(", s)) == string::npos)
+ s2 = output.find("<", s);
+ else if(s2 > output.find("<", s))
+ s2 = output.find("<", s);
+ tmp = new char [output.substr(s,s2-s-1).length()+1];
+ strcpy(tmp, output.substr(s,s2-s-1).c_str());
+ mir_utf8decode(tmp, 0);
+ DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", tmp);
+ mir_free(tmp);
+ if((s = output.find(")", s2)) == string::npos)
+ s = output.find(">", s2);
+ else if(s > output.find(">", s2))
+ s = output.find(">", s2);
+ s2++;
+ if(output[s] == ')')
+ {
+ tmp = new char [output.substr(s2,s-s2).length()+1];
+ strcpy(tmp, output.substr(s2,s-s2).c_str());
+ mir_utf8decode(tmp, 0);
+ DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", tmp);
+ mir_free(tmp);
+ s+=3;
+ s2 = output.find(">", s);
+ tmp = new char [output.substr(s,s2-s).length()+1];
+ strcpy(tmp, output.substr(s,s2-s).c_str());
+ mir_utf8decode(tmp, 0);
+ DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", tmp);
+ mir_free(tmp);
+ }
+ else
+ {
+ tmp = new char [output.substr(s2,s-s2).length()+1];
+ strcpy(tmp, output.substr(s2,s-s2).c_str());
+ mir_utf8decode(tmp, 0);
+ DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str());
+ mir_free(tmp);
+ }
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 <JabberAccount*> Accounts;
- list<JabberAccount*>::iterator end = Accounts.end();
- for(list<JabberAccount*>::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 <JabberAccount*> Accounts;
+ list<JabberAccount*>::iterator end = Accounts.end();
+ for(list<JabberAccount*>::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 <JabberAccount*> Accounts;
- list<JabberAccount*>::iterator end = Accounts.end();
- for(list<JabberAccount*>::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 <JabberAccount*> Accounts;
+ list<JabberAccount*>::iterator end = Accounts.end();
+ for(list<JabberAccount*>::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<int, HANDLE> 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, &params));
- if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
- {
- gpg_thread.~thread();
- debuglog<<time_str()<<": GPG execution timed out, aborted\n";
- mir_free(tmp);
- break;
- }
- if(result == pxNotFound)
- {
- mir_free(tmp);
- break;
- }
- if(output.find("--delete-secret-keys") != string::npos)
- MessageBoxA(0, "we have secret key for this public key, do not removing from GPG keyring", "info", MB_OK);
- else
- MessageBoxA(0, "Key removed from GPG keyring", "info", MB_OK);
- }
- mir_free(tmp);
- if(ismetacontact)
- {
- if(MessageBox(0, _T("Do you want to remove key from entire metacontact (all subcontacts) ?"), _T("Metacontact detected"), MB_YESNO) == IDYES)
- {
- HANDLE hcnt = NULL;
- int count = metaGetContactsNum(meta);
- for(int i = 0; i < count; i++)
- {
- hcnt = metaGetSubcontact(meta, i);
- if(hcnt)
- {
- DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyID");
- DBDeleteContactSetting(hcnt, szGPGModuleName, "GPGPubKey");
- DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyMainName");
- DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyType");
- DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyMainEmail");
- DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyComment");
- setClistIcon(hcnt);
- setSrmmIcon(hcnt);
- }
- }
- }
- else
- {
- DBDeleteContactSetting(hContact, szGPGModuleName, "KeyID");
- DBDeleteContactSetting(hContact, szGPGModuleName, "GPGPubKey");
- DBDeleteContactSetting(hContact, szGPGModuleName, "KeyMainName");
- DBDeleteContactSetting(hContact, szGPGModuleName, "KeyType");
- DBDeleteContactSetting(hContact, szGPGModuleName, "KeyMainEmail");
- DBDeleteContactSetting(hContact, szGPGModuleName, "KeyComment");
- setClistIcon(hContact);
- setSrmmIcon(hContact);
- }
- }
- else
- {
- DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyID");
- DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "GPGPubKey");
- DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyMainName");
- DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyType");
- DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyMainEmail");
- DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyComment");
- setClistIcon(user_data[item_num+1]);
- setSrmmIcon(user_data[item_num+1]);
- }
- }
- ListView_SetItemText(hwndList, item_num, 3, _T("not set"));
- ListView_SetItemText(hwndList, item_num, 2, _T("not set"));
- ListView_SetItemText(hwndList, item_num, 1, _T("not set"));
- break;
- case IDC_SELECT_KEY:
- {
- void ShowFirstRunDialog();
- ShowFirstRunDialog();
- }
- break;
- case IDC_SAVE_KEY_BUTTON:
- {
- tmp = GetFilePath(_T("Export public key"), _T("*"), _T(".asc pubkey file"), true);
- if(!tmp)
- {
- break;
- }
- wstring str;
- {
- TCHAR *tmp = UniGetContactSettingUtf(user_data[item_num+1], szGPGModuleName, "GPGPubKey", _T(""));
- str.append(tmp);
- mir_free(tmp);
- }
- wstring::size_type s = 0;
- while((s = str.find(_T("\r"), s)) != wstring::npos)
- {
- str.erase(s, 1);
- }
- wfstream f(tmp, std::ios::out);
- delete [] tmp;
- f<<str.c_str();
- f.close();
- }
- break;
- case IDC_LOG_FILE_SET:
- {
- tmp = GetFilePath(_T("Set log file"), _T("*"), _T("LOG files"), 1);
- SetDlgItemText(hwndDlg, IDC_LOG_FILE_EDIT, tmp);
- mir_free(tmp);
- }
- break;
- default:
- break;
- }
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
- }
-
- case WM_NOTIFY:
- {
- EnableWindow(GetDlgItem(hwndDlg, IDC_AUTO_EXCHANGE), (bIsMiranda09 && IsDlgButtonChecked(hwndDlg, IDC_JABBER_API)));
- if(hdr && IsWindowVisible(hdr->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, &params));
- 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("<GPGdec>"));
- SetDlgItemText(hwndDlg, IDC_IN_OPEN_TAG, tmp);
- mir_free(tmp);
- tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", _T("</GPGdec>"));
- SetDlgItemText(hwndDlg, IDC_IN_CLOSE_TAG, tmp);
- mir_free(tmp);
- tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", _T("<GPGenc>"));
- SetDlgItemText(hwndDlg, IDC_OUT_OPEN_TAG, tmp);
- mir_free(tmp);
- tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", _T("</GPGenc>"));
- 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, &params));
- if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
- {
- gpg_thread.~thread();
- debuglog<<time_str()<<": GPG execution timed out, aborted\n";
- }
- if((out.find("-----BEGIN PGP PUBLIC KEY BLOCK-----") != string::npos) && (out.find("-----END PGP PUBLIC KEY BLOCK-----") != string::npos))
- {
- string::size_type p = 0, stop = 0;
- for(;;)
- {
- if((p = out.find("\n", p+2)) != string::npos)
- {
- if(p > 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<<str.c_str();
- f.close();
- cmd += _T(" --batch ");
- cmd += _T(" --import \"");
- cmd += tmp2;
- cmd += _T("\"");
- }
- 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, &params));
- if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
- {
- gpg_thread.~thread();
- debuglog<<time_str()<<": GPG execution timed out, aborted\n";
- break;
- }
- if(result == pxNotFound)
- break;
- mir_free(begin);
- mir_free(end);
- 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)
- DBDeleteContactSetting(hcnt, szGPGModuleName, "bAlwatsTrust");
- }
- }
- else
- DBDeleteContactSetting(metaGetMostOnline(hContact), szGPGModuleName, "bAlwatsTrust");
- }
- else
- DBDeleteContactSetting(hContact, szGPGModuleName, "bAlwatsTrust");
- }
- {
- TCHAR *tmp;
- if(output.find("already in secret keyring") != string::npos)
- {
- MessageBox(0, _T("Key already in scret key ring."), _T("Info"), MB_OK);
- DeleteFile(tmp2);
- break;
- }
- char *tmp2;
- string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
- string::size_type 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(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, "KeyID", tmp2);
- }
- }
- else
- DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyID", tmp2);
- }
- else
- DBWriteContactSettingString(hContact, szGPGModuleName, "KeyID", tmp2);
- }
- mir_free(tmp2);
- tmp = mir_wstrdup(toUTF16(output.substr(s,s2-s)).c_str());
- if(hContact && hwndList_p)
- ListView_SetItemText(hwndList_p, item_num, 1, tmp);
- mir_free(tmp);
- s = output.find("“", s2);
- if(s == string::npos)
- {
- s = output.find("\"", s2);
- s += 1;
- }
- else
- s += 3;
- if((s2 = output.find("(", s)) == string::npos)
- s2 = output.find("<", s);
- else if(s2 > 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, &params));
- if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
- {
- gpg_thread.~thread();
- debuglog<<time_str()<<": GPG execution timed out, aborted\n";
- break;
- }
- if(result == pxNotFound)
- break;
- string::size_type s = 0;
- while((s = out.find("\r", s)) != string::npos)
- {
- out.erase(s, 1);
- }
- DBWriteContactSettingString(hContact, szGPGModuleName, "GPGPubKey", out.c_str());
- }
- }
- tmp = mir_wstrdup(toUTF16(output).c_str());
- MessageBox(0, tmp, _T(""), MB_OK);
- mir_free(tmp);
- DeleteFile(tmp2);
- }
- key_buf.clear();
- if(IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ENCRYPTION))
- {
- void setSrmmIcon(HANDLE);
- void setClistIcon(HANDLE);
- 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)
- {
- if(!isContactSecured(hcnt))
- DBWriteContactSettingByte(hcnt, szGPGModuleName, "GPGEncryption", 1);
- else
- DBWriteContactSettingByte(hcnt, szGPGModuleName, "GPGEncryption", 0);
- setSrmmIcon(hContact);
- setClistIcon(hContact);
- }
- }
- }
- else if(!isContactSecured(hContact))
- DBWriteContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 1);
- else
- DBWriteContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0);
- }
- else if(!isContactSecured(hContact))
- DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1);
- else
- DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
- }
- }
- DestroyWindow(hwndDlg);
- }
- break;
- case ID_LOAD_FROM_FILE:
- {
- tmp = GetFilePath(_T("Set file containing GPG public key"), _T("*"), _T("GPG public key file"));
- if(!tmp)
- {
- break;
- }
- wfstream f(tmp, std::ios::in | std::ios::ate | std::ios::binary);
- delete [] tmp;
- if(!f.is_open())
- {
- MessageBox(0, _T("Failed to open file"), _T("Error"), MB_OK);
- break;
- }
- if(f.is_open())
- {
- std::wifstream::pos_type size = f.tellg();
- TCHAR *tmp = new TCHAR [(std::ifstream::pos_type)size+(std::ifstream::pos_type)1];
- f.seekg(0, std::ios::beg);
- f.read(tmp, size);
- tmp[size]= '\0';
- key_buf.append(tmp);
- delete [] tmp;
- f.close();
- }
- if(key_buf.empty())
- {
- key_buf.clear();
- debuglog<<time_str()<<": info: Failed to read key file\n";
- break;
- }
- ws2 = key_buf.find(_T("-----END PGP PUBLIC KEY BLOCK-----"));
- ws1 = key_buf.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"));
- if(ws2 == wstring::npos || ws1 == wstring::npos)
- {
- ws2 = key_buf.find(_T("-----END PGP PRIVATE KEY BLOCK-----"));
- ws1 = key_buf.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----"));
- }
- if(ws2 == wstring::npos || ws1 == wstring::npos)
- {
- MessageBox(0, _T("Where is no public or private key."), _T("Info"), MB_OK);
- break;
- }
- ws2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----"));
- SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, key_buf.substr(ws1,ws2-ws1).c_str());
- key_buf.clear();
- }
- break;
- case IDC_IMPORT:
- extern HANDLE new_key_hcnt;
- extern boost::mutex new_key_hcnt_mutex;
- new_key_hcnt_mutex.lock();
- new_key_hcnt = hContact;
- void ShowImportKeyDialog();
- ShowImportKeyDialog();
- break;
- case IDC_SELECT_EXISTING:
- void ShowSelectExistingKeyDialog();
- ShowSelectExistingKeyDialog();
- break;
- }
- break;
- }
-
- case WM_NOTIFY:
- {
- switch (((LPNMHDR)lParam)->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<int, HANDLE> 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, &params));
+ if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
+ {
+ gpg_thread.~thread();
+ debuglog<<time_str()<<": GPG execution timed out, aborted\n";
+ mir_free(tmp);
+ break;
+ }
+ if(result == pxNotFound)
+ {
+ mir_free(tmp);
+ break;
+ }
+ if(output.find("--delete-secret-keys") != string::npos)
+ MessageBoxA(0, "we have secret key for this public key, do not removing from GPG keyring", "info", MB_OK);
+ else
+ MessageBoxA(0, "Key removed from GPG keyring", "info", MB_OK);
+ }
+ mir_free(tmp);
+ if(ismetacontact)
+ {
+ if(MessageBox(0, _T("Do you want to remove key from entire metacontact (all subcontacts) ?"), _T("Metacontact detected"), MB_YESNO) == IDYES)
+ {
+ HANDLE hcnt = NULL;
+ int count = metaGetContactsNum(meta);
+ for(int i = 0; i < count; i++)
+ {
+ hcnt = metaGetSubcontact(meta, i);
+ if(hcnt)
+ {
+ DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyID");
+ DBDeleteContactSetting(hcnt, szGPGModuleName, "GPGPubKey");
+ DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyMainName");
+ DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyType");
+ DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyMainEmail");
+ DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyComment");
+ setClistIcon(hcnt);
+ setSrmmIcon(hcnt);
+ }
+ }
+ }
+ else
+ {
+ DBDeleteContactSetting(hContact, szGPGModuleName, "KeyID");
+ DBDeleteContactSetting(hContact, szGPGModuleName, "GPGPubKey");
+ DBDeleteContactSetting(hContact, szGPGModuleName, "KeyMainName");
+ DBDeleteContactSetting(hContact, szGPGModuleName, "KeyType");
+ DBDeleteContactSetting(hContact, szGPGModuleName, "KeyMainEmail");
+ DBDeleteContactSetting(hContact, szGPGModuleName, "KeyComment");
+ setClistIcon(hContact);
+ setSrmmIcon(hContact);
+ }
+ }
+ else
+ {
+ DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyID");
+ DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "GPGPubKey");
+ DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyMainName");
+ DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyType");
+ DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyMainEmail");
+ DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyComment");
+ setClistIcon(user_data[item_num+1]);
+ setSrmmIcon(user_data[item_num+1]);
+ }
+ }
+ ListView_SetItemText(hwndList, item_num, 3, _T("not set"));
+ ListView_SetItemText(hwndList, item_num, 2, _T("not set"));
+ ListView_SetItemText(hwndList, item_num, 1, _T("not set"));
+ break;
+ case IDC_SELECT_KEY:
+ {
+ void ShowFirstRunDialog();
+ ShowFirstRunDialog();
+ }
+ break;
+ case IDC_SAVE_KEY_BUTTON:
+ {
+ tmp = GetFilePath(_T("Export public key"), _T("*"), _T(".asc pubkey file"), true);
+ if(!tmp)
+ {
+ break;
+ }
+ wstring str;
+ {
+ TCHAR *tmp = UniGetContactSettingUtf(user_data[item_num+1], szGPGModuleName, "GPGPubKey", _T(""));
+ str.append(tmp);
+ mir_free(tmp);
+ }
+ wstring::size_type s = 0;
+ while((s = str.find(_T("\r"), s)) != wstring::npos)
+ {
+ str.erase(s, 1);
+ }
+ wfstream f(tmp, std::ios::out);
+ delete [] tmp;
+ f<<str.c_str();
+ f.close();
+ }
+ break;
+ case IDC_LOG_FILE_SET:
+ {
+ tmp = GetFilePath(_T("Set log file"), _T("*"), _T("LOG files"), 1);
+ SetDlgItemText(hwndDlg, IDC_LOG_FILE_EDIT, tmp);
+ mir_free(tmp);
+ }
+ break;
+ default:
+ break;
+ }
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+ }
+
+ case WM_NOTIFY:
+ {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_AUTO_EXCHANGE), (bIsMiranda09 && IsDlgButtonChecked(hwndDlg, IDC_JABBER_API)));
+ if(hdr && IsWindowVisible(hdr->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, &params));
+ 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("<GPGdec>"));
+ SetDlgItemText(hwndDlg, IDC_IN_OPEN_TAG, tmp);
+ mir_free(tmp);
+ tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", _T("</GPGdec>"));
+ SetDlgItemText(hwndDlg, IDC_IN_CLOSE_TAG, tmp);
+ mir_free(tmp);
+ tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", _T("<GPGenc>"));
+ SetDlgItemText(hwndDlg, IDC_OUT_OPEN_TAG, tmp);
+ mir_free(tmp);
+ tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", _T("</GPGenc>"));
+ 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, &params));
+ if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
+ {
+ gpg_thread.~thread();
+ debuglog<<time_str()<<": GPG execution timed out, aborted\n";
+ }
+ if((out.find("-----BEGIN PGP PUBLIC KEY BLOCK-----") != string::npos) && (out.find("-----END PGP PUBLIC KEY BLOCK-----") != string::npos))
+ {
+ string::size_type p = 0, stop = 0;
+ for(;;)
+ {
+ if((p = out.find("\n", p+2)) != string::npos)
+ {
+ if(p > 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<<str.c_str();
+ f.close();
+ cmd += _T(" --batch ");
+ cmd += _T(" --import \"");
+ cmd += tmp2;
+ cmd += _T("\"");
+ }
+ 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, &params));
+ if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
+ {
+ gpg_thread.~thread();
+ debuglog<<time_str()<<": GPG execution timed out, aborted\n";
+ break;
+ }
+ if(result == pxNotFound)
+ break;
+ mir_free(begin);
+ mir_free(end);
+ 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)
+ DBDeleteContactSetting(hcnt, szGPGModuleName, "bAlwatsTrust");
+ }
+ }
+ else
+ DBDeleteContactSetting(metaGetMostOnline(hContact), szGPGModuleName, "bAlwatsTrust");
+ }
+ else
+ DBDeleteContactSetting(hContact, szGPGModuleName, "bAlwatsTrust");
+ }
+ {
+ TCHAR *tmp;
+ if(output.find("already in secret keyring") != string::npos)
+ {
+ MessageBox(0, _T("Key already in scret key ring."), _T("Info"), MB_OK);
+ DeleteFile(tmp2);
+ break;
+ }
+ char *tmp2;
+ string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
+ string::size_type 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(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, "KeyID", tmp2);
+ }
+ }
+ else
+ DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyID", tmp2);
+ }
+ else
+ DBWriteContactSettingString(hContact, szGPGModuleName, "KeyID", tmp2);
+ }
+ mir_free(tmp2);
+ tmp = mir_wstrdup(toUTF16(output.substr(s,s2-s)).c_str());
+ if(hContact && hwndList_p)
+ ListView_SetItemText(hwndList_p, item_num, 1, tmp);
+ mir_free(tmp);
+ s = output.find("“", s2);
+ if(s == string::npos)
+ {
+ s = output.find("\"", s2);
+ s += 1;
+ }
+ else
+ s += 3;
+ if((s2 = output.find("(", s)) == string::npos)
+ s2 = output.find("<", s);
+ else if(s2 > 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, &params));
+ if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
+ {
+ gpg_thread.~thread();
+ debuglog<<time_str()<<": GPG execution timed out, aborted\n";
+ break;
+ }
+ if(result == pxNotFound)
+ break;
+ string::size_type s = 0;
+ while((s = out.find("\r", s)) != string::npos)
+ {
+ out.erase(s, 1);
+ }
+ DBWriteContactSettingString(hContact, szGPGModuleName, "GPGPubKey", out.c_str());
+ }
+ }
+ tmp = mir_wstrdup(toUTF16(output).c_str());
+ MessageBox(0, tmp, _T(""), MB_OK);
+ mir_free(tmp);
+ DeleteFile(tmp2);
+ }
+ key_buf.clear();
+ if(IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ENCRYPTION))
+ {
+ void setSrmmIcon(HANDLE);
+ void setClistIcon(HANDLE);
+ 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)
+ {
+ if(!isContactSecured(hcnt))
+ DBWriteContactSettingByte(hcnt, szGPGModuleName, "GPGEncryption", 1);
+ else
+ DBWriteContactSettingByte(hcnt, szGPGModuleName, "GPGEncryption", 0);
+ setSrmmIcon(hContact);
+ setClistIcon(hContact);
+ }
+ }
+ }
+ else if(!isContactSecured(hContact))
+ DBWriteContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 1);
+ else
+ DBWriteContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0);
+ }
+ else if(!isContactSecured(hContact))
+ DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1);
+ else
+ DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
+ }
+ }
+ DestroyWindow(hwndDlg);
+ }
+ break;
+ case ID_LOAD_FROM_FILE:
+ {
+ tmp = GetFilePath(_T("Set file containing GPG public key"), _T("*"), _T("GPG public key file"));
+ if(!tmp)
+ {
+ break;
+ }
+ wfstream f(tmp, std::ios::in | std::ios::ate | std::ios::binary);
+ delete [] tmp;
+ if(!f.is_open())
+ {
+ MessageBox(0, _T("Failed to open file"), _T("Error"), MB_OK);
+ break;
+ }
+ if(f.is_open())
+ {
+ std::wifstream::pos_type size = f.tellg();
+ TCHAR *tmp = new TCHAR [(std::ifstream::pos_type)size+(std::ifstream::pos_type)1];
+ f.seekg(0, std::ios::beg);
+ f.read(tmp, size);
+ tmp[size]= '\0';
+ key_buf.append(tmp);
+ delete [] tmp;
+ f.close();
+ }
+ if(key_buf.empty())
+ {
+ key_buf.clear();
+ debuglog<<time_str()<<": info: Failed to read key file\n";
+ break;
+ }
+ ws2 = key_buf.find(_T("-----END PGP PUBLIC KEY BLOCK-----"));
+ ws1 = key_buf.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"));
+ if(ws2 == wstring::npos || ws1 == wstring::npos)
+ {
+ ws2 = key_buf.find(_T("-----END PGP PRIVATE KEY BLOCK-----"));
+ ws1 = key_buf.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----"));
+ }
+ if(ws2 == wstring::npos || ws1 == wstring::npos)
+ {
+ MessageBox(0, _T("Where is no public or private key."), _T("Info"), MB_OK);
+ break;
+ }
+ ws2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----"));
+ SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, key_buf.substr(ws1,ws2-ws1).c_str());
+ key_buf.clear();
+ }
+ break;
+ case IDC_IMPORT:
+ extern HANDLE new_key_hcnt;
+ extern boost::mutex new_key_hcnt_mutex;
+ new_key_hcnt_mutex.lock();
+ new_key_hcnt = hContact;
+ void ShowImportKeyDialog();
+ ShowImportKeyDialog();
+ break;
+ case IDC_SELECT_EXISTING:
+ void ShowSelectExistingKeyDialog();
+ ShowSelectExistingKeyDialog();
+ break;
+ }
+ break;
+ }
+
+ case WM_NOTIFY:
+ {
+ switch (((LPNMHDR)lParam)->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<int, HANDLE> 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<int, HANDLE> 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<wstring> 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<<time_str()<<": GPG execution timed out, aborted\n";
}
- DeleteFile(filename);
- mir_free(filename);
- }
- }
- break;
- }
- return 0;
+ DeleteFile(filename);
+ mir_free(filename);
+ }
+ }
+ break;
+ }
+ return 0;
}
@@ -406,10 +406,10 @@ int onSendFile(WPARAM w, LPARAM l)
delete gpg_thread;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
}
- mir_free(file[i]);
- file[i]=mir_wstrdup(path_out.c_str());
- mir_free(file_out);
- transfers.push_back(path_out);
+ mir_free(file[i]);
+ file[i]=mir_wstrdup(path_out.c_str());
+ mir_free(file_out);
+ transfers.push_back(path_out);
}
}
@@ -840,162 +840,162 @@ bool isGPGConfigured()
mir_free(id);
mir_free(key);
return true;
- }
- mir_free(id);
+ }
+ mir_free(id);
mir_free(key);
return false;
}
-#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 <process.h>
-
-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<boost::random_device&, boost::uniform_int<>> 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<string>::iterator end = hcontact_data[hContact].msgs_to_send.end();
- for(list<string>::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 <process.h>
+
+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<boost::random_device&, boost::uniform_int<>> 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<string>::iterator end = hcontact_data[hContact].msgs_to_send.end();
+ for(list<string>::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