+ dialback_requests[attr.from] = nil;
+ end
+ end);
+
+module:add_handler({ "s2sout_unauthed", "s2sout" }, "result", xmlns_dialback,
+ function (origin, stanza)
+ -- Remote server is telling us whether we passed dialback
+
+ local attr = stanza.attr;
+ if not hosts[attr.to] then
+ origin:close("host-unknown");
+ return;
+ elseif hosts[attr.to].s2sout[attr.from] ~= origin then
+ -- This isn't right
+ origin:close("invalid-id");
+ return;
+ end
+ if stanza.attr.type == "valid" then
+ s2s_make_authenticated(origin, attr.from);
+ else
+ s2s_destroy_session(origin)
+ end
+ end);
+
+module:hook_stanza(xmlns_stream, "features", function (origin, stanza)
+ 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' }):tag("optional"):up():up();
+ end);