Annotate

plugins/muc/request.lib.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6226
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
1 -- Prosody IM
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
4 -- Copyright (C) 2014 Daurnimator
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
5 --
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
6 -- This project is MIT/X11 licensed. Please see the
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
7 -- COPYING file in the source package for more information.
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
8 --
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
9
12977
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 9703
diff changeset
10 local st = require "prosody.util.stanza";
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 9703
diff changeset
11 local jid_resource = require "prosody.util.jid".resource;
8851
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
12
8871
b67a861e883e MUC: Advertise support for voice requests
Kim Alvefur <zash@zash.se>
parents: 8865
diff changeset
13 module:hook("muc-disco#info", function(event)
b67a861e883e MUC: Advertise support for voice requests
Kim Alvefur <zash@zash.se>
parents: 8865
diff changeset
14 event.reply:tag("feature", {var = "http://jabber.org/protocol/muc#request"}):up();
b67a861e883e MUC: Advertise support for voice requests
Kim Alvefur <zash@zash.se>
parents: 8865
diff changeset
15 end);
b67a861e883e MUC: Advertise support for voice requests
Kim Alvefur <zash@zash.se>
parents: 8865
diff changeset
16
12977
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 9703
diff changeset
17 local voice_request_form = require "prosody.util.dataforms".new({
8865
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
18 title = "Voice Request";
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
19 {
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
20 name = "FORM_TYPE";
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
21 type = "hidden";
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
22 value = "http://jabber.org/protocol/muc#request";
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
23 },
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
24 {
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
25 name = "muc#jid";
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
26 type = "jid-single";
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
27 label = "User ID";
9034
1c709e3d2e5e MUC: Improve labels of all config form items
Matthew Wild <mwild1@gmail.com>
parents: 8871
diff changeset
28 desc = "The user's JID (address)";
8865
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
29 },
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
30 {
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
31 name = "muc#roomnick";
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
32 type = "text-single";
9034
1c709e3d2e5e MUC: Improve labels of all config form items
Matthew Wild <mwild1@gmail.com>
parents: 8871
diff changeset
33 label = "Room nickname";
1c709e3d2e5e MUC: Improve labels of all config form items
Matthew Wild <mwild1@gmail.com>
parents: 8871
diff changeset
34 desc = "The user's nickname within the room";
8865
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
35 },
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
36 {
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
37 name = "muc#role";
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
38 type = "list-single";
9034
1c709e3d2e5e MUC: Improve labels of all config form items
Matthew Wild <mwild1@gmail.com>
parents: 8871
diff changeset
39 label = "Requested role";
8865
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
40 value = "participant";
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
41 options = {
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
42 "none",
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
43 "visitor",
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
44 "participant",
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
45 "moderator",
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
46 };
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
47 },
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
48 {
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
49 name = "muc#request_allow";
6226
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
50 type = "boolean";
8865
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
51 label = "Grant voice to this person?";
9034
1c709e3d2e5e MUC: Improve labels of all config form items
Matthew Wild <mwild1@gmail.com>
parents: 8871
diff changeset
52 desc = "Specify whether this person is able to speak in a moderated room";
8865
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
53 value = false;
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
54 }
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
55 });
6226
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
56
8865
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
57 local function handle_request(room, origin, stanza, form)
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
58 local occupant = room:get_occupant_by_real_jid(stanza.attr.from);
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
59 local fields = voice_request_form:data(form);
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
60 local event = {
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
61 room = room;
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
62 origin = origin;
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
63 stanza = stanza;
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
64 fields = fields;
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
65 occupant = occupant;
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
66 };
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
67 if occupant.role == "moderator" then
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
68 module:log("debug", "%s responded to a voice request in %s", jid_resource(occupant.nick), room.jid);
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
69 module:fire_event("muc-voice-response", event);
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
70 else
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
71 module:log("debug", "%s requested voice in %s", jid_resource(occupant.nick), room.jid);
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
72 module:fire_event("muc-voice-request", event);
6226
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
73 end
8865
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
74 end
6226
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
75
8851
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
76 module:hook("muc-voice-request", function(event)
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
77 if event.occupant.role == "visitor" then
8854
5cd7813d4e94 MUC: Split out the nickname from the full room JID in voice request from
Kim Alvefur <zash@zash.se>
parents: 8853
diff changeset
78 local nick = jid_resource(event.occupant.nick);
8853
f84f566dea58 MUC: Reuse the same dataform for voice requests
Kim Alvefur <zash@zash.se>
parents: 8852
diff changeset
79 local formdata = {
f84f566dea58 MUC: Reuse the same dataform for voice requests
Kim Alvefur <zash@zash.se>
parents: 8852
diff changeset
80 ["muc#jid"] = event.stanza.attr.from;
8854
5cd7813d4e94 MUC: Split out the nickname from the full room JID in voice request from
Kim Alvefur <zash@zash.se>
parents: 8853
diff changeset
81 ["muc#roomnick"] = nick;
8853
f84f566dea58 MUC: Reuse the same dataform for voice requests
Kim Alvefur <zash@zash.se>
parents: 8852
diff changeset
82 };
8851
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
83
9081
ce57c69a20e2 MUC: Split long lines [luacheck strict]
Kim Alvefur <zash@zash.se>
parents: 9034
diff changeset
84 local message = st.message({ type = "normal"; from = event.room.jid })
9703
0cfb7b3593eb MUC: Fix traceback when requesting voice (fixes #1269) (thanks jonas’)
Kim Alvefur <zash@zash.se>
parents: 9081
diff changeset
85 :add_child(voice_request_form:form(formdata));
8851
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
86
8852
5e98d62f3f9b MUC: Ignore unused argumens [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8851
diff changeset
87 event.room:broadcast(message, function (_, occupant)
8851
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
88 return occupant.role == "moderator";
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
89 end);
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
90 end
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
91 end);
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
92
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
93 module:hook("muc-voice-response", function(event)
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
94 local actor = event.stanza.attr.from;
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
95 local affected_occupant = event.room:get_occupant_by_real_jid(event.fields["muc#jid"]);
8857
f4cc818db995 MUC: Get acting occupant into a local variable for easier access
Kim Alvefur <zash@zash.se>
parents: 8854
diff changeset
96 local occupant = event.occupant;
8851
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
97
8857
f4cc818db995 MUC: Get acting occupant into a local variable for easier access
Kim Alvefur <zash@zash.se>
parents: 8854
diff changeset
98 if occupant.role ~= "moderator" then
8859
11176f47a03a MUC: Add some debug logging for voice requests
Kim Alvefur <zash@zash.se>
parents: 8858
diff changeset
99 module:log("debug", "%s tried to grant voice but wasn't a moderator", jid_resource(occupant.nick));
8851
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
100 return;
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
101 end
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
102
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
103 if not event.fields["muc#request_allow"] then
8859
11176f47a03a MUC: Add some debug logging for voice requests
Kim Alvefur <zash@zash.se>
parents: 8858
diff changeset
104 module:log("debug", "%s did not grant voice", jid_resource(occupant.nick));
8851
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
105 return;
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
106 end
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
107
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
108 if not affected_occupant then
9081
ce57c69a20e2 MUC: Split long lines [luacheck strict]
Kim Alvefur <zash@zash.se>
parents: 9034
diff changeset
109 module:log("debug", "%s tried to grant voice to unknown occupant %s",
ce57c69a20e2 MUC: Split long lines [luacheck strict]
Kim Alvefur <zash@zash.se>
parents: 9034
diff changeset
110 jid_resource(occupant.nick), event.fields["muc#jid"]);
8851
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
111 return;
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
112 end
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
113
8858
2096742859c1 MUC: Invert final conditional to be consistent with the other if statements
Kim Alvefur <zash@zash.se>
parents: 8857
diff changeset
114 if affected_occupant.role ~= "visitor" then
9081
ce57c69a20e2 MUC: Split long lines [luacheck strict]
Kim Alvefur <zash@zash.se>
parents: 9034
diff changeset
115 module:log("debug", "%s tried to grant voice to %s but they already have it",
ce57c69a20e2 MUC: Split long lines [luacheck strict]
Kim Alvefur <zash@zash.se>
parents: 9034
diff changeset
116 jid_resource(occupant.nick), jid_resource(occupant.jid));
8858
2096742859c1 MUC: Invert final conditional to be consistent with the other if statements
Kim Alvefur <zash@zash.se>
parents: 8857
diff changeset
117 return;
8851
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
118 end
8858
2096742859c1 MUC: Invert final conditional to be consistent with the other if statements
Kim Alvefur <zash@zash.se>
parents: 8857
diff changeset
119
8860
0bb46a1bb398 MUC: Handle and return error in role change when granting voice
Kim Alvefur <zash@zash.se>
parents: 8859
diff changeset
120 module:log("debug", "%s granted voice to %s", jid_resource(event.occupant.nick), jid_resource(occupant.jid));
0bb46a1bb398 MUC: Handle and return error in role change when granting voice
Kim Alvefur <zash@zash.se>
parents: 8859
diff changeset
121 local ok, errtype, err = event.room:set_role(actor, affected_occupant.nick, "participant", "Voice granted");
0bb46a1bb398 MUC: Handle and return error in role change when granting voice
Kim Alvefur <zash@zash.se>
parents: 8859
diff changeset
122
0bb46a1bb398 MUC: Handle and return error in role change when granting voice
Kim Alvefur <zash@zash.se>
parents: 8859
diff changeset
123 if not ok then
0bb46a1bb398 MUC: Handle and return error in role change when granting voice
Kim Alvefur <zash@zash.se>
parents: 8859
diff changeset
124 module:log("debug", "Error granting voice: %s", err or errtype);
0bb46a1bb398 MUC: Handle and return error in role change when granting voice
Kim Alvefur <zash@zash.se>
parents: 8859
diff changeset
125 event.origin.send(st.error_reply(event.stanza, errtype, err));
0bb46a1bb398 MUC: Handle and return error in role change when granting voice
Kim Alvefur <zash@zash.se>
parents: 8859
diff changeset
126 end
8851
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
127 end);
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
128
ab5f678f1376 MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
129
6226
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
130 return {
8865
2a8bbfcb6868 MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents: 8860
diff changeset
131 handle_request = handle_request;
6226
7582deb85812 plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
daurnimator <quae@daurnimator.com>
parents:
diff changeset
132 };