From e341f785e6025bb36d3219444d379f1b8b634df0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 24 Sep 2021 20:17:31 +0200 Subject: 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. --- core/moduleapi.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'core') 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 -- cgit v1.2.3