diff options
author | Kevin Smith <git@kismith.co.uk> | 2010-04-20 09:43:31 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2010-04-23 10:52:55 (GMT) |
commit | 6bd72c67896a20041556519548650590553f47c9 (patch) | |
tree | 20f6a3895647ad67adfe29ef688a618bf7c30a6a /Swiften | |
parent | bfe07e82cd79d56f1327425ce3e6c8a84908421b (diff) | |
download | swift-6bd72c67896a20041556519548650590553f47c9.zip swift-6bd72c67896a20041556519548650590553f47c9.tar.bz2 |
Add XEP-0203 (Delay) support.
Puts delay warnings in the chat log. Not optional yet.
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Elements/ChatState.h | 2 | ||||
-rw-r--r-- | Swiften/Elements/Delay.h | 31 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/ChatStateParser.cpp | 2 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/ChatStateParser.h | 2 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/ChatStateParserFactory.h | 2 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/DelayParser.cpp | 50 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/DelayParser.h | 25 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/DelayParserFactory.h | 29 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp | 2 | ||||
-rw-r--r-- | Swiften/Parser/SConscript | 1 | ||||
-rw-r--r-- | Swiften/SConscript | 1 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp | 30 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/DelaySerializer.h | 21 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp | 2 |
14 files changed, 196 insertions, 4 deletions
diff --git a/Swiften/Elements/ChatState.h b/Swiften/Elements/ChatState.h index a6b4d9b..8dcf77c 100644 --- a/Swiften/Elements/ChatState.h +++ b/Swiften/Elements/ChatState.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ diff --git a/Swiften/Elements/Delay.h b/Swiften/Elements/Delay.h new file mode 100644 index 0000000..f59d729 --- /dev/null +++ b/Swiften/Elements/Delay.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/optional.hpp> + +#include "Swiften/Elements/Payload.h" +#include "Swiften/JID/JID.h" + +namespace Swift { + class Delay : public Payload { + public: + Delay() {}; + Delay(const boost::posix_time::ptime& time, const JID& from) : time_(time), from_(from) {}; + + const boost::posix_time::ptime& getStamp() const {return time_;}; + void setStamp(const boost::posix_time::ptime& time) {time_ = time;}; + + const boost::optional<JID>& getFrom() const {return from_;}; + void setFrom(const JID& from) {from_ = from;}; + + private: + boost::posix_time::ptime time_; + boost::optional<JID> from_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/ChatStateParser.cpp b/Swiften/Parser/PayloadParsers/ChatStateParser.cpp index ef1f930..db205dd 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParser.cpp +++ b/Swiften/Parser/PayloadParsers/ChatStateParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ diff --git a/Swiften/Parser/PayloadParsers/ChatStateParser.h b/Swiften/Parser/PayloadParsers/ChatStateParser.h index 4ca2f4d..2ae4e43 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParser.h +++ b/Swiften/Parser/PayloadParsers/ChatStateParser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ diff --git a/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h b/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h index a2eff2f..27d3c51 100644 --- a/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h +++ b/Swiften/Parser/PayloadParsers/ChatStateParserFactory.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ diff --git a/Swiften/Parser/PayloadParsers/DelayParser.cpp b/Swiften/Parser/PayloadParsers/DelayParser.cpp new file mode 100644 index 0000000..a416ac1 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/DelayParser.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/Parser/PayloadParsers/DelayParser.h" + +#include <locale> +#include <iostream> + +#include <boost/date_time/time_facet.hpp> + +namespace Swift { + +DelayParser::DelayParser() : level_(0) { +} + +boost::posix_time::ptime DelayParser::dateFromString(const String& string) { + boost::posix_time::time_input_facet* facet = new boost::posix_time::time_input_facet("%Y-%m-%d %H:%M:%S%F%Q"); + boost::posix_time::ptime result(boost::posix_time::not_a_date_time); + std::locale dateLocale(std::locale::classic(), facet); + std::istringstream stream(string.getUTF8String()); + stream.imbue(dateLocale); + stream >> result; + return result; +} + +void DelayParser::handleStartElement(const String& /*element*/, const String& /*ns*/, const AttributeMap& attributes) { + if (level_ == 0) { + boost::posix_time::ptime stamp = dateFromString(attributes.getAttribute("stamp")); + getPayloadInternal()->setStamp(stamp); + if (!attributes.getAttribute("from").isEmpty()) { + std::cout << attributes.getAttribute("from"); + String from = attributes.getAttribute("from"); + getPayloadInternal()->setFrom(JID(from)); + } + } + ++level_; +} + +void DelayParser::handleEndElement(const String&, const String&) { + --level_; +} + +void DelayParser::handleCharacterData(const String&) { + +} + +} diff --git a/Swiften/Parser/PayloadParsers/DelayParser.h b/Swiften/Parser/PayloadParsers/DelayParser.h new file mode 100644 index 0000000..ce92dc2 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/DelayParser.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Elements/Delay.h" +#include "Swiften/Parser/GenericPayloadParser.h" + +namespace Swift { + class DelayParser : public GenericPayloadParser<Delay> { + public: + DelayParser(); + + virtual void handleStartElement(const String& element, const String&, const AttributeMap& attributes); + virtual void handleEndElement(const String& element, const String&); + virtual void handleCharacterData(const String& data); + + private: + boost::posix_time::ptime dateFromString(const String& string); + int level_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/DelayParserFactory.h b/Swiften/Parser/PayloadParsers/DelayParserFactory.h new file mode 100644 index 0000000..8b1f91e --- /dev/null +++ b/Swiften/Parser/PayloadParsers/DelayParserFactory.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Parser/PayloadParserFactory.h" +#include "Swiften/Parser/PayloadParsers/DelayParser.h" + +namespace Swift { + class PayloadParserFactoryCollection; + + class DelayParserFactory : public PayloadParserFactory { + public: + DelayParserFactory() { + } + + virtual bool canParse(const String& /*element*/, const String& ns, const AttributeMap&) const { + return ns == "urn:xmpp:delay"; + } + + virtual PayloadParser* createPayloadParser() { + return new DelayParser(); + } + + }; +} diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index b2fd54c..b0e4eb2 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -26,6 +26,7 @@ #include "Swiften/Parser/PayloadParsers/VCardParserFactory.h" #include "Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h" #include "Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h" +#include "Swiften/Parser/PayloadParsers/DelayParserFactory.h" using namespace boost; @@ -49,6 +50,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(shared_ptr<PayloadParserFactory>(new VCardParserFactory())); factories_.push_back(shared_ptr<PayloadParserFactory>(new PrivateStorageParserFactory(this))); factories_.push_back(shared_ptr<PayloadParserFactory>(new ChatStateParserFactory())); + factories_.push_back(shared_ptr<PayloadParserFactory>(new DelayParserFactory())); foreach(shared_ptr<PayloadParserFactory> factory, factories_) { addFactory(factory.get()); } diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index 7d93d8b..0d3aad2 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -35,6 +35,7 @@ sources = [ "PayloadParsers/StatusShowParser.cpp", "PayloadParsers/VCardParser.cpp", "PayloadParsers/VCardUpdateParser.cpp", + "PayloadParsers/DelayParser.cpp", "PlatformXMLParserFactory.cpp", "PresenceParser.cpp", "SerializingParser.cpp", diff --git a/Swiften/SConscript b/Swiften/SConscript index edc1885..a3426db 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -80,6 +80,7 @@ if env["SCONS_STAGE"] == "build" : "Serializer/PayloadSerializers/VCardUpdateSerializer.cpp", "Serializer/PayloadSerializers/StorageSerializer.cpp", "Serializer/PayloadSerializers/PrivateStorageSerializer.cpp", + "Serializer/PayloadSerializers/DelaySerializer.cpp", "Serializer/PresenceSerializer.cpp", "Serializer/StanzaSerializer.cpp", "Serializer/StreamFeaturesSerializer.cpp", diff --git a/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp b/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp new file mode 100644 index 0000000..041165f --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/DelaySerializer.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/Serializer/PayloadSerializers/DelaySerializer.h" + +#include <boost/shared_ptr.hpp> + +#include "Swiften/Serializer/XML/XMLElement.h" + +namespace Swift { + +DelaySerializer::DelaySerializer() : GenericPayloadSerializer<Delay>() { +} + +String DelaySerializer::serializePayload(boost::shared_ptr<Delay> delay) const { + XMLElement delayElement("delay", "urn:xmpp:delay"); + if (delay->getFrom()) { + delayElement.setAttribute("from", delay->getFrom()->toString()); + } + String stampString = String(boost::posix_time::to_iso_extended_string(delay->getStamp())); + stampString.replaceAll(',', "."); + stampString += "Z"; + delayElement.setAttribute("stamp", stampString); + return delayElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/DelaySerializer.h b/Swiften/Serializer/PayloadSerializers/DelaySerializer.h new file mode 100644 index 0000000..949b084 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/DelaySerializer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010 Kevin Smith + * 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/Delay.h" + +namespace Swift { + class DelaySerializer : public GenericPayloadSerializer<Delay> { + public: + DelaySerializer(); + + virtual String serializePayload(boost::shared_ptr<Delay>) const; + }; +} + + diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 8c83c09..8dc9d86 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -27,6 +27,7 @@ #include "Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h" #include "Swiften/Serializer/PayloadSerializers/StorageSerializer.h" #include "Swiften/Serializer/PayloadSerializers/PrivateStorageSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/DelaySerializer.h" namespace Swift { @@ -50,6 +51,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new VCardUpdateSerializer()); serializers_.push_back(new RawXMLPayloadSerializer()); serializers_.push_back(new StorageSerializer()); + serializers_.push_back(new DelaySerializer()); serializers_.push_back(new PrivateStorageSerializer(this)); foreach(PayloadSerializer* serializer, serializers_) { addSerializer(serializer); |