From 6948ef81d66680858b88b1bc7dc67687310f57cf Mon Sep 17 00:00:00 2001 From: Edwin Mons 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 ResultSetConvertor::doConvertFromLua(lua_State* L) result->setCount(boost::numeric_cast(lua_tonumber(L, -1))); } lua_pop(L, 1); + lua_getfield(L, -1, "index"); + if (lua_isnumber(L, -1)) { + result->setIndex(boost::numeric_cast(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(lua_tonumber(L, -1))); @@ -71,6 +76,10 @@ void ResultSetConvertor::doConvertToLua(lua_State* L, boost::shared_ptrgetCount()); 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& count) { count_ = count; } const boost::optional& getCount() const { return count_; } + void setIndex(const boost::optional& index) { index_ = index; } + const boost::optional& getIndex() const { return index_; } + void setFirstIDIndex(const boost::optional& firstIndex) { firstIndex_ = firstIndex; } const boost::optional& getFirstIDIndex() const { return firstIndex_; } @@ -36,9 +39,11 @@ namespace Swift { void setAfter(const boost::optional& after) { after_ = after; } const boost::optional& getAfter() const { return after_; } + private: boost::optional maxItems_; boost::optional count_; + boost::optional index_; boost::optional firstIndex_; boost::optional firstID_; boost::optional 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(currentText_)); } catch(boost::bad_lexical_cast&) { } + } else if (element == "index") { + try { + getPayloadInternal()->setIndex(boost::lexical_cast(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 "" "100" "800" + "0" "stpeter@jabber.org" "peterpan@neverland.lit" "decaf-badba-dbad1" @@ -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 p element.addNode(boost::make_shared("count", "", boost::lexical_cast(*payload->getCount()))); } + if (payload->getIndex()) { + element.addNode(boost::make_shared("index", "", boost::lexical_cast(*payload->getIndex()))); + } + if (payload->getFirstID()) { boost::shared_ptr firstElement = boost::make_shared("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 { "" "100" "800" + "0" "stpeter@jabber.org" "peterpan@neverland.lit" "decaf-badba-dbad1" -- cgit v0.10.2-6-g49f6