Software /
code /
verse
Annotate
plugins/bind.lua @ 39:07192be5020b
plugins.bind: Requested JID should be in <jid/> tag (thanks Maranda :) )
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 22 Dec 2009 01:48:01 +0000 |
parent | 9:ca225a2d67b4 |
child | 40:afd037420977 |
rev | line source |
---|---|
9 | 1 local st = require "util.stanza"; |
2 local xmlns_bind = "urn:ietf:params:xml:ns:xmpp-bind"; | |
3 | |
4 function verse.plugins.bind(stream) | |
5 local function handle_features(features) | |
6 if stream.bound then return; end | |
7 stream:debug("Binding resource..."); | |
39
07192be5020b
plugins.bind: Requested JID should be in <jid/> tag (thanks Maranda :) )
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
8 stream:send_iq(st.iq({ type = "set" }):tag("bind", {xmlns=xmlns_bind}):tag("jid"):text(stream.jid), |
9 | 9 function (reply) |
10 if reply.attr.type == "result" then | |
11 local result_jid = reply | |
12 :get_child("bind", xmlns_bind) | |
13 :get_child("jid") | |
14 :get_text(); | |
15 stream.username, stream.host, stream.resource = jid.split(result_jid); | |
16 stream.jid, stream.bound = result_jid, true; | |
17 stream:event("binding-success", full_jid); | |
18 elseif reply.attr.type == "error" then | |
19 local err = result:child_with_name("error"); | |
20 local type, condition, text = result:get_error(); | |
21 stream:event("binding-failure", { error = condition, text = text, type = type }); | |
22 end | |
23 end); | |
24 end | |
25 stream:hook("stream-features", handle_features, 200); | |
26 return true; | |
27 end | |
28 |