From 5520516fceee3d96906db5b36168c9cf95e44ff6 Mon Sep 17 00:00:00 2001 From: Marco Cirillo Date: Wed, 9 May 2012 02:56:22 +0000 Subject: [PATCH] mod_dialback: COMPAT reset session.send function for servers (e.g. ejabberd) which don't include a from attr when opening the stream. --- plugins/mod_dialback.lua | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/plugins/mod_dialback.lua b/plugins/mod_dialback.lua index 8f69b55a..cc076db5 100644 --- a/plugins/mod_dialback.lua +++ b/plugins/mod_dialback.lua @@ -64,29 +64,31 @@ module:hook("stanza/jabber:server:dialback:result", function(event) -- he wants to be identified through dialback -- We need to check the key with the Authoritative server local attr = stanza.attr; - local to, from = attr.to, attr.from; + origin.hosts[attr.from] = { dialback_key = stanza[1] }; - origin.hosts[from] = { dialback_key = stanza[1] }; - - if not hosts[to] then + if not hosts[attr.to] then -- Not a host that we serve - origin.log("info", "%s tried to connect to %s, which we don't serve", from, to); + origin.log("info", "%s tried to connect to %s, which we don't serve", attr.from, attr.to); origin:close("host-unknown"); return true; end - dialback_requests[from.."/"..origin.streamid] = origin; + dialback_requests[attr.from.."/"..origin.streamid] = origin; - -- 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 = attr.from; + -- COMPAT: Fix ejabberd chopness by resetting the send function + origin.log("debug", "Remote server didn't specify a from attr, resetting session.send now that we know where to knock to."); + 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 + if not origin.to_host then + -- Just used for friendlier logging + origin.to_host = attr.to; + end - 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]); - }); + 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])); return true; end end); -- 2.30.2