blob: 39eb149669ce09ad86da6688c39942ed783583e5 (
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
70
71
72
73
74
75
76
77
78
79
80
|
/*
* Copyright (c) 2011 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.h>
#include <memory>
#include <Swiften/Base/Log.h>
#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/JingleIBBTransportPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.h>
#include <Swiften/Serializer/XML/XMLElement.h>
#include <Swiften/Serializer/XML/XMLNode.h>
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
namespace Swift {
JingleContentPayloadSerializer::JingleContentPayloadSerializer() {
}
std::string JingleContentPayloadSerializer::serializePayload(std::shared_ptr<JingleContentPayload> payload) const {
XMLElement payloadXML("content");
payloadXML.setAttribute("creator", creatorToString(payload->getCreator()));
payloadXML.setAttribute("name", payload->getName());
if (!payload->getDescriptions().empty()) {
// JingleFileTransferDescription
JingleFileTransferDescriptionSerializer ftSerializer;
JingleFileTransferDescription::ref filetransfer;
for (auto&& desc : payload->getDescriptions()) {
if ((filetransfer = std::dynamic_pointer_cast<JingleFileTransferDescription>(desc))) {
payloadXML.addNode(std::make_shared<XMLRawTextNode>(ftSerializer.serializePayload(filetransfer)));
}
}
}
if (!payload->getTransports().empty()) {
// JingleIBBTransportPayload
JingleIBBTransportPayloadSerializer ibbSerializer;
JingleIBBTransportPayload::ref ibb;
// JingleS5BTransportPayload
JingleS5BTransportPayloadSerializer s5bSerializer;
JingleS5BTransportPayload::ref s5b;
for (auto&& transport : payload->getTransports()) {
if ((ibb = std::dynamic_pointer_cast<JingleIBBTransportPayload>(transport))) {
payloadXML.addNode(std::make_shared<XMLRawTextNode>(ibbSerializer.serializePayload(ibb)));
} else if ((s5b = std::dynamic_pointer_cast<JingleS5BTransportPayload>(transport))) {
payloadXML.addNode(std::make_shared<XMLRawTextNode>(s5bSerializer.serializePayload(s5b)));
}
}
}
return payloadXML.serialize();
}
std::string JingleContentPayloadSerializer::creatorToString(JingleContentPayload::Creator creator) const {
switch(creator) {
case JingleContentPayload::InitiatorCreator:
return "initiator";
case JingleContentPayload::ResponderCreator:
return "responder";
case JingleContentPayload::UnknownCreator:
SWIFT_LOG(error) << "Serializing unknown creator value.";
return "ERROR ERROR ERROR";
}
assert(false);
return "";
}
}
|