From d915fa0a609b1f482531c3ac0149f26fd772bf9b Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 24 Oct 2008 00:26:01 +0500 Subject: Presence fixes (again) - Presence to other resources sent correctly - Resource of the recipient ignored for all presence except available and unavailable - Set things up for presence subscriptions --- core/stanza_router.lua | 60 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'core') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 2203f351..ca147a92 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -64,13 +64,20 @@ function core_handle_stanza(origin, stanza) core_route_stanza(origin, stanza); end end - --[[local node, host = jid_split(stanza.attr.from); - for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources - if res.full_jid then - res = user.sessions[k]; - break; + local node, host = jid_split(stanza.attr.from); + for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources and from resources + if res ~= origin then + if res.full_jid then -- to resource. FIXME is this check correct? Maybe it should be res.presence + stanza.attr.to = res.full_jid; + core_route_stanza(origin, stanza); + end + if res.presence then -- from all resources for which we have presence + res.presence.attr.to = origin.full_jid; + core_route_stanza(res, res.presence); + res.presence.attr.to = nil; + end end - end]] + end if not origin.presence then -- presence probes on initial presence local probe = st.presence({from = origin.full_jid, type = "probe"}); for jid in pairs(origin.roster) do @@ -80,6 +87,7 @@ function core_handle_stanza(origin, stanza) core_route_stanza(origin, probe); end end + -- TODO resend subscription requests end origin.presence = stanza; stanza.attr.to = nil; -- reset it @@ -107,7 +115,7 @@ function core_route_stanza(origin, stanza) local to = stanza.attr.to; local node, host, resource = jid_split(to); - if stanza.name == "presence" and stanza.attr.type == "probe" then resource = nil; end + if stanza.name == "presence" and (stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable") then resource = nil; end local host_session = hosts[host] if host_session and host_session.type == "local" then @@ -118,22 +126,32 @@ function core_route_stanza(origin, stanza) if not res then -- if we get here, resource was not specified or was unavailable if stanza.name == "presence" then - if stanza.attr.type == "probe" then - if is_authorized_to_see_presence(origin, node, host) then - for k in pairs(user.sessions) do -- return presence for all resources - if user.sessions[k].presence then - local pres = user.sessions[k].presence; - pres.attr.to = origin.full_jid; - pres.attr.from = user.sessions[k].full_jid; - send(origin, pres); - pres.attr.to = nil; - pres.attr.from = nil; + if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then + if stanza.attr.type == "probe" then + if is_authorized_to_see_presence(origin, node, host) then + for k in pairs(user.sessions) do -- return presence for all resources + if user.sessions[k].presence then + local pres = user.sessions[k].presence; + pres.attr.to = origin.full_jid; + pres.attr.from = user.sessions[k].full_jid; + send(origin, pres); + pres.attr.to = nil; + pres.attr.from = nil; + end end + else + send(origin, st.presence({from=user.."@"..host, to=origin.username.."@"..origin.host, type="unsubscribed"})); end - else - send(origin, st.presence({from = user.."@"..host, to = origin.username.."@"..origin.host, type = "unsubscribed"})); - end - else + elseif stanza.attr.type == "subscribe" then + -- TODO + elseif stanza.attr.type == "unsubscribe" then + -- TODO + elseif stanza.attr.type == "subscribed" then + -- TODO + elseif stanza.attr.type == "unsubscribed" then + -- TODO + end -- discard any other type + else -- sender is available or unavailable for k in pairs(user.sessions) do -- presence broadcast to all user resources if user.sessions[k].full_jid then stanza.attr.to = user.sessions[k].full_jid; -- cgit v1.2.3 From e644856b72667b12ed9b71fbca0ac7e49d8ffb41 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 24 Oct 2008 01:06:54 +0500 Subject: Moved some code and removed unnecessary checks. --- core/stanza_router.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'core') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index ca147a92..52ab20e8 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -56,7 +56,7 @@ function core_handle_stanza(origin, stanza) local session = origin; if stanza.name == "presence" and origin.roster then - if stanza.attr.type == nil or stanza.attr.type == "available" or stanza.attr.type == "unavailable" then + if stanza.attr.type == nil or stanza.attr.type == "unavailable" then for jid in pairs(origin.roster) do -- broadcast to all interested contacts local subscription = origin.roster[jid].subscription; if subscription == "both" or subscription == "from" then @@ -65,28 +65,28 @@ function core_handle_stanza(origin, stanza) end end local node, host = jid_split(stanza.attr.from); - for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources and from resources - if res ~= origin then - if res.full_jid then -- to resource. FIXME is this check correct? Maybe it should be res.presence - stanza.attr.to = res.full_jid; - core_route_stanza(origin, stanza); - end - if res.presence then -- from all resources for which we have presence - res.presence.attr.to = origin.full_jid; - core_route_stanza(res, res.presence); - res.presence.attr.to = nil; - end + for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources + if res ~= origin and res.full_jid then -- to resource. FIXME is res.full_jid the correct check? Maybe it should be res.presence + stanza.attr.to = res.full_jid; + core_route_stanza(origin, stanza); end end if not origin.presence then -- presence probes on initial presence local probe = st.presence({from = origin.full_jid, type = "probe"}); - for jid in pairs(origin.roster) do + for jid in pairs(origin.roster) do -- probe all contacts we are subscribed to local subscription = origin.roster[jid].subscription; if subscription == "both" or subscription == "to" then probe.attr.to = jid; core_route_stanza(origin, probe); end end + for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast from all resources + if res ~= origin and stanza.attr.type ~= "unavailable" and res.presence then -- FIXME does unavailable qualify as initial presence? + res.presence.attr.to = origin.full_jid; + core_route_stanza(res, res.presence); + res.presence.attr.to = nil; + end + end -- TODO resend subscription requests end origin.presence = stanza; -- cgit v1.2.3