# HG changeset patch # User Waqas Hussain # Date 1223423395 -18000 # Node ID fbb4ef1da82e1e511798c6adfd8ea8f1cb711379 # Parent a6c00467a3f8cf51948c75f8b2b81ff7db754ad3 Added: Local stanza routing diff -r a6c00467a3f8 -r fbb4ef1da82e core/stanza_router.lua --- a/core/stanza_router.lua Wed Oct 08 03:38:07 2008 +0500 +++ b/core/stanza_router.lua Wed Oct 08 04:49:55 2008 +0500 @@ -7,19 +7,24 @@ local log = require "util.logger".init("stanzarouter") +local st = require "util.stanza"; +local send = require "core.sessionmanager".send_to_session; + require "util.jid" local jid_split = jid.split; function core_process_stanza(origin, stanza) log("debug", "Received: "..tostring(stanza)) + -- TODO verify validity of stanza + local to = stanza.attr.to; + stanza.attr.from = origin.full_jid -- quick fix to prevent impersonation if not to or (hosts[to] and hosts[to].type == "local") then core_handle_stanza(origin, stanza); elseif origin.type == "c2s" then core_route_stanza(origin, stanza); end - end function core_handle_stanza(origin, stanza) @@ -36,7 +41,7 @@ -- Stanza is to this server, or a user on this server log("debug", "Routing stanza to local"); handle_stanza(session, stanza); - end + end end function core_route_stanza(origin, stanza) @@ -48,6 +53,27 @@ local host_session = hosts[host] if host_session and host_session.type == "local" then -- Local host + local user = host_session.sessions[node]; + if user then + local res = nil; + if resource then + res = user.sessions[resource]; + end + -- TODO do something about presence broadcast + if not res then + -- if we get here, resource was not specified or was unavailable + for k in pairs(user.sessions) do + res = user.sessions[k]; + break; + end + -- TODO find resource with greatest priority + end + stanza.attr.to = res.full_jid; + send(res, stanza); -- Yay \o/ + else + -- user not found + send(origin, st.error_reply(stanza, "cancel", "service-unavailable")); + end else -- Remote host if host_session then