33 handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to), core_route_stanza); |
33 handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to), core_route_stanza); |
34 return; |
34 return; |
35 end |
35 end |
36 end |
36 end |
37 _core_route_stanza(origin, stanza); |
37 _core_route_stanza(origin, stanza); |
38 end |
|
39 |
|
40 function handle_presence(origin, stanza, from_bare, to_bare, core_route_stanza, inbound) |
|
41 local type = stanza.attr.type; |
|
42 if type and type ~= "unavailable" and type ~= "error" then |
|
43 if inbound then |
|
44 handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza); |
|
45 else |
|
46 handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza); |
|
47 end |
|
48 elseif not inbound and not stanza.attr.to then |
|
49 handle_normal_presence(origin, stanza, core_route_stanza); |
|
50 else |
|
51 core_route_stanza(origin, stanza); |
|
52 end |
|
53 end |
38 end |
54 |
39 |
55 local function select_top_resources(user) |
40 local function select_top_resources(user) |
56 local priority = 0; |
41 local priority = 0; |
57 local recipients = {}; |
42 local recipients = {}; |
266 end |
251 end |
267 end -- discard any other type |
252 end -- discard any other type |
268 stanza.attr.from, stanza.attr.to = st_from, st_to; |
253 stanza.attr.from, stanza.attr.to = st_from, st_to; |
269 end |
254 end |
270 |
255 |
271 local function presence_handler(data) |
|
272 local origin, stanza = data.origin, data.stanza; |
|
273 local to = stanza.attr.to; |
|
274 local node, host = jid_split(to); |
|
275 local to_bare = jid_bare(to); |
|
276 local from_bare = jid_bare(stanza.attr.from); |
|
277 if origin.type == "c2s" then |
|
278 if to ~= nil and not(origin.roster[to_bare] and (origin.roster[to_bare].subscription == "both" or origin.roster[to_bare].subscription == "from")) then -- directed presence |
|
279 origin.directed = origin.directed or {}; |
|
280 origin.directed[to] = true; -- FIXME does it make more sense to add to_bare rather than to? |
|
281 end |
|
282 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then |
|
283 handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza); |
|
284 elseif not to then |
|
285 handle_normal_presence(origin, stanza, core_route_stanza); |
|
286 else |
|
287 core_route_stanza(origin, stanza); |
|
288 end |
|
289 elseif (origin.type == "s2sin" or origin.type == "component") and hosts[host] then |
|
290 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then |
|
291 handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza); |
|
292 else |
|
293 core_route_stanza(origin, stanza); |
|
294 end |
|
295 end |
|
296 return true; |
|
297 end |
|
298 |
|
299 prosody.events.add_handler(module:get_host().."/presence", presence_handler); |
|
300 module.unload = function() |
|
301 prosody.events.remove_handler(module:get_host().."/presence", presence_handler); |
|
302 end |
|
303 |
|
304 local outbound_presence_handler = function(data) |
256 local outbound_presence_handler = function(data) |
305 -- outbound presence recieved |
257 -- outbound presence recieved |
306 local origin, stanza = data.origin, data.stanza; |
258 local origin, stanza = data.origin, data.stanza; |
307 |
259 |
308 local to = stanza.attr.to; |
260 local to = stanza.attr.to; |