diff options
Diffstat (limited to 'core/stanza_router.lua')
-rw-r--r-- | core/stanza_router.lua | 62 |
1 files changed, 6 insertions, 56 deletions
diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 3333354e..fc8cfa92 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -16,6 +16,9 @@ local sessionmanager = require "core.sessionmanager"; 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 @@ function core_process_stanza(origin, stanza) 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 @@ end -- 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 @@ function core_handle_stanza(origin, stanza) 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); |