diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-12 19:58:37 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-12 19:58:37 +0300 |
commit | 82e4196bfcfe5fa976ef602f54fbaf82d3854f6d (patch) | |
tree | 8045756a9c048ffd1d08a311e560e19974390fe6 /messages.cpp | |
parent | 5d7dc0a0e6021470eac321b7af090f01a7bfe82f (diff) |
modified: main.cpp
modified: messages.cpp
Diffstat (limited to 'messages.cpp')
-rw-r--r-- | messages.cpp | 75 |
1 files changed, 61 insertions, 14 deletions
diff --git a/messages.cpp b/messages.cpp index 2b81167..f6cff09 100644 --- a/messages.cpp +++ b/messages.cpp @@ -40,13 +40,59 @@ int RecvMsgSvc(WPARAM w, LPARAM l) if(!DBGetContactSettingByte(ccs->hContact, szModuleName, "GPGEncryption", 0))
;//
}
- else if(((s2 = str.find(_T("-/ENCRYPTED-"))) != wstring::npos) && ((s1 = str.find(_T("-ENCRYPTED-"))) != wstring::npos))
+ else if((str.find(_T("-----END PGP MESSAGE-----")) != wstring::npos) && (str.find(_T("-----BEGIN PGP MESSAGE-----")) != wstring::npos))
{ //this is generic encrypted data block
if(!DBGetContactSettingByte(ccs->hContact, szModuleName, "GPGEncryption", 0))
;//
+ {
+ wstring::size_type p = 0;
+ while((p = str.find(_T("\r"), p)) != wstring::npos)
+ str.erase(p, 1);
+ }
+ char *tmp = mir_t2a(str.c_str());
+ TCHAR *tmp2 = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T(""));
+ wstring path = tmp2;
+ path.append(_T("\\encrypted_data.asc"));
+ wfstream f(path.c_str(), std::ios::out);
+ f<<tmp;
+ mir_free(tmp);
+ f.close();
+ {
+ string out;
+ DWORD code;
+ TCHAR cmd[512] = {0};
+ _tcscpy(cmd, _T(" -d \""));
+ _tcscat(cmd, path.c_str());
+ _tcscat(cmd, _T("\" > "));
+ wstring path2 = tmp2;
+ mir_free(tmp2);
+ path2.append(_T("\\decrypted_data"));
+ _tcscat(cmd, _T("\""));
+ _tcscat(cmd, path2.c_str());
+ _tcscat(cmd, _T("\""));
+ pxExecute(cmd, "", &out, &code);
+ wfstream f(path2.c_str(), std::ios::in);
+ str.clear();
+ while(!f.eof() && f.is_open())
+ {
+ TCHAR tmp[128];
+ f.getline(tmp, 128);
+ str.append(tmp);
+ str.append(_T("\n"));
+ }
+ f.close();
+ DeleteFile(path.c_str());
+ DeleteFile(path2.c_str());
+ if(str.length() > 0)
+ {
+ mir_free((void**)ccs->lParam);
+ char *utf = mir_utf8encodeW(str.c_str());
+ ccs->lParam = (LPARAM)utf;
+ }
+ }
}
else if(((s1 = str.find(_T("<body>This message is encrypted.</body>"))) != wstring::npos))
- { //this is jabber encrypted data
+ { //this is xmpp encrypted data
if(!DBGetContactSettingByte(ccs->hContact, szModuleName, "GPGEncryption", 0))
;//
}
@@ -75,10 +121,9 @@ int SendMsgSvc(WPARAM w, LPARAM l) { //encrypt data here
wchar_t *tmp = mir_utf8decodeW(msg);
wstring str = tmp;
- MessageBox(0, str.c_str(), _T(""), MB_OK);
mir_free(tmp);
wstring::size_type s1, s2;
- { //not xmpp
+ { //not xmpp, just replace whole message
string out;
DWORD code;
TCHAR cmd[128];
@@ -94,7 +139,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(tmp);
_tcscat(cmd, tmp2);
mir_free(tmp2);
- _tcscat(cmd, _T("\""));
+ _tcscat(cmd, _T(" \""));
tmp2 = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T(""));
path.append(tmp2);
_tcscat(cmd, tmp2);
@@ -103,28 +148,30 @@ int SendMsgSvc(WPARAM w, LPARAM l) path.append(_T("\\exported_data"));
_tcscat(cmd, _T("\""));
{
- wfstream f(path.c_str(), std::ios_base::in);
- f<<str;
+ char *tmp = mir_t2a(str.c_str());
+ wfstream f(path.c_str(), std::ios::out);
+ f<<tmp;
+ mir_free(tmp);
f.close();
}
pxExecute(cmd, "", &out, &code);
DeleteFile(path.c_str());
path.append(_T(".asc"));
- wfstream f(path.c_str(), std::ios_base::out);
+ wfstream f(path.c_str(), std::ios::in);
str.clear();
while(!f.eof())
{
TCHAR tmp[128];
f.getline(tmp, 128);
str.append(tmp);
+ str.append(_T("\n"));
}
+ f.close();
+ DeleteFile(path.c_str());
mir_free((void**)ccs->lParam);
- char *utf = mir_utf8encodeW(str.c_str()); //for later usage
- ccs->hContact = utf;
- }
-
-
+ char *utf = mir_utf8encodeW(str.c_str());
+ ccs->lParam = (LPARAM)utf;
+ }
}
-
return CallService(MS_PROTO_CHAINSEND, w, l);
}
\ No newline at end of file |