Mercurial > prosody-hg
comparison plugins/mod_s2s/mod_s2s.lua @ 6256:d05627c89c99
mod_s2s: Move filter initialization to common place
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 22 May 2014 22:48:06 +0200 |
| parents | 6167f8bc5a6b |
| children | 9dace3a712f0 |
comparison
equal
deleted
inserted
replaced
| 6255:6167f8bc5a6b | 6256:d05627c89c99 |
|---|---|
| 539 session.stream:reset(); | 539 session.stream:reset(); |
| 540 end | 540 end |
| 541 | 541 |
| 542 session.stream_attrs = session_stream_attrs; | 542 session.stream_attrs = session_stream_attrs; |
| 543 | 543 |
| 544 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 | |
| 545 function session.data(data) | 561 function session.data(data) |
| 546 data = filter("bytes/in", data); | 562 data = filter("bytes/in", data); |
| 547 if data then | 563 if data then |
| 548 local ok, err = stream:feed(data); | 564 local ok, err = stream:feed(data); |
| 549 if ok then return; end | 565 if ok then return; end |
| 578 local session = sessions[conn]; | 594 local session = sessions[conn]; |
| 579 if not session then -- New incoming connection | 595 if not session then -- New incoming connection |
| 580 session = s2s_new_incoming(conn); | 596 session = s2s_new_incoming(conn); |
| 581 sessions[conn] = session; | 597 sessions[conn] = session; |
| 582 session.log("debug", "Incoming s2s connection"); | 598 session.log("debug", "Incoming s2s connection"); |
| 583 | |
| 584 local filter = initialize_filters(session); | |
| 585 local w = conn.write; | |
| 586 session.sends2s = function (t) | |
| 587 log("debug", "sending: %s", t.top_tag and t:top_tag() or t:match("^([^>]*>?)")); | |
| 588 if t.name then | |
| 589 t = filter("stanzas/out", t); | |
| 590 end | |
| 591 if t then | |
| 592 t = filter("bytes/out", tostring(t)); | |
| 593 if t then | |
| 594 return w(conn, t); | |
| 595 end | |
| 596 end | |
| 597 end | |
| 598 | |
| 599 initialize_session(session); | 599 initialize_session(session); |
| 600 else -- Outgoing session connected | 600 else -- Outgoing session connected |
| 601 session:open_stream(session.from_host, session.to_host); | 601 session:open_stream(session.from_host, session.to_host); |
| 602 end | 602 end |
| 603 session.ip = conn:ip(); | 603 session.ip = conn:ip(); |
