diff options
6 files changed, 25 insertions, 2 deletions
diff --git a/Sluift/ElementConvertors/MAMQueryConvertor.cpp b/Sluift/ElementConvertors/MAMQueryConvertor.cpp index cf4f787..6217eb7 100644 --- a/Sluift/ElementConvertors/MAMQueryConvertor.cpp +++ b/Sluift/ElementConvertors/MAMQueryConvertor.cpp @@ -31,6 +31,11 @@ boost::shared_ptr<MAMQuery> MAMQueryConvertor::doConvertFromLua(lua_State* L) { result->setQueryID(std::string(lua_tostring(L, -1))); } lua_pop(L, 1); + lua_getfield(L, -1, "node"); + if (lua_isstring(L, -1)) { + result->setNode(std::string(lua_tostring(L, -1))); + } + lua_pop(L, 1); lua_getfield(L, -1, "form"); if (!lua_isnil(L, -1)) { boost::shared_ptr<Form> form = boost::dynamic_pointer_cast<Form>(convertors->convertFromLuaUntyped(L, -1, "form")); @@ -56,6 +61,10 @@ void MAMQueryConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<MAMQuery> lua_pushstring(L, (*payload->getQueryID()).c_str()); lua_setfield(L, -2, "query_id"); } + if (payload->getNode()) { + lua_pushstring(L, (*payload->getNode()).c_str()); + lua_setfield(L, -2, "node"); + } if (convertors->convertToLuaUntyped(L, payload->getForm()) > 0) { lua_setfield(L, -2, "form"); } @@ -69,6 +78,7 @@ boost::optional<LuaElementConvertor::Documentation> MAMQueryConvertor::getDocume "MAMQuery", "This table has the following fields:\n\n" "- `query_id`: string (Optional)\n" + "- `node`: string (Optional)\n" "- `form`: string @{Form} (Optional)\n" "- `result_set`: @{ResultSet} (Optional)\n" ); diff --git a/Swiften/Elements/MAMQuery.h b/Swiften/Elements/MAMQuery.h index 09b5af0..12148c8 100644 --- a/Swiften/Elements/MAMQuery.h +++ b/Swiften/Elements/MAMQuery.h @@ -24,6 +24,9 @@ namespace Swift { void setQueryID(const boost::optional<std::string>& queryID) { queryID_ = queryID; } const boost::optional<std::string>& getQueryID() const { return queryID_; } + void setNode(const boost::optional<std::string>& node) { node_ = node; } + const boost::optional<std::string>& getNode() const { return node_; } + void setForm(boost::shared_ptr<Form> form) { form_ = form; } const boost::shared_ptr<Form>& getForm() const { return form_; } @@ -32,6 +35,7 @@ namespace Swift { private: boost::optional<std::string> queryID_; + boost::optional<std::string> node_; boost::shared_ptr<Form> form_; boost::shared_ptr<ResultSet> resultSet_; }; diff --git a/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp index 6b3dc65..b0b279d 100644 --- a/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp +++ b/Swiften/Parser/PayloadParsers/MAMQueryParser.cpp @@ -22,6 +22,9 @@ void MAMQueryParser::handleStartElement(const std::string& element, const std::s if ((attributeValue = attributes.getAttributeValue("queryid"))) { getPayloadInternal()->setQueryID(*attributeValue); } + if ((attributeValue = attributes.getAttributeValue("node"))) { + getPayloadInternal()->setNode(*attributeValue); + } } else if (level_ == PayloadLevel) { if (element == "x" && ns == "jabber:x:data") { formParser_ = boost::make_shared<FormParser>(); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp index e1c8e3e..541f2af 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp @@ -26,7 +26,7 @@ class MAMQueryParserTest : public CppUnit::TestFixture void testParse() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( - "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">" + "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\" node=\"node1\">" "<x type=\"form\" xmlns=\"jabber:x:data\">" "<field type=\"text-single\" var=\"FORM_TYPE\">" "<value>urn:xmpp:mam:0</value>" @@ -45,6 +45,7 @@ class MAMQueryParserTest : public CppUnit::TestFixture CPPUNIT_ASSERT(!!payload); CPPUNIT_ASSERT(payload->getQueryID()); CPPUNIT_ASSERT_EQUAL(std::string("id0"), *payload->getQueryID()); + CPPUNIT_ASSERT_EQUAL(std::string("node1"), *payload->getNode()); CPPUNIT_ASSERT(payload->getForm()); boost::shared_ptr<FormField> fieldType = payload->getForm()->getField("FORM_TYPE"); diff --git a/Swiften/Serializer/PayloadSerializers/MAMQuerySerializer.cpp b/Swiften/Serializer/PayloadSerializers/MAMQuerySerializer.cpp index 6a12f8e..591e73c 100644 --- a/Swiften/Serializer/PayloadSerializers/MAMQuerySerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/MAMQuerySerializer.cpp @@ -33,6 +33,10 @@ std::string MAMQuerySerializer::serializePayload(boost::shared_ptr<MAMQuery> pay element.setAttribute("queryid", *payload->getQueryID()); } + if (payload->getNode()) { + element.setAttribute("node", *payload->getNode()); + } + if (payload->getForm()) { element.addNode(boost::make_shared<XMLRawTextNode>(FormSerializer().serialize(payload->getForm()))); } diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp index 7f6cbd9..1d695cd 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp @@ -44,11 +44,12 @@ class MAMQuerySerializerTest : public CppUnit::TestFixture { boost::shared_ptr<MAMQuery> query(boost::make_shared<MAMQuery>()); query->setQueryID(std::string("id0")); + query->setNode(std::string("node1")); query->setForm(parameters); query->setResultSet(set); std::string expectedResult = - "<query queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">" + "<query node=\"node1\" queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">" "<x type=\"form\" xmlns=\"jabber:x:data\">" "<field type=\"text-single\" var=\"FORM_TYPE\">" "<value>urn:xmpp:mam:0</value>" |