summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoger Planas <roger.planas@isode.com>2017-06-28 15:09:37 (GMT)
committerTobias Markmann <tm@ayena.de>2017-07-04 08:56:54 (GMT)
commit93a0f41d4af17db3e3eedb61e786fec23dbd8db9 (patch)
tree419daecd39e31d98cfb6c1b9dc47c4a584580393 /Sluift/ElementConvertors
parent4f61e116c83be5e38a8406ac3285a07b84712ec1 (diff)
downloadswift-93a0f41d4af17db3e3eedb61e786fec23dbd8db9.zip
swift-93a0f41d4af17db3e3eedb61e786fec23dbd8db9.tar.bz2
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
Diffstat (limited to 'Sluift/ElementConvertors')
-rw-r--r--Sluift/ElementConvertors/DiscoInfoConvertor.cpp31
-rw-r--r--Sluift/ElementConvertors/DiscoInfoConvertor.h9
2 files changed, 35 insertions, 5 deletions
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 <lua.hpp>
+#include <Swiften/Elements/Form.h>
+#include <Sluift/LuaElementConvertors.h>
#include <Sluift/Lua/LuaUtils.h>
using namespace Swift;
-DiscoInfoConvertor::DiscoInfoConvertor() : GenericLuaElementConvertor<DiscoInfo>("disco_info") {
+DiscoInfoConvertor::DiscoInfoConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<DiscoInfo>("disco_info"),
+ convertors(convertors) {
}
DiscoInfoConvertor::~DiscoInfoConvertor() {
@@ -52,7 +56,17 @@ std::shared_ptr<DiscoInfo> 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> form = std::dynamic_pointer_cast<Form>(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<DiscoInfo>
lua_setfield(L, -2, "features");
}
- // TODO: Extension
+ const std::vector<Form::ref>& extensions = payload->getExtensions();
+ if (!extensions.empty()) {
+ lua_createtable(L, boost::numeric_cast<int>(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<int>(i+1));
+ }
+ }
+ lua_setfield(L, -2, "extensions");
+ }
}
boost::optional<LuaElementConvertor::Documentation> DiscoInfoConvertor::getDocumentation() const {
@@ -115,5 +138,7 @@ boost::optional<LuaElementConvertor::Documentation> 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 <Sluift/GenericLuaElementConvertor.h>
namespace Swift {
+ class LuaElementConvertors;
+
class DiscoInfoConvertor : public GenericLuaElementConvertor<DiscoInfo> {
public:
- DiscoInfoConvertor();
+ DiscoInfoConvertor(LuaElementConvertors* convertors);
virtual ~DiscoInfoConvertor();
virtual std::shared_ptr<DiscoInfo> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
virtual void doConvertToLua(lua_State*, std::shared_ptr<DiscoInfo>) SWIFTEN_OVERRIDE;
virtual boost::optional<Documentation> getDocumentation() const SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
};
}