Comparison

net/xmppclient_listener.lua @ 275:7af22e56d625

Fix logging of disconnect reason, and also sending of unavailable presence on disconnect
author Matthew Wild <mwild1@gmail.com>
date Sat, 15 Nov 2008 19:32:58 +0000
parent 267:6303b7454ad0
child 318:cc20ea4a8697
comparison
equal deleted inserted replaced
274:9e68a697435d 275:7af22e56d625
71 if data then 71 if data then
72 session.data(conn, data); 72 session.data(conn, data);
73 end 73 end
74 end 74 end
75 75
76 function xmppclient.disconnect(conn) 76 function xmppclient.disconnect(conn, err)
77 local session = sessions[conn]; 77 local session = sessions[conn];
78 if session then 78 if session then
79 if session.last_presence and session.last_presence.attr.type ~= "unavailable" then 79 if session.presence and session.presence.attr.type ~= "unavailable" then
80 local pres = st.presence{ type = "unavailable" }; 80 local pres = st.presence{ type = "unavailable" };
81 if err == "closed" then err = "connection closed"; end --FIXME where did err come from? 81 if err == "closed" then err = "connection closed"; end
82 pres:tag("status"):text("Disconnected: "..err); 82 pres:tag("status"):text("Disconnected: "..err);
83 session.stanza_dispatch(pres); 83 session.stanza_dispatch(pres);
84 end 84 end
85 session.log("info", "Client disconnected: %s", err);
85 sm_destroy_session(session); 86 sm_destroy_session(session);
86 sessions[conn] = nil; 87 sessions[conn] = nil;
87 session = nil; 88 session = nil;
88 collectgarbage("collect"); 89 collectgarbage("collect");
89 end 90 end