Comparison

plugins/mod_presence.lua @ 1286:a9b1675ad16e

mod_presence: Check for nil 'to' attribute in all cases for outgoing stanzas
author Waqas Hussain <waqas20@gmail.com>
date Tue, 02 Jun 2009 20:10:25 +0500
parent 1285:0a6e2d6ae459
child 1287:ac82c7b9c76b
comparison
equal deleted inserted replaced
1285:0a6e2d6ae459 1286:a9b1675ad16e
274 274
275 local outbound_presence_handler = function(data) 275 local outbound_presence_handler = function(data)
276 -- outbound presence recieved 276 -- outbound presence recieved
277 local origin, stanza = data.origin, data.stanza; 277 local origin, stanza = data.origin, data.stanza;
278 278
279 local t = stanza.attr.type;
280 if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes
281 handle_outbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to), core_route_stanza);
282 return true;
283 end
284
285 local to = stanza.attr.to; 279 local to = stanza.attr.to;
286 local to_bare = jid_bare(to); 280 if to then
287 if not(origin.roster[to_bare] and (origin.roster[to_bare].subscription == "both" or origin.roster[to_bare].subscription == "from")) then -- directed presence 281 local t = stanza.attr.type;
288 origin.directed = origin.directed or {}; 282 if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes
289 if t then -- removing from directed presence list on sending an error or unavailable 283 handle_outbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to), core_route_stanza);
290 origin.directed[to] = nil; -- FIXME does it make more sense to add to_bare rather than to? 284 return true;
291 else 285 end
292 origin.directed[to] = true; -- FIXME does it make more sense to add to_bare rather than to? 286
293 end 287 local to_bare = jid_bare(to);
294 end 288 if not(origin.roster[to_bare] and (origin.roster[to_bare].subscription == "both" or origin.roster[to_bare].subscription == "from")) then -- directed presence
289 origin.directed = origin.directed or {};
290 if t then -- removing from directed presence list on sending an error or unavailable
291 origin.directed[to] = nil; -- FIXME does it make more sense to add to_bare rather than to?
292 else
293 origin.directed[to] = true; -- FIXME does it make more sense to add to_bare rather than to?
294 end
295 end
296 end -- TODO maybe handle normal presence here, instead of letting it pass to incoming handlers?
295 end 297 end
296 298
297 module:hook("pre-presence/full", outbound_presence_handler); 299 module:hook("pre-presence/full", outbound_presence_handler);
298 module:hook("pre-presence/bare", outbound_presence_handler); 300 module:hook("pre-presence/bare", outbound_presence_handler);
299 module:hook("pre-presence/host", outbound_presence_handler); 301 module:hook("pre-presence/host", outbound_presence_handler);