Mercurial > prosody-hg
annotate plugins/muc/gc3.lib.lua @ 14016:1df1782ccdfe
prosodyctl shell: Improve process exit codes
This fixes a bug introduced in 3326c8a29a86 where prosodyctl shell would
always exit with non-zero error codes, even on success. Now it will exit with
0 for success, or 1 if any errors were printed.
It also updates the other exit codes in the shell command to help distinguish
between different error cases. These are based on the sysexits.h codes,
although it is not recommended to rely on that interface.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 19 Dec 2025 15:32:26 +0000 |
| parents | 356c8ec22e9a |
| children |
| rev | line source |
|---|---|
|
13908
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local jid_bare = require "prosody.util.jid".bare; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local st = require "prosody.util.stanza"; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local muc_util = module:require "muc/util"; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local valid_affiliations = muc_util.valid_affiliations; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local xmlns_gc3 = "urn:xmpp:gc3:tmp" |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 --luacheck: ignore 113/get_room_from_jid |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 function fetch_participant_list(room, stanza, origin) |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local from_jid = stanza.attr.from; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local from_aff = room:get_affiliation(from_jid); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local from_rank = valid_affiliations[from_aff or "none"]; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local required_aff_rank = valid_affiliations[room:get_members_only() and "member" or "none"]; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 if from_rank < required_aff_rank then |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 return true; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 end |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 local can_see_real_jids = not room:is_anonymous_for(from_jid); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 local reply = st.reply(stanza) |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 :tag("participants", { xmlns = xmlns_gc3 }); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 for jid, aff in room:each_affiliation() do |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 local nick = room:get_registered_nick(jid); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 local visible_jid = can_see_real_jids and jid or nil; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 reply:text_tag("item", nil, { |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 affiliation = aff; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 jid = visible_jid; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 nick = nick; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 id = room:get_occupant_id_from_jid(jid); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 }); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 end |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 origin.send(reply); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 return true; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 end |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 local function room_event_handler(handler, allow_nonexistent) |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 return function (event) |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 local origin, stanza = event.origin, event.stanza; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 local room_jid = jid_bare(stanza.attr.to); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 local room = get_room_from_jid(room_jid); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 if not room and allow_nonexistent ~= true then |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 return true; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 end |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 return handler(room, stanza, origin); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 end; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 end |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 module:hook("iq-get/bare/"..xmlns_gc3..":participants", room_event_handler(fetch_participant_list)); |
