summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-08-25 16:39:06 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-08-27 19:47:48 (GMT)
commit1bb607f96e79845ce30dd5590b0d53cc394ac150 (patch)
tree6156622ddd1b3238aec73536e0dc25b632965a71 /Sluift/ElementConvertors
parentc4431ee90f3f1daac0a12b35bfa3378d5c570eaa (diff)
downloadswift-1bb607f96e79845ce30dd5590b0d53cc394ac150.zip
swift-1bb607f96e79845ce30dd5590b0d53cc394ac150.tar.bz2
PubSub implementation & Sluift refactoring.
Change-Id: I04ff7111b73565c00bff6db183451774a633344f
Diffstat (limited to 'Sluift/ElementConvertors')
-rw-r--r--Sluift/ElementConvertors/DOMElementConvertor.cpp194
-rw-r--r--Sluift/ElementConvertors/DOMElementConvertor.h28
-rw-r--r--Sluift/ElementConvertors/DefaultElementConvertor.cpp30
-rw-r--r--Sluift/ElementConvertors/DefaultElementConvertor.h22
-rw-r--r--Sluift/ElementConvertors/DiscoInfoConvertor.cpp101
-rw-r--r--Sluift/ElementConvertors/DiscoInfoConvertor.h23
-rw-r--r--Sluift/ElementConvertors/DiscoItemsConvertor.cpp62
-rw-r--r--Sluift/ElementConvertors/DiscoItemsConvertor.h23
-rw-r--r--Sluift/ElementConvertors/ElementConvertors.ipp81
-rw-r--r--Sluift/ElementConvertors/FormConvertor.cpp331
-rw-r--r--Sluift/ElementConvertors/FormConvertor.h23
-rw-r--r--Sluift/ElementConvertors/PubSubAffiliationConvertor.cpp64
-rw-r--r--Sluift/ElementConvertors/PubSubAffiliationConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubAffiliationsConvertor.cpp70
-rw-r--r--Sluift/ElementConvertors/PubSubAffiliationsConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubConfigureConvertor.cpp44
-rw-r--r--Sluift/ElementConvertors/PubSubConfigureConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubCreateConvertor.cpp51
-rw-r--r--Sluift/ElementConvertors/PubSubCreateConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubDefaultConvertor.cpp57
-rw-r--r--Sluift/ElementConvertors/PubSubDefaultConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubEventAssociateConvertor.cpp41
-rw-r--r--Sluift/ElementConvertors/PubSubEventAssociateConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubEventCollectionConvertor.cpp63
-rw-r--r--Sluift/ElementConvertors/PubSubEventCollectionConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubEventConfigurationConvertor.cpp51
-rw-r--r--Sluift/ElementConvertors/PubSubEventConfigurationConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubEventConvertor.cpp37
-rw-r--r--Sluift/ElementConvertors/PubSubEventConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubEventDeleteConvertor.cpp51
-rw-r--r--Sluift/ElementConvertors/PubSubEventDeleteConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubEventDisassociateConvertor.cpp41
-rw-r--r--Sluift/ElementConvertors/PubSubEventDisassociateConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubEventItemConvertor.cpp92
-rw-r--r--Sluift/ElementConvertors/PubSubEventItemConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubEventItemsConvertor.cpp102
-rw-r--r--Sluift/ElementConvertors/PubSubEventItemsConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubEventPurgeConvertor.cpp41
-rw-r--r--Sluift/ElementConvertors/PubSubEventPurgeConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubEventRedirectConvertor.cpp41
-rw-r--r--Sluift/ElementConvertors/PubSubEventRedirectConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubEventRetractConvertor.cpp41
-rw-r--r--Sluift/ElementConvertors/PubSubEventRetractConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubEventSubscriptionConvertor.cpp81
-rw-r--r--Sluift/ElementConvertors/PubSubEventSubscriptionConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubItemConvertor.cpp72
-rw-r--r--Sluift/ElementConvertors/PubSubItemConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubItemsConvertor.cpp86
-rw-r--r--Sluift/ElementConvertors/PubSubItemsConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubOptionsConvertor.cpp67
-rw-r--r--Sluift/ElementConvertors/PubSubOptionsConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerAffiliationConvertor.cpp64
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerAffiliationConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.cpp68
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerConfigureConvertor.cpp53
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerConfigureConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerDefaultConvertor.cpp44
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerDefaultConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerDeleteConvertor.cpp51
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerDeleteConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerPurgeConvertor.cpp41
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerPurgeConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerRedirectConvertor.cpp41
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerRedirectConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerSubscriptionConvertor.cpp58
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerSubscriptionConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.cpp68
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubPublishConvertor.cpp72
-rw-r--r--Sluift/ElementConvertors/PubSubPublishConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubRetractConvertor.cpp79
-rw-r--r--Sluift/ElementConvertors/PubSubRetractConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubSubscribeConvertor.cpp60
-rw-r--r--Sluift/ElementConvertors/PubSubSubscribeConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubSubscribeOptionsConvertor.cpp41
-rw-r--r--Sluift/ElementConvertors/PubSubSubscribeOptionsConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubSubscriptionConvertor.cpp86
-rw-r--r--Sluift/ElementConvertors/PubSubSubscriptionConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubSubscriptionsConvertor.cpp70
-rw-r--r--Sluift/ElementConvertors/PubSubSubscriptionsConvertor.h28
-rw-r--r--Sluift/ElementConvertors/PubSubUnsubscribeConvertor.cpp59
-rw-r--r--Sluift/ElementConvertors/PubSubUnsubscribeConvertor.h28
-rw-r--r--Sluift/ElementConvertors/RawXMLElementConvertor.cpp37
-rw-r--r--Sluift/ElementConvertors/RawXMLElementConvertor.h26
-rw-r--r--Sluift/ElementConvertors/SConscript42
-rw-r--r--Sluift/ElementConvertors/SoftwareVersionConvertor.cpp50
-rw-r--r--Sluift/ElementConvertors/SoftwareVersionConvertor.h23
-rw-r--r--Sluift/ElementConvertors/UserLocationConvertor.cpp232
-rw-r--r--Sluift/ElementConvertors/UserLocationConvertor.h28
-rw-r--r--Sluift/ElementConvertors/VCardConvertor.cpp46
-rw-r--r--Sluift/ElementConvertors/VCardConvertor.h23
-rw-r--r--Sluift/ElementConvertors/VCardUpdateConvertor.cpp36
-rw-r--r--Sluift/ElementConvertors/VCardUpdateConvertor.h23
94 files changed, 4640 insertions, 0 deletions
diff --git a/Sluift/ElementConvertors/DOMElementConvertor.cpp b/Sluift/ElementConvertors/DOMElementConvertor.cpp
new file mode 100644
index 0000000..bb4256d
--- /dev/null
+++ b/Sluift/ElementConvertors/DOMElementConvertor.cpp
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/DOMElementConvertor.h>
+
+#include <iostream>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <lua.hpp>
+
+#include <Swiften/Base/foreach.h>
+#include <Swiften/Elements/RawXMLPayload.h>
+#include <Swiften/Serializer/PayloadSerializer.h>
+#include <Sluift/Lua/Check.h>
+#include <Sluift/Lua/LuaUtils.h>
+#include <Swiften/Parser/XMLParserClient.h>
+#include <Swiften/Parser/XMLParser.h>
+#include <Swiften/Parser/AttributeMap.h>
+#include <Swiften/Parser/Attribute.h>
+#include <Swiften/Serializer/XML/XMLElement.h>
+#include <Swiften/Serializer/XML/XMLTextNode.h>
+#include <Swiften/Serializer/XML/XMLRawTextNode.h>
+#include <Sluift/Lua/Debug.h>
+
+using namespace Swift;
+
+namespace {
+ class ParserClient : public XMLParserClient {
+ public:
+ ParserClient(lua_State* L) : L(L), currentIndex(1) {
+ }
+
+ virtual void handleStartElement(
+ const std::string& element, const std::string& ns,
+ const AttributeMap& attributes) SWIFTEN_OVERRIDE {
+ lua_pushnumber(L, currentIndex);
+ lua_newtable(L);
+ lua_pushstring(L, element.c_str());
+ lua_setfield(L, -2, "tag");
+ if (!ns.empty()) {
+ lua_pushstring(L, ns.c_str());
+ lua_setfield(L, -2, "ns");
+ }
+ if (!attributes.getEntries().empty()) {
+ lua_newtable(L);
+ int i = 1;
+ foreach(const AttributeMap::Entry& entry, attributes.getEntries()) {
+ lua_pushnumber(L, i);
+ lua_newtable(L);
+ lua_pushstring(L, entry.getAttribute().getName().c_str());
+ lua_setfield(L, -2, "name");
+ if (!entry.getAttribute().getNamespace().empty()) {
+ lua_pushstring(L, entry.getAttribute().getNamespace().c_str());
+ lua_setfield(L, -2, "ns");
+ }
+ lua_pushstring(L, entry.getValue().c_str());
+ lua_setfield(L, -2, "value");
+ lua_settable(L, -3);
+ ++i;
+ }
+ lua_setfield(L, -2, "attributes");
+ }
+
+ indexStack.push_back(currentIndex);
+ currentIndex = 1;
+ lua_newtable(L);
+ }
+
+ virtual void handleEndElement(
+ const std::string&, const std::string&) SWIFTEN_OVERRIDE {
+ lua_setfield(L, -2, "children");
+ lua_settable(L, -3);
+ currentIndex = indexStack.back();
+ indexStack.pop_back();
+ currentIndex++;
+ }
+
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE {
+ lua_pushnumber(L, currentIndex);
+ lua_pushstring(L, data.c_str());
+ lua_settable(L, -3);
+ currentIndex++;
+ }
+
+ private:
+ lua_State* L;
+ std::vector<int> indexStack;
+ int currentIndex;
+ };
+
+ std::string serializeElement(lua_State* L) {
+ std::string tag;
+ lua_getfield(L, -1, "tag");
+ if (lua_isstring(L, -1)) {
+ tag = lua_tostring(L, -1);
+ }
+ lua_pop(L, 1);
+
+ std::string ns;
+ lua_getfield(L, -1, "ns");
+ if (lua_isstring(L, -1)) {
+ ns = lua_tostring(L, -1);
+ }
+ lua_pop(L, 1);
+
+ XMLElement element(tag, ns);
+
+ lua_getfield(L, -1, "attributes");
+ if (lua_istable(L, -1)) {
+ int index = Lua::absoluteOffset(L, -1);
+ for (lua_pushnil(L); lua_next(L, index) != 0; ) {
+ if (lua_istable(L, -1)) {
+ std::string attributeName;
+ lua_getfield(L, -1, "name");
+ if (lua_isstring(L, -1)) {
+ attributeName = lua_tostring(L, -1);
+ }
+ lua_pop(L, 1);
+
+ std::string attributeValue;
+ lua_getfield(L, -1, "value");
+ if (lua_isstring(L, -1)) {
+ attributeValue = lua_tostring(L, -1);
+ }
+ lua_pop(L, 1);
+
+ if (!attributeName.empty()) {
+ element.setAttribute(attributeName, attributeValue);
+ }
+ }
+ lua_pop(L, 1); // value
+ }
+ }
+ lua_pop(L, 1); // children
+
+ lua_getfield(L, -1, "children");
+ if (lua_istable(L, -1)) {
+ int index = Lua::absoluteOffset(L, -1);
+ for (lua_pushnil(L); lua_next(L, index) != 0; ) {
+ if (lua_isstring(L, -1)) {
+ element.addNode(boost::make_shared<XMLTextNode>(lua_tostring(L, -1)));
+ }
+ else if (lua_istable(L, -1)) {
+ element.addNode(boost::make_shared<XMLRawTextNode>(serializeElement(L)));
+ }
+ lua_pop(L, 1); // value
+ }
+ }
+ lua_pop(L, 1); // children
+
+ return element.serialize();
+ }
+}
+
+DOMElementConvertor::DOMElementConvertor() {
+}
+
+DOMElementConvertor::~DOMElementConvertor() {
+}
+
+boost::shared_ptr<Payload> DOMElementConvertor::convertFromLua(lua_State* L, int index, const std::string& type) {
+ if (!lua_istable(L, index) || type != "dom") {
+ return boost::shared_ptr<Payload>();
+ }
+ return boost::make_shared<RawXMLPayload>(serializeElement(L).c_str());
+}
+
+boost::optional<std::string> DOMElementConvertor::convertToLua(
+ lua_State* L, boost::shared_ptr<Payload> payload) {
+ // Serialize payload to XML
+ PayloadSerializer* serializer = serializers.getPayloadSerializer(payload);
+ assert(serializer);
+ std::string serializedPayload = serializer->serialize(payload);
+
+ lua_newtable(L);
+
+ // Parse the payload again
+ ParserClient parserClient(L);
+ boost::shared_ptr<XMLParser> parser(parsers.createXMLParser(&parserClient));
+ bool result = parser->parse(serializedPayload);
+ assert(result);
+
+ // There can only be one element, so stripping the list
+ lua_pushnil(L);
+ lua_next(L, -2);
+ Lua::registerTableToString(L, -1);
+
+ lua_replace(L, -3);
+ lua_settop(L, -2);
+
+ return std::string("dom");
+}
diff --git a/Sluift/ElementConvertors/DOMElementConvertor.h b/Sluift/ElementConvertors/DOMElementConvertor.h
new file mode 100644
index 0000000..94d0669
--- /dev/null
+++ b/Sluift/ElementConvertors/DOMElementConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/LuaElementConvertor.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+#include <Swiften/Parser/PlatformXMLParserFactory.h>
+
+namespace Swift {
+ class DOMElementConvertor : public LuaElementConvertor {
+ public:
+ DOMElementConvertor();
+ virtual ~DOMElementConvertor();
+
+ virtual boost::shared_ptr<Payload> convertFromLua(lua_State*, int index, const std::string& type) SWIFTEN_OVERRIDE;
+ virtual boost::optional<std::string> convertToLua(lua_State*, boost::shared_ptr<Payload>) SWIFTEN_OVERRIDE;
+
+ private:
+ PlatformXMLParserFactory parsers;
+ FullPayloadSerializerCollection serializers;
+ };
+}
diff --git a/Sluift/ElementConvertors/DefaultElementConvertor.cpp b/Sluift/ElementConvertors/DefaultElementConvertor.cpp
new file mode 100644
index 0000000..62c799b
--- /dev/null
+++ b/Sluift/ElementConvertors/DefaultElementConvertor.cpp
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/DefaultElementConvertor.h>
+
+#include <iostream>
+#include <typeinfo>
+#include <string>
+
+using namespace Swift;
+
+DefaultElementConvertor::DefaultElementConvertor() {
+}
+
+DefaultElementConvertor::~DefaultElementConvertor() {
+}
+
+boost::shared_ptr<Payload> DefaultElementConvertor::convertFromLua(lua_State*, int, const std::string& type) {
+ std::cerr << "Warning: Unable to convert type '" << type << "'" << std::endl;
+ return boost::shared_ptr<Payload>();
+}
+
+boost::optional<std::string> DefaultElementConvertor::convertToLua(lua_State*, boost::shared_ptr<Payload>) {
+ // Should have been handled by the raw XML convertor
+ assert(false);
+ return NO_RESULT;
+}
diff --git a/Sluift/ElementConvertors/DefaultElementConvertor.h b/Sluift/ElementConvertors/DefaultElementConvertor.h
new file mode 100644
index 0000000..ad8fe75
--- /dev/null
+++ b/Sluift/ElementConvertors/DefaultElementConvertor.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/LuaElementConvertor.h>
+
+namespace Swift {
+ class DefaultElementConvertor : public LuaElementConvertor {
+ public:
+ DefaultElementConvertor();
+ virtual ~DefaultElementConvertor();
+
+ virtual boost::shared_ptr<Payload> convertFromLua(lua_State*, int index, const std::string& type) SWIFTEN_OVERRIDE;
+ virtual boost::optional<std::string> convertToLua(lua_State*, boost::shared_ptr<Payload>) SWIFTEN_OVERRIDE;
+ };
+}
diff --git a/Sluift/ElementConvertors/DiscoInfoConvertor.cpp b/Sluift/ElementConvertors/DiscoInfoConvertor.cpp
new file mode 100644
index 0000000..ac0cf2e
--- /dev/null
+++ b/Sluift/ElementConvertors/DiscoInfoConvertor.cpp
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/DiscoInfoConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+#include <Sluift/Lua/LuaUtils.h>
+
+using namespace Swift;
+
+DiscoInfoConvertor::DiscoInfoConvertor() : GenericLuaElementConvertor<DiscoInfo>("disco_info") {
+}
+
+DiscoInfoConvertor::~DiscoInfoConvertor() {
+}
+
+boost::shared_ptr<DiscoInfo> DiscoInfoConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<DiscoInfo> result = boost::make_shared<DiscoInfo>();
+ if (boost::optional<std::string> value = Lua::getStringField(L, -1, "node")) {
+ result->setNode(*value);
+ }
+
+ lua_getfield(L, -1, "identities");
+ if (lua_istable(L, -1)) {
+ for (lua_pushnil(L); lua_next(L, -2); ) {
+ result->addIdentity(DiscoInfo::Identity(
+ Lua::getStringField(L, -1, "name").get_value_or(""),
+ Lua::getStringField(L, -1, "category").get_value_or("client"),
+ Lua::getStringField(L, -1, "type").get_value_or("pc"),
+ Lua::getStringField(L, -1, "language").get_value_or("")));
+ lua_pop(L, 1);
+ }
+ }
+ lua_pop(L, 1);
+
+ lua_getfield(L, -1, "features");
+ if (lua_istable(L, -1)) {
+ for (lua_pushnil(L); lua_next(L, -2); ) {
+ if (lua_isstring(L, -1)) {
+ result->addFeature(lua_tostring(L, -1));
+ }
+ lua_pop(L, 1);
+ }
+ }
+ lua_pop(L, 1);
+
+ // TODO: Extension
+
+ return result;
+}
+
+void DiscoInfoConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<DiscoInfo> payload) {
+ lua_newtable(L);
+ if (!payload->getNode().empty()) {
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ }
+
+ const std::vector<DiscoInfo::Identity>& identities = payload->getIdentities();
+ if (!identities.empty()) {
+ lua_createtable(L, boost::numeric_cast<int>(identities.size()), 0);
+ for (size_t i = 0; i < identities.size(); ++i) {
+ lua_createtable(L, 0, 0);
+ if (!identities[i].getName().empty()) {
+ lua_pushstring(L, identities[i].getName().c_str());
+ lua_setfield(L, -2, "name");
+ }
+ if (!identities[i].getCategory().empty()) {
+ lua_pushstring(L, identities[i].getCategory().c_str());
+ lua_setfield(L, -2, "category");
+ }
+ if (!identities[i].getType().empty()) {
+ lua_pushstring(L, identities[i].getType().c_str());
+ lua_setfield(L, -2, "type");
+ }
+ if (!identities[i].getLanguage().empty()) {
+ lua_pushstring(L, identities[i].getLanguage().c_str());
+ lua_setfield(L, -2, "language");
+ }
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ }
+ lua_setfield(L, -2, "identities");
+ }
+
+ const std::vector<std::string>& features = payload->getFeatures();
+ if (!features.empty()) {
+ lua_createtable(L, boost::numeric_cast<int>(features.size()), 0);
+ for (size_t i = 0; i < features.size(); ++i) {
+ lua_pushstring(L, features[i].c_str());
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ }
+ lua_setfield(L, -2, "features");
+ }
+
+ // TODO: Extension
+}
diff --git a/Sluift/ElementConvertors/DiscoInfoConvertor.h b/Sluift/ElementConvertors/DiscoInfoConvertor.h
new file mode 100644
index 0000000..7a2270e
--- /dev/null
+++ b/Sluift/ElementConvertors/DiscoInfoConvertor.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/DiscoInfo.h>
+
+namespace Swift {
+ class DiscoInfoConvertor : public GenericLuaElementConvertor<DiscoInfo> {
+ public:
+ DiscoInfoConvertor();
+ virtual ~DiscoInfoConvertor();
+
+ virtual boost::shared_ptr<DiscoInfo> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<DiscoInfo>) SWIFTEN_OVERRIDE;
+ };
+}
diff --git a/Sluift/ElementConvertors/DiscoItemsConvertor.cpp b/Sluift/ElementConvertors/DiscoItemsConvertor.cpp
new file mode 100644
index 0000000..6c39aea
--- /dev/null
+++ b/Sluift/ElementConvertors/DiscoItemsConvertor.cpp
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/DiscoItemsConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+#include <Sluift/Lua/LuaUtils.h>
+
+using namespace Swift;
+
+DiscoItemsConvertor::DiscoItemsConvertor() : GenericLuaElementConvertor<DiscoItems>("disco_items") {
+}
+
+DiscoItemsConvertor::~DiscoItemsConvertor() {
+}
+
+boost::shared_ptr<DiscoItems> DiscoItemsConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<DiscoItems> result = boost::make_shared<DiscoItems>();
+ if (boost::optional<std::string> value = Lua::getStringField(L, -1, "node")) {
+ result->setNode(*value);
+ }
+ lua_getfield(L, -1, "items");
+ if (lua_istable(L, -1)) {
+ for (lua_pushnil(L); lua_next(L, -2); ) {
+ result->addItem(DiscoItems::Item(
+ Lua::getStringField(L, -1, "name").get_value_or(""),
+ JID(Lua::getStringField(L, -1, "jid").get_value_or("")),
+ Lua::getStringField(L, -1, "node").get_value_or("")));
+ lua_pop(L, 1);
+ }
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void DiscoItemsConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<DiscoItems> payload) {
+ lua_newtable(L);
+ if (!payload->getNode().empty()) {
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ }
+ const std::vector<DiscoItems::Item>& items = payload->getItems();
+ if (!items.empty()) {
+ lua_createtable(L, boost::numeric_cast<int>(items.size()), 0);
+ for (size_t i = 0; i < items.size(); ++i) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, items[i].getName().c_str());
+ lua_setfield(L, -2, "name");
+ lua_pushstring(L, items[i].getNode().c_str());
+ lua_setfield(L, -2, "node");
+ lua_pushstring(L, items[i].getJID().toString().c_str());
+ lua_setfield(L, -2, "jid");
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ }
+ lua_setfield(L, -2, "items");
+ }
+}
diff --git a/Sluift/ElementConvertors/DiscoItemsConvertor.h b/Sluift/ElementConvertors/DiscoItemsConvertor.h
new file mode 100644
index 0000000..8972a84
--- /dev/null
+++ b/Sluift/ElementConvertors/DiscoItemsConvertor.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/DiscoItems.h>
+
+namespace Swift {
+ class DiscoItemsConvertor : public GenericLuaElementConvertor<DiscoItems> {
+ public:
+ DiscoItemsConvertor();
+ virtual ~DiscoItemsConvertor();
+
+ virtual boost::shared_ptr<DiscoItems> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<DiscoItems>) SWIFTEN_OVERRIDE;
+ };
+}
diff --git a/Sluift/ElementConvertors/ElementConvertors.ipp b/Sluift/ElementConvertors/ElementConvertors.ipp
new file mode 100644
index 0000000..b7b9166
--- /dev/null
+++ b/Sluift/ElementConvertors/ElementConvertors.ipp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubRetractConvertor.h>
+#include <Sluift/ElementConvertors/PubSubAffiliationsConvertor.h>
+#include <Sluift/ElementConvertors/PubSubPublishConvertor.h>
+#include <Sluift/ElementConvertors/PubSubItemsConvertor.h>
+#include <Sluift/ElementConvertors/PubSubOwnerRedirectConvertor.h>
+#include <Sluift/ElementConvertors/PubSubEventRedirectConvertor.h>
+#include <Sluift/ElementConvertors/PubSubConfigureConvertor.h>
+#include <Sluift/ElementConvertors/PubSubEventDisassociateConvertor.h>
+#include <Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.h>
+#include <Sluift/ElementConvertors/PubSubOwnerConfigureConvertor.h>
+#include <Sluift/ElementConvertors/UserLocationConvertor.h>
+#include <Sluift/ElementConvertors/PubSubSubscribeOptionsConvertor.h>
+#include <Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.h>
+#include <Sluift/ElementConvertors/PubSubDefaultConvertor.h>
+#include <Sluift/ElementConvertors/PubSubEventCollectionConvertor.h>
+#include <Sluift/ElementConvertors/PubSubEventSubscriptionConvertor.h>
+#include <Sluift/ElementConvertors/PubSubEventRetractConvertor.h>
+#include <Sluift/ElementConvertors/PubSubItemConvertor.h>
+#include <Sluift/ElementConvertors/PubSubUnsubscribeConvertor.h>
+#include <Sluift/ElementConvertors/PubSubEventDeleteConvertor.h>
+#include <Sluift/ElementConvertors/PubSubCreateConvertor.h>
+#include <Sluift/ElementConvertors/PubSubOwnerPurgeConvertor.h>
+#include <Sluift/ElementConvertors/PubSubEventItemsConvertor.h>
+#include <Sluift/ElementConvertors/PubSubOptionsConvertor.h>
+#include <Sluift/ElementConvertors/PubSubEventItemConvertor.h>
+#include <Sluift/ElementConvertors/PubSubOwnerSubscriptionConvertor.h>
+#include <Sluift/ElementConvertors/PubSubOwnerAffiliationConvertor.h>
+#include <Sluift/ElementConvertors/PubSubEventPurgeConvertor.h>
+#include <Sluift/ElementConvertors/PubSubAffiliationConvertor.h>
+#include <Sluift/ElementConvertors/PubSubSubscribeConvertor.h>
+#include <Sluift/ElementConvertors/PubSubOwnerDeleteConvertor.h>
+#include <Sluift/ElementConvertors/PubSubOwnerDefaultConvertor.h>
+#include <Sluift/ElementConvertors/PubSubSubscriptionsConvertor.h>
+#include <Sluift/ElementConvertors/PubSubEventAssociateConvertor.h>
+#include <Sluift/ElementConvertors/PubSubSubscriptionConvertor.h>
+#include <Sluift/ElementConvertors/PubSubEventConfigurationConvertor.h>
+
+void LuaElementConvertors::registerConvertors() {
+ convertors.push_back(boost::make_shared<PubSubRetractConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubAffiliationsConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubPublishConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubItemsConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubOwnerRedirectConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubEventRedirectConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubConfigureConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubEventDisassociateConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubOwnerAffiliationsConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubOwnerConfigureConvertor>(this));
+ convertors.push_back(boost::make_shared<UserLocationConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubSubscribeOptionsConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubOwnerSubscriptionsConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubDefaultConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubEventCollectionConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubEventSubscriptionConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubEventRetractConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubItemConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubUnsubscribeConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubEventDeleteConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubCreateConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubOwnerPurgeConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubEventItemsConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubOptionsConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubEventItemConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubOwnerSubscriptionConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubOwnerAffiliationConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubEventPurgeConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubAffiliationConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubSubscribeConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubOwnerDeleteConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubOwnerDefaultConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubSubscriptionsConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubEventAssociateConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubSubscriptionConvertor>(this));
+ convertors.push_back(boost::make_shared<PubSubEventConfigurationConvertor>(this));
+}
diff --git a/Sluift/ElementConvertors/FormConvertor.cpp b/Sluift/ElementConvertors/FormConvertor.cpp
new file mode 100644
index 0000000..1720037
--- /dev/null
+++ b/Sluift/ElementConvertors/FormConvertor.cpp
@@ -0,0 +1,331 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/FormConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+#include <Sluift/Lua/Check.h>
+#include <Sluift/Lua/Value.h>
+#include <Swiften/Base/foreach.h>
+#include <boost/assign/list_of.hpp>
+#include <sstream>
+
+using namespace Swift;
+
+namespace {
+ // TODO: add __newindex to set a field value
+ int formIndex(lua_State* L) {
+ lua_getfield(L, 1, "fields");
+ if (lua_type(L, -1) != LUA_TTABLE) {
+ return 0;
+ }
+ int index = Lua::absoluteOffset(L, -1);
+ lua_pushnil(L);
+ for (lua_pushnil(L); lua_next(L, index) != 0; ) {
+ lua_getfield(L, -1, "name");
+ if (lua_equal(L, -1, 2)) {
+ lua_pop(L, 1);
+ return 1;
+ }
+ lua_pop(L, 2);
+ }
+ return 0;
+ }
+
+ Lua::Table convertFieldToLua(boost::shared_ptr<FormField> field) {
+ Lua::Table luaField = boost::assign::map_list_of("name", Lua::valueRef(field->getName()));
+ std::string type;
+ switch (field->getType()) {
+ case FormField::UnknownType: type = ""; break;
+ case FormField::BooleanType: type = "boolean"; break;
+ case FormField::FixedType: type = "fixed"; break;
+ case FormField::HiddenType: type = "hidden"; break;
+ case FormField::ListSingleType: type = "list-single"; break;
+ case FormField::TextMultiType: type = "text-multi"; break;
+ case FormField::TextPrivateType: type = "text-private"; break;
+ case FormField::TextSingleType: type = "text-single"; break;
+ case FormField::JIDSingleType: type = "jid-single"; break;
+ case FormField::JIDMultiType: type = "jid-multi"; break;
+ case FormField::ListMultiType: type = "list-multi"; break;
+ }
+ if (!type.empty()) {
+ luaField["type"] = Lua::valueRef(type);
+ }
+ if (!field->getLabel().empty()) {
+ luaField["label"] = Lua::valueRef(field->getLabel());
+ }
+ if (field->getRequired()) {
+ luaField["required"] = Lua::boolRef(field->getRequired());
+ }
+ if (!field->getDescription().empty()) {
+ luaField["description"] = Lua::valueRef(field->getDescription());
+ }
+
+ if (field->getType() == FormField::ListMultiType || field->getType() == FormField::JIDMultiType || field->getType() == FormField::TextMultiType) {
+ luaField["values"] = Lua::valueRef(Lua::Array(field->getValues().begin(), field->getValues().end()));
+ }
+ else if (field->getType() == FormField::BooleanType) {
+ luaField["value"] = Lua::boolRef(field->getBoolValue());
+ }
+ else if (!field->getValues().empty()) {
+ luaField["value"] = Lua::valueRef(field->getValues()[0]);
+ }
+
+ if (!field->getOptions().empty()) {
+ Lua::Array options;
+ foreach(const FormField::Option& option, field->getOptions()) {
+ Lua::Table luaOption = boost::assign::map_list_of
+ ("label", Lua::valueRef(option.label))
+ ("value", Lua::valueRef(option.value));
+ options.push_back(luaOption);
+ }
+ luaField["options"] = valueRef(options);
+ }
+ return luaField;
+ }
+
+ Lua::Array convertFieldListToLua(const std::vector< boost::shared_ptr<FormField> >& fieldList) {
+ Lua::Array fields;
+ foreach(boost::shared_ptr<FormField> field, fieldList) {
+ fields.push_back(convertFieldToLua(field));
+ }
+ return fields;
+ }
+
+
+ boost::shared_ptr<FormField> convertFieldFromLua(lua_State* L) {
+ boost::shared_ptr<FormField> result = boost::make_shared<FormField>();
+ FormField::Type fieldType = FormField::UnknownType;
+ boost::optional<std::string> type = Lua::getStringField(L, -1, "type");
+ if (type) {
+ if (*type == "boolean") {
+ fieldType = FormField::BooleanType;
+ }
+ if (*type == "fixed") {
+ fieldType = FormField::FixedType;
+ }
+ if (*type == "hidden") {
+ fieldType = FormField::HiddenType;
+ }
+ if (*type == "list-single") {
+ fieldType = FormField::ListSingleType;
+ }
+ if (*type == "text-multi") {
+ fieldType = FormField::TextMultiType;
+ }
+ if (*type == "text-private") {
+ fieldType = FormField::TextPrivateType;
+ }
+ if (*type == "text-single") {
+ fieldType = FormField::TextSingleType;
+ }
+ if (*type == "jid-single") {
+ fieldType = FormField::JIDSingleType;
+ }
+ if (*type == "jid-multi") {
+ fieldType = FormField::JIDMultiType;
+ }
+ if (*type == "list-multi") {
+ fieldType = FormField::ListMultiType;
+ }
+ }
+ result->setType(fieldType);
+ if (boost::optional<std::string> name = Lua::getStringField(L, -1, "name")) {
+ result->setName(*name);
+ }
+ if (boost::optional<std::string> description = Lua::getStringField(L, -1, "description")) {
+ result->setDescription(*description);
+ }
+ if (boost::optional<std::string> label = Lua::getStringField(L, -1, "label")) {
+ result->setLabel(*label);
+ }
+ if (boost::optional<bool> required = Lua::getBooleanField(L, -1, "required")) {
+ result->setRequired(*required);
+ }
+ if (boost::optional<std::string> value = Lua::getStringField(L, -1, "value")) {
+ result->addValue(*value);
+ }
+ else if (boost::optional<bool> value = Lua::getBooleanField(L, -1, "value")) {
+ result->setBoolValue(*value);
+ }
+ else {
+ lua_getfield(L, -1, "values");
+ if (lua_istable(L, -1)) {
+ for (lua_pushnil(L); lua_next(L, -2); ) {
+ if (lua_isstring(L, -1)) {
+ result->addValue(lua_tostring(L, -1));
+ }
+ lua_pop(L, 1);
+ }
+ }
+ lua_pop(L, 1);
+ }
+ lua_getfield(L, -1, "options");
+ if (lua_istable(L, -1)) {
+ for (lua_pushnil(L); lua_next(L, -2); ) {
+ if (lua_istable(L, -1)) {
+ FormField::Option option("", "");
+ if (boost::optional<std::string> value = Lua::getStringField(L, -1, "value")) {
+ option.value = *value;
+ }
+ if (boost::optional<std::string> label = Lua::getStringField(L, -1, "label")) {
+ option.label = *label;
+ }
+ result->addOption(option);
+ }
+ lua_pop(L, 1);
+ }
+ }
+ lua_pop(L, 1);
+ return result;
+ }
+
+ std::vector< boost::shared_ptr<FormField> > convertFieldListFromLua(lua_State* L) {
+ std::vector< boost::shared_ptr<FormField> > result;
+ for (lua_pushnil(L); lua_next(L, -2);) {
+ result.push_back(convertFieldFromLua(L));
+ lua_pop(L, 1);
+ }
+ return result;
+ }
+
+ boost::shared_ptr<Form> convertFormFromLua(lua_State* L) {
+ boost::shared_ptr<Form> result = boost::make_shared<Form>();
+ if (boost::optional<std::string> title = Lua::getStringField(L, -1, "title")) {
+ result->setTitle(*title);
+ }
+ if (boost::optional<std::string> instructions = Lua::getStringField(L, -1, "instructions")) {
+ result->setInstructions(*instructions);
+ }
+ if (boost::optional<std::string> type = Lua::getStringField(L, -1, "type")) {
+ Form::Type formType = Form::FormType;
+ if (*type == "submit") {
+ formType = Form::SubmitType;
+ }
+ else if (*type == "cancel") {
+ formType = Form::CancelType;
+ }
+ else if (*type == "result") {
+ formType = Form::ResultType;
+ }
+ result->setType(formType);
+ }
+
+ lua_getfield(L, -1, "fields");
+ if (lua_istable(L, -1)) {
+ foreach (boost::shared_ptr<FormField> formField, convertFieldListFromLua(L)) {
+ result->addField(formField);
+ }
+ }
+ lua_pop(L, 1);
+
+ lua_getfield(L, -1, "reported_fields");
+ if (lua_istable(L, -1)) {
+ foreach (boost::shared_ptr<FormField> formField, convertFieldListFromLua(L)) {
+ result->addReportedField(formField);
+ }
+ }
+ lua_pop(L, 1);
+
+ lua_getfield(L, -1, "items");
+ if (lua_istable(L, -1)) {
+ for (lua_pushnil(L); lua_next(L, -2);) {
+ result->addItem(convertFieldListFromLua(L));
+ lua_pop(L, 1);
+ }
+ }
+ lua_pop(L, 1);
+
+ return result;
+ }
+
+ void convertFormToLua(lua_State* L, boost::shared_ptr<Form> payload) {
+ std::string type;
+ switch (payload->getType()) {
+ case Form::FormType: type = "form"; break;
+ case Form::SubmitType: type = "submit"; break;
+ case Form::CancelType: type = "cancel"; break;
+ case Form::ResultType: type = "result"; break;
+ }
+
+ Lua::Table result = boost::assign::map_list_of("type", Lua::valueRef(type));
+ if (!payload->getTitle().empty()) {
+ result["title"] = Lua::valueRef(payload->getTitle());
+ }
+ if (!payload->getInstructions().empty()) {
+ result["instructions"] = Lua::valueRef(payload->getInstructions());
+ }
+ if (!payload->getFields().empty()) {
+ result["fields"] = valueRef(convertFieldListToLua(payload->getFields()));
+ }
+ if (!payload->getReportedFields().empty()) {
+ result["reported_fields"] = valueRef(convertFieldListToLua(payload->getReportedFields()));
+ }
+
+ if (!payload->getItems().empty()) {
+ Lua::Array luaItems;
+ foreach(const Form::FormItem& item, payload->getItems()) {
+ if (!item.empty()) {
+ luaItems.push_back(convertFieldListToLua(item));
+ }
+ }
+ result["items"] = valueRef(luaItems);
+ }
+
+ Lua::pushValue(L, result);
+ lua_newtable(L);
+ lua_pushcfunction(L, formIndex);
+ lua_setfield(L, -2, "__index");
+ lua_setmetatable(L, -2);
+ }
+
+ int createSubmission(lua_State* L) {
+ boost::shared_ptr<Form> form = convertFormFromLua(L);
+
+ // Remove all redundant elements
+ form->setInstructions("");
+ form->setTitle("");
+ form->clearItems();
+ form->clearReportedFields();
+ std::vector< boost::shared_ptr<FormField> > fields(form->getFields());
+ form->clearFields();
+ foreach (boost::shared_ptr<FormField> field, fields) {
+ if (field->getType() == FormField::FixedType) {
+ continue;
+ }
+ field->clearOptions();
+ field->setLabel("");
+ field->setType(FormField::UnknownType);
+ field->setDescription("");
+ form->addField(field);
+ }
+
+ // Convert back
+ convertFormToLua(L, form);
+ Lua::registerTableToString(L, -1);
+ return 1;
+ }
+}
+
+FormConvertor::FormConvertor() : GenericLuaElementConvertor<Form>("form") {
+}
+
+FormConvertor::~FormConvertor() {
+}
+
+boost::shared_ptr<Form> FormConvertor::doConvertFromLua(lua_State* L) {
+ return convertFormFromLua(L);
+}
+
+void FormConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<Form> payload) {
+ convertFormToLua(L, payload);
+
+ lua_pushcfunction(L, createSubmission);
+ lua_setfield(L, -2, "create_submission");
+
+}
diff --git a/Sluift/ElementConvertors/FormConvertor.h b/Sluift/ElementConvertors/FormConvertor.h
new file mode 100644
index 0000000..eaccf74
--- /dev/null
+++ b/Sluift/ElementConvertors/FormConvertor.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/Form.h>
+
+namespace Swift {
+ class FormConvertor : public GenericLuaElementConvertor<Form> {
+ public:
+ FormConvertor();
+ virtual ~FormConvertor();
+
+ virtual boost::shared_ptr<Form> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<Form>) SWIFTEN_OVERRIDE;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubAffiliationConvertor.cpp b/Sluift/ElementConvertors/PubSubAffiliationConvertor.cpp
new file mode 100644
index 0000000..3d40be9
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubAffiliationConvertor.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubAffiliationConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubAffiliationConvertor::PubSubAffiliationConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubAffiliation>("pubsub_affiliation"),
+ convertors(convertors) {
+}
+
+PubSubAffiliationConvertor::~PubSubAffiliationConvertor() {
+}
+
+boost::shared_ptr<PubSubAffiliation> PubSubAffiliationConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubAffiliation> result = boost::make_shared<PubSubAffiliation>();
+ 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, "type");
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubAffiliationConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubAffiliation> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ switch (payload->getType()) {
+ case PubSubAffiliation::None:
+ lua_pushstring(L, "none");
+ break;
+ case PubSubAffiliation::Member:
+ lua_pushstring(L, "member");
+ break;
+ case PubSubAffiliation::Outcast:
+ lua_pushstring(L, "outcast");
+ break;
+ case PubSubAffiliation::Owner:
+ lua_pushstring(L, "owner");
+ break;
+ case PubSubAffiliation::Publisher:
+ lua_pushstring(L, "publisher");
+ break;
+ case PubSubAffiliation::PublishOnly:
+ lua_pushstring(L, "publish_only");
+ break;
+ }
+ lua_setfield(L, -2, "type");
+}
diff --git a/Sluift/ElementConvertors/PubSubAffiliationConvertor.h b/Sluift/ElementConvertors/PubSubAffiliationConvertor.h
new file mode 100644
index 0000000..632a8d7
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubAffiliationConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubAffiliation.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubAffiliationConvertor : public GenericLuaElementConvertor<PubSubAffiliation> {
+ public:
+ PubSubAffiliationConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubAffiliationConvertor();
+
+ virtual boost::shared_ptr<PubSubAffiliation> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubAffiliation>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubAffiliationsConvertor.cpp b/Sluift/ElementConvertors/PubSubAffiliationsConvertor.cpp
new file mode 100644
index 0000000..9f34235
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubAffiliationsConvertor.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubAffiliationsConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include <Sluift/LuaElementConvertors.h>
+#include <Swiften/Base/foreach.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubAffiliationsConvertor::PubSubAffiliationsConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubAffiliations>("pubsub_affiliations"),
+ convertors(convertors) {
+}
+
+PubSubAffiliationsConvertor::~PubSubAffiliationsConvertor() {
+}
+
+boost::shared_ptr<PubSubAffiliations> PubSubAffiliationsConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubAffiliations> result = boost::make_shared<PubSubAffiliations>();
+ lua_getfield(L, -1, "node");
+ if (lua_isstring(L, -1)) {
+ result->setNode(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ if (lua_type(L, -1) == LUA_TTABLE) {
+ std::vector< boost::shared_ptr<PubSubAffiliation> > items;
+ for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
+ lua_pushnumber(L, i + 1);
+ lua_gettable(L, -2);
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubAffiliation> payload = boost::dynamic_pointer_cast<PubSubAffiliation>(convertors->convertFromLuaUntyped(L, -1, "pubsub_affiliation"))) {
+ items.push_back(payload);
+ }
+ }
+ lua_pop(L, 1);
+ }
+
+ result->setAffiliations(items);
+ }
+ return result;
+}
+
+void PubSubAffiliationsConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubAffiliations> payload) {
+ lua_createtable(L, 0, 0);
+ if (payload->getNode()) {
+ lua_pushstring(L, (*payload->getNode()).c_str());
+ lua_setfield(L, -2, "node");
+ }
+ if (!payload->getAffiliations().empty()) {
+ {
+ int i = 0;
+ foreach(boost::shared_ptr<PubSubAffiliation> item, payload->getAffiliations()) {
+ if (convertors->convertToLuaUntyped(L, item) > 0) {
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ ++i;
+ }
+ }
+ }
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubAffiliationsConvertor.h b/Sluift/ElementConvertors/PubSubAffiliationsConvertor.h
new file mode 100644
index 0000000..fb0279a
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubAffiliationsConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubAffiliations.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubAffiliationsConvertor : public GenericLuaElementConvertor<PubSubAffiliations> {
+ public:
+ PubSubAffiliationsConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubAffiliationsConvertor();
+
+ virtual boost::shared_ptr<PubSubAffiliations> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubAffiliations>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubConfigureConvertor.cpp b/Sluift/ElementConvertors/PubSubConfigureConvertor.cpp
new file mode 100644
index 0000000..893bc27
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubConfigureConvertor.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubConfigureConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+#include <Sluift/LuaElementConvertors.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubConfigureConvertor::PubSubConfigureConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubConfigure>("pubsub_configure"),
+ convertors(convertors) {
+}
+
+PubSubConfigureConvertor::~PubSubConfigureConvertor() {
+}
+
+boost::shared_ptr<PubSubConfigure> PubSubConfigureConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubConfigure> result = boost::make_shared<PubSubConfigure>();
+ lua_getfield(L, -1, "data");
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<Form> payload = boost::dynamic_pointer_cast<Form>(convertors->convertFromLuaUntyped(L, -1, "form"))) {
+ result->setData(payload);
+ }
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubConfigureConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubConfigure> payload) {
+ lua_createtable(L, 0, 0);
+ if (convertors->convertToLuaUntyped(L, payload->getData()) > 0) {
+ lua_setfield(L, -2, "data");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubConfigureConvertor.h b/Sluift/ElementConvertors/PubSubConfigureConvertor.h
new file mode 100644
index 0000000..0dd9094
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubConfigureConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubConfigure.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubConfigureConvertor : public GenericLuaElementConvertor<PubSubConfigure> {
+ public:
+ PubSubConfigureConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubConfigureConvertor();
+
+ virtual boost::shared_ptr<PubSubConfigure> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubConfigure>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubCreateConvertor.cpp b/Sluift/ElementConvertors/PubSubCreateConvertor.cpp
new file mode 100644
index 0000000..64e2ee3
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubCreateConvertor.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubCreateConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+#include <Sluift/LuaElementConvertors.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubCreateConvertor::PubSubCreateConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubCreate>("pubsub_create"),
+ convertors(convertors) {
+}
+
+PubSubCreateConvertor::~PubSubCreateConvertor() {
+}
+
+boost::shared_ptr<PubSubCreate> PubSubCreateConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubCreate> result = boost::make_shared<PubSubCreate>();
+ 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, "configure");
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubConfigure> payload = boost::dynamic_pointer_cast<PubSubConfigure>(convertors->convertFromLuaUntyped(L, -1, "pubsub_configure"))) {
+ result->setConfigure(payload);
+ }
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubCreateConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubCreate> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ if (convertors->convertToLuaUntyped(L, payload->getConfigure()) > 0) {
+ lua_setfield(L, -2, "configure");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubCreateConvertor.h b/Sluift/ElementConvertors/PubSubCreateConvertor.h
new file mode 100644
index 0000000..2cb1ea6
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubCreateConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubCreate.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubCreateConvertor : public GenericLuaElementConvertor<PubSubCreate> {
+ public:
+ PubSubCreateConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubCreateConvertor();
+
+ virtual boost::shared_ptr<PubSubCreate> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubCreate>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubDefaultConvertor.cpp b/Sluift/ElementConvertors/PubSubDefaultConvertor.cpp
new file mode 100644
index 0000000..89609ed
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubDefaultConvertor.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubDefaultConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubDefaultConvertor::PubSubDefaultConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubDefault>("pubsub_default"),
+ convertors(convertors) {
+}
+
+PubSubDefaultConvertor::~PubSubDefaultConvertor() {
+}
+
+boost::shared_ptr<PubSubDefault> PubSubDefaultConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubDefault> result = boost::make_shared<PubSubDefault>();
+ 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, "type");
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubDefaultConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubDefault> payload) {
+ lua_createtable(L, 0, 0);
+ if (payload->getNode()) {
+ lua_pushstring(L, (*payload->getNode()).c_str());
+ lua_setfield(L, -2, "node");
+ }
+ switch (payload->getType()) {
+ case PubSubDefault::None:
+ lua_pushstring(L, "none");
+ break;
+ case PubSubDefault::Collection:
+ lua_pushstring(L, "collection");
+ break;
+ case PubSubDefault::Leaf:
+ lua_pushstring(L, "leaf");
+ break;
+ }
+ lua_setfield(L, -2, "type");
+}
diff --git a/Sluift/ElementConvertors/PubSubDefaultConvertor.h b/Sluift/ElementConvertors/PubSubDefaultConvertor.h
new file mode 100644
index 0000000..89dd9be
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubDefaultConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubDefault.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubDefaultConvertor : public GenericLuaElementConvertor<PubSubDefault> {
+ public:
+ PubSubDefaultConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubDefaultConvertor();
+
+ virtual boost::shared_ptr<PubSubDefault> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubDefault>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubEventAssociateConvertor.cpp b/Sluift/ElementConvertors/PubSubEventAssociateConvertor.cpp
new file mode 100644
index 0000000..2b004c8
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventAssociateConvertor.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubEventAssociateConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubEventAssociateConvertor::PubSubEventAssociateConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubEventAssociate>("pubsub_event_associate"),
+ convertors(convertors) {
+}
+
+PubSubEventAssociateConvertor::~PubSubEventAssociateConvertor() {
+}
+
+boost::shared_ptr<PubSubEventAssociate> PubSubEventAssociateConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubEventAssociate> result = boost::make_shared<PubSubEventAssociate>();
+ lua_getfield(L, -1, "node");
+ if (lua_isstring(L, -1)) {
+ result->setNode(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubEventAssociateConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubEventAssociate> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+}
diff --git a/Sluift/ElementConvertors/PubSubEventAssociateConvertor.h b/Sluift/ElementConvertors/PubSubEventAssociateConvertor.h
new file mode 100644
index 0000000..60c9d28
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventAssociateConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubEventAssociate.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubEventAssociateConvertor : public GenericLuaElementConvertor<PubSubEventAssociate> {
+ public:
+ PubSubEventAssociateConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubEventAssociateConvertor();
+
+ virtual boost::shared_ptr<PubSubEventAssociate> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubEventAssociate>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubEventCollectionConvertor.cpp b/Sluift/ElementConvertors/PubSubEventCollectionConvertor.cpp
new file mode 100644
index 0000000..d05b479
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventCollectionConvertor.cpp
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubEventCollectionConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+#include <Sluift/LuaElementConvertors.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubEventCollectionConvertor::PubSubEventCollectionConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubEventCollection>("pubsub_event_collection"),
+ convertors(convertors) {
+}
+
+PubSubEventCollectionConvertor::~PubSubEventCollectionConvertor() {
+}
+
+boost::shared_ptr<PubSubEventCollection> PubSubEventCollectionConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubEventCollection> result = boost::make_shared<PubSubEventCollection>();
+ 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, "disassociate");
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubEventDisassociate> payload = boost::dynamic_pointer_cast<PubSubEventDisassociate>(convertors->convertFromLuaUntyped(L, -1, "pubsub_event_disassociate"))) {
+ result->setDisassociate(payload);
+ }
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "associate");
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubEventAssociate> payload = boost::dynamic_pointer_cast<PubSubEventAssociate>(convertors->convertFromLuaUntyped(L, -1, "pubsub_event_associate"))) {
+ result->setAssociate(payload);
+ }
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubEventCollectionConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubEventCollection> payload) {
+ lua_createtable(L, 0, 0);
+ if (payload->getNode()) {
+ lua_pushstring(L, (*payload->getNode()).c_str());
+ lua_setfield(L, -2, "node");
+ }
+ if (convertors->convertToLuaUntyped(L, payload->getDisassociate()) > 0) {
+ lua_setfield(L, -2, "disassociate");
+ }
+ if (convertors->convertToLuaUntyped(L, payload->getAssociate()) > 0) {
+ lua_setfield(L, -2, "associate");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubEventCollectionConvertor.h b/Sluift/ElementConvertors/PubSubEventCollectionConvertor.h
new file mode 100644
index 0000000..eed2541
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventCollectionConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubEventCollection.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubEventCollectionConvertor : public GenericLuaElementConvertor<PubSubEventCollection> {
+ public:
+ PubSubEventCollectionConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubEventCollectionConvertor();
+
+ virtual boost::shared_ptr<PubSubEventCollection> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubEventCollection>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubEventConfigurationConvertor.cpp b/Sluift/ElementConvertors/PubSubEventConfigurationConvertor.cpp
new file mode 100644
index 0000000..ecdf145
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventConfigurationConvertor.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubEventConfigurationConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+#include <Sluift/LuaElementConvertors.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubEventConfigurationConvertor::PubSubEventConfigurationConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubEventConfiguration>("pubsub_event_configuration"),
+ convertors(convertors) {
+}
+
+PubSubEventConfigurationConvertor::~PubSubEventConfigurationConvertor() {
+}
+
+boost::shared_ptr<PubSubEventConfiguration> PubSubEventConfigurationConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubEventConfiguration> result = boost::make_shared<PubSubEventConfiguration>();
+ 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, "data");
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<Form> payload = boost::dynamic_pointer_cast<Form>(convertors->convertFromLuaUntyped(L, -1, "form"))) {
+ result->setData(payload);
+ }
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubEventConfigurationConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubEventConfiguration> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ if (convertors->convertToLuaUntyped(L, payload->getData()) > 0) {
+ lua_setfield(L, -2, "data");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubEventConfigurationConvertor.h b/Sluift/ElementConvertors/PubSubEventConfigurationConvertor.h
new file mode 100644
index 0000000..4347ebc
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventConfigurationConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubEventConfiguration.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubEventConfigurationConvertor : public GenericLuaElementConvertor<PubSubEventConfiguration> {
+ public:
+ PubSubEventConfigurationConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubEventConfigurationConvertor();
+
+ virtual boost::shared_ptr<PubSubEventConfiguration> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubEventConfiguration>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubEventConvertor.cpp b/Sluift/ElementConvertors/PubSubEventConvertor.cpp
new file mode 100644
index 0000000..46d870a
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventConvertor.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubEventConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+#include <Sluift/LuaElementConvertors.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubEventConvertor::PubSubEventConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubEvent>("pubsub_event"),
+ convertors(convertors) {
+}
+
+PubSubEventConvertor::~PubSubEventConvertor() {
+}
+
+boost::shared_ptr<PubSubEvent> PubSubEventConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubEvent> result = boost::make_shared<PubSubEvent>();
+ if (boost::shared_ptr<PubSubEventPayload> payload = boost::dynamic_pointer_cast<PubSubEventPayload>(convertors->convertFromLua(L, -1))) {
+ result->setPayload(payload);
+ }
+ return result;
+}
+
+void PubSubEventConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubEvent> event) {
+ convertors->convertToLua(L, event->getPayload());
+}
diff --git a/Sluift/ElementConvertors/PubSubEventConvertor.h b/Sluift/ElementConvertors/PubSubEventConvertor.h
new file mode 100644
index 0000000..8250fc4
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubEvent.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubEventConvertor : public GenericLuaElementConvertor<PubSubEvent> {
+ public:
+ PubSubEventConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubEventConvertor();
+
+ virtual boost::shared_ptr<PubSubEvent> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubEvent>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubEventDeleteConvertor.cpp b/Sluift/ElementConvertors/PubSubEventDeleteConvertor.cpp
new file mode 100644
index 0000000..b03f22a
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventDeleteConvertor.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubEventDeleteConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+#include <Sluift/LuaElementConvertors.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubEventDeleteConvertor::PubSubEventDeleteConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubEventDelete>("pubsub_event_delete"),
+ convertors(convertors) {
+}
+
+PubSubEventDeleteConvertor::~PubSubEventDeleteConvertor() {
+}
+
+boost::shared_ptr<PubSubEventDelete> PubSubEventDeleteConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubEventDelete> result = boost::make_shared<PubSubEventDelete>();
+ 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, "redirects");
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubEventRedirect> payload = boost::dynamic_pointer_cast<PubSubEventRedirect>(convertors->convertFromLuaUntyped(L, -1, "pubsub_event_redirect"))) {
+ result->setRedirects(payload);
+ }
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubEventDeleteConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubEventDelete> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ if (convertors->convertToLuaUntyped(L, payload->getRedirects()) > 0) {
+ lua_setfield(L, -2, "redirects");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubEventDeleteConvertor.h b/Sluift/ElementConvertors/PubSubEventDeleteConvertor.h
new file mode 100644
index 0000000..a0cfd3d
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventDeleteConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubEventDelete.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubEventDeleteConvertor : public GenericLuaElementConvertor<PubSubEventDelete> {
+ public:
+ PubSubEventDeleteConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubEventDeleteConvertor();
+
+ virtual boost::shared_ptr<PubSubEventDelete> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubEventDelete>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubEventDisassociateConvertor.cpp b/Sluift/ElementConvertors/PubSubEventDisassociateConvertor.cpp
new file mode 100644
index 0000000..ccd8c6e
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventDisassociateConvertor.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubEventDisassociateConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubEventDisassociateConvertor::PubSubEventDisassociateConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubEventDisassociate>("pubsub_event_disassociate"),
+ convertors(convertors) {
+}
+
+PubSubEventDisassociateConvertor::~PubSubEventDisassociateConvertor() {
+}
+
+boost::shared_ptr<PubSubEventDisassociate> PubSubEventDisassociateConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubEventDisassociate> result = boost::make_shared<PubSubEventDisassociate>();
+ lua_getfield(L, -1, "node");
+ if (lua_isstring(L, -1)) {
+ result->setNode(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubEventDisassociateConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubEventDisassociate> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+}
diff --git a/Sluift/ElementConvertors/PubSubEventDisassociateConvertor.h b/Sluift/ElementConvertors/PubSubEventDisassociateConvertor.h
new file mode 100644
index 0000000..90c8232
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventDisassociateConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubEventDisassociate.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubEventDisassociateConvertor : public GenericLuaElementConvertor<PubSubEventDisassociate> {
+ public:
+ PubSubEventDisassociateConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubEventDisassociateConvertor();
+
+ virtual boost::shared_ptr<PubSubEventDisassociate> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubEventDisassociate>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubEventItemConvertor.cpp b/Sluift/ElementConvertors/PubSubEventItemConvertor.cpp
new file mode 100644
index 0000000..fab4bff
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventItemConvertor.cpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubEventItemConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include <Sluift/LuaElementConvertors.h>
+#include <Swiften/Base/foreach.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubEventItemConvertor::PubSubEventItemConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubEventItem>("pubsub_event_item"),
+ convertors(convertors) {
+}
+
+PubSubEventItemConvertor::~PubSubEventItemConvertor() {
+}
+
+boost::shared_ptr<PubSubEventItem> PubSubEventItemConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubEventItem> result = boost::make_shared<PubSubEventItem>();
+ 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, "publisher");
+ if (lua_isstring(L, -1)) {
+ result->setPublisher(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "data");
+ if (lua_type(L, -1) == LUA_TTABLE) {
+ std::vector< boost::shared_ptr<Payload> > items;
+ for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
+ lua_pushnumber(L, i + 1);
+ lua_gettable(L, -2);
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<Payload> payload = convertors->convertFromLua(L, -1)) {
+ items.push_back(payload);
+ }
+ }
+ lua_pop(L, 1);
+ }
+
+ result->setData(items);
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "id");
+ if (lua_isstring(L, -1)) {
+ result->setID(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubEventItemConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubEventItem> payload) {
+ lua_createtable(L, 0, 0);
+ if (payload->getNode()) {
+ lua_pushstring(L, (*payload->getNode()).c_str());
+ lua_setfield(L, -2, "node");
+ }
+ if (payload->getPublisher()) {
+ lua_pushstring(L, (*payload->getPublisher()).c_str());
+ lua_setfield(L, -2, "publisher");
+ }
+ if (!payload->getData().empty()) {
+ lua_createtable(L, boost::numeric_cast<int>(payload->getData().size()), 0);
+ {
+ int i = 0;
+ foreach(boost::shared_ptr<Payload> item, payload->getData()) {
+ if (convertors->convertToLua(L, item) > 0) {
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ ++i;
+ }
+ }
+ }
+ lua_setfield(L, -2, "data");
+ }
+ if (payload->getID()) {
+ lua_pushstring(L, (*payload->getID()).c_str());
+ lua_setfield(L, -2, "id");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubEventItemConvertor.h b/Sluift/ElementConvertors/PubSubEventItemConvertor.h
new file mode 100644
index 0000000..340602a
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventItemConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubEventItem.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubEventItemConvertor : public GenericLuaElementConvertor<PubSubEventItem> {
+ public:
+ PubSubEventItemConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubEventItemConvertor();
+
+ virtual boost::shared_ptr<PubSubEventItem> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubEventItem>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubEventItemsConvertor.cpp b/Sluift/ElementConvertors/PubSubEventItemsConvertor.cpp
new file mode 100644
index 0000000..9996cc6
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventItemsConvertor.cpp
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubEventItemsConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include <Sluift/LuaElementConvertors.h>
+#include <Swiften/Base/foreach.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubEventItemsConvertor::PubSubEventItemsConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubEventItems>("pubsub_event_items"),
+ convertors(convertors) {
+}
+
+PubSubEventItemsConvertor::~PubSubEventItemsConvertor() {
+}
+
+boost::shared_ptr<PubSubEventItems> PubSubEventItemsConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubEventItems> result = boost::make_shared<PubSubEventItems>();
+ 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, "items");
+ if (lua_type(L, -1) == LUA_TTABLE) {
+ std::vector< boost::shared_ptr<PubSubEventItem> > items;
+ for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
+ lua_pushnumber(L, i + 1);
+ lua_gettable(L, -2);
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubEventItem> payload = boost::dynamic_pointer_cast<PubSubEventItem>(convertors->convertFromLuaUntyped(L, -1, "pubsub_event_item"))) {
+ items.push_back(payload);
+ }
+ }
+ lua_pop(L, 1);
+ }
+
+ result->setItems(items);
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "retracts");
+ if (lua_type(L, -1) == LUA_TTABLE) {
+ std::vector< boost::shared_ptr<PubSubEventRetract> > items;
+ for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
+ lua_pushnumber(L, i + 1);
+ lua_gettable(L, -2);
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubEventRetract> payload = boost::dynamic_pointer_cast<PubSubEventRetract>(convertors->convertFromLuaUntyped(L, -1, "pubsub_event_retract"))) {
+ items.push_back(payload);
+ }
+ }
+ lua_pop(L, 1);
+ }
+
+ result->setRetracts(items);
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubEventItemsConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubEventItems> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ if (!payload->getItems().empty()) {
+ lua_createtable(L, boost::numeric_cast<int>(payload->getItems().size()), 0);
+ {
+ int i = 0;
+ foreach(boost::shared_ptr<PubSubEventItem> item, payload->getItems()) {
+ if (convertors->convertToLuaUntyped(L, item) > 0) {
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ ++i;
+ }
+ }
+ }
+ lua_setfield(L, -2, "items");
+ }
+ if (!payload->getRetracts().empty()) {
+ lua_createtable(L, boost::numeric_cast<int>(payload->getRetracts().size()), 0);
+ {
+ int i = 0;
+ foreach(boost::shared_ptr<PubSubEventRetract> item, payload->getRetracts()) {
+ if (convertors->convertToLuaUntyped(L, item) > 0) {
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ ++i;
+ }
+ }
+ }
+ lua_setfield(L, -2, "retracts");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubEventItemsConvertor.h b/Sluift/ElementConvertors/PubSubEventItemsConvertor.h
new file mode 100644
index 0000000..9adbf15
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventItemsConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubEventItems.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubEventItemsConvertor : public GenericLuaElementConvertor<PubSubEventItems> {
+ public:
+ PubSubEventItemsConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubEventItemsConvertor();
+
+ virtual boost::shared_ptr<PubSubEventItems> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubEventItems>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubEventPurgeConvertor.cpp b/Sluift/ElementConvertors/PubSubEventPurgeConvertor.cpp
new file mode 100644
index 0000000..e389fcf
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventPurgeConvertor.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubEventPurgeConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubEventPurgeConvertor::PubSubEventPurgeConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubEventPurge>("pubsub_event_purge"),
+ convertors(convertors) {
+}
+
+PubSubEventPurgeConvertor::~PubSubEventPurgeConvertor() {
+}
+
+boost::shared_ptr<PubSubEventPurge> PubSubEventPurgeConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubEventPurge> result = boost::make_shared<PubSubEventPurge>();
+ lua_getfield(L, -1, "node");
+ if (lua_isstring(L, -1)) {
+ result->setNode(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubEventPurgeConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubEventPurge> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+}
diff --git a/Sluift/ElementConvertors/PubSubEventPurgeConvertor.h b/Sluift/ElementConvertors/PubSubEventPurgeConvertor.h
new file mode 100644
index 0000000..d94aa36
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventPurgeConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubEventPurge.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubEventPurgeConvertor : public GenericLuaElementConvertor<PubSubEventPurge> {
+ public:
+ PubSubEventPurgeConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubEventPurgeConvertor();
+
+ virtual boost::shared_ptr<PubSubEventPurge> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubEventPurge>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubEventRedirectConvertor.cpp b/Sluift/ElementConvertors/PubSubEventRedirectConvertor.cpp
new file mode 100644
index 0000000..6e128da
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventRedirectConvertor.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubEventRedirectConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubEventRedirectConvertor::PubSubEventRedirectConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubEventRedirect>("pubsub_event_redirect"),
+ convertors(convertors) {
+}
+
+PubSubEventRedirectConvertor::~PubSubEventRedirectConvertor() {
+}
+
+boost::shared_ptr<PubSubEventRedirect> PubSubEventRedirectConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubEventRedirect> result = boost::make_shared<PubSubEventRedirect>();
+ lua_getfield(L, -1, "uri");
+ if (lua_isstring(L, -1)) {
+ result->setURI(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubEventRedirectConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubEventRedirect> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getURI().c_str());
+ lua_setfield(L, -2, "uri");
+}
diff --git a/Sluift/ElementConvertors/PubSubEventRedirectConvertor.h b/Sluift/ElementConvertors/PubSubEventRedirectConvertor.h
new file mode 100644
index 0000000..4904102
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventRedirectConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubEventRedirect.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubEventRedirectConvertor : public GenericLuaElementConvertor<PubSubEventRedirect> {
+ public:
+ PubSubEventRedirectConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubEventRedirectConvertor();
+
+ virtual boost::shared_ptr<PubSubEventRedirect> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubEventRedirect>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubEventRetractConvertor.cpp b/Sluift/ElementConvertors/PubSubEventRetractConvertor.cpp
new file mode 100644
index 0000000..aed29a0
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventRetractConvertor.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubEventRetractConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubEventRetractConvertor::PubSubEventRetractConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubEventRetract>("pubsub_event_retract"),
+ convertors(convertors) {
+}
+
+PubSubEventRetractConvertor::~PubSubEventRetractConvertor() {
+}
+
+boost::shared_ptr<PubSubEventRetract> PubSubEventRetractConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubEventRetract> result = boost::make_shared<PubSubEventRetract>();
+ lua_getfield(L, -1, "id");
+ if (lua_isstring(L, -1)) {
+ result->setID(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubEventRetractConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubEventRetract> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getID().c_str());
+ lua_setfield(L, -2, "id");
+}
diff --git a/Sluift/ElementConvertors/PubSubEventRetractConvertor.h b/Sluift/ElementConvertors/PubSubEventRetractConvertor.h
new file mode 100644
index 0000000..7a7c0f9
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventRetractConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubEventRetract.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubEventRetractConvertor : public GenericLuaElementConvertor<PubSubEventRetract> {
+ public:
+ PubSubEventRetractConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubEventRetractConvertor();
+
+ virtual boost::shared_ptr<PubSubEventRetract> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubEventRetract>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubEventSubscriptionConvertor.cpp b/Sluift/ElementConvertors/PubSubEventSubscriptionConvertor.cpp
new file mode 100644
index 0000000..68cb34a
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventSubscriptionConvertor.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubEventSubscriptionConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+#include <Swiften/Base/DateTime.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubEventSubscriptionConvertor::PubSubEventSubscriptionConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubEventSubscription>("pubsub_event_subscription"),
+ convertors(convertors) {
+}
+
+PubSubEventSubscriptionConvertor::~PubSubEventSubscriptionConvertor() {
+}
+
+boost::shared_ptr<PubSubEventSubscription> PubSubEventSubscriptionConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubEventSubscription> result = boost::make_shared<PubSubEventSubscription>();
+ 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, "jid");
+ if (lua_isstring(L, -1)) {
+ result->setJID(JID(std::string(lua_tostring(L, -1))));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "subscription");
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "subscriptionid");
+ if (lua_isstring(L, -1)) {
+ result->setSubscriptionID(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "expiry");
+ if (lua_isstring(L, -1)) {
+ result->setExpiry(stringToDateTime(std::string(lua_tostring(L, -1))));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubEventSubscriptionConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubEventSubscription> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ lua_pushstring(L, payload->getJID().toString().c_str());
+ lua_setfield(L, -2, "jid");
+ switch (payload->getSubscription()) {
+ case PubSubEventSubscription::None:
+ lua_pushstring(L, "none");
+ break;
+ case PubSubEventSubscription::Pending:
+ lua_pushstring(L, "pending");
+ break;
+ case PubSubEventSubscription::Subscribed:
+ lua_pushstring(L, "subscribed");
+ break;
+ case PubSubEventSubscription::Unconfigured:
+ lua_pushstring(L, "unconfigured");
+ break;
+ }
+ lua_setfield(L, -2, "subscription");
+ if (payload->getSubscriptionID()) {
+ lua_pushstring(L, (*payload->getSubscriptionID()).c_str());
+ lua_setfield(L, -2, "subscriptionid");
+ }
+ lua_pushstring(L, dateTimeToString(payload->getExpiry()).c_str());
+ lua_setfield(L, -2, "expiry");
+}
diff --git a/Sluift/ElementConvertors/PubSubEventSubscriptionConvertor.h b/Sluift/ElementConvertors/PubSubEventSubscriptionConvertor.h
new file mode 100644
index 0000000..fa04fb7
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubEventSubscriptionConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubEventSubscription.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubEventSubscriptionConvertor : public GenericLuaElementConvertor<PubSubEventSubscription> {
+ public:
+ PubSubEventSubscriptionConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubEventSubscriptionConvertor();
+
+ virtual boost::shared_ptr<PubSubEventSubscription> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubEventSubscription>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubItemConvertor.cpp b/Sluift/ElementConvertors/PubSubItemConvertor.cpp
new file mode 100644
index 0000000..e06065b
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubItemConvertor.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubItemConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include <Sluift/LuaElementConvertors.h>
+#include <Swiften/Base/foreach.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubItemConvertor::PubSubItemConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubItem>("pubsub_item"),
+ convertors(convertors) {
+}
+
+PubSubItemConvertor::~PubSubItemConvertor() {
+}
+
+boost::shared_ptr<PubSubItem> PubSubItemConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubItem> result = boost::make_shared<PubSubItem>();
+ lua_getfield(L, -1, "data");
+ if (lua_type(L, -1) == LUA_TTABLE) {
+ std::vector< boost::shared_ptr<Payload> > items;
+ for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
+ lua_pushnumber(L, i + 1);
+ lua_gettable(L, -2);
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<Payload> payload = convertors->convertFromLua(L, -1)) {
+ items.push_back(payload);
+ }
+ }
+ lua_pop(L, 1);
+ }
+
+ result->setData(items);
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "id");
+ if (lua_isstring(L, -1)) {
+ result->setID(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubItemConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubItem> payload) {
+ lua_createtable(L, 0, 0);
+ if (!payload->getData().empty()) {
+ lua_createtable(L, boost::numeric_cast<int>(payload->getData().size()), 0);
+ {
+ int i = 0;
+ foreach(boost::shared_ptr<Payload> item, payload->getData()) {
+ if (convertors->convertToLua(L, item) > 0) {
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ ++i;
+ }
+ }
+ }
+ lua_setfield(L, -2, "data");
+ }
+ lua_pushstring(L, payload->getID().c_str());
+ lua_setfield(L, -2, "id");
+}
diff --git a/Sluift/ElementConvertors/PubSubItemConvertor.h b/Sluift/ElementConvertors/PubSubItemConvertor.h
new file mode 100644
index 0000000..176e1c4
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubItemConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubItem.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubItemConvertor : public GenericLuaElementConvertor<PubSubItem> {
+ public:
+ PubSubItemConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubItemConvertor();
+
+ virtual boost::shared_ptr<PubSubItem> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubItem>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubItemsConvertor.cpp b/Sluift/ElementConvertors/PubSubItemsConvertor.cpp
new file mode 100644
index 0000000..5ecb72e
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubItemsConvertor.cpp
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubItemsConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include <Sluift/LuaElementConvertors.h>
+#include <Swiften/Base/foreach.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubItemsConvertor::PubSubItemsConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubItems>("pubsub_items"),
+ convertors(convertors) {
+}
+
+PubSubItemsConvertor::~PubSubItemsConvertor() {
+}
+
+boost::shared_ptr<PubSubItems> PubSubItemsConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubItems> result = boost::make_shared<PubSubItems>();
+ lua_getfield(L, -1, "node");
+ if (lua_isstring(L, -1)) {
+ result->setNode(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ if (lua_type(L, -1) == LUA_TTABLE) {
+ std::vector< boost::shared_ptr<PubSubItem> > items;
+ for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
+ lua_pushnumber(L, i + 1);
+ lua_gettable(L, -2);
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubItem> payload = boost::dynamic_pointer_cast<PubSubItem>(convertors->convertFromLuaUntyped(L, -1, "pubsub_item"))) {
+ items.push_back(payload);
+ }
+ }
+ lua_pop(L, 1);
+ }
+
+ result->setItems(items);
+ }
+ lua_getfield(L, -1, "maximum_items");
+ if (lua_isnumber(L, -1)) {
+ result->setMaximumItems(boost::numeric_cast<unsigned int>(lua_tonumber(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "subscriptionid");
+ if (lua_isstring(L, -1)) {
+ result->setSubscriptionID(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubItemsConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubItems> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ if (!payload->getItems().empty()) {
+ {
+ int i = 0;
+ foreach(boost::shared_ptr<PubSubItem> item, payload->getItems()) {
+ if (convertors->convertToLuaUntyped(L, item) > 0) {
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ ++i;
+ }
+ }
+ }
+ }
+ if (payload->getMaximumItems()) {
+ lua_pushnumber(L, (*payload->getMaximumItems()));
+ lua_setfield(L, -2, "maximum_items");
+ }
+ if (payload->getSubscriptionID()) {
+ lua_pushstring(L, (*payload->getSubscriptionID()).c_str());
+ lua_setfield(L, -2, "subscriptionid");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubItemsConvertor.h b/Sluift/ElementConvertors/PubSubItemsConvertor.h
new file mode 100644
index 0000000..9978806
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubItemsConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubItems.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubItemsConvertor : public GenericLuaElementConvertor<PubSubItems> {
+ public:
+ PubSubItemsConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubItemsConvertor();
+
+ virtual boost::shared_ptr<PubSubItems> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubItems>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubOptionsConvertor.cpp b/Sluift/ElementConvertors/PubSubOptionsConvertor.cpp
new file mode 100644
index 0000000..cc27973
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOptionsConvertor.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubOptionsConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+#include <Sluift/LuaElementConvertors.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubOptionsConvertor::PubSubOptionsConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubOptions>("pubsub_options"),
+ convertors(convertors) {
+}
+
+PubSubOptionsConvertor::~PubSubOptionsConvertor() {
+}
+
+boost::shared_ptr<PubSubOptions> PubSubOptionsConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubOptions> result = boost::make_shared<PubSubOptions>();
+ 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, "jid");
+ if (lua_isstring(L, -1)) {
+ result->setJID(JID(std::string(lua_tostring(L, -1))));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "data");
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<Form> payload = boost::dynamic_pointer_cast<Form>(convertors->convertFromLuaUntyped(L, -1, "form"))) {
+ result->setData(payload);
+ }
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "subscriptionid");
+ if (lua_isstring(L, -1)) {
+ result->setSubscriptionID(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubOptionsConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubOptions> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ lua_pushstring(L, payload->getJID().toString().c_str());
+ lua_setfield(L, -2, "jid");
+ if (convertors->convertToLuaUntyped(L, payload->getData()) > 0) {
+ lua_setfield(L, -2, "data");
+ }
+ if (payload->getSubscriptionID()) {
+ lua_pushstring(L, (*payload->getSubscriptionID()).c_str());
+ lua_setfield(L, -2, "subscriptionid");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubOptionsConvertor.h b/Sluift/ElementConvertors/PubSubOptionsConvertor.h
new file mode 100644
index 0000000..95a1dc8
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOptionsConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubOptions.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubOptionsConvertor : public GenericLuaElementConvertor<PubSubOptions> {
+ public:
+ PubSubOptionsConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubOptionsConvertor();
+
+ virtual boost::shared_ptr<PubSubOptions> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubOptions>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerAffiliationConvertor.cpp b/Sluift/ElementConvertors/PubSubOwnerAffiliationConvertor.cpp
new file mode 100644
index 0000000..d7edaf4
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerAffiliationConvertor.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubOwnerAffiliationConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubOwnerAffiliationConvertor::PubSubOwnerAffiliationConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubOwnerAffiliation>("pubsub_owner_affiliation"),
+ convertors(convertors) {
+}
+
+PubSubOwnerAffiliationConvertor::~PubSubOwnerAffiliationConvertor() {
+}
+
+boost::shared_ptr<PubSubOwnerAffiliation> PubSubOwnerAffiliationConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubOwnerAffiliation> result = boost::make_shared<PubSubOwnerAffiliation>();
+ lua_getfield(L, -1, "jid");
+ if (lua_isstring(L, -1)) {
+ result->setJID(JID(std::string(lua_tostring(L, -1))));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "type");
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubOwnerAffiliationConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubOwnerAffiliation> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getJID().toString().c_str());
+ lua_setfield(L, -2, "jid");
+ switch (payload->getType()) {
+ case PubSubOwnerAffiliation::None:
+ lua_pushstring(L, "none");
+ break;
+ case PubSubOwnerAffiliation::Member:
+ lua_pushstring(L, "member");
+ break;
+ case PubSubOwnerAffiliation::Outcast:
+ lua_pushstring(L, "outcast");
+ break;
+ case PubSubOwnerAffiliation::Owner:
+ lua_pushstring(L, "owner");
+ break;
+ case PubSubOwnerAffiliation::Publisher:
+ lua_pushstring(L, "publisher");
+ break;
+ case PubSubOwnerAffiliation::PublishOnly:
+ lua_pushstring(L, "publish_only");
+ break;
+ }
+ lua_setfield(L, -2, "type");
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerAffiliationConvertor.h b/Sluift/ElementConvertors/PubSubOwnerAffiliationConvertor.h
new file mode 100644
index 0000000..72bfaa1
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerAffiliationConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubOwnerAffiliation.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubOwnerAffiliationConvertor : public GenericLuaElementConvertor<PubSubOwnerAffiliation> {
+ public:
+ PubSubOwnerAffiliationConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubOwnerAffiliationConvertor();
+
+ virtual boost::shared_ptr<PubSubOwnerAffiliation> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubOwnerAffiliation>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.cpp b/Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.cpp
new file mode 100644
index 0000000..bee8539
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include <Sluift/LuaElementConvertors.h>
+#include <Swiften/Base/foreach.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubOwnerAffiliationsConvertor::PubSubOwnerAffiliationsConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubOwnerAffiliations>("pubsub_owner_affiliations"),
+ convertors(convertors) {
+}
+
+PubSubOwnerAffiliationsConvertor::~PubSubOwnerAffiliationsConvertor() {
+}
+
+boost::shared_ptr<PubSubOwnerAffiliations> PubSubOwnerAffiliationsConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubOwnerAffiliations> result = boost::make_shared<PubSubOwnerAffiliations>();
+ lua_getfield(L, -1, "node");
+ if (lua_isstring(L, -1)) {
+ result->setNode(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ if (lua_type(L, -1) == LUA_TTABLE) {
+ std::vector< boost::shared_ptr<PubSubOwnerAffiliation> > items;
+ for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
+ lua_pushnumber(L, i + 1);
+ lua_gettable(L, -2);
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubOwnerAffiliation> payload = boost::dynamic_pointer_cast<PubSubOwnerAffiliation>(convertors->convertFromLuaUntyped(L, -1, "pubsub_owner_affiliation"))) {
+ items.push_back(payload);
+ }
+ }
+ lua_pop(L, 1);
+ }
+
+ result->setAffiliations(items);
+ }
+ return result;
+}
+
+void PubSubOwnerAffiliationsConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubOwnerAffiliations> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ if (!payload->getAffiliations().empty()) {
+ {
+ int i = 0;
+ foreach(boost::shared_ptr<PubSubOwnerAffiliation> item, payload->getAffiliations()) {
+ if (convertors->convertToLuaUntyped(L, item) > 0) {
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ ++i;
+ }
+ }
+ }
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.h b/Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.h
new file mode 100644
index 0000000..377e108
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubOwnerAffiliations.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubOwnerAffiliationsConvertor : public GenericLuaElementConvertor<PubSubOwnerAffiliations> {
+ public:
+ PubSubOwnerAffiliationsConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubOwnerAffiliationsConvertor();
+
+ virtual boost::shared_ptr<PubSubOwnerAffiliations> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubOwnerAffiliations>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerConfigureConvertor.cpp b/Sluift/ElementConvertors/PubSubOwnerConfigureConvertor.cpp
new file mode 100644
index 0000000..87505e1
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerConfigureConvertor.cpp
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubOwnerConfigureConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+#include <Sluift/LuaElementConvertors.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubOwnerConfigureConvertor::PubSubOwnerConfigureConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubOwnerConfigure>("pubsub_owner_configure"),
+ convertors(convertors) {
+}
+
+PubSubOwnerConfigureConvertor::~PubSubOwnerConfigureConvertor() {
+}
+
+boost::shared_ptr<PubSubOwnerConfigure> PubSubOwnerConfigureConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubOwnerConfigure> result = boost::make_shared<PubSubOwnerConfigure>();
+ 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, "data");
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<Form> payload = boost::dynamic_pointer_cast<Form>(convertors->convertFromLuaUntyped(L, -1, "form"))) {
+ result->setData(payload);
+ }
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubOwnerConfigureConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubOwnerConfigure> payload) {
+ lua_createtable(L, 0, 0);
+ if (payload->getNode()) {
+ lua_pushstring(L, (*payload->getNode()).c_str());
+ lua_setfield(L, -2, "node");
+ }
+ if (convertors->convertToLuaUntyped(L, payload->getData()) > 0) {
+ lua_setfield(L, -2, "data");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerConfigureConvertor.h b/Sluift/ElementConvertors/PubSubOwnerConfigureConvertor.h
new file mode 100644
index 0000000..83b1153
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerConfigureConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubOwnerConfigure.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubOwnerConfigureConvertor : public GenericLuaElementConvertor<PubSubOwnerConfigure> {
+ public:
+ PubSubOwnerConfigureConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubOwnerConfigureConvertor();
+
+ virtual boost::shared_ptr<PubSubOwnerConfigure> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubOwnerConfigure>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerDefaultConvertor.cpp b/Sluift/ElementConvertors/PubSubOwnerDefaultConvertor.cpp
new file mode 100644
index 0000000..17612cc
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerDefaultConvertor.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubOwnerDefaultConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+#include <Sluift/LuaElementConvertors.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubOwnerDefaultConvertor::PubSubOwnerDefaultConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubOwnerDefault>("pubsub_owner_default"),
+ convertors(convertors) {
+}
+
+PubSubOwnerDefaultConvertor::~PubSubOwnerDefaultConvertor() {
+}
+
+boost::shared_ptr<PubSubOwnerDefault> PubSubOwnerDefaultConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubOwnerDefault> result = boost::make_shared<PubSubOwnerDefault>();
+ lua_getfield(L, -1, "data");
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<Form> payload = boost::dynamic_pointer_cast<Form>(convertors->convertFromLuaUntyped(L, -1, "form"))) {
+ result->setData(payload);
+ }
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubOwnerDefaultConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubOwnerDefault> payload) {
+ lua_createtable(L, 0, 0);
+ if (convertors->convertToLuaUntyped(L, payload->getData()) > 0) {
+ lua_setfield(L, -2, "data");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerDefaultConvertor.h b/Sluift/ElementConvertors/PubSubOwnerDefaultConvertor.h
new file mode 100644
index 0000000..3a0f8ee
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerDefaultConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubOwnerDefault.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubOwnerDefaultConvertor : public GenericLuaElementConvertor<PubSubOwnerDefault> {
+ public:
+ PubSubOwnerDefaultConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubOwnerDefaultConvertor();
+
+ virtual boost::shared_ptr<PubSubOwnerDefault> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubOwnerDefault>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerDeleteConvertor.cpp b/Sluift/ElementConvertors/PubSubOwnerDeleteConvertor.cpp
new file mode 100644
index 0000000..f67ed1e
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerDeleteConvertor.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubOwnerDeleteConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+#include <Sluift/LuaElementConvertors.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubOwnerDeleteConvertor::PubSubOwnerDeleteConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubOwnerDelete>("pubsub_owner_delete"),
+ convertors(convertors) {
+}
+
+PubSubOwnerDeleteConvertor::~PubSubOwnerDeleteConvertor() {
+}
+
+boost::shared_ptr<PubSubOwnerDelete> PubSubOwnerDeleteConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubOwnerDelete> result = boost::make_shared<PubSubOwnerDelete>();
+ 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, "redirect");
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubOwnerRedirect> payload = boost::dynamic_pointer_cast<PubSubOwnerRedirect>(convertors->convertFromLuaUntyped(L, -1, "pubsub_owner_redirect"))) {
+ result->setRedirect(payload);
+ }
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubOwnerDeleteConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubOwnerDelete> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ if (convertors->convertToLuaUntyped(L, payload->getRedirect()) > 0) {
+ lua_setfield(L, -2, "redirect");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerDeleteConvertor.h b/Sluift/ElementConvertors/PubSubOwnerDeleteConvertor.h
new file mode 100644
index 0000000..7475e9c
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerDeleteConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubOwnerDelete.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubOwnerDeleteConvertor : public GenericLuaElementConvertor<PubSubOwnerDelete> {
+ public:
+ PubSubOwnerDeleteConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubOwnerDeleteConvertor();
+
+ virtual boost::shared_ptr<PubSubOwnerDelete> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubOwnerDelete>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerPurgeConvertor.cpp b/Sluift/ElementConvertors/PubSubOwnerPurgeConvertor.cpp
new file mode 100644
index 0000000..a060db9
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerPurgeConvertor.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubOwnerPurgeConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubOwnerPurgeConvertor::PubSubOwnerPurgeConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubOwnerPurge>("pubsub_owner_purge"),
+ convertors(convertors) {
+}
+
+PubSubOwnerPurgeConvertor::~PubSubOwnerPurgeConvertor() {
+}
+
+boost::shared_ptr<PubSubOwnerPurge> PubSubOwnerPurgeConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubOwnerPurge> result = boost::make_shared<PubSubOwnerPurge>();
+ lua_getfield(L, -1, "node");
+ if (lua_isstring(L, -1)) {
+ result->setNode(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubOwnerPurgeConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubOwnerPurge> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerPurgeConvertor.h b/Sluift/ElementConvertors/PubSubOwnerPurgeConvertor.h
new file mode 100644
index 0000000..34c979b
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerPurgeConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubOwnerPurge.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubOwnerPurgeConvertor : public GenericLuaElementConvertor<PubSubOwnerPurge> {
+ public:
+ PubSubOwnerPurgeConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubOwnerPurgeConvertor();
+
+ virtual boost::shared_ptr<PubSubOwnerPurge> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubOwnerPurge>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerRedirectConvertor.cpp b/Sluift/ElementConvertors/PubSubOwnerRedirectConvertor.cpp
new file mode 100644
index 0000000..d11df72
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerRedirectConvertor.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubOwnerRedirectConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubOwnerRedirectConvertor::PubSubOwnerRedirectConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubOwnerRedirect>("pubsub_owner_redirect"),
+ convertors(convertors) {
+}
+
+PubSubOwnerRedirectConvertor::~PubSubOwnerRedirectConvertor() {
+}
+
+boost::shared_ptr<PubSubOwnerRedirect> PubSubOwnerRedirectConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubOwnerRedirect> result = boost::make_shared<PubSubOwnerRedirect>();
+ lua_getfield(L, -1, "uri");
+ if (lua_isstring(L, -1)) {
+ result->setURI(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubOwnerRedirectConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubOwnerRedirect> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getURI().c_str());
+ lua_setfield(L, -2, "uri");
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerRedirectConvertor.h b/Sluift/ElementConvertors/PubSubOwnerRedirectConvertor.h
new file mode 100644
index 0000000..fc1ddce
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerRedirectConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubOwnerRedirect.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubOwnerRedirectConvertor : public GenericLuaElementConvertor<PubSubOwnerRedirect> {
+ public:
+ PubSubOwnerRedirectConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubOwnerRedirectConvertor();
+
+ virtual boost::shared_ptr<PubSubOwnerRedirect> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubOwnerRedirect>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerSubscriptionConvertor.cpp b/Sluift/ElementConvertors/PubSubOwnerSubscriptionConvertor.cpp
new file mode 100644
index 0000000..0216874
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerSubscriptionConvertor.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubOwnerSubscriptionConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubOwnerSubscriptionConvertor::PubSubOwnerSubscriptionConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubOwnerSubscription>("pubsub_owner_subscription"),
+ convertors(convertors) {
+}
+
+PubSubOwnerSubscriptionConvertor::~PubSubOwnerSubscriptionConvertor() {
+}
+
+boost::shared_ptr<PubSubOwnerSubscription> PubSubOwnerSubscriptionConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubOwnerSubscription> result = boost::make_shared<PubSubOwnerSubscription>();
+ lua_getfield(L, -1, "jid");
+ if (lua_isstring(L, -1)) {
+ result->setJID(JID(std::string(lua_tostring(L, -1))));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "subscription");
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubOwnerSubscriptionConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubOwnerSubscription> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getJID().toString().c_str());
+ lua_setfield(L, -2, "jid");
+ switch (payload->getSubscription()) {
+ case PubSubOwnerSubscription::None:
+ lua_pushstring(L, "none");
+ break;
+ case PubSubOwnerSubscription::Pending:
+ lua_pushstring(L, "pending");
+ break;
+ case PubSubOwnerSubscription::Subscribed:
+ lua_pushstring(L, "subscribed");
+ break;
+ case PubSubOwnerSubscription::Unconfigured:
+ lua_pushstring(L, "unconfigured");
+ break;
+ }
+ lua_setfield(L, -2, "subscription");
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerSubscriptionConvertor.h b/Sluift/ElementConvertors/PubSubOwnerSubscriptionConvertor.h
new file mode 100644
index 0000000..ca80c82
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerSubscriptionConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubOwnerSubscription.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubOwnerSubscriptionConvertor : public GenericLuaElementConvertor<PubSubOwnerSubscription> {
+ public:
+ PubSubOwnerSubscriptionConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubOwnerSubscriptionConvertor();
+
+ virtual boost::shared_ptr<PubSubOwnerSubscription> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubOwnerSubscription>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.cpp b/Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.cpp
new file mode 100644
index 0000000..045cf12
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include <Sluift/LuaElementConvertors.h>
+#include <Swiften/Base/foreach.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubOwnerSubscriptionsConvertor::PubSubOwnerSubscriptionsConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubOwnerSubscriptions>("pubsub_owner_subscriptions"),
+ convertors(convertors) {
+}
+
+PubSubOwnerSubscriptionsConvertor::~PubSubOwnerSubscriptionsConvertor() {
+}
+
+boost::shared_ptr<PubSubOwnerSubscriptions> PubSubOwnerSubscriptionsConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubOwnerSubscriptions> result = boost::make_shared<PubSubOwnerSubscriptions>();
+ lua_getfield(L, -1, "node");
+ if (lua_isstring(L, -1)) {
+ result->setNode(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ if (lua_type(L, -1) == LUA_TTABLE) {
+ std::vector< boost::shared_ptr<PubSubOwnerSubscription> > items;
+ for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
+ lua_pushnumber(L, i + 1);
+ lua_gettable(L, -2);
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubOwnerSubscription> payload = boost::dynamic_pointer_cast<PubSubOwnerSubscription>(convertors->convertFromLuaUntyped(L, -1, "pubsub_owner_subscription"))) {
+ items.push_back(payload);
+ }
+ }
+ lua_pop(L, 1);
+ }
+
+ result->setSubscriptions(items);
+ }
+ return result;
+}
+
+void PubSubOwnerSubscriptionsConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubOwnerSubscriptions> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ if (!payload->getSubscriptions().empty()) {
+ {
+ int i = 0;
+ foreach(boost::shared_ptr<PubSubOwnerSubscription> item, payload->getSubscriptions()) {
+ if (convertors->convertToLuaUntyped(L, item) > 0) {
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ ++i;
+ }
+ }
+ }
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.h b/Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.h
new file mode 100644
index 0000000..2e12c93
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubOwnerSubscriptions.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubOwnerSubscriptionsConvertor : public GenericLuaElementConvertor<PubSubOwnerSubscriptions> {
+ public:
+ PubSubOwnerSubscriptionsConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubOwnerSubscriptionsConvertor();
+
+ virtual boost::shared_ptr<PubSubOwnerSubscriptions> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubOwnerSubscriptions>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubPublishConvertor.cpp b/Sluift/ElementConvertors/PubSubPublishConvertor.cpp
new file mode 100644
index 0000000..880d9fc
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubPublishConvertor.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubPublishConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include <Sluift/LuaElementConvertors.h>
+#include <Swiften/Base/foreach.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubPublishConvertor::PubSubPublishConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubPublish>("pubsub_publish"),
+ convertors(convertors) {
+}
+
+PubSubPublishConvertor::~PubSubPublishConvertor() {
+}
+
+boost::shared_ptr<PubSubPublish> PubSubPublishConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubPublish> result = boost::make_shared<PubSubPublish>();
+ 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, "items");
+ if (lua_type(L, -1) == LUA_TTABLE) {
+ std::vector< boost::shared_ptr<PubSubItem> > items;
+ for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
+ lua_pushnumber(L, i + 1);
+ lua_gettable(L, -2);
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubItem> payload = boost::dynamic_pointer_cast<PubSubItem>(convertors->convertFromLuaUntyped(L, -1, "pubsub_item"))) {
+ items.push_back(payload);
+ }
+ }
+ lua_pop(L, 1);
+ }
+
+ result->setItems(items);
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubPublishConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubPublish> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ if (!payload->getItems().empty()) {
+ lua_createtable(L, boost::numeric_cast<int>(payload->getItems().size()), 0);
+ {
+ int i = 0;
+ foreach(boost::shared_ptr<PubSubItem> item, payload->getItems()) {
+ if (convertors->convertToLuaUntyped(L, item) > 0) {
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ ++i;
+ }
+ }
+ }
+ lua_setfield(L, -2, "items");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubPublishConvertor.h b/Sluift/ElementConvertors/PubSubPublishConvertor.h
new file mode 100644
index 0000000..4415566
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubPublishConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubPublish.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubPublishConvertor : public GenericLuaElementConvertor<PubSubPublish> {
+ public:
+ PubSubPublishConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubPublishConvertor();
+
+ virtual boost::shared_ptr<PubSubPublish> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubPublish>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubRetractConvertor.cpp b/Sluift/ElementConvertors/PubSubRetractConvertor.cpp
new file mode 100644
index 0000000..61ca3df
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubRetractConvertor.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubRetractConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include <Sluift/LuaElementConvertors.h>
+#include <Swiften/Base/foreach.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubRetractConvertor::PubSubRetractConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubRetract>("pubsub_retract"),
+ convertors(convertors) {
+}
+
+PubSubRetractConvertor::~PubSubRetractConvertor() {
+}
+
+boost::shared_ptr<PubSubRetract> PubSubRetractConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubRetract> result = boost::make_shared<PubSubRetract>();
+ 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, "items");
+ if (lua_type(L, -1) == LUA_TTABLE) {
+ std::vector< boost::shared_ptr<PubSubItem> > items;
+ for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
+ lua_pushnumber(L, i + 1);
+ lua_gettable(L, -2);
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubItem> payload = boost::dynamic_pointer_cast<PubSubItem>(convertors->convertFromLuaUntyped(L, -1, "pubsub_item"))) {
+ items.push_back(payload);
+ }
+ }
+ lua_pop(L, 1);
+ }
+
+ result->setItems(items);
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "notify");
+ if (lua_isboolean(L, -1)) {
+ result->setNotify(lua_toboolean(L, -1));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubRetractConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubRetract> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getNode().c_str());
+ lua_setfield(L, -2, "node");
+ if (!payload->getItems().empty()) {
+ lua_createtable(L, boost::numeric_cast<int>(payload->getItems().size()), 0);
+ {
+ int i = 0;
+ foreach(boost::shared_ptr<PubSubItem> item, payload->getItems()) {
+ if (convertors->convertToLuaUntyped(L, item) > 0) {
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ ++i;
+ }
+ }
+ }
+ lua_setfield(L, -2, "items");
+ }
+ lua_pushboolean(L, payload->isNotify());
+ lua_setfield(L, -2, "notify");
+}
diff --git a/Sluift/ElementConvertors/PubSubRetractConvertor.h b/Sluift/ElementConvertors/PubSubRetractConvertor.h
new file mode 100644
index 0000000..80d888b
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubRetractConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubRetract.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubRetractConvertor : public GenericLuaElementConvertor<PubSubRetract> {
+ public:
+ PubSubRetractConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubRetractConvertor();
+
+ virtual boost::shared_ptr<PubSubRetract> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubRetract>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubSubscribeConvertor.cpp b/Sluift/ElementConvertors/PubSubSubscribeConvertor.cpp
new file mode 100644
index 0000000..06d6447
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubSubscribeConvertor.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubSubscribeConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+#include <Sluift/LuaElementConvertors.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubSubscribeConvertor::PubSubSubscribeConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubSubscribe>("pubsub_subscribe"),
+ convertors(convertors) {
+}
+
+PubSubSubscribeConvertor::~PubSubSubscribeConvertor() {
+}
+
+boost::shared_ptr<PubSubSubscribe> PubSubSubscribeConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubSubscribe> result = boost::make_shared<PubSubSubscribe>();
+ 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, "jid");
+ if (lua_isstring(L, -1)) {
+ result->setJID(JID(std::string(lua_tostring(L, -1))));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "options");
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubOptions> payload = boost::dynamic_pointer_cast<PubSubOptions>(convertors->convertFromLuaUntyped(L, -1, "pubsub_options"))) {
+ result->setOptions(payload);
+ }
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubSubscribeConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubSubscribe> payload) {
+ lua_createtable(L, 0, 0);
+ if (payload->getNode()) {
+ lua_pushstring(L, (*payload->getNode()).c_str());
+ lua_setfield(L, -2, "node");
+ }
+ lua_pushstring(L, payload->getJID().toString().c_str());
+ lua_setfield(L, -2, "jid");
+ if (convertors->convertToLuaUntyped(L, payload->getOptions()) > 0) {
+ lua_setfield(L, -2, "options");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubSubscribeConvertor.h b/Sluift/ElementConvertors/PubSubSubscribeConvertor.h
new file mode 100644
index 0000000..2073c09
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubSubscribeConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubSubscribe.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubSubscribeConvertor : public GenericLuaElementConvertor<PubSubSubscribe> {
+ public:
+ PubSubSubscribeConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubSubscribeConvertor();
+
+ virtual boost::shared_ptr<PubSubSubscribe> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubSubscribe>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubSubscribeOptionsConvertor.cpp b/Sluift/ElementConvertors/PubSubSubscribeOptionsConvertor.cpp
new file mode 100644
index 0000000..e8053fb
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubSubscribeOptionsConvertor.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubSubscribeOptionsConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubSubscribeOptionsConvertor::PubSubSubscribeOptionsConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubSubscribeOptions>("pubsub_subscribe_options"),
+ convertors(convertors) {
+}
+
+PubSubSubscribeOptionsConvertor::~PubSubSubscribeOptionsConvertor() {
+}
+
+boost::shared_ptr<PubSubSubscribeOptions> PubSubSubscribeOptionsConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubSubscribeOptions> result = boost::make_shared<PubSubSubscribeOptions>();
+ lua_getfield(L, -1, "required");
+ if (lua_isboolean(L, -1)) {
+ result->setRequired(lua_toboolean(L, -1));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubSubscribeOptionsConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubSubscribeOptions> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushboolean(L, payload->isRequired());
+ lua_setfield(L, -2, "required");
+}
diff --git a/Sluift/ElementConvertors/PubSubSubscribeOptionsConvertor.h b/Sluift/ElementConvertors/PubSubSubscribeOptionsConvertor.h
new file mode 100644
index 0000000..71e1baf
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubSubscribeOptionsConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubSubscribeOptions.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubSubscribeOptionsConvertor : public GenericLuaElementConvertor<PubSubSubscribeOptions> {
+ public:
+ PubSubSubscribeOptionsConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubSubscribeOptionsConvertor();
+
+ virtual boost::shared_ptr<PubSubSubscribeOptions> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubSubscribeOptions>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubSubscriptionConvertor.cpp b/Sluift/ElementConvertors/PubSubSubscriptionConvertor.cpp
new file mode 100644
index 0000000..9ec9fec
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubSubscriptionConvertor.cpp
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubSubscriptionConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+#include <Sluift/LuaElementConvertors.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubSubscriptionConvertor::PubSubSubscriptionConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubSubscription>("pubsub_subscription"),
+ convertors(convertors) {
+}
+
+PubSubSubscriptionConvertor::~PubSubSubscriptionConvertor() {
+}
+
+boost::shared_ptr<PubSubSubscription> PubSubSubscriptionConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubSubscription> result = boost::make_shared<PubSubSubscription>();
+ 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, "subscriptionid");
+ if (lua_isstring(L, -1)) {
+ result->setSubscriptionID(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "jid");
+ if (lua_isstring(L, -1)) {
+ result->setJID(JID(std::string(lua_tostring(L, -1))));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "options");
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubSubscribeOptions> payload = boost::dynamic_pointer_cast<PubSubSubscribeOptions>(convertors->convertFromLuaUntyped(L, -1, "pubsub_subscribe_options"))) {
+ result->setOptions(payload);
+ }
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "subscription");
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubSubscriptionConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubSubscription> payload) {
+ lua_createtable(L, 0, 0);
+ if (payload->getNode()) {
+ lua_pushstring(L, (*payload->getNode()).c_str());
+ lua_setfield(L, -2, "node");
+ }
+ if (payload->getSubscriptionID()) {
+ lua_pushstring(L, (*payload->getSubscriptionID()).c_str());
+ lua_setfield(L, -2, "subscriptionid");
+ }
+ lua_pushstring(L, payload->getJID().toString().c_str());
+ lua_setfield(L, -2, "jid");
+ if (convertors->convertToLuaUntyped(L, payload->getOptions()) > 0) {
+ lua_setfield(L, -2, "options");
+ }
+ switch (payload->getSubscription()) {
+ case PubSubSubscription::None:
+ lua_pushstring(L, "none");
+ break;
+ case PubSubSubscription::Pending:
+ lua_pushstring(L, "pending");
+ break;
+ case PubSubSubscription::Subscribed:
+ lua_pushstring(L, "subscribed");
+ break;
+ case PubSubSubscription::Unconfigured:
+ lua_pushstring(L, "unconfigured");
+ break;
+ }
+ lua_setfield(L, -2, "subscription");
+}
diff --git a/Sluift/ElementConvertors/PubSubSubscriptionConvertor.h b/Sluift/ElementConvertors/PubSubSubscriptionConvertor.h
new file mode 100644
index 0000000..2da4930
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubSubscriptionConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubSubscription.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubSubscriptionConvertor : public GenericLuaElementConvertor<PubSubSubscription> {
+ public:
+ PubSubSubscriptionConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubSubscriptionConvertor();
+
+ virtual boost::shared_ptr<PubSubSubscription> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubSubscription>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubSubscriptionsConvertor.cpp b/Sluift/ElementConvertors/PubSubSubscriptionsConvertor.cpp
new file mode 100644
index 0000000..04f8da8
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubSubscriptionsConvertor.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubSubscriptionsConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include <Sluift/LuaElementConvertors.h>
+#include <Swiften/Base/foreach.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubSubscriptionsConvertor::PubSubSubscriptionsConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubSubscriptions>("pubsub_subscriptions"),
+ convertors(convertors) {
+}
+
+PubSubSubscriptionsConvertor::~PubSubSubscriptionsConvertor() {
+}
+
+boost::shared_ptr<PubSubSubscriptions> PubSubSubscriptionsConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubSubscriptions> result = boost::make_shared<PubSubSubscriptions>();
+ lua_getfield(L, -1, "node");
+ if (lua_isstring(L, -1)) {
+ result->setNode(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ if (lua_type(L, -1) == LUA_TTABLE) {
+ std::vector< boost::shared_ptr<PubSubSubscription> > items;
+ for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
+ lua_pushnumber(L, i + 1);
+ lua_gettable(L, -2);
+ if (!lua_isnil(L, -1)) {
+ if (boost::shared_ptr<PubSubSubscription> payload = boost::dynamic_pointer_cast<PubSubSubscription>(convertors->convertFromLuaUntyped(L, -1, "pubsub_subscription"))) {
+ items.push_back(payload);
+ }
+ }
+ lua_pop(L, 1);
+ }
+
+ result->setSubscriptions(items);
+ }
+ return result;
+}
+
+void PubSubSubscriptionsConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubSubscriptions> payload) {
+ lua_createtable(L, 0, 0);
+ if (payload->getNode()) {
+ lua_pushstring(L, (*payload->getNode()).c_str());
+ lua_setfield(L, -2, "node");
+ }
+ if (!payload->getSubscriptions().empty()) {
+ {
+ int i = 0;
+ foreach(boost::shared_ptr<PubSubSubscription> item, payload->getSubscriptions()) {
+ if (convertors->convertToLuaUntyped(L, item) > 0) {
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ ++i;
+ }
+ }
+ }
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubSubscriptionsConvertor.h b/Sluift/ElementConvertors/PubSubSubscriptionsConvertor.h
new file mode 100644
index 0000000..7f18f64
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubSubscriptionsConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubSubscriptions.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubSubscriptionsConvertor : public GenericLuaElementConvertor<PubSubSubscriptions> {
+ public:
+ PubSubSubscriptionsConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubSubscriptionsConvertor();
+
+ virtual boost::shared_ptr<PubSubSubscriptions> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubSubscriptions>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/PubSubUnsubscribeConvertor.cpp b/Sluift/ElementConvertors/PubSubUnsubscribeConvertor.cpp
new file mode 100644
index 0000000..323cb29
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubUnsubscribeConvertor.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/PubSubUnsubscribeConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+
+
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+PubSubUnsubscribeConvertor::PubSubUnsubscribeConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<PubSubUnsubscribe>("pubsub_unsubscribe"),
+ convertors(convertors) {
+}
+
+PubSubUnsubscribeConvertor::~PubSubUnsubscribeConvertor() {
+}
+
+boost::shared_ptr<PubSubUnsubscribe> PubSubUnsubscribeConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<PubSubUnsubscribe> result = boost::make_shared<PubSubUnsubscribe>();
+ 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, "jid");
+ if (lua_isstring(L, -1)) {
+ result->setJID(JID(std::string(lua_tostring(L, -1))));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "subscriptionid");
+ if (lua_isstring(L, -1)) {
+ result->setSubscriptionID(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void PubSubUnsubscribeConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<PubSubUnsubscribe> payload) {
+ lua_createtable(L, 0, 0);
+ if (payload->getNode()) {
+ lua_pushstring(L, (*payload->getNode()).c_str());
+ lua_setfield(L, -2, "node");
+ }
+ lua_pushstring(L, payload->getJID().toString().c_str());
+ lua_setfield(L, -2, "jid");
+ if (payload->getSubscriptionID()) {
+ lua_pushstring(L, (*payload->getSubscriptionID()).c_str());
+ lua_setfield(L, -2, "subscriptionid");
+ }
+}
diff --git a/Sluift/ElementConvertors/PubSubUnsubscribeConvertor.h b/Sluift/ElementConvertors/PubSubUnsubscribeConvertor.h
new file mode 100644
index 0000000..16d279f
--- /dev/null
+++ b/Sluift/ElementConvertors/PubSubUnsubscribeConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/PubSubUnsubscribe.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class PubSubUnsubscribeConvertor : public GenericLuaElementConvertor<PubSubUnsubscribe> {
+ public:
+ PubSubUnsubscribeConvertor(LuaElementConvertors* convertors);
+ virtual ~PubSubUnsubscribeConvertor();
+
+ virtual boost::shared_ptr<PubSubUnsubscribe> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<PubSubUnsubscribe>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/RawXMLElementConvertor.cpp b/Sluift/ElementConvertors/RawXMLElementConvertor.cpp
new file mode 100644
index 0000000..35a53ca
--- /dev/null
+++ b/Sluift/ElementConvertors/RawXMLElementConvertor.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/RawXMLElementConvertor.h>
+
+#include <iostream>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <lua.hpp>
+
+#include <Swiften/Elements/RawXMLPayload.h>
+#include <Swiften/Serializer/PayloadSerializer.h>
+#include <Sluift/Lua/Check.h>
+
+using namespace Swift;
+
+RawXMLElementConvertor::RawXMLElementConvertor() {
+}
+
+RawXMLElementConvertor::~RawXMLElementConvertor() {
+}
+
+boost::shared_ptr<Payload> RawXMLElementConvertor::convertFromLua(lua_State* L, int index, const std::string& type) {
+ if (type == "xml") {
+ return boost::make_shared<RawXMLPayload>(std::string(Lua::checkString(L, index)));
+ }
+ return boost::shared_ptr<Payload>();
+}
+
+boost::optional<std::string> RawXMLElementConvertor::convertToLua(lua_State* L, boost::shared_ptr<Payload> payload) {
+ PayloadSerializer* serializer = serializers.getPayloadSerializer(payload);
+ assert(serializer);
+ lua_pushstring(L, serializer->serialize(payload).c_str());
+ return std::string("xml");
+}
diff --git a/Sluift/ElementConvertors/RawXMLElementConvertor.h b/Sluift/ElementConvertors/RawXMLElementConvertor.h
new file mode 100644
index 0000000..6087ba0
--- /dev/null
+++ b/Sluift/ElementConvertors/RawXMLElementConvertor.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/LuaElementConvertor.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+
+namespace Swift {
+ class RawXMLElementConvertor : public LuaElementConvertor {
+ public:
+ RawXMLElementConvertor();
+ virtual ~RawXMLElementConvertor();
+
+ virtual boost::shared_ptr<Payload> convertFromLua(lua_State*, int index, const std::string& type) SWIFTEN_OVERRIDE;
+ virtual boost::optional<std::string> convertToLua(lua_State*, boost::shared_ptr<Payload>) SWIFTEN_OVERRIDE;
+
+ private:
+ FullPayloadSerializerCollection serializers;
+ };
+}
diff --git a/Sluift/ElementConvertors/SConscript b/Sluift/ElementConvertors/SConscript
new file mode 100644
index 0000000..e98f7c4
--- /dev/null
+++ b/Sluift/ElementConvertors/SConscript
@@ -0,0 +1,42 @@
+
+Import('env')
+
+convertors = [
+ env.File("PubSubRetractConvertor.cpp"),
+ env.File("PubSubAffiliationsConvertor.cpp"),
+ env.File("PubSubPublishConvertor.cpp"),
+ env.File("PubSubItemsConvertor.cpp"),
+ env.File("PubSubOwnerRedirectConvertor.cpp"),
+ env.File("PubSubEventRedirectConvertor.cpp"),
+ env.File("PubSubConfigureConvertor.cpp"),
+ env.File("PubSubEventDisassociateConvertor.cpp"),
+ env.File("PubSubOwnerAffiliationsConvertor.cpp"),
+ env.File("PubSubOwnerConfigureConvertor.cpp"),
+ env.File("UserLocationConvertor.cpp"),
+ env.File("PubSubSubscribeOptionsConvertor.cpp"),
+ env.File("PubSubOwnerSubscriptionsConvertor.cpp"),
+ env.File("PubSubDefaultConvertor.cpp"),
+ env.File("PubSubEventCollectionConvertor.cpp"),
+ 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("PubSubEventConfigurationConvertor.cpp")
+]
+Return('convertors')
diff --git a/Sluift/ElementConvertors/SoftwareVersionConvertor.cpp b/Sluift/ElementConvertors/SoftwareVersionConvertor.cpp
new file mode 100644
index 0000000..5799614
--- /dev/null
+++ b/Sluift/ElementConvertors/SoftwareVersionConvertor.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/SoftwareVersionConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+#include <Sluift/Lua/Check.h>
+
+using namespace Swift;
+
+SoftwareVersionConvertor::SoftwareVersionConvertor() : GenericLuaElementConvertor<SoftwareVersion>("software_version") {
+}
+
+SoftwareVersionConvertor::~SoftwareVersionConvertor() {
+}
+
+boost::shared_ptr<SoftwareVersion> SoftwareVersionConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<SoftwareVersion> result = boost::make_shared<SoftwareVersion>();
+ lua_getfield(L, -1, "name");
+ if (!lua_isnil(L, -1)) {
+ result->setName(std::string(Lua::checkString(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "version");
+ if (!lua_isnil(L, -1)) {
+ result->setVersion(std::string(Lua::checkString(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "os");
+ if (!lua_isnil(L, -1)) {
+ result->setOS(std::string(Lua::checkString(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void SoftwareVersionConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<SoftwareVersion> payload) {
+ lua_createtable(L, 0, 0);
+ lua_pushstring(L, payload->getName().c_str());
+ lua_setfield(L, -2, "name");
+ lua_pushstring(L, payload->getVersion().c_str());
+ lua_setfield(L, -2, "version");
+ lua_pushstring(L, payload->getOS().c_str());
+ lua_setfield(L, -2, "os");
+}
diff --git a/Sluift/ElementConvertors/SoftwareVersionConvertor.h b/Sluift/ElementConvertors/SoftwareVersionConvertor.h
new file mode 100644
index 0000000..5fa3cc3
--- /dev/null
+++ b/Sluift/ElementConvertors/SoftwareVersionConvertor.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/SoftwareVersion.h>
+
+namespace Swift {
+ class SoftwareVersionConvertor : public GenericLuaElementConvertor<SoftwareVersion> {
+ public:
+ SoftwareVersionConvertor();
+ virtual ~SoftwareVersionConvertor();
+
+ virtual boost::shared_ptr<SoftwareVersion> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<SoftwareVersion>) SWIFTEN_OVERRIDE;
+ };
+}
diff --git a/Sluift/ElementConvertors/UserLocationConvertor.cpp b/Sluift/ElementConvertors/UserLocationConvertor.cpp
new file mode 100644
index 0000000..97cb288
--- /dev/null
+++ b/Sluift/ElementConvertors/UserLocationConvertor.cpp
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/UserLocationConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include <Swiften/Base/DateTime.h>
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+using namespace Swift;
+
+UserLocationConvertor::UserLocationConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<UserLocation>("user_location"),
+ convertors(convertors) {
+}
+
+UserLocationConvertor::~UserLocationConvertor() {
+}
+
+boost::shared_ptr<UserLocation> UserLocationConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<UserLocation> result = boost::make_shared<UserLocation>();
+ lua_getfield(L, -1, "area");
+ if (lua_isstring(L, -1)) {
+ result->setArea(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "altitude");
+ if (lua_isnumber(L, -1)) {
+ result->setAltitude(boost::numeric_cast<float>(lua_tonumber(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "locality");
+ if (lua_isstring(L, -1)) {
+ result->setLocality(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "latitude");
+ if (lua_isnumber(L, -1)) {
+ result->setLatitude(boost::numeric_cast<float>(lua_tonumber(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "accuracy");
+ if (lua_isnumber(L, -1)) {
+ result->setAccuracy(boost::numeric_cast<float>(lua_tonumber(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "description");
+ if (lua_isstring(L, -1)) {
+ result->setDescription(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "country_code");
+ if (lua_isstring(L, -1)) {
+ result->setCountryCode(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "timestamp");
+ if (lua_isstring(L, -1)) {
+ result->setTimestamp(stringToDateTime(std::string(lua_tostring(L, -1))));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "floor");
+ if (lua_isstring(L, -1)) {
+ result->setFloor(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "building");
+ if (lua_isstring(L, -1)) {
+ result->setBuilding(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "room");
+ if (lua_isstring(L, -1)) {
+ result->setRoom(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "country");
+ if (lua_isstring(L, -1)) {
+ result->setCountry(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "region");
+ if (lua_isstring(L, -1)) {
+ result->setRegion(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "uri");
+ if (lua_isstring(L, -1)) {
+ result->setURI(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "longitude");
+ if (lua_isnumber(L, -1)) {
+ result->setLongitude(boost::numeric_cast<float>(lua_tonumber(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "error");
+ if (lua_isnumber(L, -1)) {
+ result->setError(boost::numeric_cast<float>(lua_tonumber(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "postal_code");
+ if (lua_isstring(L, -1)) {
+ result->setPostalCode(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "bearing");
+ if (lua_isnumber(L, -1)) {
+ result->setBearing(boost::numeric_cast<float>(lua_tonumber(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "text");
+ if (lua_isstring(L, -1)) {
+ result->setText(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "datum");
+ if (lua_isstring(L, -1)) {
+ result->setDatum(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "street");
+ if (lua_isstring(L, -1)) {
+ result->setStreet(std::string(lua_tostring(L, -1)));
+ }
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "speed");
+ if (lua_isnumber(L, -1)) {
+ result->setSpeed(boost::numeric_cast<float>(lua_tonumber(L, -1)));
+ }
+ lua_pop(L, 1);
+ return result;
+}
+
+void UserLocationConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<UserLocation> payload) {
+ lua_createtable(L, 0, 0);
+ if (payload->getArea()) {
+ lua_pushstring(L, (*payload->getArea()).c_str());
+ lua_setfield(L, -2, "area");
+ }
+ if (payload->getAltitude()) {
+ lua_pushnumber(L, (*payload->getAltitude()));
+ lua_setfield(L, -2, "altitude");
+ }
+ if (payload->getLocality()) {
+ lua_pushstring(L, (*payload->getLocality()).c_str());
+ lua_setfield(L, -2, "locality");
+ }
+ if (payload->getLatitude()) {
+ lua_pushnumber(L, (*payload->getLatitude()));
+ lua_setfield(L, -2, "latitude");
+ }
+ if (payload->getAccuracy()) {
+ lua_pushnumber(L, (*payload->getAccuracy()));
+ lua_setfield(L, -2, "accuracy");
+ }
+ if (payload->getDescription()) {
+ lua_pushstring(L, (*payload->getDescription()).c_str());
+ lua_setfield(L, -2, "description");
+ }
+ if (payload->getCountryCode()) {
+ lua_pushstring(L, (*payload->getCountryCode()).c_str());
+ lua_setfield(L, -2, "country_code");
+ }
+ if (payload->getTimestamp()) {
+ lua_pushstring(L, dateTimeToString((*payload->getTimestamp())).c_str());
+ lua_setfield(L, -2, "timestamp");
+ }
+ if (payload->getFloor()) {
+ lua_pushstring(L, (*payload->getFloor()).c_str());
+ lua_setfield(L, -2, "floor");
+ }
+ if (payload->getBuilding()) {
+ lua_pushstring(L, (*payload->getBuilding()).c_str());
+ lua_setfield(L, -2, "building");
+ }
+ if (payload->getRoom()) {
+ lua_pushstring(L, (*payload->getRoom()).c_str());
+ lua_setfield(L, -2, "room");
+ }
+ if (payload->getCountry()) {
+ lua_pushstring(L, (*payload->getCountry()).c_str());
+ lua_setfield(L, -2, "country");
+ }
+ if (payload->getRegion()) {
+ lua_pushstring(L, (*payload->getRegion()).c_str());
+ lua_setfield(L, -2, "region");
+ }
+ if (payload->getURI()) {
+ lua_pushstring(L, (*payload->getURI()).c_str());
+ lua_setfield(L, -2, "uri");
+ }
+ if (payload->getLongitude()) {
+ lua_pushnumber(L, (*payload->getLongitude()));
+ lua_setfield(L, -2, "longitude");
+ }
+ if (payload->getError()) {
+ lua_pushnumber(L, (*payload->getError()));
+ lua_setfield(L, -2, "error");
+ }
+ if (payload->getPostalCode()) {
+ lua_pushstring(L, (*payload->getPostalCode()).c_str());
+ lua_setfield(L, -2, "postal_code");
+ }
+ if (payload->getBearing()) {
+ lua_pushnumber(L, (*payload->getBearing()));
+ lua_setfield(L, -2, "bearing");
+ }
+ if (payload->getText()) {
+ lua_pushstring(L, (*payload->getText()).c_str());
+ lua_setfield(L, -2, "text");
+ }
+ if (payload->getDatum()) {
+ lua_pushstring(L, (*payload->getDatum()).c_str());
+ lua_setfield(L, -2, "datum");
+ }
+ if (payload->getStreet()) {
+ lua_pushstring(L, (*payload->getStreet()).c_str());
+ lua_setfield(L, -2, "street");
+ }
+ if (payload->getSpeed()) {
+ lua_pushnumber(L, (*payload->getSpeed()));
+ lua_setfield(L, -2, "speed");
+ }
+}
diff --git a/Sluift/ElementConvertors/UserLocationConvertor.h b/Sluift/ElementConvertors/UserLocationConvertor.h
new file mode 100644
index 0000000..a5eb153
--- /dev/null
+++ b/Sluift/ElementConvertors/UserLocationConvertor.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/UserLocation.h>
+
+namespace Swift {
+ class LuaElementConvertors;
+
+ class UserLocationConvertor : public GenericLuaElementConvertor<UserLocation> {
+ public:
+ UserLocationConvertor(LuaElementConvertors* convertors);
+ virtual ~UserLocationConvertor();
+
+ virtual boost::shared_ptr<UserLocation> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<UserLocation>) SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
+ };
+}
diff --git a/Sluift/ElementConvertors/VCardConvertor.cpp b/Sluift/ElementConvertors/VCardConvertor.cpp
new file mode 100644
index 0000000..a1c57be
--- /dev/null
+++ b/Sluift/ElementConvertors/VCardConvertor.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/VCardConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+#include <Sluift/Lua/LuaUtils.h>
+#include <Swiften/Base/ByteArray.h>
+
+using namespace Swift;
+
+VCardConvertor::VCardConvertor() : GenericLuaElementConvertor<VCard>("vcard") {
+}
+
+VCardConvertor::~VCardConvertor() {
+}
+
+boost::shared_ptr<VCard> VCardConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<VCard> result = boost::make_shared<VCard>();
+ lua_getfield(L, -1, "photo");
+ if (lua_isstring(L, -1)) {
+ size_t len;
+ const char* data = lua_tolstring(L, -1, &len);
+ result->setPhoto(createByteArray(data, len));
+ }
+ lua_pop(L, 1);
+
+ // TODO
+
+ return result;
+}
+
+void VCardConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<VCard> payload) {
+ lua_newtable(L);
+ if (!payload->getPhoto().empty()) {
+ lua_pushlstring(L,
+ reinterpret_cast<const char*>(vecptr(payload->getPhoto())),
+ payload->getPhoto().size());
+ lua_setfield(L, -2, "photo");
+ }
+}
diff --git a/Sluift/ElementConvertors/VCardConvertor.h b/Sluift/ElementConvertors/VCardConvertor.h
new file mode 100644
index 0000000..1cf4e9f
--- /dev/null
+++ b/Sluift/ElementConvertors/VCardConvertor.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/VCard.h>
+
+namespace Swift {
+ class VCardConvertor : public GenericLuaElementConvertor<VCard> {
+ public:
+ VCardConvertor();
+ virtual ~VCardConvertor();
+
+ virtual boost::shared_ptr<VCard> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<VCard>) SWIFTEN_OVERRIDE;
+ };
+}
diff --git a/Sluift/ElementConvertors/VCardUpdateConvertor.cpp b/Sluift/ElementConvertors/VCardUpdateConvertor.cpp
new file mode 100644
index 0000000..0010ca5
--- /dev/null
+++ b/Sluift/ElementConvertors/VCardUpdateConvertor.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/VCardUpdateConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+#include <Sluift/Lua/LuaUtils.h>
+
+using namespace Swift;
+
+VCardUpdateConvertor::VCardUpdateConvertor() : GenericLuaElementConvertor<VCardUpdate>("vcard_update") {
+}
+
+VCardUpdateConvertor::~VCardUpdateConvertor() {
+}
+
+boost::shared_ptr<VCardUpdate> VCardUpdateConvertor::doConvertFromLua(lua_State* L) {
+ boost::shared_ptr<VCardUpdate> result = boost::make_shared<VCardUpdate>();
+ if (boost::optional<std::string> value = Lua::getStringField(L, -1, "photo_hash")) {
+ result->setPhotoHash(*value);
+ }
+ return result;
+}
+
+void VCardUpdateConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<VCardUpdate> payload) {
+ lua_newtable(L);
+ if (!payload->getPhotoHash().empty()) {
+ lua_pushstring(L, payload->getPhotoHash().c_str());
+ lua_setfield(L, -2, "photo_hash");
+ }
+}
diff --git a/Sluift/ElementConvertors/VCardUpdateConvertor.h b/Sluift/ElementConvertors/VCardUpdateConvertor.h
new file mode 100644
index 0000000..e9bcd0f
--- /dev/null
+++ b/Sluift/ElementConvertors/VCardUpdateConvertor.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/VCardUpdate.h>
+
+namespace Swift {
+ class VCardUpdateConvertor : public GenericLuaElementConvertor<VCardUpdate> {
+ public:
+ VCardUpdateConvertor();
+ virtual ~VCardUpdateConvertor();
+
+ virtual boost::shared_ptr<VCardUpdate> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+ virtual void doConvertToLua(lua_State*, boost::shared_ptr<VCardUpdate>) SWIFTEN_OVERRIDE;
+ };
+}