File

plugins/session.lua @ 62:d4b6f9e33c6e

verse.client: Load TLS along with other core plugins
author Matthew Wild <mwild1@gmail.com>
date Tue, 11 May 2010 23:05:26 +0100
parent 50:432ac110544f
child 68:1789dac44823
line wrap: on
line source

local st = require "util.stanza";
local xmlns_session = "urn:ietf:params:xml:ns:xmpp-session";

function verse.plugins.session(stream)
        local function handle_binding(jid)
                stream:debug("Establishing Session...");
                stream:send_iq(st.iq({ type = "set" }):tag("session", {xmlns=xmlns_session}),
                        function (reply)
                                if reply.attr.type == "result" then
                                        stream:event("session-success");
                                elseif reply.attr.type == "error" then
                                        local err = reply:child_with_name("error");
                                        local type, condition, text = reply:get_error();
                                        stream:event("session-failure", { error = condition, text = text, type = type });
                                end
                        end);
        end
        stream:hook("binding-success", handle_binding);
        return true;
end