Annotate

core/rostermanager.lua @ 11503:7adda14945ad

mod_http_file_share: Include expiry time of the upload itself in token Lets an external upload service know this so it can do expiry itself. Could possibly have been calculated based on the token expiry or issuance time, explicit > implicit.
author Kim Alvefur <zash@zash.se>
date Mon, 05 Apr 2021 17:21:18 +0200
parent 10570:962efe23975d
child 12387:05c250fa335a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1523
841d61be198f Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents: 1380
diff changeset
1 -- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2050
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2050
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5747
diff changeset
4 --
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
6 -- COPYING file in the source package for more information.
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 268
diff changeset
7 --
7949
8acc35b5355a core: Allow select core modules to mutate some globals (needs luacheck 1.19)
Kim Alvefur <zash@zash.se>
parents: 7779
diff changeset
8 -- luacheck: globals prosody.bare_sessions.?.roster
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 268
diff changeset
9
0
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
10
263
75275b6b4e03 Update rostermanager to use new logger
Matthew Wild <mwild1@gmail.com>
parents: 193
diff changeset
11
75275b6b4e03 Update rostermanager to use new logger
Matthew Wild <mwild1@gmail.com>
parents: 193
diff changeset
12 local log = require "util.logger".init("rostermanager");
0
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
13
9303
72f0862978ef rostermanager: Use util.id to generate ids for roster pushed
Matthew Wild <mwild1@gmail.com>
parents: 8717
diff changeset
14 local new_id = require "util.id".short;
10569
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
15 local new_cache = require "util.cache".new;
9303
72f0862978ef rostermanager: Use util.id to generate ids for roster pushed
Matthew Wild <mwild1@gmail.com>
parents: 8717
diff changeset
16
5348
ca0d820e9318 rostermanager: Remove unused imports
Kim Alvefur <zash@zash.se>
parents: 5060
diff changeset
17 local pairs = pairs;
916
f0743928ef7e core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
18 local tostring = tostring;
6622
fb60cee2144e rostermanager: Add missing import of `type()`
Florian Zeitz <florob@babelmonkeys.de>
parents: 6616
diff changeset
19 local type = type;
0
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
20
8717
9ddd0fbbe53a core: Use prosody.hosts instead of _G.hosts for consistency
Kim Alvefur <zash@zash.se>
parents: 8555
diff changeset
21 local hosts = prosody.hosts;
6550
a335d02951b3 rostermanager: Access bare_sessions through prosody.bare_sessions
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
22 local bare_sessions = prosody.bare_sessions;
103
ebdb7875443e Fixed: Typos caused by lack of sleep.
Waqas Hussain <waqas20@gmail.com>
parents: 101
diff changeset
23
5429
25333de6e7c7 rostermanager: do not save rosters for unexistant users.
Marco Cirillo <maranda@lightwitch.org>
parents: 5348
diff changeset
24 local um_user_exists = require "core.usermanager".user_exists;
107
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
25 local st = require "util.stanza";
7167
7ae430fecf12 rostermanager: Require storagemanager at the top, fixes traceback on Lua 5.2
Matthew Wild <mwild1@gmail.com>
parents: 7155
diff changeset
26 local storagemanager = require "core.storagemanager";
0
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
27
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
28 local _ENV = nil;
8555
4f0f5b49bb03 vairious: Add annotation when an empty environment is set [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8496
diff changeset
29 -- luacheck: std none
0
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
30
6787
ad64e2eacd0e rostermanager: Add forward declarations
Kim Alvefur <zash@zash.se>
parents: 6779
diff changeset
31 local save_roster; -- forward declaration
ad64e2eacd0e rostermanager: Add forward declarations
Kim Alvefur <zash@zash.se>
parents: 6779
diff changeset
32
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
33 local function add_to_roster(session, jid, item)
107
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
34 if session.roster then
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
35 local old_item = session.roster[jid];
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
36 session.roster[jid] = item;
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
37 if save_roster(session.username, session.host, nil, jid) then
107
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
38 return true;
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
39 else
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
40 session.roster[jid] = old_item;
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
41 return nil, "wait", "internal-server-error", "Unable to save roster";
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
42 end
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
43 else
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
44 return nil, "auth", "not-authorized", "Session's roster not loaded";
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
45 end
101
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
46 end
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
47
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
48 local function remove_from_roster(session, jid)
107
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
49 if session.roster then
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
50 local old_item = session.roster[jid];
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
51 session.roster[jid] = nil;
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
52 if save_roster(session.username, session.host, nil, jid) then
107
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
53 return true;
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
54 else
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
55 session.roster[jid] = old_item;
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
56 return nil, "wait", "internal-server-error", "Unable to save roster";
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
57 end
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
58 else
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
59 return nil, "auth", "not-authorized", "Session's roster not loaded";
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
60 end
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
61 end
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
62
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
63 local function roster_push(username, host, jid)
6613
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
64 local roster = jid and hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster;
916
f0743928ef7e core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
65 if roster then
107
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
66 local item = hosts[host].sessions[username].roster[jid];
9303
72f0862978ef rostermanager: Use util.id to generate ids for roster pushed
Matthew Wild <mwild1@gmail.com>
parents: 8717
diff changeset
67 local stanza = st.iq({type="set", id=new_id()});
916
f0743928ef7e core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
68 stanza:tag("query", {xmlns = "jabber:iq:roster", ver = tostring(roster[false].version or "1") });
107
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
69 if item then
132
9a4aa57af367 Roster updates
Waqas Hussain <waqas20@gmail.com>
parents: 114
diff changeset
70 stanza:tag("item", {jid = jid, subscription = item.subscription, name = item.name, ask = item.ask});
110
bb5ac5976a97 Fixed: Roster support
Waqas Hussain <waqas20@gmail.com>
parents: 107
diff changeset
71 for group in pairs(item.groups) do
bb5ac5976a97 Fixed: Roster support
Waqas Hussain <waqas20@gmail.com>
parents: 107
diff changeset
72 stanza:tag("group"):text(group):up();
bb5ac5976a97 Fixed: Roster support
Waqas Hussain <waqas20@gmail.com>
parents: 107
diff changeset
73 end
107
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
74 else
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
75 stanza:tag("item", {jid = jid, subscription = "remove"});
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
76 end
193
13ac34255c37 mod_roster fix
Waqas Hussain <waqas20@gmail.com>
parents: 183
diff changeset
77 stanza:up(); -- move out from item
13ac34255c37 mod_roster fix
Waqas Hussain <waqas20@gmail.com>
parents: 183
diff changeset
78 stanza:up(); -- move out from stanza
107
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
79 -- stanza ready
110
bb5ac5976a97 Fixed: Roster support
Waqas Hussain <waqas20@gmail.com>
parents: 107
diff changeset
80 for _, session in pairs(hosts[host].sessions[username].sessions) do
114
bed2a8508cf5 Added session property for interested resources
Waqas Hussain <waqas20@gmail.com>
parents: 110
diff changeset
81 if session.interested then
110
bb5ac5976a97 Fixed: Roster support
Waqas Hussain <waqas20@gmail.com>
parents: 107
diff changeset
82 session.send(stanza);
107
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
83 end
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
84 end
8d8debda3df2 Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents: 103
diff changeset
85 end
101
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
86 end
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
87
6613
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
88 local function roster_metadata(roster, err)
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
89 local metadata = roster[false];
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
90 if not metadata then
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
91 metadata = { broken = err or nil };
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
92 roster[false] = metadata;
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
93 end
6624
7f9b49f2758a rostermanager: Fix roster upgrade code (thanks mva)
Kim Alvefur <zash@zash.se>
parents: 6622
diff changeset
94 if roster.pending and type(roster.pending.subscription) ~= "string" then
7f9b49f2758a rostermanager: Fix roster upgrade code (thanks mva)
Kim Alvefur <zash@zash.se>
parents: 6622
diff changeset
95 metadata.pending = roster.pending;
7f9b49f2758a rostermanager: Fix roster upgrade code (thanks mva)
Kim Alvefur <zash@zash.se>
parents: 6622
diff changeset
96 roster.pending = nil;
7f9b49f2758a rostermanager: Fix roster upgrade code (thanks mva)
Kim Alvefur <zash@zash.se>
parents: 6622
diff changeset
97 elseif not metadata.pending then
7f9b49f2758a rostermanager: Fix roster upgrade code (thanks mva)
Kim Alvefur <zash@zash.se>
parents: 6622
diff changeset
98 metadata.pending = {};
6613
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
99 end
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
100 return metadata;
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
101 end
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
102
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
103 local function load_roster(username, host)
2048
d420722519e1 rostermanager: Log a warning when a self-contact is detected.
Waqas Hussain <waqas20@gmail.com>
parents: 2047
diff changeset
104 local jid = username.."@"..host;
4993
5243b74a4cbb Hopefully inert commit to clean up logging across a number of modules, removing all cases of concatenation when building log messages
Matthew Wild <mwild1@gmail.com>
parents: 3129
diff changeset
105 log("debug", "load_roster: asked for: %s", jid);
2049
227f3fd2caaf rostermanager: Refactored roster loading to remove duplicate code.
Waqas Hussain <waqas20@gmail.com>
parents: 2048
diff changeset
106 local user = bare_sessions[jid];
1380
9b3b43b8963a rostermanager: Fire event on roster load
Matthew Wild <mwild1@gmail.com>
parents: 925
diff changeset
107 local roster;
2049
227f3fd2caaf rostermanager: Refactored roster loading to remove duplicate code.
Waqas Hussain <waqas20@gmail.com>
parents: 2048
diff changeset
108 if user then
227f3fd2caaf rostermanager: Refactored roster loading to remove duplicate code.
Waqas Hussain <waqas20@gmail.com>
parents: 2048
diff changeset
109 roster = user.roster;
227f3fd2caaf rostermanager: Refactored roster loading to remove duplicate code.
Waqas Hussain <waqas20@gmail.com>
parents: 2048
diff changeset
110 if roster then return roster; end
8356
bbd18b617296 rostermanager: Simplify logging.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8147
diff changeset
111 log("debug", "load_roster: loading for new user: %s", jid);
2049
227f3fd2caaf rostermanager: Refactored roster loading to remove duplicate code.
Waqas Hussain <waqas20@gmail.com>
parents: 2048
diff changeset
112 else -- Attempt to load roster for non-loaded user
8356
bbd18b617296 rostermanager: Simplify logging.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8147
diff changeset
113 log("debug", "load_roster: loading for offline user: %s", jid);
101
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
114 end
10569
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
115 local roster_cache = hosts[host] and hosts[host].roster_cache;
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
116 if not roster_cache then
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
117 if hosts[host] then
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
118 roster_cache = new_cache(1024);
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
119 hosts[host].roster_cache = roster_cache;
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
120 end
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
121 else
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
122 roster = roster_cache:get(jid);
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
123 if roster then
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
124 log("debug", "load_roster: cache hit");
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
125 roster_cache:set(jid, roster);
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
126 if user then user.roster = roster; end
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
127 return roster;
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
128 else
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
129 log("debug", "load_roster: cache miss, loading from storage");
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
130 end
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
131 end
7167
7ae430fecf12 rostermanager: Require storagemanager at the top, fixes traceback on Lua 5.2
Matthew Wild <mwild1@gmail.com>
parents: 7155
diff changeset
132 local roster_store = storagemanager.open(host, "roster", "keyval");
7154
b3b92204802f rostermanager: Use storagemanager
Kim Alvefur <zash@zash.se>
parents: 7064
diff changeset
133 local data, err = roster_store:get(username);
3087
9b31e36528e0 rostermanager: When loading the roster, also return a datamanager error if available.
Waqas Hussain <waqas20@gmail.com>
parents: 2925
diff changeset
134 roster = data or {};
2049
227f3fd2caaf rostermanager: Refactored roster loading to remove duplicate code.
Waqas Hussain <waqas20@gmail.com>
parents: 2048
diff changeset
135 if user then user.roster = roster; end
8496
9b81c22d5b54 rostermanager: Explicitly remove old-style 'pending' table from rosters (or it stays forever due to map stores)
Kim Alvefur <zash@zash.se>
parents: 8361
diff changeset
136 local legacy_pending = roster.pending and type(roster.pending.subscription) ~= "string";
6613
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
137 roster_metadata(roster, err);
8496
9b81c22d5b54 rostermanager: Explicitly remove old-style 'pending' table from rosters (or it stays forever due to map stores)
Kim Alvefur <zash@zash.se>
parents: 8361
diff changeset
138 if legacy_pending then
9b81c22d5b54 rostermanager: Explicitly remove old-style 'pending' table from rosters (or it stays forever due to map stores)
Kim Alvefur <zash@zash.se>
parents: 8361
diff changeset
139 -- Due to map store use, we need to manually delete this entry
9b81c22d5b54 rostermanager: Explicitly remove old-style 'pending' table from rosters (or it stays forever due to map stores)
Kim Alvefur <zash@zash.se>
parents: 8361
diff changeset
140 log("debug", "Removing legacy 'pending' entry");
9b81c22d5b54 rostermanager: Explicitly remove old-style 'pending' table from rosters (or it stays forever due to map stores)
Kim Alvefur <zash@zash.se>
parents: 8361
diff changeset
141 if not save_roster(username, host, roster, "pending") then
9b81c22d5b54 rostermanager: Explicitly remove old-style 'pending' table from rosters (or it stays forever due to map stores)
Kim Alvefur <zash@zash.se>
parents: 8361
diff changeset
142 log("warn", "Could not remove legacy 'pendig' entry");
9b81c22d5b54 rostermanager: Explicitly remove old-style 'pending' table from rosters (or it stays forever due to map stores)
Kim Alvefur <zash@zash.se>
parents: 8361
diff changeset
143 end
9b81c22d5b54 rostermanager: Explicitly remove old-style 'pending' table from rosters (or it stays forever due to map stores)
Kim Alvefur <zash@zash.se>
parents: 8361
diff changeset
144 end
2048
d420722519e1 rostermanager: Log a warning when a self-contact is detected.
Waqas Hussain <waqas20@gmail.com>
parents: 2047
diff changeset
145 if roster[jid] then
d420722519e1 rostermanager: Log a warning when a self-contact is detected.
Waqas Hussain <waqas20@gmail.com>
parents: 2047
diff changeset
146 roster[jid] = nil;
8359
467ca83e6c0e rostermanager: Demote warning to debug message
Kim Alvefur <zash@zash.se>
parents: 8358
diff changeset
147 log("debug", "Roster for %s had a self-contact, removing", jid);
8361
6af950b834a6 rostermanager: Log warning if removal self-contact failed
Kim Alvefur <zash@zash.se>
parents: 8360
diff changeset
148 if not save_roster(username, host, roster, jid) then
6af950b834a6 rostermanager: Log warning if removal self-contact failed
Kim Alvefur <zash@zash.se>
parents: 8360
diff changeset
149 log("warn", "Could not remove self-contact from roster for %s", jid);
6af950b834a6 rostermanager: Log warning if removal self-contact failed
Kim Alvefur <zash@zash.se>
parents: 8360
diff changeset
150 end
2048
d420722519e1 rostermanager: Log a warning when a self-contact is detected.
Waqas Hussain <waqas20@gmail.com>
parents: 2047
diff changeset
151 end
3090
f14d2962f32c rostermanager: Don't fire roster-load event if there was an error loading the roster
Matthew Wild <mwild1@gmail.com>
parents: 3087
diff changeset
152 if not err then
5747
23076ee191d3 rostermanager, mod_groups: Change roster-load event to pass an event table for consistency
Matthew Wild <mwild1@gmail.com>
parents: 5429
diff changeset
153 hosts[host].events.fire_event("roster-load", { username = username, host = host, roster = roster });
3090
f14d2962f32c rostermanager: Don't fire roster-load event if there was an error loading the roster
Matthew Wild <mwild1@gmail.com>
parents: 3087
diff changeset
154 end
10569
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
155 if roster_cache and not user then
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
156 log("debug", "load_roster: caching loaded roster");
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
157 roster_cache:set(jid, roster);
fdc2bae50100 core.rostermanager: Cache rosters of offline users for faster access (fixes #1233)
Kim Alvefur <zash@zash.se>
parents: 9303
diff changeset
158 end
3087
9b31e36528e0 rostermanager: When loading the roster, also return a datamanager error if available.
Waqas Hussain <waqas20@gmail.com>
parents: 2925
diff changeset
159 return roster, err;
101
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
160 end
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
161
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
162 function save_roster(username, host, roster, jid)
5429
25333de6e7c7 rostermanager: do not save rosters for unexistant users.
Marco Cirillo <maranda@lightwitch.org>
parents: 5348
diff changeset
163 if not um_user_exists(username, host) then
25333de6e7c7 rostermanager: do not save rosters for unexistant users.
Marco Cirillo <maranda@lightwitch.org>
parents: 5348
diff changeset
164 log("debug", "not saving roster for %s@%s: the user doesn't exist", username, host);
25333de6e7c7 rostermanager: do not save rosters for unexistant users.
Marco Cirillo <maranda@lightwitch.org>
parents: 5348
diff changeset
165 return nil;
25333de6e7c7 rostermanager: do not save rosters for unexistant users.
Marco Cirillo <maranda@lightwitch.org>
parents: 5348
diff changeset
166 end
25333de6e7c7 rostermanager: do not save rosters for unexistant users.
Marco Cirillo <maranda@lightwitch.org>
parents: 5348
diff changeset
167
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
168 log("debug", "save_roster: saving roster for %s@%s, (%s)", username, host, jid or "all contacts");
1897
6d81e74310a7 rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
169 if not roster then
6d81e74310a7 rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
170 roster = hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster;
6d81e74310a7 rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
171 --if not roster then
6d81e74310a7 rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
172 -- --roster = load_roster(username, host);
6d81e74310a7 rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
173 -- return true; -- roster unchanged, no reason to save
6d81e74310a7 rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
174 --end
6d81e74310a7 rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
175 end
6d81e74310a7 rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
176 if roster then
6613
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
177 local metadata = roster_metadata(roster);
2909
bcfd76cc9b7d rostermanager: Don't bump the roster version if it is == true (ie. we are not versioning the roster)
Matthew Wild <mwild1@gmail.com>
parents: 2050
diff changeset
178 if metadata.version ~= true then
bcfd76cc9b7d rostermanager: Don't bump the roster version if it is == true (ie. we are not versioning the roster)
Matthew Wild <mwild1@gmail.com>
parents: 2050
diff changeset
179 metadata.version = (metadata.version or 0) + 1;
bcfd76cc9b7d rostermanager: Don't bump the roster version if it is == true (ie. we are not versioning the roster)
Matthew Wild <mwild1@gmail.com>
parents: 2050
diff changeset
180 end
6613
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
181 if metadata.broken then return nil, "Not saving broken roster" end
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
182 if jid == nil then
7167
7ae430fecf12 rostermanager: Require storagemanager at the top, fixes traceback on Lua 5.2
Matthew Wild <mwild1@gmail.com>
parents: 7155
diff changeset
183 local roster_store = storagemanager.open(host, "roster", "keyval");
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
184 return roster_store:set(username, roster);
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
185 else
7167
7ae430fecf12 rostermanager: Require storagemanager at the top, fixes traceback on Lua 5.2
Matthew Wild <mwild1@gmail.com>
parents: 7155
diff changeset
186 local roster_store = storagemanager.open(host, "roster", "map");
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
187 return roster_store:set_keys(username, { [false] = metadata, [jid] = roster[jid] or roster_store.remove });
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
188 end
101
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
189 end
916
f0743928ef7e core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
190 log("warn", "save_roster: user had no roster to save");
101
c690fa382743 Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents: 80
diff changeset
191 return nil;
0
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
192 end
80
523ac742cc19 Fixed: rostermanager.lua now returns the module
Waqas Hussain <waqas20@gmail.com>
parents: 6
diff changeset
193
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
194 local function process_inbound_subscription_approval(username, host, jid)
171
28f420d057a0 Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents: 132
diff changeset
195 local roster = load_roster(username, host);
28f420d057a0 Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents: 132
diff changeset
196 local item = roster[jid];
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
197 if item and item.ask then
171
28f420d057a0 Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents: 132
diff changeset
198 if item.subscription == "none" then
28f420d057a0 Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents: 132
diff changeset
199 item.subscription = "to";
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
200 else -- subscription == from
171
28f420d057a0 Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents: 132
diff changeset
201 item.subscription = "both";
28f420d057a0 Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents: 132
diff changeset
202 end
28f420d057a0 Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents: 132
diff changeset
203 item.ask = nil;
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
204 return save_roster(username, host, roster, jid);
171
28f420d057a0 Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents: 132
diff changeset
205 end
28f420d057a0 Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents: 132
diff changeset
206 end
28f420d057a0 Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents: 132
diff changeset
207
6787
ad64e2eacd0e rostermanager: Add forward declarations
Kim Alvefur <zash@zash.se>
parents: 6779
diff changeset
208 local is_contact_pending_out -- forward declaration
ad64e2eacd0e rostermanager: Add forward declarations
Kim Alvefur <zash@zash.se>
parents: 6779
diff changeset
209
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
210 local function process_inbound_subscription_cancellation(username, host, jid)
172
71247788c7c7 Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents: 171
diff changeset
211 local roster = load_roster(username, host);
71247788c7c7 Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents: 171
diff changeset
212 local item = roster[jid];
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
213 local changed = nil;
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
214 if is_contact_pending_out(username, host, jid) then
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
215 item.ask = nil;
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
216 changed = true;
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
217 end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
218 if item then
172
71247788c7c7 Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents: 171
diff changeset
219 if item.subscription == "to" then
71247788c7c7 Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents: 171
diff changeset
220 item.subscription = "none";
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
221 changed = true;
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
222 elseif item.subscription == "both" then
172
71247788c7c7 Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents: 171
diff changeset
223 item.subscription = "from";
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
224 changed = true;
172
71247788c7c7 Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents: 171
diff changeset
225 end
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
226 end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
227 if changed then
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
228 return save_roster(username, host, roster, jid);
172
71247788c7c7 Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents: 171
diff changeset
229 end
71247788c7c7 Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents: 171
diff changeset
230 end
71247788c7c7 Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents: 171
diff changeset
231
6787
ad64e2eacd0e rostermanager: Add forward declarations
Kim Alvefur <zash@zash.se>
parents: 6779
diff changeset
232 local is_contact_pending_in -- forward declaration
ad64e2eacd0e rostermanager: Add forward declarations
Kim Alvefur <zash@zash.se>
parents: 6779
diff changeset
233
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
234 local function process_inbound_unsubscribe(username, host, jid)
173
f3a2af4d2ff2 Inbound unsubscribe
Waqas Hussain <waqas20@gmail.com>
parents: 172
diff changeset
235 local roster = load_roster(username, host);
f3a2af4d2ff2 Inbound unsubscribe
Waqas Hussain <waqas20@gmail.com>
parents: 172
diff changeset
236 local item = roster[jid];
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
237 local changed = nil;
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
238 if is_contact_pending_in(username, host, jid) then
6613
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
239 roster[false].pending[jid] = nil;
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
240 changed = true;
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
241 end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
242 if item then
173
f3a2af4d2ff2 Inbound unsubscribe
Waqas Hussain <waqas20@gmail.com>
parents: 172
diff changeset
243 if item.subscription == "from" then
f3a2af4d2ff2 Inbound unsubscribe
Waqas Hussain <waqas20@gmail.com>
parents: 172
diff changeset
244 item.subscription = "none";
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
245 changed = true;
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
246 elseif item.subscription == "both" then
173
f3a2af4d2ff2 Inbound unsubscribe
Waqas Hussain <waqas20@gmail.com>
parents: 172
diff changeset
247 item.subscription = "to";
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
248 changed = true;
173
f3a2af4d2ff2 Inbound unsubscribe
Waqas Hussain <waqas20@gmail.com>
parents: 172
diff changeset
249 end
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
250 end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
251 if changed then
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
252 return save_roster(username, host, roster, jid);
173
f3a2af4d2ff2 Inbound unsubscribe
Waqas Hussain <waqas20@gmail.com>
parents: 172
diff changeset
253 end
f3a2af4d2ff2 Inbound unsubscribe
Waqas Hussain <waqas20@gmail.com>
parents: 172
diff changeset
254 end
f3a2af4d2ff2 Inbound unsubscribe
Waqas Hussain <waqas20@gmail.com>
parents: 172
diff changeset
255
3129
125f03db0b1a rostermanager: Optimisation to avoid unnecessarily loading rosters for offline contacts on probes, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 3111
diff changeset
256 local function _get_online_roster_subscription(jidA, jidB)
125f03db0b1a rostermanager: Optimisation to avoid unnecessarily loading rosters for offline contacts on probes, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 3111
diff changeset
257 local user = bare_sessions[jidA];
125f03db0b1a rostermanager: Optimisation to avoid unnecessarily loading rosters for offline contacts on probes, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 3111
diff changeset
258 local item = user and (user.roster[jidB] or { subscription = "none" });
125f03db0b1a rostermanager: Optimisation to avoid unnecessarily loading rosters for offline contacts on probes, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 3111
diff changeset
259 return item and item.subscription;
125f03db0b1a rostermanager: Optimisation to avoid unnecessarily loading rosters for offline contacts on probes, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 3111
diff changeset
260 end
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
261 local function is_contact_subscribed(username, host, jid)
3129
125f03db0b1a rostermanager: Optimisation to avoid unnecessarily loading rosters for offline contacts on probes, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 3111
diff changeset
262 do
125f03db0b1a rostermanager: Optimisation to avoid unnecessarily loading rosters for offline contacts on probes, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 3111
diff changeset
263 local selfjid = username.."@"..host;
6662
5ef319efedba rostermanager: Variable rename for clarity and to avoid name clash [luacheck]
Matthew Wild <mwild1@gmail.com>
parents: 6624
diff changeset
264 local user_subscription = _get_online_roster_subscription(selfjid, jid);
5ef319efedba rostermanager: Variable rename for clarity and to avoid name clash [luacheck]
Matthew Wild <mwild1@gmail.com>
parents: 6624
diff changeset
265 if user_subscription then return (user_subscription == "both" or user_subscription == "from"); end
5ef319efedba rostermanager: Variable rename for clarity and to avoid name clash [luacheck]
Matthew Wild <mwild1@gmail.com>
parents: 6624
diff changeset
266 local contact_subscription = _get_online_roster_subscription(jid, selfjid);
5ef319efedba rostermanager: Variable rename for clarity and to avoid name clash [luacheck]
Matthew Wild <mwild1@gmail.com>
parents: 6624
diff changeset
267 if contact_subscription then return (contact_subscription == "both" or contact_subscription == "to"); end
3129
125f03db0b1a rostermanager: Optimisation to avoid unnecessarily loading rosters for offline contacts on probes, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 3111
diff changeset
268 end
3111
826cb5f1859b rostermanager: Return an error string when subscription test fails due to an error.
Waqas Hussain <waqas20@gmail.com>
parents: 3110
diff changeset
269 local roster, err = load_roster(username, host);
174
f9aff1fc7e99 Inbound subscription request
Waqas Hussain <waqas20@gmail.com>
parents: 173
diff changeset
270 local item = roster[jid];
3111
826cb5f1859b rostermanager: Return an error string when subscription test fails due to an error.
Waqas Hussain <waqas20@gmail.com>
parents: 3110
diff changeset
271 return item and (item.subscription == "from" or item.subscription == "both"), err;
174
f9aff1fc7e99 Inbound subscription request
Waqas Hussain <waqas20@gmail.com>
parents: 173
diff changeset
272 end
7779
b1f80447a2b1 Merge 0.9->0.10
Kim Alvefur <zash@zash.se>
parents: 7271 7777
diff changeset
273 local function is_user_subscribed(username, host, jid)
7777
65836cf2d057 core.rostermanager: Add method for checking if the user is subscribed to a contact
Kim Alvefur <zash@zash.se>
parents: 5429
diff changeset
274 do
65836cf2d057 core.rostermanager: Add method for checking if the user is subscribed to a contact
Kim Alvefur <zash@zash.se>
parents: 5429
diff changeset
275 local selfjid = username.."@"..host;
65836cf2d057 core.rostermanager: Add method for checking if the user is subscribed to a contact
Kim Alvefur <zash@zash.se>
parents: 5429
diff changeset
276 local user_subscription = _get_online_roster_subscription(selfjid, jid);
65836cf2d057 core.rostermanager: Add method for checking if the user is subscribed to a contact
Kim Alvefur <zash@zash.se>
parents: 5429
diff changeset
277 if user_subscription then return (user_subscription == "both" or user_subscription == "to"); end
65836cf2d057 core.rostermanager: Add method for checking if the user is subscribed to a contact
Kim Alvefur <zash@zash.se>
parents: 5429
diff changeset
278 local contact_subscription = _get_online_roster_subscription(jid, selfjid);
65836cf2d057 core.rostermanager: Add method for checking if the user is subscribed to a contact
Kim Alvefur <zash@zash.se>
parents: 5429
diff changeset
279 if contact_subscription then return (contact_subscription == "both" or contact_subscription == "from"); end
65836cf2d057 core.rostermanager: Add method for checking if the user is subscribed to a contact
Kim Alvefur <zash@zash.se>
parents: 5429
diff changeset
280 end
65836cf2d057 core.rostermanager: Add method for checking if the user is subscribed to a contact
Kim Alvefur <zash@zash.se>
parents: 5429
diff changeset
281 local roster, err = load_roster(username, host);
65836cf2d057 core.rostermanager: Add method for checking if the user is subscribed to a contact
Kim Alvefur <zash@zash.se>
parents: 5429
diff changeset
282 local item = roster[jid];
65836cf2d057 core.rostermanager: Add method for checking if the user is subscribed to a contact
Kim Alvefur <zash@zash.se>
parents: 5429
diff changeset
283 return item and (item.subscription == "to" or item.subscription == "both"), err;
65836cf2d057 core.rostermanager: Add method for checking if the user is subscribed to a contact
Kim Alvefur <zash@zash.se>
parents: 5429
diff changeset
284 end
174
f9aff1fc7e99 Inbound subscription request
Waqas Hussain <waqas20@gmail.com>
parents: 173
diff changeset
285
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
286 function is_contact_pending_in(username, host, jid)
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
287 local roster = load_roster(username, host);
9671
e50559a42dfe rostermanager, mod_presence: Store stanza for incoming subscription requests (fixes #689) (thanks Zash, Ge0rG)
Matthew Wild <mwild1@gmail.com>
parents: 9303
diff changeset
288 return roster[false].pending[jid] ~= nil;
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
289 end
9671
e50559a42dfe rostermanager, mod_presence: Store stanza for incoming subscription requests (fixes #689) (thanks Zash, Ge0rG)
Matthew Wild <mwild1@gmail.com>
parents: 9303
diff changeset
290 local function set_contact_pending_in(username, host, jid, stanza)
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
291 local roster = load_roster(username, host);
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
292 local item = roster[jid];
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
293 if item and (item.subscription == "from" or item.subscription == "both") then
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
294 return; -- false
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
295 end
9671
e50559a42dfe rostermanager, mod_presence: Store stanza for incoming subscription requests (fixes #689) (thanks Zash, Ge0rG)
Matthew Wild <mwild1@gmail.com>
parents: 9303
diff changeset
296 roster[false].pending[jid] = st.is_stanza(stanza) and st.preserialize(stanza) or true;
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
297 return save_roster(username, host, roster, jid);
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
298 end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
299 function is_contact_pending_out(username, host, jid)
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
300 local roster = load_roster(username, host);
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
301 local item = roster[jid];
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
302 return item and item.ask;
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
303 end
10514
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
304 local function is_contact_preapproved(username, host, jid)
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
305 local roster = load_roster(username, host);
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
306 local item = roster[jid];
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
307 return item and (item.approved == "true");
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
308 end
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
309 local function set_contact_pending_out(username, host, jid) -- subscribe
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
310 local roster = load_roster(username, host);
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
311 local item = roster[jid];
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
312 if item and (item.ask or item.subscription == "to" or item.subscription == "both") then
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
313 return true;
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
314 end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
315 if not item then
177
606c433955e7 Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents: 176
diff changeset
316 item = {subscription = "none", groups = {}};
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
317 roster[jid] = item;
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
318 end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
319 item.ask = "subscribe";
4993
5243b74a4cbb Hopefully inert commit to clean up logging across a number of modules, removing all cases of concatenation when building log messages
Matthew Wild <mwild1@gmail.com>
parents: 3129
diff changeset
320 log("debug", "set_contact_pending_out: saving roster; set %s@%s.roster[%q].ask=subscribe", username, host, jid);
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
321 return save_roster(username, host, roster, jid);
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
322 end
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
323 local function unsubscribe(username, host, jid)
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
324 local roster = load_roster(username, host);
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
325 local item = roster[jid];
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
326 if not item then return false; end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
327 if (item.subscription == "from" or item.subscription == "none") and not item.ask then
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
328 return true;
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
329 end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
330 item.ask = nil;
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
331 if item.subscription == "both" then
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
332 item.subscription = "from";
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
333 elseif item.subscription == "to" then
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
334 item.subscription = "none";
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
335 end
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
336 return save_roster(username, host, roster, jid);
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
337 end
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
338 local function subscribed(username, host, jid)
10514
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
339 local roster = load_roster(username, host);
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
340 local item = roster[jid];
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
341
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
342 if is_contact_pending_in(username, host, jid) then
925
4861bcf0afa4 Fixed: rostermanager: Create new roster item if one doesn't exist on subscription approval (fixes issue #77)
Waqas Hussain <waqas20@gmail.com>
parents: 916
diff changeset
343 if not item then -- FIXME should roster item be auto-created?
4861bcf0afa4 Fixed: rostermanager: Create new roster item if one doesn't exist on subscription approval (fixes issue #77)
Waqas Hussain <waqas20@gmail.com>
parents: 916
diff changeset
344 item = {subscription = "none", groups = {}};
4861bcf0afa4 Fixed: rostermanager: Create new roster item if one doesn't exist on subscription approval (fixes issue #77)
Waqas Hussain <waqas20@gmail.com>
parents: 916
diff changeset
345 roster[jid] = item;
4861bcf0afa4 Fixed: rostermanager: Create new roster item if one doesn't exist on subscription approval (fixes issue #77)
Waqas Hussain <waqas20@gmail.com>
parents: 916
diff changeset
346 end
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
347 if item.subscription == "none" then
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
348 item.subscription = "from";
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
349 else -- subscription == to
177
606c433955e7 Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents: 176
diff changeset
350 item.subscription = "both";
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
351 end
6613
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
352 roster[false].pending[jid] = nil;
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
353 return save_roster(username, host, roster, jid);
10514
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
354 elseif not item or item.subscription == "none" or item.subscription == "to" then
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
355 -- Contact is not subscribed and has not sent a subscription request.
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
356 -- We store a pre-approval as per RFC6121 3.4
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
357 if not item then
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
358 item = {subscription = "none", groups = {}};
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
359 roster[jid] = item;
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
360 end
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
361 item.approved = "true";
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
362 log("debug", "Storing preapproval for %s", jid);
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
363 return save_roster(username, host, roster, jid);
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
364 end
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
365 end
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
366 local function unsubscribed(username, host, jid)
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
367 local roster = load_roster(username, host);
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
368 local item = roster[jid];
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
369 local pending = is_contact_pending_in(username, host, jid);
5060
b0e36777f715 mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
Waqas Hussain <waqas20@gmail.com>
parents: 5024
diff changeset
370 if pending then
6613
2aae36312eb9 rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents: 6550
diff changeset
371 roster[false].pending[jid] = nil;
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
372 end
7064
b98006bfd97a rostermanager: Rename variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6787
diff changeset
373 local is_subscribed;
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
374 if item then
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
375 if item.subscription == "from" then
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
376 item.subscription = "none";
7064
b98006bfd97a rostermanager: Rename variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6787
diff changeset
377 is_subscribed = true;
267
6303b7454ad0 Some bugs fixed
Waqas Hussain <waqas20@gmail.com>
parents: 193
diff changeset
378 elseif item.subscription == "both" then
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
379 item.subscription = "to";
7064
b98006bfd97a rostermanager: Rename variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents: 6787
diff changeset
380 is_subscribed = true;
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
381 end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
382 end
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
383 local success = (pending or is_subscribed) and save_roster(username, host, roster, jid);
8147
d44c6582059d rostermanager: Use correct variable (missed one place while renaming variable in b98006bfd97a)
Kim Alvefur <zash@zash.se>
parents: 7949
diff changeset
384 return success, pending, is_subscribed;
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
385 end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
386
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
387 local function process_outbound_subscription_request(username, host, jid)
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
388 local roster = load_roster(username, host);
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
389 local item = roster[jid];
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
390 if item and (item.subscription == "none" or item.subscription == "from") then
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
391 item.ask = "subscribe";
7155
4a0825984e42 rostermanager: Use map stores when only one contact is changed
Kim Alvefur <zash@zash.se>
parents: 7154
diff changeset
392 return save_roster(username, host, roster, jid);
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
393 end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
394 end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
395
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
396 --[[function process_outbound_subscription_approval(username, host, jid)
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
397 local roster = load_roster(username, host);
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
398 local item = roster[jid];
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
399 if item and (item.subscription == "none" or item.subscription == "from" then
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
400 item.ask = "subscribe";
1898
1ce02e2f5a3f rostermanager: Fixed: Roster version was not being properly updated in some edge cases.
Waqas Hussain <waqas20@gmail.com>
parents: 1897
diff changeset
401 return save_roster(username, host, roster);
176
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
402 end
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
403 end]]
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
404
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
405
e5cd2a03891d Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents: 174
diff changeset
406
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
407 return {
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
408 add_to_roster = add_to_roster;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
409 remove_from_roster = remove_from_roster;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
410 roster_push = roster_push;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
411 load_roster = load_roster;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
412 save_roster = save_roster;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
413 process_inbound_subscription_approval = process_inbound_subscription_approval;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
414 process_inbound_subscription_cancellation = process_inbound_subscription_cancellation;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
415 process_inbound_unsubscribe = process_inbound_unsubscribe;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
416 is_contact_subscribed = is_contact_subscribed;
7779
b1f80447a2b1 Merge 0.9->0.10
Kim Alvefur <zash@zash.se>
parents: 7271 7777
diff changeset
417 is_user_subscribed = is_user_subscribed;
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
418 is_contact_pending_in = is_contact_pending_in;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
419 set_contact_pending_in = set_contact_pending_in;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
420 is_contact_pending_out = is_contact_pending_out;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
421 set_contact_pending_out = set_contact_pending_out;
10514
f0e9e5bda415 rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents: 9705
diff changeset
422 is_contact_preapproved = is_contact_preapproved;
6779
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
423 unsubscribe = unsubscribe;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
424 subscribed = subscribed;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
425 unsubscribed = unsubscribed;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
426 process_outbound_subscription_request = process_outbound_subscription_request;
6236668da30a core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents: 6662
diff changeset
427 };