diff options
author | George Hazan <ghazan@miranda.im> | 2020-06-10 18:41:08 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-06-10 18:41:15 +0300 |
commit | f435c6b618bfded57d65bb46aa91d94f2cf404dd (patch) | |
tree | 844d2acf3df595510f9837a563e865dddec143e8 /plugins/New_GPG/src/utilities.cpp | |
parent | 073d217dffa8906d0024d3d8c471b76fabf79f95 (diff) |
fixes #2441 (New_GPG: miranda-ng dies after switching the plugin off)
Diffstat (limited to 'plugins/New_GPG/src/utilities.cpp')
-rwxr-xr-x | plugins/New_GPG/src/utilities.cpp | 88 |
1 files changed, 42 insertions, 46 deletions
diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp index a9a885901a..e89d01eff1 100755 --- a/plugins/New_GPG/src/utilities.cpp +++ b/plugins/New_GPG/src/utilities.cpp @@ -506,39 +506,6 @@ int ComboBoxAddStringUtf(HWND hCombo, const wchar_t *szString, DWORD data) } -int GetJabberInterface(WPARAM, LPARAM) //get interface for all jabber accounts, options later -{ - void AddHandlers(); - - list <JabberAccount*>::iterator p; - globals.Accounts.clear(); - globals.Accounts.push_back(new JabberAccount); - p = globals.Accounts.begin(); - (*p)->setAccountNumber(0); - for (auto &pa : Accounts()) { - IJabberInterface *JIftmp = getJabberApi(pa->szModuleName); - int a = 0; - if (JIftmp) { - (*p)->setJabberInterface(JIftmp); - if (pa->tszAccountName) { - wchar_t* tmp = mir_wstrdup(pa->tszAccountName); - (*p)->setAccountName(tmp); - } - else { - wchar_t *tmp = mir_a2u(pa->szModuleName); - (*p)->setAccountName(tmp); - } - (*p)->setAccountNumber(a); - a++; - globals.Accounts.push_back(new JabberAccount); - p++; - } - } - globals.Accounts.pop_back(); - AddHandlers(); - return 0; -} - static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, TiXmlElement *node, void*) { TiXmlDocument *pDoc = node->GetDocument(); @@ -773,25 +740,54 @@ static JABBER_HANDLER_FUNC MessageHandler(IJabberInterface*, TiXmlElement*, void return FALSE; } -void AddHandlers() +int GetJabberInterface(WPARAM, LPARAM) //get interface for all jabber accounts, options later { - 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->getPresenceHandler() == INVALID_HANDLE_VALUE) - p->setPresenceHandler(p->getJabberInterface()->AddPresenceHandler((JABBER_HANDLER_FUNC)PresenceHandler)); + list <JabberAccount *>::iterator p; + globals.Accounts.clear(); + + int accNum = 0; + for (auto &pa : Accounts()) { + IJabberInterface *pApi = getJabberApi(pa->szModuleName); + if (pApi == nullptr) + continue; + + auto *pAcc = new JabberAccount(); + pAcc->setJabberInterface(pApi); + if (pa->tszAccountName) + pAcc->setAccountName(mir_wstrdup(pa->tszAccountName)); + else + pAcc->setAccountName(mir_a2u(pa->szModuleName)); + + pAcc->setAccountNumber(accNum++); + pAcc->setSendHandler(pApi->AddSendHandler((JABBER_HANDLER_FUNC)SendHandler)); + pAcc->setPresenceHandler(pApi->AddPresenceHandler((JABBER_HANDLER_FUNC)PresenceHandler)); if (g_plugin.bAutoExchange) { - p->getJabberInterface()->RegisterFeature("GPG_Key_Auto_Exchange:0", "Indicates that gpg installed and configured to public key auto exchange (currently implemented in new_gpg plugin for Miranda IM and Miranda NG)"); - p->getJabberInterface()->AddFeatures("GPG_Key_Auto_Exchange:0\0\0"); + pApi->RegisterFeature("GPG_Key_Auto_Exchange:0", "Indicates that gpg installed and configured to public key auto exchange (currently implemented in new_gpg plugin for Miranda IM and Miranda NG)"); + pApi->AddFeatures("GPG_Key_Auto_Exchange:0\0\0"); } if (g_plugin.bFileTransfers) { - p->getJabberInterface()->RegisterFeature("GPG_Encrypted_FileTransfers:0", "Indicates that gpg installed and configured to encrypt files (currently implemented in new_gpg plugin for Miranda IM and Miranda NG)"); - p->getJabberInterface()->AddFeatures("GPG_Encrypted_FileTransfers:0\0\0"); + pApi->RegisterFeature("GPG_Encrypted_FileTransfers:0", "Indicates that gpg installed and configured to encrypt files (currently implemented in new_gpg plugin for Miranda IM and Miranda NG)"); + pApi->AddFeatures("GPG_Encrypted_FileTransfers:0\0\0"); } + + globals.Accounts.push_back(pAcc); + } + + return 0; +} + +void RemoveHandlers() +{ + for (auto &it : globals.Accounts) { + auto *pApi = it->getJabberInterface(); + if (pApi == nullptr) + continue; + + pApi->RemoveHandler(it->getMessageHandler()); + pApi->RemoveHandler(it->getPresenceHandler()); + pApi->RemoveFeatures("GPG_Encrypted_FileTransfers:0\0\0"); + pApi->RemoveFeatures("GPG_Key_Auto_Exchange:0\0\0"); } } |