25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +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), -define(HEADER(CType),
[CType, ?AC_ALLOW_ORIGIN, ?AC_ALLOW_HEADERS]). [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) -> start(#body{attrs = Attrs} = Body, IP, SID) ->
XMPPDomain = get_attr(to, Attrs), 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, case catch supervisor:start_child(SupervisorProc,
[Body, IP, SID]) [Body, IP, SID])
of of

View File

@ -26,9 +26,12 @@
-module(gen_mod). -module(gen_mod).
-behaviour(ejabberd_config). -behaviour(ejabberd_config).
-behaviour(supervisor).
-author('alexey@process-one.net'). -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, -export([start/0, start_module/2, start_module/3,
stop_module/2, stop_module_keep_config/2, get_opt/3, stop_module/2, stop_module_keep_config/2, get_opt/3,
get_opt/4, get_opt_host/3, opt_type/1, get_opt/4, get_opt_host/3, opt_type/1,
@ -59,14 +62,43 @@
-export_type([opts/0]). -export_type([opts/0]).
-export_type([db_type/0]). -export_type([db_type/0]).
%%behaviour_info(callbacks) -> [{start, 2}, {stop, 1}]; -ifndef(GEN_SERVER).
%%behaviour_info(_Other) -> undefined. -define(GEN_SERVER, gen_server).
-endif.
start() -> 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, ets:new(ejabberd_modules,
[named_table, public, [named_table, public,
{keypos, #ejabberd_module.module_host}]), {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(). -spec start_modules() -> any().
@ -500,7 +532,6 @@ get_hosts(Opts, Prefix) ->
end. end.
-spec get_module_proc(binary(), {frontend, atom()} | atom()) -> atom(). -spec get_module_proc(binary(), {frontend, atom()} | atom()) -> atom().
get_module_proc(Host, {frontend, Base}) -> get_module_proc(Host, {frontend, Base}) ->
get_module_proc(<<"frontend_", Host/binary>>, Base); get_module_proc(<<"frontend_", Host/binary>>, Base);
get_module_proc(Host, Base) -> get_module_proc(Host, Base) ->

View File

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

View File

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

View File

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

View File

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

View File

@ -32,8 +32,7 @@
-behaviour(gen_mod). -behaviour(gen_mod).
%% API %% API
-export([start_link/2, start/2, stop/1, -export([start/2, stop/1, do_client_version/3]).
do_client_version/3]).
-export([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, handle_info/2, terminate/2, code_change/3,
@ -46,31 +45,20 @@
-record(state, {host = <<"">> :: binary()}). -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) -> start(Host, Opts) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME), gen_mod:start_child(?MODULE, Host, Opts).
ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 1000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
stop(Host) -> stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME), gen_mod:stop_child(?MODULE, Host).
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc), depends(_Host, _Opts) ->
ok. [].
mod_opt_type(host) -> fun iolist_to_binary/1;
mod_opt_type(_) -> [host].
%%==================================================================== %%====================================================================
%% gen_server callbacks %% gen_server callbacks
@ -190,9 +178,3 @@ do_client_version(enabled, From, To) ->
after 5000 -> % Timeout in miliseconds: 5 seconds after 5000 -> % Timeout in miliseconds: 5 seconds
[] []
end. 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). -behaviour(gen_server).
%% API %% 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]). c2s_stream_started/2]).
-export([init/1, handle_call/3, handle_cast/2, -export([init/1, handle_call/3, handle_cast/2,
@ -49,10 +49,6 @@
%%%=================================================================== %%%===================================================================
%%% API %%% 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()) -spec c2s_auth_result(ejabberd_c2s:state(), boolean(), binary())
-> ejabberd_c2s:state() | {stop, ejabberd_c2s:state()}. -> ejabberd_c2s:state() | {stop, ejabberd_c2s:state()}.
c2s_auth_result(#{ip := {Addr, _}, lserver := LServer} = State, false, _User) -> c2s_auth_result(#{ip := {Addr, _}, lserver := LServer} = State, false, _User) ->
@ -111,16 +107,10 @@ c2s_stream_started(#{ip := {Addr, _}} = State, _) ->
%%==================================================================== %%====================================================================
start(Host, Opts) -> start(Host, Opts) ->
catch ets:new(failed_auth, [named_table, public]), catch ets:new(failed_auth, [named_table, public]),
Proc = gen_mod:get_module_proc(Host, ?MODULE), gen_mod:start_child(?MODULE, Host, Opts).
ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
transient, 1000, worker, [?MODULE]},
supervisor:start_child(ejabberd_sup, ChildSpec).
stop(Host) -> stop(Host) ->
Proc = gen_mod:get_module_proc(Host, ?MODULE), gen_mod:stop_child(?MODULE, Host).
supervisor:terminate_child(ejabberd_sup, Proc),
supervisor:delete_child(ejabberd_sup, Proc),
ok.
depends(_Host, _Opts) -> depends(_Host, _Opts) ->
[]. [].

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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