summaryrefslogtreecommitdiffstats
path: root/Sluift
diff options
context:
space:
mode:
authorRoger Planas <roger.planas@isode.com>2016-10-27 12:54:40 (GMT)
committerTobias Markmann <tm@ayena.de>2016-11-07 10:27:34 (GMT)
commit41c771ec02682c2b344263d29f68eb6452c42dbe (patch)
tree34aa3b366e56f0e529454a8d7f9d53a136062383 /Sluift
parent7eab2eb9de931236b7bbc10265b963a9948492f0 (diff)
downloadswift-41c771ec02682c2b344263d29f68eb6452c42dbe.zip
swift-41c771ec02682c2b344263d29f68eb6452c42dbe.tar.bz2
Sluift: Added Carbons element convertors
Sluift was showing payloads coming from a carbon copied message as a series of dom payloads, which was not really usable. With these ElementConvertors, the payload is translated into a much more sensible table Also a minor update to both presence/message events, which now will report the 'to' as well. Seemed handy to have. Test-information: Carbons sent/received messages are formated into a meaningful table now. Change-Id: I5b8943636e09e5377bde76d16970c01df29164d6
Diffstat (limited to 'Sluift')
-rw-r--r--Sluift/ElementConvertors/CarbonsReceivedConvertor.cpp53
-rw-r--r--Sluift/ElementConvertors/CarbonsReceivedConvertor.h30
-rw-r--r--Sluift/ElementConvertors/CarbonsSentConvertor.cpp52
-rw-r--r--Sluift/ElementConvertors/CarbonsSentConvertor.h30
-rw-r--r--Sluift/ElementConvertors/SConscript2
-rw-r--r--Sluift/LuaElementConvertors.cpp4
-rw-r--r--Sluift/client.cpp3
7 files changed, 173 insertions, 1 deletions
diff --git a/Sluift/ElementConvertors/CarbonsReceivedConvertor.cpp b/Sluift/ElementConvertors/CarbonsReceivedConvertor.cpp
new file mode 100644
index 0000000..cfd55f3
--- /dev/null
+++ b/Sluift/ElementConvertors/CarbonsReceivedConvertor.cpp
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2016 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/CarbonsReceivedConvertor.h>
+
+#include <memory>
+#include <lua.hpp>
+
+#include <Swiften/Elements/Forwarded.h>
+
+#include <Sluift/LuaElementConvertors.h>
+
+using namespace Swift;
+
+CarbonsReceivedConvertor::CarbonsReceivedConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<CarbonsReceived>("carbons_received"),
+ convertors(convertors) {
+}
+
+CarbonsReceivedConvertor::~CarbonsReceivedConvertor() {
+}
+
+std::shared_ptr<CarbonsReceived> CarbonsReceivedConvertor::doConvertFromLua(lua_State* L) {
+ std::shared_ptr<CarbonsReceived> result = std::make_shared<CarbonsReceived>();
+ lua_getfield(L, -1, "payload");
+ if (!lua_isnil(L, -1)) {
+ std::shared_ptr<Forwarded> payload = std::dynamic_pointer_cast<Forwarded>(convertors->convertFromLuaUntyped(L, -1, "payload"));
+ if (!!payload) {
+ result->setForwarded(payload);
+ }
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void CarbonsReceivedConvertor::doConvertToLua(lua_State* L, std::shared_ptr<CarbonsReceived> payload) {
+ lua_createtable(L, 0, 0);
+ if (convertors->convertToLuaUntyped(L, payload->getForwarded()) > 0) {
+ lua_setfield(L, -2, "payload");
+
+ }
+}
+
+boost::optional<LuaElementConvertor::Documentation> CarbonsReceivedConvertor::getDocumentation() const {
+ return Documentation(
+ "CarbonsReceived",
+ "This table has the following fields:\n\n"
+ "- `payload`: @{Forwarded}\n"
+ );
+}
diff --git a/Sluift/ElementConvertors/CarbonsReceivedConvertor.h b/Sluift/ElementConvertors/CarbonsReceivedConvertor.h
new file mode 100644
index 0000000..f18f699
--- /dev/null
+++ b/Sluift/ElementConvertors/CarbonsReceivedConvertor.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Elements/CarbonsReceived.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class CarbonsReceivedConvertor : public GenericLuaElementConvertor<CarbonsReceived> {
+ public:
+ CarbonsReceivedConvertor(LuaElementConvertors* convertors);
+ virtual ~CarbonsReceivedConvertor();
+
+ virtual std::shared_ptr<CarbonsReceived> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, std::shared_ptr<CarbonsReceived>) SWIFTEN_OVERRIDE;
+ virtual boost::optional<Documentation> getDocumentation() const SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
+
diff --git a/Sluift/ElementConvertors/CarbonsSentConvertor.cpp b/Sluift/ElementConvertors/CarbonsSentConvertor.cpp
new file mode 100644
index 0000000..45851d2
--- /dev/null
+++ b/Sluift/ElementConvertors/CarbonsSentConvertor.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2016 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/CarbonsSentConvertor.h>
+
+#include <memory>
+#include <lua.hpp>
+
+#include <Swiften/Elements/Forwarded.h>
+
+#include <Sluift/LuaElementConvertors.h>
+
+using namespace Swift;
+
+CarbonsSentConvertor::CarbonsSentConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<CarbonsSent>("carbons_sent"),
+ convertors(convertors) {
+}
+
+CarbonsSentConvertor::~CarbonsSentConvertor() {
+}
+
+std::shared_ptr<CarbonsSent> CarbonsSentConvertor::doConvertFromLua(lua_State* L) {
+ std::shared_ptr<CarbonsSent> result = std::make_shared<CarbonsSent>();
+ lua_getfield(L, -1, "payload");
+ if (!lua_isnil(L, -1)) {
+ std::shared_ptr<Forwarded> payload = std::dynamic_pointer_cast<Forwarded>(convertors->convertFromLuaUntyped(L, -1, "payload"));
+ if (!!payload) {
+ result->setForwarded(payload);
+ }
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void CarbonsSentConvertor::doConvertToLua(lua_State* L, std::shared_ptr<CarbonsSent> payload) {
+ lua_createtable(L, 0, 0);
+ if (convertors->convertToLuaUntyped(L, payload->getForwarded()) > 0) {
+ lua_setfield(L, -2, "payload");
+ }
+}
+
+boost::optional<LuaElementConvertor::Documentation> CarbonsSentConvertor::getDocumentation() const {
+ return Documentation(
+ "CarbonsSent",
+ "This table has the following fields:\n\n"
+ "- `payload`: @{Forwarded}\n"
+ );
+}
diff --git a/Sluift/ElementConvertors/CarbonsSentConvertor.h b/Sluift/ElementConvertors/CarbonsSentConvertor.h
new file mode 100644
index 0000000..a36a6a8
--- /dev/null
+++ b/Sluift/ElementConvertors/CarbonsSentConvertor.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Elements/CarbonsSent.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class CarbonsSentConvertor : public GenericLuaElementConvertor<CarbonsSent> {
+ public:
+ CarbonsSentConvertor(LuaElementConvertors* convertors);
+ virtual ~CarbonsSentConvertor();
+
+ virtual std::shared_ptr<CarbonsSent> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, std::shared_ptr<CarbonsSent>) SWIFTEN_OVERRIDE;
+ virtual boost::optional<Documentation> getDocumentation() const SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
+
diff --git a/Sluift/ElementConvertors/SConscript b/Sluift/ElementConvertors/SConscript
index b67c65b..0bf8022 100644
--- a/Sluift/ElementConvertors/SConscript
+++ b/Sluift/ElementConvertors/SConscript
@@ -48,6 +48,8 @@ convertors = [
env.File("MAMResultConvertor.cpp"),
env.File("MAMQueryConvertor.cpp"),
env.File("MAMFinConvertor.cpp"),
+ env.File("CarbonsReceivedConvertor.cpp"),
+ env.File("CarbonsSentConvertor.cpp"),
env.File("SubjectConvertor.cpp"),
env.File("IsodeIQDelegationConvertor.cpp")
]
diff --git a/Sluift/LuaElementConvertors.cpp b/Sluift/LuaElementConvertors.cpp
index cfc90d8..38926e9 100644
--- a/Sluift/LuaElementConvertors.cpp
+++ b/Sluift/LuaElementConvertors.cpp
@@ -11,6 +11,8 @@
#include <Swiften/Base/foreach.h>
#include <Sluift/ElementConvertors/BodyConvertor.h>
+#include <Sluift/ElementConvertors/CarbonsReceivedConvertor.h>
+#include <Sluift/ElementConvertors/CarbonsSentConvertor.h>
#include <Sluift/ElementConvertors/CommandConvertor.h>
#include <Sluift/ElementConvertors/DOMElementConvertor.h>
#include <Sluift/ElementConvertors/DefaultElementConvertor.h>
@@ -63,6 +65,8 @@ LuaElementConvertors::LuaElementConvertors() {
convertors.push_back(std::make_shared<MAMResultConvertor>(this));
convertors.push_back(std::make_shared<MAMQueryConvertor>(this));
convertors.push_back(std::make_shared<MAMFinConvertor>(this));
+ convertors.push_back(std::make_shared<CarbonsReceivedConvertor>(this));
+ convertors.push_back(std::make_shared<CarbonsSentConvertor>(this));
convertors.push_back(std::make_shared<DOMElementConvertor>());
convertors.push_back(std::make_shared<RawXMLElementConvertor>());
convertors.push_back(std::make_shared<DefaultElementConvertor>());
diff --git a/Sluift/client.cpp b/Sluift/client.cpp
index 7d0924f..6376e9d 100644
--- a/Sluift/client.cpp
+++ b/Sluift/client.cpp
@@ -12,7 +12,6 @@
#include <Swiften/Base/foreach.h>
#include <Swiften/Disco/ClientDiscoManager.h>
#include <Swiften/Elements/DiscoInfo.h>
-#include <Swiften/Elements/MAMQuery.h>
#include <Swiften/Elements/Message.h>
#include <Swiften/Elements/Presence.h>
#include <Swiften/Elements/RawXMLPayload.h>
@@ -487,6 +486,7 @@ static void pushEvent(lua_State* L, const SluiftClient::Event& event) {
Lua::Table result = boost::assign::map_list_of
("type", std::make_shared<Lua::Value>(std::string("message")))
("from", std::make_shared<Lua::Value>(message->getFrom().toString()))
+ ("to", std::make_shared<Lua::Value>(message->getTo().toString()))
("body", std::make_shared<Lua::Value>(message->getBody().get_value_or("")))
("message_type", std::make_shared<Lua::Value>(MessageConvertor::convertMessageTypeToString(message->getType())));
Lua::pushValue(L, result);
@@ -499,6 +499,7 @@ static void pushEvent(lua_State* L, const SluiftClient::Event& event) {
Lua::Table result = boost::assign::map_list_of
("type", std::make_shared<Lua::Value>(std::string("presence")))
("from", std::make_shared<Lua::Value>(presence->getFrom().toString()))
+ ("to", std::make_shared<Lua::Value>(presence->getTo().toString()))
("status", std::make_shared<Lua::Value>(presence->getStatus()))
("presence_type", std::make_shared<Lua::Value>(PresenceConvertor::convertPresenceTypeToString(presence->getType())));
Lua::pushValue(L, result);