diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2017-12-08 04:42:36 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2017-12-08 05:05:53 +0300 |
commit | b3d3b95a16be5b1785681f0f6fdc3bcdb967a42e (patch) | |
tree | d507c610892797e467f8a0b1fc5d8b088b1e6bee | |
parent | 75f678d3a4f23536e2170582dabd740eb195fa17 (diff) |
new_gpg: get rid of "extern chaos"
- moving ui related code to separated file, split definition and implementation of ui
-rwxr-xr-x[-rw-r--r--] | plugins/New_GPG/src/globals.h | 35 | ||||
-rwxr-xr-x | plugins/New_GPG/src/gpg_wrapper.cpp | 38 | ||||
-rwxr-xr-x[-rw-r--r--] | plugins/New_GPG/src/icons.cpp | 8 | ||||
-rwxr-xr-x[-rw-r--r--] | plugins/New_GPG/src/init.cpp | 105 | ||||
-rwxr-xr-x[-rw-r--r--] | plugins/New_GPG/src/log.cpp | 12 | ||||
-rwxr-xr-x | plugins/New_GPG/src/main.cpp | 133 | ||||
-rwxr-xr-x[-rw-r--r--] | plugins/New_GPG/src/main.h | 3 | ||||
-rwxr-xr-x | plugins/New_GPG/src/messages.cpp | 281 | ||||
-rwxr-xr-x | plugins/New_GPG/src/options.cpp | 89 | ||||
-rwxr-xr-x | plugins/New_GPG/src/options.h | 22 | ||||
-rwxr-xr-x | plugins/New_GPG/src/srmm.cpp | 4 | ||||
-rwxr-xr-x | plugins/New_GPG/src/stdafx.h | 4 | ||||
-rwxr-xr-x | plugins/New_GPG/src/ui.cpp | 167 | ||||
-rwxr-xr-x | plugins/New_GPG/src/ui.h | 63 | ||||
-rwxr-xr-x | plugins/New_GPG/src/utilities.cpp | 368 | ||||
-rwxr-xr-x[-rw-r--r--] | plugins/New_GPG/src/utilities.h | 4 |
16 files changed, 703 insertions, 633 deletions
diff --git a/plugins/New_GPG/src/globals.h b/plugins/New_GPG/src/globals.h index cc631be568..0434802bea 100644..100755 --- a/plugins/New_GPG/src/globals.h +++ b/plugins/New_GPG/src/globals.h @@ -16,15 +16,32 @@ #ifndef GLOBALS_H #define GLOBALS_H -extern bool bAppendTags, bPresenceSigning, bStripTags, gpg_valid, gpg_keyexist, tabsrmm_used, bSameAction, bFileTransfers, bDebugLog; -extern wchar_t *inopentag, *inclosetag, *outopentag, *outclosetag; -extern logtofile debuglog; -extern map<int, MCONTACT> user_data; -extern int item_num; +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;; + wchar_t *inopentag = nullptr, *inclosetag = nullptr, *outopentag = nullptr, *outclosetag = nullptr, *password = nullptr; + wchar_t key_id_global[17] = { 0 }; + list <JabberAccount*> Accounts; + HINSTANCE hInst; + 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; + map<int, MCONTACT> user_data; + bool _terminate; + wstring new_key; + MCONTACT new_key_hcnt; + boost::mutex new_key_hcnt_mutex; + + int item_num; //TODO: get rid of this + +}; + +extern globals_s globals; + -extern bool _terminate; -extern wstring new_key; -extern MCONTACT new_key_hcnt; -extern boost::mutex new_key_hcnt_mutex; #endif diff --git a/plugins/New_GPG/src/gpg_wrapper.cpp b/plugins/New_GPG/src/gpg_wrapper.cpp index 38e06f2254..30d9fc0264 100755 --- a/plugins/New_GPG/src/gpg_wrapper.cpp +++ b/plugins/New_GPG/src/gpg_wrapper.cpp @@ -20,9 +20,8 @@ pxResult pxExecute(std::vector<std::wstring> &aargv, string *aoutput, LPDWORD aexitcode, pxResult *result, boost::process::child *_child) { - if(!gpg_valid) + if(!globals.gpg_valid) return pxNotConfigured; - extern logtofile debuglog; wchar_t *bin_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", L""); @@ -30,8 +29,8 @@ pxResult pxExecute(std::vector<std::wstring> &aargv, string *aoutput, LPDWORD ae if(!boost::filesystem::exists(bin_path)) { mir_free(bin_path); - if(bDebugLog) - debuglog<<std::string(time_str()+": GPG executable not found"); + if(globals.bDebugLog) + globals.debuglog<<std::string(time_str()+": GPG executable not found"); *result = pxNotFound; return pxNotFound; } @@ -60,7 +59,7 @@ pxResult pxExecute(std::vector<std::wstring> &aargv, string *aoutput, LPDWORD ae argv.push_back(L"-z9"); argv.insert(argv.end(), aargv.begin(), aargv.end()); - if(bDebugLog) + if(globals.bDebugLog) { std::wstring args; for(unsigned int i = 0; i < argv.size(); ++i) @@ -69,7 +68,7 @@ pxResult pxExecute(std::vector<std::wstring> &aargv, string *aoutput, LPDWORD ae args += L" "; } args.erase(args.size()-1, 1); - debuglog<<std::string(time_str()+": gpg in: "+toUTF8(args)); + globals.debuglog<<std::string(time_str()+": gpg in: "+toUTF8(args)); } @@ -104,8 +103,8 @@ pxResult pxExecute(std::vector<std::wstring> &aargv, string *aoutput, LPDWORD ae } catch(const std::exception &e) { - if(bDebugLog) - debuglog<<std::string(time_str()+": failed to read from stream with error: " + e.what() + "\n\tSuccesfully read : " + *aoutput); + if(globals.bDebugLog) + globals.debuglog<<std::string(time_str()+": failed to read from stream with error: " + e.what() + "\n\tSuccesfully read : " + *aoutput); } file_descriptor_source source2(perr.source, close_handle); @@ -122,14 +121,14 @@ pxResult pxExecute(std::vector<std::wstring> &aargv, string *aoutput, LPDWORD ae } catch(const std::exception &e) { - if(bDebugLog) - debuglog<<std::string(time_str()+": failed to read from stream with error: " + e.what() + "\n\tSuccesfully read : " + *aoutput); + if(globals.bDebugLog) + globals.debuglog<<std::string(time_str()+": failed to read from stream with error: " + e.what() + "\n\tSuccesfully read : " + *aoutput); } fix_line_term(*aoutput); - if(bDebugLog) - debuglog<<std::string(time_str()+": gpg out: "+*aoutput); + if(globals.bDebugLog) + globals.debuglog<<std::string(time_str()+": gpg out: "+*aoutput); auto ec = wait_for_exit(*c); delete c; @@ -139,8 +138,8 @@ pxResult pxExecute(std::vector<std::wstring> &aargv, string *aoutput, LPDWORD ae if(*aexitcode) { - if(bDebugLog) - debuglog<<std::string(time_str()+": warning: wrong gpg exit status, gpg output: "+*aoutput); + if(globals.bDebugLog) + globals.debuglog<<std::string(time_str()+": warning: wrong gpg exit status, gpg output: "+*aoutput); return pxSuccessExitCodeInvalid; } @@ -163,25 +162,24 @@ bool gpg_launcher(gpg_execution_params ¶ms, boost::posix_time::time_duration delete gpg_thread; if(params.child) boost::process::terminate(*(params.child)); - if(bDebugLog) - debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); + if(globals.bDebugLog) + globals.debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); } return ret; } pxResult pxExecute_passwd_change(std::vector<std::wstring> &aargv, pxResult *result, boost::process::child *_child) { - if(!gpg_valid) + if(!globals.gpg_valid) return pxNotConfigured; - extern logtofile debuglog; wchar_t *bin_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", L""); { if(!boost::filesystem::exists(bin_path)) { mir_free(bin_path); - if(bDebugLog) - debuglog<<std::string(time_str()+": GPG executable not found"); + if(globals.bDebugLog) + globals.debuglog<<std::string(time_str()+": GPG executable not found"); *result = pxNotFound; return pxNotFound; } diff --git a/plugins/New_GPG/src/icons.cpp b/plugins/New_GPG/src/icons.cpp index c78075418e..f868cb705b 100644..100755 --- a/plugins/New_GPG/src/icons.cpp +++ b/plugins/New_GPG/src/icons.cpp @@ -16,7 +16,6 @@ #include "stdafx.h" -extern HINSTANCE hInst; static IconItem iconList[] = { @@ -26,7 +25,7 @@ static IconItem iconList[] = void InitIconLib() { - Icon_Register(hInst, szGPGModuleName, iconList, _countof(iconList)); + Icon_Register(globals.hInst, szGPGModuleName, iconList, _countof(iconList)); } HANDLE IconLibHookIconsChanged(MIRANDAHOOK hook) @@ -37,12 +36,11 @@ HANDLE IconLibHookIconsChanged(MIRANDAHOOK hook) void setClistIcon(MCONTACT hContact) { bool enabled = isContactSecured(hContact); - extern HANDLE g_hCLIcon; MCONTACT hMC = db_mc_tryMeta(hContact); const char *szIconId = (enabled) ? "secured" : nullptr; - ExtraIcon_SetIconByName(g_hCLIcon, hContact, szIconId); + ExtraIcon_SetIconByName(globals.g_hCLIcon, hContact, szIconId); if(hMC != hContact) - ExtraIcon_SetIconByName(g_hCLIcon, hMC, szIconId); + ExtraIcon_SetIconByName(globals.g_hCLIcon, hMC, szIconId); } void setSrmmIcon(MCONTACT h) diff --git a/plugins/New_GPG/src/init.cpp b/plugins/New_GPG/src/init.cpp index 2d2bbe76e2..fc83d06c14 100644..100755 --- a/plugins/New_GPG/src/init.cpp +++ b/plugins/New_GPG/src/init.cpp @@ -17,22 +17,9 @@ #include "stdafx.h" //global variables -bool bAppendTags = false, bDebugLog = false, bJabberAPI = false, bPresenceSigning = false, bFileTransfers = false, bSameAction = false, bAutoExchange = false, bStripTags = false, tabsrmm_used = false; -wchar_t *inopentag = nullptr, *inclosetag = nullptr, *outopentag = nullptr, *outclosetag = nullptr, *password = nullptr; - -list <JabberAccount*> Accounts; - CLIST_INTERFACE *pcli; -HINSTANCE hInst; -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}; - int hLangpack = 0; -logtofile debuglog; -bool gpg_valid = false, gpg_keyexist = false; -std::map<MCONTACT, contact_data> hcontact_data; + PLUGININFOEX pluginInfo={ sizeof(PLUGININFOEX), @@ -50,7 +37,7 @@ PLUGININFOEX pluginInfo={ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) { - hInst = hinstDLL; + globals.hInst = hinstDLL; return TRUE; } @@ -72,36 +59,36 @@ void InitIconLib(); void init_vars() { - bAppendTags = db_get_b(NULL, szGPGModuleName, "bAppendTags", 0) != 0; - bStripTags = db_get_b(NULL, szGPGModuleName, "bStripTags", 0) != 0; - inopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", L"<GPGdec>"); - inclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", L"</GPGdec>"); - outopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", L"<GPGenc>"); - outclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", L"</GPGenc>"); - bDebugLog = db_get_b(NULL, szGPGModuleName, "bDebugLog", 0) != 0; - bAutoExchange = db_get_b(NULL, szGPGModuleName, "bAutoExchange", 0) != 0; - bSameAction = db_get_b(NULL, szGPGModuleName, "bSameAction", 0) != 0; - password = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", L""); - debuglog.init(); - bJabberAPI = db_get_b(NULL, szGPGModuleName, "bJabberAPI", true) != 0; - bPresenceSigning = db_get_b(NULL, szGPGModuleName, "bPresenceSigning", 0) != 0; - bFileTransfers = db_get_b(NULL, szGPGModuleName, "bFileTransfers", 0) != 0; - firstrun_rect.left = db_get_dw(NULL, szGPGModuleName, "FirstrunWindowX", 0); - firstrun_rect.top = db_get_dw(NULL, szGPGModuleName, "FirstrunWindowY", 0); - key_password_rect.left = db_get_dw(NULL, szGPGModuleName, "PasswordWindowX", 0); - key_password_rect.top = db_get_dw(NULL, szGPGModuleName, "PasswordWindowY", 0); - key_gen_rect.left = db_get_dw(NULL, szGPGModuleName, "KeyGenWindowX", 0); - key_gen_rect.top = db_get_dw(NULL, szGPGModuleName, "KeyGenWindowY", 0); - load_key_rect.left = db_get_dw(NULL, szGPGModuleName, "LoadKeyWindowX", 0); - load_key_rect.top = db_get_dw(NULL, szGPGModuleName, "LoadKeyWindowY", 0); - import_key_rect.left = db_get_dw(NULL, szGPGModuleName, "ImportKeyWindowX", 0); - import_key_rect.top = db_get_dw(NULL, szGPGModuleName, "ImportKeyWindowY", 0); - new_key_rect.left = db_get_dw(NULL, szGPGModuleName, "NewKeyWindowX", 0); - new_key_rect.top = db_get_dw(NULL, szGPGModuleName, "NewKeyWindowY", 0); - load_existing_key_rect.left = db_get_dw(NULL, szGPGModuleName, "LoadExistingKeyWindowX", 0); - load_existing_key_rect.top = db_get_dw(NULL, szGPGModuleName, "LoadExistingKeyWindowY", 0); - tabsrmm_used = isTabsrmmUsed(); - bold_font = CreateFont(14, 0, 0, 0, 600, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, L"Arial"); + globals.bAppendTags = db_get_b(NULL, szGPGModuleName, "bAppendTags", 0) != 0; + globals.bStripTags = db_get_b(NULL, szGPGModuleName, "bStripTags", 0) != 0; + globals.inopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", L"<GPGdec>"); + globals.inclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", L"</GPGdec>"); + globals.outopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", L"<GPGenc>"); + globals.outclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", L"</GPGenc>"); + globals.bDebugLog = db_get_b(NULL, szGPGModuleName, "bDebugLog", 0) != 0; + globals.bAutoExchange = db_get_b(NULL, szGPGModuleName, "bAutoExchange", 0) != 0; + globals.bSameAction = db_get_b(NULL, szGPGModuleName, "bSameAction", 0) != 0; + globals.password = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", L""); + globals.debuglog.init(); + globals.bJabberAPI = db_get_b(NULL, szGPGModuleName, "bJabberAPI", true) != 0; + globals.bPresenceSigning = db_get_b(NULL, szGPGModuleName, "bPresenceSigning", 0) != 0; + globals.bFileTransfers = db_get_b(NULL, szGPGModuleName, "bFileTransfers", 0) != 0; + globals.firstrun_rect.left = db_get_dw(NULL, szGPGModuleName, "FirstrunWindowX", 0); + globals.firstrun_rect.top = db_get_dw(NULL, szGPGModuleName, "FirstrunWindowY", 0); + globals.key_password_rect.left = db_get_dw(NULL, szGPGModuleName, "PasswordWindowX", 0); + globals.key_password_rect.top = db_get_dw(NULL, szGPGModuleName, "PasswordWindowY", 0); + globals.key_gen_rect.left = db_get_dw(NULL, szGPGModuleName, "KeyGenWindowX", 0); + globals.key_gen_rect.top = db_get_dw(NULL, szGPGModuleName, "KeyGenWindowY", 0); + globals.load_key_rect.left = db_get_dw(NULL, szGPGModuleName, "LoadKeyWindowX", 0); + globals.load_key_rect.top = db_get_dw(NULL, szGPGModuleName, "LoadKeyWindowY", 0); + globals.import_key_rect.left = db_get_dw(NULL, szGPGModuleName, "ImportKeyWindowX", 0); + globals.import_key_rect.top = db_get_dw(NULL, szGPGModuleName, "ImportKeyWindowY", 0); + globals.new_key_rect.left = db_get_dw(NULL, szGPGModuleName, "NewKeyWindowX", 0); + globals.new_key_rect.top = db_get_dw(NULL, szGPGModuleName, "NewKeyWindowY", 0); + globals.load_existing_key_rect.left = db_get_dw(NULL, szGPGModuleName, "LoadExistingKeyWindowX", 0); + globals.load_existing_key_rect.top = db_get_dw(NULL, szGPGModuleName, "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"); } static int OnModulesLoaded(WPARAM, LPARAM) @@ -137,12 +124,12 @@ static int OnModulesLoaded(WPARAM, LPARAM) sid.szTooltip = LPGEN("GPG Turn on encryption"); Srmm_AddIcon(&sid); - if(bJabberAPI) + if(globals.bJabberAPI) GetJabberInterface(0,0); HookEvent(ME_OPT_INITIALISE, GpgOptInit); HookEvent(ME_DB_EVENT_FILTER_ADD, HookSendMsg); - if(bJabberAPI) + if(globals.bJabberAPI) HookEvent(ME_PROTO_ACCLISTCHANGED, GetJabberInterface); HookEvent(ME_PROTO_ACK, onProtoAck); @@ -187,39 +174,39 @@ extern "C" int __declspec(dllexport) Load() mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA); mi.name.w = LPGENW("Load public GPG key"); mi.pszService = "/LoadPubKey"; - hLoadPubKey = Menu_AddContactMenuItem(&mi); + globals.hLoadPubKey = Menu_AddContactMenuItem(&mi); 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.pszService = "/ToggleEncryption"; - hToggleEncryption = Menu_AddContactMenuItem(&mi); + globals.hToggleEncryption = Menu_AddContactMenuItem(&mi); 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.pszService = "/SendKey"; - hSendKey = Menu_AddContactMenuItem(&mi); + globals.hSendKey = Menu_AddContactMenuItem(&mi); 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.pszService = "/ExportGPGKeys"; - hExportGpgKeys = Menu_AddMainMenuItem(&mi); + globals.hExportGpgKeys = Menu_AddMainMenuItem(&mi); SET_UID(mi, 0x627fcfc1, 0x4e60, 0x4428, 0xaf, 0x96, 0x11, 0x42, 0x24, 0xeb, 0x7, 0xea); mi.position = -0x7FFFFFFF; mi.hIcolibItem = Skin_LoadIcon(SKINICON_OTHER_MIRANDA); mi.name.w = LPGENW("Import GPG Public keys"); mi.pszService = "/ImportGPGKeys"; - hImportGpgKeys = Menu_AddMainMenuItem(&mi); + globals.hImportGpgKeys = Menu_AddMainMenuItem(&mi); InitIconLib(); - g_hCLIcon = ExtraIcon_RegisterCallback(szGPGModuleName, Translate("GPG encryption status"), "secured", onExtraImageListRebuilding, onExtraImageApplying); + globals.g_hCLIcon = ExtraIcon_RegisterCallback(szGPGModuleName, Translate("GPG encryption status"), "secured", onExtraImageListRebuilding, onExtraImageApplying); return 0; } @@ -232,12 +219,12 @@ extern "C" int __declspec(dllexport) Unload(void) if(!(*p).empty()) boost::filesystem::remove((*p)); } - mir_free(inopentag); - mir_free(inclosetag); - mir_free(outopentag); - mir_free(outclosetag); - if(password) - mir_free(password); + mir_free(globals.inopentag); + mir_free(globals.inclosetag); + mir_free(globals.outopentag); + mir_free(globals.outclosetag); + if(globals.password) + mir_free(globals.password); clean_temp_dir(); return 0; } diff --git a/plugins/New_GPG/src/log.cpp b/plugins/New_GPG/src/log.cpp index bc3dc5047f..c4d0ef7156 100644..100755 --- a/plugins/New_GPG/src/log.cpp +++ b/plugins/New_GPG/src/log.cpp @@ -19,7 +19,7 @@ logtofile& logtofile::operator<<(wchar_t *buf) { - if(_bDebugLog != bDebugLog) + if(_bDebugLog != globals.bDebugLog) init(); log_mutex.lock(); log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate); @@ -31,7 +31,7 @@ logtofile& logtofile::operator<<(wchar_t *buf) } logtofile& logtofile::operator<<(char *buf) { - if(_bDebugLog != bDebugLog) + if(_bDebugLog != globals.bDebugLog) init(); log_mutex.lock(); log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate); @@ -43,7 +43,7 @@ logtofile& logtofile::operator<<(char *buf) } logtofile& logtofile::operator<<(string buf) { - if(_bDebugLog != bDebugLog) + if(_bDebugLog != globals.bDebugLog) init(); log_mutex.lock(); char *tmp = mir_utf8encode(buf.c_str()); @@ -57,7 +57,7 @@ logtofile& logtofile::operator<<(string buf) } logtofile& logtofile::operator<<(wstring buf) { - if(_bDebugLog != bDebugLog) + if(_bDebugLog != globals.bDebugLog) init(); log_mutex.lock(); log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate); @@ -69,13 +69,13 @@ logtofile& logtofile::operator<<(wstring buf) } void logtofile::init() { - if(bDebugLog) + if(globals.bDebugLog) { if(path) mir_free(path); path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", L"C:\\GPGdebug.log"); } - _bDebugLog = bDebugLog; + _bDebugLog = globals.bDebugLog; } logtofile::logtofile() { diff --git a/plugins/New_GPG/src/main.cpp b/plugins/New_GPG/src/main.cpp index 16680cb572..a8404fec3e 100755 --- a/plugins/New_GPG/src/main.cpp +++ b/plugins/New_GPG/src/main.cpp @@ -18,9 +18,6 @@ #pragma comment(lib, "shlwapi.lib") -extern HFONT bold_font; -extern bool bAutoExchange; - void ShowFirstRunDialog(); HWND hwndFirstRun = nullptr, hwndSetDirs = nullptr, hwndNewKey = nullptr, hwndKeyGen = nullptr, hwndSelectExistingKey = nullptr; @@ -35,10 +32,6 @@ BOOL CheckStateStoreDB(HWND hwndDlg, int idCtrl, const char* szSetting) return state; } -wchar_t key_id_global[17] = { 0 }; - -extern HINSTANCE hInst; - bool gpg_validate_paths(wchar_t *gpg_bin_path, wchar_t *gpg_home_path) { wstring tmp = gpg_bin_path; @@ -67,9 +60,10 @@ bool gpg_validate_paths(wchar_t *gpg_bin_path, wchar_t *gpg_home_path) params.out = &out; params.code = &code; params.result = &result; - gpg_valid = true; + bool _gpg_valid = globals.gpg_valid; + globals.gpg_valid = true; gpg_launcher(params); - gpg_valid = false; + globals.gpg_valid = _gpg_valid; //TODO: check this db_unset(NULL, szGPGModuleName, "szGpgBinPath"); string::size_type p1 = out.find("(GnuPG) "); if (p1 != string::npos) { @@ -221,7 +215,7 @@ bool gpg_use_new_random_key(char *account_name = Translate("Default"), wchar_t * class CDlgFirstRun : public CDlgBase { public: - CDlgFirstRun() : CDlgBase(hInst, IDD_FIRST_RUN), + CDlgFirstRun() : CDlgBase(globals.hInst, IDD_FIRST_RUN), list_KEY_LIST(this, IDC_KEY_LIST), btn_COPY_PUBKEY(this, IDC_COPY_PUBKEY), btn_EXPORT_PRIVATE(this, IDC_EXPORT_PRIVATE), btn_CHANGE_PASSWD(this, IDC_CHANGE_PASSWD), btn_GENERATE_RANDOM(this, IDC_GENERATE_RANDOM), btn_GENERATE_KEY(this, IDC_GENERATE_KEY), btn_OTHER(this, IDC_OTHER), btn_DELETE_KEY(this, IDC_DELETE_KEY), btn_OK(this, ID_OK), @@ -244,7 +238,7 @@ public: } virtual void OnInitDialog() override { - SetWindowPos(m_hwnd, nullptr, firstrun_rect.left, firstrun_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); + SetWindowPos(m_hwnd, nullptr, globals.firstrun_rect.left, globals.firstrun_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); SetCaption(TranslateT("Set own key")); btn_COPY_PUBKEY.Disable(); btn_EXPORT_PRIVATE.Disable(); @@ -387,7 +381,7 @@ public: int i = list_KEY_LIST.GetSelectionMark(); if (i == -1) return; - list_KEY_LIST.GetItemText(i, 0, key_id_global, _countof(key_id_global)); + list_KEY_LIST.GetItemText(i, 0, globals.key_id_global, _countof(globals.key_id_global)); //temporary code follows std::vector<std::wstring> cmd; @@ -395,7 +389,7 @@ public: string output; DWORD exitcode; cmd.push_back(L"--edit-key"); - cmd.push_back(key_id_global); + cmd.push_back(globals.key_id_global); cmd.push_back(L"passwd"); gpg_execution_params_pass params(cmd, old_pass, new_pass); pxResult result; @@ -407,15 +401,15 @@ public: gpg_thread.~thread(); if (params.child) boost::process::terminate(*(params.child)); - if (bDebugLog) - debuglog << std::string(time_str() + ": GPG execution timed out, aborted"); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": GPG execution timed out, aborted"); this->Close(); } } void onClick_GENERATE_RANDOM(CCtrlButton*) { - lbl_GENERATING_KEY.SendMsg(WM_SETFONT, (WPARAM)bold_font, TRUE); + lbl_GENERATING_KEY.SendMsg(WM_SETFONT, (WPARAM)globals.bold_font, TRUE); lbl_GENERATING_KEY.SetText(TranslateT("Generating new random key, please wait")); btn_GENERATE_KEY.Disable(); btn_OTHER.Disable(); @@ -434,8 +428,8 @@ public: void onClick_OTHER(CCtrlButton*) { void ShowLoadPublicKeyDialog(bool = false); - item_num = 0; //black magic here - user_data[1] = 0; + globals.item_num = 0; //black magic here + globals.user_data[1] = 0; ShowLoadPublicKeyDialog(true); refresh_key_list(); } @@ -603,8 +597,8 @@ public: delete[] name; } //bAutoExchange = CheckStateStoreDB(hwndDlg, IDC_AUTO_EXCHANGE, "bAutoExchange") != 0; //TODO: check is it just typo, or doing something - gpg_valid = isGPGValid(); - gpg_keyexist = isGPGKeyExist(); + globals.gpg_valid = isGPGValid(); + globals.gpg_keyexist = isGPGKeyExist(); DestroyWindow(m_hwnd); } void onChange_ACCOUNT(CCtrlCombo*) @@ -647,9 +641,9 @@ public: } virtual void OnDestroy() override { - GetWindowRect(m_hwnd, &firstrun_rect); - db_set_dw(NULL, szGPGModuleName, "FirstrunWindowX", firstrun_rect.left); - db_set_dw(NULL, szGPGModuleName, "FirstrunWindowY", firstrun_rect.top); + GetWindowRect(m_hwnd, &globals.firstrun_rect); + db_set_dw(NULL, szGPGModuleName, "FirstrunWindowX", globals.firstrun_rect.left); + db_set_dw(NULL, szGPGModuleName, "FirstrunWindowY", globals.firstrun_rect.top); hwndFirstRun = nullptr; delete this; } @@ -812,7 +806,7 @@ private: class CDlgGpgBinOpts : public CDlgBase { public: - CDlgGpgBinOpts() : CDlgBase(hInst, IDD_BIN_PATH), + CDlgGpgBinOpts() : CDlgBase(globals.hInst, IDD_BIN_PATH), btn_SET_BIN_PATH(this, IDC_SET_BIN_PATH), btn_SET_HOME_DIR(this, IDC_SET_HOME_DIR), btn_OK(this, ID_OK), btn_GENERATE_RANDOM(this, IDC_GENERATE_RANDOM), edit_BIN_PATH(this, IDC_BIN_PATH), edit_HOME_DIR(this, IDC_HOME_DIR), chk_AUTO_EXCHANGE(this, IDC_AUTO_EXCHANGE) @@ -869,9 +863,10 @@ public: params.out = &out; params.code = &code; params.result = &result; - gpg_valid = true; + bool _gpg_valid = globals.gpg_valid; + globals.gpg_valid = true; gpg_launcher(params); - gpg_valid = false; + globals.gpg_valid = _gpg_valid; //TODO: check this db_unset(NULL, szGPGModuleName, "szGpgBinPath"); string::size_type p1 = out.find("(GnuPG) "); if (p1 != string::npos) { @@ -943,7 +938,7 @@ public: if (gpg_validate_paths(edit_BIN_PATH.GetText(), edit_HOME_DIR.GetText())) { gpg_save_paths(edit_BIN_PATH.GetText(), edit_HOME_DIR.GetText()); - gpg_valid = true; + globals.gpg_valid = true; db_set_b(NULL, szGPGModuleName, "FirstRun", 0); this->Hide(); ShowFirstRunDialog(); @@ -955,11 +950,11 @@ public: if (gpg_validate_paths(edit_BIN_PATH.GetText(), edit_HOME_DIR.GetText())) { gpg_save_paths(edit_BIN_PATH.GetText(), edit_HOME_DIR.GetText()); - gpg_valid = true; + globals.gpg_valid = true; if (gpg_use_new_random_key()) { - db_set_b(NULL, szGPGModuleName, "bAutoExchange", bAutoExchange = chk_AUTO_EXCHANGE.GetState()); - gpg_valid = true; + db_set_b(NULL, szGPGModuleName, "bAutoExchange", globals.bAutoExchange = chk_AUTO_EXCHANGE.GetState()); + globals.gpg_valid = true; db_set_b(NULL, szGPGModuleName, "FirstRun", 0); this->Close(); } @@ -981,7 +976,7 @@ private: class CDlgNewKey : public CDlgBase { public: - CDlgNewKey() : CDlgBase(hInst, IDD_NEW_KEY), + CDlgNewKey() : CDlgBase(globals.hInst, IDD_NEW_KEY), lbl_KEY_FROM(this, IDC_KEY_FROM), lbl_MESSAGE(this, IDC_MESSAGE), btn_IMPORT(this, ID_IMPORT), btn_IMPORT_AND_USE(this, IDC_IMPORT_AND_USE), btn_IGNORE_KEY(this, IDC_IGNORE_KEY) { @@ -993,9 +988,9 @@ public: } virtual void OnInitDialog() override { - hContact = new_key_hcnt; + hContact = globals.new_key_hcnt; //new_key_hcnt_mutex.unlock(); - SetWindowPos(m_hwnd, nullptr, new_key_rect.left, new_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); + SetWindowPos(m_hwnd, nullptr, globals.new_key_rect.left, globals.new_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); wchar_t *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", L""); lbl_MESSAGE.SetText(tmp[0] ? 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(db_get_b(hContact, szGPGModuleName, "GPGEncryption", 0)); @@ -1008,9 +1003,9 @@ public: } virtual void OnDestroy() override { - GetWindowRect(m_hwnd, &new_key_rect); - db_set_dw(NULL, szGPGModuleName, "NewKeyWindowX", new_key_rect.left); - db_set_dw(NULL, szGPGModuleName, "NewKeyWindowY", new_key_rect.top); + GetWindowRect(m_hwnd, &globals.new_key_rect); + db_set_dw(NULL, szGPGModuleName, "NewKeyWindowX", globals.new_key_rect.left); + db_set_dw(NULL, szGPGModuleName, "NewKeyWindowY", globals.new_key_rect.top); delete this; } void onClick_IMPORT(CCtrlButton*) @@ -1043,7 +1038,7 @@ private: class CDlgKeyGen : public CDlgBase //TODO: in modal mode window destroying on any button press even without direct "Close" call { public: - CDlgKeyGen() : CDlgBase(hInst, IDD_KEY_GEN), + CDlgKeyGen() : CDlgBase(globals.hInst, IDD_KEY_GEN), combo_KEY_TYPE(this, IDC_KEY_TYPE), edit_KEY_LENGTH(this, IDC_KEY_LENGTH), edit_KEY_PASSWD(this, IDC_KEY_PASSWD), edit_KEY_REAL_NAME(this, IDC_KEY_REAL_NAME), edit_KEY_EMAIL(this, IDC_KEY_EMAIL), edit_KEY_COMMENT(this, IDC_KEY_COMMENT), edit_KEY_EXPIRE_DATE(this, IDC_KEY_EXPIRE_DATE), @@ -1055,7 +1050,7 @@ public: } virtual void OnInitDialog() override { - SetWindowPos(m_hwnd, nullptr, key_gen_rect.left, key_gen_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); + SetWindowPos(m_hwnd, nullptr, globals.key_gen_rect.left, globals.key_gen_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); SetCaption(TranslateT("Key Generation dialog")); combo_KEY_TYPE.AddString(L"RSA"); combo_KEY_TYPE.AddString(L"DSA"); @@ -1206,7 +1201,7 @@ public: params.out = &out; params.code = &code; params.result = &result; - lbl_GENERATING_TEXT.SendMsg(WM_SETFONT, (WPARAM)bold_font, TRUE); + lbl_GENERATING_TEXT.SendMsg(WM_SETFONT, (WPARAM)globals.bold_font, TRUE); lbl_GENERATING_TEXT.SetText(TranslateT("Generating new key, please wait...")); btn_CANCEL.Disable(); btn_OK.Disable(); @@ -1232,9 +1227,9 @@ public: } virtual void OnDestroy() override { - GetWindowRect(m_hwnd, &key_gen_rect); - db_set_dw(NULL, szGPGModuleName, "KeyGenWindowX", key_gen_rect.left); - db_set_dw(NULL, szGPGModuleName, "KeyGenWindowY", key_gen_rect.top); + GetWindowRect(m_hwnd, &globals.key_gen_rect); + db_set_dw(NULL, szGPGModuleName, "KeyGenWindowX", globals.key_gen_rect.left); + db_set_dw(NULL, szGPGModuleName, "KeyGenWindowY", globals.key_gen_rect.top); delete this; } @@ -1251,7 +1246,7 @@ int itemnum2 = 0; class CDlgLoadExistingKey : public CDlgBase { public: - CDlgLoadExistingKey() : CDlgBase(hInst, IDD_LOAD_EXISTING_KEY), + CDlgLoadExistingKey() : CDlgBase(globals.hInst, IDD_LOAD_EXISTING_KEY), btn_OK(this, IDOK), btn_CANCEL(this, IDCANCEL), list_EXISTING_KEY_LIST(this, IDC_EXISTING_KEY_LIST) { @@ -1262,7 +1257,7 @@ public: } virtual void OnInitDialog() override { - SetWindowPos(m_hwnd, nullptr, load_existing_key_rect.left, load_existing_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); + SetWindowPos(m_hwnd, nullptr, globals.load_existing_key_rect.left, globals.load_existing_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); list_EXISTING_KEY_LIST.AddColumn(0, TranslateT("Key ID"), 50); @@ -1371,9 +1366,9 @@ public: } virtual void OnDestroy() override { - GetWindowRect(m_hwnd, &load_existing_key_rect); - db_set_dw(NULL, szGPGModuleName, "LoadExistingKeyWindowX", load_existing_key_rect.left); - db_set_dw(NULL, szGPGModuleName, "LoadExistingKeyWindowY", load_existing_key_rect.top); + GetWindowRect(m_hwnd, &globals.load_existing_key_rect); + db_set_dw(NULL, szGPGModuleName, "LoadExistingKeyWindowX", globals.load_existing_key_rect.left); + db_set_dw(NULL, szGPGModuleName, "LoadExistingKeyWindowY", globals.load_existing_key_rect.top); delete this; } void onClick_OK(CCtrlButton*) @@ -1442,7 +1437,7 @@ private: class CDlgImportKey : public CDlgBase { public: - CDlgImportKey() : CDlgBase(hInst, IDD_IMPORT_KEY), + CDlgImportKey() : CDlgBase(globals.hInst, IDD_IMPORT_KEY), combo_KEYSERVER(this, IDC_KEYSERVER), btn_IMPORT(this, IDC_IMPORT) { @@ -1451,17 +1446,17 @@ public: } virtual void OnInitDialog() override { - hContact = new_key_hcnt; - new_key_hcnt_mutex.unlock(); - SetWindowPos(m_hwnd, nullptr, import_key_rect.left, import_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); + hContact = globals.new_key_hcnt; + globals.new_key_hcnt_mutex.unlock(); + SetWindowPos(m_hwnd, nullptr, globals.import_key_rect.left, globals.import_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); combo_KEYSERVER.AddString(L"subkeys.pgp.net"); combo_KEYSERVER.AddString(L"keys.gnupg.net"); } virtual void OnDestroy() override { - GetWindowRect(m_hwnd, &import_key_rect); - db_set_dw(NULL, szGPGModuleName, "ImportKeyWindowX", import_key_rect.left); - db_set_dw(NULL, szGPGModuleName, "ImportKeyWindowY", import_key_rect.top); + GetWindowRect(m_hwnd, &globals.import_key_rect); + db_set_dw(NULL, szGPGModuleName, "ImportKeyWindowX", globals.import_key_rect.left); + db_set_dw(NULL, szGPGModuleName, "ImportKeyWindowY", globals.import_key_rect.top); delete this; } void onClick_IMPORT(CCtrlButton*) @@ -1472,7 +1467,7 @@ public: cmd.push_back(L"--keyserver"); cmd.push_back(combo_KEYSERVER.GetText()); cmd.push_back(L"--recv-keys"); - cmd.push_back(toUTF16(hcontact_data[hContact].key_in_prescense)); + cmd.push_back(toUTF16(globals.hcontact_data[hContact].key_in_prescense)); gpg_execution_params params(cmd); pxResult result; params.out = &out; @@ -1538,7 +1533,7 @@ void InitCheck() // parse gpg output wchar_t *current_home = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", L""); db_set_ws(NULL, szGPGModuleName, "szHomePath", L""); //we do not need home for gpg binary validation - gpg_valid = isGPGValid(); + globals.gpg_valid = isGPGValid(); db_set_ws(NULL, szGPGModuleName, "szHomePath", current_home); //return current home dir back mir_free(current_home); bool home_dir_access = false, temp_access = false; @@ -1568,18 +1563,18 @@ void InitCheck() test_file.close(); boost::filesystem::remove(test_path); } - if (!home_dir_access || !temp_access || !gpg_valid) { + if (!home_dir_access || !temp_access || !globals.gpg_valid) { wchar_t buf[4096]; - wcsncpy(buf, gpg_valid ? TranslateT("GPG binary is set and valid (this is good).\n") : TranslateT("GPG binary unset or invalid (plugin will not work).\n"), _countof(buf)); + wcsncpy(buf, globals.gpg_valid ? TranslateT("GPG binary is set and valid (this is good).\n") : TranslateT("GPG binary unset or invalid (plugin will not work).\n"), _countof(buf)); mir_wstrncat(buf, home_dir_access ? TranslateT("Home dir write access granted (this is good).\n") : TranslateT("Home dir has no write access (plugin most probably will not work).\n"), _countof(buf) - mir_wstrlen(buf)); mir_wstrncat(buf, temp_access ? TranslateT("Temp dir write access granted (this is good).\n") : TranslateT("Temp dir has no write access (plugin should work, but may have some problems, file transfers will not work)."), _countof(buf) - mir_wstrlen(buf)); - if (!gpg_valid) + if (!globals.gpg_valid) mir_wstrncat(buf, TranslateT("\nGPG will be disabled until you solve these problems"), _countof(buf) - mir_wstrlen(buf)); MessageBox(nullptr, buf, TranslateT("GPG plugin problems"), MB_OK); } - if (!gpg_valid) + if (!globals.gpg_valid) return; - gpg_keyexist = isGPGKeyExist(); + globals.gpg_keyexist = isGPGKeyExist(); string out; DWORD code; pxResult result; @@ -1741,7 +1736,7 @@ void InitCheck() } mir_free(path); } - if (bAutoExchange) { + if (globals.bAutoExchange) { int count = 0; PROTOACCOUNT **accounts; Proto_EnumAccounts(&count, &accounts); @@ -1755,7 +1750,7 @@ void InitCheck() if (ProtoServiceExists(accounts[i]->szProtoName, PS_ICQ_ADDCAPABILITY)) CallProtoService(accounts[i]->szProtoName, PS_ICQ_ADDCAPABILITY, 0, (LPARAM)&cap); } - if (bFileTransfers) { + if (globals.bFileTransfers) { int count = 0; PROTOACCOUNT **accounts; Proto_EnumAccounts(&count, &accounts); @@ -1773,8 +1768,8 @@ void InitCheck() void ImportKey() { - MCONTACT hContact = new_key_hcnt; - new_key_hcnt_mutex.unlock(); + MCONTACT hContact = globals.new_key_hcnt; + globals.new_key_hcnt_mutex.unlock(); bool for_all_sub = false; if (db_mc_isMeta(hContact)) { if (MessageBox(nullptr, TranslateT("Do you want to load key for all subcontacts?"), TranslateT("Metacontact detected"), MB_YESNO) == IDYES) @@ -1785,14 +1780,14 @@ void ImportKey() for (int i = 0; i < count; i++) { MCONTACT hcnt = db_mc_getSub(hContact, i); if (hcnt) - db_set_ws(hcnt, szGPGModuleName, "GPGPubKey", new_key.c_str()); + db_set_ws(hcnt, szGPGModuleName, "GPGPubKey", globals.new_key.c_str()); } } - else db_set_ws(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", new_key.c_str()); + else db_set_ws(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", globals.new_key.c_str()); } - else db_set_ws(hContact, szGPGModuleName, "GPGPubKey", new_key.c_str()); + else db_set_ws(hContact, szGPGModuleName, "GPGPubKey", globals.new_key.c_str()); - new_key.clear(); + globals.new_key.clear(); // gpg execute block std::vector<wstring> cmd; diff --git a/plugins/New_GPG/src/main.h b/plugins/New_GPG/src/main.h index c04a47302e..fd0d688c6b 100644..100755 --- a/plugins/New_GPG/src/main.h +++ b/plugins/New_GPG/src/main.h @@ -22,9 +22,6 @@ struct contact_data string key_in_prescense; }; -extern std::map<MCONTACT, contact_data> hcontact_data; -extern bool bAutoExchange; -extern RECT key_from_keyserver_rect, firstrun_rect, new_key_rect, key_gen_rect, load_key_rect, import_key_rect, key_password_rect, load_existing_key_rect; #endif diff --git a/plugins/New_GPG/src/messages.cpp b/plugins/New_GPG/src/messages.cpp index 2b17efb7db..fc240c5574 100755 --- a/plugins/New_GPG/src/messages.cpp +++ b/plugins/New_GPG/src/messages.cpp @@ -16,10 +16,6 @@ #include "stdafx.h" -wstring new_key; -MCONTACT new_key_hcnt = NULL; -boost::mutex new_key_hcnt_mutex; -bool _terminate = false; int returnNoError(MCONTACT hContact); std::list<HANDLE> sent_msgs; @@ -35,15 +31,15 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR { //this is generic encrypted data block if (!isContactSecured(hContact)) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: received encrypted message from: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " with turned off encryption"); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: received encrypted message from: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " 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)) { void ShowLoadPublicKeyDialog(bool = false); - item_num = 0; //black magic here - user_data[1] = hContact; + globals.item_num = 0; //black magic here + globals.user_data[1] = hContact; ShowLoadPublicKeyDialog(true); } else @@ -65,8 +61,8 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR return; } } - else if (bDebugLog) - debuglog << std::string(time_str() + ": info: received encrypted message from: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + else if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: received encrypted message from: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); boost::algorithm::erase_all(str, "\r"); s2 += mir_wstrlen(L"-----END PGP MESSAGE-----"); @@ -75,7 +71,7 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR wstring decfile = toUTF16(get_random(10)); { wstring path = wstring(ptszHomePath) + L"\\tmp\\" + encfile; - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(path, e); @@ -95,7 +91,7 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR db_set_b(hContact, szGPGModuleName, "GPGEncryption", 0); setSrmmIcon(hContact); setClistIcon(hContact); - debuglog<<std::string(time_str() + "info: failed to create temporary file for decryption, disabling gpg for contact to avoid deadlock"); + globals.debuglog<<std::string(time_str() + "info: failed to create temporary file for decryption, disabling gpg for contact to avoid deadlock"); return; } f.open(path.c_str(), std::ios::out); @@ -105,7 +101,6 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR mir_free(tmp); f.close(); } - extern wchar_t *password; string out; DWORD code; std::vector<wstring> cmd; @@ -118,33 +113,33 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR dbsetting += inkeyid; dbsetting += "_Password"; pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), L""); - if (pass[0] && bDebugLog) - debuglog << std::string(time_str() + ": info: found password in database for key ID: " + inkeyid + ", trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " with password"); + if (pass[0] && globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: found password in database for key ID: " + inkeyid + ", trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " with password"); } else { pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", L""); - if (pass[0] && bDebugLog) - debuglog << std::string(time_str() + ": info: found password for all keys in database, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " with password"); + if (pass[0] && globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: found password for all keys in database, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " with password"); } if (pass && pass[0]) { cmd.push_back(L"--passphrase"); cmd.push_back(pass); } - else if (password && password[0]) + else if (globals.password && globals.password[0]) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: found password in memory, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " with password"); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: found password in memory, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " with password"); cmd.push_back(L"--passphrase"); - cmd.push_back(password); + cmd.push_back(globals.password); } - else if (bDebugLog) - debuglog << std::string(time_str() + ": info: passwords not found in database or memory, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " with out password"); + else if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: passwords not found in database or memory, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " with out password"); mir_free(pass); mir_free(inkeyid); } - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(wstring(ptszHomePath) + L"\\tmp\\" + decfile, e); @@ -162,7 +157,7 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR params.result = &result; if (!gpg_launcher(params)) { - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(path, e); @@ -177,7 +172,7 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR } if (result == pxNotFound) { - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(path, e); @@ -200,12 +195,12 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR } */ //TODO: check gpg output for errors - _terminate = false; + globals._terminate = false; while (out.find("public key decryption failed: bad passphrase") != string::npos) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: failed to decrypt messaage from " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " password needed, trying to get one"); - if (_terminate) { + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: failed to decrypt messaage from " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " password needed, trying to get one"); + if (globals._terminate) { BYTE enc = db_get_b(hContact, szGPGModuleName, "GPGEncryption", 0); db_set_b(hContact, szGPGModuleName, "GPGEncryption", 0); ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)"Unable to decrypt PGP encrypted message"); @@ -220,17 +215,17 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR db_set_s(db_mc_isMeta(hContact) ? metaGetMostOnline(hContact) : hContact, szGPGModuleName, "InKeyID", out.substr(s, out.find(",", s) - s).c_str()); } void ShowLoadKeyPasswordWindow(); - new_key_hcnt_mutex.lock(); - new_key_hcnt = hContact; + globals.new_key_hcnt_mutex.lock(); + globals.new_key_hcnt = hContact; ShowLoadKeyPasswordWindow(); std::vector<wstring> cmd2 = cmd; - if (password) + if (globals.password) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: found password in memory, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: found password in memory, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); std::vector<wstring> tmp3; tmp3.push_back(L"--passphrase"); - tmp3.push_back(password); + tmp3.push_back(globals.password); cmd2.insert(cmd2.begin(), tmp3.begin(), tmp3.end()); } out.clear(); @@ -240,7 +235,7 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR params2.code = &code; params2.result = &result2; if (!gpg_launcher(params2)) { - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(path, e); @@ -256,7 +251,7 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR } if (result2 == pxNotFound) { - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(path, e); @@ -269,7 +264,7 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR out.clear(); if (!gpg_launcher(params)) { - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(path, e); @@ -285,7 +280,7 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR } if (result == pxNotFound) { - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(path, e); @@ -293,7 +288,7 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); } - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(wstring(ptszHomePath) + L"\\tmp\\" + encfile, e); @@ -303,8 +298,8 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR { string str1 = msg; str1.insert(0, "Received unencrypted message:\n"); - if (bDebugLog) - debuglog << std::string(time_str() + ": info: Failed to decrypt GPG encrypted message."); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: Failed to decrypt GPG encrypted message."); ptrA tmp4((char*)mir_alloc(sizeof(char)*(str1.length() + 1))); mir_strcpy(tmp4, str1.c_str()); @@ -333,7 +328,7 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR str.append(toUTF16(tmp)); delete[] tmp; f.close(); - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code ec; boost::filesystem::remove(tszDecPath, ec); @@ -348,8 +343,8 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR { string szMsg = msg; szMsg.insert(0, "Failed to decrypt GPG encrypted message.\nMessage body for manual decryption:\n"); - if (bDebugLog) - debuglog << std::string(time_str() + ": info: Failed to decrypt GPG encrypted message."); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: Failed to decrypt GPG encrypted message."); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); BYTE enc = db_get_b(hContact, szGPGModuleName, "GPGEncryption", 0); @@ -361,10 +356,10 @@ void RecvMsgSvc_func(MCONTACT hContact, std::wstring str, char *msg, DWORD, DWOR } fix_line_term(str); - if (bAppendTags) + if (globals.bAppendTags) { - str.insert(0, inopentag); - str.append(inclosetag); + str.insert(0, globals.inopentag); + str.append(globals.inclosetag); } char *tmp = mir_strdup(toUTF8(str).c_str()); @@ -401,23 +396,23 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) return Proto_ChainRecv(w, ccs); else { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: blocked pgp message to metacontact:" + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: blocked pgp message to metacontact:" + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); return 0; } } wstring str = toUTF16(msg); size_t s1, s2; - if (bAutoExchange && (str.find(L"-----PGP KEY RESPONSE-----") != wstring::npos)) + if (globals.bAutoExchange && (str.find(L"-----PGP KEY RESPONSE-----") != wstring::npos)) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info(autoexchange): parsing key response:" + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info(autoexchange): parsing key response:" + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); 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 (bDebugLog) - debuglog << std::string(time_str() + ": info(autoexchange): found pubkey block:" + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info(autoexchange): found pubkey block:" + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); s2 += mir_wstrlen(L"-----END PGP PUBLIC KEY BLOCK-----"); db_set_ws(ccs->hContact, szGPGModuleName, "GPGPubKey", str.substr(s1, s2 - s1).c_str()); { //gpg execute block @@ -435,7 +430,7 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) mir_wstrcat(tmp2, L".asc"); mir_free(tmp3); //mir_wstrcat(tmp2, L"temporary_exported.asc"); - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(tmp2, e); @@ -453,7 +448,7 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) db_set_b(ccs->hContact, szGPGModuleName, "GPGEncryption", 0); setSrmmIcon(ccs->hContact); setClistIcon(ccs->hContact); - debuglog<<std::string(time_str() + "info: failed to create temporary file for decryption, disabling gpg for contact to avoid deadlock"); + globals.debuglog<<std::string(time_str() + "info: failed to create temporary file for decryption, disabling gpg for contact to avoid deadlock"); return 1; } f.open(tmp2, std::ios::out); @@ -473,7 +468,7 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) params.result = &result; if (!gpg_launcher(params)) return 1; - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(tmp2, e); @@ -558,8 +553,8 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) } if ((s2 != wstring::npos) && (s1 != wstring::npos)) { //this is public key - if (bDebugLog) - debuglog << std::string(time_str() + ": info: received key from: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: received key from: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); s1 = 0; while ((s1 = str.find(L"\r", s1)) != wstring::npos) str.erase(s1, 1); @@ -568,17 +563,17 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) s2 += mir_wstrlen(L"-----END PGP PUBLIC KEY BLOCK-----"); else if (((s2 = str.find(L"-----BEGIN PGP PRIVATE KEY BLOCK-----")) != wstring::npos) && ((s1 = str.find(L"-----END PGP PRIVATE KEY BLOCK-----")) != wstring::npos)) s2 += mir_wstrlen(L"-----END PGP PRIVATE KEY BLOCK-----"); - new_key.append(str.substr(s1, s2 - s1)); + globals.new_key.append(str.substr(s1, s2 - s1)); //new_key_hcnt_mutex.lock(); - new_key_hcnt = ccs->hContact; + globals.new_key_hcnt = ccs->hContact; ShowNewKeyDialog(); HistoryLog(ccs->hContact, db_event(msg, 0, 0, dbflags)); return 0; } - if (bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && gpg_valid && gpg_keyexist) + if (globals.bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && globals.gpg_valid && globals.gpg_keyexist) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info(autoexchange): received key request from: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info(autoexchange): received key request from: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); ptrA tmp(UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", "")); if (tmp[0]) { @@ -594,7 +589,7 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) } return 0; } - else if (!isContactHaveKey(ccs->hContact) && bAutoExchange && gpg_valid && gpg_keyexist) + else if (!isContactHaveKey(ccs->hContact) && globals.bAutoExchange && globals.gpg_valid && globals.gpg_keyexist) { char *proto = GetContactProto(ccs->hContact); DWORD uin = db_get_dw(ccs->hContact, proto, "UIN", 0); @@ -616,11 +611,9 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) wchar_t *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", L""); if (jid[0]) { - extern list <JabberAccount*> Accounts; - list<JabberAccount*>::iterator end = Accounts.end(); - for (list<JabberAccount*>::iterator p = Accounts.begin(); p != end; p++) + for(auto p : globals.Accounts) { - wchar_t *caps = (*p)->getJabberInterface()->GetResourceFeatures(jid); + wchar_t *caps = p->getJabberInterface()->GetResourceFeatures(jid); if (caps) { wstring str1; @@ -653,9 +646,9 @@ INT_PTR RecvMsgSvc(WPARAM w, LPARAM l) void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags) { wstring str = toUTF16(msg); - if (bStripTags && bAppendTags) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: stripping tags in outgoing message, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.bStripTags && globals.bAppendTags) { + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: stripping tags in outgoing message, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); strip_tags(str); } /* for(std::wstring::size_type i = str.find(L"\r\n"); i != std::wstring::npos; i = str.find(L"\r\n", i+1)) @@ -664,7 +657,6 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags) DWORD code; wstring file = toUTF16(get_random(10)), path; std::vector<std::wstring> cmd; - extern bool bJabberAPI; { wchar_t *tmp2; { @@ -675,7 +667,7 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags) ProtoChainSend(hContact, PSS_MESSAGE, flags, (LPARAM)msg); return; } - if (!bJabberAPI) //force jabber to handle encrypted message by itself + if (!globals.bJabberAPI) //force jabber to handle encrypted message by itself { cmd.push_back(L"--comment"); cmd.push_back(L"\"\""); @@ -714,7 +706,7 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags) db_set_b(hContact, szGPGModuleName, "GPGEncryption", 0); //disable encryption setSrmmIcon(hContact); setClistIcon(hContact); - debuglog << std::string(time_str() + ": info: failed to create temporary file for encryption, disabling encryption to avoid deadlock"); + globals.debuglog << std::string(time_str() + ": info: failed to create temporary file for encryption, disabling encryption to avoid deadlock"); break; } f.open(path.c_str(), std::ios::out); @@ -782,14 +774,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(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(path, e); } return; } - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(path, e); @@ -806,7 +798,7 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags) db_set_b(hContact, szGPGModuleName, "GPGEncryption", 0); //disable encryption setSrmmIcon(hContact); setClistIcon(hContact); - debuglog << std::string(time_str() + ": info: gpg failed to encrypt message, disabling encryption to avoid deadlock"); + globals.debuglog << std::string(time_str() + ": info: gpg failed to encrypt message, disabling encryption to avoid deadlock"); break; } } @@ -820,7 +812,7 @@ void SendMsgSvc_func(MCONTACT hContact, char *msg, DWORD flags) str.append(tmp); delete[] tmp; f.close(); - if(!bDebugLog) + if(!globals.bDebugLog) { boost::system::error_code e; boost::filesystem::remove(path, e); @@ -828,19 +820,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 (bDebugLog) - debuglog << std::string(time_str() + ": info: Failed to encrypt message with GPG"); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: Failed to encrypt message with GPG"); ProtoChainSend(hContact, PSS_MESSAGE, flags, (LPARAM)msg); return; } string str_event = msg; - if (bAppendTags) { - str_event.insert(0, toUTF8(outopentag)); - str_event.append(toUTF8(outclosetag)); + if (globals.bAppendTags) { + str_event.insert(0, toUTF8(globals.outopentag)); + str_event.append(toUTF8(globals.outclosetag)); } - if (bDebugLog) - debuglog << std::string(time_str() + ": adding event to contact: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " on send message."); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": adding event to contact: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " on send message."); fix_line_term(str); sent_msgs.push_back((HANDLE)ProtoChainSend(hContact, PSS_MESSAGE, flags, (LPARAM)toUTF8(str).c_str())); @@ -855,22 +847,22 @@ INT_PTR SendMsgSvc(WPARAM w, LPARAM l) return Proto_ChainSend(w, ccs); char *msg = (char*)ccs->lParam; if (!msg) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: failed to get message data, name: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: failed to get message data, name: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); return Proto_ChainSend(w, ccs); } if (strstr(msg, "-----BEGIN PGP MESSAGE-----")) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: encrypted messge, let it go, name: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: encrypted messge, let it go, name: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); return Proto_ChainSend(w, ccs); } - if (bDebugLog) - debuglog << std::string(time_str() + ": info: contact have key, name: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); - if (bDebugLog && db_mc_isMeta(ccs->hContact)) - debuglog << std::string(time_str() + ": info: protocol is metacontacts, name: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: contact have key, name: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); + if (globals.bDebugLog && db_mc_isMeta(ccs->hContact)) + globals.debuglog << std::string(time_str() + ": info: protocol is metacontacts, name: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); if (!isContactSecured(ccs->hContact) || db_mc_isMeta(ccs->hContact)) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: contact not secured, name: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: contact not secured, name: " + toUTF8(pcli->pfnGetContactDisplayName(ccs->hContact, 0))); return Proto_ChainSend(w, ccs); } return returnNoError(ccs->hContact); @@ -889,14 +881,14 @@ 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 (bDebugLog) - debuglog << std::string(time_str() + ": info(send handler): block pgp message event, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info(send handler): block pgp message event, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); return 1; } - if (bAutoExchange && (strstr((char*)dbei->pBlob, "-----PGP KEY RESPONSE-----") || strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----"))) ///do not show service data in history + 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 (bDebugLog) - debuglog << std::string(time_str() + ": info(send handler): block pgp key request/response event, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info(send handler): block pgp key request/response event, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); return 1; } } @@ -904,29 +896,29 @@ int HookSendMsg(WPARAM w, LPARAM l) return 0; if (!isContactHaveKey(hContact)) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: contact have not key, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); - if (bAutoExchange && !strstr((char*)dbei->pBlob, "-----PGP KEY REQUEST-----") && !strstr((char*)dbei->pBlob, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && gpg_valid) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: checking for autoexchange possibility, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: contact have not key, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.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 << std::string(time_str() + ": info: checking for autoexchange possibility, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); LPSTR proto = GetContactProto(hContact); DWORD uin = db_get_dw(hContact, proto, "UIN", 0); if (uin) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info(autoexchange): protocol looks like icq, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info(autoexchange): protocol looks like icq, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); char *proto2 = GetContactProto(hContact); if (ProtoServiceExists(proto2, PS_ICQ_CHECKCAPABILITY)) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info(autoexchange, icq): checking for autoexchange icq capability, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info(autoexchange, icq): checking for autoexchange icq capability, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); ICQ_CUSTOMCAP cap = { 0 }; strncpy(cap.caps, "GPGAutoExchange", sizeof(cap.caps)); if (CallProtoService(proto2, PS_ICQ_CHECKCAPABILITY, hContact, (LPARAM)&cap)) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info(autoexchange, icq): sending key requiest, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info(autoexchange, icq): sending key requiest, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)"-----PGP KEY REQUEST-----"); - hcontact_data[hContact].msgs_to_send.push_back((char*)dbei->pBlob); + globals.hcontact_data[hContact].msgs_to_send.push_back((char*)dbei->pBlob); new boost::thread(boost::bind(send_encrypted_msgs_thread, (void*)hContact)); return 0; } @@ -935,12 +927,11 @@ int HookSendMsg(WPARAM w, LPARAM l) else { wchar_t *jid = UniGetContactSettingUtf(hContact, proto, "jid", L""); if (jid[0]) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info(autoexchange): protocol looks like jabber, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); - extern list <JabberAccount*> Accounts; - list<JabberAccount*>::iterator end = Accounts.end(); - for (list<JabberAccount*>::iterator p = Accounts.begin(); p != end; p++) { - wchar_t *caps = (*p)->getJabberInterface()->GetResourceFeatures(jid); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info(autoexchange): protocol looks like jabber, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + for(auto p : globals.Accounts) + { + wchar_t *caps = p->getJabberInterface()->GetResourceFeatures(jid); if (caps) { wstring str; for (int i = 0;; i++) { @@ -951,10 +942,10 @@ int HookSendMsg(WPARAM w, LPARAM l) } mir_free(caps); if (str.find(L"GPG_Key_Auto_Exchange:0") != string::npos) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info(autoexchange, jabber): autoexchange capability found, sending key request, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info(autoexchange, jabber): autoexchange capability found, sending key request, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)"-----PGP KEY REQUEST-----"); - hcontact_data[hContact].msgs_to_send.push_back((char*)dbei->pBlob); + globals.hcontact_data[hContact].msgs_to_send.push_back((char*)dbei->pBlob); new boost::thread(boost::bind(send_encrypted_msgs_thread, (void*)hContact)); return 0; } @@ -972,11 +963,11 @@ int HookSendMsg(WPARAM w, LPARAM l) { SendMsgSvc_func(hContact, (char*)dbei->pBlob, 0); //TODO: handle errors somehow ... - if (bAppendTags) { + if (globals.bAppendTags) { string str_event = (char*)dbei->pBlob; //mir_free(dbei->pBlob); - str_event.insert(0, toUTF8(outopentag)); - str_event.append(toUTF8(outclosetag)); + str_event.insert(0, toUTF8(globals.outopentag)); + str_event.append(toUTF8(globals.outclosetag)); dbei->pBlob = (PBYTE)mir_strdup(str_event.c_str()); dbei->cbBlob = (DWORD)str_event.length() + 1; } @@ -984,8 +975,8 @@ int HookSendMsg(WPARAM w, LPARAM l) return 0; } if (!isContactSecured(hContact)) { - if (bDebugLog) - debuglog << std::string(time_str() + ": event message: \"" + (char*)dbei->pBlob + "\" passed event filter, contact " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " is unsecured"); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": event message: \"" + (char*)dbei->pBlob + "\" passed event filter, contact " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0)) + " is unsecured"); return 0; } if (!(dbei->flags & DBEF_SENT) && db_mc_isMeta((MCONTACT)w)) { @@ -993,19 +984,18 @@ int HookSendMsg(WPARAM w, LPARAM l) strncpy(tmp, (char*)dbei->pBlob, 27); tmp[28] = '\0'; if (strstr(tmp, "-----BEGIN PGP MESSAGE-----")) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info(send handler): block pgp message event, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info(send handler): block pgp message event, name: " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); return 1; } } return 0; } -extern HINSTANCE hInst; class CDlgKeyPasswordMsgBox : public CDlgBase //always modal { public: - CDlgKeyPasswordMsgBox() : CDlgBase(hInst, IDD_KEY_PASSWD), + CDlgKeyPasswordMsgBox() : CDlgBase(globals.hInst, IDD_KEY_PASSWD), lbl_KEYID(this, IDC_KEYID), edit_KEY_PASSWORD(this, IDC_KEY_PASSWORD), chk_DEFAULT_PASSWORD(this, IDC_DEFAULT_PASSWORD), chk_SAVE_PASSWORD(this, IDC_SAVE_PASSWORD), @@ -1016,10 +1006,10 @@ public: } virtual void OnInitDialog() override { - inkeyid = UniGetContactSettingUtf(new_key_hcnt, szGPGModuleName, "InKeyID", ""); - new_key_hcnt_mutex.unlock(); + inkeyid = UniGetContactSettingUtf(globals.new_key_hcnt, szGPGModuleName, "InKeyID", ""); + globals.new_key_hcnt_mutex.unlock(); - SetWindowPos(m_hwnd, nullptr, key_password_rect.left, key_password_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); + SetWindowPos(m_hwnd, nullptr, globals.key_password_rect.left, globals.key_password_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); { string questionstr = "Please enter password for key with ID: "; questionstr += inkeyid; @@ -1035,18 +1025,17 @@ public: virtual void OnDestroy() override { mir_free(inkeyid); - GetWindowRect(m_hwnd, &key_password_rect); - db_set_dw(NULL, szGPGModuleName, "PasswordWindowX", key_password_rect.left); - db_set_dw(NULL, szGPGModuleName, "PasswordWindowY", key_password_rect.top); + GetWindowRect(m_hwnd, &globals.key_password_rect); + db_set_dw(NULL, szGPGModuleName, "PasswordWindowX", globals.key_password_rect.left); + db_set_dw(NULL, szGPGModuleName, "PasswordWindowY", globals.key_password_rect.top); delete this; } void onClick_OK(CCtrlButton*) { wchar_t *tmp = mir_wstrdup(edit_KEY_PASSWORD.GetText()); if (tmp && tmp[0]) { - extern wchar_t *password; if (chk_SAVE_PASSWORD.GetState()) { - inkeyid = UniGetContactSettingUtf(new_key_hcnt, szGPGModuleName, "InKeyID", ""); + inkeyid = UniGetContactSettingUtf(globals.new_key_hcnt, szGPGModuleName, "InKeyID", ""); if (inkeyid && inkeyid[0] && !chk_DEFAULT_PASSWORD.GetState()) { string dbsetting = "szKey_"; dbsetting += inkeyid; @@ -1056,17 +1045,17 @@ public: else db_set_ws(NULL, szGPGModuleName, "szKeyPassword", tmp); } - if (password) - mir_free(password); - password = (wchar_t*)mir_alloc(sizeof(wchar_t)*(mir_wstrlen(tmp) + 1)); - mir_wstrcpy(password, tmp); + if (globals.password) + mir_free(globals.password); + globals.password = (wchar_t*)mir_alloc(sizeof(wchar_t)*(mir_wstrlen(tmp) + 1)); + mir_wstrcpy(globals.password, tmp); } mir_free(inkeyid); DestroyWindow(m_hwnd); } void onClick_CANCEL(CCtrlButton*) { - _terminate = true; + globals._terminate = true; DestroyWindow(m_hwnd); } private: diff --git a/plugins/New_GPG/src/options.cpp b/plugins/New_GPG/src/options.cpp index b6bcac6774..4d6b3a5bc6 100755 --- a/plugins/New_GPG/src/options.cpp +++ b/plugins/New_GPG/src/options.cpp @@ -16,8 +16,7 @@ #include "stdafx.h" -extern HINSTANCE hInst; -extern bool bJabberAPI, bFileTransfers; +globals_s globals; map<int, MCONTACT> user_data; @@ -37,7 +36,7 @@ class COptGpgMainDlg : public CDlgBase CCtrlButton btn_DELETE_KEY_BUTTON, btn_SELECT_KEY, btn_SAVE_KEY_BUTTON, btn_COPY_KEY, btn_LOG_FILE_SET; public: - COptGpgMainDlg() : CDlgBase(hInst, IDD_OPT_GPG), + COptGpgMainDlg() : CDlgBase(globals.hInst, IDD_OPT_GPG), list_USERLIST(this, IDC_USERLIST), lbl_CURRENT_KEY(this, IDC_CURRENT_KEY), edit_LOG_FILE_EDIT(this, IDC_LOG_FILE_EDIT), check_DEBUG_LOG(this, IDC_DEBUG_LOG), check_JABBER_API(this, IDC_JABBER_API), check_AUTO_EXCHANGE(this, IDC_AUTO_EXCHANGE), check_FILE_TRANSFERS(this, IDC_FILE_TRANSFERS), btn_DELETE_KEY_BUTTON(this, IDC_DELETE_KEY_BUTTON), btn_SELECT_KEY(this, IDC_SELECT_KEY), btn_SAVE_KEY_BUTTON(this, IDC_SAVE_KEY_BUTTON), btn_COPY_KEY(this, IDC_COPY_KEY), btn_LOG_FILE_SET(this, IDC_LOG_FILE_SET) @@ -113,7 +112,7 @@ public: check_DEBUG_LOG.SetState(db_get_b(NULL, szGPGModuleName, "bDebugLog", 0)); check_JABBER_API.Enable(); - check_AUTO_EXCHANGE.Enable(bJabberAPI); + check_AUTO_EXCHANGE.Enable(globals.bJabberAPI); { string keyinfo = Translate("Default private key ID"); @@ -138,18 +137,18 @@ public: virtual void OnApply() override { - db_set_b(NULL, szGPGModuleName, "bDebugLog", bDebugLog = check_DEBUG_LOG.GetState()); + db_set_b(NULL, szGPGModuleName, "bDebugLog", globals.bDebugLog = check_DEBUG_LOG.GetState()); - if (bDebugLog) - debuglog.init(); - db_set_b(NULL, szGPGModuleName, "bJabberAPI", bJabberAPI = check_JABBER_API.GetState()); + if (globals.bDebugLog) + globals.debuglog.init(); + db_set_b(NULL, szGPGModuleName, "bJabberAPI", globals.bJabberAPI = check_JABBER_API.GetState()); bool old_bFileTransfers = db_get_b(NULL, szGPGModuleName, "bFileTransfers", 0) != 0; - db_set_b(NULL, szGPGModuleName, "bFileTransfers", bFileTransfers = check_FILE_TRANSFERS.GetState()); - if (bFileTransfers != old_bFileTransfers) { + db_set_b(NULL, szGPGModuleName, "bFileTransfers", globals.bFileTransfers = check_FILE_TRANSFERS.GetState()); + if (globals.bFileTransfers != old_bFileTransfers) { db_set_b(NULL, szGPGModuleName, "bSameAction", 0); - bSameAction = false; + globals.bSameAction = false; } - db_set_b(NULL, szGPGModuleName, "bAutoExchange", bAutoExchange = check_AUTO_EXCHANGE.GetState()); + db_set_b(NULL, szGPGModuleName, "bAutoExchange", globals.bAutoExchange = check_AUTO_EXCHANGE.GetState()); db_set_ws(NULL, szGPGModuleName, "szLogFilePath", ptrW(edit_LOG_FILE_EDIT.GetText())); } @@ -163,13 +162,13 @@ public: bool keep = false; bool ismetacontact = false; MCONTACT meta = NULL; - MCONTACT hContact = user_data[item_num + 1]; + MCONTACT hContact = globals.user_data[item_num + 1]; if (db_mc_isMeta(hContact)) { meta = hContact; hContact = metaGetMostOnline(hContact); ismetacontact = true; } - else if ((meta = db_mc_getMeta(user_data[item_num + 1])) != NULL) { + else if ((meta = db_mc_getMeta(globals.user_data[item_num + 1])) != NULL) { hContact = metaGetMostOnline(meta); ismetacontact = true; } @@ -376,7 +375,7 @@ class COptGpgBinDlg : public CDlgBase CCtrlButton btn_SET_BIN_PATH, btn_SET_HOME_DIR; public: - COptGpgBinDlg() : CDlgBase(hInst, IDD_OPT_GPG_BIN), + COptGpgBinDlg() : CDlgBase(globals.hInst, IDD_OPT_GPG_BIN), edit_BIN_PATH(this, IDC_BIN_PATH), edit_HOME_DIR(this, IDC_HOME_DIR), btn_SET_BIN_PATH(this, IDC_SET_BIN_PATH), btn_SET_HOME_DIR(this, IDC_SET_HOME_DIR) { @@ -423,10 +422,10 @@ public: params.out = &out; params.code = &code; params.result = &result; - auto old_gpg_state = gpg_valid; - gpg_valid = true; + bool old_gpg_state = globals.gpg_valid; + globals.gpg_valid = true; gpg_launcher(params); - gpg_valid = old_gpg_state; + globals.gpg_valid = old_gpg_state; db_set_ws(NULL, szGPGModuleName, "szGpgBinPath", tmp_path); mir_free(tmp_path); string::size_type p1 = out.find("(GnuPG) "); @@ -471,7 +470,7 @@ class COptGpgMsgDlg : public CDlgBase CCtrlEdit edit_IN_OPEN_TAG, edit_IN_CLOSE_TAG, edit_OUT_OPEN_TAG, edit_OUT_CLOSE_TAG; public: - COptGpgMsgDlg() : CDlgBase(hInst, IDD_OPT_GPG_MESSAGES), + COptGpgMsgDlg() : CDlgBase(globals.hInst, 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) {} @@ -488,25 +487,25 @@ public: virtual void OnApply() override { - db_set_b(NULL, szGPGModuleName, "bAppendTags", bAppendTags = check_APPEND_TAGS.GetState()); - db_set_b(NULL, szGPGModuleName, "bStripTags", bStripTags = check_STRIP_TAGS.GetState()); + db_set_b(NULL, szGPGModuleName, "bAppendTags", globals.bAppendTags = check_APPEND_TAGS.GetState()); + db_set_b(NULL, szGPGModuleName, "bStripTags", globals.bStripTags = check_STRIP_TAGS.GetState()); { wchar_t *tmp = mir_wstrdup(edit_IN_OPEN_TAG.GetText()); db_set_ws(NULL, szGPGModuleName, "szInOpenTag", tmp); - mir_free(inopentag); - inopentag = tmp; + mir_free(globals.inopentag); + globals.inopentag = tmp; tmp = mir_wstrdup(edit_IN_CLOSE_TAG.GetText()); db_set_ws(NULL, szGPGModuleName, "szInCloseTag", tmp); - mir_free(inclosetag); - inclosetag = tmp; + mir_free(globals.inclosetag); + globals.inclosetag = tmp; tmp = mir_wstrdup(edit_OUT_OPEN_TAG.GetText()); db_set_ws(NULL, szGPGModuleName, "szOutOpenTag", tmp); - mir_free(outopentag); - outopentag = tmp; + mir_free(globals.outopentag); + globals.outopentag = tmp; tmp = mir_wstrdup(edit_OUT_CLOSE_TAG.GetText()); db_set_ws(NULL, szGPGModuleName, "szOutCloseTag", tmp); - mir_free(outclosetag); - outclosetag = tmp; + mir_free(globals.outclosetag); + globals.outclosetag = tmp; } } }; @@ -517,7 +516,7 @@ class COptGpgAdvDlg : public CDlgBase CCtrlCheck check_PRESCENSE_SUBSCRIPTION; public: - COptGpgAdvDlg() : CDlgBase(hInst, IDD_OPT_GPG_ADVANCED), + COptGpgAdvDlg() : CDlgBase(globals.hInst, IDD_OPT_GPG_ADVANCED), btn_EXPORT(this, IDC_EXPORT), btn_IMPORT(this, IDC_IMPORT), check_PRESCENSE_SUBSCRIPTION(this, IDC_PRESCENSE_SUBSCRIPTION) { @@ -528,12 +527,12 @@ public: virtual void OnInitDialog() override { check_PRESCENSE_SUBSCRIPTION.SetState(db_get_b(NULL, szGPGModuleName, "bPresenceSigning", 0)); - check_PRESCENSE_SUBSCRIPTION.Enable(bJabberAPI); + check_PRESCENSE_SUBSCRIPTION.Enable(globals.bJabberAPI); } virtual void OnApply() override { - db_set_b(NULL, szGPGModuleName, "bPresenceSigning", bPresenceSigning = check_PRESCENSE_SUBSCRIPTION.GetState()); + db_set_b(NULL, szGPGModuleName, "bPresenceSigning", globals.bPresenceSigning = check_PRESCENSE_SUBSCRIPTION.GetState()); } void onClick_EXPORT(CCtrlButton*) @@ -573,7 +572,7 @@ class CDlgLoadPubKeyDlg : public CDlgBase CCtrlEdit edit_PUBLIC_KEY_EDIT; public: - CDlgLoadPubKeyDlg() : CDlgBase(hInst, IDD_LOAD_PUBLIC_KEY), + CDlgLoadPubKeyDlg() : CDlgBase(globals.hInst, IDD_LOAD_PUBLIC_KEY), chk_ENABLE_ENCRYPTION(this, IDC_ENABLE_ENCRYPTION), btn_SELECT_EXISTING(this, IDC_SELECT_EXISTING), btn_OK(this, ID_OK), btn_LOAD_FROM_FILE(this, ID_LOAD_FROM_FILE), btn_IMPORT(this, IDC_IMPORT), edit_PUBLIC_KEY_EDIT(this, IDC_PUBLIC_KEY_EDIT) @@ -587,7 +586,7 @@ public: virtual void OnInitDialog() override { hContact = user_data[1]; - SetWindowPos(m_hwnd, nullptr, load_key_rect.left, load_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); + SetWindowPos(m_hwnd, nullptr, globals.load_key_rect.left, globals.load_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); mir_subclassWindow(GetDlgItem(m_hwnd, IDC_PUBLIC_KEY_EDIT), editctrl_ctrl_a); MCONTACT hcnt = db_mc_tryMeta(hContact); { @@ -622,7 +621,7 @@ public: } } // char *tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID_Prescense", ""); - if (!hcontact_data[hcnt].key_in_prescense.empty()) { + if (!globals.hcontact_data[hcnt].key_in_prescense.empty()) { char *tmp2 = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID", ""); if (!tmp2[0]) { string out; @@ -630,7 +629,7 @@ public: std::vector<wstring> cmd; cmd.push_back(L"--export"); cmd.push_back(L"-a"); - cmd.push_back(toUTF16(hcontact_data[hcnt].key_in_prescense)); + cmd.push_back(toUTF16(globals.hcontact_data[hcnt].key_in_prescense)); gpg_execution_params params(cmd); pxResult result; params.out = &out; @@ -647,13 +646,13 @@ public: string msg = Translate("Load Public GPG Key for "); msg += _T2A(pcli->pfnGetContactDisplayName(hcnt, 0)); msg += " (Key ID: "; - msg += hcontact_data[hcnt].key_in_prescense; + msg += globals.hcontact_data[hcnt].key_in_prescense; msg += Translate(" found in presence, and exists in keyring.)"); SetCaption(toUTF16(msg).c_str()); } else { string msg = Translate("Load Public GPG Key (Key ID: "); - msg += hcontact_data[hcnt].key_in_prescense; + msg += globals.hcontact_data[hcnt].key_in_prescense; msg += Translate(" found in presence.)"); SetCaption(toUTF16(msg).c_str()); btn_IMPORT.Enable(); @@ -670,9 +669,9 @@ public: virtual void OnDestroy() override { - GetWindowRect(m_hwnd, &load_key_rect); - db_set_dw(NULL, szGPGModuleName, "LoadKeyWindowX", load_key_rect.left); - db_set_dw(NULL, szGPGModuleName, "LoadKeyWindowY", load_key_rect.top); + GetWindowRect(m_hwnd, &globals.load_key_rect); + db_set_dw(NULL, szGPGModuleName, "LoadKeyWindowX", globals.load_key_rect.left); + db_set_dw(NULL, szGPGModuleName, "LoadKeyWindowY", globals.load_key_rect.top); edit_p_PubKeyEdit = nullptr; delete this; } @@ -1029,8 +1028,8 @@ public: } if (key_buf.empty()) { key_buf.clear(); - if (bDebugLog) - debuglog << std::string(time_str() + ": info: Failed to read key file"); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: Failed to read key file"); return; } ws2 = key_buf.find(L"-----END PGP PUBLIC KEY BLOCK-----"); @@ -1049,8 +1048,8 @@ public: } void onClick_IMPORT(CCtrlButton*) { - new_key_hcnt_mutex.lock(); - new_key_hcnt = hContact; + globals.new_key_hcnt_mutex.lock(); + globals.new_key_hcnt = hContact; void ShowImportKeyDialog(); ShowImportKeyDialog(); } diff --git a/plugins/New_GPG/src/options.h b/plugins/New_GPG/src/options.h new file mode 100755 index 0000000000..cb032f1db3 --- /dev/null +++ b/plugins/New_GPG/src/options.h @@ -0,0 +1,22 @@ +// Copyright © 2017 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 OPTIONS_H +#define OPTIONS_H + + + +#endif
\ No newline at end of file diff --git a/plugins/New_GPG/src/srmm.cpp b/plugins/New_GPG/src/srmm.cpp index 80aea96aa5..b95491f38d 100755 --- a/plugins/New_GPG/src/srmm.cpp +++ b/plugins/New_GPG/src/srmm.cpp @@ -58,8 +58,8 @@ int __cdecl onIconPressed(WPARAM wParam, LPARAM lParam) if(!isContactHaveKey(hContact)) { void ShowLoadPublicKeyDialog(bool = false); - item_num = 0; //black magic here - user_data[1] = hContact; + globals.item_num = 0; //black magic here + globals.user_data[1] = hContact; ShowLoadPublicKeyDialog(); } else diff --git a/plugins/New_GPG/src/stdafx.h b/plugins/New_GPG/src/stdafx.h index 0900c87e0f..38f774112e 100755 --- a/plugins/New_GPG/src/stdafx.h +++ b/plugins/New_GPG/src/stdafx.h @@ -78,11 +78,13 @@ using std::fstream; #include "version.h" #include "constants.h" #include "log.h" -#include "globals.h" #include "utilities.h" #include "main.h" #include "gpg_wrapper.h" #include "jabber_account.h" #include "metacontacts.h" +#include "ui.h" +#include "options.h" +#include "globals.h" #endif diff --git a/plugins/New_GPG/src/ui.cpp b/plugins/New_GPG/src/ui.cpp new file mode 100755 index 0000000000..4271e8d442 --- /dev/null +++ b/plugins/New_GPG/src/ui.cpp @@ -0,0 +1,167 @@ +// Copyright � 2017 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. + + +#include "stdafx.h" + + + +void CDlgEncryptedFileMsgBox::OnInitDialog() +{ + globals.bDecryptFiles = false; +} + +CDlgEncryptedFileMsgBox::CDlgEncryptedFileMsgBox() : CDlgBase(globals.hInst, IDD_ENCRYPTED_FILE_MSG_BOX), +chk_REMEMBER(this, IDC_REMEMBER), +btn_IGNORE(this, IDC_IGNORE), btn_DECRYPT(this, IDC_DECRYPT) +{ + btn_IGNORE.OnClick = Callback(this, &CDlgEncryptedFileMsgBox::onClick_IGNORE); + btn_DECRYPT.OnClick = Callback(this, &CDlgEncryptedFileMsgBox::onClick_DECRYPT); +} + +void CDlgEncryptedFileMsgBox::OnDestroy() +{ + delete this; +} + +void CDlgEncryptedFileMsgBox::onClick_IGNORE(CCtrlButton*) +{ + if (chk_REMEMBER.GetState()) + { + db_set_b(NULL, szGPGModuleName, "bSameAction", 1); + globals.bSameAction = true; + } + this->Close(); +} + +void CDlgEncryptedFileMsgBox::onClick_DECRYPT(CCtrlButton*) +{ + globals.bDecryptFiles = true; + if (chk_REMEMBER.GetState()) + { + db_set_b(NULL, szGPGModuleName, "bFileTransfers", 1); + globals.bFileTransfers = true; + db_set_b(NULL, szGPGModuleName, "bSameAction", 0); + globals.bSameAction = false; + } + this->Close(); +} + + + +CDlgExportKeysMsgBox::CDlgExportKeysMsgBox() : CDlgBase(globals.hInst, IDD_EXPORT_TYPE), +btn_OK(this, IDC_OK), btn_CANCEL(this, IDC_CANCEL), +chk_PUBLIC(this, IDC_PUBLIC), chk_PRIVATE(this, IDC_PRIVATE), chk_ALL(this, IDC_ALL) +{ + btn_OK.OnClick = Callback(this, &CDlgExportKeysMsgBox::onClick_OK); + btn_CANCEL.OnClick = Callback(this, &CDlgExportKeysMsgBox::onClick_CANCEL); +} +void CDlgExportKeysMsgBox::OnInitDialog() +{ + chk_PUBLIC.SetState(1); +} +void CDlgExportKeysMsgBox::OnDestroy() +{ + delete this; +} +void CDlgExportKeysMsgBox::onClick_OK(CCtrlButton*) +{ + if (chk_PUBLIC.GetState()) + ExportGpGKeysFunc(0); + else if (chk_PRIVATE.GetState()) + ExportGpGKeysFunc(1); + else if (chk_ALL.GetState()) + ExportGpGKeysFunc(2); + this->Close(); +} +void CDlgExportKeysMsgBox::onClick_CANCEL(CCtrlButton*) +{ + this->Close(); +} + + + +CDlgChangePasswdMsgBox::CDlgChangePasswdMsgBox() : CDlgBase(globals.hInst, IDD_CHANGE_PASSWD), +btn_OK(this, ID_OK), +edit_NEW_PASSWD1(this, IDC_NEW_PASSWD1), edit_NEW_PASSWD2(this, IDC_NEW_PASSWD2), edit_OLD_PASSWD(this, IDC_OLD_PASSWD) +{ + btn_OK.OnClick = Callback(this, &CDlgChangePasswdMsgBox::onClick_OK); +} +void CDlgChangePasswdMsgBox::OnDestroy() +{ + delete this; +} +void CDlgChangePasswdMsgBox::onClick_OK(CCtrlButton*) +{ + //TODO: show some prgress + { + if (mir_wstrcmp(edit_NEW_PASSWD1.GetText(), edit_NEW_PASSWD2.GetText())) + { + MessageBox(m_hwnd, TranslateT("New passwords do not match"), TranslateT("Error"), MB_OK); + return; + } + std::string old_pass, new_pass; + // wchar_t buf[256] = { 0 }; + new_pass = toUTF8(edit_NEW_PASSWD1.GetText()); + old_pass = toUTF8(edit_OLD_PASSWD.GetText()); + bool old_pass_match = false; + wchar_t *pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", L""); + if (!mir_wstrcmp(pass, edit_OLD_PASSWD.GetText())) + old_pass_match = true; + mir_free(pass); + + if (!old_pass_match) { + if (globals.key_id_global[0]) { + string dbsetting = "szKey_"; + dbsetting += toUTF8(globals.key_id_global); + dbsetting += "_Password"; + pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), L""); + if (!mir_wstrcmp(pass, edit_OLD_PASSWD.GetText())) + old_pass_match = true; + mir_free(pass); + } + } + + if (!old_pass_match) + if (MessageBox(m_hwnd, TranslateT("Old password does not match, you can continue, but GPG will reject wrong password.\nDo you want to continue?"), TranslateT("Error"), MB_YESNO) == IDNO) + return; + + std::vector<std::wstring> cmd; + string output; + DWORD exitcode; + cmd.push_back(L"--edit-key"); + cmd.push_back(globals.key_id_global); + cmd.push_back(L"passwd"); + gpg_execution_params_pass params(cmd, old_pass, new_pass); + pxResult result; + params.out = &output; + params.code = &exitcode; + params.result = &result; + boost::thread gpg_thread(boost::bind(&pxEexcute_passwd_change_thread, ¶ms)); + if (!gpg_thread.timed_join(boost::posix_time::minutes(10))) { + gpg_thread.~thread(); + if (params.child) + boost::process::terminate(*(params.child)); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": GPG execution timed out, aborted"); + this->Close(); + return; + } + if (result == pxNotFound) + return; + } + this->Close(); +} diff --git a/plugins/New_GPG/src/ui.h b/plugins/New_GPG/src/ui.h new file mode 100755 index 0000000000..5c017b7e1f --- /dev/null +++ b/plugins/New_GPG/src/ui.h @@ -0,0 +1,63 @@ +// Copyright © 2017 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 UI_H +#define UI_H + + +class CDlgEncryptedFileMsgBox : public CDlgBase +{ +public: + CDlgEncryptedFileMsgBox(); + virtual void OnInitDialog() override; + virtual void OnDestroy() override; + void onClick_IGNORE(CCtrlButton*); + void onClick_DECRYPT(CCtrlButton*); + +private: + CCtrlCheck chk_REMEMBER; + CCtrlButton btn_IGNORE, btn_DECRYPT; +}; + +class CDlgExportKeysMsgBox : public CDlgBase +{ +public: + CDlgExportKeysMsgBox(); + virtual void OnInitDialog() override; + virtual void OnDestroy() override; + void onClick_OK(CCtrlButton*); + void onClick_CANCEL(CCtrlButton*); + +private: + CCtrlButton btn_OK, btn_CANCEL; + CCtrlCheck chk_PUBLIC, chk_PRIVATE, chk_ALL; +}; + +class CDlgChangePasswdMsgBox : public CDlgBase //always modal +{ +public: + CDlgChangePasswdMsgBox(); + virtual void OnDestroy() override; + void onClick_OK(CCtrlButton*); +private: + CCtrlButton btn_OK; + CCtrlEdit edit_NEW_PASSWD1, edit_NEW_PASSWD2, edit_OLD_PASSWD; +}; + + + + +#endif // UI_H
\ No newline at end of file diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp index d7262b9bd6..a7802c3558 100755 --- a/plugins/New_GPG/src/utilities.cpp +++ b/plugins/New_GPG/src/utilities.cpp @@ -1,4 +1,4 @@ -// Copyright © 2010-2012 sss +// Copyright © 2010-2017 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -20,10 +20,6 @@ void ShowExportKeysDlg(); void ShowLoadPublicKeyDialog(bool = false); -extern HINSTANCE hInst; -extern HANDLE hLoadPublicKey; -extern HGENMENU hToggleEncryption, hSendKey; - wchar_t* __stdcall UniGetContactSettingUtf(MCONTACT hContact, const char *szModule, const char* szSetting, wchar_t* szDef) { DBVARIANT dbv = { DBVT_DELETED }; @@ -136,7 +132,7 @@ void GetFolderPath(wchar_t *WindowTittle, char*) INT_PTR LoadKey(WPARAM w, LPARAM) { - user_data[1] = (MCONTACT)w; + globals.user_data[1] = (MCONTACT)w; ShowLoadPublicKeyDialog(); return 0; } @@ -213,7 +209,7 @@ INT_PTR ToggleEncryption(WPARAM w, LPARAM) setSrmmIcon(hContact); setClistIcon(hContact); - Menu_ModifyItem(hToggleEncryption, enc ? LPGENW("Turn off GPG encryption") : LPGENW("Turn on GPG encryption")); + Menu_ModifyItem(globals.hToggleEncryption, enc ? LPGENW("Turn off GPG encryption") : LPGENW("Turn on GPG encryption")); return 0; } @@ -240,7 +236,7 @@ int OnPreBuildContactMenu(WPARAM w, LPARAM) wchar_t buf[128] = { 0 }; mir_snwprintf(buf, L"%s: %s", TranslateT("Send public key"), toUTF16(keyid).c_str()); mir_free(keyid); - Menu_ModifyItem(hSendKey, buf); + Menu_ModifyItem(globals.hSendKey, buf); } int flags; @@ -251,7 +247,7 @@ int OnPreBuildContactMenu(WPARAM w, LPARAM) } else flags = 0; - Menu_ModifyItem(hToggleEncryption, + Menu_ModifyItem(globals.hToggleEncryption, db_get_b(hContact, szGPGModuleName, "GPGEncryption", 0) ? L"Turn off GPG encryption" : L"Turn on GPG encryption", INVALID_HANDLE_VALUE, flags); mir_free(tmp); @@ -261,8 +257,6 @@ int OnPreBuildContactMenu(WPARAM w, LPARAM) list<wstring> transfers; -DWORD file_msg_state = -1; - int onProtoAck(WPARAM, LPARAM l) { ACKDATA *ack = (ACKDATA*)l; @@ -292,13 +286,13 @@ int onProtoAck(WPARAM, LPARAM l) } if (wcsstr(filename, L".gpg")) { //decrypt it //process encrypted file - if (!bFileTransfers && !bSameAction) { + if (!globals.bFileTransfers && !globals.bSameAction) { void ShowEncryptedFileMsgBox(); ShowEncryptedFileMsgBox(); } - if (!bFileTransfers && bSameAction) + if (!globals.bFileTransfers && globals.bSameAction) return 0; - if (file_msg_state < 1) + if (!globals.bDecryptFiles) return 0; HistoryLog(ack->hContact, db_event("Received encrypted file, trying to decrypt", 0, 0, 0)); if (!boost::filesystem::exists(f->tszCurrentFile)) @@ -317,7 +311,6 @@ int onProtoAck(WPARAM, LPARAM l) } cmd.push_back(file); boost::filesystem::remove(file); - extern wchar_t *password; { // password wchar_t *pass = nullptr; char *keyid = UniGetContactSettingUtf(ack->hContact, szGPGModuleName, "KeyID", ""); @@ -326,26 +319,26 @@ int onProtoAck(WPARAM, LPARAM l) dbsetting += keyid; dbsetting += "_Password"; pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), L""); - if (mir_wstrlen(pass) > 0 && bDebugLog) - debuglog << std::string(time_str() + ": info: found password in database for key ID: " + keyid + ", trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(ack->hContact, 0)) + " with password"); + if (mir_wstrlen(pass) > 0 && globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: found password in database for key ID: " + keyid + ", trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(ack->hContact, 0)) + " with password"); } else { pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", L""); - if (mir_wstrlen(pass) > 0 && bDebugLog) - debuglog << std::string(time_str() + ": info: found password for all keys in database, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(ack->hContact, 0)) + " with password"); + if (mir_wstrlen(pass) > 0 && globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: found password for all keys in database, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(ack->hContact, 0)) + " with password"); } if (mir_wstrlen(pass) > 0) { cmd.push_back(L"--passphrase"); cmd.push_back(pass); } - else if (password) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: found password in memory, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(ack->hContact, 0)) + " with password"); + else if (globals.password) { + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: found password in memory, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(ack->hContact, 0)) + " with password"); cmd.push_back(L"--passphrase"); - cmd.push_back(password); + cmd.push_back(globals.password); } - else if (bDebugLog) - debuglog << std::string(time_str() + ": info: passwords not found in database or memory, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(ack->hContact, 0)) + " with out password"); + else if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: passwords not found in database or memory, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(ack->hContact, 0)) + " with out password"); mir_free(pass); mir_free(keyid); } @@ -358,9 +351,9 @@ int onProtoAck(WPARAM, LPARAM l) if (!gpg_launcher(params, boost::posix_time::minutes(15))) return 0; while (out.find("public key decryption failed: bad passphrase") != string::npos) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: failed to decrypt messaage from " + toUTF8(pcli->pfnGetContactDisplayName(ack->hContact, 0)) + " password needed, trying to get one"); - if (_terminate) + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: failed to decrypt messaage from " + toUTF8(pcli->pfnGetContactDisplayName(ack->hContact, 0)) + " password needed, trying to get one"); + if (globals._terminate) break; { //save inkey id string::size_type s = out.find(" encrypted with "); @@ -373,16 +366,16 @@ int onProtoAck(WPARAM, LPARAM l) db_set_s(ack->hContact, szGPGModuleName, "InKeyID", out.substr(s, s2 - s).c_str()); } void ShowLoadKeyPasswordWindow(); - new_key_hcnt_mutex.lock(); - new_key_hcnt = ack->hContact; + globals.new_key_hcnt_mutex.lock(); + globals.new_key_hcnt = ack->hContact; ShowLoadKeyPasswordWindow(); std::vector<wstring> cmd2 = cmd; - if (password) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: found password in memory, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(ack->hContact, 0))); + if (globals.password) { + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: found password in memory, trying to decrypt message from " + toUTF8(pcli->pfnGetContactDisplayName(ack->hContact, 0))); std::vector<wstring> tmp; tmp.push_back(L"--passphrase"); - tmp.push_back(password); + tmp.push_back(globals.password); cmd2.insert(cmd2.begin(), tmp.begin(), tmp.end()); } out.clear(); @@ -485,7 +478,7 @@ std::wstring encrypt_file(MCONTACT hContact, wchar_t *filename) INT_PTR onSendFile(WPARAM w, LPARAM l) { CCSDATA *ccs = (CCSDATA*)l; - if (!bFileTransfers) + if (!globals.bFileTransfers) return Proto_ChainSend(w, ccs); if (isContactSecured(ccs->hContact)) { @@ -504,14 +497,15 @@ INT_PTR onSendFile(WPARAM w, LPARAM l) else { wchar_t *jid = UniGetContactSettingUtf(ccs->hContact, proto, "jid", L""); if (jid[0]) { - extern list <JabberAccount*> Accounts; - list<JabberAccount*>::iterator end = Accounts.end(); - for (list<JabberAccount*>::iterator p = Accounts.begin(); p != end; p++) { - wchar_t *caps = (*p)->getJabberInterface()->GetResourceFeatures(jid); - if (caps) { + for(auto p : globals.Accounts) + { + wchar_t *caps = p->getJabberInterface()->GetResourceFeatures(jid); + if (caps) + { supported_proto = true; wstring str; - for (int i = 0;; i++) { + for (int i = 0;; i++) + { str.push_back(caps[i]); if (caps[i] == '\0') if (caps[i + 1] == '\0') @@ -602,15 +596,14 @@ int ComboBoxAddStringUtf(HWND hCombo, const wchar_t *szString, DWORD data) int GetJabberInterface(WPARAM, LPARAM) //get interface for all jabber accounts, options later { - extern list <JabberAccount*> Accounts; void AddHandlers(); int count = 0; PROTOACCOUNT **accounts; Proto_EnumAccounts(&count, &accounts); list <JabberAccount*>::iterator p; - Accounts.clear(); - Accounts.push_back(new JabberAccount); - p = Accounts.begin(); + globals.Accounts.clear(); + globals.Accounts.push_back(new JabberAccount); + p = globals.Accounts.begin(); (*p)->setAccountNumber(0); for (int i = 0; i < count; i++) //get only jabber accounts from all accounts { @@ -628,11 +621,11 @@ int GetJabberInterface(WPARAM, LPARAM) //get interface for all jabber accounts, } (*p)->setAccountNumber(a); a++; - Accounts.push_back(new JabberAccount); + globals.Accounts.push_back(new JabberAccount); p++; } } - Accounts.pop_back(); + globals.Accounts.pop_back(); AddHandlers(); return 0; } @@ -675,14 +668,14 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void*) wstring::size_type p2 = data.find(L"-----END PGP MESSAGE-----"); wstring data2 = data.substr(p1, p2 - p1 - 2); strip_line_term(data2); - if(bDebugLog) - debuglog<<std::string(time_str() + ": jabber_api: attaching:\r\n\r\n" + toUTF8(data2) + "\n\n\t to outgoing xml"); + if(globals.bDebugLog) + globals.debuglog<<std::string(time_str() + ": jabber_api: attaching:\r\n\r\n" + toUTF8(data2) + "\n\n\t to outgoing xml"); HXML encrypted_data = xmlAddChild(node, L"x", data2.c_str()); xmlAddAttr(encrypted_data, L"xmlns", L"jabber:x:encrypted"); break; } - if (bPresenceSigning && nodename && wcsstr(nodename, L"status")) { + if (globals.bPresenceSigning && nodename && wcsstr(nodename, L"status")) { wchar_t *path_c = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", L""); wstring path_out = path_c; wstring file = toUTF16(get_random(10)); @@ -694,12 +687,11 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void*) f << toUTF8(str).c_str(); f.close(); if (!boost::filesystem::exists(path_out)) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: Failed to write prescense in file"); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: Failed to write prescense in file"); break; } - extern wchar_t *password; string out; DWORD code; std::vector<wstring> cmd; @@ -720,26 +712,26 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void*) dbsetting += inkeyid; dbsetting += "_Password"; pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), L""); - if (pass[0] && bDebugLog) - debuglog << std::string(time_str() + ": info: found password in database for key ID: " + inkeyid.get() + ", trying to encrypt message from self with password"); + if (pass[0] && globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: found password in database for key ID: " + inkeyid.get() + ", trying to encrypt message from self with password"); } else { pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", L""); - if (pass[0] && bDebugLog) - debuglog << std::string(time_str() + ": info: found password for all keys in database, trying to encrypt message from self with password"); + if (pass[0] && globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: found password for all keys in database, trying to encrypt message from self with password"); } if (pass[0]) { cmd.push_back(L"--passphrase"); cmd.push_back(pass.get()); } - else if (password) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: found password in memory, trying to encrypt message from self with password"); + else if (globals.password) { + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: found password in memory, trying to encrypt message from self with password"); cmd.push_back(L"--passphrase"); - cmd.push_back(password); + cmd.push_back(globals.password); } - else if (bDebugLog) - debuglog << std::string(time_str() + ": info: passwords not found in database or memory, trying to encrypt message from self with out password"); + else if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: passwords not found in database or memory, trying to encrypt message from self with out password"); } cmd.push_back(L"--local-user"); @@ -774,8 +766,8 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void*) boost::filesystem::remove(path_out); } if (data.empty()) { - if (bDebugLog) - debuglog << std::string(time_str() + ": info: Failed to read prescense sign from file"); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: Failed to read prescense sign from file"); break; } if (data.find(L"-----BEGIN PGP SIGNATURE-----") != wstring::npos && data.find(L"-----END PGP SIGNATURE-----") != wstring::npos) { @@ -869,8 +861,8 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface*, HXML node, void*) f.close(); if (!boost::filesystem::exists(path_out)) { // sign_file_mutex.unlock(); - if (bDebugLog) - debuglog << std::string(time_str() + ": info: Failed to write sign in file"); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": info: Failed to write sign in file"); return FALSE; } { //gpg @@ -901,14 +893,13 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface*, HXML node, void*) if (p1 != string::npos && p2 != string::npos) { MCONTACT hContact = NULL; { - extern list <JabberAccount*> Accounts; - list <JabberAccount*>::iterator p = Accounts.begin(); - for (unsigned int m = 0; m < Accounts.size(); m++, p++) { - if (!(*p)) - break; - hContact = (*p)->getJabberInterface()->ContactFromJID(xmlGetAttrValue(node, L"from")); + for(auto p : globals.Accounts) + { + /*if (!p) + break;*/ + hContact = p->getJabberInterface()->ContactFromJID(xmlGetAttrValue(node, L"from")); if (hContact) - hcontact_data[hContact].key_in_prescense = out.substr(p1, p2 - p1 - 1).c_str(); + globals.hcontact_data[hContact].key_in_prescense = out.substr(p1, p2 - p1 - 1).c_str(); } } } @@ -931,24 +922,23 @@ static JABBER_HANDLER_FUNC MessageHandler(IJabberInterface*, HXML, void*) void AddHandlers() { - extern list<JabberAccount*> Accounts; - list<JabberAccount*>::iterator end = Accounts.end(); - for (list<JabberAccount*>::iterator p = Accounts.begin(); p != end; p++) { - if (!(*p)) - break; - if ((*p)->getSendHandler() == INVALID_HANDLE_VALUE) - (*p)->setSendHandler((*p)->getJabberInterface()->AddSendHandler((JABBER_HANDLER_FUNC)SendHandler)); - if ((*p)->getPrescenseHandler() == INVALID_HANDLE_VALUE) - (*p)->setPrescenseHandler((*p)->getJabberInterface()->AddPresenceHandler((JABBER_HANDLER_FUNC)PrescenseHandler)); + for(auto p : globals.Accounts) + { + /*if (p) + break;*/ + if (p->getSendHandler() == INVALID_HANDLE_VALUE) + p->setSendHandler(p->getJabberInterface()->AddSendHandler((JABBER_HANDLER_FUNC)SendHandler)); + if (p->getPrescenseHandler() == INVALID_HANDLE_VALUE) + p->setPrescenseHandler(p->getJabberInterface()->AddPresenceHandler((JABBER_HANDLER_FUNC)PrescenseHandler)); // if((*p)->getMessageHandler() == INVALID_HANDLE_VALUE) // (*p)->setMessageHandler((*p)->getJabberInterface()->AddMessageHandler((JABBER_HANDLER_FUNC)MessageHandler, JABBER_MESSAGE_TYPE_ANY ,NULL,NULL)); - if (bAutoExchange) { - (*p)->getJabberInterface()->RegisterFeature(L"GPG_Key_Auto_Exchange:0", L"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(L"GPG_Key_Auto_Exchange:0\0\0"); + if (globals.bAutoExchange) { + p->getJabberInterface()->RegisterFeature(L"GPG_Key_Auto_Exchange:0", L"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(L"GPG_Key_Auto_Exchange:0\0\0"); } - if (bFileTransfers) { - (*p)->getJabberInterface()->RegisterFeature(L"GPG_Encrypted_FileTransfers:0", L"Indicates that gpg installed and configured to encrypt files (currently implemented in new_gpg plugin for Miranda IM and Miranda NG)"); - (*p)->getJabberInterface()->AddFeatures(L"GPG_Encrypted_FileTransfers:0\0\0"); + if (globals.bFileTransfers) { + p->getJabberInterface()->RegisterFeature(L"GPG_Encrypted_FileTransfers:0", L"Indicates that gpg installed and configured to encrypt files (currently implemented in new_gpg plugin for Miranda IM and Miranda NG)"); + p->getJabberInterface()->AddFeatures(L"GPG_Encrypted_FileTransfers:0\0\0"); } } } @@ -957,22 +947,22 @@ bool isContactSecured(MCONTACT hContact) { BYTE gpg_enc = db_get_b(hContact, szGPGModuleName, "GPGEncryption", 0); if (!gpg_enc) { - if (bDebugLog) - debuglog << std::string(time_str() + ": encryption is turned off for " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": encryption is turned off for " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); return false; } if (!db_mc_isMeta(hContact)) { wchar_t *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", L""); if (!key[0]) { mir_free(key); - if (bDebugLog) - debuglog << std::string(time_str() + ": encryption is turned off for " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": encryption is turned off for " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); return false; } mir_free(key); } - if (bDebugLog) - debuglog << std::string(time_str() + ": encryption is turned on for " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); + if (globals.bDebugLog) + globals.debuglog << std::string(time_str() + ": encryption is turned on for " + toUTF8(pcli->pfnGetContactDisplayName(hContact, 0))); return true; } @@ -1047,9 +1037,10 @@ bool isGPGValid() params.out = &out; params.code = &code; params.result = &result; - gpg_valid = true; + bool _gpg_valid = globals.gpg_valid; + globals.gpg_valid = true; gpg_launcher(params); - gpg_valid = false; + globals.gpg_valid = _gpg_valid; //TODO: check this string::size_type p1 = out.find("(GnuPG) "); if (p1 == string::npos) is_valid = false; @@ -1157,8 +1148,8 @@ string toUTF8(wstring str) utf8::utf16to8(str.begin(), str.end(), back_inserter(ustr)); } catch (const utf8::exception& e) { - if (bDebugLog) - debuglog << std::string("utf8cpp encoding exception: ") + (char*)e.what(); + if (globals.bDebugLog) + globals.debuglog << std::string("utf8cpp encoding exception: ") + (char*)e.what(); //TODO } return ustr; @@ -1175,8 +1166,8 @@ wstring toUTF16(string str) //convert as much as possible utf8::utf8to16(tmpstr.begin(), tmpstr.end(), back_inserter(ustr)); } catch (const utf8::exception& e) { - if (bDebugLog) - debuglog << std::string("utf8cpp decoding exception: ") + (char*)e.what(); + if (globals.bDebugLog) + globals.debuglog << std::string("utf8cpp decoding exception: ") + (char*)e.what(); //TODO } return ustr; @@ -1200,16 +1191,16 @@ void send_encrypted_msgs_thread(void *param) //char *key = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", ""); while (!isContactSecured(hContact)) boost::this_thread::sleep(boost::posix_time::seconds(1)); - if (!hcontact_data[hContact].msgs_to_send.empty()) { + if (!globals.hcontact_data[hContact].msgs_to_send.empty()) { boost::this_thread::sleep(boost::posix_time::seconds(1)); - list<string>::iterator end = hcontact_data[hContact].msgs_to_send.end(); + list<string>::iterator end = globals.hcontact_data[hContact].msgs_to_send.end(); extern std::list<HANDLE> sent_msgs; - for (list<string>::iterator p = hcontact_data[hContact].msgs_to_send.begin(); p != end; ++p) { + for (list<string>::iterator p = globals.hcontact_data[hContact].msgs_to_send.begin(); p != end; ++p) { sent_msgs.push_back((HANDLE)ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)p->c_str())); HistoryLog(hContact, db_event((char*)p->c_str(), 0, 0, DBEF_SENT)); boost::this_thread::sleep(boost::posix_time::seconds(1)); } - hcontact_data[hContact].msgs_to_send.clear(); + globals.hcontact_data[hContact].msgs_to_send.clear(); return; } else @@ -1790,55 +1781,13 @@ void strip_tags(std::wstring &str) { if (str.empty()) return; - boost::algorithm::erase_all(str, inopentag); - boost::algorithm::erase_all(str, inclosetag); - boost::algorithm::erase_all(str, outopentag); - boost::algorithm::erase_all(str, outclosetag); + boost::algorithm::erase_all(str, globals.inopentag); + boost::algorithm::erase_all(str, globals.inclosetag); + boost::algorithm::erase_all(str, globals.outopentag); + boost::algorithm::erase_all(str, globals.outclosetag); } -class CDlgEncryptedFileMsgBox : public CDlgBase -{ -public: - CDlgEncryptedFileMsgBox() : CDlgBase(hInst, IDD_ENCRYPTED_FILE_MSG_BOX), - chk_REMEMBER(this, IDC_REMEMBER), - btn_IGNORE(this, IDC_IGNORE), btn_DECRYPT(this, IDC_DECRYPT) - { - btn_IGNORE.OnClick = Callback(this, &CDlgEncryptedFileMsgBox::onClick_IGNORE); - btn_DECRYPT.OnClick = Callback(this, &CDlgEncryptedFileMsgBox::onClick_DECRYPT); - } - virtual void OnInitDialog() override - { - file_msg_state = -1; - } - virtual void OnDestroy() override - { - delete this; - } - void onClick_IGNORE(CCtrlButton*) - { - if (chk_REMEMBER.GetState()) - { - db_set_b(NULL, szGPGModuleName, "bSameAction", 1); - bSameAction = true; - } - this->Close(); - } - void onClick_DECRYPT(CCtrlButton*) - { - file_msg_state = 1; - if (chk_REMEMBER.GetState()) - { - db_set_b(NULL, szGPGModuleName, "bFileTransfers", 1); - bFileTransfers = true; - db_set_b(NULL, szGPGModuleName, "bSameAction", 0); - bSameAction = false; - } - this->Close(); - } -private: - CCtrlCheck chk_REMEMBER; - CCtrlButton btn_IGNORE, btn_DECRYPT; -}; + void ShowEncryptedFileMsgBox() @@ -1847,43 +1796,7 @@ void ShowEncryptedFileMsgBox() d->DoModal(); } -class CDlgExportKeysMsgBox : public CDlgBase -{ -public: - CDlgExportKeysMsgBox() : CDlgBase(hInst, IDD_EXPORT_TYPE), - btn_OK(this, IDC_OK), btn_CANCEL(this, IDC_CANCEL), - chk_PUBLIC(this, IDC_PUBLIC), chk_PRIVATE(this, IDC_PRIVATE), chk_ALL(this, IDC_ALL) - { - btn_OK.OnClick = Callback(this, &CDlgExportKeysMsgBox::onClick_OK); - btn_CANCEL.OnClick = Callback(this, &CDlgExportKeysMsgBox::onClick_CANCEL); - } - virtual void OnInitDialog() override - { - chk_PUBLIC.SetState(1); - } - virtual void OnDestroy() override - { - delete this; - } - void onClick_OK(CCtrlButton*) - { - if (chk_PUBLIC.GetState()) - ExportGpGKeysFunc(0); - else if (chk_PRIVATE.GetState()) - ExportGpGKeysFunc(1); - else if (chk_ALL.GetState()) - ExportGpGKeysFunc(2); - this->Close(); - } - void onClick_CANCEL(CCtrlButton*) - { - this->Close(); - } -private: - CCtrlButton btn_OK, btn_CANCEL; - CCtrlCheck chk_PUBLIC, chk_PRIVATE, chk_ALL; -}; void ShowExportKeysDlg() @@ -1892,86 +1805,7 @@ void ShowExportKeysDlg() d->Show(); } -class CDlgChangePasswdMsgBox : public CDlgBase //always modal -{ -public: - CDlgChangePasswdMsgBox() : CDlgBase(hInst, IDD_CHANGE_PASSWD), - btn_OK(this, ID_OK), - edit_NEW_PASSWD1(this, IDC_NEW_PASSWD1), edit_NEW_PASSWD2(this, IDC_NEW_PASSWD2), edit_OLD_PASSWD(this, IDC_OLD_PASSWD) - { - btn_OK.OnClick = Callback(this, &CDlgChangePasswdMsgBox::onClick_OK); - } - virtual void OnDestroy() override - { - delete this; - } - void onClick_OK(CCtrlButton*) - { - //TODO: show some prgress - { - if (mir_wstrcmp(edit_NEW_PASSWD1.GetText(), edit_NEW_PASSWD2.GetText())) - { - MessageBox(m_hwnd, TranslateT("New passwords do not match"), TranslateT("Error"), MB_OK); - return; - } - std::string old_pass, new_pass; - extern wchar_t key_id_global[17]; -// wchar_t buf[256] = { 0 }; - new_pass = toUTF8(edit_NEW_PASSWD1.GetText()); - old_pass = toUTF8(edit_OLD_PASSWD.GetText()); - bool old_pass_match = false; - wchar_t *pass = UniGetContactSettingUtf(NULL, szGPGModuleName, "szKeyPassword", L""); - if (!mir_wstrcmp(pass, edit_OLD_PASSWD.GetText())) - old_pass_match = true; - mir_free(pass); - - if (!old_pass_match) { - if (key_id_global[0]) { - string dbsetting = "szKey_"; - dbsetting += toUTF8(key_id_global); - dbsetting += "_Password"; - pass = UniGetContactSettingUtf(NULL, szGPGModuleName, dbsetting.c_str(), L""); - if (!mir_wstrcmp(pass, edit_OLD_PASSWD.GetText())) - old_pass_match = true; - mir_free(pass); - } - } - if (!old_pass_match) - if (MessageBox(m_hwnd, TranslateT("Old password does not match, you can continue, but GPG will reject wrong password.\nDo you want to continue?"), TranslateT("Error"), MB_YESNO) == IDNO) - return; - - std::vector<std::wstring> cmd; - string output; - DWORD exitcode; - cmd.push_back(L"--edit-key"); - cmd.push_back(key_id_global); - cmd.push_back(L"passwd"); - gpg_execution_params_pass params(cmd, old_pass, new_pass); - pxResult result; - params.out = &output; - params.code = &exitcode; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_passwd_change_thread, ¶ms)); - if (!gpg_thread.timed_join(boost::posix_time::minutes(10))) { - gpg_thread.~thread(); - if (params.child) - boost::process::terminate(*(params.child)); - if (bDebugLog) - debuglog << std::string(time_str() + ": GPG execution timed out, aborted"); - this->Close(); - return; - } - if (result == pxNotFound) - return; - } - this->Close(); - } -private: - CCtrlButton btn_OK; - CCtrlEdit edit_NEW_PASSWD1, edit_NEW_PASSWD2, edit_OLD_PASSWD; - -}; void ShowChangePasswdDlg() diff --git a/plugins/New_GPG/src/utilities.h b/plugins/New_GPG/src/utilities.h index 7c78cbfa0b..b14f50dd69 100644..100755 --- a/plugins/New_GPG/src/utilities.h +++ b/plugins/New_GPG/src/utilities.h @@ -1,4 +1,4 @@ -// Copyright © 2010-2012 sss +// Copyright © 2010-2017 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -16,6 +16,7 @@ #ifndef UTILITIES_H #define UTILITIES_H + wchar_t* __stdcall UniGetContactSettingUtf(MCONTACT hContact, const char *szModule,const char* szSetting, wchar_t* szDef); char* __stdcall UniGetContactSettingUtf(MCONTACT hContact, const char *szModule,const char* szSetting, char* szDef); void GetFilePath(wchar_t *WindowTittle, char *szSetting, wchar_t *szExt, wchar_t *szExtDesc); @@ -35,6 +36,7 @@ bool isContactHaveKey(MCONTACT hContact); bool isTabsrmmUsed(); bool isGPGKeyExist(); bool isGPGValid(); +void ExportGpGKeysFunc(int type); const bool StriStr(const char *str, const char *substr); string toUTF8(wstring str); wstring toUTF16(string str); |