summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-06-03 14:45:41 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-06-03 14:45:41 (GMT)
commitcdb0b448b9a64dc5144b1119236f63cadd99d79d (patch)
tree922a2c34d8c6ca63c8cd723e2871aeb76f5cf1f9 /Swiften
parentd513bcc4c33d23faaf2e48a82007ae2803d17acb (diff)
downloadswift-cdb0b448b9a64dc5144b1119236f63cadd99d79d.zip
swift-cdb0b448b9a64dc5144b1119236f63cadd99d79d.tar.bz2
Split off StreamResumedParser.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Parser/SConscript1
-rw-r--r--Swiften/Parser/StreamResumedParser.cpp36
-rw-r--r--Swiften/Parser/StreamResumedParser.h27
-rw-r--r--Swiften/Parser/XMPPParser.cpp3
4 files changed, 66 insertions, 1 deletions
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index fe5bfb1..daa21be 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -63,6 +63,7 @@ sources = [
"StreamFeaturesParser.cpp",
"StreamManagementEnabledParser.cpp",
"StreamResumeParser.cpp",
+ "StreamResumedParser.cpp",
"XMLParser.cpp",
"XMLParserClient.cpp",
"XMLParserFactory.cpp",
diff --git a/Swiften/Parser/StreamResumedParser.cpp b/Swiften/Parser/StreamResumedParser.cpp
new file mode 100644
index 0000000..4b39c04
--- /dev/null
+++ b/Swiften/Parser/StreamResumedParser.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2011 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Parser/StreamResumedParser.h>
+
+#include <boost/lexical_cast.hpp>
+
+using namespace Swift;
+
+StreamResumedParser::StreamResumedParser() : level(TopLevel) {
+}
+
+StreamResumedParser::~StreamResumedParser() {
+}
+
+void StreamResumedParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) {
+ if (level == TopLevel) {
+ boost::optional<std::string> handledStanzasCount = attributes.getAttributeValue("h");
+ if (handledStanzasCount) {
+ try {
+ getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<unsigned int>(*handledStanzasCount));
+ }
+ catch (const boost::bad_lexical_cast &) {
+ }
+ }
+ getElementGeneric()->setResumeID(attributes.getAttribute("previd"));
+ }
+ ++level;
+}
+
+void StreamResumedParser::handleEndElement(const std::string&, const std::string&) {
+ --level;
+}
diff --git a/Swiften/Parser/StreamResumedParser.h b/Swiften/Parser/StreamResumedParser.h
new file mode 100644
index 0000000..f2377aa
--- /dev/null
+++ b/Swiften/Parser/StreamResumedParser.h
@@ -0,0 +1,27 @@
+/*
+ * 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 <Swiften/Parser/GenericElementParser.h>
+#include <Swiften/Elements/StreamResumed.h>
+
+namespace Swift {
+ class StreamResumedParser : public GenericElementParser<StreamResumed> {
+ public:
+ StreamResumedParser();
+ ~StreamResumedParser();
+
+ virtual void handleStartElement(const std::string&, const std::string&, const AttributeMap&);
+ virtual void handleEndElement(const std::string&, const std::string&);
+
+ private:
+ enum Level {
+ TopLevel = 0
+ };
+ int level;
+ };
+}
diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp
index 62e1630..6779b86 100644
--- a/Swiften/Parser/XMPPParser.cpp
+++ b/Swiften/Parser/XMPPParser.cpp
@@ -30,6 +30,7 @@
#include <Swiften/Parser/StreamManagementEnabledParser.h>
#include <Swiften/Parser/StreamManagementFailedParser.h>
#include <Swiften/Parser/StreamResumeParser.h>
+#include <Swiften/Parser/StreamResumedParser.h>
#include <Swiften/Parser/StanzaAckParser.h>
#include <Swiften/Parser/StanzaAckRequestParser.h>
#include <Swiften/Parser/StartTLSParser.h>
@@ -187,7 +188,7 @@ ElementParser* XMPPParser::createElementParser(const std::string& element, const
return new StreamResumeParser();
}
else if (element == "resumed" && ns == "urn:xmpp:sm:2") {
- return new StreamResumeParser();
+ return new StreamResumedParser();
}
else if (element == "a" && ns == "urn:xmpp:sm:2") {
return new StanzaAckParser();