From 0ab2db678a2a79f624a74a51ac617110d9b4413e Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 22 Mar 2011 08:23:16 +0200 Subject: extended threading (test) --- messages.cpp | 177 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 113 insertions(+), 64 deletions(-) (limited to 'messages.cpp') diff --git a/messages.cpp b/messages.cpp index dbb87c2..b37bbd0 100644 --- a/messages.cpp +++ b/messages.cpp @@ -23,24 +23,13 @@ boost::mutex new_key_hcnt_mutex; bool _terminate = false; int returnNoError(HANDLE hContact); -int RecvMsgSvc(WPARAM w, LPARAM l) +int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { - CCSDATA *ccs = (CCSDATA*)l; - if (!ccs) - return CallService(MS_PROTO_CHAINRECV, w, l); - PROTORECVEVENT *pre = (PROTORECVEVENT*)(ccs->lParam); - if (!pre) - return CallService(MS_PROTO_CHAINRECV, w, l); - char *msg = pre->szMessage; - if (!msg) - return CallService(MS_PROTO_CHAINRECV, w, l); - HANDLE hContact = ccs->hContact; - { //check for gpg related data wstring str = toUTF16(msg); wstring::size_type s1 = wstring::npos, s2 = wstring::npos; - if((str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos) && !metaIsProtoMetaContacts(ccs->hContact)) + if((str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos) && !metaIsProtoMetaContacts(hContact)) { s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); @@ -85,10 +74,14 @@ int RecvMsgSvc(WPARAM w, LPARAM l) { gpg_thread.~thread(); debuglog<szMessage; - mir_free((void**)pre->szMessage); + string str = msg; str.insert(0, "Received unencrypted message:\n"); debuglog<szMessage = tmp; - return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); + HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, flags); + mir_free(tmp); + mir_free(msg); + return 0; } } } @@ -486,12 +502,14 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } if(str.empty()) { - string str = pre->szMessage; - mir_free((void**)pre->szMessage); + string str = msg; str.insert(0, "Failed to decrypt GPG encrypted message.\nMessage body for manual decryption:\n"); debuglog<szMessage = mir_strdup(str.c_str()); - return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); + char *tmp = mir_strdup(str.c_str()); + HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, flags); + mir_free(tmp); + mir_free(msg); + return 0; } else { @@ -508,9 +526,13 @@ int RecvMsgSvc(WPARAM w, LPARAM l) mir_free(msg); return 1; } - mir_free((void**)pre->szMessage); - pre->szMessage = mir_strdup(toUTF8(str).c_str()); - return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); + char *tmp = mir_strdup(toUTF8(str).c_str()); + if(!(flags & DBEF_UTF)) + flags |= DBEF_UTF; + HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, flags); + mir_free(tmp); + mir_free(msg); + return 0; } } } @@ -526,31 +548,35 @@ int RecvMsgSvc(WPARAM w, LPARAM l) return 1; } string str = msg; - mir_free((void**)pre->szMessage); str.insert(0, "Received unencrypted message:\n"); - pre->szMessage = mir_strdup(str.c_str()); - return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); + char *tmp = mir_strdup(str.c_str()); + HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, flags); + mir_free(tmp); + mir_free(msg); + return 0; } - return CallService(MS_PROTO_CHAINRECV, w, l); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + mir_free(msg); + return 0; } -int SendMsgSvc(WPARAM w, LPARAM l) +int RecvMsgSvc(WPARAM w, LPARAM l) { CCSDATA *ccs = (CCSDATA*)l; if (!ccs) - return CallService(MS_PROTO_CHAINSEND, w, l); - - char *msg = (char*)(ccs->lParam); + return CallService(MS_PROTO_CHAINRECV, w, l); + PROTORECVEVENT *pre = (PROTORECVEVENT*)(ccs->lParam); + if (!pre) + return CallService(MS_PROTO_CHAINRECV, w, l); + char *msg = mir_strdup(pre->szMessage); if (!msg) - return CallService(MS_PROTO_CHAINSEND, w, l); - if(strstr(msg,"-----BEGIN PGP MESSAGE-----")) //metecontacts .... %) - return CallService(MS_PROTO_CHAINSEND, w, l); - HANDLE hContact = ccs->hContact; - if(metaIsProtoMetaContacts(hContact)) - { - hcontact_data[ccs->hContact].msgs_to_ignore.push_back((char*)ccs->lParam); - return CallService(MS_PROTO_CHAINSEND, w, l); - } + return CallService(MS_PROTO_CHAINRECV, w, l); + boost::thread *thr = new boost::thread(boost::bind(RecvMsgSvc_func, ccs->hContact, msg, ccs->wParam)); + return returnNoError(ccs->hContact); +} + +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); @@ -564,7 +590,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) strcpy(cap.caps, "GPG AutoExchange"); if(CallService("ICQ"PS_ICQ_CHECKCAPABILITY, (WPARAM)hContact, (LPARAM)&cap)) { - CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); + 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)); @@ -595,7 +621,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(caps); if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) { - CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"-----PGP KEY REQUEST-----"); + 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)); @@ -607,7 +633,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) } } if(!isContactSecured(hContact)) - return CallService(MS_PROTO_CHAINSEND, w, l); + return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); { //encrypt data here wstring str; @@ -636,7 +662,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) { mir_free(tmp); HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT); - return CallService(MS_PROTO_CHAINSEND, w, l); + 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 "); @@ -675,10 +701,10 @@ int SendMsgSvc(WPARAM w, LPARAM l) { gpg_thread.~thread(); debuglog<lParam; + string str_event = msg; if(bAppendTags) { //utf8 tag will cause problems here str_event.insert(0, toUTF8(outopentag)); @@ -755,11 +781,34 @@ int SendMsgSvc(WPARAM w, LPARAM l) return returnNoError(hContact); } if(bAppendTags) - hcontact_data[hContact].msgs_to_tag.push_back((char*)ccs->lParam); - ccs->lParam = (LPARAM)mir_strdup(toUTF8(str).c_str()); + hcontact_data[hContact].msgs_to_tag.push_back(msg); + mir_free(msg); + msg = mir_strdup(toUTF8(str).c_str()); } } - return CallService(MS_PROTO_CHAINSEND, w, l); + if(!(flags & PREF_UTF)) + flags |= PREF_UTF; + CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); + return 0; +} + +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)); + if (!msg) + return CallService(MS_PROTO_CHAINSEND, w, l); + if(strstr(msg,"-----BEGIN PGP MESSAGE-----")) + return CallService(MS_PROTO_CHAINSEND, w, l); + if(metaIsProtoMetaContacts(ccs->hContact)) + { + hcontact_data[ccs->hContact].msgs_to_ignore.push_back((char*)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); } int HookSendMsg(WPARAM w, LPARAM l) -- cgit v1.2.3