]> granicus.if.org Git - ejabberd/commitdiff
add room_id_regexp option
authorHAMANO Tsukasa <hamano@cuspy.org>
Thu, 14 Jan 2016 14:08:31 +0000 (23:08 +0900)
committerBadlop <badlop@process-one.net>
Fri, 5 Feb 2016 11:09:18 +0000 (12:09 +0100)
src/mod_muc.erl

index f7c6d26de360a1f2e84838aadf362bf652593d24..c887b964d6b63592a6803559edb52f27cb89379f 100644 (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,