Comparison

core/stanza_router.lua @ 966:d2692d427496

Fixed: Issue with presence error routing
author Waqas Hussain <waqas20@gmail.com>
date Tue, 07 Apr 2009 02:24:37 +0500
parent 924:db022135aed4
child 967:b021403c5d80
comparison
equal deleted inserted replaced
959:e3db909065f2 966:d2692d427496
122 component_handle_stanza(origin, stanza); 122 component_handle_stanza(origin, stanza);
123 elseif hosts[to_bare] and hosts[to_bare].type == "component" then -- hack to allow components to handle node@server 123 elseif hosts[to_bare] and hosts[to_bare].type == "component" then -- hack to allow components to handle node@server
124 component_handle_stanza(origin, stanza); 124 component_handle_stanza(origin, stanza);
125 elseif hosts[host] and hosts[host].type == "component" then -- directed at a component 125 elseif hosts[host] and hosts[host].type == "component" then -- directed at a component
126 component_handle_stanza(origin, stanza); 126 component_handle_stanza(origin, stanza);
127 elseif origin.type == "c2s" and stanza.name == "presence" and stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then 127 elseif origin.type == "c2s" and stanza.name == "presence" and stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then
128 handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza); 128 handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza);
129 elseif hosts[host] and hosts[host].type == "local" and stanza.name == "iq" and not resource then -- directed at bare JID 129 elseif hosts[host] and hosts[host].type == "local" and stanza.name == "iq" and not resource then -- directed at bare JID
130 core_handle_stanza(origin, stanza); 130 core_handle_stanza(origin, stanza);
131 else 131 else
132 core_route_stanza(origin, stanza); 132 core_route_stanza(origin, stanza);
142 -- Handlers 142 -- Handlers
143 if modules_handle_stanza(select(2, jid_split(stanza.attr.to)) or origin.host, origin, stanza) then return; end 143 if modules_handle_stanza(select(2, jid_split(stanza.attr.to)) or origin.host, origin, stanza) then return; end
144 if origin.type == "c2s" or origin.type == "s2sin" then 144 if origin.type == "c2s" or origin.type == "s2sin" then
145 if origin.type == "c2s" then 145 if origin.type == "c2s" then
146 if stanza.name == "presence" and origin.roster then 146 if stanza.name == "presence" and origin.roster then
147 if stanza.attr.type == nil or stanza.attr.type == "unavailable" then 147 if stanza.attr.type == nil or stanza.attr.type == "unavailable" and stanza.attr.type ~= "error" then
148 handle_normal_presence(origin, stanza, core_route_stanza); 148 handle_normal_presence(origin, stanza, core_route_stanza);
149 else 149 else
150 log("warn", "Unhandled c2s presence: %s", tostring(stanza)); 150 log("warn", "Unhandled c2s presence: %s", tostring(stanza));
151 checked_error_reply(origin, stanza); 151 checked_error_reply(origin, stanza);
152 end 152 end
186 return component_handle_stanza(origin, stanza); 186 return component_handle_stanza(origin, stanza);
187 elseif hosts[host] and hosts[host].type == "component" then -- directed at a component 187 elseif hosts[host] and hosts[host].type == "component" then -- directed at a component
188 return component_handle_stanza(origin, stanza); 188 return component_handle_stanza(origin, stanza);
189 end 189 end
190 190
191 if stanza.name == "presence" and (stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable") then resource = nil; end 191 if stanza.name == "presence" and (stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error") then resource = nil; end
192 192
193 local host_session = hosts[host] 193 local host_session = hosts[host]
194 if host_session and host_session.type == "local" then 194 if host_session and host_session.type == "local" then
195 -- Local host 195 -- Local host
196 local user = host_session.sessions[node]; 196 local user = host_session.sessions[node];
197 if user then 197 if user then
198 local res = user.sessions[resource]; 198 local res = user.sessions[resource];
199 if not res then 199 if not res then
200 -- if we get here, resource was not specified or was unavailable 200 -- if we get here, resource was not specified or was unavailable
201 if stanza.name == "presence" then 201 if stanza.name == "presence" then
202 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then 202 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then
203 handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza); 203 handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza);
204 else -- sender is available or unavailable 204 elseif not resource then -- sender is available or unavailable or error
205 for _, session in pairs(user.sessions) do -- presence broadcast to all user resources. 205 for _, session in pairs(user.sessions) do -- presence broadcast to all user resources.
206 if session.full_jid then -- FIXME should this be just for available resources? Do we need to check subscription? 206 if session.full_jid then -- FIXME should this be just for available resources? Do we need to check subscription?
207 stanza.attr.to = session.full_jid; -- reset at the end of function 207 stanza.attr.to = session.full_jid; -- reset at the end of function
208 session.send(stanza); 208 session.send(stanza);
209 end 209 end
254 end 254 end
255 else 255 else
256 -- user not online 256 -- user not online
257 if user_exists(node, host) then 257 if user_exists(node, host) then
258 if stanza.name == "presence" then 258 if stanza.name == "presence" then
259 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then 259 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then
260 handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza); 260 handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza);
261 else 261 else
262 -- TODO send unavailable presence or unsubscribed 262 -- TODO send unavailable presence or unsubscribed
263 end 263 end
264 elseif stanza.name == "message" then -- FIXME if full jid, then send out to resources with highest priority 264 elseif stanza.name == "message" then -- FIXME if full jid, then send out to resources with highest priority