Mercurial > prosody-hg
annotate plugins/mod_roster.lua @ 14213:75d09be04f13 13.0
util.poll: Reject file descriptors outside of FD_SETSIZE in all methods
To prevent accesses outside the bounds of the FD sets.
Previously only checked on the write, but maybe this could potentially
cause weird behavior as well?
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 31 May 2026 11:51:22 +0200 |
| parents | 0ff587d7c742 |
| children |
| rev | line source |
|---|---|
|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1355
diff
changeset
|
1 -- Prosody IM |
|
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2227
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
|
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2227
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5372
diff
changeset
|
4 -- |
| 758 | 5 -- This project is MIT/X11 licensed. Please see the |
| 6 -- COPYING file in the source package for more information. | |
|
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
7 -- |
|
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
8 |
|
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
9 |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12101
diff
changeset
|
10 local st = require "prosody.util.stanza" |
| 30 | 11 |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12101
diff
changeset
|
12 local jid_split = require "prosody.util.jid".split; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12101
diff
changeset
|
13 local jid_resource = require "prosody.util.jid".resource; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12101
diff
changeset
|
14 local jid_prep = require "prosody.util.jid".prep; |
|
3526
69a8c7e635c5
mod_roster: Cleaned up some unused variables and global accesses.
Waqas Hussain <waqas20@gmail.com>
parents:
3525
diff
changeset
|
15 local tonumber = tonumber; |
|
8644
3b28c7728e3f
mod_roster: Iterate over roster group items in more modern manner
Kim Alvefur <zash@zash.se>
parents:
7783
diff
changeset
|
16 local pairs = pairs; |
|
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
17 |
|
13584
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
18 local rostermanager = require "prosody.core.rostermanager"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
19 local rm_load_roster = rostermanager.load_roster; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
20 local rm_remove_from_roster = rostermanager.remove_from_roster; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
21 local rm_add_to_roster = rostermanager.add_to_roster; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
22 local rm_roster_push = rostermanager.roster_push; |
|
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
23 |
|
541
3521e0851c9e
Change modules to use the new add_feature module API method.
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
24 module:add_feature("jabber:iq:roster"); |
|
421
63be85693710
Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents:
326
diff
changeset
|
25 |
|
4265
d56c26c258e4
mod_roster: Remove <optional/> from roster version stream feature, as per latest specs.
Waqas Hussain <waqas20@gmail.com>
parents:
3540
diff
changeset
|
26 local rosterver_stream_feature = st.stanza("ver", {xmlns="urn:xmpp:features:rosterver"}); |
|
2611
c3ea4d3f857f
mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
2227
diff
changeset
|
27 module:hook("stream-features", function(event) |
|
c3ea4d3f857f
mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
2227
diff
changeset
|
28 local origin, features = event.origin, event.features; |
|
c3ea4d3f857f
mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
2227
diff
changeset
|
29 if origin.username then |
|
c3ea4d3f857f
mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
2227
diff
changeset
|
30 features:add_child(rosterver_stream_feature); |
|
c3ea4d3f857f
mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
2227
diff
changeset
|
31 end |
|
c3ea4d3f857f
mod_roster: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
2227
diff
changeset
|
32 end); |
|
1133
b293d7dc6a45
mod_roster: Advertize roster versioning support
Waqas Hussain <waqas20@gmail.com>
parents:
928
diff
changeset
|
33 |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
34 module:hook("iq/self/jabber:iq:roster:query", function(event) |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
35 local session, stanza = event.origin, event.stanza; |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
36 |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
37 if stanza.attr.type == "get" then |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
38 local roster = st.reply(stanza); |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5372
diff
changeset
|
39 |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
40 local client_ver = tonumber(stanza.tags[1].attr.ver); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
41 local server_ver = tonumber(session.roster[false].version or 1); |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5372
diff
changeset
|
42 |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
43 if not (client_ver and server_ver) or client_ver ~= server_ver then |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
44 roster:query("jabber:iq:roster"); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
45 -- Client does not support versioning, or has stale roster |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
46 for jid, item in pairs(session.roster) do |
|
6613
2aae36312eb9
rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
47 if jid then |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
48 roster:tag("item", { |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
49 jid = jid, |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
50 subscription = item.subscription, |
|
14203
0ff587d7c742
rostermanager, mod_roster: Include 'approved' attribute in roster items (thanks singpolyma)
Matthew Wild <mwild1@gmail.com>
parents:
13950
diff
changeset
|
51 approved = item.approved, |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
52 ask = item.ask, |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
53 name = item.name, |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
54 }); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
55 for group in pairs(item.groups) do |
|
8646
a267dfa9d81d
mod_roster: Use new :text_tag()
Kim Alvefur <zash@zash.se>
parents:
8644
diff
changeset
|
56 roster:text_tag("group", group); |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
57 end |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
58 roster:up(); -- move out from item |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
59 end |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
60 end |
|
13566
2fb4ce131131
mod_roster: do not store number in attribute
Jonas Schäfer <jonas@wielicki.name>
parents:
12977
diff
changeset
|
61 roster.tags[1].attr.ver = tostring(server_ver); |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
62 end |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
63 session.send(roster); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
64 session.interested = true; -- resource is interested in roster updates |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
65 else -- stanza.attr.type == "set" |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
66 local query = stanza.tags[1]; |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
67 if #query.tags == 1 and query.tags[1].name == "item" |
|
6613
2aae36312eb9
rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
68 and query.tags[1].attr.xmlns == "jabber:iq:roster" and query.tags[1].attr.jid then |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
69 local item = query.tags[1]; |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
70 local from_node, from_host = jid_split(stanza.attr.from); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
71 local jid = jid_prep(item.attr.jid); |
|
12101
7cd94469d15f
mod_roster: Improve readability of bare-JID check
Kim Alvefur <zash@zash.se>
parents:
12100
diff
changeset
|
72 if jid and not jid_resource(jid) then |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
73 if jid ~= from_node.."@"..from_host then |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
74 if item.attr.subscription == "remove" then |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
75 local roster = session.roster; |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
76 local r_item = roster[jid]; |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
77 if r_item then |
|
7331
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
6613
diff
changeset
|
78 module:fire_event("roster-item-removed", { |
|
12100
0b14b541fd27
mod_roster: pass correct username to roster-item-removed
Jonas Schäfer <jonas@wielicki.name>
parents:
8646
diff
changeset
|
79 username = from_node, jid = jid, item = r_item, origin = session, roster = roster, |
|
7331
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
6613
diff
changeset
|
80 }); |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
81 local success, err_type, err_cond, err_msg = rm_remove_from_roster(session, jid); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
82 if success then |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
83 session.send(st.reply(stanza)); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
84 rm_roster_push(from_node, from_host, jid); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
85 else |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
86 session.send(st.error_reply(stanza, err_type, err_cond, err_msg)); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
87 end |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
88 else |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
89 session.send(st.error_reply(stanza, "modify", "item-not-found")); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
90 end |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
91 else |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
92 local r_item = {name = item.attr.name, groups = {}}; |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
93 if r_item.name == "" then r_item.name = nil; end |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
94 if session.roster[jid] then |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
95 r_item.subscription = session.roster[jid].subscription; |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
96 r_item.ask = session.roster[jid].ask; |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
97 else |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
98 r_item.subscription = "none"; |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
99 end |
|
8644
3b28c7728e3f
mod_roster: Iterate over roster group items in more modern manner
Kim Alvefur <zash@zash.se>
parents:
7783
diff
changeset
|
100 for group in item:childtags("group") do |
|
3b28c7728e3f
mod_roster: Iterate over roster group items in more modern manner
Kim Alvefur <zash@zash.se>
parents:
7783
diff
changeset
|
101 local text = group:get_text(); |
|
3b28c7728e3f
mod_roster: Iterate over roster group items in more modern manner
Kim Alvefur <zash@zash.se>
parents:
7783
diff
changeset
|
102 if text then |
|
3b28c7728e3f
mod_roster: Iterate over roster group items in more modern manner
Kim Alvefur <zash@zash.se>
parents:
7783
diff
changeset
|
103 r_item.groups[text] = true; |
|
177
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
104 end |
|
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
105 end |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
106 local success, err_type, err_cond, err_msg = rm_add_to_roster(session, jid, r_item); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
107 if success then |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
108 -- Ok, send success |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
109 session.send(st.reply(stanza)); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
110 -- and push change to all resources |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
111 rm_roster_push(from_node, from_host, jid); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
112 else |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
113 -- Adding to roster failed |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
114 session.send(st.error_reply(stanza, err_type, err_cond, err_msg)); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
115 end |
|
102
a5b914370db5
Fixed: mod_roster now outputs all roster data (instead of just the JIDs)
Waqas Hussain <waqas20@gmail.com>
parents:
79
diff
changeset
|
116 end |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
117 else |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
118 -- Trying to add self to roster |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
119 session.send(st.error_reply(stanza, "cancel", "not-allowed")); |
| 30 | 120 end |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
121 else |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
122 -- Invalid JID added to roster |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
123 session.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME what's the correct error? |
| 30 | 124 end |
|
3525
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
125 else |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
126 -- Roster set didn't include a single item, or its name wasn't 'item' |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
127 session.send(st.error_reply(stanza, "modify", "bad-request")); |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
128 end |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
129 end |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
130 return true; |
|
1e44e7e8e79c
mod_roster: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3323
diff
changeset
|
131 end); |
|
5099
39eb688e106a
mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
132 |
|
39eb688e106a
mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
133 module:hook_global("user-deleted", function(event) |
|
39eb688e106a
mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
134 local username, host = event.username, event.host; |
|
7333
9d0e65d919e8
mod_roster: Handle roster item removal with event on user deletion
Kim Alvefur <zash@zash.se>
parents:
7331
diff
changeset
|
135 local origin = event.origin or prosody.hosts[host]; |
|
5099
39eb688e106a
mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
136 if host ~= module.host then return end |
|
39eb688e106a
mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
137 local roster = rm_load_roster(username, host); |
|
39eb688e106a
mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
138 for jid, item in pairs(roster) do |
|
6613
2aae36312eb9
rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
139 if jid then |
|
7333
9d0e65d919e8
mod_roster: Handle roster item removal with event on user deletion
Kim Alvefur <zash@zash.se>
parents:
7331
diff
changeset
|
140 module:fire_event("roster-item-removed", { |
|
9d0e65d919e8
mod_roster: Handle roster item removal with event on user deletion
Kim Alvefur <zash@zash.se>
parents:
7331
diff
changeset
|
141 username = username, jid = jid, item = item, roster = roster, origin = origin, |
|
9d0e65d919e8
mod_roster: Handle roster item removal with event on user deletion
Kim Alvefur <zash@zash.se>
parents:
7331
diff
changeset
|
142 }); |
|
7334
566d0a56b37f
mod_roster: Fire event for pending items for good measure
Kim Alvefur <zash@zash.se>
parents:
7333
diff
changeset
|
143 else |
|
7783
f54c960240da
mod_roster: Rename variable to silence shadowing warning [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7782
diff
changeset
|
144 for pending_jid in pairs(item.pending) do |
|
7334
566d0a56b37f
mod_roster: Fire event for pending items for good measure
Kim Alvefur <zash@zash.se>
parents:
7333
diff
changeset
|
145 module:fire_event("roster-item-removed", { |
|
7783
f54c960240da
mod_roster: Rename variable to silence shadowing warning [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7782
diff
changeset
|
146 username = username, jid = pending_jid, roster = roster, origin = origin, |
|
7334
566d0a56b37f
mod_roster: Fire event for pending items for good measure
Kim Alvefur <zash@zash.se>
parents:
7333
diff
changeset
|
147 }); |
|
566d0a56b37f
mod_roster: Fire event for pending items for good measure
Kim Alvefur <zash@zash.se>
parents:
7333
diff
changeset
|
148 end |
|
5099
39eb688e106a
mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
149 end |
|
39eb688e106a
mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
150 end |
|
39eb688e106a
mod_roster: When an user is deleted, unsubscribe from their contacts
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
151 end, 300); |
|
13584
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
152 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
153 -- API/commands |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
154 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
155 -- Make a *one-way* subscription. User will see when contact is online, |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
156 -- contact will not see when user is online. |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
157 function subscribe(user_jid, contact_jid) |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
158 local user_username, user_host = jid_split(user_jid); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
159 local contact_username, contact_host = jid_split(contact_jid); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
160 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
161 -- Update user's roster to say subscription request is pending. Bare hosts (e.g. components) don't have rosters. |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
162 if user_username ~= nil then |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
163 rostermanager.set_contact_pending_out(user_username, user_host, contact_jid); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
164 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
165 |
|
13798
35819bc9471a
mod_roster: Fix shell commands when a component is involved (fixes #1908)
Kim Alvefur <zash@zash.se>
parents:
13584
diff
changeset
|
166 if prosody.hosts[contact_host] and prosody.hosts[contact_host].type == "local" then -- Sending to a local host? |
|
13584
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
167 -- Update contact's roster to say subscription request is pending... |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
168 rostermanager.set_contact_pending_in(contact_username, contact_host, user_jid); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
169 -- Update contact's roster to say subscription request approved... |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
170 rostermanager.subscribed(contact_username, contact_host, user_jid); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
171 -- Update user's roster to say subscription request approved. Bare hosts (e.g. components) don't have rosters. |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
172 if user_username ~= nil then |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
173 rostermanager.process_inbound_subscription_approval(user_username, user_host, contact_jid); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
174 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
175 else |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
176 -- Send a subscription request |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
177 local sub_request = st.presence({ from = user_jid, to = contact_jid, type = "subscribe" }); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
178 module:send(sub_request); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
179 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
180 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
181 return true; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
182 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
183 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
184 -- Make a mutual subscription between jid1 and jid2. Each JID will see |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
185 -- when the other one is online. |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
186 function subscribe_both(jid1, jid2) |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
187 local ok1, err1 = subscribe(jid1, jid2); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
188 local ok2, err2 = subscribe(jid2, jid1); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
189 return ok1 and ok2, err1 or err2; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
190 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
191 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
192 -- Unsubscribes user from contact (not contact from user, if subscribed). |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
193 function unsubscribe(user_jid, contact_jid) |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
194 local user_username, user_host = jid_split(user_jid); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
195 local contact_username, contact_host = jid_split(contact_jid); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
196 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
197 -- Update user's roster to say subscription is cancelled... |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
198 rostermanager.unsubscribe(user_username, user_host, contact_jid); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
199 if prosody.hosts[contact_host] then -- Local host? |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
200 -- Update contact's roster to say subscription is cancelled... |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
201 rostermanager.unsubscribed(contact_username, contact_host, user_jid); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
202 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
203 return true; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
204 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
205 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
206 -- Cancel any subscription in either direction. |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
207 function unsubscribe_both(jid1, jid2) |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
208 local ok1 = unsubscribe(jid1, jid2); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
209 local ok2 = unsubscribe(jid2, jid1); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
210 return ok1 and ok2; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
211 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
212 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
213 module:add_item("shell-command", { |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
214 section = "roster"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
215 section_desc = "View and manage user rosters (contact lists)"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
216 name = "show"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
217 desc = "Show a user's current roster"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
218 args = { |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
219 { name = "jid", type = "string" }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
220 { name = "sub", type = "string" }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
221 }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
222 host_selector = "jid"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
223 handler = function(self, jid, sub) --luacheck: ignore 212/self |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
224 local print = self.session.print; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
225 local it = require "prosody.util.iterators"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
226 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
227 local roster = assert(rm_load_roster(jid_split(jid))); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
228 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
229 local function sort_func(a, b) |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
230 if type(a) == "string" and type(b) == "string" then |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
231 return a < b; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
232 else |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
233 return a == false; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
234 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
235 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
236 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
237 local count = 0; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
238 if sub == "pending" then |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
239 local pending_subs = roster[false].pending or {}; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
240 for pending_jid in it.sorted_pairs(pending_subs) do |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
241 print(pending_jid); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
242 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
243 else |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
244 for contact, item in it.sorted_pairs(roster, sort_func) do |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
245 if contact and (not sub or sub == item.subscription) then |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
246 count = count + 1; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
247 print(contact, ("sub=%s\task=%s"):format(item.subscription or "none", item.ask or "none")); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
248 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
249 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
250 end |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
251 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
252 return true, ("Showing %d entries"):format(count); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
253 end; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
254 }); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
255 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
256 module:add_item("shell-command", { |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
257 section = "roster"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
258 section_desc = "View and manage user rosters (contact lists)"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
259 name = "subscribe"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
260 desc = "Subscribe a user to another JID"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
261 args = { |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
262 { name = "jid", type = "string" }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
263 { name = "contact", type = "string" }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
264 }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
265 host_selector = "jid"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
266 handler = function(self, jid, contact) --luacheck: ignore 212/self |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
267 return subscribe(jid, contact); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
268 end; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
269 }); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
270 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
271 module:add_item("shell-command", { |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
272 section = "roster"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
273 section_desc = "View and manage user rosters (contact lists)"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
274 name = "subscribe_both"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
275 desc = "Subscribe a user and a contact JID to each other"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
276 args = { |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
277 { name = "jid", type = "string" }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
278 { name = "contact", type = "string" }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
279 }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
280 host_selector = "jid"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
281 handler = function(self, jid, contact) --luacheck: ignore 212/self |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
282 return subscribe_both(jid, contact); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
283 end; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
284 }); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
285 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
286 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
287 module:add_item("shell-command", { |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
288 section = "roster"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
289 section_desc = "View and manage user rosters (contact lists)"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
290 name = "unsubscribe"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
291 desc = "Unsubscribe a user from another JID"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
292 args = { |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
293 { name = "jid", type = "string" }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
294 { name = "contact", type = "string" }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
295 }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
296 host_selector = "jid"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
297 handler = function(self, jid, contact) --luacheck: ignore 212/self |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
298 return unsubscribe(jid, contact); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
299 end; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
300 }); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
301 |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
302 module:add_item("shell-command", { |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
303 section = "roster"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
304 section_desc = "View and manage user rosters (contact lists)"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
305 name = "unsubscribe_both"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
306 desc = "Unubscribe a user and a contact JID from each other"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
307 args = { |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
308 { name = "jid", type = "string" }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
309 { name = "contact", type = "string" }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
310 }; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
311 host_selector = "jid"; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
312 handler = function(self, jid, contact) --luacheck: ignore 212/self |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
313 return unsubscribe_both(jid, contact); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
314 end; |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
315 }); |
|
0f265142117a
mod_roster: Add basic roster management shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13566
diff
changeset
|
316 |
|
13950
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
317 module:add_item("shell-command", { |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
318 section = "roster"; |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
319 section_desc = "View and manage user rosters (contact lists)"; |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
320 name = "clean"; |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
321 desc = "Remove invalid JIDs from roster"; |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
322 args = { |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
323 { name = "jid", type = "string" }; |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
324 }; |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
325 host_selector = "jid"; |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
326 handler = function(self, jid) -- luacheck: ignore 212/self |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
327 local function iter(user, host) |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
328 if user then return pairs({ [user] = true }); end |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
329 local users = require"prosody.core.usermanager".users; |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
330 return users(host); |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
331 end |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
332 |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
333 local user, host = jid_split(jid); |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
334 local removed = 0; |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
335 for user_ in iter(user, host) do |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
336 local roster = assert(rm_load_roster(user_, host)); |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
337 for contact in pairs(roster) do |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
338 if type(contact) == "string" then |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
339 if not jid_prep(contact) or jid_resource(contact) then |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
340 roster[contact] = nil; |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
341 removed = removed + 1; |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
342 end |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
343 end |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
344 end |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
345 end |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
346 return true, ("%d invalid roster entrie(s) removed"):format(removed); |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
347 end; |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
348 }); |
|
d00409d2329f
mod_roster: Add command for cleaning out invalid contact JIDs
Kim Alvefur <zash@zash.se>
parents:
13798
diff
changeset
|
349 |
