summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers')
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/InputEventParser.cpp81
-rw-r--r--Swiften/Parser/PayloadParsers/InputEventParser.h26
-rw-r--r--Swiften/Parser/PayloadParsers/JingleParserFactory.h2
-rw-r--r--Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.cpp8
-rw-r--r--Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.h45
6 files changed, 134 insertions, 30 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index 167f5c1..ec05ef6 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -70,6 +70,7 @@
#include <Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.h>
#include <Swiften/Parser/PayloadParsers/JingleRTPDescriptionParserFactory.h>
#include <Swiften/Parser/PayloadParsers/JingleRawUDPTransportPayloadParser.h>
+#include <Swiften/Parser/PayloadParsers/InputEventParser.h>
using namespace boost;
@@ -134,6 +135,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(boost::make_shared<JingleRTPDescriptionParserFactory>(this));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<RTPPayloadTypeParser> >("payload-type"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleRawUDPTransportPayloadParser> >("transport", "urn:xmpp:jingle:transports:raw-udp:1"));
+ factories_.push_back(boost::make_shared<GenericPayloadParserFactory<InputEventParser> >("inputevt", "http://sip-comunicator.org/protocol/inputevt"));
foreach(shared_ptr<PayloadParserFactory> factory, factories_) {
addFactory(factory.get());
diff --git a/Swiften/Parser/PayloadParsers/InputEventParser.cpp b/Swiften/Parser/PayloadParsers/InputEventParser.cpp
new file mode 100644
index 0000000..44d9849
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/InputEventParser.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2012 Yoann Blein
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/InputEventParser.h>
+
+#include <boost/optional.hpp>
+#include <boost/lexical_cast.hpp>
+
+namespace Swift {
+
+void InputEventParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) {
+ if (level == 0) {
+ // <inputevt> tag
+ InputEventPayload::ref payload = getPayloadInternal();
+ payload->setAction(actionFromString(attributes.getAttributeValue("action").get_value_or("")));
+ } else if (level == 1) {
+ // <remote-control> tag
+ } else if (level == 2) {
+ InputEventPayload::Event event(eventTypeFromString(element));
+ switch (event.type) {
+ case InputEventPayload::Event::MouseMove:
+ try {
+ event.realArg1 = boost::lexical_cast<float>(attributes.getAttributeValue("x").get_value_or("0"));
+ event.realArg2 = boost::lexical_cast<float>(attributes.getAttributeValue("y").get_value_or("0"));
+ } catch (boost::bad_lexical_cast &) {}
+ break;
+ case InputEventPayload::Event::MouseWheel:
+ case InputEventPayload::Event::MousePress:
+ case InputEventPayload::Event::MouseRelease:
+ case InputEventPayload::Event::KeyType:
+ case InputEventPayload::Event::KeyPress:
+ case InputEventPayload::Event::KeyRelease:
+ try {
+ event.integerArg = boost::lexical_cast<int>(attributes.getEntries().front().getValue());
+ } catch (boost::bad_lexical_cast &) {}
+ default:
+ break;
+ }
+ }
+ ++level;
+}
+
+void InputEventParser::handleEndElement(const std::string&, const std::string&) {
+ --level;
+}
+
+void InputEventParser::handleCharacterData(const std::string&){
+
+}
+
+InputEventPayload::Action InputEventParser::actionFromString(const std::string& action)
+{
+ if (action == "notify")
+ return InputEventPayload::Notify;
+
+ return InputEventPayload::Unknown;
+}
+
+InputEventPayload::Event::EventType InputEventParser::eventTypeFromString(const std::string& eventType) {
+ if (eventType == "mouse-move")
+ return InputEventPayload::Event::MouseMove;
+ else if (eventType == "mouse-wheel")
+ return InputEventPayload::Event::MouseWheel;
+ else if (eventType == "mouse-press")
+ return InputEventPayload::Event::MousePress;
+ else if (eventType == "mouse-release")
+ return InputEventPayload::Event::MouseRelease;
+ else if (eventType == "key-type")
+ return InputEventPayload::Event::KeyType;
+ else if (eventType == "key-press")
+ return InputEventPayload::Event::KeyPress;
+ else if (eventType == "key-release")
+ return InputEventPayload::Event::KeyRelease;
+
+ return InputEventPayload::Event::Unknown;
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/InputEventParser.h b/Swiften/Parser/PayloadParsers/InputEventParser.h
new file mode 100644
index 0000000..a131254
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/InputEventParser.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2012 Yoann Blein
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/InputEventPayload.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class InputEventParser : public GenericPayloadParser<InputEventPayload> {
+ public:
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes);
+ virtual void handleEndElement(const std::string&, const std::string&);
+ virtual void handleCharacterData(const std::string&);
+
+ private:
+ static InputEventPayload::Action actionFromString(const std::string& action);
+ static InputEventPayload::Event::EventType eventTypeFromString(const std::string& eventType);
+
+ private:
+ int level;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/JingleParserFactory.h b/Swiften/Parser/PayloadParsers/JingleParserFactory.h
index fa25aeb..9feade7 100644
--- a/Swiften/Parser/PayloadParsers/JingleParserFactory.h
+++ b/Swiften/Parser/PayloadParsers/JingleParserFactory.h
@@ -31,5 +31,3 @@ namespace Swift {
};
}
-
-
diff --git a/Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.cpp b/Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.cpp
index 7429b39..68893c7 100644
--- a/Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.cpp
+++ b/Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.cpp
@@ -4,7 +4,7 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
-#include "JingleRTPDescriptionParser.h"
+#include <Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.h>
#include <Swiften/Parser/PayloadParserFactoryCollection.h>
#include <Swiften/Parser/PayloadParserFactory.h>
@@ -23,7 +23,7 @@ void JingleRTPDescriptionParser::handleStartElement(const std::string& element,
const std::string& media = attributes.getAttributeValue("media").get_value_or("");
getPayloadInternal()->setMedia(mediaTypeFromString(media));
}
-
+
if (level == 1) {
if (element == "bandwidth") {
parsingBandwidth = true;
@@ -66,8 +66,8 @@ void JingleRTPDescriptionParser::handleCharacterData(const std::string& data) {
bandwidthValue += data;
}
}
-
-JingleRTPDescription::MediaType JingleRTPDescriptionParser::mediaTypeFromString(const std::string& media) const {
+
+JingleRTPDescription::MediaType JingleRTPDescriptionParser::mediaTypeFromString(const std::string& media) {
if (media == "audio") {
return JingleRTPDescription::Audio;
} else if (media == "video") {
diff --git a/Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.h b/Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.h
index d250754..6ffad45 100644
--- a/Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.h
+++ b/Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.h
@@ -11,28 +11,25 @@
#include <Swiften/Parser/PayloadParser.h>
namespace Swift {
-
-class PayloadParserFactoryCollection;
-
-class JingleRTPDescriptionParser : public GenericPayloadParser<JingleRTPDescription> {
- public:
- JingleRTPDescriptionParser(PayloadParserFactoryCollection* factories);
-
- virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes);
- virtual void handleEndElement(const std::string& element, const std::string& ns);
- virtual void handleCharacterData(const std::string& data);
-
- private:
- JingleRTPDescription::MediaType mediaTypeFromString(const std::string& media) const;
-
- private:
- PayloadParserFactoryCollection* factories;
- int level;
- //CurrentParseElement currentElement;
- boost::shared_ptr<PayloadParser> currentPayloadParser;
- bool parsingBandwidth;
- std::string bandwidthType;
- std::string bandwidthValue;
-};
-
+ class PayloadParserFactoryCollection;
+
+ class JingleRTPDescriptionParser : public GenericPayloadParser<JingleRTPDescription> {
+ public:
+ JingleRTPDescriptionParser(PayloadParserFactoryCollection* factories);
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes);
+ virtual void handleEndElement(const std::string& element, const std::string& ns);
+ virtual void handleCharacterData(const std::string& data);
+
+ private:
+ static JingleRTPDescription::MediaType mediaTypeFromString(const std::string& media);
+
+ private:
+ PayloadParserFactoryCollection* factories;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ bool parsingBandwidth;
+ std::string bandwidthType;
+ std::string bandwidthValue;
+ };
}