diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2011-04-01 10:14:07 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2011-04-01 10:14:07 +0300 |
commit | 77664979ae7f2e534e31f66aa9286d874d9da2bc (patch) | |
tree | 854290346b15a887b2a6005bde46e912089615ce | |
parent | 21f2c63d296d4cdf534de24a216811b4c4b744fc (diff) |
modified: gpg_wrapper.cpp
modified: gpg_wrapper.h
modified: main.cpp
modified: messages.cpp
modified: options.cpp
modified: utilities.cpp
-rw-r--r-- | gpg_wrapper.cpp | 6 | ||||
-rw-r--r-- | gpg_wrapper.h | 1 | ||||
-rw-r--r-- | main.cpp | 19 | ||||
-rw-r--r-- | messages.cpp | 11 | ||||
-rw-r--r-- | options.cpp | 5 | ||||
-rw-r--r-- | utilities.cpp | 20 |
6 files changed, 51 insertions, 11 deletions
diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp index 3ed7f4a..0a50667 100644 --- a/gpg_wrapper.cpp +++ b/gpg_wrapper.cpp @@ -21,7 +21,7 @@ //boost::mutex gpg_mutex; -pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result, HANDLE hProcess) +pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result, HANDLE hProcess, PROCESS_INFORMATION *pr) { // gpg_mutex.lock(); if(!gpg_configured) @@ -122,6 +122,8 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD while (TRUE) { + if(!pri.hProcess) + break; success=GetExitCodeProcess(pri.hProcess,aexitcode); if (success && *aexitcode!=STILL_ACTIVE) break; @@ -157,5 +159,5 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD void pxEexcute_thread(void *param) { gpg_execution_params *params = (gpg_execution_params*)param; - pxResult result = pxExecute(params->cmd, params->useless, params->out, params->code, params->result, params->hProcess); + pxResult result = pxExecute(params->cmd, params->useless, params->out, params->code, params->result, params->hProcess, params->proc); } diff --git a/gpg_wrapper.h b/gpg_wrapper.h index f9d6670..77f84f8 100644 --- a/gpg_wrapper.h +++ b/gpg_wrapper.h @@ -25,6 +25,7 @@ struct gpg_execution_params LPDWORD code;
pxResult *result;
HANDLE hProcess;
+ PROCESS_INFORMATION *proc;
};
void pxEexcute_thread(void *param);
@@ -95,6 +95,7 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } @@ -189,6 +190,7 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } @@ -258,6 +260,7 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } @@ -330,6 +333,7 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM { delete gpg_thread; TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } @@ -358,6 +362,7 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM { delete gpg_thread; TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } @@ -423,6 +428,7 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted"; break; } @@ -454,6 +460,7 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<"GPG execution timed out, aborted\n"; break; } @@ -591,6 +598,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; } gpg_configured = false; @@ -709,6 +717,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; gpg_thread.~thread(); debuglog<<time_str()<<": GPG execution timed out, aborted\n"; } @@ -797,6 +806,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; gpg_thread.~thread(); debuglog<<time_str()<<": GPG execution timed out, aborted\n"; } @@ -889,6 +899,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted"; gpg_configured = false; break; @@ -922,6 +933,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<"GPG execution timed out, aborted\n"; gpg_configured = false; break; @@ -1238,6 +1250,7 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; @@ -1271,6 +1284,7 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } @@ -1432,6 +1446,7 @@ static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam, { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } @@ -1540,6 +1555,7 @@ static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam, { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } @@ -1650,6 +1666,7 @@ static BOOL CALLBACK DlgProcImportKeyDialog(HWND hwndDlg, UINT msg, WPARAM wPara { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; } MessageBoxA(0, out.c_str(), "GPG output", MB_OK); @@ -1771,6 +1788,7 @@ void InitCheck() { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; return; } @@ -1883,6 +1901,7 @@ void ImportKey() { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; return; } diff --git a/messages.cpp b/messages.cpp index f421e4a..88a9097 100644 --- a/messages.cpp +++ b/messages.cpp @@ -36,7 +36,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) void setSrmmIcon(HANDLE); void setClistIcon(HANDLE); bool isContactHaveKey(HANDLE hContact); - if(!DBGetContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0)) + if(!isContactSecured(hContact)) { debuglog<<time_str()<<": info: "<<"received message from: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" whith tyrned off encryption\n"; if(MessageBox(0, _T("We received encrypted message from contact with encryption turned off.\nDo you want turn on encryption for this contact ?"), _T("Warning"), MB_YESNO) == IDYES) @@ -157,6 +157,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) { delete gpg_thread; TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; DeleteFile(path.c_str()); HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); @@ -207,6 +208,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) { delete gpg_thread; TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; DeleteFile(path.c_str()); HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); @@ -225,6 +227,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) { delete gpg_thread; TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; DeleteFile(path.c_str()); HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); @@ -302,7 +305,8 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) char *msg = mir_strdup(toUTF8(str).c_str()); HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags|DBEF_READ); HistoryLog(metaGetContact(hContact), msg, EVENTTYPE_MESSAGE, dbflags); - return 1; + mir_free(msg); + return 0; } char *tmp = mir_strdup(toUTF8(str).c_str()); HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, dbflags); @@ -389,6 +393,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; return 1; } @@ -643,6 +648,7 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; mir_free(msg); return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); @@ -671,6 +677,7 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; mir_free(msg); return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); diff --git a/options.cpp b/options.cpp index 04cb56b..c9b9de7 100644 --- a/options.cpp +++ b/options.cpp @@ -257,6 +257,7 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA {
gpg_thread.~thread();
TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
mir_free(tmp);
break;
@@ -466,6 +467,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP {
gpg_thread.~thread();
TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
}
DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp_path);
mir_free(tmp_path);
@@ -712,6 +714,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP {
gpg_thread.~thread();
TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
}
if((out.find("-----BEGIN PGP PUBLIC KEY BLOCK-----") != string::npos) && (out.find("-----END PGP PUBLIC KEY BLOCK-----") != string::npos))
@@ -864,6 +867,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP {
gpg_thread.~thread();
TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
break;
}
@@ -1100,6 +1104,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP {
gpg_thread.~thread();
TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
break;
}
diff --git a/utilities.cpp b/utilities.cpp index 8d33d4b..c8dc2ae 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -380,6 +380,7 @@ int onProtoAck(WPARAM w, LPARAM l) { delete gpg_thread; TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; return 0; } @@ -424,6 +425,7 @@ int onProtoAck(WPARAM w, LPARAM l) { delete gpg_thread; TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; DeleteFile(filename); return 0; @@ -490,6 +492,7 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename) { delete gpg_thread; TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; return 0; } @@ -505,6 +508,7 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename) { delete gpg_thread; TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; return 0; } @@ -771,6 +775,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<"GPG execution timed out, aborted\n"; } DeleteFile(path_out.c_str()); @@ -899,17 +904,15 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; -// sign_file_mutex.unlock(); return FALSE; } if(result == pxNotFound) { -// sign_file_mutex.unlock(); return FALSE; } DeleteFile(path_out.c_str()); -// sign_file_mutex.unlock(); if(out.find("key ID ") != string::npos) { //need to get hcontact here, i can get jid from hxml, and get handle from jid, maybe exists better way ? @@ -981,13 +984,16 @@ bool isContactSecured(HANDLE hContact) debuglog<<time_str()<<": encryption is turned of for "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"\n"; return false; } - TCHAR *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); - if(!key[0] && !metaIsProtoMetaContacts(hContact)) + if(!metaIsProtoMetaContacts(hContact)) { + TCHAR *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); + if(!key[0]) + { + mir_free(key); + return false; + } mir_free(key); - return false; } - mir_free(key); return true; } |