Comparison

core/stanza_router.lua @ 176:e5cd2a03891d

Outbound presence subscription
author Waqas Hussain <waqas20@gmail.com>
date Sat, 25 Oct 2008 21:16:08 +0500
parent 175:5f71d290bb44
child 177:606c433955e7
comparison
equal deleted inserted replaced
175:5f71d290bb44 176:e5cd2a03891d
194 end 194 end
195 end 195 end
196 return count; 196 return count;
197 end 197 end
198 198
199 function handle_outbound_presence_subscriptions(origin, stanza, from_bare, to_bare)
200 local node, host = jid_split(to_bare);
201 if stanza.attr.type == "subscribe" then
202 -- 1. route stanza
203 -- 2. roster push (subscription = none, ask = subscribe)
204 if rostermanager.set_contact_pending_out(node, host, from_bare) then
205 rostermanager.roster_push(node, host, from_bare);
206 end -- else file error
207 core_route_stanza(origin, st.presence({from=from_bare, to=to_bare, type="subscribe"}));
208 elseif stanza.attr.type == "unsubscribe" then
209 -- 1. route stanza
210 -- 2. roster push (subscription = none or from)
211 if rostermanager.unsubscribe(node, host, from_bare) then
212 rostermanager.roster_push(node, host, from_bare); -- FIXME do roster push when roster has in fact not changed?
213 end -- else file error
214 core_route_stanza(origin, st.presence({from=from_bare, to=to_bare, type="unsubscribe"}));
215 elseif stanza.attr.type == "subscribed" then
216 -- 1. route stanza
217 -- 2. roster_push ()
218 -- 3. send_presence_of_available_resources
219 if rostermanager.subscribed(node, host, from_bare) then
220 rostermanager.roster_push(node, host, from_bare);
221 core_route_stanza(origin, st.presence({from=from_bare, to=to_bare, type="subscribed"}));
222 send_presence_of_available_resources(user, host, from_bare, origin);
223 end
224 elseif stanza.attr.type == "unsubscribed" then
225 -- 1. route stanza
226 -- 2. roster push (subscription = none or to)
227 if rostermanager.unsubscribed(node, host, from_bare) then
228 rostermanager.roster_push(node, host, from_bare);
229 core_route_stanza(origin, st.presence({from=from_bare, to=to_bare, type="unsubscribed"}));
230 end
231 end
232 end
233
199 function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare) 234 function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare)
200 local node, host = jid_split(to_bare); 235 local node, host = jid_split(to_bare);
201 if stanza.attr.type == "probe" then 236 if stanza.attr.type == "probe" then
202 if rostermanager.is_contact_subscribed(node, host, from_bare) then 237 if rostermanager.is_contact_subscribed(node, host, from_bare) then
203 if 0 == send_presence_of_available_resources(node, host, from_bare, origin) then 238 if 0 == send_presence_of_available_resources(node, host, from_bare, origin) then
208 end 243 end
209 elseif stanza.attr.type == "subscribe" then 244 elseif stanza.attr.type == "subscribe" then
210 if rostermanager.is_contact_subscribed(node, host, from_bare) then 245 if rostermanager.is_contact_subscribed(node, host, from_bare) then
211 send(origin, st.presence({from=to_bare, to=from_bare, type="subscribed"})); -- already subscribed 246 send(origin, st.presence({from=to_bare, to=from_bare, type="subscribed"})); -- already subscribed
212 else 247 else
213 sessionmanager.send_to_available_resources(node, host, st.presence({from=from_bare, type="subscribe"})); 248 if not rostermanager.is_contact_pending(node, host, from_bare) then
214 -- TODO store when no resources online 249 if rostermanager.set_contact_pending(node, host, from_bare) then
250 sessionmanager.send_to_available_resources(node, host, st.presence({from=from_bare, type="subscribe"}));
251 end -- TODO else return error, unable to save
252 end
215 end 253 end
216 elseif stanza.attr.type == "unsubscribe" then 254 elseif stanza.attr.type == "unsubscribe" then
217 if rostermanager.process_inbound_unsubscribe(node, host, from_bare) then 255 if rostermanager.process_inbound_unsubscribe(node, host, from_bare) then
218 rostermanager.roster_push(node, host, from_bare); 256 rostermanager.roster_push(node, host, from_bare);
219 end 257 end