From 34d93528ae288e17dcf10986e924d7b18bd4a2dc Mon Sep 17 00:00:00 2001 From: Badlop Date: Wed, 26 Nov 2008 15:10:38 +0000 Subject: [PATCH] * src/gen_mod.erl: First store module options in ETS and Mnesia, then start the module. In case of failure, remove options from ETS. Until now the module was started before the options were stored in database, and some modules started incorrectly because they couldn't access the options from database; for instance mod_muc_room required this for reading max_users option. * src/mod_muc/mod_muc_room.erl: Include the value of max_users service option and the current max_users room option in the list of allowed room limit values. SVN Revision: 1685 --- ChangeLog | 13 +++++++++++++ src/gen_mod.erl | 10 ++++++---- src/mod_muc/mod_muc_room.erl | 25 +++++++++++++++++-------- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 63859f40a..002fe4014 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-11-26 Badlop + + * src/gen_mod.erl: First store module options in ETS and Mnesia, + then start the module. In case of failure, remove options from + ETS. Until now the module was started before the options were + stored in database, and some modules started incorrectly because + they couldn't access the options from database; for instance + mod_muc_room required this for reading max_users option. + + * src/mod_muc/mod_muc_room.erl: Include the value of max_users + service option and the current max_users room option in the list + of allowed room limit values. + 2008-10-17 Christophe Romain * src/mod_pubsub/node_pep.erl: Fix get_node_affiliations resultset to diff --git a/src/gen_mod.erl b/src/gen_mod.erl index bbc4e860d..03ebc1635 100644 --- a/src/gen_mod.erl +++ b/src/gen_mod.erl @@ -62,14 +62,16 @@ start() -> start_module(Host, Module, Opts) -> + set_module_opts_mnesia(Host, Module, Opts), + ets:insert(ejabberd_modules, + #ejabberd_module{module_host = {Module, Host}, + opts = Opts}), case catch Module:start(Host, Opts) of {'EXIT', Reason} -> + del_module_mnesia(Host, Module), + ets:delete(ejabberd_modules, {Module, Host}), ?ERROR_MSG("~p", [Reason]); _ -> - set_module_opts_mnesia(Host, Module, Opts), - ets:insert(ejabberd_modules, - #ejabberd_module{module_host = {Module, Host}, - opts = Opts}), ok end. diff --git a/src/mod_muc/mod_muc_room.erl b/src/mod_muc/mod_muc_room.erl index e8b314c53..6c6579ffe 100644 --- a/src/mod_muc/mod_muc_room.erl +++ b/src/mod_muc/mod_muc_room.erl @@ -2626,11 +2626,25 @@ check_allowed_persistent_change(XEl, StateData, From) -> -define(PRIVATEXFIELD(Label, Var, Val), ?XFIELD("text-private", Label, Var, Val)). +get_default_room_maxusers(RoomState) -> + DefRoomOpts = gen_mod:get_module_opt(RoomState#state.server_host, mod_muc, default_room_options, ?MAX_USERS_DEFAULT), + RoomState2 = set_opts(DefRoomOpts, RoomState), + (RoomState2#state.config)#config.max_users. get_config(Lang, StateData, From) -> {_AccessRoute, _AccessCreate, _AccessAdmin, AccessPersistent} = StateData#state.access, ServiceMaxUsers = get_service_max_users(StateData), + + DefaultRoomMaxUsers = get_default_room_maxusers(StateData), %+++ + ?INFO_MSG("DefaultMaxUsers: ~p", [DefaultRoomMaxUsers]), + Config = StateData#state.config, + {MaxUsersRoomInteger, MaxUsersRoomString} = + case get_max_users(StateData) of + N when is_integer(N) -> + {N, erlang:integer_to_list(N)}; + _ -> {0, "none"} + end, Res = [{xmlelement, "title", [], [{xmlcdata, translate:translate(Lang, "Configuration for ") ++ @@ -2670,13 +2684,7 @@ get_config(Lang, StateData, From) -> [{"type", "list-single"}, {"label", translate:translate(Lang, "Maximum Number of Occupants")}, {"var", "muc#roomconfig_maxusers"}], - [{xmlelement, "value", [], [{xmlcdata, - case get_max_users(StateData) of - N when is_integer(N) -> - erlang:integer_to_list(N); - _ -> "none" - end - }]}] ++ + [{xmlelement, "value", [], [{xmlcdata, MaxUsersRoomString}]}] ++ if is_integer(ServiceMaxUsers) -> []; true -> @@ -2687,7 +2695,8 @@ get_config(Lang, StateData, From) -> [{xmlelement, "option", [{"label", erlang:integer_to_list(N)}], [{xmlelement, "value", [], [{xmlcdata, erlang:integer_to_list(N)}]}]} || - N <- ?MAX_USERS_DEFAULT_LIST, N =< ServiceMaxUsers] + N <- lists:usort([ServiceMaxUsers, DefaultRoomMaxUsers, MaxUsersRoomInteger | + ?MAX_USERS_DEFAULT_LIST]), N =< ServiceMaxUsers] }, {xmlelement, "field", [{"type", "list-single"},