Software /
code /
prosody
Diff
core/stanza_router.lua @ 191:e64c8a44060f
Fix s2s once and for all
- Moved dialback to the new mod_dialback (mostly).
- Modules can now supply a list of origins to handle to add_handler
- Modules can now handle and process any stanza, overriding the core
- Modules handle non-jabber:client/jabber:server xmlns'd stanzas
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 01 Nov 2008 21:07:14 +0000 |
parent | 190:1e993b7deae7 |
child | 192:71c389c6fc2e |
line wrap: on
line diff
--- a/core/stanza_router.lua Sat Nov 01 18:28:46 2008 +0000 +++ b/core/stanza_router.lua Sat Nov 01 21:07:14 2008 +0000 @@ -16,6 +16,9 @@ local s2s_verify_dialback = require "core.s2smanager".verify_dialback; local s2s_make_authenticated = require "core.s2smanager".make_authenticated; + +local modules_handle_stanza = require "core.modulemanager".handle_stanza; + local format = string.format; local tostring = tostring; @@ -57,6 +60,8 @@ core_handle_stanza(origin, stanza); elseif stanza.name == "iq" and not select(3, jid_split(to)) then core_handle_stanza(origin, stanza); + elseif 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); end @@ -66,6 +71,7 @@ -- that is, they are handled by this server function core_handle_stanza(origin, stanza) -- Handlers + if modules_handle_stanza(origin, stanza) then return; end if origin.type == "c2s" or origin.type == "c2s_unauthed" then local session = origin; @@ -108,62 +114,6 @@ else -- TODO error, bad type end - else - log("debug", "Routing stanza to local"); - handle_stanza(session, stanza); - end - elseif origin.type == "s2sin_unauthed" or origin.type == "s2sin" then - if stanza.attr.xmlns == "jabber:server:dialback" then - if stanza.name == "verify" then - -- We are being asked to verify the key, to ensure it was generated by us - log("debug", "verifying dialback key..."); - local attr = stanza.attr; - print(tostring(attr.to), tostring(attr.from)) - print(tostring(origin.to_host), tostring(origin.from_host)) - -- FIXME: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34 - --if attr.from ~= origin.to_host then error("invalid-from"); end - local type; - if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then - type = "valid" - else - type = "invalid" - log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); - end - origin.sends2s(format("<db:verify from='%s' to='%s' id='%s' type='%s'>%s</db:verify>", attr.to, attr.from, attr.id, type, stanza[1])); - elseif stanza.name == "result" and origin.type == "s2sin_unauthed" then - -- he wants to be identified through dialback - -- We need to check the key with the Authoritative server - local attr = stanza.attr; - origin.from_host = attr.from; - origin.to_host = attr.to; - origin.dialback_key = stanza[1]; - log("debug", "asking %s if key %s belongs to them", origin.from_host, origin.dialback_key); - send_s2s(origin.to_host, origin.from_host, format("<db:verify from='%s' to='%s' id='%s'>%s</db:verify>", origin.to_host, origin.from_host, origin.streamid, origin.dialback_key)); - hosts[origin.from_host].dialback_verifying = origin; - end - end - elseif origin.type == "s2sout_unauthed" or origin.type == "s2sout" then - if stanza.attr.xmlns == "jabber:server:dialback" then - if stanza.name == "result" then - if stanza.attr.type == "valid" then - s2s_make_authenticated(origin); - else - -- FIXME - error("dialback failed!"); - end - elseif stanza.name == "verify" and origin.dialback_verifying then - local valid; - local attr = stanza.attr; - if attr.type == "valid" then - s2s_make_authenticated(origin.dialback_verifying); - valid = "valid"; - else - -- Warn the original connection that is was not verified successfully - log("warn", "dialback for "..(origin.dialback_verifying.from_host or "(unknown)").." failed"); - valid = "invalid"; - end - origin.dialback_verifying.sends2s(format("<db:result from='%s' to='%s' id='%s' type='%s'>%s</db:result>", attr.from, attr.to, attr.id, valid, origin.dialback_verifying.dialback_key)); - end end else log("warn", "Unhandled origin: %s", origin.type);