summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2012-05-05 07:11:25 (GMT)
committerRemko Tronçon <git@el-tramo.be>2012-05-05 07:11:25 (GMT)
commit1824826fffbe9ebf508264db13843bd1a94f0778 (patch)
tree418ce84968cfd33c2ca160a58bf70a498e066f5c /Swiften
parent14215c76b373ee8bbb7e73d4577f40eec01f5d85 (diff)
downloadswift-1824826fffbe9ebf508264db13843bd1a94f0778.zip
swift-1824826fffbe9ebf508264db13843bd1a94f0778.tar.bz2
Serialize error payload.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp10
-rw-r--r--Swiften/Serializer/PayloadSerializers/ErrorSerializer.h7
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp26
4 files changed, 36 insertions, 9 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp
index e3bfd54..fa6a566 100644
--- a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp
@@ -6,10 +6,11 @@
#include <Swiften/Serializer/PayloadSerializers/ErrorSerializer.h>
#include <Swiften/Serializer/XML/XMLTextNode.h>
+#include <Swiften/Serializer/PayloadSerializerCollection.h>
namespace Swift {
-ErrorSerializer::ErrorSerializer() : GenericPayloadSerializer<ErrorPayload>() {
+ErrorSerializer::ErrorSerializer(PayloadSerializerCollection* serializers) : GenericPayloadSerializer<ErrorPayload>(), serializers(serializers) {
}
std::string ErrorSerializer::serializePayload(boost::shared_ptr<ErrorPayload> error) const {
@@ -55,6 +56,13 @@ std::string ErrorSerializer::serializePayload(boost::shared_ptr<ErrorPayload> er
result += "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">" + textNode.serialize() + "</text>";
}
+ if (error->getPayload()) {
+ PayloadSerializer* serializer = serializers->getPayloadSerializer(error->getPayload());
+ if (serializer) {
+ result += serializer->serialize(error->getPayload());
+ }
+ }
+
result += "</error>";
return result;
}
diff --git a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h
index d06efc8..41e35a9 100644
--- a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h
+++ b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h
@@ -10,10 +10,15 @@
#include <Swiften/Elements/ErrorPayload.h>
namespace Swift {
+ class PayloadSerializerCollection;
+
class ErrorSerializer : public GenericPayloadSerializer<ErrorPayload> {
public:
- ErrorSerializer();
+ ErrorSerializer(PayloadSerializerCollection* serializers);
virtual std::string serializePayload(boost::shared_ptr<ErrorPayload> error) const;
+
+ private:
+ PayloadSerializerCollection* serializers;
};
}
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index 499a185..93fd70f 100644
--- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -71,7 +71,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new SubjectSerializer());
serializers_.push_back(new ChatStateSerializer());
serializers_.push_back(new PrioritySerializer());
- serializers_.push_back(new ErrorSerializer());
+ serializers_.push_back(new ErrorSerializer(this));
serializers_.push_back(new RosterSerializer());
serializers_.push_back(new RosterItemExchangeSerializer());
serializers_.push_back(new MUCPayloadSerializer());
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp
index 27d4ac5..d1408f7 100644
--- a/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp
@@ -1,31 +1,45 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2012 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 <boost/smart_ptr/make_shared.hpp>
#include <Swiften/Serializer/PayloadSerializers/ErrorSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+#include <Swiften/Elements/Delay.h>
using namespace Swift;
-class ErrorSerializerTest : public CppUnit::TestFixture
-{
+class ErrorSerializerTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ErrorSerializerTest);
CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST(testSerialize_Payload);
CPPUNIT_TEST_SUITE_END();
public:
- ErrorSerializerTest() {}
-
void testSerialize() {
- ErrorSerializer testling;
+ ErrorSerializer testling(&serializers);
boost::shared_ptr<ErrorPayload> error(new ErrorPayload(ErrorPayload::BadRequest, ErrorPayload::Cancel, "My Error"));
CPPUNIT_ASSERT_EQUAL(std::string("<error type=\"cancel\"><bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/><text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">My Error</text></error>"), testling.serialize(error));
}
+
+ void testSerialize_Payload() {
+ ErrorSerializer testling(&serializers);
+ boost::shared_ptr<ErrorPayload> error = boost::make_shared<ErrorPayload>();
+ error->setPayload(boost::make_shared<Delay>());
+
+ CPPUNIT_ASSERT_EQUAL(std::string(
+ "<error type=\"cancel\"><undefined-condition xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/><delay stamp=\"not-a-date-timeZ\" xmlns=\"urn:xmpp:delay\"/></error>"
+ ), testling.serialize(error));
+ }
+
+ private:
+ FullPayloadSerializerCollection serializers;
};
CPPUNIT_TEST_SUITE_REGISTRATION(ErrorSerializerTest);