diff options
Diffstat (limited to 'Sluift')
-rw-r--r-- | Sluift/ElementConvertors/CarbonsReceivedConvertor.cpp | 53 | ||||
-rw-r--r-- | Sluift/ElementConvertors/CarbonsReceivedConvertor.h | 30 | ||||
-rw-r--r-- | Sluift/ElementConvertors/CarbonsSentConvertor.cpp | 52 | ||||
-rw-r--r-- | Sluift/ElementConvertors/CarbonsSentConvertor.h | 30 | ||||
-rw-r--r-- | Sluift/ElementConvertors/SConscript | 2 | ||||
-rw-r--r-- | Sluift/LuaElementConvertors.cpp | 4 | ||||
-rw-r--r-- | Sluift/client.cpp | 3 |
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 @@ -21,34 +21,36 @@ convertors = [ env.File("PubSubEventSubscriptionConvertor.cpp"), env.File("PubSubEventRetractConvertor.cpp"), env.File("PubSubItemConvertor.cpp"), env.File("PubSubUnsubscribeConvertor.cpp"), env.File("PubSubEventDeleteConvertor.cpp"), env.File("PubSubCreateConvertor.cpp"), env.File("PubSubOwnerPurgeConvertor.cpp"), env.File("PubSubEventItemsConvertor.cpp"), env.File("PubSubOptionsConvertor.cpp"), env.File("PubSubEventItemConvertor.cpp"), env.File("PubSubOwnerSubscriptionConvertor.cpp"), env.File("PubSubOwnerAffiliationConvertor.cpp"), env.File("PubSubEventPurgeConvertor.cpp"), env.File("PubSubAffiliationConvertor.cpp"), env.File("PubSubSubscribeConvertor.cpp"), env.File("PubSubOwnerDeleteConvertor.cpp"), env.File("PubSubOwnerDefaultConvertor.cpp"), env.File("PubSubSubscriptionsConvertor.cpp"), env.File("PubSubEventAssociateConvertor.cpp"), env.File("PubSubSubscriptionConvertor.cpp"), env.File("SecurityLabelConvertor.cpp"), env.File("PubSubEventConfigurationConvertor.cpp"), env.File("IQConvertor.cpp"), env.File("PresenceConvertor.cpp"), env.File("MessageConvertor.cpp"), env.File("ResultSetConvertor.cpp"), env.File("ForwardedConvertor.cpp"), 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") ] Return('convertors') diff --git a/Sluift/LuaElementConvertors.cpp b/Sluift/LuaElementConvertors.cpp index cfc90d8..38926e9 100644 --- a/Sluift/LuaElementConvertors.cpp +++ b/Sluift/LuaElementConvertors.cpp @@ -1,95 +1,99 @@ /* * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Sluift/LuaElementConvertors.h> #include <memory> #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> #include <Sluift/ElementConvertors/DelayConvertor.h> #include <Sluift/ElementConvertors/DiscoInfoConvertor.h> #include <Sluift/ElementConvertors/DiscoItemsConvertor.h> #include <Sluift/ElementConvertors/FormConvertor.h> #include <Sluift/ElementConvertors/ForwardedConvertor.h> #include <Sluift/ElementConvertors/IQConvertor.h> #include <Sluift/ElementConvertors/MAMFinConvertor.h> #include <Sluift/ElementConvertors/MAMQueryConvertor.h> #include <Sluift/ElementConvertors/MAMResultConvertor.h> #include <Sluift/ElementConvertors/MessageConvertor.h> #include <Sluift/ElementConvertors/PresenceConvertor.h> #include <Sluift/ElementConvertors/PubSubEventConvertor.h> #include <Sluift/ElementConvertors/RawXMLElementConvertor.h> #include <Sluift/ElementConvertors/ResultSetConvertor.h> #include <Sluift/ElementConvertors/SoftwareVersionConvertor.h> #include <Sluift/ElementConvertors/StatusConvertor.h> #include <Sluift/ElementConvertors/StatusShowConvertor.h> #include <Sluift/ElementConvertors/SubjectConvertor.h> #include <Sluift/ElementConvertors/VCardConvertor.h> #include <Sluift/ElementConvertors/VCardUpdateConvertor.h> #include <Sluift/Lua/Exception.h> #include <Sluift/Lua/LuaUtils.h> #include <Sluift/LuaElementConvertor.h> using namespace Swift; LuaElementConvertors::LuaElementConvertors() { registerConvertors(); convertors.push_back(std::make_shared<StatusConvertor>()); convertors.push_back(std::make_shared<StatusShowConvertor>()); convertors.push_back(std::make_shared<DelayConvertor>()); convertors.push_back(std::make_shared<CommandConvertor>(this)); convertors.push_back(std::make_shared<PubSubEventConvertor>(this)); convertors.push_back(std::make_shared<BodyConvertor>()); convertors.push_back(std::make_shared<SubjectConvertor>()); convertors.push_back(std::make_shared<VCardConvertor>()); convertors.push_back(std::make_shared<VCardUpdateConvertor>()); convertors.push_back(std::make_shared<FormConvertor>()); convertors.push_back(std::make_shared<SoftwareVersionConvertor>()); convertors.push_back(std::make_shared<DiscoInfoConvertor>()); convertors.push_back(std::make_shared<DiscoItemsConvertor>()); convertors.push_back(std::make_shared<IQConvertor>(this)); convertors.push_back(std::make_shared<PresenceConvertor>(this)); convertors.push_back(std::make_shared<MessageConvertor>(this)); convertors.push_back(std::make_shared<ResultSetConvertor>()); convertors.push_back(std::make_shared<ForwardedConvertor>(this)); 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>()); } LuaElementConvertors::~LuaElementConvertors() { } #include <Sluift/ElementConvertors/ElementConvertors.ipp> std::shared_ptr<Element> LuaElementConvertors::convertFromLua(lua_State* L, int index) { if (lua_isstring(L, index)) { return convertFromLuaUntyped(L, index, "xml"); } else if (lua_istable(L, index)) { lua_getfield(L, index, "_type"); if (lua_isstring(L, -1)) { std::string type = lua_tostring(L, -1); lua_pop(L, 1); return convertFromLuaUntyped(L, index, type); } lua_pop(L, 1); } throw Lua::Exception("Unable to determine type"); } std::shared_ptr<Element> LuaElementConvertors::convertFromLuaUntyped(lua_State* L, int index, const std::string& type) { index = Lua::absoluteOffset(L, index); foreach (std::shared_ptr<LuaElementConvertor> convertor, convertors) { if (std::shared_ptr<Element> result = convertor->convertFromLua(L, index, type)) { diff --git a/Sluift/client.cpp b/Sluift/client.cpp index 7d0924f..6376e9d 100644 --- a/Sluift/client.cpp +++ b/Sluift/client.cpp @@ -1,45 +1,44 @@ /* * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <boost/assign/list_of.hpp> #include <boost/lambda/bind.hpp> #include <boost/lambda/lambda.hpp> #include <Swiften/Base/IDGenerator.h> #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> #include <Swiften/Elements/RosterItemPayload.h> #include <Swiften/Elements/RosterPayload.h> #include <Swiften/Elements/SoftwareVersion.h> #include <Swiften/JID/JID.h> #include <Swiften/Presence/PresenceSender.h> #include <Swiften/Presence/SubscriptionManager.h> #include <Swiften/Queries/GenericRequest.h> #include <Swiften/Queries/IQRouter.h> #include <Swiften/Queries/Requests/GetSoftwareVersionRequest.h> #include <Swiften/Roster/SetRosterRequest.h> #include <Swiften/Roster/XMPPRoster.h> #include <Swiften/Roster/XMPPRosterItem.h> #include <Swiften/TLS/PKCS12Certificate.h> #include <Sluift/ElementConvertors/IQConvertor.h> #include <Sluift/ElementConvertors/MessageConvertor.h> #include <Sluift/ElementConvertors/PresenceConvertor.h> #include <Sluift/ElementConvertors/StanzaConvertor.h> #include <Sluift/ElementConvertors/StatusShowConvertor.h> #include <Sluift/Lua/Check.h> #include <Sluift/Lua/Exception.h> #include <Sluift/Lua/FunctionRegistration.h> #include <Sluift/Lua/LuaUtils.h> #include <Sluift/Lua/Value.h> #include <Sluift/SluiftClient.h> #include <Sluift/globals.h> @@ -460,72 +459,74 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( SLUIFT_LUA_FUNCTION_WITH_HELP( Client, get_options, "Returns a table with all the connection options of this client.", "self\n", "" ) { Sluift::globals.eventLoop.runOnce(); SluiftClient* client = getClient(L); Lua::Table optionsTable = boost::assign::map_list_of ("host", std::make_shared<Lua::Value>(client->getOptions().manualHostname)) ("port", std::make_shared<Lua::Value>(client->getOptions().manualPort)) ("ack", std::make_shared<Lua::Value>(client->getOptions().useAcks)) ("compress", std::make_shared<Lua::Value>(client->getOptions().useStreamCompression)) ("tls", std::make_shared<Lua::Value>(client->getOptions().useTLS == ClientOptions::NeverUseTLS ? false : true)) ("bosh_url", std::make_shared<Lua::Value>(client->getOptions().boshURL.toString())) ("allow_plain_without_tls", std::make_shared<Lua::Value>(client->getOptions().allowPLAINWithoutTLS)); pushValue(L, optionsTable); Lua::registerTableToString(L, -1); return 1; } static void pushEvent(lua_State* L, const SluiftClient::Event& event) { switch (event.type) { case SluiftClient::Event::MessageType: { Message::ref message = std::dynamic_pointer_cast<Message>(event.stanza); 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); addPayloadsToTable(L, message->getPayloads()); Lua::registerTableToString(L, -1); break; } case SluiftClient::Event::PresenceType: { Presence::ref presence = std::dynamic_pointer_cast<Presence>(event.stanza); 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); addPayloadsToTable(L, presence->getPayloads()); Lua::registerTableToString(L, -1); break; } case SluiftClient::Event::PubSubEventType: { Sluift::globals.elementConvertor.convertToLua(L, event.pubsubEvent); lua_pushstring(L, "pubsub"); lua_setfield(L, -2, "type"); lua_pushstring(L, event.from.toString().c_str()); lua_setfield(L, -2, "from"); lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.coreLibIndex); lua_getfield(L, -1, "process_pubsub_event"); lua_pushvalue(L, -3); lua_call(L, 1, 0); lua_pop(L, 1); } } } struct CallUnaryLuaPredicateOnEvent { CallUnaryLuaPredicateOnEvent(lua_State* L, int index) : L(L), index(index) { } bool operator()(const SluiftClient::Event& event) { lua_pushvalue(L, index); pushEvent(L, event); |