blob: af1300394044f03d5e7cc7014cdef7dba16ae513 (
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
|
/*
* Copyright (c) 2012 Yoann Blein
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <Swiften/Serializer/PayloadSerializers/JingleRawUDPTransportPayloadSerializer.h>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/lexical_cast.hpp>
#include <Swiften/Base/foreach.h>
#include <Swiften/Serializer/XML/XMLElement.h>
namespace Swift {
JingleRawUDPTransportPayloadSerializer::JingleRawUDPTransportPayloadSerializer() {
}
std::string JingleRawUDPTransportPayloadSerializer::serializePayload(boost::shared_ptr<JingleRawUDPTransportPayload> payload) const {
XMLElement payloadXML("transport", "urn:xmpp:jingle:transports:raw-udp:1");
foreach (JingleRawUDPTransportPayload::Candidate candidate, payload->getCandidates()) {
boost::shared_ptr<XMLElement> candidateXML = boost::make_shared<XMLElement>("candidate");
candidateXML->setAttribute("component", boost::lexical_cast<std::string>(static_cast<int>(candidate.component)));
candidateXML->setAttribute("generation", boost::lexical_cast<std::string>(static_cast<int>(candidate.generation)));
candidateXML->setAttribute("id", candidate.cid);
candidateXML->setAttribute("ip", candidate.hostAddressPort.getAddress().toString());
candidateXML->setAttribute("port", boost::lexical_cast<std::string>(candidate.hostAddressPort.getPort()));
if (candidate.type != JingleRawUDPTransportPayload::Candidate::Unknown)
candidateXML->setAttribute("type", typeToString(candidate.type));
payloadXML.addNode(candidateXML);
}
return payloadXML.serialize();
}
std::string JingleRawUDPTransportPayloadSerializer::typeToString(JingleRawUDPTransportPayload::Candidate::Type type) const {
switch (type) {
case JingleRawUDPTransportPayload::Candidate::Unknown:
return "";
case JingleRawUDPTransportPayload::Candidate::Host:
return "host";
case JingleRawUDPTransportPayload::Candidate::PeerReflected:
return "prflx";
case JingleRawUDPTransportPayload::Candidate::Relayed:
return "relay";
case JingleRawUDPTransportPayload::Candidate::ServerReflected:
return "srflx";
}
assert(false);
return "";
}
}
|