summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Base/DateTime.cpp25
-rw-r--r--Swiften/Base/DateTime.h17
-rw-r--r--Swiften/Base/SConscript1
-rw-r--r--Swiften/Parser/PayloadParsers/DelayParser.cpp17
-rw-r--r--Swiften/Parser/PayloadParsers/DelayParser.h6
-rw-r--r--Swiften/Parser/PayloadParsers/DelayParserFactory.cpp19
-rw-r--r--Swiften/Parser/PayloadParsers/DelayParserFactory.h30
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp4
-rw-r--r--Swiften/Parser/SConscript1
9 files changed, 49 insertions, 71 deletions
diff --git a/Swiften/Base/DateTime.cpp b/Swiften/Base/DateTime.cpp
new file mode 100644
index 0000000..1120938
--- /dev/null
+++ b/Swiften/Base/DateTime.cpp
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2011 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Base/DateTime.h>
+
+#include <locale>
+
+#include <boost/date_time/time_facet.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+namespace Swift {
+
+boost::posix_time::ptime stringToDateTime(const std::string& string) {
+ static std::locale locale(std::locale::classic(), new boost::posix_time::time_input_facet("%Y-%m-%d %H:%M:%S%F%Q"));
+ std::istringstream stream(string);
+ stream.imbue(locale);
+ boost::posix_time::ptime result(boost::posix_time::not_a_date_time);
+ stream >> result;
+ return result;
+}
+
+}
diff --git a/Swiften/Base/DateTime.h b/Swiften/Base/DateTime.h
new file mode 100644
index 0000000..309ee56
--- /dev/null
+++ b/Swiften/Base/DateTime.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2011 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <boost/date_time/posix_time/ptime.hpp>
+
+namespace Swift {
+ /**
+ * Converts a date formatted according to XEP-0082 into a time
+ * object.
+ */
+ boost::posix_time::ptime stringToDateTime(const std::string& string);
+}
diff --git a/Swiften/Base/SConscript b/Swiften/Base/SConscript
index 3279c22..8752ea8 100644
--- a/Swiften/Base/SConscript
+++ b/Swiften/Base/SConscript
@@ -2,6 +2,7 @@ Import("swiften_env")
objects = swiften_env.SwiftenObject([
"ByteArray.cpp",
+ "DateTime.cpp",
"SafeByteArray.cpp",
"Error.cpp",
"Log.cpp",
diff --git a/Swiften/Parser/PayloadParsers/DelayParser.cpp b/Swiften/Parser/PayloadParsers/DelayParser.cpp
index e2a6bad..e18d09d 100644
--- a/Swiften/Parser/PayloadParsers/DelayParser.cpp
+++ b/Swiften/Parser/PayloadParsers/DelayParser.cpp
@@ -6,27 +6,16 @@
#include <Swiften/Parser/PayloadParsers/DelayParser.h>
-#include <locale>
-
-#include <boost/date_time/time_facet.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
+#include <Swiften/Base/DateTime.h>
namespace Swift {
-DelayParser::DelayParser(const std::locale& locale) : locale(locale), level_(0) {
-}
-
-boost::posix_time::ptime DelayParser::dateFromString(const std::string& string) {
- std::istringstream stream(string);
- stream.imbue(locale);
- boost::posix_time::ptime result(boost::posix_time::not_a_date_time);
- stream >> result;
- return result;
+DelayParser::DelayParser() : level_(0) {
}
void DelayParser::handleStartElement(const std::string& /*element*/, const std::string& /*ns*/, const AttributeMap& attributes) {
if (level_ == 0) {
- boost::posix_time::ptime stamp = dateFromString(attributes.getAttribute("stamp"));
+ boost::posix_time::ptime stamp = stringToDateTime(attributes.getAttribute("stamp"));
getPayloadInternal()->setStamp(stamp);
if (!attributes.getAttribute("from").empty()) {
std::string from = attributes.getAttribute("from");
diff --git a/Swiften/Parser/PayloadParsers/DelayParser.h b/Swiften/Parser/PayloadParsers/DelayParser.h
index 02103d9..144220a 100644
--- a/Swiften/Parser/PayloadParsers/DelayParser.h
+++ b/Swiften/Parser/PayloadParsers/DelayParser.h
@@ -12,17 +12,13 @@
namespace Swift {
class DelayParser : public GenericPayloadParser<Delay> {
public:
- DelayParser(const std::locale& locale);
+ DelayParser();
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& data);
private:
- boost::posix_time::ptime dateFromString(const std::string& string);
-
- private:
- std::locale locale;
int level_;
};
}
diff --git a/Swiften/Parser/PayloadParsers/DelayParserFactory.cpp b/Swiften/Parser/PayloadParsers/DelayParserFactory.cpp
deleted file mode 100644
index 48841d2..0000000
--- a/Swiften/Parser/PayloadParsers/DelayParserFactory.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * 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/DelayParserFactory.h>
-
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/date_time/time_facet.hpp>
-
-namespace Swift {
-
-DelayParserFactory::DelayParserFactory() {
- boost::posix_time::time_input_facet* facet = new boost::posix_time::time_input_facet("%Y-%m-%d %H:%M:%S%F%Q");
- locale = std::locale(std::locale::classic(), facet);
-}
-
-}
diff --git a/Swiften/Parser/PayloadParsers/DelayParserFactory.h b/Swiften/Parser/PayloadParsers/DelayParserFactory.h
deleted file mode 100644
index 7dde35e..0000000
--- a/Swiften/Parser/PayloadParsers/DelayParserFactory.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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 std::string& /*element*/, const std::string& ns, const AttributeMap&) const {
- return ns == "urn:xmpp:delay";
- }
-
- virtual PayloadParser* createPayloadParser() {
- return new DelayParser(locale);
- }
-
- private:
- std::locale locale;
- };
-}
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index 88a7bb6..4b143fd 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -38,7 +38,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>
+#include <Swiften/Parser/PayloadParsers/DelayParser.h>
#include <Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h>
#include <Swiften/Parser/PayloadParsers/NicknameParserFactory.h>
#include <Swiften/Parser/PayloadParsers/ReplaceParser.h>
@@ -58,6 +58,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<SubjectParser>("subject")));
factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<PriorityParser>("priority")));
factories_.push_back(shared_ptr<PayloadParserFactory>(new ErrorParserFactory(this)));
+ factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<DelayParser>("delay", "urn:xmpp:delay")));
factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<SoftwareVersionParser>("query", "jabber:iq:version")));
factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<StorageParser>("storage", "storage:bookmarks")));
factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<RosterItemExchangeParser>("x", "http://jabber.org/protocol/rosterx")));
@@ -79,7 +80,6 @@ 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()));
factories_.push_back(shared_ptr<PayloadParserFactory>(new MUCUserPayloadParserFactory()));
factories_.push_back(shared_ptr<PayloadParserFactory>(new NicknameParserFactory()));
foreach(shared_ptr<PayloadParserFactory> factory, factories_) {
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index daa21be..17505f1 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -26,7 +26,6 @@ sources = [
"PayloadParsers/CapsInfoParser.cpp",
"PayloadParsers/DiscoInfoParser.cpp",
"PayloadParsers/DiscoItemsParser.cpp",
- "PayloadParsers/DelayParserFactory.cpp",
"PayloadParsers/ErrorParser.cpp",
"PayloadParsers/FormParser.cpp",
"PayloadParsers/IBBParser.cpp",