summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
-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
6 files changed, 116 insertions, 80 deletions
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);