comparison mod_adhoc/adhoc/mod_adhoc.lua @ 254:9b4a114b2fe6

mod_adhoc: Answer disco#info for node=xmlns_cmd
author Florian Zeitz <florob@babelmonkeys.de>
date Fri, 01 Oct 2010 16:15:36 +0200
parents 5a389f9f2ec7
children
comparison
equal deleted inserted replaced
252:8eae74a31acb 254:9b4a114b2fe6
15 module:add_feature(xmlns_cmd); 15 module:add_feature(xmlns_cmd);
16 16
17 module:hook("iq/host/"..xmlns_disco.."#info:query", function (event) 17 module:hook("iq/host/"..xmlns_disco.."#info:query", function (event)
18 local origin, stanza = event.origin, event.stanza; 18 local origin, stanza = event.origin, event.stanza;
19 local node = stanza.tags[1].attr.node; 19 local node = stanza.tags[1].attr.node;
20 if stanza.attr.type == "get" and node 20 if stanza.attr.type == "get" and node then
21 and commands[node] then 21 if commands[node] then
22 -- Required for Prosody <= 0.7 22 -- Required for Prosody <= 0.7
23 local privileged = is_admin(stanza.attr.from) 23 local privileged = is_admin(stanza.attr.from)
24 or is_admin(stanza.attr.from, stanza.attr.to); 24 or is_admin(stanza.attr.from, stanza.attr.to);
25 if (commands[node].permission == "admin" and privileged) 25 if (commands[node].permission == "admin" and privileged)
26 or (commands[node].permission == "user") then 26 or (commands[node].permission == "user") then
27 reply = st.reply(stanza);
28 reply:tag("query", { xmlns = xmlns_disco.."#info",
29 node = node });
30 reply:tag("identity", { name = commands[node].name,
31 category = "automation", type = "command-node" }):up();
32 reply:tag("feature", { var = xmlns_cmd }):up();
33 reply:tag("feature", { var = "jabber:x:data" }):up();
34 else
35 reply = st.error_reply(stanza, "auth", "forbidden", "This item is not available to you");
36 end
37 origin.send(reply);
38 return true;
39 elseif node == xmlns_cmd then
27 reply = st.reply(stanza); 40 reply = st.reply(stanza);
28 reply:tag("query", { xmlns = xmlns_disco.."#info", 41 reply:tag("query", { xmlns = xmlns_disco.."#info",
29 node = node }); 42 node = node });
30 reply:tag("identity", { name = commands[node].name, 43 reply:tag("identity", { name = "Ad-Hoc Commands",
31 category = "automation", type = "command-node" }):up(); 44 category = "automation", type = "command-list" }):up();
32 reply:tag("feature", { var = xmlns_cmd }):up(); 45 origin.send(reply);
33 reply:tag("feature", { var = "jabber:x:data" }):up(); 46 return true;
34 else
35 reply = st.error_reply(stanza, "auth", "forbidden", "This item is not available to you");
36 end 47 end
37 origin.send(reply);
38 return true;
39 end 48 end
40 end); 49 end);
41 50
42 module:hook("iq/host/"..xmlns_disco.."#items:query", function (event) 51 module:hook("iq/host/"..xmlns_disco.."#items:query", function (event)
43 local origin, stanza = event.origin, event.stanza; 52 local origin, stanza = event.origin, event.stanza;