diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2011-03-30 08:51:28 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2011-03-30 08:51:28 +0300 |
commit | 8174eb73282e177112615c2dd332b69401959764 (patch) | |
tree | 7388d613aacc928cfb006341ed7b66bc27ce09ab /utilities.cpp | |
parent | c5e0140f26c8f95a1f83f1e2c86e1eb11820e901 (diff) |
one more threading variant (without mutexes)
Diffstat (limited to 'utilities.cpp')
-rw-r--r-- | utilities.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/utilities.cpp b/utilities.cpp index e87bb8c..43d5828 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -376,7 +376,7 @@ int onProtoAck(WPARAM w, LPARAM l) params.code = &code; params.result = &result; boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::minutes(10))) + if(!gpg_thread->timed_join(boost::posix_time::minutes(15))) { delete gpg_thread; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; @@ -419,7 +419,7 @@ int onProtoAck(WPARAM w, LPARAM l) params.code = &code; params.result = &result; gpg_thread = gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::seconds(10))) + if(!gpg_thread->timed_join(boost::posix_time::seconds(15))) { delete gpg_thread; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; @@ -689,8 +689,10 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU { TCHAR *path_c = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); wstring path_out = path_c; + wstring file = toUTF16(get_random(10)); mir_free(path_c); - path_out += _T("\\prescense_text"); + path_out += _T("\\tmp\\"); + path_out += file; DeleteFile(path_out.c_str()); wfstream f(path_out.c_str(), std::ios::out); f<<toUTF8(str).c_str(); @@ -761,7 +763,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU params.code = &code; params.result = &result; boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + if(!gpg_thread.timed_join(boost::posix_time::seconds(15))) { gpg_thread.~thread(); debuglog<<time_str()<<"GPG execution timed out, aborted\n"; @@ -829,7 +831,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU return FALSE; } -boost::mutex sign_file_mutex; +//boost::mutex sign_file_mutex; static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, void *pUserData) { @@ -850,13 +852,15 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi { LPCTSTR data = xi.getText(local_node); wstring sign = _T("-----BEGIN PGP MESSAGE-----\n\n"); + wstring file = toUTF16(get_random(10)); sign += data; sign += _T("\n-----END PGP MESSAGE-----\n"); TCHAR *path_c = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); wstring path_out = path_c; mir_free(path_c); - path_out += _T("\\sign.asc"); - sign_file_mutex.lock(); + path_out += _T("\\tmp\\"); + path_out += file; +// sign_file_mutex.lock(); DeleteFile(path_out.c_str()); wfstream f(path_out.c_str(), std::ios::out); while(!f.is_open()) @@ -867,7 +871,7 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi { if(errno == ENOENT) { - sign_file_mutex.unlock(); +// sign_file_mutex.unlock(); debuglog<<time_str()<<": info: Failed to write sign in file\n"; return FALSE; } @@ -886,20 +890,20 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi params.code = &code; params.result = &result; boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + if(!gpg_thread.timed_join(boost::posix_time::seconds(15))) { gpg_thread.~thread(); debuglog<<time_str()<<": GPG execution timed out, aborted\n"; - sign_file_mutex.unlock(); +// sign_file_mutex.unlock(); return FALSE; } if(result == pxNotFound) { - sign_file_mutex.unlock(); +// sign_file_mutex.unlock(); return FALSE; } DeleteFile(path_out.c_str()); - sign_file_mutex.unlock(); +// 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 ? @@ -965,19 +969,16 @@ void AddHandlers() bool isContactSecured(HANDLE hContact) { + if(!DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)) + return false; TCHAR *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); if(!key[0]) { mir_free(key); - key = UniGetContactSettingUtf(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", _T("")); - } - if((DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0) > 0 || DBGetContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0) > 0) && (_tcslen(key) > 0)) - { - mir_free(key); - return true; + return false; } mir_free(key); - return false; + return true; } bool isContactHaveKey(HANDLE hContact) |