summaryrefslogtreecommitdiff
path: root/utilities.cpp
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2011-04-13 16:43:43 +0300
committerGluzskiy Alexandr <sss123next@list.ru>2011-04-13 16:43:43 +0300
commit191c2e330ab91f4b35860e08c5424667ed1893c5 (patch)
tree986158bd87ca65c1a3a722f2593b9d32a1aede56 /utilities.cpp
parentf1a201a3c3aeb1ec731d50568eb583a21ed1440c (diff)
parent3d4fe3639635d0496906fb56b8014b14b0fd1ec7 (diff)
Merge branch 'new_gpg' into new_gpg_autoexchange
Conflicts: messages.cpp
Diffstat (limited to 'utilities.cpp')
-rw-r--r--utilities.cpp71
1 files changed, 41 insertions, 30 deletions
diff --git a/utilities.cpp b/utilities.cpp
index d368c56..dbf8786 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);
@@ -218,25 +218,23 @@ int ToggleEncryption(WPARAM w, LPARAM l)
enc = DBGetContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0);
else
enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
+ if(metaIsProtoMetaContacts(hContact))
{
- if(metaIsProtoMetaContacts(hContact))
+ HANDLE hcnt = NULL;
+ if(MessageBox(0, _T("Do you want to toggle encryption for all subcontacts ?"), _T("Metacontact detected"), MB_YESNO) == IDYES)
{
- HANDLE hcnt = NULL;
- if(MessageBox(0, _T("Do you want to toggle encryption for all subcontacts ?"), _T("Metacontact detected"), MB_YESNO) == IDYES)
+ int count = metaGetContactsNum(hContact);
+ for(int i = 0; i < count; i++)
{
- int count = metaGetContactsNum(hContact);
- for(int i = 0; i < count; i++)
- {
- hcnt = metaGetSubcontact(hContact, i);
- if(hcnt)
- DBWriteContactSettingByte(hcnt, szGPGModuleName, "GPGEncryption", enc?0:1);
- }
- DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc?0:1);
+ hcnt = metaGetSubcontact(hContact, i);
+ if(hcnt)
+ DBWriteContactSettingByte(hcnt, szGPGModuleName, "GPGEncryption", enc?0:1);
}
+ DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc?0:1);
}
- else
- DBWriteContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", enc?0:1);
}
+ else
+ DBWriteContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", enc?0:1);
void setSrmmIcon(HANDLE hContact);
void setClistIcon(HANDLE hContact);
setSrmmIcon(hContact);
@@ -380,6 +378,7 @@ int onProtoAck(WPARAM w, LPARAM l)
{
delete gpg_thread;
TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
return 0;
}
@@ -424,6 +423,7 @@ int onProtoAck(WPARAM w, LPARAM l)
{
delete gpg_thread;
TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
DeleteFile(filename);
return 0;
@@ -490,6 +490,7 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename)
{
delete gpg_thread;
TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
return 0;
}
@@ -505,6 +506,7 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename)
{
delete gpg_thread;
TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
return 0;
}
@@ -582,16 +584,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);
}
@@ -771,6 +776,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU
{
gpg_thread.~thread();
TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
debuglog<<time_str()<<"GPG execution timed out, aborted\n";
}
DeleteFile(path_out.c_str());
@@ -899,17 +905,15 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi
{
gpg_thread.~thread();
TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
-// sign_file_mutex.unlock();
return FALSE;
}
if(result == pxNotFound)
{
-// sign_file_mutex.unlock();
return FALSE;
}
DeleteFile(path_out.c_str());
-// sign_file_mutex.unlock();
if(out.find("key ID ") != string::npos)
{
//need to get hcontact here, i can get jid from hxml, and get handle from jid, maybe exists better way ?
@@ -975,18 +979,24 @@ void AddHandlers()
bool isContactSecured(HANDLE hContact)
{
- if(metaIsProtoMetaContacts(hContact))
- hContact = metaGetContact(hContact);
BYTE gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
if(!gpg_enc)
+ {
+ debuglog<<time_str()<<": encryption is turned off for "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"\n";
return false;
- TCHAR *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T(""));
- if(!key[0])
+ }
+ if(!metaIsProtoMetaContacts(hContact))
{
+ TCHAR *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T(""));
+ if(!key[0])
+ {
+ mir_free(key);
+ debuglog<<time_str()<<": encryption is turned off for "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"\n";
+ return false;
+ }
mir_free(key);
- return false;
}
- mir_free(key);
+ debuglog<<time_str()<<": encryption is turned on for "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)<<"\n";
return true;
}
@@ -1147,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;