plugins/register.lua

Sun, 12 Feb 2012 20:21:52 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 12 Feb 2012 20:21:52 +0000
changeset 279
7a0aa3d055f4
parent 250
a5ac643a7fd6
child 342
7aed4bc4949c
permissions
-rw-r--r--

verse: Accept a file object as a log handler, and automatically call :write() on it with a formatted message

local verse = require "verse";

local xmlns_register = "jabber:iq:register";

function verse.plugins.register(stream)
	local function handle_features(features_stanza)
		if features_stanza:get_child("register", "http://jabber.org/features/iq-register") then
			stream:send_iq(verse.iq({ to = stream.host_, type = "set" })
				:tag("query", { xmlns = xmlns_register })
					:tag("username"):text(stream.username):up()
					:tag("password"):text(stream.password):up()
			, function (result)
				if result.attr.type == "result" then
					stream:event("registration-success");
				else
					local type, condition, text = result:get_error();
					stream:debug("Registration failed: %s", condition);
					stream:event("registration-failure", { type = type, condition = condition, text = text });
				end
			end);
		else
			stream:debug("In-band registration not offered by server");
			stream:event("registration-failed", { condition = "service-unavailable" });
		end
		stream:unhook("stream-features", handle_features);
		return true;
	end
	stream:hook("stream-features", handle_features, 310);
end

mercurial