Comparison

core/stanza_router.lua @ 251:5b6dec537914

Merge from waqas
author Matthew Wild <mwild1@gmail.com>
date Thu, 13 Nov 2008 16:58:29 +0000
parent 250:9f66ede8deeb
child 257:762274c98040
comparison
equal deleted inserted replaced
245:5dc6ae7b5ce8 251:5b6dec537914
11 local send_s2s = require "core.s2smanager".send_to_host; 11 local send_s2s = require "core.s2smanager".send_to_host;
12 local user_exists = require "core.usermanager".user_exists; 12 local user_exists = require "core.usermanager".user_exists;
13 13
14 local rostermanager = require "core.rostermanager"; 14 local rostermanager = require "core.rostermanager";
15 local sessionmanager = require "core.sessionmanager"; 15 local sessionmanager = require "core.sessionmanager";
16 local offlinemanager = require "core.offlinemanager";
16 17
17 local s2s_verify_dialback = require "core.s2smanager".verify_dialback; 18 local s2s_verify_dialback = require "core.s2smanager".verify_dialback;
18 local s2s_make_authenticated = require "core.s2smanager".make_authenticated; 19 local s2s_make_authenticated = require "core.s2smanager".make_authenticated;
19 20
20 local modules_handle_stanza = require "core.modulemanager".handle_stanza; 21 local modules_handle_stanza = require "core.modulemanager".handle_stanza;
147 if item.ask then 148 if item.ask then
148 request.attr.to = jid; 149 request.attr.to = jid;
149 core_route_stanza(origin, request); 150 core_route_stanza(origin, request);
150 end 151 end
151 end 152 end
153 for _, msg in ipairs(offlinemanager.load(node, host) or {}) do
154 origin.send(msg); -- FIXME do we need to modify to/from in any way?
155 end
156 offlinemanager.deleteAll(node, host);
152 end 157 end
153 origin.priority = 0; 158 origin.priority = 0;
154 if stanza.attr.type == "unavailable" then 159 if stanza.attr.type == "unavailable" then
155 origin.presence = nil; 160 origin.presence = nil;
156 else 161 else
166 end 171 end
167 end 172 end
168 end 173 end
169 stanza.attr.to = nil; -- reset it 174 stanza.attr.to = nil; -- reset it
170 else 175 else
171 -- TODO error, bad type 176 log("warn", "Unhandled c2s presence: %s", tostring(stanza));
172 end 177 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
178 end
179 else
180 log("warn", "Unhandled c2s stanza: %s", tostring(stanza));
181 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
173 end -- TODO handle other stanzas 182 end -- TODO handle other stanzas
174 else 183 else
175 log("warn", "Unhandled origin: %s", origin.type); -- FIXME reply with error 184 log("warn", "Unhandled origin: %s", origin.type);
185 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
176 end 186 end
177 end 187 end
178 188
179 function send_presence_of_available_resources(user, host, jid, recipient_session) 189 function send_presence_of_available_resources(user, host, jid, recipient_session)
180 local h = hosts[host]; 190 local h = hosts[host];
326 recipients = {session}; 336 recipients = {session};
327 elseif p == priority then 337 elseif p == priority then
328 t_insert(recipients, session); 338 t_insert(recipients, session);
329 end 339 end
330 end 340 end
341 local count = 0;
331 for _, session in pairs(recipients) do 342 for _, session in pairs(recipients) do
332 session.send(stanza); 343 session.send(stanza);
344 count = count + 1;
345 end
346 if count == 0 then
347 offlinemanager.store(node, host, stanza);
348 -- TODO deal with storage errors
333 end 349 end
334 else 350 else
335 -- TODO send IQ error 351 -- TODO send IQ error
336 end 352 end
337 else 353 else
347 handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare); 363 handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare);
348 else 364 else
349 -- TODO send unavailable presence or unsubscribed 365 -- TODO send unavailable presence or unsubscribed
350 end 366 end
351 elseif stanza.name == "message" then 367 elseif stanza.name == "message" then
352 -- TODO send message error, or store offline messages 368 if stanza.attr.type == "chat" or stanza.attr.type == "normal" or not stanza.attr.type then
369 offlinemanager.store(node, host, stanza);
370 -- FIXME don't store messages with only chat state notifications
371 end
372 -- TODO allow configuration of offline storage
373 -- TODO send error if not storing offline
353 elseif stanza.name == "iq" then 374 elseif stanza.name == "iq" then
354 -- TODO send IQ error 375 -- TODO send IQ error
355 end 376 end
356 else -- user does not exist 377 else -- user does not exist
357 -- TODO we would get here for nodeless JIDs too. Do something fun maybe? Echo service? Let plugins use xmpp:server/resource addresses? 378 -- TODO we would get here for nodeless JIDs too. Do something fun maybe? Echo service? Let plugins use xmpp:server/resource addresses?