mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Use xmpp:try_subtag/2 wherever possible
This commit is contained in:
parent
ae66c17ec0
commit
bd064fa3fc
@ -61,11 +61,16 @@ mod_opt_type(_) ->
|
|||||||
c2s_state() | {stop, c2s_state()}.
|
c2s_state() | {stop, c2s_state()}.
|
||||||
c2s_unauthenticated_packet(State, #iq{type = T, sub_els = [_]} = IQ)
|
c2s_unauthenticated_packet(State, #iq{type = T, sub_els = [_]} = IQ)
|
||||||
when T == get; T == set ->
|
when T == get; T == set ->
|
||||||
case xmpp:get_subtag(IQ, #legacy_auth{}) of
|
try xmpp:try_subtag(IQ, #legacy_auth{}) of
|
||||||
#legacy_auth{} = Auth ->
|
#legacy_auth{} = Auth ->
|
||||||
{stop, authenticate(State, xmpp:set_els(IQ, [Auth]))};
|
{stop, authenticate(State, xmpp:set_els(IQ, [Auth]))};
|
||||||
false ->
|
false ->
|
||||||
State
|
State
|
||||||
|
catch _:{xmpp_codec, Why} ->
|
||||||
|
Txt = xmpp:io_format_error(Why),
|
||||||
|
Lang = maps:get(lang, State),
|
||||||
|
Err = xmpp:make_error(IQ, xmpp:error_bad_request(Txt, Lang)),
|
||||||
|
{stop, ejabberd_c2s:send(State, Err)}
|
||||||
end;
|
end;
|
||||||
c2s_unauthenticated_packet(State, _) ->
|
c2s_unauthenticated_packet(State, _) ->
|
||||||
State.
|
State.
|
||||||
|
@ -4006,7 +4006,7 @@ route_invitation(From, Invitation, Lang, StateData) ->
|
|||||||
%% Otherwise, an error message is sent to the sender.
|
%% Otherwise, an error message is sent to the sender.
|
||||||
-spec handle_roommessage_from_nonparticipant(message(), state(), jid()) -> ok.
|
-spec handle_roommessage_from_nonparticipant(message(), state(), jid()) -> ok.
|
||||||
handle_roommessage_from_nonparticipant(Packet, StateData, From) ->
|
handle_roommessage_from_nonparticipant(Packet, StateData, From) ->
|
||||||
case xmpp:get_subtag(Packet, #muc_user{}) of
|
try xmpp:try_subtag(Packet, #muc_user{}) of
|
||||||
#muc_user{decline = #muc_decline{to = #jid{} = To} = Decline} = XUser ->
|
#muc_user{decline = #muc_decline{to = #jid{} = To} = Decline} = XUser ->
|
||||||
NewDecline = Decline#muc_decline{to = undefined, from = From},
|
NewDecline = Decline#muc_decline{to = undefined, from = From},
|
||||||
NewXUser = XUser#muc_user{decline = NewDecline},
|
NewXUser = XUser#muc_user{decline = NewDecline},
|
||||||
@ -4018,6 +4018,10 @@ handle_roommessage_from_nonparticipant(Packet, StateData, From) ->
|
|||||||
"to the conference">>,
|
"to the conference">>,
|
||||||
Err = xmpp:err_not_acceptable(ErrText, xmpp:get_lang(Packet)),
|
Err = xmpp:err_not_acceptable(ErrText, xmpp:get_lang(Packet)),
|
||||||
ejabberd_router:route_error(Packet, Err)
|
ejabberd_router:route_error(Packet, Err)
|
||||||
|
catch _:{xmpp_codec, Why} ->
|
||||||
|
Txt = xmpp:io_format_error(Why),
|
||||||
|
Err = xmpp:err_bad_request(Txt, xmpp:get_lang(Packet)),
|
||||||
|
ejabberd_router:route_error(Packet, Err)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
@ -402,7 +402,7 @@ strip_addresses_element(Packet) ->
|
|||||||
#addresses{list = Addrs} ->
|
#addresses{list = Addrs} ->
|
||||||
PacketStripped = xmpp:remove_subtag(Packet, #addresses{}),
|
PacketStripped = xmpp:remove_subtag(Packet, #addresses{}),
|
||||||
{ok, PacketStripped, Addrs};
|
{ok, PacketStripped, Addrs};
|
||||||
undefined ->
|
false ->
|
||||||
throw(eadsele)
|
throw(eadsele)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ get_permissions(ServerHost) ->
|
|||||||
forward_message(#message{to = To} = Msg) ->
|
forward_message(#message{to = To} = Msg) ->
|
||||||
ServerHost = To#jid.lserver,
|
ServerHost = To#jid.lserver,
|
||||||
Lang = xmpp:get_lang(Msg),
|
Lang = xmpp:get_lang(Msg),
|
||||||
case xmpp:get_subtag(Msg, #privilege{}) of
|
try xmpp:try_subtag(Msg, #privilege{}) of
|
||||||
#privilege{forwarded = #forwarded{xml_els = [SubEl]}} ->
|
#privilege{forwarded = #forwarded{xml_els = [SubEl]}} ->
|
||||||
try xmpp:decode(SubEl, ?NS_CLIENT, [ignore_els]) of
|
try xmpp:decode(SubEl, ?NS_CLIENT, [ignore_els]) of
|
||||||
#message{} = NewMsg ->
|
#message{} = NewMsg ->
|
||||||
@ -297,7 +297,11 @@ forward_message(#message{to = To} = Msg) ->
|
|||||||
ejabberd_router:route_error(Msg, Err)
|
ejabberd_router:route_error(Msg, Err)
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
Txt = <<"Invalid <forwarded/> element">>,
|
Txt = <<"No <forwarded/> element found">>,
|
||||||
|
Err = xmpp:err_bad_request(Txt, Lang),
|
||||||
|
ejabberd_router:route_error(Msg, Err)
|
||||||
|
catch _:{xmpp_codec, Why} ->
|
||||||
|
Txt = xmpp:io_format_error(Why),
|
||||||
Err = xmpp:err_bad_request(Txt, Lang),
|
Err = xmpp:err_bad_request(Txt, Lang),
|
||||||
ejabberd_router:route_error(Msg, Err)
|
ejabberd_router:route_error(Msg, Err)
|
||||||
end.
|
end.
|
||||||
|
@ -95,7 +95,7 @@ stream_feature_register(Acc, Host) ->
|
|||||||
c2s_unauthenticated_packet(#{ip := IP, server := Server} = State,
|
c2s_unauthenticated_packet(#{ip := IP, server := Server} = State,
|
||||||
#iq{type = T, sub_els = [_]} = IQ)
|
#iq{type = T, sub_els = [_]} = IQ)
|
||||||
when T == set; T == get ->
|
when T == set; T == get ->
|
||||||
case xmpp:get_subtag(IQ, #register{}) of
|
try xmpp:try_subtag(IQ, #register{}) of
|
||||||
#register{} = Register ->
|
#register{} = Register ->
|
||||||
{Address, _} = IP,
|
{Address, _} = IP,
|
||||||
IQ1 = xmpp:set_els(IQ, [Register]),
|
IQ1 = xmpp:set_els(IQ, [Register]),
|
||||||
@ -105,6 +105,11 @@ c2s_unauthenticated_packet(#{ip := IP, server := Server} = State,
|
|||||||
{stop, ejabberd_c2s:send(State, ResIQ1)};
|
{stop, ejabberd_c2s:send(State, ResIQ1)};
|
||||||
false ->
|
false ->
|
||||||
State
|
State
|
||||||
|
catch _:{xmpp_codec, Why} ->
|
||||||
|
Txt = xmpp:io_format_error(Why),
|
||||||
|
Lang = maps:get(lang, State),
|
||||||
|
Err = xmpp:make_error(IQ, xmpp:error_bad_request(Txt, Lang)),
|
||||||
|
{stop, ejabberd_c2s:send(State, Err)}
|
||||||
end;
|
end;
|
||||||
c2s_unauthenticated_packet(State, _) ->
|
c2s_unauthenticated_packet(State, _) ->
|
||||||
State.
|
State.
|
||||||
|
Loading…
Reference in New Issue
Block a user