mod_auto_answer_disco_info/mod_auto_answer_disco_info.lua
author Kim Alvefur <zash@zash.se>
Sat, 28 Sep 2019 00:16:13 +0200
changeset 3909 5ae2e865eea0
parent 3272 4cdd1ddae72c
child 4589 05c74210c007
permissions -rw-r--r--
mod_sasl2: Experimental implementation of XEP-0388

module:depends("cache_c2s_caps");

local st = require "util.stanza";

local function disco_handler(event)
	local stanza, origin = event.stanza, event.origin;
	local query = stanza.tags[1];
	local to = stanza.attr.to;
	local node = query.attr.node;

	local target_session = prosody.full_sessions[to];
	if target_session == nil then
		return;
	end

	local disco_info = target_session.caps_cache;
	if disco_info ~= nil and (node == nil or node == disco_info.attr.node) then
		local iq = st.reply(stanza);
		iq:add_child(st.clone(disco_info));
		local log = origin.log or module._log;
		log("debug", "Answering disco#info on the behalf of %s", to);
		module:send(iq);
		return true;
	end
end

module:hook("iq-get/full/http://jabber.org/protocol/disco#info:query", disco_handler, 1);