summaryrefslogtreecommitdiff
path: root/messages.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'messages.cpp')
-rwxr-xr-xmessages.cpp388
1 files changed, 224 insertions, 164 deletions
diff --git a/messages.cpp b/messages.cpp
index 1821035..7a4667f 100755
--- a/messages.cpp
+++ b/messages.cpp
@@ -86,7 +86,7 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags,
wstring decfile = toUTF16(get_random(10));
path.append(_T("\\tmp\\"));
path.append(encfile);
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
fstream f(path.c_str(), std::ios::out);
while(!f.is_open())
f.open(path.c_str(), std::ios::out);
@@ -97,8 +97,8 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags,
extern TCHAR *password;
string out;
DWORD code;
- wstring cmd;
- cmd += _T("--batch ");
+ std::vector<wstring> cmd;
+ cmd.push_back(L"--batch");
{
char *inkeyid = UniGetContactSettingUtf(metaIsProtoMetaContacts(hContact)?metaGetMostOnline(hContact):hContact, szGPGModuleName, "InKeyID", "");
TCHAR *pass = NULL;
@@ -119,17 +119,15 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags,
}
if(pass && pass[0])
{
- cmd += _T("--passphrase \"");
- cmd += pass;
- cmd += _T("\" ");
+ cmd.push_back(L"--passphrase");
+ cmd.push_back(pass);
}
else if(password && password[0])
{
if(bDebugLog)
debuglog<<std::string(time_str()+": info: found password in memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" with password");
- cmd += _T("--passphrase \"");
- cmd += password;
- cmd += _T("\" ");
+ cmd.push_back(L"--passphrase");
+ cmd.push_back(password);
}
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)hContact, GCDNF_TCHAR))+" with out password");
@@ -140,32 +138,21 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags,
wstring path = tmp2;
path += _T("\\tmp\\");
path += decfile;
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
}
- cmd += _T("--output \"");
- cmd += tmp2;
- cmd += _T("\\tmp\\");
- cmd += decfile;
- cmd += _T("\"");
- cmd += _T(" -d -a \"");
- cmd += path;
- cmd += _T("\"");
- gpg_execution_params params;
+ cmd.push_back(L"--output");
+ cmd.push_back(std::wstring(tmp2) + L"\\tmp\\" + decfile);
+ cmd.push_back(L"-d");
+ cmd.push_back(L"-a");
+ cmd.push_back(path);
+ gpg_execution_params params(cmd);
pxResult result;
- params.cmd = &cmd;
- params.useless = "";
params.out = &out;
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::seconds(10)))
+ if(!gpg_launcher(params))
{
- delete gpg_thread;
- TerminateProcess(params.hProcess, 1);
- params.hProcess = NULL;
- if(bDebugLog)
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags));
BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
@@ -176,13 +163,13 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags,
}
if(result == pxNotFound)
{
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags));
return;
}
if(result == pxSuccessExitCodeInvalid)
{
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags));
HistoryLog(hContact, db_event(Translate("failed to decrypt message, GPG returned error, turn on debug log for more details"), timestamp, 0, 0));
return;
@@ -214,33 +201,25 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags,
new_key_hcnt_mutex.lock();
new_key_hcnt = hContact;
ShowLoadKeyPasswordWindow();
- wstring cmd2 = cmd;
+ std::vector<wstring> cmd2 = cmd;
if(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)hContact, GCDNF_TCHAR)));
- wstring tmp = _T("--passphrase \"");
- tmp += password;
- tmp += _T("\" ");
- cmd2.insert(0, tmp);
+ std::vector<wstring> tmp;
+ tmp.push_back(L"--passphrase");
+ tmp.push_back(password);
+ cmd2.insert(cmd2.begin(), tmp.begin(), tmp.end());
}
out.clear();
- gpg_execution_params params;
+ gpg_execution_params params(cmd2);
pxResult result;
- params.cmd = &cmd2;
- params.useless = "";
params.out = &out;
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_launcher(params))
{
- delete gpg_thread;
- TerminateProcess(params.hProcess, 1);
- params.hProcess = NULL;
- if(bDebugLog)
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags));
BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
@@ -251,21 +230,15 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags,
}
if(result == pxNotFound)
{
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags));
return;
}
}
out.clear();
- gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, &params));
- if(!gpg_thread->timed_join(boost::posix_time::seconds(10)))
+ if(!gpg_launcher(params))
{
- delete gpg_thread;
- TerminateProcess(params.hProcess, 1);
- params.hProcess = NULL;
- if(bDebugLog)
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags));
BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
@@ -276,38 +249,35 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags,
}
if(result == pxNotFound)
{
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags));
}
{
wstring tmp = tmp2;
tmp += _T("\\tmp\\");
tmp += encfile;
- DeleteFile(tmp.c_str());
+ boost::filesystem::remove(tmp);
}
{
wstring tmp = tmp2;
tmp += _T("\\tmp\\");
tmp += decfile;
- if(_waccess(tmp.c_str(), 0) == -1)
+ if(!boost::filesystem::exists(tmp))
{
- if(errno == ENOENT)
- {
- string str = msg;
- str.insert(0, "Received unencrypted message:\n");
- if(bDebugLog)
- debuglog<<std::string(time_str()+": info: Failed to decrypt GPG encrypted message.");
- char *tmp = new char [str.length()+1];
- strcpy(tmp, str.c_str());
- HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags));
- BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
- DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
- CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"Unable to decrypt PGP encrypted message");
- HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT));
- DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc);
- mir_free(tmp);
- return;
- }
+ string str = msg;
+ str.insert(0, "Received unencrypted message:\n");
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: Failed to decrypt GPG encrypted message.");
+ char *tmp = new char [str.length()+1];
+ strcpy(tmp, str.c_str());
+ HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags));
+ BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
+ DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0);
+ CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"Unable to decrypt PGP encrypted message");
+ HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT));
+ DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc);
+ mir_free(tmp);
+ return;
}
}
str.clear();
@@ -328,7 +298,7 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags,
str.append(toUTF16(tmp));
delete [] tmp;
f.close();
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
}
if(str.empty())
{
@@ -424,7 +394,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
s2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----"));
DBWriteContactSettingTString(ccs->hContact, szGPGModuleName, "GPGPubKey", str.substr(s1,s2-s1).c_str());
{ //gpg execute block
- wstring cmd;
+ std::vector<wstring> cmd;
TCHAR tmp2[MAX_PATH] = {0};
TCHAR *ptmp;
string output;
@@ -439,7 +409,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
_tcscat(tmp2, _T(".asc"));
mir_free(tmp3);
//_tcscat(tmp2, _T("temporary_exported.asc"));
- DeleteFile(tmp2);
+ boost::filesystem::remove(tmp2);
wfstream f(tmp2, std::ios::out);
while(!f.is_open())
f.open(tmp2, std::ios::out);
@@ -448,29 +418,18 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
mir_free(ptmp);
f<<new_key.c_str();
f.close();
- cmd += _T(" --batch ");
- cmd += _T(" --import \"");
- cmd += tmp2;
- cmd += _T("\"");
+ cmd.push_back(L"--batch");
+ cmd.push_back(L"--import");
+ cmd.push_back(tmp2);
}
- gpg_execution_params params;
+ gpg_execution_params params(cmd);
pxResult result;
- params.cmd = &cmd;
- params.useless = "";
params.out = &output;
params.code = &exitcode;
params.result = &result;
- boost::thread gpg_thread(boost::bind(&pxEexcute_thread, &params));
- if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
- {
- gpg_thread.~thread();
- TerminateProcess(params.hProcess, 1);
- params.hProcess = NULL;
- if(bDebugLog)
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
+ if(!gpg_launcher(params))
return 1;
- }
- DeleteFile(tmp2);
+ boost::filesystem::remove(tmp2);
if(result == pxNotFound)
return 1;
if(result == pxSuccessExitCodeInvalid)
@@ -683,39 +642,43 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
str.replace(i, 2, _T("\n")); */
string out;
DWORD code;
- wstring cmd;
- wstring file = toUTF16(get_random(10));
- wstring path;
+ wstring file = toUTF16(get_random(10)), path;
+ std::vector<std::wstring> cmd;
extern bool bJabberAPI, bIsMiranda09;
char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", "");
if(!tmp[0])
{
mir_free(tmp);
HistoryLog(hContact, db_event("Failed to encrypt message with GPG (not found key for encryption in db)", 0,0, DBEF_SENT));
- hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG (not found key for encryption in db)");
- mir_free(msg);
+// hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG (not found key for encryption in db)");
+ //mir_free(msg);
CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
return;
}
if(!bJabberAPI || !bIsMiranda09) //force jabber to handle encrypted message by itself
- cmd += _T("--comment \"\" --no-version ");
+ {
+ cmd.push_back(L"--comment");
+ cmd.push_back(L"\"\"");
+ cmd.push_back(L"--no-version");
+ }
if(DBGetContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 0))
- cmd += _T("--trust-model always ");
- cmd += _T("--batch --yes -e -a -t -r ");
+ {
+ cmd.push_back(L"--trust-model");
+ cmd.push_back(L"always");
+ }
+ cmd.push_back(L"--batch");
+ cmd.push_back(L"--yes");
+ cmd.push_back(L"-eatr");
TCHAR *tmp2 = mir_a2t(tmp);
mir_free(tmp);
- cmd += tmp2;
+ cmd.push_back(tmp2);
mir_free(tmp2);
- cmd += _T(" \"");
tmp2 = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
- path.append(tmp2);
- cmd += tmp2;
+ path = tmp2;
+ cmd.push_back(std::wstring(tmp2) + L"\\tmp\\" + file);
mir_free(tmp2);
- cmd += _T("\\tmp\\");
- cmd += file;
- path.append(_T("\\tmp\\"));
+ path += L"\\tmp\\";
path += file;
- cmd += _T("\"");
{
fstream f(path.c_str(), std::ios::out);
while(!f.is_open())
@@ -727,28 +690,20 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
f.write(tmp.c_str(), tmp.size());
f.close();
}
- gpg_execution_params params;
+ gpg_execution_params params(cmd);
pxResult result;
- params.cmd = &cmd;
- params.useless = "";
params.out = &out;
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_launcher(params))
{
- gpg_thread.~thread();
- TerminateProcess(params.hProcess, 1);
- params.hProcess = NULL;
- if(bDebugLog)
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
- mir_free(msg);
+ //mir_free(msg);
CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
return;
}
if(result == pxNotFound)
{
- mir_free(msg);
+ //mir_free(msg);
CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
return;
}
@@ -758,29 +713,24 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
if(MessageBox(0, TranslateT("We trying to encrypt with untrusted key, do you want to trust this key permanently ?"), TranslateT("Warning"), MB_YESNO) == IDYES)
{
DBWriteContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 1);
- cmd.insert(0, _T("--trust-model always "));
- gpg_execution_params params;
+ std::vector<std::wstring> tmp;
+ tmp.push_back(L"--trust-model");
+ tmp.push_back(L"always");
+ cmd.insert(cmd.begin(), tmp.begin(), tmp.end());
+ gpg_execution_params params(cmd);
pxResult result;
- params.cmd = &cmd;
- params.useless = "";
params.out = &out;
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_launcher(params))
{
- gpg_thread.~thread();
- TerminateProcess(params.hProcess, 1);
- params.hProcess = NULL;
- if(bDebugLog)
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
- mir_free(msg);
+ //mir_free(msg);
CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
return;
}
if(result == pxNotFound)
{
- mir_free(msg);
+ //mir_free(msg);
CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
return;
}
@@ -788,25 +738,26 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
}
else
{
- mir_free(msg);
+ //mir_free(msg);
return;
}
}
if(result == pxSuccessExitCodeInvalid)
{
- mir_free(msg);
+ //mir_free(msg);
HistoryLog(hContact, db_event(Translate("failed o encrypt message, GPG returned error, turn on debug log for more details"), 0,0, DBEF_SENT));
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
return;
}
if(out.find("usage: ") != string::npos)
{
MessageBox(0, TranslateT("Something wrong, gpg does not understand us, aborting encryption."), TranslateT("Warning"), MB_OK);
- mir_free(msg);
+ //mir_free(msg);
CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
return;
}
+ boost::filesystem::remove(path);
path.append(_T(".asc"));
wfstream f(path.c_str(), std::ios::in | std::ios::ate | std::ios::binary);
while(!f.is_open())
@@ -825,15 +776,15 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
str.append(tmp);
delete [] tmp;
f.close();
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
}
if(str.empty())
{
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");
+// hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG");
if(bDebugLog)
debuglog<<std::string(time_str()+": info: Failed to encrypt message with GPG");
- mir_free(msg);
+ //mir_free(msg);
CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg);
return;
}
@@ -853,15 +804,15 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags)
}
HistoryLog(metaGetContact(hContact), db_event((char*)str_event.c_str(), 0,0, DBEF_SENT|dbflags));
}*/ //unneeded ?
- hcontact_data[hContact].msgs_to_pass.push_back(str_event);
+// hcontact_data[hContact].msgs_to_pass.push_back(str_event);
if(bDebugLog)
debuglog<<std::string(time_str()+": adding event to contact: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+" on send message.");
- HistoryLog(hContact, db_event((char*)str_event.c_str(), 0,0, dbflags|DBEF_SENT));
+ //HistoryLog(hContact, db_event((char*)str_event.c_str(), 0,0, dbflags|DBEF_SENT));
if(!(flags & PREF_UTF))
flags |= PREF_UTF;
fix_line_term(str);
sent_msgs.push_back((HANDLE)CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)toUTF8(str).c_str()));
- mir_free(msg);
+ //mir_free(msg);
return;
}
@@ -888,7 +839,7 @@ int SendMsgSvc(WPARAM w, LPARAM l)
debuglog<<std::string(time_str()+": info: encrypted messge, let it go, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)));
return CallService(MS_PROTO_CHAINSEND, w, l);
}
- if(!isContactHaveKey(ccs->hContact))
+ /*if(!isContactHaveKey(ccs->hContact))
{
if(bDebugLog)
debuglog<<std::string(time_str()+": info: contact have not key, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)));
@@ -969,7 +920,7 @@ int SendMsgSvc(WPARAM w, LPARAM l)
mir_free(msg);
return CallService(MS_PROTO_CHAINSEND, w, l);
}
- }
+ } */
else if(bDebugLog)
debuglog<<std::string(time_str()+": info: contact have key, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)));
if(bDebugLog && metaIsProtoMetaContacts(ccs->hContact))
@@ -981,7 +932,8 @@ int SendMsgSvc(WPARAM w, LPARAM l)
mir_free(msg);
return CallService(MS_PROTO_CHAINSEND, w, l);
}
- boost::thread *thr = new boost::thread(boost::bind(SendMsgSvc_func, ccs->hContact, msg, (DWORD)ccs->wParam));
+ mir_free(msg);
+ //boost::thread *thr = new boost::thread(boost::bind(SendMsgSvc_func, ccs->hContact, msg, (DWORD)ccs->wParam));
return returnNoError(ccs->hContact);
}
@@ -1010,28 +962,136 @@ int HookSendMsg(WPARAM w, LPARAM l)
return 1;
}
}
- if(isContactSecured(hContact) && (dbei->flags & DBEF_SENT)) //aggressive outgoing events filtering
+ if(metaIsProtoMetaContacts(hContact))
+ return 0;
+
+ if(!isContactHaveKey(hContact))
{
- if(!hcontact_data[hContact].msgs_to_pass.empty())
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: contact have not key, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)));
+ if(bAutoExchange && !strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----") && !strstr((char*)dbei->pBlob, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && gpg_valid)
{
- event_processing_mutex.lock();
- std::list<string>::iterator end = hcontact_data[hContact].msgs_to_pass.end();
- for(std::list<string>::iterator i = hcontact_data[hContact].msgs_to_pass.begin(); i != end; ++i)
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: checking for autoexchange possibility, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)));
+ void send_encrypted_msgs_thread(HANDLE hContact);
+ LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
+ DWORD uin = DBGetContactSettingDword(hContact, proto, "UIN", 0);
+ if(uin)
+ {
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info(autoexchange): protocol looks like icq, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)));
+ char *proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
+ char svc[64];
+ strcpy(svc, proto);
+ strcat(svc, PS_ICQ_CHECKCAPABILITY);
+
+ if(ServiceExists(svc))
+ {
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info(autoexchange, icq): checking for autoexchange icq capability, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)));
+ ICQ_CUSTOMCAP cap = {0};
+ strcpy(cap.caps, "GPG AutoExchange");
+ if(CallService(svc, (WPARAM)hContact, (LPARAM)&cap))
+ {
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info(autoexchange, icq): sending key requiest, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)));
+ CallContactService(hContact, PSS_MESSAGE, (WPARAM)((dbei->flags & DBEF_UTF) == DBEF_UTF)?PREF_UTF:0, (LPARAM)"-----PGP KEY REQUEST-----");
+ hcontact_data[hContact].msgs_to_send.push_back((char*)dbei->pBlob);
+ boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, hContact));
+ //TODO: wait for message
+ return 0;
+ }
+ }
+ }
+ else
{
- if(!strcmp((*i).c_str(), (char*)dbei->pBlob))
+ TCHAR *jid = UniGetContactSettingUtf(hContact, proto, "jid", _T(""));
+ if(jid[0])
{
- hcontact_data[hContact].msgs_to_pass.erase(i);
if(bDebugLog)
- debuglog<<std::string(time_str()+": event message: \""+(char*)dbei->pBlob+"\" passed event filter, contact "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+", message is in allowed list");
- event_processing_mutex.unlock();
- return 0;
+ debuglog<<std::string(time_str()+": info(autoexchange): protocol looks like jabber, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)));
+ extern list <JabberAccount*> Accounts;
+ list<JabberAccount*>::iterator end = Accounts.end();
+ for(list<JabberAccount*>::iterator p = Accounts.begin(); p != end; p++)
+ {
+ TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid);
+ if(caps)
+ {
+ wstring str;
+ for(int i=0;;i++)
+ {
+ str.push_back(caps[i]);
+ if(caps[i] == '\0')
+ if(caps[i+1] == '\0')
+ break;
+ }
+ mir_free(caps);
+ if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos)
+ {
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info(autoexchange, jabber): autoexchange capability found, sending key request, name: "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR)));
+ CallContactService(hContact, PSS_MESSAGE, (WPARAM)((dbei->flags & DBEF_UTF) == DBEF_UTF)?PREF_UTF:0, (LPARAM)"-----PGP KEY REQUEST-----");
+ hcontact_data[hContact].msgs_to_send.push_back((char*)dbei->pBlob);
+ boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, hContact));
+ mir_free((char*)dbei->pBlob);
+ //TODO: wait for message
+ return 0;
+ }
+ }
+ }
}
}
- event_processing_mutex.unlock();
}
- if(metaIsProtoMetaContacts(hContact) && !isContactSecured(metaGetMostOnline(hContact)))
+ else
+ {
return 0;
- return 1;
+ }
+ }
+ if(isContactSecured(hContact) && (dbei->flags & DBEF_SENT)) //aggressive outgoing events filtering
+ {
+ DWORD flags;
+ if((dbei->flags & DBEF_UTF) == DBEF_UTF)
+ flags |= PREF_UTF;
+ SendMsgSvc_func(hContact, (char*)dbei->pBlob, flags);
+ //TODO: handle errors somehow ...
+ if(bAppendTags)
+ {
+ string str_event = (char*)dbei->pBlob;
+ mir_free(dbei->pBlob);
+ str_event.insert(0, toUTF8(outopentag));
+ str_event.append(toUTF8(outclosetag));
+ dbei->pBlob = (PBYTE)mir_strdup(str_event.c_str());
+ dbei->cbBlob = str_event.length() + 1;
+ }
+
+ return 0;
+/* bool stop = false;
+ int count = 0; */
+/* while(!stop)
+ {
+ if(count >= 300)
+ stop = true;
+ if(!hcontact_data[hContact].msgs_to_pass.empty())
+ {
+ event_processing_mutex.lock();
+ std::list<string>::iterator end = hcontact_data[hContact].msgs_to_pass.end();
+ for(std::list<string>::iterator i = hcontact_data[hContact].msgs_to_pass.begin(); i != end; ++i)
+ {
+ if(!strcmp((*i).c_str(), (char*)dbei->pBlob))
+ {
+ hcontact_data[hContact].msgs_to_pass.erase(i);
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": event message: \""+(char*)dbei->pBlob+"\" passed event filter, contact "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+", message is in allowed list");
+ event_processing_mutex.unlock();
+ return 0;
+ }
+ }
+ event_processing_mutex.unlock();
+ }
+ boost::this_thread::sleep(boost::posix_time::milliseconds(100));
+ count++;
+ } */
+ //return 1;
}
if(!isContactSecured(hContact))
{