summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gluzsky <sss123next@list.ru>2013-03-02 19:39:56 +0000
committerAlexander Gluzsky <sss123next@list.ru>2013-03-02 19:39:56 +0000
commit260ec979bf45846e404d6c1ba4792894f34ec521 (patch)
tree54ea12de752ab72cc4e428f64ff39f692fe984fe
parent55f3f8ff12e1a7388706b8ccdae139ca946742dc (diff)
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
-rwxr-xr-xplugins/New_GPG/src/gpg_wrapper.cpp26
-rwxr-xr-xplugins/New_GPG/src/utilities.cpp152
2 files changed, 105 insertions, 73 deletions
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<std::wstring> &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<std::wstring> &aargv, string *aoutput, LPDWORD ae
*aexitcode = ec;
_child = nullptr;
}
-
+
+
file_descriptor_source source(pout.source, close_handle);
stream<file_descriptor_source> is(source);
@@ -102,6 +105,25 @@ 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(pout.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)
diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp
index b6e7cc8fc4..c0ef7ab162 100755
--- a/plugins/New_GPG/src/utilities.cpp
+++ b/plugins/New_GPG/src/utilities.cpp
@@ -541,60 +541,60 @@ int onSendFile(WPARAM w, LPARAM l)
if(isContactSecured(ccs->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 <JabberAccount*> Accounts;
- list<JabberAccount*>::iterator end = Accounts.end();
- for(list<JabberAccount*>::iterator p = Accounts.begin(); p != end; p++)
- {
- TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid);
- if(caps)
- {
- 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 <JabberAccount*> Accounts;
+ list<JabberAccount*>::iterator end = Accounts.end();
+ for(list<JabberAccount*>::iterator p = Accounts.begin(); p != end; p++)
+ {
+ TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid);
+ if(caps)
+ {
+ 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);