diff options
-rw-r--r-- | commonheaders.h | 1 | ||||
-rw-r--r-- | globals.h | 4 | ||||
-rw-r--r-- | gpg_wrapper.cpp | 8 | ||||
-rw-r--r-- | gpg_wrapper.h | 3 | ||||
-rw-r--r-- | init.cpp | 1 | ||||
-rw-r--r-- | jabber_account.h | 2 | ||||
-rw-r--r-- | log.cpp | 1 | ||||
-rw-r--r-- | main.cpp | 76 | ||||
-rw-r--r-- | messages.cpp | 49 | ||||
-rw-r--r-- | options.cpp | 21 | ||||
-rw-r--r-- | utilities.cpp | 49 | ||||
-rw-r--r-- | utilities.h | 1 |
12 files changed, 78 insertions, 138 deletions
diff --git a/commonheaders.h b/commonheaders.h index 57ba0af..990497b 100644 --- a/commonheaders.h +++ b/commonheaders.h @@ -47,6 +47,7 @@ using std::fstream; #include <boost/nondet_random.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/random/uniform_int.hpp>
+#include <boost/date_time.hpp>
//utf8cpp @@ -1,4 +1,4 @@ -// Copyright © 2010 sss, chaos.persei +// Copyright © 2010 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -16,7 +16,7 @@ #ifndef GLOBALS_H #define GLOBALS_H -extern bool bAppendTags; +extern bool bAppendTags, gpg_configured; extern TCHAR *inopentag, *inclosetag, *outopentag, *outclosetag; extern logtofile debuglog; #endif diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp index 04f3512..8ab32a3 100644 --- a/gpg_wrapper.cpp +++ b/gpg_wrapper.cpp @@ -24,6 +24,8 @@ boost::mutex gpg_mutex; pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result) { gpg_mutex.lock(); + if(!gpg_configured) + return pxNotConfigured; extern logtofile debuglog; BOOL success; STARTUPINFO sinfo = {0}; @@ -97,7 +99,7 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD delete [] home_dir; } - debuglog<<"gpg in: "<<commandline<<"\n"; + debuglog<<time_str()<<": gpg in: "<<commandline; success = CreateProcess(NULL, (TCHAR*)commandline.c_str(), NULL, NULL, TRUE, CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT, (void*)_T("LANGUAGE=en@quot\0LC_ALL=English\0"), NULL, &sinfo, &pri); @@ -134,7 +136,7 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD storeOutput(readstdout,aoutput); - debuglog<<"gpg out: "<<aoutput->c_str()<<"\n"; + debuglog<<time_str()<<": gpg out: "<<aoutput->c_str(); WaitForSingleObject(pri.hProcess,INFINITE); @@ -155,6 +157,6 @@ void pxEexcute_thread(void *param) pxResult result = pxExecute(params->cmd, params->useless, params->out, params->code, params->result); if(result == pxNotFound) { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + debuglog<<time_str()<<": Gpg binary not found"; } }
diff --git a/gpg_wrapper.h b/gpg_wrapper.h index 5d0ce2a..52b3c1c 100644 --- a/gpg_wrapper.h +++ b/gpg_wrapper.h @@ -10,7 +10,8 @@ typedef enum { pxThreadWaitFailed, pxReadFileFailed, pxBufferOverflow, - pxNotFound + pxNotFound, + pxNotConfigured } pxResult; @@ -32,6 +32,7 @@ MM_INTERFACE mmi = {0}; UTF8_INTERFACE utfi = {0}; XML_API xi = {0}; logtofile debuglog; +bool gpg_configured = false; std::map<HANDLE, contact_data> hcontact_data; diff --git a/jabber_account.h b/jabber_account.h index 3f2f6a9..490ea63 100644 --- a/jabber_account.h +++ b/jabber_account.h @@ -1,4 +1,4 @@ -// Copyright © 2010 sss, chaos.persei +// Copyright © 2010 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -16,6 +16,7 @@ #include "commonheaders.h" + logtofile& logtofile::operator<<(TCHAR *buf) { extern bool bDebugLog; @@ -93,14 +93,11 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); break; - } } while(p != string::npos) { @@ -189,14 +186,11 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); break; - } string::size_type s = 0; while((s = out.find("\r", s)) != string::npos) { @@ -226,6 +220,7 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM delete [] name; } bAutoExchange = CheckStateStoreDB(hwndDlg, IDC_AUTO_EXCHANGE, "bAutoExchange"); + gpg_configured = isGPGConfigured(); DestroyWindow(hwndDlg); break; case IDC_OTHER: @@ -260,14 +255,11 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); break; - } } while(p != string::npos) { @@ -334,14 +326,11 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM if(!gpg_thread->timed_join(boost::posix_time::seconds(10))) { delete gpg_thread; - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); break; - } string::size_type s = out.find("Key fingerprint = "); s += strlen("Key fingerprint = "); string::size_type s2 = out.find("\n", s); @@ -364,14 +353,11 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM if(!gpg_thread->timed_join(boost::posix_time::seconds(10))) { delete gpg_thread; - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); break; - } } DBDeleteContactSetting(NULL, szGPGModuleName, "GPGPubKey"); DBDeleteContactSetting(NULL, szGPGModuleName, "KeyID"); @@ -431,14 +417,12 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM if(!gpg_thread.timed_join(boost::posix_time::minutes(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted"; break; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); break; - } + DeleteFile(path.c_str()); string::size_type p1 = 0; if((p1 = out.find("key ")) != string::npos) @@ -463,14 +447,11 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<"GPG execution timed out, aborted\n"; break; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); break; - } string::size_type s = 0; while((s = out.find("\r", s)) != string::npos) { @@ -1064,14 +1045,11 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); break; - } } ListView_DeleteAllItems(hwndList_g); while(p != string::npos) @@ -1215,14 +1193,11 @@ static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam, if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); break; - } } while(p != string::npos) { @@ -1294,14 +1269,11 @@ static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam, if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); break; - } string::size_type s = 0; while((s = out.find("\r", s)) != string::npos) { @@ -1400,11 +1372,7 @@ static BOOL CALLBACK DlgProcImportKeyDialog(HWND hwndDlg, UINT msg, WPARAM wPara if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - 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); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; } MessageBoxA(0, out.c_str(), "GPG output", MB_OK); } @@ -1500,12 +1468,9 @@ void FirstRun() void InitCheck() { {//parse gpg output - char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); - if(strlen(keyid) < 1) - { - mir_free(keyid); + gpg_configured = isGPGConfigured(); + if(!gpg_configured) return; - } string out; DWORD code; pxResult result; @@ -1522,16 +1487,14 @@ void InitCheck() if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; return; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); return; - } } string question = "Your secret key whith id: "; + char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); question += keyid; mir_free(keyid); question += " deleted from gpg secret keyring\nDo you want to set another key ?"; @@ -1628,14 +1591,11 @@ void ImportKey() if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; return; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); return; - } { if(metaIsProtoMetaContacts(hContact)) { diff --git a/messages.cpp b/messages.cpp index d1ee06d..92bdb78 100644 --- a/messages.cpp +++ b/messages.cpp @@ -85,14 +85,11 @@ int RecvMsgSvc(WPARAM w, LPARAM l) if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
{
gpg_thread.~thread();
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
+ debuglog<<time_str()<<": GPG execution timed out, aborted\n";
return 1;
}
if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
return 1;
- } {
char *tmp = NULL;
string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
@@ -165,7 +162,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) { //this is public key if(metaIsSubcontact(hContact)) return CallService(MS_PROTO_CHAINRECV, w, l); //yet another metacontacts problem - debuglog<<"info: "<<"received key from: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"\n"; + debuglog<<time_str()<<": info: "<<"received key from: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"\n"; s1 = 0; while((s1 = str.find(_T("\r"), s1)) != wstring::npos) { @@ -255,7 +252,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) bool isContactHaveKey(HANDLE hContact); if(!DBGetContactSettingByte(metaGetCurrent(hContact), szGPGModuleName, "GPGEncryption", 0)) { - debuglog<<"info: "<<"received message from: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" whith tyrned off encryption\n"; + 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) { if(!isContactHaveKey(hContact)) @@ -314,13 +311,13 @@ int RecvMsgSvc(WPARAM w, LPARAM l) dbsetting += "_Password"; pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T("")); if(_tcslen(pass) > 0) - debuglog<<"info: found password in database for key id: "<<inkeyid<<", trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" with password\n"; + debuglog<<time_str()<<": info: found password in database for key id: "<<inkeyid<<", trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" with password\n"; } else { pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); if(_tcslen(pass) > 0) - debuglog<<"info: found password for all keys in database, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" with password\n"; + debuglog<<time_str()<<": info: found password for all keys in database, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" with password\n"; } if(_tcslen(pass) > 0) { @@ -330,13 +327,13 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } else if(password) { - debuglog<<"info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" with password\n"; + debuglog<<time_str()<<": info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" with password\n"; cmd += _T("--passphrase \""); cmd += password; cmd += _T("\" "); } else - debuglog<<"info: passwords not found in database or memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" with out password\n"; + debuglog<<time_str()<<": info: passwords not found in database or memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" with out password\n"; mir_free(pass); mir_free(inkeyid); } @@ -362,19 +359,19 @@ int RecvMsgSvc(WPARAM w, LPARAM l) if(!gpg_thread->timed_join(boost::posix_time::seconds(10))) { delete gpg_thread; - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; + DeleteFile(path.c_str()); return CallService(MS_PROTO_CHAINRECV, w, l); } 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); } _terminate = false; while(out.find("public key decryption failed: bad passphrase") != string::npos) { - debuglog<<"info: failed to decrypt messaage from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" password needed, trying to get one\n"; + debuglog<<time_str()<<": info: failed to decrypt messaage from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" password needed, trying to get one\n"; if(_terminate) break; { //save inkey id @@ -391,7 +388,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) wstring cmd2 = cmd; if(password) { - debuglog<<"info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"\n"; + debuglog<<time_str()<<": info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"\n"; wstring tmp = _T("--passphrase \""); tmp += password; tmp += _T("\" "); @@ -409,12 +406,12 @@ int RecvMsgSvc(WPARAM w, LPARAM l) if(!gpg_thread->timed_join(boost::posix_time::seconds(10))) { delete gpg_thread; - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; + DeleteFile(path.c_str()); return CallService(MS_PROTO_CHAINRECV, w, l); } 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); } @@ -424,12 +421,12 @@ int RecvMsgSvc(WPARAM w, LPARAM l) if(!gpg_thread->timed_join(boost::posix_time::seconds(10))) { delete gpg_thread; - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; + DeleteFile(path.c_str()); return CallService(MS_PROTO_CHAINRECV, w, l); } 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); } @@ -448,7 +445,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) string str = pre->szMessage; mir_free((void**)pre->szMessage); str.insert(0, "Received unencrypted message:\n"); - debuglog<<"info: Failed to decrypt GPG encrypted message.\n"; + debuglog<<time_str()<<": info: Failed to decrypt GPG encrypted message.\n"; char *tmp = new char [str.length()+1]; strcpy(tmp, str.c_str()); pre->szMessage = tmp; @@ -482,7 +479,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) string str = pre->szMessage; mir_free((void**)pre->szMessage); str.insert(0, "Received unencrypted message:\n"); - debuglog<<"info: Failed to decrypt GPG encrypted message.\n"; + debuglog<<time_str()<<": info: Failed to decrypt GPG encrypted message.\n"; pre->szMessage = mir_strdup(str.c_str()); return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); } @@ -653,14 +650,11 @@ int SendMsgSvc(WPARAM w, LPARAM l) if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; return CallService(MS_PROTO_CHAINSEND, w, l); } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); return CallService(MS_PROTO_CHAINSEND, w, l); - } if(out.find("There is no assurance this key belongs to the named user") != string::npos) { out.clear(); @@ -679,14 +673,11 @@ int SendMsgSvc(WPARAM w, LPARAM l) if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; return CallService(MS_PROTO_CHAINSEND, w, l); } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); return CallService(MS_PROTO_CHAINSEND, w, l); - } } else return 0; @@ -716,7 +707,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) if(str.empty()) { HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT); - debuglog<<"info: Failed to encrypt message with GPG"; + debuglog<<time_str()<<": info: Failed to encrypt message with GPG"; return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); } if(metaIsSubcontact(hContact)) diff --git a/options.cpp b/options.cpp index 246be86..ab12158 100644 --- a/options.cpp +++ b/options.cpp @@ -255,13 +255,12 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; mir_free(tmp); break; } if(result == pxNotFound) { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); mir_free(tmp); break; } @@ -697,11 +696,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - 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); + 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)) { @@ -850,14 +845,11 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); break; - } mir_free(begin); mir_free(end); if(hContact) @@ -1088,14 +1080,11 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; break; } if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); break; - } string::size_type s = 0; while((s = out.find("\r", s)) != string::npos) { @@ -1178,7 +1167,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP if(key_buf.empty()) { key_buf.clear(); - debuglog<<"info: Failed to read key file\n"; + debuglog<<time_str()<<": info: Failed to read key file\n"; break; } ws2 = key_buf.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); diff --git a/utilities.cpp b/utilities.cpp index d281283..c1bb062 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -340,12 +340,8 @@ int onProtoAck(WPARAM w, LPARAM l) if(!gpg_thread->timed_join(boost::posix_time::minutes(10))) { delete gpg_thread; - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; } - if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); - }
DeleteFile(filename);
mir_free(filename);
}
@@ -408,11 +404,7 @@ int onSendFile(WPARAM w, LPARAM l) if(!gpg_thread->timed_join(boost::posix_time::minutes(10))) { delete gpg_thread; - 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); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; } mir_free(file[i]);
file[i]=mir_wstrdup(path_out.c_str());
@@ -561,7 +553,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU { if(errno == ENOENT) { - debuglog<<"info: Failed to write prescense in file\n"; + debuglog<<time_str()<<": info: Failed to write prescense in file\n"; return FALSE; } } @@ -580,13 +572,13 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU dbsetting += "_Password"; pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T("")); if(pass[0]) - debuglog<<"info: found password in database for key id: "<<inkeyid<<", trying to encrypt message from self with password\n"; + debuglog<<time_str()<<": info: found password in database for key id: "<<inkeyid<<", trying to encrypt message from self with password\n"; } else { pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); if(pass[0]) - debuglog<<"info: found password for all keys in database, trying to encrypt message from self with password\n"; + debuglog<<time_str()<<": info: found password for all keys in database, trying to encrypt message from self with password\n"; } if(pass[0]) { @@ -596,13 +588,13 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU } else if(password) { - debuglog<<"info: found password in memory, trying to encrypt message from self with password\n"; + debuglog<<time_str()<<": info: found password in memory, trying to encrypt message from self with password\n"; cmd += _T("--passphrase \""); cmd += password; cmd += _T("\" "); } else - debuglog<<"info: passwords not found in database or memory, trying to encrypt message from self with out password\n"; + debuglog<<time_str()<<": info: passwords not found in database or memory, trying to encrypt message from self with out password\n"; mir_free(pass); mir_free(inkeyid); } @@ -626,11 +618,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - 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); + debuglog<<time_str()<<"GPG execution timed out, aborted\n"; } DeleteFile(path_out.c_str()); path_out += _T(".asc"); @@ -650,7 +638,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU } if(data.empty()) { - debuglog<<"info: Failed to read prescense sign from file\n"; + debuglog<<time_str()<<": info: Failed to read prescense sign from file\n"; return FALSE; } if(data.find(_T("-----BEGIN PGP MESSAGE-----")) != wstring::npos && data.find(_T("-----END PGP MESSAGE-----")) != wstring::npos) @@ -732,7 +720,7 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi if(errno == ENOENT) { sign_file_mutex.unlock(); - debuglog<<"info: Failed to write sign in file\n"; + debuglog<<time_str()<<": info: Failed to write sign in file\n"; return FALSE; } } @@ -753,14 +741,13 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { gpg_thread.~thread(); - MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; + return FALSE; } + if(result == pxNotFound) + return FALSE; DeleteFile(path_out.c_str()); sign_file_mutex.unlock(); - if(result == pxNotFound) - { - MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); - } 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 ? @@ -992,4 +979,10 @@ void send_encrypted_msgs_thread(HANDLE hContact) else
return;
}
-}
\ No newline at end of file +}
+
+string time_str() +{
+ boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
+ return (string)boost::posix_time::to_simple_string(now); +} diff --git a/utilities.h b/utilities.h index e055f18..7255724 100644 --- a/utilities.h +++ b/utilities.h @@ -34,5 +34,6 @@ const bool StriStr(const char *str, const char *substr); string toUTF8(wstring str); wstring toUTF16(string str); string get_random(int length); +string time_str(); #endif |