From 260ec979bf45846e404d6c1ba4792894f34ec521 Mon Sep 17 00:00:00 2001 From: Alexander Gluzsky Date: Sat, 2 Mar 2013 19:39:56 +0000 Subject: modified: plugins/New_GPG/src/gpg_wrapper.cpp modified: plugins/New_GPG/src/utilities.cpp git-svn-id: http://svn.miranda-ng.org/main/trunk@3853 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/New_GPG/src/gpg_wrapper.cpp | 26 +++++- plugins/New_GPG/src/utilities.cpp | 152 +++++++++++++++++++----------------- 2 files changed, 105 insertions(+), 73 deletions(-) (limited to 'plugins/New_GPG/src') diff --git a/plugins/New_GPG/src/gpg_wrapper.cpp b/plugins/New_GPG/src/gpg_wrapper.cpp index bfa359d69a..a031912b4d 100755 --- a/plugins/New_GPG/src/gpg_wrapper.cpp +++ b/plugins/New_GPG/src/gpg_wrapper.cpp @@ -70,13 +70,15 @@ pxResult pxExecute(std::vector &aargv, string *aoutput, LPDWORD ae pipe pout = create_pipe(); + pipe perr = create_pipe(); { file_descriptor_sink sout(pout.sink, close_handle); + file_descriptor_sink serr(perr.sink, close_handle); char *mir_path = new char [MAX_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 = 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; @@ -84,7 +86,8 @@ pxResult pxExecute(std::vector &aargv, string *aoutput, LPDWORD ae *aexitcode = ec; _child = nullptr; } - + + file_descriptor_source source(pout.source, close_handle); stream is(source); @@ -102,6 +105,25 @@ pxResult pxExecute(std::vector &aargv, string *aoutput, LPDWORD ae if(bDebugLog) debuglog< 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<hContact)) { char *proto = GetContactProto(ccs->hContact); - DWORD uin = DBGetContactSettingDword(ccs->hContact, proto, "UIN", 0); - bool cap_found = false, supported_proto = false; - if(uin) - { - char svc[64]; - strcpy(svc, proto); - strcat(svc, PS_ICQ_CHECKCAPABILITY); - if(ServiceExists(svc)) - { - supported_proto = true; - ICQ_CUSTOMCAP cap = {0}; - strcpy(cap.caps, "GPG FileTransfer"); - if(CallService(svc, (WPARAM)ccs->hContact, (LPARAM)&cap)) - cap_found = true; - } - } - else - { - TCHAR *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", _T("")); - if(jid[0]) - { - extern list Accounts; - list::iterator end = Accounts.end(); - for(list::iterator p = Accounts.begin(); p != end; p++) - { - TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid); - if(caps) - { - supported_proto = true; - wstring str; - for(int i=0;;i++) - { - str.push_back(caps[i]); - if(caps[i] == '\0') - if(caps[i+1] == '\0') - break; - } - mir_free(caps); - if(str.find(_T("GPG_Encrypted_FileTransfers:0")) != string::npos) - cap_found = true; - } - } - } - } - if(supported_proto && !cap_found) - { - if(MessageBox(0, TranslateT("Capability to decrypt file not found on other side\nRecipient may be unable to decrypt file(s)\nDo you want to encrypt file(s) anyway?"), TranslateT("Filetransfer warning"), MB_YESNO) == IDNO) - return CallService(MS_PROTO_CHAINSEND, w, l); - } - if(!supported_proto) - { - if(MessageBox(0, TranslateT("Unable to check encryption support on other side\nRecipient may be unable to decrypt file(s)\nCurrently capability check supported only for ICQ and Jabber protocols.\nIt will work for any other proto if Miranda with new_gpg used on other side.\nDo you want to encrypt file(s) anyway?"), TranslateT("Filetransfer warning"), MB_YESNO) == IDNO) - return CallService(MS_PROTO_CHAINSEND, w, l); - } + DWORD uin = DBGetContactSettingDword(ccs->hContact, proto, "UIN", 0); + bool cap_found = false, supported_proto = false; + if(uin) + { + char svc[64]; + strcpy(svc, proto); + strcat(svc, PS_ICQ_CHECKCAPABILITY); + if(ServiceExists(svc)) + { + supported_proto = true; + ICQ_CUSTOMCAP cap = {0}; + strcpy(cap.caps, "GPG FileTransfer"); + if(CallService(svc, (WPARAM)ccs->hContact, (LPARAM)&cap)) + cap_found = true; + } + } + else + { + TCHAR *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", _T("")); + if(jid[0]) + { + extern list Accounts; + list::iterator end = Accounts.end(); + for(list::iterator p = Accounts.begin(); p != end; p++) + { + TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid); + if(caps) + { + supported_proto = true; + wstring str; + for(int i=0;;i++) + { + str.push_back(caps[i]); + if(caps[i] == '\0') + if(caps[i+1] == '\0') + break; + } + mir_free(caps); + if(str.find(_T("GPG_Encrypted_FileTransfers:0")) != string::npos) + cap_found = true; + } + } + } + } + if(supported_proto && !cap_found) + { + if(MessageBox(0, TranslateT("Capability to decrypt file not found on other side\nRecipient may be unable to decrypt file(s)\nDo you want to encrypt file(s) anyway?"), TranslateT("Filetransfer warning"), MB_YESNO) == IDNO) + return CallService(MS_PROTO_CHAINSEND, w, l); + } + if(!supported_proto) + { + if(MessageBox(0, TranslateT("Unable to check encryption support on other side\nRecipient may be unable to decrypt file(s)\nCurrently capability check supported only for ICQ and Jabber protocols.\nIt will work for any other proto if Miranda with new_gpg used on other side.\nDo you want to encrypt file(s) anyway?"), TranslateT("Filetransfer warning"), MB_YESNO) == IDNO) + return CallService(MS_PROTO_CHAINSEND, w, l); + } HistoryLog(ccs->hContact, db_event(Translate("encrypting file for transfer"), 0, 0, DBEF_SENT)); DWORD flags = (DWORD)ccs->wParam; //check for PFTS_UNICODE here int i; @@ -1925,28 +1925,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); @@ -2118,17 +2128,17 @@ static INT_PTR CALLBACK DlgProcChangePasswd(HWND hwndDlg, UINT msg, WPARAM wPara old_pass_match = true; mir_free(pass); if(!old_pass_match) - { - if(key_id_global[0]) - { - string dbsetting = "szKey_"; - dbsetting += toUTF8(key_id_global); - dbsetting += "_Password"; - pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T("")); - if(!_tcscmp(pass,buf)) - old_pass_match = true; - mir_free(pass); - } + { + if(key_id_global[0]) + { + string dbsetting = "szKey_"; + dbsetting += toUTF8(key_id_global); + dbsetting += "_Password"; + pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T("")); + if(!_tcscmp(pass,buf)) + old_pass_match = true; + mir_free(pass); + } } if(!old_pass_match) { @@ -2205,12 +2215,12 @@ void ShowChangePasswdDlg() void clean_temp_dir() { - using namespace boost::filesystem; - char *mir_path = new char [MAX_PATH]; - PathToAbsolute("\\", mir_path); - wstring path = toUTF16(mir_path); - SetCurrentDirectoryA(mir_path); - delete [] mir_path; + using namespace boost::filesystem; + char *mir_path = new char [MAX_PATH]; + PathToAbsolute("\\", mir_path); + wstring path = toUTF16(mir_path); + SetCurrentDirectoryA(mir_path); + delete [] mir_path; TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); path += tmp; mir_free(tmp); -- cgit v1.2.3