# HG changeset patch # User Emmanuel Gil Peyrot # Date 1520439109 -3600 # Node ID 0286ccacec7c5a04b0e452ede2582d34a8c766e9 # Parent 0273d7583373a853e1499f18b615397ae4075d05 mod_auto_answer_disco_info: New module answering disco#info queries on the behalf of the recipient diff -r 0273d7583373 -r 0286ccacec7c mod_auto_answer_disco_info/README.markdown --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_auto_answer_disco_info/README.markdown Wed Mar 07 17:11:49 2018 +0100 @@ -0,0 +1,10 @@ +--- +summary: Answers disco#info queries on the behalf of the recipient +--- + +Description +=========== + +This module intercepts disco#info queries and checks if we already know the +capabilities of this session, in which case we don’t transmit the iq and answer +it ourselves. diff -r 0273d7583373 -r 0286ccacec7c mod_auto_answer_disco_info/mod_auto_answer_disco_info.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_auto_answer_disco_info/mod_auto_answer_disco_info.lua Wed Mar 07 17:11:49 2018 +0100 @@ -0,0 +1,28 @@ +module:depends("cache_c2s_caps"); + +local st = require "util.stanza"; + +local function iq_stanza_handler(event) + local origin, stanza = event.origin, event.stanza; + local type = stanza.attr.type; + + local query = stanza:get_child("query", "http://jabber.org/protocol/disco#info"); + if type ~= "get" or query == nil then + return; + end + + local to = stanza.attr.to; + local node = query.attr.node; + + local target_session = full_sessions[to]; + 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)); + module:log("debug", "Answering disco#info on the behalf of the recipient") + module:send(iq); + return true; + end +end + +module:hook("iq/full", iq_stanza_handler, 1);