Software /
code /
prosody
Annotate
plugins/mod_storage_xep0227.lua @ 13134:638f627e707f
util.datamanager: Add O(1) list indexing with on-disk index
Index file contains offsets and lengths of each item() which allows
seeking directly to each item and reading it without parsing the entire
file.
Also allows tricks like binary search, assuming items have some defined
order.
We take advantage of the 1-based indexing in tables to store a magic
header in the 0 position, so that table index 1 ends up at file index 1.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 11 May 2021 02:09:56 +0200 |
parent | 12977:74b9e05af71e |
child | 13225:6375f0741f90 |
rev | line source |
---|---|
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 local ipairs, pairs = ipairs, pairs; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 local setmetatable = setmetatable; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 local tostring = tostring; |
12589
39ae08180c81
compat: Remove handling of Lua 5.1 location of 'unpack' function
Kim Alvefur <zash@zash.se>
parents:
12460
diff
changeset
|
5 local next, unpack = next, table.unpack; |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 local os_remove = os.remove; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 local io_open = io.open; |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
8 local jid_bare = require "prosody.util.jid".bare; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
9 local jid_prep = require "prosody.util.jid".prep; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
10 local jid_join = require "prosody.util.jid".join; |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
12 local array = require "prosody.util.array"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
13 local base64 = require "prosody.util.encodings".base64; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
14 local dt = require "prosody.util.datetime"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
15 local hex = require "prosody.util.hex"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
16 local it = require "prosody.util.iterators"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
17 local paths = require"prosody.util.paths"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
18 local set = require "prosody.util.set"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
19 local st = require "prosody.util.stanza"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12589
diff
changeset
|
20 local parse_xml_real = require "prosody.util.xml".parse; |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
22 local lfs = require "lfs"; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
23 |
12175
39921b979edb
mod_storage_xep0227: Ignore luacheck warning
Matthew Wild <mwild1@gmail.com>
parents:
12174
diff
changeset
|
24 local function default_get_user_xml(self, user, host) --luacheck: ignore 212/self |
12176
e7639625a848
mod_storage_xep0227: Fix writing non-user data
Kim Alvefur <zash@zash.se>
parents:
12175
diff
changeset
|
25 local jid = jid_join(user, host); |
6697
3d27f5855f4b
mod_storage_xep0227: Use configured storage path
Kim Alvefur <zash@zash.se>
parents:
6696
diff
changeset
|
26 local path = paths.join(prosody.paths.data, jid..".xml"); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
27 local f, err = io_open(path); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
28 if not f then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
29 module:log("debug", "Unable to load XML file for <%s>: %s", jid, err); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
30 return; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
31 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
32 module:log("debug", "Loaded %s", path); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 local s = f:read("*a"); |
6698
95a8aeca1fc9
mod_storage_xep0227: Close file handle after reading
Kim Alvefur <zash@zash.se>
parents:
6697
diff
changeset
|
34 f:close(); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 return parse_xml_real(s); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 end |
12195
c5788969b812
mod_storage_xep0227: Fix luacheck warning
Matthew Wild <mwild1@gmail.com>
parents:
12194
diff
changeset
|
37 local function default_set_user_xml(self, user, host, xml) --luacheck: ignore 212/self |
12176
e7639625a848
mod_storage_xep0227: Fix writing non-user data
Kim Alvefur <zash@zash.se>
parents:
12175
diff
changeset
|
38 local jid = jid_join(user, host); |
6697
3d27f5855f4b
mod_storage_xep0227: Use configured storage path
Kim Alvefur <zash@zash.se>
parents:
6696
diff
changeset
|
39 local path = paths.join(prosody.paths.data, jid..".xml"); |
6700
0103dc8fa179
mod_storage_xep0227: Return error from io.open if unable to open file for writing
Kim Alvefur <zash@zash.se>
parents:
6699
diff
changeset
|
40 local f, err = io_open(path, "w"); |
0103dc8fa179
mod_storage_xep0227: Return error from io.open if unable to open file for writing
Kim Alvefur <zash@zash.se>
parents:
6699
diff
changeset
|
41 if not f then return f, err; end |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 if xml then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 local s = tostring(xml); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 f:write(s); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 f:close(); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 return true; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 else |
6699
ccdd0b615106
mod_storage_xep0227: Open file for writing even if removing so os.remove has a file to delete
Kim Alvefur <zash@zash.se>
parents:
6698
diff
changeset
|
48 f:close(); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 return os_remove(path); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 local function getUserElement(xml) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 if xml and xml.name == "server-data" then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 local host = xml.tags[1]; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 if host and host.name == "host" then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 local user = host.tags[1]; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 if user and user.name == "user" then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 return user; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 end |
12456
64722dcb0b8c
mod_storage_xep0227: Improve logging
Kim Alvefur <zash@zash.se>
parents:
12454
diff
changeset
|
62 module:log("warn", "Unable to find user element in %s", xml and xml:top_tag() or "nothing"); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 local function createOuterXml(user, host) |
6702
6a5c6c95cf78
mod_storage_xep0227: Use the registered namespace
Kim Alvefur <zash@zash.se>
parents:
6701
diff
changeset
|
65 return st.stanza("server-data", {xmlns='urn:xmpp:pie:0'}) |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 :tag("host", {jid=host}) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 :tag("user", {name = user}); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
70 local function hex_to_base64(s) |
12355
a0ff5c438e9d
util.hex: Deprecate to/from in favour of encode/decode, for consistency!
Matthew Wild <mwild1@gmail.com>
parents:
12195
diff
changeset
|
71 return base64.encode(hex.decode(s)); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
72 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
73 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
74 local function base64_to_hex(s) |
12458
10cc52e4b310
mod_storage_xep0227: Fix conversion of SCRAM into internal format (fix #1741)
Kim Alvefur <zash@zash.se>
parents:
12457
diff
changeset
|
75 return hex.encode(base64.decode(s)); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
76 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
77 |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
78 local handlers = {}; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
79 |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
80 -- In order to support custom account properties |
6703
353a7d4dfdc2
mod_storage_xep0227: Store data from mod_auth_internal_hashed in a private namespace
Kim Alvefur <zash@zash.se>
parents:
6702
diff
changeset
|
81 local extended = "http://prosody.im/protocol/extended-xep0227\1"; |
353a7d4dfdc2
mod_storage_xep0227: Store data from mod_auth_internal_hashed in a private namespace
Kim Alvefur <zash@zash.se>
parents:
6702
diff
changeset
|
82 |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
83 local scram_hash_name = module:get_option_string("password_hash", "SHA-1"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
84 local scram_properties = set.new({ "server_key", "stored_key", "iteration_count", "salt" }); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
85 |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
86 handlers.accounts = { |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
87 get = function(self, user) |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
88 user = getUserElement(self:_get_user_xml(user, self.host)); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
89 local scram_credentials = user and user:get_child_with_attr( |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
90 "scram-credentials", "urn:xmpp:pie:0#scram", |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
91 "mechanism", "SCRAM-"..scram_hash_name |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
92 ); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
93 if scram_credentials then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
94 return { |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
95 iteration_count = tonumber(scram_credentials:get_child_text("iter-count")); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
96 server_key = base64_to_hex(scram_credentials:get_child_text("server-key")); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
97 stored_key = base64_to_hex(scram_credentials:get_child_text("stored-key")); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
98 salt = base64.decode(scram_credentials:get_child_text("salt")); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
99 }; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
100 elseif user and user.attr.password then |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
101 return { password = user.attr.password }; |
6703
353a7d4dfdc2
mod_storage_xep0227: Store data from mod_auth_internal_hashed in a private namespace
Kim Alvefur <zash@zash.se>
parents:
6702
diff
changeset
|
102 elseif user then |
353a7d4dfdc2
mod_storage_xep0227: Store data from mod_auth_internal_hashed in a private namespace
Kim Alvefur <zash@zash.se>
parents:
6702
diff
changeset
|
103 local data = {}; |
353a7d4dfdc2
mod_storage_xep0227: Store data from mod_auth_internal_hashed in a private namespace
Kim Alvefur <zash@zash.se>
parents:
6702
diff
changeset
|
104 for k, v in pairs(user.attr) do |
353a7d4dfdc2
mod_storage_xep0227: Store data from mod_auth_internal_hashed in a private namespace
Kim Alvefur <zash@zash.se>
parents:
6702
diff
changeset
|
105 if k:sub(1, #extended) == extended then |
353a7d4dfdc2
mod_storage_xep0227: Store data from mod_auth_internal_hashed in a private namespace
Kim Alvefur <zash@zash.se>
parents:
6702
diff
changeset
|
106 data[k:sub(#extended+1)] = v; |
353a7d4dfdc2
mod_storage_xep0227: Store data from mod_auth_internal_hashed in a private namespace
Kim Alvefur <zash@zash.se>
parents:
6702
diff
changeset
|
107 end |
353a7d4dfdc2
mod_storage_xep0227: Store data from mod_auth_internal_hashed in a private namespace
Kim Alvefur <zash@zash.se>
parents:
6702
diff
changeset
|
108 end |
353a7d4dfdc2
mod_storage_xep0227: Store data from mod_auth_internal_hashed in a private namespace
Kim Alvefur <zash@zash.se>
parents:
6702
diff
changeset
|
109 return data; |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
110 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
111 end; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
112 set = function(self, user, data) |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
113 if not data then |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
114 return self:_set_user_xml(user, self.host, nil); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
115 end |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
116 |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
117 local xml = self:_get_user_xml(user, self.host); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
118 if not xml then xml = createOuterXml(user, self.host); end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
119 local usere = getUserElement(xml); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
120 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
121 local account_properties = set.new(it.to_array(it.keys(data))); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
122 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
123 -- Include SCRAM credentials if known |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
124 if account_properties:contains_set(scram_properties) then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
125 local scram_el = st.stanza("scram-credentials", { xmlns = "urn:xmpp:pie:0#scram", mechanism = "SCRAM-"..scram_hash_name }) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
126 :text_tag("server-key", hex_to_base64(data.server_key)) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
127 :text_tag("stored-key", hex_to_base64(data.stored_key)) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
128 :text_tag("iter-count", ("%d"):format(data.iteration_count)) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
129 :text_tag("salt", base64.encode(data.salt)); |
11840
5e9e75c277a2
mod_storage_xep0227: Add scram-credentials to user element rather than server
Matthew Wild <mwild1@gmail.com>
parents:
11789
diff
changeset
|
130 usere:add_child(scram_el); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
131 account_properties:exclude(scram_properties); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
132 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
133 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
134 -- Include the password if present |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
135 if account_properties:contains("password") then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
136 usere.attr.password = data.password; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
137 account_properties:remove("password"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
138 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
139 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
140 -- Preserve remaining properties as namespaced attributes |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
141 for property in account_properties do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
142 usere.attr[extended..property] = data[property]; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
143 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
144 |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
145 return self:_set_user_xml(user, self.host, xml); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
146 end; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
147 }; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
148 handlers.vcard = { |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
149 get = function(self, user) |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
150 user = getUserElement(self:_get_user_xml(user, self.host)); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
151 if user then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
152 local vcard = user:get_child("vCard", 'vcard-temp'); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
153 if vcard then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
154 return st.preserialize(vcard); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
155 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
156 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
157 end; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
158 set = function(self, user, data) |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
159 local xml = self:_get_user_xml(user, self.host); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
160 local usere = xml and getUserElement(xml); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
161 if usere then |
12082
e87563fefd85
mod_storage_xep0227: Replace custom tag-removal helpers with :remove_children()
Matthew Wild <mwild1@gmail.com>
parents:
11840
diff
changeset
|
162 usere:remove_children("vCard", "vcard-temp"); |
12188
0fee75871f78
mod_storage_xep0227: be defensive against empty vCard
Jonas Schäfer <jonas@wielicki.name>
parents:
12185
diff
changeset
|
163 if not data or not data.attr then |
12082
e87563fefd85
mod_storage_xep0227: Replace custom tag-removal helpers with :remove_children()
Matthew Wild <mwild1@gmail.com>
parents:
11840
diff
changeset
|
164 -- No data to set, old one deleted, success |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
165 return true; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
166 end |
12082
e87563fefd85
mod_storage_xep0227: Replace custom tag-removal helpers with :remove_children()
Matthew Wild <mwild1@gmail.com>
parents:
11840
diff
changeset
|
167 local vcard = st.deserialize(data); |
e87563fefd85
mod_storage_xep0227: Replace custom tag-removal helpers with :remove_children()
Matthew Wild <mwild1@gmail.com>
parents:
11840
diff
changeset
|
168 usere:add_child(vcard); |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
169 return self:_set_user_xml(user, self.host, xml); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
170 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
171 return true; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
172 end; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
173 }; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
174 handlers.private = { |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
175 get = function(self, user) |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
176 user = getUserElement(self:_get_user_xml(user, self.host)); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
177 if user then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
178 local private = user:get_child("query", "jabber:iq:private"); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
179 if private then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
180 local r = {}; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
181 for _, tag in ipairs(private.tags) do |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
182 r[tag.name..":"..tag.attr.xmlns] = st.preserialize(tag); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
183 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
184 return r; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
185 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
186 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
187 end; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
188 set = function(self, user, data) |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
189 local xml = self:_get_user_xml(user, self.host); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
190 local usere = xml and getUserElement(xml); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
191 if usere then |
12082
e87563fefd85
mod_storage_xep0227: Replace custom tag-removal helpers with :remove_children()
Matthew Wild <mwild1@gmail.com>
parents:
11840
diff
changeset
|
192 usere:remove_children("query", "jabber:iq:private"); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
193 if data and next(data) ~= nil then |
12082
e87563fefd85
mod_storage_xep0227: Replace custom tag-removal helpers with :remove_children()
Matthew Wild <mwild1@gmail.com>
parents:
11840
diff
changeset
|
194 local private = st.stanza("query", {xmlns='jabber:iq:private'}); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
195 for _,tag in pairs(data) do |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
196 private:add_child(st.deserialize(tag)); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
197 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
198 usere:add_child(private); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
199 end |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
200 return self:_set_user_xml(user, self.host, xml); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
201 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
202 return true; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
203 end; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
204 }; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
205 |
8351
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
206 handlers.roster = { |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
207 get = function(self, user) |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
208 user = getUserElement(self:_get_user_xml(user, self.host)); |
8351
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
209 if user then |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
210 local roster = user:get_child("query", "jabber:iq:roster"); |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
211 if roster then |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
212 local r = { |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
213 [false] = { |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
214 version = roster.attr.version; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
215 pending = {}; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
216 } |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
217 }; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
218 for item in roster:childtags("item") do |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
219 r[item.attr.jid] = { |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
220 jid = item.attr.jid, |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
221 subscription = item.attr.subscription, |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
222 ask = item.attr.ask, |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
223 name = item.attr.name, |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
224 groups = {}; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
225 }; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
226 for group in item:childtags("group") do |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
227 r[item.attr.jid].groups[group:get_text()] = true; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
228 end |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
229 for pending in user:childtags("presence", "jabber:client") do |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
230 r[false].pending[pending.attr.from] = true; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
231 end |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
232 end |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
233 return r; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
234 end |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
235 end |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
236 end; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
237 set = function(self, user, data) |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
238 local xml = self:_get_user_xml(user, self.host); |
8351
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
239 local usere = xml and getUserElement(xml); |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
240 if usere then |
12185
708769a4c5da
mod_storage_xep0227: Fix luacheck warnings
Matthew Wild <mwild1@gmail.com>
parents:
12184
diff
changeset
|
241 local user_jid = jid_join(usere.name, self.host); |
12082
e87563fefd85
mod_storage_xep0227: Replace custom tag-removal helpers with :remove_children()
Matthew Wild <mwild1@gmail.com>
parents:
11840
diff
changeset
|
242 usere:remove_children("query", "jabber:iq:roster"); |
8351
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
243 usere:maptags(function (tag) |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
244 if tag.attr.xmlns == "jabber:client" and tag.name == "presence" and tag.attr.type == "subscribe" then |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
245 return nil; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
246 end |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
247 return tag; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
248 end); |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
249 if data and next(data) ~= nil then |
12082
e87563fefd85
mod_storage_xep0227: Replace custom tag-removal helpers with :remove_children()
Matthew Wild <mwild1@gmail.com>
parents:
11840
diff
changeset
|
250 local roster = st.stanza("query", {xmlns='jabber:iq:roster'}); |
8351
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
251 usere:add_child(roster); |
12183
e77c938ed92b
mod_storage_xep0227: Skip self-contacts on roster import
Matthew Wild <mwild1@gmail.com>
parents:
12176
diff
changeset
|
252 for contact_jid, item in pairs(data) do |
e77c938ed92b
mod_storage_xep0227: Skip self-contacts on roster import
Matthew Wild <mwild1@gmail.com>
parents:
12176
diff
changeset
|
253 if contact_jid ~= false then |
12189
82c8e855c850
mod_storage_xep0227: treat roster metadata pseudo-entry correctly
Jonas Schäfer <jonas@wielicki.name>
parents:
12188
diff
changeset
|
254 contact_jid = jid_bare(jid_prep(contact_jid)); |
12183
e77c938ed92b
mod_storage_xep0227: Skip self-contacts on roster import
Matthew Wild <mwild1@gmail.com>
parents:
12176
diff
changeset
|
255 if contact_jid ~= user_jid then -- Skip self-contacts |
e77c938ed92b
mod_storage_xep0227: Skip self-contacts on roster import
Matthew Wild <mwild1@gmail.com>
parents:
12176
diff
changeset
|
256 roster:tag("item", { |
e77c938ed92b
mod_storage_xep0227: Skip self-contacts on roster import
Matthew Wild <mwild1@gmail.com>
parents:
12176
diff
changeset
|
257 jid = contact_jid, |
e77c938ed92b
mod_storage_xep0227: Skip self-contacts on roster import
Matthew Wild <mwild1@gmail.com>
parents:
12176
diff
changeset
|
258 subscription = item.subscription, |
e77c938ed92b
mod_storage_xep0227: Skip self-contacts on roster import
Matthew Wild <mwild1@gmail.com>
parents:
12176
diff
changeset
|
259 ask = item.ask, |
e77c938ed92b
mod_storage_xep0227: Skip self-contacts on roster import
Matthew Wild <mwild1@gmail.com>
parents:
12176
diff
changeset
|
260 name = item.name, |
e77c938ed92b
mod_storage_xep0227: Skip self-contacts on roster import
Matthew Wild <mwild1@gmail.com>
parents:
12176
diff
changeset
|
261 }); |
e77c938ed92b
mod_storage_xep0227: Skip self-contacts on roster import
Matthew Wild <mwild1@gmail.com>
parents:
12176
diff
changeset
|
262 for group in pairs(item.groups) do |
e77c938ed92b
mod_storage_xep0227: Skip self-contacts on roster import
Matthew Wild <mwild1@gmail.com>
parents:
12176
diff
changeset
|
263 roster:tag("group"):text(group):up(); |
e77c938ed92b
mod_storage_xep0227: Skip self-contacts on roster import
Matthew Wild <mwild1@gmail.com>
parents:
12176
diff
changeset
|
264 end |
e77c938ed92b
mod_storage_xep0227: Skip self-contacts on roster import
Matthew Wild <mwild1@gmail.com>
parents:
12176
diff
changeset
|
265 roster:up(); -- move out from item |
8351
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
266 end |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
267 else |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
268 roster.attr.version = item.version; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
269 for pending_jid in pairs(item.pending) do |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
270 usere:add_child(st.presence({ from = pending_jid, type = "subscribe" })); |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
271 end |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
272 end |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
273 end |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
274 end |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
275 return self:_set_user_xml(user, self.host, xml); |
8351
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
276 end |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
277 return true; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
278 end; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
279 }; |
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
280 |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
281 -- PEP node configuration/etc. (not items) |
12457
8b7895266e99
mod_storage_xep0227: Support basic listing of PEP nodes in absence of pubsub#admin data
Kim Alvefur <zash@zash.se>
parents:
12456
diff
changeset
|
282 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
283 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
284 local lib_pubsub = module:require "pubsub"; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
285 handlers.pep = { |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
286 get = function (self, user) |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
287 local xml = self:_get_user_xml(user, self.host); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
288 local user_el = xml and getUserElement(xml); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
289 if not user_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
290 return nil; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
291 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
292 local nodes = { |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
293 --[[ |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
294 [node_name] = { |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
295 name = node_name; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
296 config = {}; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
297 affiliations = {}; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
298 subscribers = {}; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
299 }; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
300 ]] |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
301 }; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
302 local owner_el = user_el:get_child("pubsub", xmlns_pubsub_owner); |
12454
b2438f374b3e
mod_storage_xep0227: Handle missing {pubsub#owner}pubsub element (fixes #1740)
Matthew Wild <mwild1@gmail.com>
parents:
12355
diff
changeset
|
303 if not owner_el then |
12457
8b7895266e99
mod_storage_xep0227: Support basic listing of PEP nodes in absence of pubsub#admin data
Kim Alvefur <zash@zash.se>
parents:
12456
diff
changeset
|
304 local pubsub_el = user_el:get_child("pubsub", xmlns_pubsub); |
8b7895266e99
mod_storage_xep0227: Support basic listing of PEP nodes in absence of pubsub#admin data
Kim Alvefur <zash@zash.se>
parents:
12456
diff
changeset
|
305 if not pubsub_el then |
8b7895266e99
mod_storage_xep0227: Support basic listing of PEP nodes in absence of pubsub#admin data
Kim Alvefur <zash@zash.se>
parents:
12456
diff
changeset
|
306 return nil; |
8b7895266e99
mod_storage_xep0227: Support basic listing of PEP nodes in absence of pubsub#admin data
Kim Alvefur <zash@zash.se>
parents:
12456
diff
changeset
|
307 end |
8b7895266e99
mod_storage_xep0227: Support basic listing of PEP nodes in absence of pubsub#admin data
Kim Alvefur <zash@zash.se>
parents:
12456
diff
changeset
|
308 for node_el in pubsub_el:childtags("items") do |
12460
f7e40f1a5f53
mod_storage_xep0227: Fix mapping of nodes without explicit configuration
Kim Alvefur <zash@zash.se>
parents:
12458
diff
changeset
|
309 nodes[node_el.attr.node] = true; -- relies on COMPAT behavior in mod_pep |
12457
8b7895266e99
mod_storage_xep0227: Support basic listing of PEP nodes in absence of pubsub#admin data
Kim Alvefur <zash@zash.se>
parents:
12456
diff
changeset
|
310 end |
8b7895266e99
mod_storage_xep0227: Support basic listing of PEP nodes in absence of pubsub#admin data
Kim Alvefur <zash@zash.se>
parents:
12456
diff
changeset
|
311 return nodes; |
12454
b2438f374b3e
mod_storage_xep0227: Handle missing {pubsub#owner}pubsub element (fixes #1740)
Matthew Wild <mwild1@gmail.com>
parents:
12355
diff
changeset
|
312 end |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
313 for node_el in owner_el:childtags() do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
314 local node_name = node_el.attr.node; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
315 local node = nodes[node_name]; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
316 if not node then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
317 node = { |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
318 name = node_name; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
319 config = {}; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
320 affiliations = {}; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
321 subscribers = {}; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
322 }; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
323 nodes[node_name] = node; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
324 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
325 if node_el.name == "configure" then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
326 local form = node_el:get_child("x", "jabber:x:data"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
327 if form then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
328 node.config = lib_pubsub.node_config_form:data(form); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
329 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
330 elseif node_el.name == "affiliations" then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
331 for affiliation_el in node_el:childtags("affiliation") do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
332 local aff_jid = jid_prep(affiliation_el.attr.jid); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
333 local aff_value = affiliation_el.attr.affiliation; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
334 if aff_jid and aff_value then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
335 node.affiliations[aff_jid] = aff_value; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
336 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
337 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
338 elseif node_el.name == "subscriptions" then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
339 for subscription_el in node_el:childtags("subscription") do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
340 local sub_jid = jid_prep(subscription_el.attr.jid); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
341 local sub_state = subscription_el.attr.subscription; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
342 if sub_jid and sub_state == "subscribed" then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
343 local options; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
344 local subscription_options_el = subscription_el:get_child("options"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
345 if subscription_options_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
346 local options_form = subscription_options_el:get_child("x", "jabber:x:data"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
347 if options_form then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
348 options = lib_pubsub.subscription_options_form:data(options_form); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
349 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
350 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
351 node.subscribers[sub_jid] = options or true; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
352 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
353 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
354 else |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
355 module:log("warn", "Ignoring unknown pubsub element: %s", node_el.name); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
356 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
357 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
358 return nodes; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
359 end; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
360 set = function(self, user, data) |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
361 local xml = self:_get_user_xml(user, self.host); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
362 local user_el = xml and getUserElement(xml); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
363 if not user_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
364 return true; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
365 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
366 -- Remove existing data, if any |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
367 user_el:remove_children("pubsub", xmlns_pubsub_owner); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
368 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
369 -- Generate new data |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
370 local owner_el = st.stanza("pubsub", { xmlns = xmlns_pubsub_owner }); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
371 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
372 for node_name, node_data in pairs(data) do |
12174
a38b7cb5fd6a
mod_storage_xep0227: Support for exporting nodes with no stored configuration
Matthew Wild <mwild1@gmail.com>
parents:
12173
diff
changeset
|
373 if node_data == true then |
a38b7cb5fd6a
mod_storage_xep0227: Support for exporting nodes with no stored configuration
Matthew Wild <mwild1@gmail.com>
parents:
12173
diff
changeset
|
374 node_data = { config = {} }; |
a38b7cb5fd6a
mod_storage_xep0227: Support for exporting nodes with no stored configuration
Matthew Wild <mwild1@gmail.com>
parents:
12173
diff
changeset
|
375 end |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
376 local configure_el = st.stanza("configure", { node = node_name }) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
377 :add_child(lib_pubsub.node_config_form:form(node_data.config, "submit")); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
378 owner_el:add_child(configure_el); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
379 if node_data.affiliations and next(node_data.affiliations) ~= nil then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
380 local affiliations_el = st.stanza("affiliations", { node = node_name }); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
381 for aff_jid, aff_value in pairs(node_data.affiliations) do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
382 affiliations_el:tag("affiliation", { jid = aff_jid, affiliation = aff_value }):up(); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
383 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
384 owner_el:add_child(affiliations_el); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
385 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
386 if node_data.subscribers and next(node_data.subscribers) ~= nil then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
387 local subscriptions_el = st.stanza("subscriptions", { node = node_name }); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
388 for sub_jid, sub_data in pairs(node_data.subscribers) do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
389 local sub_el = st.stanza("subscription", { jid = sub_jid, subscribed = "subscribed" }); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
390 if sub_data ~= true then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
391 local options_form = lib_pubsub.subscription_options_form:form(sub_data, "submit"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
392 sub_el:tag("options"):add_child(options_form):up(); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
393 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
394 subscriptions_el:add_child(sub_el); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
395 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
396 owner_el:add_child(subscriptions_el); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
397 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
398 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
399 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
400 user_el:add_child(owner_el); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
401 |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
402 return self:_set_user_xml(user, self.host, xml); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
403 end; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
404 }; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
405 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
406 -- PEP items |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
407 handlers.pep_ = { |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
408 _stores = function (self, xml) --luacheck: ignore 212/self |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
409 local store_names = set.new(); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
410 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
411 local user_el = xml and getUserElement(xml); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
412 if not user_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
413 return store_names; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
414 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
415 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
416 -- Locate existing pubsub element, if any |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
417 local pubsub_el = user_el:get_child("pubsub", xmlns_pubsub); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
418 if not pubsub_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
419 return store_names; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
420 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
421 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
422 -- Find node items element, if any |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
423 for items_el in pubsub_el:childtags("items") do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
424 store_names:add("pep_"..items_el.attr.node); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
425 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
426 return store_names; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
427 end; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
428 find = function (self, user, query) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
429 -- query keys: limit, reverse, key (id) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
430 |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
431 local xml = self:_get_user_xml(user, self.host); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
432 local user_el = xml and getUserElement(xml); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
433 if not user_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
434 return nil, "no 227 user element found"; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
435 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
436 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
437 local node_name = self.datastore:match("^pep_(.+)$"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
438 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
439 -- Locate existing pubsub element, if any |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
440 local pubsub_el = user_el:get_child("pubsub", xmlns_pubsub); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
441 if not pubsub_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
442 return nil; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
443 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
444 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
445 -- Find node items element, if any |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
446 local node_items_el; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
447 for items_el in pubsub_el:childtags("items") do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
448 if items_el.attr.node == node_name then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
449 node_items_el = items_el; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
450 break; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
451 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
452 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
453 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
454 if not node_items_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
455 return nil; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
456 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
457 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
458 local user_jid = user.."@"..self.host; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
459 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
460 local results = {}; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
461 for item_el in node_items_el:childtags("item") do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
462 if query and query.key then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
463 if item_el.attr.id == query.key then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
464 table.insert(results, { item_el.attr.id, item_el.tags[1], 0, user_jid }); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
465 break; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
466 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
467 else |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
468 table.insert(results, { item_el.attr.id, item_el.tags[1], 0, user_jid }); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
469 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
470 if query and query.limit and #results >= query.limit then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
471 break; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
472 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
473 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
474 if query and query.reverse then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
475 return array.reverse(results); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
476 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
477 local i = 0; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
478 return function () |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
479 i = i + 1; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
480 local v = results[i]; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
481 if v == nil then return nil; end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
482 return unpack(v, 1, 4); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
483 end; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
484 end; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
485 append = function (self, user, key, payload, when, with) --luacheck: ignore 212/when 212/with 212/key |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
486 local xml = self:_get_user_xml(user, self.host); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
487 local user_el = xml and getUserElement(xml); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
488 if not user_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
489 return true; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
490 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
491 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
492 local node_name = self.datastore:match("^pep_(.+)$"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
493 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
494 -- Locate existing pubsub element, if any |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
495 local pubsub_el = user_el:get_child("pubsub", xmlns_pubsub); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
496 if not pubsub_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
497 pubsub_el = st.stanza("pubsub", { xmlns = xmlns_pubsub }); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
498 user_el:add_child(pubsub_el); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
499 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
500 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
501 -- Find node items element, if any |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
502 local node_items_el; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
503 for items_el in pubsub_el:childtags("items") do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
504 if items_el.attr.node == node_name then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
505 node_items_el = items_el; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
506 break; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
507 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
508 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
509 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
510 if not node_items_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
511 -- Doesn't exist yet, create one |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
512 node_items_el = st.stanza("items", { node = node_name }); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
513 pubsub_el:add_child(node_items_el); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
514 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
515 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
516 -- Append item to pubsub_el |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
517 local item_el = st.stanza("item", { id = key }) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
518 :add_child(payload); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
519 node_items_el:add_child(item_el); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
520 |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
521 return self:_set_user_xml(user, self.host, xml); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
522 end; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
523 delete = function (self, user, query) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
524 -- query keys: limit, reverse, key (id) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
525 |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
526 local xml = self:_get_user_xml(user, self.host); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
527 local user_el = xml and getUserElement(xml); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
528 if not user_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
529 return nil, "no 227 user element found"; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
530 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
531 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
532 local node_name = self.datastore:match("^pep_(.+)$"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
533 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
534 -- Locate existing pubsub element, if any |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
535 local pubsub_el = user_el:get_child("pubsub", xmlns_pubsub); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
536 if not pubsub_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
537 return nil; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
538 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
539 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
540 -- Find node items element, if any |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
541 local node_items_el; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
542 for items_el in pubsub_el:childtags("items") do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
543 if items_el.attr.node == node_name then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
544 node_items_el = items_el; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
545 break; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
546 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
547 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
548 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
549 if not node_items_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
550 return nil; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
551 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
552 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
553 local results = array(); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
554 for item_el in pubsub_el:childtags("item") do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
555 if query and query.key then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
556 if item_el.attr.id == query.key then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
557 table.insert(results, item_el); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
558 break; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
559 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
560 else |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
561 table.insert(results, item_el); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
562 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
563 if query and query.limit and #results >= query.limit then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
564 break; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
565 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
566 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
567 if query and query.truncate then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
568 results:sub(-query.truncate); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
569 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
570 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
571 -- Actually remove the matching items |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
572 local delete_keys = set.new(results:map(function (item) return item.attr.id; end)); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
573 pubsub_el:maptags(function (item_el) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
574 if delete_keys:contains(item_el.attr.id) then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
575 return nil; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
576 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
577 return item_el; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
578 end); |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
579 return self:_set_user_xml(user, self.host, xml); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
580 end; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
581 }; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
582 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
583 -- MAM archives |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
584 local xmlns_pie_mam = "urn:xmpp:pie:0#mam"; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
585 handlers.archive = { |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
586 find = function (self, user, query) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
587 assert(query == nil, "XEP-0313 queries are not supported on XEP-0227 files"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
588 |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
589 local xml = self:_get_user_xml(user, self.host); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
590 local user_el = xml and getUserElement(xml); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
591 if not user_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
592 return nil, "no 227 user element found"; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
593 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
594 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
595 -- Locate existing archive element, if any |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
596 local archive_el = user_el:get_child("archive", xmlns_pie_mam); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
597 if not archive_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
598 return nil; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
599 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
600 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
601 local user_jid = user.."@"..self.host; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
602 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
603 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
604 local f, s, result_el = archive_el:childtags("result", "urn:xmpp:mam:2"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
605 return function () |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
606 result_el = f(s, result_el); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
607 if not result_el then return nil; end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
608 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
609 local id = result_el.attr.id; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
610 local item = result_el:find("{urn:xmpp:forward:0}forwarded/{jabber:client}message"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
611 assert(item, "Invalid stanza in XEP-0227 archive"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
612 local when = dt.parse(result_el:find("{urn:xmpp:forward:0}forwarded/{urn:xmpp:delay}delay@stamp")); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
613 local to_bare, from_bare = jid_bare(item.attr.to), jid_bare(item.attr.from); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
614 local with = to_bare == user_jid and from_bare or to_bare; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
615 -- id, item, when, with |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
616 return id, item, when, with; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
617 end; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
618 end; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
619 append = function (self, user, key, payload, when, with) --luacheck: ignore 212/when 212/with 212/key |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
620 local xml = self:_get_user_xml(user, self.host); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
621 local user_el = xml and getUserElement(xml); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
622 if not user_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
623 return true; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
624 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
625 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
626 -- Locate existing archive element, if any |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
627 local archive_el = user_el:get_child("archive", xmlns_pie_mam); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
628 if not archive_el then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
629 archive_el = st.stanza("archive", { xmlns = xmlns_pie_mam }); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
630 user_el:add_child(archive_el); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
631 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
632 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
633 local item = st.clone(payload); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
634 item.attr.xmlns = "jabber:client"; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
635 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
636 local result_el = st.stanza("result", { xmlns = "urn:xmpp:mam:2", id = key }) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
637 :tag("forwarded", { xmlns = "urn:xmpp:forward:0" }) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
638 :tag("delay", { xmlns = "urn:xmpp:delay", stamp = dt.datetime(when) }):up() |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
639 :add_child(item) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
640 :up(); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
641 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
642 -- Append item to archive_el |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
643 archive_el:add_child(result_el); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
644 |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
645 return self:_set_user_xml(user, self.host, xml); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
646 end; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
647 }; |
8351
cc05b6366576
mod_storage_xep0227: Add roster storage (fixes #1023)
Kim Alvefur <zash@zash.se>
parents:
8350
diff
changeset
|
648 |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
649 ----------------------------- |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
650 local driver = {}; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
651 |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
652 local function users(self) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
653 local file_patt = "^.*@"..(self.host:gsub("%p", "%%%1")).."%.xml$"; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
654 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
655 local f, s, filename = lfs.dir(prosody.paths.data); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
656 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
657 return function () |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
658 filename = f(s, filename); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
659 while filename and not filename:match(file_patt) do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
660 filename = f(s, filename); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
661 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
662 if not filename then return nil; end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
663 return filename:match("^[^@]+"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
664 end; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
665 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
666 |
8352
6ff50541d2a6
mod_storage_xep0227: Ignore unused 'self' argument [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8351
diff
changeset
|
667 function driver:open(datastore, typ) -- luacheck: ignore 212/self |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
668 if typ and typ ~= "keyval" and typ ~= "archive" then return nil, "unsupported-store"; end |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
669 local handler = handlers[datastore]; |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
670 if not handler and datastore:match("^pep_") then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
671 handler = handlers.pep_; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
672 end |
6701
88a25c364a14
mod_storage_xep0227: Update open method for current API
Kim Alvefur <zash@zash.se>
parents:
6700
diff
changeset
|
673 if not handler then return nil, "unsupported-datastore"; end |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
674 local instance = setmetatable({ |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
675 host = module.host; |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
676 datastore = datastore; |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
677 users = users; |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
678 _get_user_xml = assert(default_get_user_xml); |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
679 _set_user_xml = default_set_user_xml; |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
680 }, { |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
681 __index = handler; |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
682 } |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
683 ); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
684 if instance.init then instance:init(); end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
685 return instance; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
686 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
687 |
12173
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
688 -- Custom API that allows some configuration |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
689 function driver:open_xep0227(datastore, typ, options) |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
690 local instance, err = self:open(datastore, typ); |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
691 if not instance then |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
692 return instance, err; |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
693 end |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
694 if options then |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
695 instance._set_user_xml = assert(options.set_user_xml); |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
696 instance._get_user_xml = assert(options.get_user_xml); |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
697 end |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
698 return instance; |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
699 end |
270047afa6af
mod_storage_xep0227: Allow overriding the input/output layer for XEP-0227 data
Matthew Wild <mwild1@gmail.com>
parents:
12082
diff
changeset
|
700 |
12184
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
701 local function get_store_names_from_xml(self, user_xml) |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
702 local stores = set.new(); |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
703 for handler_name, handler_funcs in pairs(handlers) do |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
704 if handler_funcs._stores then |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
705 stores:include(handler_funcs._stores(self, user_xml)); |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
706 else |
12194
9965d7d126c7
mod_storage_xep0227: Fix traceback during iteration of driver stores
Matthew Wild <mwild1@gmail.com>
parents:
12193
diff
changeset
|
707 stores:add(handler_name); |
12184
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
708 end |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
709 end |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
710 return stores; |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
711 end |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
712 |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
713 local function get_store_names(self, path) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
714 local stores = set.new(); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
715 local f, err = io_open(paths.join(prosody.paths.data, path)); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
716 if not f then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
717 module:log("warn", "Unable to load XML file for <%s>: %s", "store listing", err); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
718 return stores; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
719 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
720 module:log("info", "Loaded %s", path); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
721 local s = f:read("*a"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
722 f:close(); |
12184
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
723 local user_xml = parse_xml_real(s); |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
724 return get_store_names_from_xml(self, user_xml); |
11789
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
725 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
726 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
727 function driver:stores(username) |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
728 local store_dir = prosody.paths.data; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
729 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
730 local mode, err = lfs.attributes(store_dir, "mode"); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
731 if not mode then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
732 return function() module:log("debug", "Could not iterate over stores in %s: %s", store_dir, err); end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
733 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
734 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
735 local file_patt = "^.*@"..(module.host:gsub("%p", "%%%1")).."%.xml$"; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
736 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
737 local all_users = username == true; |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
738 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
739 local store_names = set.new(); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
740 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
741 for filename in lfs.dir(prosody.paths.data) do |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
742 if filename:match(file_patt) then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
743 if all_users or filename == username.."@"..module.host..".xml" then |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
744 store_names:include(get_store_names(self, filename)); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
745 if not all_users then break; end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
746 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
747 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
748 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
749 |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
750 return store_names:items(); |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
751 end |
f3085620b6ff
mod_storage_xep0227: Update for XEP-0227 r1.1: Support for SCRAM, MAM, PEP
Matthew Wild <mwild1@gmail.com>
parents:
8352
diff
changeset
|
752 |
12184
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
753 function driver:xep0227_user_stores(username, host) |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
754 local user_xml = self:_get_user_xml(username, host); |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
755 if not user_xml then |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
756 return nil; |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
757 end |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
758 local store_names = get_store_names_from_xml(username, host); |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
759 return store_names:items(); |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
760 end |
326f5466ddc7
mod_storage_xep0227: Add API to iterate all stores of a user
Matthew Wild <mwild1@gmail.com>
parents:
12183
diff
changeset
|
761 |
5121
b5a5643f8572
core.storagemanager, mod_storage_*: "data-driver" -> "storage-provider", to allow using module:provides().
Waqas Hussain <waqas20@gmail.com>
parents:
3414
diff
changeset
|
762 module:provides("storage", driver); |