@@ -41,7 +41,6 @@ allowed_methods(Req, State) ->
41
41
42
42
resource_exists (Req , #{jid := # jid {lserver = Server }} = State ) ->
43
43
{RoomIDOrJID , Req2 } = cowboy_req :binding (id , Req ),
44
- MUCLightDomain = muc_light_domain (Server ),
45
44
case RoomIDOrJID of
46
45
undefined ->
47
46
{Method , Req3 } = cowboy_req :method (Req2 ),
@@ -53,8 +52,8 @@ resource_exists(Req, #{jid := #jid{lserver = Server}} = State) ->
53
52
end ;
54
53
_ ->
55
54
case validate_room_id (RoomIDOrJID , Server ) of
56
- {ok , RoomID } ->
57
- does_room_exist (RoomID , MUCLightDomain , Req2 , State );
55
+ {ok , RoomID , RoomHost } ->
56
+ does_room_exist (RoomID , RoomHost , Req2 , State );
58
57
_ ->
59
58
bad_request (Req2 , State )
60
59
end
@@ -150,15 +149,30 @@ determine_role(US, Users) ->
150
149
Role
151
150
end .
152
151
153
- -spec validate_room_id (RoomIDOrJID :: binary (), Server :: binary ()) ->
154
- {ok , RoomID :: binary ()} | error .
155
- validate_room_id (RoomIDOrJID , Server ) ->
156
- MUCLightDomain = muc_light_domain (Server ),
152
+ -spec validate_room_id (RoomIDOrJID :: binary () | term (), Server :: binary ()) ->
153
+ {ok , RoomID :: binary (), RoomHost :: binary ()} | error .
154
+ validate_room_id (RoomIDOrJID , Server ) when is_binary (RoomIDOrJID ) ->
157
155
case jid :from_binary (RoomIDOrJID ) of
158
156
# jid {luser = <<>>, lserver = RoomID , lresource = <<>>} ->
159
- {ok , RoomID };
160
- # jid {luser = RoomID , lserver = MUCLightDomain , lresource = <<>>} ->
161
- {ok , RoomID };
157
+ DefaultMucLightDomain = muc_light_domain (Server ),
158
+ {ok , RoomID , DefaultMucLightDomain };
159
+ # jid {luser = RoomID , lserver = RoomHost , lresource = <<>>} ->
160
+ case validate_room_host (RoomHost ) of
161
+ ok ->
162
+ {ok , RoomID , RoomHost };
163
+ error ->
164
+ error
165
+ end ;
162
166
_ ->
163
167
error
164
168
end .
169
+
170
+ -spec validate_room_host (binary ()) -> ok | error .
171
+ validate_room_host (RoomHost ) ->
172
+ MucLightDomains = ejabberd_router :dirty_get_routes_to_module (mod_muc_light ),
173
+ case lists :member (RoomHost , MucLightDomains ) of
174
+ true ->
175
+ ok ;
176
+ false ->
177
+ error
178
+ end .
0 commit comments