local uuid_generate = require "util.uuid".generate;
local rm_load_roster = require "core.rostermanager".load_roster;
+local st = require "util.stanza";
+
local newproxy = newproxy;
local getmetatable = getmetatable;
getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; print("Session got collected, now "..open_sessions.." sessions are allocated") end;
end
open_sessions = open_sessions + 1;
+ log("info", "open sessions now: ".. open_sessions);
local w = conn.write;
session.send = function (t) w(tostring(t)); end
return session;
end
-function destroy_session(session)
+function destroy_session(session, err)
(session.log or log)("info", "Destroying session");
-- Send unavailable presence
- if session.presence and session.presence.attr.type ~= "unavailable" then
+ if session.presence then
local pres = st.presence{ type = "unavailable" };
- if err == "closed" then err = "connection closed"; end
+ if (not err) or err == "closed" then err = "connection closed"; end
pres:tag("status"):text("Disconnected: "..err);
session.stanza_dispatch(pres);
end
if not hosts[session.host] then
-- We don't serve this host...
- session:disconnect{ condition = "host-unknown", text = "This server does not serve "..tostring(session.host)};
+ session:close{ condition = "host-unknown", text = "This server does not serve "..tostring(session.host)};
return;
end
- local features = {};
+ local features = st.stanza("stream:features");
modulemanager.fire_event("stream-features", session, features);
- -- FIXME: Need to send() this all at once
- send("<stream:features>");
+ send(features);
- for _, feature in ipairs(features) do
- send(tostring(feature));
- end
-
- send("</stream:features>");
- log("info", "Stream opened successfully");
+ (session.log or log)("info", "Sent reply <stream:stream> to client");
session.notopen = nil;
end