aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-05-28 20:39:32 +0100
committerMatthew Wild <mwild1@gmail.com>2009-05-28 20:39:32 +0100
commit762a39c8d024c74897747c35f51cbbf8018fae42 (patch)
treec04b81ebc5cc3ac3f4502826e3642c967379b446 /core
parent72b2a6fd6bd4003ec222f6fdb3f82c7eff73281c (diff)
downloadprosody-762a39c8d024c74897747c35f51cbbf8018fae42.tar.gz
prosody-762a39c8d024c74897747c35f51cbbf8018fae42.zip
stanza_router: Break off resource selection for messages into a standalone function
Diffstat (limited to 'core')
-rw-r--r--core/stanza_router.lua34
1 files changed, 20 insertions, 14 deletions
diff --git a/core/stanza_router.lua b/core/stanza_router.lua
index 6fa41232..b739c99e 100644
--- a/core/stanza_router.lua
+++ b/core/stanza_router.lua
@@ -44,6 +44,8 @@ local jid_prepped_split = require "util.jid".prepped_split;
local print = print;
local fire_event = require "core.eventmanager2".fire_event;
+local select_best_resources;
+
function core_process_stanza(origin, stanza)
(origin.log or log)("debug", "Received[%s]: %s", origin.type, stanza:top_tag())
@@ -199,21 +201,8 @@ function core_route_stanza(origin, stanza)
-- Groupchat message sent to offline resource
origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
else
- local priority = 0;
- local recipients = {};
- for _, session in pairs(user.sessions) do -- find resource with greatest priority
- if session.presence then
- local p = session.priority;
- if p > priority then
- priority = p;
- recipients = {session};
- elseif p == priority then
- t_insert(recipients, session);
- end
- end
- end
local count = 0;
- for _, session in ipairs(recipients) do
+ for _, session in ipairs(select_best_resources(user)) do
session.send(stanza);
count = count + 1;
end
@@ -280,3 +269,20 @@ function core_route_stanza(origin, stanza)
end
stanza.attr.to = to; -- reset
end
+
+function select_best_resources(user)
+ local priority = 0;
+ local recipients = {};
+ for _, session in pairs(user.sessions) do -- find resource with greatest priority
+ if session.presence then
+ local p = session.priority;
+ if p > priority then
+ priority = p;
+ recipients = {session};
+ elseif p == priority then
+ t_insert(recipients, session);
+ end
+ end
+ end
+ return recipients;
+end