summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2014-01-19 11:46:51 (GMT)
committerRemko Tronçon <git@el-tramo.be>2014-01-19 16:49:19 (GMT)
commitcbd01a5368f0b761d2032d75c9f7dfde2bf61578 (patch)
tree5016505b1e977e84655cc3bba4435ef7cb80e811 /Swiften
parent4083d6da47ac0e3b77da9c7c222a9439b3e1c04c (diff)
downloadswift-cbd01a5368f0b761d2032d75c9f7dfde2bf61578.zip
swift-cbd01a5368f0b761d2032d75c9f7dfde2bf61578.tar.bz2
Sluift: Add iTunes & PEP User Tune support
Change-Id: I25b3840bb40ce38531922cc737bc82828e026d3f
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Elements/UserTune.cpp15
-rw-r--r--Swiften/Elements/UserTune.h91
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp4
-rw-r--r--Swiften/Parser/PayloadParsers/UserTuneParser.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/UserTuneParser.h31
-rw-r--r--Swiften/Parser/SConscript1
-rw-r--r--Swiften/SConscript2
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp4
-rw-r--r--Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp48
-rw-r--r--Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h19
10 files changed, 272 insertions, 2 deletions
diff --git a/Swiften/Elements/UserTune.cpp b/Swiften/Elements/UserTune.cpp
new file mode 100644
index 0000000..e4c0241
--- /dev/null
+++ b/Swiften/Elements/UserTune.cpp
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2014 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Swiften/Elements/UserTune.h>
+
+using namespace Swift;
+
+UserTune::UserTune() {
+}
+
+UserTune::~UserTune() {
+}
diff --git a/Swiften/Elements/UserTune.h b/Swiften/Elements/UserTune.h
new file mode 100644
index 0000000..5e0999a
--- /dev/null
+++ b/Swiften/Elements/UserTune.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2014 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/Payload.h>
+#include <boost/optional.hpp>
+#include <string>
+
+
+
+namespace Swift {
+ class SWIFTEN_API UserTune : public Payload {
+ public:
+
+ UserTune();
+
+ virtual ~UserTune();
+
+ const boost::optional< unsigned int >& getRating() const {
+ return rating;
+ }
+
+ void setRating(const boost::optional< unsigned int >& value) {
+ this->rating = value ;
+ }
+
+ const boost::optional< std::string >& getTitle() const {
+ return title;
+ }
+
+ void setTitle(const boost::optional< std::string >& value) {
+ this->title = value ;
+ }
+
+ const boost::optional< std::string >& getTrack() const {
+ return track;
+ }
+
+ void setTrack(const boost::optional< std::string >& value) {
+ this->track = value ;
+ }
+
+ const boost::optional< std::string >& getArtist() const {
+ return artist;
+ }
+
+ void setArtist(const boost::optional< std::string >& value) {
+ this->artist = value ;
+ }
+
+ const boost::optional< std::string >& getURI() const {
+ return uri;
+ }
+
+ void setURI(const boost::optional< std::string >& value) {
+ this->uri = value ;
+ }
+
+ const boost::optional< std::string >& getSource() const {
+ return source;
+ }
+
+ void setSource(const boost::optional< std::string >& value) {
+ this->source = value ;
+ }
+
+ const boost::optional< unsigned int >& getLength() const {
+ return length;
+ }
+
+ void setLength(const boost::optional< unsigned int >& value) {
+ this->length = value ;
+ }
+
+
+ private:
+ boost::optional< unsigned int > rating;
+ boost::optional< std::string > title;
+ boost::optional< std::string > track;
+ boost::optional< std::string > artist;
+ boost::optional< std::string > uri;
+ boost::optional< std::string > source;
+ boost::optional< unsigned int > length;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index 3ec5a7a..22019b4 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2013 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -75,6 +75,7 @@
#include <Swiften/Parser/PayloadParsers/PubSubEventParser.h>
#include <Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h>
#include <Swiften/Parser/PayloadParsers/UserLocationParser.h>
+#include <Swiften/Parser/PayloadParsers/UserTuneParser.h>
using namespace boost;
@@ -135,6 +136,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<S5BProxyRequestParser> >("query", "http://jabber.org/protocol/bytestreams"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<WhiteboardParser> >("wb", "http://swift.im/whiteboard"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<UserLocationParser> >("geoloc", "http://jabber.org/protocol/geoloc"));
+ factories_.push_back(boost::make_shared<GenericPayloadParserFactory<UserTuneParser> >("tune", "http://jabber.org/protocol/tune"));
factories_.push_back(boost::make_shared<DeliveryReceiptParserFactory>());
factories_.push_back(boost::make_shared<DeliveryReceiptRequestParserFactory>());
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<IdleParser> >("idle", "urn:xmpp:idle:1"));
diff --git a/Swiften/Parser/PayloadParsers/UserTuneParser.cpp b/Swiften/Parser/PayloadParsers/UserTuneParser.cpp
new file mode 100644
index 0000000..bb299e4
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UserTuneParser.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/UserTuneParser.h>
+
+#include <boost/lexical_cast.hpp>
+
+using namespace Swift;
+
+UserTuneParser::UserTuneParser() : level(0) {
+}
+
+UserTuneParser::~UserTuneParser() {
+}
+
+void UserTuneParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) {
+ if (level == 1) {
+ currentText = "";
+ }
+ ++level;
+}
+
+void UserTuneParser::handleEndElement(const std::string& element, const std::string&) {
+ --level;
+ if (level == 1) {
+ try {
+ if (element == "artist") {
+ getPayloadInternal()->setArtist(currentText);
+ }
+ else if (element == "length") {
+ getPayloadInternal()->setLength(boost::lexical_cast<unsigned int>(currentText));
+ }
+ else if (element == "rating") {
+ getPayloadInternal()->setRating(boost::lexical_cast<unsigned int>(currentText));
+ }
+ else if (element == "source") {
+ getPayloadInternal()->setSource(currentText);
+ }
+ else if (element == "title") {
+ getPayloadInternal()->setTitle(currentText);
+ }
+ else if (element == "track") {
+ getPayloadInternal()->setTrack(currentText);
+ }
+ else if (element == "URI") {
+ getPayloadInternal()->setURI(currentText);
+ }
+ }
+ catch (const boost::bad_lexical_cast&) {
+ }
+ }
+}
+
+void UserTuneParser::handleCharacterData(const std::string& data) {
+ currentText += data;
+}
diff --git a/Swiften/Parser/PayloadParsers/UserTuneParser.h b/Swiften/Parser/PayloadParsers/UserTuneParser.h
new file mode 100644
index 0000000..1cfadea
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UserTuneParser.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+#include <string>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+#include <Swiften/Elements/UserTune.h>
+
+namespace Swift {
+ class SWIFTEN_API UserTuneParser : public GenericPayloadParser<UserTune> {
+ public:
+ UserTuneParser();
+ virtual ~UserTuneParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ int level;
+ std::string currentText;
+ };
+}
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index 0a6972e..4d6db11 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -74,6 +74,7 @@ sources = [
"PayloadParsers/DeliveryReceiptParser.cpp",
"PayloadParsers/DeliveryReceiptRequestParser.cpp",
"PayloadParsers/UserLocationParser.cpp",
+ "PayloadParsers/UserTuneParser.cpp",
"PayloadParsers/WhiteboardParser.cpp",
"PayloadParsers/PubSubErrorParserFactory.cpp",
"PlatformXMLParserFactory.cpp",
diff --git a/Swiften/SConscript b/Swiften/SConscript
index 75944f0..b5e13a9 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -137,6 +137,7 @@ if env["SCONS_STAGE"] == "build" :
"Elements/StreamResume.cpp",
"Elements/StreamResumed.cpp",
"Elements/UserLocation.cpp",
+ "Elements/UserTune.cpp",
"Elements/VCard.cpp",
"Elements/MUCOccupant.cpp",
"Entity/Entity.cpp",
@@ -215,6 +216,7 @@ if env["SCONS_STAGE"] == "build" :
"Serializer/PayloadSerializers/DeliveryReceiptSerializer.cpp",
"Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.cpp",
"Serializer/PayloadSerializers/UserLocationSerializer.cpp",
+ "Serializer/PayloadSerializers/UserTuneSerializer.cpp",
"Serializer/PayloadSerializers/WhiteboardSerializer.cpp",
"Serializer/PresenceSerializer.cpp",
"Serializer/StanzaSerializer.cpp",
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index a57a74e..16c79d5 100644
--- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2013 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -52,6 +52,7 @@
#include <Swiften/Serializer/PayloadSerializers/LastSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/IdleSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubOwnerPubSubSerializer.h>
@@ -117,6 +118,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new LastSerializer());
serializers_.push_back(new WhiteboardSerializer());
serializers_.push_back(new UserLocationSerializer());
+ serializers_.push_back(new UserTuneSerializer());
serializers_.push_back(new IdleSerializer());
serializers_.push_back(new StreamInitiationFileInfoSerializer());
diff --git a/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp
new file mode 100644
index 0000000..6c7799e
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2014 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h>
+
+#include <boost/shared_ptr.hpp>
+#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 {
+
+UserTuneSerializer::UserTuneSerializer() {
+}
+
+std::string UserTuneSerializer::serializePayload(
+ boost::shared_ptr<UserTune> payload) const {
+ XMLElement result("tune", "http://jabber.org/protocol/tune");
+ if (boost::optional<std::string> value = payload->getArtist()) {
+ result.addNode(boost::make_shared<XMLElement>("artist", "", *value));
+ }
+ if (boost::optional<unsigned int> value = payload->getLength()) {
+ result.addNode(boost::make_shared<XMLElement>("length", "", boost::lexical_cast<std::string>(*value)));
+ }
+ if (boost::optional<unsigned int> value = payload->getRating()) {
+ result.addNode(boost::make_shared<XMLElement>("rating", "", boost::lexical_cast<std::string>(*value)));
+ }
+ if (boost::optional<std::string> value = payload->getSource()) {
+ result.addNode(boost::make_shared<XMLElement>("source", "", *value));
+ }
+ if (boost::optional<std::string> value = payload->getTitle()) {
+ result.addNode(boost::make_shared<XMLElement>("title", "", *value));
+ }
+ if (boost::optional<std::string> value = payload->getTrack()) {
+ result.addNode(boost::make_shared<XMLElement>("track", "", *value));
+ }
+ if (boost::optional<std::string> value = payload->getURI()) {
+ result.addNode(boost::make_shared<XMLElement>("uri", "", *value));
+ }
+ return result.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h
new file mode 100644
index 0000000..8c20cbd
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2014 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+#include <Swiften/Elements/UserTune.h>
+
+namespace Swift {
+ class UserTuneSerializer : public GenericPayloadSerializer<UserTune> {
+ public:
+ UserTuneSerializer();
+
+ virtual std::string serializePayload(boost::shared_ptr<UserTune>) const;
+ };
+}