core/stanza_router.lua

changeset 171
28f420d057a0
parent 170
e7bff9cfbb65
child 172
71247788c7c7
equal deleted inserted replaced
170:e7bff9cfbb65 171:28f420d057a0
9 9
10 local st = require "util.stanza"; 10 local st = require "util.stanza";
11 local send = require "core.sessionmanager".send_to_session; 11 local send = require "core.sessionmanager".send_to_session;
12 local send_s2s = require "core.s2smanager".send_to_host; 12 local send_s2s = require "core.s2smanager".send_to_host;
13 local user_exists = require "core.usermanager".user_exists; 13 local user_exists = require "core.usermanager".user_exists;
14
15 local rostermanager = require "core.rostermanager";
14 16
15 local s2s_verify_dialback = require "core.s2smanager".verify_dialback; 17 local s2s_verify_dialback = require "core.s2smanager".verify_dialback;
16 local s2s_make_authenticated = require "core.s2smanager".make_authenticated; 18 local s2s_make_authenticated = require "core.s2smanager".make_authenticated;
17 local format = string.format; 19 local format = string.format;
18 local tostring = tostring; 20 local tostring = tostring;
192 if stanza.attr.type == "probe" then 194 if stanza.attr.type == "probe" then
193 if is_authorized_to_see_presence(origin, node, host) then 195 if is_authorized_to_see_presence(origin, node, host) then
194 for k in pairs(user.sessions) do -- return presence for all resources 196 for k in pairs(user.sessions) do -- return presence for all resources
195 local pres = user.sessions[k].presence; 197 local pres = user.sessions[k].presence;
196 if pres then 198 if pres then
197 pres.attr.to = from; -- FIXME use from_bare? 199 pres.attr.to = from; -- FIXME use from_bare or from?
198 pres.attr.from = user.sessions[k].full_jid; 200 pres.attr.from = user.sessions[k].full_jid;
199 send(origin, pres); 201 send(origin, pres);
200 pres.attr.to = nil;
201 pres.attr.from = nil;
202 end 202 end
203 end 203 end
204 pres.attr.to = nil;
205 pres.attr.from = nil;
204 else 206 else
205 send(origin, st.presence({from=to_bare, to=origin.username.."@"..origin.host, type="unsubscribed"})); 207 send(origin, st.presence({from=to_bare, to=from_bare, type="unsubscribed"}));
206 end 208 end
207 elseif stanza.attr.type == "subscribe" then 209 elseif stanza.attr.type == "subscribe" then
208 -- TODO 210 -- TODO
209 elseif stanza.attr.type == "unsubscribe" then 211 elseif stanza.attr.type == "unsubscribe" then
210 -- TODO 212 -- TODO
211 elseif stanza.attr.type == "subscribed" then 213 elseif stanza.attr.type == "subscribed" then
212 -- TODO 214 -- TODO
213 -- sender.roster[recipient.bare_jid]. subscription = from or both 215 if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then
214 -- sender.rosterpush recipient 216 rostermanager.roster_push(node, host, from_bare);
215 -- send presence for all sender resources to recipient.bare_jid 217 for k in pairs(user.sessions) do -- return presence for all resources
218 local pres = user.sessions[k].presence;
219 if pres then
220 pres.attr.to = from; -- FIXME use from_bare or from?
221 pres.attr.from = user.sessions[k].full_jid;
222 send(origin, pres);
223 end
224 end
225 pres.attr.to = nil;
226 pres.attr.from = nil;
227 end
216 elseif stanza.attr.type == "unsubscribed" then 228 elseif stanza.attr.type == "unsubscribed" then
217 -- TODO 229 -- TODO
218 end -- discard any other type 230 end -- discard any other type
219 else -- sender is available or unavailable 231 else -- sender is available or unavailable
220 for k in pairs(user.sessions) do -- presence broadcast to all user resources 232 for k in pairs(user.sessions) do -- presence broadcast to all user resources

mercurial