diff options
| author | Tobias Markmann <tm@ayena.de> | 2014-11-04 17:37:29 (GMT) | 
|---|---|---|
| committer | Tobias Markmann <tm@ayena.de> | 2014-11-04 17:42:55 (GMT) | 
| commit | a13511f0fc7998ab1350b3549f42c3e2eef04be3 (patch) | |
| tree | 9e0f1f16d295c86f01df24aff73bcc87938607a3 | |
| parent | a48fd35709f0ae6e9d6a58ad0c7f0ff4bc7e9f8d (diff) | |
| download | swift-a13511f0fc7998ab1350b3549f42c3e2eef04be3.zip swift-a13511f0fc7998ab1350b3549f42c3e2eef04be3.tar.bz2 | |
Add Sluift element convertor for MAM fin element.
Test-Information:
Yet to be done.
Change-Id: I624a64ae8817695fb1be00f0473ede3915751a21
| -rw-r--r-- | Sluift/ElementConvertors/MAMFinConvertor.cpp | 79 | ||||
| -rw-r--r-- | Sluift/ElementConvertors/MAMFinConvertor.h | 29 | ||||
| -rw-r--r-- | Sluift/ElementConvertors/SConscript | 1 | ||||
| -rw-r--r-- | Sluift/LuaElementConvertors.cpp | 2 | 
4 files changed, 111 insertions, 0 deletions
| diff --git a/Sluift/ElementConvertors/MAMFinConvertor.cpp b/Sluift/ElementConvertors/MAMFinConvertor.cpp new file mode 100644 index 0000000..0df1023 --- /dev/null +++ b/Sluift/ElementConvertors/MAMFinConvertor.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <boost/numeric/conversion/cast.hpp> +#include <boost/smart_ptr/make_shared.hpp> +#include <lua.hpp> +#include <Sluift/ElementConvertors/MAMFinConvertor.h> +#include <Sluift/LuaElementConvertors.h> +#include <Swiften/Elements/Form.h> +#include <Swiften/Elements/ResultSet.h> + +#pragma clang diagnostic ignored "-Wunused-private-field" + +using namespace Swift; + +MAMFinConvertor::MAMFinConvertor(LuaElementConvertors* convertors) :  +		GenericLuaElementConvertor<MAMFin>("mam_fin"), +		convertors(convertors) { +} + +MAMFinConvertor::~MAMFinConvertor() { +} + +boost::shared_ptr<MAMFin> MAMFinConvertor::doConvertFromLua(lua_State* L) { +	boost::shared_ptr<MAMFin> result = boost::make_shared<MAMFin>(); +	lua_getfield(L, -1, "query_id"); +	if (lua_isstring(L, -1)) { +		result->setQueryID(std::string(lua_tostring(L, -1))); +	} +	lua_pop(L, 1); +	lua_getfield(L, -1, "complete"); +	if (lua_isboolean(L, -1)) { +		result->setComplete(lua_toboolean(L, -1) != 0); +	} +	lua_pop(L, 1); +	lua_getfield(L, -1, "stable"); +	if (!lua_isnil(L, -1)) { +		result->setStable(lua_toboolean(L, -1) != 0); +	} +	lua_pop(L, 1); +	lua_getfield(L, -1, "result_set"); +	if (!lua_isnil(L, -1)) { +		boost::shared_ptr<ResultSet> resultSet = boost::dynamic_pointer_cast<ResultSet>(convertors->convertFromLuaUntyped(L, -1, "result_set")); +		if (!!resultSet) { +			result->setResultSet(resultSet); +		} +	} +	lua_pop(L, 1); +	return result; +} + +void MAMFinConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<MAMFin> payload) { +	lua_createtable(L, 0, 0); +	if (payload->getQueryID()) { +		lua_pushstring(L, (*payload->getQueryID()).c_str()); +		lua_setfield(L, -2, "query_id"); +	} +	lua_pushboolean(L, payload->isComplete()); +	lua_setfield(L, -2, "complete"); +	lua_pushboolean(L, payload->isStable()); +	lua_setfield(L, -2, "stable"); +	if (convertors->convertToLuaUntyped(L, payload->getResultSet()) > 0) { +		lua_setfield(L, -2, "result_set"); +	} +} + +boost::optional<LuaElementConvertor::Documentation> MAMFinConvertor::getDocumentation() const { +	return Documentation( +		"MAMFin", +		"This table has the following fields:\n\n" +		"- `query_id`: string (Optional)\n" +		"- `complete`: string (Optional)\n" +		"- `stable`: string @{Form} (Optional)\n" +		"- `result_set`: @{ResultSet} (Optional)\n" +	); +} diff --git a/Sluift/ElementConvertors/MAMFinConvertor.h b/Sluift/ElementConvertors/MAMFinConvertor.h new file mode 100644 index 0000000..2aabd05 --- /dev/null +++ b/Sluift/ElementConvertors/MAMFinConvertor.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Sluift/GenericLuaElementConvertor.h> +#include <Swiften/Base/Override.h> +#include <Swiften/Elements/MAMFin.h> + +namespace Swift { +	class LuaElementConvertors; + +	class MAMFinConvertor : public GenericLuaElementConvertor<MAMFin> { +		public: +			MAMFinConvertor(LuaElementConvertors* convertors); +			virtual ~MAMFinConvertor(); + +			virtual boost::shared_ptr<MAMFin> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE; +			virtual void doConvertToLua(lua_State*, boost::shared_ptr<MAMFin>) SWIFTEN_OVERRIDE; +			virtual boost::optional<Documentation> getDocumentation() const SWIFTEN_OVERRIDE; + +		private: +			LuaElementConvertors* convertors; +	}; +} + diff --git a/Sluift/ElementConvertors/SConscript b/Sluift/ElementConvertors/SConscript index 33d40ab..265017b 100644 --- a/Sluift/ElementConvertors/SConscript +++ b/Sluift/ElementConvertors/SConscript @@ -47,6 +47,7 @@ convertors = [  	env.File("ForwardedConvertor.cpp"),  	env.File("MAMResultConvertor.cpp"),  	env.File("MAMQueryConvertor.cpp"), +	env.File("MAMFinConvertor.cpp"),  	env.File("SubjectConvertor.cpp"),  	env.File("IsodeIQDelegationConvertor.cpp")  ] diff --git a/Sluift/LuaElementConvertors.cpp b/Sluift/LuaElementConvertors.cpp index d2af664..d6f603b 100644 --- a/Sluift/LuaElementConvertors.cpp +++ b/Sluift/LuaElementConvertors.cpp @@ -33,6 +33,7 @@  #include <Sluift/ElementConvertors/ForwardedConvertor.h>  #include <Sluift/ElementConvertors/MAMResultConvertor.h>  #include <Sluift/ElementConvertors/MAMQueryConvertor.h> +#include <Sluift/ElementConvertors/MAMFinConvertor.h>  #include <Sluift/Lua/LuaUtils.h>  #include <Sluift/Lua/Exception.h> @@ -60,6 +61,7 @@ LuaElementConvertors::LuaElementConvertors() {  	convertors.push_back(boost::make_shared<ForwardedConvertor>(this));  	convertors.push_back(boost::make_shared<MAMResultConvertor>(this));  	convertors.push_back(boost::make_shared<MAMQueryConvertor>(this)); +	convertors.push_back(boost::make_shared<MAMFinConvertor>(this));  	convertors.push_back(boost::make_shared<DOMElementConvertor>());  	convertors.push_back(boost::make_shared<RawXMLElementConvertor>());  	convertors.push_back(boost::make_shared<DefaultElementConvertor>()); | 
 Swift
 Swift