aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2008-11-18 17:52:33 +0000
committerMatthew Wild <mwild1@gmail.com>2008-11-18 17:52:33 +0000
commit01c770997f61259d6e5b8ae5018aab1ef6ac0ef8 (patch)
treee58078b7e8fe4e6d58e6fdfb0be12fcea875ee29 /net
parentf4e09200420e410c608ef9b841a0669b5c0d88a9 (diff)
downloadprosody-01c770997f61259d6e5b8ae5018aab1ef6ac0ef8.tar.gz
prosody-01c770997f61259d6e5b8ae5018aab1ef6ac0ef8.zip
Quite some changes, to:
- Small logging fix for s2smanager - Send a stream error if an incoming s2s connection is to an unrecognised hostname (fixes #11) - init_xmlhandlers now takes a table of callbacks (includes changes to net/xmpp*_listener for this) - Move sending of unavailable presence to where it should be, sessionmanager.destroy_session - Fix sending of stream errors to wrong connection
Diffstat (limited to 'net')
-rw-r--r--net/xmppclient_listener.lua11
-rw-r--r--net/xmppserver_listener.lua18
2 files changed, 13 insertions, 16 deletions
diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua
index 85430308..e89a591e 100644
--- a/net/xmppclient_listener.lua
+++ b/net/xmppclient_listener.lua
@@ -13,8 +13,11 @@ local m_random = math.random;
local format = string.format;
local sm_new_session, sm_destroy_session = sessionmanager.new_session, sessionmanager.destroy_session; --import("core.sessionmanager", "new_session", "destroy_session");
local sm_streamopened = sessionmanager.streamopened;
+local sm_streamclosed = sessionmanager.streamclosed;
local st = stanza;
+local stream_callbacks = { streamopened = sm_streamopened, streamclosed = sm_streamclosed };
+
local sessions = {};
local xmppclient = { default_port = 5222 };
@@ -22,7 +25,7 @@ local xmppclient = { default_port = 5222 };
local function session_reset_stream(session)
-- Reset stream
- local parser = lxp.new(init_xmlhandlers(session, sm_streamopened), "|");
+ local parser = lxp.new(init_xmlhandlers(session, stream_callbacks), "|");
session.parser = parser;
session.notopen = true;
@@ -107,12 +110,6 @@ end
function xmppclient.disconnect(conn, err)
local session = sessions[conn];
if session then
- 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
(session.log or log)("info", "Client disconnected: %s", err);
sm_destroy_session(session);
sessions[conn] = nil;
diff --git a/net/xmppserver_listener.lua b/net/xmppserver_listener.lua
index 21351c12..4564eee1 100644
--- a/net/xmppserver_listener.lua
+++ b/net/xmppserver_listener.lua
@@ -5,8 +5,11 @@ local init_xmlhandlers = require "core.xmlhandlers"
local sm_new_session = require "core.sessionmanager".new_session;
local s2s_new_incoming = require "core.s2smanager".new_incoming;
local s2s_streamopened = require "core.s2smanager".streamopened;
+local s2s_streamclosed = require "core.s2smanager".streamopened;
local s2s_destroy_session = require "core.s2smanager".destroy_session;
+local stream_callbacks = { streamopened = s2s_streamopened, streamclosed = s2s_streamclosed };
+
local connlisteners_register = require "net.connlisteners".register;
local t_insert = table.insert;
@@ -24,7 +27,7 @@ local xmppserver = { default_port = 5269 };
local function session_reset_stream(session)
-- Reset stream
- local parser = lxp.new(init_xmlhandlers(session, s2s_streamopened), "|");
+ local parser = lxp.new(init_xmlhandlers(session, stream_callbacks), "|");
session.parser = parser;
session.notopen = true;
@@ -43,7 +46,7 @@ local function session_disconnect(session, reason)
if reason then
if type(reason) == "string" then -- assume stream error
log("info", "Disconnecting %s[%s], <stream:error> is: %s", session.host or "(unknown host)", session.type, reason);
- session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }));
+ session.sends2s(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }));
elseif type(reason) == "table" then
if reason.condition then
local stanza = st.stanza("stream:error"):tag(reason.condition, stream_xmlns_attr):up();
@@ -54,14 +57,14 @@ local function session_disconnect(session, reason)
stanza:add_child(reason.extra);
end
log("info", "Disconnecting %s[%s], <stream:error> is: %s", session.host or "(unknown host)", session.type, tostring(stanza));
- session.send(stanza);
+ session.sends2s(stanza);
elseif reason.name then -- a stanza
- log("info", "Disconnecting %s[%s], <stream:error> is: %s", session.host or "(unknown host)", session.type, tostring(reason));
- session.send(reason);
+ log("info", "Disconnecting %s->%s[%s], <stream:error> is: %s", session.from_host or "(unknown host)", session.to_host or "(unknown host)", session.type, tostring(reason));
+ session.sends2s(reason);
end
end
end
- session.send("</stream:stream>");
+ session.sends2s("</stream:stream>");
session.conn.close();
xmppserver.disconnect(session.conn, "stream error");
end
@@ -100,9 +103,6 @@ function xmppserver.listener(conn, data)
-- Debug version --
local function handleerr(err) print("Traceback:", err, debug.traceback()); end
session.stanza_dispatch = function (stanza) return select(2, xpcall(function () return core_process_stanza(session, stanza); end, handleerr)); end
-
--- session.stanza_dispatch = function (stanza) return core_process_stanza(session, stanza); end
-
end
if data then
session.data(conn, data);