summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Elements/MAMArchived.h29
-rw-r--r--Swiften/Elements/MAMFin.cpp (renamed from Swiften/Elements/MAMArchived.cpp)8
-rw-r--r--Swiften/Elements/MAMFin.h63
-rw-r--r--Swiften/Elements/MAMQuery.h6
-rw-r--r--Swiften/Elements/MAMResult.h3
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp4
-rw-r--r--Swiften/Parser/PayloadParsers/MAMArchivedParser.cpp38
-rw-r--r--Swiften/Parser/PayloadParsers/MAMFinParser.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/MAMFinParser.h (renamed from Swiften/Parser/PayloadParsers/MAMArchivedParser.h)12
-rw-r--r--Swiften/Parser/PayloadParsers/MAMQueryParser.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/MAMQueryParser.h3
-rw-r--r--Swiften/Parser/PayloadParsers/MAMResultParser.cpp3
-rw-r--r--Swiften/Parser/PayloadParsers/MAMResultParser.h2
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp35
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp47
-rw-r--r--Swiften/Parser/SConscript2
-rw-r--r--Swiften/SConscript8
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.cpp32
-rw-r--r--Swiften/Serializer/PayloadSerializers/MAMFinSerializer.cpp47
-rw-r--r--Swiften/Serializer/PayloadSerializers/MAMFinSerializer.h (renamed from Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.h)10
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/MAMArchivedSerializerTest.cpp41
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/MAMFinSerializerTest.cpp64
24 files changed, 375 insertions, 204 deletions
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 <boost/optional.hpp>
-#include <Swiften/Base/API.h>
-#include <Swiften/Elements/Payload.h>
-#include <Swiften/JID/JID.h>
-
-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/MAMArchived.cpp b/Swiften/Elements/MAMFin.cpp
index 4ec5750..163ee05 100644
--- a/Swiften/Elements/MAMArchived.cpp
+++ b/Swiften/Elements/MAMFin.cpp
@@ -4,9 +4,11 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include <Swiften/Elements/MAMArchived.h>
+#include <Swiften/Elements/MAMFin.h>
-using namespace Swift;
+namespace Swift {
+
+MAMFin::~MAMFin() {
+}
-MAMArchived::~MAMArchived() {
}
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 <string>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/optional.hpp>
+
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/Payload.h>
+#include <Swiften/Elements/ResultSet.h>
+
+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_ = resultSet;
+ }
+
+ boost::shared_ptr<ResultSet> getResultSet() const {
+ return resultSet_;
+ }
+
+ void setQueryID(const std::string& queryID) {
+ queryID_ = queryID;
+ }
+
+ const boost::optional<std::string>& getQueryID() const {
+ return queryID_;
+ }
+
+
+ private:
+ bool isComplete_;
+ bool isStable_;
+ boost::shared_ptr<ResultSet> resultSet_;
+ boost::optional<std::string> 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 <string>
+
+#include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
+
#include <Swiften/Base/API.h>
#include <Swiften/Elements/Form.h>
-#include <Swiften/Elements/Forwarded.h>
-#include <Swiften/Elements/MAMResult.h>
#include <Swiften/Elements/Payload.h>
#include <Swiften/Elements/ResultSet.h>
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 <string>
+
#include <boost/optional.hpp>
+
#include <Swiften/Base/API.h>
#include <Swiften/Elements/ContainerPayload.h>
#include <Swiften/Elements/Forwarded.h>
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 <Swiften/Parser/PayloadParsers/JingleReasonParser.h>
#include <Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/LastParser.h>
-#include <Swiften/Parser/PayloadParsers/MAMArchivedParser.h>
+#include <Swiften/Parser/PayloadParsers/MAMFinParser.h>
#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h>
#include <Swiften/Parser/PayloadParsers/MAMResultParser.h>
#include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h>
@@ -157,7 +157,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<ForwardedParser> >("forwarded", "urn:xmpp:forward:0", this));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<MAMResultParser> >("result", "urn:xmpp:mam:0", this));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMQueryParser> >("query", "urn:xmpp:mam:0"));
- factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMArchivedParser> >("archived", "urn:xmpp:mam:0"));
+ factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMFinParser> >("fin", "urn:xmpp:mam:0"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<IsodeIQDelegationParser> >("delegate", "http://isode.com/iq_delegation", this));
foreach(shared_ptr<PayloadParserFactory> factory, factories_) {
diff --git a/Swiften/Parser/PayloadParsers/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 <boost/lexical_cast.hpp>
-#include <boost/optional.hpp>
-#include <Swiften/Base/DateTime.h>
-#include <Swiften/Parser/PayloadParserFactory.h>
-#include <Swiften/Parser/PayloadParserFactoryCollection.h>
-#include <Swiften/Parser/PayloadParsers/MAMArchivedParser.h>
-
-using namespace Swift;
-
-MAMArchivedParser::MAMArchivedParser() : level_(TopLevel) {
-}
-
-void MAMArchivedParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) {
- if (level_ == TopLevel) {
- boost::optional<std::string> attributeValue;
- if ((attributeValue = attributes.getAttributeValue("by"))) {
- getPayloadInternal()->setBy(*attributeValue);
- }
- if ((attributeValue = attributes.getAttributeValue("id"))) {
- getPayloadInternal()->setID(*attributeValue);
- }
- }
-
- ++level_;
-}
-
-void MAMArchivedParser::handleEndElement(const std::string&, const std::string&) {
- --level_;
-}
-
-void MAMArchivedParser::handleCharacterData(const std::string&) {
-}
diff --git a/Swiften/Parser/PayloadParsers/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 <boost/lexical_cast.hpp>
+#include <boost/optional.hpp>
+#include <Swiften/Base/DateTime.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParsers/ResultSetParser.h>
+#include <Swiften/Parser/PayloadParsers/MAMFinParser.h>
+
+using namespace Swift;
+
+MAMFinParser::MAMFinParser() : level_(TopLevel) {
+}
+
+void MAMFinParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level_ == TopLevel) {
+ getPayloadInternal()->setComplete(attributes.getBoolAttribute("complete", false));
+ getPayloadInternal()->setStable(attributes.getBoolAttribute("stable", true));
+ boost::optional<std::string> attributeValue;
+ if ((attributeValue = attributes.getAttributeValue("queryid"))) {
+ getPayloadInternal()->setQueryID(*attributeValue);
+ }
+ }
+ else if (level_ == PayloadLevel) {
+ if (element == "set" && ns == "http://jabber.org/protocol/rsm") {
+ resultSetParser_ = boost::make_shared<ResultSetParser>();
+ }
+ }
+
+ if (resultSetParser_) { /* parsing a nested ResultSet */
+ resultSetParser_->handleStartElement(element, ns, attributes);
+ }
+
+ ++level_;
+}
+
+void MAMFinParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level_;
+
+ if (resultSetParser_ && level_ >= PayloadLevel) {
+ resultSetParser_->handleEndElement(element, ns);
+ }
+ if (resultSetParser_ && level_ == PayloadLevel) {
+ /* done parsing nested ResultSet */
+ getPayloadInternal()->setResultSet(boost::dynamic_pointer_cast<ResultSet>(resultSetParser_->getPayload()));
+ resultSetParser_.reset();
+ }
+}
+
+void MAMFinParser::handleCharacterData(const std::string& data) {
+ if (resultSetParser_) {
+ resultSetParser_->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/MAMArchivedParser.h b/Swiften/Parser/PayloadParsers/MAMFinParser.h
index b92b41a..08a7f16 100644
--- a/Swiften/Parser/PayloadParsers/MAMArchivedParser.h
+++ b/Swiften/Parser/PayloadParsers/MAMFinParser.h
@@ -10,25 +10,27 @@
#include <Swiften/Base/Override.h>
#include <Swiften/Base/API.h>
-#include <Swiften/Elements/MAMArchived.h>
#include <Swiften/Parser/GenericPayloadParser.h>
+#include <Swiften/Elements/MAMFin.h>
namespace Swift {
- class PayloadParserFactoryCollection;
+ class ResultSetParser;
- class SWIFTEN_API MAMArchivedParser : public GenericPayloadParser<MAMArchived> {
+ class SWIFTEN_API MAMFinParser : public GenericPayloadParser<MAMFin> {
public:
- MAMArchivedParser();
+ 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
+ TopLevel = 0,
+ PayloadLevel = 1
};
private:
+ boost::shared_ptr<ResultSetParser> 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 <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include <Swiften/Base/DateTime.h>
-#include <Swiften/Parser/PayloadParserFactory.h>
-#include <Swiften/Parser/PayloadParserFactoryCollection.h>
#include <Swiften/Parser/PayloadParsers/FormParser.h>
#include <Swiften/Parser/PayloadParsers/ResultSetParser.h>
#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h>
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 <string>
+
#include <boost/shared_ptr.hpp>
#include <Swiften/Base/Override.h>
@@ -14,7 +16,6 @@
#include <Swiften/Parser/GenericPayloadParser.h>
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 <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
+
#include <Swiften/Base/DateTime.h>
-#include <Swiften/Parser/PayloadParserFactory.h>
-#include <Swiften/Parser/PayloadParserFactoryCollection.h>
#include <Swiften/Parser/PayloadParsers/ForwardedParser.h>
#include <Swiften/Parser/PayloadParsers/MAMResultParser.h>
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 <string>
+
#include <boost/shared_ptr.hpp>
#include <Swiften/Base/Override.h>
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 <cppunit/extensions/HelperMacros.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-
-#include <Swiften/Base/DateTime.h>
-#include <Swiften/Parser/PayloadParsers/MAMArchivedParser.h>
-#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
-
-using namespace Swift;
-
-class MAMArchivedParserTest : public CppUnit::TestFixture
-{
- CPPUNIT_TEST_SUITE(MAMArchivedParserTest);
- CPPUNIT_TEST(testParse);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void testParse() {
- PayloadsParserTester parser;
- CPPUNIT_ASSERT(parser.parse(
- "<archived by=\"juliet@capulet.lit\" id=\"28482-98726-73623\" xmlns=\"urn:xmpp:mam:0\"/>"));
-
- boost::shared_ptr<MAMArchived> payload = parser.getPayload<MAMArchived>();
- CPPUNIT_ASSERT(!!payload);
- CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit"), payload->getBy());
- CPPUNIT_ASSERT_EQUAL(std::string("28482-98726-73623"), payload->getID());
- }
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(MAMArchivedParserTest);
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/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 <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Elements/MAMFin.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+class MAMFinParserTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(MAMFinParserTest);
+ CPPUNIT_TEST(testParse_XEP0313_Exmaple1);
+ CPPUNIT_TEST(testParse_XEP0313_Exmaple9);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testParse_XEP0313_Exmaple1() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<fin xmlns='urn:xmpp:mam:0' queryid='f27' />"));
+
+ boost::shared_ptr<MAMFin> payload = parser.getPayload<MAMFin>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT_EQUAL(false, payload->isComplete());
+ CPPUNIT_ASSERT_EQUAL(true, payload->isStable());
+
+ boost::optional<std::string> queryID = payload->getQueryID();
+ CPPUNIT_ASSERT(queryID);
+ CPPUNIT_ASSERT_EQUAL(std::string("f27"), queryID.get());
+ }
+
+ void testParse_XEP0313_Exmaple9() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<fin xmlns='urn:xmpp:mam:0' complete='true'>"
+ "<set xmlns='http://jabber.org/protocol/rsm'>"
+ "<first index='0'>23452-4534-1</first>"
+ "<last>390-2342-22</last>"
+ "<count>16</count>"
+ "</set>"
+ "</fin>"));
+
+ boost::shared_ptr<MAMFin> payload = parser.getPayload<MAMFin>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT_EQUAL(true, payload->isComplete());
+ CPPUNIT_ASSERT_EQUAL(true, payload->isStable());
+
+ CPPUNIT_ASSERT(!!payload->getResultSet());
+ boost::shared_ptr<ResultSet> resultSet = payload->getResultSet();
+ }
+};
+
+CPPUNIT_TEST_SUITE_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(
+ "<query xmlns='urn:xmpp:mam:0'>"
+ "<x xmlns='jabber:x:data'>"
+ "<field var='FORM_TYPE'>"
+ "<value>urn:xmpp:mam:0</value>"
+ "</field>"
+ "<field var='with'>"
+ "<value>juliet@capulet.lit</value>"
+ "</field>"
+ "</x>"
+ "</query>"));
+
+ boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>();
+ CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("with"));
+ CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue());
+ CPPUNIT_ASSERT_EQUAL(std::string("juliet@capulet.lit"), payload->getForm()->getField("with")->getTextSingleValue());
+ }
+
+ void testParse_XEP0313_Example4() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<query xmlns='urn:xmpp:mam:0'>"
+ "<x xmlns='jabber:x:data'>"
+ "<field var='FORM_TYPE'>"
+ "<value>urn:xmpp:mam:0</value>"
+ "</field>"
+ "<field var='start'>"
+ "<value>2010-06-07T00:00:00Z</value>"
+ "</field>"
+ "<field var='end'>"
+ "<value>2010-07-07T13:23:54Z</value>"
+ "</field>"
+ "</x>"
+ "</query>"));
+ boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>();
+ CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("start") && !!payload->getForm()->getField("start"));
+ CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue());
+ CPPUNIT_ASSERT_EQUAL(std::string("2010-06-07T00:00:00Z"), payload->getForm()->getField("start")->getTextSingleValue());
+ CPPUNIT_ASSERT_EQUAL(std::string("2010-07-07T13:23:54Z"), payload->getForm()->getField("end")->getTextSingleValue());
+ }
+
void testParseEmpty() {
PayloadsParserTester parser;
CPPUNIT_ASSERT(parser.parse(
@@ -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 <Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/LastSerializer.h>
-#include <Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MAMQuerySerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MAMResultSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h>
@@ -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 <boost/lexical_cast.hpp>
-#include <boost/smart_ptr/make_shared.hpp>
-#include <Swiften/Serializer/XML/XMLElement.h>
-#include <Swiften/Serializer/XML/XMLRawTextNode.h>
-#include <Swiften/Serializer/PayloadSerializerCollection.h>
-#include <Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.h>
-
-using namespace Swift;
-
-MAMArchivedSerializer::MAMArchivedSerializer() {
-}
-
-MAMArchivedSerializer::~MAMArchivedSerializer() {
-}
-
-std::string MAMArchivedSerializer::serializePayload(boost::shared_ptr<MAMArchived> 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/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 <boost/lexical_cast.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <Swiften/Serializer/XML/XMLElement.h>
+#include <Swiften/Serializer/XML/XMLRawTextNode.h>
+#include <Swiften/Serializer/PayloadSerializerCollection.h>
+#include <Swiften/Serializer/PayloadSerializers/MAMFinSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/ResultSetSerializer.h>
+
+using namespace Swift;
+
+MAMFinSerializer::MAMFinSerializer() {
+}
+
+MAMFinSerializer::~MAMFinSerializer() {
+}
+
+std::string MAMFinSerializer::serializePayload(boost::shared_ptr<MAMFin> 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<XMLRawTextNode>(ResultSetSerializer().serialize(payload->getResultSet())));
+ }
+
+ return element.serialize();
+}
diff --git a/Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.h b/Swiften/Serializer/PayloadSerializers/MAMFinSerializer.h
index 67fffcb..e07bf46 100644
--- a/Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.h
+++ b/Swiften/Serializer/PayloadSerializers/MAMFinSerializer.h
@@ -9,17 +9,17 @@
#include <boost/shared_ptr.hpp>
#include <Swiften/Base/Override.h>
#include <Swiften/Base/API.h>
-#include <Swiften/Elements/MAMArchived.h>
+#include <Swiften/Elements/MAMFin.h>
#include <Swiften/Serializer/GenericPayloadSerializer.h>
namespace Swift {
class PayloadSerializerCollection;
- class SWIFTEN_API MAMArchivedSerializer : public GenericPayloadSerializer<MAMArchived> {
+ class SWIFTEN_API MAMFinSerializer : public GenericPayloadSerializer<MAMFin> {
public:
- MAMArchivedSerializer();
- virtual ~MAMArchivedSerializer();
+ MAMFinSerializer();
+ virtual ~MAMFinSerializer();
- virtual std::string serializePayload(boost::shared_ptr<MAMArchived>) const SWIFTEN_OVERRIDE;
+ virtual std::string serializePayload(boost::shared_ptr<MAMFin>) 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 <boost/smart_ptr/make_shared.hpp>
-
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-
-#include <Swiften/Base/DateTime.h>
-#include <Swiften/Serializer/PayloadSerializers/MAMArchivedSerializer.h>
-#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
-
-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<MAMArchived> archived(boost::make_shared<MAMArchived>());
- archived->setBy("juliet@capulet.lit");
- archived->setID("28482-98726-73623");
-
- std::string expectedResult =
- "<archived by=\"juliet@capulet.lit\" id=\"28482-98726-73623\" xmlns=\"urn:xmpp:mam:0\"/>";
-
- 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 <boost/smart_ptr/make_shared.hpp>
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Serializer/PayloadSerializers/MAMFinSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+
+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<MAMFin> fin = boost::make_shared<MAMFin>();
+ fin->setQueryID("f27");
+
+ std::string expectedResult =
+ "<fin queryid=\"f27\" xmlns=\"urn:xmpp:mam:0\"/>";
+ CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(fin));
+ }
+
+ void testSerialize_XEP0313_Exmaple9() {
+ MAMFinSerializer serializer;
+
+ boost::shared_ptr<MAMFin> fin = boost::make_shared<MAMFin>();
+ fin->setComplete(true);
+
+ boost::shared_ptr<ResultSet> set = boost::make_shared<ResultSet>();
+ 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 =
+ "<fin complete=\"true\" xmlns=\"urn:xmpp:mam:0\">"
+ "<set xmlns=\"http://jabber.org/protocol/rsm\">"
+ "<count>16</count>"
+ "<first index=\"0\">23452-4534-1</first>"
+ "<last>390-2342-22</last>"
+ "</set>"
+ "</fin>";
+ CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(fin));
+ }
+
+ private:
+ FullPayloadSerializerCollection serializers;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MAMFinSerializerTest);