diff options
Diffstat (limited to 'Swiften/Parser')
12 files changed, 16 insertions, 32 deletions
diff --git a/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp b/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp index 8a0ecd2..405c593 100644 --- a/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp +++ b/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp @@ -1,42 +1,40 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/BytestreamsParser.h> #include <boost/lexical_cast.hpp> -#include <Swiften/Base/foreach.h> - namespace Swift { BytestreamsParser::BytestreamsParser() : level(TopLevel) { } BytestreamsParser::~BytestreamsParser() { } void BytestreamsParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { if (level == TopLevel) { getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); } else if (level == PayloadLevel) { if (element == "streamhost") { try { getPayloadInternal()->addStreamHost(Bytestreams::StreamHost(attributes.getAttribute("host"), JID(attributes.getAttribute("jid")), boost::lexical_cast<int>(attributes.getAttribute("port")))); } catch (boost::bad_lexical_cast&) { } } else if (element == "streamhost-used") { getPayloadInternal()->setUsedStreamHost(JID(attributes.getAttribute("jid"))); } } ++level; } void BytestreamsParser::handleEndElement(const std::string&, const std::string&) { --level; } diff --git a/Swiften/Parser/PayloadParsers/FormParser.cpp b/Swiften/Parser/PayloadParsers/FormParser.cpp index 5ea75c5..dff45df 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.cpp +++ b/Swiften/Parser/PayloadParsers/FormParser.cpp @@ -1,41 +1,39 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/FormParser.h> #include <map> -#include <Swiften/Base/foreach.h> - namespace Swift { FormParser::FormParser() : level_(TopLevel), parsingItem_(false), parsingReported_(false), parsingOption_(false), hasReportedRef_(false){ } void FormParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { if (level_ == TopLevel) { std::string type = attributes.getAttribute("type"); if (type == "form") { getPayloadInternal()->setType(Form::FormType); } else if (type == "submit") { getPayloadInternal()->setType(Form::SubmitType); } else if (type == "cancel") { getPayloadInternal()->setType(Form::CancelType); } else if (type == "result") { getPayloadInternal()->setType(Form::ResultType); } } else if (level_ == PayloadLevel) { if (element == "title") { currentText_.clear(); } else if (element == "instructions") { currentText_.clear(); } else if (element == "reported") { parsingReported_ = true; @@ -163,69 +161,69 @@ void FormParser::handleEndElement(const std::string& element, const std::string& else if (currentField_) { if (element == "required") { currentField_->setRequired(true); } else if (element == "desc") { currentField_->setDescription(currentText_); } else if (element == "option") { currentField_->addOption(FormField::Option(currentOptionLabel_, currentOptionValue_)); parsingOption_ = false; } else if (element == "value") { if (parsingOption_) { currentOptionValue_ = currentText_; } else { currentField_->addValue(currentText_); } } } if (level_ >= PayloadLevel && currentField_) { if (element == "field") { if (parsingReported_) { getPayloadInternal()->addReportedField(currentField_); } else if (parsingItem_) { currentFields_.push_back(currentField_); } else { if (currentPages_.size() > 0) { - foreach (std::shared_ptr<FormPage> page, currentPages_) { - foreach (std::string pageRef, page->getFieldRefs()) { + for (const auto& page : currentPages_) { + for (const auto& pageRef : page->getFieldRefs()) { if (pageRef == currentField_->getName()) { page->addField(currentField_); } } } - foreach (std::shared_ptr<FormSection> section, currentSections_) { - foreach (std::string sectionRef, section->getFieldRefs()) { + for (const auto& section : currentSections_) { + for (const auto& sectionRef : section->getFieldRefs()) { if (sectionRef == currentField_->getName()) { section->addField(currentField_); } } } } else { getPayloadInternal()->addField(currentField_); } } currentField_.reset(); } } if (level_ > PayloadLevel) { if (element == "section") { if (sectionStack_.size() > 1) { // Add the section at the top of the stack to the level below sectionStack_.at(sectionStack_.size()-2)->addChildSection(sectionStack_.at(sectionStack_.size()-1)); sectionStack_.pop_back(); } else if (sectionStack_.size() == 1) { // Add the remaining section on the stack to its parent page currentPage_->addChildSection(sectionStack_.at(sectionStack_.size()-1)); sectionStack_.pop_back(); } } if (currentReportedRef_ && !hasReportedRef_) { if (sectionStack_.size() > 0) { sectionStack_.at(sectionStack_.size()-1)->addReportedRef(currentReportedRef_); } else if (currentPage_) { currentPage_->addReportedRef(currentReportedRef_); diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index a231397..b67556e 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -1,39 +1,38 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Elements/BlockListPayload.h> #include <Swiften/Elements/BlockPayload.h> #include <Swiften/Elements/UnblockPayload.h> #include <Swiften/Parser/GenericPayloadParser.h> #include <Swiften/Parser/GenericPayloadParserFactory.h> #include <Swiften/Parser/GenericPayloadParserFactory2.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/BlockParser.h> #include <Swiften/Parser/PayloadParsers/BodyParser.h> #include <Swiften/Parser/PayloadParsers/BytestreamsParser.h> #include <Swiften/Parser/PayloadParsers/CapsInfoParser.h> #include <Swiften/Parser/PayloadParsers/CarbonsDisableParser.h> #include <Swiften/Parser/PayloadParsers/CarbonsEnableParser.h> #include <Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h> #include <Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h> #include <Swiften/Parser/PayloadParsers/CarbonsSentParser.h> #include <Swiften/Parser/PayloadParsers/ChatStateParserFactory.h> #include <Swiften/Parser/PayloadParsers/CommandParser.h> #include <Swiften/Parser/PayloadParsers/DelayParser.h> #include <Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h> #include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h> #include <Swiften/Parser/PayloadParsers/DiscoInfoParser.h> #include <Swiften/Parser/PayloadParsers/DiscoItemsParser.h> #include <Swiften/Parser/PayloadParsers/ErrorParser.h> #include <Swiften/Parser/PayloadParsers/ErrorParserFactory.h> #include <Swiften/Parser/PayloadParsers/FormParserFactory.h> #include <Swiften/Parser/PayloadParsers/ForwardedParser.h> #include <Swiften/Parser/PayloadParsers/IBBParser.h> #include <Swiften/Parser/PayloadParsers/IdleParser.h> #include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h> @@ -140,46 +139,46 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(std::make_shared<JingleContentPayloadParserFactory>(this)); factories_.push_back(std::make_shared<GenericPayloadParserFactory<JingleIBBTransportMethodPayloadParser> >("transport", "urn:xmpp:jingle:transports:ibb:1")); factories_.push_back(std::make_shared<GenericPayloadParserFactory<JingleS5BTransportMethodPayloadParser> >("transport", "urn:xmpp:jingle:transports:s5b:1")); factories_.push_back(std::make_shared<JingleFileTransferDescriptionParserFactory>(this)); factories_.push_back(std::make_shared<GenericPayloadParserFactory<StreamInitiationFileInfoParser> >("file", "http://jabber.org/protocol/si/profile/file-transfer")); factories_.push_back(std::make_shared<GenericPayloadParserFactory<JingleFileTransferFileInfoParser> >("file", "urn:xmpp:jingle:apps:file-transfer:4")); factories_.push_back(std::make_shared<GenericPayloadParserFactory<JingleFileTransferHashParser> >("checksum")); factories_.push_back(std::make_shared<GenericPayloadParserFactory<S5BProxyRequestParser> >("query", "http://jabber.org/protocol/bytestreams")); factories_.push_back(std::make_shared<GenericPayloadParserFactory<WhiteboardParser> >("wb", "http://swift.im/whiteboard")); factories_.push_back(std::make_shared<GenericPayloadParserFactory<UserLocationParser> >("geoloc", "http://jabber.org/protocol/geoloc")); factories_.push_back(std::make_shared<GenericPayloadParserFactory<UserTuneParser> >("tune", "http://jabber.org/protocol/tune")); factories_.push_back(std::make_shared<DeliveryReceiptParserFactory>()); factories_.push_back(std::make_shared<DeliveryReceiptRequestParserFactory>()); factories_.push_back(std::make_shared<GenericPayloadParserFactory<IdleParser> >("idle", "urn:xmpp:idle:1")); factories_.push_back(std::make_shared<GenericPayloadParserFactory2<PubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub", this)); factories_.push_back(std::make_shared<GenericPayloadParserFactory2<PubSubOwnerPubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub#owner", this)); factories_.push_back(std::make_shared<GenericPayloadParserFactory2<PubSubEventParser> >("event", "http://jabber.org/protocol/pubsub#event", this)); factories_.push_back(std::make_shared<PubSubErrorParserFactory>()); factories_.push_back(std::make_shared<GenericPayloadParserFactory<ResultSetParser> >("set", "http://jabber.org/protocol/rsm")); factories_.push_back(std::make_shared<GenericPayloadParserFactory2<ForwardedParser> >("forwarded", "urn:xmpp:forward:0", this)); factories_.push_back(std::make_shared<GenericPayloadParserFactory2<MAMResultParser> >("result", "urn:xmpp:mam:0", this)); factories_.push_back(std::make_shared<GenericPayloadParserFactory<MAMQueryParser> >("query", "urn:xmpp:mam:0")); factories_.push_back(std::make_shared<GenericPayloadParserFactory<MAMFinParser> >("fin", "urn:xmpp:mam:0")); factories_.push_back(std::make_shared<GenericPayloadParserFactory2<IsodeIQDelegationParser> >("delegate", "http://isode.com/iq_delegation", this)); factories_.push_back(std::make_shared<GenericPayloadParserFactory<CarbonsEnableParser> >("enable", "urn:xmpp:carbons:2")); factories_.push_back(std::make_shared<GenericPayloadParserFactory<CarbonsDisableParser> >("disable", "urn:xmpp:carbons:2")); factories_.push_back(std::make_shared<GenericPayloadParserFactory2<CarbonsReceivedParser> >("received", "urn:xmpp:carbons:2", this)); factories_.push_back(std::make_shared<GenericPayloadParserFactory2<CarbonsSentParser> >("sent", "urn:xmpp:carbons:2", this)); factories_.push_back(std::make_shared<GenericPayloadParserFactory<CarbonsPrivateParser> >("private", "urn:xmpp:carbons:2")); - foreach(std::shared_ptr<PayloadParserFactory> factory, factories_) { + for (auto& factory : factories_) { addFactory(factory.get()); } defaultFactory_ = new RawXMLPayloadParserFactory(); setDefaultFactory(defaultFactory_); } FullPayloadParserFactoryCollection::~FullPayloadParserFactoryCollection() { setDefaultFactory(nullptr); delete defaultFactory_; - foreach(std::shared_ptr<PayloadParserFactory> factory, factories_) { + for (auto& factory : factories_) { removeFactory(factory.get()); } } } diff --git a/Swiften/Parser/PayloadParsers/IBBParser.cpp b/Swiften/Parser/PayloadParsers/IBBParser.cpp index 4a6b841..9b6babc 100644 --- a/Swiften/Parser/PayloadParsers/IBBParser.cpp +++ b/Swiften/Parser/PayloadParsers/IBBParser.cpp @@ -1,41 +1,40 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/IBBParser.h> #include <boost/lexical_cast.hpp> -#include <Swiften/Base/foreach.h> #include <Swiften/StringCodecs/Base64.h> namespace Swift { IBBParser::IBBParser() : level(TopLevel) { } IBBParser::~IBBParser() { } void IBBParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { if (level == TopLevel) { if (element == "data") { getPayloadInternal()->setAction(IBB::Data); getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); try { getPayloadInternal()->setSequenceNumber(boost::lexical_cast<int>(attributes.getAttribute("seq"))); } catch (boost::bad_lexical_cast&) { } } else if (element == "open") { getPayloadInternal()->setAction(IBB::Open); getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); if (attributes.getAttribute("stanza") == "message") { getPayloadInternal()->setStanzaType(IBB::MessageStanza); } else { getPayloadInternal()->setStanzaType(IBB::IQStanza); } diff --git a/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp index 1fbff1c..bac2a78 100644 --- a/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp @@ -1,23 +1,22 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h> #include <boost/lexical_cast.hpp> -#include <Swiften/Base/foreach.h> #include <Swiften/Elements/MUCOccupant.h> namespace Swift { void MUCAdminPayloadParser::handleTree(ParserElement::ref root) { - foreach (ParserElement::ref itemElement, root->getChildren("item", "http://jabber.org/protocol/muc#admin")) { + for (const auto& itemElement : root->getChildren("item", "http://jabber.org/protocol/muc#admin")) { MUCItem item = MUCItemParser::itemFromTree(itemElement); getPayloadInternal()->addItem(item); } } } diff --git a/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.cpp index 95ff8c5..46bc9c5 100644 --- a/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.cpp @@ -1,22 +1,20 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h> -#include <Swiften/Base/foreach.h> - namespace Swift { void MUCDestroyPayloadParser::handleTree(ParserElement::ref root) { std::string ns = root->getNamespace(); std::string jid = root->getAttributes().getAttribute("jid"); if (!jid.empty()) { getPayloadInternal()->setNewVenue(JID(jid)); } getPayloadInternal()->setReason(root->getChild("reason", ns)->getText()); } } diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp index 00a5d4f..b1bf78e 100644 --- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp @@ -1,50 +1,49 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h> #include <boost/lexical_cast.hpp> -#include <Swiften/Base/foreach.h> #include <Swiften/Elements/MUCOccupant.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/Tree/TreeReparser.h> namespace Swift { void MUCUserPayloadParser::handleTree(ParserElement::ref root) { - foreach (ParserElement::ref child, root->getAllChildren()) { + for (const auto& child : root->getAllChildren()) { if (child->getName() == "item" && child->getNamespace() == root->getNamespace()) { MUCItem item = MUCItemParser::itemFromTree(child); getPayloadInternal()->addItem(item); } else if (child->getName() == "password" && child->getNamespace() == root->getNamespace()) { getPayloadInternal()->setPassword(child->getText()); } else if (child->getName() == "invite" && child->getNamespace() == root->getNamespace()) { MUCUserPayload::Invite invite; std::string to = child->getAttributes().getAttribute("to"); if (!to.empty()) { invite.to = to; } std::string from = child->getAttributes().getAttribute("from"); if (!from.empty()) { invite.from = from; } ParserElement::ref reason = child->getChild("reason", root->getNamespace()); if (reason) { invite.reason = reason->getText(); } getPayloadInternal()->setInvite(invite); } else if (child->getName() == "status" && child->getNamespace() == root->getNamespace()) { MUCUserPayload::StatusCode status; try { status.code = boost::lexical_cast<int>(child->getAttributes().getAttribute("code").c_str()); getPayloadInternal()->addStatusCode(status); } catch (boost::bad_lexical_cast&) { } diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp index 1b0c95d..ad66b3f 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp +++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp @@ -1,47 +1,45 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/StreamInitiationParser.h> #include <boost/lexical_cast.hpp> #include <boost/cast.hpp> #include <cassert> #include <Swiften/Parser/PayloadParsers/FormParserFactory.h> #include <Swiften/Parser/PayloadParsers/FormParser.h> -#include <Swiften/Base/foreach.h> - #define FILE_TRANSFER_NS "http://jabber.org/protocol/si/profile/file-transfer" #define FEATURE_NEG_NS "http://jabber.org/protocol/feature-neg" namespace Swift { StreamInitiationParser::StreamInitiationParser() : level(TopLevel), formParser(nullptr), inFile(false), inFeature(false) { formParserFactory = new FormParserFactory(); } StreamInitiationParser::~StreamInitiationParser() { delete formParserFactory; } void StreamInitiationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == TopLevel) { getPayloadInternal()->setID(attributes.getAttribute("id")); if (!attributes.getAttribute("profile").empty()) { getPayloadInternal()->setIsFileTransfer(attributes.getAttribute("profile") == FILE_TRANSFER_NS); } } else if (level == PayloadLevel) { if (element == "file") { inFile = true; currentFile = StreamInitiationFileInfo(); currentFile.setName(attributes.getAttribute("name")); try { currentFile.setSize(boost::lexical_cast<unsigned long long>(attributes.getAttribute("size"))); } catch (boost::bad_lexical_cast&) { @@ -66,58 +64,58 @@ void StreamInitiationParser::handleStartElement(const std::string& element, cons } ++level; } void StreamInitiationParser::handleEndElement(const std::string& element, const std::string& ns) { --level; if (formParser) { formParser->handleEndElement(element, ns); } if (level == TopLevel) { } else if (level == PayloadLevel) { if (element == "file") { getPayloadInternal()->setFileInfo(currentFile); inFile = false; } else if (element == "feature" && ns == FEATURE_NEG_NS) { inFeature = false; } } else if (level == FileOrFeatureLevel) { if (inFile && element == "desc") { currentFile.setDescription(currentText); } else if (formParser) { Form::ref form = formParser->getPayloadInternal(); if (form) { FormField::ref field = std::dynamic_pointer_cast<FormField>(form->getField("stream-method")); if (field) { if (form->getType() == Form::FormType) { - foreach (const FormField::Option& option, field->getOptions()) { + for (const auto& option : field->getOptions()) { getPayloadInternal()->addProvidedMethod(option.value); } } else if (form->getType() == Form::SubmitType) { if (!field->getValues().empty()) { getPayloadInternal()->setRequestedMethod(field->getValues()[0]); } } } } delete formParser; formParser = nullptr; } } } void StreamInitiationParser::handleCharacterData(const std::string& data) { if (formParser) { formParser->handleCharacterData(data); } else { currentText += data; } } } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp index 18597bd..f0cf68d 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp @@ -1,69 +1,68 @@ /* * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Elements/MUCDestroyPayload.h> #include <Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h> #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; class MUCUserPayloadParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(MUCUserPayloadParserTest); CPPUNIT_TEST(testParseEmpty); CPPUNIT_TEST(testParse); CPPUNIT_TEST(testParseDestroy); CPPUNIT_TEST(testParseInvite); CPPUNIT_TEST_SUITE_END(); public: MUCUserPayloadParserTest() {} void testParse() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"><status code='110'/><item affiliation=\"owner\" role=\"visitor\"><actor jid=\"kev@tester.lit\"/><reason>malice</reason></item><status code='210'/></x>")); bool found110 = false; bool found210 = false; MUCUserPayload::ref payload = std::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); - foreach (MUCUserPayload::StatusCode status, payload->getStatusCodes()) { + for (const auto& status : payload->getStatusCodes()) { if (status.code == 110) found110 = true; if (status.code == 210) found210 = true; } MUCItem item = payload->getItems()[0]; CPPUNIT_ASSERT_EQUAL(MUCOccupant::Owner, item.affiliation.get()); CPPUNIT_ASSERT_EQUAL(MUCOccupant::Visitor, item.role.get()); CPPUNIT_ASSERT_EQUAL(JID("kev@tester.lit"), item.actor.get()); CPPUNIT_ASSERT_EQUAL(std::string("malice"), item.reason.get()); CPPUNIT_ASSERT(found110); CPPUNIT_ASSERT(found210); } void testParseEmpty() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"/>")); MUCUserPayload::ref payload = std::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); CPPUNIT_ASSERT(payload); CPPUNIT_ASSERT(payload->getItems().empty()); } void testParseDestroy() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"><destroy jid='alice@wonderland.lit'><reason>bert</reason></destroy></x>")); MUCUserPayload::ref payload = std::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); CPPUNIT_ASSERT(payload); diff --git a/Swiften/Parser/PayloadParsers/VCardParser.cpp b/Swiften/Parser/PayloadParsers/VCardParser.cpp index 7867b2c..f8779d1 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.cpp +++ b/Swiften/Parser/PayloadParsers/VCardParser.cpp @@ -1,42 +1,41 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/VCardParser.h> #include <cassert> #include <Swiften/Base/DateTime.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Parser/SerializingParser.h> #include <Swiften/StringCodecs/Base64.h> namespace Swift { VCardParser::VCardParser() : unknownContentParser_(nullptr) { } void VCardParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { elementStack_.push_back(element); std::string elementHierarchy = getElementHierarchy(); if (elementHierarchy == "/vCard/EMAIL") { currentEMailAddress_ = VCard::EMailAddress(); } if (elementHierarchy == "/vCard/TEL") { currentTelephone_ = VCard::Telephone(); } if (elementHierarchy == "/vCard/ADR") { currentAddress_ = VCard::Address(); } if (elementHierarchy == "/vCard/LABEL") { currentAddressLabel_ = VCard::AddressLabel(); } if (elementHierarchy == "/vCard/ORG") { currentOrganization_ = VCard::Organization(); } if (elementStack_.size() == 2) { assert(!unknownContentParser_); unknownContentParser_ = new SerializingParser(); unknownContentParser_->handleStartElement(element, ns, attributes); @@ -255,37 +254,37 @@ void VCardParser::handleEndElement(const std::string& element, const std::string } else if (elementHierarchy == "/vCard/TITLE" && !currentText_.empty()) { getPayloadInternal()->addTitle(currentText_); } else if (elementHierarchy == "/vCard/ROLE" && !currentText_.empty()) { getPayloadInternal()->addRole(currentText_); } else if (elementHierarchy == "/vCard/URL" && !currentText_.empty()) { getPayloadInternal()->addURL(currentText_); } else if (elementStack_.size() == 2 && unknownContentParser_) { getPayloadInternal()->addUnknownContent(unknownContentParser_->getResult()); } if (elementStack_.size() == 2 && unknownContentParser_) { delete unknownContentParser_; unknownContentParser_ = nullptr; } elementStack_.pop_back(); } void VCardParser::handleCharacterData(const std::string& text) { if (unknownContentParser_) { unknownContentParser_->handleCharacterData(text); } currentText_ += text; } std::string VCardParser::getElementHierarchy() const { std::string result; - foreach(const std::string& element, elementStack_) { + for (const auto& element : elementStack_) { result += "/" + element; } return result; } } diff --git a/Swiften/Parser/SerializingParser.cpp b/Swiften/Parser/SerializingParser.cpp index ad794aa..85b0dd4 100644 --- a/Swiften/Parser/SerializingParser.cpp +++ b/Swiften/Parser/SerializingParser.cpp @@ -1,51 +1,50 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/SerializingParser.h> #include <cassert> #include <memory> -#include <Swiften/Base/foreach.h> #include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { SerializingParser::SerializingParser() { } void SerializingParser::handleStartElement(const std::string& tag, const std::string& ns, const AttributeMap& attributes) { std::shared_ptr<XMLElement> element = std::make_shared<XMLElement>(tag, ns); // FIXME: Ignoring attribute namespace - foreach (const AttributeMap::Entry& e, attributes.getEntries()) { + for (const auto& e : attributes.getEntries()) { element->setAttribute(e.getAttribute().getName(), e.getValue()); } if (elementStack_.empty()) { rootElement_ = element; } else { (*(elementStack_.end() - 1))->addNode(element); } elementStack_.push_back(element); } void SerializingParser::handleEndElement(const std::string&, const std::string&) { assert(!elementStack_.empty()); elementStack_.pop_back(); } void SerializingParser::handleCharacterData(const std::string& data) { if (!elementStack_.empty()) { (*(elementStack_.end()-1))->addNode(std::make_shared<XMLTextNode>(data)); } } std::string SerializingParser::getResult() const { return (rootElement_ ? rootElement_->serialize() : ""); } } diff --git a/Swiften/Parser/Tree/TreeReparser.cpp b/Swiften/Parser/Tree/TreeReparser.cpp index 7fc74cf..6993d73 100644 --- a/Swiften/Parser/Tree/TreeReparser.cpp +++ b/Swiften/Parser/Tree/TreeReparser.cpp @@ -1,49 +1,48 @@ /* * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/Tree/TreeReparser.h> #include <deque> #include <utility> #include <boost/lexical_cast.hpp> -#include <Swiften/Base/foreach.h> #include <Swiften/Elements/MUCOccupant.h> #include <Swiften/Parser/PayloadParser.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParserFactoryCollection.h> namespace Swift { typedef std::pair<ParserElement::ref, bool> ElementState; std::shared_ptr<Payload> TreeReparser::parseTree(ParserElement::ref root, PayloadParserFactoryCollection* collection) { PayloadParser* parser = collection->getPayloadParserFactory(root->getName(), root->getNamespace(), root->getAttributes())->createPayloadParser(); std::deque<ElementState > stack; stack.push_back(ElementState(root, true)); while (!stack.empty()) { ElementState current = stack.back(); stack.pop_back(); if (current.second) { stack.push_back(ElementState(current.first, false)); parser->handleStartElement(current.first->getName(), current.first->getNamespace(), current.first->getAttributes()); - foreach(ParserElement::ref child, current.first->getAllChildren()) { + for (const auto& child : current.first->getAllChildren()) { stack.push_back(ElementState(child, true)); } } else { parser->handleCharacterData(current.first->getText()); parser->handleEndElement(current.first->getName(), current.first->getNamespace()); } } std::shared_ptr<Payload> payload = parser->getPayload(); delete parser; return payload; } } |