From d884a2fd95cd535aef2640e6a592762b3c484ed2 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 12 Jan 2013 09:49:04 +0200 Subject: merged with miranda_ng main repo --- messages.cpp | 165 +++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 110 insertions(+), 55 deletions(-) (limited to 'messages.cpp') diff --git a/messages.cpp b/messages.cpp index f076067..2869a89 100755 --- a/messages.cpp +++ b/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<hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<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<hContact, GCDNF_TCHAR))); + if(bDebugLog) + 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))); + if(bDebugLog) + 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 @@ -450,12 +466,18 @@ int RecvMsgSvc(WPARAM w, LPARAM l) gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); params.hProcess = NULL; - debuglog<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<hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<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<hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<hContact, GCDNF_TCHAR))); char *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); if(tmp[0]) { @@ -633,7 +657,7 @@ 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); @@ -715,7 +739,8 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); params.hProcess = NULL; - debuglog<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<hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<hContact, GCDNF_TCHAR))); mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); } if(strstr(msg,"-----BEGIN PGP MESSAGE-----")) { - debuglog<hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<hContact, GCDNF_TCHAR))); return CallService(MS_PROTO_CHAINSEND, w, l); } if(!isContactHaveKey(ccs->hContact)) { - debuglog<hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<hContact, GCDNF_TCHAR))); if(bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && gpg_valid) { - debuglog<hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<hContact, GCDNF_TCHAR))); void send_encrypted_msgs_thread(HANDLE hContact); LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); DWORD uin = DBGetContactSettingDword(ccs->hContact, proto, "UIN", 0); if(uin) { - debuglog<hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<hContact, GCDNF_TCHAR))); char *proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0); char svc[64]; strcpy(svc, proto); @@ -864,12 +909,14 @@ int SendMsgSvc(WPARAM w, LPARAM l) if(ServiceExists(svc)) { - debuglog<hContact, GCDNF_TCHAR))); + if(bDebugLog) + 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))); + if(bDebugLog) + 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)); @@ -883,7 +930,8 @@ int SendMsgSvc(WPARAM w, LPARAM l) TCHAR *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", _T("")); if(jid[0]) { - debuglog<hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<hContact, GCDNF_TCHAR))); extern list Accounts; list::iterator end = Accounts.end(); for(list::iterator p = Accounts.begin(); p != end; p++) @@ -902,7 +950,8 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(caps); if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) { - debuglog<hContact, GCDNF_TCHAR))); + if(bDebugLog) + 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)); @@ -920,13 +969,14 @@ int SendMsgSvc(WPARAM w, LPARAM l) return CallService(MS_PROTO_CHAINSEND, w, l); } } - else + else if(bDebugLog) debuglog<hContact, GCDNF_TCHAR))); - if(metaIsProtoMetaContacts(ccs->hContact)) + if(bDebugLog && metaIsProtoMetaContacts(ccs->hContact)) debuglog<hContact, GCDNF_TCHAR))); if(!isContactSecured(ccs->hContact) || metaIsProtoMetaContacts(ccs->hContact)) { - debuglog<hContact, GCDNF_TCHAR))); + if(bDebugLog) + debuglog<hContact, GCDNF_TCHAR))); mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); } @@ -948,12 +998,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<pBlob, "-----PGP KEY RESPONSE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----"))) ///do not show service data in history { - debuglog<pBlob)) { hcontact_data[hContact].msgs_to_pass.erase(i); - debuglog<pBlob+"\" passed event filter, contact "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+", message is in allowed list"); + if(bDebugLog) + 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; } @@ -981,7 +1034,8 @@ int HookSendMsg(WPARAM w, LPARAM l) } if(!isContactSecured(hContact)) { - debuglog<pBlob+"\" passed event filter, contact "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" is unsecured"); + if(bDebugLog) + 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)) @@ -991,7 +1045,8 @@ int HookSendMsg(WPARAM w, LPARAM l) tmp[28] = '\0'; if(strstr(tmp, "-----BEGIN PGP MESSAGE-----")) { - debuglog<