Mercurial > prosody-modules
annotate mod_bind2/mod_bind2.lua @ 4794:d17a1581ea30
mod_bind2: Advertise stream feature
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 28 Nov 2021 19:59:26 +0100 |
parents | aaa6f412dce3 |
children | 8849b4f68534 |
rev | line source |
---|---|
4793
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local mm = require "core.modulemanager"; |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local sm = require "core.sessionmanager"; |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local xmlns_bind2 --[[<const>]] = "urn:xmpp:bind2:0"; |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 local xmlns_carbons --[[<const>]] = "urn:xmpp:carbons:2"; |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 module:depends("sasl2"); |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 module:depends("carbons"); |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 |
4794
d17a1581ea30
mod_bind2: Advertise stream feature
Kim Alvefur <zash@zash.se>
parents:
4793
diff
changeset
|
10 module:hook("stream-features", function(event) |
d17a1581ea30
mod_bind2: Advertise stream feature
Kim Alvefur <zash@zash.se>
parents:
4793
diff
changeset
|
11 local origin, features = event.origin, event.features; |
d17a1581ea30
mod_bind2: Advertise stream feature
Kim Alvefur <zash@zash.se>
parents:
4793
diff
changeset
|
12 if origin.type ~= "c2s_unauthed" then return end |
d17a1581ea30
mod_bind2: Advertise stream feature
Kim Alvefur <zash@zash.se>
parents:
4793
diff
changeset
|
13 features:tag("bind", xmlns_bind2):up(); |
d17a1581ea30
mod_bind2: Advertise stream feature
Kim Alvefur <zash@zash.se>
parents:
4793
diff
changeset
|
14 end); |
d17a1581ea30
mod_bind2: Advertise stream feature
Kim Alvefur <zash@zash.se>
parents:
4793
diff
changeset
|
15 |
4793
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 module:hook_tag(xmlns_sasl2, "authenticate", function (session, auth) |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 session.bind2 = auth:get_child("bind", xmlns_bind2); |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 end, 1); |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 module:hook("sasl2/c2s/success", function (event) |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 local session = event.session; |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 if not session.bind2 then return end |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 -- When it receives a bind 2.0 on an authenticated not-yet-bound session, the |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 -- server MUST: |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 -- Clear the offline messages for this user, if any, without sending them (as |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 -- they will be provided by MAM). |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 if mm.is_loaded(module.host, "offline") then |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 -- TODO |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 end |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 -- Perform resource binding to a random resource (see 6120) |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 if not sm.bind_resource(session, nil) then |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 -- FIXME How should this be handled even? |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 session:close("reset"); |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 return true; |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 end |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 -- Work out which contacts have unread messages in the user's MAM archive, |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 -- how many, and what the id of the last read message is |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 -- XXX How do we know what the last read message was? |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 -- TODO archive:summary(session.username, { after = ??? }); |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 -- Get the id of the newest stanza in the user's MAM archive |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 -- TODO archive:find(session.username, { reverse = true, limit = 1 }); |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 -- Silently enable carbons for this session |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 session.carbons = xmlns_carbons; |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 -- After processing the bind stanza, as above, the server MUST respond with |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 -- an element of type 'bound' in the namespace 'urn:xmpp:bind2:0', as in the |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 -- below example |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 event.success:tag("bound", xmlns_bind2):text_tag("jid", session.full_jid):up(); |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 session.bind2 = nil; |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 end); |