From e4704555946626980014d936dcfe6ede2710501b Mon Sep 17 00:00:00 2001 From: Richard Maudsley Date: Tue, 25 Feb 2014 13:19:11 +0000 Subject: Added MAM parsers, serializers and tests. Change-Id: I589a7c65664bfecfd0ac34240600dcccb4cbd40e diff --git a/Swiften/Elements/Forwarded.cpp b/Swiften/Elements/Forwarded.cpp new file mode 100644 index 0000000..590c1ca --- /dev/null +++ b/Swiften/Elements/Forwarded.cpp @@ -0,0 +1,12 @@ +/* + * 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 + +using namespace Swift; + +Forwarded::~Forwarded() { +} diff --git a/Swiften/Elements/Forwarded.h b/Swiften/Elements/Forwarded.h new file mode 100644 index 0000000..f1a718c --- /dev/null +++ b/Swiften/Elements/Forwarded.h @@ -0,0 +1,32 @@ +/* + * 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 +#include +#include +#include + +namespace Swift { + class Delay; + class Stanza; + + class SWIFTEN_API Forwarded : public Payload { + public: + virtual ~Forwarded(); + + void setDelay(boost::shared_ptr delay) { delay_ = delay; } + const boost::shared_ptr& getDelay() const { return delay_; } + + void setStanza(boost::shared_ptr stanza) { stanza_ = stanza; } + const boost::shared_ptr& getStanza() const { return stanza_; } + + private: + boost::shared_ptr delay_; + boost::shared_ptr stanza_; + }; +} diff --git a/Swiften/Elements/MAMArchived.cpp b/Swiften/Elements/MAMArchived.cpp new file mode 100644 index 0000000..4ec5750 --- /dev/null +++ b/Swiften/Elements/MAMArchived.cpp @@ -0,0 +1,12 @@ +/* + * 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 + +using namespace Swift; + +MAMArchived::~MAMArchived() { +} diff --git a/Swiften/Elements/MAMArchived.h b/Swiften/Elements/MAMArchived.h new file mode 100644 index 0000000..df83427 --- /dev/null +++ b/Swiften/Elements/MAMArchived.h @@ -0,0 +1,29 @@ +/* + * 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 +#include +#include +#include + +namespace Swift { + class SWIFTEN_API MAMArchived : public Payload { + public: + virtual ~MAMArchived(); + + void setBy(const JID& by) { by_ = by; } + const JID& getBy() const { return by_; } + + void setID(const std::string& id) { id_ = id; } + const std::string& getID() const { return id_; } + + private: + JID by_; + std::string id_; + }; +} diff --git a/Swiften/Elements/MAMQuery.cpp b/Swiften/Elements/MAMQuery.cpp new file mode 100644 index 0000000..ff71bcc --- /dev/null +++ b/Swiften/Elements/MAMQuery.cpp @@ -0,0 +1,12 @@ +/* + * 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 + +using namespace Swift; + +MAMQuery::~MAMQuery() { +} diff --git a/Swiften/Elements/MAMQuery.h b/Swiften/Elements/MAMQuery.h new file mode 100644 index 0000000..3f3724e --- /dev/null +++ b/Swiften/Elements/MAMQuery.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 +#include +#include +#include +#include +#include +#include + +namespace Swift { + class SWIFTEN_API MAMQuery : public Payload { + public: + virtual ~MAMQuery(); + + void setQueryID(const boost::optional& queryID) { queryID_ = queryID; } + const boost::optional& getQueryID() const { return queryID_; } + + void setForm(boost::shared_ptr
form) { form_ = form; } + const boost::shared_ptr& getForm() const { return form_; } + + void setResultSet(boost::shared_ptr resultSet) { resultSet_ = resultSet; } + const boost::shared_ptr& getResultSet() const { return resultSet_; } + + private: + boost::optional queryID_; + boost::shared_ptr form_; + boost::shared_ptr resultSet_; + }; +} diff --git a/Swiften/Elements/MAMResult.cpp b/Swiften/Elements/MAMResult.cpp new file mode 100644 index 0000000..79913d3 --- /dev/null +++ b/Swiften/Elements/MAMResult.cpp @@ -0,0 +1,12 @@ +/* + * 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 + +using namespace Swift; + +MAMResult::~MAMResult() { +} diff --git a/Swiften/Elements/MAMResult.h b/Swiften/Elements/MAMResult.h new file mode 100644 index 0000000..7d43902 --- /dev/null +++ b/Swiften/Elements/MAMResult.h @@ -0,0 +1,29 @@ +/* + * 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 +#include +#include +#include + +namespace Swift { + class SWIFTEN_API MAMResult : public ContainerPayload { + public: + virtual ~MAMResult(); + + void setID(const std::string& id) { id_ = id; } + const std::string& getID() const { return id_; } + + void setQueryID(const boost::optional& queryID) { queryID_ = queryID; } + const boost::optional& getQueryID() const { return queryID_; } + + private: + std::string id_; + boost::optional queryID_; + }; +} diff --git a/Swiften/Elements/ResultSet.cpp b/Swiften/Elements/ResultSet.cpp new file mode 100644 index 0000000..2565bbb --- /dev/null +++ b/Swiften/Elements/ResultSet.cpp @@ -0,0 +1,12 @@ +/* + * 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 + +using namespace Swift; + +ResultSet::~ResultSet() { +} diff --git a/Swiften/Elements/ResultSet.h b/Swiften/Elements/ResultSet.h new file mode 100644 index 0000000..871b699 --- /dev/null +++ b/Swiften/Elements/ResultSet.h @@ -0,0 +1,44 @@ +/* + * 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 +#include +#include + +namespace Swift { + class SWIFTEN_API ResultSet : public Payload { + public: + virtual ~ResultSet(); + + void setMaxItems(const boost::optional& maxItems) { maxItems_ = maxItems; } + const boost::optional& getMaxItems() const { return maxItems_; } + + void setCount(const boost::optional& count) { count_ = count; } + const boost::optional& getCount() const { return count_; } + + void setFirstIDIndex(const boost::optional& firstIndex) { firstIndex_ = firstIndex; } + const boost::optional& getFirstIDIndex() const { return firstIndex_; } + + void setFirstID(const boost::optional& firstID) { firstID_ = firstID; } + const boost::optional& getFirstID() const { return firstID_; } + + void setLastID(const boost::optional& lastID) { lastID_ = lastID; } + const boost::optional& getLastID() const { return lastID_; } + + void setAfter(const boost::optional& after) { after_ = after; } + const boost::optional& getAfter() const { return after_; } + + private: + boost::optional maxItems_; + boost::optional count_; + boost::optional firstIndex_; + boost::optional firstID_; + boost::optional lastID_; + boost::optional after_; + }; +} 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +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(boost::make_shared(factories_)); + } else if (element == "message" && ns == "jabber:client") { + childParser_ = boost::dynamic_pointer_cast(boost::make_shared(factories_)); + } else if (element == "presence" && ns == "jabber:client") { + childParser_ = boost::dynamic_pointer_cast(boost::make_shared(factories_)); + } else if (element == "delay" && ns == "urn:xmpp:delay") { /* nested delay payload */ + delayParser_ = boost::make_shared(); + } + } + 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(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 + +#include +#include +#include +#include + +namespace Swift { + class PayloadParserFactoryCollection; + class StanzaParser; + class DelayParser; + + class SWIFTEN_API ForwardedParser : public GenericPayloadParser { + 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 childParser_; + boost::shared_ptr delayParser_; + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 22019b4..4541b3b 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -76,6 +76,11 @@ #include #include #include +#include +#include +#include +#include +#include using namespace boost; @@ -144,6 +149,11 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(boost::make_shared >("pubsub", "http://jabber.org/protocol/pubsub#owner", this)); factories_.push_back(boost::make_shared >("event", "http://jabber.org/protocol/pubsub#event", this)); factories_.push_back(boost::make_shared()); + factories_.push_back(boost::make_shared >("set", "http://jabber.org/protocol/rsm")); + factories_.push_back(boost::make_shared >("forwarded", "urn:xmpp:forward:0", this)); + factories_.push_back(boost::make_shared >("result", "urn:xmpp:mam:0", this)); + factories_.push_back(boost::make_shared >("query", "urn:xmpp:mam:0")); + factories_.push_back(boost::make_shared >("archived", "urn:xmpp:mam:0")); foreach(shared_ptr factory, factories_) { addFactory(factory.get()); 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 +#include +#include +#include +#include +#include + +using namespace Swift; + +MAMArchivedParser::MAMArchivedParser() : level_(TopLevel) { +} + +void MAMArchivedParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + if (level_ == TopLevel) { + boost::optional 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 + +#include +#include +#include +#include + +namespace Swift { + class PayloadParserFactoryCollection; + + class SWIFTEN_API MAMArchivedParser : public GenericPayloadParser { + 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 +#include +#include +#include +#include +#include +#include +#include + +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 attributeValue; + if ((attributeValue = attributes.getAttributeValue("queryid"))) { + getPayloadInternal()->setQueryID(*attributeValue); + } + } else if (level_ == PayloadLevel) { + if (element == "x" && ns == "jabber:x:data") { + formParser_ = boost::make_shared(); + } else if (element == "set" && ns == "http://jabber.org/protocol/rsm") { + resultSetParser_ = boost::make_shared(); + } + } + + 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(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(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 + +#include +#include +#include +#include + +namespace Swift { + class PayloadParserFactoryCollection; + class ResultSetParser; + class FormParser; + + class SWIFTEN_API MAMQueryParser : public GenericPayloadParser { + 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_; + boost::shared_ptr 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 +#include +#include +#include +#include +#include +#include + +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 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(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(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 + +#include +#include +#include +#include + +namespace Swift { + class PayloadParserFactoryCollection; + class ForwardedParser; + + class SWIFTEN_API MAMResultParser : public GenericPayloadParser { + 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 payloadParser_; + PayloadParserFactoryCollection* factories_; + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/ResultSetParser.cpp b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp new file mode 100644 index 0000000..95960d7 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/ResultSetParser.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 +#include +#include +#include +#include + +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 attributeValue = attributes.getAttributeValue("index")) { + try { + getPayloadInternal()->setFirstIDIndex(boost::lexical_cast(*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(currentText_)); + } catch(boost::bad_lexical_cast&) { + } + } else if (element == "count") { + try { + getPayloadInternal()->setCount(boost::lexical_cast(currentText_)); + } catch(boost::bad_lexical_cast&) { + } + } else if (element == "first") { + getPayloadInternal()->setFirstID(currentText_); + } else if (element == "last") { + getPayloadInternal()->setLastID(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 + +#include +#include +#include +#include + +namespace Swift { + class PayloadParserFactoryCollection; + + class SWIFTEN_API ResultSetParser : public GenericPayloadParser { + 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/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 +#include + +#include +#include +#include +#include +#include +#include +#include + +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( + "" + "" + "" + "")); + + boost::shared_ptr payload = parser.getPayload(); + 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 = boost::dynamic_pointer_cast(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( + "" + "" + "" + "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo." + "" + "")); + + boost::shared_ptr payload = parser.getPayload(); + 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 = boost::dynamic_pointer_cast(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( + "" + "" + "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo." + "" + "")); + + boost::shared_ptr payload = parser.getPayload(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(!payload->getDelay()); + + boost::shared_ptr message = boost::dynamic_pointer_cast(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( + "" + "" + "" + "")); + + boost::shared_ptr payload = parser.getPayload(); + 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 = boost::dynamic_pointer_cast(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/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 +#include + +#include +#include +#include + +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( + "")); + + boost::shared_ptr payload = parser.getPayload(); + 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 +#include + +#include +#include +#include + +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( + "" + "" + "" + "urn:xmpp:mam:0" + "" + "" + "2010-08-07T00:00:00Z" + "" + "" + "" + "10" + "" + "")); + + + boost::shared_ptr payload = parser.getPayload(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT(payload->getQueryID()); + CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID()); + + CPPUNIT_ASSERT(payload->getForm()); + boost::shared_ptr fieldType = payload->getForm()->getField("FORM_TYPE"); + CPPUNIT_ASSERT(fieldType); + CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), fieldType->getTextSingleValue()); + boost::shared_ptr 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 = payload->getResultSet(); + CPPUNIT_ASSERT(resultSet->getMaxItems()); + CPPUNIT_ASSERT_EQUAL(*resultSet->getMaxItems(), 10); + } + + void testParseEmpty() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "" + "")); + + boost::shared_ptr payload = parser.getPayload(); + 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 +#include + +#include +#include +#include +#include +#include +#include + +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( + "" + "" + "" + "" + "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo." + "" + "" + "")); + + boost::shared_ptr payload = parser.getPayload(); + 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 = payload->getPayload(); + CPPUNIT_ASSERT(forwarded->getDelay()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-10T23:08:25Z"), dateTimeToString(forwarded->getDelay()->getStamp())); + + boost::shared_ptr message = boost::dynamic_pointer_cast(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/ResultSetParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp new file mode 100644 index 0000000..68df71b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp @@ -0,0 +1,65 @@ +/* + * 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 +#include + +#include +#include + +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( + "" + "100" + "800" + "stpeter@jabber.org" + "peterpan@neverland.lit" + "09af3-cc343-b409f" + "")); + + boost::shared_ptr payload = parser.getPayload(); + 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->getAfter()); + CPPUNIT_ASSERT_EQUAL(std::string("09af3-cc343-b409f"), *payload->getAfter()); + } + + void testParseFirstNoIndex() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "" + "stpeter@jabber.org" + "")); + + boost::shared_ptr payload = parser.getPayload(); + 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/SConscript b/Swiften/Parser/SConscript index 4d6db11..056862f 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -77,6 +77,11 @@ sources = [ "PayloadParsers/UserTuneParser.cpp", "PayloadParsers/WhiteboardParser.cpp", "PayloadParsers/PubSubErrorParserFactory.cpp", + "PayloadParsers/ResultSetParser.cpp", + "PayloadParsers/ForwardedParser.cpp", + "PayloadParsers/MAMResultParser.cpp", + "PayloadParsers/MAMQueryParser.cpp", + "PayloadParsers/MAMArchivedParser.cpp", "PlatformXMLParserFactory.cpp", "PresenceParser.cpp", "SerializingParser.cpp", diff --git a/Swiften/SConscript b/Swiften/SConscript index 80db7da..574b7d8 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -141,6 +141,11 @@ if env["SCONS_STAGE"] == "build" : "Elements/UserTune.cpp", "Elements/VCard.cpp", "Elements/MUCOccupant.cpp", + "Elements/ResultSet.cpp", + "Elements/Forwarded.cpp", + "Elements/MAMResult.cpp", + "Elements/MAMQuery.cpp", + "Elements/MAMArchived.cpp", "Entity/Entity.cpp", "Entity/PayloadPersister.cpp", "MUC/MUC.cpp", @@ -219,6 +224,11 @@ if env["SCONS_STAGE"] == "build" : "Serializer/PayloadSerializers/UserLocationSerializer.cpp", "Serializer/PayloadSerializers/UserTuneSerializer.cpp", "Serializer/PayloadSerializers/WhiteboardSerializer.cpp", + "Serializer/PayloadSerializers/ResultSetSerializer.cpp", + "Serializer/PayloadSerializers/ForwardedSerializer.cpp", + "Serializer/PayloadSerializers/MAMResultSerializer.cpp", + "Serializer/PayloadSerializers/MAMQuerySerializer.cpp", + "Serializer/PayloadSerializers/MAMArchivedSerializer.cpp", "Serializer/PresenceSerializer.cpp", "Serializer/StanzaSerializer.cpp", "Serializer/StreamErrorSerializer.cpp", @@ -407,6 +417,11 @@ if env["SCONS_STAGE"] == "build" : File("Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/IdleParserTest.cpp"), + File("Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp"), + File("Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp"), + File("Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp"), + File("Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp"), + File("Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp"), File("Parser/UnitTest/BOSHBodyExtractorTest.cpp"), File("Parser/UnitTest/AttributeMapTest.cpp"), File("Parser/UnitTest/EnumParserTest.cpp"), @@ -459,6 +474,11 @@ if env["SCONS_STAGE"] == "build" : File("Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/IdleSerializerTest.cpp"), + File("Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp"), + File("Serializer/PayloadSerializers/UnitTest/ForwardedSerializerTest.cpp"), + File("Serializer/PayloadSerializers/UnitTest/MAMResultSerializerTest.cpp"), + File("Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp"), + File("Serializer/PayloadSerializers/UnitTest/MAMArchivedSerializerTest.cpp"), File("Serializer/UnitTest/StreamFeaturesSerializerTest.cpp"), File("Serializer/UnitTest/AuthSuccessSerializerTest.cpp"), File("Serializer/UnitTest/AuthChallengeSerializerTest.cpp"), diff --git a/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp b/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp index 6148632..f809798 100644 --- a/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp @@ -20,7 +20,7 @@ DelaySerializer::DelaySerializer() : GenericPayloadSerializer() { std::string DelaySerializer::serializePayload(boost::shared_ptr delay) const { XMLElement delayElement("delay", "urn:xmpp:delay"); - if (delay->getFrom()) { + if (delay->getFrom() && delay->getFrom()->isValid()) { delayElement.setAttribute("from", delay->getFrom()->toString()); } delayElement.setAttribute("stamp", dateTimeToString(delay->getStamp())); diff --git a/Swiften/Serializer/PayloadSerializers/ForwardedSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ForwardedSerializer.cpp new file mode 100644 index 0000000..767d9de --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ForwardedSerializer.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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +using namespace Swift; + +ForwardedSerializer::ForwardedSerializer(PayloadSerializerCollection* serializers) : serializers_(serializers) { +} + +ForwardedSerializer::~ForwardedSerializer() { +} + +std::string ForwardedSerializer::serializePayload(boost::shared_ptr payload) const { + if (!payload) { + return ""; + } + + XMLElement element("forwarded", "urn:xmpp:forward:0"); + + if (payload->getDelay()) { + element.addNode(boost::make_shared(DelaySerializer().serialize(payload->getDelay()))); + } + + if (payload->getStanza()) { /* find out what type of stanza we are dealing with and branch into the correct serializer*/ + boost::shared_ptr iq; + boost::shared_ptr message; + boost::shared_ptr presence; + const std::string ns = "jabber:client"; + if ((iq = boost::dynamic_pointer_cast(payload->getStanza()))) { + element.addNode(boost::make_shared(safeByteArrayToString(IQSerializer(serializers_).serialize(iq, ns)))); + } else if ((message = boost::dynamic_pointer_cast(payload->getStanza()))) { + element.addNode(boost::make_shared(safeByteArrayToString(MessageSerializer(serializers_).serialize(message, ns)))); + } else if ((presence = boost::dynamic_pointer_cast(payload->getStanza()))) { + element.addNode(boost::make_shared(safeByteArrayToString(PresenceSerializer(serializers_).serialize(presence, ns)))); + } + } + + return element.serialize(); +} diff --git a/Swiften/Serializer/PayloadSerializers/ForwardedSerializer.h b/Swiften/Serializer/PayloadSerializers/ForwardedSerializer.h new file mode 100644 index 0000000..4b283e2 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ForwardedSerializer.h @@ -0,0 +1,28 @@ +/* + * 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 +#include +#include +#include +#include + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API ForwardedSerializer : public GenericPayloadSerializer { + public: + ForwardedSerializer(PayloadSerializerCollection* serializers); + virtual ~ForwardedSerializer(); + + virtual std::string serializePayload(boost::shared_ptr) const SWIFTEN_OVERRIDE; + + private: + PayloadSerializerCollection* serializers_; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.cpp new file mode 100644 index 0000000..04a6584 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.cpp @@ -0,0 +1,32 @@ +/* + * 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 +#include +#include +#include +#include +#include + +using namespace Swift; + +MAMArchivedSerializer::MAMArchivedSerializer(PayloadSerializerCollection* serializers) : serializers_(serializers) { +} + +MAMArchivedSerializer::~MAMArchivedSerializer() { +} + +std::string MAMArchivedSerializer::serializePayload(boost::shared_ptr payload) const { + if (!payload) { + return ""; + } + + XMLElement element("archived", "urn:xmpp:mam:0"); + element.setAttribute("by", payload->getBy()); + element.setAttribute("id", payload->getID()); + + return element.serialize(); +} diff --git a/Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.h b/Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.h new file mode 100644 index 0000000..7c60798 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.h @@ -0,0 +1,28 @@ +/* + * 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 +#include +#include +#include +#include + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API MAMArchivedSerializer : public GenericPayloadSerializer { + public: + MAMArchivedSerializer(PayloadSerializerCollection* serializers); + virtual ~MAMArchivedSerializer(); + + virtual std::string serializePayload(boost::shared_ptr) const SWIFTEN_OVERRIDE; + + private: + PayloadSerializerCollection* serializers_; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/MAMQuerySerializer.cpp b/Swiften/Serializer/PayloadSerializers/MAMQuerySerializer.cpp new file mode 100644 index 0000000..1151fba --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MAMQuerySerializer.cpp @@ -0,0 +1,45 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Swift; + +MAMQuerySerializer::MAMQuerySerializer(PayloadSerializerCollection* serializers) : serializers_(serializers) { +} + +MAMQuerySerializer::~MAMQuerySerializer() { +} + +std::string MAMQuerySerializer::serializePayload(boost::shared_ptr payload) const { + if (!payload) { + return ""; + } + + XMLElement element("query", "urn:xmpp:mam:0"); + + if (payload->getQueryID()) { + element.setAttribute("queryid", *payload->getQueryID()); + } + + if (payload->getForm()) { + element.addNode(boost::make_shared(FormSerializer().serialize(payload->getForm()))); + } + + if (payload->getResultSet()) { + element.addNode(boost::make_shared(ResultSetSerializer().serialize(payload->getResultSet()))); + } + + return element.serialize(); +} diff --git a/Swiften/Serializer/PayloadSerializers/MAMQuerySerializer.h b/Swiften/Serializer/PayloadSerializers/MAMQuerySerializer.h new file mode 100644 index 0000000..a6d1339 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MAMQuerySerializer.h @@ -0,0 +1,28 @@ +/* + * 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 +#include +#include +#include +#include + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API MAMQuerySerializer : public GenericPayloadSerializer { + public: + MAMQuerySerializer(PayloadSerializerCollection* serializers); + virtual ~MAMQuerySerializer(); + + virtual std::string serializePayload(boost::shared_ptr) const SWIFTEN_OVERRIDE; + + private: + PayloadSerializerCollection* serializers_; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/MAMResultSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MAMResultSerializer.cpp new file mode 100644 index 0000000..c4fd4a5 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MAMResultSerializer.cpp @@ -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. + */ + +#include +#include +#include +#include +#include +#include +#include + +using namespace Swift; + +MAMResultSerializer::MAMResultSerializer(PayloadSerializerCollection* serializers) : serializers_(serializers) { +} + +MAMResultSerializer::~MAMResultSerializer() { +} + +std::string MAMResultSerializer::serializePayload(boost::shared_ptr payload) const { + if (!payload) { + return ""; + } + + XMLElement element("result", "urn:xmpp:mam:0"); + + element.setAttribute("id", payload->getID()); + + if (payload->getQueryID()) { + element.setAttribute("queryid", *payload->getQueryID()); + } + + element.addNode(boost::make_shared(ForwardedSerializer(serializers_).serialize(payload->getPayload()))); + + return element.serialize(); +} diff --git a/Swiften/Serializer/PayloadSerializers/MAMResultSerializer.h b/Swiften/Serializer/PayloadSerializers/MAMResultSerializer.h new file mode 100644 index 0000000..bb0c326 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MAMResultSerializer.h @@ -0,0 +1,28 @@ +/* + * 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 +#include +#include +#include +#include + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API MAMResultSerializer : public GenericPayloadSerializer { + public: + MAMResultSerializer(PayloadSerializerCollection* serializers); + virtual ~MAMResultSerializer(); + + virtual std::string serializePayload(boost::shared_ptr) const SWIFTEN_OVERRIDE; + + private: + PayloadSerializerCollection* serializers_; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp new file mode 100644 index 0000000..86d8830 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp @@ -0,0 +1,53 @@ +/* + * 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 +#include +#include +#include +#include + +using namespace Swift; + +ResultSetSerializer::ResultSetSerializer() { +} + +ResultSetSerializer::~ResultSetSerializer() { +} + +std::string ResultSetSerializer::serializePayload(boost::shared_ptr payload) const { + if (!payload) { + return ""; + } + + XMLElement element("set", "http://jabber.org/protocol/rsm"); + + if (payload->getMaxItems()) { + element.addNode(boost::make_shared("max", "", boost::lexical_cast(*payload->getMaxItems()))); + } + + if (payload->getCount()) { + element.addNode(boost::make_shared("count", "", boost::lexical_cast(*payload->getCount()))); + } + + if (payload->getFirstID()) { + boost::shared_ptr firstElement = boost::make_shared("first", "", *payload->getFirstID()); + if (payload->getFirstIDIndex()) { + firstElement->setAttribute("index", boost::lexical_cast(*payload->getFirstIDIndex())); + } + element.addNode(firstElement); + } + + if (payload->getLastID()) { + element.addNode(boost::make_shared("last", "", *payload->getLastID())); + } + + if (payload->getAfter()) { + element.addNode(boost::make_shared("after", "", *payload->getAfter())); + } + + return element.serialize(); +} diff --git a/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.h b/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.h new file mode 100644 index 0000000..1d476e2 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.h @@ -0,0 +1,25 @@ +/* + * 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 +#include +#include +#include +#include + +namespace Swift { + class PayloadSerializerCollection; + + class SWIFTEN_API ResultSetSerializer : public GenericPayloadSerializer { + public: + ResultSetSerializer(); + virtual ~ResultSetSerializer(); + + virtual std::string serializePayload(boost::shared_ptr) const SWIFTEN_OVERRIDE; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ForwardedSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ForwardedSerializerTest.cpp new file mode 100644 index 0000000..8af1672 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ForwardedSerializerTest.cpp @@ -0,0 +1,119 @@ +/* + * 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Swift; + +class ForwardedSerializerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(ForwardedSerializerTest); + CPPUNIT_TEST(testSerializeIQ); + CPPUNIT_TEST(testSerializeMessage); + CPPUNIT_TEST(testSerializeMessageNoDelay); + CPPUNIT_TEST(testSerializePresence); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerializeIQ() { + ForwardedSerializer serializer(&serializers); + + boost::shared_ptr iq = IQ::createResult(JID("juliet@capulet.lit/balcony"), JID("romeo@montague.lit/orchard"), "id0"); + + boost::shared_ptr forwarded(boost::make_shared()); + forwarded->setStanza(iq); + forwarded->setDelay(boost::make_shared(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); + + std::string expectedResult = + "" + "" + "" + ""; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); + } + + void testSerializeMessage() { + ForwardedSerializer serializer(&serializers); + + boost::shared_ptr message(boost::make_shared()); + message->setType(Message::Chat); + message->setTo(JID("juliet@capulet.lit/balcony")); + message->setFrom(JID("romeo@montague.lit/orchard")); + message->setBody("Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."); + + boost::shared_ptr forwarded(boost::make_shared()); + forwarded->setStanza(message); + forwarded->setDelay(boost::make_shared(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); + + std::string expectedResult = + "" + "" + "" + "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo." + "" + ""; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); + } + + void testSerializeMessageNoDelay() { + ForwardedSerializer serializer(&serializers); + + boost::shared_ptr message(boost::make_shared()); + message->setType(Message::Chat); + message->setTo(JID("juliet@capulet.lit/balcony")); + message->setFrom(JID("romeo@montague.lit/orchard")); + message->setBody("Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."); + + boost::shared_ptr forwarded(boost::make_shared()); + forwarded->setStanza(message); + + std::string expectedResult = + "" + "" + "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo." + "" + ""; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); + } + + void testSerializePresence() { + ForwardedSerializer serializer(&serializers); + + boost::shared_ptr presence(boost::make_shared()); + presence->setType(Presence::Subscribe); + + boost::shared_ptr forwarded(boost::make_shared()); + forwarded->setStanza(presence); + forwarded->setDelay(boost::make_shared(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); + + std::string expectedResult = + "" + "" + "" + ""; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); + } + + private: + FullPayloadSerializerCollection serializers; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ForwardedSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MAMArchivedSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMArchivedSerializerTest.cpp new file mode 100644 index 0000000..b174d32 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMArchivedSerializerTest.cpp @@ -0,0 +1,41 @@ +/* + * 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 + +#include +#include + +#include +#include +#include + +using namespace Swift; + +class MAMArchivedSerializerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(MAMArchivedSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerialize() { + MAMArchivedSerializer serializer(&serializers); + + boost::shared_ptr archived(boost::make_shared()); + archived->setBy("juliet@capulet.lit"); + archived->setID("28482-98726-73623"); + + std::string expectedResult = + ""; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(archived)); + } + + private: + FullPayloadSerializerCollection serializers; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(MAMArchivedSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp new file mode 100644 index 0000000..cc49be1 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.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 + +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace Swift; + +class MAMQuerySerializerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(MAMQuerySerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerialize() { + MAMQuerySerializer serializer(&serializers); + + boost::shared_ptr parameters(boost::make_shared()); + + boost::shared_ptr fieldType = boost::make_shared(FormField::TextSingleType); + fieldType->setName("FORM_TYPE"); + fieldType->addValue("urn:xmpp:mam:0"); + parameters->addField(fieldType); + + boost::shared_ptr fieldStart = boost::make_shared(FormField::TextSingleType); + fieldStart->setName("start"); + fieldStart->addValue("2010-08-07T00:00:00Z"); + parameters->addField(fieldStart); + + boost::shared_ptr set = boost::make_shared(); + set->setMaxItems(10); + + boost::shared_ptr query(boost::make_shared()); + query->setQueryID(std::string("id0")); + query->setForm(parameters); + query->setResultSet(set); + + std::string expectedResult = + "" + "" + "" + "urn:xmpp:mam:0" + "" + "" + "2010-08-07T00:00:00Z" + "" + "" + "" + "10" + "" + ""; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(query)); + } + + private: + FullPayloadSerializerCollection serializers; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(MAMQuerySerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MAMResultSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMResultSerializerTest.cpp new file mode 100644 index 0000000..2060c97 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMResultSerializerTest.cpp @@ -0,0 +1,62 @@ +/* + * 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 + +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace Swift; + +class MAMResultSerializerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(MAMResultSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerialize() { + MAMResultSerializer serializer(&serializers); + + boost::shared_ptr message(boost::make_shared()); + message->setType(Message::Chat); + message->setTo(JID("juliet@capulet.lit/balcony")); + message->setFrom(JID("romeo@montague.lit/orchard")); + message->setBody("Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."); + + boost::shared_ptr forwarded(boost::make_shared()); + forwarded->setStanza(message); + forwarded->setDelay(boost::make_shared(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); + + boost::shared_ptr result(boost::make_shared()); + result->setID("28482-98726-73623"); + result->setQueryID(std::string("f27")); + result->setPayload(forwarded); + + std::string expectedResult = + "" + "" + "" + "" + "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo." + "" + "" + ""; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(result)); + } + + private: + FullPayloadSerializerCollection serializers; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(MAMResultSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp new file mode 100644 index 0000000..641b856 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp @@ -0,0 +1,98 @@ +/* + * 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 + +#include +#include + +#include +#include +#include + +using namespace Swift; + +class ResultSetSerializerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(ResultSetSerializerTest); + CPPUNIT_TEST(testSerializeFull); + CPPUNIT_TEST(testSerializeMaxItems); + CPPUNIT_TEST(testSerializeFirst); + CPPUNIT_TEST(testSerializeFirstWithIndex); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerializeFull() { + ResultSetSerializer serializer; + + boost::shared_ptr resultSet(boost::make_shared()); + + resultSet->setMaxItems(100); + resultSet->setCount(800); + resultSet->setFirstIDIndex(123); + resultSet->setFirstID(std::string("stpeter@jabber.org")); + resultSet->setLastID(std::string("peterpan@neverland.lit")); + resultSet->setAfter(std::string("09af3-cc343-b409f")); + + std::string expectedResult = + "" + "100" + "800" + "stpeter@jabber.org" + "peterpan@neverland.lit" + "09af3-cc343-b409f" + ""; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); + } + + void testSerializeMaxItems() { + ResultSetSerializer serializer; + + boost::shared_ptr resultSet(boost::make_shared()); + + resultSet->setMaxItems(100); + + std::string expectedResult = + "" + "100" + ""; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); + } + + void testSerializeFirst() { + ResultSetSerializer serializer; + + boost::shared_ptr resultSet(boost::make_shared()); + + resultSet->setFirstID(std::string("stpeter@jabber.org")); + + std::string expectedResult = + "" + "stpeter@jabber.org" + ""; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); + } + + void testSerializeFirstWithIndex() { + ResultSetSerializer serializer; + + boost::shared_ptr resultSet(boost::make_shared()); + + resultSet->setFirstID(std::string("stpeter@jabber.org")); + resultSet->setFirstIDIndex(123); + + std::string expectedResult = + "" + "stpeter@jabber.org" + ""; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ResultSetSerializerTest); diff --git a/Swiften/Serializer/StanzaSerializer.cpp b/Swiften/Serializer/StanzaSerializer.cpp index 9a4fd2c..b5f0b22 100644 --- a/Swiften/Serializer/StanzaSerializer.cpp +++ b/Swiften/Serializer/StanzaSerializer.cpp @@ -1,5 +1,5 @@ /* - * 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,9 +23,13 @@ StanzaSerializer::StanzaSerializer(const std::string& tag, PayloadSerializerColl } SafeByteArray StanzaSerializer::serialize(boost::shared_ptr element) const { + return serialize(element, ""); +} + +SafeByteArray StanzaSerializer::serialize(boost::shared_ptr element, const std::string& xmlns) const { boost::shared_ptr stanza(boost::dynamic_pointer_cast(element)); - XMLElement stanzaElement(tag_); + XMLElement stanzaElement(tag_, xmlns); if (stanza->getFrom().isValid()) { stanzaElement.setAttribute("from", stanza->getFrom()); } diff --git a/Swiften/Serializer/StanzaSerializer.h b/Swiften/Serializer/StanzaSerializer.h index db18aa2..d569d82 100644 --- a/Swiften/Serializer/StanzaSerializer.h +++ b/Swiften/Serializer/StanzaSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2013-2014 Kevin Smith and Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -18,7 +18,8 @@ namespace Swift { public: StanzaSerializer(const std::string& tag, PayloadSerializerCollection* payloadSerializers); - virtual SafeByteArray serialize(boost::shared_ptr) const; + virtual SafeByteArray serialize(boost::shared_ptr element) const; + virtual SafeByteArray serialize(boost::shared_ptr element, const std::string& xmlns) const; virtual void setStanzaSpecificAttributes(boost::shared_ptr, XMLElement&) const = 0; private: -- cgit v0.10.2-6-g49f6