2003-03-23 21:08:44 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_muc.erl
|
2007-12-24 14:57:53 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2010-04-14 01:00:14 +02:00
|
|
|
%%% Purpose : MUC support (XEP-0045)
|
2007-12-24 14:57:53 +01:00
|
|
|
%%% Created : 19 Mar 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2018-01-05 21:18:58 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2018 ProcessOne
|
2007-12-24 14:57:53 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-12 15:44:42 +01:00
|
|
|
%%%
|
2014-02-22 11:27:40 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-12-24 14:57:53 +01:00
|
|
|
%%%
|
2003-03-23 21:08:44 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_muc).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-12-24 14:57:53 +01:00
|
|
|
-author('alexey@process-one.net').
|
2003-03-23 21:08:44 +01:00
|
|
|
|
2015-05-21 17:02:36 +02:00
|
|
|
-protocol({xep, 45, '1.25'}).
|
|
|
|
|
2006-02-02 06:00:27 +01:00
|
|
|
-behaviour(gen_server).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2003-03-23 21:08:44 +01:00
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2006-02-02 06:00:27 +01:00
|
|
|
%% API
|
2017-02-14 10:39:26 +01:00
|
|
|
-export([start/2,
|
2005-06-20 05:18:13 +02:00
|
|
|
stop/1,
|
2017-02-22 17:46:47 +01:00
|
|
|
reload/3,
|
2007-01-19 05:46:44 +01:00
|
|
|
room_destroyed/4,
|
2012-03-31 13:41:54 +02:00
|
|
|
store_room/4,
|
2017-10-31 14:00:41 +01:00
|
|
|
store_room/5,
|
2012-03-31 13:41:54 +02:00
|
|
|
restore_room/3,
|
|
|
|
forget_room/3,
|
2009-02-16 16:24:40 +01:00
|
|
|
create_room/5,
|
2015-10-07 00:06:58 +02:00
|
|
|
shutdown_rooms/1,
|
2016-07-25 12:50:30 +02:00
|
|
|
process_disco_info/1,
|
|
|
|
process_disco_items/1,
|
|
|
|
process_vcard/1,
|
|
|
|
process_register/1,
|
|
|
|
process_muc_unique/1,
|
|
|
|
process_mucsub/1,
|
2017-01-13 10:03:39 +01:00
|
|
|
broadcast_service_message/3,
|
2015-10-07 00:06:58 +02:00
|
|
|
export/1,
|
2016-11-22 14:48:01 +01:00
|
|
|
import_info/0,
|
|
|
|
import/5,
|
|
|
|
import_start/2,
|
2016-04-13 20:07:32 +02:00
|
|
|
opts_to_binary/1,
|
2017-01-13 10:03:39 +01:00
|
|
|
find_online_room/2,
|
|
|
|
register_online_room/3,
|
|
|
|
get_online_rooms/1,
|
|
|
|
count_online_rooms/1,
|
|
|
|
register_online_user/4,
|
|
|
|
unregister_online_user/4,
|
2017-08-24 10:40:24 +02:00
|
|
|
iq_set_register_info/5,
|
2017-01-13 10:03:39 +01:00
|
|
|
count_online_rooms_by_user/3,
|
|
|
|
get_online_rooms_by_user/3,
|
2012-03-31 13:41:54 +02:00
|
|
|
can_use_nick/4]).
|
2003-03-23 21:08:44 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-export([init/1, handle_call/3, handle_cast/2,
|
2015-06-01 14:38:27 +02:00
|
|
|
handle_info/2, terminate/2, code_change/3,
|
2018-01-23 08:54:52 +01:00
|
|
|
mod_opt_type/1, mod_options/1, depends/2]).
|
2006-02-02 06:00:27 +01:00
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2016-07-25 12:50:30 +02:00
|
|
|
-include("xmpp.hrl").
|
2016-01-15 13:34:48 +01:00
|
|
|
-include("mod_muc.hrl").
|
2018-01-08 09:29:17 +01:00
|
|
|
-include("translate.hrl").
|
2003-04-17 21:47:43 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-record(state,
|
2017-08-08 16:46:26 +02:00
|
|
|
{hosts = [] :: [binary()],
|
2013-03-14 10:33:02 +01:00
|
|
|
server_host = <<"">> :: binary(),
|
|
|
|
access = {none, none, none, none} :: {atom(), atom(), atom(), atom()},
|
|
|
|
history_size = 20 :: non_neg_integer(),
|
2016-10-18 22:59:34 +02:00
|
|
|
max_rooms_discoitems = 100 :: non_neg_integer(),
|
2017-03-10 13:12:43 +01:00
|
|
|
queue_type = ram :: ram | file,
|
2013-03-14 10:33:02 +01:00
|
|
|
default_room_opts = [] :: list(),
|
2018-07-05 08:31:55 +02:00
|
|
|
room_shaper = none :: ejabberd_shaper:shaper()}).
|
2006-02-02 06:00:27 +01:00
|
|
|
|
2016-04-13 20:07:32 +02:00
|
|
|
-type muc_room_opts() :: [{atom(), any()}].
|
|
|
|
-callback init(binary(), gen_mod:opts()) -> any().
|
2016-11-22 14:48:01 +01:00
|
|
|
-callback import(binary(), binary(), [binary()]) -> ok.
|
2017-10-31 14:00:41 +01:00
|
|
|
-callback store_room(binary(), binary(), binary(), list(), list()|undefined) -> {atomic, any()}.
|
2016-04-13 20:07:32 +02:00
|
|
|
-callback restore_room(binary(), binary(), binary()) -> muc_room_opts() | error.
|
|
|
|
-callback forget_room(binary(), binary(), binary()) -> {atomic, any()}.
|
|
|
|
-callback can_use_nick(binary(), binary(), jid(), binary()) -> boolean().
|
|
|
|
-callback get_rooms(binary(), binary()) -> [#muc_room{}].
|
|
|
|
-callback get_nick(binary(), binary(), jid()) -> binary() | error.
|
|
|
|
-callback set_nick(binary(), binary(), jid(), binary()) -> {atomic, ok | false}.
|
2017-03-29 11:58:01 +02:00
|
|
|
-callback register_online_room(binary(), binary(), binary(), pid()) -> any().
|
|
|
|
-callback unregister_online_room(binary(), binary(), binary(), pid()) -> any().
|
|
|
|
-callback find_online_room(binary(), binary(), binary()) -> {ok, pid()} | error.
|
|
|
|
-callback get_online_rooms(binary(), binary(), undefined | rsm_set()) -> [{binary(), binary(), pid()}].
|
|
|
|
-callback count_online_rooms(binary(), binary()) -> non_neg_integer().
|
2017-01-13 10:03:39 +01:00
|
|
|
-callback rsm_supported() -> boolean().
|
2017-03-29 11:58:01 +02:00
|
|
|
-callback register_online_user(binary(), ljid(), binary(), binary()) -> any().
|
|
|
|
-callback unregister_online_user(binary(), ljid(), binary(), binary()) -> any().
|
|
|
|
-callback count_online_rooms_by_user(binary(), binary(), binary()) -> non_neg_integer().
|
|
|
|
-callback get_online_rooms_by_user(binary(), binary(), binary()) -> [{binary(), binary()}].
|
2018-08-10 17:46:47 +02:00
|
|
|
-callback get_subscribed_rooms(binary(), binary(), jid()) -> [{ljid(), [binary()]}] | [].
|
2016-04-13 20:07:32 +02:00
|
|
|
|
2006-02-02 06:00:27 +01:00
|
|
|
%%====================================================================
|
|
|
|
%% API
|
|
|
|
%%====================================================================
|
2005-06-20 05:18:13 +02:00
|
|
|
start(Host, Opts) ->
|
2017-02-14 10:39:26 +01:00
|
|
|
gen_mod:start_child(?MODULE, Host, Opts).
|
2006-02-02 06:00:27 +01:00
|
|
|
|
|
|
|
stop(Host) ->
|
2013-06-19 13:30:31 +02:00
|
|
|
Rooms = shutdown_rooms(Host),
|
2017-02-14 10:39:26 +01:00
|
|
|
gen_mod:stop_child(?MODULE, Host),
|
2013-06-19 13:30:31 +02:00
|
|
|
{wait, Rooms}.
|
|
|
|
|
2017-02-22 17:46:47 +01:00
|
|
|
reload(Host, NewOpts, OldOpts) ->
|
|
|
|
Proc = gen_mod:get_module_proc(Host, ?MODULE),
|
|
|
|
gen_server:cast(Proc, {reload, Host, NewOpts, OldOpts}).
|
|
|
|
|
2016-07-06 13:58:48 +02:00
|
|
|
depends(_Host, _Opts) ->
|
|
|
|
[{mod_mam, soft}].
|
|
|
|
|
2013-06-19 13:30:31 +02:00
|
|
|
shutdown_rooms(Host) ->
|
2017-01-13 10:03:39 +01:00
|
|
|
RMod = gen_mod:ram_db_mod(Host, ?MODULE),
|
2013-06-19 13:30:31 +02:00
|
|
|
MyHost = gen_mod:get_module_opt_host(Host, mod_muc,
|
|
|
|
<<"conference.@HOST@">>),
|
2017-03-29 11:58:01 +02:00
|
|
|
Rooms = RMod:get_online_rooms(Host, MyHost, undefined),
|
2017-01-23 11:51:05 +01:00
|
|
|
lists:flatmap(
|
2017-01-13 10:03:39 +01:00
|
|
|
fun({_, _, Pid}) when node(Pid) == node() ->
|
|
|
|
Pid ! shutdown,
|
2017-01-23 11:51:05 +01:00
|
|
|
[Pid];
|
2017-01-13 10:03:39 +01:00
|
|
|
(_) ->
|
2017-01-23 11:51:05 +01:00
|
|
|
[]
|
2017-01-13 10:03:39 +01:00
|
|
|
end, Rooms).
|
2006-02-02 06:00:27 +01:00
|
|
|
|
2008-02-28 01:30:23 +01:00
|
|
|
%% This function is called by a room in three situations:
|
|
|
|
%% A) The owner of the room destroyed it
|
|
|
|
%% B) The only participant of a temporary room leaves it
|
|
|
|
%% C) mod_muc:stop was called, and each room is being terminated
|
|
|
|
%% In this case, the mod_muc process died before the room processes
|
|
|
|
%% So the message sending must be catched
|
2007-01-19 05:46:44 +01:00
|
|
|
room_destroyed(Host, Room, Pid, ServerHost) ->
|
2017-02-14 10:39:26 +01:00
|
|
|
catch gen_mod:get_module_proc(ServerHost, ?MODULE) !
|
2013-03-14 10:33:02 +01:00
|
|
|
{room_destroyed, {Room, Host}, Pid},
|
2006-02-02 06:00:27 +01:00
|
|
|
ok.
|
|
|
|
|
2009-02-16 16:24:40 +01:00
|
|
|
%% @doc Create a room.
|
|
|
|
%% If Opts = default, the default room options are used.
|
|
|
|
%% Else use the passed options as defined in mod_muc_room.
|
|
|
|
create_room(Host, Name, From, Nick, Opts) ->
|
2017-08-08 16:46:26 +02:00
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
Proc = gen_mod:get_module_proc(ServerHost, ?MODULE),
|
|
|
|
gen_server:call(Proc, {create, Name, Host, From, Nick, Opts}).
|
2009-02-16 16:24:40 +01:00
|
|
|
|
2012-04-27 11:52:05 +02:00
|
|
|
store_room(ServerHost, Host, Name, Opts) ->
|
2017-10-31 14:00:41 +01:00
|
|
|
store_room(ServerHost, Host, Name, Opts, undefined).
|
|
|
|
|
|
|
|
store_room(ServerHost, Host, Name, Opts, ChangesHints) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
LServer = jid:nameprep(ServerHost),
|
2016-04-13 20:07:32 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
2017-10-31 14:00:41 +01:00
|
|
|
Mod:store_room(LServer, Host, Name, Opts, ChangesHints).
|
2012-04-27 11:52:05 +02:00
|
|
|
|
|
|
|
restore_room(ServerHost, Host, Name) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
LServer = jid:nameprep(ServerHost),
|
2016-04-13 20:07:32 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
|
|
|
Mod:restore_room(LServer, Host, Name).
|
2006-02-02 06:00:27 +01:00
|
|
|
|
2012-04-27 11:52:05 +02:00
|
|
|
forget_room(ServerHost, Host, Name) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
LServer = jid:nameprep(ServerHost),
|
2017-08-10 13:49:05 +02:00
|
|
|
ejabberd_hooks:run(remove_room, LServer, [LServer, Name, Host]),
|
2016-04-13 20:07:32 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
|
|
|
Mod:forget_room(LServer, Host, Name).
|
2006-02-02 06:00:27 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
can_use_nick(_ServerHost, _Host, _JID, <<"">>) -> false;
|
2012-04-27 11:52:05 +02:00
|
|
|
can_use_nick(ServerHost, Host, JID, Nick) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
LServer = jid:nameprep(ServerHost),
|
2016-04-13 20:07:32 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
|
|
|
Mod:can_use_nick(LServer, Host, JID, Nick).
|
2006-02-02 06:00:27 +01:00
|
|
|
|
2017-01-13 10:03:39 +01:00
|
|
|
-spec find_online_room(binary(), binary()) -> {ok, pid()} | error.
|
|
|
|
find_online_room(Room, Host) ->
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
2017-03-29 11:58:01 +02:00
|
|
|
RMod:find_online_room(ServerHost, Room, Host).
|
2017-01-13 10:03:39 +01:00
|
|
|
|
|
|
|
-spec register_online_room(binary(), binary(), pid()) -> any().
|
|
|
|
register_online_room(Room, Host, Pid) ->
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
2017-03-29 11:58:01 +02:00
|
|
|
RMod:register_online_room(ServerHost, Room, Host, Pid).
|
2017-01-13 10:03:39 +01:00
|
|
|
|
|
|
|
-spec get_online_rooms(binary()) -> [{binary(), binary(), pid()}].
|
|
|
|
get_online_rooms(Host) ->
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
get_online_rooms(ServerHost, Host).
|
|
|
|
|
|
|
|
-spec count_online_rooms(binary()) -> non_neg_integer().
|
|
|
|
count_online_rooms(Host) ->
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
count_online_rooms(ServerHost, Host).
|
|
|
|
|
|
|
|
-spec register_online_user(binary(), ljid(), binary(), binary()) -> any().
|
|
|
|
register_online_user(ServerHost, LJID, Name, Host) ->
|
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
2017-03-29 11:58:01 +02:00
|
|
|
RMod:register_online_user(ServerHost, LJID, Name, Host).
|
2017-01-13 10:03:39 +01:00
|
|
|
|
|
|
|
-spec unregister_online_user(binary(), ljid(), binary(), binary()) -> any().
|
|
|
|
unregister_online_user(ServerHost, LJID, Name, Host) ->
|
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
2017-03-29 11:58:01 +02:00
|
|
|
RMod:unregister_online_user(ServerHost, LJID, Name, Host).
|
2017-01-13 10:03:39 +01:00
|
|
|
|
|
|
|
-spec count_online_rooms_by_user(binary(), binary(), binary()) -> non_neg_integer().
|
|
|
|
count_online_rooms_by_user(ServerHost, LUser, LServer) ->
|
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
2017-03-29 11:58:01 +02:00
|
|
|
RMod:count_online_rooms_by_user(ServerHost, LUser, LServer).
|
2017-01-13 10:03:39 +01:00
|
|
|
|
|
|
|
-spec get_online_rooms_by_user(binary(), binary(), binary()) -> [{binary(), binary()}].
|
|
|
|
get_online_rooms_by_user(ServerHost, LUser, LServer) ->
|
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
2017-03-29 11:58:01 +02:00
|
|
|
RMod:get_online_rooms_by_user(ServerHost, LUser, LServer).
|
2017-01-13 10:03:39 +01:00
|
|
|
|
2006-02-02 06:00:27 +01:00
|
|
|
%%====================================================================
|
|
|
|
%% gen_server callbacks
|
|
|
|
%%====================================================================
|
|
|
|
|
|
|
|
init([Host, Opts]) ->
|
2017-02-14 08:25:08 +01:00
|
|
|
process_flag(trap_exit, true),
|
2017-08-08 16:46:26 +02:00
|
|
|
#state{access = Access, hosts = MyHosts,
|
2017-03-10 13:12:43 +01:00
|
|
|
history_size = HistorySize, queue_type = QueueType,
|
2017-02-22 17:46:47 +01:00
|
|
|
room_shaper = RoomShaper} = State = init_state(Host, Opts),
|
2016-04-13 20:07:32 +02:00
|
|
|
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
|
2017-01-13 10:03:39 +01:00
|
|
|
RMod = gen_mod:ram_db_mod(Host, Opts, ?MODULE),
|
2017-08-08 16:46:26 +02:00
|
|
|
Mod:init(Host, [{hosts, MyHosts}|Opts]),
|
|
|
|
RMod:init(Host, [{hosts, MyHosts}|Opts]),
|
|
|
|
lists:foreach(
|
|
|
|
fun(MyHost) ->
|
2018-02-11 10:54:15 +01:00
|
|
|
register_iq_handlers(MyHost),
|
2017-08-08 16:46:26 +02:00
|
|
|
ejabberd_router:register_route(MyHost, Host),
|
|
|
|
load_permanent_rooms(MyHost, Host, Access, HistorySize,
|
|
|
|
RoomShaper, QueueType)
|
|
|
|
end, MyHosts),
|
2017-02-22 17:46:47 +01:00
|
|
|
{ok, State}.
|
|
|
|
|
|
|
|
handle_call(stop, _From, State) ->
|
|
|
|
{stop, normal, ok, State};
|
2017-08-08 16:46:26 +02:00
|
|
|
handle_call({create, Room, Host, From, Nick, Opts}, _From,
|
|
|
|
#state{server_host = ServerHost,
|
2017-02-22 17:46:47 +01:00
|
|
|
access = Access, default_room_opts = DefOpts,
|
2017-03-10 13:12:43 +01:00
|
|
|
history_size = HistorySize, queue_type = QueueType,
|
2017-02-22 17:46:47 +01:00
|
|
|
room_shaper = RoomShaper} = State) ->
|
|
|
|
?DEBUG("MUC: create new room '~s'~n", [Room]),
|
|
|
|
NewOpts = case Opts of
|
|
|
|
default -> DefOpts;
|
|
|
|
_ -> Opts
|
|
|
|
end,
|
|
|
|
{ok, Pid} = mod_muc_room:start(
|
|
|
|
Host, ServerHost, Access,
|
|
|
|
Room, HistorySize,
|
|
|
|
RoomShaper, From,
|
2017-03-10 13:12:43 +01:00
|
|
|
Nick, NewOpts, QueueType),
|
2017-02-22 17:46:47 +01:00
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
2017-03-29 11:58:01 +02:00
|
|
|
RMod:register_online_room(ServerHost, Room, Host, Pid),
|
2017-07-27 17:02:06 +02:00
|
|
|
ejabberd_hooks:run(create_room, ServerHost, [ServerHost, Room, Host]),
|
2017-02-22 17:46:47 +01:00
|
|
|
{reply, ok, State}.
|
|
|
|
|
2017-08-08 16:46:26 +02:00
|
|
|
handle_cast({reload, ServerHost, NewOpts, OldOpts}, #state{hosts = OldHosts}) ->
|
2017-02-22 17:46:47 +01:00
|
|
|
NewMod = gen_mod:db_mod(ServerHost, NewOpts, ?MODULE),
|
|
|
|
NewRMod = gen_mod:ram_db_mod(ServerHost, NewOpts, ?MODULE),
|
|
|
|
OldMod = gen_mod:db_mod(ServerHost, OldOpts, ?MODULE),
|
|
|
|
OldRMod = gen_mod:ram_db_mod(ServerHost, OldOpts, ?MODULE),
|
2017-08-08 16:46:26 +02:00
|
|
|
#state{hosts = NewHosts} = NewState = init_state(ServerHost, NewOpts),
|
2017-02-22 17:46:47 +01:00
|
|
|
if NewMod /= OldMod ->
|
2017-08-08 16:46:26 +02:00
|
|
|
NewMod:init(ServerHost, [{hosts, NewHosts}|NewOpts]);
|
2017-02-22 17:46:47 +01:00
|
|
|
true ->
|
|
|
|
ok
|
|
|
|
end,
|
|
|
|
if NewRMod /= OldRMod ->
|
2017-08-08 16:46:26 +02:00
|
|
|
NewRMod:init(ServerHost, [{hosts, NewHosts}|NewOpts]);
|
2017-02-22 17:46:47 +01:00
|
|
|
true ->
|
|
|
|
ok
|
|
|
|
end,
|
2017-08-08 16:46:26 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun(NewHost) ->
|
|
|
|
ejabberd_router:register_route(NewHost, ServerHost),
|
2018-02-11 10:54:15 +01:00
|
|
|
register_iq_handlers(NewHost)
|
2017-08-08 16:46:26 +02:00
|
|
|
end, NewHosts -- OldHosts),
|
|
|
|
lists:foreach(
|
|
|
|
fun(OldHost) ->
|
|
|
|
ejabberd_router:unregister_route(OldHost),
|
|
|
|
unregister_iq_handlers(OldHost)
|
|
|
|
end, OldHosts -- NewHosts),
|
2018-07-08 13:52:12 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun(Host) ->
|
|
|
|
lists:foreach(
|
|
|
|
fun({_, _, Pid}) when node(Pid) == node() ->
|
|
|
|
Pid ! config_reloaded;
|
|
|
|
(_) ->
|
|
|
|
ok
|
|
|
|
end, get_online_rooms(ServerHost, Host))
|
|
|
|
end, misc:intersection(NewHosts, OldHosts)),
|
2017-02-22 17:46:47 +01:00
|
|
|
{noreply, NewState};
|
|
|
|
handle_cast(Msg, State) ->
|
|
|
|
?WARNING_MSG("unexpected cast: ~p", [Msg]),
|
|
|
|
{noreply, State}.
|
|
|
|
|
|
|
|
handle_info({route, Packet},
|
2017-08-08 16:46:26 +02:00
|
|
|
#state{server_host = ServerHost,
|
2017-02-22 17:46:47 +01:00
|
|
|
access = Access, default_room_opts = DefRoomOpts,
|
2017-03-10 13:12:43 +01:00
|
|
|
history_size = HistorySize, queue_type = QueueType,
|
2017-02-22 17:46:47 +01:00
|
|
|
max_rooms_discoitems = MaxRoomsDiscoItems,
|
|
|
|
room_shaper = RoomShaper} = State) ->
|
|
|
|
From = xmpp:get_from(Packet),
|
|
|
|
To = xmpp:get_to(Packet),
|
2017-08-08 16:46:26 +02:00
|
|
|
Host = To#jid.lserver,
|
2017-02-22 17:46:47 +01:00
|
|
|
case catch do_route(Host, ServerHost, Access, HistorySize, RoomShaper,
|
2017-03-10 13:12:43 +01:00
|
|
|
From, To, Packet, DefRoomOpts, MaxRoomsDiscoItems,
|
|
|
|
QueueType) of
|
2017-02-22 17:46:47 +01:00
|
|
|
{'EXIT', Reason} ->
|
|
|
|
?ERROR_MSG("~p", [Reason]);
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end,
|
|
|
|
{noreply, State};
|
|
|
|
handle_info({room_destroyed, {Room, Host}, Pid}, State) ->
|
|
|
|
ServerHost = State#state.server_host,
|
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
2017-03-29 11:58:01 +02:00
|
|
|
RMod:unregister_online_room(ServerHost, Room, Host, Pid),
|
2017-02-22 17:46:47 +01:00
|
|
|
{noreply, State};
|
|
|
|
handle_info(Info, State) ->
|
|
|
|
?ERROR_MSG("unexpected info: ~p", [Info]),
|
|
|
|
{noreply, State}.
|
|
|
|
|
2017-08-08 16:46:26 +02:00
|
|
|
terminate(_Reason, #state{hosts = MyHosts}) ->
|
|
|
|
lists:foreach(
|
|
|
|
fun(MyHost) ->
|
|
|
|
ejabberd_router:unregister_route(MyHost),
|
|
|
|
unregister_iq_handlers(MyHost)
|
|
|
|
end, MyHosts).
|
2017-02-22 17:46:47 +01:00
|
|
|
|
|
|
|
code_change(_OldVsn, State, _Extra) -> {ok, State}.
|
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
%%% Internal functions
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
init_state(Host, Opts) ->
|
2018-01-23 08:54:52 +01:00
|
|
|
MyHosts = gen_mod:get_opt_hosts(Host, Opts),
|
|
|
|
Access = gen_mod:get_opt(access, Opts),
|
|
|
|
AccessCreate = gen_mod:get_opt(access_create, Opts),
|
|
|
|
AccessAdmin = gen_mod:get_opt(access_admin, Opts),
|
|
|
|
AccessPersistent = gen_mod:get_opt(access_persistent, Opts),
|
|
|
|
HistorySize = gen_mod:get_opt(history_size, Opts),
|
|
|
|
MaxRoomsDiscoItems = gen_mod:get_opt(max_rooms_discoitems, Opts),
|
|
|
|
DefRoomOpts = gen_mod:get_opt(default_room_options, Opts),
|
|
|
|
QueueType = gen_mod:get_opt(queue_type, Opts),
|
|
|
|
RoomShaper = gen_mod:get_opt(room_shaper, Opts),
|
2017-08-08 16:46:26 +02:00
|
|
|
#state{hosts = MyHosts,
|
2017-02-22 17:46:47 +01:00
|
|
|
server_host = Host,
|
|
|
|
access = {Access, AccessCreate, AccessAdmin, AccessPersistent},
|
|
|
|
default_room_opts = DefRoomOpts,
|
2017-03-10 13:12:43 +01:00
|
|
|
queue_type = QueueType,
|
2017-02-22 17:46:47 +01:00
|
|
|
history_size = HistorySize,
|
|
|
|
max_rooms_discoitems = MaxRoomsDiscoItems,
|
|
|
|
room_shaper = RoomShaper}.
|
|
|
|
|
2018-02-11 10:54:15 +01:00
|
|
|
register_iq_handlers(Host) ->
|
2017-02-22 17:46:47 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_REGISTER,
|
2018-02-11 10:54:15 +01:00
|
|
|
?MODULE, process_register),
|
2017-02-22 17:46:47 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_VCARD,
|
2018-02-11 10:54:15 +01:00
|
|
|
?MODULE, process_vcard),
|
2017-02-22 17:46:47 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MUCSUB,
|
2018-02-11 10:54:15 +01:00
|
|
|
?MODULE, process_mucsub),
|
2017-02-22 17:46:47 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MUC_UNIQUE,
|
2018-02-11 10:54:15 +01:00
|
|
|
?MODULE, process_muc_unique),
|
2017-02-22 17:46:47 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_INFO,
|
2018-02-11 10:54:15 +01:00
|
|
|
?MODULE, process_disco_info),
|
2017-02-22 17:46:47 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_ITEMS,
|
2018-02-11 10:54:15 +01:00
|
|
|
?MODULE, process_disco_items).
|
2017-02-22 17:46:47 +01:00
|
|
|
|
|
|
|
unregister_iq_handlers(Host) ->
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_REGISTER),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_VCARD),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_MUCSUB),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_MUC_UNIQUE),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_DISCO_INFO),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_DISCO_ITEMS).
|
2003-03-23 21:08:44 +01:00
|
|
|
|
2007-09-01 23:05:04 +02:00
|
|
|
do_route(Host, ServerHost, Access, HistorySize, RoomShaper,
|
2017-03-10 13:12:43 +01:00
|
|
|
From, To, Packet, DefRoomOpts, _MaxRoomsDiscoItems, QueueType) ->
|
2007-08-02 04:30:25 +02:00
|
|
|
{AccessRoute, _AccessCreate, _AccessAdmin, _AccessPersistent} = Access,
|
2005-06-20 05:18:13 +02:00
|
|
|
case acl:match_rule(ServerHost, AccessRoute, From) of
|
2004-05-17 22:36:41 +02:00
|
|
|
allow ->
|
2007-09-01 23:05:04 +02:00
|
|
|
do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
|
2017-03-10 13:12:43 +01:00
|
|
|
From, To, Packet, DefRoomOpts, QueueType);
|
2016-07-25 12:50:30 +02:00
|
|
|
deny ->
|
|
|
|
Lang = xmpp:get_lang(Packet),
|
2013-03-14 10:33:02 +01:00
|
|
|
ErrText = <<"Access denied by service policy">>,
|
2016-07-25 12:50:30 +02:00
|
|
|
Err = xmpp:err_forbidden(ErrText, Lang),
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_router:route_error(Packet, Err)
|
2004-05-17 22:36:41 +02:00
|
|
|
end.
|
|
|
|
|
2016-07-25 12:50:30 +02:00
|
|
|
do_route1(_Host, _ServerHost, _Access, _HistorySize, _RoomShaper,
|
2017-02-16 09:00:26 +01:00
|
|
|
_From, #jid{luser = <<"">>, lresource = <<"">>} = _To,
|
2017-03-10 13:12:43 +01:00
|
|
|
#iq{} = IQ, _DefRoomOpts, _QueueType) ->
|
2018-05-09 09:30:00 +02:00
|
|
|
ejabberd_router:process_iq(IQ);
|
2016-07-25 12:50:30 +02:00
|
|
|
do_route1(Host, ServerHost, Access, _HistorySize, _RoomShaper,
|
2017-02-16 09:00:26 +01:00
|
|
|
From, #jid{luser = <<"">>, lresource = <<"">>} = _To,
|
2017-03-10 13:12:43 +01:00
|
|
|
#message{lang = Lang, body = Body, type = Type} = Packet, _, _) ->
|
2016-07-25 12:50:30 +02:00
|
|
|
{_AccessRoute, _AccessCreate, AccessAdmin, _AccessPersistent} = Access,
|
|
|
|
if Type == error ->
|
|
|
|
ok;
|
|
|
|
true ->
|
|
|
|
case acl:match_rule(ServerHost, AccessAdmin, From) of
|
|
|
|
allow ->
|
|
|
|
Msg = xmpp:get_text(Body),
|
2017-01-13 10:03:39 +01:00
|
|
|
broadcast_service_message(ServerHost, Host, Msg);
|
2016-07-25 12:50:30 +02:00
|
|
|
deny ->
|
|
|
|
ErrText = <<"Only service administrators are allowed "
|
|
|
|
"to send service messages">>,
|
2016-11-25 09:41:24 +01:00
|
|
|
Err = xmpp:err_forbidden(ErrText, Lang),
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_router:route_error(Packet, Err)
|
2016-07-25 12:50:30 +02:00
|
|
|
end
|
|
|
|
end;
|
|
|
|
do_route1(_Host, _ServerHost, _Access, _HistorySize, _RoomShaper,
|
2017-03-10 13:12:43 +01:00
|
|
|
_From, #jid{luser = <<"">>} = _To, Packet, _DefRoomOpts, _) ->
|
2016-10-17 12:37:23 +02:00
|
|
|
Err = xmpp:err_service_unavailable(),
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_router:route_error(Packet, Err);
|
2007-09-01 23:05:04 +02:00
|
|
|
do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
|
2017-03-10 13:12:43 +01:00
|
|
|
From, To, Packet, DefRoomOpts, QueueType) ->
|
2016-07-25 12:50:30 +02:00
|
|
|
{_AccessRoute, AccessCreate, _AccessAdmin, _AccessPersistent} = Access,
|
2015-11-24 16:44:13 +01:00
|
|
|
{Room, _, Nick} = jid:tolower(To),
|
2017-01-13 10:03:39 +01:00
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
2018-09-17 12:28:39 +02:00
|
|
|
case RMod:find_online_room(ServerHost, Room, Host) of
|
2017-01-13 10:03:39 +01:00
|
|
|
error ->
|
2016-09-07 10:15:19 +02:00
|
|
|
case is_create_request(Packet) of
|
|
|
|
true ->
|
2016-07-25 12:50:30 +02:00
|
|
|
case check_user_can_create_room(
|
|
|
|
ServerHost, AccessCreate, From, Room) and
|
|
|
|
check_create_roomid(ServerHost, Room) of
|
|
|
|
true ->
|
|
|
|
{ok, Pid} = start_new_room(
|
|
|
|
Host, ServerHost, Access,
|
|
|
|
Room, HistorySize,
|
2017-03-10 13:12:43 +01:00
|
|
|
RoomShaper, From, Nick, DefRoomOpts,
|
|
|
|
QueueType),
|
2017-03-29 11:58:01 +02:00
|
|
|
RMod:register_online_room(ServerHost, Room, Host, Pid),
|
2017-02-16 09:00:26 +01:00
|
|
|
mod_muc_room:route(Pid, Packet),
|
2016-07-25 12:50:30 +02:00
|
|
|
ok;
|
|
|
|
false ->
|
2016-09-07 10:15:19 +02:00
|
|
|
Lang = xmpp:get_lang(Packet),
|
2016-07-25 12:50:30 +02:00
|
|
|
ErrText = <<"Room creation is denied by service policy">>,
|
2016-11-25 09:41:24 +01:00
|
|
|
Err = xmpp:err_forbidden(ErrText, Lang),
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_router:route_error(Packet, Err)
|
2015-10-07 00:06:58 +02:00
|
|
|
end;
|
2016-09-07 10:15:19 +02:00
|
|
|
false ->
|
2016-07-25 12:50:30 +02:00
|
|
|
Lang = xmpp:get_lang(Packet),
|
|
|
|
ErrText = <<"Conference room does not exist">>,
|
|
|
|
Err = xmpp:err_item_not_found(ErrText, Lang),
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_router:route_error(Packet, Err)
|
2016-07-25 12:50:30 +02:00
|
|
|
end;
|
2017-01-13 10:03:39 +01:00
|
|
|
{ok, Pid} ->
|
2016-07-25 12:50:30 +02:00
|
|
|
?DEBUG("MUC: send to process ~p~n", [Pid]),
|
2017-02-16 09:00:26 +01:00
|
|
|
mod_muc_room:route(Pid, Packet),
|
2016-07-25 12:50:30 +02:00
|
|
|
ok
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec process_vcard(iq()) -> iq().
|
2016-10-17 12:37:23 +02:00
|
|
|
process_vcard(#iq{type = get, lang = Lang, sub_els = [#vcard_temp{}]} = IQ) ->
|
2016-07-25 12:50:30 +02:00
|
|
|
xmpp:make_iq_result(
|
|
|
|
IQ, #vcard_temp{fn = <<"ejabberd/mod_muc">>,
|
2018-06-14 13:00:47 +02:00
|
|
|
url = ejabberd_config:get_uri(),
|
2018-06-20 11:50:36 +02:00
|
|
|
desc = misc:get_descr(Lang, ?T("ejabberd MUC module"))});
|
2016-07-25 12:50:30 +02:00
|
|
|
process_vcard(#iq{type = set, lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
2016-10-17 12:37:23 +02:00
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
|
|
|
process_vcard(#iq{lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"No module is handling this query">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
|
2016-07-25 12:50:30 +02:00
|
|
|
|
|
|
|
-spec process_register(iq()) -> iq().
|
2018-04-24 11:29:59 +02:00
|
|
|
process_register(#iq{type = Type, from = From, to = To, lang = Lang,
|
|
|
|
sub_els = [El = #register{}]} = IQ) ->
|
2016-07-25 12:50:30 +02:00
|
|
|
Host = To#jid.lserver,
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
2018-04-24 11:29:59 +02:00
|
|
|
AccessRegister = gen_mod:get_module_opt(ServerHost, ?MODULE, access_register),
|
|
|
|
case acl:match_rule(ServerHost, AccessRegister, From) of
|
|
|
|
allow ->
|
|
|
|
case Type of
|
|
|
|
get ->
|
|
|
|
xmpp:make_iq_result(
|
|
|
|
IQ, iq_get_register_info(ServerHost, Host, From, Lang));
|
|
|
|
set ->
|
|
|
|
case process_iq_register_set(ServerHost, Host, From, El, Lang) of
|
|
|
|
{result, Result} ->
|
|
|
|
xmpp:make_iq_result(IQ, Result);
|
|
|
|
{error, Err} ->
|
|
|
|
xmpp:make_error(IQ, Err)
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
deny ->
|
|
|
|
ErrText = <<"Access denied by service policy">>,
|
|
|
|
Err = xmpp:err_forbidden(ErrText, Lang),
|
2016-07-25 12:50:30 +02:00
|
|
|
xmpp:make_error(IQ, Err)
|
2003-03-23 21:08:44 +01:00
|
|
|
end.
|
|
|
|
|
2016-07-25 12:50:30 +02:00
|
|
|
-spec process_disco_info(iq()) -> iq().
|
|
|
|
process_disco_info(#iq{type = set, lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
2018-04-24 11:29:59 +02:00
|
|
|
process_disco_info(#iq{type = get, from = From, to = To, lang = Lang,
|
2016-08-05 07:41:08 +02:00
|
|
|
sub_els = [#disco_info{node = <<"">>}]} = IQ) ->
|
2016-07-25 12:50:30 +02:00
|
|
|
ServerHost = ejabberd_router:host_of_route(To#jid.lserver),
|
2017-01-13 10:03:39 +01:00
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
2018-04-24 11:29:59 +02:00
|
|
|
AccessRegister = gen_mod:get_module_opt(ServerHost, ?MODULE, access_register),
|
2016-07-25 12:50:30 +02:00
|
|
|
X = ejabberd_hooks:run_fold(disco_info, ServerHost, [],
|
2016-08-05 07:41:08 +02:00
|
|
|
[ServerHost, ?MODULE, <<"">>, Lang]),
|
2016-07-25 12:50:30 +02:00
|
|
|
MAMFeatures = case gen_mod:is_loaded(ServerHost, mod_mam) of
|
2017-11-08 13:15:39 +01:00
|
|
|
true -> [?NS_MAM_TMP, ?NS_MAM_0, ?NS_MAM_1, ?NS_MAM_2];
|
2016-07-25 12:50:30 +02:00
|
|
|
false -> []
|
|
|
|
end,
|
2017-01-13 10:03:39 +01:00
|
|
|
RSMFeatures = case RMod:rsm_supported() of
|
|
|
|
true -> [?NS_RSM];
|
|
|
|
false -> []
|
|
|
|
end,
|
2018-04-24 11:29:59 +02:00
|
|
|
RegisterFeatures = case acl:match_rule(ServerHost, AccessRegister, From) of
|
|
|
|
allow -> [?NS_REGISTER];
|
|
|
|
deny -> []
|
|
|
|
end,
|
2016-07-25 12:50:30 +02:00
|
|
|
Features = [?NS_DISCO_INFO, ?NS_DISCO_ITEMS,
|
2018-04-24 11:29:59 +02:00
|
|
|
?NS_MUC, ?NS_VCARD, ?NS_MUCSUB, ?NS_MUC_UNIQUE
|
|
|
|
| RegisterFeatures ++ RSMFeatures ++ MAMFeatures],
|
2018-01-23 08:54:52 +01:00
|
|
|
Name = gen_mod:get_module_opt(ServerHost, ?MODULE, name),
|
2016-07-25 12:50:30 +02:00
|
|
|
Identity = #identity{category = <<"conference">>,
|
|
|
|
type = <<"text">>,
|
2018-01-08 09:29:17 +01:00
|
|
|
name = translate:translate(Lang, Name)},
|
2016-07-25 12:50:30 +02:00
|
|
|
xmpp:make_iq_result(
|
|
|
|
IQ, #disco_info{features = Features,
|
|
|
|
identities = [Identity],
|
|
|
|
xdata = X});
|
2016-10-17 12:37:23 +02:00
|
|
|
process_disco_info(#iq{type = get, lang = Lang,
|
|
|
|
sub_els = [#disco_info{}]} = IQ) ->
|
|
|
|
xmpp:make_error(IQ, xmpp:err_item_not_found(<<"Node not found">>, Lang));
|
|
|
|
process_disco_info(#iq{lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"No module is handling this query">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
|
2016-07-25 12:50:30 +02:00
|
|
|
|
|
|
|
-spec process_disco_items(iq()) -> iq().
|
|
|
|
process_disco_items(#iq{type = set, lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
|
|
|
process_disco_items(#iq{type = get, from = From, to = To, lang = Lang,
|
|
|
|
sub_els = [#disco_items{node = Node, rsm = RSM}]} = IQ) ->
|
|
|
|
Host = To#jid.lserver,
|
2016-11-12 11:27:15 +01:00
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
MaxRoomsDiscoItems = gen_mod:get_module_opt(
|
2018-01-23 08:54:52 +01:00
|
|
|
ServerHost, ?MODULE, max_rooms_discoitems),
|
2017-01-13 10:03:39 +01:00
|
|
|
case iq_disco_items(ServerHost, Host, From, Lang,
|
|
|
|
MaxRoomsDiscoItems, Node, RSM) of
|
2016-11-20 16:08:49 +01:00
|
|
|
{error, Err} ->
|
|
|
|
xmpp:make_error(IQ, Err);
|
|
|
|
{result, Result} ->
|
|
|
|
xmpp:make_iq_result(IQ, Result)
|
|
|
|
end;
|
2016-10-17 12:37:23 +02:00
|
|
|
process_disco_items(#iq{lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"No module is handling this query">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
|
2016-07-25 12:50:30 +02:00
|
|
|
|
|
|
|
-spec process_muc_unique(iq()) -> iq().
|
|
|
|
process_muc_unique(#iq{type = set, lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
2016-10-17 12:37:23 +02:00
|
|
|
process_muc_unique(#iq{from = From, type = get,
|
|
|
|
sub_els = [#muc_unique{}]} = IQ) ->
|
2017-03-14 00:31:51 +01:00
|
|
|
Name = str:sha(term_to_binary([From, p1_time_compat:timestamp(),
|
2018-07-05 10:51:49 +02:00
|
|
|
p1_rand:get_string()])),
|
2016-07-25 12:50:30 +02:00
|
|
|
xmpp:make_iq_result(IQ, #muc_unique{name = Name}).
|
|
|
|
|
|
|
|
-spec process_mucsub(iq()) -> iq().
|
|
|
|
process_mucsub(#iq{type = set, lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
2016-10-17 12:37:23 +02:00
|
|
|
process_mucsub(#iq{type = get, from = From, to = To,
|
|
|
|
sub_els = [#muc_subscriptions{}]} = IQ) ->
|
2016-07-25 12:50:30 +02:00
|
|
|
Host = To#jid.lserver,
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
2018-08-10 17:46:47 +02:00
|
|
|
Subs = get_subscribed_rooms(ServerHost, Host, From),
|
|
|
|
xmpp:make_iq_result(IQ, #muc_subscriptions{list = Subs});
|
2016-10-17 12:37:23 +02:00
|
|
|
process_mucsub(#iq{lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"No module is handling this query">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
|
2016-07-25 12:50:30 +02:00
|
|
|
|
2016-09-07 10:15:19 +02:00
|
|
|
-spec is_create_request(stanza()) -> boolean().
|
|
|
|
is_create_request(#presence{type = available}) ->
|
|
|
|
true;
|
2016-10-17 12:37:23 +02:00
|
|
|
is_create_request(#iq{type = T} = IQ) when T == get; T == set ->
|
|
|
|
xmpp:has_subtag(IQ, #muc_subscribe{}) orelse
|
|
|
|
xmpp:has_subtag(IQ, #muc_owner{});
|
2016-09-07 10:15:19 +02:00
|
|
|
is_create_request(_) ->
|
|
|
|
false.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
check_user_can_create_room(ServerHost, AccessCreate,
|
2016-01-14 15:08:31 +01:00
|
|
|
From, _RoomID) ->
|
2009-04-22 14:05:10 +02:00
|
|
|
case acl:match_rule(ServerHost, AccessCreate, From) of
|
2016-01-14 15:08:31 +01:00
|
|
|
allow -> true;
|
2013-03-14 10:33:02 +01:00
|
|
|
_ -> false
|
2009-04-22 14:05:10 +02:00
|
|
|
end.
|
2003-03-23 21:08:44 +01:00
|
|
|
|
2016-01-14 15:08:31 +01:00
|
|
|
check_create_roomid(ServerHost, RoomID) ->
|
2018-01-23 08:54:52 +01:00
|
|
|
Max = gen_mod:get_module_opt(ServerHost, ?MODULE, max_room_id),
|
|
|
|
Regexp = gen_mod:get_module_opt(ServerHost, ?MODULE, regexp_room_id),
|
2016-01-14 15:08:31 +01:00
|
|
|
(byte_size(RoomID) =< Max) and
|
|
|
|
(re:run(RoomID, Regexp, [unicode, {capture, none}]) == match).
|
|
|
|
|
2012-04-27 11:52:05 +02:00
|
|
|
get_rooms(ServerHost, Host) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
LServer = jid:nameprep(ServerHost),
|
2016-04-13 20:07:32 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
|
|
|
Mod:get_rooms(LServer, Host).
|
2003-03-25 22:03:35 +01:00
|
|
|
|
2015-10-07 00:06:58 +02:00
|
|
|
load_permanent_rooms(Host, ServerHost, Access,
|
2017-03-10 13:12:43 +01:00
|
|
|
HistorySize, RoomShaper, QueueType) ->
|
2017-01-13 10:03:39 +01:00
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
2012-04-27 11:52:05 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun(R) ->
|
2015-10-07 00:06:58 +02:00
|
|
|
{Room, Host} = R#muc_room.name_host,
|
2017-03-29 11:58:01 +02:00
|
|
|
case RMod:find_online_room(ServerHost, Room, Host) of
|
2017-01-13 10:03:39 +01:00
|
|
|
error ->
|
2015-10-07 00:06:58 +02:00
|
|
|
{ok, Pid} = mod_muc_room:start(Host,
|
|
|
|
ServerHost, Access, Room,
|
|
|
|
HistorySize, RoomShaper,
|
2017-03-10 13:12:43 +01:00
|
|
|
R#muc_room.opts, QueueType),
|
2017-03-29 11:58:01 +02:00
|
|
|
RMod:register_online_room(ServerHost, Room, Host, Pid);
|
2017-01-13 10:03:39 +01:00
|
|
|
{ok, _} ->
|
|
|
|
ok
|
2015-10-07 00:06:58 +02:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
get_rooms(ServerHost, Host)).
|
2012-04-27 11:52:05 +02:00
|
|
|
|
2009-08-26 06:14:54 +02:00
|
|
|
start_new_room(Host, ServerHost, Access, Room,
|
2015-10-07 00:06:58 +02:00
|
|
|
HistorySize, RoomShaper, From,
|
2017-03-10 13:12:43 +01:00
|
|
|
Nick, DefRoomOpts, QueueType) ->
|
2014-01-23 15:39:52 +01:00
|
|
|
case restore_room(ServerHost, Host, Room) of
|
2015-10-07 00:06:58 +02:00
|
|
|
error ->
|
2009-08-26 06:14:54 +02:00
|
|
|
?DEBUG("MUC: open new room '~s'~n", [Room]),
|
2015-10-07 00:06:58 +02:00
|
|
|
mod_muc_room:start(Host, ServerHost, Access, Room,
|
|
|
|
HistorySize, RoomShaper,
|
2017-03-10 13:12:43 +01:00
|
|
|
From, Nick, DefRoomOpts, QueueType);
|
2015-10-07 00:06:58 +02:00
|
|
|
Opts ->
|
2009-08-26 06:14:54 +02:00
|
|
|
?DEBUG("MUC: restore room '~s'~n", [Room]),
|
2015-10-07 00:06:58 +02:00
|
|
|
mod_muc_room:start(Host, ServerHost, Access, Room,
|
2017-03-10 13:12:43 +01:00
|
|
|
HistorySize, RoomShaper, Opts, QueueType)
|
2009-08-26 06:14:54 +02:00
|
|
|
end.
|
|
|
|
|
2017-01-13 10:03:39 +01:00
|
|
|
-spec iq_disco_items(binary(), binary(), jid(), binary(), integer(), binary(),
|
2016-11-20 16:08:49 +01:00
|
|
|
rsm_set() | undefined) ->
|
|
|
|
{result, disco_items()} | {error, stanza_error()}.
|
2017-01-13 10:03:39 +01:00
|
|
|
iq_disco_items(ServerHost, Host, From, Lang, MaxRoomsDiscoItems, Node, RSM)
|
2016-11-20 16:08:49 +01:00
|
|
|
when Node == <<"">>; Node == <<"nonemptyrooms">>; Node == <<"emptyrooms">> ->
|
2017-01-13 10:03:39 +01:00
|
|
|
Count = count_online_rooms(ServerHost, Host),
|
2016-11-20 16:08:49 +01:00
|
|
|
Query = if Node == <<"">>, RSM == undefined, Count > MaxRoomsDiscoItems ->
|
|
|
|
{get_disco_item, only_non_empty, From, Lang};
|
|
|
|
Node == <<"nonemptyrooms">> ->
|
|
|
|
{get_disco_item, only_non_empty, From, Lang};
|
|
|
|
Node == <<"emptyrooms">> ->
|
|
|
|
{get_disco_item, 0, From, Lang};
|
|
|
|
true ->
|
|
|
|
{get_disco_item, all, From, Lang}
|
|
|
|
end,
|
2017-01-13 10:03:39 +01:00
|
|
|
Items = lists:flatmap(
|
|
|
|
fun(R) ->
|
|
|
|
case get_room_disco_item(R, Query) of
|
|
|
|
{ok, Item} -> [Item];
|
|
|
|
{error, _} -> []
|
|
|
|
end
|
|
|
|
end, get_online_rooms(ServerHost, Host, RSM)),
|
2016-11-20 16:08:49 +01:00
|
|
|
ResRSM = case Items of
|
|
|
|
[_|_] when RSM /= undefined ->
|
|
|
|
#disco_item{jid = #jid{luser = First}} = hd(Items),
|
|
|
|
#disco_item{jid = #jid{luser = Last}} = lists:last(Items),
|
|
|
|
#rsm_set{first = #rsm_first{data = First},
|
|
|
|
last = Last,
|
|
|
|
count = Count};
|
|
|
|
[] when RSM /= undefined ->
|
|
|
|
#rsm_set{count = Count};
|
|
|
|
_ ->
|
|
|
|
undefined
|
|
|
|
end,
|
|
|
|
{result, #disco_items{node = Node, items = Items, rsm = ResRSM}};
|
2017-01-13 10:03:39 +01:00
|
|
|
iq_disco_items(_ServerHost, _Host, _From, Lang, _MaxRoomsDiscoItems, _Node, _RSM) ->
|
2016-11-20 16:08:49 +01:00
|
|
|
{error, xmpp:err_item_not_found(<<"Node not found">>, Lang)}.
|
|
|
|
|
2017-01-13 10:03:39 +01:00
|
|
|
-spec get_room_disco_item({binary(), binary(), pid()},
|
|
|
|
term()) -> {ok, disco_item()} |
|
2017-09-25 12:01:00 +02:00
|
|
|
{error, timeout | notfound}.
|
2017-01-13 10:03:39 +01:00
|
|
|
get_room_disco_item({Name, Host, Pid}, Query) ->
|
2016-11-20 16:08:49 +01:00
|
|
|
RoomJID = jid:make(Name, Host),
|
2017-08-05 19:58:21 +02:00
|
|
|
try p1_fsm:sync_send_all_state_event(Pid, Query, 100) of
|
2016-11-20 16:08:49 +01:00
|
|
|
{item, Desc} ->
|
|
|
|
{ok, #disco_item{jid = RoomJID, name = Desc}};
|
|
|
|
false ->
|
|
|
|
{error, notfound}
|
2017-09-25 12:01:00 +02:00
|
|
|
catch _:{timeout, {p1_fsm, _, _}} ->
|
2016-11-20 16:08:49 +01:00
|
|
|
{error, timeout};
|
2017-09-25 12:01:00 +02:00
|
|
|
_:{_, {p1_fsm, _, _}} ->
|
2016-11-20 16:08:49 +01:00
|
|
|
{error, notfound}
|
|
|
|
end.
|
2008-12-23 14:04:42 +01:00
|
|
|
|
2017-01-13 10:03:39 +01:00
|
|
|
get_subscribed_rooms(ServerHost, Host, From) ->
|
2017-10-31 14:00:41 +01:00
|
|
|
LServer = jid:nameprep(ServerHost),
|
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
2016-09-09 12:04:47 +02:00
|
|
|
BareFrom = jid:remove_resource(From),
|
2017-10-31 14:00:41 +01:00
|
|
|
case Mod:get_subscribed_rooms(LServer, Host, BareFrom) of
|
2017-10-31 17:11:17 +01:00
|
|
|
not_implemented ->
|
2017-10-31 14:00:41 +01:00
|
|
|
Rooms = get_online_rooms(ServerHost, Host),
|
2017-10-31 17:11:17 +01:00
|
|
|
lists:flatmap(
|
|
|
|
fun({Name, _, Pid}) ->
|
|
|
|
case p1_fsm:sync_send_all_state_event(Pid, {is_subscribed, BareFrom}) of
|
2018-08-10 17:46:47 +02:00
|
|
|
{true, Nodes} ->
|
|
|
|
[#muc_subscription{jid = jid:make(Name, Host), events = Nodes}];
|
2017-10-31 17:11:17 +01:00
|
|
|
false -> []
|
|
|
|
end;
|
|
|
|
(_) ->
|
|
|
|
[]
|
|
|
|
end, Rooms);
|
2017-10-31 14:00:41 +01:00
|
|
|
V ->
|
2018-08-10 17:46:47 +02:00
|
|
|
[#muc_subscription{jid = Jid, events = Nodes} || {Jid, Nodes} <- V]
|
2017-10-31 14:00:41 +01:00
|
|
|
end.
|
2016-07-07 13:53:15 +02:00
|
|
|
|
2012-04-27 11:52:05 +02:00
|
|
|
get_nick(ServerHost, Host, From) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
LServer = jid:nameprep(ServerHost),
|
2016-04-13 20:07:32 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
|
|
|
Mod:get_nick(LServer, Host, From).
|
2012-04-27 11:52:05 +02:00
|
|
|
|
|
|
|
iq_get_register_info(ServerHost, Host, From, Lang) ->
|
2016-10-07 09:31:03 +02:00
|
|
|
{Nick, Registered} = case get_nick(ServerHost, Host, From) of
|
|
|
|
error -> {<<"">>, false};
|
|
|
|
N -> {N, true}
|
|
|
|
end,
|
2016-07-25 12:50:30 +02:00
|
|
|
Title = <<(translate:translate(
|
|
|
|
Lang, <<"Nickname Registration at ">>))/binary, Host/binary>>,
|
|
|
|
Inst = translate:translate(Lang, <<"Enter nickname you want to register">>),
|
2017-03-20 07:57:11 +01:00
|
|
|
Fields = muc_register:encode([{roomnick, Nick}], Lang),
|
2016-07-25 12:50:30 +02:00
|
|
|
X = #xdata{type = form, title = Title,
|
2016-10-07 09:31:03 +02:00
|
|
|
instructions = [Inst], fields = Fields},
|
2016-07-25 12:50:30 +02:00
|
|
|
#register{nick = Nick,
|
|
|
|
registered = Registered,
|
2018-02-12 15:12:46 +01:00
|
|
|
instructions =
|
2016-07-25 12:50:30 +02:00
|
|
|
translate:translate(
|
|
|
|
Lang, <<"You need a client that supports x:data "
|
|
|
|
"to register the nickname">>),
|
|
|
|
xdata = X}.
|
2003-04-17 21:47:43 +02:00
|
|
|
|
2012-04-27 11:52:05 +02:00
|
|
|
set_nick(ServerHost, Host, From, Nick) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
LServer = jid:nameprep(ServerHost),
|
2016-04-13 20:07:32 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
|
|
|
Mod:set_nick(LServer, Host, From, Nick).
|
2012-04-27 11:52:05 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
iq_set_register_info(ServerHost, Host, From, Nick,
|
|
|
|
Lang) ->
|
2012-04-27 11:52:05 +02:00
|
|
|
case set_nick(ServerHost, Host, From, Nick) of
|
2016-07-25 12:50:30 +02:00
|
|
|
{atomic, ok} -> {result, undefined};
|
2013-03-14 10:33:02 +01:00
|
|
|
{atomic, false} ->
|
|
|
|
ErrText = <<"That nickname is registered by another "
|
|
|
|
"person">>,
|
2016-07-25 12:50:30 +02:00
|
|
|
{error, xmpp:err_conflict(ErrText, Lang)};
|
2016-03-31 10:00:29 +02:00
|
|
|
_ ->
|
|
|
|
Txt = <<"Database failure">>,
|
2016-07-25 12:50:30 +02:00
|
|
|
{error, xmpp:err_internal_server_error(Txt, Lang)}
|
2003-04-17 21:47:43 +02:00
|
|
|
end.
|
|
|
|
|
2016-07-25 12:50:30 +02:00
|
|
|
process_iq_register_set(ServerHost, Host, From,
|
|
|
|
#register{remove = true}, Lang) ->
|
|
|
|
iq_set_register_info(ServerHost, Host, From, <<"">>, Lang);
|
|
|
|
process_iq_register_set(_ServerHost, _Host, _From,
|
|
|
|
#register{xdata = #xdata{type = cancel}}, _Lang) ->
|
|
|
|
{result, undefined};
|
|
|
|
process_iq_register_set(ServerHost, Host, From,
|
|
|
|
#register{nick = Nick, xdata = XData}, Lang) ->
|
|
|
|
case XData of
|
|
|
|
#xdata{type = submit, fields = Fs} ->
|
2016-10-07 09:31:03 +02:00
|
|
|
try
|
|
|
|
Options = muc_register:decode(Fs),
|
|
|
|
N = proplists:get_value(roomnick, Options),
|
|
|
|
iq_set_register_info(ServerHost, Host, From, N, Lang)
|
|
|
|
catch _:{muc_register, Why} ->
|
|
|
|
ErrText = muc_register:format_error(Why),
|
|
|
|
{error, xmpp:err_bad_request(ErrText, Lang)}
|
2016-07-25 12:50:30 +02:00
|
|
|
end;
|
|
|
|
#xdata{} ->
|
|
|
|
Txt = <<"Incorrect data form">>,
|
|
|
|
{error, xmpp:err_bad_request(Txt, Lang)};
|
|
|
|
_ when is_binary(Nick), Nick /= <<"">> ->
|
|
|
|
iq_set_register_info(ServerHost, Host, From, Nick, Lang);
|
|
|
|
_ ->
|
|
|
|
ErrText = <<"You must fill in field \"Nickname\" in the form">>,
|
|
|
|
{error, xmpp:err_not_acceptable(ErrText, Lang)}
|
2003-04-17 21:47:43 +02:00
|
|
|
end.
|
|
|
|
|
2017-02-18 07:36:27 +01:00
|
|
|
-spec broadcast_service_message(binary(), binary(), binary()) -> ok.
|
2017-01-13 10:03:39 +01:00
|
|
|
broadcast_service_message(ServerHost, Host, Msg) ->
|
2003-05-18 18:41:15 +02:00
|
|
|
lists:foreach(
|
2017-01-13 10:03:39 +01:00
|
|
|
fun({_, _, Pid}) ->
|
2017-08-05 19:58:21 +02:00
|
|
|
p1_fsm:send_all_state_event(
|
2015-10-07 00:06:58 +02:00
|
|
|
Pid, {service_message, Msg})
|
2017-01-13 10:03:39 +01:00
|
|
|
end, get_online_rooms(ServerHost, Host)).
|
|
|
|
|
|
|
|
-spec get_online_rooms(binary(), binary()) -> [{binary(), binary(), pid()}].
|
|
|
|
get_online_rooms(ServerHost, Host) ->
|
|
|
|
get_online_rooms(ServerHost, Host, undefined).
|
|
|
|
|
|
|
|
-spec get_online_rooms(binary(), binary(), undefined | rsm_set()) ->
|
|
|
|
[{binary(), binary(), pid()}].
|
|
|
|
get_online_rooms(ServerHost, Host, RSM) ->
|
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
2017-03-29 11:58:01 +02:00
|
|
|
RMod:get_online_rooms(ServerHost, Host, RSM).
|
2017-01-13 10:03:39 +01:00
|
|
|
|
|
|
|
-spec count_online_rooms(binary(), binary()) -> non_neg_integer().
|
|
|
|
count_online_rooms(ServerHost, Host) ->
|
|
|
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
2017-03-29 11:58:01 +02:00
|
|
|
RMod:count_online_rooms(ServerHost, Host).
|
2016-11-20 16:08:49 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
opts_to_binary(Opts) ->
|
|
|
|
lists:map(
|
|
|
|
fun({title, Title}) ->
|
|
|
|
{title, iolist_to_binary(Title)};
|
|
|
|
({description, Desc}) ->
|
|
|
|
{description, iolist_to_binary(Desc)};
|
|
|
|
({password, Pass}) ->
|
|
|
|
{password, iolist_to_binary(Pass)};
|
2017-11-24 07:45:22 +01:00
|
|
|
({subject, [C|_] = Subj}) when is_integer(C), C >= 0, C =< 255 ->
|
2013-03-14 10:33:02 +01:00
|
|
|
{subject, iolist_to_binary(Subj)};
|
|
|
|
({subject_author, Author}) ->
|
|
|
|
{subject_author, iolist_to_binary(Author)};
|
|
|
|
({affiliations, Affs}) ->
|
|
|
|
{affiliations, lists:map(
|
|
|
|
fun({{U, S, R}, Aff}) ->
|
|
|
|
NewAff =
|
|
|
|
case Aff of
|
|
|
|
{A, Reason} ->
|
|
|
|
{A, iolist_to_binary(Reason)};
|
|
|
|
_ ->
|
|
|
|
Aff
|
|
|
|
end,
|
|
|
|
{{iolist_to_binary(U),
|
|
|
|
iolist_to_binary(S),
|
|
|
|
iolist_to_binary(R)},
|
|
|
|
NewAff}
|
|
|
|
end, Affs)};
|
|
|
|
({captcha_whitelist, CWList}) ->
|
|
|
|
{captcha_whitelist, lists:map(
|
|
|
|
fun({U, S, R}) ->
|
|
|
|
{iolist_to_binary(U),
|
|
|
|
iolist_to_binary(S),
|
|
|
|
iolist_to_binary(R)}
|
|
|
|
end, CWList)};
|
|
|
|
(Opt) ->
|
|
|
|
Opt
|
|
|
|
end, Opts).
|
|
|
|
|
2016-04-13 20:07:32 +02:00
|
|
|
export(LServer) ->
|
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
|
|
|
Mod:export(LServer).
|
2003-03-26 21:51:18 +01:00
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
import_info() ->
|
|
|
|
[{<<"muc_room">>, 4}, {<<"muc_registered">>, 4}].
|
|
|
|
|
|
|
|
import_start(LServer, DBType) ->
|
|
|
|
Mod = gen_mod:db_mod(DBType, ?MODULE),
|
|
|
|
Mod:init(LServer, []).
|
2013-07-21 12:24:36 +02:00
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
import(LServer, {sql, _}, DBType, Tab, L) ->
|
2016-04-13 20:07:32 +02:00
|
|
|
Mod = gen_mod:db_mod(DBType, ?MODULE),
|
2016-11-22 14:48:01 +01:00
|
|
|
Mod:import(LServer, Tab, L).
|
2015-06-01 14:38:27 +02:00
|
|
|
|
|
|
|
mod_opt_type(access) ->
|
2016-06-21 13:18:24 +02:00
|
|
|
fun acl:access_rules_validator/1;
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(access_admin) ->
|
2016-06-21 13:18:24 +02:00
|
|
|
fun acl:access_rules_validator/1;
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(access_create) ->
|
2016-06-21 13:18:24 +02:00
|
|
|
fun acl:access_rules_validator/1;
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(access_persistent) ->
|
2016-06-21 13:18:24 +02:00
|
|
|
fun acl:access_rules_validator/1;
|
2018-04-24 11:29:59 +02:00
|
|
|
mod_opt_type(access_register) ->
|
|
|
|
fun acl:access_rules_validator/1;
|
2016-04-27 16:10:50 +02:00
|
|
|
mod_opt_type(db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
|
2017-01-13 10:03:39 +01:00
|
|
|
mod_opt_type(ram_db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(history_size) ->
|
|
|
|
fun (I) when is_integer(I), I >= 0 -> I end;
|
2018-07-08 19:28:11 +02:00
|
|
|
mod_opt_type(host) -> fun ejabberd_config:v_host/1;
|
2018-01-08 09:29:17 +01:00
|
|
|
mod_opt_type(name) -> fun iolist_to_binary/1;
|
2018-07-08 19:28:11 +02:00
|
|
|
mod_opt_type(hosts) -> fun ejabberd_config:v_hosts/1;
|
2015-06-03 14:18:09 +02:00
|
|
|
mod_opt_type(max_room_desc) ->
|
|
|
|
fun (infinity) -> infinity;
|
|
|
|
(I) when is_integer(I), I > 0 -> I
|
|
|
|
end;
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(max_room_id) ->
|
|
|
|
fun (infinity) -> infinity;
|
|
|
|
(I) when is_integer(I), I > 0 -> I
|
|
|
|
end;
|
2016-10-18 22:59:34 +02:00
|
|
|
mod_opt_type(max_rooms_discoitems) ->
|
|
|
|
fun (I) when is_integer(I), I >= 0 -> I end;
|
2016-02-05 12:08:40 +01:00
|
|
|
mod_opt_type(regexp_room_id) ->
|
2016-01-14 15:08:31 +01:00
|
|
|
fun iolist_to_binary/1;
|
2015-06-03 14:18:09 +02:00
|
|
|
mod_opt_type(max_room_name) ->
|
|
|
|
fun (infinity) -> infinity;
|
|
|
|
(I) when is_integer(I), I > 0 -> I
|
|
|
|
end;
|
|
|
|
mod_opt_type(max_user_conferences) ->
|
|
|
|
fun (I) when is_integer(I), I > 0 -> I end;
|
|
|
|
mod_opt_type(max_users) ->
|
|
|
|
fun (I) when is_integer(I), I > 0 -> I end;
|
|
|
|
mod_opt_type(max_users_admin_threshold) ->
|
|
|
|
fun (I) when is_integer(I), I > 0 -> I end;
|
|
|
|
mod_opt_type(max_users_presence) ->
|
|
|
|
fun (MUP) when is_integer(MUP) -> MUP end;
|
|
|
|
mod_opt_type(min_message_interval) ->
|
2017-04-30 18:01:47 +02:00
|
|
|
fun (MMI) when is_number(MMI), MMI >= 0 -> MMI end;
|
2015-06-03 14:18:09 +02:00
|
|
|
mod_opt_type(min_presence_interval) ->
|
|
|
|
fun (I) when is_number(I), I >= 0 -> I end;
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(room_shaper) ->
|
|
|
|
fun (A) when is_atom(A) -> A end;
|
2015-06-03 14:18:09 +02:00
|
|
|
mod_opt_type(user_message_shaper) ->
|
|
|
|
fun (A) when is_atom(A) -> A end;
|
|
|
|
mod_opt_type(user_presence_shaper) ->
|
|
|
|
fun (A) when is_atom(A) -> A end;
|
2017-03-10 13:12:43 +01:00
|
|
|
mod_opt_type(queue_type) ->
|
|
|
|
fun(ram) -> ram; (file) -> file end;
|
2017-05-05 10:11:17 +02:00
|
|
|
mod_opt_type({default_room_options, allow_change_subj}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, allow_private_messages}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, allow_query_users}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, allow_user_invites}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, allow_visitor_nickchange}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, allow_visitor_status}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, anonymous}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, captcha_protected}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, logging}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, members_by_default}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, members_only}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, moderated}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, password_protected}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, persistent}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, public}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, public_list}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, mam}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, allow_subscription}) ->
|
|
|
|
fun(B) when is_boolean(B) -> B end;
|
|
|
|
mod_opt_type({default_room_options, password}) ->
|
|
|
|
fun iolist_to_binary/1;
|
|
|
|
mod_opt_type({default_room_options, title}) ->
|
|
|
|
fun iolist_to_binary/1;
|
|
|
|
mod_opt_type({default_room_options, allow_private_messages_from_visitors}) ->
|
|
|
|
fun(anyone) -> anyone;
|
|
|
|
(moderators) -> moderators;
|
|
|
|
(nobody) -> nobody
|
|
|
|
end;
|
|
|
|
mod_opt_type({default_room_options, max_users}) ->
|
|
|
|
fun(I) when is_integer(I), I > 0 -> I end;
|
|
|
|
mod_opt_type({default_room_options, presence_broadcast}) ->
|
|
|
|
fun(L) ->
|
|
|
|
lists:map(
|
|
|
|
fun(moderator) -> moderator;
|
|
|
|
(participant) -> participant;
|
|
|
|
(visitor) -> visitor
|
|
|
|
end, L)
|
2018-05-30 07:11:58 +02:00
|
|
|
end;
|
|
|
|
mod_opt_type({default_room_options, lang}) ->
|
|
|
|
fun iolist_to_binary/1.
|
2018-01-23 08:54:52 +01:00
|
|
|
|
|
|
|
mod_options(Host) ->
|
|
|
|
[{access, all},
|
|
|
|
{access_admin, none},
|
|
|
|
{access_create, all},
|
|
|
|
{access_persistent, all},
|
2018-04-24 11:29:59 +02:00
|
|
|
{access_register, all},
|
2018-01-23 08:54:52 +01:00
|
|
|
{db_type, ejabberd_config:default_db(Host, ?MODULE)},
|
|
|
|
{ram_db_type, ejabberd_config:default_ram_db(Host, ?MODULE)},
|
|
|
|
{history_size, 20},
|
|
|
|
{host, <<"conference.@HOST@">>},
|
|
|
|
{hosts, []},
|
|
|
|
{name, ?T("Chatrooms")},
|
|
|
|
{max_room_desc, infinity},
|
|
|
|
{max_room_id, infinity},
|
|
|
|
{max_room_name, infinity},
|
|
|
|
{max_rooms_discoitems, 100},
|
2018-07-10 01:00:06 +02:00
|
|
|
{max_user_conferences, 100},
|
2018-01-23 08:54:52 +01:00
|
|
|
{max_users, 200},
|
|
|
|
{max_users_admin_threshold, 5},
|
|
|
|
{max_users_presence, 1000},
|
|
|
|
{min_message_interval, 0},
|
|
|
|
{min_presence_interval, 0},
|
|
|
|
{queue_type, ejabberd_config:default_queue_type(Host)},
|
|
|
|
{regexp_room_id, <<"">>},
|
|
|
|
{room_shaper, none},
|
|
|
|
{user_message_shaper, none},
|
|
|
|
{user_presence_shaper, none},
|
|
|
|
{default_room_options,
|
|
|
|
[{allow_change_subj,true},
|
|
|
|
{allow_private_messages,true},
|
|
|
|
{allow_query_users,true},
|
|
|
|
{allow_user_invites,false},
|
|
|
|
{allow_visitor_nickchange,true},
|
|
|
|
{allow_visitor_status,true},
|
|
|
|
{anonymous,true},
|
|
|
|
{captcha_protected,false},
|
2018-07-16 15:15:36 +02:00
|
|
|
{lang,<<>>},
|
2018-01-23 08:54:52 +01:00
|
|
|
{logging,false},
|
|
|
|
{members_by_default,true},
|
|
|
|
{members_only,false},
|
|
|
|
{moderated,true},
|
|
|
|
{password_protected,false},
|
|
|
|
{persistent,false},
|
|
|
|
{public,true},
|
|
|
|
{public_list,true},
|
|
|
|
{mam,false},
|
|
|
|
{allow_subscription,false},
|
|
|
|
{password,<<>>},
|
|
|
|
{title,<<>>},
|
|
|
|
{allow_private_messages_from_visitors,anyone},
|
|
|
|
{max_users,200},
|
|
|
|
{presence_broadcast,[moderator,participant,visitor]}]}].
|