diff options
Diffstat (limited to 'Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp')
-rw-r--r-- | Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp | 79 |
1 files changed, 39 insertions, 40 deletions
diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp index 45be402..b1bf78e 100644 --- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -8,51 +8,50 @@ #include <boost/lexical_cast.hpp> -#include <Swiften/Parser/PayloadParserFactoryCollection.h> -#include <Swiften/Parser/PayloadParserFactory.h> -#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()) { - 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&) { - } - } - else { - getPayloadInternal()->setPayload(TreeReparser::parseTree(child, factories)); - } - } + 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&) { + } + } + else { + getPayloadInternal()->setPayload(TreeReparser::parseTree(child, factories)); + } + } } } |