add room_id_regexp option

This commit is contained in:
HAMANO Tsukasa 2016-01-14 23:08:31 +09:00 committed by Badlop
parent 942072cf9d
commit 268f0b30ec
1 changed files with 17 additions and 9 deletions

View File

@ -597,7 +597,8 @@ do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
case {Name, Type} of
{<<"presence">>, <<"">>} ->
case check_user_can_create_room(ServerHost,
AccessCreate, From, Room) of
AccessCreate, From, Room) and
check_create_roomid(ServerHost, Room) of
true ->
{ok, Pid} = start_new_room(Host, ServerHost, Access,
Room, HistorySize,
@ -628,17 +629,22 @@ do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
end.
check_user_can_create_room(ServerHost, AccessCreate,
From, RoomID) ->
From, _RoomID) ->
case acl:match_rule(ServerHost, AccessCreate, From) of
allow ->
byte_size(RoomID) =<
gen_mod:get_module_opt(ServerHost, ?MODULE, max_room_id,
fun(infinity) -> infinity;
(I) when is_integer(I), I>0 -> I
end, infinity);
allow -> true;
_ -> false
end.
check_create_roomid(ServerHost, RoomID) ->
Max = gen_mod:get_module_opt(ServerHost, ?MODULE, max_room_id,
fun(infinity) -> infinity;
(I) when is_integer(I), I>0 -> I
end, infinity),
Regexp = gen_mod:get_module_opt(ServerHost, ?MODULE, room_id_regexp,
fun iolist_to_binary/1, ""),
(byte_size(RoomID) =< Max) and
(re:run(RoomID, Regexp, [unicode, {capture, none}]) == match).
get_rooms(ServerHost, Host) ->
LServer = jid:nameprep(ServerHost),
get_rooms(LServer, Host,
@ -1317,6 +1323,8 @@ mod_opt_type(max_room_id) ->
fun (infinity) -> infinity;
(I) when is_integer(I), I > 0 -> I
end;
mod_opt_type(room_id_regexp) ->
fun iolist_to_binary/1;
mod_opt_type(max_room_name) ->
fun (infinity) -> infinity;
(I) when is_integer(I), I > 0 -> I
@ -1342,7 +1350,7 @@ mod_opt_type(user_presence_shaper) ->
mod_opt_type(_) ->
[access, access_admin, access_create, access_persistent,
db_type, default_room_options, history_size, host,
max_room_desc, max_room_id, max_room_name,
max_room_desc, max_room_id, max_room_name, room_id_regexp,
max_user_conferences, max_users,
max_users_admin_threshold, max_users_presence,
min_message_interval, min_presence_interval,