summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.cpp66
-rw-r--r--Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.h26
2 files changed, 92 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.cpp b/Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.cpp
new file mode 100644
index 0000000..bddf96a
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2011 Yoann Blein
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "RTPPayloadTypeParser.h"
+
+#include <boost/optional.hpp>
+#include <boost/lexical_cast.hpp>
+
+//#include <Swiften/Base/DateTime.h>
+//#include <Swiften/Base/Log.h>
+
+namespace Swift {
+
+RTPPayloadTypeParser::RTPPayloadTypeParser() : level(0) {
+
+}
+
+void RTPPayloadTypeParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) {
+ if (level == 0) {
+ // channel
+ try {
+ getPayloadInternal()->setChannels(boost::lexical_cast<boost::uint32_t>(attributes.getAttributeValue("channels").get_value_or("1")));
+ } catch (boost::bad_lexical_cast &) {
+ getPayloadInternal()->setChannels(1);
+ }
+ // clockrate
+ try {
+ getPayloadInternal()->setClockrate(boost::lexical_cast<boost::uint32_t>(attributes.getAttributeValue("clockrate").get_value_or("0")));
+ } catch (boost::bad_lexical_cast &) {
+ getPayloadInternal()->setClockrate(0);
+ }
+ // ID
+ try {
+ getPayloadInternal()->setID(boost::lexical_cast<boost::uint8_t>(attributes.getAttributeValue("id").get_value_or("0")));
+ } catch (boost::bad_lexical_cast &) {
+ getPayloadInternal()->setID(0);
+ }
+ // maxptime
+ try {
+ getPayloadInternal()->setMaxptime(boost::lexical_cast<boost::uint32_t>(attributes.getAttributeValue("maxptime").get_value_or("0")));
+ } catch (boost::bad_lexical_cast &) {
+ getPayloadInternal()->setMaxptime(0);
+ }
+ // name
+ getPayloadInternal()->setName(attributes.getAttributeValue("name").get_value_or(""));
+ // ptime
+ try {
+ getPayloadInternal()->setPTime(boost::lexical_cast<boost::uint32_t>(attributes.getAttributeValue("ptime").get_value_or("0")));
+ } catch (boost::bad_lexical_cast &) {
+ getPayloadInternal()->setPTime(0);
+ }
+ } else if (level == 1) {
+ getPayloadInternal()->addParameter(attributes.getAttributeValue("name").get_value_or(""),
+ attributes.getAttributeValue("value").get_value_or(""));
+ }
+ ++level;
+}
+
+void RTPPayloadTypeParser::handleEndElement(const std::string& element, const std::string&) {
+ --level;
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.h b/Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.h
new file mode 100644
index 0000000..360053f
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2011 Yoann Blein
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/RTPPayloadType.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+
+class RTPPayloadTypeParser : public GenericPayloadParser<RTPPayloadType> {
+ public:
+ RTPPayloadTypeParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes);
+ virtual void handleEndElement(const std::string& element, const std::string&);
+ virtual void handleCharacterData(const std::string&) {};
+
+ private:
+ int level;
+};
+
+}