diff options
author | George Hazan <ghazan@miranda.im> | 2020-03-21 12:32:50 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-03-21 12:32:50 +0300 |
commit | d889d65d4b832259ae68f0e596aee75a0c139c8e (patch) | |
tree | edec69174c01503825fe99e757502ead23bc81fc /plugins/New_GPG/src/messages.cpp | |
parent | 90a31cc69ee19b332410aa0f69692dc328625270 (diff) |
NewGPG:
- fixes #2266 (New_GPG: вынести пункты плагина в подменю);
- the rest of boolean options moved to CMOption<bool>;
- custom window location storing code reimplemented using Util_SaveWindowPosition;
- log generation code optimization;
- version bump
Diffstat (limited to 'plugins/New_GPG/src/messages.cpp')
-rwxr-xr-x | plugins/New_GPG/src/messages.cpp | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/plugins/New_GPG/src/messages.cpp b/plugins/New_GPG/src/messages.cpp index 4bd3f03698..105aeef442 100755 --- a/plugins/New_GPG/src/messages.cpp +++ b/plugins/New_GPG/src/messages.cpp @@ -45,7 +45,7 @@ static void RecvMsgSvc_func(RecvParams *param) wstring::size_type s2 = param->str.find(L"-----END PGP MESSAGE-----"); if (s2 != wstring::npos && s1 != wstring::npos) { //this is generic encrypted data block if (!isContactSecured(hContact)) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: received encrypted message from: " + toUTF8(Clist_GetContactDisplayName(hContact)) + " with turned off encryption"; if (MessageBox(nullptr, TranslateT("We received encrypted message from contact with encryption turned off.\nDo you want to turn on encryption for this contact?"), TranslateT("Warning"), MB_YESNO) == IDYES) { if (!isContactHaveKey(hContact)) @@ -68,7 +68,7 @@ static void RecvMsgSvc_func(RecvParams *param) return; } } - else if (globals.bDebugLog) + else if (globals.debuglog) globals.debuglog << "info: received encrypted message from: " + toUTF8(Clist_GetContactDisplayName(hContact)); boost::algorithm::erase_all(param->str, "\r"); s2 += mir_wstrlen(L"-----END PGP MESSAGE-----"); @@ -78,7 +78,7 @@ static void RecvMsgSvc_func(RecvParams *param) wstring decfile = toUTF16(get_random(10)); { wstring path = wstring(ptszHomePath) + L"\\tmp\\" + encfile; - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(path, e); } @@ -117,12 +117,12 @@ static void RecvMsgSvc_func(RecvParams *param) dbsetting += inkeyid; dbsetting += "_Password"; pass = g_plugin.getMStringW(dbsetting.c_str()); - if (!pass.IsEmpty() && globals.bDebugLog) + if (!pass.IsEmpty() && globals.debuglog) globals.debuglog << "info: found password in database for key ID: " + string(inkeyid.c_str()) + ", trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(hContact)) + " with password"; } else { pass = g_plugin.getMStringW("szKeyPassword"); - if (!pass.IsEmpty() && globals.bDebugLog) + if (!pass.IsEmpty() && globals.debuglog) globals.debuglog << "info: found password for all keys in database, trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(hContact)) + " with password"; } if (!pass.IsEmpty()) { @@ -130,16 +130,16 @@ static void RecvMsgSvc_func(RecvParams *param) params.addParam(pass.c_str()); } else if (!globals.wszPassword.IsEmpty()) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: found password in memory, trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(hContact)) + " with password"; params.addParam(L"--passphrase"); params.addParam(globals.wszPassword.c_str()); } - else if (globals.bDebugLog) + else if (globals.debuglog) globals.debuglog << "info: passwords not found in database or memory, trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(hContact)) + " without password"; } - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(wstring(ptszHomePath) + L"\\tmp\\" + decfile, e); } @@ -151,7 +151,7 @@ static void RecvMsgSvc_func(RecvParams *param) params.addParam(path); if (!gpg_launcher(params)) { - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(path, e); } @@ -165,7 +165,7 @@ static void RecvMsgSvc_func(RecvParams *param) return; } if (params.result == pxNotFound) { - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(path, e); } @@ -180,7 +180,7 @@ static void RecvMsgSvc_func(RecvParams *param) string out(params.out); while (out.find("public key decryption failed: bad passphrase") != string::npos) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: failed to decrypt messaage from " + toUTF8(Clist_GetContactDisplayName(hContact)) + " password needed, trying to get one"; if (globals._terminate) { BYTE enc = g_plugin.getByte(hContact, "GPGEncryption", 0); @@ -203,7 +203,7 @@ static void RecvMsgSvc_func(RecvParams *param) gpg_execution_params params2; params2.aargv = params.aargv; if (!globals.wszPassword.IsEmpty()) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: found password in memory, trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(hContact)); params2.addParam(L"--passphrase"); @@ -211,7 +211,7 @@ static void RecvMsgSvc_func(RecvParams *param) } if (!gpg_launcher(params2)) { - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(path, e); } @@ -226,7 +226,7 @@ static void RecvMsgSvc_func(RecvParams *param) return; } if (params2.result == pxNotFound) { - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(path, e); } @@ -238,7 +238,7 @@ static void RecvMsgSvc_func(RecvParams *param) } out.clear(); if (!gpg_launcher(params)) { - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(path, e); } @@ -254,7 +254,7 @@ static void RecvMsgSvc_func(RecvParams *param) } if (params.result == pxNotFound) { - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(path, e); } @@ -262,7 +262,7 @@ static void RecvMsgSvc_func(RecvParams *param) HistoryLog(hContact, db_event(param->msg, param->timestamp, 0, dbflags)); } - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(wstring(ptszHomePath) + L"\\tmp\\" + encfile, e); } @@ -270,7 +270,7 @@ static void RecvMsgSvc_func(RecvParams *param) if (!boost::filesystem::exists(wstring(ptszHomePath) + L"\\tmp\\" + decfile)) { string str1 = param->msg; str1.insert(0, "Received unencrypted message:\n"); - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: Failed to decrypt GPG encrypted message."; ptrA tmp4((char*)mir_alloc(sizeof(char)*(str1.length() + 1))); @@ -300,7 +300,7 @@ static void RecvMsgSvc_func(RecvParams *param) param->str.append(toUTF16(tmp)); delete[] tmp; f.close(); - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code ec; boost::filesystem::remove(tszDecPath, ec); if (ec) { @@ -312,7 +312,7 @@ static void RecvMsgSvc_func(RecvParams *param) if (param->str.empty()) { string szMsg = param->msg; szMsg.insert(0, "Failed to decrypt GPG encrypted message.\nMessage body for manual decryption:\n"); - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: Failed to decrypt GPG encrypted message."; HistoryLog(hContact, db_event(param->msg, param->timestamp, 0, dbflags)); @@ -326,7 +326,7 @@ static void RecvMsgSvc_func(RecvParams *param) } fix_line_term(param->str); - if (globals.bAppendTags) { + if (g_plugin.bAppendTags) { param->str.insert(0, globals.wszInopentag); param->str.append(globals.wszInclosetag); } @@ -366,7 +366,7 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) if (!strstr(msg, "-----BEGIN PGP MESSAGE-----")) return Proto_ChainRecv(w, ccs); else { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: blocked pgp message to metacontact:" + toUTF8(Clist_GetContactDisplayName(ccs->hContact)); return 0; } @@ -374,12 +374,12 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) wstring str = toUTF16(msg); size_t s1, s2; if (g_plugin.bAutoExchange && (str.find(L"-----PGP KEY RESPONSE-----") != wstring::npos)) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info(autoexchange): parsing key response:" + toUTF8(Clist_GetContactDisplayName(ccs->hContact)); s2 = str.find(L"-----END PGP PUBLIC KEY BLOCK-----"); s1 = str.find(L"-----BEGIN PGP PUBLIC KEY BLOCK-----"); if (s1 != wstring::npos && s2 != wstring::npos) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info(autoexchange): found pubkey block:" + toUTF8(Clist_GetContactDisplayName(ccs->hContact)); s2 += mir_wstrlen(L"-----END PGP PUBLIC KEY BLOCK-----"); g_plugin.setWString(ccs->hContact, "GPGPubKey", str.substr(s1, s2 - s1).c_str()); @@ -390,7 +390,7 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) tmp2 += get_random(5).c_str(); tmp2 += L".asc"; - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(tmp2.c_str(), e); } @@ -421,7 +421,7 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) if (!gpg_launcher(params)) return 1; - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(tmp2.c_str(), e); } @@ -494,7 +494,7 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) s1 = str.find(L"-----BEGIN PGP PRIVATE KEY BLOCK-----"); } if ((s2 != wstring::npos) && (s1 != wstring::npos)) { //this is public key - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: received key from: " + toUTF8(Clist_GetContactDisplayName(ccs->hContact)); s1 = 0; while ((s1 = str.find(L"\r", s1)) != wstring::npos) @@ -510,7 +510,7 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) } if (g_plugin.bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && globals.gpg_valid && globals.gpg_keyexist) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info(autoexchange): received key request from: " + toUTF8(Clist_GetContactDisplayName(ccs->hContact)); CMStringA tmp(g_plugin.getMStringA("GPGPubKey")); @@ -561,8 +561,8 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags) { wstring str = toUTF16(msg); - if (globals.bStripTags && globals.bAppendTags) { - if (globals.bDebugLog) + if (g_plugin.bStripTags && g_plugin.bAppendTags) { + if (globals.debuglog) globals.debuglog << "info: stripping tags in outgoing message, name: " + toUTF8(Clist_GetContactDisplayName(hContact)); strip_tags(str); } @@ -648,14 +648,14 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags) MessageBox(nullptr, TranslateT("Something is wrong, GPG does not understand us, aborting encryption."), TranslateT("Warning"), MB_OK); //mir_free(msg); ProtoChainSend(hContact, PSS_MESSAGE, flags, (LPARAM)msg); - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(path.c_str(), e); } return; } - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(path.c_str(), e); } @@ -686,7 +686,7 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags) str.append(tmp); delete[] tmp; f.close(); - if (!globals.bDebugLog) { + if (!globals.debuglog) { boost::system::error_code e; boost::filesystem::remove(path.c_str(), e); } @@ -694,19 +694,19 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags) if (str.empty()) { HistoryLog(hContact, db_event("Failed to encrypt message with GPG", 0, 0, DBEF_SENT)); - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: Failed to encrypt message with GPG"; ProtoChainSend(hContact, PSS_MESSAGE, flags, (LPARAM)msg); return; } string str_event = msg; - if (globals.bAppendTags) { + if (g_plugin.bAppendTags) { str_event.insert(0, toUTF8(globals.wszOutopentag.c_str())); str_event.append(toUTF8(globals.wszOutclosetag.c_str())); } - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "adding event to contact: " + toUTF8(Clist_GetContactDisplayName(hContact)) + " on send message."; fix_line_term(str); @@ -724,25 +724,25 @@ INT_PTR SendMsgSvc(WPARAM w, LPARAM l) char *msg = (char*)ccs->lParam; if (!msg) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: failed to get message data, name: " + toUTF8(Clist_GetContactDisplayName(ccs->hContact)); return Proto_ChainSend(w, ccs); } if (strstr(msg, "-----BEGIN PGP MESSAGE-----")) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: encrypted message, let it go, name: " + toUTF8(Clist_GetContactDisplayName(ccs->hContact)); return Proto_ChainSend(w, ccs); } - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: contact have key, name: " + toUTF8(Clist_GetContactDisplayName(ccs->hContact)); - if (globals.bDebugLog && db_mc_isMeta(ccs->hContact)) + if (globals.debuglog && db_mc_isMeta(ccs->hContact)) globals.debuglog << "info: protocol is metacontacts, name: " + toUTF8(Clist_GetContactDisplayName(ccs->hContact)); if (!isContactSecured(ccs->hContact) || db_mc_isMeta(ccs->hContact)) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: contact not secured, name: " + toUTF8(Clist_GetContactDisplayName(ccs->hContact)); return Proto_ChainSend(w, ccs); } @@ -763,13 +763,13 @@ int HookSendMsg(WPARAM w, LPARAM l) if (dbei->flags & DBEF_SENT) { if (isContactSecured(hContact) && strstr((char*)dbei->pBlob, "-----BEGIN PGP MESSAGE-----")) //our service data, can be double added by metacontacts e.w.c. { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info(send handler): block pgp message event, name: " + toUTF8(Clist_GetContactDisplayName(hContact)); return 1; } if (g_plugin.bAutoExchange && (strstr((char*)dbei->pBlob, "-----PGP KEY RESPONSE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----"))) ///do not show service data in history { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info(send handler): block pgp key request/response event, name: " + toUTF8(Clist_GetContactDisplayName(hContact)); return 1; } @@ -779,17 +779,17 @@ int HookSendMsg(WPARAM w, LPARAM l) return 0; if (!isContactHaveKey(hContact)) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: contact have not key, name: " + toUTF8(Clist_GetContactDisplayName(hContact)); if (g_plugin.bAutoExchange && !strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----") && !strstr((char*)dbei->pBlob, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && globals.gpg_valid) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info: checking for autoexchange possibility, name: " + toUTF8(Clist_GetContactDisplayName(hContact)); LPSTR proto = Proto_GetBaseAccountName(hContact); ptrA jid(db_get_utfa(hContact, proto, "jid", "")); if (jid[0]) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info(autoexchange): protocol looks like jabber, name: " + toUTF8(Clist_GetContactDisplayName(hContact)); for (auto p : globals.Accounts) { ptrA caps(p->getJabberInterface()->GetResourceFeatures(jid)); @@ -803,7 +803,7 @@ int HookSendMsg(WPARAM w, LPARAM l) } if (str.find("GPG_Key_Auto_Exchange:0") != string::npos) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info(autoexchange, jabber): autoexchange capability found, sending key request, name: " + toUTF8(Clist_GetContactDisplayName(hContact)); ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)"-----PGP KEY REQUEST-----"); globals.hcontact_data[hContact].msgs_to_send.push_back((char*)dbei->pBlob); @@ -821,7 +821,7 @@ int HookSendMsg(WPARAM w, LPARAM l) { SendMsgSvc_func(hContact, (char*)dbei->pBlob, 0); //TODO: handle errors somehow ... - if (globals.bAppendTags) { + if (g_plugin.bAppendTags) { string str_event = (char*)dbei->pBlob; //mir_free(dbei->pBlob); str_event.insert(0, toUTF8(globals.wszOutopentag.c_str())); @@ -834,7 +834,7 @@ int HookSendMsg(WPARAM w, LPARAM l) } if (!isContactSecured(hContact)) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "event message: \"" + string((char*)dbei->pBlob) + "\" passed event filter, contact " + toUTF8(Clist_GetContactDisplayName(hContact)) + " is unsecured"; return 0; } @@ -844,7 +844,7 @@ int HookSendMsg(WPARAM w, LPARAM l) strncpy(tmp, (char*)dbei->pBlob, 27); tmp[28] = '\0'; if (strstr(tmp, "-----BEGIN PGP MESSAGE-----")) { - if (globals.bDebugLog) + if (globals.debuglog) globals.debuglog << "info(send handler): block pgp message event, name: " + toUTF8(Clist_GetContactDisplayName(hContact)); return 1; } |