diff options
author | Kim Alvefur <zash@zash.se> | 2021-09-24 20:17:31 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-09-24 20:17:31 +0200 |
commit | e341f785e6025bb36d3219444d379f1b8b634df0 (patch) | |
tree | f3ded3306ebf9eb28a96051bfa2f507a5d072bb7 | |
parent | 73d73278960523d3a1d603d08a76a9fb72fc067d (diff) | |
download | prosody-e341f785e6025bb36d3219444d379f1b8b634df0.tar.gz prosody-e341f785e6025bb36d3219444d379f1b8b634df0.zip |
core.moduleapi: Enable full JID origin queries with module:send_iq()
Since we don't currently have hooks that includes type and id here, we
need to check those attributes in the handlers.
-rw-r--r-- | core/moduleapi.lua | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua index a38a6076..52410352 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -20,6 +20,7 @@ local promise = require "util.promise"; local time_now = require "util.time".now; local format = require "util.format".format; local jid_node = require "util.jid".node; +local jid_resource = require "util.jid".resource; local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; local error, setmetatable, type = error, setmetatable, type; @@ -382,23 +383,31 @@ function api:send_iq(stanza, origin, timeout) local event_type; if not jid_node(stanza.attr.from) then event_type = "host"; + elseif jid_resource(stanza.attr.from) then + event_type = "full"; else -- assume bare since we can't hook full jids event_type = "bare"; end local result_event = "iq-result/"..event_type.."/"..stanza.attr.id; local error_event = "iq-error/"..event_type.."/"..stanza.attr.id; local cache_key = event_type.."/"..stanza.attr.id; + if event_type == "full" then + result_event = "iq/" .. event_type; + error_event = "iq/" .. event_type; + end local p = promise.new(function (resolve, reject) local function result_handler(event) - if event.stanza.attr.from == stanza.attr.to then + local response = event.stanza; + if response.attr.type == "result" and response.attr.from == stanza.attr.to and response.attr.id == stanza.attr.id then resolve(event); return true; end end local function error_handler(event) - if event.stanza.attr.from == stanza.attr.to then + local response = event.stanza; + if response.attr.type == "error" and response.attr.from == stanza.attr.to and response.attr.id == stanza.attr.id then reject(errors.from_stanza(event.stanza, event)); return true; end |