From 8096f80861667381b777af774cfd446d6fc8cda8 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Fri, 24 Oct 2014 11:57:13 +0200 Subject: Brining XEP-0313 (MAM) implementation in line with version 3.0. Added support for element, including serializer/parsers and unit tests for them. Added more unit tests based on XEP examples for existing parsers. Removed unneccesarry includes from existing MAM implementation. Test-Information: Existing and new unit tests pass successfully. Change-Id: I7e6bf85e0961d59801b452e4559cc1db9e9e6ed8 diff --git a/Sluift/ElementConvertors/MAMArchivedConvertor.cpp b/Sluift/ElementConvertors/MAMArchivedConvertor.cpp deleted file mode 100644 index 39ac7df..0000000 --- a/Sluift/ElementConvertors/MAMArchivedConvertor.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 - -#pragma clang diagnostic ignored "-Wunused-private-field" - -using namespace Swift; - -MAMArchivedConvertor::MAMArchivedConvertor(LuaElementConvertors* convertors) : - GenericLuaElementConvertor("mam_archived"), - convertors(convertors) { -} - -MAMArchivedConvertor::~MAMArchivedConvertor() { -} - -boost::shared_ptr MAMArchivedConvertor::doConvertFromLua(lua_State* L) { - boost::shared_ptr result = boost::make_shared(); - lua_getfield(L, -1, "by"); - if (lua_isstring(L, -1)) { - result->setBy(JID(std::string(lua_tostring(L, -1)))); - } - lua_pop(L, 1); - lua_getfield(L, -1, "id"); - if (lua_isstring(L, -1)) { - result->setID(std::string(lua_tostring(L, -1))); - } - lua_pop(L, 1); - return result; -} - -void MAMArchivedConvertor::doConvertToLua(lua_State* L, boost::shared_ptr payload) { - lua_createtable(L, 0, 0); - lua_pushstring(L, payload->getBy().toString().c_str()); - lua_setfield(L, -2, "by"); - lua_pushstring(L, payload->getID().c_str()); - lua_setfield(L, -2, "id"); -} - -boost::optional MAMArchivedConvertor::getDocumentation() const { - return Documentation( - "MAMArchived", - "This table has the following fields:\n\n" - "- `by`: string\n" - "- `id`: string\n" - ); -} diff --git a/Sluift/ElementConvertors/MAMArchivedConvertor.h b/Sluift/ElementConvertors/MAMArchivedConvertor.h deleted file mode 100644 index 9d95e4a..0000000 --- a/Sluift/ElementConvertors/MAMArchivedConvertor.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 LuaElementConvertors; - - class MAMArchivedConvertor : public GenericLuaElementConvertor { - public: - MAMArchivedConvertor(LuaElementConvertors* convertors); - virtual ~MAMArchivedConvertor(); - - virtual boost::shared_ptr doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE; - virtual void doConvertToLua(lua_State*, boost::shared_ptr) SWIFTEN_OVERRIDE; - virtual boost::optional getDocumentation() const SWIFTEN_OVERRIDE; - - private: - LuaElementConvertors* convertors; - }; -} - diff --git a/Sluift/ElementConvertors/SConscript b/Sluift/ElementConvertors/SConscript index 5ff5379..33d40ab 100644 --- a/Sluift/ElementConvertors/SConscript +++ b/Sluift/ElementConvertors/SConscript @@ -47,7 +47,6 @@ convertors = [ env.File("ForwardedConvertor.cpp"), env.File("MAMResultConvertor.cpp"), env.File("MAMQueryConvertor.cpp"), - env.File("MAMArchivedConvertor.cpp"), env.File("SubjectConvertor.cpp"), env.File("IsodeIQDelegationConvertor.cpp") ] diff --git a/Sluift/LuaElementConvertors.cpp b/Sluift/LuaElementConvertors.cpp index 253a820..d2af664 100644 --- a/Sluift/LuaElementConvertors.cpp +++ b/Sluift/LuaElementConvertors.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -61,7 +60,6 @@ LuaElementConvertors::LuaElementConvertors() { convertors.push_back(boost::make_shared(this)); convertors.push_back(boost::make_shared(this)); convertors.push_back(boost::make_shared(this)); - convertors.push_back(boost::make_shared(this)); convertors.push_back(boost::make_shared()); convertors.push_back(boost::make_shared()); convertors.push_back(boost::make_shared()); diff --git a/Swiften/Elements/MAMArchived.cpp b/Swiften/Elements/MAMArchived.cpp deleted file mode 100644 index 4ec5750..0000000 --- a/Swiften/Elements/MAMArchived.cpp +++ /dev/null @@ -1,12 +0,0 @@ -/* - * 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 deleted file mode 100644 index df83427..0000000 --- a/Swiften/Elements/MAMArchived.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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/MAMFin.cpp b/Swiften/Elements/MAMFin.cpp new file mode 100644 index 0000000..163ee05 --- /dev/null +++ b/Swiften/Elements/MAMFin.cpp @@ -0,0 +1,14 @@ +/* + * 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 + +namespace Swift { + +MAMFin::~MAMFin() { +} + +} diff --git a/Swiften/Elements/MAMFin.h b/Swiften/Elements/MAMFin.h new file mode 100644 index 0000000..5393230 --- /dev/null +++ b/Swiften/Elements/MAMFin.h @@ -0,0 +1,63 @@ +/* + * 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 + +namespace Swift { + class SWIFTEN_API MAMFin : public Payload { + public: + MAMFin() : isComplete_(false), isStable_(true) {} + virtual ~MAMFin(); + + void setComplete(const bool isComplete) { + isComplete_ = isComplete; + } + + bool isComplete() const { + return isComplete_; + } + + void setStable(const bool isStable) { + isStable_ = isStable; + } + + bool isStable() const { + return isStable_; + } + + void setResultSet(boost::shared_ptr resultSet) { + resultSet_ = resultSet; + } + + boost::shared_ptr getResultSet() const { + return resultSet_; + } + + void setQueryID(const std::string& queryID) { + queryID_ = queryID; + } + + const boost::optional& getQueryID() const { + return queryID_; + } + + + private: + bool isComplete_; + bool isStable_; + boost::shared_ptr resultSet_; + boost::optional queryID_; + }; +} diff --git a/Swiften/Elements/MAMQuery.h b/Swiften/Elements/MAMQuery.h index 3f3724e..09b5af0 100644 --- a/Swiften/Elements/MAMQuery.h +++ b/Swiften/Elements/MAMQuery.h @@ -6,11 +6,13 @@ #pragma once +#include + +#include #include + #include #include -#include -#include #include #include diff --git a/Swiften/Elements/MAMResult.h b/Swiften/Elements/MAMResult.h index 7d43902..17c7527 100644 --- a/Swiften/Elements/MAMResult.h +++ b/Swiften/Elements/MAMResult.h @@ -6,7 +6,10 @@ #pragma once +#include + #include + #include #include #include diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 49dd1e3..de7386b 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include #include #include @@ -157,7 +157,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { 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")); + factories_.push_back(boost::make_shared >("fin", "urn:xmpp:mam:0")); factories_.push_back(boost::make_shared >("delegate", "http://isode.com/iq_delegation", this)); foreach(shared_ptr factory, factories_) { diff --git a/Swiften/Parser/PayloadParsers/MAMArchivedParser.cpp b/Swiften/Parser/PayloadParsers/MAMArchivedParser.cpp deleted file mode 100644 index 616d41a..0000000 --- a/Swiften/Parser/PayloadParsers/MAMArchivedParser.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 deleted file mode 100644 index b92b41a..0000000 --- a/Swiften/Parser/PayloadParsers/MAMArchivedParser.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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/MAMFinParser.cpp b/Swiften/Parser/PayloadParsers/MAMFinParser.cpp new file mode 100644 index 0000000..cab493b --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMFinParser.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; + +MAMFinParser::MAMFinParser() : level_(TopLevel) { +} + +void MAMFinParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level_ == TopLevel) { + getPayloadInternal()->setComplete(attributes.getBoolAttribute("complete", false)); + getPayloadInternal()->setStable(attributes.getBoolAttribute("stable", true)); + boost::optional attributeValue; + if ((attributeValue = attributes.getAttributeValue("queryid"))) { + getPayloadInternal()->setQueryID(*attributeValue); + } + } + else if (level_ == PayloadLevel) { + if (element == "set" && ns == "http://jabber.org/protocol/rsm") { + resultSetParser_ = boost::make_shared(); + } + } + + if (resultSetParser_) { /* parsing a nested ResultSet */ + resultSetParser_->handleStartElement(element, ns, attributes); + } + + ++level_; +} + +void MAMFinParser::handleEndElement(const std::string& element, const std::string& ns) { + --level_; + + if (resultSetParser_ && level_ >= PayloadLevel) { + resultSetParser_->handleEndElement(element, ns); + } + if (resultSetParser_ && level_ == PayloadLevel) { + /* done parsing nested ResultSet */ + getPayloadInternal()->setResultSet(boost::dynamic_pointer_cast(resultSetParser_->getPayload())); + resultSetParser_.reset(); + } +} + +void MAMFinParser::handleCharacterData(const std::string& data) { + if (resultSetParser_) { + resultSetParser_->handleCharacterData(data); + } +} diff --git a/Swiften/Parser/PayloadParsers/MAMFinParser.h b/Swiften/Parser/PayloadParsers/MAMFinParser.h new file mode 100644 index 0000000..08a7f16 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MAMFinParser.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 ResultSetParser; + + class SWIFTEN_API MAMFinParser : public GenericPayloadParser { + public: + MAMFinParser(); + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) SWIFTEN_OVERRIDE; + virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE; + virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE; + + enum Level { + TopLevel = 0, + PayloadLevel = 1 + }; + + private: + boost::shared_ptr resultSetParser_; + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp index 9ae8e41..6b3dc65 100644 --- a/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp +++ b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp @@ -7,8 +7,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/Swiften/Parser/PayloadParsers/MAMQueryParser.h b/Swiften/Parser/PayloadParsers/MAMQueryParser.h index 7bbdacb..d160926 100644 --- a/Swiften/Parser/PayloadParsers/MAMQueryParser.h +++ b/Swiften/Parser/PayloadParsers/MAMQueryParser.h @@ -6,6 +6,8 @@ #pragma once +#include + #include #include @@ -14,7 +16,6 @@ #include namespace Swift { - class PayloadParserFactoryCollection; class ResultSetParser; class FormParser; diff --git a/Swiften/Parser/PayloadParsers/MAMResultParser.cpp b/Swiften/Parser/PayloadParsers/MAMResultParser.cpp index e4eec3b..55db8ad 100644 --- a/Swiften/Parser/PayloadParsers/MAMResultParser.cpp +++ b/Swiften/Parser/PayloadParsers/MAMResultParser.cpp @@ -6,9 +6,8 @@ #include #include + #include -#include -#include #include #include diff --git a/Swiften/Parser/PayloadParsers/MAMResultParser.h b/Swiften/Parser/PayloadParsers/MAMResultParser.h index 39ff20a..cb58732 100644 --- a/Swiften/Parser/PayloadParsers/MAMResultParser.h +++ b/Swiften/Parser/PayloadParsers/MAMResultParser.h @@ -6,6 +6,8 @@ #pragma once +#include + #include #include diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp deleted file mode 100644 index 3e65cc6..0000000 --- a/Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/MAMFinParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp new file mode 100644 index 0000000..3f7cdc9 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.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 + +using namespace Swift; + +class MAMFinParserTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(MAMFinParserTest); + CPPUNIT_TEST(testParse_XEP0313_Exmaple1); + CPPUNIT_TEST(testParse_XEP0313_Exmaple9); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse_XEP0313_Exmaple1() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "")); + + boost::shared_ptr payload = parser.getPayload(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT_EQUAL(false, payload->isComplete()); + CPPUNIT_ASSERT_EQUAL(true, payload->isStable()); + + boost::optional queryID = payload->getQueryID(); + CPPUNIT_ASSERT(queryID); + CPPUNIT_ASSERT_EQUAL(std::string("f27"), queryID.get()); + } + + void testParse_XEP0313_Exmaple9() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "" + "" + "23452-4534-1" + "390-2342-22" + "16" + "" + "")); + + boost::shared_ptr payload = parser.getPayload(); + CPPUNIT_ASSERT(!!payload); + CPPUNIT_ASSERT_EQUAL(true, payload->isComplete()); + CPPUNIT_ASSERT_EQUAL(true, payload->isStable()); + + CPPUNIT_ASSERT(!!payload->getResultSet()); + boost::shared_ptr resultSet = payload->getResultSet(); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(MAMFinParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp index ddcd7c4..e1c8e3e 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp @@ -17,6 +17,8 @@ class MAMQueryParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(MAMQueryParserTest); CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_XEP0313_Example3); + CPPUNIT_TEST(testParse_XEP0313_Example4); CPPUNIT_TEST(testParseEmpty); CPPUNIT_TEST_SUITE_END(); @@ -58,6 +60,49 @@ class MAMQueryParserTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL(*resultSet->getMaxItems(), 10); } + void testParse_XEP0313_Example3() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "" + "" + "" + "urn:xmpp:mam:0" + "" + "" + "juliet@capulet.lit" + "" + "" + "")); + + boost::shared_ptr payload = parser.getPayload(); + CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("with")); + CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue()); + CPPUNIT_ASSERT_EQUAL(std::string("juliet@capulet.lit"), payload->getForm()->getField("with")->getTextSingleValue()); + } + + void testParse_XEP0313_Example4() { + PayloadsParserTester parser; + CPPUNIT_ASSERT(parser.parse( + "" + "" + "" + "urn:xmpp:mam:0" + "" + "" + "2010-06-07T00:00:00Z" + "" + "" + "2010-07-07T13:23:54Z" + "" + "" + "")); + boost::shared_ptr payload = parser.getPayload(); + CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("start") && !!payload->getForm()->getField("start")); + CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-06-07T00:00:00Z"), payload->getForm()->getField("start")->getTextSingleValue()); + CPPUNIT_ASSERT_EQUAL(std::string("2010-07-07T13:23:54Z"), payload->getForm()->getField("end")->getTextSingleValue()); + } + void testParseEmpty() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( @@ -71,6 +116,8 @@ class MAMQueryParserTest : public CppUnit::TestFixture CPPUNIT_ASSERT(!payload->getForm()); CPPUNIT_ASSERT(!payload->getResultSet()); } + + }; CPPUNIT_TEST_SUITE_REGISTRATION(MAMQueryParserTest); diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index e748320..94ea6d3 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -79,9 +79,9 @@ sources = [ "PayloadParsers/PubSubErrorParserFactory.cpp", "PayloadParsers/ResultSetParser.cpp", "PayloadParsers/ForwardedParser.cpp", + "PayloadParsers/MAMFinParser.cpp", "PayloadParsers/MAMResultParser.cpp", "PayloadParsers/MAMQueryParser.cpp", - "PayloadParsers/MAMArchivedParser.cpp", "PayloadParsers/IsodeIQDelegationParser.cpp", "PlatformXMLParserFactory.cpp", "PresenceParser.cpp", diff --git a/Swiften/SConscript b/Swiften/SConscript index 29298ca..877b084 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -149,7 +149,7 @@ if env["SCONS_STAGE"] == "build" : "Elements/Forwarded.cpp", "Elements/MAMResult.cpp", "Elements/MAMQuery.cpp", - "Elements/MAMArchived.cpp", + "Elements/MAMFin.cpp", "Elements/IsodeIQDelegation.cpp", "Entity/Entity.cpp", "Entity/PayloadPersister.cpp", @@ -231,9 +231,9 @@ if env["SCONS_STAGE"] == "build" : "Serializer/PayloadSerializers/WhiteboardSerializer.cpp", "Serializer/PayloadSerializers/ResultSetSerializer.cpp", "Serializer/PayloadSerializers/ForwardedSerializer.cpp", + "Serializer/PayloadSerializers/MAMFinSerializer.cpp", "Serializer/PayloadSerializers/MAMResultSerializer.cpp", "Serializer/PayloadSerializers/MAMQuerySerializer.cpp", - "Serializer/PayloadSerializers/MAMArchivedSerializer.cpp", "Serializer/PayloadSerializers/IsodeIQDelegationSerializer.cpp", "Serializer/PresenceSerializer.cpp", "Serializer/StanzaSerializer.cpp", @@ -426,9 +426,9 @@ if env["SCONS_STAGE"] == "build" : File("Parser/PayloadParsers/UnitTest/IdleParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp"), + File("Parser/PayloadParsers/UnitTest/MAMFinParserTest.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"), @@ -483,9 +483,9 @@ if env["SCONS_STAGE"] == "build" : File("Serializer/PayloadSerializers/UnitTest/IdleSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/ForwardedSerializerTest.cpp"), + File("Serializer/PayloadSerializers/UnitTest/MAMFinSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/MAMResultSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp"), - File("Serializer/PayloadSerializers/UnitTest/MAMArchivedSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/PubSubItemSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/PubSubItemsSerializerTest.cpp"), File("Serializer/UnitTest/StreamFeaturesSerializerTest.cpp"), diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index dcfb4ed..33f288d 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -147,7 +146,6 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new ForwardedSerializer(this)); serializers_.push_back(new MAMResultSerializer(this)); serializers_.push_back(new MAMQuerySerializer()); - serializers_.push_back(new MAMArchivedSerializer()); serializers_.push_back(new IsodeIQDelegationSerializer(this)); foreach(PayloadSerializer* serializer, serializers_) { diff --git a/Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.cpp deleted file mode 100644 index 0a49a4b..0000000 --- a/Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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() { -} - -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 deleted file mode 100644 index 67fffcb..0000000 --- a/Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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(); - virtual ~MAMArchivedSerializer(); - - virtual std::string serializePayload(boost::shared_ptr) const SWIFTEN_OVERRIDE; - }; -} diff --git a/Swiften/Serializer/PayloadSerializers/MAMFinSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MAMFinSerializer.cpp new file mode 100644 index 0000000..8e4c2eb --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MAMFinSerializer.cpp @@ -0,0 +1,47 @@ +/* + * 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; + +MAMFinSerializer::MAMFinSerializer() { +} + +MAMFinSerializer::~MAMFinSerializer() { +} + +std::string MAMFinSerializer::serializePayload(boost::shared_ptr payload) const { + if (!payload) { + return ""; + } + + XMLElement element("fin", "urn:xmpp:mam:0"); + + if (payload->isComplete()) { + element.setAttribute("complete", "true"); + } + + if (!payload->isStable()) { + element.setAttribute("stable", "false"); + } + + if (payload->getQueryID()) { + element.setAttribute("queryid", *payload->getQueryID()); + } + + if (payload->getResultSet()) { + element.addNode(boost::make_shared(ResultSetSerializer().serialize(payload->getResultSet()))); + } + + return element.serialize(); +} diff --git a/Swiften/Serializer/PayloadSerializers/MAMFinSerializer.h b/Swiften/Serializer/PayloadSerializers/MAMFinSerializer.h new file mode 100644 index 0000000..e07bf46 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MAMFinSerializer.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 MAMFinSerializer : public GenericPayloadSerializer { + public: + MAMFinSerializer(); + virtual ~MAMFinSerializer(); + + virtual std::string serializePayload(boost::shared_ptr) const SWIFTEN_OVERRIDE; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MAMArchivedSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMArchivedSerializerTest.cpp deleted file mode 100644 index 2bd5c6a..0000000 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/MAMArchivedSerializerTest.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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; - - 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/MAMFinSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMFinSerializerTest.cpp new file mode 100644 index 0000000..372af97 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMFinSerializerTest.cpp @@ -0,0 +1,64 @@ +/* + * 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 MAMFinSerializerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(MAMFinSerializerTest); + CPPUNIT_TEST(testSerialize_XEP0313_Exmaple1); + CPPUNIT_TEST(testSerialize_XEP0313_Exmaple9); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerialize_XEP0313_Exmaple1() { + MAMFinSerializer serializer; + + boost::shared_ptr fin = boost::make_shared(); + fin->setQueryID("f27"); + + std::string expectedResult = + ""; + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(fin)); + } + + void testSerialize_XEP0313_Exmaple9() { + MAMFinSerializer serializer; + + boost::shared_ptr fin = boost::make_shared(); + fin->setComplete(true); + + boost::shared_ptr set = boost::make_shared(); + set->setFirstID(std::string("23452-4534-1")); + set->setFirstIDIndex(0); + set->setLastID(std::string("390-2342-22")); + set->setCount(16); + + fin->setResultSet(set); + + std::string expectedResult = + "" + "" + "16" + "23452-4534-1" + "390-2342-22" + "" + ""; + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(fin)); + } + + private: + FullPayloadSerializerCollection serializers; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(MAMFinSerializerTest); -- cgit v0.10.2-6-g49f6