Merge with Maranda
authorMatthew Wild <mwild1@gmail.com>
Fri, 11 May 2012 00:53:32 +0000 (01:53 +0100)
committerMatthew Wild <mwild1@gmail.com>
Fri, 11 May 2012 00:53:32 +0000 (01:53 +0100)
1  2 
plugins/mod_dialback.lua

index 4b19f2d924cd01f7082200187a5aa7919c58a098,8f69b55a90b5757ab108f4e20f49facee0494d47..c239250225c5cb5b86f59f5e4fd29464e9e30f5b
@@@ -74,35 -75,18 +76,31 @@@ module:hook("stanza/jabber:server:dialb
                        return true;
                end
                
-               dialback_requests[attr.from.."/"..origin.streamid] = origin;
+               dialback_requests[from.."/"..origin.streamid] = origin;
                
-               local compat_check;
+               -- COMPAT: ejabberd, gmail and perhaps others do not always set 'to' and 'from'
+               -- on streams. We fill in the session's to/from here instead.
 -              if not origin.from_host then origin.from_host = from; end
 -              if not origin.to_host then origin.to_host = to; end
 +              if not origin.from_host then
-                       -- Just used for friendlier logging
 +                      origin.from_host = nameprep(attr.from);
 +                      if not origin.from_host then
 +                              origin.log("debug", "We need to know where to connect but remote server blindly refuses to tell us and to comply to specs, closing connection.");
 +                              origin:close("invalid-from");
 +                      end
 +              end
 +              if not origin.to_host then
-                       -- Just used for friendlier logging
 +                      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]);
-               origin.send(st.stanza("db:verify", { from = attr.to, to = attr.from, id = origin.streamid }):text(stanza[1]));
+               origin.log("debug", "asking %s if key %s belongs to them", from, stanza[1]);
+               module:fire_event("route/remote", {
+                       from_host = to, to_host = from;
+                       stanza = st.stanza("db:verify", { from = to, to = from, id = origin.streamid }):text(stanza[1]);
+               });
                return true;
        end
  end);