summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-03-21 12:32:50 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-03-21 12:32:50 +0300
commitd889d65d4b832259ae68f0e596aee75a0c139c8e (patch)
treeedec69174c01503825fe99e757502ead23bc81fc /plugins
parent90a31cc69ee19b332410aa0f69692dc328625270 (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')
-rwxr-xr-xplugins/New_GPG/src/globals.h9
-rwxr-xr-xplugins/New_GPG/src/gpg_wrapper.cpp12
-rwxr-xr-xplugins/New_GPG/src/init.cpp65
-rwxr-xr-xplugins/New_GPG/src/log.cpp16
-rw-r--r--plugins/New_GPG/src/log.h2
-rwxr-xr-xplugins/New_GPG/src/main.h30
-rwxr-xr-xplugins/New_GPG/src/messages.cpp100
-rwxr-xr-xplugins/New_GPG/src/options.cpp47
-rwxr-xr-xplugins/New_GPG/src/stdafx.h3
-rwxr-xr-xplugins/New_GPG/src/ui.cpp43
-rwxr-xr-xplugins/New_GPG/src/utilities.cpp56
-rwxr-xr-xplugins/New_GPG/src/utilities.h4
-rwxr-xr-xplugins/New_GPG/src/version.h2
13 files changed, 160 insertions, 229 deletions
diff --git a/plugins/New_GPG/src/globals.h b/plugins/New_GPG/src/globals.h
index 1bb0087629..adc25a42f0 100755
--- a/plugins/New_GPG/src/globals.h
+++ b/plugins/New_GPG/src/globals.h
@@ -17,16 +17,21 @@
#ifndef GLOBALS_H
#define GLOBALS_H
+struct contact_data
+{
+ list<string> msgs_to_send;// msgs_to_pass;
+ string key_in_prescense;
+};
+
struct globals_s
{
- bool bAppendTags = false, bDebugLog = false, bStripTags = false, tabsrmm_used = false, bDecryptFiles = false;
+ bool bDecryptFiles = false;
CMStringW wszInopentag, wszInclosetag, wszOutopentag, wszOutclosetag, wszPassword;
wchar_t key_id_global[17] = { 0 };
list <JabberAccount*> Accounts;
HFONT bold_font = nullptr;
HANDLE hLoadPubKey = nullptr, g_hCLIcon = nullptr, hExportGpgKeys = nullptr, hImportGpgKeys = nullptr;
HGENMENU hSendKey = nullptr, hToggleEncryption = nullptr;
- RECT key_from_keyserver_rect = { 0 }, firstrun_rect = { 0 }, new_key_rect = { 0 }, key_gen_rect = { 0 }, load_key_rect = { 0 }, import_key_rect = { 0 }, key_password_rect = { 0 }, load_existing_key_rect = { 0 };
logtofile debuglog;
bool gpg_valid = false, gpg_keyexist = false;
std::map<MCONTACT, contact_data> hcontact_data;
diff --git a/plugins/New_GPG/src/gpg_wrapper.cpp b/plugins/New_GPG/src/gpg_wrapper.cpp
index d7e9677ead..ec61fe129a 100755
--- a/plugins/New_GPG/src/gpg_wrapper.cpp
+++ b/plugins/New_GPG/src/gpg_wrapper.cpp
@@ -31,7 +31,7 @@ void pxEexcute_thread(gpg_execution_params *params)
CMStringW bin_path(g_plugin.getMStringW("szGpgBinPath"));
if (_waccess(bin_path, 0)) {
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << "GPG executable not found";
params->result = pxNotFound;
return;
@@ -54,7 +54,7 @@ void pxEexcute_thread(gpg_execution_params *params)
argv.push_back(L"-z9");
argv.insert(argv.end(), params->aargv.begin(), params->aargv.end());
- if (globals.bDebugLog) {
+ if (globals.debuglog) {
std::wstring args;
for (unsigned int i = 0; i < argv.size(); ++i) {
args += argv[i];
@@ -96,7 +96,7 @@ void pxEexcute_thread(gpg_execution_params *params)
params->out.Replace("\r\r", "");
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << "gpg out: " << params->out.c_str();
}
@@ -105,7 +105,7 @@ void pxEexcute_thread(gpg_execution_params *params)
delete c;
if (params->code) {
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << ": warning: wrong gpg exit status, gpg output: " << params->out.c_str();
params->result = pxSuccessExitCodeInvalid;
}
@@ -120,7 +120,7 @@ bool gpg_launcher(gpg_execution_params &params, boost::posix_time::time_duration
ret = false;
if (params.child)
params.child->terminate();
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << "GPG execution timed out, aborted";
}
return ret;
@@ -137,7 +137,7 @@ void pxEexcute_passwd_change_thread(gpg_execution_params_pass *params)
CMStringW bin_path(g_plugin.getMStringW("szGpgBinPath"));
if (_waccess(bin_path, 0)) {
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << "GPG executable not found";
params->result = pxNotFound;
return;
diff --git a/plugins/New_GPG/src/init.cpp b/plugins/New_GPG/src/init.cpp
index 479edbd329..fc1bc328ef 100755
--- a/plugins/New_GPG/src/init.cpp
+++ b/plugins/New_GPG/src/init.cpp
@@ -52,7 +52,10 @@ PLUGININFOEX pluginInfoEx = {
CMPlugin::CMPlugin() :
PLUGIN<CMPlugin>(MODULENAME, pluginInfoEx),
+ bDebugLog(MODULENAME, "bDebugLog", false),
bJabberAPI(MODULENAME, "bJabberAPI", true),
+ bStripTags(MODULENAME, "bStripTags", false),
+ bAppendTags(MODULENAME, "bAppendTags", false),
bSameAction(MODULENAME, "bSameAction", false),
bAutoExchange(MODULENAME, "bAutoExchange", false),
bFileTransfers(MODULENAME, "bFileTransfers", false),
@@ -75,29 +78,11 @@ void InitIconLib();
void init_vars()
{
- globals.bAppendTags = g_plugin.getBool("bAppendTags", 0);
- globals.bStripTags = g_plugin.getBool("bStripTags", 0);
globals.wszInopentag = g_plugin.getMStringW("szInOpenTag", L"<GPGdec>");
globals.wszInclosetag = g_plugin.getMStringW("szInCloseTag", L"</GPGdec>");
globals.wszOutopentag = g_plugin.getMStringW("szOutOpenTag", L"<GPGenc>");
globals.wszOutclosetag = g_plugin.getMStringW("szOutCloseTag", L"</GPGenc>");
- globals.bDebugLog = g_plugin.getBool("bDebugLog", 0);
globals.wszPassword = g_plugin.getMStringW("szKeyPassword");
- globals.firstrun_rect.left = g_plugin.getDword("FirstrunWindowX", 0);
- globals.firstrun_rect.top = g_plugin.getDword("FirstrunWindowY", 0);
- globals.key_password_rect.left = g_plugin.getDword("PasswordWindowX", 0);
- globals.key_password_rect.top = g_plugin.getDword("PasswordWindowY", 0);
- globals.key_gen_rect.left = g_plugin.getDword("KeyGenWindowX", 0);
- globals.key_gen_rect.top = g_plugin.getDword("KeyGenWindowY", 0);
- globals.load_key_rect.left = g_plugin.getDword("LoadKeyWindowX", 0);
- globals.load_key_rect.top = g_plugin.getDword("LoadKeyWindowY", 0);
- globals.import_key_rect.left = g_plugin.getDword("ImportKeyWindowX", 0);
- globals.import_key_rect.top = g_plugin.getDword("ImportKeyWindowY", 0);
- globals.new_key_rect.left = g_plugin.getDword("NewKeyWindowX", 0);
- globals.new_key_rect.top = g_plugin.getDword("NewKeyWindowY", 0);
- globals.load_existing_key_rect.left = g_plugin.getDword("LoadExistingKeyWindowX", 0);
- globals.load_existing_key_rect.top = g_plugin.getDword("LoadExistingKeyWindowY", 0);
- globals.tabsrmm_used = isTabsrmmUsed();
globals.bold_font = CreateFont(14, 0, 0, 0, 600, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, L"Arial");
globals.debuglog.init();
@@ -147,52 +132,58 @@ int CMPlugin::Load()
HookEvent(ME_PROTO_ACK, onProtoAck);
HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
+ InitIconLib();
init_vars();
- CreateServiceFunction("/LoadPubKey", LoadKey);
- CreateServiceFunction("/ToggleEncryption", ToggleEncryption);
- CreateServiceFunction("/SendKey", SendKey);
- CreateServiceFunction("/ExportGPGKeys", ExportGpGKeys);
- CreateServiceFunction("/ImportGPGKeys", ImportGpGKeys);
+
+ ////////////////////////////////////////////////////////////////////////////////////////
+ // Comtact menu items
CMenuItem mi(&g_plugin);
+ mi.hIcolibItem = g_plugin.getIconHandle(IDI_SECURED);
SET_UID(mi, 0xbd22e3f8, 0xc19c, 0x45a8, 0xb7, 0x37, 0x6b, 0x3b, 0x27, 0xf0, 0x8c, 0xbb);
mi.position = -0x7FFFFFFF;
- mi.flags = CMIF_UNICODE;
- mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
- mi.name.w = LPGENW("Load public GPG key");
+ mi.name.a = LPGEN("Load public GPG key");
mi.pszService = "/LoadPubKey";
globals.hLoadPubKey = Menu_AddContactMenuItem(&mi);
+ CreateServiceFunction(mi.pszService, LoadKey);
SET_UID(mi, 0xc8008193, 0x56a9, 0x414a, 0x82, 0x98, 0x78, 0xe8, 0xa8, 0x84, 0x20, 0x67);
mi.position = -0x7FFFFFFe;
- mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
- mi.name.w = LPGENW("Toggle GPG encryption");
+ mi.name.a = LPGEN("Toggle GPG encryption");
mi.pszService = "/ToggleEncryption";
globals.hToggleEncryption = Menu_AddContactMenuItem(&mi);
+ CreateServiceFunction(mi.pszService, ToggleEncryption);
SET_UID(mi, 0x42bb535f, 0xd58e, 0x4edb, 0xbf, 0x2c, 0xfa, 0x9a, 0xbf, 0x1e, 0xb8, 0x69);
mi.position = -0x7FFFFFFd;
- mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
- mi.name.w = LPGENW("Send public key");
+ mi.name.a = LPGEN("Send public key");
mi.pszService = "/SendKey";
globals.hSendKey = Menu_AddContactMenuItem(&mi);
+ CreateServiceFunction(mi.pszService, SendKey);
+
+ ////////////////////////////////////////////////////////////////////////////////////////
+ // Main menu items
+
+ SET_UID(mi, 0x0bac023bb, 0xd2e, 0x46e0, 0x93, 0x13, 0x7c, 0xf9, 0xf6, 0xb5, 0x02, 0xd1);
+ mi.position = -0x7FFFFFFe;
+ mi.name.a = "GPG";
+ mi.root = Menu_AddMainMenuItem(&mi);
+ mi.flags = CMIF_UNMOVABLE;
SET_UID(mi, 0x33a204b2, 0xe3c0, 0x413b, 0xbf, 0xd8, 0x8b, 0x2e, 0x3d, 0xa0, 0xef, 0xa4);
mi.position = -0x7FFFFFFe;
- mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
- mi.name.w = LPGENW("Export GPG Public keys");
+ mi.name.a = LPGEN("Export GPG Public keys");
mi.pszService = "/ExportGPGKeys";
globals.hExportGpgKeys = Menu_AddMainMenuItem(&mi);
+ CreateServiceFunction(mi.pszService, ExportGpGKeys);
- SET_UID(mi, 0x627fcfc1, 0x4e60, 0x4428, 0xaf, 0x96, 0x11, 0x42, 0x24, 0xeb, 0x7, 0xea);
+ SET_UID(mi, 0x627fcfc1, 0x4e60, 0x4428, 0xaf, 0x96, 0x11, 0x42, 0x24, 0xeb, 0x07, 0xea);
mi.position = -0x7FFFFFFF;
- mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
- mi.name.w = LPGENW("Import GPG Public keys");
+ mi.name.a = LPGEN("Import GPG Public keys");
mi.pszService = "/ImportGPGKeys";
globals.hImportGpgKeys = Menu_AddMainMenuItem(&mi);
-
- InitIconLib();
+ CreateServiceFunction(mi.pszService, ImportGpGKeys);
globals.g_hCLIcon = ExtraIcon_RegisterCallback(MODULENAME, Translate("GPG encryption status"), "secured", onExtraImageListRebuilding, onExtraImageApplying);
return 0;
diff --git a/plugins/New_GPG/src/log.cpp b/plugins/New_GPG/src/log.cpp
index feebd738e8..6d2c7ba88e 100755
--- a/plugins/New_GPG/src/log.cpp
+++ b/plugins/New_GPG/src/log.cpp
@@ -24,30 +24,26 @@ static string time_str()
logtofile &logtofile::operator<<(const char *buf)
{
- if (bEnabled != globals.bDebugLog)
- init();
-
- mir_writeLogA(hLogger, "%s: %s\n", time_str().c_str(), buf);
+ if (bEnabled)
+ mir_writeLogA(hLogger, "%s: %s\n", time_str().c_str(), buf);
return *this;
}
logtofile& logtofile::operator<<(const string &buf)
{
- if (bEnabled != globals.bDebugLog)
- init();
-
- mir_writeLogA(hLogger, "%s: %s\n", time_str().c_str(), buf.c_str());
+ if (bEnabled)
+ mir_writeLogA(hLogger, "%s: %s\n", time_str().c_str(), buf.c_str());
return *this;
}
void logtofile::init()
{
- if (globals.bDebugLog)
+ if (g_plugin.bDebugLog)
hLogger = mir_createLog("NewGPG", L"NewGPG log file", g_plugin.getMStringW("szLogFilePath", L"C:\\GPGdebug.log"), 0);
else {
mir_closeLog(hLogger);
hLogger = nullptr;
}
- bEnabled = globals.bDebugLog;
+ bEnabled = g_plugin.bDebugLog;
}
diff --git a/plugins/New_GPG/src/log.h b/plugins/New_GPG/src/log.h
index e48d298bd6..e563bc71d0 100644
--- a/plugins/New_GPG/src/log.h
+++ b/plugins/New_GPG/src/log.h
@@ -25,6 +25,8 @@ public:
logtofile& operator<<(const char *buf);
logtofile& operator<<(const std::string &buf);
void init();
+
+ __forceinline operator bool() const { return bEnabled; }
};
#endif
diff --git a/plugins/New_GPG/src/main.h b/plugins/New_GPG/src/main.h
deleted file mode 100755
index 779908b70b..0000000000
--- a/plugins/New_GPG/src/main.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright © 2010-20 sss
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#ifndef MAIN_H
-#define MAIN_H
-
-struct contact_data
-{
- list<string> msgs_to_send;// msgs_to_pass;
- string key_in_prescense;
-};
-
-void ImportKey(MCONTACT hContact, std::wstring new_key);
-
-
-#endif
-
-
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;
}
diff --git a/plugins/New_GPG/src/options.cpp b/plugins/New_GPG/src/options.cpp
index c76a775406..c3ff7da01e 100755
--- a/plugins/New_GPG/src/options.cpp
+++ b/plugins/New_GPG/src/options.cpp
@@ -51,6 +51,7 @@ public:
list_USERLIST.OnItemChanged = Callback(this, &COptGpgMainDlg::onItemChanged_USERLIST);
+ CreateLink(check_DEBUG_LOG, g_plugin.bDebugLog);
CreateLink(check_JABBER_API, g_plugin.bJabberAPI);
CreateLink(check_AUTO_EXCHANGE, g_plugin.bAutoExchange);
CreateLink(check_FILE_TRANSFERS, g_plugin.bFileTransfers);
@@ -99,7 +100,6 @@ public:
edit_LOG_FILE_EDIT.SetText(ptrW(g_plugin.getWStringA("szLogFilePath", L"")));
- check_DEBUG_LOG.SetState(g_plugin.getByte("bDebugLog", 0));
check_JABBER_API.Enable();
check_AUTO_EXCHANGE.Enable(g_plugin.bJabberAPI);
@@ -123,7 +123,6 @@ public:
bool OnApply() override
{
- g_plugin.setByte("bDebugLog", globals.bDebugLog = check_DEBUG_LOG.GetState());
globals.debuglog.init();
if (g_plugin.bFileTransfers != old_bFileTransfers)
@@ -446,12 +445,13 @@ public:
COptGpgMsgDlg() : CDlgBase(g_plugin, IDD_OPT_GPG_MESSAGES),
check_APPEND_TAGS(this, IDC_APPEND_TAGS), check_STRIP_TAGS(this, IDC_STRIP_TAGS),
edit_IN_OPEN_TAG(this, IDC_IN_OPEN_TAG), edit_IN_CLOSE_TAG(this, IDC_IN_CLOSE_TAG), edit_OUT_OPEN_TAG(this, IDC_OUT_OPEN_TAG), edit_OUT_CLOSE_TAG(this, IDC_OUT_CLOSE_TAG)
- {}
+ {
+ CreateLink(check_STRIP_TAGS, g_plugin.bStripTags);
+ CreateLink(check_APPEND_TAGS, g_plugin.bAppendTags);
+ }
bool OnInitDialog() override
{
- check_APPEND_TAGS.SetState(g_plugin.getByte("bAppendTags", 0));
- check_STRIP_TAGS.SetState(g_plugin.getByte("bStripTags", 0));
edit_IN_OPEN_TAG.SetText(g_plugin.getMStringW("szInOpenTag", L"<GPGdec>"));
edit_IN_CLOSE_TAG.SetText(g_plugin.getMStringW("szInCloseTag", L"</GPGdec>"));
edit_OUT_OPEN_TAG.SetText(g_plugin.getMStringW("szOutOpenTag", L"<GPGenc>"));
@@ -461,25 +461,21 @@ public:
bool OnApply() override
{
- g_plugin.setByte("bAppendTags", globals.bAppendTags = check_APPEND_TAGS.GetState());
- g_plugin.setByte("bStripTags", globals.bStripTags = check_STRIP_TAGS.GetState());
- {
- ptrW tmp(edit_IN_OPEN_TAG.GetText());
- g_plugin.setWString("szInOpenTag", tmp);
- globals.wszInopentag = tmp;
+ ptrW tmp(edit_IN_OPEN_TAG.GetText());
+ g_plugin.setWString("szInOpenTag", tmp);
+ globals.wszInopentag = tmp;
- tmp = edit_IN_CLOSE_TAG.GetText();
- g_plugin.setWString("szInCloseTag", tmp);
- globals.wszInclosetag = tmp;
+ tmp = edit_IN_CLOSE_TAG.GetText();
+ g_plugin.setWString("szInCloseTag", tmp);
+ globals.wszInclosetag = tmp;
- tmp = mir_wstrdup(edit_OUT_OPEN_TAG.GetText());
- g_plugin.setWString("szOutOpenTag", tmp);
- globals.wszOutopentag = tmp;
+ tmp = mir_wstrdup(edit_OUT_OPEN_TAG.GetText());
+ g_plugin.setWString("szOutOpenTag", tmp);
+ globals.wszOutopentag = tmp;
- tmp = mir_wstrdup(edit_OUT_CLOSE_TAG.GetText());
- g_plugin.setWString("szOutCloseTag", tmp);
- globals.wszOutclosetag = tmp;
- }
+ tmp = mir_wstrdup(edit_OUT_CLOSE_TAG.GetText());
+ g_plugin.setWString("szOutCloseTag", tmp);
+ globals.wszOutclosetag = tmp;
return true;
}
};
@@ -557,7 +553,8 @@ public:
bool OnInitDialog() override
{
- SetWindowPos(m_hwnd, nullptr, globals.load_key_rect.left, globals.load_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
+ Utils_RestoreWindowPosition(m_hwnd, 0, MODULENAME, "LoadKeyWindow");
+
mir_subclassWindow(GetDlgItem(m_hwnd, IDC_PUBLIC_KEY_EDIT), editctrl_ctrl_a);
MCONTACT hcnt = db_mc_tryMeta(hContact);
{
@@ -630,9 +627,7 @@ public:
virtual void OnDestroy() override
{
- GetWindowRect(m_hwnd, &globals.load_key_rect);
- g_plugin.setDword("LoadKeyWindowX", globals.load_key_rect.left);
- g_plugin.setDword("LoadKeyWindowY", globals.load_key_rect.top);
+ Utils_SaveWindowPosition(m_hwnd, 0, MODULENAME, "LoadKeyWindow");
edit_p_PubKeyEdit = nullptr;
}
@@ -944,7 +939,7 @@ public:
}
if (key_buf.empty()) {
key_buf.clear();
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << "info: Failed to read key file";
return;
}
diff --git a/plugins/New_GPG/src/stdafx.h b/plugins/New_GPG/src/stdafx.h
index b3dfcfe3f6..f049d155a9 100755
--- a/plugins/New_GPG/src/stdafx.h
+++ b/plugins/New_GPG/src/stdafx.h
@@ -72,7 +72,7 @@ using std::fstream;
struct CMPlugin : public PLUGIN<CMPlugin>
{
- CMOption<bool> bJabberAPI, bPresenceSigning, bFileTransfers, bAutoExchange, bSameAction;
+ CMOption<bool> bJabberAPI, bPresenceSigning, bFileTransfers, bAutoExchange, bSameAction, bAppendTags, bStripTags, bDebugLog;
CMPlugin();
@@ -86,7 +86,6 @@ struct CMPlugin : public PLUGIN<CMPlugin>
#include "constants.h"
#include "log.h"
#include "utilities.h"
-#include "main.h"
#include "gpg_wrapper.h"
#include "jabber_account.h"
#include "metacontacts.h"
diff --git a/plugins/New_GPG/src/ui.cpp b/plugins/New_GPG/src/ui.cpp
index 5c45535c2b..2048d5fcbb 100755
--- a/plugins/New_GPG/src/ui.cpp
+++ b/plugins/New_GPG/src/ui.cpp
@@ -129,7 +129,7 @@ bool CDlgChangePasswdMsgBox::OnApply()
if (WaitForSingleObject(hThread, 600000) != WAIT_OBJECT_0) {
if (params.child)
params.child->terminate();
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << "GPG execution timed out, aborted";
return true;
}
@@ -173,7 +173,7 @@ CDlgFirstRun::CDlgFirstRun() :
bool CDlgFirstRun::OnInitDialog()
{
- SetWindowPos(m_hwnd, nullptr, globals.firstrun_rect.left, globals.firstrun_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
+ Utils_RestoreWindowPosition(m_hwnd, 0, MODULENAME, "FirstrunWindow");
SetCaption(TranslateT("Set own key"));
btn_COPY_PUBKEY.Disable();
btn_EXPORT_PRIVATE.Disable();
@@ -311,7 +311,7 @@ void CDlgFirstRun::onClick_CHANGE_PASSWD(CCtrlButton*)
if (WaitForSingleObject(hThread, 600000) != WAIT_OBJECT_0) {
if (params.child)
params.child->terminate();
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << "GPG execution timed out, aborted";
this->Close();
}
@@ -494,9 +494,7 @@ void CDlgFirstRun::onChange_KEY_LIST(CCtrlListView::TEventInfo *ev) //TODO: chec
void CDlgFirstRun::OnDestroy()
{
- GetWindowRect(m_hwnd, &globals.firstrun_rect);
- g_plugin.setDword("FirstrunWindowX", globals.firstrun_rect.left);
- g_plugin.setDword("FirstrunWindowY", globals.firstrun_rect.top);
+ Utils_SaveWindowPosition(m_hwnd, 0, MODULENAME, "FirstrunWindow");
}
void CDlgFirstRun::refresh_key_list()
@@ -812,7 +810,8 @@ CDlgNewKey::CDlgNewKey(MCONTACT _hContact, wstring _new_key) :
bool CDlgNewKey::OnInitDialog()
{
- SetWindowPos(m_hwnd, nullptr, globals.new_key_rect.left, globals.new_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
+ Utils_RestoreWindowPosition(m_hwnd, 0, MODULENAME, "NewKeyWindow");
+
CMStringW tmp = g_plugin.getMStringW(hContact, "GPGPubKey");
lbl_MESSAGE.SetText(!tmp.IsEmpty() ? TranslateT("There is existing key for contact, would you like to replace it with new key?") : TranslateT("New public key was received, do you want to import it?"));
btn_IMPORT_AND_USE.Enable(g_plugin.getByte(hContact, "GPGEncryption", 0));
@@ -825,9 +824,7 @@ bool CDlgNewKey::OnInitDialog()
void CDlgNewKey::OnDestroy()
{
- GetWindowRect(m_hwnd, &globals.new_key_rect);
- g_plugin.setDword("NewKeyWindowX", globals.new_key_rect.left);
- g_plugin.setDword("NewKeyWindowY", globals.new_key_rect.top);
+ Utils_SaveWindowPosition(m_hwnd, 0, MODULENAME, "NewKeyWindow");
}
void CDlgNewKey::onClick_IMPORT(CCtrlButton*)
@@ -869,8 +866,9 @@ CDlgKeyGen::CDlgKeyGen() :
bool CDlgKeyGen::OnInitDialog()
{
- SetWindowPos(m_hwnd, nullptr, globals.key_gen_rect.left, globals.key_gen_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
+ Utils_RestoreWindowPosition(m_hwnd, 0, MODULENAME, "KeygenWindow");
SetCaption(TranslateT("Key Generation dialog"));
+
combo_KEY_TYPE.AddString(L"RSA");
combo_KEY_TYPE.AddString(L"DSA");
combo_KEY_TYPE.SelectString(L"RSA");
@@ -995,9 +993,7 @@ bool CDlgKeyGen::OnApply()
void CDlgKeyGen::OnDestroy()
{
- GetWindowRect(m_hwnd, &globals.key_gen_rect);
- g_plugin.setDword("KeyGenWindowX", globals.key_gen_rect.left);
- g_plugin.setDword("KeyGenWindowY", globals.key_gen_rect.top);
+ Utils_SaveWindowPosition(m_hwnd, 0, MODULENAME, "KeygenWindow");
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -1011,7 +1007,7 @@ CDlgLoadExistingKey::CDlgLoadExistingKey() :
bool CDlgLoadExistingKey::OnInitDialog()
{
- SetWindowPos(m_hwnd, nullptr, globals.load_existing_key_rect.left, globals.load_existing_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
+ Utils_RestoreWindowPosition(m_hwnd, 0, MODULENAME, "LoadKeyWindow");
list_EXISTING_KEY_LIST.AddColumn(0, TranslateT("Key ID"), 50);
list_EXISTING_KEY_LIST.AddColumn(1, TranslateT("Email"), 30);
@@ -1105,9 +1101,7 @@ bool CDlgLoadExistingKey::OnInitDialog()
void CDlgLoadExistingKey::OnDestroy()
{
- GetWindowRect(m_hwnd, &globals.load_existing_key_rect);
- g_plugin.setDword("LoadExistingKeyWindowX", globals.load_existing_key_rect.left);
- g_plugin.setDword("LoadExistingKeyWindowY", globals.load_existing_key_rect.top);
+ Utils_SaveWindowPosition(m_hwnd, 0, MODULENAME, "LoadKeyWindow");
}
bool CDlgLoadExistingKey::OnApply()
@@ -1167,7 +1161,8 @@ CDlgImportKey::CDlgImportKey(MCONTACT _hContact) :
bool CDlgImportKey::OnInitDialog()
{
- SetWindowPos(m_hwnd, nullptr, globals.import_key_rect.left, globals.import_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
+ Utils_RestoreWindowPosition(m_hwnd, 0, MODULENAME, "ImportKeyWindow");
+
combo_KEYSERVER.AddString(L"subkeys.pgp.net");
combo_KEYSERVER.AddString(L"keys.gnupg.net");
return true;
@@ -1175,9 +1170,7 @@ bool CDlgImportKey::OnInitDialog()
void CDlgImportKey::OnDestroy()
{
- GetWindowRect(m_hwnd, &globals.import_key_rect);
- g_plugin.setDword("ImportKeyWindowX", globals.import_key_rect.left);
- g_plugin.setDword("ImportKeyWindowY", globals.import_key_rect.top);
+ Utils_SaveWindowPosition(m_hwnd, 0, MODULENAME, "ImportKeyWindow");
}
void CDlgImportKey::onClick_IMPORT(CCtrlButton*)
@@ -1210,7 +1203,7 @@ CDlgKeyPasswordMsgBox::CDlgKeyPasswordMsgBox(MCONTACT _hContact) :
bool CDlgKeyPasswordMsgBox::OnInitDialog()
{
- SetWindowPos(m_hwnd, nullptr, globals.key_password_rect.left, globals.key_password_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
+ Utils_RestoreWindowPosition(m_hwnd, 0, MODULENAME, "PasswordWindow");
CMStringW questionstr = TranslateT("Please enter password for key with ID: ");
questionstr += g_plugin.getMStringW(hContact, "InKeyID");
@@ -1223,9 +1216,7 @@ bool CDlgKeyPasswordMsgBox::OnInitDialog()
void CDlgKeyPasswordMsgBox::OnDestroy()
{
mir_free(inkeyid);
- GetWindowRect(m_hwnd, &globals.key_password_rect);
- g_plugin.setDword("PasswordWindowX", globals.key_password_rect.left);
- g_plugin.setDword("PasswordWindowY", globals.key_password_rect.top);
+ Utils_SaveWindowPosition(m_hwnd, 0, MODULENAME, "PasswordWindow");
}
void CDlgKeyPasswordMsgBox::onClick_OK(CCtrlButton*)
diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp
index ec91c56660..e9e64f0f95 100755
--- a/plugins/New_GPG/src/utilities.cpp
+++ b/plugins/New_GPG/src/utilities.cpp
@@ -264,12 +264,12 @@ int onProtoAck(WPARAM, LPARAM l)
dbsetting += keyid;
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(keyid.c_str()) + ", trying to decrypt message from " + toUTF8(Clist_GetContactDisplayName(ack->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(ack->hContact)) + " with password";
}
if (!pass.IsEmpty()) {
@@ -277,12 +277,12 @@ int onProtoAck(WPARAM, LPARAM l)
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(ack->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(ack->hContact)) + " without password";
}
params.addParam(L"-d");
@@ -292,7 +292,7 @@ int onProtoAck(WPARAM, LPARAM l)
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(ack->hContact)) + " password needed, trying to get one";
if (globals._terminate)
break;
@@ -310,7 +310,7 @@ int onProtoAck(WPARAM, LPARAM l)
d->DoModal();
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(ack->hContact));
params.addParam(L"--passphrase");
@@ -568,7 +568,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, TiXmlElement *node,
f << str;
f.close();
if (!boost::filesystem::exists(path_out)) {
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << "info: Failed to write prescense in file";
break;
}
@@ -587,12 +587,12 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, TiXmlElement *node,
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 encrypt message from self 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 encrypt message from self with password";
}
if (pass[0]) {
@@ -600,12 +600,12 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, TiXmlElement *node,
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 encrypt message from self 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 encrypt message from self without password";
}
@@ -635,7 +635,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, TiXmlElement *node,
boost::filesystem::remove(path_out);
}
if (data.empty()) {
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << "info: Failed to read prescense sign from file";
break;
}
@@ -730,7 +730,7 @@ static JABBER_HANDLER_FUNC PresenceHandler(IJabberInterface *ji, TiXmlElement* n
f << status_str.c_str();
f.close();
if (!boost::filesystem::exists(path_out.c_str())) {
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << "info: Failed to write sign in file";
return FALSE;
}
@@ -799,19 +799,19 @@ bool isContactSecured(MCONTACT hContact)
{
BYTE gpg_enc = g_plugin.getByte(hContact, "GPGEncryption", 0);
if (!gpg_enc) {
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << "encryption is turned off for " + toUTF8(Clist_GetContactDisplayName(hContact));
return false;
}
if (!db_mc_isMeta(hContact)) {
CMStringW key = g_plugin.getMStringW(hContact, "GPGPubKey");
if (key.IsEmpty()) {
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << "encryption is turned off for " + toUTF8(Clist_GetContactDisplayName(hContact));
return false;
}
}
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << "encryption is turned on for " + toUTF8(Clist_GetContactDisplayName(hContact));
return true;
}
@@ -960,7 +960,7 @@ string toUTF8(wstring str)
utf8::utf16to8(str.begin(), str.end(), back_inserter(ustr));
}
catch (const utf8::exception& e) {
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << std::string("utf8cpp encoding exception: ") + (char*)e.what();
//TODO
}
@@ -978,7 +978,7 @@ wstring toUTF16(string str) //convert as much as possible
utf8::utf8to16(tmpstr.begin(), tmpstr.end(), back_inserter(ustr));
}
catch (const utf8::exception& e) {
- if (globals.bDebugLog)
+ if (globals.debuglog)
globals.debuglog << std::string("utf8cpp decoding exception: ") + (char*)e.what();
//TODO
}
@@ -1020,26 +1020,6 @@ void send_encrypted_msgs_thread(void *param)
}
}
-int handleEnum(const char *szSetting, void *lParam)
-{
- if (!*(bool*)lParam && szSetting[0] && StriStr(szSetting, "tabsrmm")) {
- bool f = false, *found = (bool*)lParam;
- f = !db_get_b(0, "PluginDisable", szSetting, 0);
- if (f)
- *found = f;
- }
- return 0;
-}
-
-bool isTabsrmmUsed()
-{
- bool found = false;
- if (db_enum_settings(NULL, handleEnum, "PluginDisable", &found) == -1)
- return false;
-
- return found;
-}
-
void ExportGpGKeysFunc(int type)
{
ptrW p(GetFilePath(L"Choose file to export keys", L"*", L"Any file", true));
diff --git a/plugins/New_GPG/src/utilities.h b/plugins/New_GPG/src/utilities.h
index e2737b3da3..8107076040 100755
--- a/plugins/New_GPG/src/utilities.h
+++ b/plugins/New_GPG/src/utilities.h
@@ -29,10 +29,12 @@ void send_encrypted_msgs_thread(void*);
int ComboBoxAddStringUtf(HWND hCombo, const wchar_t *szString, DWORD data);
bool isContactSecured(MCONTACT hContact);
bool isContactHaveKey(MCONTACT hContact);
-bool isTabsrmmUsed();
bool isGPGKeyExist();
bool isGPGValid();
+
void ExportGpGKeysFunc(int type);
+void ImportKey(MCONTACT hContact, std::wstring new_key);
+
const bool StriStr(const char *str, const char *substr);
string toUTF8(wstring str);
wstring toUTF16(string str);
diff --git a/plugins/New_GPG/src/version.h b/plugins/New_GPG/src/version.h
index 345aae4638..ef5e99d8e3 100755
--- a/plugins/New_GPG/src/version.h
+++ b/plugins/New_GPG/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 2
#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>