Software /
code /
prosody
File
util/caps.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 |
line wrap: on
line source
-- Prosody IM -- Copyright (C) 2008-2010 Matthew Wild -- Copyright (C) 2008-2010 Waqas Hussain -- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. -- local base64 = require "util.encodings".base64.encode; local sha1 = require "util.hashes".sha1; local t_insert, t_sort, t_concat = table.insert, table.sort, table.concat; local ipairs = ipairs; local _ENV = nil; local function calculate_hash(disco_info) local identities, features, extensions = {}, {}, {}; for _, tag in ipairs(disco_info) do if tag.name == "identity" then t_insert(identities, (tag.attr.category or "").."\0"..(tag.attr.type or "").."\0"..(tag.attr["xml:lang"] or "").."\0"..(tag.attr.name or "")); elseif tag.name == "feature" then t_insert(features, tag.attr.var or ""); elseif tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then local form = {}; local FORM_TYPE; for _, field in ipairs(tag.tags) do if field.name == "field" and field.attr.var then local values = {}; for _, val in ipairs(field.tags) do val = #val.tags == 0 and val:get_text(); if val then t_insert(values, val); end end t_sort(values); if field.attr.var == "FORM_TYPE" then FORM_TYPE = values[1]; elseif #values > 0 then t_insert(form, field.attr.var.."\0"..t_concat(values, "<")); else t_insert(form, field.attr.var); end end end t_sort(form); form = t_concat(form, "<"); if FORM_TYPE then form = FORM_TYPE.."\0"..form; end t_insert(extensions, form); end end t_sort(identities); t_sort(features); t_sort(extensions); if #identities > 0 then identities = t_concat(identities, "<"):gsub("%z", "/").."<"; else identities = ""; end if #features > 0 then features = t_concat(features, "<").."<"; else features = ""; end if #extensions > 0 then extensions = t_concat(extensions, "<"):gsub("%z", "<").."<"; else extensions = ""; end local S = identities..features..extensions; local ver = base64(sha1(S)); return ver, S; end return { calculate_hash = calculate_hash; };