blob: 0e61331b3290d6a443c4da75d3f8d6c1f5ae51c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/*
* Copyright (c) 2013 Remko Tronçon
* Licensed under the GNU General Public License.
* See the COPYING file for more information.
*/
#pragma clang diagnostic ignored "-Wunused-private-field"
#include <Swiften/Serializer/PayloadSerializers/PubSubSerializer.h>
#include <Swiften/Serializer/XML/XMLElement.h>
#include <boost/smart_ptr/make_shared.hpp>
#include <Swiften/Serializer/PayloadSerializerCollection.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubConfigureSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubAffiliationsSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubCreateSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubDefaultSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.h>
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubSubscriptionSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubUnsubscribeSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubPublishSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubOptionsSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubSubscribeSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubSubscriptionsSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubOptionsSerializer.h>
#include <Swiften/Base/foreach.h>
using namespace Swift;
PubSubSerializer::PubSubSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) {
pubsubSerializers.push_back(boost::make_shared<PubSubItemsSerializer>(serializers));
pubsubSerializers.push_back(boost::make_shared<PubSubCreateSerializer>(serializers));
pubsubSerializers.push_back(boost::make_shared<PubSubPublishSerializer>(serializers));
pubsubSerializers.push_back(boost::make_shared<PubSubOptionsSerializer>(serializers));
pubsubSerializers.push_back(boost::make_shared<PubSubAffiliationsSerializer>(serializers));
pubsubSerializers.push_back(boost::make_shared<PubSubRetractSerializer>(serializers));
pubsubSerializers.push_back(boost::make_shared<PubSubDefaultSerializer>(serializers));
pubsubSerializers.push_back(boost::make_shared<PubSubSubscriptionsSerializer>(serializers));
pubsubSerializers.push_back(boost::make_shared<PubSubSubscribeSerializer>(serializers));
pubsubSerializers.push_back(boost::make_shared<PubSubUnsubscribeSerializer>(serializers));
pubsubSerializers.push_back(boost::make_shared<PubSubSubscriptionSerializer>(serializers));
}
PubSubSerializer::~PubSubSerializer() {
}
std::string PubSubSerializer::serializePayload(boost::shared_ptr<PubSub> payload) const {
if (!payload) {
return "";
}
XMLElement element("pubsub", "http://jabber.org/protocol/pubsub");
boost::shared_ptr<PubSubPayload> p = payload->getPayload();
foreach(boost::shared_ptr<PayloadSerializer> serializer, pubsubSerializers) {
if (serializer->canSerialize(p)) {
element.addNode(boost::make_shared<XMLRawTextNode>(serializer->serialize(p)));
if (boost::shared_ptr<PubSubCreate> create = boost::dynamic_pointer_cast<PubSubCreate>(p)) {
element.addNode(boost::make_shared<XMLRawTextNode>(boost::make_shared<PubSubConfigureSerializer>(serializers)->serialize(create->getConfigure())));
}
if (boost::shared_ptr<PubSubSubscribe> subscribe = boost::dynamic_pointer_cast<PubSubSubscribe>(p)) {
element.addNode(boost::make_shared<XMLRawTextNode>(boost::make_shared<PubSubConfigureSerializer>(serializers)->serialize(subscribe->getOptions())));
}
}
}
return element.serialize();
}
|