Skip to content

Commit

Permalink
Update some modules to the new gen_mod API
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyshch committed Aug 4, 2023
1 parent 20a8654 commit 60002fc
Show file tree
Hide file tree
Showing 24 changed files with 209 additions and 526 deletions.
55 changes: 13 additions & 42 deletions src/mod_adhoc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,49 +42,20 @@
-include_lib("xmpp/include/xmpp.hrl").
-include("translate.hrl").

start(Host, _Opts) ->
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_COMMANDS, ?MODULE, process_local_iq),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_COMMANDS, ?MODULE, process_sm_iq),
ejabberd_hooks:add(disco_local_identity, Host, ?MODULE,
get_local_identity, 99),
ejabberd_hooks:add(disco_local_features, Host, ?MODULE,
get_local_features, 99),
ejabberd_hooks:add(disco_local_items, Host, ?MODULE,
get_local_commands, 99),
ejabberd_hooks:add(disco_sm_identity, Host, ?MODULE,
get_sm_identity, 99),
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE,
get_sm_features, 99),
ejabberd_hooks:add(disco_sm_items, Host, ?MODULE,
get_sm_commands, 99),
ejabberd_hooks:add(adhoc_local_items, Host, ?MODULE,
ping_item, 100),
ejabberd_hooks:add(adhoc_local_commands, Host, ?MODULE,
ping_command, 100).
start(_Host, _Opts) ->
{ok, [{iq_handler, ejabberd_local, ?NS_COMMANDS, process_local_iq},
{iq_handler, ejabberd_sm, ?NS_COMMANDS, process_sm_iq},
{hook, disco_local_identity, get_local_identity, 99},
{hook, disco_local_features, get_local_features, 99},
{hook, disco_local_items, get_local_commands, 99},
{hook, disco_sm_identity, get_sm_identity, 99},
{hook, disco_sm_features, get_sm_features, 99},
{hook, disco_sm_items, get_sm_commands, 99},
{hook, adhoc_local_items, ping_item, 100},
{hook, adhoc_local_commands, ping_command, 100}]}.

stop(Host) ->
ejabberd_hooks:delete(adhoc_local_commands, Host,
?MODULE, ping_command, 100),
ejabberd_hooks:delete(adhoc_local_items, Host, ?MODULE,
ping_item, 100),
ejabberd_hooks:delete(disco_sm_items, Host, ?MODULE,
get_sm_commands, 99),
ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE,
get_sm_features, 99),
ejabberd_hooks:delete(disco_sm_identity, Host, ?MODULE,
get_sm_identity, 99),
ejabberd_hooks:delete(disco_local_items, Host, ?MODULE,
get_local_commands, 99),
ejabberd_hooks:delete(disco_local_features, Host,
?MODULE, get_local_features, 99),
ejabberd_hooks:delete(disco_local_identity, Host,
?MODULE, get_local_identity, 99),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host,
?NS_COMMANDS),
gen_iq_handler:remove_iq_handler(ejabberd_local, Host,
?NS_COMMANDS).
stop(_Host) ->
ok.

reload(_Host, _NewOpts, _OldOpts) ->
ok.
Expand Down
23 changes: 7 additions & 16 deletions src/mod_avatar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,14 @@
%%%===================================================================
%%% API
%%%===================================================================
start(Host, _Opts) ->
ejabberd_hooks:add(pubsub_publish_item, Host, ?MODULE,
pubsub_publish_item, 50),
ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE,
vcard_iq_convert, 30),
ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE,
vcard_iq_publish, 100),
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE,
get_sm_features, 50).
start(_Host, _Opts) ->
{ok, [{hook, pubsub_publish_item, pubsub_publish_item, 50},
{hook, vcard_iq_set, vcard_iq_convert, 30},
{hook, vcard_iq_set, vcard_iq_publish, 100},
{hook, disco_sm_features, get_sm_features, 50}]}.

stop(Host) ->
ejabberd_hooks:delete(pubsub_publish_item, Host, ?MODULE,
pubsub_publish_item, 50),
ejabberd_hooks:delete(vcard_iq_set, Host, ?MODULE, vcard_iq_convert, 30),
ejabberd_hooks:delete(vcard_iq_set, Host, ?MODULE, vcard_iq_publish, 100),
ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE,
get_sm_features, 50).
stop(_Host) ->
ok.

