From ea8554407ed4038aca0eb7835f9d813bdf37c1a9 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 14 Aug 2010 03:50:31 +0300 Subject: fixes .... mainly --- messages.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 16 deletions(-) (limited to 'messages.cpp') diff --git a/messages.cpp b/messages.cpp index d3456ec..5c37e71 100644 --- a/messages.cpp +++ b/messages.cpp @@ -35,14 +35,21 @@ int RecvMsgSvc(WPARAM w, LPARAM l) mir_free(tmp); wstring::size_type s1, s2; - if(((s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----"))) != wstring::npos) && ((s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"))) != wstring::npos)) + s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); + s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); + if((s2 != wstring::npos) && (s1 != wstring::npos)) { //this is public key if(!DBGetContactSettingByte(ccs->hContact, szModuleName, "GPGEncryption", 0)) ;// + s1 = 0; + while((s1 = str.find(_T("\r"), s1)) != wstring::npos) + { + str.erase(s1, 1); + } + s2 = str.find(_T("-----END PGP PUBLIC KEY BLOCK-----")); + s1 = str.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); s2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")); DBWriteContactSettingTString(ccs->hContact, szModuleName, "GPGPubKey", str.substr(s1,s2-s1).c_str()); - tmp = new TCHAR [str.length()+1]; -// _tcscpy(tmp, str.substr(ws1,ws2-ws1).c_str()); { //gpg execute block wstring cmd; TCHAR tmp2[MAX_PATH] = {0}; @@ -59,13 +66,9 @@ int RecvMsgSvc(WPARAM w, LPARAM l) ptmp = UniGetContactSettingUtf(ccs->hContact, szModuleName, "GPGPubKey", _T("")); wstring str = ptmp; mir_free(ptmp); - wstring::size_type s = 0; - while((s = str.find(_T("\r"), s)) != wstring::npos) - { - str.erase(s, 1); - } f<hContact, szModuleName, "GPGEncryption", 0)) ;// @@ -89,7 +94,8 @@ int RecvMsgSvc(WPARAM w, LPARAM l) while((p = str.find(_T("\r"), p)) != wstring::npos) str.erase(p, 1); } - char *tmp = mir_t2a(str.c_str()); + s2 += _tcslen(_T("-----END PGP MESSAGE-----")); + char *tmp = mir_t2a(str.substr(s1,s2-s1).c_str()); TCHAR *tmp2 = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T("")); wstring path = tmp2; path.append(_T("\\encrypted_data.asc")); @@ -101,20 +107,30 @@ int RecvMsgSvc(WPARAM w, LPARAM l) string out; DWORD code; wstring cmd; + { + TCHAR *tmp = UniGetContactSettingUtf(NULL, szModuleName, "szKeyPassword", _T("")); + if(_tcslen(tmp) > 0) + { + cmd += _T("--passphrase \""); + cmd += tmp; + cmd += _T("\" "); + } + mir_free(tmp); + } cmd += _T("--output \""); cmd += tmp2; cmd += _T("\\decrypted_data\""); cmd += _T(" -d -a \""); cmd += path; cmd += _T("\""); - MessageBox(0, cmd.c_str(), _T("in"), MB_OK); + //MessageBox(0, cmd.c_str(), _T("in"), MB_OK); if(pxExecute(&cmd, "", &out, &code) == pxNotFound) { MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); DeleteFile(path.c_str()); return CallService(MS_PROTO_CHAINRECV, w, l); } - MessageBoxA(0, out.c_str(), "out", MB_OK); + //MessageBoxA(0, out.c_str(), "out", MB_OK); { wstring tmp = tmp2; tmp += _T("\\decrypted_data"); @@ -146,10 +162,11 @@ int RecvMsgSvc(WPARAM w, LPARAM l) // else // tmp2 = mir_a2t(tmp); str.append(tmp2).append(_T("\n")); - mir_free(tmp); + mir_free(tmp2); } f.close(); DeleteFile(path.c_str()); + str.erase(str.find_last_of(_T("\n")), 1); if(!str.length()) { mir_free((void**)pre->szMessage); @@ -159,6 +176,11 @@ int RecvMsgSvc(WPARAM w, LPARAM l) else { mir_free((void**)pre->szMessage); + if(bAppendTags) + { + str.insert(0, inopentag); + str.append(inclosetag); + } char *utf = mir_utf8encodeW(str.c_str()); pre->szMessage = utf; return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); @@ -199,6 +221,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(tmp); return CallService(MS_PROTO_CHAINSEND, w, l); } + cmd += _T("--trust-model always "); cmd += _T("--batch --yes -e -a -r "); TCHAR *tmp2 = mir_a2t(tmp); mir_free(tmp); @@ -223,13 +246,13 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(tmp); f.close(); } - MessageBox(0, cmd.c_str(), _T("in"), MB_OK); + //MessageBox(0, cmd.c_str(), _T("in"), MB_OK); if(pxExecute(&cmd, "", &out, &code) == pxNotFound) { MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); return CallService(MS_PROTO_CHAINSEND, w, l); } - MessageBoxA(0, out.c_str(), "out", MB_OK); + //MessageBoxA(0, out.c_str(), "out", MB_OK); DeleteFile(path.c_str()); path.append(_T(".asc")); wfstream f(path.c_str(), std::ios::in); @@ -245,13 +268,47 @@ int SendMsgSvc(WPARAM w, LPARAM l) DeleteFile(path.c_str()); if(!str.length()) { - ccs->lParam = (LPARAM)"Failed to encrypt message with GPG"; + HistoryLog(ccs->hContact, "Failed to encrypt message with GPG", EVENTTYPE_MESSAGE, DBEF_SENT); return CallService(MS_PROTO_CHAINRECV, w, (LPARAM)ccs); } mir_free((void**)ccs->lParam); char *utf = mir_utf8encodeW(str.c_str()); ccs->lParam = (LPARAM)utf; + if(bAppendTags) + DBWriteContactSettingByte(ccs->hContact, szModuleName, "MsgsForTagging", DBGetContactSettingByte(ccs->hContact, szModuleName, "MsgsForTagging", 0) + 1); } } return CallService(MS_PROTO_CHAINSEND, w, l); +} + +int HookSendMsg(WPARAM w, LPARAM l) +{ + HANDLE hContact = (HANDLE)w; + if(!DBGetContactSettingByte(hContact, szModuleName, "GPGEncryption", 0)) + return 0; + + if(bAppendTags) + { + if(!l) + return 0; + BYTE Msgs = DBGetContactSettingByte(hContact, szModuleName, "MsgsForTagging", 0); + if(!Msgs) + return 0; + DBEVENTINFO * dbei = (DBEVENTINFO*)l; + if((dbei->eventType == EVENTTYPE_MESSAGE) && (dbei->flags & DBEF_SENT)) + { + char *msg = (char*)dbei->pBlob; + TCHAR *tmp = mir_utf8decodeW(msg); + wstring str = tmp; + mir_free(tmp); + str.insert(0, outopentag); + str.append(outclosetag); + char *msg2 = mir_utf8encodeW(str.c_str()); + mir_free(dbei->pBlob); + dbei->pBlob = (PBYTE)msg2; + dbei->cbBlob = strlen(msg2)+1; + DBWriteContactSettingByte(hContact, szModuleName, "MsgsForTagging", Msgs - 1); + } + } + return 0; } \ No newline at end of file -- cgit v1.2.3