diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2011-03-22 14:09:37 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2011-03-22 14:09:37 +0200 |
commit | 59822f2c393d553d43adb4a5eb8daf77609063f2 (patch) | |
tree | 6e53e461a18f78516ba12f6ca9670e7c7ce7584e /messages.cpp | |
parent | 0ab2db678a2a79f624a74a51ac617110d9b4413e (diff) |
new threading code (part 2, usable)
Diffstat (limited to 'messages.cpp')
-rw-r--r-- | messages.cpp | 490 |
1 files changed, 237 insertions, 253 deletions
diff --git a/messages.cpp b/messages.cpp index b37bbd0..05d138a 100644 --- a/messages.cpp +++ b/messages.cpp @@ -28,6 +28,9 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { //check for gpg related data wstring str = toUTF16(msg); wstring::size_type s1 = wstring::npos, s2 = wstring::npos; + DWORD dbflags = 0; + if(flags & PREF_UTF) + flags |= DBEF_UTF; if((str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos) && !metaIsProtoMetaContacts(hContact)) { @@ -147,7 +150,6 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) HistoryLog(hContact, "PGP Encryption turned on by key autoexchange feature", EVENTTYPE_MESSAGE, 0); } } - hcontact_data[hContact].msgs_to_ignore.push_back(msg); mir_free(msg); return 1; } @@ -166,7 +168,7 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { //this is public key if(metaIsSubcontact(hContact)) { - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); mir_free(msg); return 0; } @@ -193,7 +195,7 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) new_key_hcnt_mutex.lock(); new_key_hcnt = hContact; ShowNewKeyDialog(); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); mir_free(msg); return 0; } @@ -290,7 +292,7 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) } else if(MessageBox(0, _T("Do you want try to decrypt encrypted message ?"), _T("Warning"), MB_YESNO) == IDNO) { - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); mir_free(msg); return 0; } @@ -376,14 +378,14 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) delete gpg_thread; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; DeleteFile(path.c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); mir_free(msg); return 0; } if(result == pxNotFound) { DeleteFile(path.c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); mir_free(msg); return 0; } @@ -427,14 +429,14 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) delete gpg_thread; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; DeleteFile(path.c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); mir_free(msg); return 0; } if(result == pxNotFound) { DeleteFile(path.c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); mir_free(msg); return 0; } @@ -446,14 +448,14 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) delete gpg_thread; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; DeleteFile(path.c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); mir_free(msg); return 0; } if(result == pxNotFound) { DeleteFile(path.c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); } { wstring tmp = tmp2; @@ -472,7 +474,7 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) debuglog<<time_str()<<": info: Failed to decrypt GPG encrypted message.\n"; char *tmp = new char [str.length()+1]; strcpy(tmp, str.c_str()); - HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, dbflags); mir_free(tmp); mir_free(msg); return 0; @@ -506,7 +508,7 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) str.insert(0, "Failed to decrypt GPG encrypted message.\nMessage body for manual decryption:\n"); debuglog<<time_str()<<": info: Failed to decrypt GPG encrypted message.\n"; char *tmp = mir_strdup(str.c_str()); - HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, dbflags); mir_free(tmp); mir_free(msg); return 0; @@ -521,15 +523,15 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) if(metaIsSubcontact(hContact)) { char *msg = mir_strdup(toUTF8(str).c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, DBEF_UTF|DBEF_READ); - HistoryLog(metaGetContact(hContact), msg, EVENTTYPE_MESSAGE, DBEF_UTF); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags|DBEF_READ); + HistoryLog(metaGetContact(hContact), msg, EVENTTYPE_MESSAGE, dbflags); mir_free(msg); return 1; } char *tmp = mir_strdup(toUTF8(str).c_str()); if(!(flags & DBEF_UTF)) flags |= DBEF_UTF; - HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, flags); + HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, dbflags); mir_free(tmp); mir_free(msg); return 0; @@ -545,10 +547,9 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, DBEF_UTF| DBEF_READ); HistoryLog(metaGetContact(hContact), msg, EVENTTYPE_MESSAGE, DBEF_UTF); mir_free(msg); - return 1; + return 0; } string str = msg; - str.insert(0, "Received unencrypted message:\n"); char *tmp = mir_strdup(str.c_str()); HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, flags); mir_free(tmp); @@ -577,118 +578,90 @@ int RecvMsgSvc(WPARAM w, LPARAM l) int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { - if(!isContactHaveKey(hContact) && bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && isGPGConfigured()) - { - void send_encrypted_msgs_thread(HANDLE hContact); - LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - DWORD uin = DBGetContactSettingDword(hContact, proto, "UIN", 0); - if(uin) + wstring str; + bool isansi = false; + DWORD dbflags = 0; + if(flags & PREF_UTF) + dbflags |= DBEF_UTF; + if(!metaIsSubcontact(hContact)) + str = toUTF16(msg); + else + {//workaround ... + wchar_t *tmp = mir_utf8decodeW(msg); + if(!tmp) { - if(ServiceExists("ICQ"PS_ICQ_CHECKCAPABILITY)) - { - ICQ_CUSTOMCAP cap = {0}; - strcpy(cap.caps, "GPG AutoExchange"); - if(CallService("ICQ"PS_ICQ_CHECKCAPABILITY, (WPARAM)hContact, (LPARAM)&cap)) - { - CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)"-----PGP KEY REQUEST-----"); - hcontact_data[hContact].msgs_to_ignore.push_back(msg); - hcontact_data[hContact].msgs_to_send.push_back(msg); - boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, hContact)); - return returnNoError(hContact); - } - } - } - else - { - TCHAR *jid = UniGetContactSettingUtf(hContact, proto, "jid", _T("")); - if(jid[0]) - { - extern list <JabberAccount*> Accounts; - list<JabberAccount*>::iterator end = Accounts.end(); - for(list<JabberAccount*>::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) - { - CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)"-----PGP KEY REQUEST-----"); - hcontact_data[hContact].msgs_to_ignore.push_back(msg); - hcontact_data[hContact].msgs_to_send.push_back(msg); - boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, hContact)); - return returnNoError(hContact); - } - } - } - } + tmp = mir_a2t(msg); + isansi = true; } + str.append(tmp); + mir_free(tmp); } - if(!isContactSecured(hContact)) + string out; + DWORD code; + wstring cmd; + wstring path; + extern bool bJabberAPI, bIsMiranda09; + char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); + if(!tmp[0]) + { + mir_free(tmp); + HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT); + hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG"); + mir_free(msg); return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); - - { //encrypt data here - wstring str; - bool isansi = false; - if(!metaIsSubcontact(hContact)) - str = toUTF16(msg); - else - {//workaround ... - wchar_t *tmp = mir_utf8decodeW(msg); - if(!tmp) - { - tmp = mir_a2t(msg); - isansi = true; - } - str.append(tmp); - mir_free(tmp); - } + } + if(!bJabberAPI || !bIsMiranda09) //force jabber to handle encrypted message by itself + cmd += _T("--comment \"\" --no-version "); + if(DBGetContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 0)) + cmd += _T("--trust-model always "); + cmd += _T("--batch --yes -e -a -r "); + TCHAR *tmp2 = mir_a2t(tmp); + mir_free(tmp); + cmd += tmp2; + mir_free(tmp2); + cmd += _T(" \""); + tmp2 = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + path.append(tmp2); + cmd += tmp2; + mir_free(tmp2); + cmd += _T("\\exported_data"); + path.append(_T("\\exported_data")); + cmd += _T("\""); + { + char *tmp; + tmp = mir_strdup(toUTF8(str).c_str()); + fstream f(path.c_str(), std::ios::out); + f<<tmp; + mir_free(tmp); + f.close(); + } + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + { + gpg_thread.~thread(); + debuglog<<time_str()<<": GPG execution timed out, aborted\n"; + mir_free(msg); + return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); + } + if(result == pxNotFound) + { + mir_free(msg); + return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); + } + if(out.find("There is no assurance this key belongs to the named user") != string::npos) + { + out.clear(); + if(MessageBox(0, _T("We trying to encrypt with untrusted key, do you want to trust this key permanently ?"), _T("Warning"), MB_YESNO) == IDYES) { - string out; - DWORD code; - wstring cmd; - wstring path; - extern bool bJabberAPI, bIsMiranda09; - char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); - if(!tmp[0]) - { - mir_free(tmp); - HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT); - return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); - } - if(!bJabberAPI || !bIsMiranda09) //force jabber to handle encrypted message by itself - cmd += _T("--comment \"\" --no-version "); - if(DBGetContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 0)) - cmd += _T("--trust-model always "); - cmd += _T("--batch --yes -e -a -r "); - TCHAR *tmp2 = mir_a2t(tmp); - mir_free(tmp); - cmd += tmp2; - mir_free(tmp2); - cmd += _T(" \""); - tmp2 = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - path.append(tmp2); - cmd += tmp2; - mir_free(tmp2); - cmd += _T("\\exported_data"); - path.append(_T("\\exported_data")); - cmd += _T("\""); - { - char *tmp; - tmp = mir_strdup(toUTF8(str).c_str()); - fstream f(path.c_str(), std::ios::out); - f<<tmp; - mir_free(tmp); - f.close(); - } + DBWriteContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 1); + cmd.insert(0, _T("--trust-model always ")); gpg_execution_params params; pxResult result; params.cmd = &cmd; @@ -701,94 +674,69 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { gpg_thread.~thread(); debuglog<<time_str()<<": GPG execution timed out, aborted\n"; + mir_free(msg); return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); } if(result == pxNotFound) - return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); - if(out.find("There is no assurance this key belongs to the named user") != string::npos) - { - out.clear(); - if(MessageBox(0, _T("We trying to encrypt with untrusted key, do you want to trust this key permanently ?"), _T("Warning"), MB_YESNO) == IDYES) - { - DBWriteContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 1); - cmd.insert(0, _T("--trust-model always ")); - gpg_execution_params params; - pxResult result; - params.cmd = &cmd; - params.useless = ""; - params.out = &out; - params.code = &code; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - debuglog<<time_str()<<": GPG execution timed out, aborted\n"; - return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); - } - if(result == pxNotFound) - return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); - } - else - return 0; - } - if(out.find("usage: ") != string::npos) - { - MessageBox(0, _T("Something wrong, gpg does not understand us, aborting encryption."), _T("Warning"), MB_OK); - DeleteFile(path.c_str()); - return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); - } - DeleteFile(path.c_str()); - path.append(_T(".asc")); - wfstream f(path.c_str(), std::ios::in | std::ios::ate | std::ios::binary); - str.clear(); - if(f.is_open()) { - std::wifstream::pos_type size = f.tellg(); - TCHAR *tmp = new TCHAR [(std::ifstream::pos_type)size+(std::ifstream::pos_type)1]; - f.seekg(0, std::ios::beg); - f.read(tmp, size); - tmp[size]= '\0'; - str.append(tmp); - delete [] tmp; - f.close(); - DeleteFile(path.c_str()); - } - if(str.empty()) - { - HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT); - debuglog<<time_str()<<": info: Failed to encrypt message with GPG"; + mir_free(msg); return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); } - if(metaIsSubcontact(hContact)) - { //dirty hack to avoid metacontacts problem ..., this also broke filters chain - string str_event = msg; - if(bAppendTags) - { //utf8 tag will cause problems here - str_event.insert(0, toUTF8(outopentag)); - str_event.append(toUTF8(outclosetag)); - } - DWORD flags = 0, flags2 = 0; - if(!isansi) //message from metacontact itself, yet another metacontacts workaround... - flags |= DBEF_UTF; - else - flags2 |= DBEF_READ; - HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | flags2 | flags); - HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | flags); - hcontact_data[hContact].msgs_to_ignore.push_back(msg); - hcontact_data[metaGetContact(hContact)].msgs_to_ignore.push_back(msg); - CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)toUTF8(str).c_str()); - return returnNoError(hContact); - } - if(bAppendTags) - hcontact_data[hContact].msgs_to_tag.push_back(msg); + } + else + { mir_free(msg); - msg = mir_strdup(toUTF8(str).c_str()); - } + return 0; + } + } + if(out.find("usage: ") != string::npos) + { + MessageBox(0, _T("Something wrong, gpg does not understand us, aborting encryption."), _T("Warning"), MB_OK); + DeleteFile(path.c_str()); + mir_free(msg); + return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); + } + DeleteFile(path.c_str()); + path.append(_T(".asc")); + wfstream f(path.c_str(), std::ios::in | std::ios::ate | std::ios::binary); + str.clear(); + if(f.is_open()) + { + std::wifstream::pos_type size = f.tellg(); + TCHAR *tmp = new TCHAR [(std::ifstream::pos_type)size+(std::ifstream::pos_type)1]; + f.seekg(0, std::ios::beg); + f.read(tmp, size); + tmp[size]= '\0'; + str.append(tmp); + delete [] tmp; + f.close(); + DeleteFile(path.c_str()); + } + if(str.empty()) + { + HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT); + hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG"); + debuglog<<time_str()<<": info: Failed to encrypt message with GPG"; + mir_free(msg); + return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); + } + string str_event = msg; + if(bAppendTags) + { + str_event.insert(0, toUTF8(outopentag)); + str_event.append(toUTF8(outclosetag)); + } + if(metaIsSubcontact(hContact)) + { + hcontact_data[metaGetContact(hContact)].msgs_to_pass.push_back(str_event); + HistoryLog(metaGetContact(hContact), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT | dbflags); } + hcontact_data[hContact].msgs_to_pass.push_back(str_event); + HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, dbflags|DBEF_SENT); if(!(flags & PREF_UTF)) flags |= PREF_UTF; - CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); + CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)toUTF8(str).c_str()); + mir_free(msg); return 0; } @@ -799,80 +747,121 @@ int SendMsgSvc(WPARAM w, LPARAM l) return CallService(MS_PROTO_CHAINSEND, w, l); char *msg = mir_strdup((char*)(ccs->lParam)); if (!msg) + { + mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); + } if(strstr(msg,"-----BEGIN PGP MESSAGE-----")) return CallService(MS_PROTO_CHAINSEND, w, l); + if(!isContactHaveKey(ccs->hContact)) + { + if(bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && isGPGConfigured()) + { + 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) + { + if(ServiceExists("ICQ"PS_ICQ_CHECKCAPABILITY)) + { + ICQ_CUSTOMCAP cap = {0}; + strcpy(cap.caps, "GPG AutoExchange"); + if(CallService("ICQ"PS_ICQ_CHECKCAPABILITY, (WPARAM)ccs->hContact, (LPARAM)&cap)) + { + 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)); + mir_free(msg); + return returnNoError(ccs->hContact); + } + } + } + else + { + TCHAR *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", _T("")); + if(jid[0]) + { + extern list <JabberAccount*> Accounts; + list<JabberAccount*>::iterator end = Accounts.end(); + for(list<JabberAccount*>::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) + { + 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)); + mir_free(msg); + return returnNoError(ccs->hContact); + } + } + } + } + } + } + else + { + mir_free(msg); + return CallService(MS_PROTO_CHAINSEND, w, l); + } + } if(metaIsProtoMetaContacts(ccs->hContact)) { - hcontact_data[ccs->hContact].msgs_to_ignore.push_back((char*)msg); + 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)); return returnNoError(ccs->hContact); } +boost::mutex event_processing_mutex; + int HookSendMsg(WPARAM w, LPARAM l) -{ //TODO: implement additional filtering for metacontacts data... +{ if(!l) return 0; DBEVENTINFO * dbei = (DBEVENTINFO*)l; - if((dbei->eventType == EVENTTYPE_MESSAGE) && (dbei->flags & DBEF_SENT)) + if(dbei->eventType != EVENTTYPE_MESSAGE) + return 0; + if(dbei->flags & DBEF_SENT) { if(strstr((char*)dbei->pBlob, "-----BEGIN PGP MESSAGE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY RESPONSE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----") || strstr((char*)dbei->pBlob, "-----PGP KEY RESPONSE-----")) //our service data, can be double added by metacontacts e.t.c. return 1; - HANDLE hContact = NULL; - if(!hcontact_data[(HANDLE)w].msgs_to_ignore.empty()) - hContact = (HANDLE)w; - else if(!hcontact_data[metaGetContact((HANDLE)w)].msgs_to_ignore.empty()) - hContact = metaGetContact((HANDLE)w); - if(hContact) - { - list<string>::iterator end = hcontact_data[hContact].msgs_to_ignore.end(); - for(list<string>::iterator p = hcontact_data[hContact].msgs_to_ignore.begin(); p != end; p++) - { - if(*p == (char*)dbei->pBlob) - { - hcontact_data[hContact].msgs_to_ignore.erase(p); - return 1; - } - } - } } HANDLE hContact = (HANDLE)w; - - - if(metaIsProtoMetaContacts(hContact)) - hContact = metaGetCurrent(hContact); - if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)) - return 0; - - if(bAppendTags) + if(isContactSecured(hContact) && (dbei->flags & DBEF_SENT)) //aggressive outgoing events filtering { - if((dbei->eventType == EVENTTYPE_MESSAGE) && (dbei->flags & DBEF_SENT)) + if(!hcontact_data[hContact].msgs_to_pass.empty()) { - if(!hcontact_data[hContact].msgs_to_tag.empty()) + event_processing_mutex.lock(); + std::list<string>::iterator end = hcontact_data[hContact].msgs_to_pass.end(); + for(std::list<string>::iterator i = hcontact_data[hContact].msgs_to_pass.begin(); i != end; ++i) { - std::list<string>::iterator end = hcontact_data[hContact].msgs_to_tag.end(); - for(std::list<string>::iterator i = hcontact_data[hContact].msgs_to_tag.begin(); i != end; ++i) + if(!strcmp((*i).c_str(), (char*)dbei->pBlob)) { - if(*i == (char*)dbei->pBlob) - { - char *msg = (char*)dbei->pBlob; - wstring str = toUTF16(msg); - str.insert(0, outopentag); - str.append(outclosetag); - char *msg2 = mir_strdup(toUTF8(str).c_str()); - mir_free(dbei->pBlob); - dbei->pBlob = (PBYTE)msg2; - dbei->cbBlob = strlen(msg2)+1; - hcontact_data[hContact].msgs_to_tag.erase(i); - break; - } + hcontact_data[hContact].msgs_to_pass.erase(i); + event_processing_mutex.unlock(); + return 0; } } + event_processing_mutex.unlock(); } + return 1; } - if((dbei->eventType == EVENTTYPE_MESSAGE) && !(dbei->flags & DBEF_SENT) && metaIsProtoMetaContacts((HANDLE)w)) + if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)) + return 0; + if(!(dbei->flags & DBEF_SENT) && metaIsProtoMetaContacts((HANDLE)w)) { char tmp[29]; strncpy(tmp, (char*)dbei->pBlob, 27); @@ -883,11 +872,6 @@ int HookSendMsg(WPARAM w, LPARAM l) return 0; } -int TestHook(WPARAM w, LPARAM l) -{ - return 0; -} - static BOOL CALLBACK DlgProcKeyPassword(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { |