Skip to content

Commit

Permalink
Remove 'local_send_to_resource' hook
Browse files Browse the repository at this point in the history
It was registered per domain, not per host type,
  what caused exometer to create one metric per domain.

It can be removed as 'ejabberd_local' was the only module handling it.
This unexpected type of stanza shouldn't be handled by modules as well.
  • Loading branch information
chrzaszcz committed May 31, 2021
1 parent cf515ef commit 95c54a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
24 changes: 11 additions & 13 deletions src/ejabberd_local.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
unregister_host/1,
unregister_iq_response_handler/2,
refresh_iq_handlers/0,
bounce_resource_packet/4,
sync/0
]).

Expand Down Expand Up @@ -224,11 +223,11 @@ refresh_iq_handlers() ->
-spec bounce_resource_packet(Acc :: mongoose_acc:t(),
From :: jid:jid(),
To :: jid:jid(),
El :: exml:element()) -> {'stop', mongoose_acc:t()}.
El :: exml:element()) -> mongoose_acc:t().
bounce_resource_packet(Acc, From, To, El) ->
{Acc1, Err} = jlib:make_error_reply(Acc, El, mongoose_xmpp_errors:item_not_found()),
ejabberd_router:route(To, From, Acc1, Err),
{stop, Acc}.
Acc.

-spec register_host(Host :: jid:server()) -> ok.
register_host(Host) ->
Expand Down Expand Up @@ -274,7 +273,7 @@ init([]) ->
[{ram_copies, [node()]},
{attributes, record_info(fields, iq_response)}]),
mnesia:add_table_copy(iq_response, node(), ram_copies),
ejabberd_hooks:add(node_cleanup, global, ?MODULE, node_cleanup, 50),
ejabberd_hooks:add(hooks()),
{ok, #state{}}.

%%--------------------------------------------------------------------
Expand Down Expand Up @@ -354,8 +353,7 @@ handle_info(_Info, State) ->
%% The return value is ignored.
%%--------------------------------------------------------------------
terminate(_Reason, _State) ->
ejabberd_hooks:delete(node_cleanup, global, ?MODULE, node_cleanup, 50),
ok.
ejabberd_hooks:delete(hooks()).

%%--------------------------------------------------------------------
%% Func: code_change(OldVsn, State, Extra) -> {ok, NewState}
Expand All @@ -367,6 +365,10 @@ code_change(_OldVsn, State, _Extra) ->
%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------

hooks() ->
[{node_cleanup, global, ?MODULE, node_cleanup, 50}].

-spec do_route(Acc :: mongoose_acc:t(),
From :: jid:jid(),
To :: jid:jid(),
Expand All @@ -387,7 +389,7 @@ do_route(Acc, From, To, El) ->
case mongoose_acc:stanza_type(Acc) of
<<"error">> -> Acc;
<<"result">> -> Acc;
_ -> mongoose_hooks:local_send_to_resource_hook(Acc, From, To, El)
_ -> bounce_resource_packet(Acc, From, To, El)
end
end.

Expand Down Expand Up @@ -458,12 +460,8 @@ cancel_timer(TRef) ->
end.

do_register_host(Host) ->
ejabberd_router:register_route(Host, mongoose_packet_handler:new(?MODULE)),
ejabberd_hooks:add(local_send_to_resource_hook, Host,
?MODULE, bounce_resource_packet, 100).
ejabberd_router:register_route(Host, mongoose_packet_handler:new(?MODULE)).

do_unregister_host(Host) ->
ejabberd_router:unregister_route(Host),
ejabberd_hooks:delete(local_send_to_resource_hook, Host,
?MODULE, bounce_resource_packet, 100).
ejabberd_router:unregister_route(Host).

12 changes: 0 additions & 12 deletions src/mongoose_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
filter_local_packet/1,
filter_packet/1,
inbox_unread_count/3,
local_send_to_resource_hook/4,
get_key/2,
packet_to_component/3,
presence_probe_hook/5,
Expand Down Expand Up @@ -288,17 +287,6 @@ filter_packet(Acc) ->
inbox_unread_count(LServer, Acc, User) ->
ejabberd_hooks:run_for_host_type(inbox_unread_count, LServer, Acc, [User]).

-spec local_send_to_resource_hook(Acc, From, To, Packet) -> Result when
Acc :: mongoose_acc:t(),
From :: jid:jid(),
To :: jid:jid(),
Packet :: exml:element(),
Result :: mongoose_acc:t().
local_send_to_resource_hook(Acc, From, To, Packet) ->
HostType = mongoose_acc:host_type(Acc),
ejabberd_hooks:run_for_host_type(local_send_to_resource_hook, HostType, Acc,
[From, To, Packet]).

%%% @doc The `get_key' hook is called to extract a key from `mod_keystore'.
-spec get_key(LServer, KeyName) -> Result when
LServer :: jid:lserver(),
Expand Down

0 comments on commit 95c54a7

Please sign in to comment.