File

plugins/session.lua @ 155:9c9af7a196ed

plugins.private, squishy: Allow setting the storage node, and not just child(s). And add to squishy.
author Kim Alvefur <zash@zash.se>
date Sat, 20 Nov 2010 17:27:03 +0100
parent 78:f4188eff53a7
child 197:7e98cf2c1d8d
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_features(features)
		local session_feature = features:get_child("session", xmlns_session);
		if session_feature and not session_feature:get_child("optional") then
			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);
				return true;
			end
			stream:hook("bind-success", handle_binding);
		end
	end
	stream:hook("stream-features", handle_features);
	
	return true;
end