annotate mod_extdisco/mod_extdisco.lua @ 1976:cd36e5bf00b3

Various READMEs: Update to reflect rename of mod_storage_sql2 → mod_storage_sql
author Kim Alvefur <zash@zash.se>
date Thu, 17 Dec 2015 16:48:11 +0100
parents e5c16c87383c
children e302537a0e4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
281
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local st = require "util.stanza";
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local services = module:get_option("external_services");
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local xmlns_extdisco = "urn:xmpp:extdisco:1";
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 module:add_feature(xmlns_extdisco);
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 module:hook("iq-get/host/"..xmlns_extdisco..":services", function (event)
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local origin, stanza = event.origin, event.stanza;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local service = stanza:get_child("service", xmlns_extdisco);
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local service_type = service and service.attr.type;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local reply = st.reply(stanza);
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 for host, service_info in pairs(services) do
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 if not(service_type) or service_info.type == service_type then
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 reply:tag("service", {
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 host = host;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 port = service_info.port;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 transport = service_info.transport;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 type = service_info.type;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 username = service_info.username;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 password = service_info.password;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 }):up();
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 end
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 end
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 origin.send(reply);
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 return true;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 end);
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 module:hook("iq-get/host/"..xmlns_extdisco..":credentials", function (event)
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 local origin, stanza = event.origin, event.stanza;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 local credentials = stanza:get_child("credentials", xmlns_extdisco);
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 local host = credentials and credentials.attr.host;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 if not host then
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 origin.send(st.error_reply(stanza, "cancel", "bad-request", "No host specified"));
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 return true;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 end
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 local service_info = services[host];
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 if not service_info then
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "No such service known"));
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 return true;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 end
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 local reply = st.reply(stanza)
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 :tag("credentials")
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 :tag("service", {
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 host = host;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 username = service_info.username;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 password = service_info.password;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 }):up();
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 origin.send(reply);
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 return true;
e5c16c87383c mod_extdisco: XEP-0215: External Service Discovery
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 end);