summaryrefslogtreecommitdiff
path: root/utilities.cpp
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2013-01-12 09:49:04 +0200
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2013-01-12 09:49:04 +0200
commitd884a2fd95cd535aef2640e6a592762b3c484ed2 (patch)
tree557a20f1199db108dc596bc97d5b31eb0e18472f /utilities.cpp
parent4a8d2270c087aef94fbd0b7d19df6dec05441edf (diff)
merged with miranda_ng main repo
Diffstat (limited to 'utilities.cpp')
-rwxr-xr-xutilities.cpp98
1 files changed, 51 insertions, 47 deletions
diff --git a/utilities.cpp b/utilities.cpp
index d23853f..a07cb77 100755
--- a/utilities.cpp
+++ b/utilities.cpp
@@ -408,13 +408,13 @@ int onProtoAck(WPARAM w, LPARAM l)
dbsetting += keyid;
dbsetting += "_Password";
pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T(""));
- if(_tcslen(pass) > 0)
+ if(_tcslen(pass) > 0 && bDebugLog)
debuglog<<std::string(time_str()+": info: found password in database for key id: "+keyid+", trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR))+" with password");
}
else
{
pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T(""));
- if(_tcslen(pass) > 0)
+ if(_tcslen(pass) > 0 && bDebugLog)
debuglog<<std::string(time_str()+": info: found password for all keys in database, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR))+" with password");
}
if(_tcslen(pass) > 0)
@@ -425,12 +425,13 @@ int onProtoAck(WPARAM w, LPARAM l)
}
else if(password)
{
- debuglog<<std::string(time_str()+": info: found password in memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR))+" with password");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: found password in memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR))+" with password");
cmd += _T("--passphrase \"");
cmd += password;
cmd += _T("\" ");
}
- else
+ else if (bDebugLog)
debuglog<<std::string(time_str()+": info: passwords not found in database or memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR))+" with out password");
mir_free(pass);
mir_free(keyid);
@@ -450,7 +451,8 @@ int onProtoAck(WPARAM w, LPARAM l)
delete gpg_thread;
TerminateProcess(params.hProcess, 1);
params.hProcess = NULL;
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
return 0;
}
while(out.find("public key decryption failed: bad passphrase") != string::npos)
@@ -458,7 +460,8 @@ int onProtoAck(WPARAM w, LPARAM l)
extern bool _terminate;
extern HANDLE new_key_hcnt;
extern boost::mutex new_key_hcnt_mutex;
- debuglog<<std::string(time_str()+": info: failed to decrypt messaage from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR))+" password needed, trying to get one");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: failed to decrypt messaage from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR))+" password needed, trying to get one");
if(_terminate)
break;
{ //save inkey id
@@ -478,7 +481,8 @@ int onProtoAck(WPARAM w, LPARAM l)
wstring cmd2 = cmd;
if(password)
{
- debuglog<<std::string(time_str()+": info: found password in memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR)));
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: found password in memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR)));
wstring tmp = _T("--passphrase \"");
tmp += password;
tmp += _T("\" ");
@@ -498,7 +502,8 @@ int onProtoAck(WPARAM w, LPARAM l)
delete gpg_thread;
TerminateProcess(params.hProcess, 1);
params.hProcess = NULL;
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
//DeleteFile(filename);
return 0;
}
@@ -589,7 +594,8 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename)
delete gpg_thread;
TerminateProcess(params.hProcess, 1);
params.hProcess = NULL;
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
return 0;
}
if(out.find("There is no assurance this key belongs to the named user") != string::npos)
@@ -605,7 +611,8 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename)
delete gpg_thread;
TerminateProcess(params.hProcess, 1);
params.hProcess = NULL;
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
return 0;
}
}
@@ -821,7 +828,8 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU
{
if(errno == ENOENT)
{
- debuglog<<std::string(time_str()+": info: Failed to write prescense in file");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: Failed to write prescense in file");
return FALSE;
}
}
@@ -851,13 +859,13 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU
dbsetting += inkeyid;
dbsetting += "_Password";
pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T(""));
- if(pass[0])
+ if(pass[0] && bDebugLog)
debuglog<<std::string(time_str()+": info: found password in database for key id: "+inkeyid+", trying to encrypt message from self with password");
}
else
{
pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T(""));
- if(pass[0])
+ if(pass[0] && bDebugLog)
debuglog<<std::string(time_str()+": info: found password for all keys in database, trying to encrypt message from self with password");
}
if(pass[0])
@@ -868,12 +876,13 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU
}
else if(password)
{
- debuglog<<std::string(time_str()+": info: found password in memory, trying to encrypt message from self with password");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: found password in memory, trying to encrypt message from self with password");
cmd += _T("--passphrase \"");
cmd += password;
cmd += _T("\" ");
}
- else
+ else if (bDebugLog)
debuglog<<std::string(time_str()+": info: passwords not found in database or memory, trying to encrypt message from self with out password");
mir_free(pass);
mir_free(inkeyid);
@@ -900,7 +909,8 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU
gpg_thread.~thread();
TerminateProcess(params.hProcess, 1);
params.hProcess = NULL;
- debuglog<<std::string(time_str()+"GPG execution timed out, aborted");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+"GPG execution timed out, aborted");
}
DeleteFile(path_out.c_str());
path_out += _T(".asc");
@@ -920,7 +930,8 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU
}
if(data.empty())
{
- debuglog<<std::string(time_str()+": info: Failed to read prescense sign from file");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: Failed to read prescense sign from file");
return FALSE;
}
if(data.find(_T("-----BEGIN PGP SIGNATURE-----")) != wstring::npos && data.find(_T("-----END PGP SIGNATURE-----")) != wstring::npos)
@@ -1035,7 +1046,8 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi
if(errno == ENOENT)
{
// sign_file_mutex.unlock();
- debuglog<<std::string(time_str()+": info: Failed to write sign in file");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: Failed to write sign in file");
return FALSE;
}
}
@@ -1061,7 +1073,8 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi
gpg_thread.~thread();
TerminateProcess(params.hProcess, 1);
params.hProcess = NULL;
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
return FALSE;
}
if(result == pxNotFound)
@@ -1138,7 +1151,8 @@ bool isContactSecured(HANDLE hContact)
BYTE gpg_enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
if(!gpg_enc)
{
- debuglog<<std::string(time_str()+": encryption is turned off for "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)));
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": encryption is turned off for "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)));
return false;
}
if(!metaIsProtoMetaContacts(hContact))
@@ -1147,12 +1161,14 @@ bool isContactSecured(HANDLE hContact)
if(!key[0])
{
mir_free(key);
- debuglog<<std::string(time_str()+": encryption is turned off for "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)));
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": encryption is turned off for "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)));
return false;
}
mir_free(key);
}
- debuglog<<std::string(time_str()+": encryption is turned on for "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)));
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": encryption is turned on for "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)));
return true;
}
@@ -1233,7 +1249,8 @@ bool isGPGValid()
gpg_thread.~thread();
TerminateProcess(params.hProcess, 1);
params.hProcess = NULL;
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
}
gpg_valid = false;
string::size_type p1 = out.find("(GnuPG) ");
@@ -1339,6 +1356,7 @@ int returnNoError(HANDLE hContact) {
// end from secureim
+
string toUTF8(wstring str)
{
string ustr;
@@ -1347,7 +1365,8 @@ string toUTF8(wstring str)
}
catch(const utf8::exception& e)
{
- debuglog<<std::string("utf8cpp encoding exception: ")+(char*)e.what();
+ if(bDebugLog)
+ debuglog<<std::string("utf8cpp encoding exception: ")+(char*)e.what();
//TODO
}
return ustr;
@@ -1365,7 +1384,8 @@ wstring toUTF16(string str) //convert as much as possible
}
catch(const utf8::exception& e)
{
- debuglog<<std::string("utf8cpp decoding exception: ")+(char*)e.what();
+ if(bDebugLog)
+ debuglog<<std::string("utf8cpp decoding exception: ")+(char*)e.what();
//TODO
}
return ustr;
@@ -1831,7 +1851,8 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l)
gpg_thread.~thread();
TerminateProcess(params.hProcess, 1);
params.hProcess = NULL;
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
break;
}
if(result == pxNotFound)
@@ -1950,27 +1971,10 @@ void strip_line_term(std::string &s)
void strip_tags(std::wstring &str)
{
- std::wstring::size_type p;
- if(_tcslen(inopentag))
- {
- for(p = str.find(inopentag); p != std::wstring::npos; p = str.find(inopentag))
- str.erase(p, _tcslen(inopentag));
- }
- if(_tcslen(inclosetag))
- {
- for(p = str.find(inclosetag); p != std::wstring::npos; p = str.find(inclosetag))
- str.erase(p, _tcslen(inclosetag));
- }
- if(_tcslen(outopentag))
- {
- for(p = str.find(outopentag); p != std::wstring::npos; p = str.find(outopentag))
- str.erase(p, _tcslen(outopentag));
- }
- if(_tcslen(outclosetag))
- {
- for(p = str.find(outclosetag); p != std::wstring::npos; p = str.find(outclosetag))
- str.erase(p, _tcslen(outclosetag));
- }
+ boost::algorithm::erase_all(str, inopentag);
+ boost::algorithm::erase_all(str, inclosetag);
+ boost::algorithm::erase_all(str, outopentag);
+ boost::algorithm::erase_all(str, outclosetag);
}