diff options
Diffstat (limited to 'Swiften/Parser')
421 files changed, 16182 insertions, 11704 deletions
diff --git a/Swiften/Parser/Attribute.h b/Swiften/Parser/Attribute.h index f1f9a83..07e63b4 100644 --- a/Swiften/Parser/Attribute.h +++ b/Swiften/Parser/Attribute.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once @@ -9,25 +9,33 @@ #include <string> namespace Swift { - class Attribute { - public: - Attribute(const std::string& name, const std::string& ns) : name(name), ns(ns) { - } - - const std::string& getName() const { - return name; - } - - const std::string& getNamespace() const { - return ns; - } - - bool operator==(const Attribute& o) const { - return o.name == name && o.ns == ns; - } - - private: - std::string name; - std::string ns; - }; + class Attribute { + public: + Attribute(const std::string& name, const std::string& ns) : name(name), ns(ns) { + } + + Attribute(const std::string& name, const std::string& ns, const std::string& prefix) : name(name), ns(ns), prefix(prefix) { + } + + const std::string& getName() const { + return name; + } + + const std::string& getNamespace() const { + return ns; + } + + const std::string& getPrefix() const { + return prefix; + } + + bool operator==(const Attribute& o) const { + return o.name == name && o.ns == ns; + } + + private: + std::string name; + std::string ns; + std::string prefix; + }; } diff --git a/Swiften/Parser/AttributeMap.cpp b/Swiften/Parser/AttributeMap.cpp index d508157..7814a64 100644 --- a/Swiften/Parser/AttributeMap.cpp +++ b/Swiften/Parser/AttributeMap.cpp @@ -1,55 +1,60 @@ /* - * Copyright (c) 2011 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/AttributeMap.h> #include <algorithm> + #include <boost/optional.hpp> -#include <boost/lambda/lambda.hpp> -#include <boost/lambda/bind.hpp> using namespace Swift; -namespace lambda = boost::lambda; AttributeMap::AttributeMap() { } std::string AttributeMap::getAttribute(const std::string& attribute, const std::string& ns) const { - AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), - lambda::bind(&AttributeMap::Entry::getAttribute, lambda::_1) == Attribute(attribute, ns)); - if (i == attributes.end()) { - return ""; - } - else { - return i->getValue(); - } + const auto i = std::find_if(attributes.begin(), attributes.end(), [&](const Entry& entry) { + return entry.getAttribute() == Attribute(attribute, ns); + }); + if (i == attributes.end()) { + return ""; + } + else { + return i->getValue(); + } } bool AttributeMap::getBoolAttribute(const std::string& attribute, bool defaultValue) const { - AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), - lambda::bind(&AttributeMap::Entry::getAttribute, lambda::_1) == Attribute(attribute, "")); - if (i == attributes.end()) { - return defaultValue; - } - else { - return i->getValue() == "true" || i->getValue() == "1"; - } + const auto i = std::find_if(attributes.begin(), attributes.end(), [&](const Entry& entry) { + return entry.getAttribute() == Attribute(attribute, ""); + }); + if (i == attributes.end()) { + return defaultValue; + } + else { + return i->getValue() == "true" || i->getValue() == "1"; + } } boost::optional<std::string> AttributeMap::getAttributeValue(const std::string& attribute) const { - AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), - lambda::bind(&AttributeMap::Entry::getAttribute, lambda::_1) == Attribute(attribute, "")); - if (i == attributes.end()) { - return boost::optional<std::string>(); - } - else { - return i->getValue(); - } + const auto i = std::find_if(attributes.begin(), attributes.end(), [&](const Entry& entry) { + return entry.getAttribute() == Attribute(attribute, ""); + }); + if (i == attributes.end()) { + return boost::optional<std::string>(); + } + else { + return i->getValue(); + } } void AttributeMap::addAttribute(const std::string& name, const std::string& ns, const std::string& value) { - attributes.push_back(Entry(Attribute(name, ns), value)); + attributes.push_back(Entry(Attribute(name, ns), value)); +} + +void AttributeMap::addAttribute(const std::string& name, const std::string& ns, const std::string& prefix, const std::string& value) { + attributes.push_back(Entry(Attribute(name, ns, prefix), value)); } diff --git a/Swiften/Parser/AttributeMap.h b/Swiften/Parser/AttributeMap.h index 77b9c23..26d5826 100644 --- a/Swiften/Parser/AttributeMap.h +++ b/Swiften/Parser/AttributeMap.h @@ -1,54 +1,56 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <vector> -#include <string> #include <map> -#include <boost/optional/optional_fwd.hpp> +#include <string> +#include <vector> + +#include <boost/optional/optional.hpp> #include <Swiften/Base/API.h> #include <Swiften/Parser/Attribute.h> namespace Swift { - class SWIFTEN_API AttributeMap { - public: - class Entry { - public: - Entry(const Attribute& attribute, const std::string& value) : attribute(attribute), value(value) { - } - - const Attribute& getAttribute() const { - return attribute; - } - - const std::string& getValue() const { - return value; - } - - private: - Attribute attribute; - std::string value; - }; - - AttributeMap(); - - std::string getAttribute(const std::string& attribute, const std::string& ns = "") const; - bool getBoolAttribute(const std::string& attribute, bool defaultValue = false) const; - boost::optional<std::string> getAttributeValue(const std::string&) const; - - void addAttribute(const std::string& name, const std::string& ns, const std::string& value); - - const std::vector<Entry>& getEntries() const { - return attributes; - } - - private: - typedef std::vector<Entry> AttributeValueMap; - AttributeValueMap attributes; - }; + class SWIFTEN_API AttributeMap { + public: + class Entry { + public: + Entry(const Attribute& attribute, const std::string& value) : attribute(attribute), value(value) { + } + + const Attribute& getAttribute() const { + return attribute; + } + + const std::string& getValue() const { + return value; + } + + private: + Attribute attribute; + std::string value; + }; + + AttributeMap(); + + std::string getAttribute(const std::string& attribute, const std::string& ns = "") const; + bool getBoolAttribute(const std::string& attribute, bool defaultValue = false) const; + boost::optional<std::string> getAttributeValue(const std::string&) const; + + void addAttribute(const std::string& name, const std::string& ns, const std::string& value); + void addAttribute(const std::string& name, const std::string& ns, const std::string& prefix, const std::string& value); + + const std::vector<Entry>& getEntries() const { + return attributes; + } + + private: + typedef std::vector<Entry> AttributeValueMap; + AttributeValueMap attributes; + }; } diff --git a/Swiften/Parser/AuthChallengeParser.cpp b/Swiften/Parser/AuthChallengeParser.cpp index 7cb665a..cf69672 100644 --- a/Swiften/Parser/AuthChallengeParser.cpp +++ b/Swiften/Parser/AuthChallengeParser.cpp @@ -1,10 +1,11 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/AuthChallengeParser.h> + #include <Swiften/StringCodecs/Base64.h> namespace Swift { @@ -13,18 +14,18 @@ AuthChallengeParser::AuthChallengeParser() : GenericElementParser<AuthChallenge> } void AuthChallengeParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++depth; + ++depth; } void AuthChallengeParser::handleEndElement(const std::string&, const std::string&) { - --depth; - if (depth == 0) { - getElementGeneric()->setValue(Base64::decode(text)); - } + --depth; + if (depth == 0) { + getElementGeneric()->setValue(Base64::decode(text)); + } } void AuthChallengeParser::handleCharacterData(const std::string& text) { - this->text += text; + this->text += text; } } diff --git a/Swiften/Parser/AuthChallengeParser.h b/Swiften/Parser/AuthChallengeParser.h index 31b6d89..48e2bfb 100644 --- a/Swiften/Parser/AuthChallengeParser.h +++ b/Swiften/Parser/AuthChallengeParser.h @@ -1,26 +1,28 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> -#include <Swiften/Elements/AuthChallenge.h> #include <string> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/AuthChallenge.h> +#include <Swiften/Parser/GenericElementParser.h> + namespace Swift { - class AuthChallengeParser : public GenericElementParser<AuthChallenge> { - public: - AuthChallengeParser(); + class SWIFTEN_API AuthChallengeParser : public GenericElementParser<AuthChallenge> { + public: + AuthChallengeParser(); - virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string& ns); - virtual void handleCharacterData(const std::string&); + virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string& ns); + virtual void handleCharacterData(const std::string&); - private: - int depth; - std::string text; - }; + private: + int depth; + std::string text; + }; } diff --git a/Swiften/Parser/AuthFailureParser.h b/Swiften/Parser/AuthFailureParser.h index 1a71ea4..1706290 100644 --- a/Swiften/Parser/AuthFailureParser.h +++ b/Swiften/Parser/AuthFailureParser.h @@ -1,17 +1,18 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/AuthFailure.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class AuthFailureParser : public GenericElementParser<AuthFailure> { - public: - AuthFailureParser() : GenericElementParser<AuthFailure>() {} - }; + class SWIFTEN_API AuthFailureParser : public GenericElementParser<AuthFailure> { + public: + AuthFailureParser() : GenericElementParser<AuthFailure>() {} + }; } diff --git a/Swiften/Parser/AuthRequestParser.cpp b/Swiften/Parser/AuthRequestParser.cpp index 04d9e4f..a24be8d 100644 --- a/Swiften/Parser/AuthRequestParser.cpp +++ b/Swiften/Parser/AuthRequestParser.cpp @@ -1,10 +1,11 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/AuthRequestParser.h> + #include <Swiften/StringCodecs/Base64.h> namespace Swift { @@ -13,21 +14,21 @@ AuthRequestParser::AuthRequestParser() : GenericElementParser<AuthRequest>(), de } void AuthRequestParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attribute) { - if (depth_ == 0) { - getElementGeneric()->setMechanism(attribute.getAttribute("mechanism")); - } - ++depth_; + if (depth_ == 0) { + getElementGeneric()->setMechanism(attribute.getAttribute("mechanism")); + } + ++depth_; } void AuthRequestParser::handleEndElement(const std::string&, const std::string&) { - --depth_; - if (depth_ == 0) { - getElementGeneric()->setMessage(createSafeByteArray(Base64::decode(text_))); - } + --depth_; + if (depth_ == 0) { + getElementGeneric()->setMessage(createSafeByteArray(Base64::decode(text_))); + } } void AuthRequestParser::handleCharacterData(const std::string& text) { - text_ += text; + text_ += text; } } diff --git a/Swiften/Parser/AuthRequestParser.h b/Swiften/Parser/AuthRequestParser.h index 1562df7..ac94abf 100644 --- a/Swiften/Parser/AuthRequestParser.h +++ b/Swiften/Parser/AuthRequestParser.h @@ -1,26 +1,28 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> -#include <Swiften/Elements/AuthRequest.h> #include <string> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/AuthRequest.h> +#include <Swiften/Parser/GenericElementParser.h> + namespace Swift { - class AuthRequestParser : public GenericElementParser<AuthRequest> { - public: - AuthRequestParser(); + class SWIFTEN_API AuthRequestParser : public GenericElementParser<AuthRequest> { + public: + AuthRequestParser(); - virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string& ns); - virtual void handleCharacterData(const std::string&); + virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string& ns); + virtual void handleCharacterData(const std::string&); - private: - std::string text_; - int depth_; - }; + private: + std::string text_; + int depth_; + }; } diff --git a/Swiften/Parser/AuthResponseParser.cpp b/Swiften/Parser/AuthResponseParser.cpp index 7f9a530..59f6455 100644 --- a/Swiften/Parser/AuthResponseParser.cpp +++ b/Swiften/Parser/AuthResponseParser.cpp @@ -1,10 +1,11 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/AuthResponseParser.h> + #include <Swiften/StringCodecs/Base64.h> namespace Swift { @@ -13,18 +14,18 @@ AuthResponseParser::AuthResponseParser() : GenericElementParser<AuthResponse>(), } void AuthResponseParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++depth; + ++depth; } void AuthResponseParser::handleEndElement(const std::string&, const std::string&) { - --depth; - if (depth == 0) { - getElementGeneric()->setValue(createSafeByteArray(Base64::decode(text))); - } + --depth; + if (depth == 0) { + getElementGeneric()->setValue(createSafeByteArray(Base64::decode(text))); + } } void AuthResponseParser::handleCharacterData(const std::string& text) { - this->text += text; + this->text += text; } } diff --git a/Swiften/Parser/AuthResponseParser.h b/Swiften/Parser/AuthResponseParser.h index 3dc2282..6cbfa22 100644 --- a/Swiften/Parser/AuthResponseParser.h +++ b/Swiften/Parser/AuthResponseParser.h @@ -1,26 +1,28 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> -#include <Swiften/Elements/AuthResponse.h> #include <string> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/AuthResponse.h> +#include <Swiften/Parser/GenericElementParser.h> + namespace Swift { - class AuthResponseParser : public GenericElementParser<AuthResponse> { - public: - AuthResponseParser(); + class SWIFTEN_API AuthResponseParser : public GenericElementParser<AuthResponse> { + public: + AuthResponseParser(); - virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string& ns); - virtual void handleCharacterData(const std::string&); + virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string& ns); + virtual void handleCharacterData(const std::string&); - private: - int depth; - std::string text; - }; + private: + int depth; + std::string text; + }; } diff --git a/Swiften/Parser/AuthSuccessParser.cpp b/Swiften/Parser/AuthSuccessParser.cpp index 50246a4..964fd6c 100644 --- a/Swiften/Parser/AuthSuccessParser.cpp +++ b/Swiften/Parser/AuthSuccessParser.cpp @@ -1,10 +1,11 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/AuthSuccessParser.h> + #include <Swiften/StringCodecs/Base64.h> namespace Swift { @@ -13,18 +14,18 @@ AuthSuccessParser::AuthSuccessParser() : GenericElementParser<AuthSuccess>(), de } void AuthSuccessParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++depth; + ++depth; } void AuthSuccessParser::handleEndElement(const std::string&, const std::string&) { - --depth; - if (depth == 0) { - getElementGeneric()->setValue(Base64::decode(text)); - } + --depth; + if (depth == 0) { + getElementGeneric()->setValue(Base64::decode(text)); + } } void AuthSuccessParser::handleCharacterData(const std::string& text) { - this->text += text; + this->text += text; } } diff --git a/Swiften/Parser/AuthSuccessParser.h b/Swiften/Parser/AuthSuccessParser.h index b726b95..cedc8d1 100644 --- a/Swiften/Parser/AuthSuccessParser.h +++ b/Swiften/Parser/AuthSuccessParser.h @@ -1,26 +1,28 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> -#include <Swiften/Elements/AuthSuccess.h> #include <string> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/AuthSuccess.h> +#include <Swiften/Parser/GenericElementParser.h> + namespace Swift { - class AuthSuccessParser : public GenericElementParser<AuthSuccess> { - public: - AuthSuccessParser(); + class SWIFTEN_API AuthSuccessParser : public GenericElementParser<AuthSuccess> { + public: + AuthSuccessParser(); - virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string& ns); - virtual void handleCharacterData(const std::string&); + virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string& ns); + virtual void handleCharacterData(const std::string&); - private: - int depth; - std::string text; - }; + private: + int depth; + std::string text; + }; } diff --git a/Swiften/Parser/BOSHBodyExtractor.cpp b/Swiften/Parser/BOSHBodyExtractor.cpp index 715a448..ff56792 100644 --- a/Swiften/Parser/BOSHBodyExtractor.cpp +++ b/Swiften/Parser/BOSHBodyExtractor.cpp @@ -1,139 +1,140 @@ /* - * Copyright (c) 2011-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/BOSHBodyExtractor.h> -#include <boost/shared_ptr.hpp> -#include <boost/numeric/conversion/cast.hpp> +#include <memory> -#include <Swiften/Parser/XMLParserClient.h> #include <Swiften/Parser/XMLParser.h> +#include <Swiften/Parser/XMLParserClient.h> #include <Swiften/Parser/XMLParserFactory.h> namespace Swift { class BOSHBodyParserClient : public XMLParserClient { - public: - BOSHBodyParserClient(BOSHBodyExtractor* bodyExtractor) : bodyExtractor(bodyExtractor) { - } + public: + BOSHBodyParserClient(BOSHBodyExtractor* bodyExtractor) : bodyExtractor(bodyExtractor) { + } - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - bodyExtractor->body->attributes = attributes; - } + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + bodyExtractor->body->attributes = attributes; + } - virtual void handleEndElement(const std::string&, const std::string&) { - } + virtual void handleEndElement(const std::string&, const std::string&) { + } - virtual void handleCharacterData(const std::string&) { - } + virtual void handleCharacterData(const std::string&) { + } - private: - BOSHBodyExtractor* bodyExtractor; + private: + BOSHBodyExtractor* bodyExtractor; }; inline bool isWhitespace(unsigned char c) { - return c == ' ' || c == '\n' || c == '\t' || c == '\r'; + return c == ' ' || c == '\n' || c == '\t' || c == '\r'; } BOSHBodyExtractor::BOSHBodyExtractor(XMLParserFactory* parserFactory, const ByteArray& data) { - // Look for the opening body element - ByteArray::const_iterator i = data.begin(); - while (i < data.end() && isWhitespace(*i)) { - ++i; - } - if (std::distance(i, data.end()) < 6 || *i != '<' || *(i+1) != 'b' || *(i+2) != 'o' || *(i+3) != 'd' || *(i+4) != 'y' || !(isWhitespace(*(i+5)) || *(i+5) == '>' || *(i+5) == '/')) { - return; - } - i += 5; - - // Parse until end of element - bool inSingleQuote = false; - bool inDoubleQuote = false; - bool endStartTagSeen = false; - bool endElementSeen = false; - for (; i != data.end(); ++i) { - char c = static_cast<char>(*i); - if (inSingleQuote) { - if (c == '\'') { - inSingleQuote = false; - } - } - else if (inDoubleQuote) { - if (c == '"') { - inDoubleQuote = false; - } - } - else if (c == '\'') { - inSingleQuote = true; - } - else if (c == '"') { - inDoubleQuote = true; - } - else if (c == '/') { - if (i + 1 == data.end() || *(i+1) != '>') { - return; - } - else { - endElementSeen = true; - endStartTagSeen = true; - i += 2; - break; - } - } - else if (c == '>') { - endStartTagSeen = true; - i += 1; - break; - } - } - - if (!endStartTagSeen) { - return; - } - - // Look for the end of the element - ByteArray::const_reverse_iterator j = data.rbegin(); - if (!endElementSeen) { - while (isWhitespace(*j) && j < data.rend()) { - ++j; - } - - if (j == data.rend() || *j != '>') { - return; - } - ++j; - - while (j < data.rend() && isWhitespace(*j)) { - ++j; - } - - if (std::distance(j, data.rend()) < 6 || *(j+5) != '<' || *(j+4) != '/' || *(j+3) != 'b' || *(j+2) != 'o' || *(j+1) != 'd' || *j != 'y') { - return; - } - j += 6; - } - - body = BOSHBody(); - if (!endElementSeen) { - body->content = std::string( - reinterpret_cast<const char*>(vecptr(data) + std::distance(data.begin(), i)), - boost::numeric_cast<size_t>(std::distance(i, j.base()))); - } - - // Parse the body element - BOSHBodyParserClient parserClient(this); - boost::shared_ptr<XMLParser> parser(parserFactory->createXMLParser(&parserClient)); - if (!parser->parse(std::string( - reinterpret_cast<const char*>(vecptr(data)), - boost::numeric_cast<size_t>(std::distance(data.begin(), i))))) { - /* TODO: This needs to be only validating the BOSH <body> element, so that XMPP parsing errors are caught at - the correct higher layer */ - body = boost::optional<BOSHBody>(); - return; - } + // Look for the opening body element + ByteArray::const_iterator i = data.begin(); + while (i < data.end() && isWhitespace(*i)) { + ++i; + } + if (std::distance(i, data.end()) < 6 || *i != '<' || *(i+1) != 'b' || *(i+2) != 'o' || *(i+3) != 'd' || *(i+4) != 'y' || !(isWhitespace(*(i+5)) || *(i+5) == '>' || *(i+5) == '/')) { + return; + } + i += 5; + + // Parse until end of element + bool inSingleQuote = false; + bool inDoubleQuote = false; + bool endStartTagSeen = false; + bool endElementSeen = false; + for (; i != data.end(); ++i) { + char c = static_cast<char>(*i); + if (inSingleQuote) { + if (c == '\'') { + inSingleQuote = false; + } + } + else if (inDoubleQuote) { + if (c == '"') { + inDoubleQuote = false; + } + } + else if (c == '\'') { + inSingleQuote = true; + } + else if (c == '"') { + inDoubleQuote = true; + } + else if (c == '/') { + if (i + 1 == data.end() || *(i+1) != '>') { + return; + } + else { + endElementSeen = true; + endStartTagSeen = true; + i += 2; + break; + } + } + else if (c == '>') { + endStartTagSeen = true; + i += 1; + break; + } + } + + if (!endStartTagSeen) { + return; + } + + // Look for the end of the element + ByteArray::const_reverse_iterator j = data.rbegin(); + if (!endElementSeen) { + while (isWhitespace(*j) && j < data.rend()) { + ++j; + } + + if (j == data.rend() || *j != '>') { + return; + } + ++j; + + while (j < data.rend() && isWhitespace(*j)) { + ++j; + } + + if (std::distance(j, data.rend()) < 6 || *(j+5) != '<' || *(j+4) != '/' || *(j+3) != 'b' || *(j+2) != 'o' || *(j+1) != 'd' || *j != 'y') { + return; + } + j += 6; + } + + body = BOSHBody(); + if (!endElementSeen) { + assert(i <= j.base()); + body->content = std::string( + reinterpret_cast<const char*>(vecptr(data) + std::distance(data.begin(), i)), + static_cast<size_t>(std::distance(i, j.base()))); + } + + // Parse the body element + BOSHBodyParserClient parserClient(this); + std::shared_ptr<XMLParser> parser(parserFactory->createXMLParser(&parserClient)); + assert(data.begin() <= i); + if (!parser->parse(std::string( + reinterpret_cast<const char*>(vecptr(data)), + static_cast<size_t>(std::distance(data.begin(), i))))) { + /* TODO: This needs to be only validating the BOSH <body> element, so that XMPP parsing errors are caught at + the correct higher layer */ + body = boost::optional<BOSHBody>(); + return; + } } } diff --git a/Swiften/Parser/BOSHBodyExtractor.h b/Swiften/Parser/BOSHBodyExtractor.h index 7510761..ba56b41 100644 --- a/Swiften/Parser/BOSHBodyExtractor.h +++ b/Swiften/Parser/BOSHBodyExtractor.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once @@ -13,23 +13,23 @@ #include <Swiften/Parser/XMLParserClient.h> namespace Swift { - class XMLParserFactory; - - class SWIFTEN_API BOSHBodyExtractor { - friend class BOSHBodyParserClient; - public: - struct BOSHBody { - AttributeMap attributes; - std::string content; - }; - - BOSHBodyExtractor(XMLParserFactory* parserFactory, const ByteArray& data); - - const boost::optional<BOSHBody>& getBody() const { - return body; - } - - private: - boost::optional<BOSHBody> body; - }; + class XMLParserFactory; + + class SWIFTEN_API BOSHBodyExtractor { + friend class BOSHBodyParserClient; + public: + struct BOSHBody { + AttributeMap attributes; + std::string content; + }; + + BOSHBodyExtractor(XMLParserFactory* parserFactory, const ByteArray& data); + + const boost::optional<BOSHBody>& getBody() const { + return body; + } + + private: + boost::optional<BOSHBody> body; + }; } diff --git a/Swiften/Parser/ComponentHandshakeParser.cpp b/Swiften/Parser/ComponentHandshakeParser.cpp index c58caf0..f98503d 100644 --- a/Swiften/Parser/ComponentHandshakeParser.cpp +++ b/Swiften/Parser/ComponentHandshakeParser.cpp @@ -1,10 +1,11 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/ComponentHandshakeParser.h> + #include <Swiften/StringCodecs/Base64.h> namespace Swift { @@ -13,18 +14,18 @@ ComponentHandshakeParser::ComponentHandshakeParser() : GenericElementParser<Comp } void ComponentHandshakeParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++depth; + ++depth; } void ComponentHandshakeParser::handleEndElement(const std::string&, const std::string&) { - --depth; - if (depth == 0) { - getElementGeneric()->setData(text); - } + --depth; + if (depth == 0) { + getElementGeneric()->setData(text); + } } void ComponentHandshakeParser::handleCharacterData(const std::string& text) { - this->text += text; + this->text += text; } } diff --git a/Swiften/Parser/ComponentHandshakeParser.h b/Swiften/Parser/ComponentHandshakeParser.h index 25cee6e..5f4af80 100644 --- a/Swiften/Parser/ComponentHandshakeParser.h +++ b/Swiften/Parser/ComponentHandshakeParser.h @@ -1,26 +1,28 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> -#include <Swiften/Elements/ComponentHandshake.h> #include <string> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/ComponentHandshake.h> +#include <Swiften/Parser/GenericElementParser.h> + namespace Swift { - class ComponentHandshakeParser : public GenericElementParser<ComponentHandshake> { - public: - ComponentHandshakeParser(); + class SWIFTEN_API ComponentHandshakeParser : public GenericElementParser<ComponentHandshake> { + public: + ComponentHandshakeParser(); - virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string& ns); - virtual void handleCharacterData(const std::string&); + virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string& ns); + virtual void handleCharacterData(const std::string&); - private: - int depth; - std::string text; - }; + private: + int depth; + std::string text; + }; } diff --git a/Swiften/Parser/CompressFailureParser.h b/Swiften/Parser/CompressFailureParser.h index ed59324..5c171ee 100644 --- a/Swiften/Parser/CompressFailureParser.h +++ b/Swiften/Parser/CompressFailureParser.h @@ -1,17 +1,18 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/CompressFailure.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class CompressFailureParser : public GenericElementParser<CompressFailure> { - public: - CompressFailureParser() : GenericElementParser<CompressFailure>() {} - }; + class SWIFTEN_API CompressFailureParser : public GenericElementParser<CompressFailure> { + public: + CompressFailureParser() : GenericElementParser<CompressFailure>() {} + }; } diff --git a/Swiften/Parser/CompressParser.cpp b/Swiften/Parser/CompressParser.cpp index d8f773b..00f762f 100644 --- a/Swiften/Parser/CompressParser.cpp +++ b/Swiften/Parser/CompressParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/CompressParser.h> @@ -12,23 +12,23 @@ CompressParser::CompressParser() : GenericElementParser<CompressRequest>(), curr } void CompressParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { - if (currentDepth_ == 1 && element == "method") { - inMethod_ = true; - currentText_ = ""; - } - ++currentDepth_; + if (currentDepth_ == 1 && element == "method") { + inMethod_ = true; + currentText_ = ""; + } + ++currentDepth_; } void CompressParser::handleEndElement(const std::string&, const std::string&) { - --currentDepth_; - if (currentDepth_ == 1 && inMethod_) { - getElementGeneric()->setMethod(currentText_); - inMethod_ = false; - } + --currentDepth_; + if (currentDepth_ == 1 && inMethod_) { + getElementGeneric()->setMethod(currentText_); + inMethod_ = false; + } } void CompressParser::handleCharacterData(const std::string& data) { - currentText_ += data; + currentText_ += data; } } diff --git a/Swiften/Parser/CompressParser.h b/Swiften/Parser/CompressParser.h index 51244c4..6f0a0cb 100644 --- a/Swiften/Parser/CompressParser.h +++ b/Swiften/Parser/CompressParser.h @@ -1,28 +1,30 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <string> -#include <Swiften/Parser/GenericElementParser.h> + +#include <Swiften/Base/API.h> #include <Swiften/Elements/CompressRequest.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class CompressParser : public GenericElementParser<CompressRequest> { - public: - CompressParser(); + class SWIFTEN_API CompressParser : public GenericElementParser<CompressRequest> { + public: + CompressParser(); - private: - void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); - void handleEndElement(const std::string& element, const std::string& ns); - void handleCharacterData(const std::string& data); + private: + void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); + void handleEndElement(const std::string& element, const std::string& ns); + void handleCharacterData(const std::string& data); - private: - int currentDepth_; - std::string currentText_; - bool inMethod_; - }; + private: + int currentDepth_; + std::string currentText_; + bool inMethod_; + }; } diff --git a/Swiften/Parser/CompressedParser.h b/Swiften/Parser/CompressedParser.h index 5ba80eb..859b509 100644 --- a/Swiften/Parser/CompressedParser.h +++ b/Swiften/Parser/CompressedParser.h @@ -1,17 +1,18 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/Compressed.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class CompressedParser : public GenericElementParser<Compressed> { - public: - CompressedParser() : GenericElementParser<Compressed>() {} - }; + class SWIFTEN_API CompressedParser : public GenericElementParser<Compressed> { + public: + CompressedParser() : GenericElementParser<Compressed>() {} + }; } diff --git a/Swiften/Parser/ElementParser.cpp b/Swiften/Parser/ElementParser.cpp index 1064f2e..4e0d27f 100644 --- a/Swiften/Parser/ElementParser.cpp +++ b/Swiften/Parser/ElementParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/ElementParser.h> diff --git a/Swiften/Parser/ElementParser.h b/Swiften/Parser/ElementParser.h index 1815240..71d4bce 100644 --- a/Swiften/Parser/ElementParser.h +++ b/Swiften/Parser/ElementParser.h @@ -1,27 +1,27 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 <string> + #include <Swiften/Base/API.h> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> #include <Swiften/Parser/AttributeMap.h> namespace Swift { - class SWIFTEN_API ElementParser { - public: - virtual ~ElementParser(); + class SWIFTEN_API ElementParser { + public: + virtual ~ElementParser(); - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) = 0; - virtual void handleEndElement(const std::string& element, const std::string& ns) = 0; - virtual void handleCharacterData(const std::string& data) = 0; + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) = 0; + virtual void handleEndElement(const std::string& element, const std::string& ns) = 0; + virtual void handleCharacterData(const std::string& data) = 0; - virtual boost::shared_ptr<Element> getElement() const = 0; - }; + virtual std::shared_ptr<ToplevelElement> getElement() const = 0; + }; } diff --git a/Swiften/Parser/EnableStreamManagementParser.h b/Swiften/Parser/EnableStreamManagementParser.h index 530efd9..b010740 100644 --- a/Swiften/Parser/EnableStreamManagementParser.h +++ b/Swiften/Parser/EnableStreamManagementParser.h @@ -1,17 +1,18 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/EnableStreamManagement.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class EnableStreamManagementParser : public GenericElementParser<EnableStreamManagement> { - public: - EnableStreamManagementParser() : GenericElementParser<EnableStreamManagement>() {} - }; + class SWIFTEN_API EnableStreamManagementParser : public GenericElementParser<EnableStreamManagement> { + public: + EnableStreamManagementParser() : GenericElementParser<EnableStreamManagement>() {} + }; } diff --git a/Swiften/Parser/EnumParser.h b/Swiften/Parser/EnumParser.h index d7bdbbc..0da765e 100644 --- a/Swiften/Parser/EnumParser.h +++ b/Swiften/Parser/EnumParser.h @@ -1,37 +1,37 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 Isode Limited. + * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <string> -#include <map> #include <cassert> +#include <map> +#include <string> + #include <boost/optional.hpp> -#include <Swiften/Base/Override.h> #include <Swiften/Base/API.h> namespace Swift { - template<typename T> - class SWIFTEN_API EnumParser { - public: - EnumParser() { - } - - EnumParser& operator()(T value, const std::string& text) { - values[text] = value; - return *this; - } - - boost::optional<T> parse(const std::string& value) { - typename std::map<std::string, T>::const_iterator i = values.find(value); - return i == values.end() ? boost::optional<T>() : i->second; - } - - private: - std::map<std::string, T> values; - }; + template<typename T> + class SWIFTEN_API EnumParser { + public: + EnumParser() { + } + + EnumParser& operator()(T value, const std::string& text) { + values[text] = value; + return *this; + } + + boost::optional<T> parse(const std::string& value) { + typename std::map<std::string, T>::const_iterator i = values.find(value); + return i == values.end() ? boost::optional<T>() : i->second; + } + + private: + std::map<std::string, T> values; + }; } diff --git a/Swiften/Parser/ExpatParser.cpp b/Swiften/Parser/ExpatParser.cpp index 8b7bf82..32d4f53 100644 --- a/Swiften/Parser/ExpatParser.cpp +++ b/Swiften/Parser/ExpatParser.cpp @@ -1,95 +1,142 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2019 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/ExpatParser.h> -#include <iostream> +#include <cassert> +#include <limits> +#include <memory> #include <string> + +#include <boost/algorithm/string.hpp> + #include <expat.h> -#include <boost/numeric/conversion/cast.hpp> #include <Swiften/Base/String.h> #include <Swiften/Parser/XMLParserClient.h> #pragma clang diagnostic ignored "-Wdisabled-macro-expansion" +namespace { +struct XmlInfo { + std::string prefix; + std::string uri; + std::string name; +}; + +XmlInfo splitExpatInfo(const std::string& s, char sep) { + // name + // uri|name + // uri|name|prefix + std::vector<std::string> v; + boost::split(v, s, [sep](char c) {return c == sep; }); + switch (v.size()) { + case 1: + return{ "", "", std::move(v[0]) }; + case 2: + return{ "", std::move(v[0]), std::move(v[1]) }; + case 3: + return{ std::move(v[2]), std::move(v[0]), std::move(v[1]) }; + default: + return{ "", "", "" }; + } +} +} + + namespace Swift { static const char NAMESPACE_SEPARATOR = '\x01'; struct ExpatParser::Private { - XML_Parser parser_; + XML_Parser parser_; }; static void handleStartElement(void* parser, const XML_Char* name, const XML_Char** attributes) { - std::pair<std::string,std::string> nsTagPair = String::getSplittedAtFirst(name, NAMESPACE_SEPARATOR); - if (nsTagPair.second == "") { - nsTagPair.second = nsTagPair.first; - nsTagPair.first = ""; - } - AttributeMap attributeValues; - const XML_Char** currentAttribute = attributes; - while (*currentAttribute) { - std::pair<std::string,std::string> nsAttributePair = String::getSplittedAtFirst(*currentAttribute, NAMESPACE_SEPARATOR); - if (nsAttributePair.second == "") { - nsAttributePair.second = nsAttributePair.first; - nsAttributePair.first = ""; - } - attributeValues.addAttribute(nsAttributePair.second, nsAttributePair.first, std::string(*(currentAttribute+1))); - currentAttribute += 2; - } - - static_cast<XMLParser*>(parser)->getClient()->handleStartElement(nsTagPair.second, nsTagPair.first, attributeValues); + auto elemInfo = splitExpatInfo(name, NAMESPACE_SEPARATOR); + + AttributeMap attributeValues; + const XML_Char** currentAttribute = attributes; + while (*currentAttribute) { + auto attribInfo = splitExpatInfo(*currentAttribute, NAMESPACE_SEPARATOR); + attributeValues.addAttribute(attribInfo.name, attribInfo.uri, attribInfo.prefix, std::string(*(currentAttribute+1))); + currentAttribute += 2; + } + + auto* client = static_cast<XMLParser*>(parser)->getClient(); + client->handleStartElementPrefix(elemInfo.prefix, elemInfo.uri, elemInfo.name, attributeValues); + client->handleStartElement(elemInfo.name, elemInfo.uri, attributeValues); } static void handleEndElement(void* parser, const XML_Char* name) { - std::pair<std::string,std::string> nsTagPair = String::getSplittedAtFirst(name, NAMESPACE_SEPARATOR); - if (nsTagPair.second == "") { - nsTagPair.second = nsTagPair.first; - nsTagPair.first = ""; - } - static_cast<XMLParser*>(parser)->getClient()->handleEndElement(nsTagPair.second, nsTagPair.first); + auto elemInfo = splitExpatInfo(name, NAMESPACE_SEPARATOR); + static_cast<XMLParser*>(parser)->getClient()->handleEndElement(elemInfo.name, elemInfo.uri); } static void handleCharacterData(void* parser, const XML_Char* data, int len) { - assert(len >= 0); - static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(data, static_cast<size_t>(len))); + assert(len >= 0); + static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(data, static_cast<size_t>(len))); } static void handleXMLDeclaration(void*, const XML_Char*, const XML_Char*, int) { } +static void handleNamespaceDeclaration(void* parser, const XML_Char* prefix, const XML_Char* uri) { + static_cast<XMLParser*>(parser)->getClient()->handleNamespaceDeclaration(std::string(prefix ? prefix : ""), std::string(uri ? uri : "")); +} + static void handleEntityDeclaration(void* parser, const XML_Char*, int, const XML_Char*, int, const XML_Char*, const XML_Char*, const XML_Char*, const XML_Char*) { - static_cast<ExpatParser*>(parser)->stopParser(); + static_cast<ExpatParser*>(parser)->stopParser(); +} + +static void handleComment(void* parser, const XML_Char* /*data*/) { + if (!static_cast<ExpatParser*>(parser)->allowsComments()) { + static_cast<ExpatParser*>(parser)->stopParser(); + } } +static void handleProcessingInstruction(void* parser, const XML_Char* /*target*/, const XML_Char* /*data*/) { + static_cast<ExpatParser*>(parser)->stopParser(); +} + +static void handleDoctypeDeclaration(void* parser, const XML_Char* /*doctypeName*/, const XML_Char* /*sysid*/, const XML_Char* /*pubid*/, int /*has_internal_subset*/) { + static_cast<ExpatParser*>(parser)->stopParser(); +} -ExpatParser::ExpatParser(XMLParserClient* client) : XMLParser(client), p(new Private()) { - p->parser_ = XML_ParserCreateNS("UTF-8", NAMESPACE_SEPARATOR); - XML_SetUserData(p->parser_, this); - XML_SetElementHandler(p->parser_, handleStartElement, handleEndElement); - XML_SetCharacterDataHandler(p->parser_, handleCharacterData); - XML_SetXmlDeclHandler(p->parser_, handleXMLDeclaration); - XML_SetEntityDeclHandler(p->parser_, handleEntityDeclaration); +ExpatParser::ExpatParser(XMLParserClient* client, bool allowComments) : XMLParser(client, allowComments), p(new Private()) { + p->parser_ = XML_ParserCreateNS("UTF-8", NAMESPACE_SEPARATOR); + XML_SetReturnNSTriplet(p->parser_, true); + XML_SetUserData(p->parser_, this); + XML_SetElementHandler(p->parser_, handleStartElement, handleEndElement); + XML_SetCharacterDataHandler(p->parser_, handleCharacterData); + XML_SetXmlDeclHandler(p->parser_, handleXMLDeclaration); + XML_SetEntityDeclHandler(p->parser_, handleEntityDeclaration); + XML_SetNamespaceDeclHandler(p->parser_, handleNamespaceDeclaration, nullptr); + XML_SetCommentHandler(p->parser_, handleComment); + XML_SetProcessingInstructionHandler(p->parser_, handleProcessingInstruction); + XML_SetDoctypeDeclHandler(p->parser_, handleDoctypeDeclaration, nullptr); } ExpatParser::~ExpatParser() { - XML_ParserFree(p->parser_); + XML_ParserFree(p->parser_); } -bool ExpatParser::parse(const std::string& data) { - bool success = XML_Parse(p->parser_, data.c_str(), boost::numeric_cast<int>(data.size()), false) == XML_STATUS_OK; - /*if (!success) { - std::cout << "ERROR: " << XML_ErrorString(XML_GetErrorCode(p->parser_)) << " while parsing " << data << std::endl; - }*/ - return success; +bool ExpatParser::parse(const std::string& data, bool finalData) { + if (data.size() > std::numeric_limits<int>::max()) { + return false; + } + bool success = XML_Parse(p->parser_, data.c_str(), static_cast<int>(data.size()), finalData) == XML_STATUS_OK; + /*if (!success) { + std::cout << "ERROR: " << XML_ErrorString(XML_GetErrorCode(p->parser_)) << " while parsing " << data << std::endl; + }*/ + return success; } void ExpatParser::stopParser() { - XML_StopParser(p->parser_, static_cast<XML_Bool>(0)); + XML_StopParser(p->parser_, static_cast<XML_Bool>(0)); } } diff --git a/Swiften/Parser/ExpatParser.h b/Swiften/Parser/ExpatParser.h index dcb0915..34d790d 100644 --- a/Swiften/Parser/ExpatParser.h +++ b/Swiften/Parser/ExpatParser.h @@ -1,29 +1,30 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2019 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <memory> + #include <boost/noncopyable.hpp> -#include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> #include <Swiften/Parser/XMLParser.h> namespace Swift { - class SWIFTEN_API ExpatParser : public XMLParser, public boost::noncopyable { - public: - ExpatParser(XMLParserClient* client); - ~ExpatParser(); + class SWIFTEN_API ExpatParser : public XMLParser, public boost::noncopyable { + public: + ExpatParser(XMLParserClient* client, bool allowComments = false); + ~ExpatParser(); - bool parse(const std::string& data); + bool parse(const std::string& data, bool finalData = false); - void stopParser(); + void stopParser(); - private: - struct Private; - boost::shared_ptr<Private> p; - }; + private: + struct Private; + const std::unique_ptr<Private> p; + }; } diff --git a/Swiften/Parser/GenericElementParser.h b/Swiften/Parser/GenericElementParser.h index 224c59e..1092710 100644 --- a/Swiften/Parser/GenericElementParser.h +++ b/Swiften/Parser/GenericElementParser.h @@ -1,46 +1,44 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> -#include <boost/smart_ptr/make_shared.hpp> +#include <memory> +#include <Swiften/Base/API.h> #include <Swiften/Parser/ElementParser.h> namespace Swift { - - class PayloadParserFactoryCollection; - template<typename ElementType> - class GenericElementParser : public ElementParser { - public: - GenericElementParser() { - stanza_ = boost::make_shared<ElementType>(); - } + template<typename ElementType> + class SWIFTEN_API GenericElementParser : public ElementParser { + public: + GenericElementParser() { + stanza_ = std::make_shared<ElementType>(); + } - virtual boost::shared_ptr<Element> getElement() const { - return stanza_; - } + virtual std::shared_ptr<ToplevelElement> getElement() const { + return stanza_; + } - virtual boost::shared_ptr<ElementType> getElementGeneric() const { - return stanza_; - } + virtual std::shared_ptr<ElementType> getElementGeneric() const { + return stanza_; + } - private: - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - } + private: + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + } - virtual void handleEndElement(const std::string&, const std::string&) { - } + virtual void handleEndElement(const std::string&, const std::string&) { + } - virtual void handleCharacterData(const std::string&) { - } + virtual void handleCharacterData(const std::string&) { + } - private: - boost::shared_ptr<ElementType> stanza_; - }; + private: + std::shared_ptr<ElementType> stanza_; + }; } diff --git a/Swiften/Parser/GenericPayloadParser.h b/Swiften/Parser/GenericPayloadParser.h index 572901b..b72189e 100644 --- a/Swiften/Parser/GenericPayloadParser.h +++ b/Swiften/Parser/GenericPayloadParser.h @@ -1,42 +1,39 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> -#include <boost/smart_ptr/make_shared.hpp> +#include <memory> +#include <Swiften/Base/API.h> #include <Swiften/Parser/PayloadParser.h> namespace Swift { - - class FormParser; - - /** - * A generic payload parser for payloads of the given type. - * - * This class provides getPayloadInternal() for retrieving the actual - * payload. - */ - template<typename PAYLOAD_TYPE> - class GenericPayloadParser : public PayloadParser { - public: - GenericPayloadParser() : PayloadParser() { - payload_ = boost::make_shared<PAYLOAD_TYPE>(); - } - - virtual boost::shared_ptr<Payload> getPayload() const { - return payload_; - } - - virtual boost::shared_ptr<PAYLOAD_TYPE> getPayloadInternal() const { - return payload_; - } - - private: - boost::shared_ptr<PAYLOAD_TYPE> payload_; - }; + /** + * A generic payload parser for payloads of the given type. + * + * This class provides getPayloadInternal() for retrieving the actual + * payload. + */ + template<typename PAYLOAD_TYPE> + class GenericPayloadParser : public PayloadParser { + public: + GenericPayloadParser() : PayloadParser() { + payload_ = std::make_shared<PAYLOAD_TYPE>(); + } + + virtual std::shared_ptr<Payload> getPayload() const { + return payload_; + } + + virtual std::shared_ptr<PAYLOAD_TYPE> getPayloadInternal() const { + return payload_; + } + + private: + std::shared_ptr<PAYLOAD_TYPE> payload_; + }; } diff --git a/Swiften/Parser/GenericPayloadParserFactory.h b/Swiften/Parser/GenericPayloadParserFactory.h index 43042a1..fcdec62 100644 --- a/Swiften/Parser/GenericPayloadParserFactory.h +++ b/Swiften/Parser/GenericPayloadParserFactory.h @@ -1,37 +1,39 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/PayloadParserFactory.h> #include <string> +#include <Swiften/Base/API.h> +#include <Swiften/Parser/PayloadParserFactory.h> + namespace Swift { - /** - * A generic class for PayloadParserFactories that parse a specific payload (given as the template parameter of the class). - */ - template<typename PARSER_TYPE> - class GenericPayloadParserFactory : public PayloadParserFactory { - public: - /** - * Construct a parser factory that can parse the given top-level tag in the given namespace. - */ - GenericPayloadParserFactory(const std::string& tag, const std::string& xmlns = "") : tag_(tag), xmlns_(xmlns) {} - - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return (tag_.empty() ? true : element == tag_) && (xmlns_.empty() ? true : xmlns_ == ns); - } - - virtual PayloadParser* createPayloadParser() { - return new PARSER_TYPE(); - } - - private: - std::string tag_; - std::string xmlns_; - }; + /** + * A generic class for PayloadParserFactories that parse a specific payload (given as the template parameter of the class). + */ + template<typename PARSER_TYPE> + class GenericPayloadParserFactory : public PayloadParserFactory { + public: + /** + * Construct a parser factory that can parse the given top-level tag in the given namespace. + */ + GenericPayloadParserFactory(const std::string& tag, const std::string& xmlns = "") : tag_(tag), xmlns_(xmlns) {} + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return (tag_.empty() ? true : element == tag_) && (xmlns_.empty() ? true : xmlns_ == ns); + } + + virtual PayloadParser* createPayloadParser() { + return new PARSER_TYPE(); + } + + private: + std::string tag_; + std::string xmlns_; + }; } diff --git a/Swiften/Parser/GenericPayloadParserFactory2.h b/Swiften/Parser/GenericPayloadParserFactory2.h index f24b64e..f55d317 100644 --- a/Swiften/Parser/GenericPayloadParserFactory2.h +++ b/Swiften/Parser/GenericPayloadParserFactory2.h @@ -1,39 +1,41 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/PayloadParserFactory.h> #include <string> +#include <Swiften/Base/API.h> +#include <Swiften/Parser/PayloadParserFactory.h> + namespace Swift { - class PayloadParserFactoryCollection; - - /** - * A generic class for PayloadParserFactories that parse a specific payload (given as the template parameter of the class). - */ - template<typename PARSER_TYPE> - class GenericPayloadParserFactory2 : public PayloadParserFactory { - public: - /** - * Construct a parser factory that can parse the given top-level tag in the given namespace. - */ - GenericPayloadParserFactory2(const std::string& tag, const std::string& xmlns, PayloadParserFactoryCollection* parsers) : tag_(tag), xmlns_(xmlns), parsers_(parsers) {} - - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { - return (tag_.empty() ? true : element == tag_) && (xmlns_.empty() ? true : xmlns_ == ns); - } - - virtual PayloadParser* createPayloadParser() { - return new PARSER_TYPE(parsers_); - } - - private: - std::string tag_; - std::string xmlns_; - PayloadParserFactoryCollection* parsers_; - }; + class PayloadParserFactoryCollection; + + /** + * A generic class for PayloadParserFactories that parse a specific payload (given as the template parameter of the class). + */ + template<typename PARSER_TYPE> + class GenericPayloadParserFactory2 : public PayloadParserFactory { + public: + /** + * Construct a parser factory that can parse the given top-level tag in the given namespace. + */ + GenericPayloadParserFactory2(const std::string& tag, const std::string& xmlns, PayloadParserFactoryCollection* parsers) : tag_(tag), xmlns_(xmlns), parsers_(parsers) {} + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return (tag_.empty() ? true : element == tag_) && (xmlns_.empty() ? true : xmlns_ == ns); + } + + virtual PayloadParser* createPayloadParser() { + return new PARSER_TYPE(parsers_); + } + + private: + std::string tag_; + std::string xmlns_; + PayloadParserFactoryCollection* parsers_; + }; } diff --git a/Swiften/Parser/GenericPayloadTreeParser.h b/Swiften/Parser/GenericPayloadTreeParser.h index df6d022..b4da1a9 100644 --- a/Swiften/Parser/GenericPayloadTreeParser.h +++ b/Swiften/Parser/GenericPayloadTreeParser.h @@ -1,53 +1,52 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <deque> +#include <memory> -#include <boost/shared_ptr.hpp> -#include <boost/smart_ptr/make_shared.hpp> - +#include <Swiften/Base/API.h> #include <Swiften/Parser/GenericPayloadParser.h> #include <Swiften/Parser/Tree/ParserElement.h> namespace Swift { - /** - * Generic parser offering something a bit like a DOM to work with. - */ - template<typename PAYLOAD_TYPE> - class GenericPayloadTreeParser : public GenericPayloadParser<PAYLOAD_TYPE> { - public: - virtual void handleStartElement(const std::string& element, const std::string& xmlns, const AttributeMap& attributes) { - if (!root_) { - root_ = boost::make_shared<ParserElement>(element, xmlns, attributes); - elementStack_.push_back(root_); - } - else { - ParserElement::ref current = *elementStack_.rbegin(); - elementStack_.push_back(current->addChild(element, xmlns, attributes)); - } - } - - virtual void handleEndElement(const std::string& /*element*/, const std::string&) { - elementStack_.pop_back(); - if (elementStack_.empty()) { - handleTree(root_); - } - } - - virtual void handleCharacterData(const std::string& data) { - ParserElement::ref current = *elementStack_.rbegin(); - current->appendCharacterData(data); - } - - virtual void handleTree(ParserElement::ref root) = 0; - - private: - std::deque<ParserElement::ref> elementStack_; - ParserElement::ref root_; - }; + /** + * Generic parser offering something a bit like a DOM to work with. + */ + template<typename PAYLOAD_TYPE> + class GenericPayloadTreeParser : public GenericPayloadParser<PAYLOAD_TYPE> { + public: + virtual void handleStartElement(const std::string& element, const std::string& xmlns, const AttributeMap& attributes) { + if (!root_) { + root_ = std::make_shared<ParserElement>(element, xmlns, attributes); + elementStack_.push_back(root_); + } + else { + ParserElement::ref current = *elementStack_.rbegin(); + elementStack_.push_back(current->addChild(element, xmlns, attributes)); + } + } + + virtual void handleEndElement(const std::string& /*element*/, const std::string&) { + elementStack_.pop_back(); + if (elementStack_.empty()) { + handleTree(root_); + } + } + + virtual void handleCharacterData(const std::string& data) { + ParserElement::ref current = *elementStack_.rbegin(); + current->appendCharacterData(data); + } + + virtual void handleTree(ParserElement::ref root) = 0; + + private: + std::deque<ParserElement::ref> elementStack_; + ParserElement::ref root_; + }; } diff --git a/Swiften/Parser/GenericStanzaParser.h b/Swiften/Parser/GenericStanzaParser.h index c756c9a..2686f2f 100644 --- a/Swiften/Parser/GenericStanzaParser.h +++ b/Swiften/Parser/GenericStanzaParser.h @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> -#include <boost/smart_ptr/make_shared.hpp> +#include <memory> +#include <Swiften/Base/API.h> #include <Swiften/Parser/StanzaParser.h> namespace Swift { - - class PayloadParserFactoryCollection; - - template<typename STANZA_TYPE> - class GenericStanzaParser : public StanzaParser { - public: - GenericStanzaParser(PayloadParserFactoryCollection* collection) : - StanzaParser(collection) { - stanza_ = boost::make_shared<STANZA_TYPE>(); - } - - virtual boost::shared_ptr<Element> getElement() const { - return stanza_; - } - - virtual boost::shared_ptr<STANZA_TYPE> getStanzaGeneric() const { - return stanza_; - } - - private: - boost::shared_ptr<STANZA_TYPE> stanza_; - }; + + class PayloadParserFactoryCollection; + + template<typename STANZA_TYPE> + class SWIFTEN_API GenericStanzaParser : public StanzaParser { + public: + GenericStanzaParser(PayloadParserFactoryCollection* collection) : + StanzaParser(collection) { + stanza_ = std::make_shared<STANZA_TYPE>(); + } + + virtual std::shared_ptr<ToplevelElement> getElement() const { + return stanza_; + } + + virtual std::shared_ptr<STANZA_TYPE> getStanzaGeneric() const { + return stanza_; + } + + private: + std::shared_ptr<STANZA_TYPE> stanza_; + }; } diff --git a/Swiften/Parser/IQParser.cpp b/Swiften/Parser/IQParser.cpp index 62d775f..363f7ec 100644 --- a/Swiften/Parser/IQParser.cpp +++ b/Swiften/Parser/IQParser.cpp @@ -1,40 +1,41 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2019 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ -#include <iostream> +#include <Swiften/Parser/IQParser.h> + #include <boost/optional.hpp> -#include <Swiften/Parser/IQParser.h> +#include <Swiften/Base/Log.h> namespace Swift { -IQParser::IQParser(PayloadParserFactoryCollection* factories) : - GenericStanzaParser<IQ>(factories) { +IQParser::IQParser(PayloadParserFactoryCollection* factories) : + GenericStanzaParser<IQ>(factories) { } void IQParser::handleStanzaAttributes(const AttributeMap& attributes) { - boost::optional<std::string> type = attributes.getAttributeValue("type"); - if (type) { - if (*type == "set") { - getStanzaGeneric()->setType(IQ::Set); - } - else if (*type == "get") { - getStanzaGeneric()->setType(IQ::Get); - } - else if (*type == "result") { - getStanzaGeneric()->setType(IQ::Result); - } - else if (*type == "error") { - getStanzaGeneric()->setType(IQ::Error); - } - else { - std::cerr << "Unknown IQ type: " << *type << std::endl; - getStanzaGeneric()->setType(IQ::Get); - } - } + boost::optional<std::string> type = attributes.getAttributeValue("type"); + if (type) { + if (*type == "set") { + getStanzaGeneric()->setType(IQ::Set); + } + else if (*type == "get") { + getStanzaGeneric()->setType(IQ::Get); + } + else if (*type == "result") { + getStanzaGeneric()->setType(IQ::Result); + } + else if (*type == "error") { + getStanzaGeneric()->setType(IQ::Error); + } + else { + SWIFT_LOG(warning) << "Unknown IQ type: " << *type; + getStanzaGeneric()->setType(IQ::Get); + } + } } } diff --git a/Swiften/Parser/IQParser.h b/Swiften/Parser/IQParser.h index 9773835..5250bfb 100644 --- a/Swiften/Parser/IQParser.h +++ b/Swiften/Parser/IQParser.h @@ -1,21 +1,21 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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/Parser/GenericStanzaParser.h> #include <Swiften/Elements/IQ.h> +#include <Swiften/Parser/GenericStanzaParser.h> namespace Swift { - class SWIFTEN_API IQParser : public GenericStanzaParser<IQ> { - public: - IQParser(PayloadParserFactoryCollection* factories); + class SWIFTEN_API IQParser : public GenericStanzaParser<IQ> { + public: + IQParser(PayloadParserFactoryCollection* factories); - private: - virtual void handleStanzaAttributes(const AttributeMap&); - }; + private: + virtual void handleStanzaAttributes(const AttributeMap&); + }; } diff --git a/Swiften/Parser/LibXMLParser.cpp b/Swiften/Parser/LibXMLParser.cpp index e4938e1..32b91a1 100644 --- a/Swiften/Parser/LibXMLParser.cpp +++ b/Swiften/Parser/LibXMLParser.cpp @@ -1,106 +1,165 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2019 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/LibXMLParser.h> -#include <iostream> -#include <boost/numeric/conversion/cast.hpp> #include <cassert> #include <cstring> -#include <libxml/parser.h> +#include <limits> +#include <memory> #include <string> +#include <libxml/parser.h> + +#include <Swiften/Base/Log.h> #include <Swiften/Parser/XMLParserClient.h> +namespace { +std::string asString(const unsigned char* s) { + return s ? std::string(reinterpret_cast<const char*>(s)) : std::string(); +} +} + namespace Swift { struct LibXMLParser::Private { - xmlSAXHandler handler_; - xmlParserCtxtPtr context_; + xmlSAXHandler handler_; + xmlParserCtxtPtr context_; }; -static void handleStartElement(void* parser, const xmlChar* name, const xmlChar*, const xmlChar* xmlns, int, const xmlChar**, int nbAttributes, int nbDefaulted, const xmlChar ** attributes) { - AttributeMap attributeValues; - if (nbDefaulted != 0) { - // Just because i don't understand what this means yet :-) - std::cerr << "Unexpected nbDefaulted on XML element" << std::endl; - } - for (int i = 0; i < nbAttributes*5; i += 5) { - std::string attributeNS = ""; - if (attributes[i+2]) { - attributeNS = std::string(reinterpret_cast<const char*>(attributes[i+2])); - } - attributeValues.addAttribute( - std::string(reinterpret_cast<const char*>(attributes[i])), - attributeNS, - std::string(reinterpret_cast<const char*>(attributes[i+3]), - boost::numeric_cast<size_t>(attributes[i+4]-attributes[i+3]))); - } - static_cast<XMLParser*>(parser)->getClient()->handleStartElement(reinterpret_cast<const char*>(name), (xmlns ? reinterpret_cast<const char*>(xmlns) : std::string()), attributeValues); +static void handleStartElement(void* parser, const xmlChar* name, const xmlChar* prefix, const xmlChar* xmlns, int nbNamespaces, const xmlChar** namespaces, int nbAttributes, int nbDefaulted, const xmlChar ** attributes) { + AttributeMap attributeValues; + if (nbDefaulted != 0) { + // Just because i don't understand what this means yet :-) + SWIFT_LOG(error) << "Unexpected nbDefaulted on XML element"; + } + for (int i = 0; i < nbAttributes*5; i += 5) { + std::string attributeName = asString(attributes[i]); + std::string attributePrefix = asString(attributes[i+1]); + std::string attributeNS = asString(attributes[i+2]); + assert(attributes[i+4] >= attributes[i+3]); + attributeValues.addAttribute( + attributeName, + attributeNS, + attributePrefix, + std::string(reinterpret_cast<const char*>(attributes[i+3]), + static_cast<size_t>(attributes[i+4]-attributes[i+3]))); + } + auto* client = static_cast<XMLParser*>(parser)->getClient(); + for (auto i = 0; i < nbNamespaces * 2; i += 2) { + const auto prefix = asString(namespaces[i]); + const auto uri = asString(namespaces[i + 1]); + client->handleNamespaceDeclaration(prefix, uri); + } + auto nameStr = asString(name); + auto xmlsnsStr = asString(xmlns); + auto prefixStr = asString(prefix); + client->handleStartElementPrefix(prefixStr, xmlsnsStr, nameStr, attributeValues); + client->handleStartElement(nameStr, xmlsnsStr, attributeValues); } static void handleEndElement(void *parser, const xmlChar* name, const xmlChar*, const xmlChar* xmlns) { - static_cast<XMLParser*>(parser)->getClient()->handleEndElement(reinterpret_cast<const char*>(name), (xmlns ? reinterpret_cast<const char*>(xmlns) : std::string())); + static_cast<XMLParser*>(parser)->getClient()->handleEndElement(asString(name), asString(xmlns)); } static void handleCharacterData(void* parser, const xmlChar* data, int len) { - static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(reinterpret_cast<const char*>(data), boost::numeric_cast<size_t>(len))); + assert(len >= 0); + static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(reinterpret_cast<const char*>(data), static_cast<size_t>(len))); +} + +static void handleComment(void* parser, const xmlChar* /*data*/) { + if (!static_cast<LibXMLParser*>(parser)->allowsComments()) { + static_cast<LibXMLParser*>(parser)->stopParser(); + } +} + +static void handleEntityDeclaration(void * parser, const xmlChar* /*name*/, int /*type*/, const xmlChar* /*publicId*/, const xmlChar* /*systemId*/, xmlChar* /*content*/) { + static_cast<LibXMLParser*>(parser)->stopParser(); +} + +static void handleProcessingInstruction(void* parser, const xmlChar* /*target*/, const xmlChar* /*data*/) { + static_cast<LibXMLParser*>(parser)->stopParser(); +} + +static void handleExternalSubset(void* parser, const xmlChar * /*name*/, const xmlChar * /*ExternalID*/, const xmlChar * /*SystemID*/) { + static_cast<LibXMLParser*>(parser)->stopParser(); } static void handleError(void*, const char* /*m*/, ... ) { - /* - va_list args; - va_start(args, m); - vfprintf(stdout, m, args); - va_end(args); - */ + /* + va_list args; + va_start(args, m); + vfprintf(stdout, m, args); + va_end(args); + */ } static void handleWarning(void*, const char*, ... ) { } -bool LibXMLParser::initialized = false; +static void handleGenericError(void*, const char*, ... ) { +} -LibXMLParser::LibXMLParser(XMLParserClient* client) : XMLParser(client), p(new Private()) { - // Initialize libXML for multithreaded applications - if (!initialized) { - xmlInitParser(); - initialized = true; - } +static void handleStructuredError(void*, xmlErrorPtr) { +} - memset(&p->handler_, 0, sizeof(p->handler_) ); - p->handler_.initialized = XML_SAX2_MAGIC; - p->handler_.startElementNs = &handleStartElement; - p->handler_.endElementNs = &handleEndElement; - p->handler_.characters = &handleCharacterData; - p->handler_.warning = &handleWarning; - p->handler_.error = &handleError; +bool LibXMLParser::initialized = false; - p->context_ = xmlCreatePushParserCtxt(&p->handler_, this, 0, 0, 0); - xmlCtxtUseOptions(p->context_, XML_PARSE_NOENT); - assert(p->context_); +LibXMLParser::LibXMLParser(XMLParserClient* client, bool allowComments) : XMLParser(client, allowComments), p(new Private()) { + // Initialize libXML for multithreaded applications + if (!initialized) { + xmlInitParser(); + xmlSetGenericErrorFunc(nullptr, handleGenericError); + xmlSetStructuredErrorFunc(nullptr, handleStructuredError); + initialized = true; + } + + memset(&p->handler_, 0, sizeof(p->handler_) ); + p->handler_.initialized = XML_SAX2_MAGIC; + p->handler_.startElementNs = &handleStartElement; + p->handler_.endElementNs = &handleEndElement; + p->handler_.characters = &handleCharacterData; + p->handler_.warning = &handleWarning; + p->handler_.error = &handleError; + p->handler_.comment = &handleComment; + p->handler_.entityDecl = &handleEntityDeclaration; + p->handler_.processingInstruction = &handleProcessingInstruction; + p->handler_.externalSubset = &handleExternalSubset; + + p->context_ = xmlCreatePushParserCtxt(&p->handler_, this, nullptr, 0, nullptr); + xmlCtxtUseOptions(p->context_, XML_PARSE_NOENT); + assert(p->context_); } LibXMLParser::~LibXMLParser() { - if (p->context_) { - xmlFreeParserCtxt(p->context_); - } -} - -bool LibXMLParser::parse(const std::string& data) { - if (xmlParseChunk(p->context_, data.c_str(), boost::numeric_cast<int>(data.size()), false) == XML_ERR_OK) { - return true; - } - xmlError* error = xmlCtxtGetLastError(p->context_); - if (error->code == XML_WAR_NS_URI || error->code == XML_WAR_NS_URI_RELATIVE) { - xmlCtxtResetLastError(p->context_); - p->context_->errNo = XML_ERR_OK; - return true; - } - return false; + if (p->context_) { + xmlFreeParserCtxt(p->context_); + } +} + +bool LibXMLParser::parse(const std::string& data, bool finalData) { + if (data.size() > std::numeric_limits<int>::max()) { + return false; + } + auto error = xmlParseChunk(p->context_, data.c_str(), static_cast<int>(data.size()), finalData); + if (error == XML_ERR_OK) { + return true; + } + if (stopped_) return false; + if (error == XML_WAR_NS_URI || error == XML_WAR_NS_URI_RELATIVE) { + xmlCtxtResetLastError(p->context_); + p->context_->errNo = XML_ERR_OK; + return true; + } + return false; +} + +void LibXMLParser::stopParser() { + stopped_ = true; + xmlStopParser(p->context_); } } diff --git a/Swiften/Parser/LibXMLParser.h b/Swiften/Parser/LibXMLParser.h index b8e1d7c..e21770d 100644 --- a/Swiften/Parser/LibXMLParser.h +++ b/Swiften/Parser/LibXMLParser.h @@ -1,32 +1,36 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2019 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <memory> + #include <boost/noncopyable.hpp> -#include <boost/shared_ptr.hpp> #include <Swiften/Parser/XMLParser.h> namespace Swift { - /** - * Warning: This constructor is not thread-safe, because it depends on global state to - * check whether it is initialized. - */ - class LibXMLParser : public XMLParser, public boost::noncopyable { - public: - LibXMLParser(XMLParserClient* client); - ~LibXMLParser(); - - bool parse(const std::string& data); - - private: - static bool initialized; - - struct Private; - boost::shared_ptr<Private> p; - }; + /** + * Warning: This constructor is not thread-safe, because it depends on global state to + * check whether it is initialized. + */ + class LibXMLParser : public XMLParser, public boost::noncopyable { + public: + LibXMLParser(XMLParserClient* client, bool allowComments = false); + virtual ~LibXMLParser(); + + bool parse(const std::string& data, bool finalData = false); + + void stopParser(); + + private: + static bool initialized; + bool stopped_ = false; + + struct Private; + const std::unique_ptr<Private> p; + }; } diff --git a/Swiften/Parser/MessageParser.cpp b/Swiften/Parser/MessageParser.cpp index 7f5e6d4..1dd7675 100644 --- a/Swiften/Parser/MessageParser.cpp +++ b/Swiften/Parser/MessageParser.cpp @@ -1,39 +1,39 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ -#include <boost/optional.hpp> - #include <Swiften/Parser/MessageParser.h> +#include <boost/optional.hpp> + namespace Swift { -MessageParser::MessageParser(PayloadParserFactoryCollection* factories) : - GenericStanzaParser<Message>(factories) { - getStanzaGeneric()->setType(Message::Normal); +MessageParser::MessageParser(PayloadParserFactoryCollection* factories) : + GenericStanzaParser<Message>(factories) { + GenericStanzaParser<Message>::getStanzaGeneric()->setType(Message::Normal); } void MessageParser::handleStanzaAttributes(const AttributeMap& attributes) { - boost::optional<std::string> type = attributes.getAttributeValue("type"); - if (type) { - if (*type == "chat") { - getStanzaGeneric()->setType(Message::Chat); - } - else if (*type == "error") { - getStanzaGeneric()->setType(Message::Error); - } - else if (*type == "groupchat") { - getStanzaGeneric()->setType(Message::Groupchat); - } - else if (*type == "headline") { - getStanzaGeneric()->setType(Message::Headline); - } - else { - getStanzaGeneric()->setType(Message::Normal); - } - } + boost::optional<std::string> type = attributes.getAttributeValue("type"); + if (type) { + if (*type == "chat") { + getStanzaGeneric()->setType(Message::Chat); + } + else if (*type == "error") { + getStanzaGeneric()->setType(Message::Error); + } + else if (*type == "groupchat") { + getStanzaGeneric()->setType(Message::Groupchat); + } + else if (*type == "headline") { + getStanzaGeneric()->setType(Message::Headline); + } + else { + getStanzaGeneric()->setType(Message::Normal); + } + } } } diff --git a/Swiften/Parser/MessageParser.h b/Swiften/Parser/MessageParser.h index e908339..cfbfc38 100644 --- a/Swiften/Parser/MessageParser.h +++ b/Swiften/Parser/MessageParser.h @@ -1,21 +1,21 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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/Parser/GenericStanzaParser.h> #include <Swiften/Elements/Message.h> +#include <Swiften/Parser/GenericStanzaParser.h> namespace Swift { - class SWIFTEN_API MessageParser : public GenericStanzaParser<Message> { - public: - MessageParser(PayloadParserFactoryCollection* factories); + class SWIFTEN_API MessageParser : public GenericStanzaParser<Message> { + public: + MessageParser(PayloadParserFactoryCollection* factories); - private: - virtual void handleStanzaAttributes(const AttributeMap&); - }; + private: + virtual void handleStanzaAttributes(const AttributeMap&); + }; } diff --git a/Swiften/Parser/PayloadParser.cpp b/Swiften/Parser/PayloadParser.cpp index 3680d63..3b93454 100644 --- a/Swiften/Parser/PayloadParser.cpp +++ b/Swiften/Parser/PayloadParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParser.h> diff --git a/Swiften/Parser/PayloadParser.h b/Swiften/Parser/PayloadParser.h index bb1ae3c..a824922 100644 --- a/Swiften/Parser/PayloadParser.h +++ b/Swiften/Parser/PayloadParser.h @@ -1,51 +1,50 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 <Swiften/Base/API.h> -#include <Swiften/Parser/AttributeMap.h> #include <Swiften/Elements/Payload.h> +#include <Swiften/Parser/AttributeMap.h> namespace Swift { - - - /** - * A parser for XMPP stanza payloads. - * - * The parser is event driven: handleStartElement, handleEndElement, and handleCharacterData will be called - * when the parser detects start and end of XML elements, or character data. - * After the data for the given top-level element is processed, getPayload() will be called to retrieve the - * payload. - */ - class SWIFTEN_API PayloadParser { - public: - virtual ~PayloadParser(); - - /** - * Handle the start of an XML element. - */ - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) = 0; - - /** - * Handle the end of an XML element. - */ - virtual void handleEndElement(const std::string& element, const std::string& ns) = 0; - - /** - * Handle character data. - */ - virtual void handleCharacterData(const std::string& data) = 0; - - /** - * Retrieve a pointer to the payload. - */ - virtual boost::shared_ptr<Payload> getPayload() const = 0; - }; + + + /** + * A parser for XMPP stanza payloads. + * + * The parser is event driven: handleStartElement, handleEndElement, and handleCharacterData will be called + * when the parser detects start and end of XML elements, or character data. + * After the data for the given top-level element is processed, getPayload() will be called to retrieve the + * payload. + */ + class SWIFTEN_API PayloadParser { + public: + virtual ~PayloadParser(); + + /** + * Handle the start of an XML element. + */ + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) = 0; + + /** + * Handle the end of an XML element. + */ + virtual void handleEndElement(const std::string& element, const std::string& ns) = 0; + + /** + * Handle character data. + */ + virtual void handleCharacterData(const std::string& data) = 0; + + /** + * Retrieve a pointer to the payload. + */ + virtual std::shared_ptr<Payload> getPayload() const = 0; + }; } diff --git a/Swiften/Parser/PayloadParserFactory.cpp b/Swiften/Parser/PayloadParserFactory.cpp index 4dac217..8c1d099 100644 --- a/Swiften/Parser/PayloadParserFactory.cpp +++ b/Swiften/Parser/PayloadParserFactory.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParserFactory.h> diff --git a/Swiften/Parser/PayloadParserFactory.h b/Swiften/Parser/PayloadParserFactory.h index e265e5b..84f11ff 100644 --- a/Swiften/Parser/PayloadParserFactory.h +++ b/Swiften/Parser/PayloadParserFactory.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once @@ -10,24 +10,24 @@ #include <Swiften/Parser/AttributeMap.h> namespace Swift { - - class PayloadParser; - /** - * A factory for PayloadParsers. - */ - class SWIFTEN_API PayloadParserFactory { - public: - virtual ~PayloadParserFactory(); + class PayloadParser; - /** - * Checks whether this factory can parse the given top-level element in the given namespace (with the given attributes). - */ - virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap& attributes) const = 0; + /** + * A factory for PayloadParsers. + */ + class SWIFTEN_API PayloadParserFactory { + public: + virtual ~PayloadParserFactory(); - /** - * Creates a new payload parser. - */ - virtual PayloadParser* createPayloadParser() = 0; - }; + /** + * Checks whether this factory can parse the given top-level element in the given namespace (with the given attributes). + */ + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap& attributes) const = 0; + + /** + * Creates a new payload parser. + */ + virtual PayloadParser* createPayloadParser() = 0; + }; } diff --git a/Swiften/Parser/PayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParserFactoryCollection.cpp index e3efc3d..bca1e83 100644 --- a/Swiften/Parser/PayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParserFactoryCollection.cpp @@ -1,37 +1,42 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ -#include <boost/bind.hpp> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> + #include <algorithm> -#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <boost/bind.hpp> + #include <Swiften/Parser/PayloadParserFactory.h> namespace Swift { -PayloadParserFactoryCollection::PayloadParserFactoryCollection() : defaultFactory_(NULL) { +PayloadParserFactoryCollection::PayloadParserFactoryCollection() : defaultFactory_(nullptr) { +} + +PayloadParserFactoryCollection::~PayloadParserFactoryCollection() { } void PayloadParserFactoryCollection::addFactory(PayloadParserFactory* factory) { - factories_.push_back(factory); + factories_.push_back(factory); } void PayloadParserFactoryCollection::removeFactory(PayloadParserFactory* factory) { - factories_.erase(remove(factories_.begin(), factories_.end(), factory), factories_.end()); + factories_.erase(std::remove(factories_.begin(), factories_.end(), factory), factories_.end()); } void PayloadParserFactoryCollection::setDefaultFactory(PayloadParserFactory* factory) { - defaultFactory_ = factory; + defaultFactory_ = factory; } PayloadParserFactory* PayloadParserFactoryCollection::getPayloadParserFactory(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - std::vector<PayloadParserFactory*>::reverse_iterator i = std::find_if( - factories_.rbegin(), factories_.rend(), - boost::bind(&PayloadParserFactory::canParse, _1, element, ns, attributes)); - return (i != factories_.rend() ? *i : defaultFactory_); + std::vector<PayloadParserFactory*>::reverse_iterator i = std::find_if( + factories_.rbegin(), factories_.rend(), + boost::bind(&PayloadParserFactory::canParse, _1, element, ns, attributes)); + return (i != factories_.rend() ? *i : defaultFactory_); } } diff --git a/Swiften/Parser/PayloadParserFactoryCollection.h b/Swiften/Parser/PayloadParserFactoryCollection.h index 1dbdd32..cc0db5a 100644 --- a/Swiften/Parser/PayloadParserFactoryCollection.h +++ b/Swiften/Parser/PayloadParserFactoryCollection.h @@ -1,31 +1,32 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <vector> -#include <Swiften/Parser/AttributeMap.h> #include <Swiften/Base/API.h> +#include <Swiften/Parser/AttributeMap.h> namespace Swift { - class PayloadParserFactory; + class PayloadParserFactory; - class SWIFTEN_API PayloadParserFactoryCollection { - public: - PayloadParserFactoryCollection(); + class SWIFTEN_API PayloadParserFactoryCollection { + public: + PayloadParserFactoryCollection(); + virtual ~PayloadParserFactoryCollection(); - void addFactory(PayloadParserFactory* factory); - void removeFactory(PayloadParserFactory* factory); - void setDefaultFactory(PayloadParserFactory* factory); + void addFactory(PayloadParserFactory* factory); + void removeFactory(PayloadParserFactory* factory); + void setDefaultFactory(PayloadParserFactory* factory); - PayloadParserFactory* getPayloadParserFactory(const std::string& element, const std::string& ns, const AttributeMap& attributes); + PayloadParserFactory* getPayloadParserFactory(const std::string& element, const std::string& ns, const AttributeMap& attributes); - private: - std::vector<PayloadParserFactory*> factories_; - PayloadParserFactory* defaultFactory_; - }; + private: + std::vector<PayloadParserFactory*> factories_; + PayloadParserFactory* defaultFactory_; + }; } diff --git a/Swiften/Parser/PayloadParsers/BlockParser.h b/Swiften/Parser/PayloadParsers/BlockParser.h index 6ee47a2..1724feb 100644 --- a/Swiften/Parser/PayloadParsers/BlockParser.h +++ b/Swiften/Parser/PayloadParsers/BlockParser.h @@ -1,40 +1,41 @@ /* - * Copyright (c) 2011 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/Nickname.h> #include <Swiften/JID/JID.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - template<typename BLOCK_ELEMENT> - class 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 ac8bdd5..5741c90 100644 --- a/Swiften/Parser/PayloadParsers/BodyParser.cpp +++ b/Swiften/Parser/PayloadParsers/BodyParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/BodyParser.h> @@ -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 f571370..bcf762b 100644 --- a/Swiften/Parser/PayloadParsers/BodyParser.h +++ b/Swiften/Parser/PayloadParsers/BodyParser.h @@ -1,25 +1,26 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/Body.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 fddc1c7..71bce54 100644 --- a/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp +++ b/Swiften/Parser/PayloadParsers/BytestreamsParser.cpp @@ -1,14 +1,13 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/BytestreamsParser.h> #include <boost/lexical_cast.hpp> - -#include <Swiften/Base/foreach.h> +#include <boost/numeric/conversion/cast.hpp> namespace Swift { @@ -19,26 +18,28 @@ 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::numeric_cast<unsigned short>(boost::lexical_cast<int>(attributes.getAttribute("port"))))); + } + catch (boost::numeric::bad_numeric_cast&) { + } + 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 5c151c2..01cb60f 100644 --- a/Swiften/Parser/PayloadParsers/BytestreamsParser.h +++ b/Swiften/Parser/PayloadParsers/BytestreamsParser.h @@ -1,31 +1,32 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <boost/optional.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Elements/Bytestreams.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 770d98b..546df57 100644 --- a/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/CapsInfoParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/CapsInfoParser.h> @@ -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 96aa734..9556a4d 100644 --- a/Swiften/Parser/PayloadParsers/CapsInfoParser.h +++ b/Swiften/Parser/PayloadParsers/CapsInfoParser.h @@ -1,24 +1,25 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/CapsInfo.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 new file mode 100644 index 0000000..b8bd4b5 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/CarbonsDisableParser.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/CarbonsDisableParser.h> + +namespace Swift { + + CarbonsDisableParser::CarbonsDisableParser() : GenericPayloadParser<CarbonsDisable>() { + } + + CarbonsDisableParser::~CarbonsDisableParser() { + } + + void CarbonsDisableParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + } + + void CarbonsDisableParser::handleEndElement(const std::string&, const std::string&) { + } + + void CarbonsDisableParser::handleCharacterData(const std::string&) { + } + +} diff --git a/Swiften/Parser/PayloadParsers/CarbonsDisableParser.h b/Swiften/Parser/PayloadParsers/CarbonsDisableParser.h new file mode 100644 index 0000000..7a5f4a4 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/CarbonsDisableParser.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/CarbonsDisable.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + 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&); + }; +} diff --git a/Swiften/Parser/PayloadParsers/CarbonsEnableParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsEnableParser.cpp new file mode 100644 index 0000000..700f939 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/CarbonsEnableParser.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/CarbonsEnableParser.h> + +namespace Swift { + + CarbonsEnableParser::CarbonsEnableParser() : GenericPayloadParser<CarbonsEnable>() { + } + + CarbonsEnableParser::~CarbonsEnableParser() { + } + + void CarbonsEnableParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + } + + void CarbonsEnableParser::handleEndElement(const std::string&, const std::string&) { + } + + void CarbonsEnableParser::handleCharacterData(const std::string&) { + } + +} diff --git a/Swiften/Parser/PayloadParsers/CarbonsEnableParser.h b/Swiften/Parser/PayloadParsers/CarbonsEnableParser.h new file mode 100644 index 0000000..0488f97 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/CarbonsEnableParser.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/CarbonsEnable.h> +#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&); + }; +} diff --git a/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.cpp new file mode 100644 index 0000000..b2038db --- /dev/null +++ b/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h> + +namespace Swift { + + CarbonsPrivateParser::CarbonsPrivateParser() : GenericPayloadParser<CarbonsPrivate>() { + } + + CarbonsPrivateParser::~CarbonsPrivateParser() { + } + + void CarbonsPrivateParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + } + + void CarbonsPrivateParser::handleEndElement(const std::string&, const std::string&) { + } + + void CarbonsPrivateParser::handleCharacterData(const std::string&) { + } + +} diff --git a/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h b/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h new file mode 100644 index 0000000..2ae3bae --- /dev/null +++ b/Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/CarbonsPrivate.h> +#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&); + }; +} diff --git a/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.cpp new file mode 100644 index 0000000..e4f8ab9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h> + +namespace Swift { + CarbonsReceivedParser::CarbonsReceivedParser(PayloadParserFactoryCollection* factories) : GenericPayloadParser<CarbonsReceived>(), factories_(factories), level_(TopLevel) { + } + + CarbonsReceivedParser::~CarbonsReceivedParser() { + } + + 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::handleCharacterData(const std::string& data) { + if (forwardedParser_) { + forwardedParser_->handleCharacterData(data); + } + } +} diff --git a/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h b/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h new file mode 100644 index 0000000..6cc1f43 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h @@ -0,0 +1,35 @@ +/* + * 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/CarbonsReceived.h> +#include <Swiften/Parser/GenericPayloadParser.h> +#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&); + + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + + private: + PayloadParserFactoryCollection* factories_; + std::shared_ptr<ForwardedParser> forwardedParser_; + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/CarbonsSentParser.cpp b/Swiften/Parser/PayloadParsers/CarbonsSentParser.cpp new file mode 100644 index 0000000..f446042 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/CarbonsSentParser.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/CarbonsSentParser.h> + +namespace Swift { + CarbonsSentParser::CarbonsSentParser(PayloadParserFactoryCollection* factories) : GenericPayloadParser<CarbonsSent>(), factories_(factories), level_(TopLevel) { + } + + CarbonsSentParser::~CarbonsSentParser() { + } + + 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::handleCharacterData(const std::string& data) { + if (forwardedParser_) { + forwardedParser_->handleCharacterData(data); + } + } +} diff --git a/Swiften/Parser/PayloadParsers/CarbonsSentParser.h b/Swiften/Parser/PayloadParsers/CarbonsSentParser.h new file mode 100644 index 0000000..d4e12ba --- /dev/null +++ b/Swiften/Parser/PayloadParsers/CarbonsSentParser.h @@ -0,0 +1,35 @@ +/* + * 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/CarbonsSent.h> +#include <Swiften/Parser/GenericPayloadParser.h> +#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&); + + private: + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + + 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 a85dcf7..75ec699 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParser.cpp +++ b/Swiften/Parser/PayloadParsers/ChatStateParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/ChatStateParser.h> @@ -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 4363d6b..b932a5c 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParser.h +++ b/Swiften/Parser/PayloadParsers/ChatStateParser.h @@ -1,24 +1,25 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/ChatState.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 80d76c4..3f9b3d3 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h +++ b/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h @@ -1,31 +1,30 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/ChatStateParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class SWIFTEN_API ChatStateParserFactory : public PayloadParserFactory { + public: + ChatStateParserFactory() { + } - class 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/ClientStateParser.cpp b/Swiften/Parser/PayloadParsers/ClientStateParser.cpp new file mode 100644 index 0000000..8a6cc9c --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ClientStateParser.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/ClientStateParser.h> + +namespace Swift { + +ClientStateParser::ClientStateParser() { +} + +void ClientStateParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { + if (level_ == 0) { + auto state = ClientState::ClientStateType::Active; + if (element == "active") { + state = ClientState::ClientStateType::Active; + } else if (element == "inactive") { + state = ClientState::ClientStateType::Inactive; + } + getPayloadInternal()->setClientState(state); + } + ++level_; +} + +void ClientStateParser::handleEndElement(const std::string&, const std::string&) { + --level_; +} + +void ClientStateParser::handleCharacterData(const std::string&) { + +} + +} diff --git a/Swiften/Parser/PayloadParsers/ClientStateParser.h b/Swiften/Parser/PayloadParsers/ClientStateParser.h new file mode 100644 index 0000000..039ae37 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ClientStateParser.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2017 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/ClientState.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class SWIFTEN_API ClientStateParser : public GenericPayloadParser<ClientState> { + public: + ClientStateParser(); + + 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_ = 0; + }; +} diff --git a/Swiften/Parser/PayloadParsers/ClientStateParserFactory.h b/Swiften/Parser/PayloadParsers/ClientStateParserFactory.h new file mode 100644 index 0000000..61f7012 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ClientStateParserFactory.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/ClientStateParser.h> + +namespace Swift { + class SWIFTEN_API ClientStateParserFactory : public PayloadParserFactory { + public: + ClientStateParserFactory() { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return ns == "urn:xmpp:csi:0" && + (element == "active" || element == "inactive"); + } + + virtual PayloadParser* createPayloadParser() { + return new ClientStateParser(); + } + + }; +} diff --git a/Swiften/Parser/PayloadParsers/CommandParser.cpp b/Swiften/Parser/PayloadParsers/CommandParser.cpp index 1af4074..80686d2 100644 --- a/Swiften/Parser/PayloadParsers/CommandParser.cpp +++ b/Swiften/Parser/PayloadParsers/CommandParser.cpp @@ -1,143 +1,145 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 80cffc4..105953a 100644 --- a/Swiften/Parser/PayloadParsers/CommandParser.h +++ b/Swiften/Parser/PayloadParsers/CommandParser.h @@ -1,45 +1,46 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <boost/optional.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Elements/Command.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class FormParserFactory; - class FormParser; - - class 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 e18d09d..95371b7 100644 --- a/Swiften/Parser/PayloadParsers/DelayParser.cpp +++ b/Swiften/Parser/PayloadParsers/DelayParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/DelayParser.h> @@ -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 144220a..d9bf44b 100644 --- a/Swiften/Parser/PayloadParsers/DelayParser.h +++ b/Swiften/Parser/PayloadParsers/DelayParser.h @@ -1,24 +1,25 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/Delay.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 90a0921..5cc0009 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h @@ -4,21 +4,28 @@ * See http://www.opensource.org/licenses/bsd-license.php for more information. */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/DeliveryReceipt.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 259e04a..322ef94 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h @@ -4,26 +4,31 @@ * See http://www.opensource.org/licenses/bsd-license.php for more information. */ +/* + * Copyright (c) 2015-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h> namespace Swift { - class PayloadParserFactoryCollection; - - class 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 55f7997..d8a68b0 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h @@ -4,18 +4,25 @@ * See http://www.opensource.org/licenses/bsd-license.php for more information. */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/DeliveryReceiptRequest.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 9bd98c2..cef5d8f 100644 --- a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h +++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h @@ -4,26 +4,31 @@ * See http://www.opensource.org/licenses/bsd-license.php for more information. */ +/* + * Copyright (c) 2015-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h> namespace Swift { - class PayloadParserFactoryCollection; - - class 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 aeb0db8..6ded2e2 100644 --- a/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp @@ -1,59 +1,62 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 1f93a88..9c26310 100644 --- a/Swiften/Parser/PayloadParsers/DiscoInfoParser.h +++ b/Swiften/Parser/PayloadParsers/DiscoInfoParser.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once @@ -11,20 +11,22 @@ #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SWIFTEN_API DiscoInfoParser : public GenericPayloadParser<DiscoInfo> { - public: - DiscoInfoParser(); + class 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); + class SWIFTEN_API DiscoInfoParser : public GenericPayloadParser<DiscoInfo> { + public: + DiscoInfoParser(); - private: - enum Level { - TopLevel = 0, - PayloadLevel = 1 - }; - int level_; - FormParser* 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); + + 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 a56dc5a..a3b9245 100644 --- a/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp +++ b/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/DiscoItemsParser.h> @@ -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 ae799cb..3197b79 100644 --- a/Swiften/Parser/PayloadParsers/DiscoItemsParser.h +++ b/Swiften/Parser/PayloadParsers/DiscoItemsParser.h @@ -1,29 +1,30 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/DiscoItems.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 8a02317..222bcbd 100644 --- a/Swiften/Parser/PayloadParsers/ErrorParser.cpp +++ b/Swiften/Parser/PayloadParsers/ErrorParser.cpp @@ -1,12 +1,13 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 b2d05cf..10f5431 100644 --- a/Swiften/Parser/PayloadParsers/ErrorParser.h +++ b/Swiften/Parser/PayloadParsers/ErrorParser.h @@ -1,32 +1,33 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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/ErrorPayload.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class 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 1463807..d8f09bf 100644 --- a/Swiften/Parser/PayloadParsers/ErrorParserFactory.h +++ b/Swiften/Parser/PayloadParsers/ErrorParserFactory.h @@ -1,32 +1,33 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/ErrorParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class 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 7c29189..dff45df 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.cpp +++ b/Swiften/Parser/PayloadParsers/FormParser.cpp @@ -1,170 +1,252 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ - #include <Swiften/Parser/PayloadParsers/FormParser.h> -#include <Swiften/Base/foreach.h> +#include <map> namespace Swift { -FormParser::FormParser() : level_(TopLevel), parsingItem_(false), parsingReported_(false), parsingOption_(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) { - 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 (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(); - } - } - ++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 (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 { - getPayloadInternal()->addField(currentField_); - } - currentField_.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 0b23a81..e1491b1 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.h +++ b/Swiften/Parser/PayloadParsers/FormParser.h @@ -1,36 +1,46 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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/Form.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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_; - bool parsingItem_; - bool parsingReported_; - bool parsingOption_; - FormField::ref currentField_; - std::vector<FormField::ref> currentFields_; - }; + 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 9e1794a..296fcd1 100644 --- a/Swiften/Parser/PayloadParsers/FormParserFactory.h +++ b/Swiften/Parser/PayloadParsers/FormParserFactory.h @@ -1,29 +1,28 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/FormParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class SWIFTEN_API FormParserFactory : public PayloadParserFactory { + public: + FormParserFactory() { + } - class 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 new file mode 100644 index 0000000..72a665a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ForwardedParser.cpp @@ -0,0 +1,73 @@ +/* + * 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/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_ = 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(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); + } +} diff --git a/Swiften/Parser/PayloadParsers/ForwardedParser.h b/Swiften/Parser/PayloadParsers/ForwardedParser.h new file mode 100644 index 0000000..c9f13df --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ForwardedParser.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2014-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> + +#include <Swiften/Base/API.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) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 3ec5a7a..9e56b63 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -1,161 +1,208 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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/Elements/BlockListPayload.h> #include <Swiften/Parser/GenericPayloadParser.h> #include <Swiften/Parser/GenericPayloadParserFactory.h> #include <Swiften/Parser/GenericPayloadParserFactory2.h> #include <Swiften/Parser/PayloadParserFactory.h> -#include <Swiften/Parser/PayloadParsers/ErrorParser.h> -#include <Swiften/Parser/PayloadParsers/ErrorParserFactory.h> -#include <Swiften/Parser/PayloadParsers/BodyParser.h> #include <Swiften/Parser/PayloadParsers/BlockParser.h> -#include <Swiften/Parser/PayloadParsers/SubjectParser.h> +#include <Swiften/Parser/PayloadParsers/BodyParser.h> +#include <Swiften/Parser/PayloadParsers/BytestreamsParser.h> +#include <Swiften/Parser/PayloadParsers/CapsInfoParser.h> +#include <Swiften/Parser/PayloadParsers/CarbonsDisableParser.h> +#include <Swiften/Parser/PayloadParsers/CarbonsEnableParser.h> +#include <Swiften/Parser/PayloadParsers/CarbonsPrivateParser.h> +#include <Swiften/Parser/PayloadParsers/CarbonsReceivedParser.h> +#include <Swiften/Parser/PayloadParsers/CarbonsSentParser.h> #include <Swiften/Parser/PayloadParsers/ChatStateParserFactory.h> -#include <Swiften/Parser/PayloadParsers/PriorityParser.h> -#include <Swiften/Parser/PayloadParsers/ResourceBindParser.h> -#include <Swiften/Parser/PayloadParsers/StartSessionParser.h> -#include <Swiften/Parser/PayloadParsers/StatusParser.h> -#include <Swiften/Parser/PayloadParsers/StatusShowParser.h> -#include <Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h> -#include <Swiften/Parser/PayloadParsers/RosterParser.h> -#include <Swiften/Parser/PayloadParsers/SoftwareVersionParser.h> -#include <Swiften/Parser/PayloadParsers/StorageParser.h> +#include <Swiften/Parser/PayloadParsers/ClientStateParserFactory.h> +#include <Swiften/Parser/PayloadParsers/CommandParser.h> +#include <Swiften/Parser/PayloadParsers/DelayParser.h> +#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h> +#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h> #include <Swiften/Parser/PayloadParsers/DiscoInfoParser.h> #include <Swiften/Parser/PayloadParsers/DiscoItemsParser.h> -#include <Swiften/Parser/PayloadParsers/CapsInfoParser.h> -#include <Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h> -#include <Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h> +#include <Swiften/Parser/PayloadParsers/ErrorParser.h> +#include <Swiften/Parser/PayloadParsers/ErrorParserFactory.h> #include <Swiften/Parser/PayloadParsers/FormParserFactory.h> -#include <Swiften/Parser/PayloadParsers/CommandParser.h> -#include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h> -#include <Swiften/Parser/PayloadParsers/SearchPayloadParser.h> -#include <Swiften/Parser/PayloadParsers/StreamInitiationParser.h> -#include <Swiften/Parser/PayloadParsers/BytestreamsParser.h> +#include <Swiften/Parser/PayloadParsers/ForwardedParser.h> #include <Swiften/Parser/PayloadParsers/IBBParser.h> -#include <Swiften/Parser/PayloadParsers/VCardUpdateParser.h> -#include <Swiften/Parser/PayloadParsers/VCardParser.h> -#include <Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h> -#include <Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h> -#include <Swiften/Parser/PayloadParsers/DelayParser.h> -#include <Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/IdleParser.h> +#include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h> +#include <Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h> +#include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h> +#include <Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h> +#include <Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.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> +#include <Swiften/Parser/PayloadParsers/LastParser.h> +#include <Swiften/Parser/PayloadParsers/MAMFinParser.h> +#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h> +#include <Swiften/Parser/PayloadParsers/MAMResultParser.h> +#include <Swiften/Parser/PayloadParsers/MIXParticipantParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXCreateParser.h> +#include <Swiften/Parser/PayloadParsers/MIXRegisterNickParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXSetNickParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXDestroyParser.h> +#include <Swiften/Parser/PayloadParsers/MIXUpdateSubscriptionParser.h> +#include <Swiften/Parser/PayloadParsers/MIXJoinParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXUserPreferenceParser.h> +#include <Swiften/Parser/PayloadParsers/MIXLeaveParser.h> #include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h> -#include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h> #include <Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h> #include <Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h> #include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/NicknameParser.h> +#include <Swiften/Parser/PayloadParsers/PriorityParser.h> +#include <Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubParser.h> +#include <Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/ReferencePayloadParser.h> #include <Swiften/Parser/PayloadParsers/ReplaceParser.h> -#include <Swiften/Parser/PayloadParsers/LastParser.h> -#include <Swiften/Parser/PayloadParsers/JingleParserFactory.h> -#include <Swiften/Parser/PayloadParsers/JingleReasonParser.h> -#include <Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h> -#include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h> -#include <Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h> -#include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h> -#include <Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h> -#include <Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.h> -#include <Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h> +#include <Swiften/Parser/PayloadParsers/ResourceBindParser.h> +#include <Swiften/Parser/PayloadParsers/ResultSetParser.h> +#include <Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h> +#include <Swiften/Parser/PayloadParsers/RosterParser.h> #include <Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h> -#include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h> -#include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h> -#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h> -#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h> -#include <Swiften/Parser/PayloadParsers/WhiteboardParser.h> -#include <Swiften/Parser/PayloadParsers/IdleParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubEventParser.h> -#include <Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h> +#include <Swiften/Parser/PayloadParsers/SearchPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h> +#include <Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h> +#include <Swiften/Parser/PayloadParsers/SoftwareVersionParser.h> +#include <Swiften/Parser/PayloadParsers/StartSessionParser.h> +#include <Swiften/Parser/PayloadParsers/StatusParser.h> +#include <Swiften/Parser/PayloadParsers/StatusShowParser.h> +#include <Swiften/Parser/PayloadParsers/StorageParser.h> +#include <Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h> +#include <Swiften/Parser/PayloadParsers/StreamInitiationParser.h> +#include <Swiften/Parser/PayloadParsers/SubjectParser.h> +#include <Swiften/Parser/PayloadParsers/ThreadParser.h> #include <Swiften/Parser/PayloadParsers/UserLocationParser.h> - -using namespace boost; +#include <Swiften/Parser/PayloadParsers/UserTuneParser.h> +#include <Swiften/Parser/PayloadParsers/VCardParser.h> +#include <Swiften/Parser/PayloadParsers/VCardUpdateParser.h> +#include <Swiften/Parser/PayloadParsers/WhiteboardParser.h> 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<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<JingleFileTransferReceivedParser> >("received", "urn:xmpp:jingle:apps:file-transfer:3")); - 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<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(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<ClientStateParserFactory>()); + factories_.push_back(std::make_shared<MIXParticipantParserFactory>()); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXDestroyParser> >("destroy", "urn:xmpp:mix:0")); + factories_.push_back(std::make_shared<MIXRegisterNickParserFactory>()); + factories_.push_back(std::make_shared<MIXSetNickParserFactory>()); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXCreateParser> >("create", "urn:xmpp:mix:0")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXUpdateSubscriptionParser> >("update-subscription", "urn:xmpp:mix:0")); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXUserPreferenceParser> >("user-preference", "urn:xmpp:mix:0")); + factories_.push_back(std::make_shared<MIXPayloadParserFactory>()); + factories_.push_back(std::make_shared<GenericPayloadParserFactory<MIXLeaveParser> >("leave", "urn:xmpp:mix:0")); + 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")); + factories_.push_back(std::make_shared<MIXJoinParserFactory>()); + factories_.push_back(std::make_shared<GenericPayloadParserFactory2<ReferencePayloadParser> >("reference", "urn:xmpp:reference:0", this)); - 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 91302b1..e59a6e0 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h @@ -1,26 +1,26 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 20a1ce9..1ba44e1 100644 --- a/Swiften/Parser/PayloadParsers/IBBParser.cpp +++ b/Swiften/Parser/PayloadParsers/IBBParser.cpp @@ -1,14 +1,13 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/IBBParser.h> #include <boost/lexical_cast.hpp> -#include <Swiften/Base/foreach.h> #include <Swiften/StringCodecs/Base64.h> namespace Swift { @@ -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<unsigned 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 59011b4..7ef3e6f 100644 --- a/Swiften/Parser/PayloadParsers/IBBParser.h +++ b/Swiften/Parser/PayloadParsers/IBBParser.h @@ -1,31 +1,32 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <boost/optional.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Elements/IBB.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 38001b2..c1922c0 100644 --- a/Swiften/Parser/PayloadParsers/IdleParser.h +++ b/Swiften/Parser/PayloadParsers/IdleParser.h @@ -4,21 +4,28 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * 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 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 06759cb..f0241b0 100644 --- a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp @@ -1,131 +1,133 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 1f85c85..7e2a4a4 100644 --- a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h @@ -1,37 +1,38 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <boost/optional.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Elements/InBandRegistrationPayload.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class FormParserFactory; - class FormParser; + class FormParserFactory; + class FormParser; - class 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 new file mode 100644 index 0000000..2efe3c8 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h> + +#include <boost/optional.hpp> + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> + +using namespace Swift; + +IsodeIQDelegationParser::IsodeIQDelegationParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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; +} + +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(std::dynamic_pointer_cast<Forwarded>(currentPayloadParser->getPayload())); + currentPayloadParser.reset(); + } + } +} + +void IsodeIQDelegationParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h new file mode 100644 index 0000000..af2f061 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2014-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/IsodeIQDelegation.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API IsodeIQDelegationParser : public GenericPayloadParser<IsodeIQDelegation> { + public: + IsodeIQDelegationParser(PayloadParserFactoryCollection* parsers); + virtual ~IsodeIQDelegationParser() override; + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) override; + + 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 a871cc4..fde07cb 100644 --- a/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h @@ -4,8 +4,15 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * 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/JingleContentPayload.h> #include <Swiften/Parser/GenericPayloadParser.h> @@ -13,18 +20,18 @@ namespace Swift { class PayloadParserFactoryCollection; -class JingleContentPayloadParser : public GenericPayloadParser<JingleContentPayload> { - public: - JingleContentPayloadParser(PayloadParserFactoryCollection* factories); +class SWIFTEN_API JingleContentPayloadParser : public GenericPayloadParser<JingleContentPayload> { + 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 6d66e74..8e9741d 100644 --- a/Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/JingleContentPayloadParserFactory.h @@ -4,32 +4,39 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/GenericPayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/JingleContentPayloadParser.h> namespace Swift { - - class PayloadParserFactoryCollection; - - class 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 b394115..1e433a6 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.cpp @@ -4,72 +4,59 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ -#include "JingleFileTransferDescriptionParser.h" +/* + * Copyright (c) 2014-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ -#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h> + +#include <boost/lexical_cast.hpp> +#include <boost/optional.hpp> + +#include <Swiften/Base/DateTime.h> #include <Swiften/Parser/PayloadParserFactory.h> -#include <Swiften/Base/Log.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/StringCodecs/Base64.h> namespace Swift { -JingleFileTransferDescriptionParser::JingleFileTransferDescriptionParser(PayloadParserFactoryCollection* factories) : factories(factories), level(0), - currentElement(UnknownElement) { - +JingleFileTransferDescriptionParser::JingleFileTransferDescriptionParser(PayloadParserFactoryCollection* factories) : factories(factories), level(0) { } void JingleFileTransferDescriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 0) { - - } - - if (level == 1) { - if (element == "offer") { - currentElement = OfferElement; - } else if (element == "request") { - currentElement = RequestElement; - } else { - currentElement = UnknownElement; - } - } - - if (level == 2) { - PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } - } - - if (level >= 2 && 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 (currentPayloadParser) { - if (level >= 2) { - currentPayloadParser->handleEndElement(element, ns); - } - - if (level == 2) { - boost::shared_ptr<StreamInitiationFileInfo> info = boost::dynamic_pointer_cast<StreamInitiationFileInfo>(currentPayloadParser->getPayload()); - if (info) { - if (currentElement == OfferElement) { - getPayloadInternal()->addOffer(*info); - } else if (currentElement == RequestElement) { - getPayloadInternal()->addRequest(*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 >= 2 && 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 7ea22b4..b148d9b 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h @@ -4,8 +4,15 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2014-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/JingleFileTransferDescription.h> #include <Swiften/Parser/GenericPayloadParser.h> #include <Swiften/Parser/PayloadParser.h> @@ -14,25 +21,18 @@ namespace Swift { class PayloadParserFactoryCollection; -class JingleFileTransferDescriptionParser : public GenericPayloadParser<JingleFileTransferDescription> { - 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); - - private: - enum CurrentParseElement { - UnknownElement, - RequestElement, - OfferElement - }; - - PayloadParserFactoryCollection* factories; - int level; - CurrentParseElement currentElement; - boost::shared_ptr<PayloadParser> currentPayloadParser; +class SWIFTEN_API JingleFileTransferDescriptionParser : public GenericPayloadParser<JingleFileTransferDescription> { + 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); + + 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 b997c1d..c75125f 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParserFactory.h @@ -4,32 +4,39 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2014-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/GenericPayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h> namespace Swift { - - class PayloadParserFactoryCollection; - - class 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:3"; - } - - 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 new file mode 100644 index 0000000..4f8b9a9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2014-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h> + +#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) { +} + +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 &) { + + } + 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("")); + } + + ++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))); + } + } +} + +void JingleFileTransferFileInfoParser::handleCharacterData(const std::string& data) { + charData += data; +} + +} diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h new file mode 100644 index 0000000..237f105 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2014-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/JingleFileTransferFileInfo.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + +class SWIFTEN_API JingleFileTransferFileInfoParser : public GenericPayloadParser<JingleFileTransferFileInfo> { + 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; +}; + +} diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp index 87f8317..4adf3bd 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.cpp @@ -4,40 +4,56 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ -#include "JingleFileTransferHashParser.h" +/* + * Copyright (c) 2014-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h> + +#include <memory> -#include <boost/shared_ptr.hpp> #include <boost/algorithm/string.hpp> -#include <Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h> #include <Swiften/Parser/GenericPayloadParserFactory.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/JingleFileTransferFileInfoParser.h> namespace Swift { -JingleFileTransferHashParser::JingleFileTransferHashParser() { +JingleFileTransferHashParser::JingleFileTransferHashParser() : level(0) { } - -void JingleFileTransferHashParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { - if (element == "hash") { - algo = attributes.getAttribute("algo"); - } + +void JingleFileTransferHashParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + 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& ) { - if (element == "hash" && !algo.empty() && !hash.empty()) { - getPayloadInternal()->setHash(algo, hash); - algo.clear(); - hash.clear(); - } +void JingleFileTransferHashParser::handleEndElement(const std::string& element, const std::string& ns) { + --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 (!algo.empty()) { - std::string new_data(data); - boost::trim(new_data); - hash += new_data; - } + if (level >= 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h index 35e4a05..1b47921 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferHashParser.h @@ -4,24 +4,31 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2014-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/JingleFileTransferHash.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { -class JingleFileTransferHashParser : public GenericPayloadParser<JingleFileTransferHash> { +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: - std::string algo; - std::string hash; + int level; + std::shared_ptr<PayloadParser> currentPayloadParser; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.cpp b/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.cpp deleted file mode 100644 index ae56981..0000000 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2011 Tobias Markmann - * Licensed under the simplified BSD license. - * See Documentation/Licenses/BSD-simplified.txt for more information. - */ - -#include <Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.h> - -#include <boost/shared_ptr.hpp> -#include <Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h> -#include <Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h> -#include <Swiften/Parser/GenericPayloadParserFactory.h> -#include <Swiften/Parser/PayloadParserFactory.h> - -namespace Swift { - -JingleFileTransferReceivedParser::JingleFileTransferReceivedParser() : level(0) { -} - -void JingleFileTransferReceivedParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level == 1 && element == "file") { - PayloadParserFactory* payloadParserFactory = new GenericPayloadParserFactory<StreamInitiationFileInfoParser>("file", "http://jabber.org/protocol/si/profile/file-transfer"); - if (payloadParserFactory) { - currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); - } - } - - if (currentPayloadParser && level >= 1) { - currentPayloadParser->handleStartElement(element, ns, attributes); - } - - ++level; -} - -void JingleFileTransferReceivedParser::handleEndElement(const std::string& element, const std::string& ) { - --level; - if (element == "file") { - boost::shared_ptr<StreamInitiationFileInfo> fileInfo = boost::dynamic_pointer_cast<StreamInitiationFileInfo>(currentPayloadParser->getPayload()); - if (fileInfo) { - getPayloadInternal()->setFileInfo(*fileInfo); - } - } -} - -void JingleFileTransferReceivedParser::handleCharacterData(const std::string& ) { - -} - -} diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.h deleted file mode 100644 index d5333ad..0000000 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2011 Tobias Markmann - * Licensed under the simplified BSD license. - * See Documentation/Licenses/BSD-simplified.txt for more information. - */ - -#pragma once - -#include <Swiften/Elements/JingleFileTransferReceived.h> -#include <Swiften/Parser/GenericPayloadParser.h> - -namespace Swift { - -class JingleFileTransferReceivedParser : public GenericPayloadParser<JingleFileTransferReceived> { -public: - JingleFileTransferReceivedParser(); - - 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: - boost::shared_ptr<PayloadParser> currentPayloadParser; - int level; -}; - -} - diff --git a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp index d140368..438420b 100644 --- a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp @@ -5,43 +5,43 @@ */ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 311cc5b..e406b9f 100644 --- a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h @@ -4,23 +4,30 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/JingleIBBTransportPayload.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { -class JingleIBBTransportMethodPayloadParser : public GenericPayloadParser<JingleIBBTransportPayload> { - public: - JingleIBBTransportMethodPayloadParser(); +class SWIFTEN_API JingleIBBTransportMethodPayloadParser : public GenericPayloadParser<JingleIBBTransportPayload> { + 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 dd34458..a88a5b2 100644 --- a/Swiften/Parser/PayloadParsers/JingleParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleParser.cpp @@ -4,116 +4,117 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * 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/JingleFileTransferReceived.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<JingleFileTransferReceived> received = boost::dynamic_pointer_cast<JingleFileTransferReceived>(currentPayloadParser->getPayload()); - if (received) { - getPayloadInternal()->addPayload(received); - } - - 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 c7bd58c..1dcc9e7 100644 --- a/Swiften/Parser/PayloadParsers/JingleParser.h +++ b/Swiften/Parser/PayloadParsers/JingleParser.h @@ -4,29 +4,36 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * 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/JinglePayload.h> #include <Swiften/Parser/GenericPayloadParser.h> #include <Swiften/Parser/PayloadParserFactoryCollection.h> namespace Swift { -class 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; +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; + std::shared_ptr<PayloadParser> currentPayloadParser; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleParserFactory.h b/Swiften/Parser/PayloadParsers/JingleParserFactory.h index fa25aeb..5f9b45b 100644 --- a/Swiften/Parser/PayloadParsers/JingleParserFactory.h +++ b/Swiften/Parser/PayloadParsers/JingleParserFactory.h @@ -4,32 +4,39 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/GenericPayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/JingleParser.h> namespace Swift { - - class PayloadParserFactoryCollection; - - class 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 08af31a..a445448 100644 --- a/Swiften/Parser/PayloadParsers/JingleReasonParser.h +++ b/Swiften/Parser/PayloadParsers/JingleReasonParser.h @@ -4,27 +4,34 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/JinglePayload.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { -class JingleReasonParser : public GenericPayloadParser<JinglePayload::Reason> { - public: - JingleReasonParser(); +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; + 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; + private: + int level; + bool parseText; + std::string text; }; } diff --git a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp index 14a80e6..a405e0e 100644 --- a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp @@ -4,85 +4,91 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2014-2018 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/numeric/conversion/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 { - std::cerr << "Unknown S5B mode; falling back to defaul!" << std::endl; - getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); - } - } 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(""); + + unsigned short port = 0; + try { + port = boost::numeric_cast<unsigned short>(boost::lexical_cast<int>(attributes.getAttributeValue("port").get_value_or("0"))); + } catch(...) { } + 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 { - std::cerr << "Unknown candidate type; falling back to default!" << std::endl; - 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 1987d3f..f48c4b5 100644 --- a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h @@ -4,26 +4,33 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/JingleS5BTransportPayload.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { -class JingleS5BTransportMethodPayloadParser : public GenericPayloadParser<JingleS5BTransportPayload> { - public: - JingleS5BTransportMethodPayloadParser(); +class SWIFTEN_API JingleS5BTransportMethodPayloadParser : public GenericPayloadParser<JingleS5BTransportPayload> { + 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 77ebba8..89d39ac 100644 --- a/Swiften/Parser/PayloadParsers/LastParser.cpp +++ b/Swiften/Parser/PayloadParsers/LastParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/LastParser.h> @@ -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 7c5c707..70bfdcb 100644 --- a/Swiften/Parser/PayloadParsers/LastParser.h +++ b/Swiften/Parser/PayloadParsers/LastParser.h @@ -1,24 +1,25 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/Last.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 new file mode 100644 index 0000000..88dd571 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMFinParser.cpp @@ -0,0 +1,61 @@ +/* + * 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> + +using namespace Swift; + +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_ = 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(std::dynamic_pointer_cast<ResultSet>(resultSetParser_->getPayload())); + resultSetParser_.reset(); + } +} + +void MAMFinParser::handleCharacterData(const std::string& data) { + if (resultSetParser_) { + resultSetParser_->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/MAMFinParser.h b/Swiften/Parser/PayloadParsers/MAMFinParser.h new file mode 100644 index 0000000..419d542 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMFinParser.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/MAMFin.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class ResultSetParser; + + class SWIFTEN_API MAMFinParser : public GenericPayloadParser<MAMFin> { + public: + MAMFinParser(); + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) override; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + private: + std::shared_ptr<ResultSetParser> resultSetParser_; + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp new file mode 100644 index 0000000..4919d22 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp @@ -0,0 +1,78 @@ +/* + * 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> + +using namespace Swift; + +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_ = 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 (resultSetParser_) { /* parsing a nested ResultSet */ + resultSetParser_->handleStartElement(element, ns, attributes); + } + + ++level_; +} + +void MAMQueryParser::handleEndElement(const std::string& element, const std::string& ns) { + --level_; + + 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(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); + } +} diff --git a/Swiften/Parser/PayloadParsers/MAMQueryParser.h b/Swiften/Parser/PayloadParsers/MAMQueryParser.h new file mode 100644 index 0000000..ab062c5 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMQueryParser.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2014-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> +#include <string> + +#include <Swiften/Base/API.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) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 new file mode 100644 index 0000000..b810b87 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMResultParser.cpp @@ -0,0 +1,59 @@ +/* + * 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> + +using namespace Swift; + +MAMResultParser::MAMResultParser(PayloadParserFactoryCollection* factories) : factories_(factories), level_(TopLevel) { +} + +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_ = 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(std::dynamic_pointer_cast<Forwarded>(payloadParser_->getPayload())); + payloadParser_.reset(); + } +} + +void MAMResultParser::handleCharacterData(const std::string& data) { + if (payloadParser_) { + payloadParser_->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/MAMResultParser.h b/Swiften/Parser/PayloadParsers/MAMResultParser.h new file mode 100644 index 0000000..f058e15 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMResultParser.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2014-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> +#include <string> + +#include <Swiften/Base/API.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) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) override; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + private: + std::shared_ptr<ForwardedParser> payloadParser_; + PayloadParserFactoryCollection* factories_; + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXCreateParser.cpp b/Swiften/Parser/PayloadParsers/MIXCreateParser.cpp new file mode 100644 index 0000000..8c4ec8a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXCreateParser.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXCreateParser.h> + +#include <boost/optional.hpp> + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> + +using namespace Swift; + +MIXCreateParser::MIXCreateParser() : level_(0) { +} + +MIXCreateParser::~MIXCreateParser() { +} + +void MIXCreateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level_ == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("channel")) { + getPayloadInternal()->setChannel(*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 MIXCreateParser::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(std::dynamic_pointer_cast<Form>(currentPayloadParser_->getPayload())); + } + currentPayloadParser_.reset(); + } + } +} + +void MIXCreateParser::handleCharacterData(const std::string& data) { + if (level_ > 1 && currentPayloadParser_) { + currentPayloadParser_->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/MIXCreateParser.h b/Swiften/Parser/PayloadParsers/MIXCreateParser.h new file mode 100644 index 0000000..ef123e1 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXCreateParser.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/MIXCreate.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParser; + + class SWIFTEN_API MIXCreateParser : public GenericPayloadParser<MIXCreate> { + public: + MIXCreateParser(); + virtual ~MIXCreateParser() override; + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) override; + + private: + int level_; + std::shared_ptr<PayloadParser> currentPayloadParser_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXDestroyParser.cpp b/Swiften/Parser/PayloadParsers/MIXDestroyParser.cpp new file mode 100644 index 0000000..0437b48 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXDestroyParser.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXDestroyParser.h> + +#include <boost/optional.hpp> + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> + +using namespace Swift; + +MIXDestroyParser::MIXDestroyParser() : level_(0) { +} + +MIXDestroyParser::~MIXDestroyParser() { +} + +void MIXDestroyParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + if (level_ == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("channel")) { + getPayloadInternal()->setChannel(*attributeValue); + } + } + ++level_; +} + +void MIXDestroyParser::handleEndElement(const std::string&, const std::string&) { + --level_; +} + +void MIXDestroyParser::handleCharacterData(const std::string&) { +} diff --git a/Swiften/Parser/PayloadParsers/MIXDestroyParser.h b/Swiften/Parser/PayloadParsers/MIXDestroyParser.h new file mode 100644 index 0000000..8cfd91e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXDestroyParser.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/MIXDestroy.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParser; + + class SWIFTEN_API MIXDestroyParser : public GenericPayloadParser<MIXDestroy> { + public: + MIXDestroyParser(); + virtual ~MIXDestroyParser() override; + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) override; + + private: + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXJoinParser.cpp b/Swiften/Parser/PayloadParsers/MIXJoinParser.cpp new file mode 100644 index 0000000..6e72f90 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXJoinParser.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXJoinParser.h> + +#include <boost/optional.hpp> + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> + +using namespace Swift; + +MIXJoinParser::MIXJoinParser() : level_(0) { +} + +MIXJoinParser::~MIXJoinParser() { +} + +void MIXJoinParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level_ == 0) { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("channel")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setChannel(*jid); + } + } + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { + if (boost::optional<JID> jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setJID(*jid); + } + } + } + + if (level_ == 1) { + if (element == "subscribe" && ns == "urn:xmpp:mix:0") { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->addSubscription(*attributeValue); + } + } + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser_ = std::make_shared<FormParser>(); + } + } + + if (level_ >= 1 && currentPayloadParser_) { + currentPayloadParser_->handleStartElement(element, ns, attributes); + } + ++level_; +} + +void MIXJoinParser::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()->setForm(std::dynamic_pointer_cast<Form>(currentPayloadParser_->getPayload())); + } + currentPayloadParser_.reset(); + } + } +} + +void MIXJoinParser::handleCharacterData(const std::string& data) { + if (level_ > 1 && currentPayloadParser_) { + currentPayloadParser_->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/MIXJoinParser.h b/Swiften/Parser/PayloadParsers/MIXJoinParser.h new file mode 100644 index 0000000..f371d6f --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXJoinParser.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/MIXJoin.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParser; + + class SWIFTEN_API MIXJoinParser : public GenericPayloadParser<MIXJoin> { + public: + MIXJoinParser(); + virtual ~MIXJoinParser() override; + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) override; + + private: + int level_; + std::shared_ptr<PayloadParser> currentPayloadParser_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXJoinParserFactory.h b/Swiften/Parser/PayloadParsers/MIXJoinParserFactory.h new file mode 100644 index 0000000..8432c61 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXJoinParserFactory.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXJoinParser.h> + +namespace Swift { + class SWIFTEN_API MIXJoinParserFactory : public PayloadParserFactory { + public: + MIXJoinParserFactory() { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "join" && ns == "urn:xmpp:mix:0"; + } + + virtual PayloadParser* createPayloadParser() { + return new MIXJoinParser(); + } + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXLeaveParser.cpp b/Swiften/Parser/PayloadParsers/MIXLeaveParser.cpp new file mode 100644 index 0000000..6330925 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXLeaveParser.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXLeaveParser.h> + +#include <boost/optional.hpp> + +namespace Swift { + +MIXLeaveParser::MIXLeaveParser() : level_(0) { +} + +MIXLeaveParser::~MIXLeaveParser() { +} + +void MIXLeaveParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + if (level_ == 0) { + if (auto attributeValue = attributes.getAttributeValue("channel")) { + if (auto jid = JID::parse(*attributeValue)) { + getPayloadInternal()->setChannel(*jid); + } + } + } + ++level_; +} + +void MIXLeaveParser::handleEndElement(const std::string&, const std::string&) { + --level_; +} + +void MIXLeaveParser::handleCharacterData(const std::string&) { + +} +} diff --git a/Swiften/Parser/PayloadParsers/MIXLeaveParser.h b/Swiften/Parser/PayloadParsers/MIXLeaveParser.h new file mode 100644 index 0000000..b0798b4 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXLeaveParser.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/MIXLeave.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + + class SWIFTEN_API MIXLeaveParser : public GenericPayloadParser<MIXLeave> { + public: + MIXLeaveParser(); + virtual ~MIXLeaveParser() override; + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) override; + + private: + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXParticipantParser.cpp b/Swiften/Parser/PayloadParsers/MIXParticipantParser.cpp new file mode 100644 index 0000000..0ab2b87 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXParticipantParser.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXParticipantParser.h> + +namespace Swift { + +void MIXParticipantParser::handleTree(ParserElement::ref root) { + for (const auto& child : root->getAllChildren()) { + if (child->getName() == "nick" && child->getNamespace() == root->getNamespace()) { + getPayloadInternal()->setNick(child->getText()); + } + else if (child->getName() == "jid" && child->getNamespace() == root->getNamespace()) { + if (boost::optional<JID> jid = JID::parse(child->getText())) { + getPayloadInternal()->setJID(*jid); + } + } + } +} + +} diff --git a/Swiften/Parser/PayloadParsers/MIXParticipantParser.h b/Swiften/Parser/PayloadParsers/MIXParticipantParser.h new file mode 100644 index 0000000..0a3ea57 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXParticipantParser.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/MIXParticipant.h> +#include <Swiften/Parser/GenericPayloadTreeParser.h> + +namespace Swift { + class SWIFTEN_API MIXParticipantParser : public GenericPayloadTreeParser<MIXParticipant> { + public: + MIXParticipantParser() {} + virtual void handleTree(ParserElement::ref root); + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXParticipantParserFactory.h b/Swiften/Parser/PayloadParsers/MIXParticipantParserFactory.h new file mode 100644 index 0000000..cd7c17e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXParticipantParserFactory.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXParticipantParser.h> + +namespace Swift { + class SWIFTEN_API MIXParticipantParserFactory : public PayloadParserFactory { + public: + MIXParticipantParserFactory() { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const { + return element == "participant" && ns == "urn:xmpp:mix:0"; + } + + virtual PayloadParser* createPayloadParser() { + return new MIXParticipantParser(); + } + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MIXPayloadParser.cpp new file mode 100644 index 0000000..51ef584 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXPayloadParser.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXPayloadParser.h> + +namespace Swift { + +void MIXPayloadParser::handleTree(ParserElement::ref root) { + for (const auto& child : root->getAllChildren()) { + if (child->getName() == "nick" && child->getNamespace() == root->getNamespace()) { + getPayloadInternal()->setNick(child->getText()); + } else if (child->getName() == "jid" && child->getNamespace() == root->getNamespace()) { + if (boost::optional<JID> jid = JID::parse(child->getText())) { + getPayloadInternal()->setJID(*jid); + } + } else if (child->getName() == "submission-id" && child->getNamespace() == root->getNamespace()) { + getPayloadInternal()->setSubmissionID(child->getText()); + } + } +} + +} diff --git a/Swiften/Parser/PayloadParsers/MIXPayloadParser.h b/Swiften/Parser/PayloadParsers/MIXPayloadParser.h new file mode 100644 index 0000000..9133e8b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXPayloadParser.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/MIXPayload.h> +#include <Swiften/Parser/GenericPayloadTreeParser.h> + +namespace Swift { + class SWIFTEN_API MIXPayloadParser : public GenericPayloadTreeParser<MIXPayload> { + public: + MIXPayloadParser() {} + virtual void handleTree(ParserElement::ref root) override; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/MIXPayloadParserFactory.h new file mode 100644 index 0000000..8397b78 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXPayloadParserFactory.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXPayloadParser.h> + +namespace Swift { + class SWIFTEN_API MIXPayloadParserFactory : public PayloadParserFactory { + public: + MIXPayloadParserFactory() { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const override { + return element == "mix" && ns == "urn:xmpp:mix:0"; + } + + virtual PayloadParser* createPayloadParser() override { + return new MIXPayloadParser(); + } + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.cpp b/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.cpp new file mode 100644 index 0000000..945e9b2 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h> + +namespace Swift { + +void MIXRegisterNickParser::handleTree(ParserElement::ref root) { + for (const auto& child : root->getAllChildren()) { + if (child->getName() == "nick" && child->getNamespace() == root->getNamespace()) { + getPayloadInternal()->setNick(child->getText()); + } + } +} + +} diff --git a/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h b/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h new file mode 100644 index 0000000..cfb618e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/MIXRegisterNick.h> +#include <Swiften/Parser/GenericPayloadTreeParser.h> + +namespace Swift { + class SWIFTEN_API MIXRegisterNickParser : public GenericPayloadTreeParser<MIXRegisterNick> { + public: + MIXRegisterNickParser() {} + virtual void handleTree(ParserElement::ref root) override; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXRegisterNickParserFactory.h b/Swiften/Parser/PayloadParsers/MIXRegisterNickParserFactory.h new file mode 100644 index 0000000..e03392c --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXRegisterNickParserFactory.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXRegisterNickParser.h> + +namespace Swift { + class SWIFTEN_API MIXRegisterNickParserFactory : public PayloadParserFactory { + public: + MIXRegisterNickParserFactory() { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const override { + return element == "register" && ns == "urn:xmpp:mix:0"; + } + + virtual PayloadParser* createPayloadParser() override { + return new MIXRegisterNickParser(); + } + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXSetNickParser.cpp b/Swiften/Parser/PayloadParsers/MIXSetNickParser.cpp new file mode 100644 index 0000000..34fec70 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXSetNickParser.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXSetNickParser.h> + +namespace Swift { + +void MIXSetNickParser::handleTree(ParserElement::ref root) { + for (const auto& child : root->getAllChildren()) { + if (child->getName() == "nick" && child->getNamespace() == root->getNamespace()) { + getPayloadInternal()->setNick(child->getText()); + } + } +} + +} diff --git a/Swiften/Parser/PayloadParsers/MIXSetNickParser.h b/Swiften/Parser/PayloadParsers/MIXSetNickParser.h new file mode 100644 index 0000000..6d552c8 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXSetNickParser.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/MIXSetNick.h> +#include <Swiften/Parser/GenericPayloadTreeParser.h> + +namespace Swift { + class SWIFTEN_API MIXSetNickParser : public GenericPayloadTreeParser<MIXSetNick> { + public: + MIXSetNickParser() {} + virtual void handleTree(ParserElement::ref root) override; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXSetNickParserFactory.h b/Swiften/Parser/PayloadParsers/MIXSetNickParserFactory.h new file mode 100644 index 0000000..e028873 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXSetNickParserFactory.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Parser/GenericPayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/MIXSetNickParser.h> + +namespace Swift { + class SWIFTEN_API MIXSetNickParserFactory : public PayloadParserFactory { + public: + MIXSetNickParserFactory() { + } + + virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const override { + return element == "setnick" && ns == "urn:xmpp:mix:0"; + } + + virtual PayloadParser* createPayloadParser() override { + return new MIXSetNickParser(); + } + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXUpdateSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/MIXUpdateSubscriptionParser.cpp new file mode 100644 index 0000000..d530e49 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXUpdateSubscriptionParser.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXUpdateSubscriptionParser.h> + +#include <boost/optional.hpp> + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> + +namespace Swift { + +MIXUpdateSubscriptionParser::MIXUpdateSubscriptionParser() : level_(0) { +} + +MIXUpdateSubscriptionParser::~MIXUpdateSubscriptionParser() { +} + +void MIXUpdateSubscriptionParser::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 (level_ == 1) { + if (element == "subscribe" && ns == "urn:xmpp:mix:0") { + if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { + getPayloadInternal()->addSubscription(*attributeValue); + } + } + } + + ++level_; +} + +void MIXUpdateSubscriptionParser::handleEndElement(const std::string&, const std::string&) { + --level_; +} + +void MIXUpdateSubscriptionParser::handleCharacterData(const std::string&) { +} + +} diff --git a/Swiften/Parser/PayloadParsers/MIXUpdateSubscriptionParser.h b/Swiften/Parser/PayloadParsers/MIXUpdateSubscriptionParser.h new file mode 100644 index 0000000..47966ff --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXUpdateSubscriptionParser.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2017-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/MIXUpdateSubscription.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParser; + + class SWIFTEN_API MIXUpdateSubscriptionParser : public GenericPayloadParser<MIXUpdateSubscription> { + public: + MIXUpdateSubscriptionParser(); + virtual ~MIXUpdateSubscriptionParser() override; + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) override; + + private: + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MIXUserPreferenceParser.cpp b/Swiften/Parser/PayloadParsers/MIXUserPreferenceParser.cpp new file mode 100644 index 0000000..f40547d --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXUserPreferenceParser.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MIXUserPreferenceParser.h> + +#include <boost/optional.hpp> + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/FormParser.h> + +namespace Swift { + +MIXUserPreferenceParser::MIXUserPreferenceParser() : level_(0) { +} + +MIXUserPreferenceParser::~MIXUserPreferenceParser() { +} + +void MIXUserPreferenceParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + + + 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 MIXUserPreferenceParser::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(std::dynamic_pointer_cast<Form>(currentPayloadParser_->getPayload())); + } + currentPayloadParser_.reset(); + } + } +} + +void MIXUserPreferenceParser::handleCharacterData(const std::string& data) { + if (level_ > 1 && currentPayloadParser_) { + currentPayloadParser_->handleCharacterData(data); + } +} +} diff --git a/Swiften/Parser/PayloadParsers/MIXUserPreferenceParser.h b/Swiften/Parser/PayloadParsers/MIXUserPreferenceParser.h new file mode 100644 index 0000000..b2a2c10 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MIXUserPreferenceParser.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/MIXUserPreference.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParser; + + class SWIFTEN_API MIXUserPreferenceParser : public GenericPayloadParser<MIXUserPreference> { + public: + MIXUserPreferenceParser(); + virtual ~MIXUserPreferenceParser() override; + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) override; + + private: + int level_; + std::shared_ptr<PayloadParser> currentPayloadParser_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp index 137ead4..bac2a78 100644 --- a/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.cpp @@ -1,23 +1,22 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h> #include <boost/lexical_cast.hpp> -#include <Swiften/Base/foreach.h> #include <Swiften/Elements/MUCOccupant.h> namespace Swift { void MUCAdminPayloadParser::handleTree(ParserElement::ref root) { - foreach (ParserElement::ref itemElement, root->getChildren("item", "http://jabber.org/protocol/muc#admin")) { - 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 dfa26da..de46690 100644 --- a/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h @@ -1,20 +1,21 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <boost/optional.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Elements/MUCAdminPayload.h> #include <Swiften/Parser/GenericPayloadTreeParser.h> #include <Swiften/Parser/PayloadParsers/MUCItemParser.h> namespace Swift { - class 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 a8d29d0..46bc9c5 100644 --- a/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.cpp @@ -1,22 +1,20 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 714651f..e79d9a6 100644 --- a/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h @@ -1,19 +1,20 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <boost/optional.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Elements/MUCDestroyPayload.h> #include <Swiften/Parser/GenericPayloadTreeParser.h> namespace Swift { - class 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 c1cf33d..14d6d16 100644 --- a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp @@ -1,23 +1,24 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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")); - invite->setIsImpromptu(root->getChild("impromptu", "http://swift.im/impromptu") ? true : false); + 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 2cd3535..7b76166 100644 --- a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h @@ -1,17 +1,18 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/MUCInvitationPayload.h> #include <Swiften/Parser/GenericPayloadTreeParser.h> namespace Swift { - class 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 2eb9997..ce74671 100644 --- a/Swiften/Parser/PayloadParsers/MUCItemParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCItemParser.cpp @@ -1,80 +1,79 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 a0ea060..6f80d54 100644 --- a/Swiften/Parser/PayloadParsers/MUCItemParser.h +++ b/Swiften/Parser/PayloadParsers/MUCItemParser.h @@ -1,20 +1,21 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/MUCItem.h> #include <Swiften/Parser/GenericPayloadTreeParser.h> namespace Swift { - class 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 d7ae789..7e7c0d4 100644 --- a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.cpp @@ -1,12 +1,13 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 2761981..4c1f048 100644 --- a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h @@ -1,31 +1,32 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <boost/optional.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Elements/MUCOwnerPayload.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class 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 918c72c..d6399e7 100644 --- a/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h @@ -1,32 +1,33 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class 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 d206010..b1bf78e 100644 --- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.cpp @@ -1,58 +1,57 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h> #include <boost/lexical_cast.hpp> -#include <Swiften/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 66e63a8..3d6dbab 100644 --- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h @@ -1,24 +1,25 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <boost/optional.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Elements/MUCUserPayload.h> #include <Swiften/Parser/GenericPayloadTreeParser.h> #include <Swiften/Parser/PayloadParsers/MUCItemParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class 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 2c1c915..4a0380d 100644 --- a/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h @@ -1,29 +1,30 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/GenericPayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/MUCUserPayloadParser.h> namespace Swift { - class 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 b647b4d..331355a 100644 --- a/Swiften/Parser/PayloadParsers/NicknameParser.cpp +++ b/Swiften/Parser/PayloadParsers/NicknameParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/NicknameParser.h> @@ -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 a89f835..1bdd600 100644 --- a/Swiften/Parser/PayloadParsers/NicknameParser.h +++ b/Swiften/Parser/PayloadParsers/NicknameParser.h @@ -1,25 +1,26 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/Nickname.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 b440444..88eef0d 100644 --- a/Swiften/Parser/PayloadParsers/PriorityParser.cpp +++ b/Swiften/Parser/PayloadParsers/PriorityParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/PriorityParser.h> @@ -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 8d6bf86..e6bf059 100644 --- a/Swiften/Parser/PayloadParsers/PriorityParser.h +++ b/Swiften/Parser/PayloadParsers/PriorityParser.h @@ -1,25 +1,26 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/Priority.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 bf16394..e40249a 100644 --- a/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp +++ b/Swiften/Parser/PayloadParsers/PrivateStorageParser.cpp @@ -1,12 +1,13 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 d350593..c1d695c 100644 --- a/Swiften/Parser/PayloadParsers/PrivateStorageParser.h +++ b/Swiften/Parser/PayloadParsers/PrivateStorageParser.h @@ -1,31 +1,32 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <boost/optional.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Elements/PrivateStorage.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class 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 5b93aef..550177c 100644 --- a/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h +++ b/Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h @@ -1,32 +1,33 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/PrivateStorageParser.h> namespace Swift { - class PayloadParserFactoryCollection; + class PayloadParserFactoryCollection; - class 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 05fa119..764b3a7 100644 --- a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp @@ -1,64 +1,58 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 43c619d..383ceae 100644 --- a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 b75e339..ffa5d2d 100644 --- a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp @@ -1,18 +1,15 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 646e7a8..48e3825 100644 --- a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 773c1c7..e0a5847 100644 --- a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp @@ -1,61 +1,57 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 8300140..e53d477 100644 --- a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 47f35c9..4f03e29 100644 --- a/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp @@ -1,59 +1,52 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 865b8ec..626419c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubCreateParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubCreateParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 7a370cd..a6d751c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp @@ -1,64 +1,58 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 7bd8d66..08f6b43 100644 --- a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 9752cd2..99a306d 100644 --- a/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013 Isode Limited. + * All rights reserved. * See the COPYING file for more information. */ @@ -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 eb7dcfe..273da82 100644 --- a/Swiften/Parser/PayloadParsers/PubSubErrorParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParser.h @@ -1,35 +1,31 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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 SWIFTEN_API PubSubErrorParser : public GenericPayloadParser<PubSubError> { - public: - PubSubErrorParser(); - virtual ~PubSubErrorParser(); + class SWIFTEN_API PubSubErrorParser : public GenericPayloadParser<PubSubError> { + public: + PubSubErrorParser(); + virtual ~PubSubErrorParser() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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.cpp b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.cpp index 10dfd63..0e94c14 100644 --- a/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013 Isode Limited. + * All rights reserved. * See the COPYING file for more information. */ diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h index e2386da..c7a3614 100644 --- a/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h @@ -1,29 +1,30 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2015 Isode Limited. + * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/PubSubErrorParser.h> namespace Swift { - class 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 f187be8..8ca1d7d 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp @@ -1,59 +1,54 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 000edf2..f4d6327 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 08b9c65..4452601 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 aad97d2..ffa1deb 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 f905299..9bde91b 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp @@ -1,65 +1,61 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 7189460..6b68d86 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 03c7423..1569b90 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 36f8e0b..54a1913 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 287ac35..4e72d85 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp @@ -1,59 +1,52 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 9015100..6a0a7ce 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 8903545..ba8f714 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp @@ -1,19 +1,17 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 6c16043..e9a986d 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 fa155e9..ae4f668 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp @@ -1,20 +1,19 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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/PayloadParsers/PubSubEventRetractParser.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParsers/PubSubEventItemParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h> using namespace Swift; @@ -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 60ecb25..067a9f7 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 c4406a9..d92730a 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp @@ -1,24 +1,23 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 1042e75..02cf01f 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 14d1e96..30a4d6c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp @@ -1,59 +1,52 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 740bff3..1c9e623 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 f053117..46f1922 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp @@ -1,59 +1,52 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 33880ed..be7593e 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 da3dea3..226bb33 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp @@ -1,59 +1,53 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 115bb7a..83a8e66 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 3367202..45c16f6 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp @@ -1,76 +1,70 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 1469920..6f2eeeb 100644 --- a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 2e7d01a..ff5bfc7 100644 --- a/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp @@ -1,19 +1,17 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 4f02211..cbbd3a5 100644 --- a/Swiften/Parser/PayloadParsers/PubSubItemParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubItemParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 615f05d..2edfddb 100644 --- a/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp @@ -1,18 +1,18 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 895863f..d792e1b 100644 --- a/Swiften/Parser/PayloadParsers/PubSubItemsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubItemsParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 3bf4998..2098d8f 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp @@ -1,73 +1,69 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 3c8754b..ee11f70 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 a648862..d868ef6 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp @@ -1,66 +1,61 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 ae54b5f..7bb93f1 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 b824279..2f21b7a 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 755d58c..20df72f 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 43d262f..7fa6506 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp @@ -1,65 +1,61 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 f9a8553..f11f357 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 4c284bf..e453230 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp @@ -1,61 +1,55 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 5207bc5..2f80b85 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 a2b7a9d..c30e404 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 c171ab8..4484329 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 5262997..e26f291 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp @@ -1,24 +1,23 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 25fee8a..cfacc97 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 ebea0a7..7c637cf 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp @@ -1,59 +1,53 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 0b85d3d..8d233b6 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 bc54e86..6d0b2a7 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp @@ -1,59 +1,52 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 9a97d74..ebb6436 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 7c91526..92b81f3 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp @@ -1,66 +1,60 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 8ef8d5b..d68d910 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 ebe90d8..6d5e43c 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 a5459a9..ca868e6 100644 --- a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 5b1462b..eef6e5e 100644 --- a/Swiften/Parser/PayloadParsers/PubSubParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubParser.cpp @@ -1,31 +1,29 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 0618361..5cc50e1 100644 --- a/Swiften/Parser/PayloadParsers/PubSubParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubParser.h @@ -1,38 +1,37 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 ca358c3..8c8db3d 100644 --- a/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 3d64e9d..e3b05ff 100644 --- a/Swiften/Parser/PayloadParsers/PubSubPublishParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubPublishParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 f4a42d0..d5d5c0a 100644 --- a/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp @@ -1,18 +1,15 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 2b5e633..aa9bbcc 100644 --- a/Swiften/Parser/PayloadParsers/PubSubRetractParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubRetractParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 caed681..88b7758 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp @@ -1,57 +1,48 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 c9ac1ca..9deae2d 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 093c2c4..1de39e7 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp @@ -1,64 +1,57 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 f0ad09d..ccd8ac8 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 be06ec8..0f27cb2 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp @@ -1,19 +1,18 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 49290c2..3d9be23 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 3ac3ca0..8b0fbef 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp @@ -1,18 +1,17 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 b08db93..c7169ae 100644 --- a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h @@ -1,34 +1,33 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 53b4fae..ea3b46d 100644 --- a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp +++ b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp @@ -1,67 +1,62 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 a9e5ed0..21d5599 100644 --- a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h +++ b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h @@ -1,34 +1,32 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 0837ae8..97abce3 100644 --- a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp @@ -1,10 +1,11 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 2e16d00..1f20105 100644 --- a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once @@ -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 d777caa..f7b7601 100644 --- a/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h +++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h @@ -1,26 +1,28 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 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/ReferencePayloadParser.cpp b/Swiften/Parser/PayloadParsers/ReferencePayloadParser.cpp new file mode 100644 index 0000000..a337a29 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ReferencePayloadParser.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/ReferencePayloadParser.h> + +#include <cassert> +#include <iostream> + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> + +namespace Swift { + +ReferencePayloadParser::ReferencePayloadParser(PayloadParserFactoryCollection* factories) : factories_(factories) { +} + +ReferencePayload::Type ReferencePayloadParser::getTypeFromString(const std::string& typeString) const { + if (typeString == "data") { + return ReferencePayload::Type::Data; + } + else if (typeString == "mention") { + return ReferencePayload::Type::Mention; + } + else if (typeString == "pubsub") { + return ReferencePayload::Type::PubSub; + } + else { + return ReferencePayload::Type::Unknown; + } +} + +void ReferencePayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level_ == topLevel_) { + if (element == "reference") { + getPayloadInternal()->setType(getTypeFromString(attributes.getAttribute("type"))); + getPayloadInternal()->setUri(attributes.getAttributeValue("uri")); + getPayloadInternal()->setBegin(attributes.getAttributeValue("begin")); + getPayloadInternal()->setEnd(attributes.getAttributeValue("end")); + getPayloadInternal()->setAnchor(attributes.getAttributeValue("anchor")); + } + } + else if (level_ == payloadLevel_) { + PayloadParserFactory* payloadParserFactory = factories_->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser_.reset(payloadParserFactory->createPayloadParser()); + } + } + + if (level_ >= payloadLevel_ && currentPayloadParser_) { + currentPayloadParser_->handleStartElement(element, ns, attributes); + } + + ++level_; +} + +void ReferencePayloadParser::handleEndElement(const std::string& element, const std::string& ns) { + --level_; + if (currentPayloadParser_) { + if (level_ >= payloadLevel_) { + currentPayloadParser_->handleEndElement(element, ns); + } + + if (level_ == payloadLevel_) { + getPayloadInternal()->addPayload(currentPayloadParser_->getPayload()); + currentPayloadParser_.reset(); + } + } +} + +void ReferencePayloadParser::handleCharacterData(const std::string& data) { + if (level_ > payloadLevel_ && currentPayloadParser_) { + currentPayloadParser_->handleCharacterData(data); + } +} + +} diff --git a/Swiften/Parser/PayloadParsers/ReferencePayloadParser.h b/Swiften/Parser/PayloadParsers/ReferencePayloadParser.h new file mode 100644 index 0000000..3afd181 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ReferencePayloadParser.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/ReferencePayload.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + + class PayloadParserFactoryCollection; + + class SWIFTEN_API ReferencePayloadParser : public GenericPayloadParser<ReferencePayload> { + public: + + ReferencePayloadParser(PayloadParserFactoryCollection* factories); + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string& ns); + virtual void handleCharacterData(const std::string& data); + + private: + + ReferencePayload::Type getTypeFromString(const std::string& typeString) const; + int level_ = 0; + const int topLevel_ = 0; + const int payloadLevel_ = 1; + PayloadParserFactoryCollection* factories_; + std::shared_ptr<PayloadParser> currentPayloadParser_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/ReplaceParser.cpp b/Swiften/Parser/PayloadParsers/ReplaceParser.cpp index 728ed63..66e219a 100644 --- a/Swiften/Parser/PayloadParsers/ReplaceParser.cpp +++ b/Swiften/Parser/PayloadParsers/ReplaceParser.cpp @@ -5,9 +5,9 @@ */ /* - * Copyright (c) 2012 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2012 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ @@ -16,22 +16,22 @@ namespace Swift { - ReplaceParser::ReplaceParser() : level_(0) { - } + 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::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::handleEndElement(const std::string&, const std::string&) { + --level_; + } - void ReplaceParser::handleCharacterData(const std::string&) { - } + void ReplaceParser::handleCharacterData(const std::string&) { + } } diff --git a/Swiften/Parser/PayloadParsers/ReplaceParser.h b/Swiften/Parser/PayloadParsers/ReplaceParser.h index 4d73459..21d7322 100644 --- a/Swiften/Parser/PayloadParsers/ReplaceParser.h +++ b/Swiften/Parser/PayloadParsers/ReplaceParser.h @@ -4,20 +4,27 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/Replace.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 81378df..2965d66 100644 --- a/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp +++ b/Swiften/Parser/PayloadParsers/ResourceBindParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/ResourceBindParser.h> @@ -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 e604751..3619c0b 100644 --- a/Swiften/Parser/PayloadParsers/ResourceBindParser.h +++ b/Swiften/Parser/PayloadParsers/ResourceBindParser.h @@ -1,27 +1,28 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/ResourceBind.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 new file mode 100644 index 0000000..80d89d7 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/ResultSetParser.h> + +#include <boost/lexical_cast.hpp> +#include <boost/optional.hpp> + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> + +using namespace Swift; + +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_; +} + +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_); + } + } +} + +void ResultSetParser::handleCharacterData(const std::string& data) { + currentText_ += data; +} diff --git a/Swiften/Parser/PayloadParsers/ResultSetParser.h b/Swiften/Parser/PayloadParsers/ResultSetParser.h new file mode 100644 index 0000000..edf6f2f --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ResultSetParser.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2014-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/ResultSet.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class SWIFTEN_API ResultSetParser : public GenericPayloadParser<ResultSet> { + public: + ResultSetParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) override; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + 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 5652b94..1fd1113 100644 --- a/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h +++ b/Swiften/Parser/PayloadParsers/RosterItemExchangeParser.h @@ -4,31 +4,36 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/RosterItemExchangePayload.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SerializingParser; - - class 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 53c433a..90fb518 100644 --- a/Swiften/Parser/PayloadParsers/RosterParser.cpp +++ b/Swiften/Parser/PayloadParsers/RosterParser.cpp @@ -1,104 +1,106 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 3b62f0b..2989f46 100644 --- a/Swiften/Parser/PayloadParsers/RosterParser.h +++ b/Swiften/Parser/PayloadParsers/RosterParser.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once @@ -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 6e33f16..7a5a1fd 100644 --- a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp +++ b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.cpp @@ -4,9 +4,16 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ -#include "S5BProxyRequestParser.h" +/* + * Copyright (c) 2015-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h> #include <boost/lexical_cast.hpp> +#include <boost/numeric/conversion/cast.hpp> #include <boost/optional.hpp> namespace Swift { @@ -18,47 +25,47 @@ 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")) { - HostAddress address = 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(""); + unsigned short port = 0; + 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 (address.isValid() && port != -1 && jid.isValid()) { - S5BProxyRequest::StreamHost streamHost; - streamHost.addressPort = HostAddressPort(address, 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::numeric_cast<unsigned short>(boost::lexical_cast<int>(attributes.getAttributeValue("port").get())); + } catch (...) { + } + if (!host.empty() && port != 0 && 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 0bf1a26..1d5fd64 100644 --- a/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h +++ b/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h @@ -4,27 +4,34 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once #include <string> +#include <Swiften/Base/API.h> #include <Swiften/Elements/S5BProxyRequest.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { -class S5BProxyRequestParser : public GenericPayloadParser<S5BProxyRequest> { +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 f4de503..0d79204 100644 --- a/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/SearchPayloadParser.cpp @@ -1,113 +1,115 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 d456eb8..aa0cf4a 100644 --- a/Swiften/Parser/PayloadParsers/SearchPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/SearchPayloadParser.h @@ -1,39 +1,40 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <boost/optional.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Elements/SearchPayload.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class FormParserFactory; - class FormParser; + class FormParserFactory; + class FormParser; - class 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 4177baa..6e2319f 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp +++ b/Swiften/Parser/PayloadParsers/SecurityLabelParser.cpp @@ -1,69 +1,72 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 5357028..cc444a4 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelParser.h +++ b/Swiften/Parser/PayloadParsers/SecurityLabelParser.h @@ -1,34 +1,35 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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/SecurityLabel.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SerializingParser; + class SerializingParser; - class 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 47c4a0c..7e6d4fd 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h +++ b/Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h @@ -1,17 +1,18 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/GenericPayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/SecurityLabelParser.h> namespace Swift { - class 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 922a00e..58b0af0 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp +++ b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.cpp @@ -1,74 +1,76 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 && currentItem_) { + 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 d50faa4..edfa86b 100644 --- a/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h +++ b/Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParser.h @@ -1,37 +1,38 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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/SecurityLabelsCatalog.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SecurityLabelParserFactory; - class SecurityLabelParser; + class SecurityLabelParserFactory; + class SecurityLabelParser; - class 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 b1c3e18..56b62c8 100644 --- a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp +++ b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/SoftwareVersionParser.h> @@ -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 01d5ed8..29f700c 100644 --- a/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h +++ b/Swiften/Parser/PayloadParsers/SoftwareVersionParser.h @@ -1,29 +1,30 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/SoftwareVersion.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 ce78ae7..e0013af 100644 --- a/Swiften/Parser/PayloadParsers/StartSessionParser.h +++ b/Swiften/Parser/PayloadParsers/StartSessionParser.h @@ -1,21 +1,22 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/StartSession.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 1394d46..128a675 100644 --- a/Swiften/Parser/PayloadParsers/StatusParser.cpp +++ b/Swiften/Parser/PayloadParsers/StatusParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/StatusParser.h> @@ -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 9d7493e..cebf0cd 100644 --- a/Swiften/Parser/PayloadParsers/StatusParser.h +++ b/Swiften/Parser/PayloadParsers/StatusParser.h @@ -1,25 +1,26 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/Status.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 f5814ec..761a411 100644 --- a/Swiften/Parser/PayloadParsers/StatusShowParser.cpp +++ b/Swiften/Parser/PayloadParsers/StatusShowParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/StatusShowParser.h> @@ -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 6e72c13..8cbb365 100644 --- a/Swiften/Parser/PayloadParsers/StatusShowParser.h +++ b/Swiften/Parser/PayloadParsers/StatusShowParser.h @@ -1,25 +1,26 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/StatusShow.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 05e24e7..9628ea8 100644 --- a/Swiften/Parser/PayloadParsers/StorageParser.cpp +++ b/Swiften/Parser/PayloadParsers/StorageParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/StorageParser.h> @@ -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 76dce90..92417c2 100644 --- a/Swiften/Parser/PayloadParsers/StorageParser.h +++ b/Swiften/Parser/PayloadParsers/StorageParser.h @@ -1,34 +1,35 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <boost/optional.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Elements/Storage.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 cc69348..ab5dbbe 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp @@ -4,10 +4,16 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ -#include "StreamInitiationFileInfoParser.h" +/* + * 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> @@ -15,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 6d3591d..a1e386c 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h +++ b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.h @@ -4,25 +4,32 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/StreamInitiationFileInfo.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { -class 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; +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; }; } diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp index ff0a061..ad66b3f 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp +++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/StreamInitiationParser.h> @@ -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 f7350cd..42de8ba 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.h +++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.h @@ -1,42 +1,43 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <boost/optional.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Elements/StreamInitiation.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class FormParserFactory; - class FormParser; + class FormParserFactory; + class FormParser; - class 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 276a05a..19a5488 100644 --- a/Swiften/Parser/PayloadParsers/SubjectParser.cpp +++ b/Swiften/Parser/PayloadParsers/SubjectParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/SubjectParser.h> @@ -12,18 +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) { - text_ += data; + if (level_ == 1) { + text_ += data; + } } } diff --git a/Swiften/Parser/PayloadParsers/SubjectParser.h b/Swiften/Parser/PayloadParsers/SubjectParser.h index 1d7d2ce..a400283 100644 --- a/Swiften/Parser/PayloadParsers/SubjectParser.h +++ b/Swiften/Parser/PayloadParsers/SubjectParser.h @@ -1,25 +1,26 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/Subject.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class 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 new file mode 100644 index 0000000..f416d32 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ThreadParser.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/ThreadParser.h> + +#include <boost/optional.hpp> + +namespace Swift { + +ThreadParser::ThreadParser() : level_(0) { +} + +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("")); + } +} + +void ThreadParser::handleEndElement(const std::string&, const std::string&) { + --level_; + if (level_ == 0) { + getPayloadInternal()->setText(text_); + } +} + +void ThreadParser::handleCharacterData(const std::string& data) { + if (level_ == 1) { + text_ += data; + } +} + +} diff --git a/Swiften/Parser/PayloadParsers/ThreadParser.h b/Swiften/Parser/PayloadParsers/ThreadParser.h new file mode 100644 index 0000000..371c535 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ThreadParser.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/Thread.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + 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); + + 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 fe91088..002da16 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/BodyParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -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 new file mode 100644 index 0000000..b5b9995 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/CarbonsParserTest.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2015-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/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/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); + + 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/ClientStateParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ClientStateParserTest.cpp new file mode 100644 index 0000000..ca89040 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/ClientStateParserTest.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/ClientState.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(ClientStateParserTest, testParse_Active) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<active xmlns='urn:xmpp:csi:0'/>" + )); + + ClientState::ref payload = parser.getPayload<ClientState>(); + ASSERT_EQ(ClientState::ClientStateType::Active, payload->getClientState()); +} + +TEST(ClientStateParserTest, testParse_Inactive) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<inactive xmlns='urn:xmpp:csi:0'/>" + )); + + ClientState::ref payload = parser.getPayload<ClientState>(); + ASSERT_EQ(ClientState::ClientStateType::Inactive, payload->getClientState()); +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp index 3e4971b..fa8d014 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/CommandParserTest.cpp @@ -1,86 +1,86 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-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/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 d01abd1..6e866fc 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -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 005fc09..5402614 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp @@ -1,57 +1,57 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-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/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 bc8f1bc..610c4f3 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp @@ -1,184 +1,231 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-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/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); - 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() { - 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 new file mode 100644 index 0000000..a807d4e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2014-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Base/DateTime.h> +#include <Swiften/Elements/Delay.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Parser/PayloadParsers/ForwardedParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +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>")); + + 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 90d7b6b..782cb32 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/IBBParserTest.cpp @@ -1,40 +1,39 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 new file mode 100644 index 0000000..6d08812 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <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> + +using namespace Swift; + +class InBandRegistrationPayloadParserTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(InBandRegistrationPayloadParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Form); + CPPUNIT_TEST_SUITE_END(); + + public: + InBandRegistrationPayloadParserTest() {} + + void testParse() { + PayloadsParserTester parser; + + 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()); + } + + 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>")); + + 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()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(InBandRegistrationPayloadParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp index 8c8601a..c502c8a 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp @@ -4,706 +4,614 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015-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/JinglePayload.h> +#include <Swiften/Base/DateTime.h> +#include <Swiften/Elements/JingleFileTransferDescription.h> +#include <Swiften/Elements/JingleFileTransferHash.h> #include <Swiften/Elements/JingleIBBTransportPayload.h> +#include <Swiften/Elements/JinglePayload.h> #include <Swiften/Elements/JingleS5BTransportPayload.h> -#include <Swiften/Elements/JingleFileTransferDescription.h> #include <Swiften/Elements/StreamInitiationFileInfo.h> -#include <Swiften/Elements/JingleFileTransferReceived.h> -#include <Swiften/Elements/JingleFileTransferHash.h> -#include <Swiften/Base/DateTime.h> - -#include <Swiften/Base/Log.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/StringCodecs/Base64.h> 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_Xep0234_Example11); - CPPUNIT_TEST(testParse_Xep0234_Example12); - - 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:3'>\n" - " <offer>\n" - " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n" - " date='1969-07-21T02:56:15Z'\n" - " hash='552da749930852c69ae5d2141d3766b1'\n" - " name='test.txt'\n" - " size='1022'>\n" - " <desc>This is a test. If this were a real file...</desc>\n" - " <range/>\n" - " </file>\n" - " </offer>\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>(); - - - std::vector<StreamInitiationFileInfo> offers = description->getOffers(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), offers.size()); - CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), offers[0].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("552da749930852c69ae5d2141d3766b1"), offers[0].getHash()); - CPPUNIT_ASSERT(1022 == offers[0].getSize()); - CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), offers[0].getDescription()); - CPPUNIT_ASSERT_EQUAL(true, offers[0].getSupportsRangeRequests()); - CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == offers[0].getDate()); - CPPUNIT_ASSERT_EQUAL(std::string("md5"), offers[0].getAlgo()); - } - - // 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:3'>\n" - " <offer>\n" - " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n" - " name='test.txt'\n" - " size='1022'\n" - " hash='552da749930852c69ae5d2141d3766b1'\n" - " date='1969-07-21T02:56:15Z'>\n" - " <desc>This is a test. If this were a real file...</desc>\n" - " <range/>\n" - " </file>\n" - " </offer>\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>(); - - - std::vector<StreamInitiationFileInfo> offers = description->getOffers(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), offers.size()); - CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), offers[0].getName()); - CPPUNIT_ASSERT_EQUAL(std::string("552da749930852c69ae5d2141d3766b1"), offers[0].getHash()); - CPPUNIT_ASSERT(1022 == offers[0].getSize()); - CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), offers[0].getDescription()); - CPPUNIT_ASSERT_EQUAL(true, offers[0].getSupportsRangeRequests()); - CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == offers[0].getDate()); - CPPUNIT_ASSERT_EQUAL(std::string("md5"), offers[0].getAlgo()); - } - - // 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:3'>\n" - " <file>\n" - " <hashes xmlns='urn:xmpp:hashes:0'>\n" - " <hash algo='sha-1'>552da749930852c69ae5d2141d3766b1</hash>\n" - " </hashes>\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("552da749930852c69ae5d2141d3766b1"), hash->getHashes().find("sha-1")->second); - - } - - // 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:3'>\n" - " <request>\n" - " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n" - " hash='552da749930852c69ae5d2141d3766b1'>\n" - " <range offset='270336'/>\n" - " </file>\n" - " </request>\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); - - StreamInitiationFileInfo file = content->getDescription<JingleFileTransferDescription>()->getRequests()[0]; - CPPUNIT_ASSERT_EQUAL(std::string("552da749930852c69ae5d2141d3766b1"), file.getHash()); - CPPUNIT_ASSERT_EQUAL(static_cast<unsigned long long>(270336), file.getRangeOffset()); - CPPUNIT_ASSERT_EQUAL(true, file.getSupportsRangeRequests()); - } - - // http://xmpp.org/extensions/xep-0234.html#example-11 - void testParse_Xep0234_Example11() { - PayloadsParserTester parser; - CPPUNIT_ASSERT(parser.parse( - "<jingle xmlns='urn:xmpp:jingle:1'\n" - " action='session-initiate'\n" - " initiator='romeo@montague.lit/orchard'\n" - " sid='h2va419i'>\n" - " <content creator='initiator' name='a-file-offer'>\n" - " <description xmlns='urn:xmpp:jingle:apps:file-transfer:3'>\n" - " <offer>\n" - " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n" - " date='2011-06-01T15:58:15Z'\n" - " hash='a749930852c69ae5d2141d3766b1552d'\n" - " name='somefile.txt'\n" - " size='1234'/>\n" - " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n" - " date='2011-06-01T15:58:15Z'\n" - " hash='930852c69ae5d2141d3766b1552da749'\n" - " name='anotherfile.txt'\n" - " size='2345'/>\n" - " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n" - " date='2011-06-01T15:58:15Z'\n" - " hash='52c69ae5d2141d3766b1552da7499308'\n" - " name='yetanotherfile.txt'\n" - " size='3456'/>\n" - " </offer>\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("h2va419i"), jingle->getSessionID()); - - JingleContentPayload::ref content = jingle->getPayload<JingleContentPayload>(); - CPPUNIT_ASSERT(content); - CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, content->getCreator()); - CPPUNIT_ASSERT_EQUAL(std::string("a-file-offer"), content->getName()); - - std::vector<StreamInitiationFileInfo> offers = content->getDescription<JingleFileTransferDescription>()->getOffers(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), offers.size()); - } - - // http://xmpp.org/extensions/xep-0234.html#example-12 - void testParse_Xep0234_Example12() { - 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" - " <received xmlns='urn:xmpp:jingle:apps:file-transfer:3'>\n" - " <file xmlns='http://jabber.org/protocol/si/profile/file-transfer'\n" - " hash='a749930852c69ae5d2141d3766b1552d'/>\n" - " </received>\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()); - - boost::shared_ptr<JingleFileTransferReceived> received = jingle->getPayload<JingleFileTransferReceived>(); - CPPUNIT_ASSERT(received); - CPPUNIT_ASSERT_EQUAL(std::string("a749930852c69ae5d2141d3766b1552d"), received->getFileInfo().getHash()); - } - - // 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" - " 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(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 new file mode 100644 index 0000000..6a8e2ed --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014-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/MAMFin.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +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' />")); + + 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 new file mode 100644 index 0000000..8750c2e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2014-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Base/DateTime.h> +#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +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>")); + + + 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()); + } + + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(MAMQueryParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp new file mode 100644 index 0000000..15912b1 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Base/DateTime.h> +#include <Swiften/Elements/Delay.h> +#include <Swiften/Elements/Forwarded.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Parser/PayloadParsers/MAMResultParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +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>")); + + 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/MIXCreateParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXCreateParserTest.cpp new file mode 100644 index 0000000..f48bbc7 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXCreateParserTest.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/MIXCreate.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXCreateParserTest, XEP0369_Example68) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<create xmlns=\"urn:xmpp:mix:0\"/>" + )); + + auto payload = parser.getPayload<MIXCreate>(); + ASSERT_TRUE(payload); + + ASSERT_FALSE(payload->getData()); + ASSERT_FALSE(payload->getChannel()); +} + +TEST(MIXCreateParserTest, XEP0369_Example66) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<create channel=\"coven\" xmlns=\"urn:xmpp:mix:0\"/>" + )); + + auto payload = parser.getPayload<MIXCreate>(); + ASSERT_TRUE(payload); + + ASSERT_FALSE(payload->getData()); + + ASSERT_TRUE(payload->getChannel()); + ASSERT_EQ(std::string("coven"), *payload->getChannel()); +} + +TEST(MIXCreateParserTest, XEP0369_Example67) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<create channel=\"coven\" xmlns=\"urn:xmpp:mix:0\">" + "<x xmlns=\"jabber:x:data\" type=\"result\">" + "<field var=\"FORM_TYPE\" type=\"hidden\">" + "<value>urn:xmpp:mix:0</value>" + "</field>" + "<field var=\"Owner\">" + "<value>hecate@shakespeare.lit</value>" + "<value>greymalkin@shakespeare.lit</value>" + "</field>" + "<field var=\"Messages Node Subscription\">" + "<value>allowed</value>" + "</field>" + "<field var=\"JID Visibility\">" + "<value>jid-mandatory-visible</value>" + "</field>" + "<field var=\"No Private Messages\">" + "<value>true</value>" + "</field>" + "</x>" + "</create>" + )); + + auto payload = parser.getPayload<MIXCreate>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getData()); + ASSERT_EQ(Form::Type::ResultType, payload->getData()->getType()); + std::shared_ptr<FormField> fieldType = payload->getData()->getField("FORM_TYPE"); + ASSERT_TRUE(fieldType); + + std::shared_ptr<FormField> fieldJIDVisibility = payload->getData()->getField("JID Visibility"); + ASSERT_TRUE(fieldJIDVisibility); + ASSERT_EQ(std::string("jid-mandatory-visible"), fieldJIDVisibility->getTextSingleValue()); + + std::shared_ptr<FormField> fieldprivateMessages = payload->getData()->getField("No Private Messages"); + ASSERT_TRUE(fieldprivateMessages); + ASSERT_EQ(std::string("true"), fieldprivateMessages->getTextSingleValue()); + + std::shared_ptr<FormField> nodeSubs = payload->getData()->getField("Messages Node Subscription"); + ASSERT_TRUE(nodeSubs); + ASSERT_EQ(std::string("allowed"), nodeSubs->getTextSingleValue()); + + ASSERT_TRUE(payload->getChannel()); + ASSERT_EQ(std::string("coven"), *payload->getChannel()); +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParser.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParser.cpp new file mode 100644 index 0000000..80eb144 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParser.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/MIXDestroy.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXDestroyParserTest, XEP0369_Example70) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<destroy channel=\"coven\" xmlns=\"urn:xmpp:mix:0\"/>" + )); + + auto payload = parser.getPayload<MIXDestroy>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getChannel()); + ASSERT_EQ(std::string("coven"), *payload->getChannel()); +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParserTest.cpp new file mode 100644 index 0000000..5fa321e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXDestroyParserTest.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/MIXDestroy.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXDestroyParserTest, XEP0369_Example70) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<destroy channel=\"coven\" xmlns=\"urn:xmpp:mix:0\"/>" + )); + + auto payload = parser.getPayload<MIXDestroy>(); + ASSERT_TRUE(payload); + + ASSERT_EQ(std::string("coven"), payload->getChannel()); +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXJoinParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXJoinParserTest.cpp new file mode 100644 index 0000000..0ad4589 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXJoinParserTest.cpp @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/MIXJoin.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXJoinParserTest, XEP0369_Example22) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<join xmlns=\"urn:xmpp:mix:0\" channel=\"coven@mix.shakespeare.example\">" + "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>" + "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>" + "<subscribe node=\"urn:xmpp:mix:nodes:participants\"/>" + "<subscribe node=\"urn:xmpp:mix:nodes:config\"/>" + "</join>" + )); + + MIXJoin::ref payload = parser.getPayload<MIXJoin>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getChannel()); + ASSERT_EQ(JID("coven@mix.shakespeare.example"), *payload->getChannel()); + ASSERT_FALSE(payload->getJID()); + ASSERT_FALSE(payload->getForm()); + + ASSERT_EQ(static_cast<size_t>(4), payload->getSubscriptions().size()); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:messages"))); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:presence"))); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:participants"))); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:config"))); +} + +TEST(MIXJoinParserTest, XEP0369_Example23) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<join xmlns=\"urn:xmpp:mix:0\">" + "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>" + "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>" + "<subscribe node=\"urn:xmpp:mix:nodes:participants\"/>" + "<subscribe node=\"urn:xmpp:mix:nodes:config\"/>" + "</join>" + )); + + MIXJoin::ref payload = parser.getPayload<MIXJoin>(); + ASSERT_TRUE(payload); + + ASSERT_FALSE(payload->getChannel()); + ASSERT_FALSE(payload->getJID()); + ASSERT_FALSE(payload->getForm()); + + ASSERT_EQ(static_cast<size_t>(4), payload->getSubscriptions().size()); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:messages"))); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:presence"))); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:participants"))); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:config"))); +} + +TEST(MIXJoinParserTest, XEP0369_Example24) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<join xmlns=\"urn:xmpp:mix:0\" jid=\"123456#coven@mix.shakespeare.example\">" + "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>" + "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>" + "<subscribe node=\"urn:xmpp:mix:nodes:participants\"/>" + "<subscribe node=\"urn:xmpp:mix:nodes:config\"/>" + "</join>" + )); + + MIXJoin::ref payload = parser.getPayload<MIXJoin>(); + ASSERT_TRUE(payload); + + ASSERT_FALSE(payload->getChannel()); + ASSERT_TRUE(payload->getJID()); + ASSERT_EQ(JID("123456#coven@mix.shakespeare.example"), *payload->getJID()); + ASSERT_FALSE(payload->getForm()); + + ASSERT_EQ(static_cast<size_t>(4), payload->getSubscriptions().size()); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:messages"))); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:presence"))); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:participants"))); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:config"))); +} + +TEST(MIXJoinParserTest, XEP0369_Example29) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<join xmlns=\"urn:xmpp:mix:0\">" + "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>" + "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>" + "<x xmlns=\"jabber:x:data\" type=\"submit\">" + "<field var=\"FORM_TYPE\" type=\"hidden\">" + "<value>urn:xmpp:mix:0</value>" + "</field>" + "<field var=\"JID Visibility\">" + "<value>never</value>" + "</field>" + "</x>" + "</join>")); + + MIXJoin::ref payload = parser.getPayload<MIXJoin>(); + ASSERT_TRUE(payload); + + ASSERT_FALSE(payload->getChannel()); + ASSERT_FALSE(payload->getJID()); + + ASSERT_EQ(static_cast<size_t>(2), payload->getSubscriptions().size()); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:messages"))); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:presence"))); + + ASSERT_TRUE(payload->getForm()); + ASSERT_EQ(Form::Type::SubmitType, payload->getForm()->getType()); + std::shared_ptr<FormField> fieldType = payload->getForm()->getField("FORM_TYPE"); + ASSERT_TRUE(fieldType); + + std::shared_ptr<FormField> fieldJIDVisibility = payload->getForm()->getField("JID Visibility"); + ASSERT_TRUE(fieldJIDVisibility); + ASSERT_EQ(std::string("never"), fieldJIDVisibility->getTextSingleValue()); +} + +TEST(MIXJoinParserTest, XEP0369_Example30) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<join xmlns=\"urn:xmpp:mix:0\" jid=\"hag66@shakespeare.example\">" + "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>" + "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>" + "<x xmlns=\"jabber:x:data\" type=\"result\">" + "<field var=\"FORM_TYPE\" type=\"hidden\">" + "<value>urn:xmpp:mix:0</value>" + "</field>" + "<field var=\"JID Visibility\">" + "<value>never</value>" + "</field>" + "<field var=\"Private Messages\">" + "<value>allow</value>" + "</field>" + "<field var=\"vCard\">" + "<value>block</value>" + "</field>" + "</x>" + "</join>")); + + MIXJoin::ref payload = parser.getPayload<MIXJoin>(); + ASSERT_TRUE(payload); + + ASSERT_FALSE(payload->getChannel()); + ASSERT_TRUE(payload->getJID()); + ASSERT_EQ(JID("hag66@shakespeare.example"), *payload->getJID()); + + ASSERT_EQ(static_cast<size_t>(2), payload->getSubscriptions().size()); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:messages"))); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:presence"))); + + ASSERT_TRUE(payload->getForm()); + ASSERT_EQ(Form::Type::ResultType, payload->getForm()->getType()); + std::shared_ptr<FormField> fieldType = payload->getForm()->getField("FORM_TYPE"); + ASSERT_TRUE(fieldType); + + std::shared_ptr<FormField> fieldJIDVisibility = payload->getForm()->getField("JID Visibility"); + ASSERT_TRUE(fieldJIDVisibility); + ASSERT_EQ(std::string("never"), fieldJIDVisibility->getTextSingleValue()); + + std::shared_ptr<FormField> fieldprivateMessages = payload->getForm()->getField("Private Messages"); + ASSERT_TRUE(fieldprivateMessages); + ASSERT_EQ(std::string("allow"), fieldprivateMessages->getTextSingleValue()); + + std::shared_ptr<FormField> vCard = payload->getForm()->getField("vCard"); + ASSERT_TRUE(vCard); + ASSERT_EQ(std::string("block"), vCard->getTextSingleValue()); +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXLeaveParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXLeaveParserTest.cpp new file mode 100644 index 0000000..0a2839e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXLeaveParserTest.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/MIXLeave.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXLeaveParserTest, XEP0369_Example33) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse("<leave xmlns=\"urn:xmpp:mix:0\" channel=\"coven@mix.shakespeare.example\"/>")); + + auto payload = parser.getPayload<MIXLeave>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getChannel()); + ASSERT_EQ(JID("coven@mix.shakespeare.example"), *payload->getChannel()); +} + +TEST(MIXLeaveParserTest, XEP0369_Example34) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse("<leave xmlns=\"urn:xmpp:mix:0\"/>")); + + auto payload = parser.getPayload<MIXLeave>(); + ASSERT_TRUE(payload); + ASSERT_FALSE(payload->getChannel()); +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXParticipantParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXParticipantParserTest.cpp new file mode 100644 index 0000000..57d4b35 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXParticipantParserTest.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/MIXParticipant.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXParticipantParserTest, XEP0369_Example1_ParticipantWithNick) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<participant xmlns='urn:xmpp:mix:0'> <nick>thirdwitch</nick> </participant>" + )); + + MIXParticipant::ref payload = parser.getPayload<MIXParticipant>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getNick()); + std::string nick = *payload->getNick(); + ASSERT_EQ("thirdwitch", nick); + + ASSERT_FALSE(payload->getJID()); +} + +TEST(MIXParticipantParserTest, XEP0369_Example2_ParticipantWithJID) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<participant xmlns='urn:xmpp:mix:0'> <jid>hecate@mix.shakespeare.example</jid> </participant>" + )); + + MIXParticipant::ref payload = parser.getPayload<MIXParticipant>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getJID()); + JID jid = *payload->getJID(); + ASSERT_EQ("hecate@mix.shakespeare.example", jid.toString()); + + ASSERT_FALSE(payload->getNick()); +} + +TEST(MIXParticipantParserTest, XEP0369_Example27_ParticipantEmpty) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<participant xmlns='urn:xmpp:mix:0'/>" + )); + + MIXParticipant::ref payload = parser.getPayload<MIXParticipant>(); + ASSERT_TRUE(payload); + ASSERT_FALSE(payload->getNick()); + ASSERT_FALSE(payload->getJID()); +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXPayloadParserTest.cpp new file mode 100644 index 0000000..920aca7 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXPayloadParserTest.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/MIXPayload.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXPayloadParserTest, WithNick) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<mix xmlns=\"urn:xmpp:mix:0\"> <nick>thirdwitch</nick> </mix>" + )); + + auto payload = parser.getPayload<MIXPayload>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getNick()); + std::string nick = *payload->getNick(); + ASSERT_EQ("thirdwitch", nick); + + ASSERT_FALSE(payload->getJID()); + ASSERT_FALSE(payload->getSubmissionID()); +} + +TEST(MIXPayloadParserTest, WithJID) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<mix xmlns=\"urn:xmpp:mix:0\"> <jid>hecate@mix.shakespeare.example</jid> </mix>" + )); + + auto payload = parser.getPayload<MIXPayload>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getJID()); + JID jid = *payload->getJID(); + ASSERT_EQ("hecate@mix.shakespeare.example", jid.toString()); + + ASSERT_FALSE(payload->getNick()); + ASSERT_FALSE(payload->getSubmissionID()); +} + +TEST(MIXPayloadParserTest, WithAll) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<mix xmlns=\"urn:xmpp:mix:0\">" + "<nick>thirdwitch</nick>" + "<jid>hecate@mix.shakespeare.example</jid>" + "<submission-id>92vax143g</submission-id>" + "</mix>" + )); + + auto payload = parser.getPayload<MIXPayload>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getNick()); + std::string nick = *payload->getNick(); + ASSERT_EQ("thirdwitch", nick); + + ASSERT_TRUE(payload->getJID()); + JID jid = *payload->getJID(); + ASSERT_EQ("hecate@mix.shakespeare.example", jid.toString()); + + ASSERT_TRUE(payload->getSubmissionID()); + std::string subID = *payload->getSubmissionID(); + ASSERT_EQ("92vax143g", subID); +} + +TEST(MIXPayloadParserTest, Empty) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<mix xmlns=\"urn:xmpp:mix:0\"/>" + )); + + auto payload = parser.getPayload<MIXPayload>(); + ASSERT_TRUE(payload); + ASSERT_FALSE(payload->getNick()); + ASSERT_FALSE(payload->getJID()); + ASSERT_FALSE(payload->getSubmissionID()); +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXRegisterNickParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXRegisterNickParserTest.cpp new file mode 100644 index 0000000..d0539fd --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXRegisterNickParserTest.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/MIXRegisterNick.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXRegisterNickParserTest, WithNick) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<register xmlns=\"urn:xmpp:mix:0\"> <nick>thirdwitch</nick> </register>" + )); + + auto payload = parser.getPayload<MIXRegisterNick>(); + ASSERT_TRUE(payload); + ASSERT_EQ("thirdwitch", payload->getNick()); +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXSetNickParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXSetNickParserTest.cpp new file mode 100644 index 0000000..84f8a5e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXSetNickParserTest.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/MIXSetNick.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXSetNickParserTest, WithNick) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<setnick xmlns=\"urn:xmpp:mix:0\"> <nick>thirdwitch</nick> </setnick>" + )); + + auto payload = parser.getPayload<MIXSetNick>(); + ASSERT_TRUE(payload); + ASSERT_EQ("thirdwitch", payload->getNick()); +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXUpdateSubscriptionParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXUpdateSubscriptionParserTest.cpp new file mode 100644 index 0000000..985a34b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXUpdateSubscriptionParserTest.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/MIXUpdateSubscription.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXUpdateSubscriptionParserTest, XEP0369_Example28) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<update-subscription xmlns=\"urn:xmpp:mix:0\">" + "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>" + "</update-subscription>" + )); + + auto payload = parser.getPayload<MIXUpdateSubscription>(); + ASSERT_TRUE(payload); + + ASSERT_FALSE(payload->getJID()); + + auto items = payload->getSubscriptions(); + ASSERT_EQ(static_cast<size_t>(1), items.size()); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:messages"))); +} + +TEST(MIXUpdateSubscriptionParserTest, XEP0369_Example28_WithJID) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<update-subscription xmlns=\"urn:xmpp:mix:0\" jid=\"hag66@shakespeare.example\">" + "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>" + "</update-subscription>" + )); + + auto payload = parser.getPayload<MIXUpdateSubscription>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getJID()); + ASSERT_EQ(JID("hag66@shakespeare.example"), *payload->getJID()); + + auto items = payload->getSubscriptions(); + ASSERT_EQ(static_cast<size_t>(1), items.size()); + ASSERT_TRUE(payload->hasSubscription(std::string("urn:xmpp:mix:nodes:messages"))); +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXUserPreferenceParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXUserPreferenceParserTest.cpp new file mode 100644 index 0000000..7115f2a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXUserPreferenceParserTest.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/MIXUserPreference.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXUserPreferenceParserTest, XEP0369_Example31) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<user-preference xmlns='urn:xmpp:mix:0'/>" + )); + + auto payload = parser.getPayload<MIXUserPreference>(); + ASSERT_TRUE(payload); + + ASSERT_FALSE(payload->getData()); +} + +TEST(MIXUserPreferenceParserTest, XEP0369_Example32) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<user-preference xmlns='urn:xmpp:mix:0'>" + "<x xmlns='jabber:x:data' type='result'>" + "<field var='FORM_TYPE' type='hidden'>" + "<value>urn:xmpp:mix:0</value>" + "</field>" + "<field var='JID Visibility'>" + "<value>never</value>" + "</field>" + "<field var='Private Messages'>" + "<value>allow</value>" + "</field>" + "<field var='vCard'>" + "<value>block</value>" + "</field>" + "</x>" + "</user-preference>" + )); + + auto payload = parser.getPayload<MIXUserPreference>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getData()); + ASSERT_EQ(Form::Type::ResultType, payload->getData()->getType()); + std::shared_ptr<FormField> fieldType = payload->getData()->getField("FORM_TYPE"); + ASSERT_TRUE(fieldType); + + std::shared_ptr<FormField> fieldJIDVisibility = payload->getData()->getField("JID Visibility"); + ASSERT_TRUE(fieldJIDVisibility); + ASSERT_EQ(std::string("never"), fieldJIDVisibility->getTextSingleValue()); + + std::shared_ptr<FormField> fieldprivateMessages = payload->getData()->getField("Private Messages"); + ASSERT_TRUE(fieldprivateMessages); + ASSERT_EQ(std::string("allow"), fieldprivateMessages->getTextSingleValue()); + + std::shared_ptr<FormField> vCard = payload->getData()->getField("vCard"); + ASSERT_TRUE(vCard); + ASSERT_EQ(std::string("block"), vCard->getTextSingleValue()); +} diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MUCAdminPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MUCAdminPayloadParserTest.cpp index 0648f58..d403872 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MUCAdminPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MUCAdminPayloadParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -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 40d7358..f0cf68d 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp @@ -1,93 +1,92 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Base/foreach.h> -#include <Swiften/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 b0f68ab..a85a692 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h +++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h @@ -1,14 +1,14 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 b328670..8f9e0e1 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h +++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h @@ -1,66 +1,64 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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); - } - - ~PayloadsParserTester() { - delete xmlParser; - } + class PayloadsParserTester : public XMLParserClient { + public: + PayloadsParserTester() : level(0) { + xmlParser = PlatformXMLParserFactory().createXMLParser(this, false); + } - 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: + std::unique_ptr<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 0974aec..2c89f0f 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -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 ef6ed9a..06f3ae5 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/PrivateStorageParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -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 4862584..2deca6e 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -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/ReferencePayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ReferencePayloadParserTest.cpp new file mode 100644 index 0000000..ca7b280 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/ReferencePayloadParserTest.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <gtest/gtest.h> + +#include <Swiften/Elements/Body.h> +#include <Swiften/Elements/Delay.h> +#include <Swiften/Elements/ErrorPayload.h> +#include <Swiften/Parser/PayloadParsers/ReferencePayloadParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(ReferencePayloadParserTest, testParse) { + PayloadsParserTester parser; + + ASSERT_TRUE(parser.parse( + "<reference xmlns='urn:xmpp:reference:0' " + "type='data' " + "uri='https://www.example.com/mindBlowingImage.jpeg' " + "begin='11' " + "end='22' " + "anchor='xmpp:data@localhost.example.test'>" + "</reference>")); + + auto payload = std::dynamic_pointer_cast<ReferencePayload>(parser.getPayload()); + ASSERT_EQ(static_cast<int>(ReferencePayload::Type::Data), static_cast<int>(payload->getType())); + ASSERT_EQ(std::string("https://www.example.com/mindBlowingImage.jpeg"), *payload->getUri()); + ASSERT_EQ(std::string("11"), *payload->getBegin()); + ASSERT_EQ(std::string("22"), *payload->getEnd()); + ASSERT_EQ(std::string("xmpp:data@localhost.example.test"), *payload->getAnchor()); +} + +TEST(ReferencePayloadParserTest, testParseNoType) { + PayloadsParserTester parser; + + ASSERT_TRUE(parser.parse( + "<reference xmlns='urn:xmpp:reference:0' " + "uri='https://www.example.com/mindBlowingImage.jpeg' " + "begin='11' " + "end='22' " + "anchor='xmpp:data@localhost.example.test'>" + "</reference>")); + + auto payload = std::dynamic_pointer_cast<ReferencePayload>(parser.getPayload()); + ASSERT_EQ(static_cast<int>(ReferencePayload::Type::Unknown), static_cast<int>(payload->getType())); + ASSERT_EQ(std::string("https://www.example.com/mindBlowingImage.jpeg"), *payload->getUri()); + ASSERT_EQ(std::string("11"), *payload->getBegin()); + ASSERT_EQ(std::string("22"), *payload->getEnd()); + ASSERT_EQ(std::string("xmpp:data@localhost.example.test"), *payload->getAnchor()); +} + +TEST(ReferencePayloadParserTest, testParseEmbeddedPayloads) { + PayloadsParserTester parser; + + ASSERT_TRUE(parser.parse( + "<reference xmlns='urn:xmpp:reference:0' type='data'> " + "<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>" + "</reference>")); + + auto payload = std::dynamic_pointer_cast<ReferencePayload>(parser.getPayload()); + ASSERT_EQ(static_cast<int>(ReferencePayload::Type::Data), static_cast<int>(payload->getType())); + ASSERT_FALSE(payload->getUri()); + ASSERT_FALSE(payload->getBegin()); + ASSERT_FALSE(payload->getEnd()); + ASSERT_FALSE(payload->getAnchor()); + auto childPayloadList = payload->getPayloads(); + auto errorPayload = std::dynamic_pointer_cast<ErrorPayload>(childPayloadList[0]); + ASSERT_TRUE(errorPayload); + ASSERT_EQ("boo", errorPayload->getText()); + auto delayPayload = std::dynamic_pointer_cast<Delay>(errorPayload->getPayload()); + ASSERT_TRUE(delayPayload); +} + +TEST(ReferencePayloadParserTest, testParseEmbeddedPayloadWithText) { + PayloadsParserTester parser; + + ASSERT_TRUE(parser.parse( + "<reference xmlns='urn:xmpp:reference:0' type='data'> " + "<body>Example Text</body>" + "</reference>")); + + auto payload = std::dynamic_pointer_cast<ReferencePayload>(parser.getPayload()); + auto childPayloadList = payload->getPayloads(); + auto bodyPayload = std::dynamic_pointer_cast<Body>(childPayloadList[0]); + ASSERT_EQ("Example Text", bodyPayload->getText()); +} + +TEST(ReferencePayloadParserTest, testParseRecursive) { + PayloadsParserTester parser; + + ASSERT_TRUE(parser.parse( + "<reference xmlns='urn:xmpp:reference:0' type='data'> " + "<reference xmlns='urn:xmpp:reference:0' type='data' uri='https://download.montague.lit/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/summit.jpg' /> " + "<reference xmlns='urn:xmpp:reference:0' type='data' uri='xmpp:romeo@montague.lit/resource?jingle;id=9559976B-3FBF-4E7E-B457-2DAA225972BB' /> " + "<reference xmlns='urn:xmpp:reference:0' type='data'> " + "<reference xmlns='urn:xmpp:reference:0' type='data' uri='https://www.example.com/mindBlowingImage.jpeg' /> " + "</reference>" + "</reference>")); + + auto payload = std::dynamic_pointer_cast<ReferencePayload>(parser.getPayload()); + ASSERT_EQ(static_cast<int>(ReferencePayload::Type::Data), static_cast<int>(payload->getType())); + auto childPayloadList = payload->getPayloads(); + auto childPayloadA = std::dynamic_pointer_cast<ReferencePayload>(childPayloadList[0]); + auto childPayloadB = std::dynamic_pointer_cast<ReferencePayload>(childPayloadList[1]); + auto childPayloadC = std::dynamic_pointer_cast<ReferencePayload>(childPayloadList[2]); + ASSERT_TRUE(childPayloadA); + ASSERT_TRUE(childPayloadB); + ASSERT_TRUE(childPayloadC); + ASSERT_EQ(static_cast<int>(ReferencePayload::Type::Data), static_cast<int>(childPayloadA->getType())); + ASSERT_EQ(static_cast<int>(ReferencePayload::Type::Data), static_cast<int>(childPayloadB->getType())); + ASSERT_EQ(static_cast<int>(ReferencePayload::Type::Data), static_cast<int>(childPayloadC->getType())); + ASSERT_EQ(std::string("https://download.montague.lit/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/summit.jpg"), *childPayloadA->getUri()); + ASSERT_EQ(std::string("xmpp:romeo@montague.lit/resource?jingle;id=9559976B-3FBF-4E7E-B457-2DAA225972BB"), *childPayloadB->getUri()); + ASSERT_FALSE(childPayloadC->getUri()); + ASSERT_FALSE(childPayloadC->getBegin()); + ASSERT_FALSE(childPayloadC->getEnd()); + ASSERT_FALSE(childPayloadC->getAnchor()); + auto grandChildPayloadList = childPayloadC->getPayloads(); + auto grandChildPayload = std::dynamic_pointer_cast<ReferencePayload>(grandChildPayloadList[0]); + ASSERT_TRUE(grandChildPayload); + ASSERT_EQ(static_cast<int>(ReferencePayload::Type::Data), static_cast<int>(grandChildPayload->getType())); + ASSERT_EQ(std::string("https://www.example.com/mindBlowingImage.jpeg"), *grandChildPayload->getUri()); + ASSERT_FALSE(grandChildPayload->getBegin()); + ASSERT_FALSE(grandChildPayload->getEnd()); + ASSERT_FALSE(grandChildPayload->getAnchor()); +} 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 663a81c..5c786c5 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -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 new file mode 100644 index 0000000..da5d978 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2014-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/ResultSetParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +class ResultSetParserTest : public CppUnit::TestFixture +{ + 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>")); + + 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>")); + + 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 6cb5dbc..261dad2 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/RosterParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -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 59ea3ff..5fe4168 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp @@ -1,181 +1,181 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-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/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 5083a07..c27b716 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -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 395daf5..ee7668c 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -14,50 +14,107 @@ 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(testParseInvalidInput); + 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()); + } + + void testParseInvalidInput() { + 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|INVALID-SECRET' xmlns=\"\">" + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking bgcolor=\"red\" fgcolor=\"black\">INVALID-SECRET</displaymarking>" + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel></label>" + "</securitylabel>" + "</item>" + "<item selector='Classified|INVALID-TOPSECRET' xmlns=\"urn:xmpp:sec-label:catalog:invalid:2\">" + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking bgcolor=\"red\" fgcolor=\"black\">INVALID-TOPSECRET</displaymarking>" + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel></label>" + "</securitylabel>" + "</item>" + "<item selector='Classified|CONFIDENTIAL' default='true' xmlns=\"urn:xmpp:sec-label:catalog:2\">" + "<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='Classified|INVALID-LABEL'>" + "<securitylabel xmlns=\"\">" + "<displaymarking bgcolor=\"yellow\" fgcolor=\"black\">INVALID</displaymarking>" + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</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(payload->getItems()[0].getLabel()); + if (payload->getItems()[0].getLabel()) { + CPPUNIT_ASSERT_EQUAL(std::string("CONFIDENTIAL"), payload->getItems()[0].getLabel()->getDisplayMarking()); + CPPUNIT_ASSERT_EQUAL(std::string("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel>"), payload->getItems()[0].getLabel()->getLabel()); + CPPUNIT_ASSERT_EQUAL(true, payload->getItems()[0].getIsDefault()); + CPPUNIT_ASSERT_EQUAL(std::string("Classified|CONFIDENTIAL"), payload->getItems()[0].getSelector()); + } + //The label is invalid, but the rest of the item entry should be there. + CPPUNIT_ASSERT(!payload->getItems()[1].getLabel()); + CPPUNIT_ASSERT_EQUAL(false, payload->getItems()[1].getIsDefault()); + CPPUNIT_ASSERT_EQUAL(std::string("Classified|INVALID-LABEL"), 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 d22d207..7471856 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -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 358ff88..6b93637 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StatusParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -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 924a87f..94f14c6 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StatusShowParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -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 5ceec27..4430668 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010-2012 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2012 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -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 63a6c9b..9b0679d 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StreamInitiationParserTest.cpp @@ -1,75 +1,75 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-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/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 new file mode 100644 index 0000000..98a147f --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Base/DateTime.h> +#include <Swiften/Elements/UserLocation.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(); + + public: + UserLocationParserTest() {} + + 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>")); + + 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; + + 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.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 new file mode 100644 index 0000000..3783231 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Base/DateTime.h> +#include <Swiften/Elements/UserTune.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(); + + public: + UserTuneParserTest() {} + + 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>")); + + 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; + + 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()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(UserTuneParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp index 6436e90..bc29921 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp @@ -1,207 +1,207 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 fe69242..11e8ded 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-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/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 d3aac69..09d0e9a 100644 --- a/Swiften/Parser/PayloadParsers/UserLocationParser.cpp +++ b/Swiften/Parser/PayloadParsers/UserLocationParser.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * 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 eb6e668..39df9de 100644 --- a/Swiften/Parser/PayloadParsers/UserLocationParser.h +++ b/Swiften/Parser/PayloadParsers/UserLocationParser.h @@ -1,31 +1,30 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License. + * Copyright (c) 2013-2017 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/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() 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; + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) 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 new file mode 100644 index 0000000..f030f8f --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UserTuneParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/UserTuneParser.h> + +#include <boost/lexical_cast.hpp> + +using namespace Swift; + +UserTuneParser::UserTuneParser() : level(0) { +} + +UserTuneParser::~UserTuneParser() { +} + +void UserTuneParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + 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&) { + } + } +} + +void UserTuneParser::handleCharacterData(const std::string& data) { + currentText += data; +} diff --git a/Swiften/Parser/PayloadParsers/UserTuneParser.h b/Swiften/Parser/PayloadParsers/UserTuneParser.h new file mode 100644 index 0000000..8c7e8c5 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UserTuneParser.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2014-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> +#include <string> + +#include <Swiften/Base/API.h> +#include <Swiften/Elements/UserTune.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class SWIFTEN_API UserTuneParser : public GenericPayloadParser<UserTune> { + public: + UserTuneParser(); + virtual ~UserTuneParser() override; + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) override; + virtual void handleEndElement(const std::string& element, const std::string&) override; + virtual void handleCharacterData(const std::string& data) override; + + private: + int level; + std::string currentText; + }; +} diff --git a/Swiften/Parser/PayloadParsers/VCardParser.cpp b/Swiften/Parser/PayloadParsers/VCardParser.cpp index 0028411..f8779d1 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.cpp +++ b/Swiften/Parser/PayloadParsers/VCardParser.cpp @@ -1,288 +1,290 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 f10d639..5a47cbf 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.h +++ b/Swiften/Parser/PayloadParsers/VCardParser.h @@ -1,38 +1,37 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 d4703da..64559ae 100644 --- a/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp +++ b/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PayloadParsers/VCardUpdateParser.h> @@ -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 4954f0a..91837fb 100644 --- a/Swiften/Parser/PayloadParsers/VCardUpdateParser.h +++ b/Swiften/Parser/PayloadParsers/VCardUpdateParser.h @@ -1,31 +1,30 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/VCardUpdate.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class SerializingParser; + class SWIFTEN_API VCardUpdateParser : public GenericPayloadParser<VCardUpdate> { + public: + VCardUpdateParser(); - class 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 0368c7c..2f22624 100644 --- a/Swiften/Parser/PayloadParsers/WhiteboardParser.h +++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.h @@ -4,31 +4,38 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once -#include <Swiften/Elements/WhiteboardPayload.h> -#include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Base/API.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 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; + }; } diff --git a/Swiften/Parser/PlatformXMLParserFactory.cpp b/Swiften/Parser/PlatformXMLParserFactory.cpp index 18acdc2..a424aca 100644 --- a/Swiften/Parser/PlatformXMLParserFactory.cpp +++ b/Swiften/Parser/PlatformXMLParserFactory.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/PlatformXMLParserFactory.h> @@ -20,11 +20,11 @@ namespace Swift { PlatformXMLParserFactory::PlatformXMLParserFactory() { } -XMLParser* PlatformXMLParserFactory::createXMLParser(XMLParserClient* client) { +std::unique_ptr<XMLParser> PlatformXMLParserFactory::createXMLParser(XMLParserClient* client, bool allowComments) { #ifdef HAVE_LIBXML - return new LibXMLParser(client); + return std::make_unique<LibXMLParser>(client, allowComments); #else - return new ExpatParser(client); + return std::make_unique<ExpatParser>(client, allowComments); #endif } diff --git a/Swiften/Parser/PlatformXMLParserFactory.h b/Swiften/Parser/PlatformXMLParserFactory.h index 70355d0..d72a513 100644 --- a/Swiften/Parser/PlatformXMLParserFactory.h +++ b/Swiften/Parser/PlatformXMLParserFactory.h @@ -1,19 +1,19 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/XMLParserFactory.h> #include <Swiften/Base/API.h> +#include <Swiften/Parser/XMLParserFactory.h> namespace Swift { - class SWIFTEN_API PlatformXMLParserFactory : public XMLParserFactory { - public: - PlatformXMLParserFactory(); + class SWIFTEN_API PlatformXMLParserFactory : public XMLParserFactory { + public: + PlatformXMLParserFactory(); - virtual XMLParser* createXMLParser(XMLParserClient*); - }; + virtual std::unique_ptr<XMLParser> createXMLParser(XMLParserClient*, bool allowComments = false); + }; } diff --git a/Swiften/Parser/PresenceParser.cpp b/Swiften/Parser/PresenceParser.cpp index 39305c0..f73e9d8 100644 --- a/Swiften/Parser/PresenceParser.cpp +++ b/Swiften/Parser/PresenceParser.cpp @@ -1,52 +1,53 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2019 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ -#include <iostream> +#include <Swiften/Parser/PresenceParser.h> + #include <boost/optional.hpp> -#include <Swiften/Parser/PresenceParser.h> +#include <Swiften/Base/Log.h> namespace Swift { -PresenceParser::PresenceParser(PayloadParserFactoryCollection* factories) : - GenericStanzaParser<Presence>(factories) { +PresenceParser::PresenceParser(PayloadParserFactoryCollection* factories) : + GenericStanzaParser<Presence>(factories) { } void PresenceParser::handleStanzaAttributes(const AttributeMap& attributes) { - boost::optional<std::string> type = attributes.getAttributeValue("type"); - if (type) { - if (*type == "unavailable") { - getStanzaGeneric()->setType(Presence::Unavailable); - } - else if (*type == "probe") { - getStanzaGeneric()->setType(Presence::Probe); - } - else if (*type == "subscribe") { - getStanzaGeneric()->setType(Presence::Subscribe); - } - else if (*type == "subscribed") { - getStanzaGeneric()->setType(Presence::Subscribed); - } - else if (*type == "unsubscribe") { - getStanzaGeneric()->setType(Presence::Unsubscribe); - } - else if (*type == "unsubscribed") { - getStanzaGeneric()->setType(Presence::Unsubscribed); - } - else if (*type == "error") { - getStanzaGeneric()->setType(Presence::Error); - } - else { - std::cerr << "Unknown Presence type: " << *type << std::endl; - getStanzaGeneric()->setType(Presence::Available); - } - } - else { - getStanzaGeneric()->setType(Presence::Available); - } + boost::optional<std::string> type = attributes.getAttributeValue("type"); + if (type) { + if (*type == "unavailable") { + getStanzaGeneric()->setType(Presence::Unavailable); + } + else if (*type == "probe") { + getStanzaGeneric()->setType(Presence::Probe); + } + else if (*type == "subscribe") { + getStanzaGeneric()->setType(Presence::Subscribe); + } + else if (*type == "subscribed") { + getStanzaGeneric()->setType(Presence::Subscribed); + } + else if (*type == "unsubscribe") { + getStanzaGeneric()->setType(Presence::Unsubscribe); + } + else if (*type == "unsubscribed") { + getStanzaGeneric()->setType(Presence::Unsubscribed); + } + else if (*type == "error") { + getStanzaGeneric()->setType(Presence::Error); + } + else { + SWIFT_LOG(error) << "Unknown Presence type: " << *type; + getStanzaGeneric()->setType(Presence::Available); + } + } + else { + getStanzaGeneric()->setType(Presence::Available); + } } } diff --git a/Swiften/Parser/PresenceParser.h b/Swiften/Parser/PresenceParser.h index eb07af8..76753f8 100644 --- a/Swiften/Parser/PresenceParser.h +++ b/Swiften/Parser/PresenceParser.h @@ -1,21 +1,21 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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/Parser/GenericStanzaParser.h> #include <Swiften/Elements/Presence.h> +#include <Swiften/Parser/GenericStanzaParser.h> namespace Swift { - class SWIFTEN_API PresenceParser : public GenericStanzaParser<Presence> { - public: - PresenceParser(PayloadParserFactoryCollection* factories); + class SWIFTEN_API PresenceParser : public GenericStanzaParser<Presence> { + public: + PresenceParser(PayloadParserFactoryCollection* factories); - private: - virtual void handleStanzaAttributes(const AttributeMap&); - }; + private: + virtual void handleStanzaAttributes(const AttributeMap&); + }; } diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index 0a6972e..4ac5aa4 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -6,101 +6,126 @@ myenv.MergeFlags(swiften_env.get("LIBXML_FLAGS", "")) myenv.MergeFlags(swiften_env.get("EXPAT_FLAGS", "")) sources = [ - "AttributeMap.cpp", - "AuthRequestParser.cpp", - "AuthChallengeParser.cpp", - "AuthSuccessParser.cpp", - "AuthResponseParser.cpp", - "CompressParser.cpp", - "ElementParser.cpp", - "IQParser.cpp", - "MessageParser.cpp", - "PayloadParser.cpp", - "StanzaAckParser.cpp", - "BOSHBodyExtractor.cpp", - "ComponentHandshakeParser.cpp", - "PayloadParserFactory.cpp", - "PayloadParserFactoryCollection.cpp", - "PayloadParsers/BodyParser.cpp", - "PayloadParsers/SubjectParser.cpp", - "PayloadParsers/ChatStateParser.cpp", - "PayloadParsers/CapsInfoParser.cpp", - "PayloadParsers/DiscoInfoParser.cpp", - "PayloadParsers/DiscoItemsParser.cpp", - "PayloadParsers/ErrorParser.cpp", - "PayloadParsers/FormParser.cpp", - "PayloadParsers/IBBParser.cpp", - "PayloadParsers/JingleParser.cpp", - "PayloadParsers/JingleReasonParser.cpp", - "PayloadParsers/JingleContentPayloadParser.cpp", - "PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp", - "PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp", - "PayloadParsers/JingleFileTransferDescriptionParser.cpp", - "PayloadParsers/JingleFileTransferReceivedParser.cpp", - "PayloadParsers/JingleFileTransferHashParser.cpp", - "PayloadParsers/StreamInitiationFileInfoParser.cpp", - "PayloadParsers/CommandParser.cpp", - "PayloadParsers/InBandRegistrationPayloadParser.cpp", - "PayloadParsers/SearchPayloadParser.cpp", - "PayloadParsers/FullPayloadParserFactoryCollection.cpp", - "PayloadParsers/PriorityParser.cpp", - "PayloadParsers/PrivateStorageParser.cpp", - "PayloadParsers/RawXMLPayloadParser.cpp", - "PayloadParsers/ResourceBindParser.cpp", - "PayloadParsers/RosterItemExchangeParser.cpp", - "PayloadParsers/RosterParser.cpp", - "PayloadParsers/SecurityLabelParser.cpp", - "PayloadParsers/SecurityLabelsCatalogParser.cpp", - "PayloadParsers/SoftwareVersionParser.cpp", - "PayloadParsers/StorageParser.cpp", - "PayloadParsers/StatusParser.cpp", - "PayloadParsers/StatusShowParser.cpp", - "PayloadParsers/StreamInitiationParser.cpp", - "PayloadParsers/BytestreamsParser.cpp", - "PayloadParsers/VCardParser.cpp", - "PayloadParsers/VCardUpdateParser.cpp", - "PayloadParsers/DelayParser.cpp", - "PayloadParsers/MUCUserPayloadParser.cpp", - "PayloadParsers/MUCAdminPayloadParser.cpp", - "PayloadParsers/MUCOwnerPayloadParser.cpp", - "PayloadParsers/MUCDestroyPayloadParser.cpp", - "PayloadParsers/MUCInvitationPayloadParser.cpp", - "PayloadParsers/MUCItemParser.cpp", - "PayloadParsers/NicknameParser.cpp", - "PayloadParsers/ReplaceParser.cpp", - "PayloadParsers/LastParser.cpp", - "PayloadParsers/IdleParser.cpp", - "PayloadParsers/S5BProxyRequestParser.cpp", - "PayloadParsers/DeliveryReceiptParser.cpp", - "PayloadParsers/DeliveryReceiptRequestParser.cpp", - "PayloadParsers/UserLocationParser.cpp", - "PayloadParsers/WhiteboardParser.cpp", - "PayloadParsers/PubSubErrorParserFactory.cpp", - "PlatformXMLParserFactory.cpp", - "PresenceParser.cpp", - "SerializingParser.cpp", - "StanzaParser.cpp", - "StreamErrorParser.cpp", - "StreamFeaturesParser.cpp", - "StreamManagementEnabledParser.cpp", - "StreamResumeParser.cpp", - "StreamResumedParser.cpp", - "Tree/ParserElement.cpp", - "Tree/NullParserElement.cpp", - "Tree/TreeReparser.cpp", - "XMLParser.cpp", - "XMLParserClient.cpp", - "XMLParserFactory.cpp", - "XMPPParser.cpp", - "XMPPParserClient.cpp", - ] + "AttributeMap.cpp", + "AuthRequestParser.cpp", + "AuthChallengeParser.cpp", + "AuthSuccessParser.cpp", + "AuthResponseParser.cpp", + "CompressParser.cpp", + "ElementParser.cpp", + "IQParser.cpp", + "MessageParser.cpp", + "PayloadParser.cpp", + "StanzaAckParser.cpp", + "BOSHBodyExtractor.cpp", + "ComponentHandshakeParser.cpp", + "PayloadParserFactory.cpp", + "PayloadParserFactoryCollection.cpp", + "PayloadParsers/BodyParser.cpp", + "PayloadParsers/SubjectParser.cpp", + "PayloadParsers/ThreadParser.cpp", + "PayloadParsers/CarbonsEnableParser.cpp", + "PayloadParsers/CarbonsDisableParser.cpp", + "PayloadParsers/CarbonsPrivateParser.cpp", + "PayloadParsers/CarbonsReceivedParser.cpp", + "PayloadParsers/CarbonsSentParser.cpp", + "PayloadParsers/ChatStateParser.cpp", + "PayloadParsers/ClientStateParser.cpp", + "PayloadParsers/CapsInfoParser.cpp", + "PayloadParsers/DiscoInfoParser.cpp", + "PayloadParsers/DiscoItemsParser.cpp", + "PayloadParsers/ErrorParser.cpp", + "PayloadParsers/FormParser.cpp", + "PayloadParsers/IBBParser.cpp", + "PayloadParsers/JingleParser.cpp", + "PayloadParsers/JingleReasonParser.cpp", + "PayloadParsers/JingleContentPayloadParser.cpp", + "PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp", + "PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp", + "PayloadParsers/JingleFileTransferDescriptionParser.cpp", + "PayloadParsers/JingleFileTransferHashParser.cpp", + "PayloadParsers/JingleFileTransferFileInfoParser.cpp", + "PayloadParsers/StreamInitiationFileInfoParser.cpp", + "PayloadParsers/CommandParser.cpp", + "PayloadParsers/InBandRegistrationPayloadParser.cpp", + "PayloadParsers/SearchPayloadParser.cpp", + "PayloadParsers/FullPayloadParserFactoryCollection.cpp", + "PayloadParsers/PriorityParser.cpp", + "PayloadParsers/PrivateStorageParser.cpp", + "PayloadParsers/RawXMLPayloadParser.cpp", + "PayloadParsers/ReferencePayloadParser.cpp", + "PayloadParsers/ResourceBindParser.cpp", + "PayloadParsers/RosterItemExchangeParser.cpp", + "PayloadParsers/RosterParser.cpp", + "PayloadParsers/SecurityLabelParser.cpp", + "PayloadParsers/SecurityLabelsCatalogParser.cpp", + "PayloadParsers/SoftwareVersionParser.cpp", + "PayloadParsers/StorageParser.cpp", + "PayloadParsers/StatusParser.cpp", + "PayloadParsers/StatusShowParser.cpp", + "PayloadParsers/StreamInitiationParser.cpp", + "PayloadParsers/BytestreamsParser.cpp", + "PayloadParsers/VCardParser.cpp", + "PayloadParsers/VCardUpdateParser.cpp", + "PayloadParsers/DelayParser.cpp", + "PayloadParsers/MIXParticipantParser.cpp", + "PayloadParsers/MIXSetNickParser.cpp", + "PayloadParsers/MIXRegisterNickParser.cpp", + "PayloadParsers/MIXDestroyParser.cpp", + "PayloadParsers/MIXCreateParser.cpp", + "PayloadParsers/MIXPayloadParser.cpp", + "PayloadParsers/MIXLeaveParser.cpp", + "PayloadParsers/MIXJoinParser.cpp", + "PayloadParsers/MIXUserPreferenceParser.cpp", + "PayloadParsers/MIXUpdateSubscriptionParser.cpp", + "PayloadParsers/MUCUserPayloadParser.cpp", + "PayloadParsers/MUCAdminPayloadParser.cpp", + "PayloadParsers/MUCOwnerPayloadParser.cpp", + "PayloadParsers/MUCDestroyPayloadParser.cpp", + "PayloadParsers/MUCInvitationPayloadParser.cpp", + "PayloadParsers/MUCItemParser.cpp", + "PayloadParsers/NicknameParser.cpp", + "PayloadParsers/ReplaceParser.cpp", + "PayloadParsers/LastParser.cpp", + "PayloadParsers/IdleParser.cpp", + "PayloadParsers/S5BProxyRequestParser.cpp", + "PayloadParsers/DeliveryReceiptParser.cpp", + "PayloadParsers/DeliveryReceiptRequestParser.cpp", + "PayloadParsers/UserLocationParser.cpp", + "PayloadParsers/UserTuneParser.cpp", + "PayloadParsers/WhiteboardParser.cpp", + "PayloadParsers/PubSubErrorParserFactory.cpp", + "PayloadParsers/ResultSetParser.cpp", + "PayloadParsers/ForwardedParser.cpp", + "PayloadParsers/MAMFinParser.cpp", + "PayloadParsers/MAMResultParser.cpp", + "PayloadParsers/MAMQueryParser.cpp", + "PayloadParsers/IsodeIQDelegationParser.cpp", + "PlatformXMLParserFactory.cpp", + "PresenceParser.cpp", + "SerializingParser.cpp", + "StanzaParser.cpp", + "StreamErrorParser.cpp", + "StreamFeaturesParser.cpp", + "StreamManagementEnabledParser.cpp", + "StreamResumeParser.cpp", + "StreamResumedParser.cpp", + "Tree/ParserElement.cpp", + "Tree/NullParserElement.cpp", + "Tree/TreeReparser.cpp", + "XMLParser.cpp", + "XMLParserClient.cpp", + "XMLParserFactory.cpp", + "XMPPParser.cpp", + "XMPPParserClient.cpp", + ] if myenv.get("HAVE_EXPAT", 0) : - myenv.Append(CPPDEFINES = "HAVE_EXPAT") - sources += ["ExpatParser.cpp"] + myenv.Append(CPPDEFINES = "HAVE_EXPAT") + sources += ["ExpatParser.cpp"] if myenv.get("HAVE_LIBXML", 0) : - myenv.Append(CPPDEFINES = "HAVE_LIBXML") - sources += ["LibXMLParser.cpp"] + myenv.Append(CPPDEFINES = "HAVE_LIBXML") + sources += ["LibXMLParser.cpp"] objects = myenv.SwiftenObject(sources) swiften_env.Append(SWIFTEN_OBJECTS = [objects]) diff --git a/Swiften/Parser/SerializingParser.cpp b/Swiften/Parser/SerializingParser.cpp index cd044cc..85b0dd4 100644 --- a/Swiften/Parser/SerializingParser.cpp +++ b/Swiften/Parser/SerializingParser.cpp @@ -1,15 +1,15 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/SerializingParser.h> -#include <boost/smart_ptr/make_shared.hpp> +#include <cassert> +#include <memory> #include <Swiften/Serializer/XML/XMLTextNode.h> -#include <Swiften/Base/foreach.h> namespace Swift { @@ -17,34 +17,34 @@ SerializingParser::SerializingParser() { } void SerializingParser::handleStartElement(const std::string& tag, const std::string& ns, const AttributeMap& attributes) { - boost::shared_ptr<XMLElement> element = boost::make_shared<XMLElement>(tag, ns); - // FIXME: Ignoring attribute namespace - foreach (const AttributeMap::Entry& e, attributes.getEntries()) { - element->setAttribute(e.getAttribute().getName(), e.getValue()); - } - - if (elementStack_.empty()) { - rootElement_ = element; - } - else { - (*(elementStack_.end() - 1))->addNode(element); - } - elementStack_.push_back(element); + std::shared_ptr<XMLElement> element = std::make_shared<XMLElement>(tag, ns); + // FIXME: Ignoring attribute namespace + for (const auto& e : attributes.getEntries()) { + element->setAttribute(e.getAttribute().getName(), e.getValue()); + } + + if (elementStack_.empty()) { + rootElement_ = element; + } + else { + (*(elementStack_.end() - 1))->addNode(element); + } + elementStack_.push_back(element); } void SerializingParser::handleEndElement(const std::string&, const std::string&) { - assert(!elementStack_.empty()); - elementStack_.pop_back(); + assert(!elementStack_.empty()); + elementStack_.pop_back(); } void SerializingParser::handleCharacterData(const std::string& data) { - if (!elementStack_.empty()) { - (*(elementStack_.end()-1))->addNode(boost::make_shared<XMLTextNode>(data)); - } + if (!elementStack_.empty()) { + (*(elementStack_.end()-1))->addNode(std::make_shared<XMLTextNode>(data)); + } } std::string SerializingParser::getResult() const { - return (rootElement_ ? rootElement_->serialize() : ""); + return (rootElement_ ? rootElement_->serialize() : ""); } } diff --git a/Swiften/Parser/SerializingParser.h b/Swiften/Parser/SerializingParser.h index 7706961..bc2d872 100644 --- a/Swiften/Parser/SerializingParser.h +++ b/Swiften/Parser/SerializingParser.h @@ -1,29 +1,30 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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/AttributeMap.h> #include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { - class SWIFTEN_API SerializingParser { - public: - SerializingParser(); + class SWIFTEN_API SerializingParser { + public: + SerializingParser(); - void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); - void handleEndElement(const std::string& element, const std::string& ns); - void handleCharacterData(const std::string& data); + void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); + void handleEndElement(const std::string& element, const std::string& ns); + void handleCharacterData(const std::string& data); - std::string getResult() const; + std::string getResult() const; - private: - std::vector< boost::shared_ptr<XMLElement> > elementStack_; - boost::shared_ptr<XMLElement> rootElement_; - }; + private: + std::vector< std::shared_ptr<XMLElement> > elementStack_; + std::shared_ptr<XMLElement> rootElement_; + }; } diff --git a/Swiften/Parser/StanzaAckParser.cpp b/Swiften/Parser/StanzaAckParser.cpp index 1730493..42ab181 100644 --- a/Swiften/Parser/StanzaAckParser.cpp +++ b/Swiften/Parser/StanzaAckParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/StanzaAckParser.h> @@ -14,19 +14,19 @@ StanzaAckParser::StanzaAckParser() : GenericElementParser<StanzaAck>(), depth(0) } void StanzaAckParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - if (depth == 0) { - std::string handledStanzasString = attributes.getAttribute("h"); - try { - getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<int>(handledStanzasString)); - } - catch (const boost::bad_lexical_cast &) { - } - } - ++depth; + if (depth == 0) { + std::string handledStanzasString = attributes.getAttribute("h"); + try { + getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<unsigned int>(handledStanzasString)); + } + catch (const boost::bad_lexical_cast &) { + } + } + ++depth; } void StanzaAckParser::handleEndElement(const std::string&, const std::string&) { - --depth; + --depth; } } diff --git a/Swiften/Parser/StanzaAckParser.h b/Swiften/Parser/StanzaAckParser.h index c453039..7e5a75f 100644 --- a/Swiften/Parser/StanzaAckParser.h +++ b/Swiften/Parser/StanzaAckParser.h @@ -1,24 +1,24 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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/Parser/GenericElementParser.h> #include <Swiften/Elements/StanzaAck.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API StanzaAckParser : public GenericElementParser<StanzaAck> { - public: - StanzaAckParser(); + class SWIFTEN_API StanzaAckParser : public GenericElementParser<StanzaAck> { + public: + StanzaAckParser(); - virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string& ns); + virtual void handleStartElement(const std::string&, const std::string& ns, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string& ns); - private: - int depth; - }; + private: + int depth; + }; } diff --git a/Swiften/Parser/StanzaAckRequestParser.h b/Swiften/Parser/StanzaAckRequestParser.h index 9a2ccd1..9766e98 100644 --- a/Swiften/Parser/StanzaAckRequestParser.h +++ b/Swiften/Parser/StanzaAckRequestParser.h @@ -1,17 +1,18 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/StanzaAckRequest.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class StanzaAckRequestParser : public GenericElementParser<StanzaAckRequest> { - public: - StanzaAckRequestParser() : GenericElementParser<StanzaAckRequest>() {} - }; + class SWIFTEN_API StanzaAckRequestParser : public GenericElementParser<StanzaAckRequest> { + public: + StanzaAckRequestParser() : GenericElementParser<StanzaAckRequest>() {} + }; } diff --git a/Swiften/Parser/StanzaParser.cpp b/Swiften/Parser/StanzaParser.cpp index 271fbf0..8be4103 100644 --- a/Swiften/Parser/StanzaParser.cpp +++ b/Swiften/Parser/StanzaParser.cpp @@ -1,15 +1,15 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/StanzaParser.h> -#include <iostream> -#include <boost/optional.hpp> #include <cassert> +#include <boost/optional.hpp> + #include <Swiften/Parser/PayloadParser.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParserFactoryCollection.h> @@ -17,69 +17,69 @@ namespace Swift { -StanzaParser::StanzaParser(PayloadParserFactoryCollection* factories) : - currentDepth_(0), factories_(factories) { +StanzaParser::StanzaParser(PayloadParserFactoryCollection* factories) : + currentDepth_(0), factories_(factories) { } StanzaParser::~StanzaParser() { } void StanzaParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (inStanza()) { - if (!inPayload()) { - assert(!currentPayloadParser_); - PayloadParserFactory* payloadParserFactory = factories_->getPayloadParserFactory(element, ns, attributes); - if (payloadParserFactory) { - currentPayloadParser_.reset(payloadParserFactory->createPayloadParser()); - } - else { - currentPayloadParser_.reset(new UnknownPayloadParser()); - } - } - assert(currentPayloadParser_); - currentPayloadParser_->handleStartElement(element, ns, attributes); - } - else { - boost::optional<std::string> from = attributes.getAttributeValue("from"); - if (from) { - getStanza()->setFrom(JID(*from)); - } - boost::optional<std::string> to = attributes.getAttributeValue("to"); - if (to) { - getStanza()->setTo(JID(*to)); - } - boost::optional<std::string> id = attributes.getAttributeValue("id"); - if (id) { - getStanza()->setID(*id); - } - handleStanzaAttributes(attributes); - } - ++currentDepth_; + if (inStanza()) { + if (!inPayload()) { + assert(!currentPayloadParser_); + PayloadParserFactory* payloadParserFactory = factories_->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser_.reset(payloadParserFactory->createPayloadParser()); + } + else { + currentPayloadParser_.reset(new UnknownPayloadParser()); + } + } + assert(currentPayloadParser_); + currentPayloadParser_->handleStartElement(element, ns, attributes); + } + else { + boost::optional<std::string> from = attributes.getAttributeValue("from"); + if (from) { + getStanza()->setFrom(JID(*from)); + } + boost::optional<std::string> to = attributes.getAttributeValue("to"); + if (to) { + getStanza()->setTo(JID(*to)); + } + boost::optional<std::string> id = attributes.getAttributeValue("id"); + if (id) { + getStanza()->setID(*id); + } + handleStanzaAttributes(attributes); + } + ++currentDepth_; } void StanzaParser::handleEndElement(const std::string& element, const std::string& ns) { - assert(inStanza()); - if (inPayload()) { - assert(currentPayloadParser_); - currentPayloadParser_->handleEndElement(element, ns); - --currentDepth_; - if (!inPayload()) { - boost::shared_ptr<Payload> payload(currentPayloadParser_->getPayload()); - if (payload) { - getStanza()->addPayload(payload); - } - currentPayloadParser_.reset(); - } - } - else { - --currentDepth_; - } + assert(inStanza()); + if (inPayload()) { + assert(currentPayloadParser_); + currentPayloadParser_->handleEndElement(element, ns); + --currentDepth_; + if (!inPayload()) { + std::shared_ptr<Payload> payload(currentPayloadParser_->getPayload()); + if (payload) { + getStanza()->addPayload(payload); + } + currentPayloadParser_.reset(); + } + } + else { + --currentDepth_; + } } void StanzaParser::handleCharacterData(const std::string& data) { - if (currentPayloadParser_) { - currentPayloadParser_->handleCharacterData(data); - } + if (currentPayloadParser_) { + currentPayloadParser_->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/StanzaParser.h b/Swiften/Parser/StanzaParser.h index 0af6b43..7b83e99 100644 --- a/Swiften/Parser/StanzaParser.h +++ b/Swiften/Parser/StanzaParser.h @@ -1,53 +1,54 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <memory> +#include <string> + #include <boost/noncopyable.hpp> -#include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> -#include <string> #include <Swiften/Elements/Stanza.h> -#include <Swiften/Parser/ElementParser.h> #include <Swiften/Parser/AttributeMap.h> +#include <Swiften/Parser/ElementParser.h> namespace Swift { - class PayloadParser; - class PayloadParserFactoryCollection; + class PayloadParser; + class PayloadParserFactoryCollection; - class SWIFTEN_API StanzaParser : public ElementParser, public boost::noncopyable { - public: - StanzaParser(PayloadParserFactoryCollection* factories); - ~StanzaParser(); + class SWIFTEN_API StanzaParser : public ElementParser, public boost::noncopyable { + public: + StanzaParser(PayloadParserFactoryCollection* factories); + ~StanzaParser(); - void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); - void handleEndElement(const std::string& element, const std::string& ns); - void handleCharacterData(const std::string& data); + void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); + void handleEndElement(const std::string& element, const std::string& ns); + void handleCharacterData(const std::string& data); - virtual boost::shared_ptr<Element> getElement() const = 0; - virtual void handleStanzaAttributes(const AttributeMap&) {} + virtual std::shared_ptr<ToplevelElement> getElement() const = 0; + virtual void handleStanzaAttributes(const AttributeMap&) {} - virtual boost::shared_ptr<Stanza> getStanza() const { - return boost::dynamic_pointer_cast<Stanza>(getElement()); - } + virtual std::shared_ptr<Stanza> getStanza() const { + return std::dynamic_pointer_cast<Stanza>(getElement()); + } - private: - bool inPayload() const { - return currentDepth_ > 1; - } + private: + bool inPayload() const { + return currentDepth_ > 1; + } - bool inStanza() const { - return currentDepth_ > 0; - } + bool inStanza() const { + return currentDepth_ > 0; + } - private: - int currentDepth_; - PayloadParserFactoryCollection* factories_; - boost::shared_ptr<PayloadParser> currentPayloadParser_; - }; + private: + int currentDepth_; + PayloadParserFactoryCollection* factories_; + std::shared_ptr<PayloadParser> currentPayloadParser_; + }; } diff --git a/Swiften/Parser/StartTLSFailureParser.h b/Swiften/Parser/StartTLSFailureParser.h index 41ecafb..2f13e71 100644 --- a/Swiften/Parser/StartTLSFailureParser.h +++ b/Swiften/Parser/StartTLSFailureParser.h @@ -1,17 +1,18 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/StartTLSFailure.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class StartTLSFailureParser : public GenericElementParser<StartTLSFailure> { - public: - StartTLSFailureParser() : GenericElementParser<StartTLSFailure>() {} - }; + class SWIFTEN_API StartTLSFailureParser : public GenericElementParser<StartTLSFailure> { + public: + StartTLSFailureParser() : GenericElementParser<StartTLSFailure>() {} + }; } diff --git a/Swiften/Parser/StartTLSParser.h b/Swiften/Parser/StartTLSParser.h index 9bc7576..f769d4d 100644 --- a/Swiften/Parser/StartTLSParser.h +++ b/Swiften/Parser/StartTLSParser.h @@ -1,17 +1,18 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/StartTLSRequest.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class StartTLSParser : public GenericElementParser<StartTLSRequest> { - public: - StartTLSParser() : GenericElementParser<StartTLSRequest>() {} - }; + class SWIFTEN_API StartTLSParser : public GenericElementParser<StartTLSRequest> { + public: + StartTLSParser() : GenericElementParser<StartTLSRequest>() {} + }; } diff --git a/Swiften/Parser/StreamErrorParser.cpp b/Swiften/Parser/StreamErrorParser.cpp index f4530f9..e89af58 100644 --- a/Swiften/Parser/StreamErrorParser.cpp +++ b/Swiften/Parser/StreamErrorParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/StreamErrorParser.h> @@ -12,98 +12,98 @@ StreamErrorParser::StreamErrorParser() : level(TopLevel) { } void StreamErrorParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { - ++level; + ++level; } void StreamErrorParser::handleEndElement(const std::string& element, const std::string& ns) { - --level; - if (level == ElementLevel && ns == "urn:ietf:params:xml:ns:xmpp-streams") { - if (element == "text") { - getElementGeneric()->setText(currentText); - } - else if (element == "bad-format") { - getElementGeneric()->setType(StreamError::BadFormat); - } - else if(element == "bad-namespace-prefix") { - getElementGeneric()->setType(StreamError::BadNamespacePrefix); - } - else if(element == "conflict") { - getElementGeneric()->setType(StreamError::Conflict); - } - else if(element == "connection-timeout") { - getElementGeneric()->setType(StreamError::ConnectionTimeout); - } - else if(element == "host-gone") { - getElementGeneric()->setType(StreamError::HostGone); - } - else if(element == "host-unknown") { - getElementGeneric()->setType(StreamError::HostUnknown); - } - else if(element == "improper-addressing") { - getElementGeneric()->setType(StreamError::ImproperAddressing); - } - else if(element == "internal-server-error") { - getElementGeneric()->setType(StreamError::InternalServerError); - } - else if(element == "invalid-from") { - getElementGeneric()->setType(StreamError::InvalidFrom); - } - else if(element == "invalid-id") { - getElementGeneric()->setType(StreamError::InvalidID); - } - else if(element == "invalid-namespace") { - getElementGeneric()->setType(StreamError::InvalidNamespace); - } - else if(element == "invalid-xml") { - getElementGeneric()->setType(StreamError::InvalidXML); - } - else if(element == "not-authorized") { - getElementGeneric()->setType(StreamError::NotAuthorized); - } - else if(element == "not-well-formed") { - getElementGeneric()->setType(StreamError::NotWellFormed); - } - else if(element == "policy-violation") { - getElementGeneric()->setType(StreamError::PolicyViolation); - } - else if(element == "remote-connection-failed") { - getElementGeneric()->setType(StreamError::RemoteConnectionFailed); - } - else if(element == "reset") { - getElementGeneric()->setType(StreamError::Reset); - } - else if(element == "resource-constraint") { - getElementGeneric()->setType(StreamError::ResourceConstraint); - } - else if(element == "restricted-xml") { - getElementGeneric()->setType(StreamError::RestrictedXML); - } - else if(element == "see-other-host") { - getElementGeneric()->setType(StreamError::SeeOtherHost); - } - else if(element == "system-shutdown") { - getElementGeneric()->setType(StreamError::SystemShutdown); - } - else if(element == "undefined-condition") { - getElementGeneric()->setType(StreamError::UndefinedCondition); - } - else if(element == "unsupported-encoding") { - getElementGeneric()->setType(StreamError::UnsupportedEncoding); - } - else if(element == "unsupported-stanza-type") { - getElementGeneric()->setType(StreamError::UnsupportedStanzaType); - } - else if(element == "unsupported-version") { - getElementGeneric()->setType(StreamError::UnsupportedVersion); - } - else { - getElementGeneric()->setType(StreamError::UndefinedCondition); - } - } + --level; + if (level == ElementLevel && ns == "urn:ietf:params:xml:ns:xmpp-streams") { + if (element == "text") { + getElementGeneric()->setText(currentText); + } + else if (element == "bad-format") { + getElementGeneric()->setType(StreamError::BadFormat); + } + else if(element == "bad-namespace-prefix") { + getElementGeneric()->setType(StreamError::BadNamespacePrefix); + } + else if(element == "conflict") { + getElementGeneric()->setType(StreamError::Conflict); + } + else if(element == "connection-timeout") { + getElementGeneric()->setType(StreamError::ConnectionTimeout); + } + else if(element == "host-gone") { + getElementGeneric()->setType(StreamError::HostGone); + } + else if(element == "host-unknown") { + getElementGeneric()->setType(StreamError::HostUnknown); + } + else if(element == "improper-addressing") { + getElementGeneric()->setType(StreamError::ImproperAddressing); + } + else if(element == "internal-server-error") { + getElementGeneric()->setType(StreamError::InternalServerError); + } + else if(element == "invalid-from") { + getElementGeneric()->setType(StreamError::InvalidFrom); + } + else if(element == "invalid-namespace") { + getElementGeneric()->setType(StreamError::InvalidNamespace); + } + else if(element == "invalid-xml") { + getElementGeneric()->setType(StreamError::InvalidXML); + } + else if(element == "not-authorized") { + getElementGeneric()->setType(StreamError::NotAuthorized); + } + else if(element == "not-well-formed") { + getElementGeneric()->setType(StreamError::NotWellFormed); + } + else if(element == "policy-violation") { + getElementGeneric()->setType(StreamError::PolicyViolation); + } + else if(element == "remote-connection-failed") { + getElementGeneric()->setType(StreamError::RemoteConnectionFailed); + } + else if(element == "reset") { + getElementGeneric()->setType(StreamError::Reset); + } + else if(element == "resource-constraint") { + getElementGeneric()->setType(StreamError::ResourceConstraint); + } + else if(element == "restricted-xml") { + getElementGeneric()->setType(StreamError::RestrictedXML); + } + else if(element == "see-other-host") { + getElementGeneric()->setType(StreamError::SeeOtherHost); + } + else if(element == "system-shutdown") { + getElementGeneric()->setType(StreamError::SystemShutdown); + } + else if(element == "undefined-condition") { + getElementGeneric()->setType(StreamError::UndefinedCondition); + } + else if(element == "unsupported-encoding") { + getElementGeneric()->setType(StreamError::UnsupportedEncoding); + } + else if(element == "unsupported-feature") { + getElementGeneric()->setType(StreamError::UnsupportedFeature); + } + else if(element == "unsupported-stanza-type") { + getElementGeneric()->setType(StreamError::UnsupportedStanzaType); + } + else if(element == "unsupported-version") { + getElementGeneric()->setType(StreamError::UnsupportedVersion); + } + else { + getElementGeneric()->setType(StreamError::UndefinedCondition); + } + } } void StreamErrorParser::handleCharacterData(const std::string& data) { - currentText += data; + currentText += data; } } diff --git a/Swiften/Parser/StreamErrorParser.h b/Swiften/Parser/StreamErrorParser.h index 61c8c12..27efc86 100644 --- a/Swiften/Parser/StreamErrorParser.h +++ b/Swiften/Parser/StreamErrorParser.h @@ -1,29 +1,30 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/StreamError.h> #include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class StreamErrorParser : public GenericElementParser<StreamError> { - public: - StreamErrorParser(); + class SWIFTEN_API StreamErrorParser : public GenericElementParser<StreamError> { + public: + StreamErrorParser(); - 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, - ElementLevel = 1 - }; - int level; - std::string currentText; - }; + private: + enum Level { + TopLevel = 0, + ElementLevel = 1 + }; + int level; + std::string currentText; + }; } diff --git a/Swiften/Parser/StreamFeaturesParser.cpp b/Swiften/Parser/StreamFeaturesParser.cpp index 6a527ce..ce99a1e 100644 --- a/Swiften/Parser/StreamFeaturesParser.cpp +++ b/Swiften/Parser/StreamFeaturesParser.cpp @@ -1,73 +1,82 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/StreamFeaturesParser.h> namespace Swift { -StreamFeaturesParser::StreamFeaturesParser() : GenericElementParser<StreamFeatures>(), currentDepth_(0), inMechanisms_(false), inMechanism_(false), inCompression_(false), inCompressionMethod_(false) { +StreamFeaturesParser::StreamFeaturesParser() : GenericElementParser<StreamFeatures>(), currentDepth_(0), inMechanisms_(false), inMechanism_(false), inAuthenticationHostname_(false), inCompression_(false), inCompressionMethod_(false) { } void StreamFeaturesParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap&) { - if (currentDepth_ == 1) { - if (element == "starttls" && ns == "urn:ietf:params:xml:ns:xmpp-tls") { - getElementGeneric()->setHasStartTLS(); - } - else if (element == "session" && ns == "urn:ietf:params:xml:ns:xmpp-session") { - getElementGeneric()->setHasSession(); - } - else if (element == "bind" && ns == "urn:ietf:params:xml:ns:xmpp-bind") { - getElementGeneric()->setHasResourceBind(); - } - else if (element == "sm" && ns == "urn:xmpp:sm:2") { - getElementGeneric()->setHasStreamManagement(); - } - else if (element == "mechanisms" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { - inMechanisms_ = true; - } - else if (element == "compression" && ns == "http://jabber.org/features/compress") { - inCompression_ = true; - } - else if (element == "ver" && ns == "urn:xmpp:features:rosterver") { - getElementGeneric()->setHasRosterVersioning(); - } - } - else if (currentDepth_ == 2) { - if (inCompression_ && element == "method") { - inCompressionMethod_ = true; - currentText_ = ""; - } - else if (inMechanisms_ && element == "mechanism") { - inMechanism_ = true; - currentText_ = ""; - } - } - ++currentDepth_; + if (currentDepth_ == 1) { + if (element == "starttls" && ns == "urn:ietf:params:xml:ns:xmpp-tls") { + getElementGeneric()->setHasStartTLS(); + } + else if (element == "session" && ns == "urn:ietf:params:xml:ns:xmpp-session") { + getElementGeneric()->setHasSession(); + } + else if (element == "bind" && ns == "urn:ietf:params:xml:ns:xmpp-bind") { + getElementGeneric()->setHasResourceBind(); + } + else if (element == "sm" && ns == "urn:xmpp:sm:2") { + getElementGeneric()->setHasStreamManagement(); + } + else if (element == "mechanisms" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { + inMechanisms_ = true; + } + else if (element == "compression" && ns == "http://jabber.org/features/compress") { + inCompression_ = true; + } + else if (element == "ver" && ns == "urn:xmpp:features:rosterver") { + getElementGeneric()->setHasRosterVersioning(); + } + } + else if (currentDepth_ == 2) { + if (inCompression_ && element == "method") { + inCompressionMethod_ = true; + currentText_ = ""; + } + else if (inMechanisms_ && element == "mechanism") { + inMechanism_ = true; + currentText_ = ""; + } + else if (inMechanisms_ && element == "hostname" && ns == "urn:xmpp:domain-based-name:1") { + inAuthenticationHostname_ = true; + currentText_ = ""; + } + + } + ++currentDepth_; } void StreamFeaturesParser::handleEndElement(const std::string&, const std::string&) { - --currentDepth_; - if (currentDepth_ == 1) { - inCompression_ = false; - inMechanisms_ = false; - } - else if (currentDepth_ == 2) { - if (inCompressionMethod_) { - getElementGeneric()->addCompressionMethod(currentText_); - inCompressionMethod_ = false; - } - else if (inMechanism_) { - getElementGeneric()->addAuthenticationMechanism(currentText_); - inMechanism_ = false; - } - } + --currentDepth_; + if (currentDepth_ == 1) { + inCompression_ = false; + inMechanisms_ = false; + } + else if (currentDepth_ == 2) { + if (inCompressionMethod_) { + getElementGeneric()->addCompressionMethod(currentText_); + inCompressionMethod_ = false; + } + else if (inMechanism_) { + getElementGeneric()->addAuthenticationMechanism(currentText_); + inMechanism_ = false; + } + else if (inAuthenticationHostname_) { + getElementGeneric()->setAuthenticationHostname(currentText_); + inAuthenticationHostname_ = false; + } + } } void StreamFeaturesParser::handleCharacterData(const std::string& data) { - currentText_ += data; + currentText_ += data; } } diff --git a/Swiften/Parser/StreamFeaturesParser.h b/Swiften/Parser/StreamFeaturesParser.h index 4bbb31c..5af8de8 100644 --- a/Swiften/Parser/StreamFeaturesParser.h +++ b/Swiften/Parser/StreamFeaturesParser.h @@ -1,32 +1,34 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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/GenericElementParser.h> #include <Swiften/Elements/StreamFeatures.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API StreamFeaturesParser : public GenericElementParser<StreamFeatures> { - public: - StreamFeaturesParser(); + class SWIFTEN_API StreamFeaturesParser : public GenericElementParser<StreamFeatures> { + public: + StreamFeaturesParser(); - private: - void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); - void handleEndElement(const std::string& element, const std::string& ns); - void handleCharacterData(const std::string& data); + private: + void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); + void handleEndElement(const std::string& element, const std::string& ns); + void handleCharacterData(const std::string& data); - private: - int currentDepth_; - std::string currentText_; - bool inMechanisms_; - bool inMechanism_; - bool inCompression_; - bool inCompressionMethod_; - }; + private: + int currentDepth_; + std::string currentText_; + bool inMechanisms_; + bool inMechanism_; + bool inAuthenticationHostname_; + bool inCompression_; + bool inCompressionMethod_; + }; } diff --git a/Swiften/Parser/StreamManagementEnabledParser.cpp b/Swiften/Parser/StreamManagementEnabledParser.cpp index 906e071..9e87d65 100644 --- a/Swiften/Parser/StreamManagementEnabledParser.cpp +++ b/Swiften/Parser/StreamManagementEnabledParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/StreamManagementEnabledParser.h> @@ -15,15 +15,15 @@ StreamManagementEnabledParser::~StreamManagementEnabledParser() { } void StreamManagementEnabledParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - if (level == TopLevel) { - if (attributes.getBoolAttribute("resume", false)) { - getElementGeneric()->setResumeSupported(); - } - getElementGeneric()->setResumeID(attributes.getAttribute("id")); - } - ++level; + if (level == TopLevel) { + if (attributes.getBoolAttribute("resume", false)) { + getElementGeneric()->setResumeSupported(); + } + getElementGeneric()->setResumeID(attributes.getAttribute("id")); + } + ++level; } void StreamManagementEnabledParser::handleEndElement(const std::string&, const std::string&) { - --level; + --level; } diff --git a/Swiften/Parser/StreamManagementEnabledParser.h b/Swiften/Parser/StreamManagementEnabledParser.h index dfe232c..0f75071 100644 --- a/Swiften/Parser/StreamManagementEnabledParser.h +++ b/Swiften/Parser/StreamManagementEnabledParser.h @@ -1,28 +1,28 @@ /* - * Copyright (c) 2010-2011 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> -#include <Swiften/Elements/StreamManagementEnabled.h> #include <Swiften/Base/API.h> +#include <Swiften/Elements/StreamManagementEnabled.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class SWIFTEN_API StreamManagementEnabledParser : public GenericElementParser<StreamManagementEnabled> { - public: - StreamManagementEnabledParser(); - ~StreamManagementEnabledParser(); + class SWIFTEN_API StreamManagementEnabledParser : public GenericElementParser<StreamManagementEnabled> { + public: + StreamManagementEnabledParser(); + ~StreamManagementEnabledParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); - private: - enum Level { - TopLevel = 0 - }; - int level; - }; + private: + enum Level { + TopLevel = 0 + }; + int level; + }; } diff --git a/Swiften/Parser/StreamManagementFailedParser.h b/Swiften/Parser/StreamManagementFailedParser.h index 6c111d0..c87beee 100644 --- a/Swiften/Parser/StreamManagementFailedParser.h +++ b/Swiften/Parser/StreamManagementFailedParser.h @@ -1,17 +1,18 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/StreamManagementFailed.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class StreamManagementFailedParser : public GenericElementParser<StreamManagementFailed> { - public: - StreamManagementFailedParser() : GenericElementParser<StreamManagementFailed>() {} - }; + class SWIFTEN_API StreamManagementFailedParser : public GenericElementParser<StreamManagementFailed> { + public: + StreamManagementFailedParser() : GenericElementParser<StreamManagementFailed>() {} + }; } diff --git a/Swiften/Parser/StreamResumeParser.cpp b/Swiften/Parser/StreamResumeParser.cpp index cb1a61d..a6ca444 100644 --- a/Swiften/Parser/StreamResumeParser.cpp +++ b/Swiften/Parser/StreamResumeParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/StreamResumeParser.h> @@ -17,20 +17,20 @@ StreamResumeParser::~StreamResumeParser() { } void StreamResumeParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - if (level == TopLevel) { - boost::optional<std::string> handledStanzasCount = attributes.getAttributeValue("h"); - if (handledStanzasCount) { - try { - getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<unsigned int>(*handledStanzasCount)); - } - catch (const boost::bad_lexical_cast &) { - } - } - getElementGeneric()->setResumeID(attributes.getAttribute("previd")); - } - ++level; + if (level == TopLevel) { + boost::optional<std::string> handledStanzasCount = attributes.getAttributeValue("h"); + if (handledStanzasCount) { + try { + getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<unsigned int>(*handledStanzasCount)); + } + catch (const boost::bad_lexical_cast &) { + } + } + getElementGeneric()->setResumeID(attributes.getAttribute("previd")); + } + ++level; } void StreamResumeParser::handleEndElement(const std::string&, const std::string&) { - --level; + --level; } diff --git a/Swiften/Parser/StreamResumeParser.h b/Swiften/Parser/StreamResumeParser.h index 0ccd24c..d3d2498 100644 --- a/Swiften/Parser/StreamResumeParser.h +++ b/Swiften/Parser/StreamResumeParser.h @@ -1,27 +1,28 @@ /* - * Copyright (c) 2011 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/StreamResume.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class StreamResumeParser : public GenericElementParser<StreamResume> { - public: - StreamResumeParser(); - ~StreamResumeParser(); + class SWIFTEN_API StreamResumeParser : public GenericElementParser<StreamResume> { + public: + StreamResumeParser(); + ~StreamResumeParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); - private: - enum Level { - TopLevel = 0 - }; - int level; - }; + private: + enum Level { + TopLevel = 0 + }; + int level; + }; } diff --git a/Swiften/Parser/StreamResumedParser.cpp b/Swiften/Parser/StreamResumedParser.cpp index 4b39c04..f69bad1 100644 --- a/Swiften/Parser/StreamResumedParser.cpp +++ b/Swiften/Parser/StreamResumedParser.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/StreamResumedParser.h> @@ -17,20 +17,20 @@ StreamResumedParser::~StreamResumedParser() { } void StreamResumedParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { - if (level == TopLevel) { - boost::optional<std::string> handledStanzasCount = attributes.getAttributeValue("h"); - if (handledStanzasCount) { - try { - getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<unsigned int>(*handledStanzasCount)); - } - catch (const boost::bad_lexical_cast &) { - } - } - getElementGeneric()->setResumeID(attributes.getAttribute("previd")); - } - ++level; + if (level == TopLevel) { + boost::optional<std::string> handledStanzasCount = attributes.getAttributeValue("h"); + if (handledStanzasCount) { + try { + getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<unsigned int>(*handledStanzasCount)); + } + catch (const boost::bad_lexical_cast &) { + } + } + getElementGeneric()->setResumeID(attributes.getAttribute("previd")); + } + ++level; } void StreamResumedParser::handleEndElement(const std::string&, const std::string&) { - --level; + --level; } diff --git a/Swiften/Parser/StreamResumedParser.h b/Swiften/Parser/StreamResumedParser.h index f2377aa..ca89597 100644 --- a/Swiften/Parser/StreamResumedParser.h +++ b/Swiften/Parser/StreamResumedParser.h @@ -1,27 +1,28 @@ /* - * Copyright (c) 2011 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/StreamResumed.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class StreamResumedParser : public GenericElementParser<StreamResumed> { - public: - StreamResumedParser(); - ~StreamResumedParser(); + class SWIFTEN_API StreamResumedParser : public GenericElementParser<StreamResumed> { + public: + StreamResumedParser(); + ~StreamResumedParser(); - virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); - virtual void handleEndElement(const std::string&, const std::string&); + virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&); + virtual void handleEndElement(const std::string&, const std::string&); - private: - enum Level { - TopLevel = 0 - }; - int level; - }; + private: + enum Level { + TopLevel = 0 + }; + int level; + }; } diff --git a/Swiften/Parser/TLSProceedParser.h b/Swiften/Parser/TLSProceedParser.h index d36f088..da6cfd1 100644 --- a/Swiften/Parser/TLSProceedParser.h +++ b/Swiften/Parser/TLSProceedParser.h @@ -1,17 +1,18 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/TLSProceed.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class TLSProceedParser : public GenericElementParser<TLSProceed> { - public: - TLSProceedParser() : GenericElementParser<TLSProceed>() {} - }; + class SWIFTEN_API TLSProceedParser : public GenericElementParser<TLSProceed> { + public: + TLSProceedParser() : GenericElementParser<TLSProceed>() {} + }; } diff --git a/Swiften/Parser/Tree/NullParserElement.cpp b/Swiften/Parser/Tree/NullParserElement.cpp index 7dda9c3..7b52926 100644 --- a/Swiften/Parser/Tree/NullParserElement.cpp +++ b/Swiften/Parser/Tree/NullParserElement.cpp @@ -1,13 +1,13 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/Tree/NullParserElement.h> namespace Swift { -boost::shared_ptr<NullParserElement> NullParserElement::element = boost::make_shared<NullParserElement>(); +std::shared_ptr<NullParserElement> NullParserElement::element = std::make_shared<NullParserElement>(); } diff --git a/Swiften/Parser/Tree/NullParserElement.h b/Swiften/Parser/Tree/NullParserElement.h index 8dd9bc1..320e098 100644 --- a/Swiften/Parser/Tree/NullParserElement.h +++ b/Swiften/Parser/Tree/NullParserElement.h @@ -1,21 +1,23 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-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/Tree/ParserElement.h> namespace Swift { - class NullParserElement : public ParserElement { - public: - NullParserElement() : ParserElement("", "", AttributeMap()) {} + class SWIFTEN_API NullParserElement : public ParserElement { + public: + NullParserElement() : ParserElement("", "", AttributeMap()) {} - virtual operator bool() { return false; } + virtual operator bool() { return false; } - static boost::shared_ptr<NullParserElement> element; - }; + static std::shared_ptr<NullParserElement> element; + }; } diff --git a/Swiften/Parser/Tree/ParserElement.cpp b/Swiften/Parser/Tree/ParserElement.cpp index e5f8bc8..988bc13 100644 --- a/Swiften/Parser/Tree/ParserElement.cpp +++ b/Swiften/Parser/Tree/ParserElement.cpp @@ -1,18 +1,13 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/Tree/ParserElement.h> -#include <Swiften/Parser/Tree/NullParserElement.h> - -#include <iostream> -#include <boost/lambda/lambda.hpp> -#include <boost/lambda/bind.hpp> -namespace lambda = boost::lambda; +#include <Swiften/Parser/Tree/NullParserElement.h> namespace Swift { @@ -23,26 +18,27 @@ ParserElement::~ParserElement() { } ParserElement::ref ParserElement::addChild(const std::string& name, const std::string& xmlns, const AttributeMap& attributes) { - ParserElement::ref child = boost::make_shared<ParserElement>(name, xmlns, attributes); - children_.push_back(child); - return child; + ParserElement::ref child = std::make_shared<ParserElement>(name, xmlns, attributes); + children_.push_back(child); + return child; } void ParserElement::appendCharacterData(const std::string& data) { - text_ += data; + text_ += data; } std::vector<ParserElement::ref> ParserElement::getChildren(const std::string& name, const std::string& xmlns) const { - std::vector<ParserElement::ref> result; - std::remove_copy_if(children_.begin(), children_.end(), std::back_inserter(result), - lambda::bind(&ParserElement::getName, *lambda::_1) != name || lambda::bind(&ParserElement::getNamespace, *lambda::_1) != xmlns); - return result; + std::vector<ParserElement::ref> result; + std::remove_copy_if(children_.begin(), children_.end(), std::back_inserter(result), [&](const ParserElement::ref& element) { + return (element->getName() != name) || (element->getNamespace() != xmlns); + }); + return result; } ParserElement::ref ParserElement::getChild(const std::string& name, const std::string& xmlns) const { - std::vector<ParserElement::ref> results = getChildren(name, xmlns); - ParserElement::ref result = results.empty() ? NullParserElement::element : results[0]; - return result; + std::vector<ParserElement::ref> results = getChildren(name, xmlns); + ParserElement::ref result = results.empty() ? NullParserElement::element : results[0]; + return result; } } diff --git a/Swiften/Parser/Tree/ParserElement.h b/Swiften/Parser/Tree/ParserElement.h index 6be0631..38f2dee 100644 --- a/Swiften/Parser/Tree/ParserElement.h +++ b/Swiften/Parser/Tree/ParserElement.h @@ -1,49 +1,50 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <memory> #include <string> #include <vector> + +#include <boost/signals2.hpp> + #include <Swiften/Base/API.h> -#include <Swiften/Base/boost_bsignals.h> #include <Swiften/Parser/AttributeMap.h> -#include <boost/shared_ptr.hpp> -#include <boost/smart_ptr/make_shared.hpp> namespace Swift { - class SWIFTEN_API ParserElement { - public: - typedef boost::shared_ptr<ParserElement> ref; - - ParserElement(const std::string& name, const std::string& xmlns, const AttributeMap& attributes); - virtual ~ParserElement(); - - const std::string& getText() const { return text_; } - const std::string& getName() const { return name_; } - const std::string& getNamespace() const { return xmlns_; } - const AttributeMap& getAttributes() const { return attributes_; } - - ParserElement::ref addChild(const std::string& name, const std::string& xmlns, const AttributeMap& attributes); - void appendCharacterData(const std::string& data); - - std::vector<ParserElement::ref> getChildren(const std::string& name, const std::string& xmlns) const; - const std::vector<ParserElement::ref>& getAllChildren() const {return children_;} - ParserElement::ref getChild(const std::string& name, const std::string& xmlns) const; - - virtual operator bool() { - return true; - } - - private: - std::vector<ParserElement::ref> children_; - std::string name_; - std::string xmlns_; - AttributeMap attributes_; - std::string text_; - }; + class SWIFTEN_API ParserElement { + public: + typedef std::shared_ptr<ParserElement> ref; + + ParserElement(const std::string& name, const std::string& xmlns, const AttributeMap& attributes); + virtual ~ParserElement(); + + const std::string& getText() const { return text_; } + const std::string& getName() const { return name_; } + const std::string& getNamespace() const { return xmlns_; } + const AttributeMap& getAttributes() const { return attributes_; } + + ParserElement::ref addChild(const std::string& name, const std::string& xmlns, const AttributeMap& attributes); + void appendCharacterData(const std::string& data); + + std::vector<ParserElement::ref> getChildren(const std::string& name, const std::string& xmlns) const; + const std::vector<ParserElement::ref>& getAllChildren() const {return children_;} + ParserElement::ref getChild(const std::string& name, const std::string& xmlns) const; + + virtual operator bool() { + return true; + } + + private: + std::vector<ParserElement::ref> children_; + std::string name_; + std::string xmlns_; + AttributeMap attributes_; + std::string text_; + }; } diff --git a/Swiften/Parser/Tree/TreeReparser.cpp b/Swiften/Parser/Tree/TreeReparser.cpp index 9d09831..6993d73 100644 --- a/Swiften/Parser/Tree/TreeReparser.cpp +++ b/Swiften/Parser/Tree/TreeReparser.cpp @@ -1,48 +1,48 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/Tree/TreeReparser.h> -#include <boost/lexical_cast.hpp> -#include <utility> #include <deque> +#include <utility> + +#include <boost/lexical_cast.hpp> -#include <Swiften/Parser/PayloadParserFactoryCollection.h> -#include <Swiften/Parser/PayloadParserFactory.h> -#include <Swiften/Parser/PayloadParser.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Elements/MUCOccupant.h> +#include <Swiften/Parser/PayloadParser.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> namespace Swift { typedef std::pair<ParserElement::ref, bool> ElementState; -boost::shared_ptr<Payload> TreeReparser::parseTree(ParserElement::ref root, PayloadParserFactoryCollection* collection) { - PayloadParser* parser = collection->getPayloadParserFactory(root->getName(), root->getNamespace(), root->getAttributes())->createPayloadParser(); - std::deque<ElementState > stack; - stack.push_back(ElementState(root, true)); - while (!stack.empty()) { - ElementState current = stack.back(); - stack.pop_back(); - if (current.second) { - stack.push_back(ElementState(current.first, false)); - parser->handleStartElement(current.first->getName(), current.first->getNamespace(), current.first->getAttributes()); - foreach(ParserElement::ref child, current.first->getAllChildren()) { - stack.push_back(ElementState(child, true)); - } - } else { - parser->handleCharacterData(current.first->getText()); - parser->handleEndElement(current.first->getName(), current.first->getNamespace()); - } - - } - - boost::shared_ptr<Payload> payload = parser->getPayload(); - delete parser; - return payload; +std::shared_ptr<Payload> TreeReparser::parseTree(ParserElement::ref root, PayloadParserFactoryCollection* collection) { + PayloadParser* parser = collection->getPayloadParserFactory(root->getName(), root->getNamespace(), root->getAttributes())->createPayloadParser(); + std::deque<ElementState > stack; + stack.push_back(ElementState(root, true)); + while (!stack.empty()) { + ElementState current = stack.back(); + stack.pop_back(); + if (current.second) { + stack.push_back(ElementState(current.first, false)); + parser->handleStartElement(current.first->getName(), current.first->getNamespace(), current.first->getAttributes()); + for (const auto& child : current.first->getAllChildren()) { + stack.push_back(ElementState(child, true)); + } + } else { + parser->handleCharacterData(current.first->getText()); + parser->handleEndElement(current.first->getName(), current.first->getNamespace()); + } + + } + + std::shared_ptr<Payload> payload = parser->getPayload(); + delete parser; + return payload; } } diff --git a/Swiften/Parser/Tree/TreeReparser.h b/Swiften/Parser/Tree/TreeReparser.h index 212c518..435922b 100644 --- a/Swiften/Parser/Tree/TreeReparser.h +++ b/Swiften/Parser/Tree/TreeReparser.h @@ -1,19 +1,20 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/GenericPayloadTreeParser.h> #include <Swiften/Parser/PayloadParsers/MUCItemParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class TreeReparser { - public: - static boost::shared_ptr<Payload> parseTree(ParserElement::ref root, PayloadParserFactoryCollection* collection); + class PayloadParserFactoryCollection; + class SWIFTEN_API TreeReparser { + public: + static std::shared_ptr<Payload> parseTree(ParserElement::ref root, PayloadParserFactoryCollection* collection); - }; + }; } diff --git a/Swiften/Parser/UnitTest/AttributeMapTest.cpp b/Swiften/Parser/UnitTest/AttributeMapTest.cpp index d6c3c01..d9335c1 100644 --- a/Swiften/Parser/UnitTest/AttributeMapTest.cpp +++ b/Swiften/Parser/UnitTest/AttributeMapTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -13,73 +13,90 @@ using namespace Swift; class AttributeMapTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(AttributeMapTest); - CPPUNIT_TEST(testGetAttribute_Namespaced); - CPPUNIT_TEST(testGetBoolAttribute_True); - CPPUNIT_TEST(testGetBoolAttribute_1); - CPPUNIT_TEST(testGetBoolAttribute_False); - CPPUNIT_TEST(testGetBoolAttribute_0); - CPPUNIT_TEST(testGetBoolAttribute_Invalid); - CPPUNIT_TEST(testGetBoolAttribute_UnknownWithDefaultTrue); - CPPUNIT_TEST(testGetBoolAttribute_UnknownWithDefaultFalse); - CPPUNIT_TEST_SUITE_END(); - - public: - void testGetAttribute_Namespaced() { - AttributeMap testling; - testling.addAttribute("lang", "", "nl"); - testling.addAttribute("lang", "http://www.w3.org/XML/1998/namespace", "en"); - testling.addAttribute("lang", "", "fr"); - - CPPUNIT_ASSERT_EQUAL(std::string("en"), testling.getAttribute("lang", "http://www.w3.org/XML/1998/namespace")); - } - - void testGetBoolAttribute_True() { - AttributeMap testling; - testling.addAttribute("foo", "", "true"); - - CPPUNIT_ASSERT(testling.getBoolAttribute("foo")); - } - - void testGetBoolAttribute_1() { - AttributeMap testling; - testling.addAttribute("foo", "", "1"); - - CPPUNIT_ASSERT(testling.getBoolAttribute("foo")); - } - - void testGetBoolAttribute_False() { - AttributeMap testling; - testling.addAttribute("foo", "", "false"); - - CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); - } - - void testGetBoolAttribute_0() { - AttributeMap testling; - testling.addAttribute("foo", "", "0"); - - CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); - } - - void testGetBoolAttribute_Invalid() { - AttributeMap testling; - testling.addAttribute("foo", "", "bla"); - - CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); - } - - void testGetBoolAttribute_UnknownWithDefaultTrue() { - AttributeMap testling; - - CPPUNIT_ASSERT(testling.getBoolAttribute("foo", true)); - } - - void testGetBoolAttribute_UnknownWithDefaultFalse() { - AttributeMap testling; - - CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", false)); - } + CPPUNIT_TEST_SUITE(AttributeMapTest); + CPPUNIT_TEST(testGetAttribute_Namespaced); + CPPUNIT_TEST(testGetAttribute_Namespaced_Prefix); + CPPUNIT_TEST(testGetBoolAttribute_True); + CPPUNIT_TEST(testGetBoolAttribute_1); + CPPUNIT_TEST(testGetBoolAttribute_False); + CPPUNIT_TEST(testGetBoolAttribute_0); + CPPUNIT_TEST(testGetBoolAttribute_Invalid); + CPPUNIT_TEST(testGetBoolAttribute_UnknownWithDefaultTrue); + CPPUNIT_TEST(testGetBoolAttribute_UnknownWithDefaultFalse); + CPPUNIT_TEST_SUITE_END(); + + public: + void testGetAttribute_Namespaced() { + AttributeMap testling; + testling.addAttribute("lang", "", "nl"); + testling.addAttribute("lang", "http://www.w3.org/XML/1998/namespace", "en"); + testling.addAttribute("lang", "", "fr"); + + CPPUNIT_ASSERT_EQUAL(std::string("en"), testling.getAttribute("lang", "http://www.w3.org/XML/1998/namespace")); + } + + void testGetAttribute_Namespaced_Prefix() { + AttributeMap testling; + testling.addAttribute("lang", "", "prefix", "nl"); + testling.addAttribute("lang", "http://www.w3.org/XML/1998/namespace", "prefix", "en"); + testling.addAttribute("lang", "", "prefix", "fr"); + + CPPUNIT_ASSERT_EQUAL(std::string("en"), testling.getAttribute("lang", "http://www.w3.org/XML/1998/namespace")); + const auto& entries = testling.getEntries(); + auto it = std::find_if(entries.begin(), entries.end(), [](const AttributeMap::Entry& e) { + return e.getValue() == "en"; + }); + const bool found = it != entries.end(); + CPPUNIT_ASSERT_EQUAL(true, found); + CPPUNIT_ASSERT_EQUAL(std::string("prefix"), it->getAttribute().getPrefix()); + } + + void testGetBoolAttribute_True() { + AttributeMap testling; + testling.addAttribute("foo", "", "true"); + + CPPUNIT_ASSERT(testling.getBoolAttribute("foo")); + } + + void testGetBoolAttribute_1() { + AttributeMap testling; + testling.addAttribute("foo", "", "1"); + + CPPUNIT_ASSERT(testling.getBoolAttribute("foo")); + } + + void testGetBoolAttribute_False() { + AttributeMap testling; + testling.addAttribute("foo", "", "false"); + + CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); + } + + void testGetBoolAttribute_0() { + AttributeMap testling; + testling.addAttribute("foo", "", "0"); + + CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); + } + + void testGetBoolAttribute_Invalid() { + AttributeMap testling; + testling.addAttribute("foo", "", "bla"); + + CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", true)); + } + + void testGetBoolAttribute_UnknownWithDefaultTrue() { + AttributeMap testling; + + CPPUNIT_ASSERT(testling.getBoolAttribute("foo", true)); + } + + void testGetBoolAttribute_UnknownWithDefaultFalse() { + AttributeMap testling; + + CPPUNIT_ASSERT(!testling.getBoolAttribute("foo", false)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(AttributeMapTest); diff --git a/Swiften/Parser/UnitTest/BOSHBodyExtractorTest.cpp b/Swiften/Parser/UnitTest/BOSHBodyExtractorTest.cpp index fc7d17b..f7ed80f 100644 --- a/Swiften/Parser/UnitTest/BOSHBodyExtractorTest.cpp +++ b/Swiften/Parser/UnitTest/BOSHBodyExtractorTest.cpp @@ -1,104 +1,104 @@ /* - * Copyright (c) 2011 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <Swiften/Parser/PlatformXMLParserFactory.h> #include <Swiften/Parser/BOSHBodyExtractor.h> +#include <Swiften/Parser/PlatformXMLParserFactory.h> using namespace Swift; class BOSHBodyExtractorTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(BOSHBodyExtractorTest); - CPPUNIT_TEST(testGetBody); - CPPUNIT_TEST(testGetBody_EmptyContent); - CPPUNIT_TEST(testGetBody_EmptyContent2); - CPPUNIT_TEST(testGetBody_EmptyElementEmptyContent); - CPPUNIT_TEST(testGetBody_InvalidStartTag); - CPPUNIT_TEST(testGetBody_InvalidStartTag2); - CPPUNIT_TEST(testGetBody_IncompleteStartTag); - CPPUNIT_TEST(testGetBody_InvalidEndTag); - CPPUNIT_TEST(testGetBody_InvalidEndTag2); - CPPUNIT_TEST_SUITE_END(); - - public: - void testGetBody() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body a1='a\"1' a2=\"a'2\" boo='bar' >" - "foo <message> <body> bar" - "</body > ")); - - CPPUNIT_ASSERT(testling.getBody()); - CPPUNIT_ASSERT_EQUAL(std::string("a\"1"), testling.getBody()->attributes.getAttribute("a1")); - CPPUNIT_ASSERT_EQUAL(std::string("foo <message> <body> bar"), testling.getBody()->content); - } - - void testGetBody_EmptyContent() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body foo='bar'/>")); - - CPPUNIT_ASSERT(testling.getBody()); - CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getBody()->attributes.getAttribute("foo")); - CPPUNIT_ASSERT(testling.getBody()->content.empty()); - } - - void testGetBody_EmptyContent2() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body foo='bar'></body>")); - - CPPUNIT_ASSERT(testling.getBody()); - CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getBody()->attributes.getAttribute("foo")); - CPPUNIT_ASSERT(testling.getBody()->content.empty()); - } - - void testGetBody_EmptyElementEmptyContent() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body/>")); - - CPPUNIT_ASSERT(testling.getBody()); - } - - void testGetBody_InvalidStartTag() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<bodi></body>")); - - CPPUNIT_ASSERT(!testling.getBody()); - } - - void testGetBody_InvalidStartTag2() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<bodyy></body>")); - - CPPUNIT_ASSERT(!testling.getBody()); - } - - void testGetBody_IncompleteStartTag() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body")); - - CPPUNIT_ASSERT(!testling.getBody()); - } - - void testGetBody_InvalidEndTag() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body></bodi>")); - - CPPUNIT_ASSERT(!testling.getBody()); - } - - void testGetBody_InvalidEndTag2() { - BOSHBodyExtractor testling(&parserFactory, createByteArray( - "<body><b/body>")); - - CPPUNIT_ASSERT(!testling.getBody()); - } - - private: - PlatformXMLParserFactory parserFactory; + CPPUNIT_TEST_SUITE(BOSHBodyExtractorTest); + CPPUNIT_TEST(testGetBody); + CPPUNIT_TEST(testGetBody_EmptyContent); + CPPUNIT_TEST(testGetBody_EmptyContent2); + CPPUNIT_TEST(testGetBody_EmptyElementEmptyContent); + CPPUNIT_TEST(testGetBody_InvalidStartTag); + CPPUNIT_TEST(testGetBody_InvalidStartTag2); + CPPUNIT_TEST(testGetBody_IncompleteStartTag); + CPPUNIT_TEST(testGetBody_InvalidEndTag); + CPPUNIT_TEST(testGetBody_InvalidEndTag2); + CPPUNIT_TEST_SUITE_END(); + + public: + void testGetBody() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body a1='a\"1' a2=\"a'2\" boo='bar' >" + "foo <message> <body> bar" + "</body > ")); + + CPPUNIT_ASSERT(testling.getBody()); + CPPUNIT_ASSERT_EQUAL(std::string("a\"1"), testling.getBody()->attributes.getAttribute("a1")); + CPPUNIT_ASSERT_EQUAL(std::string("foo <message> <body> bar"), testling.getBody()->content); + } + + void testGetBody_EmptyContent() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body foo='bar'/>")); + + CPPUNIT_ASSERT(testling.getBody()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getBody()->attributes.getAttribute("foo")); + CPPUNIT_ASSERT(testling.getBody()->content.empty()); + } + + void testGetBody_EmptyContent2() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body foo='bar'></body>")); + + CPPUNIT_ASSERT(testling.getBody()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getBody()->attributes.getAttribute("foo")); + CPPUNIT_ASSERT(testling.getBody()->content.empty()); + } + + void testGetBody_EmptyElementEmptyContent() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body/>")); + + CPPUNIT_ASSERT(testling.getBody()); + } + + void testGetBody_InvalidStartTag() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<bodi></body>")); + + CPPUNIT_ASSERT(!testling.getBody()); + } + + void testGetBody_InvalidStartTag2() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<bodyy></body>")); + + CPPUNIT_ASSERT(!testling.getBody()); + } + + void testGetBody_IncompleteStartTag() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body")); + + CPPUNIT_ASSERT(!testling.getBody()); + } + + void testGetBody_InvalidEndTag() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body></bodi>")); + + CPPUNIT_ASSERT(!testling.getBody()); + } + + void testGetBody_InvalidEndTag2() { + BOSHBodyExtractor testling(&parserFactory, createByteArray( + "<body><b/body>")); + + CPPUNIT_ASSERT(!testling.getBody()); + } + + private: + PlatformXMLParserFactory parserFactory; }; CPPUNIT_TEST_SUITE_REGISTRATION(BOSHBodyExtractorTest); diff --git a/Swiften/Parser/UnitTest/ElementParserTester.h b/Swiften/Parser/UnitTest/ElementParserTester.h index 76b8870..299fb50 100644 --- a/Swiften/Parser/UnitTest/ElementParserTester.h +++ b/Swiften/Parser/UnitTest/ElementParserTester.h @@ -1,14 +1,13 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once - #include <Swiften/Parser/UnitTest/ParserTester.h> namespace Swift { - typedef ParserTester<ElementParser> ElementParserTester; + typedef ParserTester<ElementParser> ElementParserTester; } diff --git a/Swiften/Parser/UnitTest/EnumParserTest.cpp b/Swiften/Parser/UnitTest/EnumParserTest.cpp index 44a30c0..82b3fa1 100644 --- a/Swiften/Parser/UnitTest/EnumParserTest.cpp +++ b/Swiften/Parser/UnitTest/EnumParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2013 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -12,25 +12,25 @@ using namespace Swift; class EnumParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(EnumParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_NoValue); - CPPUNIT_TEST_SUITE_END(); - - public: - enum MyEnum { - MyValue1, - MyValue2, - MyValue3 - }; - - void testParse() { - CPPUNIT_ASSERT(MyValue2 == EnumParser<MyEnum>()(MyValue1, "my-value-1")(MyValue2, "my-value-2")(MyValue3, "my-value-3").parse("my-value-2")); - } - - void testParse_NoValue() { - CPPUNIT_ASSERT(!EnumParser<MyEnum>()(MyValue1, "my-value-1")(MyValue2, "my-value-2")(MyValue3, "my-value-3").parse("my-value-4")); - } + CPPUNIT_TEST_SUITE(EnumParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_NoValue); + CPPUNIT_TEST_SUITE_END(); + + public: + enum MyEnum { + MyValue1, + MyValue2, + MyValue3 + }; + + void testParse() { + CPPUNIT_ASSERT(MyValue2 == EnumParser<MyEnum>()(MyValue1, "my-value-1")(MyValue2, "my-value-2")(MyValue3, "my-value-3").parse("my-value-2")); + } + + void testParse_NoValue() { + CPPUNIT_ASSERT(!EnumParser<MyEnum>()(MyValue1, "my-value-1")(MyValue2, "my-value-2")(MyValue3, "my-value-3").parse("my-value-4")); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(EnumParserTest); diff --git a/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp b/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp index 93d4e7f..cd94ed8 100644 --- a/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp +++ b/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp @@ -1,16 +1,16 @@ /* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <Swiften/Base/Platform.h> +#include <Swiften/Elements/RawXMLPayload.h> #include <Swiften/Parser/GenericPayloadTreeParser.h> #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h> -#include <Swiften/Elements/RawXMLPayload.h> using namespace Swift; @@ -22,44 +22,44 @@ template class __declspec(dllimport) Swift::GenericPayloadParser<RawXMLPayload>; #endif class GenericPayloadTreeParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(GenericPayloadTreeParserTest); - CPPUNIT_TEST(testTree); - CPPUNIT_TEST_SUITE_END(); - - public: - void testTree() { - MyParser testling; - - std::string data = "<topLevel xmlns='urn:test:top'><firstLevelInheritedEmpty/><firstLevelInherited><secondLevelMultiChildren num='1'/><secondLevelMultiChildren num='2'/></firstLevelInherited><firstLevelNS xmlns='urn:test:first'/></topLevel>"; - - PayloadParserTester tester(&testling); - tester.parse(data); - - ParserElement::ref tree = testling.tree; - - CPPUNIT_ASSERT_EQUAL(std::string("topLevel"), tree->getName()); - CPPUNIT_ASSERT_EQUAL(std::string("urn:test:top"), tree->getNamespace()); - CPPUNIT_ASSERT(tree->getChild("firstLevelInheritedEmpty", "urn:test:top")); - CPPUNIT_ASSERT(!*tree->getChild("firstLevelInheritedEmpty", "")); - CPPUNIT_ASSERT(tree->getChild("firstLevelInherited", "urn:test:top")); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top").size()); - CPPUNIT_ASSERT_EQUAL(std::string("1"), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top")[0]->getAttributes().getAttribute("num")); - CPPUNIT_ASSERT_EQUAL(std::string("2"), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top")[1]->getAttributes().getAttribute("num")); - CPPUNIT_ASSERT(tree->getChild("firstLevelNS", "urn:test:first")); - } - - private: - - - class MyParser : public GenericPayloadTreeParser<RawXMLPayload> - { - public: - virtual ~MyParser() {} - virtual void handleTree(ParserElement::ref root) { - tree = root; - } - ParserElement::ref tree; - }; + CPPUNIT_TEST_SUITE(GenericPayloadTreeParserTest); + CPPUNIT_TEST(testTree); + CPPUNIT_TEST_SUITE_END(); + + public: + void testTree() { + MyParser testling; + + std::string data = "<topLevel xmlns='urn:test:top'><firstLevelInheritedEmpty/><firstLevelInherited><secondLevelMultiChildren num='1'/><secondLevelMultiChildren num='2'/></firstLevelInherited><firstLevelNS xmlns='urn:test:first'/></topLevel>"; + + PayloadParserTester tester(&testling); + tester.parse(data); + + ParserElement::ref tree = testling.tree; + + CPPUNIT_ASSERT_EQUAL(std::string("topLevel"), tree->getName()); + CPPUNIT_ASSERT_EQUAL(std::string("urn:test:top"), tree->getNamespace()); + CPPUNIT_ASSERT(tree->getChild("firstLevelInheritedEmpty", "urn:test:top")); + CPPUNIT_ASSERT(!*tree->getChild("firstLevelInheritedEmpty", "")); + CPPUNIT_ASSERT(tree->getChild("firstLevelInherited", "urn:test:top")); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top").size()); + CPPUNIT_ASSERT_EQUAL(std::string("1"), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top")[0]->getAttributes().getAttribute("num")); + CPPUNIT_ASSERT_EQUAL(std::string("2"), tree->getChild("firstLevelInherited", "urn:test:top")->getChildren("secondLevelMultiChildren", "urn:test:top")[1]->getAttributes().getAttribute("num")); + CPPUNIT_ASSERT(tree->getChild("firstLevelNS", "urn:test:first")); + } + + private: + + + class MyParser : public GenericPayloadTreeParser<RawXMLPayload> + { + public: + virtual ~MyParser() {} + virtual void handleTree(ParserElement::ref root) { + tree = root; + } + ParserElement::ref tree; + }; }; diff --git a/Swiften/Parser/UnitTest/IQParserTest.cpp b/Swiften/Parser/UnitTest/IQParserTest.cpp index 3c86a5d..5c07757 100644 --- a/Swiften/Parser/UnitTest/IQParserTest.cpp +++ b/Swiften/Parser/UnitTest/IQParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -14,60 +14,60 @@ using namespace Swift; class IQParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(IQParserTest); - CPPUNIT_TEST(testParse_Set); - CPPUNIT_TEST(testParse_Get); - CPPUNIT_TEST(testParse_Result); - CPPUNIT_TEST(testParse_Error); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(IQParserTest); + CPPUNIT_TEST(testParse_Set); + CPPUNIT_TEST(testParse_Get); + CPPUNIT_TEST(testParse_Result); + CPPUNIT_TEST(testParse_Error); + CPPUNIT_TEST_SUITE_END(); - public: - void setUp() { - factoryCollection_ = new PayloadParserFactoryCollection(); - } + public: + void setUp() { + factoryCollection_ = new PayloadParserFactoryCollection(); + } - void tearDown() { - delete factoryCollection_; - } + void tearDown() { + delete factoryCollection_; + } - void testParse_Set() { - IQParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Set() { + IQParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<iq type=\"set\"/>")); + CPPUNIT_ASSERT(parser.parse("<iq type=\"set\"/>")); - CPPUNIT_ASSERT_EQUAL(IQ::Set, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(IQ::Set, testling.getStanzaGeneric()->getType()); + } - void testParse_Get() { - IQParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Get() { + IQParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<iq type=\"get\"/>")); + CPPUNIT_ASSERT(parser.parse("<iq type=\"get\"/>")); - CPPUNIT_ASSERT_EQUAL(IQ::Get, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(IQ::Get, testling.getStanzaGeneric()->getType()); + } - void testParse_Result() { - IQParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Result() { + IQParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<iq type=\"result\"/>")); + CPPUNIT_ASSERT(parser.parse("<iq type=\"result\"/>")); - CPPUNIT_ASSERT_EQUAL(IQ::Result, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(IQ::Result, testling.getStanzaGeneric()->getType()); + } - void testParse_Error() { - IQParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Error() { + IQParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<iq type=\"error\"/>")); + CPPUNIT_ASSERT(parser.parse("<iq type=\"error\"/>")); - CPPUNIT_ASSERT_EQUAL(IQ::Error, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(IQ::Error, testling.getStanzaGeneric()->getType()); + } - private: - PayloadParserFactoryCollection* factoryCollection_; + private: + PayloadParserFactoryCollection* factoryCollection_; }; CPPUNIT_TEST_SUITE_REGISTRATION(IQParserTest); diff --git a/Swiften/Parser/UnitTest/MessageParserTest.cpp b/Swiften/Parser/UnitTest/MessageParserTest.cpp index 8ab59ed..dc55711 100644 --- a/Swiften/Parser/UnitTest/MessageParserTest.cpp +++ b/Swiften/Parser/UnitTest/MessageParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -14,70 +14,70 @@ using namespace Swift; class MessageParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MessageParserTest); - CPPUNIT_TEST(testParse_Normal); - CPPUNIT_TEST(testParse_Chat); - CPPUNIT_TEST(testParse_Error); - CPPUNIT_TEST(testParse_Groupchat); - CPPUNIT_TEST(testParse_Headline); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(MessageParserTest); + CPPUNIT_TEST(testParse_Normal); + CPPUNIT_TEST(testParse_Chat); + CPPUNIT_TEST(testParse_Error); + CPPUNIT_TEST(testParse_Groupchat); + CPPUNIT_TEST(testParse_Headline); + CPPUNIT_TEST_SUITE_END(); - public: - void setUp() { - factoryCollection_ = new PayloadParserFactoryCollection(); - } + public: + void setUp() { + factoryCollection_ = new PayloadParserFactoryCollection(); + } - void tearDown() { - delete factoryCollection_; - } + void tearDown() { + delete factoryCollection_; + } - void testParse_Chat() { - MessageParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Chat() { + MessageParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<message type=\"chat\"/>")); + CPPUNIT_ASSERT(parser.parse("<message type=\"chat\"/>")); - CPPUNIT_ASSERT_EQUAL(Message::Chat, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Message::Chat, testling.getStanzaGeneric()->getType()); + } - void testParse_Groupchat() { - MessageParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Groupchat() { + MessageParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<message type=\"groupchat\"/>")); + CPPUNIT_ASSERT(parser.parse("<message type=\"groupchat\"/>")); - CPPUNIT_ASSERT_EQUAL(Message::Groupchat, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Message::Groupchat, testling.getStanzaGeneric()->getType()); + } - void testParse_Error() { - MessageParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Error() { + MessageParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<message type=\"error\"/>")); + CPPUNIT_ASSERT(parser.parse("<message type=\"error\"/>")); - CPPUNIT_ASSERT_EQUAL(Message::Error, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Message::Error, testling.getStanzaGeneric()->getType()); + } - void testParse_Headline() { - MessageParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Headline() { + MessageParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<message type=\"headline\"/>")); + CPPUNIT_ASSERT(parser.parse("<message type=\"headline\"/>")); - CPPUNIT_ASSERT_EQUAL(Message::Headline, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Message::Headline, testling.getStanzaGeneric()->getType()); + } - void testParse_Normal() { - MessageParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Normal() { + MessageParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<message/>")); + CPPUNIT_ASSERT(parser.parse("<message/>")); - CPPUNIT_ASSERT_EQUAL(Message::Normal, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Message::Normal, testling.getStanzaGeneric()->getType()); + } - private: - PayloadParserFactoryCollection* factoryCollection_; + private: + PayloadParserFactoryCollection* factoryCollection_; }; CPPUNIT_TEST_SUITE_REGISTRATION(MessageParserTest); diff --git a/Swiften/Parser/UnitTest/ParserTester.h b/Swiften/Parser/UnitTest/ParserTester.h index 73f013c..aa01d40 100644 --- a/Swiften/Parser/UnitTest/ParserTester.h +++ b/Swiften/Parser/UnitTest/ParserTester.h @@ -1,48 +1,42 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once - -#include <Swiften/Parser/XMLParserClient.h> #include <Swiften/Parser/PlatformXMLParserFactory.h> #include <Swiften/Parser/XMLParser.h> +#include <Swiften/Parser/XMLParserClient.h> namespace Swift { - class XMLParser; - - template<typename ParserType> - class ParserTester : public XMLParserClient { - public: - ParserTester(ParserType* parser) : parser_(parser) { - xmlParser_ = PlatformXMLParserFactory().createXMLParser(this); - } - - ~ParserTester() { - delete xmlParser_; - } - - bool parse(const std::string& data) { - return xmlParser_->parse(data); - } - - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - parser_->handleStartElement(element, ns, attributes); - } - - virtual void handleEndElement(const std::string& element, const std::string& ns) { - parser_->handleEndElement(element, ns); - } - - virtual void handleCharacterData(const std::string& data) { - parser_->handleCharacterData(data); - } - - private: - XMLParser* xmlParser_; - ParserType* parser_; - }; + class XMLParser; + + template<typename ParserType> + class ParserTester : public XMLParserClient { + public: + ParserTester(ParserType* parser) : xmlParser_(PlatformXMLParserFactory().createXMLParser(this)), parser_(parser) { + } + + bool parse(const std::string& data) { + return xmlParser_->parse(data); + } + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + parser_->handleStartElement(element, ns, attributes); + } + + virtual void handleEndElement(const std::string& element, const std::string& ns) { + parser_->handleEndElement(element, ns); + } + + virtual void handleCharacterData(const std::string& data) { + parser_->handleCharacterData(data); + } + + private: + std::unique_ptr<XMLParser> xmlParser_; + ParserType* parser_; + }; } diff --git a/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp b/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp index fea64e2..f7234d9 100644 --- a/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp +++ b/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp @@ -1,103 +1,103 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-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/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> using namespace Swift; class PayloadParserFactoryCollectionTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(PayloadParserFactoryCollectionTest); - CPPUNIT_TEST(testGetPayloadParserFactory); - CPPUNIT_TEST(testGetPayloadParserFactory_NoMatchingFactory); - CPPUNIT_TEST(testGetPayloadParserFactory_TwoMatchingFactories); - CPPUNIT_TEST(testGetPayloadParserFactory_MatchWithDefaultFactory); - CPPUNIT_TEST(testGetPayloadParserFactory_NoMatchWithDefaultFactory); - CPPUNIT_TEST_SUITE_END(); - - public: - PayloadParserFactoryCollectionTest() {} - - void setUp() { - } - - void tearDown() { - } - - void testGetPayloadParserFactory() { - PayloadParserFactoryCollection testling; - DummyFactory factory1("foo"); - testling.addFactory(&factory1); - DummyFactory factory2("bar"); - testling.addFactory(&factory2); - DummyFactory factory3("baz"); - testling.addFactory(&factory3); - - PayloadParserFactory* factory = testling.getPayloadParserFactory("bar", "", AttributeMap()); - - CPPUNIT_ASSERT(factory == &factory2); - } - - void testGetPayloadParserFactory_NoMatchingFactory() { - PayloadParserFactoryCollection testling; - DummyFactory factory("foo"); - - CPPUNIT_ASSERT(!testling.getPayloadParserFactory("bar", "", AttributeMap())); - } - - void testGetPayloadParserFactory_TwoMatchingFactories() { - PayloadParserFactoryCollection testling; - DummyFactory factory1("foo"); - testling.addFactory(&factory1); - DummyFactory factory2("foo"); - testling.addFactory(&factory2); - - PayloadParserFactory* factory = testling.getPayloadParserFactory("foo", "", AttributeMap()); - - CPPUNIT_ASSERT(factory == &factory2); - } - - void testGetPayloadParserFactory_MatchWithDefaultFactory() { - PayloadParserFactoryCollection testling; - DummyFactory factory1("foo"); - testling.addFactory(&factory1); - DummyFactory factory2; - testling.setDefaultFactory(&factory2); - - PayloadParserFactory* factory = testling.getPayloadParserFactory("foo", "", AttributeMap()); - - CPPUNIT_ASSERT(factory == &factory1); - } - - void testGetPayloadParserFactory_NoMatchWithDefaultFactory() { - PayloadParserFactoryCollection testling; - DummyFactory factory1("foo"); - testling.addFactory(&factory1); - DummyFactory factory2; - testling.setDefaultFactory(&factory2); - - PayloadParserFactory* factory = testling.getPayloadParserFactory("baz", "", AttributeMap()); - - CPPUNIT_ASSERT(factory == &factory2); - } - - - private: - struct DummyFactory : public PayloadParserFactory { - DummyFactory(const std::string& element = "") : element(element) {} - virtual bool canParse(const std::string& e, const std::string&, const AttributeMap&) const { - return element.empty() ? true : element == e; - } - virtual PayloadParser* createPayloadParser() { return NULL; } - std::string element; - }; + CPPUNIT_TEST_SUITE(PayloadParserFactoryCollectionTest); + CPPUNIT_TEST(testGetPayloadParserFactory); + CPPUNIT_TEST(testGetPayloadParserFactory_NoMatchingFactory); + CPPUNIT_TEST(testGetPayloadParserFactory_TwoMatchingFactories); + CPPUNIT_TEST(testGetPayloadParserFactory_MatchWithDefaultFactory); + CPPUNIT_TEST(testGetPayloadParserFactory_NoMatchWithDefaultFactory); + CPPUNIT_TEST_SUITE_END(); + + public: + PayloadParserFactoryCollectionTest() {} + + void setUp() { + } + + void tearDown() { + } + + void testGetPayloadParserFactory() { + PayloadParserFactoryCollection testling; + DummyFactory factory1("foo"); + testling.addFactory(&factory1); + DummyFactory factory2("bar"); + testling.addFactory(&factory2); + DummyFactory factory3("baz"); + testling.addFactory(&factory3); + + PayloadParserFactory* factory = testling.getPayloadParserFactory("bar", "", AttributeMap()); + + CPPUNIT_ASSERT(factory == &factory2); + } + + void testGetPayloadParserFactory_NoMatchingFactory() { + PayloadParserFactoryCollection testling; + DummyFactory factory("foo"); + + CPPUNIT_ASSERT(!testling.getPayloadParserFactory("bar", "", AttributeMap())); + } + + void testGetPayloadParserFactory_TwoMatchingFactories() { + PayloadParserFactoryCollection testling; + DummyFactory factory1("foo"); + testling.addFactory(&factory1); + DummyFactory factory2("foo"); + testling.addFactory(&factory2); + + PayloadParserFactory* factory = testling.getPayloadParserFactory("foo", "", AttributeMap()); + + CPPUNIT_ASSERT(factory == &factory2); + } + + void testGetPayloadParserFactory_MatchWithDefaultFactory() { + PayloadParserFactoryCollection testling; + DummyFactory factory1("foo"); + testling.addFactory(&factory1); + DummyFactory factory2; + testling.setDefaultFactory(&factory2); + + PayloadParserFactory* factory = testling.getPayloadParserFactory("foo", "", AttributeMap()); + + CPPUNIT_ASSERT(factory == &factory1); + } + + void testGetPayloadParserFactory_NoMatchWithDefaultFactory() { + PayloadParserFactoryCollection testling; + DummyFactory factory1("foo"); + testling.addFactory(&factory1); + DummyFactory factory2; + testling.setDefaultFactory(&factory2); + + PayloadParserFactory* factory = testling.getPayloadParserFactory("baz", "", AttributeMap()); + + CPPUNIT_ASSERT(factory == &factory2); + } + + + private: + struct DummyFactory : public PayloadParserFactory { + DummyFactory(const std::string& element = "") : element(element) {} + virtual bool canParse(const std::string& e, const std::string&, const AttributeMap&) const { + return element.empty() ? true : element == e; + } + virtual PayloadParser* createPayloadParser() { return nullptr; } + std::string element; + }; }; CPPUNIT_TEST_SUITE_REGISTRATION(PayloadParserFactoryCollectionTest); diff --git a/Swiften/Parser/UnitTest/PresenceParserTest.cpp b/Swiften/Parser/UnitTest/PresenceParserTest.cpp index f9d6cf6..2b2c242 100644 --- a/Swiften/Parser/UnitTest/PresenceParserTest.cpp +++ b/Swiften/Parser/UnitTest/PresenceParserTest.cpp @@ -1,113 +1,113 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-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/PresenceParser.h> #include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PresenceParser.h> #include <Swiften/Parser/UnitTest/StanzaParserTester.h> using namespace Swift; class PresenceParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(PresenceParserTest); - CPPUNIT_TEST(testParse_Available); - CPPUNIT_TEST(testParse_Unavailable); - CPPUNIT_TEST(testParse_Subscribe); - CPPUNIT_TEST(testParse_Subscribed); - CPPUNIT_TEST(testParse_Unsubscribe); - CPPUNIT_TEST(testParse_Unsubscribed); - CPPUNIT_TEST(testParse_Probe); - CPPUNIT_TEST(testParse_Error); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(PresenceParserTest); + CPPUNIT_TEST(testParse_Available); + CPPUNIT_TEST(testParse_Unavailable); + CPPUNIT_TEST(testParse_Subscribe); + CPPUNIT_TEST(testParse_Subscribed); + CPPUNIT_TEST(testParse_Unsubscribe); + CPPUNIT_TEST(testParse_Unsubscribed); + CPPUNIT_TEST(testParse_Probe); + CPPUNIT_TEST(testParse_Error); + CPPUNIT_TEST_SUITE_END(); - public: - void setUp() { - factoryCollection_ = new PayloadParserFactoryCollection(); - } + public: + void setUp() { + factoryCollection_ = new PayloadParserFactoryCollection(); + } - void tearDown() { - delete factoryCollection_; - } + void tearDown() { + delete factoryCollection_; + } - void testParse_Available() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Available() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence/>")); + CPPUNIT_ASSERT(parser.parse("<presence/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Available, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Available, testling.getStanzaGeneric()->getType()); + } - void testParse_Unavailable() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Unavailable() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"unavailable\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"unavailable\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, testling.getStanzaGeneric()->getType()); + } - void testParse_Probe() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Probe() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"probe\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"probe\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Probe, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Probe, testling.getStanzaGeneric()->getType()); + } - void testParse_Subscribe() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Subscribe() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"subscribe\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"subscribe\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Subscribe, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Subscribe, testling.getStanzaGeneric()->getType()); + } - void testParse_Subscribed() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Subscribed() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"subscribed\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"subscribed\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Subscribed, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Subscribed, testling.getStanzaGeneric()->getType()); + } - void testParse_Unsubscribe() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Unsubscribe() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"unsubscribe\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"unsubscribe\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Unsubscribe, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Unsubscribe, testling.getStanzaGeneric()->getType()); + } - void testParse_Unsubscribed() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Unsubscribed() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"unsubscribed\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"unsubscribed\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Unsubscribed, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Unsubscribed, testling.getStanzaGeneric()->getType()); + } - void testParse_Error() { - PresenceParser testling(factoryCollection_); - StanzaParserTester parser(&testling); + void testParse_Error() { + PresenceParser testling(factoryCollection_); + StanzaParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<presence type=\"error\"/>")); + CPPUNIT_ASSERT(parser.parse("<presence type=\"error\"/>")); - CPPUNIT_ASSERT_EQUAL(Presence::Error, testling.getStanzaGeneric()->getType()); - } + CPPUNIT_ASSERT_EQUAL(Presence::Error, testling.getStanzaGeneric()->getType()); + } - private: - PayloadParserFactoryCollection* factoryCollection_; + private: + PayloadParserFactoryCollection* factoryCollection_; }; CPPUNIT_TEST_SUITE_REGISTRATION(PresenceParserTest); diff --git a/Swiften/Parser/UnitTest/SerializingParserTest.cpp b/Swiften/Parser/UnitTest/SerializingParserTest.cpp index aef1dfb..1b4eb57 100644 --- a/Swiften/Parser/UnitTest/SerializingParserTest.cpp +++ b/Swiften/Parser/UnitTest/SerializingParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -14,51 +14,51 @@ using namespace Swift; class SerializingParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SerializingParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Empty); - CPPUNIT_TEST(testParse_ToplevelCharacterData); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(SerializingParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Empty); + CPPUNIT_TEST(testParse_ToplevelCharacterData); + CPPUNIT_TEST_SUITE_END(); - public: - SerializingParserTest() {} + public: + SerializingParserTest() {} - void testParse() { - SerializingParser testling; - ParserTester<SerializingParser> parser(&testling); + void testParse() { + SerializingParser testling; + ParserTester<SerializingParser> parser(&testling); - CPPUNIT_ASSERT(parser.parse( - "<message type=\"chat\" to=\"me@foo.com\">" - "<body>Hello<&World</body>" - "<html xmlns=\"http://www.w3.org/1999/xhtml\">" - "foo<b>bar</b>baz" - "</html>" - "</message>")); + CPPUNIT_ASSERT(parser.parse( + "<message type=\"chat\" to=\"me@foo.com\">" + "<body>Hello<&World</body>" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">" + "foo<b>bar</b>baz" + "</html>" + "</message>")); - CPPUNIT_ASSERT_EQUAL(std::string( - "<message to=\"me@foo.com\" type=\"chat\">" - "<body>Hello<&World</body>" - "<html xmlns=\"http://www.w3.org/1999/xhtml\">foo<b xmlns=\"http://www.w3.org/1999/xhtml\">bar</b>baz</html>" - "</message>"), testling.getResult()); - } + CPPUNIT_ASSERT_EQUAL(std::string( + "<message to=\"me@foo.com\" type=\"chat\">" + "<body>Hello<&World</body>" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">foo<b xmlns=\"http://www.w3.org/1999/xhtml\">bar</b>baz</html>" + "</message>"), testling.getResult()); + } - void testParse_Empty() { - SerializingParser testling; + void testParse_Empty() { + SerializingParser testling; - CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getResult()); - } + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getResult()); + } - void testParse_ToplevelCharacterData() { - SerializingParser testling; - - AttributeMap attributes; - testling.handleCharacterData("foo"); - testling.handleStartElement("message", "", attributes); - testling.handleEndElement("message", ""); - testling.handleCharacterData("bar"); + void testParse_ToplevelCharacterData() { + SerializingParser testling; - CPPUNIT_ASSERT_EQUAL(std::string("<message/>"), testling.getResult()); - } + AttributeMap attributes; + testling.handleCharacterData("foo"); + testling.handleStartElement("message", "", attributes); + testling.handleEndElement("message", ""); + testling.handleCharacterData("bar"); + + CPPUNIT_ASSERT_EQUAL(std::string("<message/>"), testling.getResult()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SerializingParserTest); diff --git a/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp b/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp index b68fb30..4591640 100644 --- a/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp +++ b/Swiften/Parser/UnitTest/StanzaAckParserTest.cpp @@ -1,53 +1,53 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-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/StanzaAckParser.h> #include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/StanzaAckParser.h> #include <Swiften/Parser/UnitTest/ElementParserTester.h> using namespace Swift; class StanzaAckParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StanzaAckParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Invalid); - CPPUNIT_TEST(testParse_Empty); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(StanzaAckParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Invalid); + CPPUNIT_TEST(testParse_Empty); + CPPUNIT_TEST_SUITE_END(); - public: - void testParse() { - StanzaAckParser testling; - ElementParserTester parser(&testling); + public: + void testParse() { + StanzaAckParser testling; + ElementParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<a h=\"12\" xmlns=\"urn:xmpp:sm:2\"/>")); + CPPUNIT_ASSERT(parser.parse("<a h=\"12\" xmlns=\"urn:xmpp:sm:2\"/>")); - CPPUNIT_ASSERT(testling.getElementGeneric()->isValid()); - CPPUNIT_ASSERT_EQUAL(12U, testling.getElementGeneric()->getHandledStanzasCount()); - } + CPPUNIT_ASSERT(testling.getElementGeneric()->isValid()); + CPPUNIT_ASSERT_EQUAL(12U, testling.getElementGeneric()->getHandledStanzasCount()); + } - void testParse_Invalid() { - StanzaAckParser testling; - ElementParserTester parser(&testling); + void testParse_Invalid() { + StanzaAckParser testling; + ElementParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<a h=\"invalid\" xmlns=\"urn:xmpp:sm:2\"/>")); + CPPUNIT_ASSERT(parser.parse("<a h=\"invalid\" xmlns=\"urn:xmpp:sm:2\"/>")); - CPPUNIT_ASSERT(!testling.getElementGeneric()->isValid()); - } + CPPUNIT_ASSERT(!testling.getElementGeneric()->isValid()); + } - void testParse_Empty() { - StanzaAckParser testling; - ElementParserTester parser(&testling); + void testParse_Empty() { + StanzaAckParser testling; + ElementParserTester parser(&testling); - CPPUNIT_ASSERT(parser.parse("<a xmlns=\"urn:xmpp:sm:2\"/>")); + CPPUNIT_ASSERT(parser.parse("<a xmlns=\"urn:xmpp:sm:2\"/>")); - CPPUNIT_ASSERT(!testling.getElementGeneric()->isValid()); - } + CPPUNIT_ASSERT(!testling.getElementGeneric()->isValid()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StanzaAckParserTest); diff --git a/Swiften/Parser/UnitTest/StanzaParserTest.cpp b/Swiften/Parser/UnitTest/StanzaParserTest.cpp index 88e6dec..6febdbc 100644 --- a/Swiften/Parser/UnitTest/StanzaParserTest.cpp +++ b/Swiften/Parser/UnitTest/StanzaParserTest.cpp @@ -1,212 +1,212 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-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/StanzaParser.h> +#include <Swiften/Elements/Payload.h> +#include <Swiften/Elements/Stanza.h> #include <Swiften/Parser/GenericPayloadParser.h> #include <Swiften/Parser/PayloadParserFactory.h> #include <Swiften/Parser/PayloadParserFactoryCollection.h> -#include <Swiften/Elements/Stanza.h> -#include <Swiften/Elements/Payload.h> +#include <Swiften/Parser/StanzaParser.h> using namespace Swift; class StanzaParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StanzaParserTest); - CPPUNIT_TEST(testHandleEndElement_OnePayload); - CPPUNIT_TEST(testHandleEndElement_MultiplePayloads); - CPPUNIT_TEST(testHandleEndElement_StrayCharacterData); - CPPUNIT_TEST(testHandleEndElement_UnknownPayload); - CPPUNIT_TEST(testHandleParse_BasicAttributes); - CPPUNIT_TEST_SUITE_END(); - - public: - void setUp() { - factoryCollection_ = new PayloadParserFactoryCollection(); - factoryCollection_->addFactory(&factory1_); - factoryCollection_->addFactory(&factory2_); - } - - void tearDown() { - delete factoryCollection_; - } - - void testHandleEndElement_OnePayload() { - MyStanzaParser testling(factoryCollection_); - - AttributeMap attributes; - attributes.addAttribute("foo", "", "fum"); - attributes.addAttribute("bar", "", "baz"); - testling.handleStartElement("mystanza", "", attributes); - testling.handleStartElement("mypayload1", "", attributes); - testling.handleStartElement("child", "", attributes); - testling.handleEndElement("child", ""); - testling.handleEndElement("mypayload1", ""); - testling.handleEndElement("mystanza", ""); - - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()->hasChild); - } - - void testHandleEndElement_MultiplePayloads() { - MyStanzaParser testling(factoryCollection_); - - AttributeMap attributes; - testling.handleStartElement("mystanza", "", attributes); - testling.handleStartElement("mypayload1", "", attributes); - testling.handleEndElement("mypayload1", ""); - testling.handleStartElement("mypayload2", "", attributes); - testling.handleEndElement("mypayload2", ""); - testling.handleEndElement("mystanza", ""); - - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload2>()); - } - - void testHandleEndElement_StrayCharacterData() { - MyStanzaParser testling(factoryCollection_); - - AttributeMap attributes; - testling.handleStartElement("mystanza", "", attributes); - testling.handleStartElement("mypayload1", "", attributes); - testling.handleEndElement("mypayload1", ""); - testling.handleCharacterData("bla"); - testling.handleStartElement("mypayload2", "", attributes); - testling.handleEndElement("mypayload2", ""); - testling.handleEndElement("mystanza", ""); - - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload2>()); - } - - void testHandleEndElement_UnknownPayload() { - MyStanzaParser testling(factoryCollection_); - - AttributeMap attributes; - testling.handleStartElement("mystanza", "", attributes); - testling.handleStartElement("mypayload1", "", attributes); - testling.handleEndElement("mypayload1", ""); - testling.handleStartElement("unknown-payload", "", attributes); - testling.handleStartElement("unknown-payload-child", "", attributes); - testling.handleEndElement("unknown-payload-child", ""); - testling.handleEndElement("unknown-payload", ""); - testling.handleStartElement("mypayload2", "", attributes); - testling.handleEndElement("mypayload2", ""); - testling.handleEndElement("mystanza", ""); - - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); - CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload2>()); - } - - void testHandleParse_BasicAttributes() { - MyStanzaParser testling(factoryCollection_); - - AttributeMap attributes; - attributes.addAttribute("to", "", "foo@example.com/blo"); - attributes.addAttribute("from", "", "bar@example.com/baz"); - attributes.addAttribute("id", "", "id-123"); - testling.handleStartElement("mystanza", "", attributes); - testling.handleEndElement("mypayload1", ""); - - CPPUNIT_ASSERT_EQUAL(JID("foo@example.com/blo"), testling.getStanza()->getTo()); - CPPUNIT_ASSERT_EQUAL(JID("bar@example.com/baz"), testling.getStanza()->getFrom()); - CPPUNIT_ASSERT_EQUAL(std::string("id-123"), testling.getStanza()->getID()); - } - - private: - class MyPayload1 : public Payload - { - public: - MyPayload1() : hasChild(false) {} - - bool hasChild; - }; - - class MyPayload1Parser : public GenericPayloadParser<MyPayload1> - { - public: - MyPayload1Parser() {} - - virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { - if (element != "mypayload1") { - getPayloadInternal()->hasChild = true; - } - } - - virtual void handleEndElement(const std::string&, const std::string&) {} - virtual void handleCharacterData(const std::string&) {} - }; - - class MyPayload1ParserFactory : public PayloadParserFactory - { - public: - MyPayload1ParserFactory() {} - - PayloadParser* createPayloadParser() { return new MyPayload1Parser(); } - - bool canParse(const std::string& element, const std::string&, const AttributeMap&) const { - return element == "mypayload1"; - } - }; - - class MyPayload2 : public Payload - { - public: - MyPayload2() {} - }; - - class MyPayload2Parser : public GenericPayloadParser<MyPayload2> - { - public: - MyPayload2Parser() {} - - 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 MyPayload2ParserFactory : public PayloadParserFactory - { - public: - MyPayload2ParserFactory() {} - - PayloadParser* createPayloadParser() { return new MyPayload2Parser(); } - bool canParse(const std::string& element, const std::string&, const AttributeMap&) const { - return element == "mypayload2"; - } - }; - - class MyStanza : public Stanza - { - public: - MyStanza() {} - }; - - class MyStanzaParser : public StanzaParser - { - public: - MyStanzaParser(PayloadParserFactoryCollection* collection) : StanzaParser(collection) - { - stanza_ = boost::make_shared<MyStanza>(); - } - - virtual boost::shared_ptr<Element> getElement() const { - return stanza_; - } - - private: - boost::shared_ptr<MyStanza> stanza_; - }; - - MyPayload1ParserFactory factory1_; - MyPayload2ParserFactory factory2_; - PayloadParserFactoryCollection* factoryCollection_; + CPPUNIT_TEST_SUITE(StanzaParserTest); + CPPUNIT_TEST(testHandleEndElement_OnePayload); + CPPUNIT_TEST(testHandleEndElement_MultiplePayloads); + CPPUNIT_TEST(testHandleEndElement_StrayCharacterData); + CPPUNIT_TEST(testHandleEndElement_UnknownPayload); + CPPUNIT_TEST(testHandleParse_BasicAttributes); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + factoryCollection_ = new PayloadParserFactoryCollection(); + factoryCollection_->addFactory(&factory1_); + factoryCollection_->addFactory(&factory2_); + } + + void tearDown() { + delete factoryCollection_; + } + + void testHandleEndElement_OnePayload() { + MyStanzaParser testling(factoryCollection_); + + AttributeMap attributes; + attributes.addAttribute("foo", "", "fum"); + attributes.addAttribute("bar", "", "baz"); + testling.handleStartElement("mystanza", "", attributes); + testling.handleStartElement("mypayload1", "", attributes); + testling.handleStartElement("child", "", attributes); + testling.handleEndElement("child", ""); + testling.handleEndElement("mypayload1", ""); + testling.handleEndElement("mystanza", ""); + + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()->hasChild); + } + + void testHandleEndElement_MultiplePayloads() { + MyStanzaParser testling(factoryCollection_); + + AttributeMap attributes; + testling.handleStartElement("mystanza", "", attributes); + testling.handleStartElement("mypayload1", "", attributes); + testling.handleEndElement("mypayload1", ""); + testling.handleStartElement("mypayload2", "", attributes); + testling.handleEndElement("mypayload2", ""); + testling.handleEndElement("mystanza", ""); + + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload2>()); + } + + void testHandleEndElement_StrayCharacterData() { + MyStanzaParser testling(factoryCollection_); + + AttributeMap attributes; + testling.handleStartElement("mystanza", "", attributes); + testling.handleStartElement("mypayload1", "", attributes); + testling.handleEndElement("mypayload1", ""); + testling.handleCharacterData("bla"); + testling.handleStartElement("mypayload2", "", attributes); + testling.handleEndElement("mypayload2", ""); + testling.handleEndElement("mystanza", ""); + + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload2>()); + } + + void testHandleEndElement_UnknownPayload() { + MyStanzaParser testling(factoryCollection_); + + AttributeMap attributes; + testling.handleStartElement("mystanza", "", attributes); + testling.handleStartElement("mypayload1", "", attributes); + testling.handleEndElement("mypayload1", ""); + testling.handleStartElement("unknown-payload", "", attributes); + testling.handleStartElement("unknown-payload-child", "", attributes); + testling.handleEndElement("unknown-payload-child", ""); + testling.handleEndElement("unknown-payload", ""); + testling.handleStartElement("mypayload2", "", attributes); + testling.handleEndElement("mypayload2", ""); + testling.handleEndElement("mystanza", ""); + + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload1>()); + CPPUNIT_ASSERT(testling.getStanza()->getPayload<MyPayload2>()); + } + + void testHandleParse_BasicAttributes() { + MyStanzaParser testling(factoryCollection_); + + AttributeMap attributes; + attributes.addAttribute("to", "", "foo@example.com/blo"); + attributes.addAttribute("from", "", "bar@example.com/baz"); + attributes.addAttribute("id", "", "id-123"); + testling.handleStartElement("mystanza", "", attributes); + testling.handleEndElement("mypayload1", ""); + + CPPUNIT_ASSERT_EQUAL(JID("foo@example.com/blo"), testling.getStanza()->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("bar@example.com/baz"), testling.getStanza()->getFrom()); + CPPUNIT_ASSERT_EQUAL(std::string("id-123"), testling.getStanza()->getID()); + } + + private: + class MyPayload1 : public Payload + { + public: + MyPayload1() : hasChild(false) {} + + bool hasChild; + }; + + class MyPayload1Parser : public GenericPayloadParser<MyPayload1> + { + public: + MyPayload1Parser() {} + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap&) { + if (element != "mypayload1") { + getPayloadInternal()->hasChild = true; + } + } + + virtual void handleEndElement(const std::string&, const std::string&) {} + virtual void handleCharacterData(const std::string&) {} + }; + + class MyPayload1ParserFactory : public PayloadParserFactory + { + public: + MyPayload1ParserFactory() {} + + PayloadParser* createPayloadParser() { return new MyPayload1Parser(); } + + bool canParse(const std::string& element, const std::string&, const AttributeMap&) const { + return element == "mypayload1"; + } + }; + + class MyPayload2 : public Payload + { + public: + MyPayload2() {} + }; + + class MyPayload2Parser : public GenericPayloadParser<MyPayload2> + { + public: + MyPayload2Parser() {} + + 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 MyPayload2ParserFactory : public PayloadParserFactory + { + public: + MyPayload2ParserFactory() {} + + PayloadParser* createPayloadParser() { return new MyPayload2Parser(); } + bool canParse(const std::string& element, const std::string&, const AttributeMap&) const { + return element == "mypayload2"; + } + }; + + class MyStanza : public Stanza + { + public: + MyStanza() {} + }; + + class MyStanzaParser : public StanzaParser + { + public: + MyStanzaParser(PayloadParserFactoryCollection* collection) : StanzaParser(collection) + { + stanza_ = std::make_shared<MyStanza>(); + } + + virtual std::shared_ptr<ToplevelElement> getElement() const { + return stanza_; + } + + private: + std::shared_ptr<MyStanza> stanza_; + }; + + MyPayload1ParserFactory factory1_; + MyPayload2ParserFactory factory2_; + PayloadParserFactoryCollection* factoryCollection_; }; CPPUNIT_TEST_SUITE_REGISTRATION(StanzaParserTest); diff --git a/Swiften/Parser/UnitTest/StanzaParserTester.h b/Swiften/Parser/UnitTest/StanzaParserTester.h index e4ce48e..36f41c9 100644 --- a/Swiften/Parser/UnitTest/StanzaParserTester.h +++ b/Swiften/Parser/UnitTest/StanzaParserTester.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once @@ -10,5 +10,5 @@ #include <Swiften/Parser/UnitTest/ParserTester.h> namespace Swift { - typedef ParserTester<StanzaParser> StanzaParserTester; + typedef ParserTester<StanzaParser> StanzaParserTester; } diff --git a/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp b/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp index 4bc971f..4664df2 100644 --- a/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp +++ b/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -13,58 +13,96 @@ using namespace Swift; class StreamFeaturesParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StreamFeaturesParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST(testParse_Empty); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - StreamFeaturesParser testling; - ElementParserTester parser(&testling); - - CPPUNIT_ASSERT(parser.parse( - "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>" - "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>" - "<compression xmlns=\"http://jabber.org/features/compress\">" - "<method>zlib</method>" - "<method>lzw</method>" - "</compression>" - "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" - "<mechanism>DIGEST-MD5</mechanism>" - "<mechanism>PLAIN</mechanism>" - "</mechanisms>" - "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>" - "<sm xmlns='urn:xmpp:sm:2'/>" - "<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>" - "<ver xmlns=\"urn:xmpp:features:rosterver\"/>" - "</stream:features>")); - - StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); - CPPUNIT_ASSERT(element->hasStartTLS()); - CPPUNIT_ASSERT(element->hasSession()); - CPPUNIT_ASSERT(element->hasResourceBind()); - CPPUNIT_ASSERT(element->hasCompressionMethod("zlib")); - CPPUNIT_ASSERT(element->hasCompressionMethod("lzw")); - CPPUNIT_ASSERT(element->hasAuthenticationMechanisms()); - CPPUNIT_ASSERT(element->hasAuthenticationMechanism("DIGEST-MD5")); - CPPUNIT_ASSERT(element->hasAuthenticationMechanism("PLAIN")); - CPPUNIT_ASSERT(element->hasStreamManagement()); - CPPUNIT_ASSERT(element->hasRosterVersioning()); - } - - void testParse_Empty() { - StreamFeaturesParser testling; - ElementParserTester parser(&testling); - - CPPUNIT_ASSERT(parser.parse("<stream:features xmlns:stream='http://etherx.jabber.org/streams'/>")); - - StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); - CPPUNIT_ASSERT(!element->hasStartTLS()); - CPPUNIT_ASSERT(!element->hasSession()); - CPPUNIT_ASSERT(!element->hasResourceBind()); - CPPUNIT_ASSERT(!element->hasAuthenticationMechanisms()); - } + CPPUNIT_TEST_SUITE(StreamFeaturesParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Empty); + CPPUNIT_TEST(testParse_AuthenticationHostname); + CPPUNIT_TEST(testParse_AuthenticationHostnameEmpty); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + StreamFeaturesParser testling; + ElementParserTester parser(&testling); + + CPPUNIT_ASSERT(parser.parse( + "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>" + "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>" + "<compression xmlns=\"http://jabber.org/features/compress\">" + "<method>zlib</method>" + "<method>lzw</method>" + "</compression>" + "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + "<mechanism>DIGEST-MD5</mechanism>" + "<mechanism>PLAIN</mechanism>" + "</mechanisms>" + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>" + "<sm xmlns='urn:xmpp:sm:2'/>" + "<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>" + "<ver xmlns=\"urn:xmpp:features:rosterver\"/>" + "</stream:features>")); + + StreamFeatures::ref element = std::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); + CPPUNIT_ASSERT(element->hasStartTLS()); + CPPUNIT_ASSERT(element->hasSession()); + CPPUNIT_ASSERT(element->hasResourceBind()); + CPPUNIT_ASSERT(element->hasCompressionMethod("zlib")); + CPPUNIT_ASSERT(element->hasCompressionMethod("lzw")); + CPPUNIT_ASSERT(element->hasAuthenticationMechanisms()); + CPPUNIT_ASSERT(element->hasAuthenticationMechanism("DIGEST-MD5")); + CPPUNIT_ASSERT(element->hasAuthenticationMechanism("PLAIN")); + CPPUNIT_ASSERT(!element->getAuthenticationHostname()); + CPPUNIT_ASSERT(element->hasStreamManagement()); + CPPUNIT_ASSERT(element->hasRosterVersioning()); + } + + void testParse_Empty() { + StreamFeaturesParser testling; + ElementParserTester parser(&testling); + + CPPUNIT_ASSERT(parser.parse("<stream:features xmlns:stream='http://etherx.jabber.org/streams'/>")); + + StreamFeatures::ref element = std::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); + CPPUNIT_ASSERT(!element->hasStartTLS()); + CPPUNIT_ASSERT(!element->hasSession()); + CPPUNIT_ASSERT(!element->hasResourceBind()); + CPPUNIT_ASSERT(!element->hasAuthenticationMechanisms()); + } + + void testParse_AuthenticationHostname() { + StreamFeaturesParser testling; + ElementParserTester parser(&testling); + std::string hostname("auth42.us.example.com"); + + CPPUNIT_ASSERT(parser.parse( + "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>" + "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + "<mechanism>GSSAPI</mechanism>" + "<hostname xmlns=\"urn:xmpp:domain-based-name:1\">auth42.us.example.com</hostname>" + "</mechanisms>" + "</stream:features>")); + + StreamFeatures::ref element = std::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); + CPPUNIT_ASSERT(element->hasAuthenticationMechanism("GSSAPI")); + CPPUNIT_ASSERT_EQUAL(*element->getAuthenticationHostname(), hostname); + } + + void testParse_AuthenticationHostnameEmpty() { + StreamFeaturesParser testling; + ElementParserTester parser(&testling); + + CPPUNIT_ASSERT(parser.parse( + "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>" + "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + "<mechanism>GSSAPI</mechanism>" + "<hostname xmlns=\"urn:xmpp:domain-based-name:1\"></hostname>" + "</mechanisms>" + "</stream:features>")); + + StreamFeatures::ref element = std::dynamic_pointer_cast<StreamFeatures>(testling.getElement()); + CPPUNIT_ASSERT(element->hasAuthenticationMechanism("GSSAPI")); + CPPUNIT_ASSERT(element->getAuthenticationHostname()->empty()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StreamFeaturesParserTest); diff --git a/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp b/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp index 07b7b31..704a89f 100644 --- a/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp +++ b/Swiften/Parser/UnitTest/StreamManagementEnabledParserTest.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> @@ -13,22 +13,22 @@ using namespace Swift; class StreamManagementEnabledParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StreamManagementEnabledParserTest); - CPPUNIT_TEST(testParse); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse() { - StreamManagementEnabledParser testling; - ElementParserTester parser(&testling); - - CPPUNIT_ASSERT(parser.parse( - "<enabled xmlns=\"urn:xmpp:sm:3\" id=\"some-long-sm-id\" resume=\"true\"/>")); - - boost::shared_ptr<StreamManagementEnabled> element = boost::dynamic_pointer_cast<StreamManagementEnabled>(testling.getElement()); - CPPUNIT_ASSERT(element->getResumeSupported()); - CPPUNIT_ASSERT_EQUAL(std::string("some-long-sm-id"), element->getResumeID()); - } + CPPUNIT_TEST_SUITE(StreamManagementEnabledParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + StreamManagementEnabledParser testling; + ElementParserTester parser(&testling); + + CPPUNIT_ASSERT(parser.parse( + "<enabled xmlns=\"urn:xmpp:sm:3\" id=\"some-long-sm-id\" resume=\"true\"/>")); + + std::shared_ptr<StreamManagementEnabled> element = std::dynamic_pointer_cast<StreamManagementEnabled>(testling.getElement()); + CPPUNIT_ASSERT(element->getResumeSupported()); + CPPUNIT_ASSERT_EQUAL(std::string("some-long-sm-id"), element->getResumeID()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StreamManagementEnabledParserTest); diff --git a/Swiften/Parser/UnitTest/XMLParserTest.cpp b/Swiften/Parser/UnitTest/XMLParserTest.cpp index 4bdeb54..89229c9 100644 --- a/Swiften/Parser/UnitTest/XMLParserTest.cpp +++ b/Swiften/Parser/UnitTest/XMLParserTest.cpp @@ -1,11 +1,12 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> +#include <unordered_map> #include <vector> #include <string> @@ -21,337 +22,470 @@ using namespace Swift; template <typename ParserType> class XMLParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(XMLParserTest); - CPPUNIT_TEST(testParse_NestedElements); - CPPUNIT_TEST(testParse_ElementInNamespacedElement); - CPPUNIT_TEST(testParse_CharacterData); - CPPUNIT_TEST(testParse_XMLEntity); - CPPUNIT_TEST(testParse_NamespacePrefix); - CPPUNIT_TEST(testParse_UnhandledXML); - CPPUNIT_TEST(testParse_InvalidXML); - CPPUNIT_TEST(testParse_InErrorState); - CPPUNIT_TEST(testParse_Incremental); - CPPUNIT_TEST(testParse_WhitespaceInAttribute); - CPPUNIT_TEST(testParse_AttributeWithoutNamespace); - CPPUNIT_TEST(testParse_AttributeWithNamespace); - CPPUNIT_TEST(testParse_BillionLaughs); - CPPUNIT_TEST(testParse_InternalEntity); - //CPPUNIT_TEST(testParse_UndefinedPrefix); - //CPPUNIT_TEST(testParse_UndefinedAttributePrefix); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(XMLParserTest); + CPPUNIT_TEST(testParse_NestedElements); + CPPUNIT_TEST(testParse_ElementInNamespacedElement); + CPPUNIT_TEST(testParse_CharacterData); + CPPUNIT_TEST(testParse_XMLEntity); + CPPUNIT_TEST(testParse_NamespacePrefix); + CPPUNIT_TEST(testParse_UnhandledXML); + CPPUNIT_TEST(testParse_InvalidXML); + CPPUNIT_TEST(testParse_InErrorState); + CPPUNIT_TEST(testParse_Incremental); + CPPUNIT_TEST(testParse_WhitespaceInAttribute); + CPPUNIT_TEST(testParse_AttributeWithoutNamespace); + CPPUNIT_TEST(testParse_AttributeWithNamespace); + CPPUNIT_TEST(testParse_AttributeWithNamespaceNoPrefix); + CPPUNIT_TEST(testParse_BillionLaughs); + CPPUNIT_TEST(testParse_InternalEntity); + //CPPUNIT_TEST(testParse_UndefinedPrefix); + //CPPUNIT_TEST(testParse_UndefinedAttributePrefix); + CPPUNIT_TEST(testParse_AllowCommentsInXML); + CPPUNIT_TEST(testParse_DisallowCommentsInXML); + CPPUNIT_TEST(testParse_Doctype); + CPPUNIT_TEST(testParse_ProcessingInstructions); + CPPUNIT_TEST(testParse_ProcessingPrefixedElement); + CPPUNIT_TEST(testParse_InvalidlyEncodedInput); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse_NestedElements() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(testling.parse( + "<iq type=\"get\">" + "<query xmlns='jabber:iq:version'/>" + "</iq>")); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); + + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("get"), client_.events[0].attributes.getAttribute("type")); + CPPUNIT_ASSERT_EQUAL(std::string(), client_.events[0].ns); + + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[1].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].ns); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[1].namespaces.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[1].namespaces.count("")); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].namespaces[""]); + + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[2].data); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[2].ns); + + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[3].data); + CPPUNIT_ASSERT_EQUAL(std::string(), client_.events[3].ns); + } + + void testParse_ElementInNamespacedElement() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(testling.parse( + "<query xmlns='jabber:iq:version'>" + "<name>Swift</name>" + "</query>")); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), client_.events.size()); + + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[0].ns); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].namespaces.size()); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[0].namespaces[""]); + + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("name"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].ns); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[1].namespaces.size()); + + CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string("Swift"), client_.events[2].data); + + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(std::string("name"), client_.events[3].data); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[3].ns); - public: - void testParse_NestedElements() { - ParserType testling(&client_); + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[4].type); + CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[4].data); + CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[4].ns); + } - CPPUNIT_ASSERT(testling.parse( - "<iq type=\"get\">" - "<query xmlns='jabber:iq:version'/>" - "</iq>")); + void testParse_CharacterData() { + ParserType testling(&client_); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); + CPPUNIT_ASSERT(testling.parse("<html>bla<i>bli</i>blo</html>")); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); - CPPUNIT_ASSERT_EQUAL(std::string("get"), client_.events[0].attributes.getAttribute("type")); - CPPUNIT_ASSERT_EQUAL(std::string(), client_.events[0].ns); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(7), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[1].attributes.getEntries().size()); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].ns); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[2].data); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[2].ns); + CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[3].data); - CPPUNIT_ASSERT_EQUAL(std::string(), client_.events[3].ns); - } + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string("i"), client_.events[2].data); - void testParse_ElementInNamespacedElement() { - ParserType testling(&client_); + CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(std::string("bli"), client_.events[3].data); - CPPUNIT_ASSERT(testling.parse( - "<query xmlns='jabber:iq:version'>" - "<name>Swift</name>" - "</query>")); + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[4].type); + CPPUNIT_ASSERT_EQUAL(std::string("i"), client_.events[4].data); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[5].type); + CPPUNIT_ASSERT_EQUAL(std::string("blo"), client_.events[5].data); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[0].attributes.getEntries().size()); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[0].ns); + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[6].type); + CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[6].data); + } - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("name"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[1].ns); + void testParse_XMLEntity() { + ParserType testling(&client_); - CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string("Swift"), client_.events[2].data); + CPPUNIT_ASSERT(testling.parse("<html><></html>")); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(std::string("name"), client_.events[3].data); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[3].ns); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[4].type); - CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[4].data); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:version"), client_.events[4].ns); - } + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[0].data); - void testParse_CharacterData() { - ParserType testling(&client_); + CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("<"), client_.events[1].data); - CPPUNIT_ASSERT(testling.parse("<html>bla<i>bli</i>blo</html>")); + CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string(">"), client_.events[2].data); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(7), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[3].data); + } - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[0].data); + void testParse_NamespacePrefix() { + ParserType testling(&client_); - CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[1].data); + CPPUNIT_ASSERT(testling.parse("<p:x xmlns:p='bla'><p:y/></p:x>")); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string("i"), client_.events[2].data); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(std::string("bli"), client_.events[3].data); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("x"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[0].ns); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].namespaces.size()); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[0].namespaces["p"]); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[4].type); - CPPUNIT_ASSERT_EQUAL(std::string("i"), client_.events[4].data); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("y"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[1].ns); - CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[5].type); - CPPUNIT_ASSERT_EQUAL(std::string("blo"), client_.events[5].data); + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string("y"), client_.events[2].data); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[2].ns); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[6].type); - CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[6].data); - } + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(std::string("x"), client_.events[3].data); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[3].ns); + } - void testParse_XMLEntity() { - ParserType testling(&client_); + void testParse_UnhandledXML() { + ParserType testling(&client_, true); - CPPUNIT_ASSERT(testling.parse("<html><></html>")); + CPPUNIT_ASSERT(testling.parse("<iq><!-- Testing --></iq>")); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("<"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[1].data); + } - CPPUNIT_ASSERT_EQUAL(Client::CharacterData, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string(">"), client_.events[2].data); + void testParse_InvalidXML() { + ParserType testling(&client_); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(std::string("html"), client_.events[3].data); - } + CPPUNIT_ASSERT(!testling.parse("<iq><bla></iq>")); + } - void testParse_NamespacePrefix() { - ParserType testling(&client_); + void testParse_InErrorState() { + ParserType testling(&client_); - CPPUNIT_ASSERT(testling.parse("<p:x xmlns:p='bla'><p:y/></p:x>")); + CPPUNIT_ASSERT(!testling.parse("<iq><bla></iq>")); + CPPUNIT_ASSERT(!testling.parse("<iq/>")); + } - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); + void testParse_Incremental() { + ParserType testling(&client_); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("x"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[0].ns); + CPPUNIT_ASSERT(testling.parse("<iq")); + CPPUNIT_ASSERT(testling.parse("></iq>")); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("y"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[1].ns); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string("y"), client_.events[2].data); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[2].ns); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(std::string("x"), client_.events[3].data); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[3].ns); - } + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[1].data); + } - void testParse_UnhandledXML() { - ParserType testling(&client_); + void testParse_CompleteDocument() { + ParserType testling(&client_); - CPPUNIT_ASSERT(testling.parse("<iq><!-- Testing --></iq>")); + CPPUNIT_ASSERT(!testling.parse("<iq", true)); + CPPUNIT_ASSERT(!testling.parse("<iq>", true)); + CPPUNIT_ASSERT(!testling.parse("<iq><child>foo</child>", true)); + CPPUNIT_ASSERT(testling.parse("<iq><child>foo</child></iq>", true)); + } - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events.size()); + void testParse_WhitespaceInAttribute() { + ParserType testling(&client_); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data); + CPPUNIT_ASSERT(testling.parse( + "<query xmlns='http://www.xmpp.org/extensions/xep-0084.html#ns-data '>")); + CPPUNIT_ASSERT(testling.parse( + "<presence/>")); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("presence"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string("presence"), client_.events[2].data); + } - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[1].data); - } + void testParse_AttributeWithoutNamespace() { + ParserType testling(&client_); - void testParse_InvalidXML() { - ParserType testling(&client_); + CPPUNIT_ASSERT(testling.parse( + "<query xmlns='http://swift.im' attr='3'/>")); - CPPUNIT_ASSERT(!testling.parse("<iq><bla></iq>")); - } + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("attr"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace()); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].attributes.getEntries()[0].getAttribute().getPrefix()); + } - void testParse_InErrorState() { - ParserType testling(&client_); + void testParse_AttributeWithNamespace() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(testling.parse( + "<query xmlns='http://swift.im' xmlns:f='http://swift.im/f' f:attr='3'/>")); - CPPUNIT_ASSERT(!testling.parse("<iq><bla></iq>")); - CPPUNIT_ASSERT(!testling.parse("<iq/>")); - } + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("attr"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); + CPPUNIT_ASSERT_EQUAL(std::string("http://swift.im/f"), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace()); + CPPUNIT_ASSERT_EQUAL(std::string("f"), client_.events[0].attributes.getEntries()[0].getAttribute().getPrefix()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events[0].namespaces.size()); + CPPUNIT_ASSERT_EQUAL(std::string("http://swift.im"), client_.events[0].namespaces[""]); + CPPUNIT_ASSERT_EQUAL(std::string("http://swift.im/f"), client_.events[0].namespaces["f"]); + } - void testParse_Incremental() { - ParserType testling(&client_); + void testParse_AttributeWithNamespaceNoPrefix() { + ParserType testling(&client_); - CPPUNIT_ASSERT(testling.parse("<iq")); - CPPUNIT_ASSERT(testling.parse("></iq>")); + CPPUNIT_ASSERT(testling.parse( + "<query xmlns='http://swift.im' xmlns:f='http://swift.im/f' attr='3'/>")); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("attr"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace()); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].attributes.getEntries()[0].getAttribute().getPrefix()); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events[0].namespaces.size()); + CPPUNIT_ASSERT_EQUAL(std::string("http://swift.im"), client_.events[0].namespaces[""]); + CPPUNIT_ASSERT_EQUAL(std::string("http://swift.im/f"), client_.events[0].namespaces["f"]); + } - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[0].data); + void testParse_BillionLaughs() { + ParserType testling(&client_); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("iq"), client_.events[1].data); - } - - void testParse_WhitespaceInAttribute() { - ParserType testling(&client_); - - CPPUNIT_ASSERT(testling.parse( - "<query xmlns='http://www.xmpp.org/extensions/xep-0084.html#ns-data '>")); - CPPUNIT_ASSERT(testling.parse( - "<presence/>")); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), client_.events.size()); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("query"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("presence"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string("presence"), client_.events[2].data); - } - - void testParse_AttributeWithoutNamespace() { - ParserType testling(&client_); - - CPPUNIT_ASSERT(testling.parse( - "<query xmlns='http://swift.im' attr='3'/>")); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); - CPPUNIT_ASSERT_EQUAL(std::string("attr"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); - CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace()); - } - - void testParse_AttributeWithNamespace() { - ParserType testling(&client_); - - CPPUNIT_ASSERT(testling.parse( - "<query xmlns='http://swift.im' xmlns:f='http://swift.im/f' f:attr='3'/>")); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); - CPPUNIT_ASSERT_EQUAL(std::string("attr"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); - CPPUNIT_ASSERT_EQUAL(std::string("http://swift.im/f"), client_.events[0].attributes.getEntries()[0].getAttribute().getNamespace()); - } - - void testParse_BillionLaughs() { - ParserType testling(&client_); - - CPPUNIT_ASSERT(!testling.parse( - "<?xml version=\"1.0\"?>" - "<!DOCTYPE lolz [" - " <!ENTITY lol \"lol\">" - " <!ENTITY lol2 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">" - " <!ENTITY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">" - " <!ENTITY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">" - " <!ENTITY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">" - " <!ENTITY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">" - " <!ENTITY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">" - " <!ENTITY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">" - " <!ENTITY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">" - "]>" - "<lolz>&lol9;</lolz>" - )); - } - - void testParse_InternalEntity() { - ParserType testling(&client_); - - CPPUNIT_ASSERT(!testling.parse("<!DOCTYPE foo [<!ENTITY bar \"Bar\">]><foo>&bar;</foo>")); - } - - void testParse_UndefinedPrefix() { - ParserType testling(&client_); - - CPPUNIT_ASSERT(testling.parse( - "<foo:bar><bla/></foo:bar>")); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); - - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("foo:bar"), client_.events[0].data); - CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].ns); - - CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[1].data); - CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[1].ns); - - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[2].data); - CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[2].ns); - - CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(std::string("foo:bar"), client_.events[3].data); - CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[3].ns); - } - - void testParse_UndefinedAttributePrefix() { - ParserType testling(&client_); - - CPPUNIT_ASSERT(testling.parse( - "<foo bar:baz='bla'/>")); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); - CPPUNIT_ASSERT_EQUAL(std::string("bar:baz"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); - } - - private: - class Client : public XMLParserClient { - public: - enum Type { StartElement, EndElement, CharacterData }; - struct Event { - Event( - Type type, - const std::string& data, - const std::string& ns, - const AttributeMap& attributes) - : type(type), data(data), ns(ns), attributes(attributes) {} - Event(Type type, const std::string& data, const std::string& ns = std::string()) - : type(type), data(data), ns(ns) {} - - Type type; - std::string data; - std::string ns; - AttributeMap attributes; - }; - - Client() {} - - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - events.push_back(Event(StartElement, element, ns, attributes)); - } - - virtual void handleEndElement(const std::string& element, const std::string& ns) { - events.push_back(Event(EndElement, element, ns)); - } - - virtual void handleCharacterData(const std::string& data) { - events.push_back(Event(CharacterData, data)); - } - - std::vector<Event> events; - } client_; + CPPUNIT_ASSERT(!testling.parse( + "<?xml version=\"1.0\"?>" + "<!DOCTYPE lolz [" + " <!ENTITY lol \"lol\">" + " <!ENTITY lol2 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">" + " <!ENTITY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">" + " <!ENTITY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">" + " <!ENTITY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">" + " <!ENTITY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">" + " <!ENTITY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">" + " <!ENTITY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">" + " <!ENTITY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">" + "]>" + "<lolz>&lol9;</lolz>" + )); + } + + void testParse_InternalEntity() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(!testling.parse("<!DOCTYPE foo [<!ENTITY bar \"Bar\">]><foo>&bar;</foo>")); + } + + void testParse_UndefinedPrefix() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(testling.parse( + "<foo:bar><bla/></foo:bar>")); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), client_.events.size()); + + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("foo:bar"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[0].ns); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), client_.events[0].namespaces.size()); + + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[1].ns); + + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(std::string("bla"), client_.events[2].data); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[2].ns); + + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(std::string("foo:bar"), client_.events[3].data); + CPPUNIT_ASSERT_EQUAL(std::string(""), client_.events[3].ns); + } + + void testParse_UndefinedAttributePrefix() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(testling.parse("<foo bar:baz='bla'/>")); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), client_.events[0].attributes.getEntries().size()); + CPPUNIT_ASSERT_EQUAL(std::string("bar:baz"), client_.events[0].attributes.getEntries()[0].getAttribute().getName()); + } + + void testParse_AllowCommentsInXML() { + ParserType testling(&client_, true); + + CPPUNIT_ASSERT(testling.parse("<message><!-- Some More Comments Testing --></message>")); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events.size()); + + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("message"), client_.events[0].data); + + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("message"), client_.events[1].data); + } + + void testParse_DisallowCommentsInXML() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(!testling.parse("<message><!-- Some More Comments Testing --></message>")); + } + + void testParse_Doctype() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(!testling.parse("<!DOCTYPE greeting SYSTEM \"hello.dtd\">")); + } + + void testParse_ProcessingInstructions() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(!testling.parse("<?xml-stylesheet type=\"text/xsl\" href=\"Sample.xsl\"?>")); + } + + void testParse_ProcessingPrefixedElement() { + client_.testingStartElementPrefix = true; + ParserType testling(&client_); + + CPPUNIT_ASSERT(testling.parse("<prefix:message xmlns='uri' xmlns:prefix='uriPrefix'/>")); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), client_.events.size()); + + CPPUNIT_ASSERT_EQUAL(Client::StartElementPrefix, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("message"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(std::string("uriPrefix"), client_.events[0].ns); + CPPUNIT_ASSERT_EQUAL(std::string("prefix"), client_.events[0].prefix); + + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(std::string("message"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(std::string("uriPrefix"), client_.events[1].ns); + } + + void testParse_InvalidlyEncodedInput() { + ParserType testling(&client_); + + // The following input was generated by a fuzzer, and triggered a crash in the LibXML2 parser because + // some types of error (buffer I/O errors, for instance) will not update the error in the parser context, + // and the code used to rely on that error always being set if parsing failed. + // This particular input will trick the parser into believing the encoding is UTF-16LE, which eventually will lead + // to two invalid encodings, followed by an I/O error. The latter will end parsing without updating the + // error in the parsing context, which used to trigger a crash. + testling.parse(std::string("<\0?\0\x80q type='get' id='aab9a'<<query xmlns='jabber:iq:roster'/>\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9b\x9br:i><quq:private'><storage xml s='s'\x00\x10</query></iq>", 271)); + testling.parse("<iq type='get'\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e\x9e to='ad5d8d2b25' ext='ca cs min@wonderland.t' id='aabda'><vCard xmlnr='vcard-temp'/>O/iq>"); + testling.parse("<\xff\xff\xff\x7fype:'get' to='won\x84" "erland.lit' id='aabea'><tuery xmlns='\xd8Vtp://jabber.org/p\x88ot\x8b" "col/disco#info'/>abber.org/protocol/disco#Nnfo'/></iq>"); + } + + private: + class Client : public XMLParserClient { + public: + using NamespaceMap = std::unordered_map<std::string /* prefix */, std::string /* uri */>; + enum Type { StartElement, StartElementPrefix, EndElement, CharacterData, NamespaceDefined }; + struct Event { + Event( + Type type, + const std::string& data, + const std::string& ns, + const std::string& prefix, + const AttributeMap& attributes, + NamespaceMap namespaces) + : type(type), data(data), ns(ns), prefix(prefix), attributes(attributes), namespaces(std::move(namespaces)) {} + Event( + Type type, + const std::string& data, + const std::string& ns, + const AttributeMap& attributes, + NamespaceMap namespaces = {}) + : Event(type, data, ns, {}, attributes, std::move(namespaces)) {} + Event(Type type, const std::string& data, const std::string& ns = std::string()) + : Event(type, data, ns, "", AttributeMap(), NamespaceMap()) {} + + Type type; + std::string data; + std::string ns; + std::string prefix; + AttributeMap attributes; + NamespaceMap namespaces; + }; + + Client() {} + + void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) override { + if (testingStartElementPrefix) return; + events.push_back(Event(StartElement, element, ns, attributes, std::move(namespaces_))); + } + + void handleStartElementPrefix(const std::string& prefix, const std::string& uri, const std::string& name, const AttributeMap&) override { + if (!testingStartElementPrefix) return; + events.push_back(Event(StartElementPrefix, name, uri, prefix, AttributeMap(), NamespaceMap())); + } + + void handleEndElement(const std::string& element, const std::string& ns) override { + events.push_back(Event(EndElement, element, ns)); + } + + void handleCharacterData(const std::string& data) override { + events.push_back(Event(CharacterData, data)); + } + + void handleNamespaceDeclaration(const std::string& prefix, const std::string& uri) override { + namespaces_[prefix] = uri; + } + + std::vector<Event> events; + bool testingStartElementPrefix = false; + private: + NamespaceMap namespaces_; + } client_; }; #ifdef HAVE_EXPAT diff --git a/Swiften/Parser/UnitTest/XMPPParserTest.cpp b/Swiften/Parser/UnitTest/XMPPParserTest.cpp index f8d60f2..2424d4d 100644 --- a/Swiften/Parser/UnitTest/XMPPParserTest.cpp +++ b/Swiften/Parser/UnitTest/XMPPParserTest.cpp @@ -1,196 +1,197 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ +#include <string> +#include <vector> + #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <vector> -#include <Swiften/Elements/ProtocolHeader.h> -#include <string> -#include <Swiften/Parser/XMPPParser.h> -#include <Swiften/Parser/ElementParser.h> -#include <Swiften/Parser/XMPPParserClient.h> -#include <Swiften/Parser/PayloadParserFactoryCollection.h> -#include <Swiften/Parser/PlatformXMLParserFactory.h> -#include <Swiften/Elements/Presence.h> #include <Swiften/Elements/IQ.h> #include <Swiften/Elements/Message.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Elements/ProtocolHeader.h> #include <Swiften/Elements/StreamFeatures.h> #include <Swiften/Elements/UnknownElement.h> +#include <Swiften/Parser/ElementParser.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PlatformXMLParserFactory.h> +#include <Swiften/Parser/XMPPParser.h> +#include <Swiften/Parser/XMPPParserClient.h> using namespace Swift; class XMPPParserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(XMPPParserTest); - CPPUNIT_TEST(testParse_SimpleSession); - CPPUNIT_TEST(testParse_SimpleClientFromServerSession); - CPPUNIT_TEST(testParse_Presence); - CPPUNIT_TEST(testParse_IQ); - CPPUNIT_TEST(testParse_Message); - CPPUNIT_TEST(testParse_StreamFeatures); - CPPUNIT_TEST(testParse_UnknownElement); - CPPUNIT_TEST(testParse_StrayCharacterData); - CPPUNIT_TEST(testParse_InvalidStreamStart); - CPPUNIT_TEST(testParse_ElementEndAfterInvalidStreamStart); - CPPUNIT_TEST_SUITE_END(); - - public: - void testParse_SimpleSession() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<?xml version='1.0'?>")); - CPPUNIT_ASSERT(testling.parse("<stream:stream to='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' >")); - CPPUNIT_ASSERT(testling.parse("<presence/>")); - CPPUNIT_ASSERT(testling.parse("<presence/>")); - CPPUNIT_ASSERT(testling.parse("<iq/>")); - CPPUNIT_ASSERT(testling.parse("</stream:stream>")); - - CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::StreamStart, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("example.com"), client_.events[0].header->getTo()); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[3].type); - CPPUNIT_ASSERT_EQUAL(Client::StreamEnd, client_.events[4].type); - } - - void testParse_SimpleClientFromServerSession() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<?xml version='1.0'?>")); - CPPUNIT_ASSERT(testling.parse("<stream:stream from='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='aeab'>")); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::StreamStart, client_.events[0].type); - CPPUNIT_ASSERT_EQUAL(std::string("example.com"), client_.events[0].header->getFrom()); - CPPUNIT_ASSERT_EQUAL(std::string("aeab"), client_.events[0].header->getID()); - } - - - void testParse_Presence() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); - CPPUNIT_ASSERT(testling.parse("<presence/>")); - - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); - CPPUNIT_ASSERT(dynamic_cast<Presence*>(client_.events[1].element.get())); - } - - void testParse_IQ() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); - CPPUNIT_ASSERT(testling.parse("<iq/>")); - - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); - CPPUNIT_ASSERT(dynamic_cast<IQ*>(client_.events[1].element.get())); - } - - void testParse_Message() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); - CPPUNIT_ASSERT(testling.parse("<message/>")); - - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); - CPPUNIT_ASSERT(dynamic_cast<Message*>(client_.events[1].element.get())); - } - - void testParse_StreamFeatures() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); - CPPUNIT_ASSERT(testling.parse("<stream:features/>")); - - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); - CPPUNIT_ASSERT(dynamic_cast<StreamFeatures*>(client_.events[1].element.get())); - } - - void testParse_UnknownElement() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); - CPPUNIT_ASSERT(testling.parse("<presence/>")); - CPPUNIT_ASSERT(testling.parse("<foo/>")); - CPPUNIT_ASSERT(testling.parse("<bar/>")); - CPPUNIT_ASSERT(testling.parse("<presence/>")); - - CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); - CPPUNIT_ASSERT(dynamic_cast<UnknownElement*>(client_.events[2].element.get())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[3].type); - CPPUNIT_ASSERT(dynamic_cast<UnknownElement*>(client_.events[3].element.get())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[4].type); - CPPUNIT_ASSERT(dynamic_cast<Presence*>(client_.events[4].element.get())); - } - - void testParse_StrayCharacterData() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); - CPPUNIT_ASSERT(testling.parse("<presence/>")); - CPPUNIT_ASSERT(testling.parse("bla")); - CPPUNIT_ASSERT(testling.parse("<iq/>")); - - CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(client_.events.size())); - CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); - CPPUNIT_ASSERT(dynamic_cast<IQ*>(client_.events[2].element.get())); - } - - void testParse_InvalidStreamStart() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - - CPPUNIT_ASSERT(!testling.parse("<tream>")); - } - - void testParse_ElementEndAfterInvalidStreamStart() { - XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + CPPUNIT_TEST_SUITE(XMPPParserTest); + CPPUNIT_TEST(testParse_SimpleSession); + CPPUNIT_TEST(testParse_SimpleClientFromServerSession); + CPPUNIT_TEST(testParse_Presence); + CPPUNIT_TEST(testParse_IQ); + CPPUNIT_TEST(testParse_Message); + CPPUNIT_TEST(testParse_StreamFeatures); + CPPUNIT_TEST(testParse_UnknownElement); + CPPUNIT_TEST(testParse_StrayCharacterData); + CPPUNIT_TEST(testParse_InvalidStreamStart); + CPPUNIT_TEST(testParse_ElementEndAfterInvalidStreamStart); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse_SimpleSession() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<?xml version='1.0'?>")); + CPPUNIT_ASSERT(testling.parse("<stream:stream to='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' >")); + CPPUNIT_ASSERT(testling.parse("<presence/>")); + CPPUNIT_ASSERT(testling.parse("<presence/>")); + CPPUNIT_ASSERT(testling.parse("<iq/>")); + CPPUNIT_ASSERT(testling.parse("</stream:stream>")); + + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::StreamStart, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("example.com"), client_.events[0].header->getTo()); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[3].type); + CPPUNIT_ASSERT_EQUAL(Client::StreamEnd, client_.events[4].type); + } + + void testParse_SimpleClientFromServerSession() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<?xml version='1.0'?>")); + CPPUNIT_ASSERT(testling.parse("<stream:stream from='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='aeab'>")); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::StreamStart, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(std::string("example.com"), client_.events[0].header->getFrom()); + CPPUNIT_ASSERT_EQUAL(std::string("aeab"), client_.events[0].header->getID()); + } + + + void testParse_Presence() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); + CPPUNIT_ASSERT(testling.parse("<presence/>")); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); + CPPUNIT_ASSERT(dynamic_cast<Presence*>(client_.events[1].element.get())); + } + + void testParse_IQ() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); + CPPUNIT_ASSERT(testling.parse("<iq/>")); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); + CPPUNIT_ASSERT(dynamic_cast<IQ*>(client_.events[1].element.get())); + } + + void testParse_Message() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); + CPPUNIT_ASSERT(testling.parse("<message/>")); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); + CPPUNIT_ASSERT(dynamic_cast<Message*>(client_.events[1].element.get())); + } + + void testParse_StreamFeatures() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); + CPPUNIT_ASSERT(testling.parse("<stream:features/>")); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[1].type); + CPPUNIT_ASSERT(dynamic_cast<StreamFeatures*>(client_.events[1].element.get())); + } + + void testParse_UnknownElement() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); + CPPUNIT_ASSERT(testling.parse("<presence/>")); + CPPUNIT_ASSERT(testling.parse("<foo/>")); + CPPUNIT_ASSERT(testling.parse("<bar/>")); + CPPUNIT_ASSERT(testling.parse("<presence/>")); + + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); + CPPUNIT_ASSERT(dynamic_cast<UnknownElement*>(client_.events[2].element.get())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[3].type); + CPPUNIT_ASSERT(dynamic_cast<UnknownElement*>(client_.events[3].element.get())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[4].type); + CPPUNIT_ASSERT(dynamic_cast<Presence*>(client_.events[4].element.get())); + } + + void testParse_StrayCharacterData() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>")); + CPPUNIT_ASSERT(testling.parse("<presence/>")); + CPPUNIT_ASSERT(testling.parse("bla")); + CPPUNIT_ASSERT(testling.parse("<iq/>")); + + CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(client_.events.size())); + CPPUNIT_ASSERT_EQUAL(Client::ElementEvent, client_.events[2].type); + CPPUNIT_ASSERT(dynamic_cast<IQ*>(client_.events[2].element.get())); + } + + void testParse_InvalidStreamStart() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); + + CPPUNIT_ASSERT(!testling.parse("<tream>")); + } + + void testParse_ElementEndAfterInvalidStreamStart() { + XMPPParser testling(&client_, &factories_, &xmlParserFactory_); - CPPUNIT_ASSERT(!testling.parse("<tream/>")); - } + CPPUNIT_ASSERT(!testling.parse("<tream/>")); + } - private: - class Client : public XMPPParserClient { - public: - enum Type { StreamStart, ElementEvent, StreamEnd }; - struct Event { - Event(Type type, boost::shared_ptr<Element> element) - : type(type), element(element) {} - Event(Type type, const ProtocolHeader& header) : type(type), header(header) {} + private: + class Client : public XMPPParserClient { + public: + enum Type { StreamStart, ElementEvent, StreamEnd }; + struct Event { + Event(Type type, std::shared_ptr<ToplevelElement> element) + : type(type), element(element) {} + Event(Type type, const ProtocolHeader& header) : type(type), header(header) {} - Event(Type type) : type(type) {} + Event(Type type) : type(type) {} - Type type; - boost::optional<ProtocolHeader> header; - boost::shared_ptr<Element> element; - }; + Type type; + boost::optional<ProtocolHeader> header; + std::shared_ptr<ToplevelElement> element; + }; - Client() {} - - void handleStreamStart(const ProtocolHeader& header) { - events.push_back(Event(StreamStart, header)); - } - - void handleElement(boost::shared_ptr<Element> element) { - events.push_back(Event(ElementEvent, element)); - } - - void handleStreamEnd() { - events.push_back(Event(StreamEnd)); - } - - std::vector<Event> events; - } client_; - PayloadParserFactoryCollection factories_; - PlatformXMLParserFactory xmlParserFactory_; + Client() {} + + void handleStreamStart(const ProtocolHeader& header) { + events.push_back(Event(StreamStart, header)); + } + + void handleElement(std::shared_ptr<ToplevelElement> element) { + events.push_back(Event(ElementEvent, element)); + } + + void handleStreamEnd() { + events.push_back(Event(StreamEnd)); + } + + std::vector<Event> events; + } client_; + PayloadParserFactoryCollection factories_; + PlatformXMLParserFactory xmlParserFactory_; }; CPPUNIT_TEST_SUITE_REGISTRATION(XMPPParserTest); diff --git a/Swiften/Parser/UnknownElementParser.h b/Swiften/Parser/UnknownElementParser.h index 59133de..44c5464 100644 --- a/Swiften/Parser/UnknownElementParser.h +++ b/Swiften/Parser/UnknownElementParser.h @@ -1,17 +1,18 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <Swiften/Parser/GenericElementParser.h> +#include <Swiften/Base/API.h> #include <Swiften/Elements/UnknownElement.h> +#include <Swiften/Parser/GenericElementParser.h> namespace Swift { - class UnknownElementParser : public GenericElementParser<UnknownElement> { - public: - UnknownElementParser() : GenericElementParser<UnknownElement>() {} - }; + class SWIFTEN_API UnknownElementParser : public GenericElementParser<UnknownElement> { + public: + UnknownElementParser() : GenericElementParser<UnknownElement>() {} + }; } diff --git a/Swiften/Parser/UnknownPayloadParser.h b/Swiften/Parser/UnknownPayloadParser.h index 0843f41..1553704 100644 --- a/Swiften/Parser/UnknownPayloadParser.h +++ b/Swiften/Parser/UnknownPayloadParser.h @@ -1,26 +1,27 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 <Swiften/Base/API.h> #include <Swiften/Parser/PayloadParser.h> namespace Swift { - class UnknownPayloadParser : public PayloadParser { - public: - UnknownPayloadParser() {} + class SWIFTEN_API UnknownPayloadParser : public PayloadParser { + public: + UnknownPayloadParser() {} - 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&) {} - virtual boost::shared_ptr<Payload> getPayload() const { - return boost::shared_ptr<Payload>(); - } - }; + virtual std::shared_ptr<Payload> getPayload() const { + return std::shared_ptr<Payload>(); + } + }; } diff --git a/Swiften/Parser/XMLParser.cpp b/Swiften/Parser/XMLParser.cpp index cd7baea..8a0799f 100644 --- a/Swiften/Parser/XMLParser.cpp +++ b/Swiften/Parser/XMLParser.cpp @@ -1,14 +1,14 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/XMLParser.h> namespace Swift { -XMLParser::XMLParser(XMLParserClient* client) : client_(client) { +XMLParser::XMLParser(XMLParserClient* client, bool allowComments) : client_(client), allowComments_(allowComments){ } XMLParser::~XMLParser() { diff --git a/Swiften/Parser/XMLParser.h b/Swiften/Parser/XMLParser.h index 6ecc626..3b09d22 100644 --- a/Swiften/Parser/XMLParser.h +++ b/Swiften/Parser/XMLParser.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2019 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once @@ -11,20 +11,25 @@ #include <Swiften/Base/API.h> namespace Swift { - class XMLParserClient; + class XMLParserClient; - class SWIFTEN_API XMLParser { - public: - XMLParser(XMLParserClient* client); - virtual ~XMLParser(); + class SWIFTEN_API XMLParser { + public: + XMLParser(XMLParserClient* client, bool allowComments = false); + virtual ~XMLParser(); - virtual bool parse(const std::string& data) = 0; + virtual bool parse(const std::string& data, bool finalData = false) = 0; - XMLParserClient* getClient() const { - return client_; - } + XMLParserClient* getClient() const { + return client_; + } - private: - XMLParserClient* client_; - }; + bool allowsComments() const { + return allowComments_; + } + + private: + XMLParserClient* client_; + const bool allowComments_ = false; + }; } diff --git a/Swiften/Parser/XMLParserClient.cpp b/Swiften/Parser/XMLParserClient.cpp index 46d57b7..6698900 100644 --- a/Swiften/Parser/XMLParserClient.cpp +++ b/Swiften/Parser/XMLParserClient.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2019 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/XMLParserClient.h> @@ -11,5 +11,14 @@ namespace Swift { XMLParserClient::~XMLParserClient() { } +void XMLParserClient::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { +} + +void XMLParserClient::handleStartElementPrefix(const std::string&, const std::string&, const std::string&, const AttributeMap&) { +} + +void XMLParserClient::handleNamespaceDeclaration(const std::string&, const std::string&) { +} + } diff --git a/Swiften/Parser/XMLParserClient.h b/Swiften/Parser/XMLParserClient.h index 956eacf..2f0bc9e 100644 --- a/Swiften/Parser/XMLParserClient.h +++ b/Swiften/Parser/XMLParserClient.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2019 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once @@ -10,12 +10,26 @@ #include <Swiften/Parser/AttributeMap.h> namespace Swift { - class SWIFTEN_API XMLParserClient { - public: - virtual ~XMLParserClient(); + class SWIFTEN_API XMLParserClient { + public: + virtual ~XMLParserClient(); - virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) = 0; - virtual void handleEndElement(const std::string& element, const std::string& ns) = 0; - virtual void handleCharacterData(const std::string& data) = 0; - }; + /** + * Client will have to implement only one of the following methods depending on whether + * he is interested in processing the element prefix or not. + */ + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); + virtual void handleStartElementPrefix(const std::string& prefix, const std::string& uri, const std::string& element, const AttributeMap& attributes); + + virtual void handleEndElement(const std::string& element, const std::string& ns) = 0; + virtual void handleCharacterData(const std::string& data) = 0; + + /** + * Signal that a namespace prefix has been declared + * This callback might be called multiple times for a single element, + * and will trigger before the corresponding \ref handleStartElement + * is called. + */ + virtual void handleNamespaceDeclaration(const std::string& prefix, const std::string& uri); + }; } diff --git a/Swiften/Parser/XMLParserFactory.cpp b/Swiften/Parser/XMLParserFactory.cpp index af719bf..bb0d5f3 100644 --- a/Swiften/Parser/XMLParserFactory.cpp +++ b/Swiften/Parser/XMLParserFactory.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/XMLParserFactory.h> diff --git a/Swiften/Parser/XMLParserFactory.h b/Swiften/Parser/XMLParserFactory.h index 6979ea4..ae3c90e 100644 --- a/Swiften/Parser/XMLParserFactory.h +++ b/Swiften/Parser/XMLParserFactory.h @@ -1,21 +1,23 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once +#include <memory> + #include <Swiften/Base/API.h> namespace Swift { - class XMLParser; - class XMLParserClient; + class XMLParser; + class XMLParserClient; - class SWIFTEN_API XMLParserFactory { - public: - virtual ~XMLParserFactory(); + class SWIFTEN_API XMLParserFactory { + public: + virtual ~XMLParserFactory(); - virtual XMLParser* createXMLParser(XMLParserClient*) = 0; - }; + virtual std::unique_ptr<XMLParser> createXMLParser(XMLParserClient*, bool allowComments = false) = 0; + }; } diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp index 069a5bd..d2a5a98 100644 --- a/Swiften/Parser/XMPPParser.cpp +++ b/Swiften/Parser/XMPPParser.cpp @@ -1,46 +1,44 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/XMPPParser.h> -#include <iostream> #include <cassert> +#include <string> #include <Swiften/Elements/ProtocolHeader.h> -#include <string> -#include <Swiften/Parser/XMLParser.h> -#include <Swiften/Parser/XMPPParserClient.h> -#include <Swiften/Parser/XMPPParser.h> +#include <Swiften/Parser/AuthChallengeParser.h> +#include <Swiften/Parser/AuthFailureParser.h> +#include <Swiften/Parser/AuthRequestParser.h> +#include <Swiften/Parser/AuthResponseParser.h> +#include <Swiften/Parser/AuthSuccessParser.h> +#include <Swiften/Parser/ComponentHandshakeParser.h> +#include <Swiften/Parser/CompressFailureParser.h> +#include <Swiften/Parser/CompressParser.h> +#include <Swiften/Parser/CompressedParser.h> #include <Swiften/Parser/ElementParser.h> -#include <Swiften/Parser/PresenceParser.h> +#include <Swiften/Parser/EnableStreamManagementParser.h> #include <Swiften/Parser/IQParser.h> #include <Swiften/Parser/MessageParser.h> -#include <Swiften/Parser/StreamFeaturesParser.h> +#include <Swiften/Parser/PresenceParser.h> +#include <Swiften/Parser/StanzaAckParser.h> +#include <Swiften/Parser/StanzaAckRequestParser.h> +#include <Swiften/Parser/StartTLSFailureParser.h> +#include <Swiften/Parser/StartTLSParser.h> #include <Swiften/Parser/StreamErrorParser.h> -#include <Swiften/Parser/AuthRequestParser.h> -#include <Swiften/Parser/AuthSuccessParser.h> -#include <Swiften/Parser/AuthFailureParser.h> -#include <Swiften/Parser/AuthChallengeParser.h> -#include <Swiften/Parser/AuthResponseParser.h> -#include <Swiften/Parser/EnableStreamManagementParser.h> +#include <Swiften/Parser/StreamFeaturesParser.h> #include <Swiften/Parser/StreamManagementEnabledParser.h> #include <Swiften/Parser/StreamManagementFailedParser.h> #include <Swiften/Parser/StreamResumeParser.h> #include <Swiften/Parser/StreamResumedParser.h> -#include <Swiften/Parser/StanzaAckParser.h> -#include <Swiften/Parser/StanzaAckRequestParser.h> -#include <Swiften/Parser/StartTLSParser.h> -#include <Swiften/Parser/StartTLSFailureParser.h> -#include <Swiften/Parser/CompressParser.h> -#include <Swiften/Parser/CompressFailureParser.h> -#include <Swiften/Parser/CompressedParser.h> -#include <Swiften/Parser/UnknownElementParser.h> #include <Swiften/Parser/TLSProceedParser.h> -#include <Swiften/Parser/ComponentHandshakeParser.h> +#include <Swiften/Parser/UnknownElementParser.h> +#include <Swiften/Parser/XMLParser.h> #include <Swiften/Parser/XMLParserFactory.h> +#include <Swiften/Parser/XMPPParserClient.h> // TODO: Whenever an error occurs in the handlers, stop the parser by returing // a bool value, and stopping the XML parser @@ -48,159 +46,158 @@ namespace Swift { XMPPParser::XMPPParser( - XMPPParserClient* client, - PayloadParserFactoryCollection* payloadParserFactories, - XMLParserFactory* xmlParserFactory) : - xmlParser_(0), - client_(client), - payloadParserFactories_(payloadParserFactories), - level_(0), - currentElementParser_(0), - parseErrorOccurred_(false) { - xmlParser_ = xmlParserFactory->createXMLParser(this); + XMPPParserClient* client, + PayloadParserFactoryCollection* payloadParserFactories, + XMLParserFactory* xmlParserFactory) : + xmlParser_(nullptr), + client_(client), + payloadParserFactories_(payloadParserFactories), + level_(0), + currentElementParser_(nullptr), + parseErrorOccurred_(false) { + xmlParser_ = xmlParserFactory->createXMLParser(this); } XMPPParser::~XMPPParser() { - delete currentElementParser_; - delete xmlParser_; + delete currentElementParser_; } bool XMPPParser::parse(const std::string& data) { - bool xmlParseResult = xmlParser_->parse(data); - return xmlParseResult && !parseErrorOccurred_; + bool xmlParseResult = xmlParser_->parse(data); + return xmlParseResult && !parseErrorOccurred_; } void XMPPParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (!parseErrorOccurred_) { - if (level_ == TopLevel) { - if (element == "stream" && ns == "http://etherx.jabber.org/streams") { - ProtocolHeader header; - header.setFrom(attributes.getAttribute("from")); - header.setTo(attributes.getAttribute("to")); - header.setID(attributes.getAttribute("id")); - header.setVersion(attributes.getAttribute("version")); - client_->handleStreamStart(header); - } - else { - parseErrorOccurred_ = true; - } - } - else { - if (level_ == StreamLevel) { - assert(!currentElementParser_); - currentElementParser_ = createElementParser(element, ns); - } - currentElementParser_->handleStartElement(element, ns, attributes); - } - } - ++level_; + if (!parseErrorOccurred_) { + if (level_ == TopLevel) { + if (element == "stream" && ns == "http://etherx.jabber.org/streams") { + ProtocolHeader header; + header.setFrom(attributes.getAttribute("from")); + header.setTo(attributes.getAttribute("to")); + header.setID(attributes.getAttribute("id")); + header.setVersion(attributes.getAttribute("version")); + client_->handleStreamStart(header); + } + else { + parseErrorOccurred_ = true; + } + } + else { + if (level_ == StreamLevel) { + assert(!currentElementParser_); + currentElementParser_ = createElementParser(element, ns); + } + currentElementParser_->handleStartElement(element, ns, attributes); + } + } + ++level_; } void XMPPParser::handleEndElement(const std::string& element, const std::string& ns) { - assert(level_ > TopLevel); - --level_; - if (!parseErrorOccurred_) { - if (level_ == TopLevel) { - assert(element == "stream"); - client_->handleStreamEnd(); - } - else { - assert(currentElementParser_); - currentElementParser_->handleEndElement(element, ns); - if (level_ == StreamLevel) { - client_->handleElement(currentElementParser_->getElement()); - delete currentElementParser_; - currentElementParser_ = NULL; - } - } - } + assert(level_ > TopLevel); + --level_; + if (!parseErrorOccurred_) { + if (level_ == TopLevel) { + assert(element == "stream"); + client_->handleStreamEnd(); + } + else { + assert(currentElementParser_); + currentElementParser_->handleEndElement(element, ns); + if (level_ == StreamLevel) { + client_->handleElement(currentElementParser_->getElement()); + delete currentElementParser_; + currentElementParser_ = nullptr; + } + } + } } void XMPPParser::handleCharacterData(const std::string& data) { - if (!parseErrorOccurred_) { - if (currentElementParser_) { - currentElementParser_->handleCharacterData(data); - } - //else { - // std::cerr << "XMPPParser: Ignoring stray character data: " << data << std::endl; - //} - } + if (!parseErrorOccurred_) { + if (currentElementParser_) { + currentElementParser_->handleCharacterData(data); + } + //else { + // std::cerr << "XMPPParser: Ignoring stray character data: " << data << std::endl; + //} + } } ElementParser* XMPPParser::createElementParser(const std::string& element, const std::string& ns) { - if (element == "presence") { - return new PresenceParser(payloadParserFactories_); - } - else if (element == "iq") { - return new IQParser(payloadParserFactories_); - } - else if (element == "message") { - return new MessageParser(payloadParserFactories_); - } - else if (element == "features" && ns == "http://etherx.jabber.org/streams") { - return new StreamFeaturesParser(); - } - else if (element == "error" && ns == "http://etherx.jabber.org/streams") { - return new StreamErrorParser(); - } - else if (element == "auth") { - return new AuthRequestParser(); - } - else if (element == "success") { - return new AuthSuccessParser(); - } - else if (element == "failure" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { - return new AuthFailureParser(); - } - else if (element == "challenge" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { - return new AuthChallengeParser(); - } - else if (element == "response" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { - return new AuthResponseParser(); - } - else if (element == "starttls") { - return new StartTLSParser(); - } - else if (element == "failure" && ns == "urn:ietf:params:xml:ns:xmpp-tls") { - return new StartTLSFailureParser(); - } - else if (element == "compress") { - return new CompressParser(); - } - else if (element == "compressed") { - return new CompressedParser(); - } - else if (element == "failure" && ns == "http://jabber.org/protocol/compress") { - return new CompressFailureParser(); - } - else if (element == "proceed") { - return new TLSProceedParser(); - } - else if (element == "enable" && ns == "urn:xmpp:sm:2") { - return new EnableStreamManagementParser(); - } - else if (element == "enabled" && ns == "urn:xmpp:sm:2") { - return new StreamManagementEnabledParser(); - } - else if (element == "failed" && ns == "urn:xmpp:sm:2") { - return new StreamManagementFailedParser(); - } - else if (element == "resume" && ns == "urn:xmpp:sm:2") { - return new StreamResumeParser(); - } - else if (element == "resumed" && ns == "urn:xmpp:sm:2") { - return new StreamResumedParser(); - } - else if (element == "a" && ns == "urn:xmpp:sm:2") { - return new StanzaAckParser(); - } - else if (element == "r" && ns == "urn:xmpp:sm:2") { - return new StanzaAckRequestParser(); - } - else if (element == "handshake") { - return new ComponentHandshakeParser(); - } - return new UnknownElementParser(); + if (element == "presence") { + return new PresenceParser(payloadParserFactories_); + } + else if (element == "iq") { + return new IQParser(payloadParserFactories_); + } + else if (element == "message") { + return new MessageParser(payloadParserFactories_); + } + else if (element == "features" && ns == "http://etherx.jabber.org/streams") { + return new StreamFeaturesParser(); + } + else if (element == "error" && ns == "http://etherx.jabber.org/streams") { + return new StreamErrorParser(); + } + else if (element == "auth") { + return new AuthRequestParser(); + } + else if (element == "success") { + return new AuthSuccessParser(); + } + else if (element == "failure" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { + return new AuthFailureParser(); + } + else if (element == "challenge" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { + return new AuthChallengeParser(); + } + else if (element == "response" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") { + return new AuthResponseParser(); + } + else if (element == "starttls") { + return new StartTLSParser(); + } + else if (element == "failure" && ns == "urn:ietf:params:xml:ns:xmpp-tls") { + return new StartTLSFailureParser(); + } + else if (element == "compress") { + return new CompressParser(); + } + else if (element == "compressed") { + return new CompressedParser(); + } + else if (element == "failure" && ns == "http://jabber.org/protocol/compress") { + return new CompressFailureParser(); + } + else if (element == "proceed") { + return new TLSProceedParser(); + } + else if (element == "enable" && ns == "urn:xmpp:sm:2") { + return new EnableStreamManagementParser(); + } + else if (element == "enabled" && ns == "urn:xmpp:sm:2") { + return new StreamManagementEnabledParser(); + } + else if (element == "failed" && ns == "urn:xmpp:sm:2") { + return new StreamManagementFailedParser(); + } + else if (element == "resume" && ns == "urn:xmpp:sm:2") { + return new StreamResumeParser(); + } + else if (element == "resumed" && ns == "urn:xmpp:sm:2") { + return new StreamResumedParser(); + } + else if (element == "a" && ns == "urn:xmpp:sm:2") { + return new StanzaAckParser(); + } + else if (element == "r" && ns == "urn:xmpp:sm:2") { + return new StanzaAckRequestParser(); + } + else if (element == "handshake") { + return new ComponentHandshakeParser(); + } + return new UnknownElementParser(); } } diff --git a/Swiften/Parser/XMPPParser.h b/Swiften/Parser/XMPPParser.h index 757ee22..6595b94 100644 --- a/Swiften/Parser/XMPPParser.h +++ b/Swiften/Parser/XMPPParser.h @@ -1,56 +1,57 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 <boost/noncopyable.hpp> #include <Swiften/Base/API.h> -#include <Swiften/Parser/XMLParserClient.h> #include <Swiften/Parser/AttributeMap.h> +#include <Swiften/Parser/XMLParserClient.h> namespace Swift { - class XMLParser; - class XMPPParserClient; - class XMLParserFactory; - class ElementParser; - class PayloadParserFactoryCollection; - - class SWIFTEN_API XMPPParser : public XMLParserClient, boost::noncopyable { - public: - XMPPParser( - XMPPParserClient* parserClient, - PayloadParserFactoryCollection* payloadParserFactories, - XMLParserFactory* xmlParserFactory); - ~XMPPParser(); - - bool parse(const std::string&); - - private: - virtual void handleStartElement( - const std::string& element, - const std::string& ns, - const AttributeMap& attributes); - virtual void handleEndElement(const std::string& element, const std::string& ns); - virtual void handleCharacterData(const std::string& data); - - ElementParser* createElementParser(const std::string& element, const std::string& xmlns); - - private: - XMLParser* xmlParser_; - XMPPParserClient* client_; - PayloadParserFactoryCollection* payloadParserFactories_; - enum Level { - TopLevel = 0, - StreamLevel = 1, - ElementLevel = 2 - }; - int level_; - ElementParser* currentElementParser_; - bool parseErrorOccurred_; - }; + class XMLParser; + class XMPPParserClient; + class XMLParserFactory; + class ElementParser; + class PayloadParserFactoryCollection; + + class SWIFTEN_API XMPPParser : public XMLParserClient, boost::noncopyable { + public: + XMPPParser( + XMPPParserClient* parserClient, + PayloadParserFactoryCollection* payloadParserFactories, + XMLParserFactory* xmlParserFactory); + virtual ~XMPPParser(); + + bool parse(const std::string&); + + private: + virtual void handleStartElement( + const std::string& element, + const std::string& ns, + const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string& ns); + virtual void handleCharacterData(const std::string& data); + + ElementParser* createElementParser(const std::string& element, const std::string& xmlns); + + private: + std::unique_ptr<XMLParser> xmlParser_; + XMPPParserClient* client_; + PayloadParserFactoryCollection* payloadParserFactories_; + enum Level { + TopLevel = 0, + StreamLevel = 1, + ElementLevel = 2 + }; + int level_; + ElementParser* currentElementParser_; + bool parseErrorOccurred_; + }; } diff --git a/Swiften/Parser/XMPPParserClient.cpp b/Swiften/Parser/XMPPParserClient.cpp index 4b7da04..34edcda 100644 --- a/Swiften/Parser/XMPPParserClient.cpp +++ b/Swiften/Parser/XMPPParserClient.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Parser/XMPPParserClient.h> diff --git a/Swiften/Parser/XMPPParserClient.h b/Swiften/Parser/XMPPParserClient.h index 85e0f86..97c0c64 100644 --- a/Swiften/Parser/XMPPParserClient.h +++ b/Swiften/Parser/XMPPParserClient.h @@ -1,26 +1,26 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 <Swiften/Base/API.h> -#include <Swiften/Elements/Element.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { - - class ProtocolHeader; - class SWIFTEN_API XMPPParserClient { - public: - virtual ~XMPPParserClient(); + class ProtocolHeader; - virtual void handleStreamStart(const ProtocolHeader&) = 0; - virtual void handleElement(boost::shared_ptr<Element>) = 0; - virtual void handleStreamEnd() = 0; - }; + class SWIFTEN_API XMPPParserClient { + public: + virtual ~XMPPParserClient(); + + virtual void handleStreamStart(const ProtocolHeader&) = 0; + virtual void handleElement(std::shared_ptr<ToplevelElement>) = 0; + virtual void handleStreamEnd() = 0; + }; } |