reload(_Host, _NewOpts, _OldOpts) ->
ok.
Expand Down
20 changes: 6 additions & 14 deletions src/mod_block_strangers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,13 @@
%%%===================================================================
%%% Callbacks and hooks
%%%===================================================================
start(Host, _Opts) ->
ejabberd_hooks:add(user_receive_packet, Host,
?MODULE, filter_packet, 25),
ejabberd_hooks:add(roster_in_subscription, Host,
?MODULE, filter_subscription, 25),
ejabberd_hooks:add(offline_message_hook, Host,
?MODULE, filter_offline_msg, 25).
start(_Host, _Opts) ->
{ok, [{hook, user_receive_packet, filter_packet, 25},
{hook, roster_in_subscription, filter_subscription, 25},
{hook, offline_message_hook, filter_offline_msg, 25}]}.

stop(Host) ->
ejabberd_hooks:delete(user_receive_packet, Host,
?MODULE, filter_packet, 25),
ejabberd_hooks:delete(roster_in_subscription, Host,
?MODULE, filter_subscription, 25),
ejabberd_hooks:delete(offline_message_hook, Host,
?MODULE, filter_offline_msg, 25).
stop(_Host) ->
ok.

reload(_Host, _NewOpts, _OldOpts) ->
ok.
Expand Down
12 changes: 5 additions & 7 deletions src/mod_blocking.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@
-include("mod_privacy.hrl").
-include("translate.hrl").

start(Host, _Opts) ->
ejabberd_hooks:add(disco_local_features, Host, ?MODULE, disco_features, 50),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_BLOCKING, ?MODULE, process_iq).
start(_Host, _Opts) ->
{ok, [{hook, disco_local_features, disco_features, 50},
{iq_handler, ejabberd_sm, ?NS_BLOCKING, process_iq}]}.

stop(Host) ->
ejabberd_hooks:delete(disco_local_features, Host, ?MODULE, disco_features, 50),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_BLOCKING).
stop(_Host) ->
ok.

reload(_Host, _NewOpts, _OldOpts) ->
ok.
Expand Down
29 changes: 11 additions & 18 deletions src/mod_carboncopy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,18 @@
-type direction() :: sent | received.
-type c2s_state() :: ejabberd_c2s:state().

start(Host, _Opts) ->
ejabberd_hooks:add(disco_local_features, Host, ?MODULE, disco_features, 50),
%% why priority 89: to define clearly that we must run BEFORE mod_logdb hook (90)
ejabberd_hooks:add(user_send_packet,Host, ?MODULE, user_send_packet, 89),
ejabberd_hooks:add(user_receive_packet,Host, ?MODULE, user_receive_packet, 89),
ejabberd_hooks:add(c2s_copy_session, Host, ?MODULE, c2s_copy_session, 50),
ejabberd_hooks:add(c2s_session_resumed, Host, ?MODULE, c2s_session_resumed, 50),
ejabberd_hooks:add(c2s_session_opened, Host, ?MODULE, c2s_session_opened, 50),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_CARBONS_2, ?MODULE, iq_handler).
start(_Host, _Opts) ->
{ok, [{hook, disco_local_features, disco_features, 50},
%% why priority 89: to define clearly that we must run BEFORE mod_logdb hook (90)
{hook, user_send_packet, user_send_packet, 89},
{hook, user_receive_packet, user_receive_packet, 89},
{hook, c2s_copy_session, c2s_copy_session, 50},
{hook, c2s_session_resumed, c2s_session_resumed, 50},
{hook, c2s_session_opened, c2s_session_opened, 50},
{iq_handler, ejabberd_sm, ?NS_CARBONS_2, iq_handler}]}.

stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_CARBONS_2),
ejabberd_hooks:delete(disco_local_features, Host, ?MODULE, disco_features, 50),
%% why priority 89: to define clearly that we must run BEFORE mod_logdb hook (90)
ejabberd_hooks:delete(user_send_packet,Host, ?MODULE, user_send_packet, 89),
ejabberd_hooks:delete(user_receive_packet,Host, ?MODULE, user_receive_packet, 89),
ejabberd_hooks:delete(c2s_copy_session, Host, ?MODULE, c2s_copy_session, 50),
ejabberd_hooks:delete(c2s_session_resumed, Host, ?MODULE, c2s_session_resumed, 50),
ejabberd_hooks:delete(c2s_session_opened, Host, ?MODULE, c2s_session_opened, 50).
stop(_Host) ->
ok.

reload(_Host, _NewOpts, _OldOpts) ->
ok.
Expand Down
56 changes: 13 additions & 43 deletions src/mod_configure.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,51 +44,21 @@
-include("translate.hrl").
-include_lib("stdlib/include/ms_transform.hrl").

start(Host, _Opts) ->
ejabberd_hooks:add(disco_local_items, Host, ?MODULE,
get_local_items, 50),
ejabberd_hooks:add(disco_local_features, Host, ?MODULE,
get_local_features, 50),
ejabberd_hooks:add(disco_local_identity, Host, ?MODULE,
get_local_identity, 50),
ejabberd_hooks:add(disco_sm_items, Host, ?MODULE,
get_sm_items, 50),
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE,
get_sm_features, 50),
ejabberd_hooks:add(disco_sm_identity, Host, ?MODULE,
get_sm_identity, 50),
ejabberd_hooks:add(adhoc_local_items, Host, ?MODULE,
adhoc_local_items, 50),
ejabberd_hooks:add(adhoc_local_commands, Host, ?MODULE,
adhoc_local_commands, 50),
ejabberd_hooks:add(adhoc_sm_items, Host, ?MODULE,
adhoc_sm_items, 50),
ejabberd_hooks:add(adhoc_sm_commands, Host, ?MODULE,
adhoc_sm_commands, 50),
start(_Host, _Opts) ->
{ok, [{hook, disco_local_items, get_local_items, 50},
{hook, disco_local_features, get_local_features, 50},
{hook, disco_local_identity, get_local_identity, 50},
{hook, disco_sm_items, get_sm_items, 50},
{hook, disco_sm_features, get_sm_features, 50},
{hook, disco_sm_identity, get_sm_identity, 50},
{hook, adhoc_local_items, adhoc_local_items, 50},
{hook, adhoc_local_commands, adhoc_local_commands, 50},
{hook, adhoc_sm_items, adhoc_sm_items, 50},
{hook, adhoc_sm_commands, adhoc_sm_commands, 50}]}.

stop(_Host) ->
ok.

stop(Host) ->
ejabberd_hooks:delete(adhoc_sm_commands, Host, ?MODULE,
adhoc_sm_commands, 50),
ejabberd_hooks:delete(adhoc_sm_items, Host, ?MODULE,
adhoc_sm_items, 50),
ejabberd_hooks:delete(adhoc_local_commands, Host,
?MODULE, adhoc_local_commands, 50),
ejabberd_hooks:delete(adhoc_local_items, Host, ?MODULE,
adhoc_local_items, 50),
ejabberd_hooks:delete(disco_sm_identity, Host, ?MODULE,
get_sm_identity, 50),
ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE,
get_sm_features, 50),
ejabberd_hooks:delete(disco_sm_items, Host, ?MODULE,
get_sm_items, 50),
ejabberd_hooks:delete(disco_local_identity, Host,
?MODULE, get_local_identity, 50),
ejabberd_hooks:delete(disco_local_features, Host,
?MODULE, get_local_features, 50),
ejabberd_hooks:delete(disco_local_items, Host, ?MODULE,
get_local_items, 50).

reload(_Host, _NewOpts, _OldOpts) ->
ok.

Expand Down
35 changes: 9 additions & 26 deletions src/mod_last.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,15 @@ start(Host, Opts) ->
Mod = gen_mod:db_mod(Opts, ?MODULE),
Mod:init(Host, Opts),
init_cache(Mod, Host, Opts),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_LAST, ?MODULE, process_local_iq),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
?NS_LAST, ?MODULE, process_sm_iq),
ejabberd_hooks:add(privacy_check_packet, Host, ?MODULE,
privacy_check_packet, 30),
ejabberd_hooks:add(register_user, Host, ?MODULE,
register_user, 50),
ejabberd_hooks:add(remove_user, Host, ?MODULE,
remove_user, 50),
ejabberd_hooks:add(unset_presence_hook, Host, ?MODULE,
on_presence_update, 50).

stop(Host) ->
ejabberd_hooks:delete(register_user, Host, ?MODULE,
register_user, 50),
ejabberd_hooks:delete(remove_user, Host, ?MODULE,
remove_user, 50),
ejabberd_hooks:delete(unset_presence_hook, Host,
?MODULE, on_presence_update, 50),
ejabberd_hooks:delete(privacy_check_packet, Host, ?MODULE,
privacy_check_packet, 30),
gen_iq_handler:remove_iq_handler(ejabberd_local, Host,
?NS_LAST),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host,
?NS_LAST).
{ok, [{iq_handler, ejabberd_local, ?NS_LAST, process_local_iq},
{iq_handler, ejabberd_sm, ?NS_LAST, process_sm_iq},
{hook, privacy_check_packet, privacy_check_packet, 30},
{hook, register_user, register_user, 50},
{hook, remove_user, remove_user, 50},
{hook, unset_presence_hook, on_presence_update, 50}]}.

stop(_Host) ->
ok.

