comparison mod_adhoc/adhoc/mod_adhoc.lua @ 121:a9898f13c89e

mod_adhoc: Major refactoring. Actuall data exchange happens here now mod_adhoc_cmd_*: Update to work with aforementioned change
author Florian Zeitz <florob@babelmonkeys.de>
date Fri, 22 Jan 2010 04:25:58 +0100
parents 9b63fd1196c0
children 8111c8a9e1ad
comparison
equal deleted inserted replaced
120:7a2d33e8ad1f 121:a9898f13c89e
4 -- COPYING file in the source package for more information. 4 -- COPYING file in the source package for more information.
5 -- 5 --
6 6
7 local st = require "util.stanza"; 7 local st = require "util.stanza";
8 local is_admin = require "core.usermanager".is_admin; 8 local is_admin = require "core.usermanager".is_admin;
9 local adhoc_handle_cmd = module:require "adhoc".handle_cmd;
9 local commands = {}; 10 local commands = {};
10 11
11 module:add_feature("http://jabber.org/protocol/commands"); 12 module:add_feature("http://jabber.org/protocol/commands");
12 13
13 module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function (event) 14 module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function (event)
14 local origin, stanza = event.origin, event.stanza; 15 local origin, stanza = event.origin, event.stanza;
15 local privileged = is_admin(event.stanza.attr.from) or is_admin(stanza.attr.from, stanza.attr.to); -- TODO: Is this correct, or should is_admin be changed? 16 local privileged = is_admin(event.stanza.attr.from) or is_admin(stanza.attr.from, stanza.attr.to); -- TODO: Is this correct, or should is_admin be changed?
16 if stanza.attr.type == "get" and stanza.tags[1].attr.node and stanza.tags[1].attr.node == "http://jabber.org/protocol/commands" then 17 if stanza.attr.type == "get" and stanza.tags[1].attr.node and stanza.tags[1].attr.node == "http://jabber.org/protocol/commands" then
17 reply = st.reply(stanza); 18 reply = st.reply(stanza);
18 reply:tag("query", {xmlns="http://jabber.org/protocol/disco#items", node="http://jabber.org/protocol/commands"}) 19 reply:tag("query", {xmlns="http://jabber.org/protocol/disco#items", node="http://jabber.org/protocol/commands"});
19 for i = 1, #commands do 20 for i = 1, #commands do
20 -- module:log("info", "adding command %s", commands[i].name); 21 -- module:log("info", "adding command %s", commands[i].name);
21 if (commands[i].permission == "admin" and privileged) or (commands[i].permission == "user") then 22 if (commands[i].permission == "admin" and privileged) or (commands[i].permission == "user") then
22 reply:tag("item", {name=commands[i].name, node=commands[i].node, jid=module:get_host()}); 23 reply:tag("item", {name=commands[i].name, node=commands[i].node, jid=module:get_host()});
23 reply:up(); 24 reply:up();
41 :add_child(commands[i]:cmdtag("canceled") 42 :add_child(commands[i]:cmdtag("canceled")
42 :tag("note", {type="error"}):text("You don't have permission to execute this command"))); 43 :tag("note", {type="error"}):text("You don't have permission to execute this command")));
43 return true 44 return true
44 end 45 end
45 -- User has permission now execute the command 46 -- User has permission now execute the command
46 return commands[i].handler(commands[i], origin, stanza); 47 return adhoc_handle_cmd(commands[i], origin, stanza);
47 end 48 end
48 end 49 end
49 end 50 end
50 end, 500); 51 end, 500);
51 52