summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2011-11-11 15:01:32 (GMT)
committerKevin Smith <git@kismith.co.uk>2011-11-28 16:44:22 (GMT)
commit86aad702d1f2e831c8e27bbe4ca1402626e4c542 (patch)
tree3be5a8ed23aef3877c9b313d0ee0f58afb54f57a /Swiften
parent81a7776d5ab523894a7c4745baee3988ad9f1ef9 (diff)
downloadswift-contrib-86aad702d1f2e831c8e27bbe4ca1402626e4c542.zip
swift-contrib-86aad702d1f2e831c8e27bbe4ca1402626e4c542.tar.bz2
Message Receipts (XEP-0184) support for 1-to-1 conversations (including 1-to-1 MUC).
Warn icon from already existing theme. Check icon from Wikipedia. See Swift/resources/icons/license_info.txt for details. License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Elements/DeliveryReceipt.h34
-rw-r--r--Swiften/Elements/DeliveryReceiptRequest.h21
-rw-r--r--Swiften/Elements/DiscoInfo.cpp2
-rw-r--r--Swiften/Elements/DiscoInfo.h1
-rw-r--r--Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp35
-rw-r--r--Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h24
-rw-r--r--Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h29
-rw-r--r--Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.cpp30
-rw-r--r--Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h21
-rw-r--r--Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h29
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp4
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp44
-rw-r--r--Swiften/Parser/SConscript2
-rw-r--r--Swiften/SConscript4
-rw-r--r--Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.cpp22
-rw-r--r--Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h19
-rw-r--r--Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.cpp21
-rw-r--r--Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h19
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp4
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp45
20 files changed, 409 insertions, 1 deletions
diff --git a/Swiften/Elements/DeliveryReceipt.h b/Swiften/Elements/DeliveryReceipt.h
new file mode 100644
index 0000000..927da73
--- /dev/null
+++ b/Swiften/Elements/DeliveryReceipt.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/Payload.h>
+
+namespace Swift {
+
+class DeliveryReceipt : public Payload {
+ public:
+ typedef boost::shared_ptr<DeliveryReceipt> ref;
+
+ public:
+ DeliveryReceipt() {}
+
+ DeliveryReceipt(const std::string& msgId) : receivedID_(msgId) {}
+
+ void setReceivedID(const std::string& msgId) {
+ receivedID_ = msgId;
+ }
+
+ std::string getReceivedID() const {
+ return receivedID_;
+ }
+
+ private:
+ std::string receivedID_;
+};
+
+}
diff --git a/Swiften/Elements/DeliveryReceiptRequest.h b/Swiften/Elements/DeliveryReceiptRequest.h
new file mode 100644
index 0000000..3998785
--- /dev/null
+++ b/Swiften/Elements/DeliveryReceiptRequest.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/Payload.h>
+
+namespace Swift {
+
+class DeliveryReceiptRequest : public Payload {
+ public:
+ typedef boost::shared_ptr<DeliveryReceiptRequest> ref;
+
+ public:
+ DeliveryReceiptRequest() {}
+};
+
+}
diff --git a/Swiften/Elements/DiscoInfo.cpp b/Swiften/Elements/DiscoInfo.cpp
index 35d4d04..a4ce079 100644
--- a/Swiften/Elements/DiscoInfo.cpp
+++ b/Swiften/Elements/DiscoInfo.cpp
@@ -21,7 +21,7 @@ const std::string DiscoInfo::JingleFTFeature = std::string("urn:xmpp:jingle:apps
const std::string DiscoInfo::JingleTransportsIBBFeature = std::string("urn:xmpp:jingle:transports:ibb:1");
const std::string DiscoInfo::JingleTransportsS5BFeature = std::string("urn:xmpp:jingle:transports:s5b:1");
const std::string DiscoInfo::Bytestream = std::string("http://jabber.org/protocol/bytestreams");
-
+const std::string DiscoInfo::MessageDeliveryReceiptsFeature = std::string("urn:xmpp:receipts");
bool DiscoInfo::Identity::operator<(const Identity& other) const {
if (category_ == other.category_) {
diff --git a/Swiften/Elements/DiscoInfo.h b/Swiften/Elements/DiscoInfo.h
index 6d6e722..3173ee6 100644
--- a/Swiften/Elements/DiscoInfo.h
+++ b/Swiften/Elements/DiscoInfo.h
@@ -28,6 +28,7 @@ namespace Swift {
static const std::string JingleTransportsIBBFeature;
static const std::string JingleTransportsS5BFeature;
static const std::string Bytestream;
+ static const std::string MessageDeliveryReceiptsFeature;
class Identity {
public:
diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp
new file mode 100644
index 0000000..347200d
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h>
+
+#include <boost/optional.hpp>
+
+namespace Swift {
+
+DeliveryReceiptParser::DeliveryReceiptParser() : level_(0) {
+}
+
+void DeliveryReceiptParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributeMap) {
+ if (level_ == 0) {
+ if (element == "received") {
+ if (attributeMap.getAttributeValue("id").is_initialized()) {
+ getPayloadInternal()->setReceivedID(attributeMap.getAttributeValue("id").get());
+ }
+ }
+ }
+ ++level_;
+}
+
+void DeliveryReceiptParser::handleEndElement(const std::string&, const std::string&) {
+ --level_;
+}
+
+void DeliveryReceiptParser::handleCharacterData(const std::string&) {
+
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h
new file mode 100644
index 0000000..90a0921
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/DeliveryReceipt.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class DeliveryReceiptParser : public GenericPayloadParser<DeliveryReceipt> {
+ public:
+ DeliveryReceiptParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributeMap);
+ virtual void handleEndElement(const std::string& element, const std::string&);
+ virtual void handleCharacterData(const std::string& data);
+
+ private:
+ int level_;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h
new file mode 100644
index 0000000..259e04a
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+
+ class DeliveryReceiptParserFactory : public PayloadParserFactory {
+ public:
+ DeliveryReceiptParserFactory() {
+ }
+
+ virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const {
+ return ns == "urn:xmpp:receipts" && element == "received";
+ }
+
+ virtual PayloadParser* createPayloadParser() {
+ return new DeliveryReceiptParser();
+ }
+
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.cpp b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.cpp
new file mode 100644
index 0000000..f10cbc9
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.cpp
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h>
+
+#include <boost/optional.hpp>
+
+#include <Swiften/Base/Log.h>
+
+namespace Swift {
+
+DeliveryReceiptRequestParser::DeliveryReceiptRequestParser() {
+}
+
+void DeliveryReceiptRequestParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) {
+
+}
+
+void DeliveryReceiptRequestParser::handleEndElement(const std::string&, const std::string&) {
+
+}
+
+void DeliveryReceiptRequestParser::handleCharacterData(const std::string&) {
+
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h
new file mode 100644
index 0000000..55f7997
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/DeliveryReceiptRequest.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class DeliveryReceiptRequestParser : public GenericPayloadParser<DeliveryReceiptRequest> {
+ public:
+ DeliveryReceiptRequestParser();
+
+ virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&);
+ virtual void handleEndElement(const std::string&, const std::string&);
+ virtual void handleCharacterData(const std::string& data);
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h
new file mode 100644
index 0000000..9bd98c2
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+
+ class DeliveryReceiptRequestParserFactory : public PayloadParserFactory {
+ public:
+ DeliveryReceiptRequestParserFactory() {
+ }
+
+ virtual bool canParse(const std::string& element, const std::string& ns, const AttributeMap&) const {
+ return ns == "urn:xmpp:receipts" && element == "request";
+ }
+
+ virtual PayloadParser* createPayloadParser() {
+ return new DeliveryReceiptRequestParser();
+ }
+
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index 04e9fa6..01addf5 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -64,6 +64,8 @@
#include <Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h>
#include <Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h>
+#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h>
using namespace boost;
@@ -121,6 +123,8 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferReceivedParser> >("received", "urn:xmpp:jingle:apps:file-transfer:3"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferHashParser> >("checksum"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<S5BProxyRequestParser> >("query", "http://jabber.org/protocol/bytestreams"));
+ factories_.push_back(boost::make_shared<DeliveryReceiptParserFactory>());
+ factories_.push_back(boost::make_shared<DeliveryReceiptRequestParserFactory>());
foreach(shared_ptr<PayloadParserFactory> factory, factories_) {
addFactory(factory.get());
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp
new file mode 100644
index 0000000..919c342
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Elements/Message.h>
+#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParser.h>
+#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParser.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+class DeliveryReceiptParserTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(DeliveryReceiptParserTest);
+ CPPUNIT_TEST(testParseXEP0184Example3);
+ CPPUNIT_TEST(testParseXEP0184Example4);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testParseXEP0184Example3() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse("<request xmlns='urn:xmpp:receipts'/>"));
+
+ DeliveryReceiptRequest::ref request = boost::dynamic_pointer_cast<DeliveryReceiptRequest>(parser.getPayload());
+
+ CPPUNIT_ASSERT(request);
+ }
+
+ void testParseXEP0184Example4() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse("<received xmlns='urn:xmpp:receipts' id='richard2-4.1.247'/>"));
+
+ DeliveryReceipt::ref receipt = boost::dynamic_pointer_cast<DeliveryReceipt>(parser.getPayload());
+
+ CPPUNIT_ASSERT_EQUAL(std::string("richard2-4.1.247"), receipt->getReceivedID());
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(DeliveryReceiptParserTest);
+
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index e1ec1d8..e4c2778 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -70,6 +70,8 @@ sources = [
"PayloadParsers/ReplaceParser.cpp",
"PayloadParsers/LastParser.cpp",
"PayloadParsers/S5BProxyRequestParser.cpp",
+ "PayloadParsers/DeliveryReceiptParser.cpp",
+ "PayloadParsers/DeliveryReceiptRequestParser.cpp",
"PlatformXMLParserFactory.cpp",
"PresenceParser.cpp",
"SerializingParser.cpp",
diff --git a/Swiften/SConscript b/Swiften/SConscript
index ee21ba8..8c3ad42 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -178,6 +178,8 @@ if env["SCONS_STAGE"] == "build" :
"Serializer/PayloadSerializers/JingleIBBTransportPayloadSerializer.cpp",
"Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.cpp",
"Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.cpp",
+ "Serializer/PayloadSerializers/DeliveryReceiptSerializer.cpp",
+ "Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.cpp",
"Serializer/PresenceSerializer.cpp",
"Serializer/StanzaSerializer.cpp",
"Serializer/StreamErrorSerializer.cpp",
@@ -309,6 +311,7 @@ if env["SCONS_STAGE"] == "build" :
File("Parser/PayloadParsers/UnitTest/ReplaceTest.cpp"),
File("Parser/PayloadParsers/UnitTest/MUCAdminPayloadParserTest.cpp"),
File("Parser/PayloadParsers/UnitTest/MUCUserPayloadParserTest.cpp"),
+ File("Parser/PayloadParsers/UnitTest/DeliveryReceiptParserTest.cpp"),
File("Parser/UnitTest/BOSHBodyExtractorTest.cpp"),
File("Parser/UnitTest/AttributeMapTest.cpp"),
File("Parser/UnitTest/IQParserTest.cpp"),
@@ -357,6 +360,7 @@ if env["SCONS_STAGE"] == "build" :
File("Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/MUCAdminPayloadSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp"),
+ File("Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp"),
File("Serializer/UnitTest/StreamFeaturesSerializerTest.cpp"),
File("Serializer/UnitTest/AuthSuccessSerializerTest.cpp"),
File("Serializer/UnitTest/AuthChallengeSerializerTest.cpp"),
diff --git a/Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.cpp b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.cpp
new file mode 100644
index 0000000..eeb0d90
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.cpp
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h>
+#include <Swiften/Serializer/XML/XMLElement.h>
+
+#include <Swiften/Base/Log.h>
+
+namespace Swift {
+
+DeliveryReceiptRequestSerializer::DeliveryReceiptRequestSerializer() : GenericPayloadSerializer<DeliveryReceiptRequest>() {
+}
+
+std::string DeliveryReceiptRequestSerializer::serializePayload(boost::shared_ptr<DeliveryReceiptRequest> /* request*/) const {
+ XMLElement requestXML("request", "urn:xmpp:receipts");
+ return requestXML.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h
new file mode 100644
index 0000000..aa3c315
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+#include <Swiften/Elements/DeliveryReceiptRequest.h>
+
+namespace Swift {
+ class DeliveryReceiptRequestSerializer : public GenericPayloadSerializer<DeliveryReceiptRequest> {
+ public:
+ DeliveryReceiptRequestSerializer();
+
+ virtual std::string serializePayload(boost::shared_ptr<DeliveryReceiptRequest> request) const;
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.cpp b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.cpp
new file mode 100644
index 0000000..a9033b2
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h>
+#include <Swiften/Serializer/XML/XMLElement.h>
+
+namespace Swift {
+
+DeliveryReceiptSerializer::DeliveryReceiptSerializer() : GenericPayloadSerializer<DeliveryReceipt>() {
+}
+
+std::string DeliveryReceiptSerializer::serializePayload(boost::shared_ptr<DeliveryReceipt> receipt) const {
+ XMLElement received("received", "urn:xmpp:receipts");
+ received.setAttribute("id", receipt->getReceivedID());
+ return received.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h
new file mode 100644
index 0000000..5fda3ea
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the BSD license.
+ * See http://www.opensource.org/licenses/bsd-license.php for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+#include <Swiften/Elements/DeliveryReceipt.h>
+
+namespace Swift {
+ class DeliveryReceiptSerializer : public GenericPayloadSerializer<DeliveryReceipt> {
+ public:
+ DeliveryReceiptSerializer();
+
+ virtual std::string serializePayload(boost::shared_ptr<DeliveryReceipt> receipt) const;
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index 87dfbc3..499a185 100644
--- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -60,6 +60,8 @@
#include <Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/S5BProxyRequestSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h>
namespace Swift {
@@ -116,6 +118,8 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new JingleS5BTransportPayloadSerializer());
serializers_.push_back(new JinglePayloadSerializer(this));
serializers_.push_back(new S5BProxyRequestSerializer());
+ serializers_.push_back(new DeliveryReceiptSerializer());
+ serializers_.push_back(new DeliveryReceiptRequestSerializer());
foreach(PayloadSerializer* serializer, serializers_) {
addSerializer(serializer);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp
new file mode 100644
index 0000000..9282db4
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <boost/shared_ptr.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h>
+
+using namespace Swift;
+
+class DeliveryReceiptSerializerTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(DeliveryReceiptSerializerTest);
+ CPPUNIT_TEST(testSerialize_XEP0184Example3);
+ CPPUNIT_TEST(testSerialize_XEP0184Example4);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testSerialize_XEP0184Example3() {
+ std::string expected = "<request xmlns=\"urn:xmpp:receipts\"/>";
+
+ DeliveryReceiptRequest::ref receipt = boost::make_shared<DeliveryReceiptRequest>();
+
+ boost::shared_ptr<DeliveryReceiptRequestSerializer> serializer = boost::make_shared<DeliveryReceiptRequestSerializer>();
+ CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(receipt));
+ }
+
+ void testSerialize_XEP0184Example4() {
+ std::string expected = "<received id=\"richard2-4.1.247\" xmlns=\"urn:xmpp:receipts\"/>";
+
+ DeliveryReceipt::ref receipt = boost::make_shared<DeliveryReceipt>("richard2-4.1.247");
+
+ boost::shared_ptr<DeliveryReceiptSerializer> serializer = boost::make_shared<DeliveryReceiptSerializer>();
+ CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(receipt));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(DeliveryReceiptSerializerTest);
+