Skip to content

Commit

Permalink
Merge c476848 into d5c1586
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides authored Jan 7, 2021
2 parents d5c1586 + c476848 commit fe00bff
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 196 deletions.
2 changes: 1 addition & 1 deletion big_tests/tests/muc_light_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ rooms_in_rosters(Config) ->
distributed_helper:mim(),
mod_roster,
get_user_rosters_length,
[AliceU, AliceS])
[jid:make(AliceU, AliceS, <<>>)])
end, 1, #{time_left => timer:seconds(10)}),
RosterResult = escalus:wait_for_stanza(Alice),
escalus_assert:is_roster_result(RosterResult),
Expand Down
8 changes: 4 additions & 4 deletions src/admin_extra/service_admin_extra_roster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ unsubscribe(LocalJID, RemoteJID) ->
[jids_nick_subs_ask_grp()].
get_roster(User, Server) ->
UserJID = jid:make(User, Server, <<>>),
Acc = mongoose_acc:new(#{ location => ?LOCATION,
lserver => UserJID#jid.lserver,
element => undefined }),
Acc2 = mongoose_hooks:roster_get(Server, Acc, UserJID#jid.luser, Server),
Acc = mongoose_acc:new(#{location => ?LOCATION,
lserver => UserJID#jid.lserver,
element => undefined}),
Acc2 = mongoose_hooks:roster_get(Server, Acc, UserJID),
Items = mongoose_acc:get(roster, items, [], Acc2),
make_roster(Items).

Expand Down
12 changes: 5 additions & 7 deletions src/ejabberd_c2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,9 @@ do_open_session(Acc, JID, StateData) ->
end
end.

