Software /
code /
prosody
Annotate
util/watchdog.lua @ 8791:8da11142fabf
muc: Allow clients to change multiple affiliations or roles at once (#345)
According to XEP-0045 sections 9.2, 9.5 and 9.8 affiliation lists and role
lists should allow mass-modification. Prosody however would just use the
first entry of the list and ignore the rest. This is fixed by introducing
a `for` loop to `set` stanzas of the respective `muc#admin` namespace.
In order for this loop to work, the error handling was changed a little.
Prosody no longer returns after the first error. Instead, an error reply
is sent for each malformed or otherwise wrong entry, but the loop keeps
going over the other entries. This may lead to multiple error messages
being sent for one client request. A notable exception from this is when
the XML Schema for `muc#admin` requests is violated. In that case the loop
is aborted with an error message to the client.
The change is a bit bigger than that in order to have the loop only for
`set` stanzas without changing the behaviour of the `get` stanzas. This is
now more in line with trunk, where there are separate methods for each
stanza type.
References: #345
author | Lennart Sauerbeck <devel@lennart.sauerbeck.org> |
---|---|
date | Sat, 18 Mar 2017 18:47:28 +0100 |
parent | 6777:5de6b93d0190 |
child | 8555:4f0f5b49bb03 |
rev | line source |
---|---|
4401
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local timer = require "util.timer"; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local setmetatable = setmetatable; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local os_time = os.time; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
4891
diff
changeset
|
5 local _ENV = nil; |
4401
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local watchdog_methods = {}; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local watchdog_mt = { __index = watchdog_methods }; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
4891
diff
changeset
|
10 local function new(timeout, callback) |
4401
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local watchdog = setmetatable({ timeout = timeout, last_reset = os_time(), callback = callback }, watchdog_mt); |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 timer.add_task(timeout+1, function (current_time) |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local last_reset = watchdog.last_reset; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 if not last_reset then |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 return; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 end |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local time_left = (last_reset + timeout) - current_time; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 if time_left < 0 then |
4891
189cfe565d03
util.watchdog: Pass watchdog object to callback so that it doesn't always have to be a closure
Matthew Wild <mwild1@gmail.com>
parents:
4401
diff
changeset
|
19 return watchdog:callback(); |
4401
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 return time_left + 1; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 end); |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 return watchdog; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 end |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 function watchdog_methods:reset() |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 self.last_reset = os_time(); |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 end |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 function watchdog_methods:cancel() |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 self.last_reset = nil; |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 end |
0ed617f58404
util.watchdog: Watchdog timer library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
4891
diff
changeset
|
34 return { |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
4891
diff
changeset
|
35 new = new; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
4891
diff
changeset
|
36 }; |