plugins/register.lua

changeset 235
3c93d6119477
child 250
a5ac643a7fd6
equal deleted inserted replaced
234:a597da99810c 235:3c93d6119477
1 local xmlns_register = "jabber:iq:register";
2
3 function verse.plugins.register(stream)
4 local function handle_features(features_stanza)
5 if features_stanza:get_child("register", "http://jabber.org/features/iq-register") then
6 stream:send_iq(verse.iq({ to = stream.host_, type = "set" })
7 :tag("query", { xmlns = xmlns_register })
8 :tag("username"):text(stream.username):up()
9 :tag("password"):text(stream.password):up()
10 , function (result)
11 if result.attr.type == "result" then
12 stream:event("registration-success");
13 else
14 local type, condition, text = result:get_error();
15 stream:debug("Registration failed: %s", condition);
16 stream:event("registration-failure", { type = type, condition = condition, text = text });
17 end
18 end);
19 else
20 stream:debug("In-band registration not offered by server");
21 stream:event("registration-failed", { condition = "service-unavailable" });
22 end
23 stream:unhook("stream-features", handle_features);
24 return true;
25 end
26 stream:hook("stream-features", handle_features, 310);
27 end

mercurial