mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
parent
3f901b3793
commit
624485fe26
@ -51,9 +51,8 @@
|
|||||||
code_change/4]).
|
code_change/4]).
|
||||||
|
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
|
||||||
-include("xmpp.hrl").
|
-include("xmpp.hrl").
|
||||||
|
-include("translate.hrl").
|
||||||
-include("mod_muc_room.hrl").
|
-include("mod_muc_room.hrl").
|
||||||
|
|
||||||
-define(MAX_USERS_DEFAULT_LIST,
|
-define(MAX_USERS_DEFAULT_LIST,
|
||||||
@ -435,11 +434,10 @@ normal_state({route, ToNick,
|
|||||||
{next_state, normal_state, StateData}
|
{next_state, normal_state, StateData}
|
||||||
end;
|
end;
|
||||||
normal_state({route, ToNick,
|
normal_state({route, ToNick,
|
||||||
#iq{from = From, type = Type, lang = Lang} = Packet},
|
#iq{from = From, lang = Lang} = Packet},
|
||||||
StateData) ->
|
#state{config = #config{allow_query_users = AllowQuery}} = StateData) ->
|
||||||
case {(StateData#state.config)#config.allow_query_users,
|
try maps:get(jid:tolower(From), StateData#state.users) of
|
||||||
maps:get(jid:tolower(From), StateData#state.users, error)} of
|
#user{nick = FromNick} when AllowQuery orelse ToNick == FromNick ->
|
||||||
{true, #user{nick = FromNick}} ->
|
|
||||||
case find_jid_by_nick(ToNick, StateData) of
|
case find_jid_by_nick(ToNick, StateData) of
|
||||||
false ->
|
false ->
|
||||||
ErrText = <<"Recipient is not in the conference room">>,
|
ErrText = <<"Recipient is not in the conference room">>,
|
||||||
@ -447,28 +445,33 @@ normal_state({route, ToNick,
|
|||||||
ejabberd_router:route_error(Packet, Err);
|
ejabberd_router:route_error(Packet, Err);
|
||||||
To ->
|
To ->
|
||||||
FromJID = jid:replace_resource(StateData#state.jid, FromNick),
|
FromJID = jid:replace_resource(StateData#state.jid, FromNick),
|
||||||
if Type == get; Type == set ->
|
case direct_iq_type(Packet) of
|
||||||
ToJID = case is_vcard_request(Packet) of
|
vcard ->
|
||||||
true -> jid:remove_resource(To);
|
|
||||||
false -> To
|
|
||||||
end,
|
|
||||||
ejabberd_router:route_iq(
|
ejabberd_router:route_iq(
|
||||||
xmpp:set_from_to(Packet, FromJID, ToJID), Packet, self());
|
xmpp:set_from_to(Packet, FromJID, jid:remove_resource(To)),
|
||||||
true ->
|
Packet, self());
|
||||||
ejabberd_router:route(
|
ping when ToNick == FromNick ->
|
||||||
xmpp:set_from_to(Packet, FromJID, To))
|
%% Self-ping optimization from XEP-0410
|
||||||
|
ejabberd_router:route(xmpp:make_iq_result(Packet));
|
||||||
|
response ->
|
||||||
|
ejabberd_router:route(xmpp:set_from_to(Packet, FromJID, To));
|
||||||
|
#stanza_error{} = Err ->
|
||||||
|
ejabberd_router:route_error(Packet, Err);
|
||||||
|
_OtherRequest ->
|
||||||
|
ejabberd_router:route_iq(
|
||||||
|
xmpp:set_from_to(Packet, FromJID, To), Packet, self())
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
{true, error} ->
|
|
||||||
ErrText = <<"Only occupants are allowed to send queries "
|
|
||||||
"to the conference">>,
|
|
||||||
Err = xmpp:err_not_acceptable(ErrText, Lang),
|
|
||||||
ejabberd_router:route_error(Packet, Err);
|
|
||||||
_ ->
|
_ ->
|
||||||
ErrText = <<"Queries to the conference members are "
|
ErrText = <<"Queries to the conference members are "
|
||||||
"not allowed in this room">>,
|
"not allowed in this room">>,
|
||||||
Err = xmpp:err_not_allowed(ErrText, Lang),
|
Err = xmpp:err_not_allowed(ErrText, Lang),
|
||||||
ejabberd_router:route_error(Packet, Err)
|
ejabberd_router:route_error(Packet, Err)
|
||||||
|
catch _:{badkey, _} ->
|
||||||
|
ErrText = <<"Only occupants are allowed to send queries "
|
||||||
|
"to the conference">>,
|
||||||
|
Err = xmpp:err_not_acceptable(ErrText, Lang),
|
||||||
|
ejabberd_router:route_error(Packet, Err)
|
||||||
end,
|
end,
|
||||||
{next_state, normal_state, StateData};
|
{next_state, normal_state, StateData};
|
||||||
normal_state(_Event, StateData) ->
|
normal_state(_Event, StateData) ->
|
||||||
@ -951,11 +954,22 @@ process_voice_approval(From, Pkt, VoiceApproval, StateData) ->
|
|||||||
StateData
|
StateData
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec is_vcard_request(iq()) -> boolean().
|
-spec direct_iq_type(iq()) -> vcard | ping | request | response | stanza_error().
|
||||||
is_vcard_request(#iq{type = T, sub_els = [El]}) ->
|
direct_iq_type(#iq{type = T, sub_els = SubEls, lang = Lang}) when T == get; T == set ->
|
||||||
(T == get orelse T == set) andalso xmpp:get_ns(El) == ?NS_VCARD;
|
case SubEls of
|
||||||
is_vcard_request(_) ->
|
[El] ->
|
||||||
false.
|
case xmpp:get_ns(El) of
|
||||||
|
?NS_VCARD when T == get -> vcard;
|
||||||
|
?NS_PING when T == get -> ping;
|
||||||
|
_ -> request
|
||||||
|
end;
|
||||||
|
[] ->
|
||||||
|
xmpp:err_bad_request(?T("No child elements found"), Lang);
|
||||||
|
[_|_] ->
|
||||||
|
xmpp:err_bad_request(?T("Too many child elements"), Lang)
|
||||||
|
end;
|
||||||
|
direct_iq_type(#iq{}) ->
|
||||||
|
response.
|
||||||
|
|
||||||
%% @doc Check if this non participant can send message to room.
|
%% @doc Check if this non participant can send message to room.
|
||||||
%%
|
%%
|
||||||
|
Loading…
Reference in New Issue
Block a user