Annotate

util/id.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 8016:9546c629289b
child 12110:b5b799a2a10c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8016
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- Prosody IM
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 -- Copyright (C) 2008-2017 Matthew Wild
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 -- Copyright (C) 2008-2017 Waqas Hussain
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 -- Copyright (C) 2008-2017 Kim Alvefur
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 --
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 -- This project is MIT/X11 licensed. Please see the
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 -- COPYING file in the source package for more information.
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 --
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 local s_gsub = string.gsub;
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local random_bytes = require "util.random".bytes;
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local base64_encode = require "util.encodings".base64.encode;
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 local b64url = { ["+"] = "-", ["/"] = "_", ["="] = "" };
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local function b64url_random(len)
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 return (s_gsub(base64_encode(random_bytes(len)), "[+/=]", b64url));
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 end
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 return {
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 short = function () return b64url_random(6); end;
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 medium = function () return b64url_random(12); end;
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 long = function () return b64url_random(24); end;
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 custom = function (size)
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 return function () return b64url_random(size); end;
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 end;
9546c629289b util.id: New util for producing random identifiers of varying sizes
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 }