Software /
code /
prosody
Comparison
core/s2smanager.lua @ 2426:4cef9808662a
s2smanager: Split sending of stream header into a :open_stream() method
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 09 Jan 2010 06:53:23 +0000 |
parent | 2422:affeb565b050 |
child | 2469:9e0c0b08f219 |
comparison
equal
deleted
inserted
replaced
2425:772b2caf762e | 2426:4cef9808662a |
---|---|
148 return session; | 148 return session; |
149 end | 149 end |
150 | 150 |
151 function new_outgoing(from_host, to_host, connect) | 151 function new_outgoing(from_host, to_host, connect) |
152 local host_session = { to_host = to_host, from_host = from_host, host = from_host, | 152 local host_session = { to_host = to_host, from_host = from_host, host = from_host, |
153 notopen = true, type = "s2sout_unauthed", direction = "outgoing" }; | 153 notopen = true, type = "s2sout_unauthed", direction = "outgoing", |
154 open_stream = session_open_stream }; | |
154 | 155 |
155 hosts[from_host].s2sout[to_host] = host_session; | 156 hosts[from_host].s2sout[to_host] = host_session; |
156 | 157 |
157 local log; | 158 local log; |
158 do | 159 do |
324 cl.register_outgoing(conn, host_session); | 325 cl.register_outgoing(conn, host_session); |
325 | 326 |
326 local w, log = conn.write, host_session.log; | 327 local w, log = conn.write, host_session.log; |
327 host_session.sends2s = function (t) log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^[^>]*>?")); w(conn, tostring(t)); end | 328 host_session.sends2s = function (t) log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^[^>]*>?")); w(conn, tostring(t)); end |
328 | 329 |
329 conn:write(format([[<stream:stream xmlns='jabber:server' xmlns:db='jabber:server:dialback' xmlns:stream='http://etherx.jabber.org/streams' from='%s' to='%s' version='1.0' xml:lang='en'>]], from_host, to_host)); | 330 host_session:open_stream(); |
331 | |
330 log("debug", "Connection attempt in progress..."); | 332 log("debug", "Connection attempt in progress..."); |
331 add_task(connect_timeout, function () | 333 add_task(connect_timeout, function () |
332 if host_session.conn ~= conn or | 334 if host_session.conn ~= conn or |
333 host_session.type == "s2sout" or | 335 host_session.type == "s2sout" or |
334 host_session.connecting then | 336 host_session.connecting then |
338 (host_session.log or log)("warn", "Destroying incomplete session %s->%s due to inactivity", | 340 (host_session.log or log)("warn", "Destroying incomplete session %s->%s due to inactivity", |
339 host_session.from_host or "(unknown)", host_session.to_host or "(unknown)"); | 341 host_session.from_host or "(unknown)", host_session.to_host or "(unknown)"); |
340 host_session:close("connection-timeout"); | 342 host_session:close("connection-timeout"); |
341 end); | 343 end); |
342 return true; | 344 return true; |
345 end | |
346 | |
347 function session_open_stream(session, from, to) | |
348 session.sends2s(st.stanza("stream:stream", { | |
349 xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', | |
350 ["xmlns:stream"]='http://etherx.jabber.org/streams', | |
351 from=from, to=to, version='1.0', ["xml:lang"]='en'}):top_tag()); | |
343 end | 352 end |
344 | 353 |
345 function streamopened(session, attr) | 354 function streamopened(session, attr) |
346 local send = session.sends2s; | 355 local send = session.sends2s; |
347 | 356 |