diff options
Diffstat (limited to 'messages.cpp')
-rw-r--r-- | messages.cpp | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/messages.cpp b/messages.cpp index 924c0de..8b339ab 100644 --- a/messages.cpp +++ b/messages.cpp @@ -23,7 +23,7 @@ boost::mutex new_key_hcnt_mutex; bool _terminate = false; int returnNoError(HANDLE hContact); -int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) +int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, DWORD timestamp) { DWORD dbflags = DBEF_UTF; { //check for gpg related data @@ -36,9 +36,9 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) void setSrmmIcon(HANDLE); void setClistIcon(HANDLE); bool isContactHaveKey(HANDLE hContact); - if(!DBGetContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0)) + if(!isContactSecured(hContact)) { - debuglog<<time_str()<<": info: "<<"received message from: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" whith tyrned off encryption\n"; + debuglog<<time_str()<<": info: "<<"received message from: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" with turned off encryption\n"; if(bAutoExchange) { if(!isContactHaveKey(hContact)) @@ -89,7 +89,8 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, 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, dbflags); + + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); return 0; } } @@ -181,15 +182,16 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) { delete gpg_thread; TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; DeleteFile(path.c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); return 0; } if(result == pxNotFound) { DeleteFile(path.c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); return 0; } _terminate = false; @@ -231,15 +233,16 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) { delete gpg_thread; TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; DeleteFile(path.c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); return 0; } if(result == pxNotFound) { DeleteFile(path.c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); return 0; } } @@ -249,15 +252,16 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) { delete gpg_thread; TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; DeleteFile(path.c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); return 0; } if(result == pxNotFound) { DeleteFile(path.c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); } { wstring tmp = tmp2; @@ -278,7 +282,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, 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, dbflags); + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); mir_free(tmp); return 0; } @@ -310,7 +314,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, 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, dbflags); + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); mir_free(tmp); return 0; } @@ -324,12 +328,13 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) if(metaIsSubcontact(hContact)) { char *msg = mir_strdup(toUTF8(str).c_str()); - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags|DBEF_READ); - HistoryLog(metaGetContact(hContact), msg, EVENTTYPE_MESSAGE, dbflags); - return 1; + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags|DBEF_READ)); + HistoryLog(metaGetContact(hContact), db_event(msg, timestamp, 0, dbflags)); + mir_free(msg); + return 0; } char *tmp = mir_strdup(toUTF8(str).c_str()); - HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, dbflags); + HistoryLog(hContact, db_event(tmp, timestamp, 0, dbflags)); mir_free(tmp); return 0; } @@ -341,14 +346,14 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags) { if(metaIsSubcontact(hContact)) { - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags| DBEF_READ); - HistoryLog(metaGetContact(hContact), msg, EVENTTYPE_MESSAGE, dbflags); + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags|DBEF_READ)); + HistoryLog(metaGetContact(hContact), db_event(msg, timestamp, 0, dbflags)); return 0; } - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags|DBEF_READ); + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags|DBEF_READ)); return 0; } - HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags); + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); return 0; } @@ -413,6 +418,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; return 1; } @@ -478,9 +484,9 @@ int RecvMsgSvc(WPARAM w, LPARAM l) { setSrmmIcon(metaGetContact(ccs->hContact)); setClistIcon(metaGetContact(ccs->hContact)); - HistoryLog(metaGetContact(ccs->hContact), "PGP Encryption turned on by key autoexchange feature", EVENTTYPE_MESSAGE, 0); + HistoryLog(metaGetContact(ccs->hContact), "PGP Encryption turned on by key autoexchange feature"); } - HistoryLog(ccs->hContact, "PGP Encryption turned on by key autoexchange feature", EVENTTYPE_MESSAGE, 0); + HistoryLog(ccs->hContact, "PGP Encryption turned on by key autoexchange feature"); } } return 1; @@ -498,9 +504,9 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } if((s2 != wstring::npos) && (s1 != wstring::npos)) { //this is public key - if(metaIsSubcontact(ccs->hContact)) + if(metaIsProtoMetaContacts(ccs->hContact)) { - HistoryLog(ccs->hContact, msg, EVENTTYPE_MESSAGE, dbflags); + HistoryLog(ccs->hContact, db_event(msg, 0, 0, dbflags)); return 0; } debuglog<<time_str()<<": info: "<<"received key from: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<"\n"; @@ -526,7 +532,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) new_key_hcnt_mutex.lock(); new_key_hcnt = ccs->hContact; ShowNewKeyDialog(); - HistoryLog(ccs->hContact, msg, EVENTTYPE_MESSAGE, dbflags); + HistoryLog(ccs->hContact, db_event(msg, 0, 0, dbflags)); return 0; } if(bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && isGPGConfigured()) @@ -587,7 +593,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) } if(!(strstr(msg, "-----BEGIN PGP MESSAGE-----") && strstr(msg, "-----END PGP MESSAGE-----"))) return CallService(MS_PROTO_CHAINRECV, w, l); - boost::thread *thr = new boost::thread(boost::bind(RecvMsgSvc_func, ccs->hContact, str, msg, ccs->wParam)); + boost::thread *thr = new boost::thread(boost::bind(RecvMsgSvc_func, ccs->hContact, str, msg, ccs->wParam, pre->timestamp)); return returnNoError(ccs->hContact); } @@ -621,7 +627,7 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) if(!tmp[0]) { mir_free(tmp); - HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT); + HistoryLog(hContact, db_event("Failed to encrypt message with GPG", 0,0, 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); @@ -667,6 +673,7 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; mir_free(msg); return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); @@ -721,6 +728,7 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { gpg_thread.~thread(); TerminateProcess(params.hProcess, 1); + params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; mir_free(msg); return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); @@ -764,7 +772,7 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) } if(str.empty()) { - HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT); + HistoryLog(hContact, db_event("Failed to encrypt message with GPG", 0,0, 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\n"; mir_free(msg); @@ -779,10 +787,13 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) 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); + debuglog<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"is subcontact of"<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)metaGetContact(hContact), GCDNF_TCHAR)<<"\n"; + debuglog<<time_str()<<": adding event to metacontact: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)metaGetContact(hContact), GCDNF_TCHAR)<<" on send message.\n"; + HistoryLog(metaGetContact(hContact), db_event((char*)str_event.c_str(), 0,0, 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); + debuglog<<time_str()<<": adding event to contact: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" on send message.\n"; + HistoryLog(hContact, db_event((char*)str_event.c_str(), 0,0, dbflags|DBEF_SENT)); if(!(flags & PREF_UTF)) flags |= PREF_UTF; CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)toUTF8(str).c_str()); @@ -901,6 +912,7 @@ int HookSendMsg(WPARAM w, LPARAM l) if(!strcmp((*i).c_str(), (char*)dbei->pBlob)) { hcontact_data[hContact].msgs_to_pass.erase(i); + debuglog<<time_str()<<": event message: \""<<(char*)dbei->pBlob<<"\" passed event filter, contact "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<", message is in allowed list\n"; event_processing_mutex.unlock(); return 0; } @@ -910,7 +922,10 @@ int HookSendMsg(WPARAM w, LPARAM l) return 1; } if(!isContactSecured(hContact)) + { + debuglog<<time_str()<<": event message: \""<<(char*)dbei->pBlob<<"\" passed event filter, contact "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" is unsecured\n"; return 0; + } if(!(dbei->flags & DBEF_SENT) && metaIsProtoMetaContacts((HANDLE)w)) { char tmp[29]; |