Backed out changeset 661752889535 - obsoleted by 878f75ccc4fb.
[prosody.git] / plugins / mod_dialback.lua
index 5cb59fef32cd6f0140236c9642fda0d53cbc5ce3..f3b9e3cf2dcf9e50cebfc043b1c863036e861b10 100644 (file)
@@ -15,9 +15,9 @@ local log = module._log;
 
 local st = require "util.stanza";
 local sha256_hash = require "util.hashes".sha256;
+local nameprep = require "util.encodings".stringprep.nameprep;
 
 local xmlns_stream = "http://etherx.jabber.org/streams";
-local xmlns_dialback = "jabber:server:dialback";
 
 local dialback_requests = setmetatable({}, { __mode = 'v' });
 
@@ -76,13 +76,27 @@ module:hook("stanza/jabber:server:dialback:result", function(event)
                
                dialback_requests[attr.from.."/"..origin.streamid] = origin;
                
+               local compat_check;
                if not origin.from_host then
                        -- Just used for friendlier logging
-                       origin.from_host = attr.from;
+                       origin.from_host = nameprep(attr.from);
+                       -- COMPAT: Fix server's chopness by not including from
+                       compat_check = true;
                end
                if not origin.to_host then
                        -- Just used for friendlier logging
-                       origin.to_host = attr.to;
+                       origin.to_host = nameprep(attr.to);
+                       -- COMPAT: Fix server's chopness by not including to
+                       compat_check = true;
+               end
+
+               if not origin.from_host and not origin.to_host then
+                       origin.log("debug", "Improper addressing supplied, no to or from?");
+                       origin:close("improper-addressing");
+               end
+               -- COMPAT: reset session.send
+               if compat_check then
+                       origin.send = function(stanza) hosts[attr.to].events.fire_event("route/remote", { from_host = origin.to_host, to_host = origin.from_host, stanza = stanza}); end
                end
                
                origin.log("debug", "asking %s if key %s belongs to them", attr.from, stanza[1]);
@@ -155,12 +169,14 @@ end, 100);
 
 module:hook_stanza(xmlns_stream, "features", function (origin, stanza)
        if not origin.external_auth or origin.external_auth == "failed" then
+               module:log("debug", "Initiating dialback...");
                initiate_dialback(origin);
                return true;
        end
 end, 100);
 
-module:hook("s2s-no-stream-features", function (event)
+module:hook("s2s-authenticate-legacy", function (event)
+       module:log("debug", "Initiating dialback...");
        initiate_dialback(event.origin);
        return true;
 end, 100);