Comparison

core/moduleapi.lua @ 11822:bdabb0425d77

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.
author Kim Alvefur <zash@zash.se>
date Fri, 24 Sep 2021 20:17:31 +0200
parent 11821:a9ad287c3388
child 11823:36a7a3137d41
comparison
equal deleted inserted replaced
11821:a9ad287c3388 11822:bdabb0425d77
18 local errors = require "util.error"; 18 local errors = require "util.error";
19 local promise = require "util.promise"; 19 local promise = require "util.promise";
20 local time_now = require "util.time".now; 20 local time_now = require "util.time".now;
21 local format = require "util.format".format; 21 local format = require "util.format".format;
22 local jid_node = require "util.jid".node; 22 local jid_node = require "util.jid".node;
23 local jid_resource = require "util.jid".resource;
23 24
24 local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; 25 local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat;
25 local error, setmetatable, type = error, setmetatable, type; 26 local error, setmetatable, type = error, setmetatable, type;
26 local ipairs, pairs, select = ipairs, pairs, select; 27 local ipairs, pairs, select = ipairs, pairs, select;
27 local tonumber, tostring = tonumber, tostring; 28 local tonumber, tostring = tonumber, tostring;
380 end 381 end
381 382
382 local event_type; 383 local event_type;
383 if not jid_node(stanza.attr.from) then 384 if not jid_node(stanza.attr.from) then
384 event_type = "host"; 385 event_type = "host";
386 elseif jid_resource(stanza.attr.from) then
387 event_type = "full";
385 else -- assume bare since we can't hook full jids 388 else -- assume bare since we can't hook full jids
386 event_type = "bare"; 389 event_type = "bare";
387 end 390 end
388 local result_event = "iq-result/"..event_type.."/"..stanza.attr.id; 391 local result_event = "iq-result/"..event_type.."/"..stanza.attr.id;
389 local error_event = "iq-error/"..event_type.."/"..stanza.attr.id; 392 local error_event = "iq-error/"..event_type.."/"..stanza.attr.id;
390 local cache_key = event_type.."/"..stanza.attr.id; 393 local cache_key = event_type.."/"..stanza.attr.id;
394 if event_type == "full" then
395 result_event = "iq/" .. event_type;
396 error_event = "iq/" .. event_type;
397 end
391 398
392 local p = promise.new(function (resolve, reject) 399 local p = promise.new(function (resolve, reject)
393 local function result_handler(event) 400 local function result_handler(event)
394 if event.stanza.attr.from == stanza.attr.to then 401 local response = event.stanza;
402 if response.attr.type == "result" and response.attr.from == stanza.attr.to and response.attr.id == stanza.attr.id then
395 resolve(event); 403 resolve(event);
396 return true; 404 return true;
397 end 405 end
398 end 406 end
399 407
400 local function error_handler(event) 408 local function error_handler(event)
401 if event.stanza.attr.from == stanza.attr.to then 409 local response = event.stanza;
410 if response.attr.type == "error" and response.attr.from == stanza.attr.to and response.attr.id == stanza.attr.id then
402 reject(errors.from_stanza(event.stanza, event)); 411 reject(errors.from_stanza(event.stanza, event));
403 return true; 412 return true;
404 end 413 end
405 end 414 end
406 415