comparison mod_delegation/mod_delegation.lua @ 3317:36a9170352b5

mod_delegation: Update to generate own iq ids
author Matthew Wild <mwild1@gmail.com>
date Thu, 13 Sep 2018 16:28:10 +0100
parents 7504f765e767
children c5e8042b174c
comparison
equal deleted inserted replaced
3316:9d8098f4b652 3317:36a9170352b5
10 -- TODO: client mode 10 -- TODO: client mode
11 11
12 local jid = require("util.jid") 12 local jid = require("util.jid")
13 local st = require("util.stanza") 13 local st = require("util.stanza")
14 local set = require("util.set") 14 local set = require("util.set")
15
16 local new_id = require("util.id").short;
15 17
16 local delegation_session = module:shared("/*/delegation/session") 18 local delegation_session = module:shared("/*/delegation/session")
17 19
18 -- FIXME: temporarily needed for disco_items_hook, to be removed when clean implementation is done 20 -- FIXME: temporarily needed for disco_items_hook, to be removed when clean implementation is done
19 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; 21 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
250 end 252 end
251 253
252 local function forward_iq(stanza, ns_data) 254 local function forward_iq(stanza, ns_data)
253 local to_jid = ns_data.connected 255 local to_jid = ns_data.connected
254 stanza.attr.xmlns = 'jabber:client' 256 stanza.attr.xmlns = 'jabber:client'
255 local iq_stanza = st.iq({ from=module.host, to=to_jid, type="set" }) 257 local iq_id = new_id();
258 local iq_stanza = st.iq({ from=module.host, to=to_jid, type="set", id = iq_id })
256 :tag("delegation", { xmlns=_DELEGATION_NS }) 259 :tag("delegation", { xmlns=_DELEGATION_NS })
257 :tag("forwarded", { xmlns=_FORWARDED_NS }) 260 :tag("forwarded", { xmlns=_FORWARDED_NS })
258 :add_child(stanza) 261 :add_child(stanza)
259 local iq_id = iq_stanza.attr.id
260 -- we save the original stanza to check the managing entity result 262 -- we save the original stanza to check the managing entity result
261 if not stanza_cache[to_jid] then stanza_cache[to_jid] = {} end 263 if not stanza_cache[to_jid] then stanza_cache[to_jid] = {} end
262 stanza_cache[to_jid][iq_id] = stanza 264 stanza_cache[to_jid][iq_id] = stanza
263 module:hook("iq-result/host/"..iq_id, managing_ent_result) 265 module:hook("iq-result/host/"..iq_id, managing_ent_result)
264 module:hook("iq-error/host/"..iq_id, managing_ent_error) 266 module:hook("iq-error/host/"..iq_id, managing_ent_error)
473 end 475 end
474 476
475 for _, prefix in ipairs(_PREFIXES) do 477 for _, prefix in ipairs(_PREFIXES) do
476 local node = prefix..namespace 478 local node = prefix..namespace
477 479
478 local iq = st.iq({from=module.host, to=entity_jid, type='get'}) 480 local iq_id = new_id();
481 local iq = st.iq({from=module.host, to=entity_jid, type='get', id = iq_id })
479 :tag('query', {xmlns=_DISCO_INFO_NS, node=node}) 482 :tag('query', {xmlns=_DISCO_INFO_NS, node=node})
480
481 local iq_id = iq.attr.id
482 483
483 module:hook("iq-result/host/"..iq_id, disco_result) 484 module:hook("iq-result/host/"..iq_id, disco_result)
484 module:hook("iq-error/host/"..iq_id, disco_error) 485 module:hook("iq-error/host/"..iq_id, disco_error)
485 module:send(iq) 486 module:send(iq)
486 end 487 end