From a6b928a9afdad2e0ce5ac8ae897f6e13670cb80b Mon Sep 17 00:00:00 2001 From: Alexander Gluzsky Date: Sat, 23 Apr 2016 09:53:31 +0000 Subject: plugins: new_gpg: additional sanity checks keep temporary files when debug is turned on git-svn-id: http://svn.miranda-ng.org/main/trunk@16752 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/New_GPG/src/messages.cpp | 149 +++++++++++++++++++++++++++++++++------ plugins/New_GPG/src/options.cpp | 13 +--- 2 files changed, 129 insertions(+), 33 deletions(-) diff --git a/plugins/New_GPG/src/messages.cpp b/plugins/New_GPG/src/messages.cpp index ccf1ca67bb..e1cf4ba1aa 100755 --- a/plugins/New_GPG/src/messages.cpp +++ b/plugins/New_GPG/src/messages.cpp @@ -75,11 +75,31 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR wstring decfile = toUTF16(get_random(10)); { wstring path = wstring(ptszHomePath) + _T("\\tmp\\") + encfile; - boost::filesystem::remove(path); + if(!bDebugLog) { + boost::system::error_code e; + boost::filesystem::remove(path, e); + } + + { + const int timeout = 5000, step = 100; + int count = 0; + fstream f(path.c_str(), std::ios::out); while (!f.is_open()) + { + boost::this_thread::sleep(boost::posix_time::milliseconds(step)); + count += step; + if(count >= timeout) + { + db_set_b(hContact, szGPGModuleName, "GPGEncryption", 0); + setSrmmIcon(hContact); + setClistIcon(hContact); + debuglog<= timeout) + { + db_set_b(ccs->hContact, szGPGModuleName, "GPGEncryption", 0); + setSrmmIcon(ccs->hContact); + setClistIcon(ccs->hContact); + debuglog<hContact, szGPGModuleName, "GPGPubKey", _T("")); f << (TCHAR*)ptmp; f.close(); @@ -388,7 +473,11 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) params.result = &result; if (!gpg_launcher(params)) return 1; - boost::filesystem::remove(tmp2); + if(!bDebugLog) + { + boost::system::error_code e; + boost::filesystem::remove(tmp2, e); + } if (result == pxNotFound) return 1; if (result == pxSuccessExitCodeInvalid) @@ -682,17 +771,29 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags) if (result == pxSuccessExitCodeInvalid) { //mir_free(msg); HistoryLog(hContact, db_event(Translate("failed to encrypt message, GPG returned error, turn on debug log for more details"), 0, 0, DBEF_SENT)); - boost::filesystem::remove(path); + if(!bDebugLog) + { + boost::system::error_code e; + boost::filesystem::remove(path, e); + } return; } if (out.find("usage: ") != string::npos) { MessageBox(0, TranslateT("Something is wrong, GPG does not understand us, aborting encryption."), TranslateT("Warning"), MB_OK); //mir_free(msg); CallContactService(hContact, PSS_MESSAGE, flags, (LPARAM)msg); - boost::filesystem::remove(path); + if(!bDebugLog) + { + boost::system::error_code e; + boost::filesystem::remove(path, e); + } return; } - boost::filesystem::remove(path); + if(!bDebugLog) + { + boost::system::error_code e; + boost::filesystem::remove(path, e); + } path.append(_T(".asc")); wfstream f(path.c_str(), std::ios::in | std::ios::ate | std::ios::binary); count = 0; @@ -719,7 +820,11 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags) str.append(tmp); delete[] tmp; f.close(); - boost::filesystem::remove(path); + if(!bDebugLog) + { + boost::system::error_code e; + boost::filesystem::remove(path, e); + } } if (str.empty()) { HistoryLog(hContact, db_event("Failed to encrypt message with GPG", 0, 0, DBEF_SENT)); diff --git a/plugins/New_GPG/src/options.cpp b/plugins/New_GPG/src/options.cpp index 8b48874774..1a76b727f0 100755 --- a/plugins/New_GPG/src/options.cpp +++ b/plugins/New_GPG/src/options.cpp @@ -711,17 +711,8 @@ static INT_PTR CALLBACK DlgProcLoadPublicKey(HWND hwndDlg, UINT uMsg, WPARAM wPa 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; - } - } + boost::algorithm::replace_all(out, "\n", "\r\n"); + TCHAR *tmp3 = mir_a2t(out.c_str()); str.clear(); str.append(tmp3); -- cgit v1.2.3