25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-24 17:29:28 +01:00

Attach modules to gen_mod's supervisor

This commit is contained in:
Evgeniy Khramtsov 2017-02-14 12:39:26 +03:00
parent a1e45ab56c
commit 28f66ddd7c
25 changed files with 125 additions and 355 deletions

View File

@ -47,5 +47,3 @@
-define(HEADER(CType),
[CType, ?AC_ALLOW_ORIGIN, ?AC_ALLOW_HEADERS]).
-define(PROCNAME, ejabberd_mod_bosh).

View File

@ -123,7 +123,7 @@
start(#body{attrs = Attrs} = Body, IP, SID) ->
XMPPDomain = get_attr(to, Attrs),
SupervisorProc = gen_mod:get_module_proc(XMPPDomain, ?PROCNAME),
SupervisorProc = gen_mod:get_module_proc(XMPPDomain, mod_bosh),
case catch supervisor:start_child(SupervisorProc,
[Body, IP, SID])
of

View File

@ -26,9 +26,12 @@
-module(gen_mod).
-behaviour(ejabberd_config).
-behaviour(supervisor).
-author('alexey@process-one.net').
-export([init/1, start_link/0, start_child/3, start_child/4,
stop_child/1, stop_child/2]).
-export([start/0, start_module/2, start_module/3,
stop_module/2, stop_module_keep_config/2, get_opt/3,
get_opt/4, get_opt_host/3, opt_type/1,
@ -59,14 +62,43 @@
-export_type([opts/0]).
-export_type([db_type/0]).
%%behaviour_info(callbacks) -> [{start, 2}, {stop, 1}];
%%behaviour_info(_Other) -> undefined.
-ifndef(GEN_SERVER).
-define(GEN_SERVER, gen_server).
-endif.
start() ->
Spec = {ejabberd_gen_mod_sup, {?MODULE, start_link, []},
permanent, infinity, supervisor, [?MODULE]},
supervisor:start_child(ejabberd_sup, Spec).
start_link() ->
supervisor:start_link({local, ejabberd_gen_mod_sup}, ?MODULE, []).
init([]) ->
ets:new(ejabberd_modules,
[named_table, public,
{keypos, #ejabberd_module.module_host}]),
ok.
{ok, {{one_for_one, 10, 1}, []}}.
-spec start_child(module(), binary() | global, opts()) -> ok | {error, any()}.
start_child(Mod, Host, Opts) ->
start_child(Mod, Host, Opts, get_module_proc(Host, Mod)).
-spec start_child(module(), binary() | global, opts(), atom()) -> ok | {error, any()}.
start_child(Mod, Host, Opts, Proc) ->
Spec = {Proc, {?GEN_SERVER, start_link,
[{local, Proc}, Mod, [Host, Opts], []]},
transient, 2000, worker, [Mod]},
supervisor:start_child(ejabberd_gen_mod_sup, Spec).
-spec stop_child(module(), binary() | global) -> ok.
stop_child(Mod, Host) ->
stop_child(get_module_proc(Host, Mod)).
-spec stop_child(atom()) -> ok | {error, any()}.
stop_child(Proc) ->
supervisor:terminate_child(ejabberd_gen_mod_sup, Proc),
supervisor:delete_child(ejabberd_gen_mod_sup, Proc).
-spec start_modules() -> any().
@ -500,7 +532,6 @@ get_hosts(Opts, Prefix) ->
end.
-spec get_module_proc(binary(), {frontend, atom()} | atom()) -> atom().
get_module_proc(Host, {frontend, Base}) ->
get_module_proc(<<"frontend_", Host/binary>>, Base);
get_module_proc(Host, Base) ->

View File

@ -37,7 +37,7 @@
disco_features/5, disco_items/5, depends/2,
send_announcement_to_all/3, announce_commands/4,
announce_items/4, mod_opt_type/1]).
-export([start_link/2, init/1, handle_call/3, handle_cast/2,
-export([init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3]).
-include("ejabberd.hrl").
@ -56,34 +56,19 @@
-record(state, {host :: binary()}).
-define(PROCNAME, ejabberd_announce).
-define(NS_ADMINL(Sub), [<<"http:">>, <<"jabber.org">>, <<"protocol">>,
<<"admin">>, <<Sub>>]).
tokenize(Node) -> str:tokens(Node, <<"/#">>).
%%====================================================================
%% API
%%====================================================================
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
%%====================================================================
%% gen_mod callbacks
%%====================================================================
start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
Spec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 2000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, Spec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
depends(_Host, _Opts) ->
[{mod_adhoc, hard}].
@ -155,7 +140,7 @@ code_change(_OldVsn, State, _Extra) ->
%% Announcing via messages to a custom resource
-spec announce(jid(), jid(), stanza()) -> ok | stop.
announce(From, #jid{luser = <<>>} = To, #message{} = Packet) ->
Proc = gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME),
Proc = gen_mod:get_module_proc(To#jid.lserver, ?MODULE),
Res = case To#jid.lresource of
<<"announce/all">> ->
gen_server:cast(Proc, {announce_all, From, To, Packet});
@ -539,7 +524,7 @@ handle_adhoc_form(From, #jid{lserver = LServer} = To,
Packet = #message{type = headline,
body = xmpp:mk_text(Body),
subject = xmpp:mk_text(Subject)},
Proc = gen_mod:get_module_proc(LServer, ?PROCNAME),
Proc = gen_mod:get_module_proc(LServer, ?MODULE),
case {Node, Body} of
{?NS_ADMIN_DELETE_MOTD, _} ->
if Confirm ->
@ -560,7 +545,7 @@ handle_adhoc_form(From, #jid{lserver = LServer} = To,
%% Throw an error and give him/her a chance to send message again.
{error, xmpp:err_not_acceptable(
<<"No body provided for announce message">>, Lang)};
%% Now send the packet to ?PROCNAME.
%% Now send the packet to ?MODULE.
%% We don't use direct announce_* functions because it
%% leads to large delay in response and <iq/> queries processing
{?NS_ADMIN_ANNOUNCE, _} ->

View File

@ -92,14 +92,14 @@ start(Host, Opts) ->
start_jiffy(Opts),
Mod = gen_mod:ram_db_mod(global, ?MODULE),
Mod:init(),
TmpSup = gen_mod:get_module_proc(Host, ?PROCNAME),
TmpSup = gen_mod:get_module_proc(Host, ?MODULE),
TmpSupSpec = {TmpSup,
{ejabberd_tmp_sup, start_link, [TmpSup, ejabberd_bosh]},
permanent, infinity, supervisor, [ejabberd_tmp_sup]},
supervisor:start_child(ejabberd_sup, TmpSupSpec).
stop(Host) ->
TmpSup = gen_mod:get_module_proc(Host, ?PROCNAME),
TmpSup = gen_mod:get_module_proc(Host, ?MODULE),
supervisor:terminate_child(ejabberd_sup, TmpSup),
supervisor:delete_child(ejabberd_sup, TmpSup).

View File

@ -41,7 +41,7 @@
get_user_caps/2, import_start/2, import_stop/2]).
%% gen_mod callbacks
-export([start/2, start_link/2, stop/1, depends/2]).
-export([start/2, stop/1, depends/2]).
%% gen_server callbacks
-export([init/1, handle_info/2, handle_call/3,
@ -56,8 +56,6 @@
-include("xmpp.hrl").
-include("mod_caps.hrl").
-define(PROCNAME, ejabberd_mod_caps).
-define(BAD_HASH_LIFETIME, 600).
-record(state, {host = <<"">> :: binary()}).
@ -69,21 +67,11 @@
-callback caps_write(binary(), {binary(), binary()},
non_neg_integer() | [binary()]) -> any().
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:start_link({local, Proc}, ?MODULE,
[Host, Opts], []).
start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 1000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc).
gen_mod:stop_child(?MODULE, Host).
-spec get_features(binary(), nothing | caps()) -> [binary()].
get_features(_Host, nothing) -> [];

View File

@ -42,7 +42,6 @@
-include("ejabberd.hrl").
-include("logger.hrl").
-include("xmpp.hrl").
-define(PROCNAME, ?MODULE).
-type direction() :: sent | received.

View File

@ -31,7 +31,6 @@
-behaviour(gen_mod).
%% API
-export([start_link/2]).
-export([start/2, stop/1, mod_opt_type/1, depends/2]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
@ -52,21 +51,11 @@
%%%===================================================================
%%% API
%%%===================================================================
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
PingSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 2000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, PingSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
mod_opt_type(namespaces) -> validate_fun();

View File

@ -32,8 +32,7 @@
-behaviour(gen_mod).
%% API
-export([start_link/2, start/2, stop/1,
do_client_version/3]).
-export([start/2, stop/1, do_client_version/3]).
-export([init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3,
@ -46,31 +45,20 @@
-record(state, {host = <<"">> :: binary()}).
-define(PROCNAME, ejabberd_mod_echo).
%%====================================================================
%% API
%% gen_mod API
%%====================================================================
%%--------------------------------------------------------------------
%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
%% Description: Starts the server
%%--------------------------------------------------------------------
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:start_link({local, Proc}, ?MODULE,
[Host, Opts], []).
start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 1000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
depends(_Host, _Opts) ->
[].
mod_opt_type(host) -> fun iolist_to_binary/1;
mod_opt_type(_) -> [host].
%%====================================================================
%% gen_server callbacks
@ -190,9 +178,3 @@ do_client_version(enabled, From, To) ->
after 5000 -> % Timeout in miliseconds: 5 seconds
[]
end.
depends(_Host, _Opts) ->
[].
mod_opt_type(host) -> fun iolist_to_binary/1;
mod_opt_type(_) -> [host].

View File

@ -28,7 +28,7 @@
-behaviour(gen_server).
%% API
-export([start_link/2, start/2, stop/1, c2s_auth_result/3,
-export([start/2, stop/1, c2s_auth_result/3,
c2s_stream_started/2]).
-export([init/1, handle_call/3, handle_cast/2,
@ -49,10 +49,6 @@
%%%===================================================================
%%% API
%%%===================================================================
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
-spec c2s_auth_result(ejabberd_c2s:state(), boolean(), binary())
-> ejabberd_c2s:state() | {stop, ejabberd_c2s:state()}.
c2s_auth_result(#{ip := {Addr, _}, lserver := LServer} = State, false, _User) ->
@ -111,16 +107,10 @@ c2s_stream_started(#{ip := {Addr, _}} = State, _) ->
%%====================================================================
start(Host, Opts) ->
catch ets:new(failed_auth, [named_table, public]),
Proc = gen_mod:get_module_proc(Host, ?MODULE),
ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 1000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
depends(_Host, _Opts) ->
[].

View File

@ -33,9 +33,6 @@
%% gen_mod callbacks
-export([start/2, stop/1]).
%% API
-export([start_link/2]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
@ -58,8 +55,6 @@
directory_indices, custom_headers, default_content_type,
content_types = [], user_access = none}).
-define(PROCNAME, ejabberd_mod_http_fileserver).
%% Response is {DataSize, Code, [{HeaderKey, HeaderValue}], Data}
-define(HTTP_ERR_FILE_NOT_FOUND,
{-1, 404, [], <<"Not found">>}).
@ -90,36 +85,14 @@
%%====================================================================
start(Host, Opts) ->
Proc = get_proc_name(Host),
ChildSpec =
{Proc,
{?MODULE, start_link, [Host, Opts]},
transient, % if process crashes abruptly, it gets restarted
1000,
worker,
[?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = get_proc_name(Host),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
depends(_Host, _Opts) ->
[].
%%====================================================================
%% API
%%====================================================================
%%--------------------------------------------------------------------
%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
%% Description: Starts the server
%%--------------------------------------------------------------------
start_link(Host, Opts) ->
Proc = get_proc_name(Host),
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
%%====================================================================
%% gen_server callbacks
%%====================================================================
@ -459,7 +432,7 @@ find_header(Header, Headers, Default) ->
%% Utilities
%%----------------------------------------------------------------------
get_proc_name(Host) -> gen_mod:get_module_proc(Host, ?PROCNAME).
get_proc_name(Host) -> gen_mod:get_module_proc(Host, ?MODULE).
join([], _) ->
<<"">>;

View File

@ -28,10 +28,11 @@
-protocol({xep, 363, '0.1'}).
-ifndef(GEN_SERVER).
-define(GEN_SERVER, gen_server).
-endif.
-define(SERVICE_REQUEST_TIMEOUT, 5000). % 5 seconds.
-define(SLOT_TIMEOUT, 18000000). % 5 hours.
-define(PROCNAME, ?MODULE).
-define(FORMAT(Error), file:format_error(Error)).
-define(URL_ENC(URL), binary_to_list(ejabberd_http:url_encode(URL))).
-define(ADDR_TO_STR(IP), ejabberd_config:may_hide_data(jlib:ip_to_list(IP))).
@ -65,8 +66,7 @@
-behaviour(gen_mod).
%% gen_mod/supervisor callbacks.
-export([start_link/3,
start/2,
-export([start/2,
stop/1,
depends/2,
mod_opt_type/1]).
@ -124,13 +124,6 @@
%%--------------------------------------------------------------------
%% gen_mod/supervisor callbacks.
%%--------------------------------------------------------------------
-spec start_link(binary(), atom(), gen_mod:opts())
-> {ok, pid()} | ignore | {error, _}.
start_link(ServerHost, Proc, Opts) ->
?GEN_SERVER:start_link({local, Proc}, ?MODULE, {ServerHost, Opts}, []).
-spec start(binary(), gen_mod:opts()) -> {ok, _} | {ok, _, _} | {error, _}.
start(ServerHost, Opts) ->
@ -143,14 +136,8 @@ start(ServerHost, Opts) ->
false ->
ok
end,
Proc = get_proc_name(ServerHost, ?PROCNAME),
Spec = {Proc,
{?MODULE, start_link, [ServerHost, Proc, Opts]},
permanent,
3000,
worker,
[?MODULE]},
supervisor:start_child(ejabberd_sup, Spec).
Proc = get_proc_name(ServerHost, ?MODULE),
gen_mod:start_child(?MODULE, ServerHost, Opts, Proc).
-spec stop(binary()) -> ok.
@ -164,9 +151,8 @@ stop(ServerHost) ->
false ->
ok
end,
Proc = get_proc_name(ServerHost, ?PROCNAME),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc).
Proc = get_proc_name(ServerHost, ?MODULE),
gen_mod:stop_child(Proc).
-spec mod_opt_type(atom()) -> fun((term()) -> term()) | [atom()].
@ -230,7 +216,7 @@ depends(_Host, _Opts) ->
-spec init({binary(), gen_mod:opts()}) -> {ok, state()}.
init({ServerHost, Opts}) ->
init([ServerHost, Opts]) ->
process_flag(trap_exit, true),
Host = gen_mod:get_opt_host(ServerHost, Opts, <<"upload.@HOST@">>),
Name = gen_mod:get_opt(name, Opts,
@ -750,7 +736,7 @@ parse_http_request(#request{host = Host, path = Path}) ->
true ->
{Host, Path}
end,
{gen_mod:get_module_proc(ProcURL, ?PROCNAME), Slot}.
{gen_mod:get_module_proc(ProcURL, ?MODULE), Slot}.
-spec store_file(binary(), binary(),
integer() | undefined,

View File

@ -26,8 +26,9 @@
-module(mod_http_upload_quota).
-author('holger@zedat.fu-berlin.de').
-ifndef(GEN_SERVER).
-define(GEN_SERVER, gen_server).
-define(PROCNAME, ?MODULE).
-endif.
-define(TIMEOUT, timer:hours(24)).
-define(INITIAL_TIMEOUT, timer:minutes(10)).
-define(FORMAT(Error), file:format_error(Error)).
@ -36,8 +37,7 @@
-behaviour(gen_mod).
%% gen_mod/supervisor callbacks.
-export([start_link/3,
start/2,
-export([start/2,
stop/1,
depends/2,
mod_opt_type/1]).
@ -71,31 +71,17 @@
%%--------------------------------------------------------------------
%% gen_mod/supervisor callbacks.
%%--------------------------------------------------------------------
-spec start_link(binary(), atom(), gen_mod:opts())
-> {ok, pid()} | ignore | {error, _}.
start_link(ServerHost, Proc, Opts) ->
?GEN_SERVER:start_link({local, Proc}, ?MODULE, {ServerHost, Opts}, []).
-spec start(binary(), gen_mod:opts()) -> {ok, _} | {ok, _, _} | {error, _}.
start(ServerHost, Opts) ->
Proc = mod_http_upload:get_proc_name(ServerHost, ?PROCNAME),
Spec = {Proc,
{?MODULE, start_link, [ServerHost, Proc, Opts]},
permanent,
3000,
worker,
[?MODULE]},
supervisor:start_child(ejabberd_sup, Spec).
Proc = mod_http_upload:get_proc_name(ServerHost, ?MODULE),
gen_mod:start_child(?MODULE, ServerHost, Opts, Proc).
-spec stop(binary()) -> ok.
stop(ServerHost) ->
Proc = mod_http_upload:get_proc_name(ServerHost, ?PROCNAME),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc).
Proc = mod_http_upload:get_proc_name(ServerHost, ?MODULE),
gen_mod:stop_child(Proc).
-spec mod_opt_type(atom()) -> fun((term()) -> term()) | [atom()].
@ -119,9 +105,7 @@ depends(_Host, _Opts) ->
%% gen_server callbacks.
%%--------------------------------------------------------------------
-spec init({binary(), gen_mod:opts()}) -> {ok, state()}.
init({ServerHost, Opts}) ->
init([ServerHost, Opts]) ->
process_flag(trap_exit, true),
AccessSoftQuota = gen_mod:get_opt(access_soft_quota, Opts,
fun acl:shaper_rules_validator/1,
@ -268,7 +252,7 @@ code_change(_OldVsn, #state{server_host = ServerHost} = State, _Extra) ->
handle_slot_request(allow, #jid{lserver = ServerHost} = JID, Path, Size,
_Lang) ->
Proc = mod_http_upload:get_proc_name(ServerHost, ?PROCNAME),
Proc = mod_http_upload:get_proc_name(ServerHost, ?MODULE),
?GEN_SERVER:cast(Proc, {handle_slot_request, JID, Path, Size}),
allow;
handle_slot_request(Acc, _JID, _Path, _Size, _Lang) -> Acc.

View File

@ -32,7 +32,7 @@
-behaviour(gen_mod).
%% API
-export([start_link/2, start/2, stop/1, export/1, import/1,
-export([start/2, stop/1, export/1, import/1,
import/3, closed_connection/3, get_connection_params/3,
data_to_binary/2, process_disco_info/1, process_disco_items/1,
process_register/1, process_vcard/1, process_command/1]).
@ -62,38 +62,21 @@
server_host = <<"">> :: binary(),
access = all :: atom()}).
-define(PROCNAME, ejabberd_mod_irc).
-callback init(binary(), gen_mod:opts()) -> any().
-callback import(binary(), #irc_custom{}) -> ok | pass.
-callback get_data(binary(), binary(), jid()) -> error | empty | irc_data().
-callback set_data(binary(), binary(), jid(), irc_data()) -> {atomic, any()}.
%%====================================================================
%% API
%% gen_mod API
%%====================================================================
%%--------------------------------------------------------------------
%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
%% Description: Starts the server
%%--------------------------------------------------------------------
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:start_link({local, Proc}, ?MODULE,
[Host, Opts], []).
start(Host, Opts) ->
start_supervisor(Host),
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 1000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
stop_supervisor(Host),
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
depends(_Host, _Opts) ->
[].

View File

@ -28,7 +28,7 @@
-behaviour(gen_mod).
%% API
-export([start_link/2, start/2, stop/1, process_iq/1,
-export([start/2, stop/1, process_iq/1,
disco_items/5, disco_identity/5, disco_info/5,
disco_features/5, mod_opt_type/1, depends/2]).
@ -39,7 +39,6 @@
-include("logger.hrl").
-include("xmpp.hrl").
-define(PROCNAME, ejabberd_mod_mix).
-define(NODES, [?NS_MIX_NODES_MESSAGES,
?NS_MIX_NODES_PRESENCE,
?NS_MIX_NODES_PARTICIPANTS,
@ -52,21 +51,11 @@
%%%===================================================================
%%% API
%%%===================================================================
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 5000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
-spec disco_features({error, stanza_error()} | {result, [binary()]} | empty,
jid(), jid(), binary(), binary()) -> {result, [binary()]}.

View File

@ -34,8 +34,7 @@
-behaviour(gen_mod).
%% API
-export([start_link/2,
start/2,
-export([start/2,
stop/1,
room_destroyed/4,
store_room/4,
@ -83,8 +82,6 @@
default_room_opts = [] :: list(),
room_shaper = none :: shaper:shaper()}).
-define(PROCNAME, ejabberd_mod_muc).
-type muc_room_opts() :: [{atom(), any()}].
-callback init(binary(), gen_mod:opts()) -> any().
-callback import(binary(), binary(), [binary()]) -> ok.
@ -109,22 +106,12 @@
%%====================================================================
%% API
%%====================================================================
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:start_link({local, Proc}, ?MODULE,
[Host, Opts], []).
start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 1000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Rooms = shutdown_rooms(Host),
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
gen_mod:stop_child(?MODULE, Host),
{wait, Rooms}.
depends(_Host, _Opts) ->
@ -150,7 +137,7 @@ shutdown_rooms(Host) ->
%% In this case, the mod_muc process died before the room processes
%% So the message sending must be catched
room_destroyed(Host, Room, Pid, ServerHost) ->
catch gen_mod:get_module_proc(ServerHost, ?PROCNAME) !
catch gen_mod:get_module_proc(ServerHost, ?MODULE) !
{room_destroyed, {Room, Host}, Pid},
ok.
@ -158,7 +145,7 @@ room_destroyed(Host, Room, Pid, ServerHost) ->
%% If Opts = default, the default room options are used.
%% Else use the passed options as defined in mod_muc_room.
create_room(Host, Name, From, Nick, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
Proc = gen_mod:get_module_proc(Host, ?MODULE),
gen_server:call(Proc, {create, Name, From, Nick, Opts}).
store_room(ServerHost, Host, Name, Opts) ->

View File

@ -36,7 +36,7 @@
-behaviour(gen_mod).
%% API
-export([start_link/2, start/2, stop/1, transform_module_options/1,
-export([start/2, stop/1, transform_module_options/1,
check_access_log/2, add_to_log/5]).
-export([init/1, handle_call/3, handle_cast/2,
@ -50,7 +50,6 @@
-include("mod_muc_room.hrl").
-define(T(Text), translate:translate(Lang, Text)).
-define(PROCNAME, ejabberd_mod_muc_log).
-record(room, {jid, title, subject, subject_author, config}).
-define(PLAINTEXT_CO, <<"ZZCZZ">>).
@ -73,21 +72,11 @@
%%====================================================================
%% API
%%====================================================================
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 1000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
add_to_log(Host, Type, Data, Room, Opts) ->
gen_server:cast(get_proc_name(Host),
@ -1185,7 +1174,7 @@ get_room_state(RoomPid) ->
R.
get_proc_name(Host) ->
gen_mod:get_module_proc(Host, ?PROCNAME).
gen_mod:get_module_proc(Host, ?MODULE).
calc_hour_offset(TimeHere) ->
TimeZero = calendar:universal_time(),

View File

@ -34,7 +34,7 @@
-behaviour(gen_mod).
%% API
-export([start_link/2, start/2, stop/1]).
-export([start/2, stop/1]).
%% gen_server callbacks
-export([init/1, handle_info/2, handle_call/3,
@ -97,8 +97,6 @@
-define(VERSION_MULTICAST, <<"$Revision: 440 $ ">>).
-define(PROCNAME, ejabberd_mod_multicast).
-define(PURGE_PROCNAME,
ejabberd_mod_multicast_purgeloop).
@ -118,23 +116,11 @@
-define(DEFAULT_LIMIT_REMOTE_PRESENCE, 20).
start_link(LServerS, Opts) ->
Proc = gen_mod:get_module_proc(LServerS, ?PROCNAME),
gen_server:start_link({local, Proc}, ?MODULE,
[LServerS, Opts], []).
start(LServerS, Opts) ->
Proc = gen_mod:get_module_proc(LServerS, ?PROCNAME),
ChildSpec = {Proc,
{?MODULE, start_link, [LServerS, Opts]}, temporary,
1000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
gen_mod:start_child(?MODULE, LServerS, Opts).
stop(LServerS) ->
Proc = gen_mod:get_module_proc(LServerS, ?PROCNAME),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, LServerS).
%%====================================================================
%% gen_server callbacks

View File

@ -33,13 +33,14 @@
-protocol({xep, 160, '1.0'}).
-protocol({xep, 334, '0.2'}).
-define(GEN_SERVER, p1_server).
-ifndef(GEN_SERVER).
-define(GEN_SERVER, gen_server).
-endif.
-behaviour(?GEN_SERVER).
-behaviour(gen_mod).
-export([start/2,
start_link/2,
stop/1,
store_packet/4,
store_offline_msg/5,
@ -83,8 +84,6 @@
-include("mod_offline.hrl").
-define(PROCNAME, ejabberd_offline).
-define(OFFLINE_TABLE_LOCK_THRESHOLD, 1000).
%% default value for the maximum number of user messages
@ -112,22 +111,11 @@
-callback remove_all_messages(binary(), binary()) -> {atomic, any()}.
-callback count_messages(binary(), binary()) -> non_neg_integer().
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
?GEN_SERVER:start_link({local, Proc}, ?MODULE,
[Host, Opts], []).
start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 1000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
depends(_Host, _Opts) ->
[].
@ -478,7 +466,7 @@ store_packet(Acc, From, To, Packet) ->
NewPacket ->
TimeStamp = p1_time_compat:timestamp(),
Expire = find_x_expire(TimeStamp, NewPacket),
gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME) !
gen_mod:get_module_proc(To#jid.lserver, ?MODULE) !
#offline_msg{us = {LUser, LServer},
timestamp = TimeStamp,
expire = Expire,

View File

@ -45,7 +45,7 @@
-define(DEFAULT_PING_INTERVAL, 60).
%% API
-export([start_link/2, start_ping/2, stop_ping/2]).
-export([start_ping/2, stop_ping/2]).
%% gen_mod callbacks
-export([start/2, stop/1]).
@ -68,11 +68,6 @@
%%====================================================================
%% API
%%====================================================================
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
gen_server:start_link({local, Proc}, ?MODULE,
[Host, Opts], []).
-spec start_ping(binary(), jid()) -> ok.
start_ping(Host, JID) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
@ -87,16 +82,10 @@ stop_ping(Host, JID) ->
%% gen_mod callbacks
%%====================================================================
start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
PingSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 2000, worker, [?MODULE]},
supervisor:start_child(?SUPERVISOR, PingSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(?SUPERVISOR, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
%%====================================================================
%% gen_server callbacks

View File

@ -31,7 +31,6 @@
-behaviour(gen_mod).
%% API
-export([start_link/2]).
-export([start/2, stop/1, mod_opt_type/1, depends/2]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
@ -50,21 +49,11 @@
%%%===================================================================
%%% API
%%%===================================================================
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
PingSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 2000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, PingSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
mod_opt_type(roster) -> v_roster();
mod_opt_type(message) -> v_message();

View File

@ -86,13 +86,12 @@
err_unsupported_access_model/0]).
%% API and gen_server callbacks
-export([start_link/2, start/2, stop/1, init/1,
-export([start/2, stop/1, init/1,
handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3, depends/2]).
-export([send_loop/1, mod_opt_type/1]).
-define(PROCNAME, ejabberd_mod_pubsub).
-define(LOOPNAME, ejabberd_mod_pubsub_loop).
%%====================================================================
@ -219,21 +218,11 @@
).
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 1000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
%%====================================================================
%% gen_server callbacks

View File

@ -33,7 +33,7 @@
-behaviour(gen_mod).
%% API
-export([start_link/2, start/2, stop/1]).
-export([start/2, stop/1]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2,
@ -90,22 +90,11 @@
%%====================================================================
%% API
%%====================================================================
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
gen_server:start_link({local, Proc}, ?MODULE,
[Host, Opts], []).
start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
permanent, 1000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
depends(_Host, _Opts) ->
[{mod_roster, hard}].

View File

@ -24,7 +24,9 @@
%%%-------------------------------------------------------------------
-module(mod_sip_registrar).
-define(GEN_SERVER, p1_server).
-ifndef(GEN_SERVER).
-define(GEN_SERVER, gen_server).
-endif.
-behaviour(?GEN_SERVER).
%% API

View File

@ -39,7 +39,7 @@
depends/2, process_search/1, process_vcard/1, get_vcard/2,
disco_items/5, disco_features/5, disco_identity/5,
decode_iq_subel/1, mod_opt_type/1, set_vcard/3, make_vcard_search/4]).
-export([start_link/2, init/1, handle_call/3, handle_cast/2,
-export([init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3]).
-include("ejabberd.hrl").
@ -49,8 +49,6 @@
-define(JUD_MATCHES, 30).
-define(PROCNAME, ejabberd_mod_vcard).
-callback init(binary(), gen_mod:opts()) -> any().
-callback stop(binary()) -> any().
-callback import(binary(), binary(), [binary()]) -> ok.
@ -66,27 +64,14 @@
-record(state, {host :: binary(), server_host :: binary()}).
%%====================================================================
%% API
%%====================================================================
start_link(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
%%====================================================================
%% gen_mod callbacks
%%====================================================================
start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
Spec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 2000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, Spec).
gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
gen_mod:stop_child(?MODULE, Host).
%%====================================================================
%% gen_server callbacks