summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers/JingleRawUDPTransportPayloadParser.cpp')
-rw-r--r--Swiften/Parser/PayloadParsers/JingleRawUDPTransportPayloadParser.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/JingleRawUDPTransportPayloadParser.cpp b/Swiften/Parser/PayloadParsers/JingleRawUDPTransportPayloadParser.cpp
new file mode 100644
index 0000000..aa6aaf7
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/JingleRawUDPTransportPayloadParser.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2012 Yoann Blein
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/JingleRawUDPTransportPayloadParser.h>
+
+#include <boost/lexical_cast.hpp>
+#include <boost/optional.hpp>
+
+namespace Swift {
+
+JingleRawUDPTransportPayloadParser::JingleRawUDPTransportPayloadParser() : level(0) {
+
+}
+
+void JingleRawUDPTransportPayloadParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) {
+ if (level == 1 && element == "candidate") {
+ JingleRawUDPTransportPayload::Candidate candidate;
+
+ // component
+ try {
+ candidate.component = boost::numeric_cast<boost::uint8_t>(boost::lexical_cast<int>(attributes.getAttributeValue("component").get_value_or("0")));
+ } catch(boost::bad_lexical_cast &) { }
+ // generation
+ try {
+ candidate.generation = boost::numeric_cast<boost::uint8_t>(boost::lexical_cast<int>(attributes.getAttributeValue("generation").get_value_or("0")));
+ } catch(boost::bad_lexical_cast &) { }
+ // id
+ candidate.cid = attributes.getAttributeValue("id").get_value_or("");
+ // ip/port
+ int port = -1;
+ try {
+ port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get_value_or("0"));
+ } catch(boost::bad_lexical_cast &) { }
+ candidate.hostAddressPort = HostAddressPort(HostAddress(attributes.getAttributeValue("ip").get_value_or("")), port);
+ // type
+ candidate.type = stringToType(attributes.getAttributeValue("type").get_value_or(""));
+
+ getPayloadInternal()->addCandidate(candidate);
+ }
+
+ ++level;
+}
+
+void JingleRawUDPTransportPayloadParser::handleEndElement(const std::string&, const std::string&) {
+ --level;
+}
+
+void JingleRawUDPTransportPayloadParser::handleCharacterData(const std::string&) {
+
+}
+
+JingleRawUDPTransportPayload::Candidate::Type JingleRawUDPTransportPayloadParser::stringToType(const std::string &str) const {
+ if (str == "host") {
+ return JingleRawUDPTransportPayload::Candidate::Host;
+ } else if (str == "prflx") {
+ return JingleRawUDPTransportPayload::Candidate::PeerReflected;
+ } else if (str == "relay") {
+ return JingleRawUDPTransportPayload::Candidate::Relayed;
+ } else if (str == "srflx") {
+ return JingleRawUDPTransportPayload::Candidate::ServerReflected;
+ } else {
+ return JingleRawUDPTransportPayload::Candidate::Unknown;
+ }
+}
+
+}