Comparison

plugins/adhoc/mod_adhoc.lua @ 3511:4495403470cb

mod_adhoc: Answer disco#info for node=xmlns_cmd
author Florian Zeitz <florob@babelmonkeys.de>
date Fri, 01 Oct 2010 16:44:49 +0200
parent 3485:3eee60c6a436
child 4291:122f142da281
comparison
equal deleted inserted replaced
3510:711eb5bf94b4 3511:4495403470cb
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 local privileged = is_admin(stanza.attr.from, stanza.attr.to); 22 local privileged = is_admin(stanza.attr.from, stanza.attr.to);
23 if (commands[node].permission == "admin" and privileged) 23 if (commands[node].permission == "admin" and privileged)
24 or (commands[node].permission == "user") then 24 or (commands[node].permission == "user") then
25 reply = st.reply(stanza);
26 reply:tag("query", { xmlns = xmlns_disco.."#info",
27 node = node });
28 reply:tag("identity", { name = commands[node].name,
29 category = "automation", type = "command-node" }):up();
30 reply:tag("feature", { var = xmlns_cmd }):up();
31 reply:tag("feature", { var = "jabber:x:data" }):up();
32 else
33 reply = st.error_reply(stanza, "auth", "forbidden", "This item is not available to you");
34 end
35 origin.send(reply);
36 return true;
37 elseif node == xmlns_cmd then
25 reply = st.reply(stanza); 38 reply = st.reply(stanza);
26 reply:tag("query", { xmlns = xmlns_disco.."#info", 39 reply:tag("query", { xmlns = xmlns_disco.."#info",
27 node = node }); 40 node = node });
28 reply:tag("identity", { name = commands[node].name, 41 reply:tag("identity", { name = "Ad-Hoc Commands",
29 category = "automation", type = "command-node" }):up(); 42 category = "automation", type = "command-list" }):up();
30 reply:tag("feature", { var = xmlns_cmd }):up(); 43 origin.send(reply);
31 reply:tag("feature", { var = "jabber:x:data" }):up(); 44 return true;
32 else 45
33 reply = st.error_reply(stanza, "auth", "forbidden", "This item is not available to you");
34 end 46 end
35 origin.send(reply);
36 return true;
37 end 47 end
38 end); 48 end);
39 49
40 module:hook("iq/host/"..xmlns_disco.."#items:query", function (event) 50 module:hook("iq/host/"..xmlns_disco.."#items:query", function (event)
41 local origin, stanza = event.origin, event.stanza; 51 local origin, stanza = event.origin, event.stanza;