diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2013-03-05 00:04:28 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2013-03-05 00:04:28 +0200 |
commit | a40ccbb5ba271641134586898e69df4855a7f687 (patch) | |
tree | 0a79ef1a59582b4367c9be65426ec88b343c500c | |
parent | 418736c65c97cdc6ca4910e1e8650e474cb12849 (diff) |
merged with miranda_ng main reponew_gpg_miranda_ng
-rw-r--r-- | res/Version.rc | 38 | ||||
-rwxr-xr-x | res/icons/secured.ico | bin | 2550 -> 0 bytes | |||
-rwxr-xr-x | res/icons/unsecured.ico | bin | 2550 -> 0 bytes | |||
-rwxr-xr-x | res/new_gpg.rc | 211 | ||||
-rw-r--r-- | res/secured.ico | bin | 0 -> 1150 bytes | |||
-rw-r--r-- | res/unsecured.ico | bin | 0 -> 1150 bytes | |||
-rw-r--r-- | src/Version.h | 14 | ||||
-rwxr-xr-x | src/commonheaders.h | 24 | ||||
-rwxr-xr-x | src/gpg_wrapper.cpp | 43 | ||||
-rwxr-xr-x | src/main.cpp | 24 | ||||
-rwxr-xr-x | src/options.cpp | 1159 | ||||
-rwxr-xr-x | src/utilities.cpp | 18 |
12 files changed, 759 insertions, 772 deletions
diff --git a/res/Version.rc b/res/Version.rc new file mode 100644 index 0000000..5bfbab4 --- /dev/null +++ b/res/Version.rc @@ -0,0 +1,38 @@ +// Microsoft Visual C++ generated resource script.
+//
+#ifdef APSTUDIO_INVOKED
+#error this file is not editable by Microsoft Visual C++
+#endif //APSTUDIO_INVOKED
+
+#include "afxres.h"
+#include "..\src\version.h"
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION __FILEVERSION_STRING
+ PRODUCTVERSION __FILEVERSION_STRING
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x0L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "000004b0"
+ BEGIN
+ VALUE "FileDescription", __DESCRIPTION
+ VALUE "InternalName", __PLUGIN_NAME
+ VALUE "LegalCopyright", __COPYRIGHT
+ VALUE "OriginalFilename", __FILENAME
+ VALUE "ProductName", __PLUGIN_NAME
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x0, 1200
+ END
+END
diff --git a/res/icons/secured.ico b/res/icons/secured.ico Binary files differdeleted file mode 100755 index 8d84167..0000000 --- a/res/icons/secured.ico +++ /dev/null diff --git a/res/icons/unsecured.ico b/res/icons/unsecured.ico Binary files differdeleted file mode 100755 index 567367b..0000000 --- a/res/icons/unsecured.ico +++ /dev/null diff --git a/res/new_gpg.rc b/res/new_gpg.rc index 2ad1f72..452c9af 100755 --- a/res/new_gpg.rc +++ b/res/new_gpg.rc @@ -55,7 +55,7 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPT CAPTION "Load Public GPG key"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
- DEFPUSHBUTTON "ОК",ID_OK,7,169,50,14
+ DEFPUSHBUTTON "OK",ID_OK,7,169,50,14
PUSHBUTTON "Load from file",ID_LOAD_FROM_FILE,256,169,75,14
EDITTEXT IDC_PUBLIC_KEY_EDIT,7,7,324,134,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | WS_VSCROLL,WS_EX_STATICEDGE
PUSHBUTTON "Select existing",IDC_SELECT_EXISTING,113,169,97,14
@@ -68,7 +68,7 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPT CAPTION "Set own key"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
- DEFPUSHBUTTON "ОК",ID_OK,12,220,50,14,WS_DISABLED
+ DEFPUSHBUTTON "OK",ID_OK,12,220,50,14,WS_DISABLED
CONTROL "",IDC_KEY_LIST,"SysListView32",LVS_REPORT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,44,277,105
PUSHBUTTON "Generate key",IDC_GENERATE_KEY,7,152,74,14
LTEXT "Select key for use",IDC_STATIC,16,33,186,8
@@ -146,7 +146,7 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPT CAPTION "Select existing public key from list"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
- DEFPUSHBUTTON "ОК",IDOK,7,236,50,14,WS_DISABLED
+ DEFPUSHBUTTON "OK",IDOK,7,236,50,14,WS_DISABLED
PUSHBUTTON "Cancel",IDCANCEL,313,236,50,14
CONTROL "",IDC_EXISTING_KEY_LIST,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,14,356,217
END
@@ -156,7 +156,7 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPT CAPTION "Enter password for your secret key"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
- DEFPUSHBUTTON "ОК",IDOK,7,87,50,14
+ DEFPUSHBUTTON "OK",IDOK,7,87,50,14
PUSHBUTTON "Cancel",IDCANCEL,150,87,50,14
EDITTEXT IDC_PASSWORD,13,38,179,14,ES_PASSWORD | ES_AUTOHSCROLL
LTEXT "Password:",IDC_STATIC,14,28,34,8
@@ -213,6 +213,68 @@ BEGIN PUSHBUTTON "Ok",IDC_OK,7,55,50,14
END
+IDD_OPT_GPG DIALOGEX 0, 0, 286, 214
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x0
+BEGIN
+ CONTROL "",IDC_USERLIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,17,272,112
+ CTEXT "Userlist:",IDC_STATIC,25,7,201,8
+ PUSHBUTTON "Export PubKey",IDC_SAVE_KEY_BUTTON,8,135,75,14
+ PUSHBUTTON "Delete key",IDC_DELETE_KEY_BUTTON,90,135,70,14
+ PUSHBUTTON "Select own key",IDC_SELECT_KEY,205,193,74,14
+ CONTROL "Turn on debug log",IDC_DEBUG_LOG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,181,159,89,10
+ EDITTEXT IDC_LOG_FILE_EDIT,11,157,98,14,ES_AUTOHSCROLL
+ PUSHBUTTON "Browse",IDC_LOG_FILE_SET,119,156,50,14
+ CONTROL "Use jabber api on Miranda NG (recomended)",IDC_JABBER_API,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,175,251,10
+ LTEXT "Default key",IDC_CURRENT_KEY,12,196,110,8
+ CONTROL "Encrypt file transfers",IDC_FILE_TRANSFERS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,185,137,10
+ CONTROL "Automatic key exchange",IDC_AUTO_EXCHANGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,163,137,111,10
+ PUSHBUTTON "Copy own key",IDC_COPY_KEY,127,193,74,14
+END
+
+IDD_OPT_GPG_BIN DIALOGEX 0, 0, 282, 71
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x0
+BEGIN
+ PUSHBUTTON "Browse",IDC_SET_BIN_PATH,216,17,60,14
+ PUSHBUTTON "Browse",IDC_SET_HOME_DIR,217,44,57,14
+ EDITTEXT IDC_BIN_PATH,7,17,195,14,ES_AUTOHSCROLL
+ EDITTEXT IDC_HOME_DIR,7,44,195,14,ES_AUTOHSCROLL
+ LTEXT "GnuPG binary:",IDC_STATIC,10,7,147,8
+ LTEXT "Home directory:",IDC_STATIC,9,34,144,8
+END
+
+IDD_OPT_GPG_MESSAGES DIALOGEX 0, 0, 302, 100
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x0
+BEGIN
+ CONTROL "Add tags to encoded and decoded messages",IDC_APPEND_TAGS,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,3,65,243,10
+ EDITTEXT IDC_IN_OPEN_TAG,39,20,88,14,ES_AUTOHSCROLL
+ EDITTEXT IDC_IN_CLOSE_TAG,151,20,90,14,ES_AUTOHSCROLL
+ LTEXT "Incomming message tags:",IDC_STATIC,15,10,84,8
+ LTEXT "Outgoing message tags:",IDC_STATIC,13,36,79,8
+ RTEXT "Open:",IDC_STATIC,13,23,26,8
+ RTEXT "Close:",IDC_STATIC,127,23,23,8
+ EDITTEXT IDC_OUT_OPEN_TAG,39,46,88,14,ES_AUTOHSCROLL
+ EDITTEXT IDC_OUT_CLOSE_TAG,151,46,90,14,ES_AUTOHSCROLL
+ RTEXT "Open:",IDC_STATIC,13,49,26,8
+ RTEXT "Close:",IDC_STATIC,127,49,23,8
+ CONTROL "Strip all tags in outgoing messages",IDC_STRIP_TAGS,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,3,76,233,10
+END
+
+IDD_OPT_GPG_ADVANCED DIALOGEX 0, 0, 286, 50
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x0
+BEGIN
+ CONTROL "Turn on presence signing (Jabber) (required by xep 0-27)",IDC_PRESCENSE_SUBSCRIPTION,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,9,268,10
+ PUSHBUTTON "Export keys",IDC_EXPORT,12,26,60,14
+ PUSHBUTTON "Import keys",IDC_IMPORT,82,26,68,14
+END
+
/////////////////////////////////////////////////////////////////////////////
//
@@ -316,6 +378,12 @@ BEGIN TOPMARGIN, 7
BOTTOMMARGIN, 69
END
+
+ IDD_OPT_GPG_ADVANCED, DIALOG
+ BEGIN
+ VERTGUIDE, 12
+ BOTTOMMARGIN, 40
+ END
END
#endif // APSTUDIO_INVOKED
@@ -327,145 +395,14 @@ END // Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
-IDI_SECURED ICON "icons\\secured.ico"
-IDI_UNSECURED ICON "icons\\unsecured.ico"
+IDI_SECURED ICON "secured.ico"
+IDI_UNSECURED ICON "unsecured.ico"
-/////////////////////////////////////////////////////////////////////////////
-//
-// Version
-//
-
-VS_VERSION_INFO VERSIONINFO
- FILEVERSION 0,0,0,11
- PRODUCTVERSION 0,9,0,0
- FILEFLAGSMASK 0x17L
-#ifdef _DEBUG
- FILEFLAGS 0x1L
-#else
- FILEFLAGS 0x0L
-#endif
- FILEOS 0x4L
- FILETYPE 0x0L
- FILESUBTYPE 0x0L
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "041904b0"
- BEGIN
- VALUE "FileDescription", "new_gpg"
- VALUE "FileVersion", "0.0.0.11"
- VALUE "InternalName", "new_gpg"
- VALUE "LegalCopyright", "Copyright (C) 2010-2011 sss"
- VALUE "OriginalFilename", "new_gpg"
- VALUE "ProductName", "new_gpg"
- VALUE "ProductVersion", "0.9.0.0"
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x419, 1200
- END
-END
#endif // Русский (Россия) resources
/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// Английский (США) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
-LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
-#pragma code_page(1252)
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Dialog
-//
-
-IDD_OPT_GPG DIALOGEX 0, 0, 286, 214
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
-FONT 8, "MS Shell Dlg", 400, 0, 0x0
-BEGIN
- CONTROL "",IDC_USERLIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,17,272,112
- CTEXT "Userlist:",IDC_STATIC,25,7,201,8
- PUSHBUTTON "Export PubKey",IDC_SAVE_KEY_BUTTON,8,135,75,14
- PUSHBUTTON "Delete key",IDC_DELETE_KEY_BUTTON,90,135,70,14
- PUSHBUTTON "Select own key",IDC_SELECT_KEY,205,193,74,14
- CONTROL "Turn on debug log",IDC_DEBUG_LOG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,181,159,89,10
- EDITTEXT IDC_LOG_FILE_EDIT,11,157,98,14,ES_AUTOHSCROLL
- PUSHBUTTON "Browse",IDC_LOG_FILE_SET,119,156,50,14
- CONTROL "Use jabber api on Miranda NG (recomended)",IDC_JABBER_API,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,175,251,10
- LTEXT "Default key",IDC_CURRENT_KEY,12,196,110,8
- CONTROL "Encrypt file transfers",IDC_FILE_TRANSFERS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,185,137,10
- CONTROL "Automatic key exchange",IDC_AUTO_EXCHANGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,163,137,111,10
- PUSHBUTTON "Copy own key",IDC_COPY_KEY,127,193,74,14
-END
-
-IDD_OPT_GPG_BIN DIALOGEX 0, 0, 282, 71
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
-FONT 8, "MS Shell Dlg", 400, 0, 0x0
-BEGIN
- PUSHBUTTON "Browse",IDC_SET_BIN_PATH,216,17,60,14
- PUSHBUTTON "Browse",IDC_SET_HOME_DIR,217,44,57,14
- EDITTEXT IDC_BIN_PATH,7,17,195,14,ES_AUTOHSCROLL
- EDITTEXT IDC_HOME_DIR,7,44,195,14,ES_AUTOHSCROLL
- LTEXT "GnuPG binary:",IDC_STATIC,10,7,147,8
- LTEXT "Home directory:",IDC_STATIC,9,34,144,8
-END
-
-IDD_OPT_GPG_MESSAGES DIALOGEX 0, 0, 302, 100
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
-FONT 8, "MS Shell Dlg", 400, 0, 0x0
-BEGIN
- CONTROL "Add tags to encoded and decoded messages",IDC_APPEND_TAGS,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,3,65,243,10
- EDITTEXT IDC_IN_OPEN_TAG,39,20,88,14,ES_AUTOHSCROLL
- EDITTEXT IDC_IN_CLOSE_TAG,151,20,90,14,ES_AUTOHSCROLL
- LTEXT "Incomming message tags:",IDC_STATIC,15,10,84,8
- LTEXT "Outgoing message tags:",IDC_STATIC,13,36,79,8
- RTEXT "Open:",IDC_STATIC,13,23,26,8
- RTEXT "Close:",IDC_STATIC,127,23,23,8
- EDITTEXT IDC_OUT_OPEN_TAG,39,46,88,14,ES_AUTOHSCROLL
- EDITTEXT IDC_OUT_CLOSE_TAG,151,46,90,14,ES_AUTOHSCROLL
- RTEXT "Open:",IDC_STATIC,13,49,26,8
- RTEXT "Close:",IDC_STATIC,127,49,23,8
- CONTROL "Strip all tags in outgoing messages",IDC_STRIP_TAGS,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,3,76,233,10
-END
-
-IDD_OPT_GPG_ADVANCED DIALOGEX 0, 0, 286, 50
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
-FONT 8, "MS Shell Dlg", 400, 0, 0x0
-BEGIN
- CONTROL "Turn on presence signing (Jabber) (required by xep 0-27)",IDC_PRESCENSE_SUBSCRIPTION,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,9,268,10
- PUSHBUTTON "Export keys",IDC_EXPORT,12,26,60,14
- PUSHBUTTON "Import keys",IDC_IMPORT,82,26,68,14
-END
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// DESIGNINFO
-//
-
-#ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO
-BEGIN
- IDD_OPT_GPG_ADVANCED, DIALOG
- BEGIN
- VERTGUIDE, 12
- BOTTOMMARGIN, 40
- END
-END
-#endif // APSTUDIO_INVOKED
-
-#endif // Английский (США) resources
-/////////////////////////////////////////////////////////////////////////////
-
-
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
diff --git a/res/secured.ico b/res/secured.ico Binary files differnew file mode 100644 index 0000000..2e1ac4a --- /dev/null +++ b/res/secured.ico diff --git a/res/unsecured.ico b/res/unsecured.ico Binary files differnew file mode 100644 index 0000000..081b360 --- /dev/null +++ b/res/unsecured.ico diff --git a/src/Version.h b/src/Version.h new file mode 100644 index 0000000..86774f7 --- /dev/null +++ b/src/Version.h @@ -0,0 +1,14 @@ +#define __MAJOR_VERSION 0
+#define __MINOR_VERSION 0
+#define __RELEASE_NUM 0
+#define __BUILD_NUM 11
+
+#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
+
+#define __PLUGIN_NAME "GPG"
+#define __FILENAME "New_GPG.dll"
+#define __DESCRIPTION "New GPG encryption support plugin, based on code from old GPG plugin and SecureIM."
+#define __AUTHOR "sss"
+#define __AUTHOREMAIL "sss123next@list.ru"
+#define __AUTHORWEB "http://miranda-ng.org/"
+#define __COPYRIGHT "© 2010-2012 sss"
diff --git a/src/commonheaders.h b/src/commonheaders.h index 37f79d5..e2ffb38 100755 --- a/src/commonheaders.h +++ b/src/commonheaders.h @@ -15,26 +15,17 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef COMMONHEADERS_H #define COMMONHEADERS_H -#define MIRANDA_VER 0x0A00 //windows #include <windows.h> #include <shlobj.h> #include <io.h> -#include <uxtheme.h> #include <shlwapi.h> -#include <richedit.h> -//c -#include <locale.h> -#include <errno.h> -#include <time.h> + //c++ -#include <iostream> #include <map> using std::map; #include <list> using std::list; -#include <vector> -using std::vector; #include <string> using std::string; using std::wstring; @@ -62,25 +53,22 @@ using std::fstream; #include <m_database.h> #include <m_options.h> #include <m_langpack.h> -#include <m_clist.h> #include <m_clui.h> -#include <m_icolib.h> #include <m_skin.h> #include <m_protomod.h> -#include <m_protosvc.h> -#include <m_netlib.h> #include <m_jabber.h> #include <m_icqplus.h> #include <m_message.h> #include <m_cluiframes.h> #include <m_icolib.h> -#include "m_extraicons.h" -#include "m_metacontacts.h" -#include "win2k.h" -#include "resource.h" +#include <m_extraicons.h> +#include <win2k.h> +#include <m_metacontacts.h> //internal +#include "resource.h" +#include "Version.h" #include "constants.h" #include "log.h" #include "globals.h" diff --git a/src/gpg_wrapper.cpp b/src/gpg_wrapper.cpp index 5f9df7d..112d860 100755 --- a/src/gpg_wrapper.cpp +++ b/src/gpg_wrapper.cpp @@ -70,21 +70,22 @@ pxResult pxExecute(std::vector<std::wstring> &aargv, string *aoutput, LPDWORD ae pipe pout = create_pipe(); + pipe perr = create_pipe(); + child *c = nullptr; { file_descriptor_sink sout(pout.sink, close_handle); + file_descriptor_sink serr(perr.sink, close_handle); char *mir_path = new char [MAX_PATH]; - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + PathToAbsolute("\\", mir_path); - child c = execute(set_args(argv), bind_stdout(sout), /*bind_stdin(sin),*/ show_window(SW_HIDE), hide_console(), inherit_env(), set_env(env), start_in_dir(toUTF16(mir_path))); - _child = &c; + c = new child(execute(set_args(argv), bind_stdout(sout), bind_stderr(serr), close_stdin(),/*bind_stdin(sin),*/ show_window(SW_HIDE), hide_console(), inherit_env(), set_env(env), start_in_dir(toUTF16(mir_path)))); + _child = c; delete [] mir_path; - auto ec = wait_for_exit(*_child); - *aexitcode = ec; - _child = nullptr; } - + + file_descriptor_source source(pout.source, close_handle); stream<file_descriptor_source> is(source); @@ -102,11 +103,35 @@ pxResult pxExecute(std::vector<std::wstring> &aargv, string *aoutput, LPDWORD ae if(bDebugLog) debuglog<<std::string(time_str()+": failed to read from stream with error: " + e.what() + "\n\tSuccesfully read : " + *aoutput); } + + file_descriptor_source source2(perr.source, close_handle); + + stream<file_descriptor_source> is2(source2); + + try{ + std::string s; + while(std::getline(is2, s)) + { + aoutput->append(s); + aoutput->append("\n"); + } + } + catch(const std::exception &e) + { + if(bDebugLog) + debuglog<<std::string(time_str()+": failed to read from stream with error: " + e.what() + "\n\tSuccesfully read : " + *aoutput); + } + fix_line_term(*aoutput); if(bDebugLog) debuglog<<std::string(time_str()+": gpg out: "+*aoutput); + auto ec = wait_for_exit(*c); + delete c; + *aexitcode = ec; + _child = nullptr; + if(*aexitcode) { @@ -185,7 +210,7 @@ pxResult pxExecute_passwd_change(std::vector<std::wstring> &aargv, string *aoutp // file_descriptor_source sin(pin.source, close_handle); char *mir_path = new char [MAX_PATH]; - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + PathToAbsolute("\\", mir_path); //execute(set_args(argv), bind_stdout(sout), bind_stdin(sin), show_window(SW_HIDE), hide_console(), inherit_env(), set_env(env), start_in_dir(toUTF16(mir_path))); child c = execute(set_args(argv), /*bind_stdin(sin), */inherit_env(), set_env(env), start_in_dir(toUTF16(mir_path))); @@ -230,7 +255,7 @@ pxResult pxExecute_passwd_change(std::vector<std::wstring> &aargv, string *aoutp ctx.environment["LC_ALL"] = "English"; char *mir_path = new char [MAX_PATH]; - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + PathToAbsolute("\\", mir_path); ctx.work_directory = mir_path; delete [] mir_path; diff --git a/src/main.cpp b/src/main.cpp index a38ff2d..fa07f24 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -860,7 +860,7 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, bool gpg_exists = false, lang_exists = false; { char *mir_path = (char*)mir_alloc(sizeof(char) * MAX_PATH);
- CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + PathToAbsolute("\\", mir_path); SetCurrentDirectoryA(mir_path); tmp = mir_a2t(mir_path); mir_free(mir_path); @@ -888,20 +888,12 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, { tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", (SHGetValue(HKEY_CURRENT_USER, _T("Software\\GNU\\GnuPG"), _T("gpgProgram"), 0, path, &len) == ERROR_SUCCESS)?path:_T("")); if(tmp[0]) - { if(!boost::filesystem::exists(tmp))
- { MessageBox(0, TranslateT("wrong gpg binary location found in system.\nplease choose another location"), TranslateT("Warning"), MB_OK);
- } -/* char *mir_path = (char*)mir_alloc(MAX_PATH);
- CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path);
- SetCurrentDirectoryA(mir_path);
- mir_free(mir_path); */
- } } - else - tmp = mir_wstrdup(path); + else tmp = mir_wstrdup(path); mir_free(path);
+ SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp); bool bad_version = false; if(gpg_exists/* && lang_exists*/)
@@ -942,7 +934,7 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, {
mir_free(tmp);
char *mir_path = (char*)mir_alloc(sizeof(char) * MAX_PATH);
- CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path);
+ PathToAbsolute("\\", mir_path); strcat(mir_path, "\\gpg");
if(_access(mir_path, 0) != -1)
{
@@ -980,7 +972,7 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, char mir_path[MAX_PATH]; char *atmp = mir_t2a(tmp); mir_free(tmp); - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + PathToAbsolute("\\", mir_path); char* p_path = NULL; if(StriStr(atmp, mir_path)) { @@ -998,7 +990,7 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, char mir_path[MAX_PATH]; char *atmp = mir_t2a(tmp); mir_free(tmp); - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + PathToAbsolute("\\", mir_path); char* p_path = NULL; if(StriStr(atmp, mir_path)) { @@ -1015,7 +1007,7 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, if(tmp[0]) { char *mir_path = new char [MAX_PATH]; - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + PathToAbsolute("\\", mir_path); SetCurrentDirectoryA(mir_path); delete [] mir_path; if(!boost::filesystem::exists(tmp))
@@ -1093,7 +1085,7 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, if(tmp[0]) { char *mir_path = new char [MAX_PATH]; - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + PathToAbsolute("\\", mir_path); SetCurrentDirectoryA(mir_path); delete [] mir_path; if(!boost::filesystem::exists(tmp))
diff --git a/src/options.cpp b/src/options.cpp index 9028232..71bd6f3 100755 --- a/src/options.cpp +++ b/src/options.cpp @@ -1,4 +1,4 @@ -// Copyright © 2010-2012 sss
+// Copyright В© 2010-2012 sss
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
@@ -548,7 +548,7 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, char mir_path[MAX_PATH];
char *atmp = mir_t2a(tmp);
mir_free(tmp);
- CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path);
+ PathToAbsolute("\\", mir_path); char* p_path = NULL;
if(StriStr(atmp, mir_path))
{
@@ -566,7 +566,7 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, char mir_path[MAX_PATH];
char *atmp = mir_t2a(tmp);
mir_free(tmp);
- CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path);
+ PathToAbsolute("\\", mir_path); char* p_path = NULL;
if(StriStr(atmp, mir_path))
{
@@ -747,22 +747,15 @@ static INT_PTR CALLBACK DlgProcGpgAdvOpts(HWND hwndDlg, UINT msg, WPARAM wParam, HWND hPubKeyEdit = NULL;
-LONG_PTR default_edit_proc = NULL;
-
-static BOOL CALLBACK editctrl_ctrl_a(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
+static LRESULT CALLBACK editctrl_ctrl_a(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) {
- LRESULT ret = 0;
- switch(msg)
- {
+ switch(msg) { case WM_KEYDOWN:
if(wParam == 0x41 && GetKeyState(VK_CONTROL)< 0 )
SendMessage(hwndDlg, EM_SETSEL, 0, -1);
- break;
- default:
- ret = CallWindowProc((WNDPROC)default_edit_proc, hwndDlg, msg, wParam, lParam);
- break;
+ return 0; }
- return ret;
+ return mir_callNextSubclass(hwndDlg, editctrl_ctrl_a, msg, wParam, lParam); }
static INT_PTR CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
@@ -771,611 +764,601 @@ static INT_PTR CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam TCHAR *tmp = NULL;
wstring key_buf;
wstring::size_type ws1 = 0, ws2 = 0;
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- hContact = user_data[1];
- default_edit_proc = GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT), GWLP_WNDPROC);
- SetWindowPos(hwndDlg, 0, load_key_rect.left, load_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW);
- SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT), GWLP_WNDPROC, (LONG_PTR)editctrl_ctrl_a);
- HANDLE hcnt = hContact;
- if(metaIsProtoMetaContacts(hcnt))
- hcnt = metaGetMostOnline(hcnt);
- TranslateDialogDefault(hwndDlg);
- {
- string msg = Translate("Load Public GPG Key for ");
- msg += (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hcnt, 0);
- SetWindowTextA(hwndDlg, msg.c_str());
- }
- bool isContactSecured(HANDLE);
- if(!hcnt)
- {
- EnableWindow(GetDlgItem(hwndDlg, IDC_SELECT_EXISTING), 0);
- EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLE_ENCRYPTION), 0);
- }
- if(isContactSecured(hcnt))
- SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, TranslateT("Turn off encryption"));
- else
- {
- SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, TranslateT("Turn on encryption"));
- CheckDlgButton(hwndDlg, IDC_ENABLE_ENCRYPTION, 1);
- }
- if(hcnt)
+ switch (msg) { + case WM_INITDIALOG: {
- tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", _T(""));
- wstring str = tmp;
- mir_free(tmp); tmp = NULL;
- wstring::size_type p = 0, stop = 0;
- if(!str.empty())
+ hContact = user_data[1]; + SetWindowPos(hwndDlg, 0, load_key_rect.left, load_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); + mir_subclassWindow(GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT), editctrl_ctrl_a); + HANDLE hcnt = hContact; + if(metaIsProtoMetaContacts(hcnt)) + hcnt = metaGetMostOnline(hcnt); + TranslateDialogDefault(hwndDlg); {
- for(;;)
+ string msg = Translate("Load Public GPG Key for "); + msg += (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hcnt, 0); + SetWindowTextA(hwndDlg, msg.c_str()); + } + bool isContactSecured(HANDLE); + if(!hcnt) + { + EnableWindow(GetDlgItem(hwndDlg, IDC_SELECT_EXISTING), 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLE_ENCRYPTION), 0); + } + if(isContactSecured(hcnt)) + SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, TranslateT("Turn off encryption")); + else + { + SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, TranslateT("Turn on encryption")); + CheckDlgButton(hwndDlg, IDC_ENABLE_ENCRYPTION, 1); + } + if(hcnt) + { + tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", _T("")); + wstring str = tmp; + mir_free(tmp); tmp = NULL; + wstring::size_type p = 0, stop = 0; + if(!str.empty()) {
- if((p = str.find(_T("\n"), p+2)) != wstring::npos)
+ for(;;) {
- if(p > stop)
+ if((p = str.find(_T("\n"), p+2)) != wstring::npos) {
- stop = p;
- str.insert(p, _T("\r"));
- }
- else
- break;
+ 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; + std::vector<wstring> cmd; + cmd.push_back(L"--export"); + cmd.push_back(L"-a"); + cmd.push_back(toUTF16(hcontact_data[hcnt].key_in_prescense)); + gpg_execution_params params(cmd); + pxResult result; + params.out = &out; + params.code = &code; + params.result = &result; + gpg_launcher(params); //TODO: handle errors + if((out.find("-----BEGIN PGP PUBLIC KEY BLOCK-----") != string::npos) && (out.find("-----END PGP PUBLIC KEY BLOCK-----") != string::npos)) + { + 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 = Translate("Load Public GPG Key for "); + msg += (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hcnt, 0); + msg += " (Key ID: "; + msg += hcontact_data[hcnt].key_in_prescense; + msg += Translate(" found in prescense, and exists in keyring.)"); + SetWindowTextA(hwndDlg, msg.c_str()); + } + else + { + string msg = Translate("Load Public GPG Key (Key ID: "); + msg += hcontact_data[hcnt].key_in_prescense; + msg += Translate(" found in prescense.)"); + SetWindowTextA(hwndDlg, msg.c_str()); + EnableWindow(GetDlgItem(hwndDlg, IDC_IMPORT), 1); + } + } + mir_free(tmp2); + } + if(tmp) + mir_free(tmp); + SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, !str.empty()?str.c_str():_T("")); }
-// char *tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID_Prescense", "");
- if(!hcontact_data[hcnt].key_in_prescense.empty())
+ hPubKeyEdit = GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT); + return TRUE; + } + + case WM_COMMAND: + { + switch (LOWORD(wParam)) {
- char *tmp2 = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID", "");
- if(!tmp2[0])
+ case ID_OK: {
- string out;
- DWORD code;
- std::vector<wstring> cmd; - cmd.push_back(L"--export"); - cmd.push_back(L"-a"); - cmd.push_back(toUTF16(hcontact_data[hcnt].key_in_prescense)); - gpg_execution_params params(cmd); - pxResult result;
- params.out = &out;
- params.code = &code;
- params.result = &result;
- gpg_launcher(params); //TODO: handle errors - if((out.find("-----BEGIN PGP PUBLIC KEY BLOCK-----") != string::npos) && (out.find("-----END PGP PUBLIC KEY BLOCK-----") != string::npos))
+ 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) {
- string::size_type p = 0, stop = 0;
- for(;;)
+ 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 = (TCHAR*)mir_alloc(sizeof(TCHAR) * (_tcslen(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) + 1)); + _tcscpy(begin, _T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); + end = (TCHAR*)mir_alloc(sizeof( 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 = (TCHAR*)mir_alloc(sizeof(TCHAR) * (_tcslen(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) + 1)); + _tcscpy(begin, _T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); + end = (TCHAR*)mir_alloc(sizeof(TCHAR) * (_tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----")) + 1)); + _tcscpy(end, _T("-----END PGP PRIVATE KEY BLOCK-----")); + } + else + { + MessageBox(0, TranslateT("This is not public or private key"), _T("INFO"), MB_OK); + break; + } + ws2 += _tcslen(end); + bool allsubcontacts = false; + { + if(metaIsProtoMetaContacts(hContact)) {
- if((p = out.find("\n", p+2)) != string::npos)
+ HANDLE hcnt = NULL; + if(MessageBox(0, TranslateT("Do you want load key for all subcontacts ?"), TranslateT("Metacontact detected"), MB_YESNO) == IDYES) {
- if(p > stop)
+ allsubcontacts = true; + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) {
- stop = p;
- out.insert(p, "\r");
- }
- else
+ 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 = (TCHAR*)mir_alloc(sizeof( TCHAR) * (key_buf.length()+1)); + _tcscpy(tmp, key_buf.substr(ws1,ws2-ws1).c_str()); + { //gpg execute block + std::vector<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")); + boost::filesystem::remove(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.push_back(L"--batch"); + cmd.push_back(L"--import"); + cmd.push_back(tmp2); + } + gpg_execution_params params(cmd); + pxResult result; + params.out = &output; + params.code = &exitcode; + params.result = &result; + if(!gpg_launcher(params)) + 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, TranslateT("Key already in scret key ring."), TranslateT("Info"), MB_OK); + boost::filesystem::remove(tmp2); + break; + } + char *tmp2; + string::size_type s = output.find("gpg: key ") + strlen("gpg: key "); + string::size_type s2 = output.find(":", s); + tmp2 = (char*)mir_alloc((output.substr(s,s2-s).length()+1)*sizeof(char)); + 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; + bool uncommon = false; + if((s2 = output.find("(", s)) == string::npos) + { + if((s2 = output.find("<", s)) == string::npos) + { + s2 = output.find("”", s); + uncommon = true; + } + } + else if(s2 > output.find("<", s)) + s2 = output.find("<", s); + if(s2 != string::npos && s != string::npos) + { + tmp2 = (char*)mir_alloc(sizeof(char)*(output.substr(s,s2-s-(uncommon?1:0)).length()+1)); + strcpy(tmp2, output.substr(s,s2-s-(uncommon?1:0)).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(s != string::npos && s2 != string::npos) + { + if(output[s] == ')') + { + tmp2 = (char*)mir_alloc((output.substr(s2,s-s2).length()+1)*sizeof(char)); + 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 = (char*)mir_alloc(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; + std::vector<wstring> cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export"); + cmd.push_back(fp); + mir_free(fp); + gpg_execution_params params(cmd); + pxResult result; + params.out = &out; + params.code = &code; + params.result = &result; + if(!gpg_launcher(params)) 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()); }
}
- TCHAR *tmp3 = mir_a2t(out.c_str());
- str.clear();
- str.append(tmp3);
- string msg = Translate("Load Public GPG Key for ");
- msg += (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hcnt, 0);
- msg += " (Key ID: ";
- msg += hcontact_data[hcnt].key_in_prescense;
- msg += Translate(" found in prescense, and exists in keyring.)");
- SetWindowTextA(hwndDlg, msg.c_str());
+ tmp = mir_wstrdup(toUTF16(output).c_str()); + MessageBox(0, tmp, _T(""), MB_OK); + mir_free(tmp); + boost::filesystem::remove(tmp2); }
- else
+ key_buf.clear(); + if(IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ENCRYPTION)) {
- string msg = Translate("Load Public GPG Key (Key ID: ");
- msg += hcontact_data[hcnt].key_in_prescense;
- msg += Translate(" found in prescense.)");
- SetWindowTextA(hwndDlg, msg.c_str());
- EnableWindow(GetDlgItem(hwndDlg, IDC_IMPORT), 1);
+ 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); }
- mir_free(tmp2);
+ break; + case ID_LOAD_FROM_FILE: + { + tmp = GetFilePath(TranslateT("Set file containing GPG public key"), _T("*"), TranslateT("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, TranslateT("Failed to open file"), TranslateT("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(); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: Failed to read key file"); + 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, TranslateT("Where is no public or private key."), TranslateT("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; }
- if(tmp)
- mir_free(tmp);
- SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, !str.empty()?str.c_str():_T(""));
+ break; }
- 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 = (TCHAR*)mir_alloc(sizeof(TCHAR) * (_tcslen(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) + 1));
- _tcscpy(begin, _T("-----BEGIN PGP PUBLIC KEY BLOCK-----"));
- end = (TCHAR*)mir_alloc(sizeof( 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 = (TCHAR*)mir_alloc(sizeof(TCHAR) * (_tcslen(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) + 1));
- _tcscpy(begin, _T("-----BEGIN PGP PRIVATE KEY BLOCK-----"));
- end = (TCHAR*)mir_alloc(sizeof(TCHAR) * (_tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----")) + 1));
- _tcscpy(end, _T("-----END PGP PRIVATE KEY BLOCK-----"));
- }
- else
- {
- MessageBox(0, TranslateT("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, TranslateT("Do you want load key for all subcontacts ?"), TranslateT("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 = (TCHAR*)mir_alloc(sizeof( TCHAR) * (key_buf.length()+1));
- _tcscpy(tmp, key_buf.substr(ws1,ws2-ws1).c_str());
- { //gpg execute block
- std::vector<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"));
- boost::filesystem::remove(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.push_back(L"--batch"); - cmd.push_back(L"--import"); - cmd.push_back(tmp2); - }
- gpg_execution_params params(cmd); - pxResult result;
- params.out = &output;
- params.code = &exitcode;
- params.result = &result;
- if(!gpg_launcher(params)) - 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, TranslateT("Key already in scret key ring."), TranslateT("Info"), MB_OK);
- boost::filesystem::remove(tmp2); - break;
- }
- char *tmp2;
- string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
- string::size_type s2 = output.find(":", s);
- tmp2 = (char*)mir_alloc((output.substr(s,s2-s).length()+1)*sizeof(char));
- 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;
- bool uncommon = false;
- if((s2 = output.find("(", s)) == string::npos)
- {
- if((s2 = output.find("<", s)) == string::npos) - {
- s2 = output.find("”", s); - uncommon = true;
- }
- }
- else if(s2 > output.find("<", s))
- s2 = output.find("<", s);
- if(s2 != string::npos && s != string::npos)
- {
- tmp2 = (char*)mir_alloc(sizeof(char)*(output.substr(s,s2-s-(uncommon?1:0)).length()+1));
- strcpy(tmp2, output.substr(s,s2-s-(uncommon?1:0)).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(s != string::npos && s2 != string::npos)
- {
- if(output[s] == ')')
- {
- tmp2 = (char*)mir_alloc((output.substr(s2,s-s2).length()+1)*sizeof(char));
- 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 = (char*)mir_alloc(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;
- std::vector<wstring> cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"-a"); - cmd.push_back(L"--export"); - cmd.push_back(fp); - mir_free(fp);
- gpg_execution_params params(cmd); - pxResult result;
- params.out = &out;
- params.code = &code;
- params.result = &result;
- if(!gpg_launcher(params)) - 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);
- boost::filesystem::remove(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(TranslateT("Set file containing GPG public key"), _T("*"), TranslateT("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, TranslateT("Failed to open file"), TranslateT("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();
- if(bDebugLog) - debuglog<<std::string(time_str()+": info: Failed to read key file"); - 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, TranslateT("Where is no public or private key."), TranslateT("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_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);
- }
+ GetWindowRect(hwndDlg, &load_key_rect); + DBWriteContactSettingDword(NULL, szGPGModuleName, "LoadKeyWindowX", load_key_rect.left); + DBWriteContactSettingDword(NULL, szGPGModuleName, "LoadKeyWindowY", load_key_rect.top); break;
- }
+ } - return FALSE;
+ return FALSE; }
-
-
void ShowLoadPublicKeyDialog()
{
DialogBox(hInst, MAKEINTRESOURCE(IDD_LOAD_PUBLIC_KEY), NULL, DlgProcLoadPublicKey);
diff --git a/src/utilities.cpp b/src/utilities.cpp index 8a7e0b3..f27b07a 100755 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -1,4 +1,4 @@ -// Copyright © 2010-2012 sss +// Copyright В© 2010-2012 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -1184,7 +1184,7 @@ bool isGPGValid() mir_free(tmp); TCHAR *path = (TCHAR*)mir_alloc(sizeof(TCHAR)*MAX_PATH); char *mir_path = (char*)mir_alloc(MAX_PATH); - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + PathToAbsolute("\\", mir_path);
SetCurrentDirectoryA(mir_path); tmp = mir_a2t(mir_path); mir_free(mir_path); @@ -1862,7 +1862,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) mir_utf8decode(tmp2, 0); DBWriteContactSettingString(hContact, szGPGModuleName, "KeyID", tmp2); mir_free(tmp2); - s = output.find("“", s2); + s = output.find("“", s2);
if(s == string::npos) { s = output.find("\"", s2); @@ -1974,28 +1974,38 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) void fix_line_term(std::string &s)
{ + if(s.empty())
+ return;
boost::algorithm::erase_all(s, "\r\r");
} void fix_line_term(std::wstring &s) { + if(s.empty())
+ return;
boost::algorithm::erase_all(s, _T("\r\r"));
} void strip_line_term(std::wstring &s) {
+ if(s.empty())
+ return;
boost::algorithm::erase_all(s, _T("\r"));
boost::algorithm::erase_all(s, _T("\n"));
}
void strip_line_term(std::string &s) {
+ if(s.empty())
+ return;
boost::algorithm::erase_all(s, "\r");
boost::algorithm::erase_all(s, "\n");
}
void strip_tags(std::wstring &str)
{ + if(str.empty())
+ return;
boost::algorithm::erase_all(str, inopentag);
boost::algorithm::erase_all(str, inclosetag);
boost::algorithm::erase_all(str, outopentag);
@@ -2256,7 +2266,7 @@ void clean_temp_dir() {
using namespace boost::filesystem; char *mir_path = new char [MAX_PATH]; - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + PathToAbsolute("\\", mir_path);
wstring path = toUTF16(mir_path); SetCurrentDirectoryA(mir_path); delete [] mir_path; |