summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Sluift/ElementConvertors/VCardConvertor.cpp')
-rw-r--r--Sluift/ElementConvertors/VCardConvertor.cpp46
1 files changed, 46 insertions, 0 deletions
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");
+ }
+}