diff options
author | Kim Alvefur <zash@zash.se> | 2020-08-17 00:24:11 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2020-08-17 00:24:11 +0200 |
commit | fb6c098ed661d4bd14f1a0515e4ae6b110c76b19 (patch) | |
tree | 92e5de69f956e12aff378954598998ada84eabd4 /plugins/mod_external_services.lua | |
parent | 5bc6130e57fe2af3108ec538b83768100bdc177c (diff) | |
download | prosody-fb6c098ed661d4bd14f1a0515e4ae6b110c76b19.tar.gz prosody-fb6c098ed661d4bd14f1a0515e4ae6b110c76b19.zip |
mod_external_services: Validate services added via events
While writing developer documentation it became obvious that i was silly
to have one item format for config and items API, and another format for
the event API.
Then there's the stanza format, but that's a common pattern.
This change reduces the possible input formats to two and allows other
modules the benefit of the processing and validation performed on items
from the config.
Diffstat (limited to 'plugins/mod_external_services.lua')
-rw-r--r-- | plugins/mod_external_services.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/plugins/mod_external_services.lua b/plugins/mod_external_services.lua index 7c18e326..e18e7c3e 100644 --- a/plugins/mod_external_services.lua +++ b/plugins/mod_external_services.lua @@ -4,6 +4,7 @@ local base64 = require "util.encodings".base64; local hashes = require "util.hashes"; local st = require "util.stanza"; local jid = require "util.jid"; +local array = require "util.array"; local default_host = module:get_option_string("external_service_host", module.host); local default_port = module:get_option_number("external_service_port"); @@ -105,6 +106,14 @@ function module.load() end end +-- Ensure only valid items are added in events +local services_mt = { + __index = getmetatable(array()).__index; + __newindex = function (self, i, v) + rawset(self, i, assert(prepare(v), "Invalid service entry added")); + end; +} + local function handle_services(event) local origin, stanza = event.origin, event.stanza; local action = stanza.tags[1]; @@ -127,6 +136,8 @@ local function handle_services(event) end); end + setmetatable(services, services_mt); + module:fire_event("external_service/services", { origin = origin; stanza = stanza; @@ -177,6 +188,9 @@ local function handle_credentials(event) }); end + setmetatable(services, services_mt); + setmetatable(requested_credentials, services_mt); + module:fire_event("external_service/credentials", { origin = origin; stanza = stanza; |