From 557320085b66813a1f6f525bf0730ed0006ec05c Mon Sep 17 00:00:00 2001 From: Alexander Gluzsky Date: Wed, 6 Feb 2013 11:29:05 +0000 Subject: srmm friendly event handling (may cause problems need testing) git-svn-id: http://svn.miranda-ng.org/main/trunk@3455 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/New_GPG/src/main.h | 2 +- plugins/New_GPG/src/messages.cpp | 169 +++++++++++++++++++++++++++++++------- plugins/New_GPG/src/utilities.cpp | 25 +++--- 3 files changed, 153 insertions(+), 43 deletions(-) (limited to 'plugins/New_GPG') diff --git a/plugins/New_GPG/src/main.h b/plugins/New_GPG/src/main.h index 23627a415a..353dee0aae 100755 --- a/plugins/New_GPG/src/main.h +++ b/plugins/New_GPG/src/main.h @@ -18,7 +18,7 @@ struct contact_data { - list msgs_to_send, msgs_to_pass; + list msgs_to_send;// msgs_to_pass; string key_in_prescense; }; diff --git a/plugins/New_GPG/src/messages.cpp b/plugins/New_GPG/src/messages.cpp index c4afd1fc48..25519d1abc 100755 --- a/plugins/New_GPG/src/messages.cpp +++ b/plugins/New_GPG/src/messages.cpp @@ -671,8 +671,8 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { mir_free(tmp); HistoryLog(hContact, db_event("Failed to encrypt message with GPG (not found key for encryption in db)", 0,0, DBEF_SENT)); - hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG (not found key for encryption in db)"); - mir_free(msg); +// hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG (not found key for encryption in db)"); + //mir_free(msg); CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); return; } @@ -721,13 +721,13 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) params.hProcess = NULL; if(bDebugLog) debuglog<hContact, GCDNF_TCHAR))); return CallService(MS_PROTO_CHAINSEND, w, l); } - if(!isContactHaveKey(ccs->hContact)) + /*if(!isContactHaveKey(ccs->hContact)) { if(bDebugLog) debuglog<hContact, GCDNF_TCHAR))); @@ -949,7 +949,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); } - } + } */ else if(bDebugLog) debuglog<hContact, GCDNF_TCHAR))); if(bDebugLog && metaIsProtoMetaContacts(ccs->hContact)) @@ -961,7 +961,8 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); } - boost::thread *thr = new boost::thread(boost::bind(SendMsgSvc_func, ccs->hContact, msg, (DWORD)ccs->wParam)); + mir_free(msg); + //boost::thread *thr = new boost::thread(boost::bind(SendMsgSvc_func, ccs->hContact, msg, (DWORD)ccs->wParam)); return returnNoError(ccs->hContact); } @@ -990,28 +991,136 @@ int HookSendMsg(WPARAM w, LPARAM l) return 1; } } - if(isContactSecured(hContact) && (dbei->flags & DBEF_SENT)) //aggressive outgoing events filtering + if(metaIsProtoMetaContacts(hContact)) + return 0; + + if(!isContactHaveKey(hContact)) { - if(!hcontact_data[hContact].msgs_to_pass.empty()) + if(bDebugLog) + debuglog<pBlob, "-----PGP KEY REQUEST-----") && !strstr((char*)dbei->pBlob, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && gpg_valid) { - event_processing_mutex.lock(); - std::list::iterator end = hcontact_data[hContact].msgs_to_pass.end(); - for(std::list::iterator i = hcontact_data[hContact].msgs_to_pass.begin(); i != end; ++i) + if(bDebugLog) + debuglog<pBlob)) + 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; + debuglog<flags & DBEF_UTF) == DBEF_UTF)?PREF_UTF:0, (LPARAM)"-----PGP KEY REQUEST-----"); + hcontact_data[hContact].msgs_to_send.push_back((char*)dbei->pBlob); + boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, hContact)); + //TODO: wait for message + return 0; + } + } + } + else + { + TCHAR *jid = UniGetContactSettingUtf(hContact, proto, "jid", _T("")); + if(jid[0]) + { + if(bDebugLog) + debuglog< Accounts; + list::iterator end = Accounts.end(); + for(list::iterator p = Accounts.begin(); p != end; p++) + { + TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid); + if(caps) + { + wstring str; + for(int i=0;;i++) + { + str.push_back(caps[i]); + if(caps[i] == '\0') + if(caps[i+1] == '\0') + break; + } + mir_free(caps); + if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) + { + if(bDebugLog) + debuglog<flags & DBEF_UTF) == DBEF_UTF)?PREF_UTF:0, (LPARAM)"-----PGP KEY REQUEST-----"); + hcontact_data[hContact].msgs_to_send.push_back((char*)dbei->pBlob); + boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, hContact)); + mir_free((char*)dbei->pBlob); + //TODO: wait for message + return 0; + } + } + } } } - event_processing_mutex.unlock(); } - if(metaIsProtoMetaContacts(hContact) && !isContactSecured(metaGetMostOnline(hContact))) + else + { return 0; - return 1; + } + } + if(isContactSecured(hContact) && (dbei->flags & DBEF_SENT)) //aggressive outgoing events filtering + { + DWORD flags; + if((dbei->flags & DBEF_UTF) == DBEF_UTF) + flags |= PREF_UTF; + SendMsgSvc_func(hContact, (char*)dbei->pBlob, flags); + //TODO: handle errors somehow ... + if(bAppendTags) + { + string str_event = (char*)dbei->pBlob; + mir_free(dbei->pBlob); + str_event.insert(0, toUTF8(outopentag)); + str_event.append(toUTF8(outclosetag)); + dbei->pBlob = (PBYTE)mir_strdup(str_event.c_str()); + dbei->cbBlob = str_event.length() + 1; + } + + return 0; +/* bool stop = false; + int count = 0; */ +/* while(!stop) + { + if(count >= 300) + stop = true; + if(!hcontact_data[hContact].msgs_to_pass.empty()) + { + event_processing_mutex.lock(); + std::list::iterator end = hcontact_data[hContact].msgs_to_pass.end(); + for(std::list::iterator i = hcontact_data[hContact].msgs_to_pass.begin(); i != end; ++i) + { + if(!strcmp((*i).c_str(), (char*)dbei->pBlob)) + { + hcontact_data[hContact].msgs_to_pass.erase(i); + 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; + } + } + event_processing_mutex.unlock(); + } + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + count++; + } */ + //return 1; } if(!isContactSecured(hContact)) { diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp index 49df88a301..558e7f6875 100755 --- a/plugins/New_GPG/src/utilities.cpp +++ b/plugins/New_GPG/src/utilities.cpp @@ -1314,11 +1314,11 @@ int SendBroadcast( HANDLE hContact, int type, int result, HANDLE hProcess, LPARA ACKDATA ack; memset(&ack,0,sizeof(ack)); ack.cbSize = sizeof( ACKDATA ); - ack.szModule = szGPGModuleName;// GetContactProto(hContact); + ack.szModule = GetContactProto(hContact);//szGPGModuleName; ack.hContact = hContact; ack.type = type; ack.result = result; - ack.hProcess = hProcess; + ack.hProcess = (HANDLE)777;//hProcess; ack.lParam = lParam; return CallService( MS_PROTO_BROADCASTACK, 0, ( LPARAM )&ack ); } @@ -1857,25 +1857,26 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) } if(found) { - wstring cmd; - TCHAR tmp2[MAX_PATH] = {0}; + wstring cmd, path; TCHAR *ptmp; string output; DWORD exitcode; { HANDLE hcnt = hContact; ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - _tcscpy(tmp2, ptmp); + path = ptmp; mir_free(ptmp); - _tcscat(tmp2, _T("\\")); - _tcscat(tmp2, _T("temporary_exported.asc")); - boost::filesystem::remove(tmp2); - wfstream f(tmp2, std::ios::out); + mir_free(ptmp); + wstring rand = toUTF16(get_random(10)); + path += L"\\"; + path += rand; + boost::filesystem::remove(path); + wfstream f(path, std::ios::out); f<