diff options
Diffstat (limited to 'src')
-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 |
6 files changed, 647 insertions, 635 deletions
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; |