- end -- TODO handle other stanzas
- else
- log("warn", "Unhandled origin: %s", origin.type); -- FIXME reply with error
- end
-end
-
-function send_presence_of_available_resources(user, host, jid, recipient_session)
- local h = hosts[host];
- local count = 0;
- if h and h.type == "local" then
- local u = h.sessions[user];
- if u then
- for k, session in pairs(u.sessions) do
- local pres = session.presence;
- if pres then
- pres.attr.to = jid;
- pres.attr.from = session.full_jid;
- recipient_session.send(pres);
- pres.attr.to = nil;
- pres.attr.from = nil;
- count = count + 1;
- end
- end
- end
- end
- return count;
-end
-
-function handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare)
- local node, host = jid_split(from_bare);
- local st_from, st_to = stanza.attr.from, stanza.attr.to;
- stanza.attr.from, stanza.attr.to = from_bare, to_bare;
- if stanza.attr.type == "subscribe" then
- log("debug", "outbound subscribe from "..from_bare.." for "..to_bare);
- -- 1. route stanza
- -- 2. roster push (subscription = none, ask = subscribe)
- if rostermanager.set_contact_pending_out(node, host, to_bare) then
- rostermanager.roster_push(node, host, to_bare);
- end -- else file error
- core_route_stanza(origin, stanza);
- elseif stanza.attr.type == "unsubscribe" then
- log("debug", "outbound unsubscribe from "..from_bare.." for "..to_bare);
- -- 1. route stanza
- -- 2. roster push (subscription = none or from)
- if rostermanager.unsubscribe(node, host, to_bare) then
- rostermanager.roster_push(node, host, to_bare); -- FIXME do roster push when roster has in fact not changed?
- end -- else file error
- core_route_stanza(origin, stanza);
- elseif stanza.attr.type == "subscribed" then
- log("debug", "outbound subscribed from "..from_bare.." for "..to_bare);
- -- 1. route stanza
- -- 2. roster_push ()
- -- 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);
- end
- elseif stanza.attr.type == "unsubscribed" then
- log("debug", "outbound unsubscribed from "..from_bare.." for "..to_bare);
- -- 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);