changeset 1461:deb79c2357bb

mod_private_adhoc: initial commit of new module
author Thomas Raschbacher <lordvan@lordvan.com>
date Sat, 28 Jun 2014 00:36:40 +0200
parents 5e1f7af23cf0
children a2a38b0a6376
files mod_private_adhoc/mod_private_adhoc.lua
diffstat 1 files changed, 44 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_private_adhoc/mod_private_adhoc.lua	Sat Jun 28 00:36:40 2014 +0200
@@ -0,0 +1,44 @@
+-- Prosody IM
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
+--
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+
+-- Module by Thomas Raschbacher 2014
+-- lordvan@lordvan.com
+
+module:depends"adhoc";
+local dataforms_new = require "util.dataforms".new;
+local st = require "util.stanza";
+local jid_split = require "util.jid".split;
+
+local private_storage = module:open_store("private");
+
+local private_adhoc_result_layout = dataforms_new{
+   { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
+   { name = "privatexmldata", type = "text-multi", label = "Private XML data" };
+};
+
+
+function private_adhoc_command_handler (self, data, state)
+   local username, hostname = jid_split(data.from);
+   local data, err = private_storage:get(username);
+   local dataString = "";
+   if not data then
+      dataString = "No data found.";
+      if err then dataString = dataString..err end;
+   else
+      for key,value in pairs(data) do
+	 dataString = dataString..tostring(st.deserialize(value)):gsub("><",">\n<")
+	 dataString = dataString.."\n\n";
+      end
+   end
+   return { status = "completed", result= { layout = private_adhoc_result_layout, values = {privatexmldata=dataString.."\n"}} };
+end
+
+local adhoc_new = module:require "adhoc".new;
+local descriptor = adhoc_new("Query private data", "private_adhoc", private_adhoc_command_handler, "local_user");
+module:add_item ("adhoc", descriptor);
+