Comparison

mod_extdisco/mod_extdisco.lua @ 281:e5c16c87383c

mod_extdisco: XEP-0215: External Service Discovery
author Matthew Wild <mwild1@gmail.com>
date Mon, 29 Nov 2010 17:58:42 +0000
child 3602:e302537a0e4e
comparison
equal deleted inserted replaced
280:6d72c5172c74 281:e5c16c87383c
1 local st = require "util.stanza";
2
3 local services = module:get_option("external_services");
4
5 local xmlns_extdisco = "urn:xmpp:extdisco:1";
6
7 module:add_feature(xmlns_extdisco);
8
9 module:hook("iq-get/host/"..xmlns_extdisco..":services", function (event)
10 local origin, stanza = event.origin, event.stanza;
11 local service = stanza:get_child("service", xmlns_extdisco);
12 local service_type = service and service.attr.type;
13 local reply = st.reply(stanza);
14 for host, service_info in pairs(services) do
15 if not(service_type) or service_info.type == service_type then
16 reply:tag("service", {
17 host = host;
18 port = service_info.port;
19 transport = service_info.transport;
20 type = service_info.type;
21 username = service_info.username;
22 password = service_info.password;
23 }):up();
24 end
25 end
26 origin.send(reply);
27 return true;
28 end);
29
30 module:hook("iq-get/host/"..xmlns_extdisco..":credentials", function (event)
31 local origin, stanza = event.origin, event.stanza;
32 local credentials = stanza:get_child("credentials", xmlns_extdisco);
33 local host = credentials and credentials.attr.host;
34 if not host then
35 origin.send(st.error_reply(stanza, "cancel", "bad-request", "No host specified"));
36 return true;
37 end
38 local service_info = services[host];
39 if not service_info then
40 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "No such service known"));
41 return true;
42 end
43 local reply = st.reply(stanza)
44 :tag("credentials")
45 :tag("service", {
46 host = host;
47 username = service_info.username;
48 password = service_info.password;
49 }):up();
50 origin.send(reply);
51 return true;
52 end);