summaryrefslogtreecommitdiff
path: root/messages.cpp
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2010-08-27 00:00:01 +0300
committerGluzskiy Alexandr <sss123next@list.ru>2010-08-27 00:00:01 +0300
commit26f425f0153de537bc676c9c38a68ef3edd882c5 (patch)
tree93f1177bfbc5f6e29bc4de2a64a476edf4264052 /messages.cpp
parentb06316ffd29888f749d927577e15ced4945cc5d0 (diff)
using threads, gpg execution timeout, fixed high cpu usage when waiting gpg process
Diffstat (limited to 'messages.cpp')
-rw-r--r--messages.cpp81
1 files changed, 73 insertions, 8 deletions
diff --git a/messages.cpp b/messages.cpp
index 78994e5..10be19f 100644
--- a/messages.cpp
+++ b/messages.cpp
@@ -154,29 +154,68 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
cmd += _T(" -d -a \"");
cmd += path;
cmd += _T("\"");
- //MessageBox(0, cmd.c_str(), _T("in"), MB_OK);
- if(pxExecute(&cmd, "", &out, &code) == pxNotFound)
+ gpg_execution_params params;
+ pxResult result;
+ params.cmd = &cmd;
+ params.useless = "";
+ params.out = &out;
+ params.code = &code;
+ params.result = &result;
+ HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)&params);
+ if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
+ {
+ TerminateThread(gpg_thread, 0);
+ MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
+ }
+ if(result == pxNotFound)
{
MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
DeleteFile(path.c_str());
return CallService(MS_PROTO_CHAINRECV, w, l);
}
- if(out.find("public key decryption failed: bad passphrase") != string::npos)
+ while(out.find("public key decryption failed: bad passphrase") != string::npos)
{
void ShowLoadKeyPasswordWindow();
ShowLoadKeyPasswordWindow();
+ wstring cmd2 = cmd;
if(password)
{
wstring tmp = _T("--passphrase \"");
tmp += password;
tmp += _T("\" ");
- cmd.insert(0, tmp);
+ cmd2.insert(0, tmp);
+ }
+ out.clear();
+ gpg_execution_params params;
+ pxResult result;
+ params.cmd = &cmd2;
+ params.useless = "";
+ params.out = &out;
+ params.code = &code;
+ params.result = &result;
+ HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)&params);
+ if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
+ {
+ TerminateThread(gpg_thread, 0);
+ MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
+ }
+ if(result == pxNotFound)
+ {
+ MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
+ DeleteFile(path.c_str());
+ return CallService(MS_PROTO_CHAINRECV, w, l);
}
}
out.clear();
- if(pxExecute(&cmd, "", &out, &code) == pxNotFound)
+ gpg_thread = mir_forkthread(pxEexcute_thread, (void*)&params);
+ if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
{
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
+ TerminateThread(gpg_thread, 0);
+ MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
+ }
+ if(result == pxNotFound)
+ {
+ MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
DeleteFile(path.c_str());
return CallService(MS_PROTO_CHAINRECV, w, l);
}
@@ -319,7 +358,20 @@ int SendMsgSvc(WPARAM w, LPARAM l)
mir_free(tmp);
f.close();
}
- if(pxExecute(&cmd, "", &out, &code) == pxNotFound)
+ gpg_execution_params params;
+ pxResult result;
+ params.cmd = &cmd;
+ params.useless = "";
+ params.out = &out;
+ params.code = &code;
+ params.result = &result;
+ HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)&params);
+ if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
+ {
+ TerminateThread(gpg_thread, 0);
+ MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
+ }
+ if(result == pxNotFound)
{
MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
return CallService(MS_PROTO_CHAINSEND, w, l);
@@ -331,7 +383,20 @@ int SendMsgSvc(WPARAM w, LPARAM l)
{
DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "bAlwaysTrust", 1);
cmd.insert(0, _T("--trust-model always "));
- if(pxExecute(&cmd, "", &out, &code) == pxNotFound)
+ gpg_execution_params params;
+ pxResult result;
+ params.cmd = &cmd;
+ params.useless = "";
+ params.out = &out;
+ params.code = &code;
+ params.result = &result;
+ HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)&params);
+ if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
+ {
+ TerminateThread(gpg_thread, 0);
+ MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
+ }
+ if(result == pxNotFound)
{
MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
return CallService(MS_PROTO_CHAINSEND, w, l);