From d59bd1a4e5cdb03de7ae785411ba2a7f08b72999 Mon Sep 17 00:00:00 2001 From: Alexander Gluzsky Date: Sun, 6 Jan 2013 12:20:59 +0000 Subject: debuglog refactoring more debug info in log git-svn-id: http://svn.miranda-ng.org/main/trunk@2993 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/New_GPG/res/new_gpg.rc | 2 +- plugins/New_GPG/src/gpg_wrapper.cpp | 11 +++-- plugins/New_GPG/src/log.cpp | 4 ++ plugins/New_GPG/src/main.cpp | 42 ++++++++-------- plugins/New_GPG/src/messages.cpp | 98 ++++++++++++++++++++++++------------- plugins/New_GPG/src/options.cpp | 10 ++-- plugins/New_GPG/src/utilities.cpp | 48 +++++++++--------- 7 files changed, 126 insertions(+), 89 deletions(-) diff --git a/plugins/New_GPG/res/new_gpg.rc b/plugins/New_GPG/res/new_gpg.rc index f6e59e4ffa..a1282311a0 100755 --- a/plugins/New_GPG/res/new_gpg.rc +++ b/plugins/New_GPG/res/new_gpg.rc @@ -76,7 +76,7 @@ BEGIN RTEXT "Key password:",IDC_STATIC,12,170,76,8 PUSHBUTTON "Load other",IDC_OTHER,83,152,64,14 PUSHBUTTON "Delete key",IDC_DELETE_KEY,149,152,70,14 - PUSHBUTTON "Generate and use random key",IDC_GENERATE_RANDOM,99,184,118,14 + PUSHBUTTON "Generate and use random key",IDC_GENERATE_RANDOM,40,184,141,14 LTEXT "",IDC_GENERATING_KEY,82,207,174,8 LTEXT "Account:",IDC_STATIC,15,12,42,8 LTEXT "key id: ",IDC_KEY_ID,178,12,99,8 diff --git a/plugins/New_GPG/src/gpg_wrapper.cpp b/plugins/New_GPG/src/gpg_wrapper.cpp index d743af4c8b..b2c65854cf 100755 --- a/plugins/New_GPG/src/gpg_wrapper.cpp +++ b/plugins/New_GPG/src/gpg_wrapper.cpp @@ -80,7 +80,7 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD if(errno == ENOENT) { mir_free(bin_path); - debuglog<c_str(); + debuglog<hContact, GCDNF_TCHAR))); return 0; + } } wstring str = toUTF16(msg); wstring::size_type s1 = wstring::npos, s2 = wstring::npos; if(bAutoExchange && (str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos)) { + debuglog<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<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 @@ -443,13 +450,12 @@ int RecvMsgSvc(WPARAM w, LPARAM l) gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); params.hProcess = NULL; - debuglog<hContact, GCDNF_TCHAR)<<"\n"; + debuglog<hContact, GCDNF_TCHAR))); s1 = 0; while((s1 = str.find(_T("\r"), s1)) != wstring::npos) str.erase(s1, 1); void ShowNewKeyDialog(); - if((str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) != wstring::npos)) + if(((s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----"))) != wstring::npos) && ((s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"))) != wstring::npos)) { - s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); - s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); s2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")); } - else if((str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) != wstring::npos) && (str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")) != wstring::npos)) + else if(((s2 = str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----"))) != wstring::npos) && ((s1 = str.find(_T("-----END PGP PRIVATE KEY BLOCK-----"))) != wstring::npos)) { - s2 = str.find(_T("-----END PGP PRIVATE KEY BLOCK-----")); - s1 = str.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); s2 += _tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----")); } new_key.append(str.substr(s1,s2-s1)); @@ -557,6 +554,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } if(bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && gpg_valid && gpg_keyexist) { + debuglog<hContact, GCDNF_TCHAR))); char *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); if(tmp[0]) { @@ -639,6 +637,7 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) str = toUTF16(msg); else {//workaround ... + debuglog<lParam)); if (!msg) { + debuglog<hContact, GCDNF_TCHAR))); mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); } if(strstr(msg,"-----BEGIN PGP MESSAGE-----")) + { + debuglog<hContact, GCDNF_TCHAR))); return CallService(MS_PROTO_CHAINSEND, w, l); + } if(!isContactHaveKey(ccs->hContact)) { + debuglog<hContact, GCDNF_TCHAR))); if(bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && gpg_valid) { + debuglog<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<hContact, GCDNF_TCHAR))); char *proto = GetContactProto(ccs->hContact); char svc[64]; strcpy(svc, proto); @@ -852,10 +862,12 @@ int SendMsgSvc(WPARAM w, LPARAM l) if(ServiceExists(svc)) { + debuglog<hContact, GCDNF_TCHAR))); ICQ_CUSTOMCAP cap = {0}; strcpy(cap.caps, "GPG AutoExchange"); if(CallService(svc, (WPARAM)ccs->hContact, (LPARAM)&cap)) { + debuglog<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)); @@ -869,6 +881,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) TCHAR *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", _T("")); if(jid[0]) { + debuglog<hContact, GCDNF_TCHAR))); extern list Accounts; list::iterator end = Accounts.end(); for(list::iterator p = Accounts.begin(); p != end; p++) @@ -887,6 +900,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(caps); if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) { + debuglog<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)); @@ -904,8 +918,13 @@ int SendMsgSvc(WPARAM w, LPARAM l) return CallService(MS_PROTO_CHAINSEND, w, l); } } + else + debuglog<hContact, GCDNF_TCHAR))); + if(metaIsProtoMetaContacts(ccs->hContact)) + debuglog<hContact, GCDNF_TCHAR))); if(!isContactSecured(ccs->hContact) || metaIsProtoMetaContacts(ccs->hContact)) { + debuglog<hContact, GCDNF_TCHAR))); mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); } @@ -926,9 +945,15 @@ int HookSendMsg(WPARAM w, LPARAM l) if(dbei->flags & DBEF_SENT) { if(isContactSecured(hContact) && strstr((char*)dbei->pBlob, "-----BEGIN PGP MESSAGE-----")) //our service data, can be double added by metacontacts e.t.c. + { + debuglog<pBlob, "-----PGP KEY RESPONSE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----"))) ///do not show service data in history + { + debuglog<flags & DBEF_SENT)) //aggressive outgoing events filtering { @@ -941,7 +966,7 @@ int HookSendMsg(WPARAM w, LPARAM l) if(!strcmp((*i).c_str(), (char*)dbei->pBlob)) { hcontact_data[hContact].msgs_to_pass.erase(i); - debuglog<pBlob<<"\" passed event filter, contact "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<", message is in allowed list\n"; + debuglog<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; } @@ -954,7 +979,7 @@ int HookSendMsg(WPARAM w, LPARAM l) } if(!isContactSecured(hContact)) { - debuglog<pBlob<<"\" passed event filter, contact "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" is unsecured\n"; + debuglog<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)) @@ -963,7 +988,10 @@ int HookSendMsg(WPARAM w, LPARAM l) strncpy(tmp, (char*)dbei->pBlob, 27); tmp[28] = '\0'; if(strstr(tmp, "-----BEGIN PGP MESSAGE-----")) + { + debuglog< 0) - debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; + debuglog<hContact, GCDNF_TCHAR))+" with password"); } else { pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T("")); if(_tcslen(pass) > 0) - debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; + debuglog<hContact, GCDNF_TCHAR))+" with password"); } if(_tcslen(pass) > 0) { @@ -373,13 +373,13 @@ int onProtoAck(WPARAM w, LPARAM l) } else if(password) { - debuglog<hContact, GCDNF_TCHAR)<<" with password\n"; + debuglog<hContact, GCDNF_TCHAR))+" with password"); cmd += _T("--passphrase \""); cmd += password; cmd += _T("\" "); } else - debuglog<hContact, GCDNF_TCHAR)<<" with out password\n"; + debuglog<hContact, GCDNF_TCHAR))+" with out password"); mir_free(pass); mir_free(keyid); } @@ -398,7 +398,7 @@ int onProtoAck(WPARAM w, LPARAM l) delete gpg_thread; TerminateProcess(params.hProcess, 1); params.hProcess = NULL; - debuglog<hContact, GCDNF_TCHAR)<<" password needed, trying to get one\n"; + debuglog<hContact, GCDNF_TCHAR))+" password needed, trying to get one"); if(_terminate) break; { //save inkey id @@ -426,7 +426,7 @@ int onProtoAck(WPARAM w, LPARAM l) wstring cmd2 = cmd; if(password) { - debuglog<hContact, GCDNF_TCHAR)<<"\n"; + debuglog<hContact, GCDNF_TCHAR))); wstring tmp = _T("--passphrase \""); tmp += password; tmp += _T("\" "); @@ -446,7 +446,7 @@ int onProtoAck(WPARAM w, LPARAM l) delete gpg_thread; TerminateProcess(params.hProcess, 1); params.hProcess = NULL; - debuglog<