Software /
code /
verse
Annotate
plugins/bind.lua @ 269:a15ede6b9ca1
doc/example_pep.lua: Reorder a bit to avoid re-sending presence multiple times when caps change.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 16 Dec 2011 22:09:37 +0100 |
parent | 250:a5ac643a7fd6 |
child | 300:b1d50f9a04c7 |
rev | line source |
---|---|
250 | 1 local verse = require "verse"; |
2 | |
9 | 3 local xmlns_bind = "urn:ietf:params:xml:ns:xmpp-bind"; |
4 | |
5 function verse.plugins.bind(stream) | |
6 local function handle_features(features) | |
7 if stream.bound then return; end | |
8 stream:debug("Binding resource..."); | |
197
7e98cf2c1d8d
plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents:
160
diff
changeset
|
9 stream:send_iq(verse.iq({ type = "set" }):tag("bind", {xmlns=xmlns_bind}):tag("resource"):text(stream.resource), |
9 | 10 function (reply) |
11 if reply.attr.type == "result" then | |
12 local result_jid = reply | |
13 :get_child("bind", xmlns_bind) | |
245 | 14 :get_child_text("jid"); |
9 | 15 stream.username, stream.host, stream.resource = jid.split(result_jid); |
16 stream.jid, stream.bound = result_jid, true; | |
160
5cbbfe42212e
plugins.bind: Fix the bind-success event, now fires with data { jid = result_jid } (thanks Jon)
Matthew Wild <mwild1@gmail.com>
parents:
78
diff
changeset
|
17 stream:event("bind-success", { jid = result_jid }); |
9 | 18 elseif reply.attr.type == "error" then |
43
a33036b7e5ab
verse.plugins.bind: Fix incorrect variable name causing traceback on unsuccessful bind
Matthew Wild <mwild1@gmail.com>
parents:
40
diff
changeset
|
19 local err = reply:child_with_name("error"); |
a33036b7e5ab
verse.plugins.bind: Fix incorrect variable name causing traceback on unsuccessful bind
Matthew Wild <mwild1@gmail.com>
parents:
40
diff
changeset
|
20 local type, condition, text = reply:get_error(); |
78
f4188eff53a7
verse.client, verse.plugins.bind, verse.plugins.session: Rename binding-success and binding-failure to bind-success and bind-failure for consistency
Matthew Wild <mwild1@gmail.com>
parents:
43
diff
changeset
|
21 stream:event("bind-failure", { error = condition, text = text, type = type }); |
9 | 22 end |
23 end); | |
24 end | |
25 stream:hook("stream-features", handle_features, 200); | |
26 return true; | |
27 end |