summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2014-10-24 09:57:13 (GMT)
committerSwift Review <review@swift.im>2014-10-30 18:55:14 (GMT)
commit8096f80861667381b777af774cfd446d6fc8cda8 (patch)
tree46d050b1e678609c241d162b06cc511fba698888 /Swiften/Parser
parent5cf50d46aed4d2dac333e5e3b3bc2f57f7a1b835 (diff)
downloadswift-8096f80861667381b777af774cfd446d6fc8cda8.zip
swift-8096f80861667381b777af774cfd446d6fc8cda8.tar.bz2
Brining XEP-0313 (MAM) implementation in line with version 3.0.
Added support for <fin/> element, including serializer/parsers and unit tests for them. Added more unit tests based on XEP examples for existing parsers. Removed unneccesarry includes from existing MAM implementation. Test-Information: Existing and new unit tests pass successfully. Change-Id: I7e6bf85e0961d59801b452e4559cc1db9e9e6ed8
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp4
-rw-r--r--Swiften/Parser/PayloadParsers/MAMArchivedParser.cpp38
-rw-r--r--Swiften/Parser/PayloadParsers/MAMFinParser.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/MAMFinParser.h (renamed from Swiften/Parser/PayloadParsers/MAMArchivedParser.h)12
-rw-r--r--Swiften/Parser/PayloadParsers/MAMQueryParser.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/MAMQueryParser.h3
-rw-r--r--Swiften/Parser/PayloadParsers/MAMResultParser.cpp3
-rw-r--r--Swiften/Parser/PayloadParsers/MAMResultParser.h2
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp35
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp47
-rw-r--r--Swiften/Parser/SConscript2
12 files changed, 180 insertions, 86 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index 49dd1e3..de7386b 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -46,7 +46,7 @@
#include <Swiften/Parser/PayloadParsers/JingleReasonParser.h>
#include <Swiften/Parser/PayloadParsers/JingleS5BTransportMethodPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/LastParser.h>
-#include <Swiften/Parser/PayloadParsers/MAMArchivedParser.h>
+#include <Swiften/Parser/PayloadParsers/MAMFinParser.h>
#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h>
#include <Swiften/Parser/PayloadParsers/MAMResultParser.h>
#include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h>
@@ -157,7 +157,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<ForwardedParser> >("forwarded", "urn:xmpp:forward:0", this));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<MAMResultParser> >("result", "urn:xmpp:mam:0", this));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMQueryParser> >("query", "urn:xmpp:mam:0"));
- factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMArchivedParser> >("archived", "urn:xmpp:mam:0"));
+ factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MAMFinParser> >("fin", "urn:xmpp:mam:0"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<IsodeIQDelegationParser> >("delegate", "http://isode.com/iq_delegation", this));
foreach(shared_ptr<PayloadParserFactory> factory, factories_) {
diff --git a/Swiften/Parser/PayloadParsers/MAMArchivedParser.cpp b/Swiften/Parser/PayloadParsers/MAMArchivedParser.cpp
deleted file mode 100644
index 616d41a..0000000
--- a/Swiften/Parser/PayloadParsers/MAMArchivedParser.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2014 Kevin Smith and Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include <boost/lexical_cast.hpp>
-#include <boost/optional.hpp>
-#include <Swiften/Base/DateTime.h>
-#include <Swiften/Parser/PayloadParserFactory.h>
-#include <Swiften/Parser/PayloadParserFactoryCollection.h>
-#include <Swiften/Parser/PayloadParsers/MAMArchivedParser.h>
-
-using namespace Swift;
-
-MAMArchivedParser::MAMArchivedParser() : level_(TopLevel) {
-}
-
-void MAMArchivedParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) {
- if (level_ == TopLevel) {
- boost::optional<std::string> attributeValue;
- if ((attributeValue = attributes.getAttributeValue("by"))) {
- getPayloadInternal()->setBy(*attributeValue);
- }
- if ((attributeValue = attributes.getAttributeValue("id"))) {
- getPayloadInternal()->setID(*attributeValue);
- }
- }
-
- ++level_;
-}
-
-void MAMArchivedParser::handleEndElement(const std::string&, const std::string&) {
- --level_;
-}
-
-void MAMArchivedParser::handleCharacterData(const std::string&) {
-}
diff --git a/Swiften/Parser/PayloadParsers/MAMFinParser.cpp b/Swiften/Parser/PayloadParsers/MAMFinParser.cpp
new file mode 100644
index 0000000..cab493b
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/MAMFinParser.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <boost/lexical_cast.hpp>
+#include <boost/optional.hpp>
+#include <Swiften/Base/DateTime.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParsers/ResultSetParser.h>
+#include <Swiften/Parser/PayloadParsers/MAMFinParser.h>
+
+using namespace Swift;
+
+MAMFinParser::MAMFinParser() : level_(TopLevel) {
+}
+
+void MAMFinParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level_ == TopLevel) {
+ getPayloadInternal()->setComplete(attributes.getBoolAttribute("complete", false));
+ getPayloadInternal()->setStable(attributes.getBoolAttribute("stable", true));
+ boost::optional<std::string> attributeValue;
+ if ((attributeValue = attributes.getAttributeValue("queryid"))) {
+ getPayloadInternal()->setQueryID(*attributeValue);
+ }
+ }
+ else if (level_ == PayloadLevel) {
+ if (element == "set" && ns == "http://jabber.org/protocol/rsm") {
+ resultSetParser_ = boost::make_shared<ResultSetParser>();
+ }
+ }
+
+ if (resultSetParser_) { /* parsing a nested ResultSet */
+ resultSetParser_->handleStartElement(element, ns, attributes);
+ }
+
+ ++level_;
+}
+
+void MAMFinParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level_;
+
+ if (resultSetParser_ && level_ >= PayloadLevel) {
+ resultSetParser_->handleEndElement(element, ns);
+ }
+ if (resultSetParser_ && level_ == PayloadLevel) {
+ /* done parsing nested ResultSet */
+ getPayloadInternal()->setResultSet(boost::dynamic_pointer_cast<ResultSet>(resultSetParser_->getPayload()));
+ resultSetParser_.reset();
+ }
+}
+
+void MAMFinParser::handleCharacterData(const std::string& data) {
+ if (resultSetParser_) {
+ resultSetParser_->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/MAMArchivedParser.h b/Swiften/Parser/PayloadParsers/MAMFinParser.h
index b92b41a..08a7f16 100644
--- a/Swiften/Parser/PayloadParsers/MAMArchivedParser.h
+++ b/Swiften/Parser/PayloadParsers/MAMFinParser.h
@@ -10,25 +10,27 @@
#include <Swiften/Base/Override.h>
#include <Swiften/Base/API.h>
-#include <Swiften/Elements/MAMArchived.h>
#include <Swiften/Parser/GenericPayloadParser.h>
+#include <Swiften/Elements/MAMFin.h>
namespace Swift {
- class PayloadParserFactoryCollection;
+ class ResultSetParser;
- class SWIFTEN_API MAMArchivedParser : public GenericPayloadParser<MAMArchived> {
+ class SWIFTEN_API MAMFinParser : public GenericPayloadParser<MAMFin> {
public:
- MAMArchivedParser();
+ MAMFinParser();
virtual void handleStartElement(const std::string& element, const std::string& ns, 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;
enum Level {
- TopLevel = 0
+ TopLevel = 0,
+ PayloadLevel = 1
};
private:
+ boost::shared_ptr<ResultSetParser> resultSetParser_;
int level_;
};
}
diff --git a/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp
index 9ae8e41..6b3dc65 100644
--- a/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp
+++ b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp
@@ -7,8 +7,6 @@
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include <Swiften/Base/DateTime.h>
-#include <Swiften/Parser/PayloadParserFactory.h>
-#include <Swiften/Parser/PayloadParserFactoryCollection.h>
#include <Swiften/Parser/PayloadParsers/FormParser.h>
#include <Swiften/Parser/PayloadParsers/ResultSetParser.h>
#include <Swiften/Parser/PayloadParsers/MAMQueryParser.h>
diff --git a/Swiften/Parser/PayloadParsers/MAMQueryParser.h b/Swiften/Parser/PayloadParsers/MAMQueryParser.h
index 7bbdacb..d160926 100644
--- a/Swiften/Parser/PayloadParsers/MAMQueryParser.h
+++ b/Swiften/Parser/PayloadParsers/MAMQueryParser.h
@@ -6,6 +6,8 @@
#pragma once
+#include <string>
+
#include <boost/shared_ptr.hpp>
#include <Swiften/Base/Override.h>
@@ -14,7 +16,6 @@
#include <Swiften/Parser/GenericPayloadParser.h>
namespace Swift {
- class PayloadParserFactoryCollection;
class ResultSetParser;
class FormParser;
diff --git a/Swiften/Parser/PayloadParsers/MAMResultParser.cpp b/Swiften/Parser/PayloadParsers/MAMResultParser.cpp
index e4eec3b..55db8ad 100644
--- a/Swiften/Parser/PayloadParsers/MAMResultParser.cpp
+++ b/Swiften/Parser/PayloadParsers/MAMResultParser.cpp
@@ -6,9 +6,8 @@
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
+
#include <Swiften/Base/DateTime.h>
-#include <Swiften/Parser/PayloadParserFactory.h>
-#include <Swiften/Parser/PayloadParserFactoryCollection.h>
#include <Swiften/Parser/PayloadParsers/ForwardedParser.h>
#include <Swiften/Parser/PayloadParsers/MAMResultParser.h>
diff --git a/Swiften/Parser/PayloadParsers/MAMResultParser.h b/Swiften/Parser/PayloadParsers/MAMResultParser.h
index 39ff20a..cb58732 100644
--- a/Swiften/Parser/PayloadParsers/MAMResultParser.h
+++ b/Swiften/Parser/PayloadParsers/MAMResultParser.h
@@ -6,6 +6,8 @@
#pragma once
+#include <string>
+
#include <boost/shared_ptr.hpp>
#include <Swiften/Base/Override.h>
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp
deleted file mode 100644
index 3e65cc6..0000000
--- a/Swiften/Parser/PayloadParsers/UnitTest/MAMArchivedParserTest.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2014 Kevin Smith and Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-
-#include <Swiften/Base/DateTime.h>
-#include <Swiften/Parser/PayloadParsers/MAMArchivedParser.h>
-#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
-
-using namespace Swift;
-
-class MAMArchivedParserTest : public CppUnit::TestFixture
-{
- CPPUNIT_TEST_SUITE(MAMArchivedParserTest);
- CPPUNIT_TEST(testParse);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void testParse() {
- PayloadsParserTester parser;
- CPPUNIT_ASSERT(parser.parse(
- "<archived by=\"juliet@capulet.lit\" id=\"28482-98726-73623\" xmlns=\"urn:xmpp:mam:0\"/>"));
-
- boost::shared_ptr<MAMArchived> payload = parser.getPayload<MAMArchived>();
- CPPUNIT_ASSERT(!!payload);
- CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit"), payload->getBy());
- CPPUNIT_ASSERT_EQUAL(std::string("28482-98726-73623"), payload->getID());
- }
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(MAMArchivedParserTest);
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp
new file mode 100644
index 0000000..3f7cdc9
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Elements/MAMFin.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+class MAMFinParserTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(MAMFinParserTest);
+ CPPUNIT_TEST(testParse_XEP0313_Exmaple1);
+ CPPUNIT_TEST(testParse_XEP0313_Exmaple9);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testParse_XEP0313_Exmaple1() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<fin xmlns='urn:xmpp:mam:0' queryid='f27' />"));
+
+ boost::shared_ptr<MAMFin> payload = parser.getPayload<MAMFin>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT_EQUAL(false, payload->isComplete());
+ CPPUNIT_ASSERT_EQUAL(true, payload->isStable());
+
+ boost::optional<std::string> queryID = payload->getQueryID();
+ CPPUNIT_ASSERT(queryID);
+ CPPUNIT_ASSERT_EQUAL(std::string("f27"), queryID.get());
+ }
+
+ void testParse_XEP0313_Exmaple9() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<fin xmlns='urn:xmpp:mam:0' complete='true'>"
+ "<set xmlns='http://jabber.org/protocol/rsm'>"
+ "<first index='0'>23452-4534-1</first>"
+ "<last>390-2342-22</last>"
+ "<count>16</count>"
+ "</set>"
+ "</fin>"));
+
+ boost::shared_ptr<MAMFin> payload = parser.getPayload<MAMFin>();
+ CPPUNIT_ASSERT(!!payload);
+ CPPUNIT_ASSERT_EQUAL(true, payload->isComplete());
+ CPPUNIT_ASSERT_EQUAL(true, payload->isStable());
+
+ CPPUNIT_ASSERT(!!payload->getResultSet());
+ boost::shared_ptr<ResultSet> resultSet = payload->getResultSet();
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MAMFinParserTest);
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp
index ddcd7c4..e1c8e3e 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp
+++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp
@@ -17,6 +17,8 @@ class MAMQueryParserTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(MAMQueryParserTest);
CPPUNIT_TEST(testParse);
+ CPPUNIT_TEST(testParse_XEP0313_Example3);
+ CPPUNIT_TEST(testParse_XEP0313_Example4);
CPPUNIT_TEST(testParseEmpty);
CPPUNIT_TEST_SUITE_END();
@@ -58,6 +60,49 @@ class MAMQueryParserTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(*resultSet->getMaxItems(), 10);
}
+ void testParse_XEP0313_Example3() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<query xmlns='urn:xmpp:mam:0'>"
+ "<x xmlns='jabber:x:data'>"
+ "<field var='FORM_TYPE'>"
+ "<value>urn:xmpp:mam:0</value>"
+ "</field>"
+ "<field var='with'>"
+ "<value>juliet@capulet.lit</value>"
+ "</field>"
+ "</x>"
+ "</query>"));
+
+ boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>();
+ CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("with"));
+ CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue());
+ CPPUNIT_ASSERT_EQUAL(std::string("juliet@capulet.lit"), payload->getForm()->getField("with")->getTextSingleValue());
+ }
+
+ void testParse_XEP0313_Example4() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<query xmlns='urn:xmpp:mam:0'>"
+ "<x xmlns='jabber:x:data'>"
+ "<field var='FORM_TYPE'>"
+ "<value>urn:xmpp:mam:0</value>"
+ "</field>"
+ "<field var='start'>"
+ "<value>2010-06-07T00:00:00Z</value>"
+ "</field>"
+ "<field var='end'>"
+ "<value>2010-07-07T13:23:54Z</value>"
+ "</field>"
+ "</x>"
+ "</query>"));
+ boost::shared_ptr<MAMQuery> payload = parser.getPayload<MAMQuery>();
+ CPPUNIT_ASSERT(!!payload && !!payload->getForm() && !!payload->getForm()->getField("FORM_TYPE") && !!payload->getForm()->getField("start") && !!payload->getForm()->getField("start"));
+ CPPUNIT_ASSERT_EQUAL(std::string("urn:xmpp:mam:0"), payload->getForm()->getField("FORM_TYPE")->getTextSingleValue());
+ CPPUNIT_ASSERT_EQUAL(std::string("2010-06-07T00:00:00Z"), payload->getForm()->getField("start")->getTextSingleValue());
+ CPPUNIT_ASSERT_EQUAL(std::string("2010-07-07T13:23:54Z"), payload->getForm()->getField("end")->getTextSingleValue());
+ }
+
void testParseEmpty() {
PayloadsParserTester parser;
CPPUNIT_ASSERT(parser.parse(
@@ -71,6 +116,8 @@ class MAMQueryParserTest : public CppUnit::TestFixture
CPPUNIT_ASSERT(!payload->getForm());
CPPUNIT_ASSERT(!payload->getResultSet());
}
+
+
};
CPPUNIT_TEST_SUITE_REGISTRATION(MAMQueryParserTest);
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index e748320..94ea6d3 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -79,9 +79,9 @@ sources = [
"PayloadParsers/PubSubErrorParserFactory.cpp",
"PayloadParsers/ResultSetParser.cpp",
"PayloadParsers/ForwardedParser.cpp",
+ "PayloadParsers/MAMFinParser.cpp",
"PayloadParsers/MAMResultParser.cpp",
"PayloadParsers/MAMQueryParser.cpp",
- "PayloadParsers/MAMArchivedParser.cpp",
"PayloadParsers/IsodeIQDelegationParser.cpp",
"PlatformXMLParserFactory.cpp",
"PresenceParser.cpp",