From 93a0f41d4af17db3e3eedb61e786fec23dbd8db9 Mon Sep 17 00:00:00 2001 From: Roger Planas Date: Wed, 28 Jun 2017 16:09:37 +0100 Subject: Sluift: Add extensions support to disco#info queries Only identities and features were reported. Now extensions, if any, will also be reported Test-information: Sent disco#info to a muc room, and got the following extensions back (along with identities and features, so no regression) Change-Id: Ib4ab17114df4da5de51945df9e53c12bd42716d1 diff --git a/Sluift/ElementConvertors/DiscoInfoConvertor.cpp b/Sluift/ElementConvertors/DiscoInfoConvertor.cpp index 2aa4a77..a528211 100644 --- a/Sluift/ElementConvertors/DiscoInfoConvertor.cpp +++ b/Sluift/ElementConvertors/DiscoInfoConvertor.cpp @@ -12,11 +12,15 @@ #include +#include +#include #include using namespace Swift; -DiscoInfoConvertor::DiscoInfoConvertor() : GenericLuaElementConvertor("disco_info") { +DiscoInfoConvertor::DiscoInfoConvertor(LuaElementConvertors* convertors) : + GenericLuaElementConvertor("disco_info"), + convertors(convertors) { } DiscoInfoConvertor::~DiscoInfoConvertor() { @@ -52,7 +56,17 @@ std::shared_ptr DiscoInfoConvertor::doConvertFromLua(lua_State* L) { } lua_pop(L, 1); - // TODO: Extension + lua_getfield(L, -1, "extensions"); + if (lua_istable(L, -1)) { + for (lua_pushnil(L); lua_next(L, -2); ) { + std::shared_ptr
form = std::dynamic_pointer_cast(convertors->convertFromLuaUntyped(L, -1, "form")); + if (!!form) { + result->addExtension(form); + } + lua_pop(L, 1); + } + } + lua_pop(L, 1); return result; } @@ -100,7 +114,16 @@ void DiscoInfoConvertor::doConvertToLua(lua_State* L, std::shared_ptr lua_setfield(L, -2, "features"); } - // TODO: Extension + const std::vector& extensions = payload->getExtensions(); + if (!extensions.empty()) { + lua_createtable(L, boost::numeric_cast(extensions.size()), 0); + for (size_t i = 0; i < extensions.size(); ++i) { + if (convertors->convertToLuaUntyped(L, extensions[i]) > 0) { + lua_rawseti(L, -2, boost::numeric_cast(i+1)); + } + } + lua_setfield(L, -2, "extensions"); + } } boost::optional DiscoInfoConvertor::getDocumentation() const { @@ -115,5 +138,7 @@ boost::optional DiscoInfoConvertor::getDocum " - `type`: string\n" " - `language`: string\n" "- `features`: array(string)\n" + "- `extensions`: array(table)\n" + "- `form`: string @{Form} (Optional)\n" ); } diff --git a/Sluift/ElementConvertors/DiscoInfoConvertor.h b/Sluift/ElementConvertors/DiscoInfoConvertor.h index 34f8237..c1b2910 100644 --- a/Sluift/ElementConvertors/DiscoInfoConvertor.h +++ b/Sluift/ElementConvertors/DiscoInfoConvertor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2016 Isode Limited. + * Copyright (c) 2013-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -12,13 +12,18 @@ #include namespace Swift { + class LuaElementConvertors; + class DiscoInfoConvertor : public GenericLuaElementConvertor { public: - DiscoInfoConvertor(); + DiscoInfoConvertor(LuaElementConvertors* convertors); virtual ~DiscoInfoConvertor(); virtual std::shared_ptr doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE; virtual void doConvertToLua(lua_State*, std::shared_ptr) SWIFTEN_OVERRIDE; virtual boost::optional getDocumentation() const SWIFTEN_OVERRIDE; + + private: + LuaElementConvertors* convertors; }; } diff --git a/Sluift/LuaElementConvertors.cpp b/Sluift/LuaElementConvertors.cpp index aac4d93..db91761 100644 --- a/Sluift/LuaElementConvertors.cpp +++ b/Sluift/LuaElementConvertors.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2016 Isode Limited. + * Copyright (c) 2013-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -53,7 +53,7 @@ LuaElementConvertors::LuaElementConvertors() { convertors.push_back(std::make_shared()); convertors.push_back(std::make_shared()); convertors.push_back(std::make_shared()); - convertors.push_back(std::make_shared()); + convertors.push_back(std::make_shared(this)); convertors.push_back(std::make_shared()); convertors.push_back(std::make_shared(this)); convertors.push_back(std::make_shared(this)); -- cgit v0.10.2-6-g49f6