summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-03-18 15:56:27 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-03-18 15:56:27 +0300
commit5f7e5caff72b4ce876c70b4ce03ff3b4c7bc6528 (patch)
tree739f255f2647ea2b7a8803e802ffd496d519ea04 /plugins
parent4be051a155c0fbc47c1e0eab75da6b4ba8bb2327 (diff)
NewGPG: options implemented using CMOption
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/New_GPG/src/globals.h5
-rwxr-xr-xplugins/New_GPG/src/init.cpp17
-rwxr-xr-xplugins/New_GPG/src/messages.cpp10
-rwxr-xr-xplugins/New_GPG/src/options.cpp30
-rwxr-xr-xplugins/New_GPG/src/stdafx.h2
-rwxr-xr-xplugins/New_GPG/src/ui.cpp15
-rwxr-xr-xplugins/New_GPG/src/utilities.cpp12
7 files changed, 41 insertions, 50 deletions
diff --git a/plugins/New_GPG/src/globals.h b/plugins/New_GPG/src/globals.h
index 113fbcd76a..1bb0087629 100755
--- a/plugins/New_GPG/src/globals.h
+++ b/plugins/New_GPG/src/globals.h
@@ -19,7 +19,7 @@
struct globals_s
{
- bool bAppendTags = false, bDebugLog = false, bJabberAPI = false, bPresenceSigning = false, bFileTransfers = false, bSameAction = false, bAutoExchange = false, bStripTags = false, tabsrmm_used = false, bDecryptFiles = false;;
+ bool bAppendTags = false, bDebugLog = false, bStripTags = false, tabsrmm_used = false, bDecryptFiles = false;
CMStringW wszInopentag, wszInclosetag, wszOutopentag, wszOutclosetag, wszPassword;
wchar_t key_id_global[17] = { 0 };
list <JabberAccount*> Accounts;
@@ -31,9 +31,6 @@ struct globals_s
bool gpg_valid = false, gpg_keyexist = false;
std::map<MCONTACT, contact_data> hcontact_data;
bool _terminate;
-
- int item_num; //TODO: get rid of this
-
};
extern globals_s globals;
diff --git a/plugins/New_GPG/src/init.cpp b/plugins/New_GPG/src/init.cpp
index eedda9a3c1..479edbd329 100755
--- a/plugins/New_GPG/src/init.cpp
+++ b/plugins/New_GPG/src/init.cpp
@@ -51,7 +51,12 @@ PLUGININFOEX pluginInfoEx = {
};
CMPlugin::CMPlugin() :
- PLUGIN<CMPlugin>(MODULENAME, pluginInfoEx)
+ PLUGIN<CMPlugin>(MODULENAME, pluginInfoEx),
+ bJabberAPI(MODULENAME, "bJabberAPI", true),
+ bSameAction(MODULENAME, "bSameAction", false),
+ bAutoExchange(MODULENAME, "bAutoExchange", false),
+ bFileTransfers(MODULENAME, "bFileTransfers", false),
+ bPresenceSigning(MODULENAME, "bPresenceSigning", false)
{
}
@@ -77,13 +82,7 @@ void init_vars()
globals.wszOutopentag = g_plugin.getMStringW("szOutOpenTag", L"<GPGenc>");
globals.wszOutclosetag = g_plugin.getMStringW("szOutCloseTag", L"</GPGenc>");
globals.bDebugLog = g_plugin.getBool("bDebugLog", 0);
- globals.bAutoExchange = g_plugin.getBool("bAutoExchange", 0);
- globals.bSameAction = g_plugin.getBool("bSameAction", 0);
globals.wszPassword = g_plugin.getMStringW("szKeyPassword");
- globals.debuglog.init();
- globals.bJabberAPI = g_plugin.getBool("bJabberAPI", true);
- globals.bPresenceSigning = g_plugin.getBool("bPresenceSigning", 0);
- globals.bFileTransfers = g_plugin.getBool("bFileTransfers", 0);
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);
@@ -100,6 +99,8 @@ void init_vars()
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();
}
static int OnModulesLoaded(WPARAM, LPARAM)
@@ -121,7 +122,7 @@ static int OnModulesLoaded(WPARAM, LPARAM)
sid.szTooltip.a = LPGEN("GPG Turn on encryption");
Srmm_AddIcon(&sid, &g_plugin);
- if (globals.bJabberAPI) {
+ if (g_plugin.bJabberAPI) {
GetJabberInterface(0, 0);
HookEvent(ME_PROTO_ACCLISTCHANGED, GetJabberInterface);
}
diff --git a/plugins/New_GPG/src/messages.cpp b/plugins/New_GPG/src/messages.cpp
index a8520d510b..8d29249403 100755
--- a/plugins/New_GPG/src/messages.cpp
+++ b/plugins/New_GPG/src/messages.cpp
@@ -373,7 +373,7 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l)
}
wstring str = toUTF16(msg);
size_t s1, s2;
- if (globals.bAutoExchange && (str.find(L"-----PGP KEY RESPONSE-----") != wstring::npos)) {
+ if (g_plugin.bAutoExchange && (str.find(L"-----PGP KEY RESPONSE-----") != wstring::npos)) {
if (globals.bDebugLog)
globals.debuglog << "info(autoexchange): parsing key response:" + toUTF8(Clist_GetContactDisplayName(ccs->hContact));
s2 = str.find(L"-----END PGP PUBLIC KEY BLOCK-----");
@@ -509,7 +509,7 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l)
return 0;
}
- if (globals.bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && globals.gpg_valid && globals.gpg_keyexist) {
+ if (g_plugin.bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && globals.gpg_valid && globals.gpg_keyexist) {
if (globals.bDebugLog)
globals.debuglog << "info(autoexchange): received key request from: " + toUTF8(Clist_GetContactDisplayName(ccs->hContact));
@@ -527,7 +527,7 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l)
}
return 0;
}
- else if (!isContactHaveKey(ccs->hContact) && globals.bAutoExchange && globals.gpg_valid && globals.gpg_keyexist) {
+ else if (!isContactHaveKey(ccs->hContact) && g_plugin.bAutoExchange && globals.gpg_valid && globals.gpg_keyexist) {
char *proto = Proto_GetBaseAccountName(ccs->hContact);
ptrA jid(db_get_utfa(ccs->hContact, proto, "jid", ""));
if (jid[0]) {
@@ -771,7 +771,7 @@ int HookSendMsg(WPARAM w, LPARAM l)
globals.debuglog << "info(send handler): block pgp message event, name: " + toUTF8(Clist_GetContactDisplayName(hContact));
return 1;
}
- if (globals.bAutoExchange && (strstr((char*)dbei->pBlob, "-----PGP KEY RESPONSE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----"))) ///do not show service data in history
+ 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)
globals.debuglog << "info(send handler): block pgp key request/response event, name: " + toUTF8(Clist_GetContactDisplayName(hContact));
@@ -786,7 +786,7 @@ int HookSendMsg(WPARAM w, LPARAM l)
if (globals.bDebugLog)
globals.debuglog << "info: contact have not key, name: " + toUTF8(Clist_GetContactDisplayName(hContact));
- if (globals.bAutoExchange && !strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----") && !strstr((char*)dbei->pBlob, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && globals.gpg_valid) {
+ 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)
globals.debuglog << "info: checking for autoexchange possibility, name: " + toUTF8(Clist_GetContactDisplayName(hContact));
diff --git a/plugins/New_GPG/src/options.cpp b/plugins/New_GPG/src/options.cpp
index fe924e710a..c76a775406 100755
--- a/plugins/New_GPG/src/options.cpp
+++ b/plugins/New_GPG/src/options.cpp
@@ -27,6 +27,8 @@ static class COptGpgMainDlg *g_pMainDlg;
class COptGpgMainDlg : public CDlgBase
{
+ bool old_bFileTransfers = g_plugin.bFileTransfers;
+
CCtrlListView list_USERLIST;
CCtrlData lbl_CURRENT_KEY;
CCtrlEdit edit_LOG_FILE_EDIT;
@@ -48,6 +50,10 @@ public:
check_JABBER_API.OnChange = Callback(this, &COptGpgMainDlg::onChange_JABBER_API);
list_USERLIST.OnItemChanged = Callback(this, &COptGpgMainDlg::onItemChanged_USERLIST);
+
+ CreateLink(check_JABBER_API, g_plugin.bJabberAPI);
+ CreateLink(check_AUTO_EXCHANGE, g_plugin.bAutoExchange);
+ CreateLink(check_FILE_TRANSFERS, g_plugin.bFileTransfers);
}
bool OnInitDialog() override
@@ -95,7 +101,7 @@ public:
check_DEBUG_LOG.SetState(g_plugin.getByte("bDebugLog", 0));
check_JABBER_API.Enable();
- check_AUTO_EXCHANGE.Enable(globals.bJabberAPI);
+ check_AUTO_EXCHANGE.Enable(g_plugin.bJabberAPI);
CMStringW keyinfo = TranslateT("Default private key ID");
keyinfo += L": ";
@@ -120,15 +126,9 @@ public:
g_plugin.setByte("bDebugLog", globals.bDebugLog = check_DEBUG_LOG.GetState());
globals.debuglog.init();
- g_plugin.setByte("bJabberAPI", globals.bJabberAPI = check_JABBER_API.GetState());
+ if (g_plugin.bFileTransfers != old_bFileTransfers)
+ g_plugin.bSameAction = false;
- bool old_bFileTransfers = g_plugin.getByte("bFileTransfers", 0) != 0;
- g_plugin.setByte("bFileTransfers", globals.bFileTransfers = check_FILE_TRANSFERS.GetState());
- if (globals.bFileTransfers != old_bFileTransfers) {
- g_plugin.setByte("bSameAction", 0);
- globals.bSameAction = false;
- }
- g_plugin.setByte("bAutoExchange", globals.bAutoExchange = check_AUTO_EXCHANGE.GetState());
g_plugin.setWString("szLogFilePath", ptrW(edit_LOG_FILE_EDIT.GetText()));
return true;
}
@@ -496,18 +496,13 @@ public:
{
btn_EXPORT.OnClick = Callback(this, &COptGpgAdvDlg::onClick_EXPORT);
btn_IMPORT.OnClick = Callback(this, &COptGpgAdvDlg::onClick_IMPORT);
- }
- bool OnInitDialog() override
- {
- check_PRESCENSE_SUBSCRIPTION.SetState(g_plugin.getByte("bPresenceSigning", 0));
- check_PRESCENSE_SUBSCRIPTION.Enable(globals.bJabberAPI);
- return true;
+ CreateLink(check_PRESCENSE_SUBSCRIPTION, g_plugin.bPresenceSigning);
}
- bool OnApply() override
+ bool OnInitDialog() override
{
- g_plugin.setByte("bPresenceSigning", globals.bPresenceSigning = check_PRESCENSE_SUBSCRIPTION.GetState());
+ check_PRESCENSE_SUBSCRIPTION.Enable(g_plugin.bJabberAPI);
return true;
}
@@ -524,7 +519,6 @@ public:
}
};
-
CCtrlEdit *edit_p_PubKeyEdit = nullptr;
static LRESULT CALLBACK editctrl_ctrl_a(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
diff --git a/plugins/New_GPG/src/stdafx.h b/plugins/New_GPG/src/stdafx.h
index 0b0d2c2694..b3dfcfe3f6 100755
--- a/plugins/New_GPG/src/stdafx.h
+++ b/plugins/New_GPG/src/stdafx.h
@@ -72,6 +72,8 @@ using std::fstream;
struct CMPlugin : public PLUGIN<CMPlugin>
{
+ CMOption<bool> bJabberAPI, bPresenceSigning, bFileTransfers, bAutoExchange, bSameAction;
+
CMPlugin();
int Load() override;
diff --git a/plugins/New_GPG/src/ui.cpp b/plugins/New_GPG/src/ui.cpp
index f3fcda137d..a09a973a1c 100755
--- a/plugins/New_GPG/src/ui.cpp
+++ b/plugins/New_GPG/src/ui.cpp
@@ -36,10 +36,9 @@ CDlgEncryptedFileMsgBox::CDlgEncryptedFileMsgBox() :
void CDlgEncryptedFileMsgBox::onClick_IGNORE(CCtrlButton*)
{
- if (chk_REMEMBER.GetState()) {
- g_plugin.setByte("bSameAction", 1);
- globals.bSameAction = true;
- }
+ if (chk_REMEMBER.GetState())
+ g_plugin.bSameAction = true;
+
this->Close();
}
@@ -47,10 +46,8 @@ void CDlgEncryptedFileMsgBox::onClick_DECRYPT(CCtrlButton*)
{
globals.bDecryptFiles = true;
if (chk_REMEMBER.GetState()) {
- g_plugin.setByte("bFileTransfers", 1);
- globals.bFileTransfers = true;
- g_plugin.setByte("bSameAction", 0);
- globals.bSameAction = false;
+ g_plugin.bFileTransfers = true;
+ g_plugin.bSameAction = false;
}
this->Close();
}
@@ -782,7 +779,7 @@ void CDlgGpgBinOpts::onClick_GENERATE_RANDOM(CCtrlButton*)
gpg_save_paths(edit_BIN_PATH.GetText(), edit_HOME_DIR.GetText());
globals.gpg_valid = true;
if (gpg_use_new_random_key(nullptr)) {
- g_plugin.setByte("bAutoExchange", globals.bAutoExchange = chk_AUTO_EXCHANGE.GetState());
+ g_plugin.bAutoExchange = chk_AUTO_EXCHANGE.GetState();
globals.gpg_valid = true;
g_plugin.setByte("FirstRun", 0);
this->Close();
diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp
index 899095e3b2..f8147f5894 100755
--- a/plugins/New_GPG/src/utilities.cpp
+++ b/plugins/New_GPG/src/utilities.cpp
@@ -232,11 +232,11 @@ int onProtoAck(WPARAM, LPARAM l)
}
if (wcsstr(filename, L".gpg")) { //decrypt it
//process encrypted file
- if (!globals.bFileTransfers && !globals.bSameAction) {
+ if (!g_plugin.bFileTransfers && !g_plugin.bSameAction) {
void ShowEncryptedFileMsgBox();
ShowEncryptedFileMsgBox();
}
- if (!globals.bFileTransfers && globals.bSameAction)
+ if (!g_plugin.bFileTransfers && g_plugin.bSameAction)
return 0;
if (!globals.bDecryptFiles)
return 0;
@@ -405,7 +405,7 @@ std::wstring encrypt_file(MCONTACT hContact, wchar_t *filename)
INT_PTR onSendFile(WPARAM w, LPARAM l)
{
CCSDATA *ccs = (CCSDATA*)l;
- if (!globals.bFileTransfers)
+ if (!g_plugin.bFileTransfers)
return Proto_ChainSend(w, ccs);
if (isContactSecured(ccs->hContact)) {
@@ -558,7 +558,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, TiXmlElement *node,
continue;
// TODO: make following block more readable
- if (globals.bPresenceSigning && nodename && strstr(nodename, "status")) {
+ if (g_plugin.bPresenceSigning && nodename && strstr(nodename, "status")) {
string path_out = ptrA(g_plugin.getUStringA("szHomePath", ""));
string file = get_random(10);
path_out += "\\tmp\\";
@@ -784,11 +784,11 @@ void AddHandlers()
if (p->getPresenceHandler() == INVALID_HANDLE_VALUE)
p->setPresenceHandler(p->getJabberInterface()->AddPresenceHandler((JABBER_HANDLER_FUNC)PresenceHandler));
- if (globals.bAutoExchange) {
+ if (g_plugin.bAutoExchange) {
p->getJabberInterface()->RegisterFeature("GPG_Key_Auto_Exchange:0", "Indicates that gpg installed and configured to public key auto exchange (currently implemented in new_gpg plugin for Miranda IM and Miranda NG)");
p->getJabberInterface()->AddFeatures("GPG_Key_Auto_Exchange:0\0\0");
}
- if (globals.bFileTransfers) {
+ if (g_plugin.bFileTransfers) {
p->getJabberInterface()->RegisterFeature("GPG_Encrypted_FileTransfers:0", "Indicates that gpg installed and configured to encrypt files (currently implemented in new_gpg plugin for Miranda IM and Miranda NG)");
p->getJabberInterface()->AddFeatures("GPG_Encrypted_FileTransfers:0\0\0");
}