diff options
Diffstat (limited to 'Swiften/Parser/PayloadParsers')
269 files changed, 9172 insertions, 9178 deletions
diff --git a/Swiften/Parser/PayloadParsers/BlockParser.h b/Swiften/Parser/PayloadParsers/BlockParser.h index 2e615a5..1724feb 100644 --- a/Swiften/Parser/PayloadParsers/BlockParser.h +++ b/Swiften/Parser/PayloadParsers/BlockParser.h @@ -12,30 +12,30 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - template<typename BLOCK_ELEMENT> - class SWIFTEN_API BlockParser : public GenericPayloadParser<BLOCK_ELEMENT> { - public: - BlockParser() : GenericPayloadParser<BLOCK_ELEMENT>(), level(0) { - } + template<typename BLOCK_ELEMENT> + class SWIFTEN_API BlockParser : public GenericPayloadParser<BLOCK_ELEMENT> { + public: + BlockParser() : GenericPayloadParser<BLOCK_ELEMENT>(), level(0) { + } - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level == 1 && element == "item") { - JID jid(attributes.getAttribute("jid")); - if (jid.isValid()) { - GenericPayloadParser<BLOCK_ELEMENT>::getPayloadInternal()->addItem(jid); - } - } - ++level; - } + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { + if (level == 1 && element == "item") { + JID jid(attributes.getAttribute("jid")); + if (jid.isValid()) { + GenericPayloadParser<BLOCK_ELEMENT>::getPayloadInternal()->addItem(jid); + } + } + ++level; + } - virtual void handleEndElement(const std::string&, const std::string&) { - --level; - } + virtual void handleEndElement(const std::string&, const std::string&) { + --level; + } - virtual void handleCharacterData(const std::string&) { - } + virtual void handleCharacterData(const std::string&) { + } - private: - int level; - }; + private: + int level; + }; } diff --git a/Swiften/Parser/PayloadParsers/BodyParser.cpp b/Swiften/Parser/PayloadParsers/BodyParser.cpp index 96a7b18..5741c90 100644 --- a/Swiften/Parser/PayloadParsers/BodyParser.cpp +++ b/Swiften/Parser/PayloadParsers/BodyParser.cpp @@ -12,18 +12,18 @@ BodyParser::BodyParser() : level_(0) { } void BodyParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level_; + ++level_; } void BodyParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 0) { - getPayloadInternal()->setText(text_); - } + --level_; + if (level_ == 0) { + getPayloadInternal()->setText(text_); + } } void BodyParser::handleCharacterData(const std::string& data) { - text_ += data; + text_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/BodyParser.h b/Swiften/Parser/PayloadParsers/BodyParser.h index 6b6a206..bcf762b 100644 --- a/Swiften/Parser/PayloadParsers/BodyParser.h +++ b/Swiften/Parser/PayloadParsers/BodyParser.h @@ -11,16 +11,16 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API BodyParser : public GenericPayloadParser<Body> { - public: - BodyParser(); + class SWIFTEN_API BodyParser : public GenericPayloadParser<Body> { + public: + BodyParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - std::string text_; - }; + private: + int level_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp b/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp index 35ee1fd..405c593 100644 --- a/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp +++ b/Swiften/Parser/PayloadParsers/BytestreamsParser.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,8 +8,6 @@ #include <boost/lexical_cast.hpp> -#include <Swiften/Base/foreach.h> - namespace Swift { BytestreamsParser::BytestreamsParser() : level(TopLevel) { @@ -19,26 +17,26 @@ 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; + 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; + --level; } void BytestreamsParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/BytestreamsParser.h b/Swiften/Parser/PayloadParsers/BytestreamsParser.h index 4180ff9..01cb60f 100644 --- a/Swiften/Parser/PayloadParsers/BytestreamsParser.h +++ b/Swiften/Parser/PayloadParsers/BytestreamsParser.h @@ -13,20 +13,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API BytestreamsParser : public GenericPayloadParser<Bytestreams> { - public: - BytestreamsParser(); - ~BytestreamsParser(); + class SWIFTEN_API BytestreamsParser : public GenericPayloadParser<Bytestreams> { + public: + BytestreamsParser(); + ~BytestreamsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - int level; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + int level; + }; } diff --git a/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp b/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp index 7843c78..546df57 100644 --- a/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp @@ -14,16 +14,16 @@ CapsInfoParser::CapsInfoParser() : level(0) { } void CapsInfoParser::handleStartElement(const std::string&, const std::string& /*ns*/, const AttributeMap& attributes) { - if (level == 0) { - getPayloadInternal()->setHash(attributes.getAttribute("hash")); - getPayloadInternal()->setNode(attributes.getAttribute("node")); - getPayloadInternal()->setVersion(attributes.getAttribute("ver")); - } - ++level; + if (level == 0) { + getPayloadInternal()->setHash(attributes.getAttribute("hash")); + getPayloadInternal()->setNode(attributes.getAttribute("node")); + getPayloadInternal()->setVersion(attributes.getAttribute("ver")); + } + ++level; } void CapsInfoParser::handleEndElement(const std::string&, const std::string&) { - --level; + --level; } void CapsInfoParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/CapsInfoParser.h b/Swiften/Parser/PayloadParsers/CapsInfoParser.h index 6e4610a..9556a4d 100644 --- a/Swiften/Parser/PayloadParsers/CapsInfoParser.h +++ b/Swiften/Parser/PayloadParsers/CapsInfoParser.h @@ -11,15 +11,15 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API CapsInfoParser : public GenericPayloadParser<CapsInfo> { - public: - CapsInfoParser(); + class SWIFTEN_API CapsInfoParser : public GenericPayloadParser<CapsInfo> { + public: + CapsInfoParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level; - }; + private: + int level; + }; } diff --git a/Swiften/Parser/PayloadParsers/CarbonsDisableParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsDisableParser.cpp index 7e26f3b..b8bd4b5 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsDisableParser.cpp +++ b/Swiften/Parser/PayloadParsers/CarbonsDisableParser.cpp @@ -8,19 +8,19 @@ namespace Swift { - CarbonsDisableParser::CarbonsDisableParser() : GenericPayloadParser<CarbonsDisable>() { - } + CarbonsDisableParser::CarbonsDisableParser() : GenericPayloadParser<CarbonsDisable>() { + } - CarbonsDisableParser::~CarbonsDisableParser() { - } + CarbonsDisableParser::~CarbonsDisableParser() { + } - void CarbonsDisableParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - } + void CarbonsDisableParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + } - void CarbonsDisableParser::handleEndElement(const std::string&, const std::string&) { - } + void CarbonsDisableParser::handleEndElement(const std::string&, const std::string&) { + } + + void CarbonsDisableParser::handleCharacterData(const std::string&) { + } - void CarbonsDisableParser::handleCharacterData(const std::string&) { - } - } diff --git a/Swiften/Parser/PayloadParsers/CarbonsDisableParser.h b/Swiften/Parser/PayloadParsers/CarbonsDisableParser.h index 56f6787..7a5f4a4 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsDisableParser.h +++ b/Swiften/Parser/PayloadParsers/CarbonsDisableParser.h @@ -11,13 +11,13 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API CarbonsDisableParser : public GenericPayloadParser<CarbonsDisable> { - public: - CarbonsDisableParser(); - virtual ~CarbonsDisableParser(); + class SWIFTEN_API CarbonsDisableParser : public GenericPayloadParser<CarbonsDisable> { + public: + CarbonsDisableParser(); + virtual ~CarbonsDisableParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); - virtual void handleCharacterData(const std::string&); - }; + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleCharacterData(const std::string&); + }; } diff --git a/Swiften/Parser/PayloadParsers/CarbonsEnableParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsEnableParser.cpp index 52bf6d7..700f939 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsEnableParser.cpp +++ b/Swiften/Parser/PayloadParsers/CarbonsEnableParser.cpp @@ -8,19 +8,19 @@ namespace Swift { - CarbonsEnableParser::CarbonsEnableParser() : GenericPayloadParser<CarbonsEnable>() { - } + CarbonsEnableParser::CarbonsEnableParser() : GenericPayloadParser<CarbonsEnable>() { + } - CarbonsEnableParser::~CarbonsEnableParser() { - } + CarbonsEnableParser::~CarbonsEnableParser() { + } - void CarbonsEnableParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - } + void CarbonsEnableParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + } - void CarbonsEnableParser::handleEndElement(const std::string&, const std::string&) { - } + void CarbonsEnableParser::handleEndElement(const std::string&, const std::string&) { + } + + void CarbonsEnableParser::handleCharacterData(const std::string&) { + } - void CarbonsEnableParser::handleCharacterData(const std::string&) { - } - } diff --git a/Swiften/Parser/PayloadParsers/CarbonsEnableParser.h b/Swiften/Parser/PayloadParsers/CarbonsEnableParser.h index d0e5771..0488f97 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsEnableParser.h +++ b/Swiften/Parser/PayloadParsers/CarbonsEnableParser.h @@ -11,12 +11,12 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API CarbonsEnableParser : public GenericPayloadParser<CarbonsEnable> { - public: - CarbonsEnableParser(); - virtual ~CarbonsEnableParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); - virtual void handleCharacterData(const std::string&); - }; + class SWIFTEN_API CarbonsEnableParser : public GenericPayloadParser<CarbonsEnable> { + public: + CarbonsEnableParser(); + virtual ~CarbonsEnableParser(); + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleCharacterData(const std::string&); + }; } diff --git a/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.cpp index 888edf1..b2038db 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.cpp +++ b/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.cpp @@ -8,19 +8,19 @@ namespace Swift { - CarbonsPrivateParser::CarbonsPrivateParser() : GenericPayloadParser<CarbonsPrivate>() { - } + CarbonsPrivateParser::CarbonsPrivateParser() : GenericPayloadParser<CarbonsPrivate>() { + } - CarbonsPrivateParser::~CarbonsPrivateParser() { - } + CarbonsPrivateParser::~CarbonsPrivateParser() { + } - void CarbonsPrivateParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - } + void CarbonsPrivateParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + } - void CarbonsPrivateParser::handleEndElement(const std::string&, const std::string&) { - } + void CarbonsPrivateParser::handleEndElement(const std::string&, const std::string&) { + } + + void CarbonsPrivateParser::handleCharacterData(const std::string&) { + } - void CarbonsPrivateParser::handleCharacterData(const std::string&) { - } - } diff --git a/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h b/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h index 2797808..2ae3bae 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h +++ b/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h @@ -11,12 +11,12 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API CarbonsPrivateParser : public GenericPayloadParser<CarbonsPrivate> { - public: - CarbonsPrivateParser(); - virtual ~CarbonsPrivateParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); - virtual void handleCharacterData(const std::string&); - }; + class SWIFTEN_API CarbonsPrivateParser : public GenericPayloadParser<CarbonsPrivate> { + public: + CarbonsPrivateParser(); + virtual ~CarbonsPrivateParser(); + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleCharacterData(const std::string&); + }; } diff --git a/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.cpp index 267c541..e4f8ab9 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.cpp +++ b/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,39 +7,39 @@ #include <Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h> namespace Swift { - CarbonsReceivedParser::CarbonsReceivedParser(PayloadParserFactoryCollection* factories) : GenericPayloadParser<CarbonsReceived>(), factories_(factories), level_(TopLevel) { - } + CarbonsReceivedParser::CarbonsReceivedParser(PayloadParserFactoryCollection* factories) : GenericPayloadParser<CarbonsReceived>(), factories_(factories), level_(TopLevel) { + } - CarbonsReceivedParser::~CarbonsReceivedParser() { - } + CarbonsReceivedParser::~CarbonsReceivedParser() { + } - void CarbonsReceivedParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == PayloadLevel) { - if (element == "forwarded") { - forwardedParser_ = boost::dynamic_pointer_cast<ForwardedParser>(boost::make_shared<ForwardedParser>(factories_)); - } - } - if (forwardedParser_) { - forwardedParser_->handleStartElement(element, ns, attributes); - } - ++level_; - } + void CarbonsReceivedParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level_ == PayloadLevel) { + if (element == "forwarded") { + forwardedParser_ = std::dynamic_pointer_cast<ForwardedParser>(std::make_shared<ForwardedParser>(factories_)); + } + } + if (forwardedParser_) { + forwardedParser_->handleStartElement(element, ns, attributes); + } + ++level_; + } - void CarbonsReceivedParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (forwardedParser_ && level_ >= PayloadLevel) { - forwardedParser_->handleEndElement(element, ns); - } - if (forwardedParser_ && level_ == PayloadLevel) { - /* done parsing nested stanza */ - getPayloadInternal()->setForwarded(forwardedParser_->getPayloadInternal()); - forwardedParser_.reset(); - } - } + void CarbonsReceivedParser::handleEndElement(const std::string& element, const std::string& ns) { + --level_; + if (forwardedParser_ && level_ >= PayloadLevel) { + forwardedParser_->handleEndElement(element, ns); + } + if (forwardedParser_ && level_ == PayloadLevel) { + /* done parsing nested stanza */ + getPayloadInternal()->setForwarded(forwardedParser_->getPayloadInternal()); + forwardedParser_.reset(); + } + } - void CarbonsReceivedParser::handleCharacterData(const std::string& data) { - if (forwardedParser_) { - forwardedParser_->handleCharacterData(data); - } - } + void CarbonsReceivedParser::handleCharacterData(const std::string& data) { + if (forwardedParser_) { + forwardedParser_->handleCharacterData(data); + } + } } diff --git a/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h b/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h index 6aa6326..6cc1f43 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h +++ b/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -12,24 +12,24 @@ #include <Swiften/Parser/PayloadParsers/ForwardedParser.h> namespace Swift { - class SWIFTEN_API CarbonsReceivedParser : public GenericPayloadParser<CarbonsReceived> { - public: - CarbonsReceivedParser(PayloadParserFactoryCollection* factories); - virtual ~CarbonsReceivedParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string&); + class SWIFTEN_API CarbonsReceivedParser : public GenericPayloadParser<CarbonsReceived> { + public: + CarbonsReceivedParser(PayloadParserFactoryCollection* factories); + virtual ~CarbonsReceivedParser(); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string&); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; - private: - PayloadParserFactoryCollection* factories_; - boost::shared_ptr<ForwardedParser> forwardedParser_; - int level_; - }; + private: + PayloadParserFactoryCollection* factories_; + std::shared_ptr<ForwardedParser> forwardedParser_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/CarbonsSentParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsSentParser.cpp index b430249..f446042 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsSentParser.cpp +++ b/Swiften/Parser/PayloadParsers/CarbonsSentParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,39 +7,39 @@ #include <Swiften/Parser/PayloadParsers/CarbonsSentParser.h> namespace Swift { - CarbonsSentParser::CarbonsSentParser(PayloadParserFactoryCollection* factories) : GenericPayloadParser<CarbonsSent>(), factories_(factories), level_(TopLevel) { - } + CarbonsSentParser::CarbonsSentParser(PayloadParserFactoryCollection* factories) : GenericPayloadParser<CarbonsSent>(), factories_(factories), level_(TopLevel) { + } - CarbonsSentParser::~CarbonsSentParser() { - } + CarbonsSentParser::~CarbonsSentParser() { + } - void CarbonsSentParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == PayloadLevel) { - if (element == "forwarded") { - forwardedParser_ = boost::dynamic_pointer_cast<ForwardedParser>(boost::make_shared<ForwardedParser>(factories_)); - } - } - if (forwardedParser_) { - forwardedParser_->handleStartElement(element, ns, attributes); - } - ++level_; - } + void CarbonsSentParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level_ == PayloadLevel) { + if (element == "forwarded") { + forwardedParser_ = std::dynamic_pointer_cast<ForwardedParser>(std::make_shared<ForwardedParser>(factories_)); + } + } + if (forwardedParser_) { + forwardedParser_->handleStartElement(element, ns, attributes); + } + ++level_; + } - void CarbonsSentParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (forwardedParser_ && level_ >= PayloadLevel) { - forwardedParser_->handleEndElement(element, ns); - } - if (forwardedParser_ && level_ == PayloadLevel) { - /* done parsing nested stanza */ - getPayloadInternal()->setForwarded(forwardedParser_->getPayloadInternal()); - forwardedParser_.reset(); - } - } + void CarbonsSentParser::handleEndElement(const std::string& element, const std::string& ns) { + --level_; + if (forwardedParser_ && level_ >= PayloadLevel) { + forwardedParser_->handleEndElement(element, ns); + } + if (forwardedParser_ && level_ == PayloadLevel) { + /* done parsing nested stanza */ + getPayloadInternal()->setForwarded(forwardedParser_->getPayloadInternal()); + forwardedParser_.reset(); + } + } - void CarbonsSentParser::handleCharacterData(const std::string& data) { - if (forwardedParser_) { - forwardedParser_->handleCharacterData(data); - } - } + void CarbonsSentParser::handleCharacterData(const std::string& data) { + if (forwardedParser_) { + forwardedParser_->handleCharacterData(data); + } + } } diff --git a/Swiften/Parser/PayloadParsers/CarbonsSentParser.h b/Swiften/Parser/PayloadParsers/CarbonsSentParser.h index 91c3292..d4e12ba 100644 --- a/Swiften/Parser/PayloadParsers/CarbonsSentParser.h +++ b/Swiften/Parser/PayloadParsers/CarbonsSentParser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -12,24 +12,24 @@ #include <Swiften/Parser/PayloadParsers/ForwardedParser.h> namespace Swift { - class SWIFTEN_API CarbonsSentParser : public GenericPayloadParser<CarbonsSent> { - public: - CarbonsSentParser(PayloadParserFactoryCollection* factories); - virtual ~CarbonsSentParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string&); + class SWIFTEN_API CarbonsSentParser : public GenericPayloadParser<CarbonsSent> { + public: + CarbonsSentParser(PayloadParserFactoryCollection* factories); + virtual ~CarbonsSentParser(); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string&); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; - private: - PayloadParserFactoryCollection* factories_; - boost::shared_ptr<ForwardedParser> forwardedParser_; - int level_; - }; + private: + PayloadParserFactoryCollection* factories_; + std::shared_ptr<ForwardedParser> forwardedParser_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/ChatStateParser.cpp b/Swiften/Parser/PayloadParsers/ChatStateParser.cpp index bd5ecbe..75ec699 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParser.cpp +++ b/Swiften/Parser/PayloadParsers/ChatStateParser.cpp @@ -12,26 +12,26 @@ ChatStateParser::ChatStateParser() : level_(0) { } void ChatStateParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { - if (level_ == 0) { - ChatState::ChatStateType state = ChatState::Active; - if (element == "active") { - state = ChatState::Active; - } else if (element == "composing") { - state = ChatState::Composing; - } else if (element == "inactive") { - state = ChatState::Inactive; - } else if (element == "paused") { - state = ChatState::Paused; - } else if (element == "gone") { - state = ChatState::Gone; - } - getPayloadInternal()->setChatState(state); - } - ++level_; + if (level_ == 0) { + ChatState::ChatStateType state = ChatState::Active; + if (element == "active") { + state = ChatState::Active; + } else if (element == "composing") { + state = ChatState::Composing; + } else if (element == "inactive") { + state = ChatState::Inactive; + } else if (element == "paused") { + state = ChatState::Paused; + } else if (element == "gone") { + state = ChatState::Gone; + } + getPayloadInternal()->setChatState(state); + } + ++level_; } void ChatStateParser::handleEndElement(const std::string&, const std::string&) { - --level_; + --level_; } void ChatStateParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/ChatStateParser.h b/Swiften/Parser/PayloadParsers/ChatStateParser.h index e18e17b..b932a5c 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParser.h +++ b/Swiften/Parser/PayloadParsers/ChatStateParser.h @@ -11,15 +11,15 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API ChatStateParser : public GenericPayloadParser<ChatState> { - public: - ChatStateParser(); + class SWIFTEN_API ChatStateParser : public GenericPayloadParser<ChatState> { + public: + ChatStateParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - }; + private: + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h b/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h index ac1c14d..cf226cc 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h +++ b/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h @@ -11,22 +11,22 @@ #include <Swiften/Parser/PayloadParsers/ChatStateParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API ChatStateParserFactory : public PayloadParserFactory { - public: - ChatStateParserFactory() { - } + class SWIFTEN_API ChatStateParserFactory : public PayloadParserFactory { + public: + ChatStateParserFactory() { + } - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return ns == "http://jabber.org/protocol/chatstates" && - (element == "active" || element == "composing" - || element == "paused" || element == "inactive" || element == "gone"); - } + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return ns == "http://jabber.org/protocol/chatstates" && + (element == "active" || element == "composing" + || element == "paused" || element == "inactive" || element == "gone"); + } - virtual PayloadParser* createPayloadParser() { - return new ChatStateParser(); - } + virtual PayloadParser* createPayloadParser() { + return new ChatStateParser(); + } - }; + }; } diff --git a/Swiften/Parser/PayloadParsers/CommandParser.cpp b/Swiften/Parser/PayloadParsers/CommandParser.cpp index a2f2c5b..80686d2 100644 --- a/Swiften/Parser/PayloadParsers/CommandParser.cpp +++ b/Swiften/Parser/PayloadParsers/CommandParser.cpp @@ -1,143 +1,145 @@ /* - * 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/CommandParser.h> +#include <cassert> + #include <boost/cast.hpp> -#include <Swiften/Parser/PayloadParsers/FormParserFactory.h> #include <Swiften/Parser/PayloadParsers/FormParser.h> +#include <Swiften/Parser/PayloadParsers/FormParserFactory.h> namespace Swift { -CommandParser::CommandParser() : level_(TopLevel), inNote_(false), inActions_(false), noteType_(Command::Note::Info), formParser_(0) { - formParserFactory_ = new FormParserFactory(); +CommandParser::CommandParser() : level_(TopLevel), inNote_(false), inActions_(false), noteType_(Command::Note::Info), formParser_(nullptr) { + formParserFactory_ = new FormParserFactory(); } CommandParser::~CommandParser() { - delete formParserFactory_; + delete formParserFactory_; } void CommandParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - ++level_; - if (level_ == PayloadLevel) { - boost::optional<Command::Action> action = parseAction(attributes.getAttribute("action")); - if (action) { - getPayloadInternal()->setAction(*action); - } - - std::string status = attributes.getAttribute("status"); - if (status == "executing") { - getPayloadInternal()->setStatus(Command::Executing); - } - else if (status == "completed") { - getPayloadInternal()->setStatus(Command::Completed); - } - else if (status == "canceled") { - getPayloadInternal()->setStatus(Command::Canceled); - } - - getPayloadInternal()->setNode(attributes.getAttribute("node")); - getPayloadInternal()->setSessionID(attributes.getAttribute("sessionid")); - } - else if (level_ == FormOrNoteOrActionsLevel) { - assert(!formParser_); - if (formParserFactory_->canParse(element, ns, attributes)) { - formParser_ = boost::polymorphic_downcast<FormParser*>(formParserFactory_->createPayloadParser()); - assert(formParser_); - } - else if (element == "note") { - inNote_ = true; - currentText_.clear(); - std::string noteType = attributes.getAttribute("type"); - if (noteType == "info") { - noteType_ = Command::Note::Info; - } - else if (noteType == "warn") { - noteType_ = Command::Note::Warn; - } - else if (noteType == "error") { - noteType_ = Command::Note::Error; - } - else { - noteType_ = Command::Note::Info; - } - } - else if (element == "actions") { - inActions_ = true; - boost::optional<Command::Action> action = parseAction(attributes.getAttribute("execute")); - if (action) { - getPayloadInternal()->setExecuteAction(*action); - } - } - } - else if (level_ == ActionsActionLevel) { - } - - if (formParser_) { - formParser_->handleStartElement(element, ns, attributes); - } + ++level_; + if (level_ == PayloadLevel) { + boost::optional<Command::Action> action = parseAction(attributes.getAttribute("action")); + if (action) { + getPayloadInternal()->setAction(*action); + } + + std::string status = attributes.getAttribute("status"); + if (status == "executing") { + getPayloadInternal()->setStatus(Command::Executing); + } + else if (status == "completed") { + getPayloadInternal()->setStatus(Command::Completed); + } + else if (status == "canceled") { + getPayloadInternal()->setStatus(Command::Canceled); + } + + getPayloadInternal()->setNode(attributes.getAttribute("node")); + getPayloadInternal()->setSessionID(attributes.getAttribute("sessionid")); + } + else if (level_ == FormOrNoteOrActionsLevel) { + assert(!formParser_); + if (formParserFactory_->canParse(element, ns, attributes)) { + formParser_ = boost::polymorphic_downcast<FormParser*>(formParserFactory_->createPayloadParser()); + assert(formParser_); + } + else if (element == "note") { + inNote_ = true; + currentText_.clear(); + std::string noteType = attributes.getAttribute("type"); + if (noteType == "info") { + noteType_ = Command::Note::Info; + } + else if (noteType == "warn") { + noteType_ = Command::Note::Warn; + } + else if (noteType == "error") { + noteType_ = Command::Note::Error; + } + else { + noteType_ = Command::Note::Info; + } + } + else if (element == "actions") { + inActions_ = true; + boost::optional<Command::Action> action = parseAction(attributes.getAttribute("execute")); + if (action) { + getPayloadInternal()->setExecuteAction(*action); + } + } + } + else if (level_ == ActionsActionLevel) { + } + + if (formParser_) { + formParser_->handleStartElement(element, ns, attributes); + } } void CommandParser::handleEndElement(const std::string& element, const std::string& ns) { - if (formParser_) { - formParser_->handleEndElement(element, ns); - } - - if (level_ == FormOrNoteOrActionsLevel) { - if (formParser_) { - Form::ref form(boost::dynamic_pointer_cast<Form>(formParser_->getPayload())); - assert(form); - getPayloadInternal()->setForm(form); - delete formParser_; - formParser_ = 0; - } - else if (inNote_) { - inNote_ = false; - getPayloadInternal()->addNote(Command::Note(currentText_, noteType_)); - } - else if (inActions_) { - inActions_ = false; - } - } - else if (level_ == ActionsActionLevel && inActions_) { - boost::optional<Command::Action> action = parseAction(element); - if (action) { - getPayloadInternal()->addAvailableAction(*action); - } - } - --level_; + if (formParser_) { + formParser_->handleEndElement(element, ns); + } + + if (level_ == FormOrNoteOrActionsLevel) { + if (formParser_) { + Form::ref form(std::dynamic_pointer_cast<Form>(formParser_->getPayload())); + assert(form); + getPayloadInternal()->setForm(form); + delete formParser_; + formParser_ = nullptr; + } + else if (inNote_) { + inNote_ = false; + getPayloadInternal()->addNote(Command::Note(currentText_, noteType_)); + } + else if (inActions_) { + inActions_ = false; + } + } + else if (level_ == ActionsActionLevel && inActions_) { + boost::optional<Command::Action> action = parseAction(element); + if (action) { + getPayloadInternal()->addAvailableAction(*action); + } + } + --level_; } void CommandParser::handleCharacterData(const std::string& data) { - if (formParser_) { - formParser_->handleCharacterData(data); - } - else { - currentText_ += data; - } + if (formParser_) { + formParser_->handleCharacterData(data); + } + else { + currentText_ += data; + } } boost::optional<Command::Action> CommandParser::parseAction(const std::string& action) { - if (action == "execute") { - return Command::Execute; - } - else if (action == "cancel") { - return Command::Cancel; - } - else if (action == "prev") { - return Command::Prev; - } - else if (action == "next") { - return Command::Next; - } - else if (action == "complete") { - return Command::Complete; - } - return boost::optional<Command::Action>(); + if (action == "execute") { + return Command::Execute; + } + else if (action == "cancel") { + return Command::Cancel; + } + else if (action == "prev") { + return Command::Prev; + } + else if (action == "next") { + return Command::Next; + } + else if (action == "complete") { + return Command::Complete; + } + return boost::optional<Command::Action>(); } } diff --git a/Swiften/Parser/PayloadParsers/CommandParser.h b/Swiften/Parser/PayloadParsers/CommandParser.h index 11badd4..105953a 100644 --- a/Swiften/Parser/PayloadParsers/CommandParser.h +++ b/Swiften/Parser/PayloadParsers/CommandParser.h @@ -13,34 +13,34 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class FormParserFactory; - class FormParser; - - class SWIFTEN_API CommandParser : public GenericPayloadParser<Command> { - public: - CommandParser(); - ~CommandParser(); - - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - - private: - static boost::optional<Command::Action> parseAction(const std::string& action); - - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - FormOrNoteOrActionsLevel = 2, - ActionsActionLevel = 3 - }; - int level_; - bool inNote_; - bool inActions_; - Command::Note::Type noteType_; - FormParserFactory* formParserFactory_; - FormParser* formParser_; - std::string currentText_; - }; + class FormParserFactory; + class FormParser; + + class SWIFTEN_API CommandParser : public GenericPayloadParser<Command> { + public: + CommandParser(); + ~CommandParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + + private: + static boost::optional<Command::Action> parseAction(const std::string& action); + + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + FormOrNoteOrActionsLevel = 2, + ActionsActionLevel = 3 + }; + int level_; + bool inNote_; + bool inActions_; + Command::Note::Type noteType_; + FormParserFactory* formParserFactory_; + FormParser* formParser_; + std::string currentText_; + }; } diff --git a/Swiften/Parser/PayloadParsers/DelayParser.cpp b/Swiften/Parser/PayloadParsers/DelayParser.cpp index b8e72d8..95371b7 100644 --- a/Swiften/Parser/PayloadParsers/DelayParser.cpp +++ b/Swiften/Parser/PayloadParsers/DelayParser.cpp @@ -14,19 +14,19 @@ DelayParser::DelayParser() : level_(0) { } void DelayParser::handleStartElement(const std::string& /*element*/, const std::string& /*ns*/, const AttributeMap& attributes) { - if (level_ == 0) { - boost::posix_time::ptime stamp = stringToDateTime(attributes.getAttribute("stamp")); - getPayloadInternal()->setStamp(stamp); - if (!attributes.getAttribute("from").empty()) { - std::string from = attributes.getAttribute("from"); - getPayloadInternal()->setFrom(JID(from)); - } - } - ++level_; + if (level_ == 0) { + boost::posix_time::ptime stamp = stringToDateTime(attributes.getAttribute("stamp")); + getPayloadInternal()->setStamp(stamp); + if (!attributes.getAttribute("from").empty()) { + std::string from = attributes.getAttribute("from"); + getPayloadInternal()->setFrom(JID(from)); + } + } + ++level_; } void DelayParser::handleEndElement(const std::string&, const std::string&) { - --level_; + --level_; } void DelayParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/DelayParser.h b/Swiften/Parser/PayloadParsers/DelayParser.h index d5fa58f..d9bf44b 100644 --- a/Swiften/Parser/PayloadParsers/DelayParser.h +++ b/Swiften/Parser/PayloadParsers/DelayParser.h @@ -11,15 +11,15 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API DelayParser : public GenericPayloadParser<Delay> { - public: - DelayParser(); + class SWIFTEN_API DelayParser : public GenericPayloadParser<Delay> { + public: + DelayParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - }; + private: + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp index 347200d..b6f0a86 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp @@ -14,18 +14,18 @@ DeliveryReceiptParser::DeliveryReceiptParser() : level_(0) { } void DeliveryReceiptParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributeMap) { - if (level_ == 0) { - if (element == "received") { - if (attributeMap.getAttributeValue("id").is_initialized()) { - getPayloadInternal()->setReceivedID(attributeMap.getAttributeValue("id").get()); - } - } - } - ++level_; + if (level_ == 0) { + if (element == "received") { + if (attributeMap.getAttributeValue("id").is_initialized()) { + getPayloadInternal()->setReceivedID(attributeMap.getAttributeValue("id").get()); + } + } + } + ++level_; } void DeliveryReceiptParser::handleEndElement(const std::string&, const std::string&) { - --level_; + --level_; } void DeliveryReceiptParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h index bcb73f3..5cc0009 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h @@ -17,15 +17,15 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API DeliveryReceiptParser : public GenericPayloadParser<DeliveryReceipt> { - public: - DeliveryReceiptParser(); + class SWIFTEN_API DeliveryReceiptParser : public GenericPayloadParser<DeliveryReceipt> { + public: + DeliveryReceiptParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributeMap); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributeMap); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - }; + private: + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h index aa5d856..dc0c311 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h @@ -17,20 +17,20 @@ #include <Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API DeliveryReceiptParserFactory : public PayloadParserFactory { - public: - DeliveryReceiptParserFactory() { - } + class SWIFTEN_API DeliveryReceiptParserFactory : public PayloadParserFactory { + public: + DeliveryReceiptParserFactory() { + } - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return ns == "urn:xmpp:receipts" && element == "received"; - } + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return ns == "urn:xmpp:receipts" && element == "received"; + } - virtual PayloadParser* createPayloadParser() { - return new DeliveryReceiptParser(); - } + virtual PayloadParser* createPayloadParser() { + return new DeliveryReceiptParser(); + } - }; + }; } diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h index 5bf27fa..d8a68b0 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h @@ -17,12 +17,12 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API DeliveryReceiptRequestParser : public GenericPayloadParser<DeliveryReceiptRequest> { - public: - DeliveryReceiptRequestParser(); + class SWIFTEN_API DeliveryReceiptRequestParser : public GenericPayloadParser<DeliveryReceiptRequest> { + public: + DeliveryReceiptRequestParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); - virtual void handleCharacterData(const std::string& data); - }; + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleCharacterData(const std::string& data); + }; } diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h index 509db63..a858285 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h @@ -17,20 +17,20 @@ #include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API DeliveryReceiptRequestParserFactory : public PayloadParserFactory { - public: - DeliveryReceiptRequestParserFactory() { - } + class SWIFTEN_API DeliveryReceiptRequestParserFactory : public PayloadParserFactory { + public: + DeliveryReceiptRequestParserFactory() { + } - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return ns == "urn:xmpp:receipts" && element == "request"; - } + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return ns == "urn:xmpp:receipts" && element == "request"; + } - virtual PayloadParser* createPayloadParser() { - return new DeliveryReceiptRequestParser(); - } + virtual PayloadParser* createPayloadParser() { + return new DeliveryReceiptRequestParser(); + } - }; + }; } diff --git a/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp b/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp index eaf9359..6ded2e2 100644 --- a/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp @@ -1,59 +1,62 @@ /* - * 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/DiscoInfoParser.h> +#include <cassert> + #include <boost/optional.hpp> + #include <Swiften/Parser/PayloadParsers/FormParser.h> namespace Swift { -DiscoInfoParser::DiscoInfoParser() : level_(TopLevel), formParser_(NULL) { +DiscoInfoParser::DiscoInfoParser() : level_(TopLevel), formParser_(nullptr) { } void DiscoInfoParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == TopLevel) { - if (attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributes.getAttributeValue("node")); - } - } - else if (level_ == PayloadLevel) { - if (element == "identity") { - getPayloadInternal()->addIdentity(DiscoInfo::Identity(attributes.getAttribute("name"), attributes.getAttribute("category"), attributes.getAttribute("type"), attributes.getAttribute("lang", "http://www.w3.org/XML/1998/namespace"))); - } - else if (element == "feature") { - getPayloadInternal()->addFeature(attributes.getAttribute("var")); - } - else if (element == "x" && ns == "jabber:x:data") { - assert(!formParser_); - formParser_ = new FormParser(); - } - } - if (formParser_) { - formParser_->handleStartElement(element, ns, attributes); - } - ++level_; + if (level_ == TopLevel) { + if (attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributes.getAttributeValue("node")); + } + } + else if (level_ == PayloadLevel) { + if (element == "identity") { + getPayloadInternal()->addIdentity(DiscoInfo::Identity(attributes.getAttribute("name"), attributes.getAttribute("category"), attributes.getAttribute("type"), attributes.getAttribute("lang", "http://www.w3.org/XML/1998/namespace"))); + } + else if (element == "feature") { + getPayloadInternal()->addFeature(attributes.getAttribute("var")); + } + else if (element == "x" && ns == "jabber:x:data") { + assert(!formParser_); + formParser_ = new FormParser(); + } + } + if (formParser_) { + formParser_->handleStartElement(element, ns, attributes); + } + ++level_; } void DiscoInfoParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (formParser_) { - formParser_->handleEndElement(element, ns); - } - if (level_ == PayloadLevel && formParser_) { - getPayloadInternal()->addExtension(formParser_->getPayloadInternal()); - delete formParser_; - formParser_ = NULL; - } + --level_; + if (formParser_) { + formParser_->handleEndElement(element, ns); + } + if (level_ == PayloadLevel && formParser_) { + getPayloadInternal()->addExtension(formParser_->getPayloadInternal()); + delete formParser_; + formParser_ = nullptr; + } } void DiscoInfoParser::handleCharacterData(const std::string& data) { - if (formParser_) { - formParser_->handleCharacterData(data); - } + if (formParser_) { + formParser_->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/DiscoInfoParser.h b/Swiften/Parser/PayloadParsers/DiscoInfoParser.h index 3d10c4b..28bfff1 100644 --- a/Swiften/Parser/PayloadParsers/DiscoInfoParser.h +++ b/Swiften/Parser/PayloadParsers/DiscoInfoParser.h @@ -11,20 +11,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API DiscoInfoParser : public GenericPayloadParser<DiscoInfo> { - public: - DiscoInfoParser(); + class SWIFTEN_API DiscoInfoParser : public GenericPayloadParser<DiscoInfo> { + public: + DiscoInfoParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - int level_; - FormParser* formParser_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + int level_; + FormParser* formParser_; + }; } diff --git a/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp b/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp index 179fb29..a3b9245 100644 --- a/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp +++ b/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp @@ -12,21 +12,21 @@ DiscoItemsParser::DiscoItemsParser() : level_(TopLevel) { } void DiscoItemsParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level_ == PayloadLevel) { - if (element == "item") { - getPayloadInternal()->addItem(DiscoItems::Item(attributes.getAttribute("name"), JID(attributes.getAttribute("jid")), attributes.getAttribute("node"))); - } - } - else if (level_ == TopLevel) { - if (element == "query") { - getPayloadInternal()->setNode(attributes.getAttribute("node")); - } - } - ++level_; + if (level_ == PayloadLevel) { + if (element == "item") { + getPayloadInternal()->addItem(DiscoItems::Item(attributes.getAttribute("name"), JID(attributes.getAttribute("jid")), attributes.getAttribute("node"))); + } + } + else if (level_ == TopLevel) { + if (element == "query") { + getPayloadInternal()->setNode(attributes.getAttribute("node")); + } + } + ++level_; } void DiscoItemsParser::handleEndElement(const std::string&, const std::string&) { - --level_; + --level_; } void DiscoItemsParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/DiscoItemsParser.h b/Swiften/Parser/PayloadParsers/DiscoItemsParser.h index b467ca1..3197b79 100644 --- a/Swiften/Parser/PayloadParsers/DiscoItemsParser.h +++ b/Swiften/Parser/PayloadParsers/DiscoItemsParser.h @@ -11,20 +11,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API DiscoItemsParser : public GenericPayloadParser<DiscoItems> { - public: - DiscoItemsParser(); + class SWIFTEN_API DiscoItemsParser : public GenericPayloadParser<DiscoItems> { + public: + DiscoItemsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - int level_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/ErrorParser.cpp b/Swiften/Parser/PayloadParsers/ErrorParser.cpp index e2e225a..222bcbd 100644 --- a/Swiften/Parser/PayloadParsers/ErrorParser.cpp +++ b/Swiften/Parser/PayloadParsers/ErrorParser.cpp @@ -1,12 +1,13 @@ /* - * 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/ErrorParser.h> -#include <Swiften/Parser/PayloadParserFactoryCollection.h> + #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> namespace Swift { @@ -14,132 +15,132 @@ ErrorParser::ErrorParser(PayloadParserFactoryCollection* factories) : factories( } void ErrorParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == TopLevel) { - std::string type = attributes.getAttribute("type"); - if (type == "continue") { - getPayloadInternal()->setType(ErrorPayload::Continue); - } - else if (type == "modify") { - getPayloadInternal()->setType(ErrorPayload::Modify); - } - else if (type == "auth") { - getPayloadInternal()->setType(ErrorPayload::Auth); - } - else if (type == "wait") { - getPayloadInternal()->setType(ErrorPayload::Wait); - } - else { - getPayloadInternal()->setType(ErrorPayload::Cancel); - } - } - else if (level_ == PayloadLevel) { - if (element == "text") { + if (level_ == TopLevel) { + std::string type = attributes.getAttribute("type"); + if (type == "continue") { + getPayloadInternal()->setType(ErrorPayload::Continue); + } + else if (type == "modify") { + getPayloadInternal()->setType(ErrorPayload::Modify); + } + else if (type == "auth") { + getPayloadInternal()->setType(ErrorPayload::Auth); + } + else if (type == "wait") { + getPayloadInternal()->setType(ErrorPayload::Wait); + } + else { + getPayloadInternal()->setType(ErrorPayload::Cancel); + } + } + else if (level_ == PayloadLevel) { + if (element == "text") { - } - else if (element == "bad-request") { - getPayloadInternal()->setCondition(ErrorPayload::BadRequest); - } - else if (element == "conflict") { - getPayloadInternal()->setCondition(ErrorPayload::Conflict); - } - else if (element == "feature-not-implemented") { - getPayloadInternal()->setCondition(ErrorPayload::FeatureNotImplemented); - } - else if (element == "forbidden") { - getPayloadInternal()->setCondition(ErrorPayload::Forbidden); - } - else if (element == "gone") { - getPayloadInternal()->setCondition(ErrorPayload::Gone); - } - else if (element == "internal-server-error") { - getPayloadInternal()->setCondition(ErrorPayload::InternalServerError); - } - else if (element == "item-not-found") { - getPayloadInternal()->setCondition(ErrorPayload::ItemNotFound); - } - else if (element == "jid-malformed") { - getPayloadInternal()->setCondition(ErrorPayload::JIDMalformed); - } - else if (element == "not-acceptable") { - getPayloadInternal()->setCondition(ErrorPayload::NotAcceptable); - } - else if (element == "not-allowed") { - getPayloadInternal()->setCondition(ErrorPayload::NotAllowed); - } - else if (element == "not-authorized") { - getPayloadInternal()->setCondition(ErrorPayload::NotAuthorized); - } - else if (element == "payment-required") { - getPayloadInternal()->setCondition(ErrorPayload::PaymentRequired); - } - else if (element == "recipient-unavailable") { - getPayloadInternal()->setCondition(ErrorPayload::RecipientUnavailable); - } - else if (element == "redirect") { - getPayloadInternal()->setCondition(ErrorPayload::Redirect); - } - else if (element == "registration-required") { - getPayloadInternal()->setCondition(ErrorPayload::RegistrationRequired); - } - else if (element == "remote-server-not-found") { - getPayloadInternal()->setCondition(ErrorPayload::RemoteServerNotFound); - } - else if (element == "remote-server-timeout") { - getPayloadInternal()->setCondition(ErrorPayload::RemoteServerTimeout); - } - else if (element == "resource-constraint") { - getPayloadInternal()->setCondition(ErrorPayload::ResourceConstraint); - } - else if (element == "service-unavailable") { - getPayloadInternal()->setCondition(ErrorPayload::ServiceUnavailable); - } - else if (element == "subscription-required") { - getPayloadInternal()->setCondition(ErrorPayload::SubscriptionRequired); - } - else if (element == "unexpected-request") { - getPayloadInternal()->setCondition(ErrorPayload::UnexpectedRequest); - } - else { - PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } else { - getPayloadInternal()->setCondition(ErrorPayload::UndefinedCondition); - } - } - } - if (level_ >= PayloadLevel && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level_; + } + else if (element == "bad-request") { + getPayloadInternal()->setCondition(ErrorPayload::BadRequest); + } + else if (element == "conflict") { + getPayloadInternal()->setCondition(ErrorPayload::Conflict); + } + else if (element == "feature-not-implemented") { + getPayloadInternal()->setCondition(ErrorPayload::FeatureNotImplemented); + } + else if (element == "forbidden") { + getPayloadInternal()->setCondition(ErrorPayload::Forbidden); + } + else if (element == "gone") { + getPayloadInternal()->setCondition(ErrorPayload::Gone); + } + else if (element == "internal-server-error") { + getPayloadInternal()->setCondition(ErrorPayload::InternalServerError); + } + else if (element == "item-not-found") { + getPayloadInternal()->setCondition(ErrorPayload::ItemNotFound); + } + else if (element == "jid-malformed") { + getPayloadInternal()->setCondition(ErrorPayload::JIDMalformed); + } + else if (element == "not-acceptable") { + getPayloadInternal()->setCondition(ErrorPayload::NotAcceptable); + } + else if (element == "not-allowed") { + getPayloadInternal()->setCondition(ErrorPayload::NotAllowed); + } + else if (element == "not-authorized") { + getPayloadInternal()->setCondition(ErrorPayload::NotAuthorized); + } + else if (element == "payment-required") { + getPayloadInternal()->setCondition(ErrorPayload::PaymentRequired); + } + else if (element == "recipient-unavailable") { + getPayloadInternal()->setCondition(ErrorPayload::RecipientUnavailable); + } + else if (element == "redirect") { + getPayloadInternal()->setCondition(ErrorPayload::Redirect); + } + else if (element == "registration-required") { + getPayloadInternal()->setCondition(ErrorPayload::RegistrationRequired); + } + else if (element == "remote-server-not-found") { + getPayloadInternal()->setCondition(ErrorPayload::RemoteServerNotFound); + } + else if (element == "remote-server-timeout") { + getPayloadInternal()->setCondition(ErrorPayload::RemoteServerTimeout); + } + else if (element == "resource-constraint") { + getPayloadInternal()->setCondition(ErrorPayload::ResourceConstraint); + } + else if (element == "service-unavailable") { + getPayloadInternal()->setCondition(ErrorPayload::ServiceUnavailable); + } + else if (element == "subscription-required") { + getPayloadInternal()->setCondition(ErrorPayload::SubscriptionRequired); + } + else if (element == "unexpected-request") { + getPayloadInternal()->setCondition(ErrorPayload::UnexpectedRequest); + } + else { + PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); + } else { + getPayloadInternal()->setCondition(ErrorPayload::UndefinedCondition); + } + } + } + if (level_ >= PayloadLevel && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level_; } void ErrorParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (currentPayloadParser) { - if (level_ >= PayloadLevel) { - currentPayloadParser->handleEndElement(element, ns); - } + --level_; + if (currentPayloadParser) { + if (level_ >= PayloadLevel) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level_ == PayloadLevel) { - getPayloadInternal()->setPayload(currentPayloadParser->getPayload()); - currentPayloadParser.reset(); - } - } - else if (level_ == PayloadLevel) { - if (element == "text") { - getPayloadInternal()->setText(currentText_); - } - } + if (level_ == PayloadLevel) { + getPayloadInternal()->setPayload(currentPayloadParser->getPayload()); + currentPayloadParser.reset(); + } + } + else if (level_ == PayloadLevel) { + if (element == "text") { + getPayloadInternal()->setText(currentText_); + } + } } void ErrorParser::handleCharacterData(const std::string& data) { - if (level_ > PayloadLevel && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } - else { - currentText_ += data; - } + if (level_ > PayloadLevel && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } + else { + currentText_ += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/ErrorParser.h b/Swiften/Parser/PayloadParsers/ErrorParser.h index fc4a5cb..10f5431 100644 --- a/Swiften/Parser/PayloadParsers/ErrorParser.h +++ b/Swiften/Parser/PayloadParsers/ErrorParser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,23 +11,23 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class SWIFTEN_API ErrorParser : public GenericPayloadParser<ErrorPayload> { - public: - ErrorParser(PayloadParserFactoryCollection* factories); + class PayloadParserFactoryCollection; + class SWIFTEN_API ErrorParser : public GenericPayloadParser<ErrorPayload> { + public: + ErrorParser(PayloadParserFactoryCollection* factories); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - PayloadParserFactoryCollection* factories; - int level_; - std::string currentText_; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + PayloadParserFactoryCollection* factories; + int level_; + std::string currentText_; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/ErrorParserFactory.h b/Swiften/Parser/PayloadParsers/ErrorParserFactory.h index bcced8b..d8f09bf 100644 --- a/Swiften/Parser/PayloadParsers/ErrorParserFactory.h +++ b/Swiften/Parser/PayloadParsers/ErrorParserFactory.h @@ -11,23 +11,23 @@ #include <Swiften/Parser/PayloadParsers/ErrorParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API ErrorParserFactory : public PayloadParserFactory { - public: - ErrorParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } + class SWIFTEN_API ErrorParserFactory : public PayloadParserFactory { + public: + ErrorParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } - virtual bool canParse(const std::string& element, const std::string& /*ns*/, const AttributeMap&) const { - return element == "error"; - } + virtual bool canParse(const std::string& element, const std::string& /*ns*/, const AttributeMap&) const { + return element == "error"; + } - virtual PayloadParser* createPayloadParser() { - return new ErrorParser(factories); - } + virtual PayloadParser* createPayloadParser() { + return new ErrorParser(factories); + } - private: - PayloadParserFactoryCollection* factories; + private: + PayloadParserFactoryCollection* factories; - }; + }; } diff --git a/Swiften/Parser/PayloadParsers/FormParser.cpp b/Swiften/Parser/PayloadParsers/FormParser.cpp index d400c4c..dff45df 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.cpp +++ b/Swiften/Parser/PayloadParsers/FormParser.cpp @@ -1,254 +1,252 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include <iostream> #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), parseStarted_(false), hasReportedRef_(false){ +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) { - parseStarted_ = true; - 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; - } - else if (element == "item") { - parsingItem_ = true; - } - else if (element == "page") { - currentPage_ = boost::make_shared<FormPage>(); - currentPage_->setLabel(attributes.getAttribute("label")); - } - } - else if (level_ == FieldLevel && currentField_) { - currentText_.clear(); - if (element == "option") { - currentOptionLabel_ = attributes.getAttribute("label"); - currentOptionValue_ = ""; - parsingOption_ = true; - } - } - if (level_ >= PayloadLevel) { - if (element == "field") { - currentField_ = boost::make_shared<FormField>(); - std::string type = attributes.getAttribute("type"); - FormField::Type fieldType = FormField::UnknownType; - if (type == "boolean") { - fieldType = FormField::BooleanType; - } - if (type == "fixed") { - fieldType = FormField::FixedType; - } - if (type == "hidden") { - fieldType = FormField::HiddenType; - } - if (type == "list-single") { - fieldType = FormField::ListSingleType; - } - if (type == "text-multi") { - fieldType = FormField::TextMultiType; - } - if (type == "text-private") { - fieldType = FormField::TextPrivateType; - } - if (type == "text-single") { - fieldType = FormField::TextSingleType; - } - if (type == "jid-single") { - fieldType = FormField::JIDSingleType; - } - if (type == "jid-multi") { - fieldType = FormField::JIDMultiType; - } - if (type == "list-multi") { - fieldType = FormField::ListMultiType; - } - currentField_->setType(fieldType); - currentField_->setName(attributes.getAttribute("var")); - currentField_->setLabel(attributes.getAttribute("label")); - } - else if (element == "value") { - currentText_.clear(); - } - } - if (level_ > PayloadLevel) { - if (element == "section") { - currentSection_ = boost::make_shared<FormSection>(); - currentSection_->setLabel(attributes.getAttribute("label")); - sectionStack_.push_back(currentSection_); - currentSections_.push_back(currentSection_); - } - if (element == "reportedref") { - currentReportedRef_ = boost::make_shared<FormReportedRef>(); - } - if (element == "fieldref") { - currentText_.clear(); - currentFieldRef_ = attributes.getAttribute("var"); - if (sectionStack_.size() > 0) { - sectionStack_.at(sectionStack_.size()-1)->addFieldRef(currentFieldRef_); - } else if (currentPage_) { - currentPage_->addFieldRef(currentFieldRef_); - } - } - if (element == "text") { - currentText_.clear(); - currentTextElement_ = boost::make_shared<FormText>(); - } - } - ++level_; + 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; + } + else if (element == "item") { + parsingItem_ = true; + } + else if (element == "page") { + currentPage_ = std::make_shared<FormPage>(); + currentPage_->setLabel(attributes.getAttribute("label")); + } + } + else if (level_ == FieldLevel && currentField_) { + currentText_.clear(); + if (element == "option") { + currentOptionLabel_ = attributes.getAttribute("label"); + currentOptionValue_ = ""; + parsingOption_ = true; + } + } + if (level_ >= PayloadLevel) { + if (element == "field") { + currentField_ = std::make_shared<FormField>(); + std::string type = attributes.getAttribute("type"); + FormField::Type fieldType = FormField::UnknownType; + if (type == "boolean") { + fieldType = FormField::BooleanType; + } + if (type == "fixed") { + fieldType = FormField::FixedType; + } + if (type == "hidden") { + fieldType = FormField::HiddenType; + } + if (type == "list-single") { + fieldType = FormField::ListSingleType; + } + if (type == "text-multi") { + fieldType = FormField::TextMultiType; + } + if (type == "text-private") { + fieldType = FormField::TextPrivateType; + } + if (type == "text-single") { + fieldType = FormField::TextSingleType; + } + if (type == "jid-single") { + fieldType = FormField::JIDSingleType; + } + if (type == "jid-multi") { + fieldType = FormField::JIDMultiType; + } + if (type == "list-multi") { + fieldType = FormField::ListMultiType; + } + currentField_->setType(fieldType); + currentField_->setName(attributes.getAttribute("var")); + currentField_->setLabel(attributes.getAttribute("label")); + } + else if (element == "value") { + currentText_.clear(); + } + } + if (level_ > PayloadLevel) { + if (element == "section") { + currentSection_ = std::make_shared<FormSection>(); + currentSection_->setLabel(attributes.getAttribute("label")); + sectionStack_.push_back(currentSection_); + currentSections_.push_back(currentSection_); + } + if (element == "reportedref") { + currentReportedRef_ = std::make_shared<FormReportedRef>(); + } + if (element == "fieldref") { + currentText_.clear(); + currentFieldRef_ = attributes.getAttribute("var"); + if (sectionStack_.size() > 0) { + sectionStack_.at(sectionStack_.size()-1)->addFieldRef(currentFieldRef_); + } else if (currentPage_) { + currentPage_->addFieldRef(currentFieldRef_); + } + } + if (element == "text") { + currentText_.clear(); + currentTextElement_ = std::make_shared<FormText>(); + } + } + ++level_; } void FormParser::handleEndElement(const std::string& element, const std::string&) { - --level_; - if (level_ == PayloadLevel) { - if (element == "title") { - std::string currentTitle = getPayloadInternal()->getTitle(); - if (currentTitle.empty()) { - getPayloadInternal()->setTitle(currentText_); - } - else { - getPayloadInternal()->setTitle(currentTitle + "\n" + currentText_); - } - } - else if (element == "instructions") { - std::string currentInstructions = getPayloadInternal()->getInstructions(); - if (currentInstructions.empty()) { - getPayloadInternal()->setInstructions(currentText_); - } - else { - getPayloadInternal()->setInstructions(currentInstructions + "\n" + currentText_); - } - } - else if (element == "reported") { - parsingReported_ = false; - } - else if (element == "item") { - parsingItem_ = false; - getPayloadInternal()->addItem(currentFields_); - currentFields_.clear(); - } - else if (element == "page") { - getPayloadInternal()->addPage(currentPage_); - currentPages_.push_back(currentPage_); - } - } - 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 (boost::shared_ptr<FormPage> page, currentPages_) { - foreach (std::string pRef, page->getFieldRefs()) { - if (pRef == currentField_->getName()) { - page->addField(currentField_); - } - } - } - foreach (boost::shared_ptr<FormSection> section, currentSections_) { - foreach (std::string sRef, section->getFieldRefs()) { - if (sRef == 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 it's 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_); - } - hasReportedRef_ = true; - currentReportedRef_.reset(); - } - if (currentTextElement_) { - if (element == "text") { - currentTextElement_->setTextString(currentText_); - } - if (sectionStack_.size() > 0) { - sectionStack_.at(sectionStack_.size()-1)->addTextElement(currentTextElement_); - } else if (currentPage_) { - currentPage_->addTextElement(currentTextElement_); - } - currentTextElement_.reset(); - } - } + --level_; + if (level_ == PayloadLevel) { + if (element == "title") { + std::string currentTitle = getPayloadInternal()->getTitle(); + if (currentTitle.empty()) { + getPayloadInternal()->setTitle(currentText_); + } + else { + getPayloadInternal()->setTitle(currentTitle + "\n" + currentText_); + } + } + else if (element == "instructions") { + std::string currentInstructions = getPayloadInternal()->getInstructions(); + if (currentInstructions.empty()) { + getPayloadInternal()->setInstructions(currentText_); + } + else { + getPayloadInternal()->setInstructions(currentInstructions + "\n" + currentText_); + } + } + else if (element == "reported") { + parsingReported_ = false; + } + else if (element == "item") { + parsingItem_ = false; + getPayloadInternal()->addItem(currentFields_); + currentFields_.clear(); + } + else if (element == "page") { + getPayloadInternal()->addPage(currentPage_); + currentPages_.push_back(currentPage_); + } + } + 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) { + for (const auto& page : currentPages_) { + for (const auto& pageRef : page->getFieldRefs()) { + if (pageRef == currentField_->getName()) { + page->addField(currentField_); + } + } + } + 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_); + } + hasReportedRef_ = true; + currentReportedRef_.reset(); + } + if (currentTextElement_) { + if (element == "text") { + currentTextElement_->setTextString(currentText_); + } + if (sectionStack_.size() > 0) { + sectionStack_.at(sectionStack_.size()-1)->addTextElement(currentTextElement_); + } else if (currentPage_) { + currentPage_->addTextElement(currentTextElement_); + } + currentTextElement_.reset(); + } + } } void FormParser::handleCharacterData(const std::string& text) { - currentText_ += text; + currentText_ += text; } } diff --git a/Swiften/Parser/PayloadParsers/FormParser.h b/Swiften/Parser/PayloadParsers/FormParser.h index a3b7556..e1491b1 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.h +++ b/Swiften/Parser/PayloadParsers/FormParser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,37 +11,36 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API FormParser : public GenericPayloadParser<Form> { - public: - FormParser(); + class SWIFTEN_API FormParser : public GenericPayloadParser<Form> { + public: + FormParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - enum Level { - TopLevel = 0, - PayloadLevel = 1, - FieldLevel = 2 - }; - int level_; - std::string currentText_; - std::string currentOptionLabel_; - std::string currentOptionValue_; - std::string currentFieldRef_; - bool parsingItem_; - bool parsingReported_; - bool parsingOption_; - bool parseStarted_; - bool hasReportedRef_; - FormField::ref currentField_; - std::vector<FormField::ref> currentFields_; - FormText::text currentTextElement_; - FormReportedRef::ref currentReportedRef_; - FormPage::page currentPage_; - FormSection::section currentSection_; - std::vector<boost::shared_ptr<FormPage> > currentPages_; - std::vector<boost::shared_ptr<FormSection> > sectionStack_; - std::vector<boost::shared_ptr<FormSection> > currentSections_; - }; + enum Level { + TopLevel = 0, + PayloadLevel = 1, + FieldLevel = 2 + }; + int level_; + std::string currentText_; + std::string currentOptionLabel_; + std::string currentOptionValue_; + std::string currentFieldRef_; + bool parsingItem_; + bool parsingReported_; + bool parsingOption_; + bool hasReportedRef_; + FormField::ref currentField_; + std::vector<FormField::ref> currentFields_; + FormText::text currentTextElement_; + FormReportedRef::ref currentReportedRef_; + FormPage::page currentPage_; + FormSection::section currentSection_; + std::vector<std::shared_ptr<FormPage> > currentPages_; + std::vector<std::shared_ptr<FormSection> > sectionStack_; + std::vector<std::shared_ptr<FormSection> > currentSections_; + }; } diff --git a/Swiften/Parser/PayloadParsers/FormParserFactory.h b/Swiften/Parser/PayloadParsers/FormParserFactory.h index 74b2d35..851b302 100644 --- a/Swiften/Parser/PayloadParsers/FormParserFactory.h +++ b/Swiften/Parser/PayloadParsers/FormParserFactory.h @@ -11,20 +11,20 @@ #include <Swiften/Parser/PayloadParsers/FormParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API FormParserFactory : public PayloadParserFactory { - public: - FormParserFactory() { - } + class SWIFTEN_API FormParserFactory : public PayloadParserFactory { + public: + FormParserFactory() { + } - virtual bool canParse(const std::string& /*element*/, const std::string& ns, const AttributeMap&) const { - return ns == "jabber:x:data"; - } + virtual bool canParse(const std::string& /*element*/, const std::string& ns, const AttributeMap&) const { + return ns == "jabber:x:data"; + } - virtual PayloadParser* createPayloadParser() { - return new FormParser(); - } + virtual PayloadParser* createPayloadParser() { + return new FormParser(); + } - }; + }; } diff --git a/Swiften/Parser/PayloadParsers/ForwardedParser.cpp b/Swiften/Parser/PayloadParsers/ForwardedParser.cpp index 431c65c..72a665a 100644 --- a/Swiften/Parser/PayloadParsers/ForwardedParser.cpp +++ b/Swiften/Parser/PayloadParsers/ForwardedParser.cpp @@ -1,72 +1,73 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ +#include <Swiften/Parser/PayloadParsers/ForwardedParser.h> + #include <boost/lexical_cast.hpp> #include <boost/optional.hpp> + #include <Swiften/Base/DateTime.h> #include <Swiften/Parser/IQParser.h> #include <Swiften/Parser/MessageParser.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/DelayParser.h> -#include <Swiften/Parser/PayloadParsers/ForwardedParser.h> #include <Swiften/Parser/PresenceParser.h> - using namespace Swift; ForwardedParser::ForwardedParser(PayloadParserFactoryCollection* factories) : factories_(factories), level_(TopLevel) { } void ForwardedParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == PayloadLevel) { - if (element == "iq" && ns == "jabber:client") { /* begin parsing a nested stanza? */ - childParser_ = boost::dynamic_pointer_cast<StanzaParser>(boost::make_shared<IQParser>(factories_)); - } else if (element == "message" && ns == "jabber:client") { - childParser_ = boost::dynamic_pointer_cast<StanzaParser>(boost::make_shared<MessageParser>(factories_)); - } else if (element == "presence" && ns == "jabber:client") { - childParser_ = boost::dynamic_pointer_cast<StanzaParser>(boost::make_shared<PresenceParser>(factories_)); - } else if (element == "delay" && ns == "urn:xmpp:delay") { /* nested delay payload */ - delayParser_ = boost::make_shared<DelayParser>(); - } - } - if (childParser_) { /* parsing a nested stanza? */ - childParser_->handleStartElement(element, ns, attributes); - } - if (delayParser_) { /* parsing a nested delay payload? */ - delayParser_->handleStartElement(element, ns, attributes); - } - ++level_; + if (level_ == PayloadLevel) { + if (element == "iq" && ns == "jabber:client") { /* begin parsing a nested stanza? */ + childParser_ = std::dynamic_pointer_cast<StanzaParser>(std::make_shared<IQParser>(factories_)); + } else if (element == "message" && ns == "jabber:client") { + childParser_ = std::dynamic_pointer_cast<StanzaParser>(std::make_shared<MessageParser>(factories_)); + } else if (element == "presence" && ns == "jabber:client") { + childParser_ = std::dynamic_pointer_cast<StanzaParser>(std::make_shared<PresenceParser>(factories_)); + } else if (element == "delay" && ns == "urn:xmpp:delay") { /* nested delay payload */ + delayParser_ = std::make_shared<DelayParser>(); + } + } + if (childParser_) { /* parsing a nested stanza? */ + childParser_->handleStartElement(element, ns, attributes); + } + if (delayParser_) { /* parsing a nested delay payload? */ + delayParser_->handleStartElement(element, ns, attributes); + } + ++level_; } void ForwardedParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (childParser_ && level_ >= PayloadLevel) { - childParser_->handleEndElement(element, ns); - } - if (childParser_ && level_ == PayloadLevel) { - /* done parsing nested stanza */ - getPayloadInternal()->setStanza(childParser_->getStanza()); - childParser_.reset(); - } - if (delayParser_ && level_ >= PayloadLevel) { - delayParser_->handleEndElement(element, ns); - } - if (delayParser_ && level_ == PayloadLevel) { - /* done parsing nested delay payload */ - getPayloadInternal()->setDelay(boost::dynamic_pointer_cast<Delay>(delayParser_->getPayload())); - delayParser_.reset(); - } + --level_; + if (childParser_ && level_ >= PayloadLevel) { + childParser_->handleEndElement(element, ns); + } + if (childParser_ && level_ == PayloadLevel) { + /* done parsing nested stanza */ + getPayloadInternal()->setStanza(childParser_->getStanza()); + childParser_.reset(); + } + if (delayParser_ && level_ >= PayloadLevel) { + delayParser_->handleEndElement(element, ns); + } + if (delayParser_ && level_ == PayloadLevel) { + /* done parsing nested delay payload */ + getPayloadInternal()->setDelay(std::dynamic_pointer_cast<Delay>(delayParser_->getPayload())); + delayParser_.reset(); + } } void ForwardedParser::handleCharacterData(const std::string& data) { - if (childParser_) { - childParser_->handleCharacterData(data); - } - if (delayParser_) { - delayParser_->handleCharacterData(data); - } + if (childParser_) { + childParser_->handleCharacterData(data); + } + if (delayParser_) { + delayParser_->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/ForwardedParser.h b/Swiften/Parser/PayloadParsers/ForwardedParser.h index ad400e8..f91fda5 100644 --- a/Swiften/Parser/PayloadParsers/ForwardedParser.h +++ b/Swiften/Parser/PayloadParsers/ForwardedParser.h @@ -1,40 +1,40 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/Forwarded.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class StanzaParser; - class DelayParser; - - class SWIFTEN_API ForwardedParser : public GenericPayloadParser<Forwarded> { - public: - ForwardedParser(PayloadParserFactoryCollection* factories); - - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - - private: - PayloadParserFactoryCollection* factories_; - boost::shared_ptr<StanzaParser> childParser_; - boost::shared_ptr<DelayParser> delayParser_; - int level_; - }; + class PayloadParserFactoryCollection; + class StanzaParser; + class DelayParser; + + class SWIFTEN_API ForwardedParser : public GenericPayloadParser<Forwarded> { + public: + ForwardedParser(PayloadParserFactoryCollection* factories); + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + private: + PayloadParserFactoryCollection* factories_; + std::shared_ptr<StanzaParser> childParser_; + std::shared_ptr<DelayParser> delayParser_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index d791819..b67556e 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -1,17 +1,14 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * 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> @@ -46,7 +43,6 @@ #include <Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h> #include <Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h> #include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h> -#include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h> #include <Swiften/Parser/PayloadParsers/JingleParserFactory.h> #include <Swiften/Parser/PayloadParsers/JingleReasonParser.h> #include <Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h> @@ -92,99 +88,97 @@ #include <Swiften/Parser/PayloadParsers/VCardUpdateParser.h> #include <Swiften/Parser/PayloadParsers/WhiteboardParser.h> -using namespace boost; - namespace Swift { FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<IBBParser> >("", "http://jabber.org/protocol/ibb")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StatusShowParser> >("show")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StatusParser> >("status")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ReplaceParser> >("replace", "http://swift.im/protocol/replace")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ReplaceParser> >("replace", "urn:xmpp:message-correct:0")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<LastParser> >("query", "jabber:iq:last")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BodyParser> >("body")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<SubjectParser> >("subject")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ThreadParser> >("thread")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<PriorityParser> >("priority")); - factories_.push_back(boost::make_shared<ErrorParserFactory>(this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<DelayParser> >("delay", "urn:xmpp:delay")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<SoftwareVersionParser> >("query", "jabber:iq:version")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StorageParser> >("storage", "storage:bookmarks")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<RosterItemExchangeParser> >("x", "http://jabber.org/protocol/rosterx")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<RosterParser> >("query", "jabber:iq:roster")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<DiscoInfoParser> >("query", "http://jabber.org/protocol/disco#info")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<DiscoItemsParser> >("query", "http://jabber.org/protocol/disco#items")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CapsInfoParser> >("c", "http://jabber.org/protocol/caps")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ResourceBindParser> >("bind", "urn:ietf:params:xml:ns:xmpp-bind")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StartSessionParser> >("session", "urn:ietf:params:xml:ns:xmpp-session")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BlockParser<BlockPayload> > >("block", "urn:xmpp:blocking")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BlockParser<BlockListPayload> > >("blocklist", "urn:xmpp:blocking")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BlockParser<UnblockPayload> > >("unblock", "urn:xmpp:blocking")); - factories_.push_back(boost::make_shared<SecurityLabelParserFactory>()); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<SecurityLabelsCatalogParser> >("catalog", "urn:xmpp:sec-label:catalog:2")); - factories_.push_back(boost::make_shared<FormParserFactory>()); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CommandParser> >("command", "http://jabber.org/protocol/commands")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<InBandRegistrationPayloadParser> >("query", "jabber:iq:register")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<SearchPayloadParser> >("query", "jabber:iq:search")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StreamInitiationParser> >("si", "http://jabber.org/protocol/si")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<BytestreamsParser> >("query", "http://jabber.org/protocol/bytestreams")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<VCardUpdateParser> >("x", "vcard-temp:x:update")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<VCardParser> >("vCard", "vcard-temp")); - factories_.push_back(boost::make_shared<PrivateStorageParserFactory>(this)); - factories_.push_back(boost::make_shared<ChatStateParserFactory>()); - factories_.push_back(boost::make_shared<MUCUserPayloadParserFactory>(this)); - factories_.push_back(boost::make_shared<MUCOwnerPayloadParserFactory>(this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCInvitationPayloadParser> >("x", "jabber:x:conference")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCAdminPayloadParser> >("query", "http://jabber.org/protocol/muc#admin")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#user")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#owner")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<NicknameParser> >("nick", "http://jabber.org/protocol/nick")); - factories_.push_back(boost::make_shared<JingleParserFactory>(this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleReasonParser> >("reason", "urn:xmpp:jingle:1")); - factories_.push_back(boost::make_shared<JingleContentPayloadParserFactory>(this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleIBBTransportMethodPayloadParser> >("transport", "urn:xmpp:jingle:transports:ibb:1")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleS5BTransportMethodPayloadParser> >("transport", "urn:xmpp:jingle:transports:s5b:1")); - factories_.push_back(boost::make_shared<JingleFileTransferDescriptionParserFactory>(this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<StreamInitiationFileInfoParser> >("file", "http://jabber.org/protocol/si/profile/file-transfer")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferFileInfoParser> >("file", "urn:xmpp:jingle:apps:file-transfer:4")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferHashParser> >("checksum")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<S5BProxyRequestParser> >("query", "http://jabber.org/protocol/bytestreams")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<WhiteboardParser> >("wb", "http://swift.im/whiteboard")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<UserLocationParser> >("geoloc", "http://jabber.org/protocol/geoloc")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<UserTuneParser> >("tune", "http://jabber.org/protocol/tune")); - factories_.push_back(boost::make_shared<DeliveryReceiptParserFactory>()); - factories_.push_back(boost::make_shared<DeliveryReceiptRequestParserFactory>()); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<IdleParser> >("idle", "urn:xmpp:idle:1")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubOwnerPubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub#owner", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubEventParser> >("event", "http://jabber.org/protocol/pubsub#event", this)); - factories_.push_back(boost::make_shared<PubSubErrorParserFactory>()); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ResultSetParser> >("set", "http://jabber.org/protocol/rsm")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<ForwardedParser> >("forwarded", "urn:xmpp:forward:0", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<MAMResultParser> >("result", "urn:xmpp:mam:0", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMQueryParser> >("query", "urn:xmpp:mam:0")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMFinParser> >("fin", "urn:xmpp:mam:0")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<IsodeIQDelegationParser> >("delegate", "http://isode.com/iq_delegation", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CarbonsEnableParser> >("enable", "urn:xmpp:carbons:2")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CarbonsDisableParser> >("disable", "urn:xmpp:carbons:2")); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<CarbonsReceivedParser> >("received", "urn:xmpp:carbons:2", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<CarbonsSentParser> >("sent", "urn:xmpp:carbons:2", this)); - factories_.push_back(boost::make_shared<GenericPayloadParserFactory<CarbonsPrivateParser> >("private", "urn:xmpp:carbons:2")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<IBBParser> >("", "http://jabber.org/protocol/ibb")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<StatusShowParser> >("show")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<StatusParser> >("status")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<ReplaceParser> >("replace", "http://swift.im/protocol/replace")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<ReplaceParser> >("replace", "urn:xmpp:message-correct:0")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<LastParser> >("query", "jabber:iq:last")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<BodyParser> >("body")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<SubjectParser> >("subject")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<ThreadParser> >("thread")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<PriorityParser> >("priority")); + factories_.push_back(std::make_shared<ErrorParserFactory>(this)); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<DelayParser> >("delay", "urn:xmpp:delay")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<SoftwareVersionParser> >("query", "jabber:iq:version")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<StorageParser> >("storage", "storage:bookmarks")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<RosterItemExchangeParser> >("x", "http://jabber.org/protocol/rosterx")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<RosterParser> >("query", "jabber:iq:roster")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<DiscoInfoParser> >("query", "http://jabber.org/protocol/disco#info")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<DiscoItemsParser> >("query", "http://jabber.org/protocol/disco#items")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<CapsInfoParser> >("c", "http://jabber.org/protocol/caps")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<ResourceBindParser> >("bind", "urn:ietf:params:xml:ns:xmpp-bind")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<StartSessionParser> >("session", "urn:ietf:params:xml:ns:xmpp-session")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<BlockParser<BlockPayload> > >("block", "urn:xmpp:blocking")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<BlockParser<BlockListPayload> > >("blocklist", "urn:xmpp:blocking")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<BlockParser<UnblockPayload> > >("unblock", "urn:xmpp:blocking")); + factories_.push_back(std::make_shared<SecurityLabelParserFactory>()); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<SecurityLabelsCatalogParser> >("catalog", "urn:xmpp:sec-label:catalog:2")); + factories_.push_back(std::make_shared<FormParserFactory>()); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<CommandParser> >("command", "http://jabber.org/protocol/commands")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<InBandRegistrationPayloadParser> >("query", "jabber:iq:register")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<SearchPayloadParser> >("query", "jabber:iq:search")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<StreamInitiationParser> >("si", "http://jabber.org/protocol/si")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<BytestreamsParser> >("query", "http://jabber.org/protocol/bytestreams")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<VCardUpdateParser> >("x", "vcard-temp:x:update")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<VCardParser> >("vCard", "vcard-temp")); + factories_.push_back(std::make_shared<PrivateStorageParserFactory>(this)); + factories_.push_back(std::make_shared<ChatStateParserFactory>()); + factories_.push_back(std::make_shared<MUCUserPayloadParserFactory>(this)); + factories_.push_back(std::make_shared<MUCOwnerPayloadParserFactory>(this)); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<MUCInvitationPayloadParser> >("x", "jabber:x:conference")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<MUCAdminPayloadParser> >("query", "http://jabber.org/protocol/muc#admin")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#user")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#owner")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<NicknameParser> >("nick", "http://jabber.org/protocol/nick")); + factories_.push_back(std::make_shared<JingleParserFactory>(this)); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<JingleReasonParser> >("reason", "urn:xmpp:jingle:1")); + 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(shared_ptr<PayloadParserFactory> factory, factories_) { - addFactory(factory.get()); - } - defaultFactory_ = new RawXMLPayloadParserFactory(); - setDefaultFactory(defaultFactory_); + for (auto& factory : factories_) { + addFactory(factory.get()); + } + defaultFactory_ = new RawXMLPayloadParserFactory(); + setDefaultFactory(defaultFactory_); } FullPayloadParserFactoryCollection::~FullPayloadParserFactoryCollection() { - setDefaultFactory(NULL); - delete defaultFactory_; - foreach(shared_ptr<PayloadParserFactory> factory, factories_) { - removeFactory(factory.get()); - } + setDefaultFactory(nullptr); + delete defaultFactory_; + for (auto& factory : factories_) { + removeFactory(factory.get()); + } } } diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h index 73d785e..e59a6e0 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h @@ -1,26 +1,26 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> #include <vector> #include <Swiften/Base/API.h> -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> namespace Swift { - class SWIFTEN_API FullPayloadParserFactoryCollection : public PayloadParserFactoryCollection { - public: - FullPayloadParserFactoryCollection(); - ~FullPayloadParserFactoryCollection(); + class SWIFTEN_API FullPayloadParserFactoryCollection : public PayloadParserFactoryCollection { + public: + FullPayloadParserFactoryCollection(); + ~FullPayloadParserFactoryCollection(); - private: - std::vector< boost::shared_ptr<PayloadParserFactory> > factories_; - PayloadParserFactory* defaultFactory_; - }; + private: + std::vector< std::shared_ptr<PayloadParserFactory> > factories_; + PayloadParserFactory* defaultFactory_; + }; } diff --git a/Swiften/Parser/PayloadParsers/IBBParser.cpp b/Swiften/Parser/PayloadParsers/IBBParser.cpp index c04e3cc..9b6babc 100644 --- a/Swiften/Parser/PayloadParsers/IBBParser.cpp +++ b/Swiften/Parser/PayloadParsers/IBBParser.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,7 +8,6 @@ #include <boost/lexical_cast.hpp> -#include <Swiften/Base/foreach.h> #include <Swiften/StringCodecs/Base64.h> namespace Swift { @@ -20,57 +19,56 @@ 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); - } - try { - getPayloadInternal()->setBlockSize(boost::lexical_cast<int>(attributes.getAttribute("block-size"))); - } - catch (boost::bad_lexical_cast&) { - } - } - else if (element == "close") { - getPayloadInternal()->setAction(IBB::Close); - getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); - } - } - ++level; + 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); + } + try { + getPayloadInternal()->setBlockSize(boost::lexical_cast<int>(attributes.getAttribute("block-size"))); + } + catch (boost::bad_lexical_cast&) { + } + } + else if (element == "close") { + getPayloadInternal()->setAction(IBB::Close); + getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); + } + } + ++level; } void IBBParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (level == TopLevel) { - if (element == "data") { - std::vector<char> data; - for (size_t i = 0; i < currentText.size(); ++i) { - char c = currentText[i]; - if ((c >= 48 && c <= 122) || c == 47 || c == 43) { - data.push_back(c); - } - } - getPayloadInternal()->setData(Base64::decode(std::string(&data[0], data.size()))); - } - } + --level; + if (level == TopLevel) { + if (element == "data") { + std::vector<char> data; + for (char c : currentText) { + if ((c >= 48 && c <= 122) || c == 47 || c == 43) { + data.push_back(c); + } + } + getPayloadInternal()->setData(Base64::decode(std::string(&data[0], data.size()))); + } + } } void IBBParser::handleCharacterData(const std::string& data) { - currentText += data; + currentText += data; } diff --git a/Swiften/Parser/PayloadParsers/IBBParser.h b/Swiften/Parser/PayloadParsers/IBBParser.h index 95fe61a..7ef3e6f 100644 --- a/Swiften/Parser/PayloadParsers/IBBParser.h +++ b/Swiften/Parser/PayloadParsers/IBBParser.h @@ -13,20 +13,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API IBBParser : public GenericPayloadParser<IBB> { - public: - IBBParser(); - ~IBBParser(); + class SWIFTEN_API IBBParser : public GenericPayloadParser<IBB> { + public: + IBBParser(); + ~IBBParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0 - }; - int level; - std::string currentText; - }; + private: + enum Level { + TopLevel = 0 + }; + int level; + std::string currentText; + }; } diff --git a/Swiften/Parser/PayloadParsers/IdleParser.cpp b/Swiften/Parser/PayloadParsers/IdleParser.cpp index 51aa34b..e985576 100644 --- a/Swiften/Parser/PayloadParsers/IdleParser.cpp +++ b/Swiften/Parser/PayloadParsers/IdleParser.cpp @@ -14,15 +14,15 @@ IdleParser::IdleParser() : level_(0) { } void IdleParser::handleStartElement(const std::string& /*element*/, const std::string& /*ns*/, const AttributeMap& attributes) { - if (level_ == 0) { - boost::posix_time::ptime since = stringToDateTime(attributes.getAttribute("since")); - getPayloadInternal()->setSince(since); - } - ++level_; + if (level_ == 0) { + boost::posix_time::ptime since = stringToDateTime(attributes.getAttribute("since")); + getPayloadInternal()->setSince(since); + } + ++level_; } void IdleParser::handleEndElement(const std::string&, const std::string&) { - --level_; + --level_; } void IdleParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/IdleParser.h b/Swiften/Parser/PayloadParsers/IdleParser.h index e8bbcf6..c1922c0 100644 --- a/Swiften/Parser/PayloadParsers/IdleParser.h +++ b/Swiften/Parser/PayloadParsers/IdleParser.h @@ -5,27 +5,27 @@ */ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once - + #include <Swiften/Base/API.h> #include <Swiften/Elements/Idle.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API IdleParser : public GenericPayloadParser<Idle> { - public: - IdleParser(); + class SWIFTEN_API IdleParser : public GenericPayloadParser<Idle> { + public: + IdleParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - }; + private: + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp index a9aa266..f0241b0 100644 --- a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp @@ -1,131 +1,133 @@ /* - * 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/InBandRegistrationPayloadParser.h> +#include <cassert> + #include <boost/cast.hpp> -#include <Swiften/Parser/PayloadParsers/FormParserFactory.h> #include <Swiften/Parser/PayloadParsers/FormParser.h> +#include <Swiften/Parser/PayloadParsers/FormParserFactory.h> namespace Swift { -InBandRegistrationPayloadParser::InBandRegistrationPayloadParser() : level(TopLevel), formParser(NULL) { - formParserFactory = new FormParserFactory(); +InBandRegistrationPayloadParser::InBandRegistrationPayloadParser() : level(TopLevel), formParser(nullptr) { + formParserFactory = new FormParserFactory(); } InBandRegistrationPayloadParser::~InBandRegistrationPayloadParser() { - delete formParserFactory; + delete formParserFactory; } void InBandRegistrationPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == TopLevel) { - } - else if (level == PayloadLevel) { - if (element == "x" && ns == "jabber:x:data") { - assert(!formParser); - formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); - } - else { - currentText.clear(); - } - } + if (level == TopLevel) { + } + else if (level == PayloadLevel) { + if (element == "x" && ns == "jabber:x:data") { + assert(!formParser); + formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); + } + else { + currentText.clear(); + } + } - if (formParser) { - formParser->handleStartElement(element, ns, attributes); - } + if (formParser) { + formParser->handleStartElement(element, ns, attributes); + } - ++level; + ++level; } void InBandRegistrationPayloadParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; + --level; - if (formParser) { - formParser->handleEndElement(element, ns); - } + if (formParser) { + formParser->handleEndElement(element, ns); + } - if (level == TopLevel) { - } - else if (level == PayloadLevel) { - if (formParser) { - getPayloadInternal()->setForm(formParser->getPayloadInternal()); - delete formParser; - formParser = NULL; - } - else if (element == "registered") { - getPayloadInternal()->setRegistered(true); - } - else if (element == "remove") { - getPayloadInternal()->setRemove(true); - } - else if (element == "instructions") { - getPayloadInternal()->setInstructions(currentText); - } - else if (element == "username") { - getPayloadInternal()->setUsername(currentText); - } - else if (element == "nick") { - getPayloadInternal()->setNick(currentText); - } - else if (element == "password") { - getPayloadInternal()->setPassword(currentText); - } - else if (element == "name") { - getPayloadInternal()->setName(currentText); - } - else if (element == "first") { - getPayloadInternal()->setFirst(currentText); - } - else if (element == "last") { - getPayloadInternal()->setLast(currentText); - } - else if (element == "email") { - getPayloadInternal()->setEMail(currentText); - } - else if (element == "address") { - getPayloadInternal()->setAddress(currentText); - } - else if (element == "city") { - getPayloadInternal()->setCity(currentText); - } - else if (element == "state") { - getPayloadInternal()->setState(currentText); - } - else if (element == "zip") { - getPayloadInternal()->setZip(currentText); - } - else if (element == "phone") { - getPayloadInternal()->setPhone(currentText); - } - else if (element == "url") { - getPayloadInternal()->setURL(currentText); - } - else if (element == "date") { - getPayloadInternal()->setDate(currentText); - } - else if (element == "misc") { - getPayloadInternal()->setMisc(currentText); - } - else if (element == "text") { - getPayloadInternal()->setText(currentText); - } - else if (element == "key") { - getPayloadInternal()->setKey(currentText); - } - } + if (level == TopLevel) { + } + else if (level == PayloadLevel) { + if (formParser) { + getPayloadInternal()->setForm(formParser->getPayloadInternal()); + delete formParser; + formParser = nullptr; + } + else if (element == "registered") { + getPayloadInternal()->setRegistered(true); + } + else if (element == "remove") { + getPayloadInternal()->setRemove(true); + } + else if (element == "instructions") { + getPayloadInternal()->setInstructions(currentText); + } + else if (element == "username") { + getPayloadInternal()->setUsername(currentText); + } + else if (element == "nick") { + getPayloadInternal()->setNick(currentText); + } + else if (element == "password") { + getPayloadInternal()->setPassword(currentText); + } + else if (element == "name") { + getPayloadInternal()->setName(currentText); + } + else if (element == "first") { + getPayloadInternal()->setFirst(currentText); + } + else if (element == "last") { + getPayloadInternal()->setLast(currentText); + } + else if (element == "email") { + getPayloadInternal()->setEMail(currentText); + } + else if (element == "address") { + getPayloadInternal()->setAddress(currentText); + } + else if (element == "city") { + getPayloadInternal()->setCity(currentText); + } + else if (element == "state") { + getPayloadInternal()->setState(currentText); + } + else if (element == "zip") { + getPayloadInternal()->setZip(currentText); + } + else if (element == "phone") { + getPayloadInternal()->setPhone(currentText); + } + else if (element == "url") { + getPayloadInternal()->setURL(currentText); + } + else if (element == "date") { + getPayloadInternal()->setDate(currentText); + } + else if (element == "misc") { + getPayloadInternal()->setMisc(currentText); + } + else if (element == "text") { + getPayloadInternal()->setText(currentText); + } + else if (element == "key") { + getPayloadInternal()->setKey(currentText); + } + } } void InBandRegistrationPayloadParser::handleCharacterData(const std::string& data) { - if (formParser) { - formParser->handleCharacterData(data); - } - else { - currentText += data; - } + if (formParser) { + formParser->handleCharacterData(data); + } + else { + currentText += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h index cd8c452..7e2a4a4 100644 --- a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h @@ -13,26 +13,26 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class FormParserFactory; - class FormParser; + class FormParserFactory; + class FormParser; - class SWIFTEN_API InBandRegistrationPayloadParser : public GenericPayloadParser<InBandRegistrationPayload> { - public: - InBandRegistrationPayloadParser(); - ~InBandRegistrationPayloadParser(); + class SWIFTEN_API InBandRegistrationPayloadParser : public GenericPayloadParser<InBandRegistrationPayload> { + public: + InBandRegistrationPayloadParser(); + ~InBandRegistrationPayloadParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - int level; - FormParserFactory* formParserFactory; - FormParser* formParser; - std::string currentText; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + int level; + FormParserFactory* formParserFactory; + FormParser* formParser; + std::string currentText; + }; } diff --git a/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp index 483654a..2efe3c8 100644 --- a/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp +++ b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp @@ -1,19 +1,15 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - +#include <Swiften/Parser/PayloadParserFactoryCollection.h> using namespace Swift; @@ -24,36 +20,36 @@ IsodeIQDelegationParser::~IsodeIQDelegationParser() { } void IsodeIQDelegationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - - - if (level == 1) { - if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { - currentPayloadParser.reset(factory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + + + if (level == 1) { + if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { + currentPayloadParser.reset(factory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void IsodeIQDelegationParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - getPayloadInternal()->setForward(boost::dynamic_pointer_cast<Forwarded>(currentPayloadParser->getPayload())); - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + getPayloadInternal()->setForward(std::dynamic_pointer_cast<Forwarded>(currentPayloadParser->getPayload())); + currentPayloadParser.reset(); + } + } } void IsodeIQDelegationParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h index fcdbeb1..eaedd27 100644 --- a/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h +++ b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/IsodeIQDelegation.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API IsodeIQDelegationParser : public GenericPayloadParser<IsodeIQDelegation> { - public: - IsodeIQDelegationParser(PayloadParserFactoryCollection* parsers); - virtual ~IsodeIQDelegationParser(); + class SWIFTEN_API IsodeIQDelegationParser : public GenericPayloadParser<IsodeIQDelegation> { + public: + IsodeIQDelegationParser(PayloadParserFactoryCollection* parsers); + virtual ~IsodeIQDelegationParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.cpp b/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.cpp index 1431b9e..3a01676 100644 --- a/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.cpp @@ -4,71 +4,77 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ -#include "JingleContentPayloadParser.h" -#include <Swiften/Parser/PayloadParserFactoryCollection.h> -#include <Swiften/Parser/PayloadParserFactory.h> -#include <Swiften/Elements/JinglePayload.h> +/* + * Copyright (c) 2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h> #include <Swiften/Base/Log.h> +#include <Swiften/Elements/JinglePayload.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> namespace Swift { - JingleContentPayloadParser::JingleContentPayloadParser(PayloadParserFactoryCollection* factories) : factories(factories), level(0) { - - } - - void JingleContentPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - std::string creator = attributes.getAttributeValue("creator").get_value_or(""); - if (creator == "initiator") { - getPayloadInternal()->setCreator(JingleContentPayload::InitiatorCreator); - } else if (creator == "responder") { - getPayloadInternal()->setCreator(JingleContentPayload::ResponderCreator); - } else { - getPayloadInternal()->setCreator(JingleContentPayload::UnknownCreator); - } - - getPayloadInternal()->setName(attributes.getAttributeValue("name").get_value_or("")); - } - - if (level == 1) { - PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - - ++level; - } - - void JingleContentPayloadParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - boost::shared_ptr<JingleTransportPayload> transport = boost::dynamic_pointer_cast<JingleTransportPayload>(currentPayloadParser->getPayload()); - if (transport) { - getPayloadInternal()->addTransport(transport); - } - - boost::shared_ptr<JingleDescription> description = boost::dynamic_pointer_cast<JingleDescription>(currentPayloadParser->getPayload()); - if (description) { - getPayloadInternal()->addDescription(description); - } - } - } - } - - void JingleContentPayloadParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } - } + JingleContentPayloadParser::JingleContentPayloadParser(PayloadParserFactoryCollection* factories) : factories(factories), level(0) { + + } + + void JingleContentPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + std::string creator = attributes.getAttributeValue("creator").get_value_or(""); + if (creator == "initiator") { + getPayloadInternal()->setCreator(JingleContentPayload::InitiatorCreator); + } else if (creator == "responder") { + getPayloadInternal()->setCreator(JingleContentPayload::ResponderCreator); + } else { + getPayloadInternal()->setCreator(JingleContentPayload::UnknownCreator); + } + + getPayloadInternal()->setName(attributes.getAttributeValue("name").get_value_or("")); + } + + if (level == 1) { + PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + + ++level; + } + + void JingleContentPayloadParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + std::shared_ptr<JingleTransportPayload> transport = std::dynamic_pointer_cast<JingleTransportPayload>(currentPayloadParser->getPayload()); + if (transport) { + getPayloadInternal()->addTransport(transport); + } + + std::shared_ptr<JingleDescription> description = std::dynamic_pointer_cast<JingleDescription>(currentPayloadParser->getPayload()); + if (description) { + getPayloadInternal()->addDescription(description); + } + } + } + } + + void JingleContentPayloadParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } + } } diff --git a/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h b/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h index 977d2eb..fde07cb 100644 --- a/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -21,17 +21,17 @@ namespace Swift { class PayloadParserFactoryCollection; class SWIFTEN_API JingleContentPayloadParser : public GenericPayloadParser<JingleContentPayload> { - public: - JingleContentPayloadParser(PayloadParserFactoryCollection* factories); + public: + JingleContentPayloadParser(PayloadParserFactoryCollection* factories); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - PayloadParserFactoryCollection* factories; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; + private: + PayloadParserFactoryCollection* factories; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h index b343c24..8e9741d 100644 --- a/Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h @@ -17,26 +17,26 @@ #include <Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h> namespace Swift { - - class PayloadParserFactoryCollection; - - class SWIFTEN_API JingleContentPayloadParserFactory : public PayloadParserFactory { - public: - JingleContentPayloadParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } - - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return element == "content" && ns == "urn:xmpp:jingle:1"; - } - - virtual PayloadParser* createPayloadParser() { - return new JingleContentPayloadParser(factories); - } - - private: - PayloadParserFactoryCollection* factories; - - }; + + class PayloadParserFactoryCollection; + + class SWIFTEN_API JingleContentPayloadParserFactory : public PayloadParserFactory { + public: + JingleContentPayloadParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "content" && ns == "urn:xmpp:jingle:1"; + } + + virtual PayloadParser* createPayloadParser() { + return new JingleContentPayloadParser(factories); + } + + private: + PayloadParserFactoryCollection* factories; + + }; } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp index fb1836f..1e433a6 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp @@ -5,19 +5,19 @@ */ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h> -#include <boost/optional.hpp> #include <boost/lexical_cast.hpp> +#include <boost/optional.hpp> -#include <Swiften/Parser/PayloadParserFactoryCollection.h> -#include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Base/DateTime.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/StringCodecs/Base64.h> namespace Swift { @@ -26,37 +26,37 @@ JingleFileTransferDescriptionParser::JingleFileTransferDescriptionParser(Payload } void JingleFileTransferDescriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 1) { - PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 1) { + PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void JingleFileTransferDescriptionParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 0) { - boost::shared_ptr<JingleFileTransferFileInfo> info = boost::dynamic_pointer_cast<JingleFileTransferFileInfo>(currentPayloadParser->getPayload()); - if (info) { - getPayloadInternal()->setFileInfo(*info); - } - } + --level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 0) { + std::shared_ptr<JingleFileTransferFileInfo> info = std::dynamic_pointer_cast<JingleFileTransferFileInfo>(currentPayloadParser->getPayload()); + if (info) { + getPayloadInternal()->setFileInfo(*info); + } + } } void JingleFileTransferDescriptionParser::handleCharacterData(const std::string& data) { - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h index 52dd232..b148d9b 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2014-2015 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -22,17 +22,17 @@ namespace Swift { class PayloadParserFactoryCollection; class SWIFTEN_API JingleFileTransferDescriptionParser : public GenericPayloadParser<JingleFileTransferDescription> { - public: - JingleFileTransferDescriptionParser(PayloadParserFactoryCollection* factories); + public: + JingleFileTransferDescriptionParser(PayloadParserFactoryCollection* factories); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - PayloadParserFactoryCollection* factories; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; + private: + PayloadParserFactoryCollection* factories; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h index f8a340c..c75125f 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h @@ -17,26 +17,26 @@ #include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h> namespace Swift { - - class PayloadParserFactoryCollection; - - class SWIFTEN_API JingleFileTransferDescriptionParserFactory : public PayloadParserFactory { - public: - JingleFileTransferDescriptionParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } - - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return element == "description" && ns == "urn:xmpp:jingle:apps:file-transfer:4"; - } - - virtual PayloadParser* createPayloadParser() { - return new JingleFileTransferDescriptionParser(factories); - } - - private: - PayloadParserFactoryCollection* factories; - - }; + + class PayloadParserFactoryCollection; + + class SWIFTEN_API JingleFileTransferDescriptionParserFactory : public PayloadParserFactory { + public: + JingleFileTransferDescriptionParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "description" && ns == "urn:xmpp:jingle:apps:file-transfer:4"; + } + + virtual PayloadParser* createPayloadParser() { + return new JingleFileTransferDescriptionParser(factories); + } + + private: + PayloadParserFactoryCollection* factories; + + }; } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp index 2a62f23..4f8b9a9 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp @@ -1,79 +1,79 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h> -#include <boost/optional.hpp> #include <boost/lexical_cast.hpp> +#include <boost/optional.hpp> #include <Swiften/Base/DateTime.h> #include <Swiften/StringCodecs/Base64.h> namespace Swift { -JingleFileTransferFileInfoParser::JingleFileTransferFileInfoParser() : level(0) { +JingleFileTransferFileInfoParser::JingleFileTransferFileInfoParser() : level(0) { } template<typename T> boost::optional<T> safeLexicalCast(const std::string& str) { - boost::optional<T> ret; - try { - ret = boost::lexical_cast<T>(str); - } catch (boost::bad_lexical_cast &) { + boost::optional<T> ret; + try { + ret = boost::lexical_cast<T>(str); + } catch (boost::bad_lexical_cast &) { - } - return ret; + } + return ret; } void JingleFileTransferFileInfoParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - charData.clear(); - if (element == "hash") { - hashAlg = attributes.getAttributeValue("algo").get_value_or(""); - } - else if (element == "range") { - rangeOffset = safeLexicalCast<boost::uintmax_t>(attributes.getAttributeValue("offset").get_value_or("")); - } + charData.clear(); + if (element == "hash") { + hashAlg = attributes.getAttributeValue("algo").get_value_or(""); + } + else if (element == "range") { + rangeOffset = safeLexicalCast<boost::uintmax_t>(attributes.getAttributeValue("offset").get_value_or("")); + } - ++level; + ++level; } void JingleFileTransferFileInfoParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (level == 1) { - if (element == "date") { - getPayloadInternal()->setDate(stringToDateTime(charData)); - } - else if (element == "desc") { - getPayloadInternal()->setDescription(charData); - } - else if (element == "media-type") { - getPayloadInternal()->setMediaType(charData); - } - else if (element == "name") { - getPayloadInternal()->setName(charData); - } - else if (element == "size") { - boost::optional<boost::uintmax_t> size = safeLexicalCast<boost::uintmax_t>(charData); - if (size) { - getPayloadInternal()->setSize(size.get()); - } - } - else if (element == "range") { - getPayloadInternal()->setSupportsRangeRequests(true); - if (rangeOffset) { - getPayloadInternal()->setRangeOffset(rangeOffset.get_value_or(0)); - } - } - else if (element == "hash") { - getPayloadInternal()->addHash(HashElement(hashAlg, Base64::decode(charData))); - } - } + --level; + if (level == 1) { + if (element == "date") { + getPayloadInternal()->setDate(stringToDateTime(charData)); + } + else if (element == "desc") { + getPayloadInternal()->setDescription(charData); + } + else if (element == "media-type") { + getPayloadInternal()->setMediaType(charData); + } + else if (element == "name") { + getPayloadInternal()->setName(charData); + } + else if (element == "size") { + boost::optional<boost::uintmax_t> size = safeLexicalCast<boost::uintmax_t>(charData); + if (size) { + getPayloadInternal()->setSize(size.get()); + } + } + else if (element == "range") { + getPayloadInternal()->setSupportsRangeRequests(true); + if (rangeOffset) { + getPayloadInternal()->setRangeOffset(rangeOffset.get_value_or(0)); + } + } + else if (element == "hash") { + getPayloadInternal()->addHash(HashElement(hashAlg, Base64::decode(charData))); + } + } } void JingleFileTransferFileInfoParser::handleCharacterData(const std::string& data) { - charData += data; + charData += data; } } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h index e49ee69..237f105 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h @@ -13,18 +13,18 @@ namespace Swift { class SWIFTEN_API JingleFileTransferFileInfoParser : public GenericPayloadParser<JingleFileTransferFileInfo> { - public: - JingleFileTransferFileInfoParser(); + public: + JingleFileTransferFileInfoParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - - private: - int level; - std::string charData; - std::string hashAlg; - boost::optional<boost::uintmax_t> rangeOffset; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + + private: + int level; + std::string charData; + std::string hashAlg; + boost::optional<boost::uintmax_t> rangeOffset; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp index 6a1a031..4adf3bd 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp @@ -5,54 +5,55 @@ */ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "JingleFileTransferHashParser.h" +#include <Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h> + +#include <memory> -#include <boost/shared_ptr.hpp> #include <boost/algorithm/string.hpp> -#include <Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h> #include <Swiften/Parser/GenericPayloadParserFactory.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h> namespace Swift { JingleFileTransferHashParser::JingleFileTransferHashParser() : level(0) { } - + void JingleFileTransferHashParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 1 && element == "file") { - currentPayloadParser = boost::make_shared<JingleFileTransferFileInfoParser>(); - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 1 && element == "file") { + currentPayloadParser = std::make_shared<JingleFileTransferFileInfoParser>(); + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void JingleFileTransferHashParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - boost::shared_ptr<JingleFileTransferFileInfo> info = boost::dynamic_pointer_cast<JingleFileTransferFileInfo>(currentPayloadParser->getPayload()); - if (info) { - getPayloadInternal()->setFileInfo(*info); - } - } + --level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + std::shared_ptr<JingleFileTransferFileInfo> info = std::dynamic_pointer_cast<JingleFileTransferFileInfo>(currentPayloadParser->getPayload()); + if (info) { + getPayloadInternal()->setFileInfo(*info); + } + } } void JingleFileTransferHashParser::handleCharacterData(const std::string& data) { - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h index 15d3294..1b47921 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2014-2015 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -20,15 +20,15 @@ namespace Swift { class SWIFTEN_API JingleFileTransferHashParser : public GenericPayloadParser<JingleFileTransferHash> { public: - JingleFileTransferHashParser(); - - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - + JingleFileTransferHashParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + private: - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp index e4c86cc..438420b 100644 --- a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp @@ -5,43 +5,43 @@ */ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ +#include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h> + #include <boost/lexical_cast.hpp> #include <boost/optional.hpp> -#include "JingleIBBTransportMethodPayloadParser.h" - #include <Swiften/Base/Log.h> namespace Swift { - JingleIBBTransportMethodPayloadParser::JingleIBBTransportMethodPayloadParser() : level(0) { - - } - - void JingleIBBTransportMethodPayloadParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - try { - boost::optional<std::string> blockSize = attributes.getAttributeValue("block-size"); - if (blockSize) { - getPayloadInternal()->setBlockSize(boost::lexical_cast<unsigned int>(*blockSize)); - } - } - catch (boost::bad_lexical_cast &) { - } - getPayloadInternal()->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); - ++level; - } - - void JingleIBBTransportMethodPayloadParser::handleEndElement(const std::string&, const std::string&) { - --level; - - - } - - void JingleIBBTransportMethodPayloadParser::handleCharacterData(const std::string&) { - - } + JingleIBBTransportMethodPayloadParser::JingleIBBTransportMethodPayloadParser() : level(0) { + + } + + void JingleIBBTransportMethodPayloadParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + try { + boost::optional<std::string> blockSize = attributes.getAttributeValue("block-size"); + if (blockSize) { + getPayloadInternal()->setBlockSize(boost::lexical_cast<unsigned int>(*blockSize)); + } + } + catch (boost::bad_lexical_cast &) { + } + getPayloadInternal()->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); + ++level; + } + + void JingleIBBTransportMethodPayloadParser::handleEndElement(const std::string&, const std::string&) { + --level; + + + } + + void JingleIBBTransportMethodPayloadParser::handleCharacterData(const std::string&) { + + } } diff --git a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h index 4e22943..e406b9f 100644 --- a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h @@ -19,15 +19,15 @@ namespace Swift { class SWIFTEN_API JingleIBBTransportMethodPayloadParser : public GenericPayloadParser<JingleIBBTransportPayload> { - public: - JingleIBBTransportMethodPayloadParser(); + public: + JingleIBBTransportMethodPayloadParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level; + private: + int level; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleParser.cpp b/Swiften/Parser/PayloadParsers/JingleParser.cpp index 7041a92..a88a5b2 100644 --- a/Swiften/Parser/PayloadParsers/JingleParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleParser.cpp @@ -5,115 +5,116 @@ */ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/JingleParser.h> -#include <Swiften/Parser/PayloadParserFactory.h> -#include <Swiften/Elements/JingleContentPayload.h> -#include <Swiften/Elements/JingleFileTransferHash.h> -#include <Swiften/Base/Log.h> #include <boost/intrusive_ptr.hpp> +#include <Swiften/Base/Log.h> +#include <Swiften/Elements/JingleContentPayload.h> +#include <Swiften/Elements/JingleFileTransferHash.h> +#include <Swiften/Parser/PayloadParserFactory.h> + namespace Swift { - JingleParser::JingleParser(PayloadParserFactoryCollection* factories) : factories(factories), level(0) { - - } - - void JingleParser::handleStartElement(const std::string& element, const std::string &ns, const AttributeMap& attributes) { - if (level == 0) { - // <jingle > tag - JinglePayload::ref payload = getPayloadInternal(); - payload->setAction(stringToAction(attributes.getAttributeValue("action").get_value_or(""))); - payload->setInitiator(JID(attributes.getAttributeValue("initiator").get_value_or(""))); - payload->setResponder(JID(attributes.getAttributeValue("responder").get_value_or(""))); - payload->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); - } - - if (level == 1) { - PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - - ++level; - } - - void JingleParser::handleEndElement(const std::string& element, const std::string &ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - boost::shared_ptr<JinglePayload::Reason> reason = boost::dynamic_pointer_cast<JinglePayload::Reason>(currentPayloadParser->getPayload()); - if (reason) { - getPayloadInternal()->setReason(*reason); - } - - boost::shared_ptr<JingleContentPayload> payload = boost::dynamic_pointer_cast<JingleContentPayload>(currentPayloadParser->getPayload()); - if (payload) { - getPayloadInternal()->addContent(payload); - } - - boost::shared_ptr<JingleFileTransferHash> hash = boost::dynamic_pointer_cast<JingleFileTransferHash>(currentPayloadParser->getPayload()); - if (hash) { - getPayloadInternal()->addPayload(hash); - } - } - } - } - - void JingleParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } - } - - JinglePayload::Action JingleParser::stringToAction(const std::string &str) const { - if (str == "content-accept") { - return JinglePayload::ContentAccept; - } else if (str == "content-add") { - return JinglePayload::ContentAdd; - } else if (str == "content-modify") { - return JinglePayload::ContentModify; - } else if (str == "content-reject") { - return JinglePayload::ContentReject; - } else if (str == "content-remove") { - return JinglePayload::ContentRemove; - } else if (str == "description-info") { - return JinglePayload::DescriptionInfo; - } else if (str == "security-info") { - return JinglePayload::SecurityInfo; - } else if (str == "session-accept") { - return JinglePayload::SessionAccept; - } else if (str == "session-info") { - return JinglePayload::SessionInfo; - } else if (str == "session-initiate") { - return JinglePayload::SessionInitiate; - } else if (str == "session-terminate") { - return JinglePayload::SessionTerminate; - } else if (str == "transport-accept") { - return JinglePayload::TransportAccept; - } else if (str == "transport-info") { - return JinglePayload::TransportInfo; - } else if (str == "transport-reject") { - return JinglePayload::TransportReject; - } else if (str == "transport-replace") { - return JinglePayload::TransportReplace; - } else { - return JinglePayload::UnknownAction; - } - - } + JingleParser::JingleParser(PayloadParserFactoryCollection* factories) : factories(factories), level(0) { + + } + + void JingleParser::handleStartElement(const std::string& element, const std::string &ns, const AttributeMap& attributes) { + if (level == 0) { + // <jingle > tag + JinglePayload::ref payload = getPayloadInternal(); + payload->setAction(stringToAction(attributes.getAttributeValue("action").get_value_or(""))); + payload->setInitiator(JID(attributes.getAttributeValue("initiator").get_value_or(""))); + payload->setResponder(JID(attributes.getAttributeValue("responder").get_value_or(""))); + payload->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); + } + + if (level == 1) { + PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + + ++level; + } + + void JingleParser::handleEndElement(const std::string& element, const std::string &ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + std::shared_ptr<JinglePayload::Reason> reason = std::dynamic_pointer_cast<JinglePayload::Reason>(currentPayloadParser->getPayload()); + if (reason) { + getPayloadInternal()->setReason(*reason); + } + + std::shared_ptr<JingleContentPayload> payload = std::dynamic_pointer_cast<JingleContentPayload>(currentPayloadParser->getPayload()); + if (payload) { + getPayloadInternal()->addContent(payload); + } + + std::shared_ptr<JingleFileTransferHash> hash = std::dynamic_pointer_cast<JingleFileTransferHash>(currentPayloadParser->getPayload()); + if (hash) { + getPayloadInternal()->addPayload(hash); + } + } + } + } + + void JingleParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } + } + + JinglePayload::Action JingleParser::stringToAction(const std::string &str) const { + if (str == "content-accept") { + return JinglePayload::ContentAccept; + } else if (str == "content-add") { + return JinglePayload::ContentAdd; + } else if (str == "content-modify") { + return JinglePayload::ContentModify; + } else if (str == "content-reject") { + return JinglePayload::ContentReject; + } else if (str == "content-remove") { + return JinglePayload::ContentRemove; + } else if (str == "description-info") { + return JinglePayload::DescriptionInfo; + } else if (str == "security-info") { + return JinglePayload::SecurityInfo; + } else if (str == "session-accept") { + return JinglePayload::SessionAccept; + } else if (str == "session-info") { + return JinglePayload::SessionInfo; + } else if (str == "session-initiate") { + return JinglePayload::SessionInitiate; + } else if (str == "session-terminate") { + return JinglePayload::SessionTerminate; + } else if (str == "transport-accept") { + return JinglePayload::TransportAccept; + } else if (str == "transport-info") { + return JinglePayload::TransportInfo; + } else if (str == "transport-reject") { + return JinglePayload::TransportReject; + } else if (str == "transport-replace") { + return JinglePayload::TransportReplace; + } else { + return JinglePayload::UnknownAction; + } + + } } diff --git a/Swiften/Parser/PayloadParsers/JingleParser.h b/Swiften/Parser/PayloadParsers/JingleParser.h index ad49e96..1dcc9e7 100644 --- a/Swiften/Parser/PayloadParsers/JingleParser.h +++ b/Swiften/Parser/PayloadParsers/JingleParser.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -20,20 +20,20 @@ namespace Swift { class SWIFTEN_API JingleParser : public GenericPayloadParser<JinglePayload> { - public: - JingleParser(PayloadParserFactoryCollection* factories); - - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - - private: - JinglePayload::Action stringToAction(const std::string &str) const; - - private: - PayloadParserFactoryCollection* factories; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; + public: + JingleParser(PayloadParserFactoryCollection* factories); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + + private: + JinglePayload::Action stringToAction(const std::string &str) const; + + private: + PayloadParserFactoryCollection* factories; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleParserFactory.h b/Swiften/Parser/PayloadParsers/JingleParserFactory.h index 73395fc..5f9b45b 100644 --- a/Swiften/Parser/PayloadParsers/JingleParserFactory.h +++ b/Swiften/Parser/PayloadParsers/JingleParserFactory.h @@ -17,26 +17,26 @@ #include <Swiften/Parser/PayloadParsers/JingleParser.h> namespace Swift { - - class PayloadParserFactoryCollection; - - class SWIFTEN_API JingleParserFactory : public PayloadParserFactory { - public: - JingleParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } - - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return element == "jingle" && ns == "urn:xmpp:jingle:1"; - } - - virtual PayloadParser* createPayloadParser() { - return new JingleParser(factories); - } - - private: - PayloadParserFactoryCollection* factories; - - }; + + class PayloadParserFactoryCollection; + + class SWIFTEN_API JingleParserFactory : public PayloadParserFactory { + public: + JingleParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "jingle" && ns == "urn:xmpp:jingle:1"; + } + + virtual PayloadParser* createPayloadParser() { + return new JingleParser(factories); + } + + private: + PayloadParserFactoryCollection* factories; + + }; } diff --git a/Swiften/Parser/PayloadParsers/JingleReasonParser.cpp b/Swiften/Parser/PayloadParsers/JingleReasonParser.cpp index 3df82ae..9a81e5f 100644 --- a/Swiften/Parser/PayloadParsers/JingleReasonParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleReasonParser.cpp @@ -4,78 +4,84 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ -#include "JingleReasonParser.h" +/* + * Copyright (c) 2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/JingleReasonParser.h> #include <Swiften/Base/Log.h> namespace Swift { - JingleReasonParser::JingleReasonParser() : level(0), parseText(false) { - - } - - void JingleReasonParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { - if (level == 1) { - if (element == "text") { - parseText = true; - } else { - // reason type - getPayloadInternal()->type = stringToReasonType(element); - } - } - ++level; - } - - void JingleReasonParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (element == "text") { - parseText = false; - getPayloadInternal()->text = text; - } - } - - void JingleReasonParser::handleCharacterData(const std::string& data) { - if (parseText) { - text += data; - } - } - - JinglePayload::Reason::Type JingleReasonParser::stringToReasonType(const std::string& type) const { - if (type == "alternative-session") { - return JinglePayload::Reason::AlternativeSession; - } else if (type == "busy") { - return JinglePayload::Reason::Busy; - } else if (type == "cancel") { - return JinglePayload::Reason::Cancel; - } else if (type == "connectivity-error") { - return JinglePayload::Reason::ConnectivityError; - } else if (type == "decline") { - return JinglePayload::Reason::Decline; - } else if (type == "expired") { - return JinglePayload::Reason::Expired; - } else if (type == "failed-application") { - return JinglePayload::Reason::FailedApplication; - } else if (type == "failed-transport") { - return JinglePayload::Reason::FailedTransport; - } else if (type == "general-error") { - return JinglePayload::Reason::GeneralError; - } else if (type == "gone") { - return JinglePayload::Reason::Gone; - } else if (type == "incompatible-parameters") { - return JinglePayload::Reason::IncompatibleParameters; - } else if (type == "media-error") { - return JinglePayload::Reason::MediaError; - } else if (type == "security-error") { - return JinglePayload::Reason::SecurityError; - } else if (type == "success") { - return JinglePayload::Reason::Success; - } else if (type == "timeout") { - return JinglePayload::Reason::Timeout; - } else if (type == "unsupported-applications") { - return JinglePayload::Reason::UnsupportedApplications; - } else if (type == "unsupported-transports") { - return JinglePayload::Reason::UnsupportedTransports; - } else { - return JinglePayload::Reason::UnknownType; - } - } + JingleReasonParser::JingleReasonParser() : level(0), parseText(false) { + + } + + void JingleReasonParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { + if (level == 1) { + if (element == "text") { + parseText = true; + } else { + // reason type + getPayloadInternal()->type = stringToReasonType(element); + } + } + ++level; + } + + void JingleReasonParser::handleEndElement(const std::string& element, const std::string&) { + --level; + if (element == "text") { + parseText = false; + getPayloadInternal()->text = text; + } + } + + void JingleReasonParser::handleCharacterData(const std::string& data) { + if (parseText) { + text += data; + } + } + + JinglePayload::Reason::Type JingleReasonParser::stringToReasonType(const std::string& type) const { + if (type == "alternative-session") { + return JinglePayload::Reason::AlternativeSession; + } else if (type == "busy") { + return JinglePayload::Reason::Busy; + } else if (type == "cancel") { + return JinglePayload::Reason::Cancel; + } else if (type == "connectivity-error") { + return JinglePayload::Reason::ConnectivityError; + } else if (type == "decline") { + return JinglePayload::Reason::Decline; + } else if (type == "expired") { + return JinglePayload::Reason::Expired; + } else if (type == "failed-application") { + return JinglePayload::Reason::FailedApplication; + } else if (type == "failed-transport") { + return JinglePayload::Reason::FailedTransport; + } else if (type == "general-error") { + return JinglePayload::Reason::GeneralError; + } else if (type == "gone") { + return JinglePayload::Reason::Gone; + } else if (type == "incompatible-parameters") { + return JinglePayload::Reason::IncompatibleParameters; + } else if (type == "media-error") { + return JinglePayload::Reason::MediaError; + } else if (type == "security-error") { + return JinglePayload::Reason::SecurityError; + } else if (type == "success") { + return JinglePayload::Reason::Success; + } else if (type == "timeout") { + return JinglePayload::Reason::Timeout; + } else if (type == "unsupported-applications") { + return JinglePayload::Reason::UnsupportedApplications; + } else if (type == "unsupported-transports") { + return JinglePayload::Reason::UnsupportedTransports; + } else { + return JinglePayload::Reason::UnknownType; + } + } } diff --git a/Swiften/Parser/PayloadParsers/JingleReasonParser.h b/Swiften/Parser/PayloadParsers/JingleReasonParser.h index 4fe334e..a445448 100644 --- a/Swiften/Parser/PayloadParsers/JingleReasonParser.h +++ b/Swiften/Parser/PayloadParsers/JingleReasonParser.h @@ -19,19 +19,19 @@ namespace Swift { class SWIFTEN_API JingleReasonParser : public GenericPayloadParser<JinglePayload::Reason> { - public: - JingleReasonParser(); - - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - private: - JinglePayload::Reason::Type stringToReasonType(const std::string& type) const; - - private: - int level; - bool parseText; - std::string text; + public: + JingleReasonParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + private: + JinglePayload::Reason::Type stringToReasonType(const std::string& type) const; + + private: + int level; + bool parseText; + std::string text; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp index dc05352..e639e20 100644 --- a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp @@ -5,91 +5,89 @@ */ /* -* Copyright (c) 2014-2015 Isode Limited. -* All rights reserved.v3. -* See the COPYING file for more information. -*/ + * Copyright (c) 2014-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h> #include <boost/lexical_cast.hpp> #include <boost/optional.hpp> -#include "JingleS5BTransportMethodPayloadParser.h" - #include <Swiften/Base/Log.h> namespace Swift { - JingleS5BTransportMethodPayloadParser::JingleS5BTransportMethodPayloadParser() : level(0) { - - } - - void JingleS5BTransportMethodPayloadParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level == 0) { - getPayloadInternal()->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); - std::string mode = attributes.getAttributeValue("mode").get_value_or("tcp"); - if (mode == "tcp") { - getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); - } else if(mode == "udp") { - getPayloadInternal()->setMode(JingleS5BTransportPayload::UDPMode); - } else { - SWIFT_LOG(warning) << "Unknown S5B mode; falling back to defaul!"; - getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); - } - getPayloadInternal()->setDstAddr(attributes.getAttributeValue("dstaddr").get_value_or("")); - } else if (level == 1) { - if (element == "candidate") { - JingleS5BTransportPayload::Candidate candidate; - candidate.cid = attributes.getAttributeValue("cid").get_value_or(""); + JingleS5BTransportMethodPayloadParser::JingleS5BTransportMethodPayloadParser() : level(0) { + + } + + void JingleS5BTransportMethodPayloadParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { + if (level == 0) { + getPayloadInternal()->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); + std::string mode = attributes.getAttributeValue("mode").get_value_or("tcp"); + if (mode == "tcp") { + getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); + } else if(mode == "udp") { + getPayloadInternal()->setMode(JingleS5BTransportPayload::UDPMode); + } else { + SWIFT_LOG(warning) << "Unknown S5B mode; falling back to defaul!"; + getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); + } + getPayloadInternal()->setDstAddr(attributes.getAttributeValue("dstaddr").get_value_or("")); + } else if (level == 1) { + if (element == "candidate") { + JingleS5BTransportPayload::Candidate candidate; + candidate.cid = attributes.getAttributeValue("cid").get_value_or(""); + + int port = -1; + try { + port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get_value_or("-1")); + } catch(boost::bad_lexical_cast &) { } + candidate.hostPort = HostAddressPort(HostAddress::fromString(attributes.getAttributeValue("host").get_value_or("")).get_value_or(HostAddress()), port); + candidate.jid = JID(attributes.getAttributeValue("jid").get_value_or("")); + int priority = -1; + try { + priority = boost::lexical_cast<int>(attributes.getAttributeValue("priority").get_value_or("-1")); + } catch(boost::bad_lexical_cast &) { } + candidate.priority = priority; + candidate.type = stringToType(attributes.getAttributeValue("type").get_value_or("direct")); - int port = -1; - try { - port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get_value_or("-1")); - } catch(boost::bad_lexical_cast &) { } - candidate.hostPort = HostAddressPort(HostAddress(attributes.getAttributeValue("host").get_value_or("")), port); - candidate.jid = JID(attributes.getAttributeValue("jid").get_value_or("")); - int priority = -1; - try { - priority = boost::lexical_cast<int>(attributes.getAttributeValue("priority").get_value_or("-1")); - } catch(boost::bad_lexical_cast &) { } - candidate.priority = priority; - candidate.type = stringToType(attributes.getAttributeValue("type").get_value_or("direct")); + getPayloadInternal()->addCandidate(candidate); + } else if (element == "candidate-used") { + getPayloadInternal()->setCandidateUsed(attributes.getAttributeValue("cid").get_value_or("")); + } else if (element == "candidate-error") { + getPayloadInternal()->setCandidateError(true); + } else if (element == "activated") { + getPayloadInternal()->setActivated(attributes.getAttributeValue("cid").get_value_or("")); + } else if (element == "proxy-error") { + getPayloadInternal()->setProxyError(true); + } + } - getPayloadInternal()->addCandidate(candidate); - } else if (element == "candidate-used") { - getPayloadInternal()->setCandidateUsed(attributes.getAttributeValue("cid").get_value_or("")); - } else if (element == "candidate-error") { - getPayloadInternal()->setCandidateError(true); - } else if (element == "activated") { - getPayloadInternal()->setActivated(attributes.getAttributeValue("cid").get_value_or("")); - } else if (element == "proxy-error") { - getPayloadInternal()->setProxyError(true); - } - } + ++level; + } - ++level; - } - - void JingleS5BTransportMethodPayloadParser::handleEndElement(const std::string&, const std::string&) { - --level; - + void JingleS5BTransportMethodPayloadParser::handleEndElement(const std::string&, const std::string&) { + --level; + } - } - - void JingleS5BTransportMethodPayloadParser::handleCharacterData(const std::string&) { + void JingleS5BTransportMethodPayloadParser::handleCharacterData(const std::string&) { - } + } - JingleS5BTransportPayload::Candidate::Type JingleS5BTransportMethodPayloadParser::stringToType(const std::string &str) const { - if (str == "direct") { - return JingleS5BTransportPayload::Candidate::DirectType; - } else if (str == "assisted") { - return JingleS5BTransportPayload::Candidate::AssistedType; - } else if (str == "tunnel") { - return JingleS5BTransportPayload::Candidate::TunnelType; - } else if (str == "proxy") { - return JingleS5BTransportPayload::Candidate::ProxyType; - } else { - SWIFT_LOG(warning) << "Unknown candidate type; falling back to default!"; - return JingleS5BTransportPayload::Candidate::DirectType; - } - } + JingleS5BTransportPayload::Candidate::Type JingleS5BTransportMethodPayloadParser::stringToType(const std::string &str) const { + if (str == "direct") { + return JingleS5BTransportPayload::Candidate::DirectType; + } else if (str == "assisted") { + return JingleS5BTransportPayload::Candidate::AssistedType; + } else if (str == "tunnel") { + return JingleS5BTransportPayload::Candidate::TunnelType; + } else if (str == "proxy") { + return JingleS5BTransportPayload::Candidate::ProxyType; + } else { + SWIFT_LOG(warning) << "Unknown candidate type; falling back to default!"; + return JingleS5BTransportPayload::Candidate::DirectType; + } + } } diff --git a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h index ccf0b1b..f48c4b5 100644 --- a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h @@ -19,18 +19,18 @@ namespace Swift { class SWIFTEN_API JingleS5BTransportMethodPayloadParser : public GenericPayloadParser<JingleS5BTransportPayload> { - public: - JingleS5BTransportMethodPayloadParser(); + public: + JingleS5BTransportMethodPayloadParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - JingleS5BTransportPayload::Candidate::Type stringToType(const std::string &str) const; + private: + JingleS5BTransportPayload::Candidate::Type stringToType(const std::string &str) const; - private: - int level; + private: + int level; }; } diff --git a/Swiften/Parser/PayloadParsers/LastParser.cpp b/Swiften/Parser/PayloadParsers/LastParser.cpp index 896a554..89d39ac 100644 --- a/Swiften/Parser/PayloadParsers/LastParser.cpp +++ b/Swiften/Parser/PayloadParsers/LastParser.cpp @@ -14,16 +14,16 @@ LastParser::LastParser() : level_(0) { } void LastParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - if (level_ == 0) { - int seconds = 0; - try { - seconds = boost::lexical_cast<int>(attributes.getAttribute("seconds")); - } - catch (boost::bad_lexical_cast&) { - } - getPayloadInternal()->setSeconds(seconds); - } - ++level_; + if (level_ == 0) { + int seconds = 0; + try { + seconds = boost::lexical_cast<int>(attributes.getAttribute("seconds")); + } + catch (boost::bad_lexical_cast&) { + } + getPayloadInternal()->setSeconds(seconds); + } + ++level_; } diff --git a/Swiften/Parser/PayloadParsers/LastParser.h b/Swiften/Parser/PayloadParsers/LastParser.h index 58cde22..70bfdcb 100644 --- a/Swiften/Parser/PayloadParsers/LastParser.h +++ b/Swiften/Parser/PayloadParsers/LastParser.h @@ -11,15 +11,15 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API LastParser : public GenericPayloadParser<Last> { - public: - LastParser(); + class SWIFTEN_API LastParser : public GenericPayloadParser<Last> { + public: + LastParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - }; + private: + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/MAMFinParser.cpp b/Swiften/Parser/PayloadParsers/MAMFinParser.cpp index adf66ef..88dd571 100644 --- a/Swiften/Parser/PayloadParsers/MAMFinParser.cpp +++ b/Swiften/Parser/PayloadParsers/MAMFinParser.cpp @@ -1,16 +1,18 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ +#include <Swiften/Parser/PayloadParsers/MAMFinParser.h> + #include <boost/lexical_cast.hpp> #include <boost/optional.hpp> + #include <Swiften/Base/DateTime.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/ResultSetParser.h> -#include <Swiften/Parser/PayloadParsers/MAMFinParser.h> using namespace Swift; @@ -18,42 +20,42 @@ MAMFinParser::MAMFinParser() : level_(TopLevel) { } void MAMFinParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == TopLevel) { - getPayloadInternal()->setComplete(attributes.getBoolAttribute("complete", false)); - getPayloadInternal()->setStable(attributes.getBoolAttribute("stable", true)); - boost::optional<std::string> attributeValue; - if ((attributeValue = attributes.getAttributeValue("queryid"))) { - getPayloadInternal()->setQueryID(*attributeValue); - } - } - else if (level_ == PayloadLevel) { - if (element == "set" && ns == "http://jabber.org/protocol/rsm") { - resultSetParser_ = boost::make_shared<ResultSetParser>(); - } - } - - if (resultSetParser_) { /* parsing a nested ResultSet */ - resultSetParser_->handleStartElement(element, ns, attributes); - } - - ++level_; + if (level_ == TopLevel) { + getPayloadInternal()->setComplete(attributes.getBoolAttribute("complete", false)); + getPayloadInternal()->setStable(attributes.getBoolAttribute("stable", true)); + boost::optional<std::string> attributeValue; + if ((attributeValue = attributes.getAttributeValue("queryid"))) { + getPayloadInternal()->setQueryID(*attributeValue); + } + } + else if (level_ == PayloadLevel) { + if (element == "set" && ns == "http://jabber.org/protocol/rsm") { + resultSetParser_ = std::make_shared<ResultSetParser>(); + } + } + + if (resultSetParser_) { /* parsing a nested ResultSet */ + resultSetParser_->handleStartElement(element, ns, attributes); + } + + ++level_; } void MAMFinParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - - if (resultSetParser_ && level_ >= PayloadLevel) { - resultSetParser_->handleEndElement(element, ns); - } - if (resultSetParser_ && level_ == PayloadLevel) { - /* done parsing nested ResultSet */ - getPayloadInternal()->setResultSet(boost::dynamic_pointer_cast<ResultSet>(resultSetParser_->getPayload())); - resultSetParser_.reset(); - } + --level_; + + if (resultSetParser_ && level_ >= PayloadLevel) { + resultSetParser_->handleEndElement(element, ns); + } + if (resultSetParser_ && level_ == PayloadLevel) { + /* done parsing nested ResultSet */ + getPayloadInternal()->setResultSet(std::dynamic_pointer_cast<ResultSet>(resultSetParser_->getPayload())); + resultSetParser_.reset(); + } } void MAMFinParser::handleCharacterData(const std::string& data) { - if (resultSetParser_) { - resultSetParser_->handleCharacterData(data); - } + if (resultSetParser_) { + resultSetParser_->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/MAMFinParser.h b/Swiften/Parser/PayloadParsers/MAMFinParser.h index ec1605a..f08231e 100644 --- a/Swiften/Parser/PayloadParsers/MAMFinParser.h +++ b/Swiften/Parser/PayloadParsers/MAMFinParser.h @@ -1,36 +1,36 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> -#include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/MAMFin.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class ResultSetParser; + class ResultSetParser; - class SWIFTEN_API MAMFinParser : public GenericPayloadParser<MAMFin> { - public: - MAMFinParser(); + class SWIFTEN_API MAMFinParser : public GenericPayloadParser<MAMFin> { + public: + MAMFinParser(); - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; - private: - boost::shared_ptr<ResultSetParser> resultSetParser_; - int level_; - }; + private: + std::shared_ptr<ResultSetParser> resultSetParser_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp index 54eaf84..4919d22 100644 --- a/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp +++ b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp @@ -1,15 +1,17 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ +#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h> + #include <boost/lexical_cast.hpp> #include <boost/optional.hpp> + #include <Swiften/Base/DateTime.h> #include <Swiften/Parser/PayloadParsers/FormParser.h> #include <Swiften/Parser/PayloadParsers/ResultSetParser.h> -#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h> using namespace Swift; @@ -17,60 +19,60 @@ MAMQueryParser::MAMQueryParser() : level_(TopLevel) { } void MAMQueryParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == TopLevel) { - boost::optional<std::string> attributeValue; - if ((attributeValue = attributes.getAttributeValue("queryid"))) { - getPayloadInternal()->setQueryID(*attributeValue); - } - if ((attributeValue = attributes.getAttributeValue("node"))) { - getPayloadInternal()->setNode(*attributeValue); - } - } else if (level_ == PayloadLevel) { - if (element == "x" && ns == "jabber:x:data") { - formParser_ = boost::make_shared<FormParser>(); - } else if (element == "set" && ns == "http://jabber.org/protocol/rsm") { - resultSetParser_ = boost::make_shared<ResultSetParser>(); - } - } + if (level_ == TopLevel) { + boost::optional<std::string> attributeValue; + if ((attributeValue = attributes.getAttributeValue("queryid"))) { + getPayloadInternal()->setQueryID(*attributeValue); + } + if ((attributeValue = attributes.getAttributeValue("node"))) { + getPayloadInternal()->setNode(*attributeValue); + } + } else if (level_ == PayloadLevel) { + if (element == "x" && ns == "jabber:x:data") { + formParser_ = std::make_shared<FormParser>(); + } else if (element == "set" && ns == "http://jabber.org/protocol/rsm") { + resultSetParser_ = std::make_shared<ResultSetParser>(); + } + } - if (formParser_) { /* parsing a nested Form */ - formParser_->handleStartElement(element, ns, attributes); - } + if (formParser_) { /* parsing a nested Form */ + formParser_->handleStartElement(element, ns, attributes); + } - if (resultSetParser_) { /* parsing a nested ResultSet */ - resultSetParser_->handleStartElement(element, ns, attributes); - } + if (resultSetParser_) { /* parsing a nested ResultSet */ + resultSetParser_->handleStartElement(element, ns, attributes); + } - ++level_; + ++level_; } void MAMQueryParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; + --level_; - if (formParser_ && level_ >= PayloadLevel) { - formParser_->handleEndElement(element, ns); - } - if (formParser_ && level_ == PayloadLevel) { - /* done parsing nested Form */ - getPayloadInternal()->setForm(boost::dynamic_pointer_cast<Form>(formParser_->getPayload())); - formParser_.reset(); - } + if (formParser_ && level_ >= PayloadLevel) { + formParser_->handleEndElement(element, ns); + } + if (formParser_ && level_ == PayloadLevel) { + /* done parsing nested Form */ + getPayloadInternal()->setForm(std::dynamic_pointer_cast<Form>(formParser_->getPayload())); + formParser_.reset(); + } - if (resultSetParser_ && level_ >= PayloadLevel) { - resultSetParser_->handleEndElement(element, ns); - } - if (resultSetParser_ && level_ == PayloadLevel) { - /* done parsing nested ResultSet */ - getPayloadInternal()->setResultSet(boost::dynamic_pointer_cast<ResultSet>(resultSetParser_->getPayload())); - resultSetParser_.reset(); - } + if (resultSetParser_ && level_ >= PayloadLevel) { + resultSetParser_->handleEndElement(element, ns); + } + if (resultSetParser_ && level_ == PayloadLevel) { + /* done parsing nested ResultSet */ + getPayloadInternal()->setResultSet(std::dynamic_pointer_cast<ResultSet>(resultSetParser_->getPayload())); + resultSetParser_.reset(); + } } void MAMQueryParser::handleCharacterData(const std::string& data) { - if (formParser_) { - formParser_->handleCharacterData(data); - } - if (resultSetParser_) { - resultSetParser_->handleCharacterData(data); - } + if (formParser_) { + formParser_->handleCharacterData(data); + } + if (resultSetParser_) { + resultSetParser_->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/MAMQueryParser.h b/Swiften/Parser/PayloadParsers/MAMQueryParser.h index 23286c8..7e4b58a 100644 --- a/Swiften/Parser/PayloadParsers/MAMQueryParser.h +++ b/Swiften/Parser/PayloadParsers/MAMQueryParser.h @@ -1,40 +1,39 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <memory> #include <string> -#include <boost/shared_ptr.hpp> - -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/MAMQuery.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class ResultSetParser; - class FormParser; - - class SWIFTEN_API MAMQueryParser : public GenericPayloadParser<MAMQuery> { - public: - MAMQueryParser(); - - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - - private: - boost::shared_ptr<FormParser> formParser_; - boost::shared_ptr<ResultSetParser> resultSetParser_; - int level_; - }; + class ResultSetParser; + class FormParser; + + class SWIFTEN_API MAMQueryParser : public GenericPayloadParser<MAMQuery> { + public: + MAMQueryParser(); + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + private: + std::shared_ptr<FormParser> formParser_; + std::shared_ptr<ResultSetParser> resultSetParser_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/MAMResultParser.cpp b/Swiften/Parser/PayloadParsers/MAMResultParser.cpp index 41a7336..b810b87 100644 --- a/Swiften/Parser/PayloadParsers/MAMResultParser.cpp +++ b/Swiften/Parser/PayloadParsers/MAMResultParser.cpp @@ -1,15 +1,16 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ +#include <Swiften/Parser/PayloadParsers/MAMResultParser.h> + #include <boost/lexical_cast.hpp> #include <boost/optional.hpp> #include <Swiften/Base/DateTime.h> #include <Swiften/Parser/PayloadParsers/ForwardedParser.h> -#include <Swiften/Parser/PayloadParsers/MAMResultParser.h> using namespace Swift; @@ -17,42 +18,42 @@ MAMResultParser::MAMResultParser(PayloadParserFactoryCollection* factories) : fa } void MAMResultParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == TopLevel) { - boost::optional<std::string> attributeValue; - if ((attributeValue = attributes.getAttributeValue("id"))) { - getPayloadInternal()->setID(*attributeValue); - } - if ((attributeValue = attributes.getAttributeValue("queryid"))) { - getPayloadInternal()->setQueryID(*attributeValue); - } - } else if (level_ == PayloadLevel) { - if (element == "forwarded" && ns == "urn:xmpp:forward:0") { - payloadParser_ = boost::make_shared<ForwardedParser>(factories_); - } - } - - if (payloadParser_) { - /* parsing a nested payload */ - payloadParser_->handleStartElement(element, ns, attributes); - } - - ++level_; + if (level_ == TopLevel) { + boost::optional<std::string> attributeValue; + if ((attributeValue = attributes.getAttributeValue("id"))) { + getPayloadInternal()->setID(*attributeValue); + } + if ((attributeValue = attributes.getAttributeValue("queryid"))) { + getPayloadInternal()->setQueryID(*attributeValue); + } + } else if (level_ == PayloadLevel) { + if (element == "forwarded" && ns == "urn:xmpp:forward:0") { + payloadParser_ = std::make_shared<ForwardedParser>(factories_); + } + } + + if (payloadParser_) { + /* parsing a nested payload */ + payloadParser_->handleStartElement(element, ns, attributes); + } + + ++level_; } void MAMResultParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (payloadParser_ && level_ >= PayloadLevel) { - payloadParser_->handleEndElement(element, ns); - } - if (payloadParser_ && level_ == PayloadLevel) { - /* done parsing nested stanza */ - getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<Forwarded>(payloadParser_->getPayload())); - payloadParser_.reset(); - } + --level_; + if (payloadParser_ && level_ >= PayloadLevel) { + payloadParser_->handleEndElement(element, ns); + } + if (payloadParser_ && level_ == PayloadLevel) { + /* done parsing nested stanza */ + getPayloadInternal()->setPayload(std::dynamic_pointer_cast<Forwarded>(payloadParser_->getPayload())); + payloadParser_.reset(); + } } void MAMResultParser::handleCharacterData(const std::string& data) { - if (payloadParser_) { - payloadParser_->handleCharacterData(data); - } + if (payloadParser_) { + payloadParser_->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/MAMResultParser.h b/Swiften/Parser/PayloadParsers/MAMResultParser.h index f0c9ee5..e68e365 100644 --- a/Swiften/Parser/PayloadParsers/MAMResultParser.h +++ b/Swiften/Parser/PayloadParsers/MAMResultParser.h @@ -1,40 +1,39 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <memory> #include <string> -#include <boost/shared_ptr.hpp> - -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/MAMResult.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class ForwardedParser; - - class SWIFTEN_API MAMResultParser : public GenericPayloadParser<MAMResult> { - public: - MAMResultParser(PayloadParserFactoryCollection* factories); - - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - - private: - boost::shared_ptr<ForwardedParser> payloadParser_; - PayloadParserFactoryCollection* factories_; - int level_; - }; + class PayloadParserFactoryCollection; + class ForwardedParser; + + class SWIFTEN_API MAMResultParser : public GenericPayloadParser<MAMResult> { + public: + MAMResultParser(PayloadParserFactoryCollection* factories); + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + private: + std::shared_ptr<ForwardedParser> payloadParser_; + PayloadParserFactoryCollection* factories_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp index 717fc60..bac2a78 100644 --- a/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -8,16 +8,15 @@ #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")) { - MUCItem item = MUCItemParser::itemFromTree(itemElement); - getPayloadInternal()->addItem(item); - } + 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/MUCAdminPayloadParser.h b/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h index 9174c7d..de46690 100644 --- a/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h @@ -14,8 +14,8 @@ #include <Swiften/Parser/PayloadParsers/MUCItemParser.h> namespace Swift { - class SWIFTEN_API MUCAdminPayloadParser : public GenericPayloadTreeParser<MUCAdminPayload> { - public: - virtual void handleTree(ParserElement::ref root); - }; + class SWIFTEN_API MUCAdminPayloadParser : public GenericPayloadTreeParser<MUCAdminPayload> { + public: + virtual void handleTree(ParserElement::ref root); + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.cpp index b70c1d4..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()); + 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/MUCDestroyPayloadParser.h b/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h index 1e5d545..e79d9a6 100644 --- a/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h @@ -13,8 +13,8 @@ #include <Swiften/Parser/GenericPayloadTreeParser.h> namespace Swift { - class SWIFTEN_API MUCDestroyPayloadParser : public GenericPayloadTreeParser<MUCDestroyPayload> { - public: - virtual void handleTree(ParserElement::ref root); - }; + class SWIFTEN_API MUCDestroyPayloadParser : public GenericPayloadTreeParser<MUCDestroyPayload> { + public: + virtual void handleTree(ParserElement::ref root); + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp index e61c2b2..14d6d16 100644 --- a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp @@ -1,23 +1,24 @@ /* - * Copyright (c) 2011-2014 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h> + #include <Swiften/Parser/Tree/NullParserElement.h> namespace Swift { void MUCInvitationPayloadParser::handleTree(ParserElement::ref root) { - MUCInvitationPayload::ref invite = getPayloadInternal(); - invite->setIsContinuation(root->getAttributes().getBoolAttribute("continue", false)); - invite->setJID(JID(root->getAttributes().getAttribute("jid"))); - invite->setPassword(root->getAttributes().getAttribute("password")); - invite->setReason(root->getAttributes().getAttribute("reason")); - invite->setThread(root->getAttributes().getAttribute("thread")); - ParserElement::ref impromptuNode = root->getChild("impromptu", "http://swift.im/impromptu"); - invite->setIsImpromptu(!boost::dynamic_pointer_cast<NullParserElement>(impromptuNode)); + MUCInvitationPayload::ref invite = getPayloadInternal(); + invite->setIsContinuation(root->getAttributes().getBoolAttribute("continue", false)); + invite->setJID(JID(root->getAttributes().getAttribute("jid"))); + invite->setPassword(root->getAttributes().getAttribute("password")); + invite->setReason(root->getAttributes().getAttribute("reason")); + invite->setThread(root->getAttributes().getAttribute("thread")); + ParserElement::ref impromptuNode = root->getChild("impromptu", "http://swift.im/impromptu"); + invite->setIsImpromptu(!std::dynamic_pointer_cast<NullParserElement>(impromptuNode)); } } diff --git a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h index f79c971..7b76166 100644 --- a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/GenericPayloadTreeParser.h> namespace Swift { - class SWIFTEN_API MUCInvitationPayloadParser : public GenericPayloadTreeParser<MUCInvitationPayload> { - public: - virtual void handleTree(ParserElement::ref root); - }; + class SWIFTEN_API MUCInvitationPayloadParser : public GenericPayloadTreeParser<MUCInvitationPayload> { + public: + virtual void handleTree(ParserElement::ref root); + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCItemParser.cpp b/Swiften/Parser/PayloadParsers/MUCItemParser.cpp index 9a0d84a..ce74671 100644 --- a/Swiften/Parser/PayloadParsers/MUCItemParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCItemParser.cpp @@ -1,80 +1,79 @@ /* - * 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/MUCItemParser.h> +#include <cassert> + #include <boost/lexical_cast.hpp> #include <Swiften/Elements/MUCOccupant.h> -#include <cassert> -#include <iostream> - namespace Swift { MUCItem MUCItemParser::itemFromTree(ParserElement::ref root) { - MUCItem item; - std::string affiliation = root->getAttributes().getAttribute("affiliation"); - std::string role = root->getAttributes().getAttribute("role"); - std::string nick = root->getAttributes().getAttribute("nick"); - std::string jid = root->getAttributes().getAttribute("jid"); - item.affiliation = parseAffiliation(affiliation); - item.role = parseRole(role); - if (!jid.empty()) { - item.realJID = JID(jid); - } - if (!nick.empty()) { - item.nick = nick; - } - std::string xmlns = root->getNamespace(); - std::string reason = root->getChild("reason", xmlns)->getText(); - std::string actor = root->getChild("actor", xmlns)->getAttributes().getAttribute("jid"); - if (!reason.empty()) { - item.reason = reason; - } - if (!actor.empty()) { - item.actor = JID(actor); - } + MUCItem item; + std::string affiliation = root->getAttributes().getAttribute("affiliation"); + std::string role = root->getAttributes().getAttribute("role"); + std::string nick = root->getAttributes().getAttribute("nick"); + std::string jid = root->getAttributes().getAttribute("jid"); + item.affiliation = parseAffiliation(affiliation); + item.role = parseRole(role); + if (!jid.empty()) { + item.realJID = JID(jid); + } + if (!nick.empty()) { + item.nick = nick; + } + std::string xmlns = root->getNamespace(); + std::string reason = root->getChild("reason", xmlns)->getText(); + std::string actor = root->getChild("actor", xmlns)->getAttributes().getAttribute("jid"); + if (!reason.empty()) { + item.reason = reason; + } + if (!actor.empty()) { + item.actor = JID(actor); + } - return item; + return item; } boost::optional<MUCOccupant::Role> MUCItemParser::parseRole(const std::string& roleString) { - if (roleString == "moderator") { - return MUCOccupant::Moderator; - } - if (roleString == "participant") { - return MUCOccupant::Participant; - } - if (roleString == "visitor") { - return MUCOccupant::Visitor; - } - if (roleString == "none") { - return MUCOccupant::NoRole; - } - return boost::optional<MUCOccupant::Role>(); + if (roleString == "moderator") { + return MUCOccupant::Moderator; + } + if (roleString == "participant") { + return MUCOccupant::Participant; + } + if (roleString == "visitor") { + return MUCOccupant::Visitor; + } + if (roleString == "none") { + return MUCOccupant::NoRole; + } + return boost::optional<MUCOccupant::Role>(); } boost::optional<MUCOccupant::Affiliation> MUCItemParser::parseAffiliation(const std::string& affiliationString) { - if (affiliationString == "owner") { - return MUCOccupant::Owner; - } - if (affiliationString == "admin") { - return MUCOccupant::Admin; - } - if (affiliationString == "member") { - return MUCOccupant::Member; - } - if (affiliationString == "outcast") { - return MUCOccupant::Outcast; - } - if (affiliationString == "none") { - return MUCOccupant::NoAffiliation; - } - return boost::optional<MUCOccupant::Affiliation>(); + if (affiliationString == "owner") { + return MUCOccupant::Owner; + } + if (affiliationString == "admin") { + return MUCOccupant::Admin; + } + if (affiliationString == "member") { + return MUCOccupant::Member; + } + if (affiliationString == "outcast") { + return MUCOccupant::Outcast; + } + if (affiliationString == "none") { + return MUCOccupant::NoAffiliation; + } + return boost::optional<MUCOccupant::Affiliation>(); } } diff --git a/Swiften/Parser/PayloadParsers/MUCItemParser.h b/Swiften/Parser/PayloadParsers/MUCItemParser.h index fc5d657..6f80d54 100644 --- a/Swiften/Parser/PayloadParsers/MUCItemParser.h +++ b/Swiften/Parser/PayloadParsers/MUCItemParser.h @@ -11,11 +11,11 @@ #include <Swiften/Parser/GenericPayloadTreeParser.h> namespace Swift { - class SWIFTEN_API MUCItemParser { - public: - static MUCItem itemFromTree(ParserElement::ref root); - private: - static boost::optional<MUCOccupant::Role> parseRole(const std::string& itemString); - static boost::optional<MUCOccupant::Affiliation> parseAffiliation(const std::string& statusString); - }; + class SWIFTEN_API MUCItemParser { + public: + static MUCItem itemFromTree(ParserElement::ref root); + private: + static boost::optional<MUCOccupant::Role> parseRole(const std::string& itemString); + static boost::optional<MUCOccupant::Affiliation> parseAffiliation(const std::string& statusString); + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.cpp index f8f0937..7e7c0d4 100644 --- a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.cpp @@ -1,12 +1,13 @@ /* - * 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/MUCOwnerPayloadParser.h> -#include <Swiften/Parser/PayloadParserFactoryCollection.h> + #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> namespace Swift { @@ -14,36 +15,36 @@ MUCOwnerPayloadParser::MUCOwnerPayloadParser(PayloadParserFactoryCollection* fac } void MUCOwnerPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 1) { - PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 1) { + PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void MUCOwnerPayloadParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - getPayloadInternal()->setPayload(currentPayloadParser->getPayload()); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + getPayloadInternal()->setPayload(currentPayloadParser->getPayload()); + } + } } void MUCOwnerPayloadParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h index 85db82f..4c1f048 100644 --- a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -13,20 +13,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API MUCOwnerPayloadParser : public GenericPayloadParser<MUCOwnerPayload> { - public: - MUCOwnerPayloadParser(PayloadParserFactoryCollection* factories); + class SWIFTEN_API MUCOwnerPayloadParser : public GenericPayloadParser<MUCOwnerPayload> { + public: + MUCOwnerPayloadParser(PayloadParserFactoryCollection* factories); - private: - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + private: + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - PayloadParserFactoryCollection* factories; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* factories; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h index 9270dc7..d6399e7 100644 --- a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h @@ -11,23 +11,23 @@ #include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API MUCOwnerPayloadParserFactory : public PayloadParserFactory { - public: - MUCOwnerPayloadParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } + class SWIFTEN_API MUCOwnerPayloadParserFactory : public PayloadParserFactory { + public: + MUCOwnerPayloadParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return element == "query" && ns == "http://jabber.org/protocol/muc#owner"; - } + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "query" && ns == "http://jabber.org/protocol/muc#owner"; + } - virtual PayloadParser* createPayloadParser() { - return new MUCOwnerPayloadParser(factories); - } + virtual PayloadParser* createPayloadParser() { + return new MUCOwnerPayloadParser(factories); + } - private: - PayloadParserFactoryCollection* factories; + private: + PayloadParserFactoryCollection* factories; - }; + }; } 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)); + } + } } } diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h index 3d7a53b..3d6dbab 100644 --- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h @@ -14,12 +14,12 @@ #include <Swiften/Parser/PayloadParsers/MUCItemParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class SWIFTEN_API MUCUserPayloadParser : public GenericPayloadTreeParser<MUCUserPayload> { - public: - MUCUserPayloadParser(PayloadParserFactoryCollection* collection) : factories(collection) {} - virtual void handleTree(ParserElement::ref root); - private: - PayloadParserFactoryCollection* factories; - }; + class PayloadParserFactoryCollection; + class SWIFTEN_API MUCUserPayloadParser : public GenericPayloadTreeParser<MUCUserPayload> { + public: + MUCUserPayloadParser(PayloadParserFactoryCollection* collection) : factories(collection) {} + virtual void handleTree(ParserElement::ref root); + private: + PayloadParserFactoryCollection* factories; + }; } diff --git a/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h index 4cc9134..4a0380d 100644 --- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h @@ -11,20 +11,20 @@ #include <Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h> namespace Swift { - class SWIFTEN_API MUCUserPayloadParserFactory : public PayloadParserFactory { - public: - MUCUserPayloadParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } + class SWIFTEN_API MUCUserPayloadParserFactory : public PayloadParserFactory { + public: + MUCUserPayloadParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return element == "x" && ns == "http://jabber.org/protocol/muc#user"; - } + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "x" && ns == "http://jabber.org/protocol/muc#user"; + } - virtual PayloadParser* createPayloadParser() { - return new MUCUserPayloadParser(factories); - } + virtual PayloadParser* createPayloadParser() { + return new MUCUserPayloadParser(factories); + } - private: - PayloadParserFactoryCollection* factories; - }; + private: + PayloadParserFactoryCollection* factories; + }; } diff --git a/Swiften/Parser/PayloadParsers/NicknameParser.cpp b/Swiften/Parser/PayloadParsers/NicknameParser.cpp index a3ce952..331355a 100644 --- a/Swiften/Parser/PayloadParsers/NicknameParser.cpp +++ b/Swiften/Parser/PayloadParsers/NicknameParser.cpp @@ -12,18 +12,18 @@ NicknameParser::NicknameParser() : level(0) { } void NicknameParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level; + ++level; } void NicknameParser::handleEndElement(const std::string&, const std::string&) { - --level; - if (level == 0) { - getPayloadInternal()->setNickname(text); - } + --level; + if (level == 0) { + getPayloadInternal()->setNickname(text); + } } void NicknameParser::handleCharacterData(const std::string& data) { - text += data; + text += data; } } diff --git a/Swiften/Parser/PayloadParsers/NicknameParser.h b/Swiften/Parser/PayloadParsers/NicknameParser.h index d8ac5b5..1bdd600 100644 --- a/Swiften/Parser/PayloadParsers/NicknameParser.h +++ b/Swiften/Parser/PayloadParsers/NicknameParser.h @@ -11,16 +11,16 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API NicknameParser : public GenericPayloadParser<Nickname> { - public: - NicknameParser(); + class SWIFTEN_API NicknameParser : public GenericPayloadParser<Nickname> { + public: + NicknameParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level; - std::string text; - }; + private: + int level; + std::string text; + }; } diff --git a/Swiften/Parser/PayloadParsers/PriorityParser.cpp b/Swiften/Parser/PayloadParsers/PriorityParser.cpp index 862d219..88eef0d 100644 --- a/Swiften/Parser/PayloadParsers/PriorityParser.cpp +++ b/Swiften/Parser/PayloadParsers/PriorityParser.cpp @@ -14,24 +14,24 @@ PriorityParser::PriorityParser() : level_(0) { } void PriorityParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level_; + ++level_; } void PriorityParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 0) { - int priority = 0; - try { - priority = boost::lexical_cast<int>(text_); - } - catch (boost::bad_lexical_cast&) { - } - getPayloadInternal()->setPriority(priority); - } + --level_; + if (level_ == 0) { + int priority = 0; + try { + priority = boost::lexical_cast<int>(text_); + } + catch (boost::bad_lexical_cast&) { + } + getPayloadInternal()->setPriority(priority); + } } void PriorityParser::handleCharacterData(const std::string& data) { - text_ += data; + text_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/PriorityParser.h b/Swiften/Parser/PayloadParsers/PriorityParser.h index 6c34e3b..e6bf059 100644 --- a/Swiften/Parser/PayloadParsers/PriorityParser.h +++ b/Swiften/Parser/PayloadParsers/PriorityParser.h @@ -11,16 +11,16 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API PriorityParser : public GenericPayloadParser<Priority> { - public: - PriorityParser(); + class SWIFTEN_API PriorityParser : public GenericPayloadParser<Priority> { + public: + PriorityParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - std::string text_; - }; + private: + int level_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp b/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp index 945895b..e40249a 100644 --- a/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp +++ b/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp @@ -1,12 +1,13 @@ /* - * 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/PrivateStorageParser.h> -#include <Swiften/Parser/PayloadParserFactoryCollection.h> + #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> namespace Swift { @@ -14,36 +15,36 @@ PrivateStorageParser::PrivateStorageParser(PayloadParserFactoryCollection* facto } void PrivateStorageParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 1) { - PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 1) { + PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PrivateStorageParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - getPayloadInternal()->setPayload(currentPayloadParser->getPayload()); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + getPayloadInternal()->setPayload(currentPayloadParser->getPayload()); + } + } } void PrivateStorageParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/PrivateStorageParser.h b/Swiften/Parser/PayloadParsers/PrivateStorageParser.h index 57e4136..c1d695c 100644 --- a/Swiften/Parser/PayloadParsers/PrivateStorageParser.h +++ b/Swiften/Parser/PayloadParsers/PrivateStorageParser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -13,20 +13,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API PrivateStorageParser : public GenericPayloadParser<PrivateStorage> { - public: - PrivateStorageParser(PayloadParserFactoryCollection* factories); + class SWIFTEN_API PrivateStorageParser : public GenericPayloadParser<PrivateStorage> { + public: + PrivateStorageParser(PayloadParserFactoryCollection* factories); - private: - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + private: + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - PayloadParserFactoryCollection* factories; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* factories; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h b/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h index e8db9af..550177c 100644 --- a/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h +++ b/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h @@ -11,23 +11,23 @@ #include <Swiften/Parser/PayloadParsers/PrivateStorageParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API PrivateStorageParserFactory : public PayloadParserFactory { - public: - PrivateStorageParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { - } + class SWIFTEN_API PrivateStorageParserFactory : public PayloadParserFactory { + public: + PrivateStorageParserFactory(PayloadParserFactoryCollection* factories) : factories(factories) { + } - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return element == "query" && ns == "jabber:iq:private"; - } + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "query" && ns == "jabber:iq:private"; + } - virtual PayloadParser* createPayloadParser() { - return new PrivateStorageParser(factories); - } + virtual PayloadParser* createPayloadParser() { + return new PrivateStorageParser(factories); + } - private: - PayloadParserFactoryCollection* factories; - - }; + private: + PayloadParserFactoryCollection* factories; + + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp index 9a470a4..764b3a7 100644 --- a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp @@ -1,64 +1,58 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> -#include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/EnumParser.h> +#include <Swiften/Parser/PayloadParserFactory.h> using namespace Swift; -PubSubAffiliationParser::PubSubAffiliationParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubAffiliationParser::PubSubAffiliationParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubAffiliationParser::~PubSubAffiliationParser() { } void PubSubAffiliationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("affiliation")) { - if (boost::optional<PubSubAffiliation::Type> value = EnumParser<PubSubAffiliation::Type>()(PubSubAffiliation::None, "none")(PubSubAffiliation::Member, "member")(PubSubAffiliation::Outcast, "outcast")(PubSubAffiliation::Owner, "owner")(PubSubAffiliation::Publisher, "publisher")(PubSubAffiliation::PublishOnly, "publish-only").parse(*attributeValue)) { - getPayloadInternal()->setType(*value); - } - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("affiliation")) { + if (boost::optional<PubSubAffiliation::Type> value = EnumParser<PubSubAffiliation::Type>()(PubSubAffiliation::None, "none")(PubSubAffiliation::Member, "member")(PubSubAffiliation::Outcast, "outcast")(PubSubAffiliation::Owner, "owner")(PubSubAffiliation::Publisher, "publisher")(PubSubAffiliation::PublishOnly, "publish-only").parse(*attributeValue)) { + getPayloadInternal()->setType(*value); + } + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubAffiliationParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { - if (level == 1) { - - currentPayloadParser.reset(); - } - } + currentPayloadParser.reset(); + } + } } void PubSubAffiliationParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h index fa13bd4..eabe3db 100644 --- a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubAffiliation.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubAffiliationParser : public GenericPayloadParser<PubSubAffiliation> { - public: - PubSubAffiliationParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubAffiliationParser(); + class SWIFTEN_API PubSubAffiliationParser : public GenericPayloadParser<PubSubAffiliation> { + public: + PubSubAffiliationParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubAffiliationParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp index b316134..ffa5d2d 100644 --- a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp @@ -1,18 +1,15 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h> using namespace Swift; @@ -24,42 +21,42 @@ PubSubAffiliationsParser::~PubSubAffiliationsParser() { } void PubSubAffiliationsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } - - if (level == 1) { - if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubAffiliationParser>(parsers); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubAffiliationParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubAffiliationsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub") { - getPayloadInternal()->addAffiliation(boost::dynamic_pointer_cast<PubSubAffiliation>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addAffiliation(std::dynamic_pointer_cast<PubSubAffiliation>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubAffiliationsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h index 25314a9..2f80dbd 100644 --- a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubAffiliations.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubAffiliationsParser : public GenericPayloadParser<PubSubAffiliations> { - public: - PubSubAffiliationsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubAffiliationsParser(); + class SWIFTEN_API PubSubAffiliationsParser : public GenericPayloadParser<PubSubAffiliations> { + public: + PubSubAffiliationsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubAffiliationsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp index cac9924..e0a5847 100644 --- a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp @@ -1,61 +1,57 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubConfigureParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/FormParser.h> using namespace Swift; -PubSubConfigureParser::PubSubConfigureParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubConfigureParser::PubSubConfigureParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubConfigureParser::~PubSubConfigureParser() { } void PubSubConfigureParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - - - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - currentPayloadParser = boost::make_shared<FormParser>(); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = std::make_shared<FormParser>(); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubConfigureParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(std::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubConfigureParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h index 8708fb7..90c2f3e 100644 --- a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubConfigure.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubConfigureParser : public GenericPayloadParser<PubSubConfigure> { - public: - PubSubConfigureParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubConfigureParser(); + class SWIFTEN_API PubSubConfigureParser : public GenericPayloadParser<PubSubConfigure> { + public: + PubSubConfigureParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubConfigureParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp index fbf2eba..4f03e29 100644 --- a/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp @@ -1,59 +1,52 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubCreateParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - using namespace Swift; -PubSubCreateParser::PubSubCreateParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubCreateParser::PubSubCreateParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubCreateParser::~PubSubCreateParser() { } void PubSubCreateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubCreateParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubCreateParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubCreateParser.h b/Swiften/Parser/PayloadParsers/PubSubCreateParser.h index 65a4c59..a1ada74 100644 --- a/Swiften/Parser/PayloadParsers/PubSubCreateParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubCreateParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubCreate.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubCreateParser : public GenericPayloadParser<PubSubCreate> { - public: - PubSubCreateParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubCreateParser(); + class SWIFTEN_API PubSubCreateParser : public GenericPayloadParser<PubSubCreate> { + public: + PubSubCreateParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubCreateParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp index bf5a210..a6d751c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp @@ -1,64 +1,58 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubDefaultParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> -#include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/EnumParser.h> +#include <Swiften/Parser/PayloadParserFactory.h> using namespace Swift; -PubSubDefaultParser::PubSubDefaultParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubDefaultParser::PubSubDefaultParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubDefaultParser::~PubSubDefaultParser() { } void PubSubDefaultParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("type")) { - if (boost::optional<PubSubDefault::Type> value = EnumParser<PubSubDefault::Type>()(PubSubDefault::None, "none")(PubSubDefault::Collection, "collection")(PubSubDefault::Leaf, "leaf").parse(*attributeValue)) { - getPayloadInternal()->setType(*value); - } - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("type")) { + if (boost::optional<PubSubDefault::Type> value = EnumParser<PubSubDefault::Type>()(PubSubDefault::None, "none")(PubSubDefault::Collection, "collection")(PubSubDefault::Leaf, "leaf").parse(*attributeValue)) { + getPayloadInternal()->setType(*value); + } + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubDefaultParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { - if (level == 1) { - - currentPayloadParser.reset(); - } - } + currentPayloadParser.reset(); + } + } } void PubSubDefaultParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h index d9ad21a..01bea7b 100644 --- a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubDefault.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubDefaultParser : public GenericPayloadParser<PubSubDefault> { - public: - PubSubDefaultParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubDefaultParser(); + class SWIFTEN_API PubSubDefaultParser : public GenericPayloadParser<PubSubDefault> { + public: + PubSubDefaultParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubDefaultParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp b/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp index f399717..99a306d 100644 --- a/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp @@ -9,95 +9,95 @@ using namespace Swift; PubSubErrorParser::PubSubErrorParser() : level(0) { - typeParser - (PubSubError::ClosedNode, "closed-node") - (PubSubError::ConfigurationRequired, "configuration-required") - (PubSubError::InvalidJID, "invalid-jid") - (PubSubError::InvalidOptions, "invalid-options") - (PubSubError::InvalidPayload, "invalid-payload") - (PubSubError::InvalidSubscriptionID, "invalid-subid") - (PubSubError::ItemForbidden, "item-forbidden") - (PubSubError::ItemRequired, "item-required") - (PubSubError::JIDRequired, "jid-required") - (PubSubError::MaximumItemsExceeded, "max-items-exceeded") - (PubSubError::MaximumNodesExceeded, "max-nodes-exceeded") - (PubSubError::NodeIDRequired, "nodeid-required") - (PubSubError::NotInRosterGroup, "not-in-roster-group") - (PubSubError::NotSubscribed, "not-subscribed") - (PubSubError::PayloadTooBig, "payload-too-big") - (PubSubError::PayloadRequired, "payload-required") - (PubSubError::PendingSubscription, "pending-subscription") - (PubSubError::PresenceSubscriptionRequired, "presence-subscription-required") - (PubSubError::SubscriptionIDRequired, "subid-required") - (PubSubError::TooManySubscriptions, "too-many-subscriptions") - (PubSubError::Unsupported, "unsupported") - (PubSubError::UnsupportedAccessModel, "unsupported-access-model"); - unsupportedTypeParser - (PubSubError::AccessAuthorize, "access-authorize") - (PubSubError::AccessOpen, "access-open") - (PubSubError::AccessPresence, "access-presence") - (PubSubError::AccessRoster, "access-roster") - (PubSubError::AccessWhitelist, "access-whitelist") - (PubSubError::AutoCreate, "auto-create") - (PubSubError::AutoSubscribe, "auto-subscribe") - (PubSubError::Collections, "collections") - (PubSubError::ConfigNode, "config-node") - (PubSubError::CreateAndConfigure, "create-and-configure") - (PubSubError::CreateNodes, "create-nodes") - (PubSubError::DeleteItems, "delete-items") - (PubSubError::DeleteNodes, "delete-nodes") - (PubSubError::FilteredNotifications, "filtered-notifications") - (PubSubError::GetPending, "get-pending") - (PubSubError::InstantNodes, "instant-nodes") - (PubSubError::ItemIDs, "item-ids") - (PubSubError::LastPublished, "last-published") - (PubSubError::LeasedSubscription, "leased-subscription") - (PubSubError::ManageSubscriptions, "manage-subscriptions") - (PubSubError::MemberAffiliation, "member-affiliation") - (PubSubError::MetaData, "meta-data") - (PubSubError::ModifyAffiliations, "modify-affiliations") - (PubSubError::MultiCollection, "multi-collection") - (PubSubError::MultiSubscribe, "multi-subscribe") - (PubSubError::OutcastAffiliation, "outcast-affiliation") - (PubSubError::PersistentItems, "persistent-items") - (PubSubError::PresenceNotifications, "presence-notifications") - (PubSubError::PresenceSubscribe, "presence-subscribe") - (PubSubError::Publish, "publish") - (PubSubError::PublishOptions, "publish-options") - (PubSubError::PublishOnlyAffiliation, "publish-only-affiliation") - (PubSubError::PublisherAffiliation, "publisher-affiliation") - (PubSubError::PurgeNodes, "purge-nodes") - (PubSubError::RetractItems, "retract-items") - (PubSubError::RetrieveAffiliations, "retrieve-affiliations") - (PubSubError::RetrieveDefault, "retrieve-default") - (PubSubError::RetrieveItems, "retrieve-items") - (PubSubError::RetrieveSubscriptions, "retrieve-subscriptions") - (PubSubError::Subscribe, "subscribe") - (PubSubError::SubscriptionOptions, "subscription-options") - (PubSubError::SubscriptionNotifications, "subscription-notifications"); + typeParser + (PubSubError::ClosedNode, "closed-node") + (PubSubError::ConfigurationRequired, "configuration-required") + (PubSubError::InvalidJID, "invalid-jid") + (PubSubError::InvalidOptions, "invalid-options") + (PubSubError::InvalidPayload, "invalid-payload") + (PubSubError::InvalidSubscriptionID, "invalid-subid") + (PubSubError::ItemForbidden, "item-forbidden") + (PubSubError::ItemRequired, "item-required") + (PubSubError::JIDRequired, "jid-required") + (PubSubError::MaximumItemsExceeded, "max-items-exceeded") + (PubSubError::MaximumNodesExceeded, "max-nodes-exceeded") + (PubSubError::NodeIDRequired, "nodeid-required") + (PubSubError::NotInRosterGroup, "not-in-roster-group") + (PubSubError::NotSubscribed, "not-subscribed") + (PubSubError::PayloadTooBig, "payload-too-big") + (PubSubError::PayloadRequired, "payload-required") + (PubSubError::PendingSubscription, "pending-subscription") + (PubSubError::PresenceSubscriptionRequired, "presence-subscription-required") + (PubSubError::SubscriptionIDRequired, "subid-required") + (PubSubError::TooManySubscriptions, "too-many-subscriptions") + (PubSubError::Unsupported, "unsupported") + (PubSubError::UnsupportedAccessModel, "unsupported-access-model"); + unsupportedTypeParser + (PubSubError::AccessAuthorize, "access-authorize") + (PubSubError::AccessOpen, "access-open") + (PubSubError::AccessPresence, "access-presence") + (PubSubError::AccessRoster, "access-roster") + (PubSubError::AccessWhitelist, "access-whitelist") + (PubSubError::AutoCreate, "auto-create") + (PubSubError::AutoSubscribe, "auto-subscribe") + (PubSubError::Collections, "collections") + (PubSubError::ConfigNode, "config-node") + (PubSubError::CreateAndConfigure, "create-and-configure") + (PubSubError::CreateNodes, "create-nodes") + (PubSubError::DeleteItems, "delete-items") + (PubSubError::DeleteNodes, "delete-nodes") + (PubSubError::FilteredNotifications, "filtered-notifications") + (PubSubError::GetPending, "get-pending") + (PubSubError::InstantNodes, "instant-nodes") + (PubSubError::ItemIDs, "item-ids") + (PubSubError::LastPublished, "last-published") + (PubSubError::LeasedSubscription, "leased-subscription") + (PubSubError::ManageSubscriptions, "manage-subscriptions") + (PubSubError::MemberAffiliation, "member-affiliation") + (PubSubError::MetaData, "meta-data") + (PubSubError::ModifyAffiliations, "modify-affiliations") + (PubSubError::MultiCollection, "multi-collection") + (PubSubError::MultiSubscribe, "multi-subscribe") + (PubSubError::OutcastAffiliation, "outcast-affiliation") + (PubSubError::PersistentItems, "persistent-items") + (PubSubError::PresenceNotifications, "presence-notifications") + (PubSubError::PresenceSubscribe, "presence-subscribe") + (PubSubError::Publish, "publish") + (PubSubError::PublishOptions, "publish-options") + (PubSubError::PublishOnlyAffiliation, "publish-only-affiliation") + (PubSubError::PublisherAffiliation, "publisher-affiliation") + (PubSubError::PurgeNodes, "purge-nodes") + (PubSubError::RetractItems, "retract-items") + (PubSubError::RetrieveAffiliations, "retrieve-affiliations") + (PubSubError::RetrieveDefault, "retrieve-default") + (PubSubError::RetrieveItems, "retrieve-items") + (PubSubError::RetrieveSubscriptions, "retrieve-subscriptions") + (PubSubError::Subscribe, "subscribe") + (PubSubError::SubscriptionOptions, "subscription-options") + (PubSubError::SubscriptionNotifications, "subscription-notifications"); } PubSubErrorParser::~PubSubErrorParser() { } void PubSubErrorParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level == 1) { - if (boost::optional<PubSubError::Type> type = typeParser.parse(element)) { - getPayloadInternal()->setType(*type); - if (type == PubSubError::Unsupported) { - if (boost::optional<std::string> feature = attributes.getAttributeValue("feature")) { - if (boost::optional<PubSubError::UnsupportedFeatureType> unsupportedType = unsupportedTypeParser.parse(*feature)) { - getPayloadInternal()->setUnsupportedFeatureType(*unsupportedType); - } - } - } - } - } - ++level; + if (level == 1) { + if (boost::optional<PubSubError::Type> type = typeParser.parse(element)) { + getPayloadInternal()->setType(*type); + if (type == PubSubError::Unsupported) { + if (boost::optional<std::string> feature = attributes.getAttributeValue("feature")) { + if (boost::optional<PubSubError::UnsupportedFeatureType> unsupportedType = unsupportedTypeParser.parse(*feature)) { + getPayloadInternal()->setUnsupportedFeatureType(*unsupportedType); + } + } + } + } + } + ++level; } void PubSubErrorParser::handleEndElement(const std::string&, const std::string&) { - --level; + --level; } void PubSubErrorParser::handleCharacterData(const std::string&) { diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParser.h b/Swiften/Parser/PayloadParsers/PubSubErrorParser.h index 276ad34..adc36e9 100644 --- a/Swiften/Parser/PayloadParsers/PubSubErrorParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParser.h @@ -1,35 +1,35 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubError.h> -#include <Swiften/Parser/GenericPayloadParser.h> #include <Swiften/Parser/EnumParser.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubErrorParser : public GenericPayloadParser<PubSubError> { - public: - PubSubErrorParser(); - virtual ~PubSubErrorParser(); + class SWIFTEN_API PubSubErrorParser : public GenericPayloadParser<PubSubError> { + public: + PubSubErrorParser(); + virtual ~PubSubErrorParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - int level; - EnumParser<PubSubError::Type> typeParser; - EnumParser<PubSubError::UnsupportedFeatureType> unsupportedTypeParser; - }; + private: + int level; + EnumParser<PubSubError::Type> typeParser; + EnumParser<PubSubError::UnsupportedFeatureType> unsupportedTypeParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h index e421581..c7a3614 100644 --- a/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h @@ -11,20 +11,20 @@ #include <Swiften/Parser/PayloadParsers/PubSubErrorParser.h> namespace Swift { - class SWIFTEN_API PubSubErrorParserFactory : public PayloadParserFactory { - public: - PubSubErrorParserFactory() { - } - ~PubSubErrorParserFactory(); + class SWIFTEN_API PubSubErrorParserFactory : public PayloadParserFactory { + public: + PubSubErrorParserFactory() { + } + ~PubSubErrorParserFactory(); - virtual bool canParse(const std::string&, const std::string& ns, const AttributeMap&) const { - return ns == "http://jabber.org/protocol/pubsub#errors"; - } + virtual bool canParse(const std::string&, const std::string& ns, const AttributeMap&) const { + return ns == "http://jabber.org/protocol/pubsub#errors"; + } - virtual PayloadParser* createPayloadParser() { - return new PubSubErrorParser(); - } - }; + virtual PayloadParser* createPayloadParser() { + return new PubSubErrorParser(); + } + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp index dd740b3..8ca1d7d 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp @@ -1,59 +1,54 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - using namespace Swift; -PubSubEventAssociateParser::PubSubEventAssociateParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubEventAssociateParser::PubSubEventAssociateParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubEventAssociateParser::~PubSubEventAssociateParser() { } void PubSubEventAssociateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventAssociateParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubEventAssociateParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h index 3aecdd5..4bb9bd9 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubEventAssociate.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventAssociateParser : public GenericPayloadParser<PubSubEventAssociate> { - public: - PubSubEventAssociateParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventAssociateParser(); + class SWIFTEN_API PubSubEventAssociateParser : public GenericPayloadParser<PubSubEventAssociate> { + public: + PubSubEventAssociateParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventAssociateParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp index 373d971..4452601 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h> #include <Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h> @@ -25,48 +24,48 @@ PubSubEventCollectionParser::~PubSubEventCollectionParser() { } void PubSubEventCollectionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "disassociate" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventDisassociateParser>(parsers); - } - if (element == "associate" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventAssociateParser>(parsers); - } - } + if (level == 1) { + if (element == "disassociate" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = std::make_shared<PubSubEventDisassociateParser>(parsers); + } + if (element == "associate" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = std::make_shared<PubSubEventAssociateParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventCollectionParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "disassociate" && ns == "http://jabber.org/protocol/pubsub#event") { - getPayloadInternal()->setDisassociate(boost::dynamic_pointer_cast<PubSubEventDisassociate>(currentPayloadParser->getPayload())); - } - if (element == "associate" && ns == "http://jabber.org/protocol/pubsub#event") { - getPayloadInternal()->setAssociate(boost::dynamic_pointer_cast<PubSubEventAssociate>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "disassociate" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->setDisassociate(std::dynamic_pointer_cast<PubSubEventDisassociate>(currentPayloadParser->getPayload())); + } + if (element == "associate" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->setAssociate(std::dynamic_pointer_cast<PubSubEventAssociate>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubEventCollectionParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h index de65837..ffdafcf 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubEventCollection.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventCollectionParser : public GenericPayloadParser<PubSubEventCollection> { - public: - PubSubEventCollectionParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventCollectionParser(); + class SWIFTEN_API PubSubEventCollectionParser : public GenericPayloadParser<PubSubEventCollection> { + public: + PubSubEventCollectionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventCollectionParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp index 97e5ad9..9bde91b 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp @@ -1,65 +1,61 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/FormParser.h> using namespace Swift; -PubSubEventConfigurationParser::PubSubEventConfigurationParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubEventConfigurationParser::PubSubEventConfigurationParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubEventConfigurationParser::~PubSubEventConfigurationParser() { } void PubSubEventConfigurationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } - - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - currentPayloadParser = boost::make_shared<FormParser>(); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = std::make_shared<FormParser>(); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventConfigurationParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(std::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubEventConfigurationParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h index 22cf70a..dddb7a4 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubEventConfiguration.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventConfigurationParser : public GenericPayloadParser<PubSubEventConfiguration> { - public: - PubSubEventConfigurationParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventConfigurationParser(); + class SWIFTEN_API PubSubEventConfigurationParser : public GenericPayloadParser<PubSubEventConfiguration> { + public: + PubSubEventConfigurationParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventConfigurationParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp index 9641a03..1569b90 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h> using namespace Swift; @@ -24,42 +23,42 @@ PubSubEventDeleteParser::~PubSubEventDeleteParser() { } void PubSubEventDeleteParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventRedirectParser>(parsers); - } - } + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = std::make_shared<PubSubEventRedirectParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventDeleteParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") { - getPayloadInternal()->setRedirects(boost::dynamic_pointer_cast<PubSubEventRedirect>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->setRedirects(std::dynamic_pointer_cast<PubSubEventRedirect>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubEventDeleteParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h index 9f24732..270430e 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubEventDelete.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventDeleteParser : public GenericPayloadParser<PubSubEventDelete> { - public: - PubSubEventDeleteParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventDeleteParser(); + class SWIFTEN_API PubSubEventDeleteParser : public GenericPayloadParser<PubSubEventDelete> { + public: + PubSubEventDeleteParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventDeleteParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp index 25ec3a9..4e72d85 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp @@ -1,59 +1,52 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - using namespace Swift; -PubSubEventDisassociateParser::PubSubEventDisassociateParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubEventDisassociateParser::PubSubEventDisassociateParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubEventDisassociateParser::~PubSubEventDisassociateParser() { } void PubSubEventDisassociateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventDisassociateParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubEventDisassociateParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h index bd0b904..5f7f1af 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubEventDisassociate.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventDisassociateParser : public GenericPayloadParser<PubSubEventDisassociate> { - public: - PubSubEventDisassociateParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventDisassociateParser(); + class SWIFTEN_API PubSubEventDisassociateParser : public GenericPayloadParser<PubSubEventDisassociate> { + public: + PubSubEventDisassociateParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventDisassociateParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp index e245e63..ba8f714 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp @@ -1,19 +1,17 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubEventItemParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - +#include <Swiften/Parser/PayloadParserFactoryCollection.h> using namespace Swift; @@ -24,46 +22,46 @@ PubSubEventItemParser::~PubSubEventItemParser() { } void PubSubEventItemParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("publisher")) { - getPayloadInternal()->setPublisher(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { - getPayloadInternal()->setID(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("publisher")) { + getPayloadInternal()->setPublisher(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { + getPayloadInternal()->setID(*attributeValue); + } + } - if (level == 1) { - if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { - currentPayloadParser.reset(factory->createPayloadParser()); - } - } + if (level == 1) { + if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { + currentPayloadParser.reset(factory->createPayloadParser()); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventItemParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - getPayloadInternal()->addData(currentPayloadParser->getPayload()); - currentPayloadParser.reset(); - } - } + if (level == 1) { + getPayloadInternal()->addData(currentPayloadParser->getPayload()); + currentPayloadParser.reset(); + } + } } void PubSubEventItemParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h index 23914fd..bd2e72e 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubEventItem.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventItemParser : public GenericPayloadParser<PubSubEventItem> { - public: - PubSubEventItemParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventItemParser(); + class SWIFTEN_API PubSubEventItemParser : public GenericPayloadParser<PubSubEventItem> { + public: + PubSubEventItemParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventItemParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp index 2aafb74..ae4f668 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubEventItemParser.h> #include <Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h> @@ -25,48 +24,48 @@ PubSubEventItemsParser::~PubSubEventItemsParser() { } void PubSubEventItemsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventItemParser>(parsers); - } - if (element == "retract" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventRetractParser>(parsers); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = std::make_shared<PubSubEventItemParser>(parsers); + } + if (element == "retract" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = std::make_shared<PubSubEventRetractParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventItemsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub#event") { - getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubEventItem>(currentPayloadParser->getPayload())); - } - if (element == "retract" && ns == "http://jabber.org/protocol/pubsub#event") { - getPayloadInternal()->addRetract(boost::dynamic_pointer_cast<PubSubEventRetract>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->addItem(std::dynamic_pointer_cast<PubSubEventItem>(currentPayloadParser->getPayload())); + } + if (element == "retract" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->addRetract(std::dynamic_pointer_cast<PubSubEventRetract>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubEventItemsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h index fb38deb..34b3669 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubEventItems.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventItemsParser : public GenericPayloadParser<PubSubEventItems> { - public: - PubSubEventItemsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventItemsParser(); + class SWIFTEN_API PubSubEventItemsParser : public GenericPayloadParser<PubSubEventItems> { + public: + PubSubEventItemsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventItemsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp index 34db2f8..d92730a 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp @@ -1,24 +1,23 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubEventParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> -#include <Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h> #include <Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h> using namespace Swift; @@ -29,53 +28,53 @@ PubSubEventParser::~PubSubEventParser() { } void PubSubEventParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - - if (level == 1) { - if (element == "items" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventItemsParser>(parsers); - } - if (element == "collection" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventCollectionParser>(parsers); - } - if (element == "purge" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventPurgeParser>(parsers); - } - if (element == "configuration" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventConfigurationParser>(parsers); - } - if (element == "delete" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventDeleteParser>(parsers); - } - if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#event") { - currentPayloadParser = boost::make_shared<PubSubEventSubscriptionParser>(parsers); - } - } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 1) { + if (element == "items" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = std::make_shared<PubSubEventItemsParser>(parsers); + } + if (element == "collection" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = std::make_shared<PubSubEventCollectionParser>(parsers); + } + if (element == "purge" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = std::make_shared<PubSubEventPurgeParser>(parsers); + } + if (element == "configuration" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = std::make_shared<PubSubEventConfigurationParser>(parsers); + } + if (element == "delete" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = std::make_shared<PubSubEventDeleteParser>(parsers); + } + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = std::make_shared<PubSubEventSubscriptionParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (currentPayloadParser) { - getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubEventPayload>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (currentPayloadParser) { + getPayloadInternal()->setPayload(std::dynamic_pointer_cast<PubSubEventPayload>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubEventParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventParser.h b/Swiften/Parser/PayloadParsers/PubSubEventParser.h index 76b9b53..3b231b0 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubEvent.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventParser : public GenericPayloadParser<PubSubEvent> { - public: - PubSubEventParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventParser(); + class SWIFTEN_API PubSubEventParser : public GenericPayloadParser<PubSubEvent> { + public: + PubSubEventParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp index cdd3808..30a4d6c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp @@ -1,59 +1,52 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - using namespace Swift; -PubSubEventPurgeParser::PubSubEventPurgeParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubEventPurgeParser::PubSubEventPurgeParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubEventPurgeParser::~PubSubEventPurgeParser() { } void PubSubEventPurgeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventPurgeParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubEventPurgeParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h index f20a7cd..563283c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubEventPurge.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventPurgeParser : public GenericPayloadParser<PubSubEventPurge> { - public: - PubSubEventPurgeParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventPurgeParser(); + class SWIFTEN_API PubSubEventPurgeParser : public GenericPayloadParser<PubSubEventPurge> { + public: + PubSubEventPurgeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventPurgeParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp index 8ea236e..46f1922 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp @@ -1,59 +1,52 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - using namespace Swift; -PubSubEventRedirectParser::PubSubEventRedirectParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubEventRedirectParser::PubSubEventRedirectParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubEventRedirectParser::~PubSubEventRedirectParser() { } void PubSubEventRedirectParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("uri")) { - getPayloadInternal()->setURI(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("uri")) { + getPayloadInternal()->setURI(*attributeValue); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventRedirectParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubEventRedirectParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h index 99076de..603fbec 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubEventRedirect.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventRedirectParser : public GenericPayloadParser<PubSubEventRedirect> { - public: - PubSubEventRedirectParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventRedirectParser(); + class SWIFTEN_API PubSubEventRedirectParser : public GenericPayloadParser<PubSubEventRedirect> { + public: + PubSubEventRedirectParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventRedirectParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp index 7a4df14..226bb33 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp @@ -1,59 +1,53 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - +#include <Swiften/Parser/PayloadParserFactoryCollection.h> using namespace Swift; -PubSubEventRetractParser::PubSubEventRetractParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubEventRetractParser::PubSubEventRetractParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubEventRetractParser::~PubSubEventRetractParser() { } void PubSubEventRetractParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { - getPayloadInternal()->setID(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { + getPayloadInternal()->setID(*attributeValue); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventRetractParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubEventRetractParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h index f49faeb..141790b 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubEventRetract.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventRetractParser : public GenericPayloadParser<PubSubEventRetract> { - public: - PubSubEventRetractParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventRetractParser(); + class SWIFTEN_API PubSubEventRetractParser : public GenericPayloadParser<PubSubEventRetract> { + public: + PubSubEventRetractParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventRetractParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp index 9308101..45c16f6 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp @@ -1,76 +1,70 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> -#include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Base/DateTime.h> #include <Swiften/Parser/EnumParser.h> +#include <Swiften/Parser/PayloadParserFactory.h> using namespace Swift; -PubSubEventSubscriptionParser::PubSubEventSubscriptionParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubEventSubscriptionParser::PubSubEventSubscriptionParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubEventSubscriptionParser::~PubSubEventSubscriptionParser() { } void PubSubEventSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { - if (boost::optional<PubSubEventSubscription::SubscriptionType> value = EnumParser<PubSubEventSubscription::SubscriptionType>()(PubSubEventSubscription::None, "none")(PubSubEventSubscription::Pending, "pending")(PubSubEventSubscription::Subscribed, "subscribed")(PubSubEventSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { - getPayloadInternal()->setSubscription(*value); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { - getPayloadInternal()->setSubscriptionID(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("expiry")) { - getPayloadInternal()->setExpiry(stringToDateTime(*attributeValue)); - } - } - - + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { + if (boost::optional<PubSubEventSubscription::SubscriptionType> value = EnumParser<PubSubEventSubscription::SubscriptionType>()(PubSubEventSubscription::None, "none")(PubSubEventSubscription::Pending, "pending")(PubSubEventSubscription::Subscribed, "subscribed")(PubSubEventSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { + getPayloadInternal()->setSubscription(*value); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("expiry")) { + getPayloadInternal()->setExpiry(stringToDateTime(*attributeValue)); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubEventSubscriptionParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { - if (level == 1) { - - currentPayloadParser.reset(); - } - } + currentPayloadParser.reset(); + } + } } void PubSubEventSubscriptionParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h index 73d8c6c..0d56a20 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubEventSubscription.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubEventSubscriptionParser : public GenericPayloadParser<PubSubEventSubscription> { - public: - PubSubEventSubscriptionParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubEventSubscriptionParser(); + class SWIFTEN_API PubSubEventSubscriptionParser : public GenericPayloadParser<PubSubEventSubscription> { + public: + PubSubEventSubscriptionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventSubscriptionParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp b/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp index a2b22ac..ff5bfc7 100644 --- a/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp @@ -1,19 +1,17 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubItemParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - +#include <Swiften/Parser/PayloadParserFactoryCollection.h> using namespace Swift; @@ -24,40 +22,40 @@ PubSubItemParser::~PubSubItemParser() { } void PubSubItemParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { - getPayloadInternal()->setID(*attributeValue); - } - } - - if (level == 1) { - if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { - currentPayloadParser.reset(factory->createPayloadParser()); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) { + getPayloadInternal()->setID(*attributeValue); + } + } + + if (level == 1) { + if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { + currentPayloadParser.reset(factory->createPayloadParser()); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubItemParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - getPayloadInternal()->addData(currentPayloadParser->getPayload()); - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + getPayloadInternal()->addData(currentPayloadParser->getPayload()); + currentPayloadParser.reset(); + } + } } void PubSubItemParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubItemParser.h b/Swiften/Parser/PayloadParsers/PubSubItemParser.h index 36cdd00..c6e4ccf 100644 --- a/Swiften/Parser/PayloadParsers/PubSubItemParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubItemParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubItem.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubItemParser : public GenericPayloadParser<PubSubItem> { - public: - PubSubItemParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubItemParser(); + class SWIFTEN_API PubSubItemParser : public GenericPayloadParser<PubSubItem> { + public: + PubSubItemParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubItemParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp index f07b6fa..2edfddb 100644 --- a/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp @@ -1,18 +1,18 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubItemsParser.h> -#include <boost/optional.hpp> #include <boost/lexical_cast.hpp> +#include <boost/optional.hpp> -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubItemParser.h> using namespace Swift; @@ -24,52 +24,52 @@ PubSubItemsParser::~PubSubItemsParser() { } void PubSubItemsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("max_items")) { - try { - getPayloadInternal()->setMaximumItems(boost::lexical_cast<unsigned int>(*attributeValue)); - } - catch (boost::bad_lexical_cast&) { - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { - getPayloadInternal()->setSubscriptionID(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("max_items")) { + try { + getPayloadInternal()->setMaximumItems(boost::lexical_cast<unsigned int>(*attributeValue)); + } + catch (boost::bad_lexical_cast&) { + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubItemParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubItemsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { - getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addItem(std::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubItemsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubItemsParser.h b/Swiften/Parser/PayloadParsers/PubSubItemsParser.h index 41d1188..ad6e746 100644 --- a/Swiften/Parser/PayloadParsers/PubSubItemsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubItemsParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubItems.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubItemsParser : public GenericPayloadParser<PubSubItems> { - public: - PubSubItemsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubItemsParser(); + class SWIFTEN_API PubSubItemsParser : public GenericPayloadParser<PubSubItems> { + public: + PubSubItemsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubItemsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp index 438d728..2098d8f 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp @@ -1,73 +1,69 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubOptionsParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/FormParser.h> using namespace Swift; -PubSubOptionsParser::PubSubOptionsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubOptionsParser::PubSubOptionsParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubOptionsParser::~PubSubOptionsParser() { } void PubSubOptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { - getPayloadInternal()->setSubscriptionID(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + } - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - currentPayloadParser = boost::make_shared<FormParser>(); - } - } + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = std::make_shared<FormParser>(); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOptionsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(std::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOptionsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h index d1458c6..ac14caf 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubOptions.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOptionsParser : public GenericPayloadParser<PubSubOptions> { - public: - PubSubOptionsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOptionsParser(); + class SWIFTEN_API PubSubOptionsParser : public GenericPayloadParser<PubSubOptions> { + public: + PubSubOptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOptionsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp index 3a8ceb8..d868ef6 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp @@ -1,66 +1,61 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> -#include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/EnumParser.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> using namespace Swift; -PubSubOwnerAffiliationParser::PubSubOwnerAffiliationParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubOwnerAffiliationParser::PubSubOwnerAffiliationParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubOwnerAffiliationParser::~PubSubOwnerAffiliationParser() { } void PubSubOwnerAffiliationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("affiliation")) { - if (boost::optional<PubSubOwnerAffiliation::Type> value = EnumParser<PubSubOwnerAffiliation::Type>()(PubSubOwnerAffiliation::None, "none")(PubSubOwnerAffiliation::Member, "member")(PubSubOwnerAffiliation::Outcast, "outcast")(PubSubOwnerAffiliation::Owner, "owner")(PubSubOwnerAffiliation::Publisher, "publisher")(PubSubOwnerAffiliation::PublishOnly, "publish-only").parse(*attributeValue)) { - getPayloadInternal()->setType(*value); - } - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("affiliation")) { + if (boost::optional<PubSubOwnerAffiliation::Type> value = EnumParser<PubSubOwnerAffiliation::Type>()(PubSubOwnerAffiliation::None, "none")(PubSubOwnerAffiliation::Member, "member")(PubSubOwnerAffiliation::Outcast, "outcast")(PubSubOwnerAffiliation::Owner, "owner")(PubSubOwnerAffiliation::Publisher, "publisher")(PubSubOwnerAffiliation::PublishOnly, "publish-only").parse(*attributeValue)) { + getPayloadInternal()->setType(*value); + } + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerAffiliationParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { - if (level == 1) { - - currentPayloadParser.reset(); - } - } + currentPayloadParser.reset(); + } + } } void PubSubOwnerAffiliationParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h index 7a95868..0a6503f 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubOwnerAffiliation.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerAffiliationParser : public GenericPayloadParser<PubSubOwnerAffiliation> { - public: - PubSubOwnerAffiliationParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerAffiliationParser(); + class SWIFTEN_API PubSubOwnerAffiliationParser : public GenericPayloadParser<PubSubOwnerAffiliation> { + public: + PubSubOwnerAffiliationParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerAffiliationParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp index df3813e..2f21b7a 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h> using namespace Swift; @@ -24,42 +23,42 @@ PubSubOwnerAffiliationsParser::~PubSubOwnerAffiliationsParser() { } void PubSubOwnerAffiliationsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerAffiliationParser>(parsers); - } - } + if (level == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = std::make_shared<PubSubOwnerAffiliationParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerAffiliationsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") { - getPayloadInternal()->addAffiliation(boost::dynamic_pointer_cast<PubSubOwnerAffiliation>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") { + getPayloadInternal()->addAffiliation(std::dynamic_pointer_cast<PubSubOwnerAffiliation>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOwnerAffiliationsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h index dc78d61..52c7fa9 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubOwnerAffiliations.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerAffiliationsParser : public GenericPayloadParser<PubSubOwnerAffiliations> { - public: - PubSubOwnerAffiliationsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerAffiliationsParser(); + class SWIFTEN_API PubSubOwnerAffiliationsParser : public GenericPayloadParser<PubSubOwnerAffiliations> { + public: + PubSubOwnerAffiliationsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerAffiliationsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp index 1cc8660..7fa6506 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp @@ -1,65 +1,61 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/FormParser.h> using namespace Swift; -PubSubOwnerConfigureParser::PubSubOwnerConfigureParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubOwnerConfigureParser::PubSubOwnerConfigureParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubOwnerConfigureParser::~PubSubOwnerConfigureParser() { } void PubSubOwnerConfigureParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } - - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - currentPayloadParser = boost::make_shared<FormParser>(); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = std::make_shared<FormParser>(); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerConfigureParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(std::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOwnerConfigureParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h index d2dca30..34000fa 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubOwnerConfigure.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerConfigureParser : public GenericPayloadParser<PubSubOwnerConfigure> { - public: - PubSubOwnerConfigureParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerConfigureParser(); + class SWIFTEN_API PubSubOwnerConfigureParser : public GenericPayloadParser<PubSubOwnerConfigure> { + public: + PubSubOwnerConfigureParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerConfigureParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp index a704411..e453230 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp @@ -1,61 +1,55 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/FormParser.h> using namespace Swift; -PubSubOwnerDefaultParser::PubSubOwnerDefaultParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubOwnerDefaultParser::PubSubOwnerDefaultParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubOwnerDefaultParser::~PubSubOwnerDefaultParser() { } void PubSubOwnerDefaultParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - - - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - currentPayloadParser = boost::make_shared<FormParser>(); - } - } - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = std::make_shared<FormParser>(); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerDefaultParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - if (element == "x" && ns == "jabber:x:data") { - getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(std::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOwnerDefaultParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h index d036a30..528c297 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubOwnerDefault.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerDefaultParser : public GenericPayloadParser<PubSubOwnerDefault> { - public: - PubSubOwnerDefaultParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerDefaultParser(); + class SWIFTEN_API PubSubOwnerDefaultParser : public GenericPayloadParser<PubSubOwnerDefault> { + public: + PubSubOwnerDefaultParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerDefaultParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp index 9817793..c30e404 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h> using namespace Swift; @@ -24,42 +23,42 @@ PubSubOwnerDeleteParser::~PubSubOwnerDeleteParser() { } void PubSubOwnerDeleteParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerRedirectParser>(parsers); - } - } + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = std::make_shared<PubSubOwnerRedirectParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerDeleteParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") { - getPayloadInternal()->setRedirect(boost::dynamic_pointer_cast<PubSubOwnerRedirect>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") { + getPayloadInternal()->setRedirect(std::dynamic_pointer_cast<PubSubOwnerRedirect>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOwnerDeleteParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h index f9ab7cb..99a8c0e 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubOwnerDelete.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerDeleteParser : public GenericPayloadParser<PubSubOwnerDelete> { - public: - PubSubOwnerDeleteParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerDeleteParser(); + class SWIFTEN_API PubSubOwnerDeleteParser : public GenericPayloadParser<PubSubOwnerDelete> { + public: + PubSubOwnerDeleteParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerDeleteParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp index 71b1c16..e26f291 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp @@ -1,24 +1,23 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h> #include <Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h> #include <Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h> #include <Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h> using namespace Swift; @@ -29,53 +28,53 @@ PubSubOwnerPubSubParser::~PubSubOwnerPubSubParser() { } void PubSubOwnerPubSubParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - - if (level == 1) { - if (element == "configure" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerConfigureParser>(parsers); - } - if (element == "subscriptions" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerSubscriptionsParser>(parsers); - } - if (element == "default" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerDefaultParser>(parsers); - } - if (element == "purge" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerPurgeParser>(parsers); - } - if (element == "affiliations" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerAffiliationsParser>(parsers); - } - if (element == "delete" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerDeleteParser>(parsers); - } - } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 1) { + if (element == "configure" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = std::make_shared<PubSubOwnerConfigureParser>(parsers); + } + if (element == "subscriptions" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = std::make_shared<PubSubOwnerSubscriptionsParser>(parsers); + } + if (element == "default" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = std::make_shared<PubSubOwnerDefaultParser>(parsers); + } + if (element == "purge" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = std::make_shared<PubSubOwnerPurgeParser>(parsers); + } + if (element == "affiliations" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = std::make_shared<PubSubOwnerAffiliationsParser>(parsers); + } + if (element == "delete" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = std::make_shared<PubSubOwnerDeleteParser>(parsers); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerPubSubParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (currentPayloadParser) { - getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubOwnerPayload>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (currentPayloadParser) { + getPayloadInternal()->setPayload(std::dynamic_pointer_cast<PubSubOwnerPayload>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOwnerPubSubParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h index 30e3bb8..35420f7 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubOwnerPubSub.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerPubSubParser : public GenericPayloadParser<PubSubOwnerPubSub> { - public: - PubSubOwnerPubSubParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerPubSubParser(); + class SWIFTEN_API PubSubOwnerPubSubParser : public GenericPayloadParser<PubSubOwnerPubSub> { + public: + PubSubOwnerPubSubParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerPubSubParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp index f417ec2..7c637cf 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp @@ -1,59 +1,53 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - +#include <Swiften/Parser/PayloadParserFactoryCollection.h> using namespace Swift; -PubSubOwnerPurgeParser::PubSubOwnerPurgeParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubOwnerPurgeParser::PubSubOwnerPurgeParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubOwnerPurgeParser::~PubSubOwnerPurgeParser() { } void PubSubOwnerPurgeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerPurgeParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubOwnerPurgeParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h index e0f5c60..f85b2bb 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubOwnerPurge.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerPurgeParser : public GenericPayloadParser<PubSubOwnerPurge> { - public: - PubSubOwnerPurgeParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerPurgeParser(); + class SWIFTEN_API PubSubOwnerPurgeParser : public GenericPayloadParser<PubSubOwnerPurge> { + public: + PubSubOwnerPurgeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerPurgeParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp index e4ad149..6d0b2a7 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp @@ -1,59 +1,52 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - using namespace Swift; -PubSubOwnerRedirectParser::PubSubOwnerRedirectParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubOwnerRedirectParser::PubSubOwnerRedirectParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubOwnerRedirectParser::~PubSubOwnerRedirectParser() { } void PubSubOwnerRedirectParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("uri")) { - getPayloadInternal()->setURI(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("uri")) { + getPayloadInternal()->setURI(*attributeValue); + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerRedirectParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } } void PubSubOwnerRedirectParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h index 5211d6f..1197952 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubOwnerRedirect.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerRedirectParser : public GenericPayloadParser<PubSubOwnerRedirect> { - public: - PubSubOwnerRedirectParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerRedirectParser(); + class SWIFTEN_API PubSubOwnerRedirectParser : public GenericPayloadParser<PubSubOwnerRedirect> { + public: + PubSubOwnerRedirectParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerRedirectParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp index 9e2fdee..92b81f3 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp @@ -1,66 +1,60 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> -#include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/EnumParser.h> +#include <Swiften/Parser/PayloadParserFactory.h> using namespace Swift; -PubSubOwnerSubscriptionParser::PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubOwnerSubscriptionParser::PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubOwnerSubscriptionParser::~PubSubOwnerSubscriptionParser() { } void PubSubOwnerSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { - if (boost::optional<PubSubOwnerSubscription::SubscriptionType> value = EnumParser<PubSubOwnerSubscription::SubscriptionType>()(PubSubOwnerSubscription::None, "none")(PubSubOwnerSubscription::Pending, "pending")(PubSubOwnerSubscription::Subscribed, "subscribed")(PubSubOwnerSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { - getPayloadInternal()->setSubscription(*value); - } - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { + if (boost::optional<PubSubOwnerSubscription::SubscriptionType> value = EnumParser<PubSubOwnerSubscription::SubscriptionType>()(PubSubOwnerSubscription::None, "none")(PubSubOwnerSubscription::Pending, "pending")(PubSubOwnerSubscription::Subscribed, "subscribed")(PubSubOwnerSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { + getPayloadInternal()->setSubscription(*value); + } + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerSubscriptionParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { - if (level == 1) { - - currentPayloadParser.reset(); - } - } + currentPayloadParser.reset(); + } + } } void PubSubOwnerSubscriptionParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h index dc2a52d..74a61a2 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubOwnerSubscription.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerSubscriptionParser : public GenericPayloadParser<PubSubOwnerSubscription> { - public: - PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerSubscriptionParser(); + class SWIFTEN_API PubSubOwnerSubscriptionParser : public GenericPayloadParser<PubSubOwnerSubscription> { + public: + PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerSubscriptionParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp index 857bd87..6d5e43c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h> using namespace Swift; @@ -24,42 +23,42 @@ PubSubOwnerSubscriptionsParser::~PubSubOwnerSubscriptionsParser() { } void PubSubOwnerSubscriptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") { - currentPayloadParser = boost::make_shared<PubSubOwnerSubscriptionParser>(parsers); - } - } + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = std::make_shared<PubSubOwnerSubscriptionParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubOwnerSubscriptionsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") { - getPayloadInternal()->addSubscription(boost::dynamic_pointer_cast<PubSubOwnerSubscription>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") { + getPayloadInternal()->addSubscription(std::dynamic_pointer_cast<PubSubOwnerSubscription>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubOwnerSubscriptionsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h index ddc2292..541d225 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubOwnerSubscriptions.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubOwnerSubscriptionsParser : public GenericPayloadParser<PubSubOwnerSubscriptions> { - public: - PubSubOwnerSubscriptionsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubOwnerSubscriptionsParser(); + class SWIFTEN_API PubSubOwnerSubscriptionsParser : public GenericPayloadParser<PubSubOwnerSubscriptions> { + public: + PubSubOwnerSubscriptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerSubscriptionsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubParser.cpp b/Swiften/Parser/PayloadParsers/PubSubParser.cpp index c6574a8..eef6e5e 100644 --- a/Swiften/Parser/PayloadParsers/PubSubParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubParser.cpp @@ -1,31 +1,29 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> -#include <Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h> #include <Swiften/Parser/PayloadParsers/PubSubConfigureParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubDefaultParser.h> #include <Swiften/Parser/PayloadParsers/PubSubCreateParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubDefaultParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubItemsParser.h> #include <Swiften/Parser/PayloadParsers/PubSubOptionsParser.h> #include <Swiften/Parser/PayloadParsers/PubSubPublishParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubOptionsParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubItemsParser.h> #include <Swiften/Parser/PayloadParsers/PubSubRetractParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h> #include <Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h> using namespace Swift; @@ -36,90 +34,90 @@ PubSubParser::~PubSubParser() { } void PubSubParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 1) { - if (element == "items" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubItemsParser>(parsers); - } - if (element == "create" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubCreateParser>(parsers); - } - if (element == "publish" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubPublishParser>(parsers); - } - if (element == "affiliations" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubAffiliationsParser>(parsers); - } - if (element == "retract" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubRetractParser>(parsers); - } - if (element == "options" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubOptionsParser>(parsers); - } - if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubConfigureParser>(parsers); - } - if (element == "default" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubDefaultParser>(parsers); - } - if (element == "subscriptions" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubSubscriptionsParser>(parsers); - } - if (element == "subscribe" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubSubscribeParser>(parsers); - } - if (element == "unsubscribe" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubUnsubscribeParser>(parsers); - } - if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubSubscriptionParser>(parsers); - } - } + if (level == 1) { + if (element == "items" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubItemsParser>(parsers); + } + if (element == "create" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubCreateParser>(parsers); + } + if (element == "publish" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubPublishParser>(parsers); + } + if (element == "affiliations" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubAffiliationsParser>(parsers); + } + if (element == "retract" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubRetractParser>(parsers); + } + if (element == "options" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubOptionsParser>(parsers); + } + if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubConfigureParser>(parsers); + } + if (element == "default" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubDefaultParser>(parsers); + } + if (element == "subscriptions" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubSubscriptionsParser>(parsers); + } + if (element == "subscribe" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubSubscribeParser>(parsers); + } + if (element == "unsubscribe" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubUnsubscribeParser>(parsers); + } + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubSubscriptionParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (currentPayloadParser) { - if (element == "options" && ns == "http://jabber.org/protocol/pubsub") { - optionsPayload = boost::dynamic_pointer_cast<PubSubOptions>(currentPayloadParser->getPayload()); - } - else if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") { - configurePayload = boost::dynamic_pointer_cast<PubSubConfigure>(currentPayloadParser->getPayload()); - } - else { - getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubPayload>(currentPayloadParser->getPayload())); - } - } - currentPayloadParser.reset(); - } + if (level == 1) { + if (currentPayloadParser) { + if (element == "options" && ns == "http://jabber.org/protocol/pubsub") { + optionsPayload = std::dynamic_pointer_cast<PubSubOptions>(currentPayloadParser->getPayload()); + } + else if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") { + configurePayload = std::dynamic_pointer_cast<PubSubConfigure>(currentPayloadParser->getPayload()); + } + else { + getPayloadInternal()->setPayload(std::dynamic_pointer_cast<PubSubPayload>(currentPayloadParser->getPayload())); + } + } + currentPayloadParser.reset(); + } - if (level == 0) { - if (boost::shared_ptr<PubSubCreate> create = boost::dynamic_pointer_cast<PubSubCreate>(getPayloadInternal()->getPayload())) { - if (configurePayload) { - create->setConfigure(configurePayload); - } - } - if (boost::shared_ptr<PubSubSubscribe> subscribe = boost::dynamic_pointer_cast<PubSubSubscribe>(getPayloadInternal()->getPayload())) { - if (optionsPayload) { - subscribe->setOptions(optionsPayload); - } - } - } - } + if (level == 0) { + if (std::shared_ptr<PubSubCreate> create = std::dynamic_pointer_cast<PubSubCreate>(getPayloadInternal()->getPayload())) { + if (configurePayload) { + create->setConfigure(configurePayload); + } + } + if (std::shared_ptr<PubSubSubscribe> subscribe = std::dynamic_pointer_cast<PubSubSubscribe>(getPayloadInternal()->getPayload())) { + if (optionsPayload) { + subscribe->setOptions(optionsPayload); + } + } + } + } } void PubSubParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubParser.h b/Swiften/Parser/PayloadParsers/PubSubParser.h index 0562046..1f40ca9 100644 --- a/Swiften/Parser/PayloadParsers/PubSubParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubParser.h @@ -1,38 +1,38 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSub.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; - class PubSubOptions; - class PubSubConfigure; + class PayloadParserFactoryCollection; + class PayloadParser; + class PubSubOptions; + class PubSubConfigure; - class SWIFTEN_API PubSubParser : public GenericPayloadParser<PubSub> { - public: - PubSubParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubParser(); + class SWIFTEN_API PubSubParser : public GenericPayloadParser<PubSub> { + public: + PubSubParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - boost::shared_ptr<PubSubConfigure> configurePayload; - boost::shared_ptr<PubSubOptions> optionsPayload; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + std::shared_ptr<PubSubConfigure> configurePayload; + std::shared_ptr<PubSubOptions> optionsPayload; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp b/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp index 2b52edc..8c8db3d 100644 --- a/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubPublishParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubItemParser.h> using namespace Swift; @@ -24,42 +23,42 @@ PubSubPublishParser::~PubSubPublishParser() { } void PubSubPublishParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubItemParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubPublishParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { - getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addItem(std::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubPublishParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubPublishParser.h b/Swiften/Parser/PayloadParsers/PubSubPublishParser.h index 6dd039f..ad7dd11 100644 --- a/Swiften/Parser/PayloadParsers/PubSubPublishParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubPublishParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubPublish.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubPublishParser : public GenericPayloadParser<PubSubPublish> { - public: - PubSubPublishParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubPublishParser(); + class SWIFTEN_API PubSubPublishParser : public GenericPayloadParser<PubSubPublish> { + public: + PubSubPublishParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubPublishParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp b/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp index 909e82f..d5d5c0a 100644 --- a/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp @@ -1,18 +1,15 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubRetractParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubItemParser.h> using namespace Swift; @@ -24,45 +21,49 @@ PubSubRetractParser::~PubSubRetractParser() { } void PubSubRetractParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("notify")) { - getPayloadInternal()->setNotify(*attributeValue == "true" ? true : false); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("notify")) { + boost::optional<bool> notify; + if (attributeValue.is_initialized()) { + notify = (attributeValue.get() == "true" || attributeValue.get() == "1") ? true : false; + } + getPayloadInternal()->setNotify(notify); + } + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubItemParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubRetractParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { - getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addItem(std::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubRetractParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubRetractParser.h b/Swiften/Parser/PayloadParsers/PubSubRetractParser.h index 8d7b3fd..6bea498 100644 --- a/Swiften/Parser/PayloadParsers/PubSubRetractParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubRetractParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubRetract.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubRetractParser : public GenericPayloadParser<PubSubRetract> { - public: - PubSubRetractParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubRetractParser(); + class SWIFTEN_API PubSubRetractParser : public GenericPayloadParser<PubSubRetract> { + public: + PubSubRetractParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubRetractParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp index 64bea49..88b7758 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp @@ -1,57 +1,48 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - using namespace Swift; -PubSubSubscribeOptionsParser::PubSubSubscribeOptionsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubSubscribeOptionsParser::PubSubSubscribeOptionsParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubSubscribeOptionsParser::~PubSubSubscribeOptionsParser() { } void PubSubSubscribeOptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubSubscribeOptionsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 1) { - if (element == "required") { - getPayloadInternal()->setRequired(true); - } - currentPayloadParser.reset(); - } - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + if (element == "required") { + getPayloadInternal()->setRequired(true); + } + currentPayloadParser.reset(); + } + } } void PubSubSubscribeOptionsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h index 928e893..328818b 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubSubscribeOptions.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubSubscribeOptionsParser : public GenericPayloadParser<PubSubSubscribeOptions> { - public: - PubSubSubscribeOptionsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubSubscribeOptionsParser(); + class SWIFTEN_API PubSubSubscribeOptionsParser : public GenericPayloadParser<PubSubSubscribeOptions> { + public: + PubSubSubscribeOptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscribeOptionsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp index 3f34fc7..1de39e7 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp @@ -1,64 +1,57 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - using namespace Swift; -PubSubSubscribeParser::PubSubSubscribeParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubSubscribeParser::PubSubSubscribeParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubSubscribeParser::~PubSubSubscribeParser() { } void PubSubSubscribeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + } + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubSubscribeParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { - if (level == 1) { - - currentPayloadParser.reset(); - } - } + currentPayloadParser.reset(); + } + } } void PubSubSubscribeParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h index b4838d3..31221cb 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubSubscribe.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubSubscribeParser : public GenericPayloadParser<PubSubSubscribe> { - public: - PubSubSubscribeParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubSubscribeParser(); + class SWIFTEN_API PubSubSubscribeParser : public GenericPayloadParser<PubSubSubscribe> { + public: + PubSubSubscribeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscribeParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp index b78c841..0f27cb2 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp @@ -1,19 +1,18 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> -#include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/EnumParser.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h> using namespace Swift; @@ -25,55 +24,55 @@ PubSubSubscriptionParser::~PubSubSubscriptionParser() { } void PubSubSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { - getPayloadInternal()->setSubscriptionID(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { - if (boost::optional<PubSubSubscription::SubscriptionType> value = EnumParser<PubSubSubscription::SubscriptionType>()(PubSubSubscription::None, "none")(PubSubSubscription::Pending, "pending")(PubSubSubscription::Subscribed, "subscribed")(PubSubSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { - getPayloadInternal()->setSubscription(*value); - } - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { + if (boost::optional<PubSubSubscription::SubscriptionType> value = EnumParser<PubSubSubscription::SubscriptionType>()(PubSubSubscription::None, "none")(PubSubSubscription::Pending, "pending")(PubSubSubscription::Subscribed, "subscribed")(PubSubSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { + getPayloadInternal()->setSubscription(*value); + } + } + } - if (level == 1) { - if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubSubscribeOptionsParser>(parsers); - } - } + if (level == 1) { + if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubSubscribeOptionsParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubSubscriptionParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") { - getPayloadInternal()->setOptions(boost::dynamic_pointer_cast<PubSubSubscribeOptions>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->setOptions(std::dynamic_pointer_cast<PubSubSubscribeOptions>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubSubscriptionParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h index 98baa3d..7075a99 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubSubscription.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubSubscriptionParser : public GenericPayloadParser<PubSubSubscription> { - public: - PubSubSubscriptionParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubSubscriptionParser(); + class SWIFTEN_API PubSubSubscriptionParser : public GenericPayloadParser<PubSubSubscription> { + public: + PubSubSubscriptionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscriptionParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp index 85929a4..8b0fbef 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" + #include <Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h> using namespace Swift; @@ -24,42 +23,42 @@ PubSubSubscriptionsParser::~PubSubSubscriptionsParser() { } void PubSubSubscriptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - } + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + } - if (level == 1) { - if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { - currentPayloadParser = boost::make_shared<PubSubSubscriptionParser>(parsers); - } - } + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = std::make_shared<PubSubSubscriptionParser>(parsers); + } + } - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubSubscriptionsParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } - if (level == 1) { - if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { - getPayloadInternal()->addSubscription(boost::dynamic_pointer_cast<PubSubSubscription>(currentPayloadParser->getPayload())); - } - currentPayloadParser.reset(); - } - } + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addSubscription(std::dynamic_pointer_cast<PubSubSubscription>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } } void PubSubSubscriptionsParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h index 25a2c2e..2371a56 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h @@ -1,34 +1,34 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubSubscriptions.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubSubscriptionsParser : public GenericPayloadParser<PubSubSubscriptions> { - public: - PubSubSubscriptionsParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubSubscriptionsParser(); + class SWIFTEN_API PubSubSubscriptionsParser : public GenericPayloadParser<PubSubSubscriptions> { + public: + PubSubSubscriptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscriptionsParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + PayloadParserFactoryCollection* parsers; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp index 1b1808e..ea3b46d 100644 --- a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp @@ -1,67 +1,62 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#pragma clang diagnostic ignored "-Wunused-private-field" - #include <Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h> #include <boost/optional.hpp> - -#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> - using namespace Swift; -PubSubUnsubscribeParser::PubSubUnsubscribeParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +PubSubUnsubscribeParser::PubSubUnsubscribeParser(PayloadParserFactoryCollection* /*parsers*/) : level(0) { } PubSubUnsubscribeParser::~PubSubUnsubscribeParser() { } void PubSubUnsubscribeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { - getPayloadInternal()->setNode(*attributeValue); - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { - if (boost::optional<JID> jid = JID::parse(*attributeValue)) { - getPayloadInternal()->setJID(*jid); - } - } - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { - getPayloadInternal()->setSubscriptionID(*attributeValue); - } - } - - - - if (level >= 1 && currentPayloadParser) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - ++level; + if (level == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributeValue); + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { + getPayloadInternal()->setSubscriptionID(*attributeValue); + } + } + + + + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + ++level; } void PubSubUnsubscribeParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (currentPayloadParser) { - if (level >= 1) { - currentPayloadParser->handleEndElement(element, ns); - } + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { - if (level == 1) { - - currentPayloadParser.reset(); - } - } + currentPayloadParser.reset(); + } + } } void PubSubUnsubscribeParser::handleCharacterData(const std::string& data) { - if (level > 1 && currentPayloadParser) { - currentPayloadParser->handleCharacterData(data); - } + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } diff --git a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h index 914554e..e471130 100644 --- a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/PubSubUnsubscribe.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class PayloadParser; + class PayloadParserFactoryCollection; + class PayloadParser; - class SWIFTEN_API PubSubUnsubscribeParser : public GenericPayloadParser<PubSubUnsubscribe> { - public: - PubSubUnsubscribeParser(PayloadParserFactoryCollection* parsers); - virtual ~PubSubUnsubscribeParser(); + class SWIFTEN_API PubSubUnsubscribeParser : public GenericPayloadParser<PubSubUnsubscribe> { + public: + PubSubUnsubscribeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubUnsubscribeParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - PayloadParserFactoryCollection* parsers; - int level; - boost::shared_ptr<PayloadParser> currentPayloadParser; - }; + private: + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; + }; } diff --git a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp index 801ee6a..97abce3 100644 --- a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp @@ -1,10 +1,11 @@ /* - * 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/RawXMLPayloadParser.h> + #include <Swiften/Parser/SerializingParser.h> namespace Swift { @@ -13,20 +14,20 @@ RawXMLPayloadParser::RawXMLPayloadParser() : level_(0) { } void RawXMLPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - ++level_; - serializingParser_.handleStartElement(element, ns, attributes); + ++level_; + serializingParser_.handleStartElement(element, ns, attributes); } void RawXMLPayloadParser::handleEndElement(const std::string& element, const std::string& ns) { - serializingParser_.handleEndElement(element, ns); - --level_; - if (level_ == 0) { - getPayloadInternal()->setRawXML(serializingParser_.getResult()); - } + serializingParser_.handleEndElement(element, ns); + --level_; + if (level_ == 0) { + getPayloadInternal()->setRawXML(serializingParser_.getResult()); + } } void RawXMLPayloadParser::handleCharacterData(const std::string& data) { - serializingParser_.handleCharacterData(data); + serializingParser_.handleCharacterData(data); } } diff --git a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h index e3c5993..1f20105 100644 --- a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h @@ -12,18 +12,18 @@ #include <Swiften/Parser/SerializingParser.h> namespace Swift { - class SerializingParser; + class SerializingParser; - class SWIFTEN_API RawXMLPayloadParser : public GenericPayloadParser<RawXMLPayload> { - public: - RawXMLPayloadParser(); + class SWIFTEN_API RawXMLPayloadParser : public GenericPayloadParser<RawXMLPayload> { + public: + RawXMLPayloadParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - SerializingParser serializingParser_; - }; + private: + int level_; + SerializingParser serializingParser_; + }; } diff --git a/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h index a363098..f7b7601 100644 --- a/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h @@ -1,27 +1,28 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <string> + #include <Swiften/Base/API.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h> -#include <string> namespace Swift { - class SWIFTEN_API RawXMLPayloadParserFactory : public PayloadParserFactory { - public: - RawXMLPayloadParserFactory() {} + class SWIFTEN_API RawXMLPayloadParserFactory : public PayloadParserFactory { + public: + RawXMLPayloadParserFactory() {} - virtual bool canParse(const std::string&, const std::string&, const AttributeMap&) const { - return true; - } + virtual bool canParse(const std::string&, const std::string&, const AttributeMap&) const { + return true; + } - virtual PayloadParser* createPayloadParser() { - return new RawXMLPayloadParser(); - } - }; + virtual PayloadParser* createPayloadParser() { + return new RawXMLPayloadParser(); + } + }; } diff --git a/Swiften/Parser/PayloadParsers/ReplaceParser.cpp b/Swiften/Parser/PayloadParsers/ReplaceParser.cpp index f3483be..66e219a 100644 --- a/Swiften/Parser/PayloadParsers/ReplaceParser.cpp +++ b/Swiften/Parser/PayloadParsers/ReplaceParser.cpp @@ -16,22 +16,22 @@ namespace Swift { - ReplaceParser::ReplaceParser() : level_(0) { - } - - void ReplaceParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - if (level_ == 0) { - std::string id = attributes.getAttribute("id"); - getPayloadInternal()->setID(id); - } - level_++; - } - - void ReplaceParser::handleEndElement(const std::string&, const std::string&) { - --level_; - } - - void ReplaceParser::handleCharacterData(const std::string&) { - } + ReplaceParser::ReplaceParser() : level_(0) { + } + + void ReplaceParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + if (level_ == 0) { + std::string id = attributes.getAttribute("id"); + getPayloadInternal()->setID(id); + } + level_++; + } + + void ReplaceParser::handleEndElement(const std::string&, const std::string&) { + --level_; + } + + void ReplaceParser::handleCharacterData(const std::string&) { + } } diff --git a/Swiften/Parser/PayloadParsers/ReplaceParser.h b/Swiften/Parser/PayloadParsers/ReplaceParser.h index 3c1fbbc..21d7322 100644 --- a/Swiften/Parser/PayloadParsers/ReplaceParser.h +++ b/Swiften/Parser/PayloadParsers/ReplaceParser.h @@ -17,14 +17,14 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API ReplaceParser : public GenericPayloadParser<Replace> { - public: - ReplaceParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + class SWIFTEN_API ReplaceParser : public GenericPayloadParser<Replace> { + public: + ReplaceParser(); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - }; + private: + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp b/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp index c49f9a4..2965d66 100644 --- a/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp +++ b/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp @@ -12,32 +12,32 @@ ResourceBindParser::ResourceBindParser() : level_(0), inJID_(false), inResource_ } void ResourceBindParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { - if (level_ == 1) { - text_ = ""; - if (element == "resource") { - inResource_ = true; - } - if (element == "jid") { - inJID_ = true; - } - } - ++level_; + if (level_ == 1) { + text_ = ""; + if (element == "resource") { + inResource_ = true; + } + if (element == "jid") { + inJID_ = true; + } + } + ++level_; } void ResourceBindParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 1) { - if (inJID_) { - getPayloadInternal()->setJID(JID(text_)); - } - else if (inResource_) { - getPayloadInternal()->setResource(text_); - } - } + --level_; + if (level_ == 1) { + if (inJID_) { + getPayloadInternal()->setJID(JID(text_)); + } + else if (inResource_) { + getPayloadInternal()->setResource(text_); + } + } } void ResourceBindParser::handleCharacterData(const std::string& data) { - text_ += data; + text_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/ResourceBindParser.h b/Swiften/Parser/PayloadParsers/ResourceBindParser.h index 134bf14..3619c0b 100644 --- a/Swiften/Parser/PayloadParsers/ResourceBindParser.h +++ b/Swiften/Parser/PayloadParsers/ResourceBindParser.h @@ -11,18 +11,18 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API ResourceBindParser : public GenericPayloadParser<ResourceBind> { - public: - ResourceBindParser(); + class SWIFTEN_API ResourceBindParser : public GenericPayloadParser<ResourceBind> { + public: + ResourceBindParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - bool inJID_; - bool inResource_; - std::string text_; - }; + private: + int level_; + bool inJID_; + bool inResource_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/ResultSetParser.cpp b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp index 6835141..80d89d7 100644 --- a/Swiften/Parser/PayloadParsers/ResultSetParser.cpp +++ b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp @@ -1,12 +1,14 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/ResultSetParser.h> -#include <boost/optional.hpp> + #include <boost/lexical_cast.hpp> +#include <boost/optional.hpp> + #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParserFactoryCollection.h> @@ -16,50 +18,50 @@ ResultSetParser::ResultSetParser() : level_(TopLevel) { } void ResultSetParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - currentText_ = ""; - if (level_ == PayloadLevel) { - if (element == "first" && ns == "http://jabber.org/protocol/rsm") { - if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("index")) { - try { - getPayloadInternal()->setFirstIDIndex(boost::lexical_cast<int>(*attributeValue)); - } catch(boost::bad_lexical_cast&) { - } - } - } - } - ++level_; + currentText_ = ""; + if (level_ == PayloadLevel) { + if (element == "first" && ns == "http://jabber.org/protocol/rsm") { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("index")) { + try { + getPayloadInternal()->setFirstIDIndex(boost::lexical_cast<int>(*attributeValue)); + } catch(boost::bad_lexical_cast&) { + } + } + } + } + ++level_; } void ResultSetParser::handleEndElement(const std::string& element, const std::string&) { - --level_; - if (level_ == PayloadLevel) { - if (element == "max") { - try { - getPayloadInternal()->setMaxItems(boost::lexical_cast<int>(currentText_)); - } catch(boost::bad_lexical_cast&) { - } - } else if (element == "count") { - try { - getPayloadInternal()->setCount(boost::lexical_cast<int>(currentText_)); - } catch(boost::bad_lexical_cast&) { - } - } else if (element == "index") { - try { - getPayloadInternal()->setIndex(boost::lexical_cast<int>(currentText_)); - } catch(boost::bad_lexical_cast&) { - } - } else if (element == "first") { - getPayloadInternal()->setFirstID(currentText_); - } else if (element == "last") { - getPayloadInternal()->setLastID(currentText_); - } else if (element == "before") { - getPayloadInternal()->setBefore(currentText_); - } else if (element == "after") { - getPayloadInternal()->setAfter(currentText_); - } - } + --level_; + if (level_ == PayloadLevel) { + if (element == "max") { + try { + getPayloadInternal()->setMaxItems(boost::lexical_cast<int>(currentText_)); + } catch(boost::bad_lexical_cast&) { + } + } else if (element == "count") { + try { + getPayloadInternal()->setCount(boost::lexical_cast<int>(currentText_)); + } catch(boost::bad_lexical_cast&) { + } + } else if (element == "index") { + try { + getPayloadInternal()->setIndex(boost::lexical_cast<int>(currentText_)); + } catch(boost::bad_lexical_cast&) { + } + } else if (element == "first") { + getPayloadInternal()->setFirstID(currentText_); + } else if (element == "last") { + getPayloadInternal()->setLastID(currentText_); + } else if (element == "before") { + getPayloadInternal()->setBefore(currentText_); + } else if (element == "after") { + getPayloadInternal()->setAfter(currentText_); + } + } } void ResultSetParser::handleCharacterData(const std::string& data) { - currentText_ += data; + currentText_ += data; } diff --git a/Swiften/Parser/PayloadParsers/ResultSetParser.h b/Swiften/Parser/PayloadParsers/ResultSetParser.h index 5277803..aa18ae6 100644 --- a/Swiften/Parser/PayloadParsers/ResultSetParser.h +++ b/Swiften/Parser/PayloadParsers/ResultSetParser.h @@ -1,36 +1,36 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/ResultSet.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class SWIFTEN_API ResultSetParser : public GenericPayloadParser<ResultSet> { - public: - ResultSetParser(); + class SWIFTEN_API ResultSetParser : public GenericPayloadParser<ResultSet> { + public: + ResultSetParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; - private: - std::string currentText_; - int level_; - }; + private: + std::string currentText_; + int level_; + }; } diff --git a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp index 32be2c7..f99f592 100644 --- a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp +++ b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.cpp @@ -4,7 +4,14 @@ * 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 <Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h> + #include <Swiften/Parser/SerializingParser.h> namespace Swift { @@ -13,56 +20,56 @@ RosterItemExchangeParser::RosterItemExchangeParser() : level_(TopLevel), inItem_ } void RosterItemExchangeParser::handleStartElement(const std::string& element, const std::string& /*ns*/, const AttributeMap& attributes) { - if (level_ == PayloadLevel) { - if (element == "item") { - inItem_ = true; + if (level_ == PayloadLevel) { + if (element == "item") { + inItem_ = true; - currentItem_ = RosterItemExchangePayload::Item(); + currentItem_ = RosterItemExchangePayload::Item(); - currentItem_.setJID(JID(attributes.getAttribute("jid"))); - currentItem_.setName(attributes.getAttribute("name")); + currentItem_.setJID(JID(attributes.getAttribute("jid"))); + currentItem_.setName(attributes.getAttribute("name")); - std::string action = attributes.getAttribute("action"); - if (action == "add") { - currentItem_.setAction(RosterItemExchangePayload::Item::Add); - } - else if (action == "modify") { - currentItem_.setAction(RosterItemExchangePayload::Item::Modify); - } - else if (action == "delete") { - currentItem_.setAction(RosterItemExchangePayload::Item::Delete); - } - else { - // Add is default action according to XEP - currentItem_.setAction(RosterItemExchangePayload::Item::Add); - } - } - } - else if (level_ == ItemLevel) { - if (element == "group") { - currentText_ = ""; - } - } - ++level_; + std::string action = attributes.getAttribute("action"); + if (action == "add") { + currentItem_.setAction(RosterItemExchangePayload::Item::Add); + } + else if (action == "modify") { + currentItem_.setAction(RosterItemExchangePayload::Item::Modify); + } + else if (action == "delete") { + currentItem_.setAction(RosterItemExchangePayload::Item::Delete); + } + else { + // Add is default action according to XEP + currentItem_.setAction(RosterItemExchangePayload::Item::Add); + } + } + } + else if (level_ == ItemLevel) { + if (element == "group") { + currentText_ = ""; + } + } + ++level_; } void RosterItemExchangeParser::handleEndElement(const std::string& element, const std::string& /*ns*/) { - --level_; - if (level_ == PayloadLevel) { - if (inItem_) { - getPayloadInternal()->addItem(currentItem_); - inItem_ = false; - } - } - else if (level_ == ItemLevel) { - if (element == "group") { - currentItem_.addGroup(currentText_); - } - } + --level_; + if (level_ == PayloadLevel) { + if (inItem_) { + getPayloadInternal()->addItem(currentItem_); + inItem_ = false; + } + } + else if (level_ == ItemLevel) { + if (element == "group") { + currentItem_.addGroup(currentText_); + } + } } void RosterItemExchangeParser::handleCharacterData(const std::string& data) { - currentText_ += data; + currentText_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h index bf3dace..40e010a 100644 --- a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h +++ b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h @@ -17,25 +17,25 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SerializingParser; + class SerializingParser; - class SWIFTEN_API RosterItemExchangeParser : public GenericPayloadParser<RosterItemExchangePayload> { - public: - RosterItemExchangeParser(); + class SWIFTEN_API RosterItemExchangeParser : public GenericPayloadParser<RosterItemExchangePayload> { + public: + RosterItemExchangeParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - ItemLevel = 2 - }; - int level_; - bool inItem_; - RosterItemExchangePayload::Item currentItem_; - std::string currentText_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + ItemLevel = 2 + }; + int level_; + bool inItem_; + RosterItemExchangePayload::Item currentItem_; + std::string currentText_; + }; } diff --git a/Swiften/Parser/PayloadParsers/RosterParser.cpp b/Swiften/Parser/PayloadParsers/RosterParser.cpp index b35d598..90fb518 100644 --- a/Swiften/Parser/PayloadParsers/RosterParser.cpp +++ b/Swiften/Parser/PayloadParsers/RosterParser.cpp @@ -1,104 +1,106 @@ /* - * 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/RosterParser.h> +#include <cassert> + #include <boost/optional.hpp> #include <Swiften/Parser/SerializingParser.h> namespace Swift { -RosterParser::RosterParser() : level_(TopLevel), inItem_(false), unknownContentParser_(0) { +RosterParser::RosterParser() : level_(TopLevel), inItem_(false), unknownContentParser_(nullptr) { } void RosterParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == TopLevel) { - boost::optional<std::string> ver = attributes.getAttributeValue("ver"); - if (ver) { - getPayloadInternal()->setVersion(*ver); - } - } - else if (level_ == PayloadLevel) { - if (element == "item") { - inItem_ = true; - currentItem_ = RosterItemPayload(); + if (level_ == TopLevel) { + boost::optional<std::string> ver = attributes.getAttributeValue("ver"); + if (ver) { + getPayloadInternal()->setVersion(*ver); + } + } + else if (level_ == PayloadLevel) { + if (element == "item") { + inItem_ = true; + currentItem_ = RosterItemPayload(); - currentItem_.setJID(JID(attributes.getAttribute("jid"))); - currentItem_.setName(attributes.getAttribute("name")); + currentItem_.setJID(JID(attributes.getAttribute("jid"))); + currentItem_.setName(attributes.getAttribute("name")); - std::string subscription = attributes.getAttribute("subscription"); - if (subscription == "both") { - currentItem_.setSubscription(RosterItemPayload::Both); - } - else if (subscription == "to") { - currentItem_.setSubscription(RosterItemPayload::To); - } - else if (subscription == "from") { - currentItem_.setSubscription(RosterItemPayload::From); - } - else if (subscription == "remove") { - currentItem_.setSubscription(RosterItemPayload::Remove); - } - else { - currentItem_.setSubscription(RosterItemPayload::None); - } + std::string subscription = attributes.getAttribute("subscription"); + if (subscription == "both") { + currentItem_.setSubscription(RosterItemPayload::Both); + } + else if (subscription == "to") { + currentItem_.setSubscription(RosterItemPayload::To); + } + else if (subscription == "from") { + currentItem_.setSubscription(RosterItemPayload::From); + } + else if (subscription == "remove") { + currentItem_.setSubscription(RosterItemPayload::Remove); + } + else { + currentItem_.setSubscription(RosterItemPayload::None); + } - if (attributes.getAttribute("ask") == "subscribe") { - currentItem_.setSubscriptionRequested(); - } - } - } - else if (level_ == ItemLevel) { - if (element == "group") { - currentText_ = ""; - } - else { - assert(!unknownContentParser_); - unknownContentParser_ = new SerializingParser(); - unknownContentParser_->handleStartElement(element, ns, attributes); - } - } - else if (unknownContentParser_) { - unknownContentParser_->handleStartElement(element, ns, attributes); - } - ++level_; + if (attributes.getAttribute("ask") == "subscribe") { + currentItem_.setSubscriptionRequested(); + } + } + } + else if (level_ == ItemLevel) { + if (element == "group") { + currentText_ = ""; + } + else { + assert(!unknownContentParser_); + unknownContentParser_ = new SerializingParser(); + unknownContentParser_->handleStartElement(element, ns, attributes); + } + } + else if (unknownContentParser_) { + unknownContentParser_->handleStartElement(element, ns, attributes); + } + ++level_; } void RosterParser::handleEndElement(const std::string& element, const std::string& ns) { - --level_; - if (level_ == PayloadLevel) { - if (inItem_) { - getPayloadInternal()->addItem(currentItem_); - inItem_ = false; - } - } - else if (level_ == ItemLevel) { - if (unknownContentParser_) { - unknownContentParser_->handleEndElement(element, ns); - currentItem_.addUnknownContent(unknownContentParser_->getResult()); - delete unknownContentParser_; - unknownContentParser_ = NULL; - } - else if (element == "group") { - currentItem_.addGroup(currentText_); - } - } - else if (unknownContentParser_) { - unknownContentParser_->handleEndElement(element, ns); - } + --level_; + if (level_ == PayloadLevel) { + if (inItem_) { + getPayloadInternal()->addItem(currentItem_); + inItem_ = false; + } + } + else if (level_ == ItemLevel) { + if (unknownContentParser_) { + unknownContentParser_->handleEndElement(element, ns); + currentItem_.addUnknownContent(unknownContentParser_->getResult()); + delete unknownContentParser_; + unknownContentParser_ = nullptr; + } + else if (element == "group") { + currentItem_.addGroup(currentText_); + } + } + else if (unknownContentParser_) { + unknownContentParser_->handleEndElement(element, ns); + } } void RosterParser::handleCharacterData(const std::string& data) { - if (unknownContentParser_) { - unknownContentParser_->handleCharacterData(data); - } - else { - currentText_ += data; - } + if (unknownContentParser_) { + unknownContentParser_->handleCharacterData(data); + } + else { + currentText_ += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/RosterParser.h b/Swiften/Parser/PayloadParsers/RosterParser.h index 3440825..2989f46 100644 --- a/Swiften/Parser/PayloadParsers/RosterParser.h +++ b/Swiften/Parser/PayloadParsers/RosterParser.h @@ -11,26 +11,26 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SerializingParser; + class SerializingParser; - class SWIFTEN_API RosterParser : public GenericPayloadParser<RosterPayload> { - public: - RosterParser(); + class SWIFTEN_API RosterParser : public GenericPayloadParser<RosterPayload> { + public: + RosterParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - ItemLevel = 2 - }; - int level_; - bool inItem_; - RosterItemPayload currentItem_; - std::string currentText_; - SerializingParser* unknownContentParser_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + ItemLevel = 2 + }; + int level_; + bool inItem_; + RosterItemPayload currentItem_; + std::string currentText_; + SerializingParser* unknownContentParser_; + }; } diff --git a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp index 5cfd28d..502f400 100644 --- a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp +++ b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp @@ -5,12 +5,12 @@ */ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "S5BProxyRequestParser.h" +#include <Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h> #include <boost/lexical_cast.hpp> #include <boost/optional.hpp> @@ -24,48 +24,48 @@ S5BProxyRequestParser::~S5BProxyRequestParser() { } void S5BProxyRequestParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (element == "streamhost") { - if (attributes.getAttributeValue("host") && attributes.getAttributeValue("jid") && attributes.getAttributeValue("port")) { - std::string host = attributes.getAttributeValue("host").get_value_or(""); - int port = -1; - JID jid = attributes.getAttributeValue("jid").get_value_or(""); + if (element == "streamhost") { + if (attributes.getAttributeValue("host") && attributes.getAttributeValue("jid") && attributes.getAttributeValue("port")) { + std::string host = attributes.getAttributeValue("host").get_value_or(""); + int port = -1; + JID jid = attributes.getAttributeValue("jid").get_value_or(""); - try { - port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get()); - } catch (boost::bad_lexical_cast &) { - port = -1; - } - if (!host.empty() && port != -1 && jid.isValid()) { - S5BProxyRequest::StreamHost streamHost; - streamHost.host = host; - streamHost.port = port; - streamHost.jid = jid; - getPayloadInternal()->setStreamHost(streamHost); - } - } - } else if (element == "activate") { - parseActivate = true; - } else if (element == "query") { - if (attributes.getAttributeValue("sid")) { - getPayloadInternal()->setSID(attributes.getAttributeValue("sid").get()); - } - } + try { + port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get()); + } catch (boost::bad_lexical_cast &) { + port = -1; + } + if (!host.empty() && port != -1 && jid.isValid()) { + S5BProxyRequest::StreamHost streamHost; + streamHost.host = host; + streamHost.port = port; + streamHost.jid = jid; + getPayloadInternal()->setStreamHost(streamHost); + } + } + } else if (element == "activate") { + parseActivate = true; + } else if (element == "query") { + if (attributes.getAttributeValue("sid")) { + getPayloadInternal()->setSID(attributes.getAttributeValue("sid").get()); + } + } } void S5BProxyRequestParser::handleEndElement(const std::string& element, const std::string&) { - if (element == "activate") { - JID activate = JID(activateJID); - if (activate.isValid()) { - getPayloadInternal()->setActivate(activate); - } - parseActivate = false; - } + if (element == "activate") { + JID activate = JID(activateJID); + if (activate.isValid()) { + getPayloadInternal()->setActivate(activate); + } + parseActivate = false; + } } void S5BProxyRequestParser::handleCharacterData(const std::string& data) { - if (parseActivate) { - activateJID = activateJID + data; - } + if (parseActivate) { + activateJID = activateJID + data; + } } } diff --git a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h index 408bb5a..1d5fd64 100644 --- a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h +++ b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h @@ -22,16 +22,16 @@ namespace Swift { class SWIFTEN_API S5BProxyRequestParser : public GenericPayloadParser<S5BProxyRequest> { public: - S5BProxyRequestParser(); - virtual ~S5BProxyRequestParser(); + S5BProxyRequestParser(); + virtual ~S5BProxyRequestParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); private: - bool parseActivate; - std::string activateJID; + bool parseActivate; + std::string activateJID; }; } diff --git a/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp b/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp index 3e1bd55..0d79204 100644 --- a/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp @@ -1,113 +1,115 @@ /* - * 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/SearchPayloadParser.h> +#include <cassert> + #include <boost/cast.hpp> -#include <Swiften/Parser/PayloadParsers/FormParserFactory.h> #include <Swiften/Parser/PayloadParsers/FormParser.h> +#include <Swiften/Parser/PayloadParsers/FormParserFactory.h> namespace Swift { -SearchPayloadParser::SearchPayloadParser() : level(TopLevel), formParser(NULL) { - formParserFactory = new FormParserFactory(); +SearchPayloadParser::SearchPayloadParser() : level(TopLevel), formParser(nullptr) { + formParserFactory = new FormParserFactory(); } SearchPayloadParser::~SearchPayloadParser() { - delete formParserFactory; + delete formParserFactory; } void SearchPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == TopLevel) { - } - else if (level == PayloadLevel) { - if (element == "x" && ns == "jabber:x:data") { - assert(!formParser); - formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); - } - else if (element == "item") { - assert(!currentItem); - currentItem.reset(SearchPayload::Item()); - currentItem->jid = JID(attributes.getAttribute("jid")); - } - else { - currentText.clear(); - } - } - else if (level == ItemLevel && currentItem) { - currentText.clear(); - } + if (level == TopLevel) { + } + else if (level == PayloadLevel) { + if (element == "x" && ns == "jabber:x:data") { + assert(!formParser); + formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); + } + else if (element == "item") { + assert(!currentItem); + currentItem.reset(SearchPayload::Item()); + currentItem->jid = JID(attributes.getAttribute("jid")); + } + else { + currentText.clear(); + } + } + else if (level == ItemLevel && currentItem) { + currentText.clear(); + } - if (formParser) { - formParser->handleStartElement(element, ns, attributes); - } + if (formParser) { + formParser->handleStartElement(element, ns, attributes); + } - ++level; + ++level; } void SearchPayloadParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; + --level; - if (formParser) { - formParser->handleEndElement(element, ns); - } + if (formParser) { + formParser->handleEndElement(element, ns); + } - if (level == TopLevel) { - } - else if (level == PayloadLevel) { - if (formParser) { - getPayloadInternal()->setForm(formParser->getPayloadInternal()); - delete formParser; - formParser = NULL; - } - else if (element == "item") { - assert(currentItem); - getPayloadInternal()->addItem(*currentItem); - currentItem.reset(); - } - else if (element == "instructions") { - getPayloadInternal()->setInstructions(currentText); - } - else if (element == "nick") { - getPayloadInternal()->setNick(currentText); - } - else if (element == "first") { - getPayloadInternal()->setFirst(currentText); - } - else if (element == "last") { - getPayloadInternal()->setLast(currentText); - } - else if (element == "email") { - getPayloadInternal()->setEMail(currentText); - } - } - else if (level == ItemLevel && currentItem) { - if (element == "nick") { - currentItem->nick = currentText; - } - else if (element == "first") { - currentItem->first = currentText; - } - else if (element == "last") { - currentItem->last = currentText; - } - else if (element == "email") { - currentItem->email = currentText; - } - } + if (level == TopLevel) { + } + else if (level == PayloadLevel) { + if (formParser) { + getPayloadInternal()->setForm(formParser->getPayloadInternal()); + delete formParser; + formParser = nullptr; + } + else if (element == "item") { + assert(currentItem); + getPayloadInternal()->addItem(*currentItem); + currentItem.reset(); + } + else if (element == "instructions") { + getPayloadInternal()->setInstructions(currentText); + } + else if (element == "nick") { + getPayloadInternal()->setNick(currentText); + } + else if (element == "first") { + getPayloadInternal()->setFirst(currentText); + } + else if (element == "last") { + getPayloadInternal()->setLast(currentText); + } + else if (element == "email") { + getPayloadInternal()->setEMail(currentText); + } + } + else if (level == ItemLevel && currentItem) { + if (element == "nick") { + currentItem->nick = currentText; + } + else if (element == "first") { + currentItem->first = currentText; + } + else if (element == "last") { + currentItem->last = currentText; + } + else if (element == "email") { + currentItem->email = currentText; + } + } } void SearchPayloadParser::handleCharacterData(const std::string& data) { - if (formParser) { - formParser->handleCharacterData(data); - } - else { - currentText += data; - } + if (formParser) { + formParser->handleCharacterData(data); + } + else { + currentText += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/SearchPayloadParser.h b/Swiften/Parser/PayloadParsers/SearchPayloadParser.h index bfcb86d..aa0cf4a 100644 --- a/Swiften/Parser/PayloadParsers/SearchPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/SearchPayloadParser.h @@ -13,28 +13,28 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class FormParserFactory; - class FormParser; + class FormParserFactory; + class FormParser; - class SWIFTEN_API SearchPayloadParser : public GenericPayloadParser<SearchPayload> { - public: - SearchPayloadParser(); - ~SearchPayloadParser(); + class SWIFTEN_API SearchPayloadParser : public GenericPayloadParser<SearchPayload> { + public: + SearchPayloadParser(); + ~SearchPayloadParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - ItemLevel = 2 - }; - int level; - FormParserFactory* formParserFactory; - FormParser* formParser; - std::string currentText; - boost::optional<SearchPayload::Item> currentItem; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + ItemLevel = 2 + }; + int level; + FormParserFactory* formParserFactory; + FormParser* formParser; + std::string currentText; + boost::optional<SearchPayload::Item> currentItem; + }; } diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp b/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp index 22b6614..6e2319f 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp +++ b/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp @@ -1,69 +1,72 @@ /* - * 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/SecurityLabelParser.h> + +#include <cassert> + #include <Swiften/Parser/SerializingParser.h> namespace Swift { -SecurityLabelParser::SecurityLabelParser() : level_(TopLevel), labelParser_(0) { +SecurityLabelParser::SecurityLabelParser() : level_(TopLevel), labelParser_(nullptr) { } void SecurityLabelParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - ++level_; - if (level_ == DisplayMarkingOrLabelLevel) { - if (element == "displaymarking") { - currentText_ = ""; - getPayloadInternal()->setBackgroundColor(attributes.getAttribute("bgcolor")); - getPayloadInternal()->setForegroundColor(attributes.getAttribute("fgcolor")); - } - else if (element == "label" || element == "equivalentlabel") { - assert(!labelParser_); - labelParser_ = new SerializingParser(); - } - } - else if (level_ >= SecurityLabelLevel && labelParser_) { - labelParser_->handleStartElement(element, ns, attributes); - } + ++level_; + if (level_ == DisplayMarkingOrLabelLevel) { + if (element == "displaymarking") { + currentText_ = ""; + getPayloadInternal()->setBackgroundColor(attributes.getAttribute("bgcolor")); + getPayloadInternal()->setForegroundColor(attributes.getAttribute("fgcolor")); + } + else if (element == "label" || element == "equivalentlabel") { + assert(!labelParser_); + labelParser_ = new SerializingParser(); + } + } + else if (level_ >= SecurityLabelLevel && labelParser_) { + labelParser_->handleStartElement(element, ns, attributes); + } } void SecurityLabelParser::handleEndElement(const std::string& element, const std::string& ns) { - if (level_ == DisplayMarkingOrLabelLevel) { - if (element == "displaymarking") { - getPayloadInternal()->setDisplayMarking(currentText_); - } - else if (labelParser_) { - if (element == "label") { - getPayloadInternal()->setLabel(labelParser_->getResult()); - } - else { - getPayloadInternal()->addEquivalentLabel(labelParser_->getResult()); - } - delete labelParser_; - labelParser_ = 0; - } - } - else if (labelParser_ && level_ >= SecurityLabelLevel) { - labelParser_->handleEndElement(element, ns); - } - --level_; + if (level_ == DisplayMarkingOrLabelLevel) { + if (element == "displaymarking") { + getPayloadInternal()->setDisplayMarking(currentText_); + } + else if (labelParser_) { + if (element == "label") { + getPayloadInternal()->setLabel(labelParser_->getResult()); + } + else { + getPayloadInternal()->addEquivalentLabel(labelParser_->getResult()); + } + delete labelParser_; + labelParser_ = nullptr; + } + } + else if (labelParser_ && level_ >= SecurityLabelLevel) { + labelParser_->handleEndElement(element, ns); + } + --level_; } void SecurityLabelParser::handleCharacterData(const std::string& data) { - if (labelParser_) { - labelParser_->handleCharacterData(data); - } - else { - currentText_ += data; - } + if (labelParser_) { + labelParser_->handleCharacterData(data); + } + else { + currentText_ += data; + } } -boost::shared_ptr<SecurityLabel> SecurityLabelParser::getLabelPayload() const { - return getPayloadInternal(); +std::shared_ptr<SecurityLabel> SecurityLabelParser::getLabelPayload() const { + return getPayloadInternal(); } } diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelParser.h b/Swiften/Parser/PayloadParsers/SecurityLabelParser.h index 857df6a..cc444a4 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelParser.h +++ b/Swiften/Parser/PayloadParsers/SecurityLabelParser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,25 +11,25 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SerializingParser; + class SerializingParser; - class SWIFTEN_API SecurityLabelParser : public GenericPayloadParser<SecurityLabel> { - public: - SecurityLabelParser(); + class SWIFTEN_API SecurityLabelParser : public GenericPayloadParser<SecurityLabel> { + public: + SecurityLabelParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - boost::shared_ptr<SecurityLabel> getLabelPayload() const; - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - DisplayMarkingOrLabelLevel = 2, - SecurityLabelLevel = 3 - }; - int level_; - SerializingParser* labelParser_; - std::string currentText_; - }; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + std::shared_ptr<SecurityLabel> getLabelPayload() const; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + DisplayMarkingOrLabelLevel = 2, + SecurityLabelLevel = 3 + }; + int level_; + SerializingParser* labelParser_; + std::string currentText_; + }; } diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h b/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h index 1eabb07..7e6d4fd 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h +++ b/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h @@ -11,8 +11,8 @@ #include <Swiften/Parser/PayloadParsers/SecurityLabelParser.h> namespace Swift { - class SWIFTEN_API SecurityLabelParserFactory : public GenericPayloadParserFactory<SecurityLabelParser> { - public: - SecurityLabelParserFactory() : GenericPayloadParserFactory<SecurityLabelParser>("securitylabel", "urn:xmpp:sec-label:0") {} - }; + class SWIFTEN_API SecurityLabelParserFactory : public GenericPayloadParserFactory<SecurityLabelParser> { + public: + SecurityLabelParserFactory() : GenericPayloadParserFactory<SecurityLabelParser>("securitylabel", "urn:xmpp:sec-label:0") {} + }; } diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp index d5e3171..1897080 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp +++ b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp @@ -1,74 +1,76 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include <boost/smart_ptr/make_shared.hpp> - #include <Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h> -#include <Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h> + +#include <cassert> +#include <memory> + #include <Swiften/Parser/PayloadParsers/SecurityLabelParser.h> +#include <Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h> namespace Swift { -SecurityLabelsCatalogParser::SecurityLabelsCatalogParser() : level_(TopLevel), labelParser_(0) { - labelParserFactory_ = new SecurityLabelParserFactory(); +SecurityLabelsCatalogParser::SecurityLabelsCatalogParser() : level_(TopLevel), labelParser_(nullptr) { + labelParserFactory_ = new SecurityLabelParserFactory(); } SecurityLabelsCatalogParser::~SecurityLabelsCatalogParser() { - delete labelParserFactory_; + delete labelParserFactory_; } void SecurityLabelsCatalogParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - ++level_; - if (level_ == PayloadLevel) { - getPayloadInternal()->setTo(JID(attributes.getAttribute("to"))); - getPayloadInternal()->setName(attributes.getAttribute("name")); - getPayloadInternal()->setDescription(attributes.getAttribute("desc")); - } - else if (level_ == ItemLevel && element == "item" && ns == "urn:xmpp:sec-label:catalog:2") { - currentItem_ = boost::make_shared<SecurityLabelsCatalog::Item>(); - currentItem_->setSelector(attributes.getAttribute("selector")); - currentItem_->setIsDefault(attributes.getBoolAttribute("default", false)); - } - else if (level_ == LabelLevel) { - assert(!labelParser_); - if (labelParserFactory_->canParse(element, ns, attributes)) { - labelParser_ = dynamic_cast<SecurityLabelParser*>(labelParserFactory_->createPayloadParser()); - assert(labelParser_); - } - } + ++level_; + if (level_ == PayloadLevel) { + getPayloadInternal()->setTo(JID(attributes.getAttribute("to"))); + getPayloadInternal()->setName(attributes.getAttribute("name")); + getPayloadInternal()->setDescription(attributes.getAttribute("desc")); + } + else if (level_ == ItemLevel && element == "item" && ns == "urn:xmpp:sec-label:catalog:2") { + currentItem_ = std::make_shared<SecurityLabelsCatalog::Item>(); + currentItem_->setSelector(attributes.getAttribute("selector")); + currentItem_->setIsDefault(attributes.getBoolAttribute("default", false)); + } + else if (level_ == LabelLevel) { + assert(!labelParser_); + if (labelParserFactory_->canParse(element, ns, attributes)) { + labelParser_ = dynamic_cast<SecurityLabelParser*>(labelParserFactory_->createPayloadParser()); + assert(labelParser_); + } + } - if (labelParser_) { - labelParser_->handleStartElement(element, ns, attributes); - } + if (labelParser_) { + labelParser_->handleStartElement(element, ns, attributes); + } } void SecurityLabelsCatalogParser::handleEndElement(const std::string& element, const std::string& ns) { - if (labelParser_) { - labelParser_->handleEndElement(element, ns); - } - if (level_ == LabelLevel && labelParser_ && currentItem_) { - boost::shared_ptr<SecurityLabel> currentLabel = labelParser_->getLabelPayload(); - assert(currentLabel); - currentItem_->setLabel(currentLabel); - delete labelParser_; - labelParser_ = 0; - } - else if (level_ == ItemLevel && element == "item" && ns == "urn:xmpp:sec-label:catalog:2") { - if (currentItem_) { - getPayloadInternal()->addItem(SecurityLabelsCatalog::Item(*currentItem_)); - currentItem_.reset(); - } - } - --level_; + if (labelParser_) { + labelParser_->handleEndElement(element, ns); + } + if (level_ == LabelLevel && labelParser_ && currentItem_) { + std::shared_ptr<SecurityLabel> currentLabel = labelParser_->getLabelPayload(); + assert(currentLabel); + currentItem_->setLabel(currentLabel); + delete labelParser_; + labelParser_ = nullptr; + } + else if (level_ == ItemLevel && element == "item" && ns == "urn:xmpp:sec-label:catalog:2") { + if (currentItem_) { + getPayloadInternal()->addItem(SecurityLabelsCatalog::Item(*currentItem_)); + currentItem_.reset(); + } + } + --level_; } void SecurityLabelsCatalogParser::handleCharacterData(const std::string& data) { - if (labelParser_) { - labelParser_->handleCharacterData(data); - } + if (labelParser_) { + labelParser_->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h index 689ebb8..edfa86b 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h +++ b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,28 +11,28 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SecurityLabelParserFactory; - class SecurityLabelParser; + class SecurityLabelParserFactory; + class SecurityLabelParser; - class SWIFTEN_API SecurityLabelsCatalogParser : public GenericPayloadParser<SecurityLabelsCatalog> { - public: - SecurityLabelsCatalogParser(); - ~SecurityLabelsCatalogParser(); + class SWIFTEN_API SecurityLabelsCatalogParser : public GenericPayloadParser<SecurityLabelsCatalog> { + public: + SecurityLabelsCatalogParser(); + ~SecurityLabelsCatalogParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - ItemLevel = 2, - LabelLevel = 3 - }; - int level_; - SecurityLabelParserFactory* labelParserFactory_; - SecurityLabelParser* labelParser_; - boost::shared_ptr<SecurityLabelsCatalog::Item> currentItem_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + ItemLevel = 2, + LabelLevel = 3 + }; + int level_; + SecurityLabelParserFactory* labelParserFactory_; + SecurityLabelParser* labelParser_; + std::shared_ptr<SecurityLabelsCatalog::Item> currentItem_; + }; } diff --git a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp index c0122fa..56b62c8 100644 --- a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp +++ b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp @@ -12,27 +12,27 @@ SoftwareVersionParser::SoftwareVersionParser() : level_(TopLevel) { } void SoftwareVersionParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level_; + ++level_; } void SoftwareVersionParser::handleEndElement(const std::string& element, const std::string&) { - --level_; - if (level_ == PayloadLevel) { - if (element == "name") { - getPayloadInternal()->setName(currentText_); - } - else if (element == "version") { - getPayloadInternal()->setVersion(currentText_); - } - else if (element == "os") { - getPayloadInternal()->setOS(currentText_); - } - currentText_ = ""; - } + --level_; + if (level_ == PayloadLevel) { + if (element == "name") { + getPayloadInternal()->setName(currentText_); + } + else if (element == "version") { + getPayloadInternal()->setVersion(currentText_); + } + else if (element == "os") { + getPayloadInternal()->setOS(currentText_); + } + currentText_ = ""; + } } void SoftwareVersionParser::handleCharacterData(const std::string& data) { - currentText_ += data; + currentText_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h index a66dd1a..29f700c 100644 --- a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h +++ b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h @@ -11,20 +11,20 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API SoftwareVersionParser : public GenericPayloadParser<SoftwareVersion> { - public: - SoftwareVersionParser(); + class SWIFTEN_API SoftwareVersionParser : public GenericPayloadParser<SoftwareVersion> { + public: + SoftwareVersionParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - int level_; - std::string currentText_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + int level_; + std::string currentText_; + }; } diff --git a/Swiften/Parser/PayloadParsers/StartSessionParser.h b/Swiften/Parser/PayloadParsers/StartSessionParser.h index d5a9c2e..e0013af 100644 --- a/Swiften/Parser/PayloadParsers/StartSessionParser.h +++ b/Swiften/Parser/PayloadParsers/StartSessionParser.h @@ -11,12 +11,12 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API StartSessionParser : public GenericPayloadParser<StartSession> { - public: - StartSessionParser() {} + class SWIFTEN_API StartSessionParser : public GenericPayloadParser<StartSession> { + public: + StartSessionParser() {} - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) {} - virtual void handleEndElement(const std::string&, const std::string&) {} - virtual void handleCharacterData(const std::string&) {} - }; + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) {} + virtual void handleEndElement(const std::string&, const std::string&) {} + virtual void handleCharacterData(const std::string&) {} + }; } diff --git a/Swiften/Parser/PayloadParsers/StatusParser.cpp b/Swiften/Parser/PayloadParsers/StatusParser.cpp index a8b49f4..128a675 100644 --- a/Swiften/Parser/PayloadParsers/StatusParser.cpp +++ b/Swiften/Parser/PayloadParsers/StatusParser.cpp @@ -12,18 +12,18 @@ StatusParser::StatusParser() : level_(0) { } void StatusParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level_; + ++level_; } void StatusParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 0) { - getPayloadInternal()->setText(text_); - } + --level_; + if (level_ == 0) { + getPayloadInternal()->setText(text_); + } } void StatusParser::handleCharacterData(const std::string& data) { - text_ += data; + text_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/StatusParser.h b/Swiften/Parser/PayloadParsers/StatusParser.h index 689897b..cebf0cd 100644 --- a/Swiften/Parser/PayloadParsers/StatusParser.h +++ b/Swiften/Parser/PayloadParsers/StatusParser.h @@ -11,16 +11,16 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API StatusParser : public GenericPayloadParser<Status> { - public: - StatusParser(); + class SWIFTEN_API StatusParser : public GenericPayloadParser<Status> { + public: + StatusParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - std::string text_; - }; + private: + int level_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/StatusShowParser.cpp b/Swiften/Parser/PayloadParsers/StatusShowParser.cpp index 5fac74c..761a411 100644 --- a/Swiften/Parser/PayloadParsers/StatusShowParser.cpp +++ b/Swiften/Parser/PayloadParsers/StatusShowParser.cpp @@ -12,32 +12,32 @@ StatusShowParser::StatusShowParser() : level_(0) { } void StatusShowParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level_; + ++level_; } void StatusShowParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 0) { - if (text_ == "away") { - getPayloadInternal()->setType(StatusShow::Away); - } - else if (text_ == "chat") { - getPayloadInternal()->setType(StatusShow::FFC); - } - else if (text_ == "xa") { - getPayloadInternal()->setType(StatusShow::XA); - } - else if (text_ == "dnd") { - getPayloadInternal()->setType(StatusShow::DND); - } - else { - getPayloadInternal()->setType(StatusShow::Online); - } - } + --level_; + if (level_ == 0) { + if (text_ == "away") { + getPayloadInternal()->setType(StatusShow::Away); + } + else if (text_ == "chat") { + getPayloadInternal()->setType(StatusShow::FFC); + } + else if (text_ == "xa") { + getPayloadInternal()->setType(StatusShow::XA); + } + else if (text_ == "dnd") { + getPayloadInternal()->setType(StatusShow::DND); + } + else { + getPayloadInternal()->setType(StatusShow::Online); + } + } } void StatusShowParser::handleCharacterData(const std::string& data) { - text_ += data; + text_ += data; } } diff --git a/Swiften/Parser/PayloadParsers/StatusShowParser.h b/Swiften/Parser/PayloadParsers/StatusShowParser.h index 2bdcd56..8cbb365 100644 --- a/Swiften/Parser/PayloadParsers/StatusShowParser.h +++ b/Swiften/Parser/PayloadParsers/StatusShowParser.h @@ -11,16 +11,16 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API StatusShowParser : public GenericPayloadParser<StatusShow> { - public: - StatusShowParser(); + class SWIFTEN_API StatusShowParser : public GenericPayloadParser<StatusShow> { + public: + StatusShowParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - std::string text_; - }; + private: + int level_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/StorageParser.cpp b/Swiften/Parser/PayloadParsers/StorageParser.cpp index 1a131a9..9628ea8 100644 --- a/Swiften/Parser/PayloadParsers/StorageParser.cpp +++ b/Swiften/Parser/PayloadParsers/StorageParser.cpp @@ -14,53 +14,53 @@ StorageParser::StorageParser() : level(TopLevel) { } void StorageParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level == BookmarkLevel) { - if (element == "conference") { - assert(!room); - room = Storage::Room(); - room->autoJoin = attributes.getBoolAttribute("autojoin", false); - room->jid = JID(attributes.getAttribute("jid")); - room->name = attributes.getAttribute("name"); - } - else if (element == "url") { - assert(!url); - url = Storage::URL(); - url->name = attributes.getAttribute("name"); - url->url = attributes.getAttribute("url"); - } - } - else if (level == DetailLevel) { - currentText = ""; - } - ++level; + if (level == BookmarkLevel) { + if (element == "conference") { + assert(!room); + room = Storage::Room(); + room->autoJoin = attributes.getBoolAttribute("autojoin", false); + room->jid = JID(attributes.getAttribute("jid")); + room->name = attributes.getAttribute("name"); + } + else if (element == "url") { + assert(!url); + url = Storage::URL(); + url->name = attributes.getAttribute("name"); + url->url = attributes.getAttribute("url"); + } + } + else if (level == DetailLevel) { + currentText = ""; + } + ++level; } void StorageParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (level == BookmarkLevel) { - if (element == "conference") { - assert(room); - getPayloadInternal()->addRoom(*room); - room.reset(); - } - else if (element == "url") { - assert(url); - getPayloadInternal()->addURL(*url); - url.reset(); - } - } - else if (level == DetailLevel && room) { - if (element == "nick") { - room->nick = currentText; - } - else if (element == "password") { - room->password = currentText; - } - } + --level; + if (level == BookmarkLevel) { + if (element == "conference") { + assert(room); + getPayloadInternal()->addRoom(*room); + room.reset(); + } + else if (element == "url") { + assert(url); + getPayloadInternal()->addURL(*url); + url.reset(); + } + } + else if (level == DetailLevel && room) { + if (element == "nick") { + room->nick = currentText; + } + else if (element == "password") { + room->password = currentText; + } + } } void StorageParser::handleCharacterData(const std::string& data) { - currentText += data; + currentText += data; } } diff --git a/Swiften/Parser/PayloadParsers/StorageParser.h b/Swiften/Parser/PayloadParsers/StorageParser.h index 0fea4c9..92417c2 100644 --- a/Swiften/Parser/PayloadParsers/StorageParser.h +++ b/Swiften/Parser/PayloadParsers/StorageParser.h @@ -13,23 +13,23 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API StorageParser : public GenericPayloadParser<Storage> { - public: - StorageParser(); + class SWIFTEN_API StorageParser : public GenericPayloadParser<Storage> { + public: + StorageParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - BookmarkLevel = 1, - DetailLevel = 2 - }; - int level; - std::string currentText; - boost::optional<Storage::Room> room; - boost::optional<Storage::URL> url; - }; + private: + enum Level { + TopLevel = 0, + BookmarkLevel = 1, + DetailLevel = 2 + }; + int level; + std::string currentText; + boost::optional<Storage::Room> room; + boost::optional<Storage::URL> url; + }; } diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp index b3888d6..ab5dbbe 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp @@ -5,15 +5,15 @@ */ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h> -#include <boost/optional.hpp> #include <boost/lexical_cast.hpp> +#include <boost/optional.hpp> #include <Swiften/Base/DateTime.h> #include <Swiften/Base/Log.h> @@ -21,55 +21,55 @@ namespace Swift { StreamInitiationFileInfoParser::StreamInitiationFileInfoParser() : level(0), parseDescription(false) { - + } void StreamInitiationFileInfoParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level == 0) { - getPayloadInternal()->setName(attributes.getAttributeValue("name").get_value_or("")); - getPayloadInternal()->setHash(attributes.getAttributeValue("hash").get_value_or("")); - getPayloadInternal()->setAlgo(attributes.getAttributeValue("algo").get_value_or("md5")); - try { - getPayloadInternal()->setSize(boost::lexical_cast<boost::uintmax_t>(attributes.getAttributeValue("size").get_value_or("0"))); - } catch (boost::bad_lexical_cast &) { - getPayloadInternal()->setSize(0); - } - getPayloadInternal()->setDate(stringToDateTime(attributes.getAttributeValue("date").get_value_or(""))); - } else if (level == 1) { - if (element == "desc") { - parseDescription = true; - } else { - parseDescription = false; - if (element == "range") { - boost::uintmax_t offset = 0; - try { - offset = boost::lexical_cast<boost::uintmax_t>(attributes.getAttributeValue("offset").get_value_or("0")); - } catch (boost::bad_lexical_cast &) { - offset = 0; - } - if (offset == 0) { - getPayloadInternal()->setSupportsRangeRequests(true); - } else { - getPayloadInternal()->setRangeOffset(offset); - } - } - } - } - ++level; + if (level == 0) { + getPayloadInternal()->setName(attributes.getAttributeValue("name").get_value_or("")); + getPayloadInternal()->setHash(attributes.getAttributeValue("hash").get_value_or("")); + getPayloadInternal()->setAlgo(attributes.getAttributeValue("algo").get_value_or("md5")); + try { + getPayloadInternal()->setSize(boost::lexical_cast<boost::uintmax_t>(attributes.getAttributeValue("size").get_value_or("0"))); + } catch (boost::bad_lexical_cast &) { + getPayloadInternal()->setSize(0); + } + getPayloadInternal()->setDate(stringToDateTime(attributes.getAttributeValue("date").get_value_or(""))); + } else if (level == 1) { + if (element == "desc") { + parseDescription = true; + } else { + parseDescription = false; + if (element == "range") { + boost::uintmax_t offset = 0; + try { + offset = boost::lexical_cast<boost::uintmax_t>(attributes.getAttributeValue("offset").get_value_or("0")); + } catch (boost::bad_lexical_cast &) { + offset = 0; + } + if (offset == 0) { + getPayloadInternal()->setSupportsRangeRequests(true); + } else { + getPayloadInternal()->setRangeOffset(offset); + } + } + } + } + ++level; } void StreamInitiationFileInfoParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (parseDescription && element == "desc") { - parseDescription = false; - getPayloadInternal()->setDescription(desc); - } + --level; + if (parseDescription && element == "desc") { + parseDescription = false; + getPayloadInternal()->setDescription(desc); + } } void StreamInitiationFileInfoParser::handleCharacterData(const std::string& data) { - if (parseDescription) { - desc += data; - } + if (parseDescription) { + desc += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h index 722797d..a1e386c 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h +++ b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h @@ -19,17 +19,17 @@ namespace Swift { class SWIFTEN_API StreamInitiationFileInfoParser : public GenericPayloadParser<StreamInitiationFileInfo> { - public: - StreamInitiationFileInfoParser(); - - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - - private: - int level; - bool parseDescription; - std::string desc; + public: + StreamInitiationFileInfoParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + + private: + int level; + bool parseDescription; + std::string desc; }; } diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp index 32c85a3..ad66b3f 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp +++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -9,112 +9,112 @@ #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(0), inFile(false), inFeature(false) { - formParserFactory = new FormParserFactory(); +StreamInitiationParser::StreamInitiationParser() : level(TopLevel), formParser(nullptr), inFile(false), inFeature(false) { + formParserFactory = new FormParserFactory(); } StreamInitiationParser::~StreamInitiationParser() { - delete formParserFactory; + 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&) { - } - } - else if (element == "feature" && ns == FEATURE_NEG_NS) { - inFeature = true; - } - } - else if (level == FileOrFeatureLevel) { - if (inFile && element == "desc") { - currentText.clear(); - } - else if (inFeature && formParserFactory->canParse(element, ns, attributes)) { - assert(!formParser); - formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); - } - } + 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&) { + } + } + else if (element == "feature" && ns == FEATURE_NEG_NS) { + inFeature = true; + } + } + else if (level == FileOrFeatureLevel) { + if (inFile && element == "desc") { + currentText.clear(); + } + else if (inFeature && formParserFactory->canParse(element, ns, attributes)) { + assert(!formParser); + formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); + } + } - if (formParser) { - formParser->handleStartElement(element, ns, attributes); - } - ++level; + if (formParser) { + formParser->handleStartElement(element, ns, attributes); + } + ++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 = boost::dynamic_pointer_cast<FormField>(form->getField("stream-method")); - if (field) { - if (form->getType() == Form::FormType) { - foreach (const FormField::Option& 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 = NULL; - } - } + --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) { + 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; - } + if (formParser) { + formParser->handleCharacterData(data); + } + else { + currentText += data; + } } diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParser.h b/Swiften/Parser/PayloadParsers/StreamInitiationParser.h index 66ce778..42de8ba 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.h +++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.h @@ -13,31 +13,31 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class FormParserFactory; - class FormParser; + class FormParserFactory; + class FormParser; - class SWIFTEN_API StreamInitiationParser : public GenericPayloadParser<StreamInitiation> { - public: - StreamInitiationParser(); - ~StreamInitiationParser(); + class SWIFTEN_API StreamInitiationParser : public GenericPayloadParser<StreamInitiation> { + public: + StreamInitiationParser(); + ~StreamInitiationParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1, - FileOrFeatureLevel = 2, - FormOrDescriptionLevel = 3 - }; - int level; - FormParserFactory* formParserFactory; - FormParser* formParser; - bool inFile; - bool inFeature; - StreamInitiationFileInfo currentFile; - std::string currentText; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1, + FileOrFeatureLevel = 2, + FormOrDescriptionLevel = 3 + }; + int level; + FormParserFactory* formParserFactory; + FormParser* formParser; + bool inFile; + bool inFeature; + StreamInitiationFileInfo currentFile; + std::string currentText; + }; } diff --git a/Swiften/Parser/PayloadParsers/SubjectParser.cpp b/Swiften/Parser/PayloadParsers/SubjectParser.cpp index 7b2d885..19a5488 100644 --- a/Swiften/Parser/PayloadParsers/SubjectParser.cpp +++ b/Swiften/Parser/PayloadParsers/SubjectParser.cpp @@ -12,20 +12,20 @@ SubjectParser::SubjectParser() : level_(0) { } void SubjectParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level_; + ++level_; } void SubjectParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 0) { - getPayloadInternal()->setText(text_); - } + --level_; + if (level_ == 0) { + getPayloadInternal()->setText(text_); + } } void SubjectParser::handleCharacterData(const std::string& data) { - if (level_ == 1) { - text_ += data; - } + if (level_ == 1) { + text_ += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/SubjectParser.h b/Swiften/Parser/PayloadParsers/SubjectParser.h index 804c50b..a400283 100644 --- a/Swiften/Parser/PayloadParsers/SubjectParser.h +++ b/Swiften/Parser/PayloadParsers/SubjectParser.h @@ -11,16 +11,16 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API SubjectParser : public GenericPayloadParser<Subject> { - public: - SubjectParser(); + class SWIFTEN_API SubjectParser : public GenericPayloadParser<Subject> { + public: + SubjectParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - std::string text_; - }; + private: + int level_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/ThreadParser.cpp b/Swiften/Parser/PayloadParsers/ThreadParser.cpp index 0d0aca8..f416d32 100644 --- a/Swiften/Parser/PayloadParsers/ThreadParser.cpp +++ b/Swiften/Parser/PayloadParsers/ThreadParser.cpp @@ -17,23 +17,23 @@ ThreadParser::~ThreadParser() { } void ThreadParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - ++level_; - if (element == "thread") { - getPayloadInternal()->setParent(attributes.getAttributeValue("parent").get_value_or("")); - } + ++level_; + if (element == "thread") { + getPayloadInternal()->setParent(attributes.getAttributeValue("parent").get_value_or("")); + } } void ThreadParser::handleEndElement(const std::string&, const std::string&) { - --level_; - if (level_ == 0) { - getPayloadInternal()->setText(text_); - } + --level_; + if (level_ == 0) { + getPayloadInternal()->setText(text_); + } } void ThreadParser::handleCharacterData(const std::string& data) { - if (level_ == 1) { - text_ += data; - } + if (level_ == 1) { + text_ += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/ThreadParser.h b/Swiften/Parser/PayloadParsers/ThreadParser.h index 270ea99..371c535 100644 --- a/Swiften/Parser/PayloadParsers/ThreadParser.h +++ b/Swiften/Parser/PayloadParsers/ThreadParser.h @@ -11,17 +11,17 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API ThreadParser : public GenericPayloadParser<Thread> { - public: - ThreadParser(); - virtual ~ThreadParser(); + class SWIFTEN_API ThreadParser : public GenericPayloadParser<Thread> { + public: + ThreadParser(); + virtual ~ThreadParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - int level_; - std::string text_; - }; + private: + int level_; + std::string text_; + }; } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp index ddd3a88..17a800e 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp @@ -4,69 +4,74 @@ * 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 <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Parser/PayloadParsers/BlockParser.h> -#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> - +#include <Swiften/Elements/BlockListPayload.h> #include <Swiften/Elements/BlockPayload.h> #include <Swiften/Elements/UnblockPayload.h> -#include <Swiften/Elements/BlockListPayload.h> +#include <Swiften/Parser/PayloadParsers/BlockParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; class BlockParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(BlockParserTest); - CPPUNIT_TEST(testExample4); - CPPUNIT_TEST(testExample6); - CPPUNIT_TEST(testExample10); - CPPUNIT_TEST_SUITE_END(); - - public: - BlockParserTest() {} - - void testExample4() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<blocklist xmlns='urn:xmpp:blocking'>" - "<item jid='romeo@montague.net'/>" - "<item jid='iago@shakespeare.lit'/>" - "</blocklist>")); - - BlockListPayload* payload = dynamic_cast<BlockListPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(2 == payload->getItems().size()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]); - CPPUNIT_ASSERT_EQUAL(JID("iago@shakespeare.lit"), payload->getItems()[1]); - } - - void testExample6() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<block xmlns='urn:xmpp:blocking'>" - "<item jid='romeo@montague.net'/>" - "</block>")); - - BlockPayload* payload = dynamic_cast<BlockPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(1 == payload->getItems().size()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]); - } - - void testExample10() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<unblock xmlns='urn:xmpp:blocking'>" - "<item jid='romeo@montague.net'/>" - "</unblock>")); - - UnblockPayload* payload = dynamic_cast<UnblockPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(1 == payload->getItems().size()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]); - } + CPPUNIT_TEST_SUITE(BlockParserTest); + CPPUNIT_TEST(testExample4); + CPPUNIT_TEST(testExample6); + CPPUNIT_TEST(testExample10); + CPPUNIT_TEST_SUITE_END(); + + public: + BlockParserTest() {} + + void testExample4() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<blocklist xmlns='urn:xmpp:blocking'>" + "<item jid='romeo@montague.net'/>" + "<item jid='iago@shakespeare.lit'/>" + "</blocklist>")); + + BlockListPayload* payload = dynamic_cast<BlockListPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(2 == payload->getItems().size()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]); + CPPUNIT_ASSERT_EQUAL(JID("iago@shakespeare.lit"), payload->getItems()[1]); + } + + void testExample6() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<block xmlns='urn:xmpp:blocking'>" + "<item jid='romeo@montague.net'/>" + "</block>")); + + BlockPayload* payload = dynamic_cast<BlockPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(1 == payload->getItems().size()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]); + } + + void testExample10() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<unblock xmlns='urn:xmpp:blocking'>" + "<item jid='romeo@montague.net'/>" + "</unblock>")); + + UnblockPayload* payload = dynamic_cast<UnblockPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(1 == payload->getItems().size()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(BlockParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp index b409ed4..002da16 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp @@ -14,21 +14,21 @@ using namespace Swift; class BodyParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(BodyParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(BodyParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); - public: - BodyParserTest() {} + public: + BodyParserTest() {} - void testParse() { - PayloadsParserTester parser; + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<body>foo<baz>bar</baz>fum</body>")); + CPPUNIT_ASSERT(parser.parse("<body>foo<baz>bar</baz>fum</body>")); - Body* payload = dynamic_cast<Body*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("foobarfum"), payload->getText()); - } + Body* payload = dynamic_cast<Body*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("foobarfum"), payload->getText()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(BodyParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/CarbonsParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/CarbonsParserTest.cpp index 6fd38bc..b5b9995 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/CarbonsParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/CarbonsParserTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,121 +7,121 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/JID/JID.h> -#include <Swiften/Elements/Message.h> -#include <Swiften/Elements/Thread.h> -#include <Swiften/Elements/CarbonsEnable.h> #include <Swiften/Elements/CarbonsDisable.h> +#include <Swiften/Elements/CarbonsEnable.h> +#include <Swiften/Elements/CarbonsPrivate.h> #include <Swiften/Elements/CarbonsReceived.h> #include <Swiften/Elements/CarbonsSent.h> -#include <Swiften/Elements/CarbonsPrivate.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/Thread.h> +#include <Swiften/JID/JID.h> #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; class CarbonsParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(CarbonsParserTest); - CPPUNIT_TEST(testParseExample3); - CPPUNIT_TEST(testParseExample6); - CPPUNIT_TEST(testParseExample12); - CPPUNIT_TEST(testParseExample14); - CPPUNIT_TEST(testParseExample15); - CPPUNIT_TEST_SUITE_END(); - - public: - CarbonsParserTest() {} - - /* - * Test parsing of example 3 in XEP-0280. - */ - void testParseExample3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<enable xmlns='urn:xmpp:carbons:2' />")); - - CarbonsEnable::ref enable = parser.getPayload<CarbonsEnable>(); - CPPUNIT_ASSERT(enable); - } - - /* - * Test parsing of example 6 in XEP-0280. - */ - void testParseExample6() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<disable xmlns='urn:xmpp:carbons:2' />")); - - CarbonsDisable::ref disable = parser.getPayload<CarbonsDisable>(); - CPPUNIT_ASSERT(disable); - } - - /* - * Test parsing of example 12 in XEP-0280. - */ - void testParseExample12() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<received xmlns='urn:xmpp:carbons:2'>" - "<forwarded xmlns='urn:xmpp:forward:0'>" - "<message xmlns='jabber:client'" - " from='juliet@capulet.example/balcony'" - " to='romeo@montague.example/garden'" - " type='chat'>" - "<body>What man art thou that, thus bescreen'd in night, so stumblest on my counsel?</body>" - "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" - "</message>" - "</forwarded>" - "</received>")); - - CarbonsReceived::ref received = parser.getPayload<CarbonsReceived>(); - CPPUNIT_ASSERT(received); - - boost::shared_ptr<Forwarded> forwarded = received->getForwarded(); - CPPUNIT_ASSERT(forwarded); - - boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(forwarded->getStanza()); - CPPUNIT_ASSERT(message); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.example/balcony"), message->getFrom()); - - boost::shared_ptr<Thread> thread = message->getPayload<Thread>(); - CPPUNIT_ASSERT(thread); - CPPUNIT_ASSERT_EQUAL(std::string("0e3141cd80894871a68e6fe6b1ec56fa"), thread->getText()); - } - - /* - * Test parsing of example 14 in XEP-0280. - */ - void testParseExample14() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<sent xmlns='urn:xmpp:carbons:2'>" - "<forwarded xmlns='urn:xmpp:forward:0'>" - "<message xmlns='jabber:client'" - " to='juliet@capulet.example/balcony'" - " from='romeo@montague.example/home'" - " type='chat'>" - "<body>Neither, fair saint, if either thee dislike.</body>" - "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" - "</message>" - "</forwarded>" - "</sent>")); - - CarbonsSent::ref sent = parser.getPayload<CarbonsSent>(); - CPPUNIT_ASSERT(sent); - - boost::shared_ptr<Forwarded> forwarded = sent->getForwarded(); - CPPUNIT_ASSERT(forwarded); - - boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(forwarded->getStanza()); - CPPUNIT_ASSERT(message); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.example/balcony"), message->getTo()); - } - - /* - * Test parsing of example 15 in XEP-0280. - */ - void testParseExample15() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<private xmlns='urn:xmpp:carbons:2'/>")); - - CPPUNIT_ASSERT(parser.getPayload<CarbonsPrivate>()); - } + CPPUNIT_TEST_SUITE(CarbonsParserTest); + CPPUNIT_TEST(testParseExample3); + CPPUNIT_TEST(testParseExample6); + CPPUNIT_TEST(testParseExample12); + CPPUNIT_TEST(testParseExample14); + CPPUNIT_TEST(testParseExample15); + CPPUNIT_TEST_SUITE_END(); + + public: + CarbonsParserTest() {} + + /* + * Test parsing of example 3 in XEP-0280. + */ + void testParseExample3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<enable xmlns='urn:xmpp:carbons:2' />")); + + CarbonsEnable::ref enable = parser.getPayload<CarbonsEnable>(); + CPPUNIT_ASSERT(enable); + } + + /* + * Test parsing of example 6 in XEP-0280. + */ + void testParseExample6() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<disable xmlns='urn:xmpp:carbons:2' />")); + + CarbonsDisable::ref disable = parser.getPayload<CarbonsDisable>(); + CPPUNIT_ASSERT(disable); + } + + /* + * Test parsing of example 12 in XEP-0280. + */ + void testParseExample12() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<received xmlns='urn:xmpp:carbons:2'>" + "<forwarded xmlns='urn:xmpp:forward:0'>" + "<message xmlns='jabber:client'" + " from='juliet@capulet.example/balcony'" + " to='romeo@montague.example/garden'" + " type='chat'>" + "<body>What man art thou that, thus bescreen'd in night, so stumblest on my counsel?</body>" + "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" + "</message>" + "</forwarded>" + "</received>")); + + CarbonsReceived::ref received = parser.getPayload<CarbonsReceived>(); + CPPUNIT_ASSERT(received); + + std::shared_ptr<Forwarded> forwarded = received->getForwarded(); + CPPUNIT_ASSERT(forwarded); + + std::shared_ptr<Message> message = std::dynamic_pointer_cast<Message>(forwarded->getStanza()); + CPPUNIT_ASSERT(message); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.example/balcony"), message->getFrom()); + + std::shared_ptr<Thread> thread = message->getPayload<Thread>(); + CPPUNIT_ASSERT(thread); + CPPUNIT_ASSERT_EQUAL(std::string("0e3141cd80894871a68e6fe6b1ec56fa"), thread->getText()); + } + + /* + * Test parsing of example 14 in XEP-0280. + */ + void testParseExample14() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<sent xmlns='urn:xmpp:carbons:2'>" + "<forwarded xmlns='urn:xmpp:forward:0'>" + "<message xmlns='jabber:client'" + " to='juliet@capulet.example/balcony'" + " from='romeo@montague.example/home'" + " type='chat'>" + "<body>Neither, fair saint, if either thee dislike.</body>" + "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" + "</message>" + "</forwarded>" + "</sent>")); + + CarbonsSent::ref sent = parser.getPayload<CarbonsSent>(); + CPPUNIT_ASSERT(sent); + + std::shared_ptr<Forwarded> forwarded = sent->getForwarded(); + CPPUNIT_ASSERT(forwarded); + + std::shared_ptr<Message> message = std::dynamic_pointer_cast<Message>(forwarded->getStanza()); + CPPUNIT_ASSERT(message); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.example/balcony"), message->getTo()); + } + + /* + * Test parsing of example 15 in XEP-0280. + */ + void testParseExample15() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<private xmlns='urn:xmpp:carbons:2'/>")); + + CPPUNIT_ASSERT(parser.getPayload<CarbonsPrivate>()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(CarbonsParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp index 56ad448..fa8d014 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.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. */ @@ -7,80 +7,80 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> #include <Swiften/Elements/Command.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; class CommandParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(CommandParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Result); - CPPUNIT_TEST(testParse_Form); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(CommandParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Result); + CPPUNIT_TEST(testParse_Form); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse() { - PayloadsParserTester parser; + public: + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<command xmlns='http://jabber.org/protocol/commands' node='list' action='prev' sessionid='myid'/>" - )); + CPPUNIT_ASSERT(parser.parse( + "<command xmlns='http://jabber.org/protocol/commands' node='list' action='prev' sessionid='myid'/>" + )); - Command::ref payload = parser.getPayload<Command>(); - CPPUNIT_ASSERT_EQUAL(Command::Prev, payload->getAction()); - CPPUNIT_ASSERT_EQUAL(std::string("list"), payload->getNode()); - CPPUNIT_ASSERT_EQUAL(std::string("myid"), payload->getSessionID()); - } + Command::ref payload = parser.getPayload<Command>(); + CPPUNIT_ASSERT_EQUAL(Command::Prev, payload->getAction()); + CPPUNIT_ASSERT_EQUAL(std::string("list"), payload->getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("myid"), payload->getSessionID()); + } - void testParse_Result() { - PayloadsParserTester parser; + void testParse_Result() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<command xmlns='http://jabber.org/protocol/commands' node='config' status='completed' sessionid='myid'>" - "<note type='warn'>Service 'httpd' has been configured.</note>" - "<note type='error'>I lied.</note>" - "<actions execute='next'>" - "<prev/>" - "<next/>" - "</actions>" - "</command>" - )); + CPPUNIT_ASSERT(parser.parse( + "<command xmlns='http://jabber.org/protocol/commands' node='config' status='completed' sessionid='myid'>" + "<note type='warn'>Service 'httpd' has been configured.</note>" + "<note type='error'>I lied.</note>" + "<actions execute='next'>" + "<prev/>" + "<next/>" + "</actions>" + "</command>" + )); - Command::ref payload = parser.getPayload<Command>(); - CPPUNIT_ASSERT_EQUAL(Command::Completed, payload->getStatus()); - std::vector<Command::Note> notes = payload->getNotes(); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(notes.size())); - CPPUNIT_ASSERT_EQUAL(Command::Note::Warn, notes[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("Service 'httpd' has been configured."), notes[0].note); - CPPUNIT_ASSERT_EQUAL(Command::Note::Error, notes[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("I lied."), notes[1].note); - std::vector<Command::Action> actions = payload->getAvailableActions(); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(actions.size())); - CPPUNIT_ASSERT_EQUAL(Command::Prev, actions[0]); - CPPUNIT_ASSERT_EQUAL(Command::Next, actions[1]); - CPPUNIT_ASSERT_EQUAL(Command::Next, payload->getExecuteAction()); - } + Command::ref payload = parser.getPayload<Command>(); + CPPUNIT_ASSERT_EQUAL(Command::Completed, payload->getStatus()); + std::vector<Command::Note> notes = payload->getNotes(); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(notes.size())); + CPPUNIT_ASSERT_EQUAL(Command::Note::Warn, notes[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("Service 'httpd' has been configured."), notes[0].note); + CPPUNIT_ASSERT_EQUAL(Command::Note::Error, notes[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("I lied."), notes[1].note); + std::vector<Command::Action> actions = payload->getAvailableActions(); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(actions.size())); + CPPUNIT_ASSERT_EQUAL(Command::Prev, actions[0]); + CPPUNIT_ASSERT_EQUAL(Command::Next, actions[1]); + CPPUNIT_ASSERT_EQUAL(Command::Next, payload->getExecuteAction()); + } - void testParse_Form() { - PayloadsParserTester parser; + void testParse_Form() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<command xmlns='http://jabber.org/protocol/commands' node='config' status='completed'>" - "<x type=\"result\" xmlns=\"jabber:x:data\">" - "<title>Bot Configuration</title>" - "<instructions>Hello!</instructions>" - "<instructions>Fill out this form to configure your new bot!</instructions>" - "</x>" - "</command>" - )); + CPPUNIT_ASSERT(parser.parse( + "<command xmlns='http://jabber.org/protocol/commands' node='config' status='completed'>" + "<x type=\"result\" xmlns=\"jabber:x:data\">" + "<title>Bot Configuration</title>" + "<instructions>Hello!</instructions>" + "<instructions>Fill out this form to configure your new bot!</instructions>" + "</x>" + "</command>" + )); - Command::ref payload = parser.getPayload<Command>(); - Form::ref form = payload->getForm(); - CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), form->getTitle()); - CPPUNIT_ASSERT_EQUAL(std::string("Hello!\nFill out this form to configure your new bot!"), form->getInstructions()); - CPPUNIT_ASSERT_EQUAL(Form::ResultType, form->getType()); - } + Command::ref payload = parser.getPayload<Command>(); + Form::ref form = payload->getForm(); + CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), form->getTitle()); + CPPUNIT_ASSERT_EQUAL(std::string("Hello!\nFill out this form to configure your new bot!"), form->getInstructions()); + CPPUNIT_ASSERT_EQUAL(Form::ResultType, form->getType()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(CommandParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp index 919c342..d93fd1f 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp @@ -4,6 +4,12 @@ * See http://www.opensource.org/licenses/bsd-license.php for more information. */ +/* + * Copyright (c) 2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> @@ -15,29 +21,29 @@ using namespace Swift; class DeliveryReceiptParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(DeliveryReceiptParserTest); - CPPUNIT_TEST(testParseXEP0184Example3); - CPPUNIT_TEST(testParseXEP0184Example4); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(DeliveryReceiptParserTest); + CPPUNIT_TEST(testParseXEP0184Example3); + CPPUNIT_TEST(testParseXEP0184Example4); + CPPUNIT_TEST_SUITE_END(); - public: - void testParseXEP0184Example3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<request xmlns='urn:xmpp:receipts'/>")); + public: + void testParseXEP0184Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<request xmlns='urn:xmpp:receipts'/>")); - DeliveryReceiptRequest::ref request = boost::dynamic_pointer_cast<DeliveryReceiptRequest>(parser.getPayload()); + DeliveryReceiptRequest::ref request = std::dynamic_pointer_cast<DeliveryReceiptRequest>(parser.getPayload()); - CPPUNIT_ASSERT(request); - } + CPPUNIT_ASSERT(request); + } - void testParseXEP0184Example4() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<received xmlns='urn:xmpp:receipts' id='richard2-4.1.247'/>")); + void testParseXEP0184Example4() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<received xmlns='urn:xmpp:receipts' id='richard2-4.1.247'/>")); - DeliveryReceipt::ref receipt = boost::dynamic_pointer_cast<DeliveryReceipt>(parser.getPayload()); + DeliveryReceipt::ref receipt = std::dynamic_pointer_cast<DeliveryReceipt>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(std::string("richard2-4.1.247"), receipt->getReceivedID()); - } + CPPUNIT_ASSERT_EQUAL(std::string("richard2-4.1.247"), receipt->getReceivedID()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(DeliveryReceiptParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp index 35995c9..6e866fc 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.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. */ @@ -13,91 +13,91 @@ using namespace Swift; class DiscoInfoParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(DiscoInfoParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Node); - CPPUNIT_TEST(testParse_Form); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(DiscoInfoParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Node); + CPPUNIT_TEST(testParse_Form); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse() { - PayloadsParserTester parser; + public: + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"http://jabber.org/protocol/disco#info\">" - "<identity name=\"Swift\" category=\"client\" type=\"pc\" xml:lang=\"en\"/>" - "<identity name=\"Vlug\" category=\"client\" type=\"pc\" xml:lang=\"nl\"/>" - "<feature var=\"foo-feature\"/>" - "<feature var=\"bar-feature\"/>" - "<feature var=\"baz-feature\"/>" - "</query>")); + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"http://jabber.org/protocol/disco#info\">" + "<identity name=\"Swift\" category=\"client\" type=\"pc\" xml:lang=\"en\"/>" + "<identity name=\"Vlug\" category=\"client\" type=\"pc\" xml:lang=\"nl\"/>" + "<feature var=\"foo-feature\"/>" + "<feature var=\"bar-feature\"/>" + "<feature var=\"baz-feature\"/>" + "</query>")); - DiscoInfo::ref payload = boost::dynamic_pointer_cast<DiscoInfo>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getIdentities().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Swift"), payload->getIdentities()[0].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[0].getType()); - CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[0].getCategory()); - CPPUNIT_ASSERT_EQUAL(std::string("en"), payload->getIdentities()[0].getLanguage()); - CPPUNIT_ASSERT_EQUAL(std::string("Vlug"), payload->getIdentities()[1].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[1].getType()); - CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[1].getCategory()); - CPPUNIT_ASSERT_EQUAL(std::string("nl"), payload->getIdentities()[1].getLanguage()); - CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(payload->getFeatures().size())); - CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); - CPPUNIT_ASSERT_EQUAL(std::string("baz-feature"), payload->getFeatures()[2]); - CPPUNIT_ASSERT(payload->getNode().empty()); - } + DiscoInfo::ref payload = std::dynamic_pointer_cast<DiscoInfo>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getIdentities().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Swift"), payload->getIdentities()[0].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[0].getType()); + CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[0].getCategory()); + CPPUNIT_ASSERT_EQUAL(std::string("en"), payload->getIdentities()[0].getLanguage()); + CPPUNIT_ASSERT_EQUAL(std::string("Vlug"), payload->getIdentities()[1].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[1].getType()); + CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[1].getCategory()); + CPPUNIT_ASSERT_EQUAL(std::string("nl"), payload->getIdentities()[1].getLanguage()); + CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(payload->getFeatures().size())); + CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); + CPPUNIT_ASSERT_EQUAL(std::string("baz-feature"), payload->getFeatures()[2]); + CPPUNIT_ASSERT(payload->getNode().empty()); + } - void testParse_Node() { - PayloadsParserTester parser; + void testParse_Node() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"http://jabber.org/protocol/disco#info\" node=\"blahblah\">" - "<identity name=\"Swift\" category=\"client\" type=\"pc\" xml:lang=\"en\"/>" - "<identity name=\"Vlug\" category=\"client\" type=\"pc\" xml:lang=\"nl\"/>" - "<feature var=\"foo-feature\"/>" - "<feature var=\"bar-feature\"/>" - "<feature var=\"baz-feature\"/>" - "</query>")); + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"http://jabber.org/protocol/disco#info\" node=\"blahblah\">" + "<identity name=\"Swift\" category=\"client\" type=\"pc\" xml:lang=\"en\"/>" + "<identity name=\"Vlug\" category=\"client\" type=\"pc\" xml:lang=\"nl\"/>" + "<feature var=\"foo-feature\"/>" + "<feature var=\"bar-feature\"/>" + "<feature var=\"baz-feature\"/>" + "</query>")); - DiscoInfo::ref payload = boost::dynamic_pointer_cast<DiscoInfo>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getIdentities().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Swift"), payload->getIdentities()[0].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[0].getType()); - CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[0].getCategory()); - CPPUNIT_ASSERT_EQUAL(std::string("en"), payload->getIdentities()[0].getLanguage()); - CPPUNIT_ASSERT_EQUAL(std::string("Vlug"), payload->getIdentities()[1].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[1].getType()); - CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[1].getCategory()); - CPPUNIT_ASSERT_EQUAL(std::string("nl"), payload->getIdentities()[1].getLanguage()); - CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(payload->getFeatures().size())); - CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); - CPPUNIT_ASSERT_EQUAL(std::string("baz-feature"), payload->getFeatures()[2]); - CPPUNIT_ASSERT_EQUAL(std::string("blahblah"), payload->getNode()); - } + DiscoInfo::ref payload = std::dynamic_pointer_cast<DiscoInfo>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getIdentities().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Swift"), payload->getIdentities()[0].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[0].getType()); + CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[0].getCategory()); + CPPUNIT_ASSERT_EQUAL(std::string("en"), payload->getIdentities()[0].getLanguage()); + CPPUNIT_ASSERT_EQUAL(std::string("Vlug"), payload->getIdentities()[1].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[1].getType()); + CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[1].getCategory()); + CPPUNIT_ASSERT_EQUAL(std::string("nl"), payload->getIdentities()[1].getLanguage()); + CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(payload->getFeatures().size())); + CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); + CPPUNIT_ASSERT_EQUAL(std::string("baz-feature"), payload->getFeatures()[2]); + CPPUNIT_ASSERT_EQUAL(std::string("blahblah"), payload->getNode()); + } - void testParse_Form() { - PayloadsParserTester parser; + void testParse_Form() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"http://jabber.org/protocol/disco#info\">" - "<feature var=\"foo-feature\"/>" - "<x type=\"submit\" xmlns=\"jabber:x:data\">" - "<title>Bot Configuration</title>" - "<instructions>Hello!</instructions>" - "</x>" - "<feature var=\"bar-feature\"/>" - "</query>")); + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"http://jabber.org/protocol/disco#info\">" + "<feature var=\"foo-feature\"/>" + "<x type=\"submit\" xmlns=\"jabber:x:data\">" + "<title>Bot Configuration</title>" + "<instructions>Hello!</instructions>" + "</x>" + "<feature var=\"bar-feature\"/>" + "</query>")); - DiscoInfo::ref payload = boost::dynamic_pointer_cast<DiscoInfo>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getExtensions().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), payload->getExtensions()[0]->getTitle()); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getFeatures().size())); - CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); - } + DiscoInfo::ref payload = std::dynamic_pointer_cast<DiscoInfo>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getExtensions().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), payload->getExtensions()[0]->getTitle()); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getFeatures().size())); + CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(DiscoInfoParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp index ee234ad..977ef8e 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp @@ -4,6 +4,12 @@ * 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 <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> @@ -13,30 +19,30 @@ using namespace Swift; class DiscoItemsParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(DiscoItemsParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='http://jabber.org/protocol/disco#items' node='http://jabber.org/protocol/commands'>" - "<item jid='responder@domain' node='list' name='List Service Configurations'/>" - "<item jid='responder@domain' node='config' name='Configure Service'/>" - "</query>")); - - boost::shared_ptr<DiscoItems> payload = boost::dynamic_pointer_cast<DiscoItems>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getItems().size())); - CPPUNIT_ASSERT_EQUAL(std::string("List Service Configurations"), payload->getItems()[0].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("list"), payload->getItems()[0].getNode()); - CPPUNIT_ASSERT_EQUAL(std::string("responder@domain"), payload->getItems()[0].getJID().toString()); - CPPUNIT_ASSERT_EQUAL(std::string("Configure Service"), payload->getItems()[1].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("config"), payload->getItems()[1].getNode()); - CPPUNIT_ASSERT_EQUAL(std::string("responder@domain"), payload->getItems()[1].getJID().toString()); - CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/commands"), payload->getNode()); - } + CPPUNIT_TEST_SUITE(DiscoItemsParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='http://jabber.org/protocol/disco#items' node='http://jabber.org/protocol/commands'>" + "<item jid='responder@domain' node='list' name='List Service Configurations'/>" + "<item jid='responder@domain' node='config' name='Configure Service'/>" + "</query>")); + + std::shared_ptr<DiscoItems> payload = std::dynamic_pointer_cast<DiscoItems>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getItems().size())); + CPPUNIT_ASSERT_EQUAL(std::string("List Service Configurations"), payload->getItems()[0].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("list"), payload->getItems()[0].getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("responder@domain"), payload->getItems()[0].getJID().toString()); + CPPUNIT_ASSERT_EQUAL(std::string("Configure Service"), payload->getItems()[1].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("config"), payload->getItems()[1].getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("responder@domain"), payload->getItems()[1].getJID().toString()); + CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/commands"), payload->getNode()); + } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp index cbd416a..5402614 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.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. */ @@ -7,51 +7,51 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> +#include <Swiften/Elements/Delay.h> #include <Swiften/Parser/PayloadParsers/ErrorParser.h> #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> -#include <Swiften/Elements/Delay.h> using namespace Swift; class ErrorParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ErrorParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParseWithPayload); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<error type=\"modify\">" - "<bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>" - "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">boo</text>" - "</error>")); - - ErrorPayload::ref payload = boost::dynamic_pointer_cast<ErrorPayload>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, payload->getCondition()); - CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, payload->getType()); - CPPUNIT_ASSERT_EQUAL(std::string("boo"), payload->getText()); - CPPUNIT_ASSERT(!payload->getPayload()); - } - - void testParseWithPayload() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<error type=\"modify\">" - "<bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>" - "<delay xmlns='urn:xmpp:delay' from='juliet@capulet.com/balcony' stamp='2002-09-10T23:41:07Z'/>" - "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">boo</text>" - "</error>")); - - ErrorPayload::ref payload = boost::dynamic_pointer_cast<ErrorPayload>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, payload->getCondition()); - CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, payload->getType()); - CPPUNIT_ASSERT_EQUAL(std::string("boo"), payload->getText()); - CPPUNIT_ASSERT(boost::dynamic_pointer_cast<Delay>(payload->getPayload())); - } + CPPUNIT_TEST_SUITE(ErrorParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParseWithPayload); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<error type=\"modify\">" + "<bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>" + "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">boo</text>" + "</error>")); + + ErrorPayload::ref payload = std::dynamic_pointer_cast<ErrorPayload>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, payload->getCondition()); + CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, payload->getType()); + CPPUNIT_ASSERT_EQUAL(std::string("boo"), payload->getText()); + CPPUNIT_ASSERT(!payload->getPayload()); + } + + void testParseWithPayload() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<error type=\"modify\">" + "<bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>" + "<delay xmlns='urn:xmpp:delay' from='juliet@capulet.com/balcony' stamp='2002-09-10T23:41:07Z'/>" + "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">boo</text>" + "</error>")); + + ErrorPayload::ref payload = std::dynamic_pointer_cast<ErrorPayload>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, payload->getCondition()); + CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, payload->getType()); + CPPUNIT_ASSERT_EQUAL(std::string("boo"), payload->getText()); + CPPUNIT_ASSERT(std::dynamic_pointer_cast<Delay>(payload->getPayload())); + } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp index c9e685e..610c4f3 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,222 +7,225 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> #include <Swiften/Elements/Form.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; class FormParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(FormParserTest); - CPPUNIT_TEST(testParse_FormInformation); - CPPUNIT_TEST(testParse_FormLayout); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_FormItems); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse_FormInformation() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<x type=\"submit\" xmlns=\"jabber:x:data\">" - "<title>Bot Configuration</title>" - "<instructions>Hello!</instructions>" - "<instructions>Fill out this form to configure your new bot!</instructions>" - "</x>" - )); - - Form* payload = dynamic_cast<Form*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), payload->getTitle()); - CPPUNIT_ASSERT_EQUAL(std::string("Hello!\nFill out this form to configure your new bot!"), payload->getInstructions()); - CPPUNIT_ASSERT_EQUAL(Form::SubmitType, payload->getType()); - } - - void testParse_FormLayout() { - PayloadsParserTester parser; - - // P1 = page one, S1 = section one, F1 = field one, T1 = text one - CPPUNIT_ASSERT(parser.parse( - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<page label=\"P1\" xmlns=\"http://jabber.org/protocol/xdata-layout\">" - "<reportedref/>" - "<text>P1T1</text>" - "<fieldref var=\"P1F1\"/>" - "<section label=\"P1S1\">" - "<text>P1S1T1</text>" - "<fieldref var=\"P1S1F1\"/>" - "</section>" - "</page>" - "<page label=\"P2\" xmlns=\"http://jabber.org/protocol/xdata-layout\">" - "<section label=\"P2S1\">" - "<section label=\"P2S2\">" - "<section label=\"P2S3\"/>" - "</section>" - "</section>" - "</page>" - "<field label=\"field one\" type=\"text-single\" var=\"P1F1\"/>" - "<field label=\"field two\" type=\"text-single\" var=\"P1S1F1\"/>" - "</x>")); - - Form* payload = dynamic_cast<Form*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(payload->getFields().size())); - // PAGE ONE - parsing of element types - CPPUNIT_ASSERT_EQUAL(std::string("P1"), payload->getPages()[0]->getLabel()); - CPPUNIT_ASSERT(payload->getPages()[0]->getReportedRefs()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("P1T1"), payload->getPages()[0]->getTextElements()[0]->getTextString()); - CPPUNIT_ASSERT_EQUAL(std::string("P1F1"), payload->getPages()[0]->getFields()[0]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("P1S1"), payload->getPages()[0]->getChildSections()[0]->getLabel()); - CPPUNIT_ASSERT_EQUAL(std::string("P1S1T1"), payload->getPages()[0]->getChildSections()[0]->getTextElements()[0]->getTextString()); - CPPUNIT_ASSERT_EQUAL(std::string("P1S1F1"), payload->getPages()[0]->getChildSections()[0]->getFields()[0]->getName()); - // PAGE TWO - parsing of nested elements - CPPUNIT_ASSERT_EQUAL(std::string("P2"), payload->getPages()[1]->getLabel()); - CPPUNIT_ASSERT_EQUAL(std::string("P2S1"), payload->getPages()[1]->getChildSections()[0]->getLabel()); - CPPUNIT_ASSERT_EQUAL(std::string("P2S2"), payload->getPages()[1]->getChildSections()[0]->getChildSections()[0]->getLabel()); - CPPUNIT_ASSERT_EQUAL(std::string("P2S3"), payload->getPages()[1]->getChildSections()[0]->getChildSections()[0]->getChildSections()[0]->getLabel()); - } - - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<field type=\"hidden\" var=\"FORM_TYPE\">" - "<value>jabber:bot</value>" - "</field>" - "<field type=\"fixed\"><value>Section 1: Bot Info</value></field>" - "<field label=\"The name of your bot\" type=\"text-single\" var=\"botname\"/>" - "<field label=\"Helpful description of your bot\" type=\"text-multi\" var=\"description\"><value>This is a bot.</value><value>A quite good one actually</value></field>" - "<field label=\"Public bot?\" type=\"boolean\" var=\"public\">" - "<required/>" - "<value>1</value>" - "</field>" - "<field label=\"Password for special access\" type=\"text-private\" var=\"password\"/>" - "<field label=\"What features will the bot support?\" type=\"list-multi\" var=\"features\">" - "<option label=\"Contests\"><value>contests</value></option>" - "<option label=\"News\"><value>news</value></option>" - "<option label=\"Polls\"><value>polls</value></option>" - "<option label=\"Reminders\"><value>reminders</value></option>" - "<option label=\"Search\"><value>search</value></option>" - "<value>news</value>" - "<value>search</value>" - "</field>" - "<field label=\"Maximum number of subscribers\" type=\"list-single\" var=\"maxsubs\">" - "<value>20</value>" - "<option label=\"10\"><value>10</value></option>" - "<option label=\"20\"><value>20</value></option>" - "<option label=\"30\"><value>30</value></option>" - "<option label=\"50\"><value>50</value></option>" - "<option label=\"100\"><value>100</value></option>" - "<option label=\"None\"><value>none</value></option>" - "</field>" - "<field label=\"People to invite\" type=\"jid-multi\" var=\"invitelist\">" - "<desc>Tell all your friends about your new bot!</desc>" - "<value>foo@bar.com</value>" - "<value>baz@fum.org</value>" - "</field>" - "<field var=\"untyped\">" - "<value>foo</value>" - "</field>" - "</x>")); - - Form* payload = dynamic_cast<Form*>(parser.getPayload().get()); - - CPPUNIT_ASSERT_EQUAL(10, static_cast<int>(payload->getFields().size())); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:bot"), payload->getFields()[0]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("FORM_TYPE"), payload->getFields()[0]->getName()); - CPPUNIT_ASSERT(!payload->getFields()[0]->getRequired()); - - CPPUNIT_ASSERT_EQUAL(std::string("Section 1: Bot Info"), payload->getFields()[1]->getValues()[0]); - - CPPUNIT_ASSERT_EQUAL(std::string("The name of your bot"), payload->getFields()[2]->getLabel()); - - CPPUNIT_ASSERT_EQUAL(std::string("This is a bot.\nA quite good one actually"), payload->getFields()[3]->getTextMultiValue()); - - CPPUNIT_ASSERT_EQUAL(true, payload->getFields()[4]->getBoolValue()); - CPPUNIT_ASSERT(payload->getFields()[4]->getRequired()); - CPPUNIT_ASSERT_EQUAL(std::string("1"), payload->getFields()[4]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getFields()[6]->getValues().size())); - CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("search"), payload->getFields()[6]->getValues()[1]); - CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(payload->getFields()[6]->getOptions().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Contests"), payload->getFields()[6]->getOptions()[0].label); - CPPUNIT_ASSERT_EQUAL(std::string("contests"), payload->getFields()[6]->getOptions()[0].value); - CPPUNIT_ASSERT_EQUAL(std::string("News"), payload->getFields()[6]->getOptions()[1].label); - CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getOptions()[1].value); - - CPPUNIT_ASSERT_EQUAL(std::string("20"), payload->getFields()[7]->getValues()[0]); - - CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), payload->getFields()[8]->getJIDMultiValue(0)); - CPPUNIT_ASSERT_EQUAL(JID("baz@fum.org"), payload->getFields()[8]->getJIDMultiValue(1)); - CPPUNIT_ASSERT_EQUAL(std::string("Tell all your friends about your new bot!"), payload->getFields()[8]->getDescription()); - - CPPUNIT_ASSERT_EQUAL(std::string("foo"), payload->getFields()[9]->getValues()[0]); - } - - void testParse_FormItems() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<x xmlns='jabber:x:data' type='result'>" - "<field type='hidden' var='FORM_TYPE'>" - "<value>jabber:iq:search</value>" - "</field>" - "<reported>" - "<field var='first' label='Given Name' type='text-single'/>" - "<field var='last' label='Family Name' type='text-single'/>" - "<field var='jid' label='Jabber ID' type='jid-single'/>" - "<field var='x-gender' label='Gender' type='list-single'/>" - "</reported>" - "<item>" - "<field var='first'><value>Benvolio</value></field>" - "<field var='last'><value>Montague</value></field>" - "<field var='jid'><value>benvolio@montague.net</value></field>" - "<field var='x-gender'><value>male</value></field>" - "</item>" - "<item>" - "<field var='first'><value>Romeo</value></field>" - "<field var='last'><value>Montague</value></field>" - "<field var='jid'><value>romeo@montague.net</value></field>" - "<field var='x-gender'><value>male</value></field>" - "</item>" - "</x>")); - - Form* dataForm = dynamic_cast<Form*>(parser.getPayload().get()); - CPPUNIT_ASSERT(dataForm); - - Form::FormItem reported = dataForm->getReportedFields(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), reported.size()); - - std::vector<Form::FormItem> items = dataForm->getItems(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); - - Form::FormItem item = items[0]; - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); - - CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); - boost::shared_ptr<FormField> jidField = item[2]; - CPPUNIT_ASSERT_EQUAL(JID("benvolio@montague.net"), jidField->getJIDSingleValue()); - CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); - - item = items[1]; - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); - - CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); - jidField = item[2]; - CPPUNIT_ASSERT(jidField); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), jidField->getJIDSingleValue()); - CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); - } + CPPUNIT_TEST_SUITE(FormParserTest); + CPPUNIT_TEST(testParse_FormInformation); + CPPUNIT_TEST(testParse_FormLayout); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_FormItems); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse_FormInformation() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<x type=\"submit\" xmlns=\"jabber:x:data\">" + "<title>Bot Configuration</title>" + "<instructions>Hello!</instructions>" + "<instructions>Fill out this form to configure your new bot!</instructions>" + "</x>" + )); + + Form* payload = dynamic_cast<Form*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT_EQUAL(std::string("Bot Configuration"), payload->getTitle()); + CPPUNIT_ASSERT_EQUAL(std::string("Hello!\nFill out this form to configure your new bot!"), payload->getInstructions()); + CPPUNIT_ASSERT_EQUAL(Form::SubmitType, payload->getType()); + } + + void testParse_FormLayout() { + PayloadsParserTester parser; + + // P1 = page one, S1 = section one, F1 = field one, T1 = text one + CPPUNIT_ASSERT(parser.parse( + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<page label=\"P1\" xmlns=\"http://jabber.org/protocol/xdata-layout\">" + "<reportedref/>" + "<text>P1T1</text>" + "<fieldref var=\"P1F1\"/>" + "<section label=\"P1S1\">" + "<text>P1S1T1</text>" + "<fieldref var=\"P1S1F1\"/>" + "</section>" + "</page>" + "<page label=\"P2\" xmlns=\"http://jabber.org/protocol/xdata-layout\">" + "<section label=\"P2S1\">" + "<section label=\"P2S2\">" + "<section label=\"P2S3\"/>" + "</section>" + "</section>" + "</page>" + "<field label=\"field one\" type=\"text-single\" var=\"P1F1\"/>" + "<field label=\"field two\" type=\"text-single\" var=\"P1S1F1\"/>" + "</x>")); + + Form* payload = dynamic_cast<Form*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(payload->getFields().size())); + // PAGE ONE - parsing of element types + CPPUNIT_ASSERT_EQUAL(std::string("P1"), payload->getPages()[0]->getLabel()); + CPPUNIT_ASSERT(payload->getPages()[0]->getReportedRefs()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("P1T1"), payload->getPages()[0]->getTextElements()[0]->getTextString()); + CPPUNIT_ASSERT_EQUAL(std::string("P1F1"), payload->getPages()[0]->getFields()[0]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("P1S1"), payload->getPages()[0]->getChildSections()[0]->getLabel()); + CPPUNIT_ASSERT_EQUAL(std::string("P1S1T1"), payload->getPages()[0]->getChildSections()[0]->getTextElements()[0]->getTextString()); + CPPUNIT_ASSERT_EQUAL(std::string("P1S1F1"), payload->getPages()[0]->getChildSections()[0]->getFields()[0]->getName()); + // PAGE TWO - parsing of nested elements + CPPUNIT_ASSERT_EQUAL(std::string("P2"), payload->getPages()[1]->getLabel()); + CPPUNIT_ASSERT_EQUAL(std::string("P2S1"), payload->getPages()[1]->getChildSections()[0]->getLabel()); + CPPUNIT_ASSERT_EQUAL(std::string("P2S2"), payload->getPages()[1]->getChildSections()[0]->getChildSections()[0]->getLabel()); + CPPUNIT_ASSERT_EQUAL(std::string("P2S3"), payload->getPages()[1]->getChildSections()[0]->getChildSections()[0]->getChildSections()[0]->getLabel()); + } + + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<field type=\"hidden\" var=\"FORM_TYPE\">" + "<value>jabber:bot</value>" + "</field>" + "<field type=\"fixed\"><value>Section 1: Bot Info</value></field>" + "<field label=\"The name of your bot\" type=\"text-single\" var=\"botname\"/>" + "<field label=\"Helpful description of your bot\" type=\"text-multi\" var=\"description\"><value>This is a bot.</value><value>A quite good one actually</value></field>" + "<field label=\"Public bot?\" type=\"boolean\" var=\"public\">" + "<required/>" + "<value>1</value>" + "</field>" + "<field label=\"Password for special access\" type=\"text-private\" var=\"password\"/>" + "<field label=\"What features will the bot support?\" type=\"list-multi\" var=\"features\">" + "<option label=\"Contests\"><value>contests</value></option>" + "<option label=\"News\"><value>news</value></option>" + "<option label=\"Polls\"><value>polls</value></option>" + "<option label=\"Reminders\"><value>reminders</value></option>" + "<option label=\"Search\"><value>search</value></option>" + "<value>news</value>" + "<value>search</value>" + "</field>" + "<field label=\"Maximum number of subscribers\" type=\"list-single\" var=\"maxsubs\">" + "<value>20</value>" + "<option label=\"10\"><value>10</value></option>" + "<option label=\"20\"><value>20</value></option>" + "<option label=\"30\"><value>30</value></option>" + "<option label=\"50\"><value>50</value></option>" + "<option label=\"100\"><value>100</value></option>" + "<option label=\"None\"><value>none</value></option>" + "</field>" + "<field label=\"People to invite\" type=\"jid-multi\" var=\"invitelist\">" + "<desc>Tell all your friends about your new bot!</desc>" + "<value>foo@bar.com</value>" + "<value>baz@fum.org</value>" + "</field>" + "<field var=\"untyped\">" + "<value>foo</value>" + "</field>" + "</x>")); + + Form* payload = dynamic_cast<Form*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + + CPPUNIT_ASSERT_EQUAL(10, static_cast<int>(payload->getFields().size())); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:bot"), payload->getFields()[0]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("FORM_TYPE"), payload->getFields()[0]->getName()); + CPPUNIT_ASSERT(!payload->getFields()[0]->getRequired()); + + CPPUNIT_ASSERT_EQUAL(std::string("Section 1: Bot Info"), payload->getFields()[1]->getValues()[0]); + + CPPUNIT_ASSERT_EQUAL(std::string("The name of your bot"), payload->getFields()[2]->getLabel()); + + CPPUNIT_ASSERT_EQUAL(std::string("This is a bot.\nA quite good one actually"), payload->getFields()[3]->getTextMultiValue()); + + CPPUNIT_ASSERT_EQUAL(true, payload->getFields()[4]->getBoolValue()); + CPPUNIT_ASSERT(payload->getFields()[4]->getRequired()); + CPPUNIT_ASSERT_EQUAL(std::string("1"), payload->getFields()[4]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getFields()[6]->getValues().size())); + CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("search"), payload->getFields()[6]->getValues()[1]); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(payload->getFields()[6]->getOptions().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Contests"), payload->getFields()[6]->getOptions()[0].label); + CPPUNIT_ASSERT_EQUAL(std::string("contests"), payload->getFields()[6]->getOptions()[0].value); + CPPUNIT_ASSERT_EQUAL(std::string("News"), payload->getFields()[6]->getOptions()[1].label); + CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getOptions()[1].value); + + CPPUNIT_ASSERT_EQUAL(std::string("20"), payload->getFields()[7]->getValues()[0]); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), payload->getFields()[8]->getJIDMultiValue(0)); + CPPUNIT_ASSERT_EQUAL(JID("baz@fum.org"), payload->getFields()[8]->getJIDMultiValue(1)); + CPPUNIT_ASSERT_EQUAL(std::string("Tell all your friends about your new bot!"), payload->getFields()[8]->getDescription()); + + CPPUNIT_ASSERT_EQUAL(std::string("foo"), payload->getFields()[9]->getValues()[0]); + } + + void testParse_FormItems() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<x xmlns='jabber:x:data' type='result'>" + "<field type='hidden' var='FORM_TYPE'>" + "<value>jabber:iq:search</value>" + "</field>" + "<reported>" + "<field var='first' label='Given Name' type='text-single'/>" + "<field var='last' label='Family Name' type='text-single'/>" + "<field var='jid' label='Jabber ID' type='jid-single'/>" + "<field var='x-gender' label='Gender' type='list-single'/>" + "</reported>" + "<item>" + "<field var='first'><value>Benvolio</value></field>" + "<field var='last'><value>Montague</value></field>" + "<field var='jid'><value>benvolio@montague.net</value></field>" + "<field var='x-gender'><value>male</value></field>" + "</item>" + "<item>" + "<field var='first'><value>Romeo</value></field>" + "<field var='last'><value>Montague</value></field>" + "<field var='jid'><value>romeo@montague.net</value></field>" + "<field var='x-gender'><value>male</value></field>" + "</item>" + "</x>")); + + Form* dataForm = dynamic_cast<Form*>(parser.getPayload().get()); + CPPUNIT_ASSERT(dataForm); + + Form::FormItem reported = dataForm->getReportedFields(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), reported.size()); + + std::vector<Form::FormItem> items = dataForm->getItems(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); + + Form::FormItem item = items[0]; + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); + + CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); + std::shared_ptr<FormField> jidField = item[2]; + CPPUNIT_ASSERT_EQUAL(JID("benvolio@montague.net"), jidField->getJIDSingleValue()); + CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); + + item = items[1]; + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); + + CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); + jidField = item[2]; + CPPUNIT_ASSERT(jidField); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), jidField->getJIDSingleValue()); + CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(FormParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp index fae259f..a807d4e 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp @@ -19,100 +19,100 @@ using namespace Swift; class ForwardedParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ForwardedParserTest); - CPPUNIT_TEST(testParseIQ); - CPPUNIT_TEST(testParseMessage); - CPPUNIT_TEST(testParseMessageNoDelay); - CPPUNIT_TEST(testParsePresence); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParseIQ() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" - "<iq xmlns=\"jabber:client\" type=\"get\" from=\"kindanormal@example.com/IM\" to=\"stupidnewbie@example.com\" id=\"id0\"/>" - "</forwarded>")); - - boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getDelay()); - CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); - - boost::shared_ptr<IQ> iq = boost::dynamic_pointer_cast<IQ>(payload->getStanza()); - CPPUNIT_ASSERT(!!iq); - CPPUNIT_ASSERT_EQUAL(JID("stupidnewbie@example.com"), iq->getTo()); - CPPUNIT_ASSERT_EQUAL(JID("kindanormal@example.com/IM"), iq->getFrom()); - CPPUNIT_ASSERT_EQUAL(std::string("id0"), iq->getID()); - CPPUNIT_ASSERT_EQUAL(IQ::Get, iq->getType()); - } - - void testParseMessage() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" - "<message xmlns=\"jabber:client\" to=\"juliet@capulet.lit/balcony\" from=\"romeo@montague.lit/orchard\" type=\"chat\">" - "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" - "</message>" - "</forwarded>")); - - boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getDelay()); - CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); - - boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(payload->getStanza()); - CPPUNIT_ASSERT(!!message); - const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; - CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody().get()); - CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); - } - - void testParseMessageNoDelay() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<message xmlns=\"jabber:client\" to=\"juliet@capulet.lit/balcony\" from=\"romeo@montague.lit/orchard\" type=\"chat\">" - "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" - "</message>" - "</forwarded>")); - - boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(!payload->getDelay()); - - boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(payload->getStanza()); - CPPUNIT_ASSERT(!!message); - const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; - CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody().get()); - CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); - } - - void testParsePresence() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" - "<presence xmlns=\"jabber:client\" from=\"alice@wonderland.lit/rabbithole\" to=\"madhatter@wonderland.lit\" type=\"unavailable\"/>" - "</forwarded>")); - - boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getDelay()); - CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); - - boost::shared_ptr<Presence> presence = boost::dynamic_pointer_cast<Presence>(payload->getStanza()); - CPPUNIT_ASSERT(!!presence); - CPPUNIT_ASSERT_EQUAL(JID("madhatter@wonderland.lit"), presence->getTo()); - CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit/rabbithole"), presence->getFrom()); - CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, presence->getType()); - } + CPPUNIT_TEST_SUITE(ForwardedParserTest); + CPPUNIT_TEST(testParseIQ); + CPPUNIT_TEST(testParseMessage); + CPPUNIT_TEST(testParseMessageNoDelay); + CPPUNIT_TEST(testParsePresence); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParseIQ() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" + "<iq xmlns=\"jabber:client\" type=\"get\" from=\"kindanormal@example.com/IM\" to=\"stupidnewbie@example.com\" id=\"id0\"/>" + "</forwarded>")); + + std::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getDelay()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); + + std::shared_ptr<IQ> iq = std::dynamic_pointer_cast<IQ>(payload->getStanza()); + CPPUNIT_ASSERT(!!iq); + CPPUNIT_ASSERT_EQUAL(JID("stupidnewbie@example.com"), iq->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("kindanormal@example.com/IM"), iq->getFrom()); + CPPUNIT_ASSERT_EQUAL(std::string("id0"), iq->getID()); + CPPUNIT_ASSERT_EQUAL(IQ::Get, iq->getType()); + } + + void testParseMessage() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" + "<message xmlns=\"jabber:client\" to=\"juliet@capulet.lit/balcony\" from=\"romeo@montague.lit/orchard\" type=\"chat\">" + "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" + "</message>" + "</forwarded>")); + + std::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getDelay()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); + + std::shared_ptr<Message> message = std::dynamic_pointer_cast<Message>(payload->getStanza()); + CPPUNIT_ASSERT(!!message); + const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; + CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody().get()); + CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); + } + + void testParseMessageNoDelay() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<message xmlns=\"jabber:client\" to=\"juliet@capulet.lit/balcony\" from=\"romeo@montague.lit/orchard\" type=\"chat\">" + "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" + "</message>" + "</forwarded>")); + + std::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(!payload->getDelay()); + + std::shared_ptr<Message> message = std::dynamic_pointer_cast<Message>(payload->getStanza()); + CPPUNIT_ASSERT(!!message); + const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; + CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody().get()); + CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); + } + + void testParsePresence() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" + "<presence xmlns=\"jabber:client\" from=\"alice@wonderland.lit/rabbithole\" to=\"madhatter@wonderland.lit\" type=\"unavailable\"/>" + "</forwarded>")); + + std::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getDelay()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); + + std::shared_ptr<Presence> presence = std::dynamic_pointer_cast<Presence>(payload->getStanza()); + CPPUNIT_ASSERT(!!presence); + CPPUNIT_ASSERT_EQUAL(JID("madhatter@wonderland.lit"), presence->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit/rabbithole"), presence->getFrom()); + CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, presence->getType()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ForwardedParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp index 5332a61..782cb32 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp @@ -1,40 +1,39 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include <Swiften/Base/ByteArray.h> - #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Base/ByteArray.h> #include <Swiften/Elements/IBB.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; class IBBParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(IBBParserTest); - CPPUNIT_TEST(testParse_Data); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse_Data() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<data xmlns='http://jabber.org/protocol/ibb' seq='4'>\n" - "\t YWJjZGVmZ2loamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjEyMzQ1\n" - "\t Njc4OTAK\n" - "</data>" - )); - - IBB::ref ibb = parser.getPayload<IBB>(); - CPPUNIT_ASSERT(ibb->getAction() == IBB::Data); - CPPUNIT_ASSERT(createByteArray("abcdefgihjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\x0a") == ibb->getData()); - CPPUNIT_ASSERT_EQUAL(4, ibb->getSequenceNumber()); - } + CPPUNIT_TEST_SUITE(IBBParserTest); + CPPUNIT_TEST(testParse_Data); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse_Data() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<data xmlns='http://jabber.org/protocol/ibb' seq='4'>\n" + "\t YWJjZGVmZ2loamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjEyMzQ1\n" + "\t Njc4OTAK\n" + "</data>" + )); + + IBB::ref ibb = parser.getPayload<IBB>(); + CPPUNIT_ASSERT(ibb->getAction() == IBB::Data); + CPPUNIT_ASSERT(createByteArray("abcdefgihjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\x0a") == ibb->getData()); + CPPUNIT_ASSERT_EQUAL(4, ibb->getSequenceNumber()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(IBBParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp index 74da474..462247a 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp @@ -4,35 +4,41 @@ * 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 <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> -#include <Swiften/Elements/Presence.h> -#include <Swiften/Elements/Idle.h> #include <Swiften/Base/DateTime.h> +#include <Swiften/Elements/Idle.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; class IdleParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(IdleParserTest); - CPPUNIT_TEST(testParse_XepWhatever_Example1); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(IdleParserTest); + CPPUNIT_TEST(testParse_XepWhatever_Example1); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse_XepWhatever_Example1() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<presence from='juliet@capulet.com/balcony'>\n" - "<show>away</show>\n" - "<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15Z'/>\n" - "</presence>\n" - )); + public: + void testParse_XepWhatever_Example1() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<presence from='juliet@capulet.com/balcony'>\n" + "<show>away</show>\n" + "<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15Z'/>\n" + "</presence>\n" + )); - Presence::ref presence = parser.getPayload<Presence>(); - CPPUNIT_ASSERT(presence); - Idle::ref idle = presence->getPayload<Idle>(); - CPPUNIT_ASSERT(idle); - CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == idle->getSince()); - } + Presence::ref presence = parser.getPayload<Presence>(); + CPPUNIT_ASSERT(presence); + Idle::ref idle = presence->getPayload<Idle>(); + CPPUNIT_ASSERT(idle); + CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == idle->getSince()); + } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp index f9a9efd..6d08812 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp @@ -4,65 +4,71 @@ * 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 <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> +#include <Swiften/Elements/Form.h> +#include <Swiften/Elements/InBandRegistrationPayload.h> #include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h> #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> -#include <Swiften/Elements/Form.h> -#include <Swiften/Elements/InBandRegistrationPayload.h> using namespace Swift; class InBandRegistrationPayloadParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(InBandRegistrationPayloadParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Form); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(InBandRegistrationPayloadParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Form); + CPPUNIT_TEST_SUITE_END(); - public: - InBandRegistrationPayloadParserTest() {} + public: + InBandRegistrationPayloadParserTest() {} - void testParse() { - PayloadsParserTester parser; + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"jabber:iq:register\">" - "<registered/>" - "</query>")); + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"jabber:iq:register\">" + "<registered/>" + "</query>")); - InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(payload->isRegistered()); - } + InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(payload->isRegistered()); + } - void testParse_Form() { - PayloadsParserTester parser; + void testParse_Form() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"jabber:iq:register\">" - "<instructions>Use the enclosed form to register.</instructions>" - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<title>Contest Registration</title>" - "<field type=\"hidden\" var=\"FORM_TYPE\">" - "<value>jabber:iq:register</value>" - "</field>" - "</x>" - "</query>")); + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"jabber:iq:register\">" + "<instructions>Use the enclosed form to register.</instructions>" + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<title>Contest Registration</title>" + "<field type=\"hidden\" var=\"FORM_TYPE\">" + "<value>jabber:iq:register</value>" + "</field>" + "</x>" + "</query>")); - InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - boost::optional<std::string> instruction = payload->getInstructions(); - CPPUNIT_ASSERT(instruction); - CPPUNIT_ASSERT_EQUAL(std::string("Use the enclosed form to register."), instruction.get()); + InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + boost::optional<std::string> instruction = payload->getInstructions(); + CPPUNIT_ASSERT(instruction); + CPPUNIT_ASSERT_EQUAL(std::string("Use the enclosed form to register."), instruction.get()); - Form::ref form = payload->getForm(); - CPPUNIT_ASSERT(form); - CPPUNIT_ASSERT_EQUAL(std::string("Contest Registration"), form->getTitle()); - CPPUNIT_ASSERT_EQUAL(Form::FormType, form->getType()); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:register"), form->getFormType()); - } + Form::ref form = payload->getForm(); + CPPUNIT_ASSERT(form); + CPPUNIT_ASSERT_EQUAL(std::string("Contest Registration"), form->getTitle()); + CPPUNIT_ASSERT_EQUAL(Form::FormType, form->getType()); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:register"), form->getFormType()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(InBandRegistrationPayloadParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp index 56143ef..c502c8a 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -26,592 +26,592 @@ using namespace Swift; class JingleParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(JingleParserTest); - CPPUNIT_TEST(testParse_Xep0166_Example3); - CPPUNIT_TEST(testParse_Xep0166_Example8); - - CPPUNIT_TEST(testParse_Xep0261_Example1); - CPPUNIT_TEST(testParse_Xep0261_Example3); - CPPUNIT_TEST(testParse_Xep0261_Example9); - CPPUNIT_TEST(testParse_Xep0261_Example13); - - CPPUNIT_TEST(testParse_Xep0234_Example1); - CPPUNIT_TEST(testParse_Xep0234_Example3); - CPPUNIT_TEST(testParse_Xep0234_Example5); - CPPUNIT_TEST(testParse_Xep0234_Example8); - CPPUNIT_TEST(testParse_Xep0234_Example10); - - CPPUNIT_TEST(testParse_Xep0260_Example1); - CPPUNIT_TEST(testParse_Xep0260_Example3); - CPPUNIT_TEST_SUITE_END(); - - public: - //http://xmpp.org/extensions/xep-0166.html#example-3 - void testParse_Xep0166_Example3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-terminate'\n" - " sid='a73sjjvkla37jfea'>\n" - " <reason>\n" - " <success/>\n" - " </reason>\n" - "</jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, - jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).type); - } - - //http://xmpp.org/extensions/xep-0166.html#example-8 - void testParse_Xep0166_Example8() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-terminate'\n" - " sid='a73sjjvkla37jfea'>\n" - " <reason>\n" - " <success/>\n" - " <text>Sorry, gotta go!</text>\n" - " </reason>\n" - "</jingle>\n" - )); - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, - jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).type); - CPPUNIT_ASSERT_EQUAL(std::string("Sorry, gotta go!"), - jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).text); - } - - // IBB Transport Method Examples - - // http://xmpp.org/extensions/xep-0261.html#example-1 - void testParse_Xep0261_Example1() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-initiate'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <content creator='initiator' name='ex'>\n" - " <description xmlns='urn:xmpp:example'/>\n" - " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" - " block-size='4096'\n" - " sid='ch3d9s71'/>\n" - " </content>\n" - "</jingle>\n" - )); - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - std::vector<JingleContentPayload::ref> payloads = jingle->getContents(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payloads.size()); - JingleContentPayload::ref payload = payloads[0]; - CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); - CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payload->getTransports().size()); - - JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); - CPPUNIT_ASSERT(transportPaylod); - CPPUNIT_ASSERT_EQUAL(4096U, *transportPaylod->getBlockSize()); - CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID()); - } - - // http://xmpp.org/extensions/xep-0261.html#example-1 - void testParse_Xep0261_Example3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-accept'\n" - " initiator='romeo@montague.lit/orchard'\n" - " responder='juliet@capulet.lit/balcony'\n" - " sid='a73sjjvkla37jfea'>\n" - " <content creator='initiator' name='ex'>\n" - " <description xmlns='urn:xmpp:example'/>\n" - " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" - " block-size='2048'\n" - " sid='ch3d9s71'/>\n" - " </content>\n" - " </jingle>\n" - )); - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), jingle->getResponder()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - std::vector<JingleContentPayload::ref> payloads = jingle->getContents(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payloads.size()); - JingleContentPayload::ref payload = payloads[0]; - CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); - CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payload->getTransports().size()); - - JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); - CPPUNIT_ASSERT(transportPaylod); - CPPUNIT_ASSERT_EQUAL(2048U, *transportPaylod->getBlockSize()); - CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID()); - } - - // http://xmpp.org/extensions/xep-0261.html#example-9 - void testParse_Xep0261_Example9() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='transport-info'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <content creator='initiator' name='ex'>\n" - " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" - " block-size='2048'\n" - " sid='bt8a71h6'/>\n" - " </content>\n" - "</jingle>\n" - )); - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::TransportInfo, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - std::vector<JingleContentPayload::ref> payloads = jingle->getContents(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payloads.size()); - JingleContentPayload::ref payload = payloads[0]; - CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); - CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); - - JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); - CPPUNIT_ASSERT(transportPaylod); - CPPUNIT_ASSERT_EQUAL(2048U, *transportPaylod->getBlockSize()); - CPPUNIT_ASSERT_EQUAL(std::string("bt8a71h6"), transportPaylod->getSessionID()); - } - - // http://xmpp.org/extensions/xep-0261.html#example-13 - void testParse_Xep0261_Example13() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-terminate'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <reason><success/></reason>\n" - " </jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, jingle->getReason().get_value_or(JinglePayload::Reason()).type); - - } - - // Jingle File Transfer Examples - - // http://xmpp.org/extensions/xep-0234.html#example-1 - void testParse_Xep0234_Example1() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-initiate'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='851ba2'>\n" - "<content creator='initiator' name='a-file-offer'>\n" - "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" - "<file>\n" - "<date>1969-07-21T02:56:15Z</date>\n" - "<desc>This is a test. If this were a real file...</desc>\n" - "<media-type>text/plain</media-type>\n" - "<name>test.txt</name>\n" - "<range/>\n" - "<size>1022</size>\n" - "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" - "</file>\n" - "</description>\n" - "<transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" - " mode='tcp'\n" - " sid='vj3hs98y'>\n" - "<candidate cid='hft54dqy'\n" - " host='192.168.4.1'\n" - " jid='romeo@montague.lit/orchard'\n" - " port='5086'\n" - " priority='8257636'\n" - " type='direct'/>\n" - "<candidate cid='hutr46fe'\n" - " host='24.24.24.1'\n" - " jid='romeo@montague.lit/orchard'\n" - " port='5087'\n" - " priority='8258636'\n" - " type='direct'/>\n" - "</transport>\n" - "</content>\n" - "</jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("851ba2"), jingle->getSessionID()); - - std::vector<JingleContentPayload::ref> contents = jingle->getContents(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), contents.size()); - - JingleFileTransferDescription::ref description = contents[0]->getDescription<JingleFileTransferDescription>(); - - CPPUNIT_ASSERT(description); - JingleFileTransferFileInfo fileInfo = description->getFileInfo(); - CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), fileInfo.getName()); - CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), fileInfo.getHashes().begin()->first); - CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(fileInfo.getHashes().begin()->second)); - CPPUNIT_ASSERT(1022 == fileInfo.getSize()); - CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), fileInfo.getDescription()); - CPPUNIT_ASSERT_EQUAL(true, fileInfo.getSupportsRangeRequests()); - CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == fileInfo.getDate()); - } - - // http://xmpp.org/extensions/xep-0234.html#example-3 - void testParse_Xep0234_Example3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-accept'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='851ba2'>\n" - "<content creator='initiator' name='a-file-offer'>\n" - "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" - "<file>\n" - "<date>1969-07-21T02:56:15Z</date>\n" - "<desc>This is a test. If this were a real file...</desc>\n" - "<media-type>text/plain</media-type>\n" - "<name>test.txt</name>\n" - "<range/>\n" - "<size>1022</size>\n" - "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" - "</file>\n" - "</description>\n" - " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" - " mode='tcp'\n" - " sid='vj3hs98y'>\n" - " <candidate cid='ht567dq'\n" - " host='192.169.1.10'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='6539'\n" - " priority='8257636'\n" - " type='direct'/>\n" - " <candidate cid='hr65dqyd'\n" - " host='134.102.201.180'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='16453'\n" - " priority='7929856'\n" - " type='assisted'/>\n" - " <candidate cid='grt654q2'\n" - " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='6539'\n" - " priority='8257606'\n" - " type='direct'/>\n" - " </transport>\n" - " </content>\n" - "</jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("851ba2"), jingle->getSessionID()); - - std::vector<JingleContentPayload::ref> contents = jingle->getContents(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), contents.size()); - - JingleFileTransferDescription::ref description = contents[0]->getDescription<JingleFileTransferDescription>(); - - CPPUNIT_ASSERT(description); - - JingleFileTransferFileInfo fileInfo = description->getFileInfo(); - CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), fileInfo.getName()); - CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), fileInfo.getHashes().begin()->first); - CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(fileInfo.getHashes().begin()->second)); - CPPUNIT_ASSERT(1022 == fileInfo.getSize()); - CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), fileInfo.getDescription()); - CPPUNIT_ASSERT_EQUAL(true, fileInfo.getSupportsRangeRequests()); - CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == fileInfo.getDate()); - } - - // http://xmpp.org/extensions/xep-0234.html#example-5 - void testParse_Xep0234_Example5() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='transport-info'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <content creator='initiator' name='ex'>\n" - " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" - " sid='vj3hs98y'>\n" - " <candidate-used cid='hr65dqyd'/>\n" - " </transport>\n" - " </content>\n" - "</jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::TransportInfo, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - std::vector<JingleContentPayload::ref> contents = jingle->getContents(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), contents.size()); - - JingleS5BTransportPayload::ref transport = contents[0]->getTransport<JingleS5BTransportPayload>(); - CPPUNIT_ASSERT(transport); - - CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), transport->getSessionID()); - CPPUNIT_ASSERT_EQUAL(std::string("hr65dqyd"), transport->getCandidateUsed()); - } - - // http://xmpp.org/extensions/xep-0234.html#example-8 - void testParse_Xep0234_Example8() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-info'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <checksum xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" - " <file>\n" - " <hash xmlns='urn:xmpp:hashes:0' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" - " </file>\n" - " </checksum>\n" - "</jingle>\n" - )); - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInfo, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - JingleFileTransferHash::ref hash = jingle->getPayload<JingleFileTransferHash>(); - CPPUNIT_ASSERT(hash); - CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(hash->getFileInfo().getHash("sha-1").get())); - } - - // http://xmpp.org/extensions/xep-0234.html#example-10 - void testParse_Xep0234_Example10() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-initiate'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='uj3b2'>\n" - " <content creator='initiator' name='a-file-request'>\n" - " <description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" - " <file>\n" - " <hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" - " <range offset='270336'/>\n" - " </file>\n" - " </description>\n" - " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" - " mode='tcp'\n" - " sid='xig361fj'>\n" - " <candidate cid='ht567dq'\n" - " host='192.169.1.10'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='6539'\n" - " priority='8257636'\n" - " type='direct'/>\n" - " <candidate cid='hr65dqyd'\n" - " host='134.102.201.180'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='16453'\n" - " priority='7929856'\n" - " type='assisted'/>\n" - " <candidate cid='grt654q2'\n" - " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='6539'\n" - " priority='8257606'\n" - " type='direct'/>\n" - " </transport>\n" - " </content>\n" - "</jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("uj3b2"), jingle->getSessionID()); - - JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>(); - CPPUNIT_ASSERT(content); - - JingleFileTransferFileInfo file = content->getDescription<JingleFileTransferDescription>()->getFileInfo(); - CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), file.getHashes().begin()->first); - CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(file.getHashes().begin()->second)); - CPPUNIT_ASSERT_EQUAL(static_cast<boost::uintmax_t>(270336), file.getRangeOffset()); - CPPUNIT_ASSERT_EQUAL(true, file.getSupportsRangeRequests()); - } - - // http://xmpp.org/extensions/xep-0260.html#example-1 - void testParse_Xep0260_Example1() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-initiate'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <content creator='initiator' name='ex'>\n" - " <description xmlns='urn:xmpp:example'/>\n" - " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" - " mode='tcp'\n" - " sid='vj3hs98y'>\n" - " <candidate cid='hft54dqy'\n" - " host='192.168.4.1'\n" - " jid='romeo@montague.lit/orchard'\n" - " port='5086'\n" - " priority='8257636'\n" - " type='direct'/>\n" - " <candidate cid='hutr46fe'\n" - " host='24.24.24.1'\n" - " jid='romeo@montague.lit/orchard'\n" - " port='5087'\n" - " priority='8258636'\n" - " type='direct'/>\n" - " </transport>\n" - " </content>\n" - "</jingle>\n" - )); - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>(); - CPPUNIT_ASSERT(content); - - JingleS5BTransportPayload::ref s5bPayload = content->getTransport<JingleS5BTransportPayload>(); - CPPUNIT_ASSERT(s5bPayload); - - CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), s5bPayload->getSessionID()); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::TCPMode, s5bPayload->getMode()); - CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasCandidateError()); - CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasProxyError()); - CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getActivated()); - CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getCandidateUsed()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), s5bPayload->getCandidates().size()); - - JingleS5BTransportPayload::Candidate candidate; - candidate = s5bPayload->getCandidates()[0]; - CPPUNIT_ASSERT_EQUAL(std::string("hft54dqy"), candidate.cid); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), candidate.jid); - CPPUNIT_ASSERT(HostAddressPort(HostAddress("192.168.4.1"), 5086) == candidate.hostPort); - CPPUNIT_ASSERT_EQUAL(8257636, candidate.priority); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); - - candidate = s5bPayload->getCandidates()[1]; - CPPUNIT_ASSERT_EQUAL(std::string("hutr46fe"), candidate.cid); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), candidate.jid); - CPPUNIT_ASSERT(HostAddressPort(HostAddress("24.24.24.1"), 5087) == candidate.hostPort); - CPPUNIT_ASSERT_EQUAL(8258636, candidate.priority); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); - } - - // http://xmpp.org/extensions/xep-0260.html#example-3 - void testParse_Xep0260_Example3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-accept'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='a73sjjvkla37jfea'>\n" - " <content creator='initiator' name='ex'>\n" - " <description xmlns='urn:xmpp:example'/>\n" - " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" - " dstaddr='1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba'\n" - " mode='tcp'\n" - " sid='vj3hs98y'>\n" - " <candidate cid='ht567dq'\n" - " host='192.169.1.10'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='6539'\n" - " priority='8257636'\n" - " type='direct'/>\n" - " <candidate cid='hr65dqyd'\n" - " host='134.102.201.180'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='16453'\n" - " priority='7929856'\n" - " type='assisted'/>\n" - " <candidate cid='grt654q2'\n" - " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" - " jid='juliet@capulet.lit/balcony'\n" - " port='6539'\n" - " priority='8257606'\n" - " type='direct'/>\n" - " </transport>\n" - " </content>\n" - "</jingle>\n" - )); - - JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); - CPPUNIT_ASSERT(jingle); - CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); - CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); - - JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>(); - CPPUNIT_ASSERT(content); - - JingleS5BTransportPayload::ref s5bPayload = content->getTransport<JingleS5BTransportPayload>(); - CPPUNIT_ASSERT(s5bPayload); - - CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), s5bPayload->getSessionID()); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::TCPMode, s5bPayload->getMode()); - CPPUNIT_ASSERT_EQUAL(std::string("1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba"), s5bPayload->getDstAddr()); - CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasCandidateError()); - CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasProxyError()); - CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getActivated()); - CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getCandidateUsed()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), s5bPayload->getCandidates().size()); - - JingleS5BTransportPayload::Candidate candidate; - candidate = s5bPayload->getCandidates()[0]; - CPPUNIT_ASSERT_EQUAL(std::string("ht567dq"), candidate.cid); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); - CPPUNIT_ASSERT(HostAddressPort(HostAddress("192.169.1.10"), 6539) == candidate.hostPort); - CPPUNIT_ASSERT_EQUAL(8257636, candidate.priority); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); - - candidate = s5bPayload->getCandidates()[1]; - CPPUNIT_ASSERT_EQUAL(std::string("hr65dqyd"), candidate.cid); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); - CPPUNIT_ASSERT(HostAddressPort(HostAddress("134.102.201.180"), 16453) == candidate.hostPort); - CPPUNIT_ASSERT_EQUAL(7929856, candidate.priority); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::AssistedType, candidate.type); - - candidate = s5bPayload->getCandidates()[2]; - CPPUNIT_ASSERT_EQUAL(std::string("grt654q2"), candidate.cid); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); - CPPUNIT_ASSERT(HostAddressPort(HostAddress("2001:638:708:30c9:219:d1ff:fea4:a17d"), 6539) == candidate.hostPort); - CPPUNIT_ASSERT_EQUAL(8257606, candidate.priority); - CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); - } + CPPUNIT_TEST_SUITE(JingleParserTest); + CPPUNIT_TEST(testParse_Xep0166_Example3); + CPPUNIT_TEST(testParse_Xep0166_Example8); + + CPPUNIT_TEST(testParse_Xep0261_Example1); + CPPUNIT_TEST(testParse_Xep0261_Example3); + CPPUNIT_TEST(testParse_Xep0261_Example9); + CPPUNIT_TEST(testParse_Xep0261_Example13); + + CPPUNIT_TEST(testParse_Xep0234_Example1); + CPPUNIT_TEST(testParse_Xep0234_Example3); + CPPUNIT_TEST(testParse_Xep0234_Example5); + CPPUNIT_TEST(testParse_Xep0234_Example8); + CPPUNIT_TEST(testParse_Xep0234_Example10); + + CPPUNIT_TEST(testParse_Xep0260_Example1); + CPPUNIT_TEST(testParse_Xep0260_Example3); + CPPUNIT_TEST_SUITE_END(); + + public: + //http://xmpp.org/extensions/xep-0166.html#example-3 + void testParse_Xep0166_Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-terminate'\n" + " sid='a73sjjvkla37jfea'>\n" + " <reason>\n" + " <success/>\n" + " </reason>\n" + "</jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, + jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).type); + } + + //http://xmpp.org/extensions/xep-0166.html#example-8 + void testParse_Xep0166_Example8() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-terminate'\n" + " sid='a73sjjvkla37jfea'>\n" + " <reason>\n" + " <success/>\n" + " <text>Sorry, gotta go!</text>\n" + " </reason>\n" + "</jingle>\n" + )); + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, + jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).type); + CPPUNIT_ASSERT_EQUAL(std::string("Sorry, gotta go!"), + jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).text); + } + + // IBB Transport Method Examples + + // http://xmpp.org/extensions/xep-0261.html#example-1 + void testParse_Xep0261_Example1() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-initiate'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <content creator='initiator' name='ex'>\n" + " <description xmlns='urn:xmpp:example'/>\n" + " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" + " block-size='4096'\n" + " sid='ch3d9s71'/>\n" + " </content>\n" + "</jingle>\n" + )); + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + std::vector<JingleContentPayload::ref> payloads = jingle->getContents(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payloads.size()); + JingleContentPayload::ref payload = payloads[0]; + CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); + CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payload->getTransports().size()); + + JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); + CPPUNIT_ASSERT(transportPaylod); + CPPUNIT_ASSERT_EQUAL(4096U, *transportPaylod->getBlockSize()); + CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID()); + } + + // http://xmpp.org/extensions/xep-0261.html#example-1 + void testParse_Xep0261_Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-accept'\n" + " initiator='romeo@montague.lit/orchard'\n" + " responder='juliet@capulet.lit/balcony'\n" + " sid='a73sjjvkla37jfea'>\n" + " <content creator='initiator' name='ex'>\n" + " <description xmlns='urn:xmpp:example'/>\n" + " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" + " block-size='2048'\n" + " sid='ch3d9s71'/>\n" + " </content>\n" + " </jingle>\n" + )); + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), jingle->getResponder()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + std::vector<JingleContentPayload::ref> payloads = jingle->getContents(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payloads.size()); + JingleContentPayload::ref payload = payloads[0]; + CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); + CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payload->getTransports().size()); + + JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); + CPPUNIT_ASSERT(transportPaylod); + CPPUNIT_ASSERT_EQUAL(2048U, *transportPaylod->getBlockSize()); + CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID()); + } + + // http://xmpp.org/extensions/xep-0261.html#example-9 + void testParse_Xep0261_Example9() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='transport-info'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <content creator='initiator' name='ex'>\n" + " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" + " block-size='2048'\n" + " sid='bt8a71h6'/>\n" + " </content>\n" + "</jingle>\n" + )); + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::TransportInfo, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + std::vector<JingleContentPayload::ref> payloads = jingle->getContents(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payloads.size()); + JingleContentPayload::ref payload = payloads[0]; + CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); + CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); + + JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); + CPPUNIT_ASSERT(transportPaylod); + CPPUNIT_ASSERT_EQUAL(2048U, *transportPaylod->getBlockSize()); + CPPUNIT_ASSERT_EQUAL(std::string("bt8a71h6"), transportPaylod->getSessionID()); + } + + // http://xmpp.org/extensions/xep-0261.html#example-13 + void testParse_Xep0261_Example13() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-terminate'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <reason><success/></reason>\n" + " </jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, jingle->getReason().get_value_or(JinglePayload::Reason()).type); + + } + + // Jingle File Transfer Examples + + // http://xmpp.org/extensions/xep-0234.html#example-1 + void testParse_Xep0234_Example1() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-initiate'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='851ba2'>\n" + "<content creator='initiator' name='a-file-offer'>\n" + "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" + "<file>\n" + "<date>1969-07-21T02:56:15Z</date>\n" + "<desc>This is a test. If this were a real file...</desc>\n" + "<media-type>text/plain</media-type>\n" + "<name>test.txt</name>\n" + "<range/>\n" + "<size>1022</size>\n" + "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" + "</file>\n" + "</description>\n" + "<transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" + " mode='tcp'\n" + " sid='vj3hs98y'>\n" + "<candidate cid='hft54dqy'\n" + " host='192.168.4.1'\n" + " jid='romeo@montague.lit/orchard'\n" + " port='5086'\n" + " priority='8257636'\n" + " type='direct'/>\n" + "<candidate cid='hutr46fe'\n" + " host='24.24.24.1'\n" + " jid='romeo@montague.lit/orchard'\n" + " port='5087'\n" + " priority='8258636'\n" + " type='direct'/>\n" + "</transport>\n" + "</content>\n" + "</jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("851ba2"), jingle->getSessionID()); + + std::vector<JingleContentPayload::ref> contents = jingle->getContents(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), contents.size()); + + JingleFileTransferDescription::ref description = contents[0]->getDescription<JingleFileTransferDescription>(); + + CPPUNIT_ASSERT(description); + JingleFileTransferFileInfo fileInfo = description->getFileInfo(); + CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), fileInfo.getName()); + CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), fileInfo.getHashes().begin()->first); + CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(fileInfo.getHashes().begin()->second)); + CPPUNIT_ASSERT(1022 == fileInfo.getSize()); + CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), fileInfo.getDescription()); + CPPUNIT_ASSERT_EQUAL(true, fileInfo.getSupportsRangeRequests()); + CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == fileInfo.getDate()); + } + + // http://xmpp.org/extensions/xep-0234.html#example-3 + void testParse_Xep0234_Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-accept'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='851ba2'>\n" + "<content creator='initiator' name='a-file-offer'>\n" + "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" + "<file>\n" + "<date>1969-07-21T02:56:15Z</date>\n" + "<desc>This is a test. If this were a real file...</desc>\n" + "<media-type>text/plain</media-type>\n" + "<name>test.txt</name>\n" + "<range/>\n" + "<size>1022</size>\n" + "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" + "</file>\n" + "</description>\n" + " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" + " mode='tcp'\n" + " sid='vj3hs98y'>\n" + " <candidate cid='ht567dq'\n" + " host='192.169.1.10'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='6539'\n" + " priority='8257636'\n" + " type='direct'/>\n" + " <candidate cid='hr65dqyd'\n" + " host='134.102.201.180'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='16453'\n" + " priority='7929856'\n" + " type='assisted'/>\n" + " <candidate cid='grt654q2'\n" + " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='6539'\n" + " priority='8257606'\n" + " type='direct'/>\n" + " </transport>\n" + " </content>\n" + "</jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("851ba2"), jingle->getSessionID()); + + std::vector<JingleContentPayload::ref> contents = jingle->getContents(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), contents.size()); + + JingleFileTransferDescription::ref description = contents[0]->getDescription<JingleFileTransferDescription>(); + + CPPUNIT_ASSERT(description); + + JingleFileTransferFileInfo fileInfo = description->getFileInfo(); + CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), fileInfo.getName()); + CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), fileInfo.getHashes().begin()->first); + CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(fileInfo.getHashes().begin()->second)); + CPPUNIT_ASSERT(1022 == fileInfo.getSize()); + CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), fileInfo.getDescription()); + CPPUNIT_ASSERT_EQUAL(true, fileInfo.getSupportsRangeRequests()); + CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == fileInfo.getDate()); + } + + // http://xmpp.org/extensions/xep-0234.html#example-5 + void testParse_Xep0234_Example5() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='transport-info'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <content creator='initiator' name='ex'>\n" + " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" + " sid='vj3hs98y'>\n" + " <candidate-used cid='hr65dqyd'/>\n" + " </transport>\n" + " </content>\n" + "</jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::TransportInfo, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + std::vector<JingleContentPayload::ref> contents = jingle->getContents(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), contents.size()); + + JingleS5BTransportPayload::ref transport = contents[0]->getTransport<JingleS5BTransportPayload>(); + CPPUNIT_ASSERT(transport); + + CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), transport->getSessionID()); + CPPUNIT_ASSERT_EQUAL(std::string("hr65dqyd"), transport->getCandidateUsed()); + } + + // http://xmpp.org/extensions/xep-0234.html#example-8 + void testParse_Xep0234_Example8() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-info'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <checksum xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" + " <file>\n" + " <hash xmlns='urn:xmpp:hashes:0' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" + " </file>\n" + " </checksum>\n" + "</jingle>\n" + )); + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInfo, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + JingleFileTransferHash::ref hash = jingle->getPayload<JingleFileTransferHash>(); + CPPUNIT_ASSERT(hash); + CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(hash->getFileInfo().getHash("sha-1").get())); + } + + // http://xmpp.org/extensions/xep-0234.html#example-10 + void testParse_Xep0234_Example10() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-initiate'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='uj3b2'>\n" + " <content creator='initiator' name='a-file-request'>\n" + " <description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" + " <file>\n" + " <hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" + " <range offset='270336'/>\n" + " </file>\n" + " </description>\n" + " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" + " mode='tcp'\n" + " sid='xig361fj'>\n" + " <candidate cid='ht567dq'\n" + " host='192.169.1.10'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='6539'\n" + " priority='8257636'\n" + " type='direct'/>\n" + " <candidate cid='hr65dqyd'\n" + " host='134.102.201.180'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='16453'\n" + " priority='7929856'\n" + " type='assisted'/>\n" + " <candidate cid='grt654q2'\n" + " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='6539'\n" + " priority='8257606'\n" + " type='direct'/>\n" + " </transport>\n" + " </content>\n" + "</jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("uj3b2"), jingle->getSessionID()); + + JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>(); + CPPUNIT_ASSERT(content); + + JingleFileTransferFileInfo file = content->getDescription<JingleFileTransferDescription>()->getFileInfo(); + CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), file.getHashes().begin()->first); + CPPUNIT_ASSERT_EQUAL(std::string("VS2nSZMIUsaa5dIUHTdmsQ=="), Base64::encode(file.getHashes().begin()->second)); + CPPUNIT_ASSERT_EQUAL(static_cast<boost::uintmax_t>(270336), file.getRangeOffset()); + CPPUNIT_ASSERT_EQUAL(true, file.getSupportsRangeRequests()); + } + + // http://xmpp.org/extensions/xep-0260.html#example-1 + void testParse_Xep0260_Example1() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-initiate'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <content creator='initiator' name='ex'>\n" + " <description xmlns='urn:xmpp:example'/>\n" + " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" + " mode='tcp'\n" + " sid='vj3hs98y'>\n" + " <candidate cid='hft54dqy'\n" + " host='192.168.4.1'\n" + " jid='romeo@montague.lit/orchard'\n" + " port='5086'\n" + " priority='8257636'\n" + " type='direct'/>\n" + " <candidate cid='hutr46fe'\n" + " host='24.24.24.1'\n" + " jid='romeo@montague.lit/orchard'\n" + " port='5087'\n" + " priority='8258636'\n" + " type='direct'/>\n" + " </transport>\n" + " </content>\n" + "</jingle>\n" + )); + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>(); + CPPUNIT_ASSERT(content); + + JingleS5BTransportPayload::ref s5bPayload = content->getTransport<JingleS5BTransportPayload>(); + CPPUNIT_ASSERT(s5bPayload); + + CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), s5bPayload->getSessionID()); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::TCPMode, s5bPayload->getMode()); + CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasCandidateError()); + CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasProxyError()); + CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getActivated()); + CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getCandidateUsed()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), s5bPayload->getCandidates().size()); + + JingleS5BTransportPayload::Candidate candidate; + candidate = s5bPayload->getCandidates()[0]; + CPPUNIT_ASSERT_EQUAL(std::string("hft54dqy"), candidate.cid); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), candidate.jid); + CPPUNIT_ASSERT(HostAddressPort(HostAddress::fromString("192.168.4.1").get(), 5086) == candidate.hostPort); + CPPUNIT_ASSERT_EQUAL(8257636, candidate.priority); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); + + candidate = s5bPayload->getCandidates()[1]; + CPPUNIT_ASSERT_EQUAL(std::string("hutr46fe"), candidate.cid); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), candidate.jid); + CPPUNIT_ASSERT(HostAddressPort(HostAddress::fromString("24.24.24.1").get(), 5087) == candidate.hostPort); + CPPUNIT_ASSERT_EQUAL(8258636, candidate.priority); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); + } + + // http://xmpp.org/extensions/xep-0260.html#example-3 + void testParse_Xep0260_Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<jingle xmlns='urn:xmpp:jingle:1'\n" + " action='session-accept'\n" + " initiator='romeo@montague.lit/orchard'\n" + " sid='a73sjjvkla37jfea'>\n" + " <content creator='initiator' name='ex'>\n" + " <description xmlns='urn:xmpp:example'/>\n" + " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" + " dstaddr='1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba'\n" + " mode='tcp'\n" + " sid='vj3hs98y'>\n" + " <candidate cid='ht567dq'\n" + " host='192.169.1.10'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='6539'\n" + " priority='8257636'\n" + " type='direct'/>\n" + " <candidate cid='hr65dqyd'\n" + " host='134.102.201.180'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='16453'\n" + " priority='7929856'\n" + " type='assisted'/>\n" + " <candidate cid='grt654q2'\n" + " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" + " jid='juliet@capulet.lit/balcony'\n" + " port='6539'\n" + " priority='8257606'\n" + " type='direct'/>\n" + " </transport>\n" + " </content>\n" + "</jingle>\n" + )); + + JinglePayload::ref jingle = parser.getPayload<JinglePayload>(); + CPPUNIT_ASSERT(jingle); + CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); + CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); + + JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>(); + CPPUNIT_ASSERT(content); + + JingleS5BTransportPayload::ref s5bPayload = content->getTransport<JingleS5BTransportPayload>(); + CPPUNIT_ASSERT(s5bPayload); + + CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), s5bPayload->getSessionID()); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::TCPMode, s5bPayload->getMode()); + CPPUNIT_ASSERT_EQUAL(std::string("1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba"), s5bPayload->getDstAddr()); + CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasCandidateError()); + CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasProxyError()); + CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getActivated()); + CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getCandidateUsed()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), s5bPayload->getCandidates().size()); + + JingleS5BTransportPayload::Candidate candidate; + candidate = s5bPayload->getCandidates()[0]; + CPPUNIT_ASSERT_EQUAL(std::string("ht567dq"), candidate.cid); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); + CPPUNIT_ASSERT(HostAddressPort(HostAddress::fromString("192.169.1.10").get(), 6539) == candidate.hostPort); + CPPUNIT_ASSERT_EQUAL(8257636, candidate.priority); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); + + candidate = s5bPayload->getCandidates()[1]; + CPPUNIT_ASSERT_EQUAL(std::string("hr65dqyd"), candidate.cid); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); + CPPUNIT_ASSERT(HostAddressPort(HostAddress::fromString("134.102.201.180").get(), 16453) == candidate.hostPort); + CPPUNIT_ASSERT_EQUAL(7929856, candidate.priority); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::AssistedType, candidate.type); + + candidate = s5bPayload->getCandidates()[2]; + CPPUNIT_ASSERT_EQUAL(std::string("grt654q2"), candidate.cid); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); + CPPUNIT_ASSERT(HostAddressPort(HostAddress::fromString("2001:638:708:30c9:219:d1ff:fea4:a17d").get(), 6539) == candidate.hostPort); + CPPUNIT_ASSERT_EQUAL(8257606, candidate.priority); + CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(JingleParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp index dd6263d..6a8e2ed 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -14,46 +14,46 @@ using namespace Swift; class MAMFinParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MAMFinParserTest); - CPPUNIT_TEST(testParse_XEP0313_Exmaple1); - CPPUNIT_TEST(testParse_XEP0313_Exmaple9); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse_XEP0313_Exmaple1() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<fin xmlns='urn:xmpp:mam:0' queryid='f27' />")); - - boost::shared_ptr<MAMFin> payload = parser.getPayload<MAMFin>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT_EQUAL(false, payload->isComplete()); - CPPUNIT_ASSERT_EQUAL(true, payload->isStable()); - - boost::optional<std::string> queryID = payload->getQueryID(); - CPPUNIT_ASSERT(queryID); - CPPUNIT_ASSERT_EQUAL(std::string("f27"), queryID.get()); - } - - void testParse_XEP0313_Exmaple9() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<fin xmlns='urn:xmpp:mam:0' complete='true'>" - "<set xmlns='http://jabber.org/protocol/rsm'>" - "<first index='0'>23452-4534-1</first>" - "<last>390-2342-22</last>" - "<count>16</count>" - "</set>" - "</fin>")); - - boost::shared_ptr<MAMFin> payload = parser.getPayload<MAMFin>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT_EQUAL(true, payload->isComplete()); - CPPUNIT_ASSERT_EQUAL(true, payload->isStable()); - - CPPUNIT_ASSERT(!!payload->getResultSet()); - boost::shared_ptr<ResultSet> resultSet = payload->getResultSet(); - } + CPPUNIT_TEST_SUITE(MAMFinParserTest); + CPPUNIT_TEST(testParse_XEP0313_Exmaple1); + CPPUNIT_TEST(testParse_XEP0313_Exmaple9); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse_XEP0313_Exmaple1() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<fin xmlns='urn:xmpp:mam:0' queryid='f27' />")); + + std::shared_ptr<MAMFin> payload = parser.getPayload<MAMFin>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT_EQUAL(false, payload->isComplete()); + CPPUNIT_ASSERT_EQUAL(true, payload->isStable()); + + boost::optional<std::string> queryID = payload->getQueryID(); + CPPUNIT_ASSERT(queryID); + CPPUNIT_ASSERT_EQUAL(std::string("f27"), queryID.get()); + } + + void testParse_XEP0313_Exmaple9() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<fin xmlns='urn:xmpp:mam:0' complete='true'>" + "<set xmlns='http://jabber.org/protocol/rsm'>" + "<first index='0'>23452-4534-1</first>" + "<last>390-2342-22</last>" + "<count>16</count>" + "</set>" + "</fin>")); + + std::shared_ptr<MAMFin> payload = parser.getPayload<MAMFin>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT_EQUAL(true, payload->isComplete()); + CPPUNIT_ASSERT_EQUAL(true, payload->isStable()); + + CPPUNIT_ASSERT(!!payload->getResultSet()); + std::shared_ptr<ResultSet> resultSet = payload->getResultSet(); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(MAMFinParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp index ff89ed1..8750c2e 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -15,108 +15,108 @@ using namespace Swift; class MAMQueryParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MAMQueryParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_XEP0313_Example3); - CPPUNIT_TEST(testParse_XEP0313_Example4); - CPPUNIT_TEST(testParseEmpty); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\" node=\"node1\">" - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<field type=\"text-single\" var=\"FORM_TYPE\">" - "<value>urn:xmpp:mam:0</value>" - "</field>" - "<field type=\"text-single\" var=\"start\">" - "<value>2010-08-07T00:00:00Z</value>" - "</field>" - "</x>" - "<set xmlns=\"http://jabber.org/protocol/rsm\">" - "<max>10</max>" - "</set>" - "</query>")); - - - boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getQueryID()); - CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID()); - CPPUNIT_ASSERT_EQUAL(std::string("node1"), *payload->getNode()); - - CPPUNIT_ASSERT(payload->getForm()); - boost::shared_ptr<FormField> fieldType = payload->getForm()->getField("FORM_TYPE"); - CPPUNIT_ASSERT(fieldType); - CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), fieldType->getTextSingleValue()); - boost::shared_ptr<FormField> fieldStart = payload->getForm()->getField("start"); - CPPUNIT_ASSERT(fieldStart); - CPPUNIT_ASSERT_EQUAL(std::string("2010-08-07T00:00:00Z"), fieldStart->getTextSingleValue()); - - CPPUNIT_ASSERT(payload->getResultSet()); - boost::shared_ptr<ResultSet> resultSet = payload->getResultSet(); - CPPUNIT_ASSERT(resultSet->getMaxItems()); - CPPUNIT_ASSERT_EQUAL(*resultSet->getMaxItems(), 10); - } - - void testParse_XEP0313_Example3() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='urn:xmpp:mam:0'>" - "<x xmlns='jabber:x:data'>" - "<field var='FORM_TYPE'>" - "<value>urn:xmpp:mam:0</value>" - "</field>" - "<field var='with'>" - "<value>juliet@capulet.lit</value>" - "</field>" - "</x>" - "</query>")); - - boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); - CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("with")); - CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue()); - CPPUNIT_ASSERT_EQUAL(std::string("juliet@capulet.lit"), payload->getForm()->getField("with")->getTextSingleValue()); - } - - void testParse_XEP0313_Example4() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='urn:xmpp:mam:0'>" - "<x xmlns='jabber:x:data'>" - "<field var='FORM_TYPE'>" - "<value>urn:xmpp:mam:0</value>" - "</field>" - "<field var='start'>" - "<value>2010-06-07T00:00:00Z</value>" - "</field>" - "<field var='end'>" - "<value>2010-07-07T13:23:54Z</value>" - "</field>" - "</x>" - "</query>")); - boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); - CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("start") && !!payload->getForm()->getField("start")); - CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue()); - CPPUNIT_ASSERT_EQUAL(std::string("2010-06-07T00:00:00Z"), payload->getForm()->getField("start")->getTextSingleValue()); - CPPUNIT_ASSERT_EQUAL(std::string("2010-07-07T13:23:54Z"), payload->getForm()->getField("end")->getTextSingleValue()); - } - - void testParseEmpty() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">" - "</query>")); - - boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getQueryID()); - CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID()); - CPPUNIT_ASSERT(!payload->getForm()); - CPPUNIT_ASSERT(!payload->getResultSet()); - } + CPPUNIT_TEST_SUITE(MAMQueryParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_XEP0313_Example3); + CPPUNIT_TEST(testParse_XEP0313_Example4); + CPPUNIT_TEST(testParseEmpty); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\" node=\"node1\">" + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<field type=\"text-single\" var=\"FORM_TYPE\">" + "<value>urn:xmpp:mam:0</value>" + "</field>" + "<field type=\"text-single\" var=\"start\">" + "<value>2010-08-07T00:00:00Z</value>" + "</field>" + "</x>" + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>10</max>" + "</set>" + "</query>")); + + + std::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getQueryID()); + CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID()); + CPPUNIT_ASSERT_EQUAL(std::string("node1"), *payload->getNode()); + + CPPUNIT_ASSERT(payload->getForm()); + std::shared_ptr<FormField> fieldType = payload->getForm()->getField("FORM_TYPE"); + CPPUNIT_ASSERT(fieldType); + CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), fieldType->getTextSingleValue()); + std::shared_ptr<FormField> fieldStart = payload->getForm()->getField("start"); + CPPUNIT_ASSERT(fieldStart); + CPPUNIT_ASSERT_EQUAL(std::string("2010-08-07T00:00:00Z"), fieldStart->getTextSingleValue()); + + CPPUNIT_ASSERT(payload->getResultSet()); + std::shared_ptr<ResultSet> resultSet = payload->getResultSet(); + CPPUNIT_ASSERT(resultSet->getMaxItems()); + CPPUNIT_ASSERT_EQUAL(*resultSet->getMaxItems(), 10); + } + + void testParse_XEP0313_Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='urn:xmpp:mam:0'>" + "<x xmlns='jabber:x:data'>" + "<field var='FORM_TYPE'>" + "<value>urn:xmpp:mam:0</value>" + "</field>" + "<field var='with'>" + "<value>juliet@capulet.lit</value>" + "</field>" + "</x>" + "</query>")); + + std::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); + CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("with")); + CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue()); + CPPUNIT_ASSERT_EQUAL(std::string("juliet@capulet.lit"), payload->getForm()->getField("with")->getTextSingleValue()); + } + + void testParse_XEP0313_Example4() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='urn:xmpp:mam:0'>" + "<x xmlns='jabber:x:data'>" + "<field var='FORM_TYPE'>" + "<value>urn:xmpp:mam:0</value>" + "</field>" + "<field var='start'>" + "<value>2010-06-07T00:00:00Z</value>" + "</field>" + "<field var='end'>" + "<value>2010-07-07T13:23:54Z</value>" + "</field>" + "</x>" + "</query>")); + std::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); + CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("start") && !!payload->getForm()->getField("start")); + CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-06-07T00:00:00Z"), payload->getForm()->getField("start")->getTextSingleValue()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-07T13:23:54Z"), payload->getForm()->getField("end")->getTextSingleValue()); + } + + void testParseEmpty() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">" + "</query>")); + + std::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getQueryID()); + CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID()); + CPPUNIT_ASSERT(!payload->getForm()); + CPPUNIT_ASSERT(!payload->getResultSet()); + } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp index a4c2f08..15912b1 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp @@ -18,41 +18,41 @@ using namespace Swift; class MAMResultParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MAMResultParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<result id=\"28482-98726-73623\" queryid=\"f27\" xmlns=\"urn:xmpp:mam:0\">" - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" - "<message xmlns=\"jabber:client\" from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\">" - "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" - "</message>" - "</forwarded>" - "</result>")); - - boost::shared_ptr<MAMResult> payload = parser.getPayload<MAMResult>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT_EQUAL(std::string("28482-98726-73623"), payload->getID()); - CPPUNIT_ASSERT(payload->getQueryID()); - CPPUNIT_ASSERT_EQUAL(std::string("f27"), *payload->getQueryID()); - - boost::shared_ptr<Forwarded> forwarded = payload->getPayload(); - CPPUNIT_ASSERT(forwarded->getDelay()); - CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(forwarded->getDelay()->getStamp())); - - boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(forwarded->getStanza()); - CPPUNIT_ASSERT(!!message); - const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; - CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody().get()); - CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); - } + CPPUNIT_TEST_SUITE(MAMResultParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<result id=\"28482-98726-73623\" queryid=\"f27\" xmlns=\"urn:xmpp:mam:0\">" + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" + "<message xmlns=\"jabber:client\" from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\">" + "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" + "</message>" + "</forwarded>" + "</result>")); + + std::shared_ptr<MAMResult> payload = parser.getPayload<MAMResult>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT_EQUAL(std::string("28482-98726-73623"), payload->getID()); + CPPUNIT_ASSERT(payload->getQueryID()); + CPPUNIT_ASSERT_EQUAL(std::string("f27"), *payload->getQueryID()); + + std::shared_ptr<Forwarded> forwarded = payload->getPayload(); + CPPUNIT_ASSERT(forwarded->getDelay()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(forwarded->getDelay()->getStamp())); + + std::shared_ptr<Message> message = std::dynamic_pointer_cast<Message>(forwarded->getStanza()); + CPPUNIT_ASSERT(!!message); + const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; + CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody().get()); + CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(MAMResultParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MUCAdminPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MUCAdminPayloadParserTest.cpp index f49ca19..d403872 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MUCAdminPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MUCAdminPayloadParserTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -14,25 +14,25 @@ using namespace Swift; class MUCAdminPayloadParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MUCAdminPayloadParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(MUCAdminPayloadParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); - public: - MUCAdminPayloadParserTest() {} + public: + MUCAdminPayloadParserTest() {} - void testParse() { - PayloadsParserTester parser; + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<query xmlns=\"http://jabber.org/protocol/muc#admin\"><item affiliation=\"owner\" role=\"visitor\"><actor jid=\"kev@tester.lit\"/><reason>malice</reason></item></query>")); + CPPUNIT_ASSERT(parser.parse("<query xmlns=\"http://jabber.org/protocol/muc#admin\"><item affiliation=\"owner\" role=\"visitor\"><actor jid=\"kev@tester.lit\"/><reason>malice</reason></item></query>")); - MUCAdminPayload::ref payload = boost::dynamic_pointer_cast<MUCAdminPayload>(parser.getPayload()); - 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()); - } + MUCAdminPayload::ref payload = std::dynamic_pointer_cast<MUCAdminPayload>(parser.getPayload()); + 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_TEST_SUITE_REGISTRATION(MUCAdminPayloadParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp index 7f5bb40..f0cf68d 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,87 +7,86 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Base/foreach.h> -#include <Swiften/Parser/PayloadParsers/MUCUserPayloadParser.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 = boost::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); - - foreach (MUCUserPayload::StatusCode 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 = boost::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 = boost::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); - CPPUNIT_ASSERT(payload); - MUCDestroyPayload::ref destroy = boost::dynamic_pointer_cast<MUCDestroyPayload>(payload->getPayload()); - CPPUNIT_ASSERT(destroy); - CPPUNIT_ASSERT_EQUAL(std::string("bert"), destroy->getReason()); - CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit"), destroy->getNewVenue()); - } - - void testParseInvite() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"><invite from='crone1@shakespeare.lit/desktop' to='alice@wonderland.lit/xxx'> <reason>Hey Hecate, this is the place for all good witches!</reason> </invite> <password>cauldronburn</password></x>")); - - MUCUserPayload::ref payload = boost::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(payload->getInvite()); - CPPUNIT_ASSERT(payload->getPassword()); - CPPUNIT_ASSERT_EQUAL(std::string("cauldronburn"), *payload->getPassword()); - MUCUserPayload::Invite invite = *payload->getInvite(); - CPPUNIT_ASSERT_EQUAL(std::string("Hey Hecate, this is the place for all good witches!"), invite.reason); - CPPUNIT_ASSERT_EQUAL(JID("crone1@shakespeare.lit/desktop"), invite.from); - CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit/xxx"), invite.to); - } + 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()); + + 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); + MUCDestroyPayload::ref destroy = std::dynamic_pointer_cast<MUCDestroyPayload>(payload->getPayload()); + CPPUNIT_ASSERT(destroy); + CPPUNIT_ASSERT_EQUAL(std::string("bert"), destroy->getReason()); + CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit"), destroy->getNewVenue()); + } + + void testParseInvite() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"><invite from='crone1@shakespeare.lit/desktop' to='alice@wonderland.lit/xxx'> <reason>Hey Hecate, this is the place for all good witches!</reason> </invite> <password>cauldronburn</password></x>")); + + MUCUserPayload::ref payload = std::dynamic_pointer_cast<MUCUserPayload>(parser.getPayload()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(payload->getInvite()); + CPPUNIT_ASSERT(payload->getPassword()); + CPPUNIT_ASSERT_EQUAL(std::string("cauldronburn"), *payload->getPassword()); + MUCUserPayload::Invite invite = *payload->getInvite(); + CPPUNIT_ASSERT_EQUAL(std::string("Hey Hecate, this is the place for all good witches!"), invite.reason); + CPPUNIT_ASSERT_EQUAL(JID("crone1@shakespeare.lit/desktop"), invite.from); + CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit/xxx"), invite.to); + } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h b/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h index f9b4193..a85a692 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h +++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h @@ -1,14 +1,14 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/UnitTest/ParserTester.h> #include <Swiften/Parser/PayloadParser.h> +#include <Swiften/Parser/UnitTest/ParserTester.h> namespace Swift { - typedef ParserTester<PayloadParser> PayloadParserTester; + typedef ParserTester<PayloadParser> PayloadParserTester; } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h index d9c30b8..2c1ff8e 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h +++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h @@ -1,66 +1,68 @@ /* - * Copyright (c) 2010-2013 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <cassert> + +#include <Swiften/Elements/Payload.h> +#include <Swiften/Parser/PayloadParser.h> #include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> +#include <Swiften/Parser/PlatformXMLParserFactory.h> #include <Swiften/Parser/XMLParser.h> #include <Swiften/Parser/XMLParserClient.h> -#include <Swiften/Parser/PlatformXMLParserFactory.h> -#include <Swiften/Elements/Payload.h> -#include <Swiften/Parser/PayloadParser.h> namespace Swift { - class PayloadsParserTester : public XMLParserClient { - public: - PayloadsParserTester() : level(0) { - xmlParser = PlatformXMLParserFactory().createXMLParser(this); - } + class PayloadsParserTester : public XMLParserClient { + public: + PayloadsParserTester() : level(0) { + xmlParser = PlatformXMLParserFactory().createXMLParser(this); + } - ~PayloadsParserTester() { - delete xmlParser; - } + ~PayloadsParserTester() { + delete xmlParser; + } - bool parse(const std::string& data) { - return xmlParser->parse(data); - } + bool parse(const std::string& data) { + return xmlParser->parse(data); + } - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - assert(!payloadParser.get()); - PayloadParserFactory* payloadParserFactory = factories.getPayloadParserFactory(element, ns, attributes); - assert(payloadParserFactory); - payloadParser.reset(payloadParserFactory->createPayloadParser()); - } - payloadParser->handleStartElement(element, ns, attributes); - level++; - } + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + assert(!payloadParser.get()); + PayloadParserFactory* payloadParserFactory = factories.getPayloadParserFactory(element, ns, attributes); + assert(payloadParserFactory); + payloadParser.reset(payloadParserFactory->createPayloadParser()); + } + payloadParser->handleStartElement(element, ns, attributes); + level++; + } - virtual void handleEndElement(const std::string& element, const std::string& ns) { - level--; - payloadParser->handleEndElement(element, ns); - } + virtual void handleEndElement(const std::string& element, const std::string& ns) { + level--; + payloadParser->handleEndElement(element, ns); + } - virtual void handleCharacterData(const std::string& data) { - payloadParser->handleCharacterData(data); - } + virtual void handleCharacterData(const std::string& data) { + payloadParser->handleCharacterData(data); + } - boost::shared_ptr<Payload> getPayload() const { - return payloadParser->getPayload(); - } + std::shared_ptr<Payload> getPayload() const { + return payloadParser->getPayload(); + } - template<typename T> - boost::shared_ptr<T> getPayload() const { - return boost::dynamic_pointer_cast<T>(payloadParser->getPayload()); - } + template<typename T> + std::shared_ptr<T> getPayload() const { + return std::dynamic_pointer_cast<T>(payloadParser->getPayload()); + } - private: - XMLParser* xmlParser; - FullPayloadParserFactoryCollection factories; - boost::shared_ptr<PayloadParser> payloadParser; - int level; - }; + private: + XMLParser* xmlParser; + FullPayloadParserFactoryCollection factories; + std::shared_ptr<PayloadParser> payloadParser; + int level; + }; } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp index 285ac56..2c89f0f 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.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. */ @@ -13,29 +13,29 @@ using namespace Swift; class PriorityParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(PriorityParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Invalid); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(PriorityParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Invalid); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse() { - PayloadsParserTester parser; + public: + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<priority>-120</priority>")); + CPPUNIT_ASSERT(parser.parse("<priority>-120</priority>")); - boost::shared_ptr<Priority> payload = boost::dynamic_pointer_cast<Priority>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(-120, payload->getPriority()); - } + std::shared_ptr<Priority> payload = std::dynamic_pointer_cast<Priority>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(-120, payload->getPriority()); + } - void testParse_Invalid() { - PayloadsParserTester parser; + void testParse_Invalid() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<priority>invalid</priority>")); + CPPUNIT_ASSERT(parser.parse("<priority>invalid</priority>")); - boost::shared_ptr<Priority> payload = boost::dynamic_pointer_cast<Priority>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(0, payload->getPriority()); - } + std::shared_ptr<Priority> payload = std::dynamic_pointer_cast<Priority>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(0, payload->getPriority()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(PriorityParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp index 58f5a6e..06f3ae5 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.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. */ @@ -9,87 +9,87 @@ #include <Swiften/Elements/Storage.h> #include <Swiften/Parser/PayloadParsers/PrivateStorageParser.h> -#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; class PrivateStorageParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(PrivateStorageParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_NoPayload); - CPPUNIT_TEST(testParse_MultiplePayloads); - CPPUNIT_TEST_SUITE_END(); - - public: - PrivateStorageParserTest() {} - - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='jabber:iq:private'>" - "<storage xmlns='storage:bookmarks'>" - "<conference name='Swift' jid='swift@rooms.swift.im'>" - "<nick>Alice</nick>" - "</conference>" - "</storage>" - "</query>")); - - boost::shared_ptr<PrivateStorage> payload = boost::dynamic_pointer_cast<PrivateStorage>(parser.getPayload()); - CPPUNIT_ASSERT(payload); - boost::shared_ptr<Storage> storage = boost::dynamic_pointer_cast<Storage>(payload->getPayload()); - CPPUNIT_ASSERT(storage); - CPPUNIT_ASSERT_EQUAL(std::string("Alice"), storage->getRooms()[0].nick); - CPPUNIT_ASSERT_EQUAL(JID("swift@rooms.swift.im"), storage->getRooms()[0].jid); - } - - void testParse_NoPayload() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:private'/>")); - - boost::shared_ptr<PrivateStorage> payload = boost::dynamic_pointer_cast<PrivateStorage>(parser.getPayload()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(!payload->getPayload()); - } - - void testParse_MultiplePayloads() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='jabber:iq:private'>" - "<storage xmlns='storage:bookmarks'>" - "<conference name='Swift' jid='swift@rooms.swift.im'>" - "<nick>Alice</nick>" - "</conference>" - "</storage>" - "<storage xmlns='storage:bookmarks'>" - "<conference name='Swift' jid='swift@rooms.swift.im'>" - "<nick>Rabbit</nick>" - "</conference>" - "</storage>" - "</query>")); - - boost::shared_ptr<PrivateStorage> payload = boost::dynamic_pointer_cast<PrivateStorage>(parser.getPayload()); - CPPUNIT_ASSERT(payload); - boost::shared_ptr<Storage> storage = boost::dynamic_pointer_cast<Storage>(payload->getPayload()); - CPPUNIT_ASSERT(storage); - CPPUNIT_ASSERT_EQUAL(std::string("Rabbit"), storage->getRooms()[0].nick); - } - - void testParse_UnsupportedPayload() { - PayloadParserFactoryCollection factories; - PrivateStorageParser testling(&factories); - PayloadParserTester parser(&testling); - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='jabber:iq:private'>" - "<foo>Bar</foo>" - "</query>")); - - CPPUNIT_ASSERT(!boost::dynamic_pointer_cast<PrivateStorage>(testling.getPayload())->getPayload()); - } + CPPUNIT_TEST_SUITE(PrivateStorageParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_NoPayload); + CPPUNIT_TEST(testParse_MultiplePayloads); + CPPUNIT_TEST_SUITE_END(); + + public: + PrivateStorageParserTest() {} + + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='jabber:iq:private'>" + "<storage xmlns='storage:bookmarks'>" + "<conference name='Swift' jid='swift@rooms.swift.im'>" + "<nick>Alice</nick>" + "</conference>" + "</storage>" + "</query>")); + + std::shared_ptr<PrivateStorage> payload = std::dynamic_pointer_cast<PrivateStorage>(parser.getPayload()); + CPPUNIT_ASSERT(payload); + std::shared_ptr<Storage> storage = std::dynamic_pointer_cast<Storage>(payload->getPayload()); + CPPUNIT_ASSERT(storage); + CPPUNIT_ASSERT_EQUAL(std::string("Alice"), storage->getRooms()[0].nick); + CPPUNIT_ASSERT_EQUAL(JID("swift@rooms.swift.im"), storage->getRooms()[0].jid); + } + + void testParse_NoPayload() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:private'/>")); + + std::shared_ptr<PrivateStorage> payload = std::dynamic_pointer_cast<PrivateStorage>(parser.getPayload()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(!payload->getPayload()); + } + + void testParse_MultiplePayloads() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='jabber:iq:private'>" + "<storage xmlns='storage:bookmarks'>" + "<conference name='Swift' jid='swift@rooms.swift.im'>" + "<nick>Alice</nick>" + "</conference>" + "</storage>" + "<storage xmlns='storage:bookmarks'>" + "<conference name='Swift' jid='swift@rooms.swift.im'>" + "<nick>Rabbit</nick>" + "</conference>" + "</storage>" + "</query>")); + + std::shared_ptr<PrivateStorage> payload = std::dynamic_pointer_cast<PrivateStorage>(parser.getPayload()); + CPPUNIT_ASSERT(payload); + std::shared_ptr<Storage> storage = std::dynamic_pointer_cast<Storage>(payload->getPayload()); + CPPUNIT_ASSERT(storage); + CPPUNIT_ASSERT_EQUAL(std::string("Rabbit"), storage->getRooms()[0].nick); + } + + void testParse_UnsupportedPayload() { + PayloadParserFactoryCollection factories; + PrivateStorageParser testling(&factories); + PayloadParserTester parser(&testling); + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='jabber:iq:private'>" + "<foo>Bar</foo>" + "</query>")); + + CPPUNIT_ASSERT(!std::dynamic_pointer_cast<PrivateStorage>(testling.getPayload())->getPayload()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(PrivateStorageParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PubSubRetractParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/PubSubRetractParserTest.cpp new file mode 100644 index 0000000..91bc123 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/PubSubRetractParserTest.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 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/Elements/ContainerPayload.h> +#include <Swiften/Parser/PayloadParsers/PubSubRetractParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +class PubSubRetractParserTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(PubSubRetractParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParseNotify); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<pubsub xmlns='http://jabber.org/protocol/pubsub'>" + "<retract node='princely_musings' xmlns='http://jabber.org/protocol/pubsub'>" + "<item id='ae890ac52d0df67ed7cfdf51b644e901' xmlns='http://jabber.org/protocol/pubsub'/>" + "</retract>" + "</pubsub>")); + + auto payload = parser.getPayload<ContainerPayload<PubSubPayload>>(); + std::shared_ptr<PubSubRetract> retract = std::dynamic_pointer_cast<PubSubRetract>(payload->getPayload()); + CPPUNIT_ASSERT(retract); + CPPUNIT_ASSERT_EQUAL(std::string("princely_musings"), retract->getNode()); + CPPUNIT_ASSERT_EQUAL(false, retract->isNotify().is_initialized()); + } + + void testParseNotify() { + { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<pubsub xmlns='http://jabber.org/protocol/pubsub'>" + "<retract node='princely_musings' notify='true' xmlns='http://jabber.org/protocol/pubsub'>" + "<item id='ae890ac52d0df67ed7cfdf51b644e901' xmlns='http://jabber.org/protocol/pubsub'/>" + "</retract>" + "</pubsub>")); + + auto payload = parser.getPayload<ContainerPayload<PubSubPayload>>(); + std::shared_ptr<PubSubRetract> retract = std::dynamic_pointer_cast<PubSubRetract>(payload->getPayload()); + CPPUNIT_ASSERT(retract); + CPPUNIT_ASSERT_EQUAL(std::string("princely_musings"), retract->getNode()); + CPPUNIT_ASSERT_EQUAL(true, retract->isNotify().get()); + } + + { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<pubsub xmlns='http://jabber.org/protocol/pubsub'>" + "<retract node='princely_musings' notify='0' xmlns='http://jabber.org/protocol/pubsub'>" + "<item id='ae890ac52d0df67ed7cfdf51b644e901' xmlns='http://jabber.org/protocol/pubsub'/>" + "</retract>" + "</pubsub>")); + + auto payload = parser.getPayload<ContainerPayload<PubSubPayload>>(); + auto retract = std::dynamic_pointer_cast<PubSubRetract>(payload->getPayload()); + CPPUNIT_ASSERT(retract); + CPPUNIT_ASSERT_EQUAL(std::string("princely_musings"), retract->getNode()); + CPPUNIT_ASSERT_EQUAL(false, retract->isNotify().get()); + } + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(PubSubRetractParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp index 800f48c..2deca6e 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp @@ -14,27 +14,27 @@ using namespace Swift; class RawXMLPayloadParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(RawXMLPayloadParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - RawXMLPayloadParserTest() {} - - void testParse() { - RawXMLPayloadParser testling; - PayloadParserTester parser(&testling); - - std::string xml = - "<foo foo-attr=\"foo-val\" xmlns=\"ns:foo\">" - "<bar bar-attr=\"bar-val\" xmlns=\"ns:bar\"/>" - "<baz baz-attr=\"baz-val\" xmlns=\"ns:baz\"/>" - "</foo>"; - CPPUNIT_ASSERT(parser.parse(xml)); - - RawXMLPayload* payload = dynamic_cast<RawXMLPayload*>(testling.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(xml, payload->getRawXML()); - } + CPPUNIT_TEST_SUITE(RawXMLPayloadParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + RawXMLPayloadParserTest() {} + + void testParse() { + RawXMLPayloadParser testling; + PayloadParserTester parser(&testling); + + std::string xml = + "<foo foo-attr=\"foo-val\" xmlns=\"ns:foo\">" + "<bar bar-attr=\"bar-val\" xmlns=\"ns:bar\"/>" + "<baz baz-attr=\"baz-val\" xmlns=\"ns:baz\"/>" + "</foo>"; + CPPUNIT_ASSERT(parser.parse(xml)); + + RawXMLPayload* payload = dynamic_cast<RawXMLPayload*>(testling.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(xml, payload->getRawXML()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(RawXMLPayloadParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ReplaceTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ReplaceTest.cpp index c3f410f..6d77d4a 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ReplaceTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ReplaceTest.cpp @@ -4,6 +4,12 @@ * 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 <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> @@ -13,24 +19,24 @@ using namespace Swift; class ReplaceParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ReplaceParserTest); - CPPUNIT_TEST(testParseTrivial); - CPPUNIT_TEST(testParseChild); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(ReplaceParserTest); + CPPUNIT_TEST(testParseTrivial); + CPPUNIT_TEST(testParseChild); + CPPUNIT_TEST_SUITE_END(); - public: - void testParseTrivial() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<replace id='bad1' xmlns='http://swift.im/protocol/replace'/>")); - Replace::ref payload = boost::dynamic_pointer_cast <Replace>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(std::string("bad1"), payload->getID()); - } - void testParseChild() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<replace id='bad1' xmlns='http://swift.im/protocol/replace' ><child xmlns='blah' id=\"hi\"/></replace>")); - Replace::ref payload = boost::dynamic_pointer_cast <Replace>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(std::string("bad1"), payload->getID()); - } + public: + void testParseTrivial() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<replace id='bad1' xmlns='http://swift.im/protocol/replace'/>")); + Replace::ref payload = std::dynamic_pointer_cast <Replace>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(std::string("bad1"), payload->getID()); + } + void testParseChild() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<replace id='bad1' xmlns='http://swift.im/protocol/replace' ><child xmlns='blah' id=\"hi\"/></replace>")); + Replace::ref payload = std::dynamic_pointer_cast <Replace>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(std::string("bad1"), payload->getID()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ReplaceParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp index 4c2b377..5c786c5 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp @@ -14,31 +14,31 @@ using namespace Swift; class ResourceBindParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ResourceBindParserTest); - CPPUNIT_TEST(testParse_JID); - CPPUNIT_TEST(testParse_Resource); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(ResourceBindParserTest); + CPPUNIT_TEST(testParse_JID); + CPPUNIT_TEST(testParse_Resource); + CPPUNIT_TEST_SUITE_END(); - public: - ResourceBindParserTest() {} + public: + ResourceBindParserTest() {} - void testParse_JID() { - PayloadsParserTester parser; + void testParse_JID() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><jid>somenode@example.com/someresource</jid></bind>")); + CPPUNIT_ASSERT(parser.parse("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><jid>somenode@example.com/someresource</jid></bind>")); - ResourceBind* payload = dynamic_cast<ResourceBind*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(JID("somenode@example.com/someresource"), payload->getJID()); - } + ResourceBind* payload = dynamic_cast<ResourceBind*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(JID("somenode@example.com/someresource"), payload->getJID()); + } - void testParse_Resource() { - PayloadsParserTester parser; + void testParse_Resource() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>someresource</resource></bind>")); + CPPUNIT_ASSERT(parser.parse("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>someresource</resource></bind>")); - ResourceBind* payload = dynamic_cast<ResourceBind*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("someresource"), payload->getResource()); - } + ResourceBind* payload = dynamic_cast<ResourceBind*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("someresource"), payload->getResource()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ResourceBindParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp index e01a811..da5d978 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -14,58 +14,58 @@ using namespace Swift; class ResultSetParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ResultSetParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParseFirstNoIndex); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(ResultSetParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParseFirstNoIndex); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<set xmlns=\"http://jabber.org/protocol/rsm\">" - "<max>100</max>" - "<count>800</count>" - "<index>0</index>" - "<first index=\"123\">stpeter@jabber.org</first>" - "<last>peterpan@neverland.lit</last>" - "<before>decaf-badba-dbad1</before>" - "<after>09af3-cc343-b409f</after>" - "</set>")); + public: + void testParse() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>100</max>" + "<count>800</count>" + "<index>0</index>" + "<first index=\"123\">stpeter@jabber.org</first>" + "<last>peterpan@neverland.lit</last>" + "<before>decaf-badba-dbad1</before>" + "<after>09af3-cc343-b409f</after>" + "</set>")); - boost::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getMaxItems()); - CPPUNIT_ASSERT_EQUAL(100, *payload->getMaxItems()); - CPPUNIT_ASSERT(payload->getCount()); - CPPUNIT_ASSERT_EQUAL(800, *payload->getCount()); - CPPUNIT_ASSERT(payload->getIndex()); - CPPUNIT_ASSERT_EQUAL(0, *payload->getIndex()); - CPPUNIT_ASSERT(payload->getFirstID()); - CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID()); - CPPUNIT_ASSERT(payload->getFirstIDIndex()); - CPPUNIT_ASSERT_EQUAL(123, *payload->getFirstIDIndex()); - CPPUNIT_ASSERT(payload->getLastID()); - CPPUNIT_ASSERT_EQUAL(std::string("peterpan@neverland.lit"), *payload->getLastID()); - CPPUNIT_ASSERT(payload->getBefore()); - CPPUNIT_ASSERT_EQUAL(std::string("decaf-badba-dbad1"), *payload->getBefore()); - CPPUNIT_ASSERT(payload->getAfter()); - CPPUNIT_ASSERT_EQUAL(std::string("09af3-cc343-b409f"), *payload->getAfter()); - } + std::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getMaxItems()); + CPPUNIT_ASSERT_EQUAL(100, *payload->getMaxItems()); + CPPUNIT_ASSERT(payload->getCount()); + CPPUNIT_ASSERT_EQUAL(800, *payload->getCount()); + CPPUNIT_ASSERT(payload->getIndex()); + CPPUNIT_ASSERT_EQUAL(0, *payload->getIndex()); + CPPUNIT_ASSERT(payload->getFirstID()); + CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID()); + CPPUNIT_ASSERT(payload->getFirstIDIndex()); + CPPUNIT_ASSERT_EQUAL(123, *payload->getFirstIDIndex()); + CPPUNIT_ASSERT(payload->getLastID()); + CPPUNIT_ASSERT_EQUAL(std::string("peterpan@neverland.lit"), *payload->getLastID()); + CPPUNIT_ASSERT(payload->getBefore()); + CPPUNIT_ASSERT_EQUAL(std::string("decaf-badba-dbad1"), *payload->getBefore()); + CPPUNIT_ASSERT(payload->getAfter()); + CPPUNIT_ASSERT_EQUAL(std::string("09af3-cc343-b409f"), *payload->getAfter()); + } - void testParseFirstNoIndex() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<set xmlns=\"http://jabber.org/protocol/rsm\">" - "<first>stpeter@jabber.org</first>" - "</set>")); + void testParseFirstNoIndex() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<first>stpeter@jabber.org</first>" + "</set>")); - boost::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>(); - CPPUNIT_ASSERT(!!payload); - CPPUNIT_ASSERT(payload->getFirstID()); - CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID()); - CPPUNIT_ASSERT(!payload->getFirstIDIndex()); - } + std::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getFirstID()); + CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID()); + CPPUNIT_ASSERT(!payload->getFirstIDIndex()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ResultSetParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp index 1a18d6d..a94a6fe 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp @@ -14,39 +14,39 @@ using namespace Swift; class RosterItemExchangeParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(RosterItemExchangeParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<x xmlns=\"http://jabber.org/protocol/rosterx\">" - "<item action=\"add\" jid=\"foo@bar.com\" name=\"Foo @ Bar\">" - "<group>Group 1</group>" - "<group>Group 2</group>" - "</item>" - "<item action=\"modify\" jid=\"baz@blo.com\" name=\"Baz\"/>" - "</x>")); - - RosterItemExchangePayload* payload = dynamic_cast<RosterItemExchangePayload*>(parser.getPayload().get()); - const RosterItemExchangePayload::RosterItemExchangePayloadItems& items = payload->getItems(); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); - - CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), items[0].getJID()); - CPPUNIT_ASSERT_EQUAL(std::string("Foo @ Bar"), items[0].getName()); - CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Item::Add, items[0].getAction()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items[0].getGroups().size()); - CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); - - CPPUNIT_ASSERT_EQUAL(JID("baz@blo.com"), items[1].getJID()); - CPPUNIT_ASSERT_EQUAL(std::string("Baz"), items[1].getName()); - CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Item::Modify, items[1].getAction()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), items[1].getGroups().size()); - } + CPPUNIT_TEST_SUITE(RosterItemExchangeParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<x xmlns=\"http://jabber.org/protocol/rosterx\">" + "<item action=\"add\" jid=\"foo@bar.com\" name=\"Foo @ Bar\">" + "<group>Group 1</group>" + "<group>Group 2</group>" + "</item>" + "<item action=\"modify\" jid=\"baz@blo.com\" name=\"Baz\"/>" + "</x>")); + + RosterItemExchangePayload* payload = dynamic_cast<RosterItemExchangePayload*>(parser.getPayload().get()); + const RosterItemExchangePayload::RosterItemExchangePayloadItems& items = payload->getItems(); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), items[0].getJID()); + CPPUNIT_ASSERT_EQUAL(std::string("Foo @ Bar"), items[0].getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Item::Add, items[0].getAction()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items[0].getGroups().size()); + CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); + + CPPUNIT_ASSERT_EQUAL(JID("baz@blo.com"), items[1].getJID()); + CPPUNIT_ASSERT_EQUAL(std::string("Baz"), items[1].getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemExchangePayload::Item::Modify, items[1].getAction()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), items[1].getGroups().size()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(RosterItemExchangeParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp index d1e1b45..261dad2 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp @@ -14,88 +14,88 @@ using namespace Swift; class RosterParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(RosterParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_ItemWithUnknownContent); - CPPUNIT_TEST(testParse_WithVersion); - CPPUNIT_TEST(testParse_WithEmptyVersion); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='jabber:iq:roster'>" - " <item jid='foo@bar.com' name='Foo @ Bar' subscription='from' ask='subscribe'>" - " <group>Group 1</group>" - " <group>Group 2</group>" - " </item>" - " <item jid='baz@blo.com' name='Baz'/>" - "</query>")); - - RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); - - CPPUNIT_ASSERT(!payload->getVersion()); - const RosterPayload::RosterItemPayloads& items = payload->getItems(); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); - - CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), items[0].getJID()); - CPPUNIT_ASSERT_EQUAL(std::string("Foo @ Bar"), items[0].getName()); - CPPUNIT_ASSERT_EQUAL(RosterItemPayload::From, items[0].getSubscription()); - CPPUNIT_ASSERT(items[0].getSubscriptionRequested()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items[0].getGroups().size()); - CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); - - CPPUNIT_ASSERT_EQUAL(JID("baz@blo.com"), items[1].getJID()); - CPPUNIT_ASSERT_EQUAL(std::string("Baz"), items[1].getName()); - CPPUNIT_ASSERT_EQUAL(RosterItemPayload::None, items[1].getSubscription()); - CPPUNIT_ASSERT(!items[1].getSubscriptionRequested()); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), items[1].getGroups().size()); - } - - void testParse_ItemWithUnknownContent() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='jabber:iq:roster'>" - " <item jid='foo@bar.com' name='Foo @ Bar' subscription='from' ask='subscribe'>" - " <group>Group 1</group>" - " <foo xmlns=\"http://example.com\"><bar>Baz</bar></foo>" - " <group>Group 2</group>" - " <baz><fum>foo</fum></baz>" - " </item>" - "</query>")); - - RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); - const RosterPayload::RosterItemPayloads& items = payload->getItems(); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), items.size()); - CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); - CPPUNIT_ASSERT_EQUAL(std::string( - "<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>" - "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>" - ), items[0].getUnknownContent()); - } - - void testParse_WithVersion() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:roster' ver='ver10'/>")); - - RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload->getVersion()); - CPPUNIT_ASSERT_EQUAL(std::string("ver10"), *payload->getVersion()); - } - - void testParse_WithEmptyVersion() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:roster' ver=''/>")); - - RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload->getVersion()); - CPPUNIT_ASSERT_EQUAL(std::string(""), *payload->getVersion()); - } + CPPUNIT_TEST_SUITE(RosterParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_ItemWithUnknownContent); + CPPUNIT_TEST(testParse_WithVersion); + CPPUNIT_TEST(testParse_WithEmptyVersion); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='jabber:iq:roster'>" + " <item jid='foo@bar.com' name='Foo @ Bar' subscription='from' ask='subscribe'>" + " <group>Group 1</group>" + " <group>Group 2</group>" + " </item>" + " <item jid='baz@blo.com' name='Baz'/>" + "</query>")); + + RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); + + CPPUNIT_ASSERT(!payload->getVersion()); + const RosterPayload::RosterItemPayloads& items = payload->getItems(); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), items[0].getJID()); + CPPUNIT_ASSERT_EQUAL(std::string("Foo @ Bar"), items[0].getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemPayload::From, items[0].getSubscription()); + CPPUNIT_ASSERT(items[0].getSubscriptionRequested()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items[0].getGroups().size()); + CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); + + CPPUNIT_ASSERT_EQUAL(JID("baz@blo.com"), items[1].getJID()); + CPPUNIT_ASSERT_EQUAL(std::string("Baz"), items[1].getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemPayload::None, items[1].getSubscription()); + CPPUNIT_ASSERT(!items[1].getSubscriptionRequested()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), items[1].getGroups().size()); + } + + void testParse_ItemWithUnknownContent() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='jabber:iq:roster'>" + " <item jid='foo@bar.com' name='Foo @ Bar' subscription='from' ask='subscribe'>" + " <group>Group 1</group>" + " <foo xmlns=\"http://example.com\"><bar>Baz</bar></foo>" + " <group>Group 2</group>" + " <baz><fum>foo</fum></baz>" + " </item>" + "</query>")); + + RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); + const RosterPayload::RosterItemPayloads& items = payload->getItems(); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), items.size()); + CPPUNIT_ASSERT_EQUAL(std::string("Group 1"), items[0].getGroups()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("Group 2"), items[0].getGroups()[1]); + CPPUNIT_ASSERT_EQUAL(std::string( + "<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>" + "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>" + ), items[0].getUnknownContent()); + } + + void testParse_WithVersion() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:roster' ver='ver10'/>")); + + RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string("ver10"), *payload->getVersion()); + } + + void testParse_WithEmptyVersion() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:roster' ver=''/>")); + + RosterPayload* payload = dynamic_cast<RosterPayload*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string(""), *payload->getVersion()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(RosterParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp index 492e0ec..5fe4168 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,175 +7,175 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> #include <Swiften/Elements/SearchPayload.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; class SearchPayloadParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SearchPayloadParserTest); - CPPUNIT_TEST(testParse_FormRequestResponse); - CPPUNIT_TEST(testParse_Results); - CPPUNIT_TEST(testParse_FormRequestResponse_XDATA); - CPPUNIT_TEST(testParse_Results_XDATA); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse_FormRequestResponse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"jabber:iq:search\">" - "<instructions>Foo</instructions>" - "<first/>" - "<last/>" - "</query>" - )); - - SearchPayload::ref payload = parser.getPayload<SearchPayload>(); - CPPUNIT_ASSERT_EQUAL(std::string("Foo"), *payload->getInstructions()); - CPPUNIT_ASSERT(payload->getFirst()); - CPPUNIT_ASSERT(payload->getLast()); - CPPUNIT_ASSERT(!payload->getNick()); - } - - void testParse_Results() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"jabber:iq:search\">" - "<item jid=\"juliet@capulet.com\">" - "<first>Juliet</first>" - "<last>Capulet</last>" - "<nick>JuliC</nick>" - "<email>juliet@shakespeare.lit</email>" - "</item>" - "<item jid=\"tybalt@shakespeare.lit\">" - "<first>Tybalt</first>" - "<last>Capulet</last>" - "<nick>ty</nick>" - "<email>tybalt@shakespeare.lit</email>" - "</item>" - "</query>" - )); - - SearchPayload::ref payload = parser.getPayload<SearchPayload>(); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getItems().size())); - CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.com"), payload->getItems()[0].jid); - CPPUNIT_ASSERT_EQUAL(std::string("Juliet"), payload->getItems()[0].first); - CPPUNIT_ASSERT_EQUAL(std::string("Capulet"), payload->getItems()[0].last); - CPPUNIT_ASSERT_EQUAL(std::string("JuliC"), payload->getItems()[0].nick); - CPPUNIT_ASSERT_EQUAL(std::string("juliet@shakespeare.lit"), payload->getItems()[0].email); - CPPUNIT_ASSERT_EQUAL(JID("tybalt@shakespeare.lit"), payload->getItems()[1].jid); - } - - void testParse_FormRequestResponse_XDATA() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns='jabber:iq:search'>" - "<instructions>" - "Use the enclosed form to search. If your Jabber client does not" - " support Data Forms, visit http://shakespeare.lit/" - "</instructions>" - "<x xmlns='jabber:x:data' type='form'>" - "<title>User Directory Search</title>" - "<instructions>" - "Please provide the following information" - " to search for Shakespearean characters." - "</instructions>" - "<field type='hidden'" - " var='FORM_TYPE'>" - "<value>jabber:iq:search</value>" - "</field>" - "<field type='text-single'" - " label='Given Name'" - " var='first'/>" - "<field type='text-single'" - " label='Family Name'" - " var='last'/>" - "<field type='list-single'" - " label='Gender'" - " var='x-gender'>" - "<option label='Male'><value>male</value></option>" - "<option label='Female'><value>female</value></option>" - "</field>" - "</x>" - "</query>" - )); - - SearchPayload::ref payload = parser.getPayload<SearchPayload>(); - CPPUNIT_ASSERT_EQUAL(std::string("Use the enclosed form to search. If your Jabber client does not" - " support Data Forms, visit http://shakespeare.lit/"), *payload->getInstructions()); - CPPUNIT_ASSERT(payload->getForm()); - CPPUNIT_ASSERT_EQUAL(std::string("Please provide the following information" - " to search for Shakespearean characters."), payload->getForm()->getInstructions()); - } - - void testParse_Results_XDATA() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:search'>" - " <x xmlns='jabber:x:data' type='result'>" - " <field type='hidden' var='FORM_TYPE'>" - " <value>jabber:iq:search</value>" - " </field>" - " <reported>" - " <field var='first' label='Given Name' type='text-single'/>" - " <field var='last' label='Family Name' type='text-single'/>" - " <field var='jid' label='Jabber ID' type='jid-single'/>" - " <field var='x-gender' label='Gender' type='list-single'/>" - " </reported>" - " <item>" - " <field var='first'><value>Benvolio</value></field>" - " <field var='last'><value>Montague</value></field>" - " <field var='jid'><value>benvolio@montague.net</value></field>" - " <field var='x-gender'><value>male</value></field>" - " </item>" - " <item>" - " <field var='first'><value>Romeo</value></field>" - " <field var='last'><value>Montague</value></field>" - " <field var='jid'><value>romeo@montague.net</value></field>" - " <field var='x-gender'><value>male</value></field>" - " </item>" - " </x>" - "</query>")); - SearchPayload::ref payload = parser.getPayload<SearchPayload>(); - CPPUNIT_ASSERT(payload); - - Form::ref dataForm = payload->getForm(); - CPPUNIT_ASSERT(dataForm); - - Form::FormItem reported = dataForm->getReportedFields(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), reported.size()); - - std::vector<Form::FormItem> items = dataForm->getItems(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); - - Form::FormItem item = items[0]; - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); - - CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("benvolio@montague.net"), item[2]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); - - item = items[1]; - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); - - CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("romeo@montague.net"), item[2]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); - } + CPPUNIT_TEST_SUITE(SearchPayloadParserTest); + CPPUNIT_TEST(testParse_FormRequestResponse); + CPPUNIT_TEST(testParse_Results); + CPPUNIT_TEST(testParse_FormRequestResponse_XDATA); + CPPUNIT_TEST(testParse_Results_XDATA); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse_FormRequestResponse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"jabber:iq:search\">" + "<instructions>Foo</instructions>" + "<first/>" + "<last/>" + "</query>" + )); + + SearchPayload::ref payload = parser.getPayload<SearchPayload>(); + CPPUNIT_ASSERT_EQUAL(std::string("Foo"), *payload->getInstructions()); + CPPUNIT_ASSERT(payload->getFirst()); + CPPUNIT_ASSERT(payload->getLast()); + CPPUNIT_ASSERT(!payload->getNick()); + } + + void testParse_Results() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"jabber:iq:search\">" + "<item jid=\"juliet@capulet.com\">" + "<first>Juliet</first>" + "<last>Capulet</last>" + "<nick>JuliC</nick>" + "<email>juliet@shakespeare.lit</email>" + "</item>" + "<item jid=\"tybalt@shakespeare.lit\">" + "<first>Tybalt</first>" + "<last>Capulet</last>" + "<nick>ty</nick>" + "<email>tybalt@shakespeare.lit</email>" + "</item>" + "</query>" + )); + + SearchPayload::ref payload = parser.getPayload<SearchPayload>(); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getItems().size())); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.com"), payload->getItems()[0].jid); + CPPUNIT_ASSERT_EQUAL(std::string("Juliet"), payload->getItems()[0].first); + CPPUNIT_ASSERT_EQUAL(std::string("Capulet"), payload->getItems()[0].last); + CPPUNIT_ASSERT_EQUAL(std::string("JuliC"), payload->getItems()[0].nick); + CPPUNIT_ASSERT_EQUAL(std::string("juliet@shakespeare.lit"), payload->getItems()[0].email); + CPPUNIT_ASSERT_EQUAL(JID("tybalt@shakespeare.lit"), payload->getItems()[1].jid); + } + + void testParse_FormRequestResponse_XDATA() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='jabber:iq:search'>" + "<instructions>" + "Use the enclosed form to search. If your Jabber client does not" + " support Data Forms, visit http://shakespeare.lit/" + "</instructions>" + "<x xmlns='jabber:x:data' type='form'>" + "<title>User Directory Search</title>" + "<instructions>" + "Please provide the following information" + " to search for Shakespearean characters." + "</instructions>" + "<field type='hidden'" + " var='FORM_TYPE'>" + "<value>jabber:iq:search</value>" + "</field>" + "<field type='text-single'" + " label='Given Name'" + " var='first'/>" + "<field type='text-single'" + " label='Family Name'" + " var='last'/>" + "<field type='list-single'" + " label='Gender'" + " var='x-gender'>" + "<option label='Male'><value>male</value></option>" + "<option label='Female'><value>female</value></option>" + "</field>" + "</x>" + "</query>" + )); + + SearchPayload::ref payload = parser.getPayload<SearchPayload>(); + CPPUNIT_ASSERT_EQUAL(std::string("Use the enclosed form to search. If your Jabber client does not" + " support Data Forms, visit http://shakespeare.lit/"), *payload->getInstructions()); + CPPUNIT_ASSERT(payload->getForm()); + CPPUNIT_ASSERT_EQUAL(std::string("Please provide the following information" + " to search for Shakespearean characters."), payload->getForm()->getInstructions()); + } + + void testParse_Results_XDATA() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<query xmlns='jabber:iq:search'>" + " <x xmlns='jabber:x:data' type='result'>" + " <field type='hidden' var='FORM_TYPE'>" + " <value>jabber:iq:search</value>" + " </field>" + " <reported>" + " <field var='first' label='Given Name' type='text-single'/>" + " <field var='last' label='Family Name' type='text-single'/>" + " <field var='jid' label='Jabber ID' type='jid-single'/>" + " <field var='x-gender' label='Gender' type='list-single'/>" + " </reported>" + " <item>" + " <field var='first'><value>Benvolio</value></field>" + " <field var='last'><value>Montague</value></field>" + " <field var='jid'><value>benvolio@montague.net</value></field>" + " <field var='x-gender'><value>male</value></field>" + " </item>" + " <item>" + " <field var='first'><value>Romeo</value></field>" + " <field var='last'><value>Montague</value></field>" + " <field var='jid'><value>romeo@montague.net</value></field>" + " <field var='x-gender'><value>male</value></field>" + " </item>" + " </x>" + "</query>")); + SearchPayload::ref payload = parser.getPayload<SearchPayload>(); + CPPUNIT_ASSERT(payload); + + Form::ref dataForm = payload->getForm(); + CPPUNIT_ASSERT(dataForm); + + Form::FormItem reported = dataForm->getReportedFields(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), reported.size()); + + std::vector<Form::FormItem> items = dataForm->getItems(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), items.size()); + + Form::FormItem item = items[0]; + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); + + CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("benvolio@montague.net"), item[2]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); + + item = items[1]; + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); + + CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("romeo@montague.net"), item[2]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SearchPayloadParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp index 14f1f17..c27b716 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp @@ -14,38 +14,38 @@ using namespace Swift; class SecurityLabelParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SecurityLabelParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - SecurityLabelParserTest() {} - - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" - "<displaymarking fgcolor=\"black\" bgcolor=\"red\">SECRET</displaymarking>" - "<label>" - "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>" - "</label>" - "<equivalentlabel>" - "<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>" - "</equivalentlabel>" - "<equivalentlabel>" - "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>" - "</equivalentlabel>" - "</securitylabel>")); - - SecurityLabel* payload = dynamic_cast<SecurityLabel*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("SECRET"), payload->getDisplayMarking()); - CPPUNIT_ASSERT_EQUAL(std::string("black"), payload->getForegroundColor()); - CPPUNIT_ASSERT_EQUAL(std::string("red"), payload->getBackgroundColor()); - CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"), payload->getLabel()); - CPPUNIT_ASSERT_EQUAL(std::string("<icismlabel classification=\"S\" disseminationControls=\"FOUO\" ownerProducer=\"USA\" xmlns=\"http://example.gov/IC-ISM/0\"/>"), payload->getEquivalentLabels()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>"), payload->getEquivalentLabels()[1]); - } + CPPUNIT_TEST_SUITE(SecurityLabelParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + SecurityLabelParserTest() {} + + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking fgcolor=\"black\" bgcolor=\"red\">SECRET</displaymarking>" + "<label>" + "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>" + "</label>" + "<equivalentlabel>" + "<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>" + "</equivalentlabel>" + "<equivalentlabel>" + "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>" + "</equivalentlabel>" + "</securitylabel>")); + + SecurityLabel* payload = dynamic_cast<SecurityLabel*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("SECRET"), payload->getDisplayMarking()); + CPPUNIT_ASSERT_EQUAL(std::string("black"), payload->getForegroundColor()); + CPPUNIT_ASSERT_EQUAL(std::string("red"), payload->getBackgroundColor()); + CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"), payload->getLabel()); + CPPUNIT_ASSERT_EQUAL(std::string("<icismlabel classification=\"S\" disseminationControls=\"FOUO\" ownerProducer=\"USA\" xmlns=\"http://example.gov/IC-ISM/0\"/>"), payload->getEquivalentLabels()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>"), payload->getEquivalentLabels()[1]); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SecurityLabelParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp index f1745d0..2b992b1 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp @@ -14,50 +14,50 @@ using namespace Swift; class SecurityLabelsCatalogParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SecurityLabelsCatalogParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - SecurityLabelsCatalogParserTest() {} - - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<catalog desc=\"an example set of labels\" name=\"Default\" to=\"example.com\" xmlns=\"urn:xmpp:sec-label:catalog:2\">" - "<item selector='Classified|SECRET'>" - "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" - "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>" - "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel></label>" - "</securitylabel>" - "</item>" - "<item selector='Classified|CONFIDENTIAL' default='true'>" - "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" - "<displaymarking bgcolor=\"navy\" fgcolor=\"black\">CONFIDENTIAL</displaymarking>" - "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel></label>" - "</securitylabel>" - "</item>" - "<item selector='Unclassified|UNCLASSIFIED'/>" - "</catalog>")); - - SecurityLabelsCatalog* payload = dynamic_cast<SecurityLabelsCatalog*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Default"), payload->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("an example set of labels"), payload->getDescription()); - CPPUNIT_ASSERT_EQUAL(JID("example.com"), payload->getTo()); - CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(payload->getItems().size())); - CPPUNIT_ASSERT_EQUAL(std::string("SECRET"), payload->getItems()[0].getLabel()->getDisplayMarking()); - CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"), payload->getItems()[0].getLabel()->getLabel()); - CPPUNIT_ASSERT_EQUAL(false, payload->getItems()[0].getIsDefault()); - CPPUNIT_ASSERT_EQUAL(std::string("Classified|SECRET"), payload->getItems()[0].getSelector()); - CPPUNIT_ASSERT_EQUAL(std::string("CONFIDENTIAL"), payload->getItems()[1].getLabel()->getDisplayMarking()); - CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel>"), payload->getItems()[1].getLabel()->getLabel()); - CPPUNIT_ASSERT_EQUAL(true, payload->getItems()[1].getIsDefault()); - CPPUNIT_ASSERT_EQUAL(std::string("Classified|CONFIDENTIAL"), payload->getItems()[1].getSelector()); - CPPUNIT_ASSERT_EQUAL(false, payload->getItems()[2].getIsDefault()); - CPPUNIT_ASSERT_EQUAL(std::string("Unclassified|UNCLASSIFIED"), payload->getItems()[2].getSelector()); - CPPUNIT_ASSERT(!payload->getItems()[2].getLabel()); - } + CPPUNIT_TEST_SUITE(SecurityLabelsCatalogParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + SecurityLabelsCatalogParserTest() {} + + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<catalog desc=\"an example set of labels\" name=\"Default\" to=\"example.com\" xmlns=\"urn:xmpp:sec-label:catalog:2\">" + "<item selector='Classified|SECRET'>" + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>" + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel></label>" + "</securitylabel>" + "</item>" + "<item selector='Classified|CONFIDENTIAL' default='true'>" + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking bgcolor=\"navy\" fgcolor=\"black\">CONFIDENTIAL</displaymarking>" + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel></label>" + "</securitylabel>" + "</item>" + "<item selector='Unclassified|UNCLASSIFIED'/>" + "</catalog>")); + + SecurityLabelsCatalog* payload = dynamic_cast<SecurityLabelsCatalog*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Default"), payload->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("an example set of labels"), payload->getDescription()); + CPPUNIT_ASSERT_EQUAL(JID("example.com"), payload->getTo()); + CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(payload->getItems().size())); + CPPUNIT_ASSERT_EQUAL(std::string("SECRET"), payload->getItems()[0].getLabel()->getDisplayMarking()); + CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"), payload->getItems()[0].getLabel()->getLabel()); + CPPUNIT_ASSERT_EQUAL(false, payload->getItems()[0].getIsDefault()); + CPPUNIT_ASSERT_EQUAL(std::string("Classified|SECRET"), payload->getItems()[0].getSelector()); + CPPUNIT_ASSERT_EQUAL(std::string("CONFIDENTIAL"), payload->getItems()[1].getLabel()->getDisplayMarking()); + CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel>"), payload->getItems()[1].getLabel()->getLabel()); + CPPUNIT_ASSERT_EQUAL(true, payload->getItems()[1].getIsDefault()); + CPPUNIT_ASSERT_EQUAL(std::string("Classified|CONFIDENTIAL"), payload->getItems()[1].getSelector()); + CPPUNIT_ASSERT_EQUAL(false, payload->getItems()[2].getIsDefault()); + CPPUNIT_ASSERT_EQUAL(std::string("Unclassified|UNCLASSIFIED"), payload->getItems()[2].getSelector()); + CPPUNIT_ASSERT(!payload->getItems()[2].getLabel()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SecurityLabelsCatalogParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp index 6650cb7..7471856 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp @@ -14,28 +14,28 @@ using namespace Swift; class SoftwareVersionParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SoftwareVersionParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - SoftwareVersionParserTest() {} - - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<query xmlns=\"jabber:iq:version\">" - "<name>myclient</name>" - "<version>1.0</version>" - "<os>Mac OS X</os>" - "</query>")); - - SoftwareVersion* payload = dynamic_cast<SoftwareVersion*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("myclient"), payload->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("1.0"), payload->getVersion()); - CPPUNIT_ASSERT_EQUAL(std::string("Mac OS X"), payload->getOS()); - } + CPPUNIT_TEST_SUITE(SoftwareVersionParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + SoftwareVersionParserTest() {} + + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"jabber:iq:version\">" + "<name>myclient</name>" + "<version>1.0</version>" + "<os>Mac OS X</os>" + "</query>")); + + SoftwareVersion* payload = dynamic_cast<SoftwareVersion*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("myclient"), payload->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("1.0"), payload->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string("Mac OS X"), payload->getOS()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SoftwareVersionParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp index 5c7f467..6b93637 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp @@ -14,21 +14,21 @@ using namespace Swift; class StatusParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StatusParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(StatusParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); - public: - StatusParserTest() {} + public: + StatusParserTest() {} - void testParse() { - PayloadsParserTester parser; + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse("<status>foo<baz>bar</baz>fum</status>")); + CPPUNIT_ASSERT(parser.parse("<status>foo<baz>bar</baz>fum</status>")); - Status* payload = dynamic_cast<Status*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("foobarfum"), payload->getText()); - } + Status* payload = dynamic_cast<Status*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("foobarfum"), payload->getText()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StatusParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp index 98653ef..94f14c6 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp @@ -14,61 +14,61 @@ using namespace Swift; class StatusShowParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StatusShowParserTest); - CPPUNIT_TEST(testParse_Invalid); - CPPUNIT_TEST(testParse_Away); - CPPUNIT_TEST(testParse_FFC); - CPPUNIT_TEST(testParse_XA); - CPPUNIT_TEST(testParse_DND); - CPPUNIT_TEST_SUITE_END(); - - public: - StatusShowParserTest() {} - - void testParse_Invalid() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<show>invalid</show>")); - - StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); - CPPUNIT_ASSERT(StatusShow::Online == payload->getType()); - } - - void testParse_Away() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<show>away</show>")); - - StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); - CPPUNIT_ASSERT(StatusShow::Away == payload->getType()); - } - - void testParse_FFC() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<show>chat</show>")); - - StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); - CPPUNIT_ASSERT(StatusShow::FFC == payload->getType()); - } - - void testParse_XA() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<show>xa</show>")); - - StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); - CPPUNIT_ASSERT(StatusShow::XA == payload->getType()); - } - - void testParse_DND() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse("<show>dnd</show>")); - - StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); - CPPUNIT_ASSERT(StatusShow::DND == payload->getType()); - } + CPPUNIT_TEST_SUITE(StatusShowParserTest); + CPPUNIT_TEST(testParse_Invalid); + CPPUNIT_TEST(testParse_Away); + CPPUNIT_TEST(testParse_FFC); + CPPUNIT_TEST(testParse_XA); + CPPUNIT_TEST(testParse_DND); + CPPUNIT_TEST_SUITE_END(); + + public: + StatusShowParserTest() {} + + void testParse_Invalid() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<show>invalid</show>")); + + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); + CPPUNIT_ASSERT(StatusShow::Online == payload->getType()); + } + + void testParse_Away() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<show>away</show>")); + + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); + CPPUNIT_ASSERT(StatusShow::Away == payload->getType()); + } + + void testParse_FFC() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<show>chat</show>")); + + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); + CPPUNIT_ASSERT(StatusShow::FFC == payload->getType()); + } + + void testParse_XA() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<show>xa</show>")); + + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); + CPPUNIT_ASSERT(StatusShow::XA == payload->getType()); + } + + void testParse_DND() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse("<show>dnd</show>")); + + StatusShow* payload = dynamic_cast<StatusShow*>(parser.getPayload().get()); + CPPUNIT_ASSERT(StatusShow::DND == payload->getType()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StatusShowParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp index 9797b6a..4430668 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp @@ -13,74 +13,74 @@ using namespace Swift; class StorageParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StorageParserTest); - CPPUNIT_TEST(testParse_Room); - CPPUNIT_TEST(testParse_MultipleRooms); - CPPUNIT_TEST(testParse_URL); - CPPUNIT_TEST_SUITE_END(); - - public: - StorageParserTest() {} - - void testParse_Room() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<storage xmlns='storage:bookmarks'>" - "<conference " - "name='Council of Oberon' " - "autojoin='true' jid='council@conference.underhill.org'>" - "<nick>Puck</nick>" - "<password>MyPass</password>" - "</conference>" - "</storage>")); - - Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); - std::vector<Storage::Room> rooms = payload->getRooms(); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rooms.size())); - CPPUNIT_ASSERT_EQUAL(std::string("Council of Oberon"), rooms[0].name); - CPPUNIT_ASSERT_EQUAL(JID("council@conference.underhill.org"), rooms[0].jid); - CPPUNIT_ASSERT(rooms[0].autoJoin); - CPPUNIT_ASSERT_EQUAL(std::string("Puck"), rooms[0].nick); - CPPUNIT_ASSERT_EQUAL(std::string("MyPass"), *rooms[0].password); - } - - void testParse_MultipleRooms() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<storage xmlns='storage:bookmarks'>" - "<conference " - "name='Council of Oberon' " - "jid='council@conference.underhill.org' />" - "<conference " - "name='Tea & jam party' " - "jid='teaparty@wonderland.lit' />" - "</storage>")); - - Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); - std::vector<Storage::Room> rooms = payload->getRooms(); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(rooms.size())); - CPPUNIT_ASSERT_EQUAL(std::string("Council of Oberon"), rooms[0].name); - CPPUNIT_ASSERT_EQUAL(JID("council@conference.underhill.org"), rooms[0].jid); - CPPUNIT_ASSERT_EQUAL(std::string("Tea & jam party"), rooms[1].name); - CPPUNIT_ASSERT_EQUAL(JID("teaparty@wonderland.lit"), rooms[1].jid); - } - - void testParse_URL() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<storage xmlns='storage:bookmarks'>" - "<url name='Complete Works of Shakespeare' url='http://the-tech.mit.edu/Shakespeare/'/>" - "</storage>")); - - Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); - std::vector<Storage::URL> urls = payload->getURLs(); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(urls.size())); - CPPUNIT_ASSERT_EQUAL(std::string("Complete Works of Shakespeare"), urls[0].name); - CPPUNIT_ASSERT_EQUAL(std::string("http://the-tech.mit.edu/Shakespeare/"), urls[0].url); - } + CPPUNIT_TEST_SUITE(StorageParserTest); + CPPUNIT_TEST(testParse_Room); + CPPUNIT_TEST(testParse_MultipleRooms); + CPPUNIT_TEST(testParse_URL); + CPPUNIT_TEST_SUITE_END(); + + public: + StorageParserTest() {} + + void testParse_Room() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<storage xmlns='storage:bookmarks'>" + "<conference " + "name='Council of Oberon' " + "autojoin='true' jid='council@conference.underhill.org'>" + "<nick>Puck</nick>" + "<password>MyPass</password>" + "</conference>" + "</storage>")); + + Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); + std::vector<Storage::Room> rooms = payload->getRooms(); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rooms.size())); + CPPUNIT_ASSERT_EQUAL(std::string("Council of Oberon"), rooms[0].name); + CPPUNIT_ASSERT_EQUAL(JID("council@conference.underhill.org"), rooms[0].jid); + CPPUNIT_ASSERT(rooms[0].autoJoin); + CPPUNIT_ASSERT_EQUAL(std::string("Puck"), rooms[0].nick); + CPPUNIT_ASSERT_EQUAL(std::string("MyPass"), *rooms[0].password); + } + + void testParse_MultipleRooms() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<storage xmlns='storage:bookmarks'>" + "<conference " + "name='Council of Oberon' " + "jid='council@conference.underhill.org' />" + "<conference " + "name='Tea & jam party' " + "jid='teaparty@wonderland.lit' />" + "</storage>")); + + Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); + std::vector<Storage::Room> rooms = payload->getRooms(); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(rooms.size())); + CPPUNIT_ASSERT_EQUAL(std::string("Council of Oberon"), rooms[0].name); + CPPUNIT_ASSERT_EQUAL(JID("council@conference.underhill.org"), rooms[0].jid); + CPPUNIT_ASSERT_EQUAL(std::string("Tea & jam party"), rooms[1].name); + CPPUNIT_ASSERT_EQUAL(JID("teaparty@wonderland.lit"), rooms[1].jid); + } + + void testParse_URL() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<storage xmlns='storage:bookmarks'>" + "<url name='Complete Works of Shakespeare' url='http://the-tech.mit.edu/Shakespeare/'/>" + "</storage>")); + + Storage* payload = dynamic_cast<Storage*>(parser.getPayload().get()); + std::vector<Storage::URL> urls = payload->getURLs(); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(urls.size())); + CPPUNIT_ASSERT_EQUAL(std::string("Complete Works of Shakespeare"), urls[0].name); + CPPUNIT_ASSERT_EQUAL(std::string("http://the-tech.mit.edu/Shakespeare/"), urls[0].url); + } }; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.cpp index 6909ec2..9b0679d 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.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. */ @@ -7,69 +7,69 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> #include <Swiften/Elements/StreamInitiation.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> using namespace Swift; class StreamInitiationParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StreamInitiationParserTest); - CPPUNIT_TEST(testParse_Request); - CPPUNIT_TEST(testParse_Response); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(StreamInitiationParserTest); + CPPUNIT_TEST(testParse_Request); + CPPUNIT_TEST(testParse_Response); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse_Request() { - PayloadsParserTester parser; + public: + void testParse_Request() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<si xmlns='http://jabber.org/protocol/si' id='a0' mime-type='text/plain' profile='http://jabber.org/protocol/si/profile/file-transfer'>" - "<file xmlns='http://jabber.org/protocol/si/profile/file-transfer' name='test.txt' size='1022'>" - "<desc>This is info about the file.</desc>" - "</file>" - "<feature xmlns='http://jabber.org/protocol/feature-neg'>" - "<x xmlns='jabber:x:data' type='form'>" - "<field var='stream-method' type='list-single'>" - "<option><value>http://jabber.org/protocol/bytestreams</value></option>" - "<option><value>jabber:iq:oob</value></option>" - "<option><value>http://jabber.org/protocol/ibb</value></option>" - "</field>" - "</x>" - "</feature>" - "</si>" - )); + CPPUNIT_ASSERT(parser.parse( + "<si xmlns='http://jabber.org/protocol/si' id='a0' mime-type='text/plain' profile='http://jabber.org/protocol/si/profile/file-transfer'>" + "<file xmlns='http://jabber.org/protocol/si/profile/file-transfer' name='test.txt' size='1022'>" + "<desc>This is info about the file.</desc>" + "</file>" + "<feature xmlns='http://jabber.org/protocol/feature-neg'>" + "<x xmlns='jabber:x:data' type='form'>" + "<field var='stream-method' type='list-single'>" + "<option><value>http://jabber.org/protocol/bytestreams</value></option>" + "<option><value>jabber:iq:oob</value></option>" + "<option><value>http://jabber.org/protocol/ibb</value></option>" + "</field>" + "</x>" + "</feature>" + "</si>" + )); - StreamInitiation::ref si = parser.getPayload<StreamInitiation>(); - CPPUNIT_ASSERT(si->getIsFileTransfer()); - CPPUNIT_ASSERT(si->getFileInfo()); - CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), si->getFileInfo()->getName()); - CPPUNIT_ASSERT(1022 == si->getFileInfo()->getSize()); - CPPUNIT_ASSERT_EQUAL(std::string("This is info about the file."), si->getFileInfo()->getDescription()); - CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(si->getProvidedMethods().size())); - CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/bytestreams"), si->getProvidedMethods()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:oob"), si->getProvidedMethods()[1]); - CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/ibb"), si->getProvidedMethods()[2]); - } + StreamInitiation::ref si = parser.getPayload<StreamInitiation>(); + CPPUNIT_ASSERT(si->getIsFileTransfer()); + CPPUNIT_ASSERT(si->getFileInfo()); + CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), si->getFileInfo()->getName()); + CPPUNIT_ASSERT(1022 == si->getFileInfo()->getSize()); + CPPUNIT_ASSERT_EQUAL(std::string("This is info about the file."), si->getFileInfo()->getDescription()); + CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(si->getProvidedMethods().size())); + CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/bytestreams"), si->getProvidedMethods()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:oob"), si->getProvidedMethods()[1]); + CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/ibb"), si->getProvidedMethods()[2]); + } - void testParse_Response() { - PayloadsParserTester parser; + void testParse_Response() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<si xmlns='http://jabber.org/protocol/si'>" - "<feature xmlns='http://jabber.org/protocol/feature-neg'>" - "<x xmlns='jabber:x:data' type='submit'>" - "<field var='stream-method'>" - "<value>http://jabber.org/protocol/bytestreams</value>" - "</field>" - "</x>" - "</feature>" - "</si>" - )); + CPPUNIT_ASSERT(parser.parse( + "<si xmlns='http://jabber.org/protocol/si'>" + "<feature xmlns='http://jabber.org/protocol/feature-neg'>" + "<x xmlns='jabber:x:data' type='submit'>" + "<field var='stream-method'>" + "<value>http://jabber.org/protocol/bytestreams</value>" + "</field>" + "</x>" + "</feature>" + "</si>" + )); - StreamInitiation::ref si = parser.getPayload<StreamInitiation>(); - CPPUNIT_ASSERT(si->getIsFileTransfer()); - CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/bytestreams"), si->getRequestedMethod()); - } + StreamInitiation::ref si = parser.getPayload<StreamInitiation>(); + CPPUNIT_ASSERT(si->getIsFileTransfer()); + CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/bytestreams"), si->getRequestedMethod()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StreamInitiationParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp index 2d5d628..98a147f 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp @@ -4,101 +4,107 @@ * 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 <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Parser/PayloadParsers/UserLocationParser.h> -#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Base/DateTime.h> #include <Swiften/Elements/UserLocation.h> -#include <Swiften/Base/DateTime.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Parser/PayloadParsers/UserLocationParser.h> using namespace Swift; class UserLocationParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(UserLocationParserTest); - CPPUNIT_TEST(testParse_with_all_variables); - CPPUNIT_TEST(testParse_with_Some_variables); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(UserLocationParserTest); + CPPUNIT_TEST(testParse_with_all_variables); + CPPUNIT_TEST(testParse_with_Some_variables); + CPPUNIT_TEST_SUITE_END(); - public: - UserLocationParserTest() {} + public: + UserLocationParserTest() {} - void testParse_with_all_variables() { - PayloadsParserTester parser; + void testParse_with_all_variables() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" - "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" - "<lat>1.67</lat><accuracy>0.95</accuracy><description>Nice</description>" - "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" - "<building>First</building><room>E315</room><country>USA</country>" - "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" - "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text>" - "<datum>Datee</datum><street>Highway</street><speed>56.77</speed></geoloc>")); + CPPUNIT_ASSERT(parser.parse( + "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" + "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" + "<lat>1.67</lat><accuracy>0.95</accuracy><description>Nice</description>" + "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" + "<building>First</building><room>E315</room><country>USA</country>" + "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" + "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text>" + "<datum>Datee</datum><street>Highway</street><speed>56.77</speed></geoloc>")); - UserLocation* payload = dynamic_cast<UserLocation*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT_EQUAL(std::string("Barbaric"), payload->getArea().get()); - CPPUNIT_ASSERT_EQUAL(5.75F, payload->getAltitude().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Near"), payload->getLocality().get()); - CPPUNIT_ASSERT_EQUAL(1.670F, payload->getLatitude().get()); - CPPUNIT_ASSERT_EQUAL(0.95F, payload->getAccuracy().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Nice"), payload->getDescription().get()); - CPPUNIT_ASSERT_EQUAL(std::string("+91"), payload->getCountryCode().get()); - CPPUNIT_ASSERT_EQUAL(std::string("2015-06-11T20:55:50Z"), dateTimeToString(payload->getTimestamp().get())); - CPPUNIT_ASSERT_EQUAL(std::string("3"), payload->getFloor().get()); - CPPUNIT_ASSERT_EQUAL(std::string("First"), payload->getBuilding().get()); - CPPUNIT_ASSERT_EQUAL(std::string("E315"), payload->getRoom().get()); - CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getCountry().get()); - CPPUNIT_ASSERT_EQUAL(std::string("NewSode"), payload->getRegion().get()); - CPPUNIT_ASSERT_EQUAL(std::string("URIs"), payload->getURI().get()); - CPPUNIT_ASSERT_EQUAL(6.7578F, payload->getLongitude().get()); - CPPUNIT_ASSERT_EQUAL(5.66F, payload->getError().get()); - CPPUNIT_ASSERT_EQUAL(std::string("67"), payload->getPostalCode().get()); - CPPUNIT_ASSERT_EQUAL(12.89F, payload->getBearing().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Hello"), payload->getText().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Datee"), payload->getDatum().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Highway"), payload->getStreet().get()); - CPPUNIT_ASSERT_EQUAL(56.77F, payload->getSpeed().get()); - } + UserLocation* payload = dynamic_cast<UserLocation*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT_EQUAL(std::string("Barbaric"), payload->getArea().get()); + CPPUNIT_ASSERT_EQUAL(5.75, payload->getAltitude().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Near"), payload->getLocality().get()); + CPPUNIT_ASSERT_EQUAL(1.670, payload->getLatitude().get()); + CPPUNIT_ASSERT_EQUAL(0.95, payload->getAccuracy().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Nice"), payload->getDescription().get()); + CPPUNIT_ASSERT_EQUAL(std::string("+91"), payload->getCountryCode().get()); + CPPUNIT_ASSERT_EQUAL(std::string("2015-06-11T20:55:50Z"), dateTimeToString(payload->getTimestamp().get())); + CPPUNIT_ASSERT_EQUAL(std::string("3"), payload->getFloor().get()); + CPPUNIT_ASSERT_EQUAL(std::string("First"), payload->getBuilding().get()); + CPPUNIT_ASSERT_EQUAL(std::string("E315"), payload->getRoom().get()); + CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getCountry().get()); + CPPUNIT_ASSERT_EQUAL(std::string("NewSode"), payload->getRegion().get()); + CPPUNIT_ASSERT_EQUAL(std::string("URIs"), payload->getURI().get()); + CPPUNIT_ASSERT_EQUAL(6.7578, payload->getLongitude().get()); + CPPUNIT_ASSERT_EQUAL(5.66, payload->getError().get()); + CPPUNIT_ASSERT_EQUAL(std::string("67"), payload->getPostalCode().get()); + CPPUNIT_ASSERT_EQUAL(12.89, payload->getBearing().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Hello"), payload->getText().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Datee"), payload->getDatum().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Highway"), payload->getStreet().get()); + CPPUNIT_ASSERT_EQUAL(56.77, payload->getSpeed().get()); + } - void testParse_with_Some_variables() { - PayloadsParserTester parser; + void testParse_with_Some_variables() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" - "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" - "<accuracy>0.95</accuracy><description>Nice</description>" - "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" - "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" - "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text></geoloc>")); + CPPUNIT_ASSERT(parser.parse( + "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" + "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" + "<accuracy>0.95</accuracy><description>Nice</description>" + "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" + "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" + "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text></geoloc>")); - UserLocation* payload = dynamic_cast<UserLocation*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT_EQUAL(std::string("Barbaric"), payload->getArea().get()); - CPPUNIT_ASSERT_EQUAL(5.75F, payload->getAltitude().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Near"), payload->getLocality().get()); - CPPUNIT_ASSERT(!payload->getLatitude()); - CPPUNIT_ASSERT_EQUAL(0.95F, payload->getAccuracy().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Nice"), payload->getDescription().get()); - CPPUNIT_ASSERT_EQUAL(std::string("+91"), payload->getCountryCode().get()); - CPPUNIT_ASSERT_EQUAL(std::string("2015-06-11T20:55:50Z"), dateTimeToString(payload->getTimestamp().get())); - CPPUNIT_ASSERT_EQUAL(std::string("3"), payload->getFloor().get()); - CPPUNIT_ASSERT(!payload->getBuilding()); - CPPUNIT_ASSERT(!payload->getRoom()); - CPPUNIT_ASSERT(!payload->getCountry()); - CPPUNIT_ASSERT_EQUAL(std::string("NewSode"), payload->getRegion().get()); - CPPUNIT_ASSERT_EQUAL(std::string("URIs"), payload->getURI().get()); - CPPUNIT_ASSERT_EQUAL(6.7578F, payload->getLongitude().get()); - CPPUNIT_ASSERT_EQUAL(5.66F, payload->getError().get()); - CPPUNIT_ASSERT_EQUAL(std::string("67"), payload->getPostalCode().get()); - CPPUNIT_ASSERT_EQUAL(12.89F, payload->getBearing().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Hello"), payload->getText().get()); - CPPUNIT_ASSERT(!payload->getDatum()); - CPPUNIT_ASSERT(!payload->getStreet()); - CPPUNIT_ASSERT(!payload->getSpeed()); - } + UserLocation* payload = dynamic_cast<UserLocation*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT_EQUAL(std::string("Barbaric"), payload->getArea().get()); + CPPUNIT_ASSERT_EQUAL(5.75, payload->getAltitude().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Near"), payload->getLocality().get()); + CPPUNIT_ASSERT(!payload->getLatitude()); + CPPUNIT_ASSERT_EQUAL(0.95, payload->getAccuracy().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Nice"), payload->getDescription().get()); + CPPUNIT_ASSERT_EQUAL(std::string("+91"), payload->getCountryCode().get()); + CPPUNIT_ASSERT_EQUAL(std::string("2015-06-11T20:55:50Z"), dateTimeToString(payload->getTimestamp().get())); + CPPUNIT_ASSERT_EQUAL(std::string("3"), payload->getFloor().get()); + CPPUNIT_ASSERT(!payload->getBuilding()); + CPPUNIT_ASSERT(!payload->getRoom()); + CPPUNIT_ASSERT(!payload->getCountry()); + CPPUNIT_ASSERT_EQUAL(std::string("NewSode"), payload->getRegion().get()); + CPPUNIT_ASSERT_EQUAL(std::string("URIs"), payload->getURI().get()); + CPPUNIT_ASSERT_EQUAL(6.7578, payload->getLongitude().get()); + CPPUNIT_ASSERT_EQUAL(5.66, payload->getError().get()); + CPPUNIT_ASSERT_EQUAL(std::string("67"), payload->getPostalCode().get()); + CPPUNIT_ASSERT_EQUAL(12.89, payload->getBearing().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Hello"), payload->getText().get()); + CPPUNIT_ASSERT(!payload->getDatum()); + CPPUNIT_ASSERT(!payload->getStreet()); + CPPUNIT_ASSERT(!payload->getSpeed()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(UserLocationParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp index a1b284b..3783231 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp @@ -4,61 +4,67 @@ * 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 <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Parser/PayloadParsers/UserTuneParser.h> -#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Base/DateTime.h> #include <Swiften/Elements/UserTune.h> -#include <Swiften/Base/DateTime.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Parser/PayloadParsers/UserTuneParser.h> using namespace Swift; class UserTuneParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(UserTuneParserTest); - CPPUNIT_TEST(testParse_with_all_variables); - CPPUNIT_TEST(testParse_with_Some_variables); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(UserTuneParserTest); + CPPUNIT_TEST(testParse_with_all_variables); + CPPUNIT_TEST(testParse_with_Some_variables); + CPPUNIT_TEST_SUITE_END(); - public: - UserTuneParserTest() {} + public: + UserTuneParserTest() {} - void testParse_with_all_variables() { - PayloadsParserTester parser; + void testParse_with_all_variables() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<tune xmlns=\"http://jabber.org/protocol/tune\">" - "<rating>5</rating><title>Minion</title><track>Yellow</track><artist>Ice</artist><URI>Fire</URI><source>Origin</source><length>226</length></tune>")); + CPPUNIT_ASSERT(parser.parse( + "<tune xmlns=\"http://jabber.org/protocol/tune\">" + "<rating>5</rating><title>Minion</title><track>Yellow</track><artist>Ice</artist><URI>Fire</URI><source>Origin</source><length>226</length></tune>")); - UserTune* payload = dynamic_cast<UserTune*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(5), payload->getRating().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Minion"), payload->getTitle().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Yellow"), payload->getTrack().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Ice"), payload->getArtist().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Fire"), payload->getURI().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Origin"), payload->getSource().get()); - CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(226), payload->getLength().get()); - } + UserTune* payload = dynamic_cast<UserTune*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(5), payload->getRating().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Minion"), payload->getTitle().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Yellow"), payload->getTrack().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Ice"), payload->getArtist().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Fire"), payload->getURI().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Origin"), payload->getSource().get()); + CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(226), payload->getLength().get()); + } - void testParse_with_Some_variables() { - PayloadsParserTester parser; + void testParse_with_Some_variables() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<tune xmlns=\"http://jabber.org/protocol/tune\">" - "<title>Minion</title><track>Yellow</track><source>Origin</source><length>226</length></tune>")); + CPPUNIT_ASSERT(parser.parse( + "<tune xmlns=\"http://jabber.org/protocol/tune\">" + "<title>Minion</title><track>Yellow</track><source>Origin</source><length>226</length></tune>")); - UserTune* payload = dynamic_cast<UserTune*>(parser.getPayload().get()); - CPPUNIT_ASSERT(payload); - CPPUNIT_ASSERT(!payload->getRating()); - CPPUNIT_ASSERT_EQUAL(std::string("Minion"), payload->getTitle().get()); - CPPUNIT_ASSERT_EQUAL(std::string("Yellow"), payload->getTrack().get()); - CPPUNIT_ASSERT(!payload->getArtist()); - CPPUNIT_ASSERT(!payload->getURI()); - CPPUNIT_ASSERT_EQUAL(std::string("Origin"), payload->getSource().get()); - CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(226), payload->getLength().get()); - } + UserTune* payload = dynamic_cast<UserTune*>(parser.getPayload().get()); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT(!payload->getRating()); + CPPUNIT_ASSERT_EQUAL(std::string("Minion"), payload->getTitle().get()); + CPPUNIT_ASSERT_EQUAL(std::string("Yellow"), payload->getTrack().get()); + CPPUNIT_ASSERT(!payload->getArtist()); + CPPUNIT_ASSERT(!payload->getURI()); + CPPUNIT_ASSERT_EQUAL(std::string("Origin"), payload->getSource().get()); + CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(226), payload->getLength().get()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(UserTuneParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp index 5c87f70..bc29921 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp @@ -1,207 +1,207 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include <Swiften/Base/ByteArray.h> -#include <QA/Checker/IO.h> - #include <boost/date_time/posix_time/posix_time.hpp> +#include <QA/Checker/IO.h> + #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Parser/PayloadParsers/VCardParser.h> +#include <Swiften/Base/ByteArray.h> #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Parser/PayloadParsers/VCardParser.h> using namespace Swift; class VCardParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(VCardParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Photo); - CPPUNIT_TEST(testParse_NewlinedPhoto); - CPPUNIT_TEST(testParse_Nickname); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<vCard xmlns=\"vcard-temp\">" - "<VERSION>2.0</VERSION>" - "<FN>Alice In Wonderland</FN>" - "<N>" - "<FAMILY>Wonderland</FAMILY>" - "<GIVEN>Alice</GIVEN>" - "<MIDDLE>In</MIDDLE>" - "<PREFIX>Mrs</PREFIX>" - "<SUFFIX>PhD</SUFFIX>" - "</N>" - "<EMAIL>" - "<USERID>alice@wonderland.lit</USERID>" - "<HOME/>" - "<INTERNET/>" - "<PREF/>" - "</EMAIL>" - "<EMAIL>" - "<USERID>alice@teaparty.lit</USERID>" - "<WORK/>" - "<X400/>" - "</EMAIL>" - "<TEL>" - "<NUMBER>555-6273</NUMBER>" - "<HOME/>" - "<VOICE/>" - "</TEL>" - "<ADR>" - "<LOCALITY>Any Town</LOCALITY>" - "<STREET>Fake Street 123</STREET>" - "<PCODE>12345</PCODE>" - "<CTRY>USA</CTRY>" - "<HOME/>" - "</ADR>" - "<LABEL>" - "<LINE>Fake Street 123</LINE>" - "<LINE>12345 Any Town</LINE>" - "<LINE>USA</LINE>" - "<HOME/>" - "</LABEL>" - "<NICKNAME>DreamGirl</NICKNAME>" - "<BDAY>1865-05-04</BDAY>" - "<JID>alice@teaparty.lit</JID>" - "<JID>alice@wonderland.lit</JID>" - "<DESC>I once fell down a rabbit hole.</DESC>" - "<ORG>" - "<ORGNAME>Alice In Wonderland Inc.</ORGNAME>" - "</ORG>" - "<TITLE>Some Title</TITLE>" - "<ROLE>Main Character</ROLE>" - "<URL>http://wonderland.lit/~alice</URL>" - "<URL>http://teaparty.lit/~alice2</URL>" - "<MAILER>mutt</MAILER>" - "</vCard>")); - - boost::shared_ptr<VCard> payload = boost::dynamic_pointer_cast<VCard>(parser.getPayload()); - CPPUNIT_ASSERT_EQUAL(std::string("2.0"), payload->getVersion()); - CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland"), payload->getFullName()); - CPPUNIT_ASSERT_EQUAL(std::string("Alice"), payload->getGivenName()); - CPPUNIT_ASSERT_EQUAL(std::string("In"), payload->getMiddleName()); - CPPUNIT_ASSERT_EQUAL(std::string("Wonderland"), payload->getFamilyName()); - CPPUNIT_ASSERT_EQUAL(std::string("Mrs"), payload->getPrefix()); - CPPUNIT_ASSERT_EQUAL(std::string("PhD"), payload->getSuffix()); - CPPUNIT_ASSERT_EQUAL(std::string("DreamGirl"), payload->getNickname()); - CPPUNIT_ASSERT_EQUAL(boost::posix_time::ptime(boost::gregorian::date(1865, 5, 4)), payload->getBirthday()); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getEMailAddresses().size())); - CPPUNIT_ASSERT_EQUAL(std::string("alice@wonderland.lit"), payload->getEMailAddresses()[0].address); - CPPUNIT_ASSERT(payload->getEMailAddresses()[0].isHome); - CPPUNIT_ASSERT(payload->getEMailAddresses()[0].isInternet); - CPPUNIT_ASSERT(payload->getEMailAddresses()[0].isPreferred); - CPPUNIT_ASSERT(!payload->getEMailAddresses()[0].isWork); - CPPUNIT_ASSERT(!payload->getEMailAddresses()[0].isX400); - CPPUNIT_ASSERT_EQUAL(std::string("alice@teaparty.lit"), payload->getEMailAddresses()[1].address); - CPPUNIT_ASSERT(!payload->getEMailAddresses()[1].isHome); - CPPUNIT_ASSERT(!payload->getEMailAddresses()[1].isInternet); - CPPUNIT_ASSERT(!payload->getEMailAddresses()[1].isPreferred); - CPPUNIT_ASSERT(payload->getEMailAddresses()[1].isWork); - CPPUNIT_ASSERT(payload->getEMailAddresses()[1].isX400); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getTelephones().size())); - CPPUNIT_ASSERT_EQUAL(std::string("555-6273"), payload->getTelephones()[0].number); - CPPUNIT_ASSERT(payload->getTelephones()[0].isHome); - CPPUNIT_ASSERT(payload->getTelephones()[0].isVoice); - CPPUNIT_ASSERT(!payload->getTelephones()[0].isPreferred); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getAddresses().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Any Town"), payload->getAddresses()[0].locality); - CPPUNIT_ASSERT_EQUAL(std::string("Fake Street 123"), payload->getAddresses()[0].street); - CPPUNIT_ASSERT_EQUAL(std::string("12345"), payload->getAddresses()[0].postalCode); - CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getAddresses()[0].country); - CPPUNIT_ASSERT(payload->getAddresses()[0].isHome); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getAddressLabels().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Fake Street 123"), payload->getAddressLabels()[0].lines[0]); - CPPUNIT_ASSERT_EQUAL(std::string("12345 Any Town"), payload->getAddressLabels()[0].lines[1]); - CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getAddressLabels()[0].lines[2]); - CPPUNIT_ASSERT(payload->getAddressLabels()[0].isHome); - - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getJIDs().size())); - CPPUNIT_ASSERT_EQUAL(JID("alice@teaparty.lit"), payload->getJIDs()[0]); - CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit"), payload->getJIDs()[1]); - - CPPUNIT_ASSERT_EQUAL(std::string("I once fell down a rabbit hole."), payload->getDescription()); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getOrganizations().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland Inc."), payload->getOrganizations()[0].name); - CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(payload->getOrganizations()[0].units.size())); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getTitles().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Some Title"), payload->getTitles()[0]); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getRoles().size())); - CPPUNIT_ASSERT_EQUAL(std::string("Main Character"), payload->getRoles()[0]); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getURLs().size())); - CPPUNIT_ASSERT_EQUAL(std::string("http://wonderland.lit/~alice"), payload->getURLs()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("http://teaparty.lit/~alice2"), payload->getURLs()[1]); - - CPPUNIT_ASSERT_EQUAL(std::string("<MAILER xmlns=\"vcard-temp\">mutt</MAILER>"), payload->getUnknownContent()); - } - - void testParse_Photo() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<vCard xmlns='vcard-temp'>" - "<PHOTO>" - "<TYPE>image/jpeg</TYPE>" - "<BINVAL>" - "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ej" - "EyMzQ1Njc4OTA=" - "</BINVAL>" - "</PHOTO>" - "</vCard>")); - - VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("image/jpeg"), payload->getPhotoType()); - CPPUNIT_ASSERT_EQUAL(createByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"), payload->getPhoto()); - } - - void testParse_NewlinedPhoto() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<vCard xmlns='vcard-temp'>" - "<PHOTO>" - "<TYPE>image/jpeg</TYPE>" - "<BINVAL>" - "dTsETKSAskgu2/BqVO+ogcu3DJy4QATGJqpsa6znWwNGiLnVElVVB6PtS+mTiHUXsrOlKvRjtvzV\n" - "VDknNaRF58Elmu5EC6VoCllBEEB/lFf0emYn2gkp0X1khNi75dl+rOj95Ar6XuwLh+ZoSStqwOWj\n" - "pIpxmZmVw7E69qr0FY0oI3zcaxXwzHw7Lx9Qf4sH7ufQvIN88ga+hwp8MiXevh3Ac8pN00kgINlq\n" - "9AY/bYJL418Y/6wWsJbgmrJ/N78wSMpC7VVszLBZVv8uFnupubyi8Ophd/1wIWWzPPwAbBhepWVb\n" - "1oPiFEBT5MNKCMTPEi0npXtedVz0HQbbPNIVwmo=" - "</BINVAL>" - "</PHOTO>" - "</vCard>")); - - VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("image/jpeg"), payload->getPhotoType()); - CPPUNIT_ASSERT_EQUAL(createByteArray("\x75\x3B\x04\x4C\xA4\x80\xB2\x48\x2E\xDB\xF0\x6A\x54\xEF\xA8\x81\xCB\xB7\x0C\x9C\xB8\x40\x04\xC6\x26\xAA\x6C\x6B\xAC\xE7\x5B\x03\x46\x88\xB9\xD5\x12\x55\x55\x07\xA3\xED\x4B\xE9\x93\x88\x75\x17\xB2\xB3\xA5\x2A\xF4\x63\xB6\xFC\xD5\x54\x39\x27\x35\xA4\x45\xE7\xC1\x25\x9A\xEE\x44\x0B\xA5\x68\x0A\x59\x41\x10\x40\x7F\x94\x57\xF4\x7A\x66\x27\xDA\x09\x29\xD1\x7D\x64\x84\xD8\xBB\xE5\xD9\x7E\xAC\xE8\xFD\xE4\x0A\xFA\x5E\xEC\x0B\x87\xE6\x68\x49\x2B\x6A\xC0\xE5\xA3\xA4\x8A\x71\x99\x99\x95\xC3\xB1\x3A\xF6\xAA\xF4\x15\x8D\x28\x23\x7C\xDC\x6B\x15\xF0\xCC\x7C\x3B\x2F\x1F\x50\x7F\x8B\x07\xEE\xE7\xD0\xBC\x83\x7C\xF2\x06\xBE\x87\x0A\x7C\x32\x25\xDE\xBE\x1D\xC0\x73\xCA\x4D\xD3\x49\x20\x20\xD9\x6A\xF4\x06\x3F\x6D\x82\x4B\xE3\x5F\x18\xFF\xAC\x16\xB0\x96\xE0\x9A\xB2\x7F\x37\xBF\x30\x48\xCA\x42\xED\x55\x6C\xCC\xB0\x59\x56\xFF\x2E\x16\x7B\xA9\xB9\xBC\xA2\xF0\xEA\x61\x77\xFD\x70\x21\x65\xB3\x3C\xFC\x00\x6C\x18\x5E\xA5\x65\x5B\xD6\x83\xE2\x14\x40\x53\xE4\xC3\x4A\x08\xC4\xCF\x12\x2D\x27\xA5\x7B\x5E\x75\x5C\xF4\x1D\x06\xDB\x3C\xD2\x15\xC2\x6A", 257), payload->getPhoto()); - } - - - - void testParse_Nickname() { - PayloadsParserTester parser; - - CPPUNIT_ASSERT(parser.parse( - "<vCard xmlns='vcard-temp'>" - "<NICKNAME>mynick</NICKNAME>" - "</vCard>")); - - VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("mynick"), payload->getNickname()); - } + CPPUNIT_TEST_SUITE(VCardParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Photo); + CPPUNIT_TEST(testParse_NewlinedPhoto); + CPPUNIT_TEST(testParse_Nickname); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<vCard xmlns=\"vcard-temp\">" + "<VERSION>2.0</VERSION>" + "<FN>Alice In Wonderland</FN>" + "<N>" + "<FAMILY>Wonderland</FAMILY>" + "<GIVEN>Alice</GIVEN>" + "<MIDDLE>In</MIDDLE>" + "<PREFIX>Mrs</PREFIX>" + "<SUFFIX>PhD</SUFFIX>" + "</N>" + "<EMAIL>" + "<USERID>alice@wonderland.lit</USERID>" + "<HOME/>" + "<INTERNET/>" + "<PREF/>" + "</EMAIL>" + "<EMAIL>" + "<USERID>alice@teaparty.lit</USERID>" + "<WORK/>" + "<X400/>" + "</EMAIL>" + "<TEL>" + "<NUMBER>555-6273</NUMBER>" + "<HOME/>" + "<VOICE/>" + "</TEL>" + "<ADR>" + "<LOCALITY>Any Town</LOCALITY>" + "<STREET>Fake Street 123</STREET>" + "<PCODE>12345</PCODE>" + "<CTRY>USA</CTRY>" + "<HOME/>" + "</ADR>" + "<LABEL>" + "<LINE>Fake Street 123</LINE>" + "<LINE>12345 Any Town</LINE>" + "<LINE>USA</LINE>" + "<HOME/>" + "</LABEL>" + "<NICKNAME>DreamGirl</NICKNAME>" + "<BDAY>1865-05-04</BDAY>" + "<JID>alice@teaparty.lit</JID>" + "<JID>alice@wonderland.lit</JID>" + "<DESC>I once fell down a rabbit hole.</DESC>" + "<ORG>" + "<ORGNAME>Alice In Wonderland Inc.</ORGNAME>" + "</ORG>" + "<TITLE>Some Title</TITLE>" + "<ROLE>Main Character</ROLE>" + "<URL>http://wonderland.lit/~alice</URL>" + "<URL>http://teaparty.lit/~alice2</URL>" + "<MAILER>mutt</MAILER>" + "</vCard>")); + + std::shared_ptr<VCard> payload = std::dynamic_pointer_cast<VCard>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(std::string("2.0"), payload->getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland"), payload->getFullName()); + CPPUNIT_ASSERT_EQUAL(std::string("Alice"), payload->getGivenName()); + CPPUNIT_ASSERT_EQUAL(std::string("In"), payload->getMiddleName()); + CPPUNIT_ASSERT_EQUAL(std::string("Wonderland"), payload->getFamilyName()); + CPPUNIT_ASSERT_EQUAL(std::string("Mrs"), payload->getPrefix()); + CPPUNIT_ASSERT_EQUAL(std::string("PhD"), payload->getSuffix()); + CPPUNIT_ASSERT_EQUAL(std::string("DreamGirl"), payload->getNickname()); + CPPUNIT_ASSERT_EQUAL(boost::posix_time::ptime(boost::gregorian::date(1865, 5, 4)), payload->getBirthday()); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getEMailAddresses().size())); + CPPUNIT_ASSERT_EQUAL(std::string("alice@wonderland.lit"), payload->getEMailAddresses()[0].address); + CPPUNIT_ASSERT(payload->getEMailAddresses()[0].isHome); + CPPUNIT_ASSERT(payload->getEMailAddresses()[0].isInternet); + CPPUNIT_ASSERT(payload->getEMailAddresses()[0].isPreferred); + CPPUNIT_ASSERT(!payload->getEMailAddresses()[0].isWork); + CPPUNIT_ASSERT(!payload->getEMailAddresses()[0].isX400); + CPPUNIT_ASSERT_EQUAL(std::string("alice@teaparty.lit"), payload->getEMailAddresses()[1].address); + CPPUNIT_ASSERT(!payload->getEMailAddresses()[1].isHome); + CPPUNIT_ASSERT(!payload->getEMailAddresses()[1].isInternet); + CPPUNIT_ASSERT(!payload->getEMailAddresses()[1].isPreferred); + CPPUNIT_ASSERT(payload->getEMailAddresses()[1].isWork); + CPPUNIT_ASSERT(payload->getEMailAddresses()[1].isX400); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getTelephones().size())); + CPPUNIT_ASSERT_EQUAL(std::string("555-6273"), payload->getTelephones()[0].number); + CPPUNIT_ASSERT(payload->getTelephones()[0].isHome); + CPPUNIT_ASSERT(payload->getTelephones()[0].isVoice); + CPPUNIT_ASSERT(!payload->getTelephones()[0].isPreferred); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getAddresses().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Any Town"), payload->getAddresses()[0].locality); + CPPUNIT_ASSERT_EQUAL(std::string("Fake Street 123"), payload->getAddresses()[0].street); + CPPUNIT_ASSERT_EQUAL(std::string("12345"), payload->getAddresses()[0].postalCode); + CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getAddresses()[0].country); + CPPUNIT_ASSERT(payload->getAddresses()[0].isHome); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getAddressLabels().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Fake Street 123"), payload->getAddressLabels()[0].lines[0]); + CPPUNIT_ASSERT_EQUAL(std::string("12345 Any Town"), payload->getAddressLabels()[0].lines[1]); + CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getAddressLabels()[0].lines[2]); + CPPUNIT_ASSERT(payload->getAddressLabels()[0].isHome); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getJIDs().size())); + CPPUNIT_ASSERT_EQUAL(JID("alice@teaparty.lit"), payload->getJIDs()[0]); + CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit"), payload->getJIDs()[1]); + + CPPUNIT_ASSERT_EQUAL(std::string("I once fell down a rabbit hole."), payload->getDescription()); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getOrganizations().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland Inc."), payload->getOrganizations()[0].name); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(payload->getOrganizations()[0].units.size())); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getTitles().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Some Title"), payload->getTitles()[0]); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getRoles().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Main Character"), payload->getRoles()[0]); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getURLs().size())); + CPPUNIT_ASSERT_EQUAL(std::string("http://wonderland.lit/~alice"), payload->getURLs()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("http://teaparty.lit/~alice2"), payload->getURLs()[1]); + + CPPUNIT_ASSERT_EQUAL(std::string("<MAILER xmlns=\"vcard-temp\">mutt</MAILER>"), payload->getUnknownContent()); + } + + void testParse_Photo() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<vCard xmlns='vcard-temp'>" + "<PHOTO>" + "<TYPE>image/jpeg</TYPE>" + "<BINVAL>" + "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ej" + "EyMzQ1Njc4OTA=" + "</BINVAL>" + "</PHOTO>" + "</vCard>")); + + VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("image/jpeg"), payload->getPhotoType()); + CPPUNIT_ASSERT_EQUAL(createByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"), payload->getPhoto()); + } + + void testParse_NewlinedPhoto() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<vCard xmlns='vcard-temp'>" + "<PHOTO>" + "<TYPE>image/jpeg</TYPE>" + "<BINVAL>" + "dTsETKSAskgu2/BqVO+ogcu3DJy4QATGJqpsa6znWwNGiLnVElVVB6PtS+mTiHUXsrOlKvRjtvzV\n" + "VDknNaRF58Elmu5EC6VoCllBEEB/lFf0emYn2gkp0X1khNi75dl+rOj95Ar6XuwLh+ZoSStqwOWj\n" + "pIpxmZmVw7E69qr0FY0oI3zcaxXwzHw7Lx9Qf4sH7ufQvIN88ga+hwp8MiXevh3Ac8pN00kgINlq\n" + "9AY/bYJL418Y/6wWsJbgmrJ/N78wSMpC7VVszLBZVv8uFnupubyi8Ophd/1wIWWzPPwAbBhepWVb\n" + "1oPiFEBT5MNKCMTPEi0npXtedVz0HQbbPNIVwmo=" + "</BINVAL>" + "</PHOTO>" + "</vCard>")); + + VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("image/jpeg"), payload->getPhotoType()); + CPPUNIT_ASSERT_EQUAL(createByteArray("\x75\x3B\x04\x4C\xA4\x80\xB2\x48\x2E\xDB\xF0\x6A\x54\xEF\xA8\x81\xCB\xB7\x0C\x9C\xB8\x40\x04\xC6\x26\xAA\x6C\x6B\xAC\xE7\x5B\x03\x46\x88\xB9\xD5\x12\x55\x55\x07\xA3\xED\x4B\xE9\x93\x88\x75\x17\xB2\xB3\xA5\x2A\xF4\x63\xB6\xFC\xD5\x54\x39\x27\x35\xA4\x45\xE7\xC1\x25\x9A\xEE\x44\x0B\xA5\x68\x0A\x59\x41\x10\x40\x7F\x94\x57\xF4\x7A\x66\x27\xDA\x09\x29\xD1\x7D\x64\x84\xD8\xBB\xE5\xD9\x7E\xAC\xE8\xFD\xE4\x0A\xFA\x5E\xEC\x0B\x87\xE6\x68\x49\x2B\x6A\xC0\xE5\xA3\xA4\x8A\x71\x99\x99\x95\xC3\xB1\x3A\xF6\xAA\xF4\x15\x8D\x28\x23\x7C\xDC\x6B\x15\xF0\xCC\x7C\x3B\x2F\x1F\x50\x7F\x8B\x07\xEE\xE7\xD0\xBC\x83\x7C\xF2\x06\xBE\x87\x0A\x7C\x32\x25\xDE\xBE\x1D\xC0\x73\xCA\x4D\xD3\x49\x20\x20\xD9\x6A\xF4\x06\x3F\x6D\x82\x4B\xE3\x5F\x18\xFF\xAC\x16\xB0\x96\xE0\x9A\xB2\x7F\x37\xBF\x30\x48\xCA\x42\xED\x55\x6C\xCC\xB0\x59\x56\xFF\x2E\x16\x7B\xA9\xB9\xBC\xA2\xF0\xEA\x61\x77\xFD\x70\x21\x65\xB3\x3C\xFC\x00\x6C\x18\x5E\xA5\x65\x5B\xD6\x83\xE2\x14\x40\x53\xE4\xC3\x4A\x08\xC4\xCF\x12\x2D\x27\xA5\x7B\x5E\x75\x5C\xF4\x1D\x06\xDB\x3C\xD2\x15\xC2\x6A", 257), payload->getPhoto()); + } + + + + void testParse_Nickname() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<vCard xmlns='vcard-temp'>" + "<NICKNAME>mynick</NICKNAME>" + "</vCard>")); + + VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("mynick"), payload->getNickname()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(VCardParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp index 14707e3..11e8ded 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.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. */ @@ -7,31 +7,31 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Parser/PayloadParsers/VCardUpdateParser.h> #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Parser/PayloadParsers/VCardUpdateParser.h> using namespace Swift; class VCardUpdateParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(VCardUpdateParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(VCardUpdateParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); - public: - VCardUpdateParserTest() {} + public: + VCardUpdateParserTest() {} - void testParse() { - PayloadsParserTester parser; + void testParse() { + PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<x xmlns='vcard-temp:x:update'>" - "<photo>sha1-hash-of-image</photo>" - "</x>")); + CPPUNIT_ASSERT(parser.parse( + "<x xmlns='vcard-temp:x:update'>" + "<photo>sha1-hash-of-image</photo>" + "</x>")); - VCardUpdate* payload = dynamic_cast<VCardUpdate*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(std::string("sha1-hash-of-image"), payload->getPhotoHash()); - } + VCardUpdate* payload = dynamic_cast<VCardUpdate*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(std::string("sha1-hash-of-image"), payload->getPhotoHash()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(VCardUpdateParserTest); diff --git a/Swiften/Parser/PayloadParsers/UserLocationParser.cpp b/Swiften/Parser/PayloadParsers/UserLocationParser.cpp index 4e98910..09d0e9a 100644 --- a/Swiften/Parser/PayloadParsers/UserLocationParser.cpp +++ b/Swiften/Parser/PayloadParsers/UserLocationParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -19,88 +19,88 @@ UserLocationParser::~UserLocationParser() { } void UserLocationParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - if (level == 1) { - currentText = ""; - } - ++level; + if (level == 1) { + currentText = ""; + } + ++level; } void UserLocationParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (level == 1) { - try { - if (element == "accuracy") { - getPayloadInternal()->setAccuracy(boost::lexical_cast<float>(currentText)); - } - else if (element == "alt") { - getPayloadInternal()->setAltitude(boost::lexical_cast<float>(currentText)); - } - else if (element == "area") { - getPayloadInternal()->setArea(currentText); - } - else if (element == "bearing") { - getPayloadInternal()->setBearing(boost::lexical_cast<float>(currentText)); - } - else if (element == "building") { - getPayloadInternal()->setBuilding(currentText); - } - else if (element == "country") { - getPayloadInternal()->setCountry(currentText); - } - else if (element == "countrycode") { - getPayloadInternal()->setCountryCode(currentText); - } - else if (element == "datum") { - getPayloadInternal()->setDatum(currentText); - } - else if (element == "description") { - getPayloadInternal()->setDescription(currentText); - } - else if (element == "error") { - getPayloadInternal()->setError(boost::lexical_cast<float>(currentText)); - } - else if (element == "floor") { - getPayloadInternal()->setFloor(currentText); - } - else if (element == "lat") { - getPayloadInternal()->setLatitude(boost::lexical_cast<float>(currentText)); - } - else if (element == "locality") { - getPayloadInternal()->setLocality(currentText); - } - else if (element == "lon") { - getPayloadInternal()->setLongitude(boost::lexical_cast<float>(currentText)); - } - else if (element == "postalcode") { - getPayloadInternal()->setPostalCode(currentText); - } - else if (element == "region") { - getPayloadInternal()->setRegion(currentText); - } - else if (element == "room") { - getPayloadInternal()->setRoom(currentText); - } - else if (element == "speed") { - getPayloadInternal()->setSpeed(boost::lexical_cast<float>(currentText)); - } - else if (element == "street") { - getPayloadInternal()->setStreet(currentText); - } - else if (element == "text") { - getPayloadInternal()->setText(currentText); - } - else if (element == "timestamp") { - getPayloadInternal()->setTimestamp(stringToDateTime(currentText)); - } - else if (element == "uri") { - getPayloadInternal()->setURI(currentText); - } - } - catch (const boost::bad_lexical_cast&) { - } - } + --level; + if (level == 1) { + try { + if (element == "accuracy") { + getPayloadInternal()->setAccuracy(boost::lexical_cast<double>(currentText)); + } + else if (element == "alt") { + getPayloadInternal()->setAltitude(boost::lexical_cast<double>(currentText)); + } + else if (element == "area") { + getPayloadInternal()->setArea(currentText); + } + else if (element == "bearing") { + getPayloadInternal()->setBearing(boost::lexical_cast<double>(currentText)); + } + else if (element == "building") { + getPayloadInternal()->setBuilding(currentText); + } + else if (element == "country") { + getPayloadInternal()->setCountry(currentText); + } + else if (element == "countrycode") { + getPayloadInternal()->setCountryCode(currentText); + } + else if (element == "datum") { + getPayloadInternal()->setDatum(currentText); + } + else if (element == "description") { + getPayloadInternal()->setDescription(currentText); + } + else if (element == "error") { + getPayloadInternal()->setError(boost::lexical_cast<double>(currentText)); + } + else if (element == "floor") { + getPayloadInternal()->setFloor(currentText); + } + else if (element == "lat") { + getPayloadInternal()->setLatitude(boost::lexical_cast<double>(currentText)); + } + else if (element == "locality") { + getPayloadInternal()->setLocality(currentText); + } + else if (element == "lon") { + getPayloadInternal()->setLongitude(boost::lexical_cast<double>(currentText)); + } + else if (element == "postalcode") { + getPayloadInternal()->setPostalCode(currentText); + } + else if (element == "region") { + getPayloadInternal()->setRegion(currentText); + } + else if (element == "room") { + getPayloadInternal()->setRoom(currentText); + } + else if (element == "speed") { + getPayloadInternal()->setSpeed(boost::lexical_cast<double>(currentText)); + } + else if (element == "street") { + getPayloadInternal()->setStreet(currentText); + } + else if (element == "text") { + getPayloadInternal()->setText(currentText); + } + else if (element == "timestamp") { + getPayloadInternal()->setTimestamp(stringToDateTime(currentText)); + } + else if (element == "uri") { + getPayloadInternal()->setURI(currentText); + } + } + catch (const boost::bad_lexical_cast&) { + } + } } void UserLocationParser::handleCharacterData(const std::string& data) { - currentText += data; + currentText += data; } diff --git a/Swiften/Parser/PayloadParsers/UserLocationParser.h b/Swiften/Parser/PayloadParsers/UserLocationParser.h index 50bf644..1445d3e 100644 --- a/Swiften/Parser/PayloadParsers/UserLocationParser.h +++ b/Swiften/Parser/PayloadParsers/UserLocationParser.h @@ -1,31 +1,31 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> #include <string> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> -#include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/UserLocation.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API UserLocationParser : public GenericPayloadParser<UserLocation> { - public: - UserLocationParser(); - virtual ~UserLocationParser(); + class SWIFTEN_API UserLocationParser : public GenericPayloadParser<UserLocation> { + public: + UserLocationParser(); + virtual ~UserLocationParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - int level; - std::string currentText; - }; + private: + int level; + std::string currentText; + }; } diff --git a/Swiften/Parser/PayloadParsers/UserTuneParser.cpp b/Swiften/Parser/PayloadParsers/UserTuneParser.cpp index f3f42ef..f030f8f 100644 --- a/Swiften/Parser/PayloadParsers/UserTuneParser.cpp +++ b/Swiften/Parser/PayloadParsers/UserTuneParser.cpp @@ -17,43 +17,43 @@ UserTuneParser::~UserTuneParser() { } void UserTuneParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - if (level == 1) { - currentText = ""; - } - ++level; + if (level == 1) { + currentText = ""; + } + ++level; } void UserTuneParser::handleEndElement(const std::string& element, const std::string&) { - --level; - if (level == 1) { - try { - if (element == "artist") { - getPayloadInternal()->setArtist(currentText); - } - else if (element == "length") { - getPayloadInternal()->setLength(boost::lexical_cast<unsigned int>(currentText)); - } - else if (element == "rating") { - getPayloadInternal()->setRating(boost::lexical_cast<unsigned int>(currentText)); - } - else if (element == "source") { - getPayloadInternal()->setSource(currentText); - } - else if (element == "title") { - getPayloadInternal()->setTitle(currentText); - } - else if (element == "track") { - getPayloadInternal()->setTrack(currentText); - } - else if (element == "URI") { - getPayloadInternal()->setURI(currentText); - } - } - catch (const boost::bad_lexical_cast&) { - } - } + --level; + if (level == 1) { + try { + if (element == "artist") { + getPayloadInternal()->setArtist(currentText); + } + else if (element == "length") { + getPayloadInternal()->setLength(boost::lexical_cast<unsigned int>(currentText)); + } + else if (element == "rating") { + getPayloadInternal()->setRating(boost::lexical_cast<unsigned int>(currentText)); + } + else if (element == "source") { + getPayloadInternal()->setSource(currentText); + } + else if (element == "title") { + getPayloadInternal()->setTitle(currentText); + } + else if (element == "track") { + getPayloadInternal()->setTrack(currentText); + } + else if (element == "URI") { + getPayloadInternal()->setURI(currentText); + } + } + catch (const boost::bad_lexical_cast&) { + } + } } void UserTuneParser::handleCharacterData(const std::string& data) { - currentText += data; + currentText += data; } diff --git a/Swiften/Parser/PayloadParsers/UserTuneParser.h b/Swiften/Parser/PayloadParsers/UserTuneParser.h index f1a3310..5a27273 100644 --- a/Swiften/Parser/PayloadParsers/UserTuneParser.h +++ b/Swiften/Parser/PayloadParsers/UserTuneParser.h @@ -1,31 +1,31 @@ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> #include <string> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> -#include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Base/Override.h> #include <Swiften/Elements/UserTune.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API UserTuneParser : public GenericPayloadParser<UserTune> { - public: - UserTuneParser(); - virtual ~UserTuneParser(); + class SWIFTEN_API UserTuneParser : public GenericPayloadParser<UserTune> { + public: + UserTuneParser(); + virtual ~UserTuneParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; - virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; - virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; - private: - int level; - std::string currentText; - }; + private: + int level; + std::string currentText; + }; } diff --git a/Swiften/Parser/PayloadParsers/VCardParser.cpp b/Swiften/Parser/PayloadParsers/VCardParser.cpp index c790c7b..f8779d1 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.cpp +++ b/Swiften/Parser/PayloadParsers/VCardParser.cpp @@ -1,288 +1,290 @@ /* - * 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/VCardParser.h> -#include <Swiften/Base/foreach.h> + +#include <cassert> + #include <Swiften/Base/DateTime.h> -#include <Swiften/StringCodecs/Base64.h> #include <Swiften/Parser/SerializingParser.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { -VCardParser::VCardParser() : unknownContentParser_(NULL) { +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); - } - else if (unknownContentParser_) { - unknownContentParser_->handleStartElement(element, ns, 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); + } + else if (unknownContentParser_) { + unknownContentParser_->handleStartElement(element, ns, attributes); + } - currentText_ = ""; + currentText_ = ""; } void VCardParser::handleEndElement(const std::string& element, const std::string& ns) { - if (unknownContentParser_) { - unknownContentParser_->handleEndElement(element, ns); - } + if (unknownContentParser_) { + unknownContentParser_->handleEndElement(element, ns); + } - std::string elementHierarchy = getElementHierarchy(); - if (elementHierarchy == "/vCard/VERSION") { - getPayloadInternal()->setVersion(currentText_); - } - else if (elementHierarchy == "/vCard/FN") { - getPayloadInternal()->setFullName(currentText_); - } - else if (elementHierarchy == "/vCard/N/FAMILY") { - getPayloadInternal()->setFamilyName(currentText_); - } - else if (elementHierarchy == "/vCard/N/GIVEN") { - getPayloadInternal()->setGivenName(currentText_); - } - else if (elementHierarchy == "/vCard/N/MIDDLE") { - getPayloadInternal()->setMiddleName(currentText_); - } - else if (elementHierarchy == "/vCard/N/PREFIX") { - getPayloadInternal()->setPrefix(currentText_); - } - else if (elementHierarchy == "/vCard/N/SUFFIX") { - getPayloadInternal()->setSuffix(currentText_); - } - else if (elementHierarchy == "/vCard/N") { - } - else if (elementHierarchy == "/vCard/NICKNAME") { - getPayloadInternal()->setNickname(currentText_); - } - else if (elementHierarchy == "/vCard/PHOTO/TYPE") { - getPayloadInternal()->setPhotoType(currentText_); - } - else if (elementHierarchy == "/vCard/PHOTO/BINVAL") { - currentText_.erase(std::remove(currentText_.begin(), currentText_.end(), '\n'), currentText_.end()); - currentText_.erase(std::remove(currentText_.begin(), currentText_.end(), '\r'), currentText_.end()); - getPayloadInternal()->setPhoto(Base64::decode(currentText_)); - } - else if (elementHierarchy == "/vCard/PHOTO") { - } - else if (elementHierarchy == "/vCard/EMAIL/USERID") { - currentEMailAddress_.address = currentText_; - } - else if (elementHierarchy == "/vCard/EMAIL/HOME") { - currentEMailAddress_.isHome = true; - } - else if (elementHierarchy == "/vCard/EMAIL/WORK") { - currentEMailAddress_.isWork = true; - } - else if (elementHierarchy == "/vCard/EMAIL/INTERNET") { - currentEMailAddress_.isInternet = true; - } - else if (elementHierarchy == "/vCard/EMAIL/X400") { - currentEMailAddress_.isX400 = true; - } - else if (elementHierarchy == "/vCard/EMAIL/PREF") { - currentEMailAddress_.isPreferred = true; - } - else if (elementHierarchy == "/vCard/EMAIL" && !currentEMailAddress_.address.empty()) { - getPayloadInternal()->addEMailAddress(currentEMailAddress_); - } - else if (elementHierarchy == "/vCard/BDAY" && !currentText_.empty()) { - getPayloadInternal()->setBirthday(stringToDateTime(currentText_)); - } - else if (elementHierarchy == "/vCard/TEL/NUMBER") { - currentTelephone_.number = currentText_; - } - else if (elementHierarchy == "/vCard/TEL/HOME") { - currentTelephone_.isHome = true; - } - else if (elementHierarchy == "/vCard/TEL/WORK") { - currentTelephone_.isWork = true; - } - else if (elementHierarchy == "/vCard/TEL/VOICE") { - currentTelephone_.isVoice = true; - } - else if (elementHierarchy == "/vCard/TEL/FAX") { - currentTelephone_.isFax = true; - } - else if (elementHierarchy == "/vCard/TEL/PAGER") { - currentTelephone_.isPager = true; - } - else if (elementHierarchy == "/vCard/TEL/MSG") { - currentTelephone_.isMSG = true; - } - else if (elementHierarchy == "/vCard/TEL/CELL") { - currentTelephone_.isCell = true; - } - else if (elementHierarchy == "/vCard/TEL/VIDEO") { - currentTelephone_.isVideo = true; - } - else if (elementHierarchy == "/vCard/TEL/BBS") { - currentTelephone_.isBBS = true; - } - else if (elementHierarchy == "/vCard/TEL/MODEM") { - currentTelephone_.isModem = true; - } - else if (elementHierarchy == "/vCard/TEL/ISDN") { - currentTelephone_.isISDN = true; - } - else if (elementHierarchy == "/vCard/TEL/PCS") { - currentTelephone_.isPCS = true; - } - else if (elementHierarchy == "/vCard/TEL/PREF") { - currentTelephone_.isPreferred = true; - } - else if (elementHierarchy == "/vCard/TEL" && !currentTelephone_.number.empty()) { - getPayloadInternal()->addTelephone(currentTelephone_); - } - else if (elementHierarchy == "/vCard/ADR/HOME") { - currentAddress_.isHome = true; - } - else if (elementHierarchy == "/vCard/ADR/WORK") { - currentAddress_.isWork = true; - } - else if (elementHierarchy == "/vCard/ADR/POSTAL") { - currentAddress_.isPostal = true; - } - else if (elementHierarchy == "/vCard/ADR/PARCEL") { - currentAddress_.isParcel = true; - } - else if (elementHierarchy == "/vCard/ADR/DOM") { - currentAddress_.deliveryType = VCard::DomesticDelivery; - } - else if (elementHierarchy == "/vCard/ADR/INTL") { - currentAddress_.deliveryType = VCard::InternationalDelivery; - } - else if (elementHierarchy == "/vCard/ADR/PREF") { - currentAddress_.isPreferred = true; - } - else if (elementHierarchy == "/vCard/ADR/POBOX") { - currentAddress_.poBox = currentText_; - } - else if (elementHierarchy == "/vCard/ADR/EXTADD") { - currentAddress_.addressExtension = currentText_; - } - else if (elementHierarchy == "/vCard/ADR/STREET") { - currentAddress_.street = currentText_; - } - else if (elementHierarchy == "/vCard/ADR/LOCALITY") { - currentAddress_.locality = currentText_; - } - else if (elementHierarchy == "/vCard/ADR/REGION") { - currentAddress_.region = currentText_; - } - else if (elementHierarchy == "/vCard/ADR/PCODE") { - currentAddress_.postalCode = currentText_; - } - else if (elementHierarchy == "/vCard/ADR/CTRY") { - currentAddress_.country = currentText_; - } - else if (elementHierarchy == "/vCard/ADR") { - if (!currentAddress_.poBox.empty() || !currentAddress_.addressExtension.empty() || - !currentAddress_.street.empty() || !currentAddress_.locality.empty() || - !currentAddress_.region.empty() || !currentAddress_.region.empty() || - !currentAddress_.postalCode.empty() || !currentAddress_.country.empty()) { - getPayloadInternal()->addAddress(currentAddress_); - } - } - else if (elementHierarchy == "/vCard/LABEL/HOME") { - currentAddressLabel_.isHome = true; - } - else if (elementHierarchy == "/vCard/LABEL/WORK") { - currentAddressLabel_.isWork = true; - } - else if (elementHierarchy == "/vCard/LABEL/POSTAL") { - currentAddressLabel_.isPostal = true; - } - else if (elementHierarchy == "/vCard/LABEL/PARCEL") { - currentAddressLabel_.isParcel = true; - } - else if (elementHierarchy == "/vCard/LABEL/DOM") { - currentAddressLabel_.deliveryType = VCard::DomesticDelivery; - } - else if (elementHierarchy == "/vCard/LABEL/INTL") { - currentAddressLabel_.deliveryType = VCard::InternationalDelivery; - } - else if (elementHierarchy == "/vCard/LABEL/PREF") { - currentAddressLabel_.isPreferred = true; - } - else if (elementHierarchy == "/vCard/LABEL/LINE") { - currentAddressLabel_.lines.push_back(currentText_); - } - else if (elementHierarchy == "/vCard/LABEL") { - getPayloadInternal()->addAddressLabel(currentAddressLabel_); - } - else if (elementHierarchy == "/vCard/JID" && !currentText_.empty()) { - getPayloadInternal()->addJID(JID(currentText_)); - } - else if (elementHierarchy == "/vCard/DESC") { - getPayloadInternal()->setDescription(currentText_); - } - else if (elementHierarchy == "/vCard/ORG/ORGNAME") { - currentOrganization_.name = currentText_; - } - else if (elementHierarchy == "/vCard/ORG/ORGUNIT" && !currentText_.empty()) { - currentOrganization_.units.push_back(currentText_); - } - else if (elementHierarchy == "/vCard/ORG") { - if (!currentOrganization_.name.empty() || !currentOrganization_.units.empty()) { - getPayloadInternal()->addOrganization(currentOrganization_); - } - } - 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()); - } + std::string elementHierarchy = getElementHierarchy(); + if (elementHierarchy == "/vCard/VERSION") { + getPayloadInternal()->setVersion(currentText_); + } + else if (elementHierarchy == "/vCard/FN") { + getPayloadInternal()->setFullName(currentText_); + } + else if (elementHierarchy == "/vCard/N/FAMILY") { + getPayloadInternal()->setFamilyName(currentText_); + } + else if (elementHierarchy == "/vCard/N/GIVEN") { + getPayloadInternal()->setGivenName(currentText_); + } + else if (elementHierarchy == "/vCard/N/MIDDLE") { + getPayloadInternal()->setMiddleName(currentText_); + } + else if (elementHierarchy == "/vCard/N/PREFIX") { + getPayloadInternal()->setPrefix(currentText_); + } + else if (elementHierarchy == "/vCard/N/SUFFIX") { + getPayloadInternal()->setSuffix(currentText_); + } + else if (elementHierarchy == "/vCard/N") { + } + else if (elementHierarchy == "/vCard/NICKNAME") { + getPayloadInternal()->setNickname(currentText_); + } + else if (elementHierarchy == "/vCard/PHOTO/TYPE") { + getPayloadInternal()->setPhotoType(currentText_); + } + else if (elementHierarchy == "/vCard/PHOTO/BINVAL") { + currentText_.erase(std::remove(currentText_.begin(), currentText_.end(), '\n'), currentText_.end()); + currentText_.erase(std::remove(currentText_.begin(), currentText_.end(), '\r'), currentText_.end()); + getPayloadInternal()->setPhoto(Base64::decode(currentText_)); + } + else if (elementHierarchy == "/vCard/PHOTO") { + } + else if (elementHierarchy == "/vCard/EMAIL/USERID") { + currentEMailAddress_.address = currentText_; + } + else if (elementHierarchy == "/vCard/EMAIL/HOME") { + currentEMailAddress_.isHome = true; + } + else if (elementHierarchy == "/vCard/EMAIL/WORK") { + currentEMailAddress_.isWork = true; + } + else if (elementHierarchy == "/vCard/EMAIL/INTERNET") { + currentEMailAddress_.isInternet = true; + } + else if (elementHierarchy == "/vCard/EMAIL/X400") { + currentEMailAddress_.isX400 = true; + } + else if (elementHierarchy == "/vCard/EMAIL/PREF") { + currentEMailAddress_.isPreferred = true; + } + else if (elementHierarchy == "/vCard/EMAIL" && !currentEMailAddress_.address.empty()) { + getPayloadInternal()->addEMailAddress(currentEMailAddress_); + } + else if (elementHierarchy == "/vCard/BDAY" && !currentText_.empty()) { + getPayloadInternal()->setBirthday(stringToDateTime(currentText_)); + } + else if (elementHierarchy == "/vCard/TEL/NUMBER") { + currentTelephone_.number = currentText_; + } + else if (elementHierarchy == "/vCard/TEL/HOME") { + currentTelephone_.isHome = true; + } + else if (elementHierarchy == "/vCard/TEL/WORK") { + currentTelephone_.isWork = true; + } + else if (elementHierarchy == "/vCard/TEL/VOICE") { + currentTelephone_.isVoice = true; + } + else if (elementHierarchy == "/vCard/TEL/FAX") { + currentTelephone_.isFax = true; + } + else if (elementHierarchy == "/vCard/TEL/PAGER") { + currentTelephone_.isPager = true; + } + else if (elementHierarchy == "/vCard/TEL/MSG") { + currentTelephone_.isMSG = true; + } + else if (elementHierarchy == "/vCard/TEL/CELL") { + currentTelephone_.isCell = true; + } + else if (elementHierarchy == "/vCard/TEL/VIDEO") { + currentTelephone_.isVideo = true; + } + else if (elementHierarchy == "/vCard/TEL/BBS") { + currentTelephone_.isBBS = true; + } + else if (elementHierarchy == "/vCard/TEL/MODEM") { + currentTelephone_.isModem = true; + } + else if (elementHierarchy == "/vCard/TEL/ISDN") { + currentTelephone_.isISDN = true; + } + else if (elementHierarchy == "/vCard/TEL/PCS") { + currentTelephone_.isPCS = true; + } + else if (elementHierarchy == "/vCard/TEL/PREF") { + currentTelephone_.isPreferred = true; + } + else if (elementHierarchy == "/vCard/TEL" && !currentTelephone_.number.empty()) { + getPayloadInternal()->addTelephone(currentTelephone_); + } + else if (elementHierarchy == "/vCard/ADR/HOME") { + currentAddress_.isHome = true; + } + else if (elementHierarchy == "/vCard/ADR/WORK") { + currentAddress_.isWork = true; + } + else if (elementHierarchy == "/vCard/ADR/POSTAL") { + currentAddress_.isPostal = true; + } + else if (elementHierarchy == "/vCard/ADR/PARCEL") { + currentAddress_.isParcel = true; + } + else if (elementHierarchy == "/vCard/ADR/DOM") { + currentAddress_.deliveryType = VCard::DomesticDelivery; + } + else if (elementHierarchy == "/vCard/ADR/INTL") { + currentAddress_.deliveryType = VCard::InternationalDelivery; + } + else if (elementHierarchy == "/vCard/ADR/PREF") { + currentAddress_.isPreferred = true; + } + else if (elementHierarchy == "/vCard/ADR/POBOX") { + currentAddress_.poBox = currentText_; + } + else if (elementHierarchy == "/vCard/ADR/EXTADD") { + currentAddress_.addressExtension = currentText_; + } + else if (elementHierarchy == "/vCard/ADR/STREET") { + currentAddress_.street = currentText_; + } + else if (elementHierarchy == "/vCard/ADR/LOCALITY") { + currentAddress_.locality = currentText_; + } + else if (elementHierarchy == "/vCard/ADR/REGION") { + currentAddress_.region = currentText_; + } + else if (elementHierarchy == "/vCard/ADR/PCODE") { + currentAddress_.postalCode = currentText_; + } + else if (elementHierarchy == "/vCard/ADR/CTRY") { + currentAddress_.country = currentText_; + } + else if (elementHierarchy == "/vCard/ADR") { + if (!currentAddress_.poBox.empty() || !currentAddress_.addressExtension.empty() || + !currentAddress_.street.empty() || !currentAddress_.locality.empty() || + !currentAddress_.region.empty() || !currentAddress_.region.empty() || + !currentAddress_.postalCode.empty() || !currentAddress_.country.empty()) { + getPayloadInternal()->addAddress(currentAddress_); + } + } + else if (elementHierarchy == "/vCard/LABEL/HOME") { + currentAddressLabel_.isHome = true; + } + else if (elementHierarchy == "/vCard/LABEL/WORK") { + currentAddressLabel_.isWork = true; + } + else if (elementHierarchy == "/vCard/LABEL/POSTAL") { + currentAddressLabel_.isPostal = true; + } + else if (elementHierarchy == "/vCard/LABEL/PARCEL") { + currentAddressLabel_.isParcel = true; + } + else if (elementHierarchy == "/vCard/LABEL/DOM") { + currentAddressLabel_.deliveryType = VCard::DomesticDelivery; + } + else if (elementHierarchy == "/vCard/LABEL/INTL") { + currentAddressLabel_.deliveryType = VCard::InternationalDelivery; + } + else if (elementHierarchy == "/vCard/LABEL/PREF") { + currentAddressLabel_.isPreferred = true; + } + else if (elementHierarchy == "/vCard/LABEL/LINE") { + currentAddressLabel_.lines.push_back(currentText_); + } + else if (elementHierarchy == "/vCard/LABEL") { + getPayloadInternal()->addAddressLabel(currentAddressLabel_); + } + else if (elementHierarchy == "/vCard/JID" && !currentText_.empty()) { + getPayloadInternal()->addJID(JID(currentText_)); + } + else if (elementHierarchy == "/vCard/DESC") { + getPayloadInternal()->setDescription(currentText_); + } + else if (elementHierarchy == "/vCard/ORG/ORGNAME") { + currentOrganization_.name = currentText_; + } + else if (elementHierarchy == "/vCard/ORG/ORGUNIT" && !currentText_.empty()) { + currentOrganization_.units.push_back(currentText_); + } + else if (elementHierarchy == "/vCard/ORG") { + if (!currentOrganization_.name.empty() || !currentOrganization_.units.empty()) { + getPayloadInternal()->addOrganization(currentOrganization_); + } + } + 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_ = NULL; - } - elementStack_.pop_back(); + 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; + if (unknownContentParser_) { + unknownContentParser_->handleCharacterData(text); + } + currentText_ += text; } std::string VCardParser::getElementHierarchy() const { - std::string result; - foreach(const std::string& element, elementStack_) { - result += "/" + element; - } - return result; + std::string result; + for (const auto& element : elementStack_) { + result += "/" + element; + } + return result; } } diff --git a/Swiften/Parser/PayloadParsers/VCardParser.h b/Swiften/Parser/PayloadParsers/VCardParser.h index 0d163f4..5a47cbf 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.h +++ b/Swiften/Parser/PayloadParsers/VCardParser.h @@ -1,38 +1,37 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/VCard.h> #include <Swiften/Parser/GenericPayloadParser.h> -#include <Swiften/Base/API.h> - namespace Swift { - class SerializingParser; - - class SWIFTEN_API VCardParser : public GenericPayloadParser<VCard> { - public: - VCardParser(); - - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); - - private: - std::string getElementHierarchy() const; - - private: - std::vector<std::string> elementStack_; - VCard::EMailAddress currentEMailAddress_; - VCard::Telephone currentTelephone_; - VCard::Address currentAddress_; - VCard::AddressLabel currentAddressLabel_; - VCard::Organization currentOrganization_; - SerializingParser* unknownContentParser_; - std::string currentText_; - }; + class SerializingParser; + + class SWIFTEN_API VCardParser : public GenericPayloadParser<VCard> { + public: + VCardParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + + private: + std::string getElementHierarchy() const; + + private: + std::vector<std::string> elementStack_; + VCard::EMailAddress currentEMailAddress_; + VCard::Telephone currentTelephone_; + VCard::Address currentAddress_; + VCard::AddressLabel currentAddressLabel_; + VCard::Organization currentOrganization_; + SerializingParser* unknownContentParser_; + std::string currentText_; + }; } diff --git a/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp b/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp index 4e0cd47..64559ae 100644 --- a/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp +++ b/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp @@ -12,21 +12,21 @@ VCardUpdateParser::VCardUpdateParser() : level_(TopLevel) { } void VCardUpdateParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - if (level_ == PayloadLevel) { - currentText_ = ""; - } - ++level_; + if (level_ == PayloadLevel) { + currentText_ = ""; + } + ++level_; } void VCardUpdateParser::handleEndElement(const std::string& element, const std::string&) { - --level_; - if (level_ == PayloadLevel && element == "photo") { - getPayloadInternal()->setPhotoHash(currentText_); - } + --level_; + if (level_ == PayloadLevel && element == "photo") { + getPayloadInternal()->setPhotoHash(currentText_); + } } void VCardUpdateParser::handleCharacterData(const std::string& text) { - currentText_ += text; + currentText_ += text; } } diff --git a/Swiften/Parser/PayloadParsers/VCardUpdateParser.h b/Swiften/Parser/PayloadParsers/VCardUpdateParser.h index cbd08e7..914f138 100644 --- a/Swiften/Parser/PayloadParsers/VCardUpdateParser.h +++ b/Swiften/Parser/PayloadParsers/VCardUpdateParser.h @@ -11,22 +11,22 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SerializingParser; + class SerializingParser; - class SWIFTEN_API VCardUpdateParser : public GenericPayloadParser<VCardUpdate> { - public: - VCardUpdateParser(); + class SWIFTEN_API VCardUpdateParser : public GenericPayloadParser<VCardUpdate> { + public: + VCardUpdateParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - int level_; - std::string currentText_; - }; + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + int level_; + std::string currentText_; + }; } diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp index a480813..d3a7211 100644 --- a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp +++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp @@ -4,312 +4,321 @@ * 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 <Swiften/Parser/PayloadParsers/WhiteboardParser.h> -#include <Swiften/Elements/Whiteboard/WhiteboardLineElement.h> -#include <Swiften/Elements/Whiteboard/WhiteboardRectElement.h> -#include <Swiften/Elements/Whiteboard/WhiteboardTextElement.h> -#include <Swiften/Elements/Whiteboard/WhiteboardPolygonElement.h> + +#include <memory> + +#include <boost/lexical_cast.hpp> +#include <boost/optional.hpp> + +#include <Swiften/Elements/Whiteboard/WhiteboardColor.h> +#include <Swiften/Elements/Whiteboard/WhiteboardDeleteOperation.h> #include <Swiften/Elements/Whiteboard/WhiteboardEllipseElement.h> #include <Swiften/Elements/Whiteboard/WhiteboardFreehandPathElement.h> -#include <Swiften/Elements/Whiteboard/WhiteboardColor.h> #include <Swiften/Elements/Whiteboard/WhiteboardInsertOperation.h> +#include <Swiften/Elements/Whiteboard/WhiteboardLineElement.h> +#include <Swiften/Elements/Whiteboard/WhiteboardPolygonElement.h> +#include <Swiften/Elements/Whiteboard/WhiteboardRectElement.h> +#include <Swiften/Elements/Whiteboard/WhiteboardTextElement.h> #include <Swiften/Elements/Whiteboard/WhiteboardUpdateOperation.h> -#include <Swiften/Elements/Whiteboard/WhiteboardDeleteOperation.h> -#include <boost/optional.hpp> -#include <boost/smart_ptr/make_shared.hpp> -#include <boost/lexical_cast.hpp> namespace Swift { - WhiteboardParser::WhiteboardParser() : actualIsText(false), level_(0) { - } + WhiteboardParser::WhiteboardParser() : actualIsText(false), level_(0) { + } - void WhiteboardParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (level_ == 0) { - getPayloadInternal()->setType(stringToType(attributes.getAttributeValue("type").get_value_or(""))); - } else if (level_ == 1) { - std::string type = attributes.getAttributeValue("type").get_value_or(""); - if (type == "insert") { - WhiteboardInsertOperation::ref insertOp = boost::make_shared<WhiteboardInsertOperation>(); - operation = insertOp; - } else if (type == "update") { - WhiteboardUpdateOperation::ref updateOp = boost::make_shared<WhiteboardUpdateOperation>(); - std::string move = attributes.getAttributeValue("newpos").get_value_or("0"); - updateOp->setNewPos(boost::lexical_cast<int>(attributes.getAttributeValue("newpos").get_value_or("0"))); - operation = updateOp; - } else if (type == "delete") { - WhiteboardDeleteOperation::ref deleteOp = boost::make_shared<WhiteboardDeleteOperation>(); - deleteOp->setElementID(attributes.getAttributeValue("elementid").get_value_or("")); - operation = deleteOp; - } - if (operation) { - try { - operation->setID(attributes.getAttributeValue("id").get_value_or("")); - operation->setParentID(attributes.getAttributeValue("parentid").get_value_or("")); - operation->setPos(boost::lexical_cast<int>(attributes.getAttributeValue("pos").get_value_or("0"))); - } catch (boost::bad_lexical_cast&) { - } - } + void WhiteboardParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { + if (level_ == 0) { + getPayloadInternal()->setType(stringToType(attributes.getAttributeValue("type").get_value_or(""))); + } else if (level_ == 1) { + std::string type = attributes.getAttributeValue("type").get_value_or(""); + if (type == "insert") { + WhiteboardInsertOperation::ref insertOp = std::make_shared<WhiteboardInsertOperation>(); + operation = insertOp; + } else if (type == "update") { + WhiteboardUpdateOperation::ref updateOp = std::make_shared<WhiteboardUpdateOperation>(); + std::string move = attributes.getAttributeValue("newpos").get_value_or("0"); + updateOp->setNewPos(boost::lexical_cast<int>(attributes.getAttributeValue("newpos").get_value_or("0"))); + operation = updateOp; + } else if (type == "delete") { + WhiteboardDeleteOperation::ref deleteOp = std::make_shared<WhiteboardDeleteOperation>(); + deleteOp->setElementID(attributes.getAttributeValue("elementid").get_value_or("")); + operation = deleteOp; + } + if (operation) { + try { + operation->setID(attributes.getAttributeValue("id").get_value_or("")); + operation->setParentID(attributes.getAttributeValue("parentid").get_value_or("")); + operation->setPos(boost::lexical_cast<int>(attributes.getAttributeValue("pos").get_value_or("0"))); + } catch (boost::bad_lexical_cast&) { + } + } - } else if (level_ == 2) { - if (element == "line") { - int x1 = 0; - int y1 = 0; - int x2 = 0; - int y2 = 0; - try { - x1 = boost::lexical_cast<int>(attributes.getAttributeValue("x1").get_value_or("0")); - y1 = boost::lexical_cast<int>(attributes.getAttributeValue("y1").get_value_or("0")); - x2 = boost::lexical_cast<int>(attributes.getAttributeValue("x2").get_value_or("0")); - y2 = boost::lexical_cast<int>(attributes.getAttributeValue("y2").get_value_or("0")); - } catch (boost::bad_lexical_cast&) { - } - WhiteboardLineElement::ref whiteboardElement = boost::make_shared<WhiteboardLineElement>(x1, y1, x2, y2); + } else if (level_ == 2) { + if (element == "line") { + int x1 = 0; + int y1 = 0; + int x2 = 0; + int y2 = 0; + try { + x1 = boost::lexical_cast<int>(attributes.getAttributeValue("x1").get_value_or("0")); + y1 = boost::lexical_cast<int>(attributes.getAttributeValue("y1").get_value_or("0")); + x2 = boost::lexical_cast<int>(attributes.getAttributeValue("x2").get_value_or("0")); + y2 = boost::lexical_cast<int>(attributes.getAttributeValue("y2").get_value_or("0")); + } catch (boost::bad_lexical_cast&) { + } + WhiteboardLineElement::ref whiteboardElement = std::make_shared<WhiteboardLineElement>(x1, y1, x2, y2); - WhiteboardColor color(attributes.getAttributeValue("stroke").get_value_or("#000000")); - color.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); - whiteboardElement->setColor(color); + WhiteboardColor color(attributes.getAttributeValue("stroke").get_value_or("#000000")); + color.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); + whiteboardElement->setColor(color); - int penWidth = 1; - try { - penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); - } catch (boost::bad_lexical_cast&) { - } - whiteboardElement->setPenWidth(penWidth); - whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); - getPayloadInternal()->setElement(whiteboardElement); - wbElement = whiteboardElement; - } else if (element == "path") { - WhiteboardFreehandPathElement::ref whiteboardElement = boost::make_shared<WhiteboardFreehandPathElement>(); - std::string pathData = attributes.getAttributeValue("d").get_value_or(""); - std::vector<std::pair<int, int> > points; - if (pathData[0] == 'M') { - size_t pos = 1; - size_t npos; - int x, y; - if (pathData[pos] == ' ') { - pos++; - } - try { - npos = pathData.find(' ', pos); - x = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); - pos = npos+1; - npos = pathData.find('L', pos); - y = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); - pos = npos+1; - if (pathData[pos] == ' ') { - pos++; - } - points.push_back(std::pair<int, int>(x, y)); - while (pos < pathData.size()) { - npos = pathData.find(' ', pos); - x = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); - pos = npos+1; - npos = pathData.find(' ', pos); - y = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); - pos = npos+1; - points.push_back(std::pair<int, int>(x, y)); - } - } catch (boost::bad_lexical_cast&) { - } - } - whiteboardElement->setPoints(points); + int penWidth = 1; + try { + penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); + } catch (boost::bad_lexical_cast&) { + } + whiteboardElement->setPenWidth(penWidth); + whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); + getPayloadInternal()->setElement(whiteboardElement); + wbElement = whiteboardElement; + } else if (element == "path") { + WhiteboardFreehandPathElement::ref whiteboardElement = std::make_shared<WhiteboardFreehandPathElement>(); + std::string pathData = attributes.getAttributeValue("d").get_value_or(""); + std::vector<std::pair<int, int> > points; + if (pathData[0] == 'M') { + size_t pos = 1; + size_t npos; + int x, y; + if (pathData[pos] == ' ') { + pos++; + } + try { + npos = pathData.find(' ', pos); + x = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); + pos = npos+1; + npos = pathData.find('L', pos); + y = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); + pos = npos+1; + if (pathData[pos] == ' ') { + pos++; + } + points.push_back(std::pair<int, int>(x, y)); + while (pos < pathData.size()) { + npos = pathData.find(' ', pos); + x = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); + pos = npos+1; + npos = pathData.find(' ', pos); + y = boost::lexical_cast<int>(pathData.substr(pos, npos-pos)); + pos = npos+1; + points.push_back(std::pair<int, int>(x, y)); + } + } catch (boost::bad_lexical_cast&) { + } + } + whiteboardElement->setPoints(points); - int penWidth = 1; - try { - penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); - } catch (boost::bad_lexical_cast&) { - } - whiteboardElement->setPenWidth(penWidth); + int penWidth = 1; + try { + penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); + } catch (boost::bad_lexical_cast&) { + } + whiteboardElement->setPenWidth(penWidth); - WhiteboardColor color(attributes.getAttributeValue("stroke").get_value_or("#000000")); - color.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); - whiteboardElement->setColor(color); - whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); - getPayloadInternal()->setElement(whiteboardElement); - wbElement = whiteboardElement; - } else if (element == "rect") { - int x = 0; - int y = 0; - int width = 0; - int height = 0; - try { - x = boost::lexical_cast<int>(attributes.getAttributeValue("x").get_value_or("0")); - y = boost::lexical_cast<int>(attributes.getAttributeValue("y").get_value_or("0")); - width = boost::lexical_cast<int>(attributes.getAttributeValue("width").get_value_or("0")); - height = boost::lexical_cast<int>(attributes.getAttributeValue("height").get_value_or("0")); - } catch (boost::bad_lexical_cast&) { - } + WhiteboardColor color(attributes.getAttributeValue("stroke").get_value_or("#000000")); + color.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); + whiteboardElement->setColor(color); + whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); + getPayloadInternal()->setElement(whiteboardElement); + wbElement = whiteboardElement; + } else if (element == "rect") { + int x = 0; + int y = 0; + int width = 0; + int height = 0; + try { + x = boost::lexical_cast<int>(attributes.getAttributeValue("x").get_value_or("0")); + y = boost::lexical_cast<int>(attributes.getAttributeValue("y").get_value_or("0")); + width = boost::lexical_cast<int>(attributes.getAttributeValue("width").get_value_or("0")); + height = boost::lexical_cast<int>(attributes.getAttributeValue("height").get_value_or("0")); + } catch (boost::bad_lexical_cast&) { + } - WhiteboardRectElement::ref whiteboardElement = boost::make_shared<WhiteboardRectElement>(x, y, width, height); + WhiteboardRectElement::ref whiteboardElement = std::make_shared<WhiteboardRectElement>(x, y, width, height); - int penWidth = 1; - try { - penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); - } catch (boost::bad_lexical_cast&) { - } - whiteboardElement->setPenWidth(penWidth); + int penWidth = 1; + try { + penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); + } catch (boost::bad_lexical_cast&) { + } + whiteboardElement->setPenWidth(penWidth); - WhiteboardColor penColor(attributes.getAttributeValue("stroke").get_value_or("#000000")); - WhiteboardColor brushColor(attributes.getAttributeValue("fill").get_value_or("#000000")); - penColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); - brushColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("fill-opacity").get_value_or("1"))); - whiteboardElement->setPenColor(penColor); - whiteboardElement->setBrushColor(brushColor); - whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); - getPayloadInternal()->setElement(whiteboardElement); - wbElement = whiteboardElement; - } else if (element == "polygon") { - WhiteboardPolygonElement::ref whiteboardElement = boost::make_shared<WhiteboardPolygonElement>(); + WhiteboardColor penColor(attributes.getAttributeValue("stroke").get_value_or("#000000")); + WhiteboardColor brushColor(attributes.getAttributeValue("fill").get_value_or("#000000")); + penColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); + brushColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("fill-opacity").get_value_or("1"))); + whiteboardElement->setPenColor(penColor); + whiteboardElement->setBrushColor(brushColor); + whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); + getPayloadInternal()->setElement(whiteboardElement); + wbElement = whiteboardElement; + } else if (element == "polygon") { + WhiteboardPolygonElement::ref whiteboardElement = std::make_shared<WhiteboardPolygonElement>(); - std::string pointsData = attributes.getAttributeValue("points").get_value_or(""); - std::vector<std::pair<int, int> > points; - size_t pos = 0; - size_t npos; - int x, y; - try { - while (pos < pointsData.size()) { - npos = pointsData.find(',', pos); - x = boost::lexical_cast<int>(pointsData.substr(pos, npos-pos)); - pos = npos+1; - npos = pointsData.find(' ', pos); - y = boost::lexical_cast<int>(pointsData.substr(pos, npos-pos)); - pos = npos+1; - points.push_back(std::pair<int, int>(x, y)); - } - } catch (boost::bad_lexical_cast&) { - } + std::string pointsData = attributes.getAttributeValue("points").get_value_or(""); + std::vector<std::pair<int, int> > points; + size_t pos = 0; + size_t npos; + int x, y; + try { + while (pos < pointsData.size()) { + npos = pointsData.find(',', pos); + x = boost::lexical_cast<int>(pointsData.substr(pos, npos-pos)); + pos = npos+1; + npos = pointsData.find(' ', pos); + y = boost::lexical_cast<int>(pointsData.substr(pos, npos-pos)); + pos = npos+1; + points.push_back(std::pair<int, int>(x, y)); + } + } catch (boost::bad_lexical_cast&) { + } - whiteboardElement->setPoints(points); + whiteboardElement->setPoints(points); - int penWidth = 1; - try { - penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); - } catch (boost::bad_lexical_cast&) { - } - whiteboardElement->setPenWidth(penWidth); + int penWidth = 1; + try { + penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); + } catch (boost::bad_lexical_cast&) { + } + whiteboardElement->setPenWidth(penWidth); - WhiteboardColor penColor(attributes.getAttributeValue("stroke").get_value_or("#000000")); - WhiteboardColor brushColor(attributes.getAttributeValue("fill").get_value_or("#000000")); - penColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); - brushColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("fill-opacity").get_value_or("1"))); - whiteboardElement->setPenColor(penColor); - whiteboardElement->setBrushColor(brushColor); - whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); - getPayloadInternal()->setElement(whiteboardElement); - wbElement = whiteboardElement; - } else if (element == "text") { - int x = 0; - int y = 0; - try { - x = boost::lexical_cast<int>(attributes.getAttributeValue("x").get_value_or("0")); - y = boost::lexical_cast<int>(attributes.getAttributeValue("y").get_value_or("0")); - } catch (boost::bad_lexical_cast&) { - } + WhiteboardColor penColor(attributes.getAttributeValue("stroke").get_value_or("#000000")); + WhiteboardColor brushColor(attributes.getAttributeValue("fill").get_value_or("#000000")); + penColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); + brushColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("fill-opacity").get_value_or("1"))); + whiteboardElement->setPenColor(penColor); + whiteboardElement->setBrushColor(brushColor); + whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); + getPayloadInternal()->setElement(whiteboardElement); + wbElement = whiteboardElement; + } else if (element == "text") { + int x = 0; + int y = 0; + try { + x = boost::lexical_cast<int>(attributes.getAttributeValue("x").get_value_or("0")); + y = boost::lexical_cast<int>(attributes.getAttributeValue("y").get_value_or("0")); + } catch (boost::bad_lexical_cast&) { + } - WhiteboardTextElement::ref whiteboardElement = boost::make_shared<WhiteboardTextElement>(x, y); + WhiteboardTextElement::ref whiteboardElement = std::make_shared<WhiteboardTextElement>(x, y); - actualIsText = true; - WhiteboardColor color(attributes.getAttributeValue("fill").get_value_or("#000000")); - color.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); - whiteboardElement->setColor(color); + actualIsText = true; + WhiteboardColor color(attributes.getAttributeValue("fill").get_value_or("#000000")); + color.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); + whiteboardElement->setColor(color); - int fontSize = 1; - try { - fontSize = boost::lexical_cast<int>(attributes.getAttributeValue("font-size").get_value_or("12")); - } catch (boost::bad_lexical_cast&) { - } - whiteboardElement->setSize(fontSize); - whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); - getPayloadInternal()->setElement(whiteboardElement); - wbElement = whiteboardElement; - } else if (element == "ellipse") { - int cx = 0; - int cy = 0; - int rx = 0; - int ry = 0; - try { - cx = boost::lexical_cast<int>(attributes.getAttributeValue("cx").get_value_or("0")); - cy = boost::lexical_cast<int>(attributes.getAttributeValue("cy").get_value_or("0")); - rx = boost::lexical_cast<int>(attributes.getAttributeValue("rx").get_value_or("0")); - ry = boost::lexical_cast<int>(attributes.getAttributeValue("ry").get_value_or("0")); - } catch (boost::bad_lexical_cast&) { - } + int fontSize = 1; + try { + fontSize = boost::lexical_cast<int>(attributes.getAttributeValue("font-size").get_value_or("12")); + } catch (boost::bad_lexical_cast&) { + } + whiteboardElement->setSize(fontSize); + whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); + getPayloadInternal()->setElement(whiteboardElement); + wbElement = whiteboardElement; + } else if (element == "ellipse") { + int cx = 0; + int cy = 0; + int rx = 0; + int ry = 0; + try { + cx = boost::lexical_cast<int>(attributes.getAttributeValue("cx").get_value_or("0")); + cy = boost::lexical_cast<int>(attributes.getAttributeValue("cy").get_value_or("0")); + rx = boost::lexical_cast<int>(attributes.getAttributeValue("rx").get_value_or("0")); + ry = boost::lexical_cast<int>(attributes.getAttributeValue("ry").get_value_or("0")); + } catch (boost::bad_lexical_cast&) { + } - WhiteboardEllipseElement::ref whiteboardElement = boost::make_shared<WhiteboardEllipseElement>(cx, cy, rx, ry); + WhiteboardEllipseElement::ref whiteboardElement = std::make_shared<WhiteboardEllipseElement>(cx, cy, rx, ry); - int penWidth = 1; - try { - penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); - } catch (boost::bad_lexical_cast&) { - } - whiteboardElement->setPenWidth(penWidth); + int penWidth = 1; + try { + penWidth = boost::lexical_cast<int>(attributes.getAttributeValue("stroke-width").get_value_or("1")); + } catch (boost::bad_lexical_cast&) { + } + whiteboardElement->setPenWidth(penWidth); - WhiteboardColor penColor(attributes.getAttributeValue("stroke").get_value_or("#000000")); - WhiteboardColor brushColor(attributes.getAttributeValue("fill").get_value_or("#000000")); - penColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); - brushColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("fill-opacity").get_value_or("1"))); - whiteboardElement->setPenColor(penColor); - whiteboardElement->setBrushColor(brushColor); - whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); - getPayloadInternal()->setElement(whiteboardElement); - wbElement = whiteboardElement; - } - } - ++level_; - } + WhiteboardColor penColor(attributes.getAttributeValue("stroke").get_value_or("#000000")); + WhiteboardColor brushColor(attributes.getAttributeValue("fill").get_value_or("#000000")); + penColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("opacity").get_value_or("1"))); + brushColor.setAlpha(opacityToAlpha(attributes.getAttributeValue("fill-opacity").get_value_or("1"))); + whiteboardElement->setPenColor(penColor); + whiteboardElement->setBrushColor(brushColor); + whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or("")); + getPayloadInternal()->setElement(whiteboardElement); + wbElement = whiteboardElement; + } + } + ++level_; + } - void WhiteboardParser::handleEndElement(const std::string& element, const std::string&) { - --level_; - if (level_ == 0) { - getPayloadInternal()->setData(data_); - } else if (level_ == 1) { - WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(operation); - if (insertOp) { - insertOp->setElement(wbElement); - } + void WhiteboardParser::handleEndElement(const std::string& element, const std::string&) { + --level_; + if (level_ == 0) { + getPayloadInternal()->setData(data_); + } else if (level_ == 1) { + WhiteboardInsertOperation::ref insertOp = std::dynamic_pointer_cast<WhiteboardInsertOperation>(operation); + if (insertOp) { + insertOp->setElement(wbElement); + } - WhiteboardUpdateOperation::ref updateOp = boost::dynamic_pointer_cast<WhiteboardUpdateOperation>(operation); - if (updateOp) { - updateOp->setElement(wbElement); - } - getPayloadInternal()->setOperation(operation); - } else if (level_ == 2) { - if (element == "text") { - actualIsText = false; - } - } - } + WhiteboardUpdateOperation::ref updateOp = std::dynamic_pointer_cast<WhiteboardUpdateOperation>(operation); + if (updateOp) { + updateOp->setElement(wbElement); + } + getPayloadInternal()->setOperation(operation); + } else if (level_ == 2) { + if (element == "text") { + actualIsText = false; + } + } + } - void WhiteboardParser::handleCharacterData(const std::string& data) { - if (level_ == 3 && actualIsText) { - WhiteboardTextElement::ref element = boost::dynamic_pointer_cast<WhiteboardTextElement>(getPayloadInternal()->getElement()); - element->setText(data); - } - } + void WhiteboardParser::handleCharacterData(const std::string& data) { + if (level_ == 3 && actualIsText) { + WhiteboardTextElement::ref element = std::dynamic_pointer_cast<WhiteboardTextElement>(getPayloadInternal()->getElement()); + element->setText(data); + } + } - WhiteboardPayload::Type WhiteboardParser::stringToType(const std::string& type) const { - if (type == "data") { - return WhiteboardPayload::Data; - } else if (type == "session-request") { - return WhiteboardPayload::SessionRequest; - } else if (type == "session-accept") { - return WhiteboardPayload::SessionAccept; - } else if (type == "session-terminate") { - return WhiteboardPayload::SessionTerminate; - } else { - return WhiteboardPayload::UnknownType; - } - } + WhiteboardPayload::Type WhiteboardParser::stringToType(const std::string& type) const { + if (type == "data") { + return WhiteboardPayload::Data; + } else if (type == "session-request") { + return WhiteboardPayload::SessionRequest; + } else if (type == "session-accept") { + return WhiteboardPayload::SessionAccept; + } else if (type == "session-terminate") { + return WhiteboardPayload::SessionTerminate; + } else { + return WhiteboardPayload::UnknownType; + } + } - int WhiteboardParser::opacityToAlpha(std::string opacity) const { - int value = 255; - if (opacity.find('.') != std::string::npos) { - opacity = opacity.substr(opacity.find('.')+1, 2); - try { - value = boost::lexical_cast<int>(opacity)*255/100; - } catch (boost::bad_lexical_cast&) { - } - } - return value; - } + int WhiteboardParser::opacityToAlpha(std::string opacity) const { + int value = 255; + if (opacity.find('.') != std::string::npos) { + opacity = opacity.substr(opacity.find('.')+1, 2); + try { + value = boost::lexical_cast<int>(opacity)*255/100; + } catch (boost::bad_lexical_cast&) { + } + } + return value; + } } diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.h b/Swiften/Parser/PayloadParsers/WhiteboardParser.h index 89848b5..2f22624 100644 --- a/Swiften/Parser/PayloadParsers/WhiteboardParser.h +++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -13,29 +13,29 @@ #pragma once #include <Swiften/Base/API.h> -#include <Swiften/Elements/WhiteboardPayload.h> -#include <Swiften/Parser/GenericPayloadParser.h> #include <Swiften/Elements/Whiteboard/WhiteboardElement.h> #include <Swiften/Elements/Whiteboard/WhiteboardOperation.h> +#include <Swiften/Elements/WhiteboardPayload.h> +#include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API WhiteboardParser : public Swift::GenericPayloadParser<WhiteboardPayload> { - public: - WhiteboardParser(); + class SWIFTEN_API WhiteboardParser : public Swift::GenericPayloadParser<WhiteboardPayload> { + public: + WhiteboardParser(); - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string&); - virtual void handleCharacterData(const std::string& data); + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); - private: - WhiteboardPayload::Type stringToType(const std::string& type) const; - int opacityToAlpha(std::string opacity) const; + private: + WhiteboardPayload::Type stringToType(const std::string& type) const; + int opacityToAlpha(std::string opacity) const; - private: - bool actualIsText; - int level_; - std::string data_; - WhiteboardElement::ref wbElement; - WhiteboardOperation::ref operation; - }; + private: + bool actualIsText; + int level_; + std::string data_; + WhiteboardElement::ref wbElement; + WhiteboardOperation::ref operation; + }; } |