Comparison

core/stanza_router.lua @ 200:5e8b3cce798f

Priority based message routing, etc
author Waqas Hussain <waqas20@gmail.com>
date Sun, 02 Nov 2008 06:53:31 +0500
parent 199:eccf66b42bd7
child 207:90c387884234
comparison
equal deleted inserted replaced
199:eccf66b42bd7 200:5e8b3cce798f
20 local modules_handle_stanza = require "core.modulemanager".handle_stanza; 20 local modules_handle_stanza = require "core.modulemanager".handle_stanza;
21 21
22 local format = string.format; 22 local format = string.format;
23 local tostring = tostring; 23 local tostring = tostring;
24 local t_concat = table.concat; 24 local t_concat = table.concat;
25 local t_insert = table.insert;
25 local tonumber = tonumber; 26 local tonumber = tonumber;
26 local s_find = string.find; 27 local s_find = string.find;
27 28
28 local jid_split = require "util.jid".split; 29 local jid_split = require "util.jid".split;
29 local print = print; 30 local print = print;
216 function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare) 217 function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare)
217 local node, host = jid_split(to_bare); 218 local node, host = jid_split(to_bare);
218 local st_from, st_to = stanza.attr.from, stanza.attr.to; 219 local st_from, st_to = stanza.attr.from, stanza.attr.to;
219 stanza.attr.from, stanza.attr.to = from_bare, to_bare; 220 stanza.attr.from, stanza.attr.to = from_bare, to_bare;
220 if stanza.attr.type == "probe" then 221 if stanza.attr.type == "probe" then
222 log("debug", "inbound probe from "..from_bare.." for "..to_bare);
221 if rostermanager.is_contact_subscribed(node, host, from_bare) then 223 if rostermanager.is_contact_subscribed(node, host, from_bare) then
222 if 0 == send_presence_of_available_resources(node, host, from_bare, origin) then 224 if 0 == send_presence_of_available_resources(node, host, from_bare, origin) then
223 -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) 225 -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too)
224 end 226 end
225 else 227 else
279 -- if we get here, resource was not specified or was unavailable 281 -- if we get here, resource was not specified or was unavailable
280 if stanza.name == "presence" then 282 if stanza.name == "presence" then
281 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then 283 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then
282 handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare); 284 handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare);
283 else -- sender is available or unavailable 285 else -- sender is available or unavailable
284 for k in pairs(user.sessions) do -- presence broadcast to all user resources. FIXME should this be just for available resources? Do we need to check subscription? 286 for _, session in pairs(user.sessions) do -- presence broadcast to all user resources.
285 if user.sessions[k].full_jid then 287 if session.full_jid then -- FIXME should this be just for available resources? Do we need to check subscription?
286 stanza.attr.to = user.sessions[k].full_jid; -- reset at the end of function 288 stanza.attr.to = session.full_jid; -- reset at the end of function
287 user.sessions[k].send(stanza); 289 session.send(stanza);
288 end 290 end
289 end 291 end
290 end 292 end
291 elseif stanza.name == "message" then -- select a resource to recieve message 293 elseif stanza.name == "message" then -- select a resource to recieve message
292 for k in pairs(user.sessions) do 294 local priority = 0;
293 if user.sessions[k].full_jid then 295 local recipients = {};
294 res = user.sessions[k]; 296 for _, session in pairs(user.sessions) do -- find resource with greatest priority
295 break; 297 local p = session.priority;
296 end 298 if p > priority then
297 end 299 priority = p;
298 -- TODO find resource with greatest priority 300 recipients = {session};
299 res.send(stanza); 301 elseif p == priority then
302 t_insert(recipients, session);
303 end
304 end
305 for _, session in pairs(recipient) do
306 session.send(stanza);
307 end
300 else 308 else
301 -- TODO send IQ error 309 -- TODO send IQ error
302 end 310 end
303 else 311 else
304 -- User + resource is online... 312 -- User + resource is online...