Comparison

plugins/mod_s2s/mod_s2s.lua @ 5533:df3c78221f26

mod_s2s: Ensure that to/from on stream headers are always correct, fixes #338
author Matthew Wild <mwild1@gmail.com>
date Mon, 29 Apr 2013 00:33:39 +0100
parent 5522:3912c9264ef0
child 5594:ad66ee47b674
comparison
equal deleted inserted replaced
5532:d5cbcdcdb2f7 5533:df3c78221f26
346 if check_cert_status(session) == false then 346 if check_cert_status(session) == false then
347 return; 347 return;
348 end 348 end
349 end 349 end
350 350
351 session:open_stream() 351 session:open_stream(session.to_host, session.from_host)
352 if session.version >= 1.0 then 352 if session.version >= 1.0 then
353 local features = st.stanza("stream:features"); 353 local features = st.stanza("stream:features");
354 354
355 if to then 355 if to then
356 hosts[to].events.fire_event("s2s-stream-features", { origin = session, features = features }); 356 hosts[to].events.fire_event("s2s-stream-features", { origin = session, features = features });
446 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; 446 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
447 local function session_close(session, reason, remote_reason) 447 local function session_close(session, reason, remote_reason)
448 local log = session.log or log; 448 local log = session.log or log;
449 if session.conn then 449 if session.conn then
450 if session.notopen then 450 if session.notopen then
451 session:open_stream() 451 if session.direction == "incoming" then
452 session:open_stream(session.to_host, session.from_host);
453 else
454 session:open_stream(session.from_host, session.to_host);
455 end
452 end 456 end
453 if reason then -- nil == no err, initiated by us, false == initiated by remote 457 if reason then -- nil == no err, initiated by us, false == initiated by remote
454 if type(reason) == "string" then -- assume stream error 458 if type(reason) == "string" then -- assume stream error
455 log("debug", "Disconnecting %s[%s], <stream:error> is: %s", session.host or "(unknown host)", session.type, reason); 459 log("debug", "Disconnecting %s[%s], <stream:error> is: %s", session.host or "(unknown host)", session.type, reason);
456 session.sends2s(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' })); 460 session.sends2s(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }));
494 end 498 end
495 end 499 end
496 end 500 end
497 501
498 function session_open_stream(session, from, to) 502 function session_open_stream(session, from, to)
499 local from = from or session.from_host;
500 local to = to or session.to_host;
501 local attr = { 503 local attr = {
502 ["xmlns:stream"] = 'http://etherx.jabber.org/streams', 504 ["xmlns:stream"] = 'http://etherx.jabber.org/streams',
503 xmlns = 'jabber:server', 505 xmlns = 'jabber:server',
504 version = session.version and (session.version > 0 and "1.0" or nil), 506 version = session.version and (session.version > 0 and "1.0" or nil),
505 ["xml:lang"] = 'en', 507 ["xml:lang"] = 'en',
506 id = session.streamid, 508 id = session.streamid,
507 from = from, to = to, 509 from = from, to = to,
508 } 510 }
509 local local_host = session.direction == "outgoing" and from or to; 511 if not from or (hosts[from] and hosts[from].modules.dialback) then
510 if not local_host or (hosts[local_host] and hosts[local_host].modules.dialback) then
511 attr["xmlns:db"] = 'jabber:server:dialback'; 512 attr["xmlns:db"] = 'jabber:server:dialback';
512 end 513 end
513 514
514 session.sends2s("<?xml version='1.0'?>"); 515 session.sends2s("<?xml version='1.0'?>");
515 session.sends2s(st.stanza("stream:stream", attr):top_tag()); 516 session.sends2s(st.stanza("stream:stream", attr):top_tag());