reload(Host, NewOpts, OldOpts) ->
NewMod = gen_mod:db_mod(NewOpts, ?MODULE),
Expand Down
17 changes: 6 additions & 11 deletions src/mod_legacy_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,12 @@
%%%===================================================================
%%% API
%%%===================================================================
start(Host, _Opts) ->
ejabberd_hooks:add(c2s_unauthenticated_packet, Host, ?MODULE,
c2s_unauthenticated_packet, 50),
ejabberd_hooks:add(c2s_pre_auth_features, Host, ?MODULE,
c2s_stream_features, 50).

stop(Host) ->
ejabberd_hooks:delete(c2s_unauthenticated_packet, Host, ?MODULE,
c2s_unauthenticated_packet, 50),
ejabberd_hooks:delete(c2s_pre_auth_features, Host, ?MODULE,
c2s_stream_features, 50).
start(_Host, _Opts) ->
{ok, [{hook, c2s_unauthenticated_packet, c2s_unauthenticated_packet, 50},
{hook, c2s_pre_auth_features, c2s_stream_features, 50}]}.

stop(_Host) ->
ok.

reload(_Host, _NewOpts, _OldOpts) ->
ok.
Expand Down
34 changes: 13 additions & 21 deletions src/mod_metrics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,19 @@
%% API
%%====================================================================

start(Host, _Opts) ->
ejabberd_hooks:add(offline_message_hook, Host, ?MODULE, offline_message_hook, 20),
ejabberd_hooks:add(sm_register_connection_hook, Host, ?MODULE, sm_register_connection_hook, 20),
ejabberd_hooks:add(sm_remove_connection_hook, Host, ?MODULE, sm_remove_connection_hook, 20),
ejabberd_hooks:add(user_send_packet, Host, ?MODULE, user_send_packet, 20),
ejabberd_hooks:add(user_receive_packet, Host, ?MODULE, user_receive_packet, 20),
ejabberd_hooks:add(s2s_send_packet, Host, ?MODULE, s2s_send_packet, 20),
ejabberd_hooks:add(s2s_receive_packet, Host, ?MODULE, s2s_receive_packet, 20),
ejabberd_hooks:add(remove_user, Host, ?MODULE, remove_user, 20),
ejabberd_hooks:add(register_user, Host, ?MODULE, register_user, 20).

stop(Host) ->
ejabberd_hooks:delete(offline_message_hook, Host, ?MODULE, offline_message_hook, 20),
ejabberd_hooks:delete(sm_register_connection_hook, Host, ?MODULE, sm_register_connection_hook, 20),
ejabberd_hooks:delete(sm_remove_connection_hook, Host, ?MODULE, sm_remove_connection_hook, 20),
ejabberd_hooks:delete(user_send_packet, Host, ?MODULE, user_send_packet, 20),
ejabberd_hooks:delete(user_receive_packet, Host, ?MODULE, user_receive_packet, 20),
ejabberd_hooks:delete(s2s_send_packet, Host, ?MODULE, s2s_send_packet, 20),
ejabberd_hooks:delete(s2s_receive_packet, Host, ?MODULE, s2s_receive_packet, 20),
ejabberd_hooks:delete(remove_user, Host, ?MODULE, remove_user, 20),
ejabberd_hooks:delete(register_user, Host, ?MODULE, register_user, 20).
start(_Host, _Opts) ->
{ok, [{hook, offline_message_hook, offline_message_hook, 20},
{hook, sm_register_connection_hook, sm_register_connection_hook, 20},
{hook, sm_remove_connection_hook, sm_remove_connection_hook, 20},
{hook, user_send_packet, user_send_packet, 20},
{hook, user_receive_packet, user_receive_packet, 20},
{hook, s2s_send_packet, s2s_send_packet, 20},
{hook, s2s_receive_packet, s2s_receive_packet, 20},
{hook, remove_user, remove_user, 20},
{hook, register_user, register_user, 20}]}.

stop(_Host) ->
ok.

reload(_Host, _NewOpts, _OldOpts) ->
ok.
Expand Down
5 changes: 2 additions & 3 deletions src/mod_mqtt_bridge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@
%%%===================================================================
%%% API
%%%===================================================================
start(Host, Opts) ->
start(_Host, Opts) ->
User = mod_mqtt_bridge_opt:replication_user(Opts),
start_servers(User, element(1, mod_mqtt_bridge_opt:servers(Opts))),
ejabberd_hooks:add(mqtt_publish, Host, ?MODULE, mqtt_publish_hook, 50).
{ok, [{hook, mqtt_publish, mqtt_publish_hook, 50}]}.

stop(Host) ->
ejabberd_hooks:delete(mqtt_publish, Host, ?MODULE, mqtt_publish_hook, 50),
stop_servers(element(1, mod_mqtt_bridge_opt:servers(Host))),
ok.

Expand Down
Loading

0 comments on commit 60002fc

Please sign in to comment.