diff options
Diffstat (limited to 'messages.cpp')
-rw-r--r-- | messages.cpp | 177 |
1 files changed, 113 insertions, 64 deletions
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<<time_str()<<": GPG execution timed out, aborted\n"; + mir_free(msg); return 1; } if(result == pxNotFound) + { + mir_free(msg); return 1; + } { char *tmp = NULL; string::size_type s = output.find("gpg: key ") + strlen("gpg: key "); @@ -155,6 +148,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } } hcontact_data[hContact].msgs_to_ignore.push_back(msg); + mir_free(msg); return 1; } } @@ -171,7 +165,11 @@ int RecvMsgSvc(WPARAM w, LPARAM l) if((s2 != wstring::npos) && (s1 != wstring::npos)) { //this is public key if(metaIsSubcontact(hContact)) - return CallService(MS_PROTO_CHAINRECV, w, l); //yet another metacontacts problem + { + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + mir_free(msg); + return 0; + } debuglog<<time_str()<<": info: "<<"received key from: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"\n"; s1 = 0; while((s1 = str.find(_T("\r"), s1)) != wstring::npos) @@ -195,7 +193,9 @@ int RecvMsgSvc(WPARAM w, LPARAM l) new_key_hcnt_mutex.lock(); new_key_hcnt = hContact; ShowNewKeyDialog(); - return CallService(MS_PROTO_CHAINRECV, w, l); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + mir_free(msg); + return 0; } if(bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && isGPGConfigured()) { @@ -251,6 +251,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } } } + mir_free(msg); return 1; } s1 = str.find(_T("-----BEGIN PGP MESSAGE-----")); @@ -288,7 +289,11 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } } else if(MessageBox(0, _T("Do you want try to decrypt encrypted message ?"), _T("Warning"), MB_YESNO) == IDNO) - return CallService(MS_PROTO_CHAINRECV, w, l); + { + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + mir_free(msg); + return 0; + } } { wstring::size_type p = 0; @@ -371,12 +376,16 @@ int RecvMsgSvc(WPARAM w, LPARAM l) delete gpg_thread; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; DeleteFile(path.c_str()); - return CallService(MS_PROTO_CHAINRECV, w, l); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + mir_free(msg); + return 0; } if(result == pxNotFound) { DeleteFile(path.c_str()); - return CallService(MS_PROTO_CHAINRECV, w, l); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + mir_free(msg); + return 0; } _terminate = false; while(out.find("public key decryption failed: bad passphrase") != string::npos) @@ -418,12 +427,16 @@ int RecvMsgSvc(WPARAM w, LPARAM l) delete gpg_thread; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; DeleteFile(path.c_str()); - return CallService(MS_PROTO_CHAINRECV, w, l); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + mir_free(msg); + return 0; } if(result == pxNotFound) { DeleteFile(path.c_str()); - return CallService(MS_PROTO_CHAINRECV, w, l); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + mir_free(msg); + return 0; } } out.clear(); @@ -433,12 +446,14 @@ int RecvMsgSvc(WPARAM w, LPARAM l) delete gpg_thread; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; DeleteFile(path.c_str()); - return CallService(MS_PROTO_CHAINRECV, w, l); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); + mir_free(msg); + return 0; } if(result == pxNotFound) { DeleteFile(path.c_str()); - return CallService(MS_PROTO_CHAINRECV, w, l); + HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, flags); } { wstring tmp = tmp2; @@ -452,14 +467,15 @@ int RecvMsgSvc(WPARAM w, LPARAM l) { if(errno == ENOENT) { - string str = pre->szMessage; - mir_free((void**)pre->szMessage); + string str = msg; str.insert(0, "Received unencrypted message:\n"); debuglog<<time_str()<<": info: Failed to decrypt GPG encrypted message.\n"; char *tmp = new char [str.length()+1]; strcpy(tmp, str.c_str()); - pre->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<<time_str()<<": info: Failed to decrypt GPG encrypted 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; } 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<<time_str()<<": GPG execution timed out, aborted\n"; - return CallService(MS_PROTO_CHAINSEND, w, l); + return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); } if(result == pxNotFound) - return CallService(MS_PROTO_CHAINSEND, w, l); + 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(); @@ -698,10 +724,10 @@ int SendMsgSvc(WPARAM w, LPARAM l) { gpg_thread.~thread(); debuglog<<time_str()<<": GPG execution timed out, aborted\n"; - return CallService(MS_PROTO_CHAINSEND, w, l); + return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); } if(result == pxNotFound) - return CallService(MS_PROTO_CHAINSEND, w, l); + return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); } else return 0; @@ -710,7 +736,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) { MessageBox(0, _T("Something wrong, gpg does not understand us, aborting encryption."), _T("Warning"), MB_OK); DeleteFile(path.c_str()); - return CallService(MS_PROTO_CHAINSEND, w, l); + return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); } DeleteFile(path.c_str()); path.append(_T(".asc")); @@ -732,11 +758,11 @@ int SendMsgSvc(WPARAM w, LPARAM l) { HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT); debuglog<<time_str()<<": info: Failed to encrypt message with GPG"; - return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); + 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 = (char*)ccs->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) |