Comparison

core/stanza_router.lua @ 152:6b8e2bd82ac5

Moved some code and removed unnecessary checks.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 24 Oct 2008 01:06:54 +0500
parent 151:096c7b9374fc
child 153:8310bfddaba8
comparison
equal deleted inserted replaced
151:096c7b9374fc 152:6b8e2bd82ac5
54 -- Handlers 54 -- Handlers
55 if origin.type == "c2s" or origin.type == "c2s_unauthed" then 55 if origin.type == "c2s" or origin.type == "c2s_unauthed" then
56 local session = origin; 56 local session = origin;
57 57
58 if stanza.name == "presence" and origin.roster then 58 if stanza.name == "presence" and origin.roster then
59 if stanza.attr.type == nil or stanza.attr.type == "available" or stanza.attr.type == "unavailable" then 59 if stanza.attr.type == nil or stanza.attr.type == "unavailable" then
60 for jid in pairs(origin.roster) do -- broadcast to all interested contacts 60 for jid in pairs(origin.roster) do -- broadcast to all interested contacts
61 local subscription = origin.roster[jid].subscription; 61 local subscription = origin.roster[jid].subscription;
62 if subscription == "both" or subscription == "from" then 62 if subscription == "both" or subscription == "from" then
63 stanza.attr.to = jid; 63 stanza.attr.to = jid;
64 core_route_stanza(origin, stanza); 64 core_route_stanza(origin, stanza);
65 end 65 end
66 end 66 end
67 local node, host = jid_split(stanza.attr.from); 67 local node, host = jid_split(stanza.attr.from);
68 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources and from resources 68 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources
69 if res ~= origin then 69 if res ~= origin and res.full_jid then -- to resource. FIXME is res.full_jid the correct check? Maybe it should be res.presence
70 if res.full_jid then -- to resource. FIXME is this check correct? Maybe it should be res.presence 70 stanza.attr.to = res.full_jid;
71 stanza.attr.to = res.full_jid; 71 core_route_stanza(origin, stanza);
72 core_route_stanza(origin, stanza);
73 end
74 if res.presence then -- from all resources for which we have presence
75 res.presence.attr.to = origin.full_jid;
76 core_route_stanza(res, res.presence);
77 res.presence.attr.to = nil;
78 end
79 end 72 end
80 end 73 end
81 if not origin.presence then -- presence probes on initial presence 74 if not origin.presence then -- presence probes on initial presence
82 local probe = st.presence({from = origin.full_jid, type = "probe"}); 75 local probe = st.presence({from = origin.full_jid, type = "probe"});
83 for jid in pairs(origin.roster) do 76 for jid in pairs(origin.roster) do -- probe all contacts we are subscribed to
84 local subscription = origin.roster[jid].subscription; 77 local subscription = origin.roster[jid].subscription;
85 if subscription == "both" or subscription == "to" then 78 if subscription == "both" or subscription == "to" then
86 probe.attr.to = jid; 79 probe.attr.to = jid;
87 core_route_stanza(origin, probe); 80 core_route_stanza(origin, probe);
81 end
82 end
83 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast from all resources
84 if res ~= origin and stanza.attr.type ~= "unavailable" and res.presence then -- FIXME does unavailable qualify as initial presence?
85 res.presence.attr.to = origin.full_jid;
86 core_route_stanza(res, res.presence);
87 res.presence.attr.to = nil;
88 end 88 end
89 end 89 end
90 -- TODO resend subscription requests 90 -- TODO resend subscription requests
91 end 91 end
92 origin.presence = stanza; 92 origin.presence = stanza;