# HG changeset patch # User Waqas Hussain # Date 1242428285 -18000 # Node ID 490ff24d0ac57e1fef4305e35c02aa8d33ceedb4 # Parent be11dc0610d51beb4c28110b79428a7da8b8fe7a stanza_router: Added global function core_post_stanza diff -r be11dc0610d5 -r 490ff24d0ac5 core/stanza_router.lua --- a/core/stanza_router.lua Sat May 16 03:56:51 2009 +0500 +++ b/core/stanza_router.lua Sat May 16 03:58:05 2009 +0500 @@ -109,27 +109,35 @@ return; -- FIXME what should we do here? does this work with subdomains? end end - local event_data = {origin=origin, stanza=stanza}; - if fire_event(tostring(host or origin.host).."/"..stanza.name, event_data) then - -- event handled - elseif not to then - modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza); - elseif hosts[to] and hosts[to].type == "local" then -- directed at a local server - modules_handle_stanza(host or origin.host or origin.to_host, 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[host] and hosts[host].type == "component" then -- directed at a component - component_handle_stanza(origin, stanza); - elseif hosts[host] and hosts[host].type == "local" and stanza.name == "iq" and not resource then -- directed at bare JID - modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza); - else - core_route_stanza(origin, stanza); - end + core_post_stanza(origin, stanza); else modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza); end end +function core_post_stanza(origin, stanza) + local to = stanza.attr.to; + local node, host, resource = jid_split(to); + local to_bare = node and (node.."@"..host) or host; -- bare JID + + local event_data = {origin=origin, stanza=stanza}; + if fire_event(tostring(host or origin.host).."/"..stanza.name, event_data) then + -- event handled + elseif not to then + modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza); + elseif hosts[to] and hosts[to].type == "local" then -- directed at a local server + modules_handle_stanza(host or origin.host or origin.to_host, 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[host] and hosts[host].type == "component" then -- directed at a component + component_handle_stanza(origin, stanza); + elseif hosts[host] and hosts[host].type == "local" and stanza.name == "iq" and not resource then -- directed at bare JID + modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza); + else + core_route_stanza(origin, stanza); + end +end + function core_route_stanza(origin, stanza) -- Hooks --- ...later