diff options
Diffstat (limited to 'plugins/New_GPG/src/messages.cpp')
-rwxr-xr-x | plugins/New_GPG/src/messages.cpp | 183 |
1 files changed, 113 insertions, 70 deletions
diff --git a/plugins/New_GPG/src/messages.cpp b/plugins/New_GPG/src/messages.cpp index 29fc06e816..d3525d2a3f 100755 --- a/plugins/New_GPG/src/messages.cpp +++ b/plugins/New_GPG/src/messages.cpp @@ -40,7 +40,8 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, bool isContactHaveKey(HANDLE hContact); if(!isContactSecured(hContact)) { - debuglog<<std::string(time_str()+": info: received encrypted message from: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" with turned off encryption"); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: received encrypted message from: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" with turned off encryption"); if(MessageBox(0, TranslateT("We received encrypted message from contact with encryption turned off.\nDo you want turn on encryption for this contact ?"), TranslateT("Warning"), MB_YESNO) == IDYES) { if(!isContactHaveKey(hContact)) @@ -72,15 +73,11 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, return; } } - else + else if(bDebugLog) { debuglog<<std::string(time_str()+": info: received encrypted message from: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))); } - { - wstring::size_type p = 0; - while((p = str.find(_T("\r"), p)) != wstring::npos) - str.erase(p, 1); - } + boost::algorithm::erase_all(str, "\r"); s2 += _tcslen(_T("-----END PGP MESSAGE-----")); char *tmp = mir_t2a(str.substr(s1,s2-s1).c_str()); TCHAR *tmp2 = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); @@ -111,13 +108,13 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, dbsetting += inkeyid; dbsetting += "_Password"; pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T("")); - if(pass[0]) + if(pass[0] && bDebugLog) debuglog<<std::string(time_str()+": info: found password in database for key id: "+inkeyid+", trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" with password"); } else { pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); - if(pass[0]) + if(pass[0] && bDebugLog) debuglog<<std::string(time_str()+": info: found password for all keys in database, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" with password"); } if(pass && pass[0]) @@ -128,12 +125,13 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, } else if(password && password[0]) { - debuglog<<std::string(time_str()+": info: found password in memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" with password"); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: found password in memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" with password"); cmd += _T("--passphrase \""); cmd += password; cmd += _T("\" "); } - else + else if (bDebugLog) debuglog<<std::string(time_str()+": info: passwords not found in database or memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" with out password"); mir_free(pass); mir_free(inkeyid); @@ -165,7 +163,8 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, delete gpg_thread; TerminateProcess(params.hProcess, 1); params.hProcess = NULL; - debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); + if(bDebugLog) + debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); DeleteFile(path.c_str()); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); @@ -181,11 +180,20 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); return; } + if(result == pxSuccessExitCodeInvalid) + { + DeleteFile(path.c_str()); + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); + HistoryLog(hContact, db_event(Translate("failed to decrypt message, GPG returned error, turn on debug log for more details"), timestamp, 0, 0)); + return; + } + //TODO: check gpg output for errors _terminate = false; while(out.find("public key decryption failed: bad passphrase") != string::npos) { - debuglog<<std::string(time_str()+": info: failed to decrypt messaage from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" password needed, trying to get one"); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: failed to decrypt messaage from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" password needed, trying to get one"); if(_terminate) { BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); @@ -209,7 +217,8 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, wstring cmd2 = cmd; if(password) { - debuglog<<std::string(time_str()+": info: found password in memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: found password in memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))); wstring tmp = _T("--passphrase \""); tmp += password; tmp += _T("\" "); @@ -229,7 +238,8 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, delete gpg_thread; TerminateProcess(params.hProcess, 1); params.hProcess = NULL; - debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); + if(bDebugLog) + debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); DeleteFile(path.c_str()); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); @@ -253,7 +263,8 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, delete gpg_thread; TerminateProcess(params.hProcess, 1); params.hProcess = NULL; - debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); + if(bDebugLog) + debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); DeleteFile(path.c_str()); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); @@ -284,7 +295,8 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, { string str = msg; str.insert(0, "Received unencrypted message:\n"); - debuglog<<std::string(time_str()+": info: Failed to decrypt GPG encrypted message."); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: Failed to decrypt GPG encrypted message."); char *tmp = new char [str.length()+1]; strcpy(tmp, str.c_str()); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); @@ -322,7 +334,8 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, { string str = msg; str.insert(0, "Failed to decrypt GPG encrypted message.\nMessage body for manual decryption:\n"); - debuglog<<std::string(time_str()+": info: Failed to decrypt GPG encrypted message."); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: Failed to decrypt GPG encrypted message."); char *tmp = mir_strdup(str.c_str()); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); @@ -391,7 +404,8 @@ int RecvMsgSvc(WPARAM w, LPARAM l) return CallService(MS_PROTO_CHAINRECV, w, l); else { - debuglog<<std::string(time_str()+": info: blocked pgp message to metacontact:"+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: blocked pgp message to metacontact:"+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); return 0; } } @@ -399,12 +413,14 @@ int RecvMsgSvc(WPARAM w, LPARAM l) wstring::size_type s1 = wstring::npos, s2 = wstring::npos; if(bAutoExchange && (str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos)) { - debuglog<<std::string(time_str()+": info(autoexchange): parsing key response:"+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info(autoexchange): parsing key response:"+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); if(s1 != wstring::npos && s2 != wstring::npos) { - debuglog<<std::string(time_str()+": info(autoexchange): found pubkey block:"+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info(autoexchange): found pubkey block:"+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); s2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")); DBWriteContactSettingTString(ccs->hContact, szGPGModuleName, "GPGPubKey", str.substr(s1,s2-s1).c_str()); { //gpg execute block @@ -450,12 +466,18 @@ int RecvMsgSvc(WPARAM w, LPARAM l) gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); params.hProcess = NULL; - debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); + if(bDebugLog) + debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); return 1; } + DeleteFile(tmp2); if(result == pxNotFound) return 1; - DeleteFile(tmp2); + if(result == pxSuccessExitCodeInvalid) + { + HistoryLog(ccs->hContact, db_event(Translate("failed to decrypt message, GPG returned error, turn on debug log for more details"))); + return 1; + } { char *tmp = NULL; string::size_type s = output.find("gpg: key ") + strlen("gpg: key "); @@ -532,7 +554,8 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } if((s2 != wstring::npos) && (s1 != wstring::npos)) { //this is public key - debuglog<<std::string(time_str()+": info: received key from: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: received key from: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); s1 = 0; while((s1 = str.find(_T("\r"), s1)) != wstring::npos) str.erase(s1, 1); @@ -554,7 +577,8 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } if(bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && gpg_valid && gpg_keyexist) { - debuglog<<std::string(time_str()+": info(autoexchange): received key request from: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info(autoexchange): received key request from: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); char *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); if(tmp[0]) { @@ -631,25 +655,13 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) wstring str; bool isansi = false; DWORD dbflags = 0; - if(flags & PREF_UTF) + if((flags & PREF_UTF) == PREF_UTF) dbflags |= DBEF_UTF; - if(!metaIsSubcontact(hContact)) - str = toUTF16(msg); - else - {//workaround ... - debuglog<<std::string(time_str()+": info: using workaround for codepage with metacontacts, name: "+ toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))); - wchar_t *tmp = mir_utf8decodeW(msg); - if(!tmp) - { - tmp = mir_a2t(msg); - isansi = true; - } - str.append(tmp); - mir_free(tmp); - } + str = toUTF16(msg); if(bStripTags && bAppendTags) { - debuglog<<std::string(time_str()+": info: stripping tags in outgoing message, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: stripping tags in outgoing message, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))); strip_tags(str); } /* for(std::wstring::size_type i = str.find(_T("\r\n")); i != std::wstring::npos; i = str.find(_T("\r\n"), i+1)) @@ -713,7 +725,8 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); params.hProcess = NULL; - debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); + if(bDebugLog) + debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); mir_free(msg); CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); return; @@ -724,7 +737,6 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); return; } - //TODO: check gpg output for errors if(out.find("There is no assurance this key belongs to the named user") != string::npos) { out.clear(); @@ -745,7 +757,8 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); params.hProcess = NULL; - debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); + if(bDebugLog) + debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); mir_free(msg); CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); return; @@ -764,15 +777,21 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) return; } } + if(result == pxSuccessExitCodeInvalid) + { + mir_free(msg); + HistoryLog(hContact, db_event(Translate("failed o encrypt message, GPG returned error, turn on debug log for more details"), 0,0, DBEF_SENT)); + DeleteFile(path.c_str()); + return; + } if(out.find("usage: ") != string::npos) { MessageBox(0, TranslateT("Something wrong, gpg does not understand us, aborting encryption."), TranslateT("Warning"), MB_OK); - DeleteFile(path.c_str()); mir_free(msg); CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); + DeleteFile(path.c_str()); return; } - DeleteFile(path.c_str()); path.append(_T(".asc")); wfstream f(path.c_str(), std::ios::in | std::ios::ate | std::ios::binary); while(!f.is_open()) @@ -797,7 +816,8 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { HistoryLog(hContact, db_event("Failed to encrypt message with GPG", 0,0, DBEF_SENT)); hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG"); - debuglog<<std::string(time_str()+": info: Failed to encrypt message with GPG"); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: Failed to encrypt message with GPG"); mir_free(msg); CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); return; @@ -808,15 +828,19 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) str_event.insert(0, toUTF8(outopentag)); str_event.append(toUTF8(outclosetag)); } -/* if(metaIsSubcontact(hContact)) + /*if(metaIsSubcontact(hContact)) { hcontact_data[metaGetContact(hContact)].msgs_to_pass.push_back(str_event); - debuglog<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"is subcontact of"<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)metaGetContact(hContact), GCDNF_TCHAR)<<"\n"; - debuglog<<time_str()<<": adding event to metacontact: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)metaGetContact(hContact), GCDNF_TCHAR)<<" on send message.\n"; + if(bDebugLog) + { + debuglog<<std::string(time_str() + toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)) +"is subcontact of" + toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)metaGetContact(hContact), GCDNF_TCHAR))); + debuglog<<std::string(time_str()+": adding event to metacontact: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)metaGetContact(hContact), GCDNF_TCHAR))+" on send message."); + } HistoryLog(metaGetContact(hContact), db_event((char*)str_event.c_str(), 0,0, DBEF_SENT|dbflags)); - } */ //unneeded ? + }*/ //unneeded ? hcontact_data[hContact].msgs_to_pass.push_back(str_event); - debuglog<<std::string(time_str()+": adding event to contact: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" on send message."); + if(bDebugLog) + debuglog<<std::string(time_str()+": adding event to contact: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" on send message."); HistoryLog(hContact, db_event((char*)str_event.c_str(), 0,0, dbflags|DBEF_SENT)); if(!(flags & PREF_UTF)) flags |= PREF_UTF; @@ -831,30 +855,39 @@ int SendMsgSvc(WPARAM w, LPARAM l) CCSDATA *ccs = (CCSDATA*)l; if (!ccs) return CallService(MS_PROTO_CHAINSEND, w, l); - char *msg = mir_strdup((char*)(ccs->lParam)); + char *msg = nullptr; + if((ccs->wParam & PREF_UTF) == PREF_UTF) + msg = mir_strdup((char*)(ccs->lParam)); + else + msg = mir_utf8encode((char*)(ccs->lParam)); if (!msg) { - debuglog<<std::string(time_str()+": info: failed to get message data, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: failed to get message data, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); } if(strstr(msg,"-----BEGIN PGP MESSAGE-----")) { - debuglog<<std::string(time_str()+": info: encrypted messge, let it go, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: encrypted messge, let it go, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); return CallService(MS_PROTO_CHAINSEND, w, l); } if(!isContactHaveKey(ccs->hContact)) { - debuglog<<std::string(time_str()+": info: contact have not key, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: contact have not key, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); if(bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && gpg_valid) { - debuglog<<std::string(time_str()+": info: checking for autoexchange possibility, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: checking for autoexchange possibility, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); void send_encrypted_msgs_thread(HANDLE hContact); LPSTR proto = GetContactProto(ccs->hContact); DWORD uin = DBGetContactSettingDword(ccs->hContact, proto, "UIN", 0); if(uin) { - debuglog<<std::string(time_str()+": info(autoexchange): protocol looks like icq, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info(autoexchange): protocol looks like icq, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); char *proto = GetContactProto(ccs->hContact); char svc[64]; strcpy(svc, proto); @@ -862,12 +895,14 @@ int SendMsgSvc(WPARAM w, LPARAM l) if(ServiceExists(svc)) { - debuglog<<std::string(time_str()+": info(autoexchange, icq): checking for autoexchange icq capability, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info(autoexchange, icq): checking for autoexchange icq capability, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); ICQ_CUSTOMCAP cap = {0}; strcpy(cap.caps, "GPG AutoExchange"); if(CallService(svc, (WPARAM)ccs->hContact, (LPARAM)&cap)) { - debuglog<<std::string(time_str()+": info(autoexchange, icq): sending key requiest, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info(autoexchange, icq): sending key requiest, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)ccs->wParam, (LPARAM)"-----PGP KEY REQUEST-----"); hcontact_data[ccs->hContact].msgs_to_send.push_back(msg); boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, ccs->hContact)); @@ -881,7 +916,8 @@ int SendMsgSvc(WPARAM w, LPARAM l) TCHAR *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", _T("")); if(jid[0]) { - debuglog<<std::string(time_str()+": info(autoexchange): protocol looks like jabber, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info(autoexchange): protocol looks like jabber, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); extern list <JabberAccount*> Accounts; list<JabberAccount*>::iterator end = Accounts.end(); for(list<JabberAccount*>::iterator p = Accounts.begin(); p != end; p++) @@ -900,7 +936,8 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(caps); if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) { - debuglog<<std::string(time_str()+": info(autoexchange, jabber): autoexchange capability found, sending key request, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info(autoexchange, jabber): autoexchange capability found, sending key request, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); CallContactService(ccs->hContact, PSS_MESSAGE, (WPARAM)ccs->wParam, (LPARAM)"-----PGP KEY REQUEST-----"); hcontact_data[ccs->hContact].msgs_to_send.push_back(msg); boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, ccs->hContact)); @@ -918,13 +955,14 @@ int SendMsgSvc(WPARAM w, LPARAM l) return CallService(MS_PROTO_CHAINSEND, w, l); } } - else + else if(bDebugLog) debuglog<<std::string(time_str()+": info: contact have key, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); - if(metaIsProtoMetaContacts(ccs->hContact)) + if(bDebugLog && metaIsProtoMetaContacts(ccs->hContact)) debuglog<<std::string(time_str()+": info: protocol is metacontacts, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); if(!isContactSecured(ccs->hContact) || metaIsProtoMetaContacts(ccs->hContact)) { - debuglog<<std::string(time_str()+": info: contact not secured, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: contact not secured, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR))); mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); } @@ -946,12 +984,14 @@ int HookSendMsg(WPARAM w, LPARAM l) { if(isContactSecured(hContact) && strstr((char*)dbei->pBlob, "-----BEGIN PGP MESSAGE-----")) //our service data, can be double added by metacontacts e.t.c. { - debuglog<<std::string(time_str()+": info(send handler): block pgp message event, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info(send handler): block pgp message event, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))); return 1; } if(bAutoExchange && (strstr((char*)dbei->pBlob, "-----PGP KEY RESPONSE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----"))) ///do not show service data in history { - debuglog<<std::string(time_str()+": info(send handler): block pgp key request/response event, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info(send handler): block pgp key request/response event, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))); return 1; } } @@ -966,7 +1006,8 @@ int HookSendMsg(WPARAM w, LPARAM l) if(!strcmp((*i).c_str(), (char*)dbei->pBlob)) { hcontact_data[hContact].msgs_to_pass.erase(i); - debuglog<<std::string(time_str()+": event message: \""+(char*)dbei->pBlob+"\" passed event filter, contact "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+", message is in allowed list"); + if(bDebugLog) + debuglog<<std::string(time_str()+": event message: \""+(char*)dbei->pBlob+"\" passed event filter, contact "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+", message is in allowed list"); event_processing_mutex.unlock(); return 0; } @@ -979,7 +1020,8 @@ int HookSendMsg(WPARAM w, LPARAM l) } if(!isContactSecured(hContact)) { - debuglog<<std::string(time_str()+": event message: \""+(char*)dbei->pBlob+"\" passed event filter, contact "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" is unsecured"); + if(bDebugLog) + debuglog<<std::string(time_str()+": event message: \""+(char*)dbei->pBlob+"\" passed event filter, contact "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" is unsecured"); return 0; } if(!(dbei->flags & DBEF_SENT) && metaIsProtoMetaContacts((HANDLE)w)) @@ -989,7 +1031,8 @@ int HookSendMsg(WPARAM w, LPARAM l) tmp[28] = '\0'; if(strstr(tmp, "-----BEGIN PGP MESSAGE-----")) { - debuglog<<std::string(time_str()+": info(send handler): block pgp message event, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<<std::string(time_str()+": info(send handler): block pgp message event, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))); return 1; } } |