blob: 6c110e2e9e654ed9fa9adcae95ecd3c367f08b90 (
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-2016 Isode Limited.
* All rights reserved.
* 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 <memory>
#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(std::make_shared<PubSubItemsSerializer>(serializers));
pubsubSerializers.push_back(std::make_shared<PubSubCreateSerializer>(serializers));
pubsubSerializers.push_back(std::make_shared<PubSubPublishSerializer>(serializers));
pubsubSerializers.push_back(std::make_shared<PubSubOptionsSerializer>(serializers));
pubsubSerializers.push_back(std::make_shared<PubSubAffiliationsSerializer>(serializers));
pubsubSerializers.push_back(std::make_shared<PubSubRetractSerializer>(serializers));
pubsubSerializers.push_back(std::make_shared<PubSubDefaultSerializer>(serializers));
pubsubSerializers.push_back(std::make_shared<PubSubSubscriptionsSerializer>(serializers));
pubsubSerializers.push_back(std::make_shared<PubSubSubscribeSerializer>(serializers));
pubsubSerializers.push_back(std::make_shared<PubSubUnsubscribeSerializer>(serializers));
pubsubSerializers.push_back(std::make_shared<PubSubSubscriptionSerializer>(serializers));
}
PubSubSerializer::~PubSubSerializer() {
}
std::string PubSubSerializer::serializePayload(std::shared_ptr<PubSub> payload) const {
if (!payload) {
return "";
}
XMLElement element("pubsub", "http://jabber.org/protocol/pubsub");
std::shared_ptr<PubSubPayload> p = payload->getPayload();
foreach(std::shared_ptr<PayloadSerializer> serializer, pubsubSerializers) {
if (serializer->canSerialize(p)) {
element.addNode(std::make_shared<XMLRawTextNode>(serializer->serialize(p)));
if (std::shared_ptr<PubSubCreate> create = std::dynamic_pointer_cast<PubSubCreate>(p)) {
element.addNode(std::make_shared<XMLRawTextNode>(std::make_shared<PubSubConfigureSerializer>(serializers)->serialize(create->getConfigure())));
}
if (std::shared_ptr<PubSubSubscribe> subscribe = std::dynamic_pointer_cast<PubSubSubscribe>(p)) {
element.addNode(std::make_shared<XMLRawTextNode>(std::make_shared<PubSubConfigureSerializer>(serializers)->serialize(subscribe->getOptions())));
}
}
}
return element.serialize();
}
|