diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-09-14 18:57:59 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-09-14 19:15:45 (GMT) |
commit | b8201141afdbd4cab6fcda37cf8daad492b1f996 (patch) | |
tree | ab4908b05a7bb0b1fe97bc4609b68dd9c0b538a9 /Swiften/Serializer/PayloadSerializers | |
parent | 5e3ef73cc312d0d79504faa3e0adf4de9bf836c2 (diff) | |
download | swift-contrib-b8201141afdbd4cab6fcda37cf8daad492b1f996.zip swift-contrib-b8201141afdbd4cab6fcda37cf8daad492b1f996.tar.bz2 |
Added private storage element, parser, and serializer.
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
4 files changed, 92 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 998dce8..fc20018 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -19,6 +19,7 @@ #include "Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h" #include "Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h" #include "Swiften/Serializer/PayloadSerializers/StorageSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h" namespace Swift { @@ -41,6 +42,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new VCardUpdateSerializer()); serializers_.push_back(new RawXMLPayloadSerializer()); serializers_.push_back(new StorageSerializer()); + serializers_.push_back(new PrivateStorageSerializer(this)); foreach(PayloadSerializer* serializer, serializers_) { addSerializer(serializer); } diff --git a/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp new file mode 100644 index 0000000..999252c --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.cpp @@ -0,0 +1,28 @@ +#include "Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h" + +#include <boost/shared_ptr.hpp> + +#include "Swiften/Base/foreach.h" +#include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" +#include "Swiften/Serializer/XML/XMLRawTextNode.h" +#include "Swiften/Serializer/PayloadSerializerCollection.h" + +namespace Swift { + +PrivateStorageSerializer::PrivateStorageSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} + +String PrivateStorageSerializer::serializePayload(boost::shared_ptr<PrivateStorage> storage) const { + XMLElement storageElement("query", "jabber:iq:private"); + boost::shared_ptr<Payload> payload = storage->getPayload(); + if (payload) { + PayloadSerializer* serializer = serializers->getPayloadSerializer(payload); + if (serializer) { + storageElement.addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(serializer->serialize(payload)))); + } + } + return storageElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h new file mode 100644 index 0000000..c655634 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h @@ -0,0 +1,18 @@ +#pragma once + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/PrivateStorage.h" + +namespace Swift { + class PayloadSerializerCollection; + + class PrivateStorageSerializer : public GenericPayloadSerializer<PrivateStorage> { + public: + PrivateStorageSerializer(PayloadSerializerCollection* serializers); + + virtual String serializePayload(boost::shared_ptr<PrivateStorage>) const; + + private: + PayloadSerializerCollection* serializers; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp new file mode 100644 index 0000000..37c3adb --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp @@ -0,0 +1,44 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h" +#include "Swiften/Elements/PrivateStorage.h" +#include "Swiften/Elements/Storage.h" + +using namespace Swift; + +class PrivateStorageSerializerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(PrivateStorageSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + PrivateStorageSerializerTest() {} + + void testSerialize() { + PayloadsSerializer serializer; + + boost::shared_ptr<PrivateStorage> privateStorage(new PrivateStorage()); + boost::shared_ptr<Storage> storage(new Storage()); + Storage::Conference conference; + conference.name = "Swift"; + conference.jid = JID("swift@rooms.swift.im"); + conference.nick = "Alice"; + storage->addConference(conference); + privateStorage->setPayload(storage); + + CPPUNIT_ASSERT_EQUAL(String( + "<query xmlns=\"jabber:iq:private\">" + "<storage xmlns=\"storage:bookmarks\">" + "<conference " + "autojoin=\"1\" " + "jid=\"swift@rooms.swift.im\" " + "name=\"Swift\">" + "<nick>Alice</nick>" + "</conference>" + "</storage>" + "</query>"), serializer.serialize(privateStorage)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(PrivateStorageSerializerTest); |