From 649aefc28e661f4c89f49e6600646de4a673b99c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 18 Jan 2010 17:14:41 +0000 Subject: mod_presence: Automatically deny presence requests for hosts, fixes traceback in #153 --- plugins/mod_presence.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'plugins/mod_presence.lua') diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index abbc3a3d..815b5c8b 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -309,6 +309,13 @@ module:hook("presence/bare", function(data) end return true; end); +module:hook("presence/host", function (data) + local stanza = data.stanza; + local reply = st.reply(stanza); + reply.attr.type = "unsubscribed"; + handle_inbound_presence_subscriptions_and_probes(data.origin, reply, jid_bare(stanza.attr.to), jid_bare(stanza.attr.from), core_route_stanza); + return true; +end); module:hook("presence/full", function(data) -- inbound presence to full JID recieved local origin, stanza = data.origin, data.stanza; -- cgit v1.2.3 From d77c415e7641d865bcea11d87b68d1c75cbc81f3 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 29 Jan 2010 18:16:39 +0500 Subject: mod_presence: Respond with an unavailable presence when subscribers probe and no resources are available. --- plugins/mod_presence.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/mod_presence.lua') diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 815b5c8b..31d2d7b4 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -217,7 +217,7 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b if stanza.attr.type == "probe" then if rostermanager.is_contact_subscribed(node, host, from_bare) then if 0 == send_presence_of_available_resources(node, host, st_from, origin, core_route_stanza) then - -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) + core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- TODO send last activity end else core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unsubscribed"})); @@ -227,7 +227,7 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="subscribed"})); -- already subscribed -- Sending presence is not clearly stated in the RFC, but it seems appropriate if 0 == send_presence_of_available_resources(node, host, from_bare, origin, core_route_stanza) then - -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) + core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- TODO send last activity end else core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- acknowledging receipt -- cgit v1.2.3 From 0e7b83863adad24bdc4ba627f034d2f6d329cf33 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 29 Jan 2010 21:06:51 +0500 Subject: mod_presence: Added handler for presence subscriptions and probes to local hosts. --- plugins/mod_presence.lua | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'plugins/mod_presence.lua') diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 31d2d7b4..ec983fc2 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -309,13 +309,6 @@ module:hook("presence/bare", function(data) end return true; end); -module:hook("presence/host", function (data) - local stanza = data.stanza; - local reply = st.reply(stanza); - reply.attr.type = "unsubscribed"; - handle_inbound_presence_subscriptions_and_probes(data.origin, reply, jid_bare(stanza.attr.to), jid_bare(stanza.attr.from), core_route_stanza); - return true; -end); module:hook("presence/full", function(data) -- inbound presence to full JID recieved local origin, stanza = data.origin, data.stanza; @@ -333,6 +326,20 @@ module:hook("presence/full", function(data) end -- resource not online, discard return true; end); +module:hook("presence/host", function(data) + -- inbound presence to the host + local origin, stanza = data.origin, data.stanza; + + local from_bare = jid_bare(stanza.attr.from); + local t = stanza.attr.type; + if t == "probe" then + core_route_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id })); + elseif t == "subscribe" then + core_route_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id, type = "subscribed" })); + core_route_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id })); + end + return true; +end); module:hook("resource-unbind", function(event) local session, err = event.session, event.error; -- cgit v1.2.3 From 0ff3e76b777a8feda3d1c1faa839daa7a397e96e Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 29 Jan 2010 21:08:18 +0500 Subject: mod_presence: Quick fix to make probes from local users to local hosts work. --- plugins/mod_presence.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/mod_presence.lua') diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index ec983fc2..c28dd338 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -76,6 +76,7 @@ function handle_normal_presence(origin, stanza, core_route_stanza) end end if stanza.attr.type == nil and not origin.presence then -- initial presence + origin.presence = stanza; -- FIXME repeated later local probe = st.presence({from = origin.full_jid, type = "probe"}); for jid, item in pairs(roster) do -- probe all contacts we are subscribed to if item.subscription == "both" or item.subscription == "to" then -- cgit v1.2.3 From 1349805068792385931dceb72f6b6865c8fa88ac Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 12 Feb 2010 00:54:14 +0500 Subject: mod_presence: Don't depend on sessions array existing for a user when handling outgoing presence broadcast. --- plugins/mod_presence.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'plugins/mod_presence.lua') diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index c28dd338..4aa8f497 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -18,6 +18,7 @@ local st = require "util.stanza"; local jid_split = require "util.jid".split; local jid_bare = require "util.jid".bare; local hosts = hosts; +local NULL = {}; local rostermanager = require "core.rostermanager"; local sessionmanager = require "core.sessionmanager"; @@ -63,7 +64,8 @@ end function handle_normal_presence(origin, stanza, core_route_stanza) local roster = origin.roster; local node, host = origin.username, origin.host; - for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources + local user = bare_sessions[node.."@"..host]; + for _, res in pairs(user and user.sessions or NULL) do -- broadcast to all resources if res ~= origin and res.presence then -- to resource stanza.attr.to = res.full_jid; core_route_stanza(origin, stanza); @@ -84,7 +86,7 @@ function handle_normal_presence(origin, stanza, core_route_stanza) core_route_stanza(origin, probe); end end - for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast from all available resources + for _, res in pairs(user and user.sessions or NULL) do -- broadcast from all available resources if res ~= origin and res.presence then res.presence.attr.to = origin.full_jid; core_route_stanza(res, res.presence); -- cgit v1.2.3 From 60c40e44de335c4d7f6ed8b6ed25e8307bc4bcd9 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 12 Feb 2010 00:55:06 +0500 Subject: mod_presence: Don't depend on user being online when calculating top resources. --- plugins/mod_presence.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'plugins/mod_presence.lua') diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 4aa8f497..f6ea9e6b 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -55,10 +55,11 @@ local function select_top_resources(user) end return recipients; end -local function recalc_resource_map(origin) - local user = hosts[origin.host].sessions[origin.username]; - user.top_resources = select_top_resources(user); - if #user.top_resources == 0 then user.top_resources = nil; end +local function recalc_resource_map(user) + if user then + user.top_resources = select_top_resources(user); + if #user.top_resources == 0 then user.top_resources = nil; end + end end function handle_normal_presence(origin, stanza, core_route_stanza) @@ -117,7 +118,7 @@ function handle_normal_presence(origin, stanza, core_route_stanza) origin.presence = nil; if origin.priority then origin.priority = nil; - recalc_resource_map(origin); + recalc_resource_map(user); end if origin.directed then for jid in pairs(origin.directed) do @@ -139,7 +140,7 @@ function handle_normal_presence(origin, stanza, core_route_stanza) else priority = 0; end if origin.priority ~= priority then origin.priority = priority; - recalc_resource_map(origin); + recalc_resource_map(user); end end stanza.attr.to = nil; -- reset it -- cgit v1.2.3 From 15b32576a96cdc8b594e8c4f5b11680c3c697ea2 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 15 Feb 2010 04:15:37 +0500 Subject: mod_presence: Reflect the user's own presence back to them. --- plugins/mod_presence.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'plugins/mod_presence.lua') diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index f6ea9e6b..a39d9c19 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -63,6 +63,9 @@ local function recalc_resource_map(user) end function handle_normal_presence(origin, stanza, core_route_stanza) + if full_sessions[origin.full_jid] then -- if user is still connected + origin.send(stanza); -- reflect their presence back to them + end local roster = origin.roster; local node, host = origin.username, origin.host; local user = bare_sessions[node.."@"..host]; -- cgit v1.2.3