summaryrefslogtreecommitdiff
path: root/utilities.cpp
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-06-04 23:56:26 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-06-04 23:56:26 +0300
commitad52d967c7f67428bf7c6aea6c376a1a43c65735 (patch)
treeb602ca9ccbccbea519b157494ad8cd7ac3d82620 /utilities.cpp
parent0711166b41c6e4f0b788ab34ef15289e98e46a31 (diff)
fixed filetransfers #21 (tested only with jabber)
Diffstat (limited to 'utilities.cpp')
-rwxr-xr-xutilities.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/utilities.cpp b/utilities.cpp
index 114f2dc..6b2261d 100755
--- a/utilities.cpp
+++ b/utilities.cpp
@@ -277,7 +277,7 @@ int onProtoAck(WPARAM w, LPARAM l)
{
ACKDATA *ack=(ACKDATA*)l;
CCSDATA *ccs=(CCSDATA*)ack->lParam;
-
+
if(ack->type == ACKTYPE_FILE && bFileTransfers)
{
switch(ack->result)
@@ -312,7 +312,7 @@ int onProtoAck(WPARAM w, LPARAM l)
string out;
DWORD code;
pxResult result;
- wstring cmd = _T("-o ");
+ wstring cmd = _T(" -o ");
wstring file = filename;
wstring::size_type p1 = file.rfind(_T(".gpg"));
file.erase(p1, _tcslen(_T(".gpg")));
@@ -325,13 +325,10 @@ int onProtoAck(WPARAM w, LPARAM l)
file.insert(0, _T("\""));
file.insert(file.length(), _T("\" "));
cmd += file;
- cmd += _T(" -d \"");
- cmd += filename;
- cmd += _T("\"");
extern TCHAR *password;
{ // password
TCHAR *pass = NULL;
- char *keyid = UniGetContactSettingUtf(ccs->hContact, szGPGModuleName, "KeyID", "");
+ char *keyid = UniGetContactSettingUtf(ack->hContact, szGPGModuleName, "KeyID", "");
if(strlen(keyid) > 0)
{
string dbsetting = "szKey_";
@@ -339,13 +336,13 @@ int onProtoAck(WPARAM w, LPARAM l)
dbsetting += "_Password";
pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), _T(""));
if(_tcslen(pass) > 0)
- debuglog<<time_str()<<": info: found password in database for key id: "<<keyid<<", trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" with password\n";
+ debuglog<<time_str()<<": info: found password in database for key id: "<<keyid<<", trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR)<<" with password\n";
}
else
{
pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", _T(""));
if(_tcslen(pass) > 0)
- debuglog<<time_str()<<": info: found password for all keys in database, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" with password\n";
+ debuglog<<time_str()<<": info: found password for all keys in database, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR)<<" with password\n";
}
if(_tcslen(pass) > 0)
{
@@ -355,16 +352,19 @@ int onProtoAck(WPARAM w, LPARAM l)
}
else if(password)
{
- debuglog<<time_str()<<": info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" with password\n";
+ debuglog<<time_str()<<": info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR)<<" with password\n";
cmd += _T("--passphrase \"");
cmd += password;
cmd += _T("\" ");
}
else
- debuglog<<time_str()<<": info: passwords not found in database or memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" with out password\n";
+ debuglog<<time_str()<<": info: passwords not found in database or memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR)<<" with out password\n";
mir_free(pass);
mir_free(keyid);
}
+ cmd += _T(" -d \"");
+ cmd += filename;
+ cmd += _T("\"");
gpg_execution_params params;
params.cmd = &cmd;
params.useless = "";
@@ -385,7 +385,7 @@ int onProtoAck(WPARAM w, LPARAM l)
extern bool _terminate;
extern HANDLE new_key_hcnt;
extern boost::mutex new_key_hcnt_mutex;
- debuglog<<time_str()<<": info: failed to decrypt messaage from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<" password needed, trying to get one\n";
+ debuglog<<time_str()<<": info: failed to decrypt messaage from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR)<<" password needed, trying to get one\n";
if(_terminate)
break;
{ //save inkey id
@@ -393,19 +393,19 @@ int onProtoAck(WPARAM w, LPARAM l)
s = out.find(" ID ", s);
s += strlen(" ID ");
string::size_type s2 = out.find(",",s);
- if(metaIsProtoMetaContacts(ccs->hContact))
- DBWriteContactSettingString(metaGetMostOnline(ccs->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str());
+ if(metaIsProtoMetaContacts(ack->hContact))
+ DBWriteContactSettingString(metaGetMostOnline(ack->hContact), szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str());
else
- DBWriteContactSettingString(ccs->hContact, szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str());
+ DBWriteContactSettingString(ack->hContact, szGPGModuleName, "InKeyID", out.substr(s, s2-s).c_str());
}
void ShowLoadKeyPasswordWindow();
new_key_hcnt_mutex.lock();
- new_key_hcnt = ccs->hContact;
+ new_key_hcnt = ack->hContact;
ShowLoadKeyPasswordWindow();
wstring cmd2 = cmd;
if(password)
{
- debuglog<<time_str()<<": info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ccs->hContact, GCDNF_TCHAR)<<"\n";
+ debuglog<<time_str()<<": info: found password in memory, trying to decrypt message from "<<(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR)<<"\n";
wstring tmp = _T("--passphrase \"");
tmp += password;
tmp += _T("\" ");
@@ -472,10 +472,9 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename)
string out;
DWORD code;
pxResult result;
+ HANDLE hcnt = metaIsProtoMetaContacts(hContact)?metaGetMostOnline(hContact):hContact;
wstring cmd = _T("--batch --yes -r ");
- char *keyid = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", "");
- if(DBGetContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 0))
- cmd += _T("--trust-model always ");
+ char *keyid = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID", "");
TCHAR *szKeyid = mir_a2t(keyid);
TCHAR *name = _tcsrchr(filename,_T('\\'));
if( !name )
@@ -485,6 +484,8 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename)
TCHAR *file_out = new TCHAR [_tcslen(filename)+4];
mir_sntprintf(file_out, _tcslen(name)+7, _T("%s.gpg"), name);
cmd += szKeyid;
+ if(DBGetContactSettingByte(hcnt, szGPGModuleName, "bAlwaysTrust", 0))
+ cmd += _T(" --trust-model always ");
mir_free(szKeyid);
mir_free(keyid);
cmd += _T(" -o \"");
@@ -523,7 +524,7 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename)
out.clear();
if(MessageBox(0, _T("We trying to encrypt with untrusted key, do you want to trust this key permanently ?"), _T("Warning"), MB_YESNO) == IDYES)
{
- DBWriteContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 1);
+ DBWriteContactSettingByte(hcnt, szGPGModuleName, "bAlwaysTrust", 1);
cmd.insert(0, _T("--trust-model always "));
gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, &params));
if(!gpg_thread->timed_join(boost::posix_time::seconds(180)))
@@ -552,7 +553,8 @@ int onSendFile(WPARAM w, LPARAM l)
DWORD flags = (DWORD)ccs->wParam; //check for PFTS_UNICODE here
int i;
- if(flags & PFTS_UNICODE)
+// if(flags & PFTS_UNICODE) //this does not work ....
+ if(StriStr(ccs->szProtoService, "/sendfilew"))
{
TCHAR **file=(TCHAR **)ccs->lParam;
for(i = 0; file[i]; i++)