Comparison

plugins/mod_s2s/mod_s2s.lua @ 6258:8a01bce29834

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Sat, 24 May 2014 01:27:09 +0200
parent 6257:9dace3a712f0
child 6259:36f611624987
comparison
equal deleted inserted replaced
6254:da4c04df90e3 6258:8a01bce29834
527 end 527 end
528 528
529 -- Session initialization logic shared by incoming and outgoing 529 -- Session initialization logic shared by incoming and outgoing
530 local function initialize_session(session) 530 local function initialize_session(session)
531 local stream = new_xmpp_stream(session, stream_callbacks); 531 local stream = new_xmpp_stream(session, stream_callbacks);
532 local log = session.log or log;
532 session.stream = stream; 533 session.stream = stream;
533 534
534 session.notopen = true; 535 session.notopen = true;
535 536
536 function session.reset_stream() 537 function session.reset_stream()
538 session.stream:reset(); 539 session.stream:reset();
539 end 540 end
540 541
541 session.stream_attrs = session_stream_attrs; 542 session.stream_attrs = session_stream_attrs;
542 543
543 local filter = session.filter; 544 local filter = initialize_filters(session);
545 local conn = session.conn;
546 local w = conn.write;
547
548 function session.sends2s(t)
549 log("debug", "sending: %s", t.top_tag and t:top_tag() or t:match("^[^>]*>?"));
550 if t.name then
551 t = filter("stanzas/out", t);
552 end
553 if t then
554 t = filter("bytes/out", tostring(t));
555 if t then
556 return w(conn, t);
557 end
558 end
559 end
560
544 function session.data(data) 561 function session.data(data)
545 data = filter("bytes/in", data); 562 data = filter("bytes/in", data);
546 if data then 563 if data then
547 local ok, err = stream:feed(data); 564 local ok, err = stream:feed(data);
548 if ok then return; end 565 if ok then return; end
549 (session.log or log)("warn", "Received invalid XML: %s", data); 566 log("warn", "Received invalid XML: %s", data);
550 (session.log or log)("warn", "Problem was: %s", err); 567 log("warn", "Problem was: %s", err);
551 session:close("not-well-formed"); 568 session:close("not-well-formed");
552 end 569 end
553 end 570 end
554 571
555 session.close = session_close; 572 session.close = session_close;
577 local session = sessions[conn]; 594 local session = sessions[conn];
578 if not session then -- New incoming connection 595 if not session then -- New incoming connection
579 session = s2s_new_incoming(conn); 596 session = s2s_new_incoming(conn);
580 sessions[conn] = session; 597 sessions[conn] = session;
581 session.log("debug", "Incoming s2s connection"); 598 session.log("debug", "Incoming s2s connection");
582
583 local filter = initialize_filters(session);
584 local w = conn.write;
585 session.sends2s = function (t)
586 log("debug", "sending: %s", t.top_tag and t:top_tag() or t:match("^([^>]*>?)"));
587 if t.name then
588 t = filter("stanzas/out", t);
589 end
590 if t then
591 t = filter("bytes/out", tostring(t));
592 if t then
593 return w(conn, t);
594 end
595 end
596 end
597
598 initialize_session(session); 599 initialize_session(session);
599 else -- Outgoing session connected 600 else -- Outgoing session connected
600 session:open_stream(session.from_host, session.to_host); 601 session:open_stream(session.from_host, session.to_host);
601 end 602 end
602 session.ip = conn:ip(); 603 session.ip = conn:ip();
640 return (hosts[session.host] or prosody).events.fire_event("s2s-read-timeout", { session = session }); 641 return (hosts[session.host] or prosody).events.fire_event("s2s-read-timeout", { session = session });
641 end 642 end
642 end 643 end
643 644
644 function listener.register_outgoing(conn, session) 645 function listener.register_outgoing(conn, session)
645 session.direction = "outgoing";
646 sessions[conn] = session; 646 sessions[conn] = session;
647 initialize_session(session); 647 initialize_session(session);
648 end 648 end
649 649
650 function check_auth_policy(event) 650 function check_auth_policy(event)