Software /
code /
prosody
Annotate
plugins/mod_groups.lua @ 13652:a08065207ef0
net.server_epoll: Call :shutdown() on TLS sockets when supported
Comment from Matthew:
This fixes a potential issue where the Prosody process gets blocked on sockets
waiting for them to close. Unlike non-TLS sockets, closing a TLS socket sends
layer 7 data, and this can cause problems for sockets which are in the process
of being cleaned up.
This depends on LuaSec changes which are not yet upstream.
From Martijn's original email:
So first my analysis of luasec. in ssl.c the socket is put into blocking
mode right before calling SSL_shutdown() inside meth_destroy(). My best
guess to why this is is because meth_destroy is linked to the __close
and __gc methods, which can't exactly be called multiple times and
luasec does want to make sure that a tls session is shutdown as clean
as possible.
I can't say I disagree with this reasoning and don't want to change this
behaviour. My solution to this without changing the current behaviour is
to introduce a shutdown() method. I am aware that this overlaps in a
conflicting way with tcp's shutdown method, but it stays close to the
OpenSSL name. This method calls SSL_shutdown() in the current
(non)blocking mode of the underlying socket and returns a boolean
whether or not the shutdown is completed (matching SSL_shutdown()'s 0
or 1 return values), and returns the familiar ssl_ioerror() strings on
error with a false for completion. This error can then be used to
determine if we have wantread/wantwrite to finalize things. Once
meth_shutdown() has been called once a shutdown flag will be set, which
indicates to meth_destroy() that the SSL_shutdown() has been handled
by the application and it shouldn't be needed to set the socket to
blocking mode. I've left the SSL_shutdown() call in the
LSEC_STATE_CONNECTED to prevent TOCTOU if the application reaches a
timeout for the shutdown code, which might allow SSL_shutdown() to
clean up anyway at the last possible moment.
Another thing I've changed to luasec is the call to socket_setblocking()
right before calling close(2) in socket_destroy() in usocket.c.
According to the latest POSIX[0]:
Note that the requirement for close() on a socket to block for up to
the current linger interval is not conditional on the O_NONBLOCK
setting.
Which I read to mean that removing O_NONBLOCK on the socket before close
doesn't impact the behaviour and only causes noise in system call
tracers. I didn't touch the windows bits of this, since I don't do
windows.
For the prosody side of things I've made the TLS shutdown bits resemble
interface:onwritable(), and put it under a combined guard of self._tls
and self.conn.shutdown. The self._tls bit is there to prevent getting
stuck on this condition, and self.conn.shutdown is there to prevent the
code being called by instances where the patched luasec isn't deployed.
The destroy() method can be called from various places and is read by
me as the "we give up" error path. To accommodate for these unexpected
entrypoints I've added a single call to self.conn:shutdown() to prevent
the socket being put into blocking mode. I have no expectations that
there is any other use here. Same as previous, the self.conn.shutdown
check is there to make sure it's not called on unpatched luasec
deployments and self._tls is there to make sure we don't call shutdown()
on tcp sockets.
I wouldn't recommend logging of the conn:shutdown() error inside
close(), since a lot of clients simply close the connection before
SSL_shutdown() is done.
author | Martijn van Duren <martijn@openbsd.org> |
---|---|
date | Thu, 06 Feb 2025 15:04:38 +0000 |
parent | 12977:74b9e05af71e |
rev | line source |
---|---|
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1388
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
1522
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 -- |
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1388
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1388
diff
changeset
|
6 -- COPYING file in the source package for more information. |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1388
diff
changeset
|
7 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1388
diff
changeset
|
8 |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
2910
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
10 local groups; |
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
11 local members; |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
10111
diff
changeset
|
13 local datamanager = require "prosody.util.datamanager"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
10111
diff
changeset
|
14 local jid_prep = require "prosody.util.jid".prep; |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local module_host = module:get_host(); |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
5747
23076ee191d3
rostermanager, mod_groups: Change roster-load event to pass an event table for consistency
Matthew Wild <mwild1@gmail.com>
parents:
5418
diff
changeset
|
18 function inject_roster_contacts(event) |
23076ee191d3
rostermanager, mod_groups: Change roster-load event to pass an event table for consistency
Matthew Wild <mwild1@gmail.com>
parents:
5418
diff
changeset
|
19 local username, host= event.username, event.host; |
3054
05b45b1281aa
mod_groups: Remove potentially verbose per-contact logging (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
20 --module:log("debug", "Injecting group members to roster"); |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 local bare_jid = username.."@"..host; |
2910
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
22 if not members[bare_jid] and not members[false] then return; end -- Not a member of any groups |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5747
diff
changeset
|
23 |
5747
23076ee191d3
rostermanager, mod_groups: Change roster-load event to pass an event table for consistency
Matthew Wild <mwild1@gmail.com>
parents:
5418
diff
changeset
|
24 local roster = event.roster; |
1388
546caa44620c
mod_groups: Support for public groups, and extra logging
Matthew Wild <mwild1@gmail.com>
parents:
1383
diff
changeset
|
25 local function import_jids_to_roster(group_name) |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 for jid in pairs(groups[group_name]) do |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 -- Add them to roster |
10111
0f335815244f
plugins: Remove tostring call from logging
Kim Alvefur <zash@zash.se>
parents:
8992
diff
changeset
|
28 --module:log("debug", "processing jid %s in group %s", jid, group_name); |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 if jid ~= bare_jid then |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 if not roster[jid] then roster[jid] = {}; end |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 roster[jid].subscription = "both"; |
3168
20c851616ade
Add the ability to have names in group files, by putting them with an = sign after the jid:
Jeff Mitchell <jeff@jefferai.org>
parents:
3125
diff
changeset
|
32 if groups[group_name][jid] then |
20c851616ade
Add the ability to have names in group files, by putting them with an = sign after the jid:
Jeff Mitchell <jeff@jefferai.org>
parents:
3125
diff
changeset
|
33 roster[jid].name = groups[group_name][jid]; |
20c851616ade
Add the ability to have names in group files, by putting them with an = sign after the jid:
Jeff Mitchell <jeff@jefferai.org>
parents:
3125
diff
changeset
|
34 end |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 if not roster[jid].groups then |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 roster[jid].groups = { [group_name] = true }; |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 roster[jid].groups[group_name] = true; |
4315
51706d2b9f77
Backout bcdff2b1d3ec from 0.8 - going to commit a slightly cleaner patch for the same issue to trunk
Matthew Wild <mwild1@gmail.com>
parents:
4312
diff
changeset
|
39 roster[jid].persist = false; |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 end |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 end |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 end |
1388
546caa44620c
mod_groups: Support for public groups, and extra logging
Matthew Wild <mwild1@gmail.com>
parents:
1383
diff
changeset
|
43 |
546caa44620c
mod_groups: Support for public groups, and extra logging
Matthew Wild <mwild1@gmail.com>
parents:
1383
diff
changeset
|
44 -- Find groups this JID is a member of |
2910
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
45 if members[bare_jid] then |
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
46 for _, group_name in ipairs(members[bare_jid]) do |
3054
05b45b1281aa
mod_groups: Remove potentially verbose per-contact logging (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
47 --module:log("debug", "Importing group %s", group_name); |
2910
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
48 import_jids_to_roster(group_name); |
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
49 end |
1388
546caa44620c
mod_groups: Support for public groups, and extra logging
Matthew Wild <mwild1@gmail.com>
parents:
1383
diff
changeset
|
50 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5747
diff
changeset
|
51 |
1388
546caa44620c
mod_groups: Support for public groups, and extra logging
Matthew Wild <mwild1@gmail.com>
parents:
1383
diff
changeset
|
52 -- Import public groups |
2910
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
53 if members[false] then |
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
54 for _, group_name in ipairs(members[false]) do |
3054
05b45b1281aa
mod_groups: Remove potentially verbose per-contact logging (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
55 --module:log("debug", "Importing group %s", group_name); |
2910
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
56 import_jids_to_roster(group_name); |
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
57 end |
1388
546caa44620c
mod_groups: Support for public groups, and extra logging
Matthew Wild <mwild1@gmail.com>
parents:
1383
diff
changeset
|
58 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5747
diff
changeset
|
59 |
2912
f5a5317f3485
mod_groups: Fixes to make compatible with roster versioning - set version to 'true' to indicate that the roster is not being versioned
Matthew Wild <mwild1@gmail.com>
parents:
2911
diff
changeset
|
60 if roster[false] then |
f5a5317f3485
mod_groups: Fixes to make compatible with roster versioning - set version to 'true' to indicate that the roster is not being versioned
Matthew Wild <mwild1@gmail.com>
parents:
2911
diff
changeset
|
61 roster[false].version = true; |
1388
546caa44620c
mod_groups: Support for public groups, and extra logging
Matthew Wild <mwild1@gmail.com>
parents:
1383
diff
changeset
|
62 end |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 end |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 function remove_virtual_contacts(username, host, datastore, data) |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 if host == module_host and datastore == "roster" then |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 local new_roster = {}; |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 for jid, contact in pairs(data) do |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 if contact.persist ~= false then |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 new_roster[jid] = contact; |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 end |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 end |
3125
f2d1079a758d
mod_groups: Check for existence of roster[false] before clearing version (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
3054
diff
changeset
|
73 if new_roster[false] then |
f2d1079a758d
mod_groups: Check for existence of roster[false] before clearing version (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
3054
diff
changeset
|
74 new_roster[false].version = nil; -- Version is void |
f2d1079a758d
mod_groups: Check for existence of roster[false] before clearing version (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
3054
diff
changeset
|
75 end |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 return username, host, datastore, new_roster; |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 end |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 return username, host, datastore, data; |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 end |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 function module.load() |
7129
e4c886946ecb
mod_groups: Move variable to smaller scope
Kim Alvefur <zash@zash.se>
parents:
7128
diff
changeset
|
83 local groups_file = module:get_option_path("groups_file", nil, "config"); |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 if not groups_file then return; end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5747
diff
changeset
|
85 |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 module:hook("roster-load", inject_roster_contacts); |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 datamanager.add_callback(remove_virtual_contacts); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5747
diff
changeset
|
88 |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 groups = { default = {} }; |
2911
30895e419e92
mod_groups: Missed hunk from last commit, don't create the list of public group members unless necessary
Matthew Wild <mwild1@gmail.com>
parents:
2910
diff
changeset
|
90 members = { }; |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 local curr_group = "default"; |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 for line in io.lines(groups_file) do |
1388
546caa44620c
mod_groups: Support for public groups, and extra logging
Matthew Wild <mwild1@gmail.com>
parents:
1383
diff
changeset
|
93 if line:match("^%s*%[.-%]%s*$") then |
546caa44620c
mod_groups: Support for public groups, and extra logging
Matthew Wild <mwild1@gmail.com>
parents:
1383
diff
changeset
|
94 curr_group = line:match("^%s*%[(.-)%]%s*$"); |
546caa44620c
mod_groups: Support for public groups, and extra logging
Matthew Wild <mwild1@gmail.com>
parents:
1383
diff
changeset
|
95 if curr_group:match("^%+") then |
546caa44620c
mod_groups: Support for public groups, and extra logging
Matthew Wild <mwild1@gmail.com>
parents:
1383
diff
changeset
|
96 curr_group = curr_group:gsub("^%+", ""); |
2910
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
97 if not members[false] then |
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
98 members[false] = {}; |
6706a02df271
mod_groups: Only create group lists when necessary (now we can reliably detect when a user is in /any/ group, including public ones)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
99 end |
1388
546caa44620c
mod_groups: Support for public groups, and extra logging
Matthew Wild <mwild1@gmail.com>
parents:
1383
diff
changeset
|
100 members[false][#members[false]+1] = curr_group; -- Is a public group |
546caa44620c
mod_groups: Support for public groups, and extra logging
Matthew Wild <mwild1@gmail.com>
parents:
1383
diff
changeset
|
101 end |
10111
0f335815244f
plugins: Remove tostring call from logging
Kim Alvefur <zash@zash.se>
parents:
8992
diff
changeset
|
102 module:log("debug", "New group: %s", curr_group); |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 groups[curr_group] = groups[curr_group] or {}; |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 else |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 -- Add JID |
3168
20c851616ade
Add the ability to have names in group files, by putting them with an = sign after the jid:
Jeff Mitchell <jeff@jefferai.org>
parents:
3125
diff
changeset
|
106 local entryjid, name = line:match("([^=]*)=?(.*)"); |
20c851616ade
Add the ability to have names in group files, by putting them with an = sign after the jid:
Jeff Mitchell <jeff@jefferai.org>
parents:
3125
diff
changeset
|
107 module:log("debug", "entryjid = '%s', name = '%s'", entryjid, name); |
20c851616ade
Add the ability to have names in group files, by putting them with an = sign after the jid:
Jeff Mitchell <jeff@jefferai.org>
parents:
3125
diff
changeset
|
108 local jid; |
20c851616ade
Add the ability to have names in group files, by putting them with an = sign after the jid:
Jeff Mitchell <jeff@jefferai.org>
parents:
3125
diff
changeset
|
109 jid = jid_prep(entryjid:match("%S+")); |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 if jid then |
10111
0f335815244f
plugins: Remove tostring call from logging
Kim Alvefur <zash@zash.se>
parents:
8992
diff
changeset
|
111 module:log("debug", "New member of %s: %s", curr_group, jid); |
3168
20c851616ade
Add the ability to have names in group files, by putting them with an = sign after the jid:
Jeff Mitchell <jeff@jefferai.org>
parents:
3125
diff
changeset
|
112 groups[curr_group][jid] = name or false; |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 members[jid] = members[jid] or {}; |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 members[jid][#members[jid]+1] = curr_group; |
8991
37ebcc7c6768
mod_groups: Log a warning about invalid JIDs (#1180)
Kim Alvefur <zash@zash.se>
parents:
7129
diff
changeset
|
115 elseif entryjid:match("%S") then |
37ebcc7c6768
mod_groups: Log a warning about invalid JIDs (#1180)
Kim Alvefur <zash@zash.se>
parents:
7129
diff
changeset
|
116 module:log("warn", "Invalid JID: %q", entryjid); |
1383
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 end |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 end |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 end |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 module:log("info", "Groups loaded successfully"); |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 end |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 function module.unload() |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 datamanager.remove_callback(remove_virtual_contacts); |
8774c5cbf147
mod_groups: Experimental shared roster support
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 end |
5417
d13ec6622752
mod_groups: Add a public function other modules can use to determine if a JID belongs to a given group
Matthew Wild <mwild1@gmail.com>
parents:
5373
diff
changeset
|
126 |
d13ec6622752
mod_groups: Add a public function other modules can use to determine if a JID belongs to a given group
Matthew Wild <mwild1@gmail.com>
parents:
5373
diff
changeset
|
127 -- Public for other modules to access |
d13ec6622752
mod_groups: Add a public function other modules can use to determine if a JID belongs to a given group
Matthew Wild <mwild1@gmail.com>
parents:
5373
diff
changeset
|
128 function group_contains(group_name, jid) |
d13ec6622752
mod_groups: Add a public function other modules can use to determine if a JID belongs to a given group
Matthew Wild <mwild1@gmail.com>
parents:
5373
diff
changeset
|
129 return groups[group_name][jid]; |
d13ec6622752
mod_groups: Add a public function other modules can use to determine if a JID belongs to a given group
Matthew Wild <mwild1@gmail.com>
parents:
5373
diff
changeset
|
130 end |