summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-04-20 09:43:31 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-04-23 10:52:55 (GMT)
commit6bd72c67896a20041556519548650590553f47c9 (patch)
tree20f6a3895647ad67adfe29ef688a618bf7c30a6a /Swiften/Parser
parentbfe07e82cd79d56f1327425ce3e6c8a84908421b (diff)
downloadswift-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/Parser')
-rw-r--r--Swiften/Parser/PayloadParsers/ChatStateParser.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/ChatStateParser.h2
-rw-r--r--Swiften/Parser/PayloadParsers/ChatStateParserFactory.h2
-rw-r--r--Swiften/Parser/PayloadParsers/DelayParser.cpp50
-rw-r--r--Swiften/Parser/PayloadParsers/DelayParser.h25
-rw-r--r--Swiften/Parser/PayloadParsers/DelayParserFactory.h29
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp2
-rw-r--r--Swiften/Parser/SConscript1
8 files changed, 110 insertions, 3 deletions
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",