From 01c770997f61259d6e5b8ae5018aab1ef6ac0ef8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 18 Nov 2008 17:52:33 +0000 Subject: 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 --- core/xmlhandlers.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'core/xmlhandlers.lua') 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)); -- cgit v1.2.3 From a6970f5b2b46915fa39ede1d11eb4758bc18cb9d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 18 Nov 2008 19:58:29 +0000 Subject: *ahem* Yes, move along please... though really, quite a classic. :) --- core/xmlhandlers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/xmlhandlers.lua') diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index 09139904..61a9e387 100644 --- a/core/xmlhandlers.lua +++ b/core/xmlhandlers.lua @@ -96,7 +96,7 @@ function init_xmlhandlers(session, stream_callbacks) end 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 (not stanza) or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then if name == "stream" and cb_streamclosed then log("debug", "Stream closed"); cb_streamclosed(session); -- cgit v1.2.3 From 0da8b7b741f592c1e2b7d54639d81a485ee8d8da Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 19 Nov 2008 05:10:16 +0000 Subject: Don't error if streamopened/streamclosed callback is not specified for a session --- core/xmlhandlers.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'core/xmlhandlers.lua') diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index 61a9e387..42ccf388 100644 --- a/core/xmlhandlers.lua +++ b/core/xmlhandlers.lua @@ -69,8 +69,10 @@ function init_xmlhandlers(session, stream_callbacks) if not stanza then --if we are not currently inside a stanza if session.notopen then print("client opening with "..tostring(name)); - if name == "stream" and cb_streamopened then - cb_streamopened(session, attr); + if name == "stream" then + if cb_streamopened then + cb_streamopened(session, attr); + end return; end error("Client failed to open stream successfully"); @@ -97,14 +99,16 @@ function init_xmlhandlers(session, stream_callbacks) function xml_handlers:EndElement(name) curr_ns,name = name:match("^(.+)|([%w%-]+)$"); if (not stanza) or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then - if name == "stream" and cb_streamclosed then + if name == "stream" then log("debug", "Stream closed"); - cb_streamclosed(session); + if cb_streamclosed then + cb_streamclosed(session); + end return; elseif name == "error" then error("Stream error: "..tostring(name)..": "..tostring(stanza)); else - error("XML parse error in client stream"); + error("XML parse error in client stream with element: "..name); end end if stanza and #chardata > 0 then -- cgit v1.2.3 From 572a0324a3b05d78028d446a1ba2f1e3280046cd Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 20 Nov 2008 01:31:15 +0000 Subject: Remove a debug print() from xmlhandlers --- core/xmlhandlers.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'core/xmlhandlers.lua') diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index 42ccf388..a97db8e9 100644 --- a/core/xmlhandlers.lua +++ b/core/xmlhandlers.lua @@ -68,7 +68,6 @@ function init_xmlhandlers(session, stream_callbacks) if not stanza then --if we are not currently inside a stanza if session.notopen then - print("client opening with "..tostring(name)); if name == "stream" then if cb_streamopened then cb_streamopened(session, attr); -- cgit v1.2.3