Comparison

core/presencemanager.lua @ 326:99a8317d1235

Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
author Waqas Hussain <waqas20@gmail.com>
date Mon, 17 Nov 2008 13:51:47 +0500
parent 325:5de1048b3fbf
child 468:ab49cb6d0e92
comparison
equal deleted inserted replaced
325:5de1048b3fbf 326:99a8317d1235
59 -- 1. route stanza 59 -- 1. route stanza
60 -- 2. roster_push () 60 -- 2. roster_push ()
61 -- 3. send_presence_of_available_resources 61 -- 3. send_presence_of_available_resources
62 if rostermanager.subscribed(node, host, to_bare) then 62 if rostermanager.subscribed(node, host, to_bare) then
63 rostermanager.roster_push(node, host, to_bare); 63 rostermanager.roster_push(node, host, to_bare);
64 core_route_stanza(origin, stanza);
65 send_presence_of_available_resources(node, host, to_bare, origin, core_route_stanza);
66 end 64 end
65 core_route_stanza(origin, stanza);
66 send_presence_of_available_resources(node, host, to_bare, origin, core_route_stanza);
67 elseif stanza.attr.type == "unsubscribed" then 67 elseif stanza.attr.type == "unsubscribed" then
68 -- 1. route stanza 68 -- 1. route stanza
69 -- 2. roster push (subscription = none or to) 69 -- 2. roster push (subscription = none or to)
70 if rostermanager.unsubscribed(node, host, to_bare) then 70 if rostermanager.unsubscribed(node, host, to_bare) then
71 rostermanager.roster_push(node, host, to_bare); 71 rostermanager.roster_push(node, host, to_bare);
72 core_route_stanza(origin, stanza);
73 end 72 end
73 core_route_stanza(origin, stanza);
74 end 74 end
75 stanza.attr.from, stanza.attr.to = st_from, st_to; 75 stanza.attr.from, stanza.attr.to = st_from, st_to;
76 end 76 end
77 77
78 function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza) 78 function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza)
89 core_route_stanza(origin, st.presence({from=to_bare, to=from_bare, type="unsubscribed"})); 89 core_route_stanza(origin, st.presence({from=to_bare, to=from_bare, type="unsubscribed"}));
90 end 90 end
91 elseif stanza.attr.type == "subscribe" then 91 elseif stanza.attr.type == "subscribe" then
92 if rostermanager.is_contact_subscribed(node, host, from_bare) then 92 if rostermanager.is_contact_subscribed(node, host, from_bare) then
93 core_route_stanza(origin, st.presence({from=to_bare, to=from_bare, type="subscribed"})); -- already subscribed 93 core_route_stanza(origin, st.presence({from=to_bare, to=from_bare, type="subscribed"})); -- already subscribed
94 -- Sending presence is not clearly stated in the RFC, but it seems appropriate
95 if 0 == send_presence_of_available_resources(node, host, from_bare, origin, core_route_stanza) then
96 -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too)
97 end
94 else 98 else
95 if not rostermanager.is_contact_pending_in(node, host, from_bare) then 99 if not rostermanager.is_contact_pending_in(node, host, from_bare) then
96 if rostermanager.set_contact_pending_in(node, host, from_bare) then 100 if rostermanager.set_contact_pending_in(node, host, from_bare) then
97 sessionmanager.send_to_available_resources(node, host, stanza); 101 sessionmanager.send_to_available_resources(node, host, stanza);
98 end -- TODO else return error, unable to save 102 end -- TODO else return error, unable to save
105 elseif stanza.attr.type == "subscribed" then 109 elseif stanza.attr.type == "subscribed" then
106 if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then 110 if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then
107 rostermanager.roster_push(node, host, from_bare); 111 rostermanager.roster_push(node, host, from_bare);
108 end 112 end
109 elseif stanza.attr.type == "unsubscribed" then 113 elseif stanza.attr.type == "unsubscribed" then
110 if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then 114 if rostermanager.process_inbound_subscription_cancellation(node, host, from_bare) then
111 rostermanager.roster_push(node, host, from_bare); 115 rostermanager.roster_push(node, host, from_bare);
112 end 116 end
113 end -- discard any other type 117 end -- discard any other type
114 stanza.attr.from, stanza.attr.to = st_from, st_to; 118 stanza.attr.from, stanza.attr.to = st_from, st_to;
115 end 119 end