Mercurial > prosody-modules
annotate mod_bind2/mod_bind2.lua @ 4793:aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Needless to say, completely untested
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 28 Nov 2021 19:45:25 +0100 |
parents | |
children | d17a1581ea30 |
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 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 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
|
11 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
|
12 end, 1); |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 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
|
15 local session = event.session; |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 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
|
17 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 -- 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
|
19 -- server MUST: |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 -- 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
|
22 -- 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
|
23 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
|
24 -- TODO |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 end |
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 -- 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
|
28 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
|
29 -- 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
|
30 session:close("reset"); |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 return true; |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 end |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 -- 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
|
35 -- 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
|
36 -- 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
|
37 -- 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
|
38 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 -- 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
|
40 -- 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
|
41 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 -- 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
|
43 session.carbons = xmlns_carbons; |
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 -- 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
|
46 -- 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
|
47 -- below example |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 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
|
49 |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 session.bind2 = nil; |
aaa6f412dce3
mod_bind2: Experimental implementation of XEP-0386: Bind 2.0
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 end); |