Don't attempt to query 'undefined' active list

Also code formatting was improved
This commit is contained in:
Evgeny Khramtsov 2019-06-21 19:37:47 +03:00
parent 72572d990a
commit a0d3fb3b23
1 changed files with 35 additions and 30 deletions

View File

@ -403,34 +403,41 @@ c2s_copy_session(State, #{privacy_active_list := List}) ->
c2s_copy_session(State, _) -> c2s_copy_session(State, _) ->
State. State.
% Adjust the client's state, so next packets (which can be already queued) %% Adjust the client's state, so next packets (which can be already queued)
% will take the active list into account. %% will take the active list into account.
-spec update_c2s_state_with_privacy_list(stanza(), c2s_state()) -> c2s_state(). -spec update_c2s_state_with_privacy_list(stanza(), c2s_state()) -> c2s_state().
update_c2s_state_with_privacy_list(#iq{ update_c2s_state_with_privacy_list(#iq{type = set,
type = set, to = #jid{luser = U, lserver = S,
to = #jid{luser = U, lserver = S, lresource = <<"">>} = To} = IQ, lresource = <<"">>} = To} = IQ,
State) -> State) ->
% match a IQ set containing a new active privacy list %% Match a IQ set containing a new active privacy list
case xmpp:get_subtag(IQ, #privacy_query{}) of case xmpp:get_subtag(IQ, #privacy_query{}) of
#privacy_query{default = undefined, active = Active} -> #privacy_query{default = undefined, active = Active} ->
case Active of case Active of
none -> none ->
?DEBUG("Removing active privacy list for user ~p", [jid:encode(To)]), ?DEBUG("Removing active privacy list for user: ~s",
State#{privacy_active_list => none}; [jid:encode(To)]),
_ -> State#{privacy_active_list => none};
case get_user_list(U, S, Active) of undefined ->
{ok, _} -> State;
?DEBUG("Setting active privacy list ~p for user ~p", [Active, jid:encode(To)]), _ ->
State#{privacy_active_list => Active}; case get_user_list(U, S, Active) of
_ -> State % unknown privacy list name {ok, _} ->
end ?DEBUG("Setting active privacy list '~s' for user: ~s",
end; [Active, jid:encode(To)]),
_ -> State State#{privacy_active_list => Active};
_ ->
%% unknown privacy list name
State
end
end;
_ ->
State
end; end;
update_c2s_state_with_privacy_list(_Packet, State) ->
State.
update_c2s_state_with_privacy_list(_Packet, State) -> State. %% Add the active privacy list to packet metadata
% add the active privacy list to packet metadata
-spec user_send_packet({stanza(), c2s_state()}) -> {stanza(), c2s_state()}. -spec user_send_packet({stanza(), c2s_state()}) -> {stanza(), c2s_state()}.
user_send_packet({#iq{type = Type, user_send_packet({#iq{type = Type,
to = #jid{luser = U, lserver = S, lresource = <<"">>}, to = #jid{luser = U, lserver = S, lresource = <<"">>},
@ -443,12 +450,10 @@ user_send_packet({#iq{type = Type,
false -> IQ false -> IQ
end, end,
{NewIQ, update_c2s_state_with_privacy_list(IQ, State)}; {NewIQ, update_c2s_state_with_privacy_list(IQ, State)};
%% For client with no active privacy list, see if there is
% for client with no active privacy list, see if there is %% one about to be activated in this packet and update client state
% one about to be activated in this packet and update client state
user_send_packet({Packet, State}) -> user_send_packet({Packet, State}) ->
{Packet, update_c2s_state_with_privacy_list(Packet, State)}. {Packet, update_c2s_state_with_privacy_list(Packet, State)}.
-spec set_list(binary(), binary(), binary(), [listitem()]) -> ok | {error, any()}. -spec set_list(binary(), binary(), binary(), [listitem()]) -> ok | {error, any()}.
set_list(LUser, LServer, Name, List) -> set_list(LUser, LServer, Name, List) ->