Software /
code /
prosody
Comparison
core/stanza_router.lua @ 153:8310bfddaba8
Merge from waqas
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 24 Oct 2008 07:57:06 +0100 |
parent | 150:d09b8a1ab046 |
parent | 152:6b8e2bd82ac5 |
child | 158:7ea96f944681 |
comparison
equal
deleted
inserted
replaced
150:d09b8a1ab046 | 153:8310bfddaba8 |
---|---|
60 -- Handlers | 60 -- Handlers |
61 if origin.type == "c2s" or origin.type == "c2s_unauthed" then | 61 if origin.type == "c2s" or origin.type == "c2s_unauthed" then |
62 local session = origin; | 62 local session = origin; |
63 | 63 |
64 if stanza.name == "presence" and origin.roster then | 64 if stanza.name == "presence" and origin.roster then |
65 if stanza.attr.type == nil or stanza.attr.type == "available" or stanza.attr.type == "unavailable" then | 65 if stanza.attr.type == nil or stanza.attr.type == "unavailable" then |
66 for jid in pairs(origin.roster) do -- broadcast to all interested contacts | 66 for jid in pairs(origin.roster) do -- broadcast to all interested contacts |
67 local subscription = origin.roster[jid].subscription; | 67 local subscription = origin.roster[jid].subscription; |
68 if subscription == "both" or subscription == "from" then | 68 if subscription == "both" or subscription == "from" then |
69 stanza.attr.to = jid; | 69 stanza.attr.to = jid; |
70 core_route_stanza(origin, stanza); | 70 core_route_stanza(origin, stanza); |
71 end | 71 end |
72 end | 72 end |
73 --[[local node, host = jid_split(stanza.attr.from); | 73 local node, host = jid_split(stanza.attr.from); |
74 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources | 74 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources |
75 if res.full_jid then | 75 if res ~= origin and res.full_jid then -- to resource. FIXME is res.full_jid the correct check? Maybe it should be res.presence |
76 res = user.sessions[k]; | 76 stanza.attr.to = res.full_jid; |
77 break; | 77 core_route_stanza(origin, stanza); |
78 end | 78 end |
79 end]] | 79 end |
80 if not origin.presence then -- presence probes on initial presence | 80 if not origin.presence then -- presence probes on initial presence |
81 local probe = st.presence({from = origin.full_jid, type = "probe"}); | 81 local probe = st.presence({from = origin.full_jid, type = "probe"}); |
82 for jid in pairs(origin.roster) do | 82 for jid in pairs(origin.roster) do -- probe all contacts we are subscribed to |
83 local subscription = origin.roster[jid].subscription; | 83 local subscription = origin.roster[jid].subscription; |
84 if subscription == "both" or subscription == "to" then | 84 if subscription == "both" or subscription == "to" then |
85 probe.attr.to = jid; | 85 probe.attr.to = jid; |
86 core_route_stanza(origin, probe); | 86 core_route_stanza(origin, probe); |
87 end | 87 end |
88 end | 88 end |
89 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast from all resources | |
90 if res ~= origin and stanza.attr.type ~= "unavailable" and res.presence then -- FIXME does unavailable qualify as initial presence? | |
91 res.presence.attr.to = origin.full_jid; | |
92 core_route_stanza(res, res.presence); | |
93 res.presence.attr.to = nil; | |
94 end | |
95 end | |
96 -- TODO resend subscription requests | |
89 end | 97 end |
90 origin.presence = stanza; | 98 origin.presence = stanza; |
91 stanza.attr.to = nil; -- reset it | 99 stanza.attr.to = nil; -- reset it |
92 else | 100 else |
93 -- TODO error, bad type | 101 -- TODO error, bad type |
163 | 171 |
164 -- Deliver | 172 -- Deliver |
165 local to = stanza.attr.to; | 173 local to = stanza.attr.to; |
166 local node, host, resource = jid_split(to); | 174 local node, host, resource = jid_split(to); |
167 | 175 |
168 if stanza.name == "presence" and stanza.attr.type == "probe" then resource = nil; end | 176 if stanza.name == "presence" and (stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable") then resource = nil; end |
169 | 177 |
170 local host_session = hosts[host] | 178 local host_session = hosts[host] |
171 if host_session and host_session.type == "local" then | 179 if host_session and host_session.type == "local" then |
172 -- Local host | 180 -- Local host |
173 local user = host_session.sessions[node]; | 181 local user = host_session.sessions[node]; |
174 if user then | 182 if user then |
175 local res = user.sessions[resource]; | 183 local res = user.sessions[resource]; |
176 if not res then | 184 if not res then |
177 -- if we get here, resource was not specified or was unavailable | 185 -- if we get here, resource was not specified or was unavailable |
178 if stanza.name == "presence" then | 186 if stanza.name == "presence" then |
179 if stanza.attr.type == "probe" then | 187 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then |
180 if is_authorized_to_see_presence(origin, node, host) then | 188 if stanza.attr.type == "probe" then |
181 for k in pairs(user.sessions) do -- return presence for all resources | 189 if is_authorized_to_see_presence(origin, node, host) then |
182 if user.sessions[k].presence then | 190 for k in pairs(user.sessions) do -- return presence for all resources |
183 local pres = user.sessions[k].presence; | 191 if user.sessions[k].presence then |
184 pres.attr.to = origin.full_jid; | 192 local pres = user.sessions[k].presence; |
185 pres.attr.from = user.sessions[k].full_jid; | 193 pres.attr.to = origin.full_jid; |
186 send(origin, pres); | 194 pres.attr.from = user.sessions[k].full_jid; |
187 pres.attr.to = nil; | 195 send(origin, pres); |
188 pres.attr.from = nil; | 196 pres.attr.to = nil; |
197 pres.attr.from = nil; | |
198 end | |
189 end | 199 end |
200 else | |
201 send(origin, st.presence({from=user.."@"..host, to=origin.username.."@"..origin.host, type="unsubscribed"})); | |
190 end | 202 end |
191 else | 203 elseif stanza.attr.type == "subscribe" then |
192 send(origin, st.presence({from = user.."@"..host, to = origin.username.."@"..origin.host, type = "unsubscribed"})); | 204 -- TODO |
193 end | 205 elseif stanza.attr.type == "unsubscribe" then |
194 else | 206 -- TODO |
207 elseif stanza.attr.type == "subscribed" then | |
208 -- TODO | |
209 elseif stanza.attr.type == "unsubscribed" then | |
210 -- TODO | |
211 end -- discard any other type | |
212 else -- sender is available or unavailable | |
195 for k in pairs(user.sessions) do -- presence broadcast to all user resources | 213 for k in pairs(user.sessions) do -- presence broadcast to all user resources |
196 if user.sessions[k].full_jid then | 214 if user.sessions[k].full_jid then |
197 stanza.attr.to = user.sessions[k].full_jid; | 215 stanza.attr.to = user.sessions[k].full_jid; |
198 send(user.sessions[k], stanza); | 216 send(user.sessions[k], stanza); |
199 end | 217 end |