Software /
code /
prosody
Comparison
plugins/s2s/mod_s2s.lua @ 4568:aae7a62671de
mod_s2s: port functionality once in s2smanager.
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Fri, 24 Feb 2012 15:21:21 +0000 |
parent | 4555:3dce04129693 |
child | 4570:9612abc89dd1 |
comparison
equal
deleted
inserted
replaced
4567:24617f360200 | 4568:aae7a62671de |
---|---|
12 local xpcall, traceback = xpcall, debug.traceback; | 12 local xpcall, traceback = xpcall, debug.traceback; |
13 | 13 |
14 local add_task = require "util.timer".add_task; | 14 local add_task = require "util.timer".add_task; |
15 local st = require "util.stanza"; | 15 local st = require "util.stanza"; |
16 local initialize_filters = require "util.filters".initialize; | 16 local initialize_filters = require "util.filters".initialize; |
17 local nameprep = require "util.encodings".stringprep.nameprep; | |
17 local new_xmpp_stream = require "util.xmppstream".new; | 18 local new_xmpp_stream = require "util.xmppstream".new; |
18 local s2s_new_incoming = require "core.s2smanager".new_incoming; | 19 local s2s_new_incoming = require "core.s2smanager".new_incoming; |
19 local s2s_new_outgoing = require "core.s2smanager".new_outgoing; | 20 local s2s_new_outgoing = require "core.s2smanager".new_outgoing; |
20 local s2s_destroy_session = require "core.s2smanager".destroy_session; | 21 local s2s_destroy_session = require "core.s2smanager".destroy_session; |
22 local uuid_gen = require "util.uuid".generate; | |
21 | 23 |
22 local s2sout = module:require("s2sout"); | 24 local s2sout = module:require("s2sout"); |
23 | 25 |
24 local connect_timeout = module:get_option_number("s2s_timeout", 60); | 26 local connect_timeout = module:get_option_number("s2s_timeout", 60); |
25 | 27 |
92 | 94 |
93 -- Store in buffer | 95 -- Store in buffer |
94 host_session.bounce_sendq = bounce_sendq; | 96 host_session.bounce_sendq = bounce_sendq; |
95 host_session.sendq = { {tostring(stanza), stanza.attr.type ~= "error" and stanza.attr.type ~= "result" and st.reply(stanza)} }; | 97 host_session.sendq = { {tostring(stanza), stanza.attr.type ~= "error" and stanza.attr.type ~= "result" and st.reply(stanza)} }; |
96 log("debug", "stanza [%s] queued until connection complete", tostring(stanza.name)); | 98 log("debug", "stanza [%s] queued until connection complete", tostring(stanza.name)); |
99 s2sout.initiate_connection(host_session); | |
97 if (not host_session.connecting) and (not host_session.conn) then | 100 if (not host_session.connecting) and (not host_session.conn) then |
98 log("warn", "Connection to %s failed already, destroying session...", to_host); | 101 log("warn", "Connection to %s failed already, destroying session...", to_host); |
99 if not s2s_destroy_session(host_session, "Connection failed") then | 102 if not s2s_destroy_session(host_session, "Connection failed") then |
100 -- Already destroyed, we need to bounce our stanza | 103 -- Already destroyed, we need to bounce our stanza |
101 host_session:bounce_sendq(host_session.destruction_reason); | 104 host_session:bounce_sendq(host_session.destruction_reason); |
102 end | 105 end |
103 return false; | 106 return false; |
104 end | 107 end |
105 s2sout.initiate_connection(host_session); | |
106 end | 108 end |
107 return true; | 109 return true; |
108 end | 110 end |
109 | 111 |
110 module:hook("route/remote", function (event) | 112 module:hook("route/remote", function (event) |
187 end | 189 end |
188 | 190 |
189 if session.secure and not session.cert_chain_status then check_cert_status(session); end | 191 if session.secure and not session.cert_chain_status then check_cert_status(session); end |
190 | 192 |
191 send("<?xml version='1.0'?>"); | 193 send("<?xml version='1.0'?>"); |
192 send(stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', | 194 send(stanza.stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', |
193 ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host, to=session.from_host, version=(session.version > 0 and "1.0" or nil) }):top_tag()); | 195 ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host, to=session.from_host, version=(session.version > 0 and "1.0" or nil) }):top_tag()); |
194 if session.version >= 1.0 then | 196 if session.version >= 1.0 then |
195 local features = st.stanza("stream:features"); | 197 local features = st.stanza("stream:features"); |
196 | 198 |
197 if session.to_host then | 199 if session.to_host then |
233 s2s_mark_connected(session); | 235 s2s_mark_connected(session); |
234 end | 236 end |
235 end | 237 end |
236 end | 238 end |
237 session.notopen = nil; | 239 session.notopen = nil; |
240 session.send = function(stanza) send_to_host(session.to_host, session.from_host, stanza); end; | |
238 end | 241 end |
239 | 242 |
240 function stream_callbacks.streamclosed(session) | 243 function stream_callbacks.streamclosed(session) |
241 (session.log or log)("debug", "Received </stream:stream>"); | 244 (session.log or log)("debug", "Received </stream:stream>"); |
242 session:close(); | 245 session:close(); |