annotate mod_adhoc/mod_adhoc.lua @ 33:f3225c55288f

mod_adhoc_cmd_admin: More utils.dataforms sugar
author Florian Zeitz <florob@babelmonkeys.de>
date Sat, 10 Oct 2009 04:01:45 +0200
parents b9d063dd16d5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
1 -- Copyright (C) 2009 Thilo Cestonaro
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
2 --
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
3 -- This file is MIT/X11 licensed. Please see the
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
4 -- COPYING file in the source package for more information.
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
5 --
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
7 local st = require "util.stanza";
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
8 local commands = {};
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
9
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
10 module:add_feature("http://jabber.org/protocol/commands");
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
11
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
12 module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function (event)
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
13 local origin, stanza = event.origin, event.stanza;
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
14 if stanza.attr.type == "get" and stanza.tags[1].attr.node and stanza.tags[1].attr.node == "http://jabber.org/protocol/commands" then
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
15 reply = st.reply(stanza);
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
16 reply:tag("query", {xmlns="http://jabber.org/protocol/disco#items", node="http://jabber.org/protocol/commands"})
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
17 for i = 1, #commands do
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
18 -- module:log("info", "adding command %s", commands[i].name);
28
b9d063dd16d5 mod_adhoc, mod_adhoc_cmd_ping: Code cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents: 9
diff changeset
19 reply:tag("item", {name=commands[i].name, node=commands[i].node, jid=module:get_host()});
6
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
20 reply:up();
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
21 end
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
22 origin.send(reply);
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
23 return true;
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
24 end
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
25 end, 500);
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
26
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
27 module:hook("iq/host", function (event)
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
28 local origin, stanza = event.origin, event.stanza;
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
29 if stanza.attr.type == "set" and stanza.tags[1] and stanza.tags[1].name == "command" then
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
30 local node = stanza.tags[1].attr.node
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
31 for i = 1, #commands do
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
32 if commands[i].node == node then
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
33 return commands[i].handler(commands[i], origin, stanza);
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
34 end
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
35 end
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
36 end
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
37 end, 500);
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
38
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
39 module:hook("item-added/adhoc", function (event)
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
40 commands[ # commands + 1] = event.item;
d497d5df360d adds mod_adhoc
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
41 end, 500);
9
2be8bcce5b18 thx to Florob:
ephraim@errorm.fritz.box
parents: 6
diff changeset
42
2be8bcce5b18 thx to Florob:
ephraim@errorm.fritz.box
parents: 6
diff changeset
43 local _G = _G;
2be8bcce5b18 thx to Florob:
ephraim@errorm.fritz.box
parents: 6
diff changeset
44 local t_remove = _G.table.remove;
2be8bcce5b18 thx to Florob:
ephraim@errorm.fritz.box
parents: 6
diff changeset
45 module:hook("item-removed/adhoc", function (event)
2be8bcce5b18 thx to Florob:
ephraim@errorm.fritz.box
parents: 6
diff changeset
46 for i = 1, #commands do
2be8bcce5b18 thx to Florob:
ephraim@errorm.fritz.box
parents: 6
diff changeset
47 if commands[i].node == event.item.node then
2be8bcce5b18 thx to Florob:
ephraim@errorm.fritz.box
parents: 6
diff changeset
48 t_remove(commands, i);
28
b9d063dd16d5 mod_adhoc, mod_adhoc_cmd_ping: Code cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents: 9
diff changeset
49 break;
9
2be8bcce5b18 thx to Florob:
ephraim@errorm.fritz.box
parents: 6
diff changeset
50 end
2be8bcce5b18 thx to Florob:
ephraim@errorm.fritz.box
parents: 6
diff changeset
51 end
2be8bcce5b18 thx to Florob:
ephraim@errorm.fritz.box
parents: 6
diff changeset
52 end, 500);