mod_dialback: More robust handling of multiple outstanding dialback requests for...
authorMatthew Wild <mwild1@gmail.com>
Mon, 6 Jun 2011 21:51:33 +0000 (22:51 +0100)
committerMatthew Wild <mwild1@gmail.com>
Mon, 6 Jun 2011 21:51:33 +0000 (22:51 +0100)
plugins/mod_dialback.lua

index 91291e2404ff90de8df874b99f0125aa81bb9152..5060f08fbd35dbf6ec1a0ac8a5ac8ba197ec5566 100644 (file)
@@ -60,7 +60,7 @@ module:hook("stanza/jabber:server:dialback:result", function(event)
                        return true;
                end
                
-               dialback_requests[attr.from] = origin;
+               dialback_requests[attr.from.."/"..origin.streamid] = origin;
                
                if not origin.from_host then
                        -- Just used for friendlier logging
@@ -83,8 +83,8 @@ module:hook("stanza/jabber:server:dialback:verify", function(event)
        
        if origin.type == "s2sout_unauthed" or origin.type == "s2sout" then
                local attr = stanza.attr;
-               local dialback_verifying = dialback_requests[attr.from];
-               if dialback_verifying then
+               local dialback_verifying = dialback_requests[attr.from.."/"..(attr.id or "")];
+               if dialback_verifying and attr.from == origin.to_host then
                        local valid;
                        if attr.type == "valid" then
                                s2s_make_authenticated(dialback_verifying, attr.from);
@@ -101,7 +101,7 @@ module:hook("stanza/jabber:server:dialback:verify", function(event)
                                                st.stanza("db:result", { from = attr.to, to = attr.from, id = attr.id, type = valid })
                                                                :text(dialback_verifying.hosts[attr.from].dialback_key));
                        end
-                       dialback_requests[attr.from] = nil;
+                       dialback_requests[attr.from.."/"..(attr.id or "")] = nil;
                end
                return true;
        end
@@ -131,22 +131,12 @@ module:hook("stanza/jabber:server:dialback:result", function(event)
        end
 end);
 
-module:hook_stanza("urn:ietf:params:xml:ns:xmpp-sasl", "failure", function (origin, stanza)
-       if origin.external_auth == "failed" then
-               module:log("debug", "SASL EXTERNAL failed, falling back to dialback");
-               s2s_initiate_dialback(origin);
-               return true;
-       end
-end, 100);
-
 module:hook_stanza(xmlns_stream, "features", function (origin, stanza)
-       if not origin.external_auth or origin.external_auth == "failed" then
-               s2s_initiate_dialback(origin);
-               return true;
-       end
+       s2s_initiate_dialback(origin);
+       return true;
 end, 100);
 
 -- Offer dialback to incoming hosts
 module:hook("s2s-stream-features", function (data)
-       data.features:tag("dialback", { xmlns='urn:xmpp:features:dialback' }):up();
+       data.features:tag("dialback", { xmlns='urn:xmpp:features:dialback' }):tag("optional"):up():up();
 end);