Comparison

core/stanza_router.lua @ 1406:83c6fb3d9e73

stanza_router: Removed old routing code
author Waqas Hussain <waqas20@gmail.com>
date Thu, 25 Jun 2009 07:57:57 +0500
parent 1370:3a467e6885f0
child 1407:85ec12aec35f
comparison
equal deleted inserted replaced
1405:19269d278c38 1406:83c6fb3d9e73
211 211
212 if stanza.name == "presence" and (stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error") then resource = nil; end 212 if stanza.name == "presence" and (stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error") then resource = nil; end
213 213
214 local host_session = hosts[host] 214 local host_session = hosts[host]
215 if host_session and host_session.type == "local" then 215 if host_session and host_session.type == "local" then
216 -- Local host 216 -- old stanza routing code removed
217 local user = host_session.sessions[node];
218 if user then
219 local res = user.sessions[resource];
220 if res then -- resource is online...
221 res.send(stanza); -- Yay \o/
222 else
223 -- if we get here, resource was not specified or was unavailable
224 if stanza.name == "presence" then
225 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then
226 -- inbound presence subscriptions and probes, already handled, so should never get here
227 elseif not resource then -- sender is available or unavailable or error
228 for _, session in pairs(user.sessions) do -- presence broadcast to all user resources.
229 if session.full_jid then -- FIXME should this be just for available resources? Do we need to check subscription?
230 stanza.attr.to = session.full_jid; -- reset at the end of function
231 session.send(stanza);
232 end
233 end
234 end
235 elseif stanza.name == "message" then -- select a resource to recieve message
236 stanza.attr.to = to_bare;
237 if stanza.attr.type == 'headline' then
238 for _, session in pairs(user.sessions) do -- find resource with greatest priority
239 if session.presence and session.priority >= 0 then
240 session.send(stanza);
241 end
242 end
243 elseif stanza.attr.type == 'groupchat' then
244 -- Groupchat message sent to offline resource
245 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
246 else
247 local count = 0;
248 for _, session in ipairs(select_best_resources(user)) do
249 session.send(stanza);
250 count = count + 1;
251 end
252 if count == 0 and (stanza.attr.type == "chat" or stanza.attr.type == "normal" or not stanza.attr.type) then
253 offlinemanager.store(node, host, stanza);
254 -- TODO deal with storage errors
255 end
256 end
257 elseif stanza.attr.type == "get" or stanza.attr.type == "set" then
258 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
259 end
260 end
261 else
262 -- user not online
263 if user_exists(node, host) then
264 if stanza.name == "presence" then
265 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then
266 -- inbound presence subscriptions and probes, already handled, so should never get here
267 else
268 -- TODO send unavailable presence or unsubscribed
269 end
270 elseif stanza.name == "message" then -- FIXME if full jid, then send out to resources with highest priority
271 stanza.attr.to = to_bare; -- TODO not in RFC, but seems obvious. Should discuss on the mailing list.
272 if stanza.attr.type == "chat" or stanza.attr.type == "normal" or not stanza.attr.type then
273 offlinemanager.store(node, host, stanza);
274 -- FIXME don't store messages with only chat state notifications
275 elseif stanza.attr.type == "groupchat" then
276 local reply = st.error_reply(stanza, "cancel", "service-unavailable");
277 reply.attr.from = to;
278 origin.send(reply);
279 end
280 -- TODO allow configuration of offline storage
281 -- TODO send error if not storing offline
282 elseif stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then
283 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
284 end
285 else -- user does not exist
286 -- TODO we would get here for nodeless JIDs too. Do something fun maybe? Echo service? Let plugins use xmpp:server/resource addresses?
287 if stanza.name == "presence" then
288 local t = stanza.attr.type;
289 if t == "subscribe" or t == "probe" then
290 origin.send(st.presence({from = to_bare, to = from_bare, type = "unsubscribed"}));
291 end
292 -- else ignore
293 elseif stanza.attr.type ~= "error" and (stanza.name ~= "iq" or stanza.attr.type ~= "result") then
294 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
295 end
296 end
297 end
298 elseif origin.type == "c2s" then 217 elseif origin.type == "c2s" then
299 -- Remote host 218 -- Remote host
300 local xmlns = stanza.attr.xmlns; 219 local xmlns = stanza.attr.xmlns;
301 --stanza.attr.xmlns = "jabber:server"; 220 --stanza.attr.xmlns = "jabber:server";
302 stanza.attr.xmlns = nil; 221 stanza.attr.xmlns = nil;