diff options
Diffstat (limited to 'Swiften/Parser')
181 files changed, 6625 insertions, 397 deletions
diff --git a/Swiften/Parser/AttributeMap.cpp b/Swiften/Parser/AttributeMap.cpp index 1aeaf99..d508157 100644 --- a/Swiften/Parser/AttributeMap.cpp +++ b/Swiften/Parser/AttributeMap.cpp @@ -9,19 +9,9 @@ #include <algorithm> #include <boost/optional.hpp> +#include <boost/lambda/lambda.hpp> +#include <boost/lambda/bind.hpp> using namespace Swift; - -namespace { - struct AttributeIs { - AttributeIs(const Attribute& attribute) : attribute(attribute) { - } - - bool operator()(const AttributeMap::Entry& o) const { - return o.getAttribute() == attribute; - } - - Attribute attribute; - }; -} +namespace lambda = boost::lambda; AttributeMap::AttributeMap() { @@ -29,5 +19,6 @@ 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(), AttributeIs(Attribute(attribute, ns))); + 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 ""; @@ -39,5 +30,6 @@ std::string AttributeMap::getAttribute(const std::string& attribute, const std:: bool AttributeMap::getBoolAttribute(const std::string& attribute, bool defaultValue) const { - AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), AttributeIs(Attribute(attribute, ""))); + 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; @@ -49,5 +41,6 @@ bool AttributeMap::getBoolAttribute(const std::string& attribute, bool defaultVa boost::optional<std::string> AttributeMap::getAttributeValue(const std::string& attribute) const { - AttributeValueMap::const_iterator i = std::find_if(attributes.begin(), attributes.end(), AttributeIs(Attribute(attribute, ""))); + 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>(); diff --git a/Swiften/Parser/AttributeMap.h b/Swiften/Parser/AttributeMap.h index 31df606..77b9c23 100644 --- a/Swiften/Parser/AttributeMap.h +++ b/Swiften/Parser/AttributeMap.h @@ -12,8 +12,9 @@ #include <boost/optional/optional_fwd.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Parser/Attribute.h> namespace Swift { - class AttributeMap { + class SWIFTEN_API AttributeMap { public: class Entry { diff --git a/Swiften/Parser/BOSHBodyExtractor.cpp b/Swiften/Parser/BOSHBodyExtractor.cpp index eeebe8a..715a448 100644 --- a/Swiften/Parser/BOSHBodyExtractor.cpp +++ b/Swiften/Parser/BOSHBodyExtractor.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2011 Remko Tronçon + * Copyright (c) 2011-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -8,4 +8,5 @@ #include <boost/shared_ptr.hpp> +#include <boost/numeric/conversion/cast.hpp> #include <Swiften/Parser/XMLParserClient.h> @@ -34,5 +35,5 @@ class BOSHBodyParserClient : public XMLParserClient { }; -inline bool isWhitespace(char c) { +inline bool isWhitespace(unsigned char c) { return c == ' ' || c == '\n' || c == '\t' || c == '\r'; } @@ -118,5 +119,7 @@ BOSHBodyExtractor::BOSHBodyExtractor(XMLParserFactory* parserFactory, const Byte body = BOSHBody(); if (!endElementSeen) { - body->content = std::string(reinterpret_cast<const char*>(vecptr(data) + std::distance(data.begin(), i)), std::distance(i, j.base())); + 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()))); } @@ -124,5 +127,7 @@ BOSHBodyExtractor::BOSHBodyExtractor(XMLParserFactory* parserFactory, const Byte BOSHBodyParserClient parserClient(this); boost::shared_ptr<XMLParser> parser(parserFactory->createXMLParser(&parserClient)); - if (!parser->parse(std::string(reinterpret_cast<const char*>(vecptr(data)), std::distance(data.begin(), i)))) { + 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 */ diff --git a/Swiften/Parser/BOSHBodyExtractor.h b/Swiften/Parser/BOSHBodyExtractor.h index 07203ae..7510761 100644 --- a/Swiften/Parser/BOSHBodyExtractor.h +++ b/Swiften/Parser/BOSHBodyExtractor.h @@ -9,4 +9,5 @@ #include <boost/optional.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Base/ByteArray.h> #include <Swiften/Parser/XMLParserClient.h> @@ -15,5 +16,5 @@ namespace Swift { class XMLParserFactory; - class BOSHBodyExtractor { + class SWIFTEN_API BOSHBodyExtractor { friend class BOSHBodyParserClient; public: diff --git a/Swiften/Parser/ElementParser.h b/Swiften/Parser/ElementParser.h index a11b505..256e2dc 100644 --- a/Swiften/Parser/ElementParser.h +++ b/Swiften/Parser/ElementParser.h @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -10,9 +10,10 @@ #include <string> -#include <Swiften/Elements/Element.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/ToplevelElement.h> #include <Swiften/Parser/AttributeMap.h> namespace Swift { - class ElementParser { + class SWIFTEN_API ElementParser { public: virtual ~ElementParser(); @@ -22,5 +23,5 @@ namespace Swift { virtual void handleCharacterData(const std::string& data) = 0; - virtual boost::shared_ptr<Element> getElement() const = 0; + virtual boost::shared_ptr<ToplevelElement> getElement() const = 0; }; } diff --git a/Swiften/Parser/EnumParser.h b/Swiften/Parser/EnumParser.h new file mode 100644 index 0000000..d7bdbbc --- /dev/null +++ b/Swiften/Parser/EnumParser.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <string> +#include <map> +#include <cassert> +#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; + }; +} diff --git a/Swiften/Parser/ExpatParser.cpp b/Swiften/Parser/ExpatParser.cpp index f3b5250..8b7bf82 100644 --- a/Swiften/Parser/ExpatParser.cpp +++ b/Swiften/Parser/ExpatParser.cpp @@ -9,12 +9,20 @@ #include <iostream> #include <string> +#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 Swift { static const char NAMESPACE_SEPARATOR = '\x01'; +struct ExpatParser::Private { + 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); @@ -48,5 +56,6 @@ static void handleEndElement(void* parser, const XML_Char* name) { static void handleCharacterData(void* parser, const XML_Char* data, int len) { - static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(data, len)); + assert(len >= 0); + static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(data, static_cast<size_t>(len))); } @@ -55,28 +64,32 @@ static void handleXMLDeclaration(void*, const XML_Char*, const XML_Char*, int) { 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*) { - XML_StopParser(static_cast<ExpatParser*>(parser)->getParser(), static_cast<XML_Bool>(0)); + static_cast<ExpatParser*>(parser)->stopParser(); } -ExpatParser::ExpatParser(XMLParserClient* client) : XMLParser(client) { - parser_ = XML_ParserCreateNS("UTF-8", NAMESPACE_SEPARATOR); - XML_SetUserData(parser_, this); - XML_SetElementHandler(parser_, handleStartElement, handleEndElement); - XML_SetCharacterDataHandler(parser_, handleCharacterData); - XML_SetXmlDeclHandler(parser_, handleXMLDeclaration); - XML_SetEntityDeclHandler(parser_, handleEntityDeclaration); +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() { - XML_ParserFree(parser_); + XML_ParserFree(p->parser_); } bool ExpatParser::parse(const std::string& data) { - bool success = XML_Parse(parser_, data.c_str(), data.size(), false) == XML_STATUS_OK; + 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(parser_)) << " while parsing " << data << std::endl; + 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)); +} + } diff --git a/Swiften/Parser/ExpatParser.h b/Swiften/Parser/ExpatParser.h index 359f786..dcb0915 100644 --- a/Swiften/Parser/ExpatParser.h +++ b/Swiften/Parser/ExpatParser.h @@ -7,11 +7,12 @@ #pragma once -#include <expat.h> #include <boost/noncopyable.hpp> +#include <boost/shared_ptr.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Parser/XMLParser.h> namespace Swift { - class ExpatParser : public XMLParser, public boost::noncopyable { + class SWIFTEN_API ExpatParser : public XMLParser, public boost::noncopyable { public: ExpatParser(XMLParserClient* client); @@ -20,10 +21,9 @@ namespace Swift { bool parse(const std::string& data); - XML_Parser getParser() { - return parser_; - } + void stopParser(); private: - XML_Parser parser_; + struct Private; + boost::shared_ptr<Private> p; }; } diff --git a/Swiften/Parser/GenericElementParser.h b/Swiften/Parser/GenericElementParser.h index 224c59e..4395622 100644 --- a/Swiften/Parser/GenericElementParser.h +++ b/Swiften/Parser/GenericElementParser.h @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -23,5 +23,5 @@ namespace Swift { } - virtual boost::shared_ptr<Element> getElement() const { + virtual boost::shared_ptr<ToplevelElement> getElement() const { return stanza_; } diff --git a/Swiften/Parser/GenericPayloadParserFactory2.h b/Swiften/Parser/GenericPayloadParserFactory2.h new file mode 100644 index 0000000..f24b64e --- /dev/null +++ b/Swiften/Parser/GenericPayloadParserFactory2.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <string> + +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_; + }; +} diff --git a/Swiften/Parser/GenericStanzaParser.h b/Swiften/Parser/GenericStanzaParser.h index c756c9a..2aff4d5 100644 --- a/Swiften/Parser/GenericStanzaParser.h +++ b/Swiften/Parser/GenericStanzaParser.h @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -24,5 +24,5 @@ namespace Swift { } - virtual boost::shared_ptr<Element> getElement() const { + virtual boost::shared_ptr<ToplevelElement> getElement() const { return stanza_; } diff --git a/Swiften/Parser/IQParser.h b/Swiften/Parser/IQParser.h index a7aa967..9773835 100644 --- a/Swiften/Parser/IQParser.h +++ b/Swiften/Parser/IQParser.h @@ -7,9 +7,10 @@ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/GenericStanzaParser.h> #include <Swiften/Elements/IQ.h> namespace Swift { - class IQParser : public GenericStanzaParser<IQ> { + class SWIFTEN_API IQParser : public GenericStanzaParser<IQ> { public: IQParser(PayloadParserFactoryCollection* factories); diff --git a/Swiften/Parser/LibXMLParser.cpp b/Swiften/Parser/LibXMLParser.cpp index 1590262..e4938e1 100644 --- a/Swiften/Parser/LibXMLParser.cpp +++ b/Swiften/Parser/LibXMLParser.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -8,12 +8,19 @@ #include <iostream> +#include <boost/numeric/conversion/cast.hpp> #include <cassert> #include <cstring> - +#include <libxml/parser.h> #include <string> + #include <Swiften/Parser/XMLParserClient.h> namespace Swift { +struct LibXMLParser::Private { + 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; @@ -27,5 +34,9 @@ static void handleStartElement(void* parser, const xmlChar* name, const xmlChar* 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]), attributes[i+4]-attributes[i+3])); + 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); @@ -37,5 +48,5 @@ static void handleEndElement(void *parser, const xmlChar* name, const xmlChar*, static void handleCharacterData(void* parser, const xmlChar* data, int len) { - static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(reinterpret_cast<const char*>(data), len)); + static_cast<XMLParser*>(parser)->getClient()->handleCharacterData(std::string(reinterpret_cast<const char*>(data), boost::numeric_cast<size_t>(len))); } @@ -54,5 +65,5 @@ static void handleWarning(void*, const char*, ... ) { bool LibXMLParser::initialized = false; -LibXMLParser::LibXMLParser(XMLParserClient* client) : XMLParser(client) { +LibXMLParser::LibXMLParser(XMLParserClient* client) : XMLParser(client), p(new Private()) { // Initialize libXML for multithreaded applications if (!initialized) { @@ -61,30 +72,31 @@ LibXMLParser::LibXMLParser(XMLParserClient* client) : XMLParser(client) { } - memset(&handler_, 0, sizeof(handler_) ); - handler_.initialized = XML_SAX2_MAGIC; - handler_.startElementNs = &handleStartElement; - handler_.endElementNs = &handleEndElement; - handler_.characters = &handleCharacterData; - handler_.warning = &handleWarning; - handler_.error = &handleError; + 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; - context_ = xmlCreatePushParserCtxt(&handler_, this, 0, 0, 0); - assert(context_); + p->context_ = xmlCreatePushParserCtxt(&p->handler_, this, 0, 0, 0); + xmlCtxtUseOptions(p->context_, XML_PARSE_NOENT); + assert(p->context_); } LibXMLParser::~LibXMLParser() { - if (context_) { - xmlFreeParserCtxt(context_); + if (p->context_) { + xmlFreeParserCtxt(p->context_); } } bool LibXMLParser::parse(const std::string& data) { - if (xmlParseChunk(context_, data.c_str(), data.size(), false) == XML_ERR_OK) { + if (xmlParseChunk(p->context_, data.c_str(), boost::numeric_cast<int>(data.size()), false) == XML_ERR_OK) { return true; } - xmlError* error = xmlCtxtGetLastError(context_); + xmlError* error = xmlCtxtGetLastError(p->context_); if (error->code == XML_WAR_NS_URI || error->code == XML_WAR_NS_URI_RELATIVE) { - xmlCtxtResetLastError(context_); - context_->errNo = XML_ERR_OK; + xmlCtxtResetLastError(p->context_); + p->context_->errNo = XML_ERR_OK; return true; } diff --git a/Swiften/Parser/LibXMLParser.h b/Swiften/Parser/LibXMLParser.h index cd73637..b8e1d7c 100644 --- a/Swiften/Parser/LibXMLParser.h +++ b/Swiften/Parser/LibXMLParser.h @@ -7,6 +7,6 @@ #pragma once -#include <libxml/parser.h> #include <boost/noncopyable.hpp> +#include <boost/shared_ptr.hpp> #include <Swiften/Parser/XMLParser.h> @@ -26,6 +26,7 @@ namespace Swift { private: static bool initialized; - xmlSAXHandler handler_; - xmlParserCtxtPtr context_; + + struct Private; + boost::shared_ptr<Private> p; }; } diff --git a/Swiften/Parser/MessageParser.h b/Swiften/Parser/MessageParser.h index a8aaa99..e908339 100644 --- a/Swiften/Parser/MessageParser.h +++ b/Swiften/Parser/MessageParser.h @@ -7,9 +7,10 @@ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/GenericStanzaParser.h> #include <Swiften/Elements/Message.h> namespace Swift { - class MessageParser : public GenericStanzaParser<Message> { + class SWIFTEN_API MessageParser : public GenericStanzaParser<Message> { public: MessageParser(PayloadParserFactoryCollection* factories); diff --git a/Swiften/Parser/PayloadParser.h b/Swiften/Parser/PayloadParser.h index 8a9a290..bb1ae3c 100644 --- a/Swiften/Parser/PayloadParser.h +++ b/Swiften/Parser/PayloadParser.h @@ -8,6 +8,8 @@ #include <boost/shared_ptr.hpp> -#include <Swiften/Parser/AttributeMap.h> + +#include <Swiften/Base/API.h> +#include <Swiften/Parser/AttributeMap.h> #include <Swiften/Elements/Payload.h> @@ -23,5 +25,5 @@ namespace Swift { * payload. */ - class PayloadParser { + class SWIFTEN_API PayloadParser { public: virtual ~PayloadParser(); diff --git a/Swiften/Parser/PayloadParserFactory.h b/Swiften/Parser/PayloadParserFactory.h index 5619d21..e265e5b 100644 --- a/Swiften/Parser/PayloadParserFactory.h +++ b/Swiften/Parser/PayloadParserFactory.h @@ -7,4 +7,5 @@ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/AttributeMap.h> @@ -16,5 +17,5 @@ namespace Swift { * A factory for PayloadParsers. */ - class PayloadParserFactory { + class SWIFTEN_API PayloadParserFactory { public: virtual ~PayloadParserFactory(); diff --git a/Swiften/Parser/PayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParserFactoryCollection.cpp index e3efc3d..269ac3d 100644 --- a/Swiften/Parser/PayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParserFactoryCollection.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -21,5 +21,5 @@ void PayloadParserFactoryCollection::addFactory(PayloadParserFactory* 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()); } diff --git a/Swiften/Parser/PayloadParserFactoryCollection.h b/Swiften/Parser/PayloadParserFactoryCollection.h index 6407641..1dbdd32 100644 --- a/Swiften/Parser/PayloadParserFactoryCollection.h +++ b/Swiften/Parser/PayloadParserFactoryCollection.h @@ -10,9 +10,10 @@ #include <Swiften/Parser/AttributeMap.h> +#include <Swiften/Base/API.h> namespace Swift { class PayloadParserFactory; - class PayloadParserFactoryCollection { + class SWIFTEN_API PayloadParserFactoryCollection { public: PayloadParserFactoryCollection(); diff --git a/Swiften/Parser/PayloadParsers/BlockParser.h b/Swiften/Parser/PayloadParsers/BlockParser.h index cd727ad..6ee47a2 100644 --- a/Swiften/Parser/PayloadParsers/BlockParser.h +++ b/Swiften/Parser/PayloadParsers/BlockParser.h @@ -8,4 +8,5 @@ #include <Swiften/Elements/Nickname.h> +#include <Swiften/JID/JID.h> #include <Swiften/Parser/GenericPayloadParser.h> @@ -14,5 +15,5 @@ namespace Swift { class BlockParser : public GenericPayloadParser<BLOCK_ELEMENT> { public: - BlockParser() : GenericPayloadParser<BLOCK_ELEMENT>() { + BlockParser() : GenericPayloadParser<BLOCK_ELEMENT>(), level(0) { } diff --git a/Swiften/Parser/PayloadParsers/BytestreamsParser.h b/Swiften/Parser/PayloadParsers/BytestreamsParser.h index 4785913..5c151c2 100644 --- a/Swiften/Parser/PayloadParsers/BytestreamsParser.h +++ b/Swiften/Parser/PayloadParsers/BytestreamsParser.h @@ -25,5 +25,5 @@ namespace Swift { enum Level { TopLevel = 0, - PayloadLevel = 1, + PayloadLevel = 1 }; int level; diff --git a/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp b/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp index 14ff79d..aeb0db8 100644 --- a/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp @@ -6,4 +6,6 @@ #include <Swiften/Parser/PayloadParsers/DiscoInfoParser.h> + +#include <boost/optional.hpp> #include <Swiften/Parser/PayloadParsers/FormParser.h> @@ -14,5 +16,10 @@ DiscoInfoParser::DiscoInfoParser() : level_(TopLevel), formParser_(NULL) { void DiscoInfoParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == PayloadLevel) { + 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"))); diff --git a/Swiften/Parser/PayloadParsers/DiscoInfoParser.h b/Swiften/Parser/PayloadParsers/DiscoInfoParser.h index df1441c..1f93a88 100644 --- a/Swiften/Parser/PayloadParsers/DiscoInfoParser.h +++ b/Swiften/Parser/PayloadParsers/DiscoInfoParser.h @@ -7,9 +7,10 @@ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/DiscoInfo.h> #include <Swiften/Parser/GenericPayloadParser.h> namespace Swift { - class DiscoInfoParser : public GenericPayloadParser<DiscoInfo> { + class SWIFTEN_API DiscoInfoParser : public GenericPayloadParser<DiscoInfo> { public: DiscoInfoParser(); diff --git a/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp b/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp index d6ac94d..a56dc5a 100644 --- a/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp +++ b/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp @@ -18,4 +18,9 @@ void DiscoItemsParser::handleStartElement(const std::string& element, const std: } } + else if (level_ == TopLevel) { + if (element == "query") { + getPayloadInternal()->setNode(attributes.getAttribute("node")); + } + } ++level_; } diff --git a/Swiften/Parser/PayloadParsers/FormParser.cpp b/Swiften/Parser/PayloadParsers/FormParser.cpp index 2df0a85..7c29189 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.cpp +++ b/Swiften/Parser/PayloadParsers/FormParser.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -11,5 +11,5 @@ namespace Swift { -FormParser::FormParser() : level_(TopLevel), parsingItem_(false), parsingReported_(false) { +FormParser::FormParser() : level_(TopLevel), parsingItem_(false), parsingReported_(false), parsingOption_(false) { } @@ -37,65 +37,60 @@ void FormParser::handleStartElement(const std::string& element, const std::strin currentText_.clear(); } - else if (element == "field") { - std::string type; - FormField::ref correspondingReportedField; - if (!parsingItem_) { - type = attributes.getAttribute("type"); - } else { - foreach(FormField::ref field, getPayloadInternal()->getReportedFields()) { - if (field->getName() == attributes.getAttribute("var")) { - correspondingReportedField = field; - break; + else if (element == "reported") { + parsingReported_ = true; } + else if (element == "item") { + parsingItem_ = true; } } - if (type == "boolean" || boost::dynamic_pointer_cast<BooleanFormField>(correspondingReportedField)) { - currentFieldParseHelper_ = BooleanFormFieldParseHelper::create(); + else if (level_ == FieldLevel && currentField_) { + currentText_.clear(); + if (element == "option") { + currentOptionLabel_ = attributes.getAttribute("label"); + currentOptionValue_ = ""; + parsingOption_ = true; } - else if (type == "fixed" || boost::dynamic_pointer_cast<FixedFormField>(correspondingReportedField)) { - currentFieldParseHelper_ = FixedFormFieldParseHelper::create(); } - else if (type == "hidden" || boost::dynamic_pointer_cast<HiddenFormField>(correspondingReportedField)) { - currentFieldParseHelper_ = HiddenFormFieldParseHelper::create(); + 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; } - else if (type == "jid-multi" || boost::dynamic_pointer_cast<JIDMultiFormField>(correspondingReportedField)) { - currentFieldParseHelper_ = JIDMultiFormFieldParseHelper::create(); + if (type == "fixed") { + fieldType = FormField::FixedType; } - else if (type == "jid-single" || boost::dynamic_pointer_cast<JIDSingleFormField>(correspondingReportedField)) { - currentFieldParseHelper_ = JIDSingleFormFieldParseHelper::create(); + if (type == "hidden") { + fieldType = FormField::HiddenType; } - else if (type == "list-multi" || boost::dynamic_pointer_cast<ListMultiFormField>(correspondingReportedField)) { - currentFieldParseHelper_ = ListMultiFormFieldParseHelper::create(); + if (type == "list-single") { + fieldType = FormField::ListSingleType; } - else if (type == "list-single" || boost::dynamic_pointer_cast<ListSingleFormField>(correspondingReportedField)) { - currentFieldParseHelper_ = ListSingleFormFieldParseHelper::create(); + if (type == "text-multi") { + fieldType = FormField::TextMultiType; } - else if (type == "text-multi" || boost::dynamic_pointer_cast<TextMultiFormField>(correspondingReportedField)) { - currentFieldParseHelper_ = TextMultiFormFieldParseHelper::create(); + if (type == "text-private") { + fieldType = FormField::TextPrivateType; } - else if (type == "text-private" || boost::dynamic_pointer_cast<TextPrivateFormField>(correspondingReportedField)) { - currentFieldParseHelper_ = TextPrivateFormFieldParseHelper::create(); + if (type == "text-single") { + fieldType = FormField::TextSingleType; } - else /*if (type == "text-single") || undefined */ { - currentFieldParseHelper_ = TextSingleFormFieldParseHelper::create(); + if (type == "jid-single") { + fieldType = FormField::JIDSingleType; } - if (currentFieldParseHelper_) { - currentFieldParseHelper_->getField()->setName(attributes.getAttribute("var")); - currentFieldParseHelper_->getField()->setLabel(attributes.getAttribute("label")); + if (type == "jid-multi") { + fieldType = FormField::JIDMultiType; } + if (type == "list-multi") { + fieldType = FormField::ListMultiType; } - else if (element == "reported") { - parsingReported_ = true; - level_ = PayloadLevel - 1; + currentField_->setType(fieldType); + currentField_->setName(attributes.getAttribute("var")); + currentField_->setLabel(attributes.getAttribute("label")); } - else if (element == "item") { - parsingItem_ = true; - level_ = PayloadLevel - 1; - } - } - else if (level_ == FieldLevel && currentFieldParseHelper_) { + else if (element == "value") { currentText_.clear(); - if (element == "option") { - currentOptionLabel_ = attributes.getAttribute("label"); } } @@ -124,40 +119,46 @@ void FormParser::handleEndElement(const std::string& element, const std::string& } } - else if (element == "field") { - if (currentFieldParseHelper_) { - if (parsingReported_) { - getPayloadInternal()->addReportedField(currentFieldParseHelper_->getField()); - } else if (parsingItem_) { - currentFields_.push_back(currentFieldParseHelper_->getField()); - } else { - getPayloadInternal()->addField(currentFieldParseHelper_->getField()); - } - currentFieldParseHelper_.reset(); + else if (element == "reported") { + parsingReported_ = false; } + else if (element == "item") { + parsingItem_ = false; + getPayloadInternal()->addItem(currentFields_); + currentFields_.clear(); } } - else if (level_ == FieldLevel && currentFieldParseHelper_) { + else if (currentField_) { if (element == "required") { - currentFieldParseHelper_->getField()->setRequired(true); + currentField_->setRequired(true); } else if (element == "desc") { - currentFieldParseHelper_->getField()->setDescription(currentText_); + currentField_->setDescription(currentText_); } else if (element == "option") { - currentFieldParseHelper_->getField()->addOption(FormField::Option(currentOptionLabel_, currentText_)); + currentField_->addOption(FormField::Option(currentOptionLabel_, currentOptionValue_)); + parsingOption_ = false; } else if (element == "value") { - currentFieldParseHelper_->addValue(currentText_); + if (parsingOption_) { + currentOptionValue_ = currentText_; } + else { + currentField_->addValue(currentText_); } - if (element == "reported") { - parsingReported_ = false; - level_++; } - else if (element == "item") { - parsingItem_ = false; - level_++; - getPayloadInternal()->addItem(currentFields_); - currentFields_.clear(); + } + 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(); + } } } diff --git a/Swiften/Parser/PayloadParsers/FormParser.h b/Swiften/Parser/PayloadParsers/FormParser.h index a3e2524..0b23a81 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.h +++ b/Swiften/Parser/PayloadParsers/FormParser.h @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -19,84 +19,4 @@ namespace Swift { virtual void handleCharacterData(const std::string& data); - private: - class FieldParseHelper { - public: - virtual ~FieldParseHelper() {} - virtual void addValue(const std::string&) = 0; - virtual boost::shared_ptr<FormField> getField() const { - return field; - } - protected: - boost::shared_ptr<FormField> field; - }; - class BoolFieldParseHelper : public FieldParseHelper { - virtual void addValue(const std::string& s) { - boost::dynamic_pointer_cast< GenericFormField<bool> >(getField())->setValue(s == "1" || s == "true"); - getField()->addRawValue(s); - } - }; - class StringFieldParseHelper : public FieldParseHelper { - virtual void addValue(const std::string& s) { - boost::shared_ptr<GenericFormField<std::string> > field = boost::dynamic_pointer_cast< GenericFormField<std::string> >(getField()); - if (field->getValue().empty()) { - field->setValue(s); - } - else { - field->setValue(field->getValue() + "\n" + s); - } - getField()->addRawValue(s); - } - }; - class JIDFieldParseHelper : public FieldParseHelper { - virtual void addValue(const std::string& s) { - getField()->addRawValue(s); - boost::dynamic_pointer_cast< GenericFormField<JID> >(getField())->setValue(JID(s)); - } - }; - class StringListFieldParseHelper : public FieldParseHelper { - virtual void addValue(const std::string& s) { - // FIXME: Inefficient, but too much hassle to do efficiently - boost::shared_ptr<GenericFormField< std::vector<std::string> > > field = boost::dynamic_pointer_cast< GenericFormField<std::vector<std::string > > >(getField()); - std::vector<std::string> l = field->getValue(); - l.push_back(s); - field->setValue(l); - getField()->addRawValue(s); - } - }; - class JIDListFieldParseHelper : public FieldParseHelper { - virtual void addValue(const std::string& s) { - // FIXME: Inefficient, but too much hassle to do efficiently - boost::shared_ptr< GenericFormField< std::vector<JID> > > field = boost::dynamic_pointer_cast< GenericFormField<std::vector<JID > > >(getField()); - std::vector<JID> l = field->getValue(); - l.push_back(JID(s)); - field->setValue(l); - getField()->addRawValue(s); - } - }; - -#define SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(name, baseParser) \ - class name##FormFieldParseHelper : public baseParser##FieldParseHelper { \ - public: \ - typedef boost::shared_ptr<name##FormFieldParseHelper> ref; \ - static ref create() { \ - return ref(new name##FormFieldParseHelper()); \ - } \ - private: \ - name##FormFieldParseHelper() : baseParser##FieldParseHelper() { \ - field = name##FormField::create(); \ - } \ - }; - - SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(Boolean, Bool); - SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(Fixed, String); - SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(Hidden, String); - SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(ListSingle, String); - SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(TextMulti, String); - SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(TextPrivate, String); - SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(TextSingle, String); - SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(JIDSingle, JID); - SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(JIDMulti, JIDList); - SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(ListMulti, StringList); - enum Level { TopLevel = 0, @@ -107,7 +27,9 @@ namespace Swift { std::string currentText_; std::string currentOptionLabel_; - boost::shared_ptr<FieldParseHelper> currentFieldParseHelper_; + std::string currentOptionValue_; bool parsingItem_; bool parsingReported_; + bool parsingOption_; + FormField::ref currentField_; std::vector<FormField::ref> currentFields_; }; diff --git a/Swiften/Parser/PayloadParsers/ForwardedParser.cpp b/Swiften/Parser/PayloadParsers/ForwardedParser.cpp new file mode 100644 index 0000000..6625e77 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ForwardedParser.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <boost/lexical_cast.hpp> +#include <boost/optional.hpp> +#include <Swiften/Base/DateTime.h> +#include <Swiften/Parser/IQParser.h> +#include <Swiften/Parser/MessageParser.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParsers/DelayParser.h> +#include <Swiften/Parser/PayloadParsers/ForwardedParser.h> +#include <Swiften/Parser/PresenceParser.h> + + +using namespace Swift; + +ForwardedParser::ForwardedParser(PayloadParserFactoryCollection* factories) : factories_(factories), level_(TopLevel) { +} + +void ForwardedParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level_ == PayloadLevel) { + if (element == "iq" && ns == "jabber:client") { /* begin parsing a nested stanza? */ + childParser_ = boost::dynamic_pointer_cast<StanzaParser>(boost::make_shared<IQParser>(factories_)); + } else if (element == "message" && ns == "jabber:client") { + childParser_ = boost::dynamic_pointer_cast<StanzaParser>(boost::make_shared<MessageParser>(factories_)); + } else if (element == "presence" && ns == "jabber:client") { + childParser_ = boost::dynamic_pointer_cast<StanzaParser>(boost::make_shared<PresenceParser>(factories_)); + } else if (element == "delay" && ns == "urn:xmpp:delay") { /* nested delay payload */ + delayParser_ = boost::make_shared<DelayParser>(); + } + } + if (childParser_) { /* parsing a nested stanza? */ + childParser_->handleStartElement(element, ns, attributes); + } + if (delayParser_) { /* parsing a nested delay payload? */ + delayParser_->handleStartElement(element, ns, attributes); + } + ++level_; +} + +void ForwardedParser::handleEndElement(const std::string& element, const std::string& ns) { + --level_; + if (childParser_ && level_ >= PayloadLevel) { + childParser_->handleEndElement(element, ns); + } + if (childParser_ && level_ == PayloadLevel) { + /* done parsing nested stanza */ + getPayloadInternal()->setStanza(childParser_->getStanza()); + childParser_.reset(); + } + if (delayParser_ && level_ >= PayloadLevel) { + delayParser_->handleEndElement(element, ns); + } + if (delayParser_ && level_ == PayloadLevel) { + /* done parsing nested delay payload */ + getPayloadInternal()->setDelay(boost::dynamic_pointer_cast<Delay>(delayParser_->getPayload())); + delayParser_.reset(); + } +} + +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..14117ae --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ForwardedParser.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#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) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + private: + PayloadParserFactoryCollection* factories_; + boost::shared_ptr<StanzaParser> childParser_; + boost::shared_ptr<DelayParser> delayParser_; + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 01addf5..49dd1e3 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -6,65 +6,84 @@ #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/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/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/JingleFileTransferHashParser.h> +#include <Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.h> +#include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/JingleParserFactory.h> +#include <Swiften/Parser/PayloadParsers/JingleReasonParser.h> +#include <Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/LastParser.h> +#include <Swiften/Parser/PayloadParsers/MAMArchivedParser.h> +#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h> +#include <Swiften/Parser/PayloadParsers/MAMResultParser.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/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/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/UserLocationParser.h> +#include <Swiften/Parser/PayloadParsers/UserTuneParser.h> +#include <Swiften/Parser/PayloadParsers/VCardParser.h> +#include <Swiften/Parser/PayloadParsers/VCardUpdateParser.h> +#include <Swiften/Parser/PayloadParsers/WhiteboardParser.h> using namespace boost; @@ -77,4 +96,5 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { 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")); @@ -124,6 +144,20 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferHashParser> >("checksum")); factories_.push_back(boost::make_shared<GenericPayloadParserFactory<S5BProxyRequestParser> >("query", "http://jabber.org/protocol/bytestreams")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<WhiteboardParser> >("wb", "http://swift.im/whiteboard")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<UserLocationParser> >("geoloc", "http://jabber.org/protocol/geoloc")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<UserTuneParser> >("tune", "http://jabber.org/protocol/tune")); factories_.push_back(boost::make_shared<DeliveryReceiptParserFactory>()); factories_.push_back(boost::make_shared<DeliveryReceiptRequestParserFactory>()); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<IdleParser> >("idle", "urn:xmpp:idle:1")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub", this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubOwnerPubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub#owner", this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubEventParser> >("event", "http://jabber.org/protocol/pubsub#event", this)); + factories_.push_back(boost::make_shared<PubSubErrorParserFactory>()); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<ResultSetParser> >("set", "http://jabber.org/protocol/rsm")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<ForwardedParser> >("forwarded", "urn:xmpp:forward:0", this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<MAMResultParser> >("result", "urn:xmpp:mam:0", this)); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMQueryParser> >("query", "urn:xmpp:mam:0")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMArchivedParser> >("archived", "urn:xmpp:mam:0")); + factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<IsodeIQDelegationParser> >("delegate", "http://isode.com/iq_delegation", this)); foreach(shared_ptr<PayloadParserFactory> factory, factories_) { diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h index 46b692b..91302b1 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h @@ -10,9 +10,10 @@ #include <vector> +#include <Swiften/Base/API.h> #include <Swiften/Parser/PayloadParserFactoryCollection.h> #include <Swiften/Parser/PayloadParserFactory.h> namespace Swift { - class FullPayloadParserFactoryCollection : public PayloadParserFactoryCollection { + class SWIFTEN_API FullPayloadParserFactoryCollection : public PayloadParserFactoryCollection { public: FullPayloadParserFactoryCollection(); diff --git a/Swiften/Parser/PayloadParsers/IBBParser.h b/Swiften/Parser/PayloadParsers/IBBParser.h index d899475..59011b4 100644 --- a/Swiften/Parser/PayloadParsers/IBBParser.h +++ b/Swiften/Parser/PayloadParsers/IBBParser.h @@ -24,5 +24,5 @@ namespace Swift { private: enum Level { - TopLevel = 0, + TopLevel = 0 }; int level; diff --git a/Swiften/Parser/PayloadParsers/IdleParser.cpp b/Swiften/Parser/PayloadParsers/IdleParser.cpp new file mode 100644 index 0000000..51aa34b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/IdleParser.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2013 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/IdleParser.h> + +#include <Swiften/Base/DateTime.h> + +namespace Swift { + +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_; +} + +void IdleParser::handleEndElement(const std::string&, const std::string&) { + --level_; +} + +void IdleParser::handleCharacterData(const std::string&) { + +} + +} diff --git a/Swiften/Parser/PayloadParsers/IdleParser.h b/Swiften/Parser/PayloadParsers/IdleParser.h new file mode 100644 index 0000000..38001b2 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/IdleParser.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2013 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Elements/Idle.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class 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); + + private: + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h index ae8d36c..1f85c85 100644 --- a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h @@ -28,5 +28,5 @@ namespace Swift { enum Level { TopLevel = 0, - PayloadLevel = 1, + PayloadLevel = 1 }; int level; diff --git a/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp new file mode 100644 index 0000000..d085d09 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014 Remko Tronçon and Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma clang diagnostic ignored "-Wunused-private-field" + +#include <Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h> + +#include <boost/optional.hpp> + + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + + +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(boost::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..83bf95e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/IsodeIQDelegationParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2014 Remko Tronçon and Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#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(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h index 93560c6..7ea22b4 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h @@ -27,5 +27,5 @@ class JingleFileTransferDescriptionParser : public GenericPayloadParser<JingleFi UnknownElement, RequestElement, - OfferElement, + OfferElement }; diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.cpp b/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.cpp index 20ad73e..ae56981 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.cpp @@ -5,9 +5,9 @@ */ -#include "JingleFileTransferReceivedParser.h" -#include "StreamInitiationFileInfoParser.h" +#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> diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.h index 824b06d..d5333ad 100644 --- a/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.h +++ b/Swiften/Parser/PayloadParsers/JingleFileTransferReceivedParser.h @@ -26,2 +26,3 @@ private: } + diff --git a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp index a3dfd12..d140368 100644 --- a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp @@ -5,4 +5,10 @@ */ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + #include <boost/lexical_cast.hpp> #include <boost/optional.hpp> @@ -19,7 +25,10 @@ namespace Swift { void JingleIBBTransportMethodPayloadParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { try { - getPayloadInternal()->setBlockSize(boost::lexical_cast<int>(attributes.getAttributeValue("block-size").get_value_or("0"))); - } catch (boost::bad_lexical_cast &) { - getPayloadInternal()->setBlockSize(0); + 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("")); diff --git a/Swiften/Parser/PayloadParsers/JingleParser.h b/Swiften/Parser/PayloadParsers/JingleParser.h index ecaca3c..c7bd58c 100644 --- a/Swiften/Parser/PayloadParsers/JingleParser.h +++ b/Swiften/Parser/PayloadParsers/JingleParser.h @@ -30,3 +30,4 @@ class JingleParser : public GenericPayloadParser<JinglePayload> { }; -};
\ No newline at end of file +} + diff --git a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp index 14a80e6..7be4c26 100644 --- a/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.cpp @@ -5,4 +5,10 @@ */ +/* +* Copyright (c) 2014 Kevin Smith +* Licensed under the GNU General Public License v3. +* See Documentation/Licenses/GPLv3.txt for more information. +*/ + #include <boost/lexical_cast.hpp> #include <boost/optional.hpp> @@ -26,5 +32,5 @@ namespace Swift { getPayloadInternal()->setMode(JingleS5BTransportPayload::UDPMode); } else { - std::cerr << "Unknown S5B mode; falling back to defaul!" << std::endl; + SWIFT_LOG(warning) << "Unknown S5B mode; falling back to defaul!"; getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); } @@ -82,5 +88,5 @@ namespace Swift { return JingleS5BTransportPayload::Candidate::ProxyType; } else { - std::cerr << "Unknown candidate type; falling back to default!" << std::endl; + SWIFT_LOG(warning) << "Unknown candidate type; falling back to default!"; return JingleS5BTransportPayload::Candidate::DirectType; } diff --git a/Swiften/Parser/PayloadParsers/MAMArchivedParser.cpp b/Swiften/Parser/PayloadParsers/MAMArchivedParser.cpp new file mode 100644 index 0000000..616d41a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMArchivedParser.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#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/MAMArchivedParser.h> + +using namespace Swift; + +MAMArchivedParser::MAMArchivedParser() : level_(TopLevel) { +} + +void MAMArchivedParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + if (level_ == TopLevel) { + boost::optional<std::string> attributeValue; + if ((attributeValue = attributes.getAttributeValue("by"))) { + getPayloadInternal()->setBy(*attributeValue); + } + if ((attributeValue = attributes.getAttributeValue("id"))) { + getPayloadInternal()->setID(*attributeValue); + } + } + + ++level_; +} + +void MAMArchivedParser::handleEndElement(const std::string&, const std::string&) { + --level_; +} + +void MAMArchivedParser::handleCharacterData(const std::string&) { +} diff --git a/Swiften/Parser/PayloadParsers/MAMArchivedParser.h b/Swiften/Parser/PayloadParsers/MAMArchivedParser.h new file mode 100644 index 0000000..b92b41a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMArchivedParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/MAMArchived.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + + class SWIFTEN_API MAMArchivedParser : public GenericPayloadParser<MAMArchived> { + public: + MAMArchivedParser(); + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + enum Level { + TopLevel = 0 + }; + + private: + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp new file mode 100644 index 0000000..9ae8e41 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#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/FormParser.h> +#include <Swiften/Parser/PayloadParsers/ResultSetParser.h> +#include <Swiften/Parser/PayloadParsers/MAMQueryParser.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); + } + } else if (level_ == PayloadLevel) { + if (element == "x" && ns == "jabber:x:data") { + formParser_ = boost::make_shared<FormParser>(); + } else if (element == "set" && ns == "http://jabber.org/protocol/rsm") { + resultSetParser_ = boost::make_shared<ResultSetParser>(); + } + } + + if (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(boost::dynamic_pointer_cast<Form>(formParser_->getPayload())); + formParser_.reset(); + } + + if (resultSetParser_ && level_ >= PayloadLevel) { + resultSetParser_->handleEndElement(element, ns); + } + if (resultSetParser_ && level_ == PayloadLevel) { + /* done parsing nested ResultSet */ + getPayloadInternal()->setResultSet(boost::dynamic_pointer_cast<ResultSet>(resultSetParser_->getPayload())); + resultSetParser_.reset(); + } +} + +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..7bbdacb --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMQueryParser.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/MAMQuery.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + class ResultSetParser; + class FormParser; + + class SWIFTEN_API MAMQueryParser : public GenericPayloadParser<MAMQuery> { + public: + MAMQueryParser(); + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + private: + boost::shared_ptr<FormParser> formParser_; + boost::shared_ptr<ResultSetParser> resultSetParser_; + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MAMResultParser.cpp b/Swiften/Parser/PayloadParsers/MAMResultParser.cpp new file mode 100644 index 0000000..e4eec3b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMResultParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#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/ForwardedParser.h> +#include <Swiften/Parser/PayloadParsers/MAMResultParser.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_ = boost::make_shared<ForwardedParser>(factories_); + } + } + + if (payloadParser_) { + /* parsing a nested payload */ + payloadParser_->handleStartElement(element, ns, attributes); + } + + ++level_; +} + +void MAMResultParser::handleEndElement(const std::string& element, const std::string& ns) { + --level_; + if (payloadParser_ && level_ >= PayloadLevel) { + payloadParser_->handleEndElement(element, ns); + } + if (payloadParser_ && level_ == PayloadLevel) { + /* done parsing nested stanza */ + getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<Forwarded>(payloadParser_->getPayload())); + payloadParser_.reset(); + } +} + +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..39ff20a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMResultParser.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#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) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + private: + boost::shared_ptr<ForwardedParser> payloadParser_; + PayloadParserFactoryCollection* factories_; + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp index fa95af7..90590ee 100644 --- a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp +++ b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2011 Kevin Smith + * Copyright (c) 2011-2014 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -6,6 +6,5 @@ #include <Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h> - - +#include <Swiften/Parser/Tree/NullParserElement.h> namespace Swift { @@ -18,4 +17,6 @@ void MUCInvitationPayloadParser::handleTree(ParserElement::ref root) { invite->setReason(root->getAttributes().getAttribute("reason")); invite->setThread(root->getAttributes().getAttribute("thread")); + ParserElement::ref impromptuNode = root->getChild("impromptu", "http://swift.im/impromptu"); + invite->setIsImpromptu(!boost::dynamic_pointer_cast<NullParserElement>(impromptuNode)); } diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp new file mode 100644 index 0000000..044aea9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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> + +using namespace Swift; + +PubSubAffiliationParser::PubSubAffiliationParser(PayloadParserFactoryCollection* parsers) : parsers(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; +} + +void PubSubAffiliationParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubAffiliationParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h new file mode 100644 index 0000000..82d4fac --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubAffiliationParser : public GenericPayloadParser<PubSubAffiliation> { + public: + PubSubAffiliationParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubAffiliationParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp new file mode 100644 index 0000000..7b35b33 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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/PayloadParsers/PubSubAffiliationParser.h> + +using namespace Swift; + +PubSubAffiliationsParser::PubSubAffiliationsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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; +} + +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(); + } + } +} + +void PubSubAffiliationsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h new file mode 100644 index 0000000..c730a1b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubAffiliationsParser : public GenericPayloadParser<PubSubAffiliations> { + public: + PubSubAffiliationsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubAffiliationsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp new file mode 100644 index 0000000..b6099b4 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +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; +} + +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(); + } + } +} + +void PubSubConfigureParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h new file mode 100644 index 0000000..8d58129 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubConfigureParser : public GenericPayloadParser<PubSubConfigure> { + public: + PubSubConfigureParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubConfigureParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp new file mode 100644 index 0000000..3c81a6f --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +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; +} + +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(); + } + } +} + +void PubSubCreateParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubCreateParser.h b/Swiften/Parser/PayloadParsers/PubSubCreateParser.h new file mode 100644 index 0000000..2ddc80f --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubCreateParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubCreateParser : public GenericPayloadParser<PubSubCreate> { + public: + PubSubCreateParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubCreateParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp new file mode 100644 index 0000000..a82c8b0 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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> + +using namespace Swift; + +PubSubDefaultParser::PubSubDefaultParser(PayloadParserFactoryCollection* parsers) : parsers(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; +} + +void PubSubDefaultParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubDefaultParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h new file mode 100644 index 0000000..ee56e73 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubDefaultParser : public GenericPayloadParser<PubSubDefault> { + public: + PubSubDefaultParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubDefaultParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp b/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp new file mode 100644 index 0000000..9752cd2 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/PubSubErrorParser.h> + +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"); +} + +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; +} + +void PubSubErrorParser::handleEndElement(const std::string&, const std::string&) { + --level; +} + +void PubSubErrorParser::handleCharacterData(const std::string&) { +} diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParser.h b/Swiften/Parser/PayloadParsers/PubSubErrorParser.h new file mode 100644 index 0000000..eb7dcfe --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParser.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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> + +namespace Swift { + class PayloadParserFactoryCollection; + class PayloadParser; + + class SWIFTEN_API PubSubErrorParser : public GenericPayloadParser<PubSubError> { + public: + PubSubErrorParser(); + virtual ~PubSubErrorParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + 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 new file mode 100644 index 0000000..10dfd63 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h> + +using namespace Swift; + +PubSubErrorParserFactory::~PubSubErrorParserFactory() { +} diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h new file mode 100644 index 0000000..e2386da --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubErrorParser.h> + +namespace Swift { + class 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 PayloadParser* createPayloadParser() { + return new PubSubErrorParser(); + } + }; +} + + diff --git a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp new file mode 100644 index 0000000..cff6f22 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +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; +} + +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(); + } + } +} + +void PubSubEventAssociateParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h new file mode 100644 index 0000000..97db1b3 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubEventAssociateParser : public GenericPayloadParser<PubSubEventAssociate> { + public: + PubSubEventAssociateParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventAssociateParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp new file mode 100644 index 0000000..e9ecdc8 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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/PayloadParsers/PubSubEventAssociateParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h> + +using namespace Swift; + +PubSubEventCollectionParser::PubSubEventCollectionParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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 == 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 && 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); + } + + 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(); + } + } +} + +void PubSubEventCollectionParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h new file mode 100644 index 0000000..05e780b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubEventCollectionParser : public GenericPayloadParser<PubSubEventCollection> { + public: + PubSubEventCollectionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventCollectionParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp new file mode 100644 index 0000000..cb9c752 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +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; +} + +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(); + } + } +} + +void PubSubEventConfigurationParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h new file mode 100644 index 0000000..49373b9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubEventConfigurationParser : public GenericPayloadParser<PubSubEventConfiguration> { + public: + PubSubEventConfigurationParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventConfigurationParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp new file mode 100644 index 0000000..258d8bc --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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/PayloadParsers/PubSubEventRedirectParser.h> + +using namespace Swift; + +PubSubEventDeleteParser::PubSubEventDeleteParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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 == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser = boost::make_shared<PubSubEventRedirectParser>(parsers); + } + } + + 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); + } + + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") { + getPayloadInternal()->setRedirects(boost::dynamic_pointer_cast<PubSubEventRedirect>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubEventDeleteParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h new file mode 100644 index 0000000..415f496 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubEventDeleteParser : public GenericPayloadParser<PubSubEventDelete> { + public: + PubSubEventDeleteParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventDeleteParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp new file mode 100644 index 0000000..e492805 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +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; +} + +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(); + } + } +} + +void PubSubEventDisassociateParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h new file mode 100644 index 0000000..9bebd39 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubEventDisassociateParser : public GenericPayloadParser<PubSubEventDisassociate> { + public: + PubSubEventDisassociateParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventDisassociateParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp new file mode 100644 index 0000000..664028b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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> + + +using namespace Swift; + +PubSubEventItemParser::PubSubEventItemParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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 == 1) { + if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) { + currentPayloadParser.reset(factory->createPayloadParser()); + } + } + + 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); + } + + if (level == 1) { + getPayloadInternal()->addData(currentPayloadParser->getPayload()); + currentPayloadParser.reset(); + } + } +} + +void PubSubEventItemParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h new file mode 100644 index 0000000..09fbc0e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubEventItemParser : public GenericPayloadParser<PubSubEventItem> { + public: + PubSubEventItemParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventItemParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp new file mode 100644 index 0000000..aa1da86 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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/PubSubEventItemParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h> + +using namespace Swift; + +PubSubEventItemsParser::PubSubEventItemsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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 == 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 && 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); + } + + 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(); + } + } +} + +void PubSubEventItemsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h new file mode 100644 index 0000000..a379b42 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubEventItemsParser : public GenericPayloadParser<PubSubEventItems> { + public: + PubSubEventItemsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventItemsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp new file mode 100644 index 0000000..c4406a9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * 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/PayloadParsers/PubSubEventCollectionParser.h> +#include <Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h> + +using namespace Swift; + +PubSubEventParser::PubSubEventParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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; +} + +void PubSubEventParser::handleEndElement(const std::string& element, const std::string& 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(); + } + } +} + +void PubSubEventParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventParser.h b/Swiften/Parser/PayloadParsers/PubSubEventParser.h new file mode 100644 index 0000000..1042e75 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubEventParser : public GenericPayloadParser<PubSubEvent> { + public: + PubSubEventParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp new file mode 100644 index 0000000..936766e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +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; +} + +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(); + } + } +} + +void PubSubEventPurgeParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h new file mode 100644 index 0000000..edc386c --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubEventPurgeParser : public GenericPayloadParser<PubSubEventPurge> { + public: + PubSubEventPurgeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventPurgeParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp new file mode 100644 index 0000000..971f5d6 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +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; +} + +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(); + } + } +} + +void PubSubEventRedirectParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h new file mode 100644 index 0000000..5ead4d5 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubEventRedirectParser : public GenericPayloadParser<PubSubEventRedirect> { + public: + PubSubEventRedirectParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventRedirectParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp new file mode 100644 index 0000000..c94f6bd --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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> + + +using namespace Swift; + +PubSubEventRetractParser::PubSubEventRetractParser(PayloadParserFactoryCollection* parsers) : parsers(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; +} + +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(); + } + } +} + +void PubSubEventRetractParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h new file mode 100644 index 0000000..98f460e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubEventRetractParser : public GenericPayloadParser<PubSubEventRetract> { + public: + PubSubEventRetractParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventRetractParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp new file mode 100644 index 0000000..818ea2e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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> + +using namespace Swift; + +PubSubEventSubscriptionParser::PubSubEventSubscriptionParser(PayloadParserFactoryCollection* parsers) : parsers(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 >= 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); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubEventSubscriptionParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h new file mode 100644 index 0000000..3b7d348 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubEventSubscriptionParser : public GenericPayloadParser<PubSubEventSubscription> { + public: + PubSubEventSubscriptionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubEventSubscriptionParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp b/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp new file mode 100644 index 0000000..6f5cac4 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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> + + +using namespace Swift; + +PubSubItemParser::PubSubItemParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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; +} + +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(); + } + } +} + +void PubSubItemParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubItemParser.h b/Swiften/Parser/PayloadParsers/PubSubItemParser.h new file mode 100644 index 0000000..1382011 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubItemParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubItemParser : public GenericPayloadParser<PubSubItem> { + public: + PubSubItemParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubItemParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp new file mode 100644 index 0000000..277d120 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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 <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParsers/PubSubItemParser.h> + +using namespace Swift; + +PubSubItemsParser::PubSubItemsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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 == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); + } + } + + 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); + } + + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubItemsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubItemsParser.h b/Swiften/Parser/PayloadParsers/PubSubItemsParser.h new file mode 100644 index 0000000..49d8520 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubItemsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubItemsParser : public GenericPayloadParser<PubSubItems> { + public: + PubSubItemsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubItemsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp new file mode 100644 index 0000000..583dc10 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +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 == 1) { + if (element == "x" && ns == "jabber:x:data") { + currentPayloadParser = boost::make_shared<FormParser>(); + } + } + + 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); + } + + if (level == 1) { + if (element == "x" && ns == "jabber:x:data") { + getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubOptionsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h new file mode 100644 index 0000000..713901d --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubOptionsParser : public GenericPayloadParser<PubSubOptions> { + public: + PubSubOptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOptionsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp new file mode 100644 index 0000000..eeed548 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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> + +using namespace Swift; + +PubSubOwnerAffiliationParser::PubSubOwnerAffiliationParser(PayloadParserFactoryCollection* parsers) : parsers(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; +} + +void PubSubOwnerAffiliationParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerAffiliationParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h new file mode 100644 index 0000000..6fb6772 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubOwnerAffiliationParser : public GenericPayloadParser<PubSubOwnerAffiliation> { + public: + PubSubOwnerAffiliationParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerAffiliationParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp new file mode 100644 index 0000000..d16db71 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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/PayloadParsers/PubSubOwnerAffiliationParser.h> + +using namespace Swift; + +PubSubOwnerAffiliationsParser::PubSubOwnerAffiliationsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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 == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerAffiliationParser>(parsers); + } + } + + 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); + } + + if (level == 1) { + if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") { + getPayloadInternal()->addAffiliation(boost::dynamic_pointer_cast<PubSubOwnerAffiliation>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerAffiliationsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h new file mode 100644 index 0000000..2e2cd26 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubOwnerAffiliationsParser : public GenericPayloadParser<PubSubOwnerAffiliations> { + public: + PubSubOwnerAffiliationsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerAffiliationsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp new file mode 100644 index 0000000..a90610e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +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; +} + +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(); + } + } +} + +void PubSubOwnerConfigureParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h new file mode 100644 index 0000000..404954f --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubOwnerConfigureParser : public GenericPayloadParser<PubSubOwnerConfigure> { + public: + PubSubOwnerConfigureParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerConfigureParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp new file mode 100644 index 0000000..55e6660 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +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; +} + +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(); + } + } +} + +void PubSubOwnerDefaultParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h new file mode 100644 index 0000000..dba021a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubOwnerDefaultParser : public GenericPayloadParser<PubSubOwnerDefault> { + public: + PubSubOwnerDefaultParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerDefaultParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp new file mode 100644 index 0000000..b8bc371 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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/PayloadParsers/PubSubOwnerRedirectParser.h> + +using namespace Swift; + +PubSubOwnerDeleteParser::PubSubOwnerDeleteParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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 == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerRedirectParser>(parsers); + } + } + + 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); + } + + if (level == 1) { + if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") { + getPayloadInternal()->setRedirect(boost::dynamic_pointer_cast<PubSubOwnerRedirect>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerDeleteParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h new file mode 100644 index 0000000..4cf67e9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubOwnerDeleteParser : public GenericPayloadParser<PubSubOwnerDelete> { + public: + PubSubOwnerDeleteParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerDeleteParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp new file mode 100644 index 0000000..5262997 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * 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/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> + +using namespace Swift; + +PubSubOwnerPubSubParser::PubSubOwnerPubSubParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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; +} + +void PubSubOwnerPubSubParser::handleEndElement(const std::string& element, const std::string& 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(); + } + } +} + +void PubSubOwnerPubSubParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h new file mode 100644 index 0000000..25fee8a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubOwnerPubSubParser : public GenericPayloadParser<PubSubOwnerPubSub> { + public: + PubSubOwnerPubSubParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerPubSubParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp new file mode 100644 index 0000000..8fc32dd --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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> + + +using namespace Swift; + +PubSubOwnerPurgeParser::PubSubOwnerPurgeParser(PayloadParserFactoryCollection* parsers) : parsers(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; +} + +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(); + } + } +} + +void PubSubOwnerPurgeParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h new file mode 100644 index 0000000..6f38fe6 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubOwnerPurgeParser : public GenericPayloadParser<PubSubOwnerPurge> { + public: + PubSubOwnerPurgeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerPurgeParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp new file mode 100644 index 0000000..132281a --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +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; +} + +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(); + } + } +} + +void PubSubOwnerRedirectParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h new file mode 100644 index 0000000..fd14760 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubOwnerRedirectParser : public GenericPayloadParser<PubSubOwnerRedirect> { + public: + PubSubOwnerRedirectParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerRedirectParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp new file mode 100644 index 0000000..629249c --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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> + +using namespace Swift; + +PubSubOwnerSubscriptionParser::PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection* parsers) : parsers(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; +} + +void PubSubOwnerSubscriptionParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerSubscriptionParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h new file mode 100644 index 0000000..53916f9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubOwnerSubscriptionParser : public GenericPayloadParser<PubSubOwnerSubscription> { + public: + PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerSubscriptionParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp new file mode 100644 index 0000000..d322bef --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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/PayloadParsers/PubSubOwnerSubscriptionParser.h> + +using namespace Swift; + +PubSubOwnerSubscriptionsParser::PubSubOwnerSubscriptionsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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 == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser = boost::make_shared<PubSubOwnerSubscriptionParser>(parsers); + } + } + + 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); + } + + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") { + getPayloadInternal()->addSubscription(boost::dynamic_pointer_cast<PubSubOwnerSubscription>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubOwnerSubscriptionsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h new file mode 100644 index 0000000..48198db --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubOwnerSubscriptionsParser : public GenericPayloadParser<PubSubOwnerSubscriptions> { + public: + PubSubOwnerSubscriptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubOwnerSubscriptionsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubParser.cpp b/Swiften/Parser/PayloadParsers/PubSubParser.cpp new file mode 100644 index 0000000..5b1462b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubParser.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * 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/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/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/PubSubSubscriptionsParser.h> + +using namespace Swift; + +PubSubParser::PubSubParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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 && 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); + } + + 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 == 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); + } + } + } + } +} + +void PubSubParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubParser.h b/Swiften/Parser/PayloadParsers/PubSubParser.h new file mode 100644 index 0000000..0618361 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubParser.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubParser : public GenericPayloadParser<PubSub> { + public: + PubSubParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + boost::shared_ptr<PubSubConfigure> configurePayload; + boost::shared_ptr<PubSubOptions> optionsPayload; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp b/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp new file mode 100644 index 0000000..4cddf57 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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/PayloadParsers/PubSubItemParser.h> + +using namespace Swift; + +PubSubPublishParser::PubSubPublishParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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 == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); + } + } + + 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); + } + + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubPublishParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubPublishParser.h b/Swiften/Parser/PayloadParsers/PubSubPublishParser.h new file mode 100644 index 0000000..6e6c6c3 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubPublishParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubPublishParser : public GenericPayloadParser<PubSubPublish> { + public: + PubSubPublishParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubPublishParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp b/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp new file mode 100644 index 0000000..69ed5f7 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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/PayloadParsers/PubSubItemParser.h> + +using namespace Swift; + +PubSubRetractParser::PubSubRetractParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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 == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); + } + } + + 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); + } + + if (level == 1) { + if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubRetractParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubRetractParser.h b/Swiften/Parser/PayloadParsers/PubSubRetractParser.h new file mode 100644 index 0000000..2d04a8f --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubRetractParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubRetractParser : public GenericPayloadParser<PubSubRetract> { + public: + PubSubRetractParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubRetractParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp new file mode 100644 index 0000000..cac65ec --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +void PubSubSubscribeOptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + + + + + 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(); + } + } +} + +void PubSubSubscribeOptionsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h new file mode 100644 index 0000000..d10b9d4 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubSubscribeOptionsParser : public GenericPayloadParser<PubSubSubscribeOptions> { + public: + PubSubSubscribeOptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscribeOptionsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp new file mode 100644 index 0000000..f989924 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +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; +} + +void PubSubSubscribeParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubSubscribeParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h new file mode 100644 index 0000000..1c2028d --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubSubscribeParser : public GenericPayloadParser<PubSubSubscribe> { + public: + PubSubSubscribeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscribeParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp new file mode 100644 index 0000000..c3cf89c --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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/PayloadParsers/PubSubSubscribeOptionsParser.h> + +using namespace Swift; + +PubSubSubscriptionParser::PubSubSubscriptionParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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 == 1) { + if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubSubscribeOptionsParser>(parsers); + } + } + + 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); + } + + if (level == 1) { + if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->setOptions(boost::dynamic_pointer_cast<PubSubSubscribeOptions>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubSubscriptionParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h new file mode 100644 index 0000000..2ae32d4 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubSubscriptionParser : public GenericPayloadParser<PubSubSubscription> { + public: + PubSubSubscriptionParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscriptionParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp new file mode 100644 index 0000000..de3b15b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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/PayloadParsers/PubSubSubscriptionParser.h> + +using namespace Swift; + +PubSubSubscriptionsParser::PubSubSubscriptionsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) { +} + +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 == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser = boost::make_shared<PubSubSubscriptionParser>(parsers); + } + } + + 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); + } + + if (level == 1) { + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { + getPayloadInternal()->addSubscription(boost::dynamic_pointer_cast<PubSubSubscription>(currentPayloadParser->getPayload())); + } + currentPayloadParser.reset(); + } + } +} + +void PubSubSubscriptionsParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h new file mode 100644 index 0000000..a1a1a68 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubSubscriptionsParser : public GenericPayloadParser<PubSubSubscriptions> { + public: + PubSubSubscriptionsParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubSubscriptionsParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp new file mode 100644 index 0000000..b47640c --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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() { +} + +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; +} + +void PubSubUnsubscribeParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + + if (level == 1) { + + currentPayloadParser.reset(); + } + } +} + +void PubSubUnsubscribeParser::handleCharacterData(const std::string& data) { + if (level > 1 && currentPayloadParser) { + currentPayloadParser->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h new file mode 100644 index 0000000..8d88e66 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#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 SWIFTEN_API PubSubUnsubscribeParser : public GenericPayloadParser<PubSubUnsubscribe> { + public: + PubSubUnsubscribeParser(PayloadParserFactoryCollection* parsers); + virtual ~PubSubUnsubscribeParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + PayloadParserFactoryCollection* parsers; + int level; + boost::shared_ptr<PayloadParser> currentPayloadParser; + }; +} diff --git a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h index 4a027a1..2e16d00 100644 --- a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h @@ -7,4 +7,5 @@ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/RawXMLPayload.h> #include <Swiften/Parser/GenericPayloadParser.h> @@ -14,5 +15,5 @@ namespace Swift { class SerializingParser; - class RawXMLPayloadParser : public GenericPayloadParser<RawXMLPayload> { + class SWIFTEN_API RawXMLPayloadParser : public GenericPayloadParser<RawXMLPayload> { public: RawXMLPayloadParser(); diff --git a/Swiften/Parser/PayloadParsers/ReplaceParser.cpp b/Swiften/Parser/PayloadParsers/ReplaceParser.cpp index fb85fbd..728ed63 100644 --- a/Swiften/Parser/PayloadParsers/ReplaceParser.cpp +++ b/Swiften/Parser/PayloadParsers/ReplaceParser.cpp @@ -5,4 +5,12 @@ */ +/* + * Copyright (c) 2012 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + + + #include <Swiften/Parser/PayloadParsers/ReplaceParser.h> diff --git a/Swiften/Parser/PayloadParsers/ResultSetParser.cpp b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp new file mode 100644 index 0000000..4c8283b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/ResultSetParser.h> +#include <boost/optional.hpp> +#include <boost/lexical_cast.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 == "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..55399ef --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ResultSetParser.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/ResultSet.h> +#include <Swiften/Parser/GenericPayloadParser.h> + +namespace Swift { + class PayloadParserFactoryCollection; + + class SWIFTEN_API ResultSetParser : public GenericPayloadParser<ResultSet> { + public: + ResultSetParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + private: + std::string currentText_; + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/RosterParser.h b/Swiften/Parser/PayloadParsers/RosterParser.h index c29064f..3b62f0b 100644 --- a/Swiften/Parser/PayloadParsers/RosterParser.h +++ b/Swiften/Parser/PayloadParsers/RosterParser.h @@ -7,4 +7,5 @@ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Elements/RosterPayload.h> #include <Swiften/Parser/GenericPayloadParser.h> @@ -13,5 +14,5 @@ namespace Swift { class SerializingParser; - class RosterParser : public GenericPayloadParser<RosterPayload> { + class SWIFTEN_API RosterParser : public GenericPayloadParser<RosterPayload> { public: RosterParser(); diff --git a/Swiften/Parser/PayloadParsers/SearchPayloadParser.h b/Swiften/Parser/PayloadParsers/SearchPayloadParser.h index 006e0d9..d456eb8 100644 --- a/Swiften/Parser/PayloadParsers/SearchPayloadParser.h +++ b/Swiften/Parser/PayloadParsers/SearchPayloadParser.h @@ -29,5 +29,5 @@ namespace Swift { TopLevel = 0, PayloadLevel = 1, - ItemLevel = 2, + ItemLevel = 2 }; int level; diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp index 0a13844..cc69348 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp @@ -36,5 +36,5 @@ void StreamInitiationFileInfoParser::handleStartElement(const std::string& eleme parseDescription = false; if (element == "range") { - int offset = 0; + boost::uintmax_t offset = 0; try { offset = boost::lexical_cast<boost::uintmax_t>(attributes.getAttributeValue("offset").get_value_or("0")); diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp index fd3d019..ff0a061 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp +++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -41,5 +41,5 @@ void StreamInitiationParser::handleStartElement(const std::string& element, cons currentFile.setName(attributes.getAttribute("name")); try { - currentFile.setSize(boost::lexical_cast<int>(attributes.getAttribute("size"))); + currentFile.setSize(boost::lexical_cast<unsigned long long>(attributes.getAttribute("size"))); } catch (boost::bad_lexical_cast&) { @@ -97,6 +97,6 @@ void StreamInitiationParser::handleEndElement(const std::string& element, const } else if (form->getType() == Form::SubmitType) { - if (field->getRawValues().size() > 0) { - getPayloadInternal()->setRequestedMethod(field->getRawValues()[0]); + if (!field->getValues().empty()) { + getPayloadInternal()->setRequestedMethod(field->getValues()[0]); } } diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParser.h b/Swiften/Parser/PayloadParsers/StreamInitiationParser.h index c2ffd07..f7350cd 100644 --- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.h +++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.h @@ -30,5 +30,5 @@ namespace Swift { PayloadLevel = 1, FileOrFeatureLevel = 2, - FormOrDescriptionLevel = 3, + FormOrDescriptionLevel = 3 }; int level; diff --git a/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp new file mode 100644 index 0000000..ddd3a88 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2013 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt 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/BlockPayload.h> +#include <Swiften/Elements/UnblockPayload.h> +#include <Swiften/Elements/BlockListPayload.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_REGISTRATION(BlockParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp index bfbc312..d01abd1 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp @@ -16,4 +16,5 @@ class DiscoInfoParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(DiscoInfoParserTest); CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Node); CPPUNIT_TEST(testParse_Form); CPPUNIT_TEST_SUITE_END(); @@ -46,4 +47,34 @@ class DiscoInfoParserTest : public CppUnit::TestFixture { 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; + + 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()); } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp new file mode 100644 index 0000000..ee234ad --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Parser/PayloadParsers/DiscoItemsParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +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_REGISTRATION(DiscoItemsParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp index c36fbeb..bc8f1bc 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -55,6 +55,4 @@ class FormParserTest : public CppUnit::TestFixture { "<field label=\"Password for special access\" type=\"text-private\" var=\"password\"/>" "<field label=\"What features will the bot support?\" type=\"list-multi\" var=\"features\">" - "<value>news</value>" - "<value>search</value>" "<option label=\"Contests\"><value>contests</value></option>" "<option label=\"News\"><value>news</value></option>" @@ -62,4 +60,6 @@ class FormParserTest : public CppUnit::TestFixture { "<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\">" @@ -85,22 +85,20 @@ class FormParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(10, static_cast<int>(payload->getFields().size())); - CPPUNIT_ASSERT_EQUAL(std::string("jabber:bot"), boost::dynamic_pointer_cast<HiddenFormField>(payload->getFields()[0])->getValue()); + 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"), boost::dynamic_pointer_cast<FixedFormField>(payload->getFields()[1])->getValue()); + 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"), boost::dynamic_pointer_cast<TextMultiFormField>(payload->getFields()[3])->getValue()); + CPPUNIT_ASSERT_EQUAL(std::string("This is a bot.\nA quite good one actually"), payload->getFields()[3]->getTextMultiValue()); - CPPUNIT_ASSERT_EQUAL(true, boost::dynamic_pointer_cast<BooleanFormField>(payload->getFields()[4])->getValue()); + CPPUNIT_ASSERT_EQUAL(true, payload->getFields()[4]->getBoolValue()); CPPUNIT_ASSERT(payload->getFields()[4]->getRequired()); - CPPUNIT_ASSERT_EQUAL(std::string("1"), boost::dynamic_pointer_cast<BooleanFormField>(payload->getFields()[4])->getRawValues()[0]); - - CPPUNIT_ASSERT_EQUAL(std::string("news"), boost::dynamic_pointer_cast<ListMultiFormField>(payload->getFields()[6])->getValue()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getRawValues()[0]); - CPPUNIT_ASSERT_EQUAL(std::string("search"), boost::dynamic_pointer_cast<ListMultiFormField>(payload->getFields()[6])->getValue()[1]); - CPPUNIT_ASSERT_EQUAL(std::string("search"), payload->getFields()[6]->getRawValues()[1]); + 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); @@ -109,11 +107,11 @@ class FormParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getOptions()[1].value); - CPPUNIT_ASSERT_EQUAL(std::string("20"), boost::dynamic_pointer_cast<ListSingleFormField>(payload->getFields()[7])->getValue()); + CPPUNIT_ASSERT_EQUAL(std::string("20"), payload->getFields()[7]->getValues()[0]); - CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), boost::dynamic_pointer_cast<JIDMultiFormField>(payload->getFields()[8])->getValue()[0]); - CPPUNIT_ASSERT_EQUAL(JID("baz@fum.org"), boost::dynamic_pointer_cast<JIDMultiFormField>(payload->getFields()[8])->getValue()[1]); + 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"), boost::dynamic_pointer_cast<TextSingleFormField>(payload->getFields()[9])->getValue()); + CPPUNIT_ASSERT_EQUAL(std::string("foo"), payload->getFields()[9]->getValues()[0]); } @@ -158,13 +156,12 @@ class FormParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); - CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getRawValues()[0]); + 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]->getRawValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); - JIDSingleFormField::ref jidField = boost::dynamic_pointer_cast<JIDSingleFormField>(item[2]); - CPPUNIT_ASSERT(jidField); - CPPUNIT_ASSERT_EQUAL(JID("benvolio@montague.net"), jidField->getValue()); + 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]->getRawValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); @@ -172,13 +169,13 @@ class FormParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); - CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getRawValues()[0]); + 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]->getRawValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]); CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName()); - jidField = boost::dynamic_pointer_cast<JIDSingleFormField>(item[2]); + jidField = item[2]; CPPUNIT_ASSERT(jidField); - CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), jidField->getValue()); + 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]->getRawValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp new file mode 100644 index 0000000..a950fa4 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Base/DateTime.h> +#include <Swiften/Parser/PayloadParsers/ForwardedParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Elements/Delay.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/Message.h> +#include <Swiften/Elements/Presence.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>")); + + boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getDelay()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); + + boost::shared_ptr<IQ> iq = boost::dynamic_pointer_cast<IQ>(payload->getStanza()); + CPPUNIT_ASSERT(!!iq); + CPPUNIT_ASSERT_EQUAL(JID("stupidnewbie@example.com"), iq->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("kindanormal@example.com/IM"), iq->getFrom()); + CPPUNIT_ASSERT_EQUAL(std::string("id0"), iq->getID()); + CPPUNIT_ASSERT_EQUAL(IQ::Get, iq->getType()); + } + + void testParseMessage() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" + "<message xmlns=\"jabber:client\" to=\"juliet@capulet.lit/balcony\" from=\"romeo@montague.lit/orchard\" type=\"chat\">" + "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" + "</message>" + "</forwarded>")); + + boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getDelay()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); + + boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(payload->getStanza()); + CPPUNIT_ASSERT(!!message); + const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; + CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody()); + CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); + } + + void testParseMessageNoDelay() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<message xmlns=\"jabber:client\" to=\"juliet@capulet.lit/balcony\" from=\"romeo@montague.lit/orchard\" type=\"chat\">" + "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" + "</message>" + "</forwarded>")); + + boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(!payload->getDelay()); + + boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(payload->getStanza()); + CPPUNIT_ASSERT(!!message); + const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; + CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody()); + CPPUNIT_ASSERT_EQUAL(Message::Chat, message->getType()); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), message->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), message->getFrom()); + } + + void testParsePresence() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-07-10T23:08:25Z\"/>" + "<presence xmlns=\"jabber:client\" from=\"alice@wonderland.lit/rabbithole\" to=\"madhatter@wonderland.lit\" type=\"unavailable\"/>" + "</forwarded>")); + + boost::shared_ptr<Forwarded> payload = parser.getPayload<Forwarded>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getDelay()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(payload->getDelay()->getStamp())); + + boost::shared_ptr<Presence> presence = boost::dynamic_pointer_cast<Presence>(payload->getStanza()); + CPPUNIT_ASSERT(!!presence); + CPPUNIT_ASSERT_EQUAL(JID("madhatter@wonderland.lit"), presence->getTo()); + CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit/rabbithole"), presence->getFrom()); + CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, presence->getType()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ForwardedParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp new file mode 100644 index 0000000..74da474 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt 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> + +using namespace Swift; + +class IdleParserTest : public CppUnit::TestFixture { + 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" + )); + + 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/JingleParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp index f1f25cd..8c8601a 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp @@ -122,5 +122,5 @@ class JingleParserTest : public CppUnit::TestFixture { JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); CPPUNIT_ASSERT(transportPaylod); - CPPUNIT_ASSERT_EQUAL(4096, transportPaylod->getBlockSize()); + CPPUNIT_ASSERT_EQUAL(4096U, *transportPaylod->getBlockSize()); CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID()); } @@ -159,5 +159,5 @@ class JingleParserTest : public CppUnit::TestFixture { JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); CPPUNIT_ASSERT(transportPaylod); - CPPUNIT_ASSERT_EQUAL(2048, transportPaylod->getBlockSize()); + CPPUNIT_ASSERT_EQUAL(2048U, *transportPaylod->getBlockSize()); CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID()); } @@ -192,5 +192,5 @@ class JingleParserTest : public CppUnit::TestFixture { JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>(); CPPUNIT_ASSERT(transportPaylod); - CPPUNIT_ASSERT_EQUAL(2048, transportPaylod->getBlockSize()); + CPPUNIT_ASSERT_EQUAL(2048U, *transportPaylod->getBlockSize()); CPPUNIT_ASSERT_EQUAL(std::string("bt8a71h6"), transportPaylod->getSessionID()); } @@ -469,5 +469,5 @@ class JingleParserTest : public CppUnit::TestFixture { StreamInitiationFileInfo file = content->getDescription<JingleFileTransferDescription>()->getRequests()[0]; CPPUNIT_ASSERT_EQUAL(std::string("552da749930852c69ae5d2141d3766b1"), file.getHash()); - CPPUNIT_ASSERT_EQUAL(270336, file.getRangeOffset()); + CPPUNIT_ASSERT_EQUAL(static_cast<unsigned long long>(270336), file.getRangeOffset()); CPPUNIT_ASSERT_EQUAL(true, file.getSupportsRangeRequests()); } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp new file mode 100644 index 0000000..3e65cc6 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Base/DateTime.h> +#include <Swiften/Parser/PayloadParsers/MAMArchivedParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +class MAMArchivedParserTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(MAMArchivedParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<archived by=\"juliet@capulet.lit\" id=\"28482-98726-73623\" xmlns=\"urn:xmpp:mam:0\"/>")); + + boost::shared_ptr<MAMArchived> payload = parser.getPayload<MAMArchived>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit"), payload->getBy()); + CPPUNIT_ASSERT_EQUAL(std::string("28482-98726-73623"), payload->getID()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(MAMArchivedParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp new file mode 100644 index 0000000..ddcd7c4 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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(testParseEmpty); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">" + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<field type=\"text-single\" var=\"FORM_TYPE\">" + "<value>urn:xmpp:mam:0</value>" + "</field>" + "<field type=\"text-single\" var=\"start\">" + "<value>2010-08-07T00:00:00Z</value>" + "</field>" + "</x>" + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>10</max>" + "</set>" + "</query>")); + + + boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getQueryID()); + CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID()); + + CPPUNIT_ASSERT(payload->getForm()); + boost::shared_ptr<FormField> fieldType = payload->getForm()->getField("FORM_TYPE"); + CPPUNIT_ASSERT(fieldType); + CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), fieldType->getTextSingleValue()); + boost::shared_ptr<FormField> fieldStart = payload->getForm()->getField("start"); + CPPUNIT_ASSERT(fieldStart); + CPPUNIT_ASSERT_EQUAL(std::string("2010-08-07T00:00:00Z"), fieldStart->getTextSingleValue()); + + CPPUNIT_ASSERT(payload->getResultSet()); + boost::shared_ptr<ResultSet> resultSet = payload->getResultSet(); + CPPUNIT_ASSERT(resultSet->getMaxItems()); + CPPUNIT_ASSERT_EQUAL(*resultSet->getMaxItems(), 10); + } + + void testParseEmpty() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">" + "</query>")); + + boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getQueryID()); + CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID()); + CPPUNIT_ASSERT(!payload->getForm()); + CPPUNIT_ASSERT(!payload->getResultSet()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(MAMQueryParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp new file mode 100644 index 0000000..e62db9b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Base/DateTime.h> +#include <Swiften/Parser/PayloadParsers/MAMResultParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> +#include <Swiften/Elements/Delay.h> +#include <Swiften/Elements/Forwarded.h> +#include <Swiften/Elements/Message.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>")); + + boost::shared_ptr<MAMResult> payload = parser.getPayload<MAMResult>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT_EQUAL(std::string("28482-98726-73623"), payload->getID()); + CPPUNIT_ASSERT(payload->getQueryID()); + CPPUNIT_ASSERT_EQUAL(std::string("f27"), *payload->getQueryID()); + + boost::shared_ptr<Forwarded> forwarded = payload->getPayload(); + CPPUNIT_ASSERT(forwarded->getDelay()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(forwarded->getDelay()->getStamp())); + + boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(forwarded->getStanza()); + CPPUNIT_ASSERT(!!message); + const std::string expectedBody = "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."; + CPPUNIT_ASSERT_EQUAL(expectedBody, message->getBody()); + 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/PayloadsParserTester.h b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h index 213cd06..b328670 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h +++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -7,6 +7,4 @@ #pragma once -#include <cppunit/extensions/HelperMacros.h> - #include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> #include <Swiften/Parser/XMLParser.h> @@ -33,7 +31,7 @@ namespace Swift { virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == 0) { - CPPUNIT_ASSERT(!payloadParser.get()); + assert(!payloadParser.get()); PayloadParserFactory* payloadParserFactory = factories.getPayloadParserFactory(element, ns, attributes); - CPPUNIT_ASSERT(payloadParserFactory); + assert(payloadParserFactory); payloadParser.reset(payloadParserFactory->createPayloadParser()); } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp new file mode 100644 index 0000000..e345323 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt 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>" + "<first index=\"123\">stpeter@jabber.org</first>" + "<last>peterpan@neverland.lit</last>" + "<before>decaf-badba-dbad1</before>" + "<after>09af3-cc343-b409f</after>" + "</set>")); + + boost::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getMaxItems()); + CPPUNIT_ASSERT_EQUAL(100, *payload->getMaxItems()); + CPPUNIT_ASSERT(payload->getCount()); + CPPUNIT_ASSERT_EQUAL(800, *payload->getCount()); + CPPUNIT_ASSERT(payload->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>")); + + boost::shared_ptr<ResultSet> payload = parser.getPayload<ResultSet>(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getFirstID()); + CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID()); + CPPUNIT_ASSERT(!payload->getFirstIDIndex()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ResultSetParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp index ef48ced..59ea3ff 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -156,11 +156,11 @@ class SearchPayloadParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); - CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getRawValues()[0]); + 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]->getRawValues()[0]); + 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]->getRawValues()[0]); + 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]->getRawValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); @@ -168,11 +168,11 @@ class SearchPayloadParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size()); - CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getRawValues()[0]); + 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]->getRawValues()[0]); + 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]->getRawValues()[0]); + 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]->getRawValues()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]); CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName()); } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp index a378d0b..5ceec27 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2012 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -55,5 +55,5 @@ class StorageParserTest : public CppUnit::TestFixture { "jid='council@conference.underhill.org' />" "<conference " - "name='Tea party' " + "name='Tea & jam party' " "jid='teaparty@wonderland.lit' />" "</storage>")); @@ -64,5 +64,5 @@ class StorageParserTest : public CppUnit::TestFixture { 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 party"), rooms[1].name); + CPPUNIT_ASSERT_EQUAL(std::string("Tea & jam party"), rooms[1].name); CPPUNIT_ASSERT_EQUAL(JID("teaparty@wonderland.lit"), rooms[1].jid); } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp index f1e6635..6436e90 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp @@ -8,4 +8,6 @@ #include <QA/Checker/IO.h> +#include <boost/date_time/posix_time/posix_time.hpp> + #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> @@ -20,4 +22,5 @@ class VCardParserTest : public CppUnit::TestFixture { CPPUNIT_TEST(testParse); CPPUNIT_TEST(testParse_Photo); + CPPUNIT_TEST(testParse_NewlinedPhoto); CPPUNIT_TEST(testParse_Nickname); CPPUNIT_TEST_SUITE_END(); @@ -49,6 +52,34 @@ class VCardParserTest : public CppUnit::TestFixture { "<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>1234</BDAY>" + "<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>")); @@ -63,5 +94,5 @@ class VCardParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(std::string("PhD"), payload->getSuffix()); CPPUNIT_ASSERT_EQUAL(std::string("DreamGirl"), payload->getNickname()); - CPPUNIT_ASSERT_EQUAL(std::string("<BDAY xmlns=\"vcard-temp\">1234</BDAY><MAILER xmlns=\"vcard-temp\">mutt</MAILER>"), payload->getUnknownContent()); + 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); @@ -77,4 +108,43 @@ class VCardParserTest : public CppUnit::TestFixture { 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()); } @@ -98,4 +168,28 @@ class VCardParserTest : public CppUnit::TestFixture { } + 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; diff --git a/Swiften/Parser/PayloadParsers/UserLocationParser.cpp b/Swiften/Parser/PayloadParsers/UserLocationParser.cpp new file mode 100644 index 0000000..d3aac69 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UserLocationParser.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Swiften/Parser/PayloadParsers/UserLocationParser.h> + +#include <boost/lexical_cast.hpp> + +#include <Swiften/Base/DateTime.h> + +using namespace Swift; + +UserLocationParser::UserLocationParser() : level(0) { +} + +UserLocationParser::~UserLocationParser() { +} + +void UserLocationParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) { + 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&) { + } + } +} + +void UserLocationParser::handleCharacterData(const std::string& data) { + currentText += data; +} diff --git a/Swiften/Parser/PayloadParsers/UserLocationParser.h b/Swiften/Parser/PayloadParsers/UserLocationParser.h new file mode 100644 index 0000000..eb6e668 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UserLocationParser.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> +#include <string> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Elements/UserLocation.h> + +namespace Swift { + class SWIFTEN_API UserLocationParser : public GenericPayloadParser<UserLocation> { + public: + UserLocationParser(); + virtual ~UserLocationParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + 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..bb299e4 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UserTuneParser.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014 Remko Tronçon + * Licensed under the GNU General Public License. + * 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..1cfadea --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UserTuneParser.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2014 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> +#include <string> + +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> +#include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Elements/UserTune.h> + +namespace Swift { + class SWIFTEN_API UserTuneParser : public GenericPayloadParser<UserTune> { + public: + UserTuneParser(); + virtual ~UserTuneParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + private: + int level; + std::string currentText; + }; +} diff --git a/Swiften/Parser/PayloadParsers/VCardParser.cpp b/Swiften/Parser/PayloadParsers/VCardParser.cpp index 553d26a..0028411 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.cpp +++ b/Swiften/Parser/PayloadParsers/VCardParser.cpp @@ -7,4 +7,5 @@ #include <Swiften/Parser/PayloadParsers/VCardParser.h> #include <Swiften/Base/foreach.h> +#include <Swiften/Base/DateTime.h> #include <Swiften/StringCodecs/Base64.h> #include <Swiften/Parser/SerializingParser.h> @@ -21,4 +22,16 @@ void VCardParser::handleStartElement(const std::string& element, const std::stri 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_); @@ -69,4 +82,6 @@ void VCardParser::handleEndElement(const std::string& element, const std::string } 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_)); } @@ -91,7 +106,158 @@ void VCardParser::handleEndElement(const std::string& element, const std::string currentEMailAddress_.isPreferred = true; } - else if (elementHierarchy == "/vCard/EMAIL") { + 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()); diff --git a/Swiften/Parser/PayloadParsers/VCardParser.h b/Swiften/Parser/PayloadParsers/VCardParser.h index 1475277..f10d639 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.h +++ b/Swiften/Parser/PayloadParsers/VCardParser.h @@ -10,8 +10,10 @@ #include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Base/API.h> + namespace Swift { class SerializingParser; - class VCardParser : public GenericPayloadParser<VCard> { + class SWIFTEN_API VCardParser : public GenericPayloadParser<VCard> { public: VCardParser(); @@ -27,4 +29,8 @@ namespace Swift { 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/WhiteboardParser.cpp b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp new file mode 100644 index 0000000..a480813 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp @@ -0,0 +1,315 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt 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 <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/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) { + } + + 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&) { + } + } + + } 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); + + 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); + + 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); + + 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>(); + + 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); + + 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&) { + } + + WhiteboardTextElement::ref whiteboardElement = boost::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); + + 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); + + 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_; + } + + 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); + } + + 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; + } + } + } + + void WhiteboardParser::handleCharacterData(const std::string& data) { + if (level_ == 3 && actualIsText) { + WhiteboardTextElement::ref element = boost::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; + } + } + + 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 new file mode 100644 index 0000000..0368c7c --- /dev/null +++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Elements/WhiteboardPayload.h> +#include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Elements/Whiteboard/WhiteboardElement.h> +#include <Swiften/Elements/Whiteboard/WhiteboardOperation.h> + +namespace Swift { + class 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); + + 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; + }; +} diff --git a/Swiften/Parser/PlatformXMLParserFactory.h b/Swiften/Parser/PlatformXMLParserFactory.h index 16756ee..70355d0 100644 --- a/Swiften/Parser/PlatformXMLParserFactory.h +++ b/Swiften/Parser/PlatformXMLParserFactory.h @@ -8,7 +8,8 @@ #include <Swiften/Parser/XMLParserFactory.h> +#include <Swiften/Base/API.h> namespace Swift { - class PlatformXMLParserFactory : public XMLParserFactory { + class SWIFTEN_API PlatformXMLParserFactory : public XMLParserFactory { public: PlatformXMLParserFactory(); diff --git a/Swiften/Parser/PresenceParser.h b/Swiften/Parser/PresenceParser.h index 19f90b3..eb07af8 100644 --- a/Swiften/Parser/PresenceParser.h +++ b/Swiften/Parser/PresenceParser.h @@ -7,9 +7,10 @@ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/GenericStanzaParser.h> #include <Swiften/Elements/Presence.h> namespace Swift { - class PresenceParser : public GenericStanzaParser<Presence> { + class SWIFTEN_API PresenceParser : public GenericStanzaParser<Presence> { public: PresenceParser(PayloadParserFactoryCollection* factories); diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index e4c2778..e748320 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -70,7 +70,18 @@ sources = [ "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/MAMResultParser.cpp", + "PayloadParsers/MAMQueryParser.cpp", + "PayloadParsers/MAMArchivedParser.cpp", + "PayloadParsers/IsodeIQDelegationParser.cpp", "PlatformXMLParserFactory.cpp", "PresenceParser.cpp", diff --git a/Swiften/Parser/SerializingParser.h b/Swiften/Parser/SerializingParser.h index 5f2c0cd..7706961 100644 --- a/Swiften/Parser/SerializingParser.h +++ b/Swiften/Parser/SerializingParser.h @@ -8,9 +8,10 @@ #include <string> +#include <Swiften/Base/API.h> #include <Swiften/Parser/AttributeMap.h> #include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { - class SerializingParser { + class SWIFTEN_API SerializingParser { public: SerializingParser(); diff --git a/Swiften/Parser/StanzaAckParser.h b/Swiften/Parser/StanzaAckParser.h index c188878..c453039 100644 --- a/Swiften/Parser/StanzaAckParser.h +++ b/Swiften/Parser/StanzaAckParser.h @@ -7,9 +7,10 @@ #pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/GenericElementParser.h> #include <Swiften/Elements/StanzaAck.h> namespace Swift { - class StanzaAckParser : public GenericElementParser<StanzaAck> { + class SWIFTEN_API StanzaAckParser : public GenericElementParser<StanzaAck> { public: StanzaAckParser(); diff --git a/Swiften/Parser/StanzaParser.h b/Swiften/Parser/StanzaParser.h index 6887981..fc60b47 100644 --- a/Swiften/Parser/StanzaParser.h +++ b/Swiften/Parser/StanzaParser.h @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -10,4 +10,5 @@ #include <boost/shared_ptr.hpp> +#include <Swiften/Base/API.h> #include <string> #include <Swiften/Elements/Stanza.h> @@ -19,5 +20,5 @@ namespace Swift { class PayloadParserFactoryCollection; - class StanzaParser : public ElementParser, public boost::noncopyable { + class SWIFTEN_API StanzaParser : public ElementParser, public boost::noncopyable { public: StanzaParser(PayloadParserFactoryCollection* factories); @@ -28,5 +29,5 @@ namespace Swift { void handleCharacterData(const std::string& data); - virtual boost::shared_ptr<Element> getElement() const = 0; + virtual boost::shared_ptr<ToplevelElement> getElement() const = 0; virtual void handleStanzaAttributes(const AttributeMap&) {} diff --git a/Swiften/Parser/StreamFeaturesParser.h b/Swiften/Parser/StreamFeaturesParser.h index d55abe9..4bbb31c 100644 --- a/Swiften/Parser/StreamFeaturesParser.h +++ b/Swiften/Parser/StreamFeaturesParser.h @@ -8,9 +8,10 @@ #include <string> +#include <Swiften/Base/API.h> #include <Swiften/Parser/GenericElementParser.h> #include <Swiften/Elements/StreamFeatures.h> namespace Swift { - class StreamFeaturesParser : public GenericElementParser<StreamFeatures> { + class SWIFTEN_API StreamFeaturesParser : public GenericElementParser<StreamFeatures> { public: StreamFeaturesParser(); diff --git a/Swiften/Parser/StreamManagementEnabledParser.h b/Swiften/Parser/StreamManagementEnabledParser.h index db616af..dfe232c 100644 --- a/Swiften/Parser/StreamManagementEnabledParser.h +++ b/Swiften/Parser/StreamManagementEnabledParser.h @@ -9,7 +9,8 @@ #include <Swiften/Parser/GenericElementParser.h> #include <Swiften/Elements/StreamManagementEnabled.h> +#include <Swiften/Base/API.h> namespace Swift { - class StreamManagementEnabledParser : public GenericElementParser<StreamManagementEnabled> { + class SWIFTEN_API StreamManagementEnabledParser : public GenericElementParser<StreamManagementEnabled> { public: StreamManagementEnabledParser(); diff --git a/Swiften/Parser/Tree/ParserElement.cpp b/Swiften/Parser/Tree/ParserElement.cpp index 9d9b9b6..e5f8bc8 100644 --- a/Swiften/Parser/Tree/ParserElement.cpp +++ b/Swiften/Parser/Tree/ParserElement.cpp @@ -10,4 +10,8 @@ #include <iostream> +#include <boost/lambda/lambda.hpp> +#include <boost/lambda/bind.hpp> + +namespace lambda = boost::lambda; namespace Swift { @@ -29,17 +33,8 @@ void ParserElement::appendCharacterData(const std::string& data) { } -struct DoesntMatch { - public: - DoesntMatch(const std::string& tagName, const std::string& ns) : tagName(tagName), ns(ns) {} - bool operator()(ParserElement::ref element) { return element->getName() != tagName || element->getNamespace() != ns; } - private: - std::string tagName; - std::string ns; -}; - - 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), DoesntMatch(name, xmlns)); + 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; } diff --git a/Swiften/Parser/Tree/ParserElement.h b/Swiften/Parser/Tree/ParserElement.h index b268c76..6be0631 100644 --- a/Swiften/Parser/Tree/ParserElement.h +++ b/Swiften/Parser/Tree/ParserElement.h @@ -10,4 +10,5 @@ #include <string> #include <vector> +#include <Swiften/Base/API.h> #include <Swiften/Base/boost_bsignals.h> #include <Swiften/Parser/AttributeMap.h> @@ -16,5 +17,5 @@ namespace Swift { - class ParserElement { + class SWIFTEN_API ParserElement { public: typedef boost::shared_ptr<ParserElement> ref; diff --git a/Swiften/Parser/UnitTest/EnumParserTest.cpp b/Swiften/Parser/UnitTest/EnumParserTest.cpp new file mode 100644 index 0000000..44a30c0 --- /dev/null +++ b/Swiften/Parser/UnitTest/EnumParserTest.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Parser/EnumParser.h> + +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_REGISTRATION(EnumParserTest); diff --git a/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp b/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp index d095afc..93d4e7f 100644 --- a/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp +++ b/Swiften/Parser/UnitTest/GenericPayloadTreeParserTest.cpp @@ -8,4 +8,5 @@ #include <cppunit/extensions/TestFactoryRegistry.h> +#include <Swiften/Base/Platform.h> #include <Swiften/Parser/GenericPayloadTreeParser.h> #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h> @@ -14,4 +15,11 @@ using namespace Swift; + +#if !SWIFTEN_STATIC && defined(SWIFTEN_PLATFORM_WINDOWS) +// This base class of a class used in this file is already exported, so need to +// explicitly import it. +template class __declspec(dllimport) Swift::GenericPayloadParser<RawXMLPayload>; +#endif + class GenericPayloadTreeParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(GenericPayloadTreeParserTest); diff --git a/Swiften/Parser/UnitTest/StanzaParserTest.cpp b/Swiften/Parser/UnitTest/StanzaParserTest.cpp index 88e6dec..020f0ca 100644 --- a/Swiften/Parser/UnitTest/StanzaParserTest.cpp +++ b/Swiften/Parser/UnitTest/StanzaParserTest.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -197,5 +197,5 @@ class StanzaParserTest : public CppUnit::TestFixture { } - virtual boost::shared_ptr<Element> getElement() const { + virtual boost::shared_ptr<ToplevelElement> getElement() const { return stanza_; } diff --git a/Swiften/Parser/UnitTest/XMLParserTest.cpp b/Swiften/Parser/UnitTest/XMLParserTest.cpp index 3c84220..4bdeb54 100644 --- a/Swiften/Parser/UnitTest/XMLParserTest.cpp +++ b/Swiften/Parser/UnitTest/XMLParserTest.cpp @@ -36,4 +36,5 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_TEST(testParse_AttributeWithNamespace); CPPUNIT_TEST(testParse_BillionLaughs); + CPPUNIT_TEST(testParse_InternalEntity); //CPPUNIT_TEST(testParse_UndefinedPrefix); //CPPUNIT_TEST(testParse_UndefinedAttributePrefix); @@ -275,4 +276,10 @@ class XMLParserTest : public CppUnit::TestFixture { } + void testParse_InternalEntity() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(!testling.parse("<!DOCTYPE foo [<!ENTITY bar \"Bar\">]><foo>&bar;</foo>")); + } + void testParse_UndefinedPrefix() { ParserType testling(&client_); diff --git a/Swiften/Parser/UnitTest/XMPPParserTest.cpp b/Swiften/Parser/UnitTest/XMPPParserTest.cpp index f8d60f2..7d2d3fa 100644 --- a/Swiften/Parser/UnitTest/XMPPParserTest.cpp +++ b/Swiften/Parser/UnitTest/XMPPParserTest.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -163,5 +163,5 @@ class XMPPParserTest : public CppUnit::TestFixture { enum Type { StreamStart, ElementEvent, StreamEnd }; struct Event { - Event(Type type, boost::shared_ptr<Element> element) + Event(Type type, boost::shared_ptr<ToplevelElement> element) : type(type), element(element) {} Event(Type type, const ProtocolHeader& header) : type(type), header(header) {} @@ -171,5 +171,5 @@ class XMPPParserTest : public CppUnit::TestFixture { Type type; boost::optional<ProtocolHeader> header; - boost::shared_ptr<Element> element; + boost::shared_ptr<ToplevelElement> element; }; @@ -180,5 +180,5 @@ class XMPPParserTest : public CppUnit::TestFixture { } - void handleElement(boost::shared_ptr<Element> element) { + void handleElement(boost::shared_ptr<ToplevelElement> element) { events.push_back(Event(ElementEvent, element)); } diff --git a/Swiften/Parser/XMLParser.h b/Swiften/Parser/XMLParser.h index 1b866e3..6ecc626 100644 --- a/Swiften/Parser/XMLParser.h +++ b/Swiften/Parser/XMLParser.h @@ -9,9 +9,10 @@ #include <string> -namespace Swift { +#include <Swiften/Base/API.h> +namespace Swift { class XMLParserClient; - class XMLParser { + class SWIFTEN_API XMLParser { public: XMLParser(XMLParserClient* client); diff --git a/Swiften/Parser/XMLParserClient.h b/Swiften/Parser/XMLParserClient.h index ff706a0..956eacf 100644 --- a/Swiften/Parser/XMLParserClient.h +++ b/Swiften/Parser/XMLParserClient.h @@ -5,13 +5,11 @@ */ -#ifndef XMLPARSERCLIENT_H -#define XMLPARSERCLIENT_H +#pragma once +#include <Swiften/Base/API.h> #include <Swiften/Parser/AttributeMap.h> namespace Swift { - - - class XMLParserClient { + class SWIFTEN_API XMLParserClient { public: virtual ~XMLParserClient(); @@ -22,4 +20,2 @@ namespace Swift { }; } - -#endif diff --git a/Swiften/Parser/XMLParserFactory.h b/Swiften/Parser/XMLParserFactory.h index 32665cb..6979ea4 100644 --- a/Swiften/Parser/XMLParserFactory.h +++ b/Swiften/Parser/XMLParserFactory.h @@ -7,9 +7,11 @@ #pragma once +#include <Swiften/Base/API.h> + namespace Swift { class XMLParser; class XMLParserClient; - class XMLParserFactory { + class SWIFTEN_API XMLParserFactory { public: virtual ~XMLParserFactory(); diff --git a/Swiften/Parser/XMPPParser.h b/Swiften/Parser/XMPPParser.h index 6cce2bd..757ee22 100644 --- a/Swiften/Parser/XMPPParser.h +++ b/Swiften/Parser/XMPPParser.h @@ -10,4 +10,5 @@ #include <boost/noncopyable.hpp> +#include <Swiften/Base/API.h> #include <Swiften/Parser/XMLParserClient.h> #include <Swiften/Parser/AttributeMap.h> @@ -20,5 +21,5 @@ namespace Swift { class PayloadParserFactoryCollection; - class XMPPParser : public XMLParserClient, boost::noncopyable { + class SWIFTEN_API XMPPParser : public XMLParserClient, boost::noncopyable { public: XMPPParser( diff --git a/Swiften/Parser/XMPPParserClient.h b/Swiften/Parser/XMPPParserClient.h index e613f8e..7d35968 100644 --- a/Swiften/Parser/XMPPParserClient.h +++ b/Swiften/Parser/XMPPParserClient.h @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -9,5 +9,6 @@ #include <boost/shared_ptr.hpp> -#include <Swiften/Elements/Element.h> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/ToplevelElement.h> namespace Swift { @@ -15,10 +16,10 @@ namespace Swift { class ProtocolHeader; - class XMPPParserClient { + class SWIFTEN_API XMPPParserClient { public: virtual ~XMPPParserClient(); virtual void handleStreamStart(const ProtocolHeader&) = 0; - virtual void handleElement(boost::shared_ptr<Element>) = 0; + virtual void handleElement(boost::shared_ptr<ToplevelElement>) = 0; virtual void handleStreamEnd() = 0; }; |