Software /
code /
prosody
Changeset
209:e9de0803676d
Part one of internal component support
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 04 Nov 2008 18:15:56 +0000 |
parents | 208:23245a92b275 |
children | 210:e679487e2fa4 |
files | core/stanza_router.lua util/stanza.lua |
diffstat | 2 files changed, 35 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/core/stanza_router.lua Tue Nov 04 01:26:56 2008 +0000 +++ b/core/stanza_router.lua Tue Nov 04 18:15:56 2008 +0000 @@ -18,6 +18,7 @@ local s2s_make_authenticated = require "core.s2smanager".make_authenticated; local modules_handle_stanza = require "core.modulemanager".handle_stanza; +local component_handle_stanza = require "core.componentmanager".handle_stanza; local format = string.format; local tostring = tostring; @@ -31,6 +32,7 @@ function core_process_stanza(origin, stanza) log("debug", "Received["..origin.type.."]: "..tostring(stanza)) + -- TODO verify validity of stanza (as well as JID validity) if stanza.name == "iq" and not(#stanza.tags == 1 and stanza.tags[1].attr.xmlns) then if stanza.attr.type == "set" or stanza.attr.type == "get" then @@ -46,28 +48,49 @@ error("Client MUST bind resource after auth"); end - local to = stanza.attr.to; -- TODO also, stazas should be returned to their original state before the function ends if origin.type == "c2s" then - stanza.attr.from = origin.full_jid; -- quick fix to prevent impersonation (FIXME this would be incorrect when the origin is not c2s) + stanza.attr.from = origin.full_jid; end + local to = stanza.attr.to; + local node, host, resource = jid_split(to); + local to_bare = node and (node.."@"..host) or host; -- bare JID + local from = stanza.attr.from; + local from_node, from_host, from_resource = jid_split(from); + local from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID + if origin.type == "s2sin" then + if origin.from_host ~= from_host then -- remote server trying to impersonate some other server? + log("warn", "Received a stanza claiming to be from %s, over a conn authed for %s!", from, origin.from_host); + return; -- FIXME what should we do here? does this work with subdomains? + end + end + --[[if to and not(hosts[to]) and not(hosts[to_bare]) and (hosts[host] and hosts[host].type ~= "local") then -- not for us? + log("warn", "stanza recieved for a non-local server"); + return; -- FIXME what should we do here? + end]] -- FIXME + + -- FIXME do stanzas not of jabber:client get handled by components? if not to then core_handle_stanza(origin, stanza); + elseif hosts[to] and hosts[to].type == "local" then -- directed at a local server + core_handle_stanza(origin, stanza); + elseif hosts[to_bare] and hosts[to_bare].type == "component" then -- hack to allow components to handle node@server + component_handle_stanza(origin, stanza); + elseif hosts[to] and hosts[to].type == "component" then -- hack to allow components to handle node@server/resource and server/resource + component_handle_stanza(origin, stanza); + elseif hosts[host].type == "component" then -- directed at a component + component_handle_stanza(origin, stanza); elseif origin.type == "c2s" and stanza.name == "presence" and stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then - local node, host = jid_split(stanza.attr.to); - local to_bare = node and (node.."@"..host) or host; -- bare JID - local from_node, from_host = jid_split(stanza.attr.from); - local from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare); - elseif hosts[to] and hosts[to].type == "local" then - core_handle_stanza(origin, stanza); - elseif stanza.name == "iq" and not select(3, jid_split(to)) then + elseif stanza.name == "iq" and not resource then -- directed at bare JID core_handle_stanza(origin, stanza); elseif stanza.attr.xmlns and stanza.attr.xmlns ~= "jabber:client" and stanza.attr.xmlns ~= "jabber:server" then modules_handle_stanza(origin, stanza); elseif origin.type == "c2s" or origin.type == "s2sin" then core_route_stanza(origin, stanza); + else + log("warn", "stanza not processed"); end end @@ -144,9 +167,9 @@ else -- TODO error, bad type end - end + end -- TODO handle other stanzas else - log("warn", "Unhandled origin: %s", origin.type); + log("warn", "Unhandled origin: %s", origin.type); -- FIXME reply with error end end
--- a/util/stanza.lua Tue Nov 04 01:26:56 2008 +0000 +++ b/util/stanza.lua Tue Nov 04 18:15:56 2008 +0000 @@ -167,7 +167,7 @@ end function reply(orig) - return stanza(orig.name, orig.attr and { to = orig.attr.from, from = orig.attr.to, id = orig.attr.id, type = ((orig.name == "iq" and "result") or nil) }); + return stanza(orig.name, orig.attr and { to = orig.attr.from, from = orig.attr.to, id = orig.attr.id, type = ((orig.name == "iq" and "result") or orig.attr.type) }); end function error_reply(orig, type, condition, message, clone)