[ejabberd] Setting to limit total number of MUC rooms per host?

Badlop badlop at gmail.com
Mon Feb 28 22:35:24 MSK 2011


2011/2/24 Armando Di Cianno <armando.dicianno at gmail.com>:
> I posted this question in the ejabberd forums, but they seem to have
> very low traffic/visibility.

Please add a comment in your forum thread linking to this thread,
so other forum users know there is some discussion here.


> I may not have googled hard enough, but I'm not sure I can find a way
> to configure a maximum number of MUC rooms per host (doesn't seem to
> be one globally-per-server either).
>
> Is this possible with a configuration setting, or is this going to
> involve deeper hacking into ejabberd mod_muc*?


I wrote a quick and dirty patch:
-----------------------------------
diff --git a/src/mod_muc/mod_muc.erl b/src/mod_muc/mod_muc.erl
index e1b473a..d7c4b4f 100644
--- a/src/mod_muc/mod_muc.erl
+++ b/src/mod_muc/mod_muc.erl
@@ -478,7 +478,8 @@ do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
                        {"presence", ""} ->
                            case check_user_can_create_room(ServerHost,
                                                            AccessCreate, From,
-                                                           Room) of
+                                                           Room)
+                               andalso
check_room_number_available(Host, ServerHost) of
                                true ->
                                    {ok, Pid} = start_new_room(
                                                  Host, ServerHost, Access,
@@ -519,6 +520,19 @@ check_user_can_create_room(ServerHost,
AccessCreate, From, RoomID) ->
            false
     end.

+check_room_number_available(MUCHost, ServerHost) ->
+    Rooms = ets:tab2list(muc_online_room),
+    RoomNumber = lists:foldl(
+      fun({_, {_Roomname, Host}, _}, Result) ->
+              case MUCHost of
+                  global -> Result+1;
+                  Host -> Result+1;
+                  _ -> Result
+              end
+      end,
+      0,
+      Rooms),
+    RoomNumber < gen_mod:get_module_opt(ServerHost, mod_muc,
max_rooms_number, infinite).

 load_permanent_rooms(Host, ServerHost, Access, HistorySize, RoomShaper) ->
     case catch mnesia:dirty_select(
-----------------------------------

Configure with:
  {mod_muc,      [
                  {max_rooms_number, 3},
  ]},


When a user tries to join a new room and the MUC service already hosts
the maximum allowed, he receives a Forbidden error.



---
Badlop
ProcessOne


More information about the ejabberd mailing list