Comparison

mod_private_adhoc/mod_private_adhoc.lua @ 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
comparison
equal deleted inserted replaced
1460:5e1f7af23cf0 1461:deb79c2357bb
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 --
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9 -- Module by Thomas Raschbacher 2014
10 -- lordvan@lordvan.com
11
12 module:depends"adhoc";
13 local dataforms_new = require "util.dataforms".new;
14 local st = require "util.stanza";
15 local jid_split = require "util.jid".split;
16
17 local private_storage = module:open_store("private");
18
19 local private_adhoc_result_layout = dataforms_new{
20 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
21 { name = "privatexmldata", type = "text-multi", label = "Private XML data" };
22 };
23
24
25 function private_adhoc_command_handler (self, data, state)
26 local username, hostname = jid_split(data.from);
27 local data, err = private_storage:get(username);
28 local dataString = "";
29 if not data then
30 dataString = "No data found.";
31 if err then dataString = dataString..err end;
32 else
33 for key,value in pairs(data) do
34 dataString = dataString..tostring(st.deserialize(value)):gsub("><",">\n<")
35 dataString = dataString.."\n\n";
36 end
37 end
38 return { status = "completed", result= { layout = private_adhoc_result_layout, values = {privatexmldata=dataString.."\n"}} };
39 end
40
41 local adhoc_new = module:require "adhoc".new;
42 local descriptor = adhoc_new("Query private data", "private_adhoc", private_adhoc_command_handler, "local_user");
43 module:add_item ("adhoc", descriptor);
44