summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2011-03-30 08:51:28 +0300
committerGluzskiy Alexandr <sss123next@list.ru>2011-03-30 08:51:28 +0300
commit8174eb73282e177112615c2dd332b69401959764 (patch)
tree7388d613aacc928cfb006341ed7b66bc27ce09ab
parentc5e0140f26c8f95a1f83f1e2c86e1eb11820e901 (diff)
one more threading variant (without mutexes)
-rw-r--r--gpg_wrapper.cpp16
-rw-r--r--main.cpp9
-rw-r--r--messages.cpp63
-rw-r--r--new_gpg.vcxproj12
-rw-r--r--utilities.cpp39
5 files changed, 60 insertions, 79 deletions
diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp
index 3091566..b85d24b 100644
--- a/gpg_wrapper.cpp
+++ b/gpg_wrapper.cpp
@@ -18,12 +18,12 @@
//thx gpg module from Harald Treder, Zakhar V. Bardymov
-boost::mutex gpg_mutex;
+//boost::mutex gpg_mutex;
pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result)
{
- gpg_mutex.lock();
+// gpg_mutex.lock();
if(!gpg_configured)
return pxNotConfigured;
extern logtofile debuglog;
@@ -80,6 +80,7 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD
if(errno == ENOENT)
{
mir_free(bin_path);
+ debuglog<<time_str()<<": GPG executable not found\n";
*result = pxNotFound;
return pxNotFound;
}
@@ -99,7 +100,7 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD
delete [] home_dir;
}
- debuglog<<time_str()<<": gpg in: "<<commandline;
+ debuglog<<time_str()<<": gpg in: "<<commandline<<"\n";
success = CreateProcess(NULL, (TCHAR*)commandline.c_str(), NULL, NULL, TRUE, CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT, (void*)_T("LANGUAGE=en@quot\0LC_ALL=English\0"), NULL, &sinfo, &pri);
@@ -110,7 +111,8 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD
CloseHandle(writestdin);
CloseHandle(newstdout);
CloseHandle(readstdout);
- gpg_mutex.unlock();
+ debuglog<<time_str()<<": Failed to create process\n";
+// gpg_mutex.unlock();
*result = pxCreateProcessFailed;
return pxCreateProcessFailed;
}
@@ -147,7 +149,7 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD
CloseHandle(writestdin);
*result = pxSuccess;
- gpg_mutex.unlock();
+// gpg_mutex.unlock();
return pxSuccess;
}
@@ -155,8 +157,4 @@ void pxEexcute_thread(void *param)
{
gpg_execution_params *params = (gpg_execution_params*)param;
pxResult result = pxExecute(params->cmd, params->useless, params->out, params->code, params->result);
- if(result == pxNotFound)
- {
- debuglog<<time_str()<<": Gpg binary not found";
- }
}
diff --git a/main.cpp b/main.cpp
index f35ff70..ad091f6 100644
--- a/main.cpp
+++ b/main.cpp
@@ -876,7 +876,6 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
gpg_configured = false;
if(result == pxNotFound)
break;
-
DeleteFile(path.c_str());
string::size_type p1 = 0;
if((p1 = out.find("key ")) != string::npos)
@@ -1221,10 +1220,7 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam,
break;
}
if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
break;
- }
}
DeleteFile(path.c_str());
DestroyWindow(hwndDlg);
@@ -1753,6 +1749,11 @@ void InitCheck()
if(result == pxNotFound)
return;
}
+ TCHAR *home_dir = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
+ wstring tmp_dir = home_dir;
+ mir_free(home_dir);
+ tmp_dir += _T("\\tmp");
+ _wmkdir(tmp_dir.c_str());
string question = "Your secret key whith id: ";
char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", "");
question += keyid;
diff --git a/messages.cpp b/messages.cpp
index ef6cf97..3426b5e 100644
--- a/messages.cpp
+++ b/messages.cpp
@@ -19,7 +19,7 @@
wstring new_key;
HANDLE new_key_hcnt = NULL;
-boost::mutex new_key_hcnt_mutex, gpg_file_mutex;
+boost::mutex new_key_hcnt_mutex;
bool _terminate = false;
int returnNoError(HANDLE hContact);
@@ -78,10 +78,11 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags)
char *tmp = mir_t2a(str.substr(s1,s2-s1).c_str());
TCHAR *tmp2 = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
wstring path = tmp2;
- path.append(_T("\\encrypted_data.asc"));
+ wstring encfile = toUTF16(get_random(10));
+ wstring decfile = toUTF16(get_random(10));
+ path.append(_T("\\tmp\\"));
+ path.append(encfile);
DeleteFile(path.c_str());
- while(!gpg_file_mutex.timed_lock(boost::posix_time::seconds(15)))
- gpg_file_mutex.unlock();
fstream f(path.c_str(), std::ios::out);
while(!f.is_open())
f.open(path.c_str(), std::ios::out);
@@ -132,12 +133,15 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags)
}
{
wstring path = tmp2;
- path += _T("\\decrypted_data");
+ path += _T("\\tmp\\");
+ path += decfile;
DeleteFile(path.c_str());
}
cmd += _T("--output \"");
cmd += tmp2;
- cmd += _T("\\decrypted_data\"");
+ cmd += _T("\\tmp\\");
+ cmd += decfile;
+ cmd += _T("\"");
cmd += _T(" -d -a \"");
cmd += path;
cmd += _T("\"");
@@ -155,14 +159,12 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags)
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
DeleteFile(path.c_str());
HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags);
- gpg_file_mutex.unlock();
return 0;
}
if(result == pxNotFound)
{
DeleteFile(path.c_str());
HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags);
- gpg_file_mutex.unlock();
return 0;
}
_terminate = false;
@@ -206,14 +208,12 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags)
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
DeleteFile(path.c_str());
HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags);
- gpg_file_mutex.unlock();
return 0;
}
if(result == pxNotFound)
{
DeleteFile(path.c_str());
HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags);
- gpg_file_mutex.unlock();
return 0;
}
}
@@ -225,7 +225,6 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags)
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
DeleteFile(path.c_str());
HistoryLog(hContact, msg, EVENTTYPE_MESSAGE, dbflags);
- gpg_file_mutex.unlock();
return 0;
}
if(result == pxNotFound)
@@ -235,12 +234,14 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags)
}
{
wstring tmp = tmp2;
- tmp += _T("\\encrypted_data.asc");
+ tmp += _T("\\tmp\\");
+ tmp += encfile;
DeleteFile(tmp.c_str());
}
{
wstring tmp = tmp2;
- tmp += _T("\\decrypted_data");
+ tmp += _T("\\tmp\\");
+ tmp += decfile;
if(_waccess(tmp.c_str(), 0) == -1)
{
if(errno == ENOENT)
@@ -252,19 +253,16 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags)
strcpy(tmp, str.c_str());
HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, dbflags);
mir_free(tmp);
- gpg_file_mutex.unlock();
return 0;
}
}
}
- gpg_file_mutex.unlock();
str.clear();
{
wstring path = tmp2;
mir_free(tmp2);
- path += _T("\\decrypted_data");
- while(!gpg_file_mutex.timed_lock(boost::posix_time::seconds(15)))
- gpg_file_mutex.unlock();
+ path += _T("\\tmp\\");
+ path += decfile;
fstream f(path.c_str(), std::ios::in | std::ios::ate | std::ios::binary);
if(f.is_open())
{
@@ -278,10 +276,7 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags)
delete [] tmp;
f.close();
DeleteFile(path.c_str());
- gpg_file_mutex.unlock();
}
- else
- gpg_file_mutex.unlock();
if(str.empty())
{
string str = msg;
@@ -309,7 +304,6 @@ int RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags)
char *tmp = mir_strdup(toUTF8(str).c_str());
HistoryLog(hContact, tmp, EVENTTYPE_MESSAGE, dbflags);
mir_free(tmp);
- gpg_file_mutex.unlock();
return 0;
}
}
@@ -367,8 +361,6 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
_tcscat(tmp2, _T("\\"));
_tcscat(tmp2, _T("temporary_exported.asc"));
DeleteFile(tmp2);
- while(!gpg_file_mutex.timed_lock(boost::posix_time::seconds(15)))
- gpg_file_mutex.unlock();
wfstream f(tmp2, std::ios::out);
while(!f.is_open())
f.open(tmp2, std::ios::out);
@@ -394,15 +386,10 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
{
gpg_thread.~thread();
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
- gpg_file_mutex.unlock();
return 1;
}
if(result == pxNotFound)
- {
- gpg_file_mutex.unlock();
return 1;
- }
- gpg_file_mutex.unlock();
{
char *tmp = NULL;
string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
@@ -599,6 +586,7 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
string out;
DWORD code;
wstring cmd;
+ wstring file = toUTF16(get_random(10));
wstring path;
extern bool bJabberAPI, bIsMiranda09;
char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", "");
@@ -624,14 +612,14 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
path.append(tmp2);
cmd += tmp2;
mir_free(tmp2);
- cmd += _T("\\exported_data");
- path.append(_T("\\exported_data"));
+ cmd += _T("\\tmp\\");
+ cmd += file;
+ path.append(_T("\\tmp\\"));
+ path += file;
cmd += _T("\"");
{
char *tmp;
tmp = mir_strdup(toUTF8(str).c_str());
- while(!gpg_file_mutex.timed_lock(boost::posix_time::seconds(15)))
- gpg_file_mutex.unlock();
fstream f(path.c_str(), std::ios::out);
while(!f.is_open())
f.open(path.c_str(), std::ios::out);
@@ -652,13 +640,11 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
gpg_thread.~thread();
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
mir_free(msg);
- gpg_file_mutex.unlock();
return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
}
if(result == pxNotFound)
{
mir_free(msg);
- gpg_file_mutex.unlock();
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)
@@ -681,20 +667,17 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
gpg_thread.~thread();
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
mir_free(msg);
- gpg_file_mutex.unlock();
return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
}
if(result == pxNotFound)
{
mir_free(msg);
- gpg_file_mutex.unlock();
return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
}
}
else
{
mir_free(msg);
- gpg_file_mutex.unlock();
return 0;
}
}
@@ -703,7 +686,6 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
MessageBox(0, _T("Something wrong, gpg does not understand us, aborting encryption."), _T("Warning"), MB_OK);
DeleteFile(path.c_str());
mir_free(msg);
- gpg_file_mutex.unlock();
return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
}
DeleteFile(path.c_str());
@@ -724,12 +706,11 @@ int SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
f.close();
DeleteFile(path.c_str());
}
- gpg_file_mutex.unlock();
if(str.empty())
{
HistoryLog(hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, 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";
+ debuglog<<time_str()<<": info: Failed to encrypt message with GPG\n";
mir_free(msg);
return CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
}
diff --git a/new_gpg.vcxproj b/new_gpg.vcxproj
index dee7bef..59b9299 100644
--- a/new_gpg.vcxproj
+++ b/new_gpg.vcxproj
@@ -477,7 +477,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
- <AdditionalIncludeDirectories>x:\temp\windows\libs\utf8cpp\include;X:\temp\windows\libs\Boost\include\boost-1_46;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>e:\temp\windows\libs\utf8cpp\include;e:\temp\windows\libs\Boost\include\boost-1_46;e:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
@@ -501,7 +501,7 @@
<Link>
<AdditionalDependencies>shlwapi.lib;%(AdditionalDependencies) libboost_thread-vc100-mt-sgd-1_46_1.lib</AdditionalDependencies>
<SuppressStartupBanner>true</SuppressStartupBanner>
- <AdditionalLibraryDirectories>X:\temp\windows\libs\Boost\lib-debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>e:\temp\windows\libs\Boost\lib-debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AssemblyDebug>true</AssemblyDebug>
<GenerateMapFile>false</GenerateMapFile>
@@ -685,7 +685,7 @@
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<WholeProgramOptimization>true</WholeProgramOptimization>
- <AdditionalIncludeDirectories>x:\temp\windows\libs\utf8cpp\include;X:\temp\windows\libs\Boost\include\boost-1_46;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>e:\temp\windows\libs\utf8cpp\include;e:\temp\windows\libs\Boost\include\boost-1_46;e:\install\git\miranda\miranda-im\miranda\include;e:\install\git\miranda\mim_plugs;../../include</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
@@ -708,7 +708,7 @@
<Link>
<AdditionalDependencies>shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SuppressStartupBanner>true</SuppressStartupBanner>
- <AdditionalLibraryDirectories>X:\temp\windows\libs\Boost\lib-release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>e:\temp\windows\libs\Boost\lib-release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>false</GenerateDebugInformation>
<SubSystem>NotSet</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
@@ -739,7 +739,7 @@
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<WholeProgramOptimization>true</WholeProgramOptimization>
- <AdditionalIncludeDirectories>x:\temp\windows\libs\utf8cpp\include;X:\temp\windows\libs\Boost\include\boost-1_46;x:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>e:\temp\windows\libs\utf8cpp\include;e:\temp\windows\libs\Boost\include\boost-1_46;e:\install\git\miranda\miranda-im\miranda\include;x:\install\git\miranda\mim_plugs;../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
@@ -762,7 +762,7 @@
<Link>
<AdditionalDependencies>shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SuppressStartupBanner>true</SuppressStartupBanner>
- <AdditionalLibraryDirectories>X:\temp\windows\libs\Boost\lib-release-x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>e:\temp\windows\libs\Boost\lib-release-x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>false</GenerateDebugInformation>
<SubSystem>NotSet</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
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, &params));
- 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, &params));
- 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, &params));
- 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, &params));
- 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)