blob: 0e21812ba3555d236094e96f2074341bae6a2df5 (
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
|
/*
* Copyright (c) 2011 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <Swiften/Serializer/PayloadSerializers/JingleContentPayloadSerializer.h>
#include <boost/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include <Swiften/Base/foreach.h>
#include <Swiften/Serializer/XML/XMLNode.h>
#include <Swiften/Serializer/XML/XMLElement.h>
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
#include <Swiften/Serializer/PayloadSerializers/JingleFileTransferDescriptionSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/JingleIBBTransportPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/JingleS5BTransportPayloadSerializer.h>
namespace Swift {
JingleContentPayloadSerializer::JingleContentPayloadSerializer() {
}
std::string JingleContentPayloadSerializer::serializePayload(boost::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;
foreach(JingleDescription::ref desc, payload->getDescriptions()) {
if ((filetransfer = boost::dynamic_pointer_cast<JingleFileTransferDescription>(desc))) {
payloadXML.addNode(boost::make_shared<XMLRawTextNode>(ftSerializer.serializePayload(filetransfer)));
}
}
}
if (!payload->getTransports().empty()) {
// JingleIBBTransportPayload
JingleIBBTransportPayloadSerializer ibbSerializer;
JingleIBBTransportPayload::ref ibb;
// JingleS5BTransportPayload
JingleS5BTransportPayloadSerializer s5bSerializer;
JingleS5BTransportPayload::ref s5b;
foreach(JingleTransportPayload::ref transport, payload->getTransports()) {
if ((ibb = boost::dynamic_pointer_cast<JingleIBBTransportPayload>(transport))) {
payloadXML.addNode(boost::make_shared<XMLRawTextNode>(ibbSerializer.serializePayload(ibb)));
} else if ((s5b = boost::dynamic_pointer_cast<JingleS5BTransportPayload>(transport))) {
payloadXML.addNode(boost::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:
std::cerr << "Serializing unknown creator value." << std::endl;
return "ERROR ERROR ERROR";
}
assert(false);
return "";
}
}
|