Software /
code /
prosody
Comparison
core/stanza_router.lua @ 783:defb0119f80f
Stanza router: Message to bare JID fixes
- headline messages get sent to all non-negative priority available resource
- all other messages get sent to the set of highest non-negative priority available resources
- only messages of type chat and normal or missing type go into offline storage
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Wed, 11 Feb 2009 23:16:14 +0500 |
parent | 781:191b9f0e5485 |
child | 784:1de8a32f81e9 |
comparison
equal
deleted
inserted
replaced
782:6f9b2a9d6d45 | 783:defb0119f80f |
---|---|
32 local tostring = tostring; | 32 local tostring = tostring; |
33 local t_concat = table.concat; | 33 local t_concat = table.concat; |
34 local t_insert = table.insert; | 34 local t_insert = table.insert; |
35 local tonumber = tonumber; | 35 local tonumber = tonumber; |
36 local s_find = string.find; | 36 local s_find = string.find; |
37 local pairs = pairs; | |
38 local ipairs = ipairs; | |
37 | 39 |
38 local jid_split = require "util.jid".split; | 40 local jid_split = require "util.jid".split; |
39 local jid_prepped_split = require "util.jid".prepped_split; | 41 local jid_prepped_split = require "util.jid".prepped_split; |
40 local print = print; | 42 local print = print; |
41 local function checked_error_reply(origin, stanza) | 43 local function checked_error_reply(origin, stanza) |
206 session.send(stanza); | 208 session.send(stanza); |
207 end | 209 end |
208 end | 210 end |
209 end | 211 end |
210 elseif stanza.name == "message" then -- select a resource to recieve message | 212 elseif stanza.name == "message" then -- select a resource to recieve message |
211 local priority = 0; | 213 if message.attr.type == 'headline' then |
212 local recipients = {}; | 214 for _, session in pairs(user.sessions) do -- find resource with greatest priority |
213 for _, session in pairs(user.sessions) do -- find resource with greatest priority | 215 if session.presence and session.priority >= 0 then |
214 local p = session.priority; | 216 stanza.attr.to = session.full_jid; |
215 if p > priority then | 217 session.send(stanza); |
216 priority = p; | 218 end |
217 recipients = {session}; | 219 end |
218 elseif p == priority then | 220 else |
219 t_insert(recipients, session); | 221 local priority = 0; |
220 end | 222 local recipients = {}; |
221 end | 223 for _, session in pairs(user.sessions) do -- find resource with greatest priority |
222 local count = 0; | 224 if session.presence then |
223 for _, session in pairs(recipients) do | 225 local p = session.priority; |
224 session.send(stanza); | 226 if p > priority then |
225 count = count + 1; | 227 priority = p; |
226 end | 228 recipients = {session}; |
227 if count == 0 then | 229 elseif p == priority then |
228 offlinemanager.store(node, host, stanza); | 230 t_insert(recipients, session); |
229 -- TODO deal with storage errors | 231 end |
232 end | |
233 end | |
234 local count = 0; | |
235 for _, session in ipairs(recipients) do | |
236 session.send(stanza); | |
237 count = count + 1; | |
238 end | |
239 if count == 0 and (stanza.attr.type == "chat" or stanza.attr.type == "normal" or not stanza.attr.type) then | |
240 offlinemanager.store(node, host, stanza); | |
241 -- TODO deal with storage errors | |
242 end | |
230 end | 243 end |
231 else | 244 else |
232 -- TODO send IQ error | 245 -- TODO send IQ error |
233 end | 246 end |
234 else | 247 else |