plugins/bind.lua

Sun, 30 May 2010 02:54:15 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 30 May 2010 02:54:15 +0100
changeset 78
f4188eff53a7
parent 43
a33036b7e5ab
child 160
5cbbfe42212e
permissions
-rw-r--r--

verse.client, verse.plugins.bind, verse.plugins.session: Rename binding-success and binding-failure to bind-success and bind-failure for consistency

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

function verse.plugins.bind(stream)
	local function handle_features(features)
		if stream.bound then return; end
		stream:debug("Binding resource...");
		stream:send_iq(st.iq({ type = "set" }):tag("bind", {xmlns=xmlns_bind}):tag("resource"):text(stream.resource),
			function (reply)
				if reply.attr.type == "result" then
					local result_jid = reply
						:get_child("bind", xmlns_bind)
							:get_child("jid")
								:get_text();
					stream.username, stream.host, stream.resource = jid.split(result_jid);
					stream.jid, stream.bound = result_jid, true;
					stream:event("bind-success", full_jid);
				elseif reply.attr.type == "error" then
					local err = reply:child_with_name("error");
					local type, condition, text = reply:get_error();
					stream:event("bind-failure", { error = condition, text = text, type = type });
				end
			end);
	end
	stream:hook("stream-features", handle_features, 200);
	return true;
end

mercurial