do_open_session_common(Acc, JID, #state{user = U, server = S} = NewStateData0) ->
do_open_session_common(Acc, JID, #state{jid = JID, user = U, server = S} = NewStateData0) ->
change_shaper(NewStateData0, JID),
Acc1 = mongoose_hooks:roster_get_subscription_lists(S, Acc, U),
Acc1 = mongoose_hooks:roster_get_subscription_lists(S, Acc, JID),
{Fs, Ts, Pending} = mongoose_acc:get(roster, subscription_lists, {[], [], []}, Acc1),
LJID = jid:to_lower(jid:to_bare(JID)),
Fs1 = [LJID | Fs],
Expand Down Expand Up @@ -1978,7 +1978,7 @@ presence_update_to_available(true, Acc, _, NewPriority, From, Packet, StateData)
Acc3 = mongoose_hooks:roster_get_subscription_lists(
StateData#state.server,
Acc2,
StateData#state.user),
StateData#state.jid),
{_, _, Pending} = mongoose_acc:get(roster, subscription_lists,
{[], [], []}, Acc3),
Acc4 = resend_offline_messages(Acc3, StateData),
Expand Down Expand Up @@ -2054,12 +2054,10 @@ presence_track(Acc, StateData) ->
StateData :: state()) -> mongoose_acc:t().
process_presence_subscription_and_route(Acc, Type, StateData) ->
From = mongoose_acc:from_jid(Acc),
User = StateData#state.user,
Server = StateData#state.server,
To = mongoose_acc:to_jid(Acc),
Acc1 = mongoose_hooks:roster_out_subscription(Server,
Acc,
User, To, Type),
Acc1 = mongoose_hooks:roster_out_subscription(
Server, Acc, From, To, Type),
check_privacy_and_route(Acc1, jid:to_bare(From), StateData).

-spec check_privacy_and_route(Acc :: mongoose_acc:t(),
Expand Down
17 changes: 7 additions & 10 deletions src/ejabberd_sm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
store_info/2,
get_info/2,
remove_info/2,
check_in_subscription/6,
check_in_subscription/5,
bounce_offline_message/4,
disconnect_removed_user/3,
get_user_resources/1,
Expand Down Expand Up @@ -315,16 +315,14 @@ remove_info(JID, Key) ->
end
end.

-spec check_in_subscription(Acc, User, Server, JID, Type, Reason) -> any() | {stop, false} when
-spec check_in_subscription(Acc, ToJID, FromJID, Type, Reason) -> any() | {stop, false} when
Acc :: any(),
User :: jid:user(),
Server :: jid:server(),
JID :: jid:jid(),
ToJID :: jid:jid(),
FromJID :: jid:jid(),
Type :: any(),
Reason :: any().
check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
JID = jid:make(User, Server, <<>>),
case ejabberd_auth:does_user_exist(JID) of
check_in_subscription(Acc, ToJID, _FromJID, _Type, _Reason) ->
case ejabberd_auth:does_user_exist(ToJID) of
true ->
Acc;
false ->
Expand Down Expand Up @@ -714,8 +712,7 @@ do_route_no_resource_presence_prv(From, To, Acc, Packet, Type, Reason) ->
case is_privacy_allow(From, To, Acc, Packet) of
true ->
Res = mongoose_hooks:roster_in_subscription(To#jid.lserver,
Acc,
To#jid.user, To#jid.server, From, Type, Reason),
Acc, To, From, Type, Reason),
mongoose_acc:get(hook, result, false, Res);
false ->
false
Expand Down
4 changes: 2 additions & 2 deletions src/mam/mod_mam_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1083,10 +1083,10 @@ send_message(From, To, Mess) ->


-spec is_jid_in_user_roster(jid:jid(), jid:jid()) -> boolean().
is_jid_in_user_roster(#jid{lserver=LServer, luser=LUser},
is_jid_in_user_roster(#jid{lserver = LServer} = ToJID,
#jid{} = RemJID) ->
RemBareJID = jid:to_bare(RemJID),
{Subscription, _G} = mongoose_hooks:roster_get_jid_info(LServer, {none, []}, LUser, RemBareJID),
{Subscription, _G} = mongoose_hooks:roster_get_jid_info(LServer, {none, []}, ToJID, RemBareJID),
Subscription == from orelse Subscription == both.


Expand Down
20 changes: 10 additions & 10 deletions src/metrics/mongoose_metrics_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
roster_get/2,
roster_set/4,
roster_push/3,
roster_in_subscription/6,
roster_in_subscription/5,
register_user/3,
remove_user/3,
privacy_iq_get/5,
Expand Down Expand Up @@ -156,9 +156,9 @@ xmpp_send_element(Acc, _El) ->

%% Roster

-spec roster_get(list(), {_, jid:server()}) -> list().
roster_get(Acc, {_, Server}) ->
mongoose_metrics:update(Server, modRosterGets, 1),
-spec roster_get(list(), jid:jid()) -> list().
roster_get(Acc, #jid{lserver = LServer}) ->
mongoose_metrics:update(LServer, modRosterGets, 1),
Acc.

-spec roster_set(Acc :: map(), JID :: jid:jid(), tuple(), tuple()) ->
Expand All @@ -167,14 +167,14 @@ roster_set(Acc, #jid{server = Server}, _, _) ->
mongoose_metrics:update(Server, modRosterSets, 1),
Acc.

-spec roster_in_subscription(term(), binary(), binary(), tuple(), atom(), term()) -> term().
roster_in_subscription(Acc, _, Server, _, subscribed, _) ->
mongoose_metrics:update(Server, modPresenceSubscriptions, 1),
-spec roster_in_subscription(term(), jid:jid(), jid:jid(), atom(), term()) -> term().
roster_in_subscription(Acc, #jid{lserver = LServer}, _, subscribed, _) ->
mongoose_metrics:update(LServer, modPresenceSubscriptions, 1),
Acc;
roster_in_subscription(Acc, _, Server, _, unsubscribed, _) ->
mongoose_metrics:update(Server, modPresenceUnsubscriptions, 1),
roster_in_subscription(Acc, #jid{lserver = LServer}, _, unsubscribed, _) ->
mongoose_metrics:update(LServer, modPresenceUnsubscriptions, 1),
Acc;
roster_in_subscription(Acc, _, _, _, _, _) ->
roster_in_subscription(Acc, _, _, _, _) ->
Acc.

-spec roster_push(map(), jid:jid(), term()) -> metrics_notify_return().
Expand Down
17 changes: 7 additions & 10 deletions src/mod_commands.erl
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,12 @@ parse_from_to(F, T) ->
end.

list_contacts(Caller) ->
CallerJID = jid:from_binary(Caller),
CallerJID = #jid{lserver = LServer} = jid:from_binary(Caller),
Acc0 = mongoose_acc:new(#{ location => ?LOCATION,
lserver => CallerJID#jid.lserver,
lserver => LServer,
element => undefined }),
Acc1 = mongoose_acc:set(roster, show_full_roster, true, Acc0),
{User, Host} = jid:to_lus(CallerJID),
Acc2 = mongoose_hooks:roster_get(Host, Acc1, User, Host),
Acc2 = mongoose_hooks:roster_get(LServer, Acc1, CallerJID),
Res = mongoose_acc:get(roster, items, Acc2),
[roster_info(mod_roster:item_to_map(I)) || I <- Res].

Expand Down Expand Up @@ -495,17 +494,15 @@ decode_action(_) -> error.
run_subscription(Type, CallerJid, OtherJid) ->
StanzaType = atom_to_binary(Type, latin1),
El = #xmlel{name = <<"presence">>, attrs = [{<<"type">>, StanzaType}]},
LServer = CallerJid#jid.lserver,
Acc1 = mongoose_acc:new(#{ location => ?LOCATION,
from_jid => CallerJid,
to_jid => OtherJid,
lserver => CallerJid#jid.lserver,
lserver => LServer,
element => El }),
% set subscription to
Server = CallerJid#jid.server,
LUser = CallerJid#jid.luser,
Acc2 = mongoose_hooks:roster_out_subscription(Server,
Acc1,
LUser, OtherJid, Type),
Acc2 = mongoose_hooks:roster_out_subscription(
LServer, Acc1, CallerJid, OtherJid, Type),
ejabberd_router:route(CallerJid, OtherJid, Acc2),
ok.

Expand Down
4 changes: 2 additions & 2 deletions src/mod_disco.erl
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,12 @@ get_sm_items(empty, From, To, _Node, _Lang) ->


-spec is_presence_subscribed(jid:jid(), jid:jid()) -> boolean().
is_presence_subscribed(#jid{luser = LFromUser, lserver = LFromServer} = _From,
is_presence_subscribed(#jid{luser = LFromUser, lserver = LFromServer} = FromJID,
#jid{luser = LToUser, lserver = LToServer} = _To) ->
A = mongoose_acc:new(#{ location => ?LOCATION,
lserver => LFromServer,
element => undefined }),
A2 = mongoose_hooks:roster_get(LFromServer, A, LFromUser, LFromServer),
A2 = mongoose_hooks:roster_get(LFromServer, A, FromJID),
Roster = mongoose_acc:get(roster, items, [], A2),
lists:any(fun({roster, _, _, JID, _, S, _, _, _, _}) ->
{TUser, TServer} = jid:to_lus(JID),
Expand Down
4 changes: 1 addition & 3 deletions src/mod_last.erl
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ process_sm_iq(From, To, Acc, #iq{type = get, sub_el = SubEl} = IQ) ->
User = To#jid.luser,
Server = To#jid.lserver,
{Subscription, _Groups} =
mongoose_hooks:roster_get_jid_info(Server,
{none, []},
User, From),
mongoose_hooks:roster_get_jid_info(Server, {none, []}, To, From),
MutualSubscription = Subscription == both,
RequesterSubscribedToTarget = Subscription == from,
QueryingSameUsersLast = (From#jid.luser == To#jid.luser) and
Expand Down
6 changes: 3 additions & 3 deletions src/mod_privacy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ check_packet(Acc, User, Server,
{Subscription, Groups} =
case NeedDb of
true ->
roster_get_jid_info(Server, User, LJID);
roster_get_jid_info(Server, jid:make(User, Server, <<>>), LJID);
false ->
{[], []}
end,
Expand Down Expand Up @@ -666,10 +666,10 @@ broadcast_privacy_list(LUser, LServer, Name, UserList) ->
broadcast_privacy_list_packet(Name, UserList) ->
{broadcast, {privacy_list, UserList, Name}}.

roster_get_jid_info(Host, User, LJID) ->
roster_get_jid_info(Host, ToJID, LJID) ->
mongoose_hooks:roster_get_jid_info(Host,
{none, []},
User, LJID).
ToJID, LJID).

config_metrics(Host) ->
OptsToReport = [{backend, mnesia}], %list of tuples {option, defualt_value}
Expand Down
Loading

0 comments on commit fe00bff

Please sign in to comment.