diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/s2smanager.lua | 11 | ||||
-rw-r--r-- | core/sessionmanager.lua | 13 | ||||
-rw-r--r-- | core/xmlhandlers.lua | 16 |
3 files changed, 31 insertions, 9 deletions
diff --git a/core/s2smanager.lua b/core/s2smanager.lua index dbfc2cb3..afc4f145 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -52,7 +52,7 @@ function send_to_host(from_host, to_host, data) -- FIXME if host.from_host ~= from_host then log("error", "WARNING! This might, possibly, be a bug, but it might not..."); - log("error", "We are going to send from %s instead of %s", host.from_host, from_host); + log("error", "We are going to send from %s instead of %s", tostring(host.from_host), tostring(from_host)); end host.sends2s(data); host.log("debug", "stanza sent over "..host.type); @@ -137,6 +137,11 @@ function streamopened(session, attr) print(session, session.from_host, "incoming s2s stream opened"); send("<?xml version='1.0'?>"); send(stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host }):top_tag()); + if session.to_host and not hosts[session.to_host] then + -- Attempting to connect to a host we don't serve + session:disconnect("host-unknown"); + return; + end elseif session.direction == "outgoing" then -- If we are just using the connection for verifying dialback keys, we won't try and auth it if not attr.id then error("stream response did not give us a streamid!!!"); end @@ -218,9 +223,13 @@ end function destroy_session(session) (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)); + + -- FIXME: Flush sendq here/report errors to originators + if session.direction == "outgoing" then hosts[session.from_host].s2sout[session.to_host] = nil; end + session.conn = nil; session.disconnect = nil; for k in pairs(session) do diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 33157567..fbfb7964 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -35,6 +35,16 @@ end function destroy_session(session) (session.log or log)("info", "Destroying session"); + + -- Send unavailable presence + if session.presence and session.presence.attr.type ~= "unavailable" then + local pres = st.presence{ type = "unavailable" }; + if err == "closed" then err = "connection closed"; end + pres:tag("status"):text("Disconnected: "..err); + session.stanza_dispatch(pres); + end + + -- Remove session/resource from user's session list if session.host and session.username then if session.resource then hosts[session.host].sessions[session.username].sessions[session.resource] = nil; @@ -46,8 +56,7 @@ function destroy_session(session) end end end - session.conn = nil; - session.disconnect = nil; + for k in pairs(session) do if k ~= "trace" then session[k] = nil; diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index 3037a848..09139904 100644 --- a/core/xmlhandlers.lua +++ b/core/xmlhandlers.lua @@ -25,7 +25,7 @@ local ns_prefixes = { ["http://www.w3.org/XML/1998/namespace"] = "xml"; } -function init_xmlhandlers(session, streamopened) +function init_xmlhandlers(session, stream_callbacks) local ns_stack = { "" }; local curr_ns = ""; local curr_tag; @@ -36,6 +36,9 @@ function init_xmlhandlers(session, streamopened) local send = session.send; + local cb_streamopened = stream_callbacks.streamopened; + local cb_streamclosed = stream_callbacks.streamclosed; + local stanza function xml_handlers:StartElement(name, attr) if stanza and #chardata > 0 then @@ -65,8 +68,9 @@ function init_xmlhandlers(session, streamopened) if not stanza then --if we are not currently inside a stanza if session.notopen then - if name == "stream" then - streamopened(session, attr); + print("client opening with "..tostring(name)); + if name == "stream" and cb_streamopened then + cb_streamopened(session, attr); return; end error("Client failed to open stream successfully"); @@ -75,7 +79,7 @@ function init_xmlhandlers(session, streamopened) error("Client sent invalid top-level stanza"); end - stanza = st.stanza(name, attr); --{ to = attr.to, type = attr.type, id = attr.id, xmlns = curr_ns }); + stanza = st.stanza(name, attr); curr_tag = stanza; else -- we are inside a stanza, so add a tag attr.xmlns = nil; @@ -93,9 +97,9 @@ function init_xmlhandlers(session, streamopened) function xml_handlers:EndElement(name) curr_ns,name = name:match("^(.+)|([%w%-]+)$"); if (not stanza) or #stanza.last_add < 0 or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then - if name == "stream" then + if name == "stream" and cb_streamclosed then log("debug", "Stream closed"); - sm_destroy_session(session); + cb_streamclosed(session); return; elseif name == "error" then error("Stream error: "..tostring(name)..": "..tostring(stanza)); |