-define(HEADER(CType),
[CType, ?AC_ALLOW_ORIGIN, ?AC_ALLOW_HEADERS]).
-
--define(PROCNAME, ejabberd_mod_bosh).
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
-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,
-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().
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) ->
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").
-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}].
%% 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});
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 ->
%% 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, _} ->
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).
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,
-include("xmpp.hrl").
-include("mod_caps.hrl").
--define(PROCNAME, ejabberd_mod_caps).
-
-define(BAD_HASH_LIFETIME, 600).
-record(state, {host = <<"">> :: binary()}).
-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) -> [];
-include("ejabberd.hrl").
-include("logger.hrl").
-include("xmpp.hrl").
--define(PROCNAME, ?MODULE).
-type direction() :: sent | received.
-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,
%%%===================================================================
%%% 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();
-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,
-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
after 5000 -> % Timeout in miliseconds: 5 seconds
[]
end.
-
-depends(_Host, _Opts) ->
- [].
-
-mod_opt_type(host) -> fun iolist_to_binary/1;
-mod_opt_type(_) -> [host].
-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,
%%%===================================================================
%%% 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) ->
%%====================================================================
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) ->
[].
%% 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]).
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">>}).
%%====================================================================
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
%%====================================================================
%% Utilities
%%----------------------------------------------------------------------
-get_proc_name(Host) -> gen_mod:get_module_proc(Host, ?PROCNAME).
+get_proc_name(Host) -> gen_mod:get_module_proc(Host, ?MODULE).
join([], _) ->
<<"">>;
-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))).
-behaviour(gen_mod).
%% gen_mod/supervisor callbacks.
--export([start_link/3,
- start/2,
+-export([start/2,
stop/1,
depends/2,
mod_opt_type/1]).
%%--------------------------------------------------------------------
%% 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) ->
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.
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()].
-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,
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,
-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)).
-behaviour(gen_mod).
%% gen_mod/supervisor callbacks.
--export([start_link/3,
- start/2,
+-export([start/2,
stop/1,
depends/2,
mod_opt_type/1]).
%%--------------------------------------------------------------------
%% 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()].
%% 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,
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.
-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]).
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) ->
[].
-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]).
-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,
%%%===================================================================
%%% 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()]}.
-behaviour(gen_mod).
%% API
--export([start_link/2,
- start/2,
+-export([start/2,
stop/1,
room_destroyed/4,
store_room/4,
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.
%%====================================================================
%% 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) ->
%% 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.
%% 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) ->
-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,
-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">>).
%%====================================================================
%% 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),
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(),
-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,
-define(VERSION_MULTICAST, <<"$Revision: 440 $ ">>).
--define(PROCNAME, ejabberd_mod_multicast).
-
-define(PURGE_PROCNAME,
ejabberd_mod_multicast_purgeloop).
-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
-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,
-include("mod_offline.hrl").
--define(PROCNAME, ejabberd_offline).
-
-define(OFFLINE_TABLE_LOCK_THRESHOLD, 1000).
%% default value for the maximum number of user messages
-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) ->
[].
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,
-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]).
%%====================================================================
%% 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),
%% 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
-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,
%%%===================================================================
%%% 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();
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).
%%====================================================================
).
-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
-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,
%%====================================================================
%% 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}].
%%%-------------------------------------------------------------------
-module(mod_sip_registrar).
--define(GEN_SERVER, p1_server).
+-ifndef(GEN_SERVER).
+-define(GEN_SERVER, gen_server).
+-endif.
-behaviour(?GEN_SERVER).
%% API
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").
-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.
-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