comparison mod_delegation/mod_delegation.lua @ 1724:2440a75e868f

mod_delegation: managing_ent_* now stop event propagation + forwarded <iq/> xmlns check
author Goffi <goffi@goffi.org>
date Thu, 07 May 2015 22:40:58 +0200
parents ef85c42ad977
children 7bfc23b2c038
comparison
equal deleted inserted replaced
1723:ef85c42ad977 1724:2440a75e868f
182 return true 182 return true
183 end 183 end
184 184
185 local iq = forwarded.tags[1] 185 local iq = forwarded.tags[1]
186 if #forwarded ~= 1 or iq.name ~= "iq" or 186 if #forwarded ~= 1 or iq.name ~= "iq" or
187 iq.attr.xmlns ~= 'jabber:client' or
187 (iq.attr.type =='result' and #iq ~= 1) or 188 (iq.attr.type =='result' and #iq ~= 1) or
188 (iq.attr.type == 'error' and #iq > 2) then 189 (iq.attr.type == 'error' and #iq > 2) then
189 module:log("warn", "ignoring invalid iq result from managing entity %s", stanza.attr.from) 190 module:log("warn", "ignoring invalid iq result from managing entity %s", stanza.attr.from)
190 stanza_cache[stanza.attr.from][stanza.attr.id] = nil 191 stanza_cache[stanza.attr.from][stanza.attr.id] = nil
191 return true 192 return true
192 end 193 end
194
195 iq.attr.xmlns = nil
193 196
194 local original = stanza_cache[stanza.attr.from][stanza.attr.id] 197 local original = stanza_cache[stanza.attr.from][stanza.attr.id]
195 stanza_cache[stanza.attr.from][stanza.attr.id] = nil 198 stanza_cache[stanza.attr.from][stanza.attr.id] = nil
196 -- we get namespace from original and not iq 199 -- we get namespace from original and not iq
197 -- because the namespace can be lacking in case of error 200 -- because the namespace can be lacking in case of error
206 end 209 end
207 210
208 -- at this point eveything is checked, 211 -- at this point eveything is checked,
209 -- and we (hopefully) can send the the result safely 212 -- and we (hopefully) can send the the result safely
210 module:send(iq) 213 module:send(iq)
214 return true
211 end 215 end
212 216
213 function managing_ent_error(event) 217 function managing_ent_error(event)
214 local stanza = event.stanza 218 local stanza = event.stanza
215 if stanza.attr.to ~= module.host then 219 if stanza.attr.to ~= module.host then
220 module:unhook("iq-error/host/"..stanza.attr.id, managing_ent_error) 224 module:unhook("iq-error/host/"..stanza.attr.id, managing_ent_error)
221 local original = stanza_cache[stanza.attr.from][stanza.attr.id] 225 local original = stanza_cache[stanza.attr.from][stanza.attr.id]
222 stanza_cache[stanza.attr.from][stanza.attr.id] = nil 226 stanza_cache[stanza.attr.from][stanza.attr.id] = nil
223 module:log("warn", "Got an error after forwarding stanza to "..stanza.attr.from) 227 module:log("warn", "Got an error after forwarding stanza to "..stanza.attr.from)
224 module:send(st.error_reply(original, 'cancel', 'service-unavailable')) 228 module:send(st.error_reply(original, 'cancel', 'service-unavailable'))
229 return true
225 end 230 end
226 231
227 local function forward_iq(stanza, ns_data) 232 local function forward_iq(stanza, ns_data)
228 local to_jid = ns_data.connected 233 local to_jid = ns_data.connected
229 stanza.attr.xmlns = 'jabber:client' 234 stanza.attr.xmlns = 'jabber:client'