aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_external_services.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/mod_external_services.lua')
-rw-r--r--plugins/mod_external_services.lua49
1 files changed, 21 insertions, 28 deletions
diff --git a/plugins/mod_external_services.lua b/plugins/mod_external_services.lua
index 3a92dc2d..6b46f890 100644
--- a/plugins/mod_external_services.lua
+++ b/plugins/mod_external_services.lua
@@ -131,6 +131,25 @@ function get_services()
return services;
end
+function services_xml(services, name, namespace)
+ local reply = st.stanza(name or "services", { xmlns = namespace or "urn:xmpp:extdisco:2" });
+
+ for _, srv in ipairs(services) do
+ reply:tag("service", {
+ type = srv.type;
+ transport = srv.transport;
+ host = srv.host;
+ port = srv.port and string.format("%d", srv.port) or nil;
+ username = srv.username;
+ password = srv.password;
+ expires = srv.expires and dt.datetime(srv.expires) or nil;
+ restricted = srv.restricted and "1" or nil;
+ }):up();
+ end
+
+ return reply;
+end
+
local function handle_services(event)
local origin, stanza = event.origin, event.stanza;
local action = stanza.tags[1];
@@ -142,7 +161,6 @@ local function handle_services(event)
return true;
end
- local reply = st.reply(stanza):tag("services", { xmlns = action.attr.xmlns });
local services = get_services();
local requested_type = action.attr.type;
@@ -155,23 +173,11 @@ local function handle_services(event)
module:fire_event("external_service/services", {
origin = origin;
stanza = stanza;
- reply = reply;
requested_type = requested_type;
services = services;
});
- for _, srv in ipairs(services) do
- reply:tag("service", {
- type = srv.type;
- transport = srv.transport;
- host = srv.host;
- port = srv.port and string.format("%d", srv.port) or nil;
- username = srv.username;
- password = srv.password;
- expires = srv.expires and dt.datetime(srv.expires) or nil;
- restricted = srv.restricted and "1" or nil;
- }):up();
- end
+ local reply = st.reply(stanza):add_child(services_xml(services, action.name, action.attr.xmlns));
origin.send(reply);
return true;
@@ -186,7 +192,6 @@ local function handle_credentials(event)
return true;
end
- local reply = st.reply(stanza):tag("credentials", { xmlns = action.attr.xmlns });
local services = get_services();
services:filter(function (item)
return item.restricted;
@@ -206,7 +211,6 @@ local function handle_credentials(event)
module:fire_event("external_service/credentials", {
origin = origin;
stanza = stanza;
- reply = reply;
requested_credentials = requested_credentials;
services = services;
});
@@ -217,18 +221,7 @@ local function handle_credentials(event)
return requested_credentials:contains(port_key) or requested_credentials:contains(portless_key);
end);
- for _, srv in ipairs(services) do
- reply:tag("service", {
- type = srv.type;
- transport = srv.transport;
- host = srv.host;
- port = srv.port and string.format("%d", srv.port) or nil;
- username = srv.username;
- password = srv.password;
- expires = srv.expires and dt.datetime(srv.expires) or nil;
- restricted = srv.restricted and "1" or nil;
- }):up();
- end
+ local reply = st.reply(stanza):add_child(services_xml(services, action.name, action.attr.xmlns));
origin.send(reply);
return true;