Software /
code /
verse
Annotate
plugins/bind.lua @ 465:6707e3a47f71
Add 'shutdown' event for a self-initiated disconnect
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 17 Mar 2023 09:23:15 +0000 |
parent | 457:73d4eb93657b |
child | 490:6b2f31da9610 |
rev | line source |
---|---|
250 | 1 local verse = require "verse"; |
300
b1d50f9a04c7
plugins.bind: Import util.jid to fix traceback
Matthew Wild <mwild1@gmail.com>
parents:
250
diff
changeset
|
2 local jid = require "util.jid"; |
250 | 3 |
9 | 4 local xmlns_bind = "urn:ietf:params:xml:ns:xmpp-bind"; |
5 | |
6 function verse.plugins.bind(stream) | |
7 local function handle_features(features) | |
8 if stream.bound then return; end | |
9 stream:debug("Binding resource..."); | |
457
73d4eb93657b
Update to use util.id for random ids instead of counters (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
300
diff
changeset
|
10 stream:send_iq(verse.iq({ id="bind",type = "set" }):tag("bind", {xmlns=xmlns_bind}):tag("resource"):text(stream.resource), |
9 | 11 function (reply) |
12 if reply.attr.type == "result" then | |
13 local result_jid = reply | |
14 :get_child("bind", xmlns_bind) | |
245 | 15 :get_child_text("jid"); |
9 | 16 stream.username, stream.host, stream.resource = jid.split(result_jid); |
17 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
|
18 stream:event("bind-success", { jid = result_jid }); |
9 | 19 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
|
20 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
|
21 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
|
22 stream:event("bind-failure", { error = condition, text = text, type = type }); |
9 | 23 end |
24 end); | |
25 end | |
26 stream:hook("stream-features", handle_features, 200); | |
27 return true; | |
28 end |