From 2f24ab95fe28c13d85faf1dbfa16b0c3a90b46b1 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Wed, 11 Feb 2009 18:09:41 +0500 Subject: Fixed directed presence handling to work correctly for components --- core/stanza_router.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'core/stanza_router.lua') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 3c905c6d..52a18eed 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -105,6 +105,11 @@ function core_process_stanza(origin, stanza) return; -- FIXME what should we do here? does this work with subdomains? end end + if origin.type == "c2s" and stanza.name == "presence" and 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 + origin.directed = origin.directed or {}; + origin.directed[to] = true; + --t_insert(origin.directed, to); -- FIXME does it make more sense to add to_bare rather than to? + end if not to then core_handle_stanza(origin, stanza); elseif hosts[to] and hosts[to].type == "local" then -- directed at a local server @@ -122,10 +127,6 @@ function core_process_stanza(origin, stanza) elseif origin.type ~= "c2s" and stanza.name == "iq" and not resource then -- directed at bare JID core_handle_stanza(origin, stanza); else - if origin.type == "c2s" and stanza.name == "presence" and to ~= nil and not(origin.roster[to_bare] and (origin.roster[to_bare].subscription == "both" or origin.roster[to_bare].subscription == "from")) then - origin.directed = origin.directed or {}; - t_insert(origin.directed, to); -- FIXME does it make more sense to add to_bare rather than to? - end core_route_stanza(origin, stanza); end else -- cgit v1.2.3 From 33306b3fb77d532af2213ab876f059c70feb599e Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Wed, 11 Feb 2009 18:11:41 +0500 Subject: Fixed: Some presence stanzas from local users were not being routed correctly to components (ghosts in mod_muc) --- core/stanza_router.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'core/stanza_router.lua') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 52a18eed..c27a6579 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -178,6 +178,14 @@ function core_route_stanza(origin, stanza) origin = origin or hosts[from_host]; if not origin then return false; end + if hosts[to] and hosts[to].type == "component" then -- hack to allow components to handle node@server/resource and server/resource + return component_handle_stanza(origin, stanza); + elseif hosts[to_bare] and hosts[to_bare].type == "component" then -- hack to allow components to handle node@server + return component_handle_stanza(origin, stanza); + elseif hosts[host] and hosts[host].type == "component" then -- directed at a component + return component_handle_stanza(origin, stanza); + end + if stanza.name == "presence" and (stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable") then resource = nil; end local host_session = hosts[host] -- cgit v1.2.3 From 55223db764c36726db0bbf69ddff3703abe4bd1f Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Wed, 11 Feb 2009 23:16:14 +0500 Subject: 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 --- core/stanza_router.lua | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'core/stanza_router.lua') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index c27a6579..f83619c6 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -34,6 +34,8 @@ local t_concat = table.concat; local t_insert = table.insert; local tonumber = tonumber; local s_find = string.find; +local pairs = pairs; +local ipairs = ipairs; local jid_split = require "util.jid".split; local jid_prepped_split = require "util.jid".prepped_split; @@ -208,25 +210,36 @@ function core_route_stanza(origin, stanza) end end elseif stanza.name == "message" then -- select a resource to recieve message - local priority = 0; - local recipients = {}; - for _, session in pairs(user.sessions) do -- find resource with greatest priority - local p = session.priority; - if p > priority then - priority = p; - recipients = {session}; - elseif p == priority then - t_insert(recipients, session); + if message.attr.type == 'headline' then + for _, session in pairs(user.sessions) do -- find resource with greatest priority + if session.presence and session.priority >= 0 then + stanza.attr.to = session.full_jid; + session.send(stanza); + end + end + 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 + session.send(stanza); + count = count + 1; + end + if count == 0 and (stanza.attr.type == "chat" or stanza.attr.type == "normal" or not stanza.attr.type) then + offlinemanager.store(node, host, stanza); + -- TODO deal with storage errors end - end - local count = 0; - for _, session in pairs(recipients) do - session.send(stanza); - count = count + 1; - end - if count == 0 then - offlinemanager.store(node, host, stanza); - -- TODO deal with storage errors end else -- TODO send IQ error -- cgit v1.2.3 From 5833e92990f5035f3b4b2c8f7c3c0651b28aa23f Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Wed, 11 Feb 2009 23:26:18 +0500 Subject: Change the to attribute of messages to the recipients' bare JID when the recipient/resource is offline. --- core/stanza_router.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'core/stanza_router.lua') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index f83619c6..a8de6b4a 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -210,10 +210,10 @@ function core_route_stanza(origin, stanza) end end elseif stanza.name == "message" then -- select a resource to recieve message - if message.attr.type == 'headline' then + stanza.attr.to = to_bare; + if stanza.attr.type == 'headline' then for _, session in pairs(user.sessions) do -- find resource with greatest priority if session.presence and session.priority >= 0 then - stanza.attr.to = session.full_jid; session.send(stanza); end end @@ -259,6 +259,7 @@ function core_route_stanza(origin, stanza) -- TODO send unavailable presence or unsubscribed end elseif stanza.name == "message" then -- FIXME if full jid, then send out to resources with highest priority + stanza.attr.to = to_bare; -- TODO not in RFC, but seems obvious. Should discuss on the mailing list. if stanza.attr.type == "chat" or stanza.attr.type == "normal" or not stanza.attr.type then offlinemanager.store(node, host, stanza); -- FIXME don't store messages with only chat state notifications -- cgit v1.2.3