# HG changeset patch # User Waqas Hussain # Date 1226911907 -18000 # Node ID 99a8317d123564ba5ad87d87da5dfed42528175f # Parent 5de1048b3fbf5bea43f54cc27c80bb0e5e0825c1 Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request diff -r 5de1048b3fbf -r 99a8317d1235 core/presencemanager.lua --- a/core/presencemanager.lua Mon Nov 17 12:27:02 2008 +0500 +++ b/core/presencemanager.lua Mon Nov 17 13:51:47 2008 +0500 @@ -61,16 +61,16 @@ -- 3. send_presence_of_available_resources if rostermanager.subscribed(node, host, to_bare) then rostermanager.roster_push(node, host, to_bare); - core_route_stanza(origin, stanza); - send_presence_of_available_resources(node, host, to_bare, origin, core_route_stanza); end + core_route_stanza(origin, stanza); + send_presence_of_available_resources(node, host, to_bare, origin, core_route_stanza); elseif stanza.attr.type == "unsubscribed" then -- 1. route stanza -- 2. roster push (subscription = none or to) if rostermanager.unsubscribed(node, host, to_bare) then rostermanager.roster_push(node, host, to_bare); - core_route_stanza(origin, stanza); end + core_route_stanza(origin, stanza); end stanza.attr.from, stanza.attr.to = st_from, st_to; end @@ -91,6 +91,10 @@ elseif stanza.attr.type == "subscribe" then if rostermanager.is_contact_subscribed(node, host, from_bare) then core_route_stanza(origin, 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) + end else if not rostermanager.is_contact_pending_in(node, host, from_bare) then if rostermanager.set_contact_pending_in(node, host, from_bare) then @@ -107,7 +111,7 @@ rostermanager.roster_push(node, host, from_bare); end elseif stanza.attr.type == "unsubscribed" then - if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then + if rostermanager.process_inbound_subscription_cancellation(node, host, from_bare) then rostermanager.roster_push(node, host, from_bare); end end -- discard any other type diff -r 5de1048b3fbf -r 99a8317d1235 plugins/mod_roster.lua --- a/plugins/mod_roster.lua Mon Nov 17 12:27:02 2008 +0500 +++ b/plugins/mod_roster.lua Mon Nov 17 13:51:47 2008 +0500 @@ -4,6 +4,7 @@ local jid_split = require "util.jid".split; local t_concat = table.concat; +local handle_outbound_presence_subscriptions_and_probes = require "core.presencemanager".handle_outbound_presence_subscriptions_and_probes; local rm_remove_from_roster = require "core.rostermanager".remove_from_roster; local rm_add_to_roster = require "core.rostermanager".add_to_roster; local rm_roster_push = require "core.rostermanager".roster_push; @@ -38,15 +39,25 @@ and query.tags[1].attr.jid ~= "pending" then local item = query.tags[1]; local from_node, from_host = jid_split(stanza.attr.from); + local from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID local node, host, resource = jid_split(item.attr.jid); - if not resource then + local to_bare = node and (node.."@"..host) or host; -- bare JID + if not resource and host then if item.attr.jid ~= from_node.."@"..from_host then if item.attr.subscription == "remove" then - if session.roster[item.attr.jid] then + local r_item = session.roster[item.attr.jid]; + if r_item then local success, err_type, err_cond, err_msg = rm_remove_from_roster(session, item.attr.jid); if success then session.send(st.reply(stanza)); rm_roster_push(from_node, from_host, item.attr.jid); + if r_item.subscription == "both" or r_item.subscription == "from" then + handle_outbound_presence_subscriptions_and_probes(session, + st.presence({type="unsubscribed"}), from_bare, to_bare); + elseif r_item.subscription == "both" or r_item.subscription == "to" then + handle_outbound_presence_subscriptions_and_probes(session, + st.presence({type="unsubscribe"}), from_bare, to_bare); + end else session.send(st.error_reply(stanza, err_type, err_cond, err_msg)); end