Mercurial > prosody-hg
comparison net/xmppclient_listener.lua @ 331:830fd67f9378
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
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 18 Nov 2008 17:52:33 +0000 |
| parents | d9d4c1de16ce |
| children | 8d15b073fdbe |
comparison
equal
deleted
inserted
replaced
| 330:d9d4c1de16ce | 331:830fd67f9378 |
|---|---|
| 11 local t_concatall = function (t, sep) local tt = {}; for _, s in ipairs(t) do t_insert(tt, tostring(s)); end return t_concat(tt, sep); end | 11 local t_concatall = function (t, sep) local tt = {}; for _, s in ipairs(t) do t_insert(tt, tostring(s)); end return t_concat(tt, sep); end |
| 12 local m_random = math.random; | 12 local m_random = math.random; |
| 13 local format = string.format; | 13 local format = string.format; |
| 14 local sm_new_session, sm_destroy_session = sessionmanager.new_session, sessionmanager.destroy_session; --import("core.sessionmanager", "new_session", "destroy_session"); | 14 local sm_new_session, sm_destroy_session = sessionmanager.new_session, sessionmanager.destroy_session; --import("core.sessionmanager", "new_session", "destroy_session"); |
| 15 local sm_streamopened = sessionmanager.streamopened; | 15 local sm_streamopened = sessionmanager.streamopened; |
| 16 local sm_streamclosed = sessionmanager.streamclosed; | |
| 16 local st = stanza; | 17 local st = stanza; |
| 18 | |
| 19 local stream_callbacks = { streamopened = sm_streamopened, streamclosed = sm_streamclosed }; | |
| 17 | 20 |
| 18 local sessions = {}; | 21 local sessions = {}; |
| 19 local xmppclient = { default_port = 5222 }; | 22 local xmppclient = { default_port = 5222 }; |
| 20 | 23 |
| 21 -- These are session methods -- | 24 -- These are session methods -- |
| 22 | 25 |
| 23 local function session_reset_stream(session) | 26 local function session_reset_stream(session) |
| 24 -- Reset stream | 27 -- Reset stream |
| 25 local parser = lxp.new(init_xmlhandlers(session, sm_streamopened), "|"); | 28 local parser = lxp.new(init_xmlhandlers(session, stream_callbacks), "|"); |
| 26 session.parser = parser; | 29 session.parser = parser; |
| 27 | 30 |
| 28 session.notopen = true; | 31 session.notopen = true; |
| 29 | 32 |
| 30 function session.data(conn, data) | 33 function session.data(conn, data) |
| 105 end | 108 end |
| 106 | 109 |
| 107 function xmppclient.disconnect(conn, err) | 110 function xmppclient.disconnect(conn, err) |
| 108 local session = sessions[conn]; | 111 local session = sessions[conn]; |
| 109 if session then | 112 if session then |
| 110 if session.presence and session.presence.attr.type ~= "unavailable" then | |
| 111 local pres = st.presence{ type = "unavailable" }; | |
| 112 if err == "closed" then err = "connection closed"; end | |
| 113 pres:tag("status"):text("Disconnected: "..err); | |
| 114 session.stanza_dispatch(pres); | |
| 115 end | |
| 116 (session.log or log)("info", "Client disconnected: %s", err); | 113 (session.log or log)("info", "Client disconnected: %s", err); |
| 117 sm_destroy_session(session); | 114 sm_destroy_session(session); |
| 118 sessions[conn] = nil; | 115 sessions[conn] = nil; |
| 119 session = nil; | 116 session = nil; |
| 120 collectgarbage("collect"); | 117 collectgarbage("collect"); |
