From 69ca360bb627c4317a7d3b16d74880dec58a4bf4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 10 Sep 2020 13:51:43 +0300 Subject: fixes #2565 (Jabber: privacy lists editor allows to remove active/delete list) --- protocols/JabberG/src/jabber_privacy.cpp | 137 +++++++++++++++++-------------- protocols/JabberG/src/jabber_privacy.h | 3 +- 2 files changed, 76 insertions(+), 64 deletions(-) (limited to 'protocols/JabberG') diff --git a/protocols/JabberG/src/jabber_privacy.cpp b/protocols/JabberG/src/jabber_privacy.cpp index f7936aff28..0debc25124 100644 --- a/protocols/JabberG/src/jabber_privacy.cpp +++ b/protocols/JabberG/src/jabber_privacy.cpp @@ -558,11 +558,11 @@ class CJabberDlgPrivacyLists : public CJabberDlgBase LIST newJids; - bool bChanged; + bool bChanged = false; - CPrivacyList *pList; + CPrivacyList *pList = nullptr; - TCLCInfo() : newJids(1, TJidData::cmp), bChanged(false), pList(nullptr) {} + TCLCInfo() : newJids(1, TJidData::cmp) {} ~TCLCInfo() { for (auto &it : newJids) { @@ -1774,10 +1774,9 @@ public: CPrivacyList *pList = GetSelectedList(m_hwnd); if (pList) { char *szListName = pList->GetListName(); - if ((m_proto->m_privacyListManager.GetActiveListName() && !mir_strcmp(szListName, m_proto->m_privacyListManager.GetActiveListName())) || - (m_proto->m_privacyListManager.GetDefaultListName() && !mir_strcmp(szListName, m_proto->m_privacyListManager.GetDefaultListName()))) { + if (!mir_strcmp(szListName, m_proto->m_privacyListManager.GetActiveListName()) || !mir_strcmp(szListName, m_proto->m_privacyListManager.GetDefaultListName())) { lck.unlock(); - MessageBox(m_hwnd, TranslateT("Can't remove active or default list"), TranslateT("Sorry"), MB_OK | MB_ICONSTOP); + MessageBox(m_hwnd, TranslateT("Can't remove active or default list"), m_proto->m_tszUserName, MB_OK | MB_ICONSTOP); return; } pList->SetDeleted(); @@ -1794,69 +1793,83 @@ public: return; } { - mir_cslock lck(m_proto->m_privacyListManager.m_cs); + mir_cslockfull lck(m_proto->m_privacyListManager.m_cs); if (IsWindowVisible(m_clcClist.GetHwnd())) CListBuildList(clc_info.pList); + for (auto *pList = m_proto->m_privacyListManager.GetFirstList(); pList; pList = pList->GetNext()) { + if (!pList->IsModified()) + continue; + + if (!pList->GetFirstRule()) { + auto *szListName = pList->GetListName(); + if (!mir_strcmp(szListName, m_proto->m_privacyListManager.GetActiveListName()) || !mir_strcmp(szListName, m_proto->m_privacyListManager.GetDefaultListName())) { + lck.unlock(); + MessageBox(m_hwnd, TranslateT("Can't remove active or default list"), m_proto->m_tszUserName, MB_OK | MB_ICONSTOP); + return; + } + } + } + CPrivacyListModifyUserParam *pUserData = nullptr; - CPrivacyList *pList = m_proto->m_privacyListManager.GetFirstList(); - while (pList) { - if (pList->IsModified()) { - CPrivacyListRule* pRule = pList->GetFirstRule(); - if (!pRule) - pList->SetDeleted(); - if (pList->IsDeleted()) { - pList->RemoveAllRules(); - pRule = nullptr; + for (auto *pList = m_proto->m_privacyListManager.GetFirstList(); pList; pList = pList->GetNext()) { + if (!pList->IsModified()) + continue; + + CPrivacyListRule* pRule = pList->GetFirstRule(); + if (!pRule) + pList->SetDeleted(); + + if (pList->IsDeleted()) { + pList->RemoveAllRules(); + pRule = nullptr; + } + pList->SetModified(FALSE); + + if (!pUserData) + pUserData = new CPrivacyListModifyUserParam(); + + pUserData->m_dwCount++; + + XmlNodeIq iq(m_proto->AddIQ(&CJabberProto::OnIqResultPrivacyListModify, JABBER_IQ_TYPE_SET, nullptr, pUserData)); + TiXmlElement *query = iq << XQUERY(JABBER_FEAT_PRIVACY_LISTS); + TiXmlElement *listTag = query << XCHILD("list") << XATTR("name", pList->GetListName()); + + while (pRule) { + TiXmlElement *itemTag = listTag << XCHILD("item"); + switch (pRule->GetType()) { + case Jid: + itemTag << XATTR("type", "jid"); + break; + case Group: + itemTag << XATTR("type", "group"); + break; + case Subscription: + itemTag << XATTR("type", "subscription"); + break; } - pList->SetModified(FALSE); - - if (!pUserData) - pUserData = new CPrivacyListModifyUserParam(); - - pUserData->m_dwCount++; - - XmlNodeIq iq(m_proto->AddIQ(&CJabberProto::OnIqResultPrivacyListModify, JABBER_IQ_TYPE_SET, nullptr, pUserData)); - TiXmlElement *query = iq << XQUERY(JABBER_FEAT_PRIVACY_LISTS); - TiXmlElement *listTag = query << XCHILD("list") << XATTR("name", pList->GetListName()); - - while (pRule) { - TiXmlElement *itemTag = listTag << XCHILD("item"); - switch (pRule->GetType()) { - case Jid: - itemTag << XATTR("type", "jid"); - break; - case Group: - itemTag << XATTR("type", "group"); - break; - case Subscription: - itemTag << XATTR("type", "subscription"); - break; - } - if (pRule->GetType() != Else) - itemTag << XATTR("value", pRule->GetValue()); - if (pRule->GetAction()) - itemTag << XATTR("action", "allow"); - else - itemTag << XATTR("action", "deny"); - itemTag << XATTRI("order", pRule->GetOrder()); - DWORD dwPackets = pRule->GetPackets(); - if (dwPackets != JABBER_PL_RULE_TYPE_ALL) { - if (dwPackets & JABBER_PL_RULE_TYPE_IQ) - itemTag << XCHILD("iq"); - if (dwPackets & JABBER_PL_RULE_TYPE_PRESENCE_IN) - itemTag << XCHILD("presence-in"); - if (dwPackets & JABBER_PL_RULE_TYPE_PRESENCE_OUT) - itemTag << XCHILD("presence-out"); - if (dwPackets & JABBER_PL_RULE_TYPE_MESSAGE) - itemTag << XCHILD("message"); - } - pRule = pRule->GetNext(); + if (pRule->GetType() != Else) + itemTag << XATTR("value", pRule->GetValue()); + if (pRule->GetAction()) + itemTag << XATTR("action", "allow"); + else + itemTag << XATTR("action", "deny"); + itemTag << XATTRI("order", pRule->GetOrder()); + DWORD dwPackets = pRule->GetPackets(); + if (dwPackets != JABBER_PL_RULE_TYPE_ALL) { + if (dwPackets & JABBER_PL_RULE_TYPE_IQ) + itemTag << XCHILD("iq"); + if (dwPackets & JABBER_PL_RULE_TYPE_PRESENCE_IN) + itemTag << XCHILD("presence-in"); + if (dwPackets & JABBER_PL_RULE_TYPE_PRESENCE_OUT) + itemTag << XCHILD("presence-out"); + if (dwPackets & JABBER_PL_RULE_TYPE_MESSAGE) + itemTag << XCHILD("message"); } - - m_proto->m_ThreadInfo->send(iq); + pRule = pRule->GetNext(); } - pList = pList->GetNext(); + + m_proto->m_ThreadInfo->send(iq); } } diff --git a/protocols/JabberG/src/jabber_privacy.h b/protocols/JabberG/src/jabber_privacy.h index 44dff9b022..bd92a7fff6 100644 --- a/protocols/JabberG/src/jabber_privacy.h +++ b/protocols/JabberG/src/jabber_privacy.h @@ -168,8 +168,7 @@ public: void RemoveAllRules() { - if (m_pRules) - delete m_pRules; + delete m_pRules; m_pRules = nullptr; } -- cgit v1.2.3