From a915fd161e0121ce4338a62d3cda7736f7e20dd9 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Wed, 7 Sep 2016 11:15:19 +0300 Subject: [PATCH] Create room on configuration request as per XEP-0045, 10.1.3 --- src/mod_muc.erl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/mod_muc.erl b/src/mod_muc.erl index b189508a8..6b71d1e1d 100644 --- a/src/mod_muc.erl +++ b/src/mod_muc.erl @@ -385,8 +385,8 @@ do_route1(Host, ServerHost, Access, HistorySize, RoomShaper, {Room, _, Nick} = jid:tolower(To), case mnesia:dirty_read(muc_online_room, {Room, Host}) of [] -> - case Packet of - #presence{type = available, lang = Lang} -> + case is_create_request(Packet) of + true -> case check_user_can_create_room( ServerHost, AccessCreate, From, Room) and check_create_roomid(ServerHost, Room) of @@ -399,12 +399,13 @@ do_route1(Host, ServerHost, Access, HistorySize, RoomShaper, mod_muc_room:route(Pid, From, Nick, Packet), ok; false -> + Lang = xmpp:get_lang(Packet), ErrText = <<"Room creation is denied by service policy">>, Err = xmpp:make_error( Packet, xmpp:err_forbidden(ErrText, Lang)), ejabberd_router:route(To, From, Err) end; - _ -> + false -> Lang = xmpp:get_lang(Packet), ErrText = <<"Conference room does not exist">>, Err = xmpp:err_item_not_found(ErrText, Lang), @@ -501,6 +502,16 @@ process_mucsub(#iq{type = get, from = From, to = To} = IQ) -> RoomJIDs = get_subscribed_rooms(ServerHost, Host, From), xmpp:make_iq_result(IQ, #muc_subscriptions{list = RoomJIDs}). +-spec is_create_request(stanza()) -> boolean(). +is_create_request(#presence{type = available}) -> + true; +is_create_request(#iq{type = set} = IQ) -> + xmpp:has_subtag(IQ, #muc_subscribe{}); +is_create_request(#iq{type = get} = IQ) -> + #muc_owner{} == xmpp:get_subtag(IQ, #muc_owner{}); +is_create_request(_) -> + false. + check_user_can_create_room(ServerHost, AccessCreate, From, _RoomID) -> case acl:match_rule(ServerHost, AccessCreate, From) of