198 -- 2. roster push (subscription = none or to) |
198 -- 2. roster push (subscription = none or to) |
199 if rostermanager.unsubscribed(node, host, to_bare) then |
199 if rostermanager.unsubscribed(node, host, to_bare) then |
200 rostermanager.roster_push(node, host, to_bare); |
200 rostermanager.roster_push(node, host, to_bare); |
201 end |
201 end |
202 core_route_stanza(origin, stanza); |
202 core_route_stanza(origin, stanza); |
203 -- COMPAT: Some legacy clients keep displaying unsubscribed contacts as online unless an unavailable presence is sent: |
|
204 send_presence_of_available_resources(node, host, to_bare, origin, core_route_stanza, |
|
205 st.presence({ type="unavailable", from=from_bare, to=to_bare, id=stanza.attr.id })); |
|
206 end |
203 end |
207 stanza.attr.from, stanza.attr.to = st_from, st_to; |
204 stanza.attr.from, stanza.attr.to = st_from, st_to; |
208 end |
205 end |
209 |
206 |
210 function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza) |
207 function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza) |
221 if rostermanager.is_contact_subscribed(node, host, from_bare) then |
218 if rostermanager.is_contact_subscribed(node, host, from_bare) then |
222 if 0 == send_presence_of_available_resources(node, host, st_from, origin, core_route_stanza) then |
219 if 0 == send_presence_of_available_resources(node, host, st_from, origin, core_route_stanza) then |
223 -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) |
220 -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) |
224 end |
221 end |
225 else |
222 else |
226 core_route_stanza(origin, st.presence({from=to_bare, to=from_bare, type="unsubscribed"})); |
223 core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unsubscribed"})); |
227 end |
224 end |
228 elseif stanza.attr.type == "subscribe" then |
225 elseif stanza.attr.type == "subscribe" then |
229 if rostermanager.is_contact_subscribed(node, host, from_bare) then |
226 if rostermanager.is_contact_subscribed(node, host, from_bare) then |
230 core_route_stanza(origin, st.presence({from=to_bare, to=from_bare, type="subscribed"})); -- already subscribed |
227 core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="subscribed"})); -- already subscribed |
231 -- Sending presence is not clearly stated in the RFC, but it seems appropriate |
228 -- Sending presence is not clearly stated in the RFC, but it seems appropriate |
232 if 0 == send_presence_of_available_resources(node, host, from_bare, origin, core_route_stanza) then |
229 if 0 == send_presence_of_available_resources(node, host, from_bare, origin, core_route_stanza) then |
233 -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) |
230 -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) |
234 end |
231 end |
235 else |
232 else |
|
233 core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- acknowledging receipt |
236 if not rostermanager.is_contact_pending_in(node, host, from_bare) then |
234 if not rostermanager.is_contact_pending_in(node, host, from_bare) then |
237 if rostermanager.set_contact_pending_in(node, host, from_bare) then |
235 if rostermanager.set_contact_pending_in(node, host, from_bare) then |
238 sessionmanager.send_to_available_resources(node, host, stanza); |
236 sessionmanager.send_to_available_resources(node, host, stanza); |
239 end -- TODO else return error, unable to save |
237 end -- TODO else return error, unable to save |
240 end |
238 end |
241 end |
239 end |
242 elseif stanza.attr.type == "unsubscribe" then |
240 elseif stanza.attr.type == "unsubscribe" then |
243 if rostermanager.process_inbound_unsubscribe(node, host, from_bare) then |
241 if rostermanager.process_inbound_unsubscribe(node, host, from_bare) then |
|
242 sessionmanager.send_to_interested_resources(node, host, stanza); |
244 rostermanager.roster_push(node, host, from_bare); |
243 rostermanager.roster_push(node, host, from_bare); |
245 end |
244 end |
246 elseif stanza.attr.type == "subscribed" then |
245 elseif stanza.attr.type == "subscribed" then |
247 if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then |
246 if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then |
|
247 sessionmanager.send_to_interested_resources(node, host, stanza); |
248 rostermanager.roster_push(node, host, from_bare); |
248 rostermanager.roster_push(node, host, from_bare); |
249 end |
249 end |
250 elseif stanza.attr.type == "unsubscribed" then |
250 elseif stanza.attr.type == "unsubscribed" then |
251 if rostermanager.process_inbound_subscription_cancellation(node, host, from_bare) then |
251 if rostermanager.process_inbound_subscription_cancellation(node, host, from_bare) then |
|
252 sessionmanager.send_to_interested_resources(node, host, stanza); |
252 rostermanager.roster_push(node, host, from_bare); |
253 rostermanager.roster_push(node, host, from_bare); |
253 end |
254 end |
254 end -- discard any other type |
255 end -- discard any other type |
255 stanza.attr.from, stanza.attr.to = st_from, st_to; |
256 stanza.attr.from, stanza.attr.to = st_from, st_to; |
256 end |
257 end |