From 6948ef81d66680858b88b1bc7dc67687310f57cf Mon Sep 17 00:00:00 2001 From: Edwin Mons <edwin.mons@isode.com> Date: Wed, 10 Dec 2014 16:50:27 +0000 Subject: Add index element to ResultSet The index element was missing, added it in Swiften and Sluift. Change-Id: I709037fafcc5242c7c2e2fddb8469316c106d51a diff --git a/Sluift/ElementConvertors/ResultSetConvertor.cpp b/Sluift/ElementConvertors/ResultSetConvertor.cpp index bd517b3..f5df2bd 100644 --- a/Sluift/ElementConvertors/ResultSetConvertor.cpp +++ b/Sluift/ElementConvertors/ResultSetConvertor.cpp @@ -33,6 +33,11 @@ boost::shared_ptr<ResultSet> ResultSetConvertor::doConvertFromLua(lua_State* L) result->setCount(boost::numeric_cast<int>(lua_tonumber(L, -1))); } lua_pop(L, 1); + lua_getfield(L, -1, "index"); + if (lua_isnumber(L, -1)) { + result->setIndex(boost::numeric_cast<int>(lua_tonumber(L, -1))); + } + lua_pop(L, 1); lua_getfield(L, -1, "first_id_index"); if (lua_isstring(L, -1)) { result->setFirstIDIndex(boost::numeric_cast<int>(lua_tonumber(L, -1))); @@ -71,6 +76,10 @@ void ResultSetConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<ResultSe lua_pushnumber(L, *payload->getCount()); lua_setfield(L, -2, "count"); } + if (payload->getIndex()) { + lua_pushnumber(L, *payload->getIndex()); + lua_setfield(L, -2, "index"); + } if (payload->getFirstIDIndex()) { lua_pushnumber(L, *payload->getFirstIDIndex()); lua_setfield(L, -2, "first_id_index"); diff --git a/Swiften/Elements/ResultSet.h b/Swiften/Elements/ResultSet.h index e84be35..b7c5574 100644 --- a/Swiften/Elements/ResultSet.h +++ b/Swiften/Elements/ResultSet.h @@ -21,6 +21,9 @@ namespace Swift { void setCount(const boost::optional<int>& count) { count_ = count; } const boost::optional<int>& getCount() const { return count_; } + void setIndex(const boost::optional<int>& index) { index_ = index; } + const boost::optional<int>& getIndex() const { return index_; } + void setFirstIDIndex(const boost::optional<int>& firstIndex) { firstIndex_ = firstIndex; } const boost::optional<int>& getFirstIDIndex() const { return firstIndex_; } @@ -36,9 +39,11 @@ namespace Swift { void setAfter(const boost::optional<std::string>& after) { after_ = after; } const boost::optional<std::string>& getAfter() const { return after_; } + private: boost::optional<int> maxItems_; boost::optional<int> count_; + boost::optional<int> index_; boost::optional<int> firstIndex_; boost::optional<std::string> firstID_; boost::optional<std::string> lastID_; diff --git a/Swiften/Parser/PayloadParsers/ResultSetParser.cpp b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp index 4c8283b..4829f98 100644 --- a/Swiften/Parser/PayloadParsers/ResultSetParser.cpp +++ b/Swiften/Parser/PayloadParsers/ResultSetParser.cpp @@ -43,6 +43,11 @@ void ResultSetParser::handleEndElement(const std::string& element, const std::st getPayloadInternal()->setCount(boost::lexical_cast<int>(currentText_)); } catch(boost::bad_lexical_cast&) { } + } else if (element == "index") { + try { + getPayloadInternal()->setIndex(boost::lexical_cast<int>(currentText_)); + } catch(boost::bad_lexical_cast&) { + } } else if (element == "first") { getPayloadInternal()->setFirstID(currentText_); } else if (element == "last") { diff --git a/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp index e345323..17d9eb2 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/ResultSetParserTest.cpp @@ -26,6 +26,7 @@ class ResultSetParserTest : public CppUnit::TestFixture "<set xmlns=\"http://jabber.org/protocol/rsm\">" "<max>100</max>" "<count>800</count>" + "<index>0</index>" "<first index=\"123\">stpeter@jabber.org</first>" "<last>peterpan@neverland.lit</last>" "<before>decaf-badba-dbad1</before>" @@ -38,6 +39,8 @@ class ResultSetParserTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL(100, *payload->getMaxItems()); CPPUNIT_ASSERT(payload->getCount()); CPPUNIT_ASSERT_EQUAL(800, *payload->getCount()); + CPPUNIT_ASSERT(payload->getIndex()); + CPPUNIT_ASSERT_EQUAL(0, *payload->getIndex()); CPPUNIT_ASSERT(payload->getFirstID()); CPPUNIT_ASSERT_EQUAL(std::string("stpeter@jabber.org"), *payload->getFirstID()); CPPUNIT_ASSERT(payload->getFirstIDIndex()); diff --git a/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp index 0f464a4..263c7de 100644 --- a/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/ResultSetSerializer.cpp @@ -33,6 +33,10 @@ std::string ResultSetSerializer::serializePayload(boost::shared_ptr<ResultSet> p element.addNode(boost::make_shared<XMLElement>("count", "", boost::lexical_cast<std::string>(*payload->getCount()))); } + if (payload->getIndex()) { + element.addNode(boost::make_shared<XMLElement>("index", "", boost::lexical_cast<std::string>(*payload->getIndex()))); + } + if (payload->getFirstID()) { boost::shared_ptr<XMLElement> firstElement = boost::make_shared<XMLElement>("first", "", *payload->getFirstID()); if (payload->getFirstIDIndex()) { diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp index 354db85..7431fcd 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp @@ -32,6 +32,7 @@ class ResultSetSerializerTest : public CppUnit::TestFixture { resultSet->setMaxItems(100); resultSet->setCount(800); + resultSet->setIndex(0); resultSet->setFirstIDIndex(123); resultSet->setFirstID(std::string("stpeter@jabber.org")); resultSet->setLastID(std::string("peterpan@neverland.lit")); @@ -42,6 +43,7 @@ class ResultSetSerializerTest : public CppUnit::TestFixture { "<set xmlns=\"http://jabber.org/protocol/rsm\">" "<max>100</max>" "<count>800</count>" + "<index>0</index>" "<first index=\"123\">stpeter@jabber.org</first>" "<last>peterpan@neverland.lit</last>" "<before>decaf-badba-dbad1</before>" -- cgit v0.10.2-6-g49f6