summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--messages.cpp55
-rw-r--r--utilities.cpp20
-rw-r--r--utilities.h67
3 files changed, 105 insertions, 37 deletions
diff --git a/messages.cpp b/messages.cpp
index 51bd113..f73223e 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
@@ -38,7 +38,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags)
bool isContactHaveKey(HANDLE hContact);
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(MessageBox(0, _T("We received encrypted message from contact with encryption turned off.\nDo you want turn on encryption for this contact ?"), _T("Warning"), MB_YESNO) == IDYES)
{
if(!isContactHaveKey(hContact))
@@ -65,7 +65,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;
}
}
@@ -160,13 +161,13 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags)
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;
@@ -211,13 +212,13 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags)
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;
}
}
@@ -230,13 +231,13 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags)
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;
@@ -257,7 +258,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;
}
@@ -289,7 +290,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;
}
@@ -303,13 +304,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);
+ 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(msg, timestamp, 0, dbflags));
mir_free(tmp);
return 0;
}
@@ -321,14 +322,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;
}
@@ -459,9 +460,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;
@@ -481,7 +482,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
{ //this is public key
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";
@@ -507,7 +508,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())
@@ -568,7 +569,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);
}
@@ -602,7 +603,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);
@@ -721,7 +722,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);
@@ -738,11 +739,11 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
hcontact_data[metaGetContact(hContact)].msgs_to_pass.push_back(str_event);
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), (char*)str_event.c_str(), EVENTTYPE_MESSAGE, DBEF_SENT|dbflags);
+ 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);
debuglog<<time_str()<<": adding event to contact: "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<" on send message.\n";
- HistoryLog(hContact, (char*)str_event.c_str(), EVENTTYPE_MESSAGE, dbflags|DBEF_SENT);
+ 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());
diff --git a/utilities.cpp b/utilities.cpp
index c8dc2ae..91ea9fb 100644
--- a/utilities.cpp
+++ b/utilities.cpp
@@ -201,7 +201,7 @@ int SendKey(WPARAM w, LPARAM l)
BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)szMessage);
- HistoryLog(hContact, "Public key sent", EVENTTYPE_MESSAGE, DBEF_SENT);
+ HistoryLog(hContact, db_event("Public key sent", 0, 0, DBEF_SENT));
DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc);
}
mir_free(szMessage);
@@ -586,16 +586,19 @@ void storeOutput(HANDLE ahandle, string *output)
} while (available>0);
}
-void HistoryLog(HANDLE hContact, char *data, int event_type, int flags)
+void HistoryLog(HANDLE hContact, db_event evt)
{
DBEVENTINFO Event = {0};
Event.cbSize = sizeof(Event);
Event.szModule = szGPGModuleName;
- Event.eventType = event_type;
- Event.flags = flags;
- Event.timestamp = (DWORD)time(NULL);
- Event.cbBlob = strlen(data)+1;
- Event.pBlob = (PBYTE)_strdup(data);
+ Event.eventType = evt.eventType;
+ Event.flags = evt.flags;
+ if(!evt.timestamp)
+ Event.timestamp = (DWORD)time(NULL);
+ else
+ Event.timestamp = evt.timestamp;
+ Event.cbBlob = strlen((char*)evt.pBlob)+1;
+ Event.pBlob = (PBYTE)_strdup((char*)evt.pBlob);
CallService(MS_DB_EVENT_ADD, (WPARAM)(HANDLE)hContact,(LPARAM)&Event);
}
@@ -1154,7 +1157,8 @@ void send_encrypted_msgs_thread(HANDLE hContact)
for(list<string>::iterator p = hcontact_data[hContact].msgs_to_send.begin(); p != end; ++p)
{
CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)p->c_str());
- HistoryLog(hContact, (char*)p->c_str(), EVENTTYPE_MESSAGE, DBEF_SENT);
+
+ HistoryLog(hContact, db_event((char*)p->c_str(),0,0, DBEF_SENT));
boost::this_thread::sleep(boost::posix_time::seconds(1));
}
return;
diff --git a/utilities.h b/utilities.h
index bb4b459..5922311 100644
--- a/utilities.h
+++ b/utilities.h
@@ -24,8 +24,6 @@ void GetFolderPath(TCHAR *WindowTittle, char *szSetting);
void storeOutput(HANDLE ahandle, string *output);
-
-void HistoryLog(HANDLE hContact, char *data, int event_type, int flags);
int ComboBoxAddStringUtf(HWND hCombo, const TCHAR *szString, DWORD data);
bool isContactSecured(HANDLE hContact);
bool isContactHaveKey(HANDLE hContact);
@@ -36,4 +34,69 @@ wstring toUTF16(string str);
string get_random(int length);
string time_str();
+struct db_event : public DBEVENTINFO
+{
+public:
+ db_event(char* msg)
+ {
+ eventType = EVENTTYPE_MESSAGE;
+ flags = 0;
+ timestamp = 0;
+ szModule = 0;
+ cbSize = 0;
+ cbBlob = strlen(msg)+1;
+ pBlob = (PBYTE)msg;
+ }
+ db_event(char* msg, DWORD time)
+ {
+ cbBlob = strlen(msg)+1;
+ pBlob = (PBYTE)msg;
+ eventType = EVENTTYPE_MESSAGE;
+ flags = 0;
+ timestamp = time;
+ szModule = 0;
+ cbSize = 0;
+ }
+ db_event(char* msg, DWORD time, int type)
+ {
+ cbBlob = strlen(msg)+1;
+ pBlob = (PBYTE)msg;
+ if(type)
+ eventType = type;
+ else
+ eventType = EVENTTYPE_MESSAGE;
+ flags = 0;
+ timestamp = time;
+ szModule = 0;
+ cbSize = 0;
+ }
+ db_event(char* msg, int type)
+ {
+ cbBlob = strlen(msg)+1;
+ pBlob = (PBYTE)msg;
+ flags = 0;
+ if(type)
+ eventType = type;
+ else
+ eventType = EVENTTYPE_MESSAGE;
+ timestamp = 0;
+ szModule = 0;
+ cbSize = 0;
+ }
+ db_event(char* msg, DWORD time, int type, DWORD _flags)
+ {
+ cbBlob = strlen(msg)+1;
+ pBlob = (PBYTE)msg;
+ if(type)
+ eventType = type;
+ else
+ eventType = EVENTTYPE_MESSAGE;
+ flags = _flags;
+ timestamp = time;
+ szModule = 0;
+ cbSize = 0;
+ }
+};
+void HistoryLog(HANDLE, db_event);
+
#endif