diff options
author | Tobias Markmann <tm@ayena.de> | 2016-11-23 07:09:39 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-11-23 11:30:02 (GMT) |
commit | e405ff3561be3d3c0bd79d7d5173923a8828cf02 (patch) | |
tree | 9118ef838ebfaec1df90ec24761944b5d833774c /Swiften/Client | |
parent | 8a71b91be885652f37c5aab5e1ecf25af4599fbc (diff) | |
download | swift-e405ff3561be3d3c0bd79d7d5173923a8828cf02.zip swift-e405ff3561be3d3c0bd79d7d5173923a8828cf02.tar.bz2 |
Migrate remaining Swiften/Base/foreach.h use to range-based for loop
Test-Information:
Build on macOS 10.12.1 and all tests pass.
Change-Id: Iedaa3fa7e7672c77909fd0568bf30e9393cb87e0
Diffstat (limited to 'Swiften/Client')
-rw-r--r-- | Swiften/Client/BlockListImpl.cpp | 12 | ||||
-rw-r--r-- | Swiften/Client/CoreClient.cpp | 3 | ||||
-rw-r--r-- | Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp | 3 | ||||
-rw-r--r-- | Swiften/Client/XMLBeautifier.cpp | 3 |
4 files changed, 8 insertions, 13 deletions
diff --git a/Swiften/Client/BlockListImpl.cpp b/Swiften/Client/BlockListImpl.cpp index ebffff8..54dcdf5 100644 --- a/Swiften/Client/BlockListImpl.cpp +++ b/Swiften/Client/BlockListImpl.cpp @@ -1,74 +1,72 @@ /* - * Copyright (c) 2011-2015 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Client/BlockListImpl.h> #include <algorithm> -#include <Swiften/Base/foreach.h> - using namespace Swift; BlockListImpl::BlockListImpl() : state(Init) { } void BlockListImpl::setItems(const std::vector<JID>& newItems) { // JIDs which are in the current list but not in the new list, are removed. - foreach (const JID& jid, items) { + for (const auto& jid : items) { if (std::find(newItems.begin(), newItems.end(), jid) == newItems.end()) { onItemRemoved(jid); } } // JIDs which are in the new list but not in the current list, are added. - foreach (const JID& jid, newItems) { + for (const auto& jid : newItems) { if (std::find(items.begin(), items.end(), jid) == items.end()) { onItemAdded(jid); } } items = newItems; } void BlockListImpl::addItem(const JID& item) { if (std::find(items.begin(), items.end(), item) == items.end()) { items.push_back(item); onItemAdded(item); } } void BlockListImpl::removeItem(const JID& item) { size_t oldSize = items.size(); items.erase(std::remove(items.begin(), items.end(), item), items.end()); if (items.size() != oldSize) { onItemRemoved(item); } } void BlockListImpl::setState(State state) { if (this->state != state) { this->state = state; onStateChanged(); } } void BlockListImpl::addItems(const std::vector<JID>& items) { - foreach (const JID& item, items) { + for (const auto& item : items) { addItem(item); } } void BlockListImpl::removeItems(const std::vector<JID>& items) { std::vector<JID> itemsToRemove = items; - foreach (const JID& item, itemsToRemove) { + for (const auto& item : itemsToRemove) { removeItem(item); } } void BlockListImpl::removeAllItems() { removeItems(items); } diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp index c2f8fd7..3d75d8b 100644 --- a/Swiften/Client/CoreClient.cpp +++ b/Swiften/Client/CoreClient.cpp @@ -1,47 +1,46 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Client/CoreClient.h> #include <memory> #include <boost/bind.hpp> #include <boost/optional.hpp> #include <Swiften/Base/Algorithm.h> #include <Swiften/Base/IDGenerator.h> #include <Swiften/Base/Log.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Client/ClientSession.h> #include <Swiften/Client/ClientSessionStanzaChannel.h> #include <Swiften/Network/ChainedConnector.h> #include <Swiften/Network/DomainNameResolveError.h> #include <Swiften/Network/HTTPConnectProxiedConnectionFactory.h> #include <Swiften/Network/NetworkFactories.h> #include <Swiften/Network/ProxyProvider.h> #include <Swiften/Network/SOCKS5ProxiedConnectionFactory.h> #include <Swiften/Queries/IQRouter.h> #include <Swiften/Session/BOSHSessionStream.h> #include <Swiften/Session/BasicSessionStream.h> #include <Swiften/TLS/CertificateVerificationError.h> #include <Swiften/TLS/PKCS12Certificate.h> #include <Swiften/TLS/TLSError.h> namespace Swift { CoreClient::CoreClient(const JID& jid, const SafeByteArray& password, NetworkFactories* networkFactories) : jid_(jid), password_(password), networkFactories(networkFactories), disconnectRequested_(false), certificateTrustChecker(nullptr) { stanzaChannel_ = new ClientSessionStanzaChannel(); stanzaChannel_->onMessageReceived.connect(boost::bind(&CoreClient::handleMessageReceived, this, _1)); stanzaChannel_->onPresenceReceived.connect(boost::bind(&CoreClient::handlePresenceReceived, this, _1)); stanzaChannel_->onStanzaAcked.connect(boost::bind(&CoreClient::handleStanzaAcked, this, _1)); stanzaChannel_->onAvailableChanged.connect(boost::bind(&CoreClient::handleStanzaChannelAvailableChanged, this, _1)); iqRouter_ = new IQRouter(stanzaChannel_); iqRouter_->setJID(jid); } CoreClient::~CoreClient() { forceReset(); @@ -416,61 +415,61 @@ bool CoreClient::isAvailable() const { } bool CoreClient::getStreamManagementEnabled() const { return stanzaChannel_->getStreamManagementEnabled(); } bool CoreClient::isStreamEncrypted() const { return sessionStream_->isTLSEncrypted(); } StanzaChannel* CoreClient::getStanzaChannel() const { return stanzaChannel_; } const JID& CoreClient::getJID() const { if (session_) { return session_->getLocalJID(); } else { return jid_; } } void CoreClient::purgePassword() { safeClear(password_); } void CoreClient::resetConnector() { connector_->onConnectFinished.disconnect(boost::bind(&CoreClient::handleConnectorFinished, this, _1, _2)); connector_.reset(); - foreach(ConnectionFactory* f, proxyConnectionFactories) { + for (auto f : proxyConnectionFactories) { delete f; } proxyConnectionFactories.clear(); } void CoreClient::resetSession() { session_->onFinished.disconnect(boost::bind(&CoreClient::handleSessionFinished, this, _1)); session_->onNeedCredentials.disconnect(boost::bind(&CoreClient::handleNeedCredentials, this)); sessionStream_->onDataRead.disconnect(boost::bind(&CoreClient::handleDataRead, this, _1)); sessionStream_->onDataWritten.disconnect(boost::bind(&CoreClient::handleDataWritten, this, _1)); if (connection_) { connection_->disconnect(); } else if (std::dynamic_pointer_cast<BOSHSessionStream>(sessionStream_)) { sessionStream_->close(); } sessionStream_.reset(); connection_.reset(); } void CoreClient::forceReset() { if (connector_) { SWIFT_LOG(warning) << "Client not disconnected properly: Connector still active" << std::endl; resetConnector(); } if (sessionStream_ || connection_) { SWIFT_LOG(warning) << "Client not disconnected properly: Session still active" << std::endl; resetSession(); diff --git a/Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp b/Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp index aaf99e0..5d22cac 100644 --- a/Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp +++ b/Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp @@ -1,48 +1,47 @@ /* * Copyright (c) 2013 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <algorithm> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Client/ClientBlockListManager.h> #include <Swiften/Client/DummyStanzaChannel.h> #include <Swiften/Client/StanzaChannel.h> #include <Swiften/Elements/IQ.h> #include <Swiften/Queries/IQRouter.h> using namespace Swift; class ClientBlockListManagerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ClientBlockListManagerTest); CPPUNIT_TEST(testFetchBlockList); CPPUNIT_TEST(testBlockCommand); CPPUNIT_TEST(testUnblockCommand); CPPUNIT_TEST(testUnblockAllCommand); CPPUNIT_TEST_SUITE_END(); public: void setUp() { ownJID_ = JID("kev@wonderland.lit"); stanzaChannel_ = new DummyStanzaChannel(); iqRouter_ = new IQRouter(stanzaChannel_); iqRouter_->setJID(ownJID_); clientBlockListManager_ = new ClientBlockListManager(iqRouter_); } void testFetchBlockList() { std::vector<JID> blockJids; blockJids.push_back(JID("romeo@montague.net")); blockJids.push_back(JID("iago@shakespeare.lit")); helperInitialBlockListFetch(blockJids); @@ -144,52 +143,52 @@ class ClientBlockListManagerTest : public CppUnit::TestFixture { std::shared_ptr<UnblockPayload> pushPayload = std::make_shared<UnblockPayload>(); IQ::ref unblockPush = IQ::createRequest(IQ::Set, ownJID_, "push1", pushPayload); stanzaChannel_->sendIQ(unblockPush); stanzaChannel_->onIQReceived(unblockPush); CPPUNIT_ASSERT_EQUAL(true, clientBlockListManager_->getBlockList()->getItems().empty()); } void tearDown() { delete clientBlockListManager_; delete iqRouter_; delete stanzaChannel_; } private: void helperInitialBlockListFetch(const std::vector<JID>& blockedJids) { std::shared_ptr<BlockList> blockList = clientBlockListManager_->requestBlockList(); CPPUNIT_ASSERT(blockList); // check for IQ request IQ::ref request = stanzaChannel_->getStanzaAtIndex<IQ>(0); CPPUNIT_ASSERT(request.get() != nullptr); std::shared_ptr<BlockListPayload> requestPayload = request->getPayload<BlockListPayload>(); CPPUNIT_ASSERT(requestPayload.get() != nullptr); CPPUNIT_ASSERT_EQUAL(BlockList::Requesting, blockList->getState()); CPPUNIT_ASSERT_EQUAL(BlockList::Requesting, clientBlockListManager_->getBlockList()->getState()); // build IQ response std::shared_ptr<BlockListPayload> responsePayload = std::make_shared<BlockListPayload>(); - foreach(const JID& jid, blockedJids) { + for (const auto& jid : blockedJids) { responsePayload->addItem(jid); } IQ::ref response = IQ::createResult(ownJID_, JID(), request->getID(), responsePayload); stanzaChannel_->sendIQ(response); stanzaChannel_->onIQReceived(response); CPPUNIT_ASSERT_EQUAL(BlockList::Available, clientBlockListManager_->getBlockList()->getState()); CPPUNIT_ASSERT(responsePayload->getItems() == clientBlockListManager_->getBlockList()->getItems()); } private: JID ownJID_; IQRouter* iqRouter_; DummyStanzaChannel* stanzaChannel_; ClientBlockListManager* clientBlockListManager_; }; CPPUNIT_TEST_SUITE_REGISTRATION(ClientBlockListManagerTest); diff --git a/Swiften/Client/XMLBeautifier.cpp b/Swiften/Client/XMLBeautifier.cpp index 9e9c4c5..e2cd58e 100644 --- a/Swiften/Client/XMLBeautifier.cpp +++ b/Swiften/Client/XMLBeautifier.cpp @@ -1,49 +1,48 @@ /* * Copyright (c) 2011 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Client/XMLBeautifier.h> #include <sstream> #include <stack> #include <Swiften/Base/Log.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Parser/PlatformXMLParserFactory.h> namespace Swift { XMLBeautifier::XMLBeautifier(bool indention, bool coloring) : doIndention(indention), doColoring(coloring), intLevel(0), parser(nullptr), lastWasStepDown(false) { factory = new PlatformXMLParserFactory(); } XMLBeautifier::~XMLBeautifier() { delete factory; } std::string XMLBeautifier::beautify(const std::string &text) { parser = factory->createXMLParser(this); intLevel = 0; buffer.str(std::string()); parser->parse(text); delete parser; return buffer.str(); } void XMLBeautifier::indent() { for (int i = 0; i < intLevel; ++i) { buffer << " "; } } // all bold but reset // static const char colorBlue[] = "\x1b[01;34m"; static const char colorCyan[] = "\x1b[01;36m"; @@ -72,61 +71,61 @@ std::string XMLBeautifier::styleNamespace(const std::string& text) const { } std::string XMLBeautifier::styleAttribute(const std::string& text) const { std::string result; result += colorGreen; result += text; result += colorReset; return result; } std::string XMLBeautifier::styleValue(const std::string& text) const { std::string result; result += colorCyan; result += text; result += colorReset; return result; } void XMLBeautifier::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (doIndention) { if (intLevel) buffer << std::endl; } indent(); buffer << "<" << (doColoring ? styleTag(element) : element); if (!ns.empty() && (!parentNSs.empty() && parentNSs.top() != ns)) { buffer << " "; buffer << (doColoring ? styleAttribute("xmlns") : "xmlns"); buffer << "="; buffer << "\"" << (doColoring ? styleNamespace(ns) : ns) << "\""; } if (!attributes.getEntries().empty()) { - foreach(AttributeMap::Entry entry, attributes.getEntries()) { + for (const auto& entry : attributes.getEntries()) { buffer << " "; buffer << (doColoring ? styleAttribute(entry.getAttribute().getName()) : entry.getAttribute().getName()); buffer << "="; buffer << "\"" << (doColoring ? styleValue(entry.getValue()) : entry.getValue()) << "\""; } } buffer << ">"; ++intLevel; lastWasStepDown = false; parentNSs.push(ns); } void XMLBeautifier::handleEndElement(const std::string& element, const std::string& /* ns */) { --intLevel; parentNSs.pop(); if (/*hadCDATA.top() ||*/ lastWasStepDown) { if (doIndention) { buffer << std::endl; } indent(); } buffer << "</" << (doColoring ? styleTag(element) : element) << ">"; lastWasStepDown = true; } void XMLBeautifier::handleCharacterData(const std::string& data) { buffer << data; lastWasStepDown = false; } |