comparison mod_auto_answer_disco_info/mod_auto_answer_disco_info.lua @ 2900:0286ccacec7c

mod_auto_answer_disco_info: New module answering disco#info queries on the behalf of the recipient
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 07 Mar 2018 17:11:49 +0100
parents
children 037ad1cd0d31
comparison
equal deleted inserted replaced
2899:0273d7583373 2900:0286ccacec7c
1 module:depends("cache_c2s_caps");
2
3 local st = require "util.stanza";
4
5 local function iq_stanza_handler(event)
6 local origin, stanza = event.origin, event.stanza;
7 local type = stanza.attr.type;
8
9 local query = stanza:get_child("query", "http://jabber.org/protocol/disco#info");
10 if type ~= "get" or query == nil then
11 return;
12 end
13
14 local to = stanza.attr.to;
15 local node = query.attr.node;
16
17 local target_session = full_sessions[to];
18 local disco_info = target_session.caps_cache;
19 if disco_info ~= nil and (node == nil or node == disco_info.attr.node) then
20 local iq = st.reply(stanza);
21 iq:add_child(st.clone(disco_info));
22 module:log("debug", "Answering disco#info on the behalf of the recipient")
23 module:send(iq);
24 return true;
25 end
26 end
27
28 module:hook("iq/full", iq_stanza_handler, 1);