25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-26 17:38:45 +01:00

Restore room when receiving message or generic iq for not started room

This commit is contained in:
Paweł Chmielowski 2019-07-05 13:46:48 +02:00
parent d7e86d1d32
commit 756adaba55

View File

@ -507,28 +507,39 @@ route_to_room(Packet, ServerHost) ->
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE), RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
case RMod:find_online_room(ServerHost, Room, Host) of case RMod:find_online_room(ServerHost, Room, Host) of
error -> error ->
case is_create_request(Packet) of case should_start_room(Packet) of
true ->
case check_create_room(ServerHost, Host, Room, From) of
true ->
case start_new_room(Host, ServerHost, Room, From, Nick) of
{ok, Pid} ->
mod_muc_room:route(Pid, Packet);
_Err ->
Err = xmpp:err_internal_server_error(),
ejabberd_router:route_error(Packet, Err)
end;
false ->
Lang = xmpp:get_lang(Packet),
ErrText = ?T("Room creation is denied by service policy"),
Err = xmpp:err_forbidden(ErrText, Lang),
ejabberd_router:route_error(Packet, Err)
end;
false -> false ->
Lang = xmpp:get_lang(Packet), Lang = xmpp:get_lang(Packet),
ErrText = ?T("Conference room does not exist"), ErrText = ?T("Conference room does not exist"),
Err = xmpp:err_item_not_found(ErrText, Lang), Err = xmpp:err_item_not_found(ErrText, Lang),
ejabberd_router:route_error(Packet, Err) ejabberd_router:route_error(Packet, Err);
StartType ->
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
case load_room(RMod, Host, ServerHost, Room) of
error when StartType == start ->
case check_create_room(ServerHost, Host, Room, From) of
true ->
case start_new_room(RMod, Host, ServerHost, Room, From, Nick) of
{ok, Pid} ->
mod_muc_room:route(Pid, Packet);
_Err ->
Err = xmpp:err_internal_server_error(),
ejabberd_router:route_error(Packet, Err)
end;
false ->
Lang = xmpp:get_lang(Packet),
ErrText = ?T("Room creation is denied by service policy"),
Err = xmpp:err_forbidden(ErrText, Lang),
ejabberd_router:route_error(Packet, Err)
end;
error ->
Lang = xmpp:get_lang(Packet),
ErrText = ?T("Conference room does not exist"),
Err = xmpp:err_item_not_found(ErrText, Lang),
ejabberd_router:route_error(Packet, Err);
{ok, Pid2} ->
mod_muc_room:route(Pid2, Packet)
end
end; end;
{ok, Pid} -> {ok, Pid} ->
mod_muc_room:route(Pid, Packet) mod_muc_room:route(Pid, Packet)
@ -665,13 +676,24 @@ process_mucsub(#iq{lang = Lang} = IQ) ->
Txt = ?T("No module is handling this query"), Txt = ?T("No module is handling this query"),
xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)). xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
-spec is_create_request(stanza()) -> boolean(). -spec should_start_room(stanza()) -> start | load | false.
is_create_request(#presence{type = available}) -> should_start_room(#presence{type = available}) ->
true; start;
is_create_request(#iq{type = T} = IQ) when T == get; T == set -> should_start_room(#iq{type = T} = IQ) when T == get; T == set ->
xmpp:has_subtag(IQ, #muc_subscribe{}) orelse case xmpp:has_subtag(IQ, #muc_subscribe{}) orelse
xmpp:has_subtag(IQ, #muc_owner{}); xmpp:has_subtag(IQ, #muc_owner{}) of
is_create_request(_) -> true ->
start;
_ ->
load
end;
should_start_room(#message{type = T, to = #jid{lresource = <<>>}})
when T == groupchat; T == normal->
load;
should_start_room(#message{type = T, to = #jid{lresource = Res}})
when Res /= <<>> andalso T /= groupchat andalso T /= error ->
load;
should_start_room(_) ->
false. false.
-spec check_create_room(binary(), binary(), binary(), jid()) -> boolean(). -spec check_create_room(binary(), binary(), binary(), jid()) -> boolean().
@ -751,29 +773,25 @@ load_permanent_rooms(Hosts, ServerHost, Opts) ->
ok ok
end. end.
start_new_room(Host, ServerHost, Room, From, Nick) -> load_room(RMod, Host, ServerHost, Room) ->
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE), case restore_room(ServerHost, Host, Room) of
Opts = case restore_room(ServerHost, Host, Room) of
error ->
error;
Opts0 ->
case proplists:get_bool(persistent, Opts0) of
true ->
Opts0;
_ ->
error
end
end,
case Opts of
error -> error ->
?DEBUG("Open new room: ~s", [Room]), error;
DefRoomOpts = mod_muc_opt:default_room_options(ServerHost), Opts0 ->
start_room(RMod, Host, ServerHost, Room, DefRoomOpts, From, Nick); case proplists:get_bool(persistent, Opts0) of
_ -> true ->
?DEBUG("Restore room: ~s", [Room]), ?DEBUG("Restore room: ~s", [Room]),
start_room(RMod, Host, ServerHost, Room, Opts) start_room(RMod, Host, ServerHost, Room, Opts0);
_ ->
error
end
end. end.
start_new_room(RMod, Host, ServerHost, Room, From, Nick) ->
?DEBUG("Open new room: ~s", [Room]),
DefRoomOpts = mod_muc_opt:default_room_options(ServerHost),
start_room(RMod, Host, ServerHost, Room, DefRoomOpts, From, Nick).
start_room(Mod, Host, ServerHost, Room, DefOpts) -> start_room(Mod, Host, ServerHost, Room, DefOpts) ->
Access = get_access(ServerHost), Access = get_access(ServerHost),
HistorySize = mod_muc_opt:history_size(ServerHost), HistorySize = mod_muc_opt:history_size(ServerHost),