summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordknn <yoann.blein@free.fr>2012-07-07 10:08:42 (GMT)
committerdknn <yoann.blein@free.fr>2012-09-22 08:55:56 (GMT)
commit62f54e12354e208c8931e069fce235c4ca14d205 (patch)
tree87e4c16fd4362b0edf2ab3345c64fe28454e8776 /Swiften/Serializer/PayloadSerializers/JingleRawUDPTransportPayloadSerializer.cpp
parent96d693d51973bd5b2ed47755c8726dc2076f6c53 (diff)
downloadswift-contrib-62f54e12354e208c8931e069fce235c4ca14d205.zip
swift-contrib-62f54e12354e208c8931e069fce235c4ca14d205.tar.bz2
Add raw UDP transport payload: element, serializer, parser and tests
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/JingleRawUDPTransportPayloadSerializer.cpp')
-rw-r--r--Swiften/Serializer/PayloadSerializers/JingleRawUDPTransportPayloadSerializer.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/JingleRawUDPTransportPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/JingleRawUDPTransportPayloadSerializer.cpp
new file mode 100644
index 0000000..af13003
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/JingleRawUDPTransportPayloadSerializer.cpp
@@ -0,0 +1,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 "";
+}
+
+}