Annotate

plugins/private.lua @ 448:6d97b42bb1b4

plugins.smacks: Handle failed resumption by trying to bind instead
author Kim Alvefur <zash@zash.se>
date Sat, 19 Feb 2022 15:43:47 +0100
parent 380:0891b4e27766
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
250
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
1 local verse = require "verse";
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
2
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
3 -- Implements XEP-0049: Private XML Storage
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
4
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
5 local xmlns_private = "jabber:iq:private";
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
6
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
7 function verse.plugins.private(stream)
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
8 function stream:private_set(name, xmlns, data, callback)
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
9 local iq = verse.iq({ type = "set" })
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
10 :tag("query", { xmlns = xmlns_private });
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
11 if data then
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
12 if data.name == name and data.attr and data.attr.xmlns == xmlns then
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
13 iq:add_child(data);
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
14 else
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
15 iq:tag(name, { xmlns = xmlns })
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
16 :add_child(data);
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
17 end
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
18 end
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
19 self:send_iq(iq, callback);
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
20 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
21
250
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
22 function stream:private_get(name, xmlns, callback)
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
23 self:send_iq(verse.iq({type="get"})
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
24 :tag("query", { xmlns = xmlns_private })
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
25 :tag(name, { xmlns = xmlns }),
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
26 function (reply)
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
27 if reply.attr.type == "result" then
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
28 local query = reply:get_child("query", xmlns_private);
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
29 local result = query:get_child(name, xmlns);
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
30 callback(result);
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
31 end
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
32 end);
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
33 end
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
34 end
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 155
diff changeset
35