25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

mod_blocking: Use #block_item{} record

This commit is contained in:
Holger Weiss 2018-05-02 22:17:32 +02:00
parent 56ee6f0518
commit 638f2d2e67
3 changed files with 25 additions and 17 deletions

View File

@ -25,7 +25,7 @@
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.22"}}}, {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.22"}}},
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.11"}}}, {stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.11"}}},
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.30"}}}, {fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.30"}}},
{xmpp, ".*", {git, "https://github.com/processone/xmpp", {tag, "1.1.21"}}}, {xmpp, ".*", {git, "https://github.com/processone/xmpp", "d958206"}},
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.14"}}}, {fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.14"}}},
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}}, {jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.3"}}}, {p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.3"}}},

View File

@ -92,12 +92,12 @@ process_iq_set(#iq{lang = Lang, sub_els = [SubEl]} = IQ) ->
Txt = <<"No items found in this query">>, Txt = <<"No items found in this query">>,
xmpp:make_error(IQ, xmpp:err_bad_request(Txt, Lang)); xmpp:make_error(IQ, xmpp:err_bad_request(Txt, Lang));
#block{items = Items} -> #block{items = Items} ->
JIDs = [jid:tolower(Item) || Item <- Items], JIDs = [jid:tolower(JID) || #block_item{jid = JID} <- Items],
process_block(IQ, JIDs); process_block(IQ, JIDs);
#unblock{items = []} -> #unblock{items = []} ->
process_unblock_all(IQ); process_unblock_all(IQ);
#unblock{items = Items} -> #unblock{items = Items} ->
JIDs = [jid:tolower(Item) || Item <- Items], JIDs = [jid:tolower(JID) || #block_item{jid = JID} <- Items],
process_unblock(IQ, JIDs); process_unblock(IQ, JIDs);
_ -> _ ->
Txt = <<"No module is handling this query">>, Txt = <<"No module is handling this query">>,
@ -163,7 +163,8 @@ process_block(#iq{from = From} = IQ, LJIDs) ->
end) of end) of
ok -> ok ->
mod_privacy:push_list_update(From, Name), mod_privacy:push_list_update(From, Name),
Items = [jid:make(LJID) || LJID <- LJIDs], Items = [#block_item{jid = jid:make(LJID)}
|| LJID <- LJIDs],
broadcast_event(From, #block{items = Items}), broadcast_event(From, #block{items = Items}),
xmpp:make_iq_result(IQ); xmpp:make_iq_result(IQ);
{error, notfound} -> {error, notfound} ->
@ -218,14 +219,16 @@ process_unblock(#iq{from = From} = IQ, LJIDs) ->
case mod_privacy:set_list(LUser, LServer, Name, NewList) of case mod_privacy:set_list(LUser, LServer, Name, NewList) of
ok -> ok ->
mod_privacy:push_list_update(From, Name), mod_privacy:push_list_update(From, Name),
Items = [jid:make(LJID) || LJID <- LJIDs], Items = [#block_item{jid = jid:make(LJID)}
|| LJID <- LJIDs],
broadcast_event(From, #unblock{items = Items}), broadcast_event(From, #unblock{items = Items}),
xmpp:make_iq_result(IQ); xmpp:make_iq_result(IQ);
{error, _} -> {error, _} ->
err_db_failure(IQ) err_db_failure(IQ)
end; end;
error -> error ->
Items = [jid:make(LJID) || LJID <- LJIDs], Items = [#block_item{jid = jid:make(LJID)}
|| LJID <- LJIDs],
broadcast_event(From, #unblock{items = Items}), broadcast_event(From, #unblock{items = Items}),
xmpp:make_iq_result(IQ); xmpp:make_iq_result(IQ);
{error, _} -> {error, _} ->
@ -249,7 +252,7 @@ process_get(#iq{from = #jid{luser = LUser, lserver = LServer}} = IQ) ->
case mod_privacy:get_user_list(LUser, LServer, default) of case mod_privacy:get_user_list(LUser, LServer, default) of
{ok, {_, List}} -> {ok, {_, List}} ->
LJIDs = listitems_to_jids(List, []), LJIDs = listitems_to_jids(List, []),
Items = [jid:make(J) || J <- LJIDs], Items = [#block_item{jid = jid:make(J)} || J <- LJIDs],
xmpp:make_iq_result(IQ, #block_list{items = Items}); xmpp:make_iq_result(IQ, #block_list{items = Items});
error -> error ->
xmpp:make_iq_result(IQ, #block_list{}); xmpp:make_iq_result(IQ, #block_list{});

View File

@ -203,6 +203,7 @@ malformed_iq_query(Config) ->
malformed_get(Config) -> malformed_get(Config) ->
JID = jid:make(randoms:get_string()), JID = jid:make(randoms:get_string()),
Item = #block_item{jid = JID},
lists:foreach( lists:foreach(
fun(SubEl) -> fun(SubEl) ->
#iq{type = error} = #iq{type = error} =
@ -211,7 +212,7 @@ malformed_get(Config) ->
#privacy_query{default = none}, #privacy_query{default = none},
#privacy_query{lists = [#privacy_list{name = <<"1">>}, #privacy_query{lists = [#privacy_list{name = <<"1">>},
#privacy_list{name = <<"2">>}]}, #privacy_list{name = <<"2">>}]},
#block{items = [JID]}, #unblock{items = [JID]}, #block{items = [Item]}, #unblock{items = [Item]},
#block{}, #unblock{}]), #block{}, #unblock{}]),
disconnect(Config). disconnect(Config).
@ -225,7 +226,9 @@ malformed_set(Config) ->
#privacy_list{name = <<"2">>}]}, #privacy_list{name = <<"2">>}]},
#block{}, #block{},
#block_list{}, #block_list{},
#block_list{items = [jid:make(randoms:get_string())]}]), #block_list{
items = [#block_item{
jid = jid:make(randoms:get_string())}]}]),
disconnect(Config). disconnect(Config).
malformed_type_value(Config) -> malformed_type_value(Config) ->
@ -609,24 +612,25 @@ set_default(Config, Name) ->
get_block(Config) -> get_block(Config) ->
case send_recv(Config, #iq{type = get, sub_els = [#block_list{}]}) of case send_recv(Config, #iq{type = get, sub_els = [#block_list{}]}) of
#iq{type = result, sub_els = [#block_list{items = JIDs}]} -> #iq{type = result, sub_els = [#block_list{items = Items}]} ->
lists:sort(JIDs); lists:sort([JID || #block_item{jid = JID} <- Items]);
#iq{type = error} = Err -> #iq{type = error} = Err ->
xmpp:get_error(Err) xmpp:get_error(Err)
end. end.
set_block(Config, JIDs) -> set_block(Config, JIDs) ->
Items = [#block_item{jid = JID} || JID <- JIDs],
case send_recv(Config, #iq{type = set, case send_recv(Config, #iq{type = set,
sub_els = [#block{items = JIDs}]}) of sub_els = [#block{items = Items}]}) of
#iq{type = result, sub_els = []} -> #iq{type = result, sub_els = []} ->
{#iq{id = I1, sub_els = [#block{items = Items}]}, {#iq{id = I1, sub_els = [#block{items = Items1}]},
#iq{id = I2, sub_els = [#privacy_query{lists = Lists}]}} = #iq{id = I2, sub_els = [#privacy_query{lists = Lists}]}} =
?recv2(#iq{type = set, sub_els = [#block{}]}, ?recv2(#iq{type = set, sub_els = [#block{}]},
#iq{type = set, sub_els = [#privacy_query{}]}), #iq{type = set, sub_els = [#privacy_query{}]}),
send(Config, #iq{type = result, id = I1}), send(Config, #iq{type = result, id = I1}),
send(Config, #iq{type = result, id = I2}), send(Config, #iq{type = result, id = I2}),
ct:comment("Checking if all JIDs present in the push"), ct:comment("Checking if all JIDs present in the push"),
true = lists:sort(JIDs) == lists:sort(Items), true = lists:sort(Items) == lists:sort(Items1),
ct:comment("Getting name of the corresponding privacy list"), ct:comment("Getting name of the corresponding privacy list"),
[#privacy_list{name = Name}] = Lists, [#privacy_list{name = Name}] = Lists,
{ok, Name}; {ok, Name};
@ -636,17 +640,18 @@ set_block(Config, JIDs) ->
set_unblock(Config, JIDs) -> set_unblock(Config, JIDs) ->
ct:comment("Unblocking ~p", [JIDs]), ct:comment("Unblocking ~p", [JIDs]),
Items = [#block_item{jid = JID} || JID <- JIDs],
case send_recv(Config, #iq{type = set, case send_recv(Config, #iq{type = set,
sub_els = [#unblock{items = JIDs}]}) of sub_els = [#unblock{items = Items}]}) of
#iq{type = result, sub_els = []} -> #iq{type = result, sub_els = []} ->
{#iq{id = I1, sub_els = [#unblock{items = Items}]}, {#iq{id = I1, sub_els = [#unblock{items = Items1}]},
#iq{id = I2, sub_els = [#privacy_query{lists = Lists}]}} = #iq{id = I2, sub_els = [#privacy_query{lists = Lists}]}} =
?recv2(#iq{type = set, sub_els = [#unblock{}]}, ?recv2(#iq{type = set, sub_els = [#unblock{}]},
#iq{type = set, sub_els = [#privacy_query{}]}), #iq{type = set, sub_els = [#privacy_query{}]}),
send(Config, #iq{type = result, id = I1}), send(Config, #iq{type = result, id = I1}),
send(Config, #iq{type = result, id = I2}), send(Config, #iq{type = result, id = I2}),
ct:comment("Checking if all JIDs present in the push"), ct:comment("Checking if all JIDs present in the push"),
true = lists:sort(JIDs) == lists:sort(Items), true = lists:sort(Items) == lists:sort(Items1),
ct:comment("Getting name of the corresponding privacy list"), ct:comment("Getting name of the corresponding privacy list"),
[#privacy_list{name = Name}] = Lists, [#privacy_list{name = Name}] = Lists,
{ok, Name}; {ok, Name};