Comparison

plugins/mod_presence.lua @ 2531:697ff4f98033

mod_presence: Added handler for presence subscriptions and probes to local hosts.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 29 Jan 2010 21:06:51 +0500
parent 2525:e385511b3a54
child 2532:b1b1b4a7db26
comparison
equal deleted inserted replaced
2530:26c1f27eb35d 2531:697ff4f98033
307 elseif not t or t == "unavailable" then 307 elseif not t or t == "unavailable" then
308 handle_normal_presence(origin, stanza, core_route_stanza); 308 handle_normal_presence(origin, stanza, core_route_stanza);
309 end 309 end
310 return true; 310 return true;
311 end); 311 end);
312 module:hook("presence/host", function (data)
313 local stanza = data.stanza;
314 local reply = st.reply(stanza);
315 reply.attr.type = "unsubscribed";
316 handle_inbound_presence_subscriptions_and_probes(data.origin, reply, jid_bare(stanza.attr.to), jid_bare(stanza.attr.from), core_route_stanza);
317 return true;
318 end);
319 module:hook("presence/full", function(data) 312 module:hook("presence/full", function(data)
320 -- inbound presence to full JID recieved 313 -- inbound presence to full JID recieved
321 local origin, stanza = data.origin, data.stanza; 314 local origin, stanza = data.origin, data.stanza;
322 315
323 local t = stanza.attr.type; 316 local t = stanza.attr.type;
329 local session = full_sessions[stanza.attr.to]; 322 local session = full_sessions[stanza.attr.to];
330 if session then 323 if session then
331 -- TODO fire post processing event 324 -- TODO fire post processing event
332 session.send(stanza); 325 session.send(stanza);
333 end -- resource not online, discard 326 end -- resource not online, discard
327 return true;
328 end);
329 module:hook("presence/host", function(data)
330 -- inbound presence to the host
331 local origin, stanza = data.origin, data.stanza;
332
333 local from_bare = jid_bare(stanza.attr.from);
334 local t = stanza.attr.type;
335 if t == "probe" then
336 core_route_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id }));
337 elseif t == "subscribe" then
338 core_route_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id, type = "subscribed" }));
339 core_route_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id }));
340 end
334 return true; 341 return true;
335 end); 342 end);
336 343
337 module:hook("resource-unbind", function(event) 344 module:hook("resource-unbind", function(event)
338 local session, err = event.session, event.error; 345 local session, err = event.session, event.error;